Reverse Payphone Payments

Reversing a transaction in the Payphone system allows you to reverse a previously completed transaction, returning the funds to the customer's original account. This process is useful in cases of erroneous transactions or refund requests. However, the reversal can only be performed under certain conditions and within a limited time frame.

🔁 Reverse Method Flow

  • 🔸Transaction identification: The reverse side must be made using a unique identifier that corresponds to the original transaction. This identifier can be the Payphone ID or the ID given by the merchant.
  • 🔸Reverse execution: Once it has been validated that the conditions are met, the reverse side can be executed using one of the two methods provided by the Payphone API, depending on the type of identifier available.

⚠️Considerations

🔐Authentication token:

  • The token used to create the original transaction must be the same token used to perform the reverse transaction. This point is critical! If the same token is not used, the reverse transaction will not be processed correctly.

⏱️Time limit:

  • The reversal can only be requested on the same day of the transaction, until 20:00 hours EC. After this time, the reverse transaction will not be possible.

🧩Automatic Reverse : For payment box

  • How does it work? If you make a payment with a Payphone payment button or box, and the merchant does not confirm the transaction within 5 minutes, the system automatically reverses the payment.
  • Why 5 minutes? This time allows the merchant's systems to send the confirmation. If they do not send it, the payment is reversed to avoid undue charges.
  • What does this mean to you? Security and peace of mind. If a payment is not confirmed, it will not be collected."

.

🖥️Reverse API Implementation

Two methods are offered to perform the reverse side, depending on the identifier available:

🧩Reverse side with Payphone ID

In this case, you must use the Payphone ID corresponding to the transaction you wish to reverse.

🔗URL of the POST request:

https://pay.payphonetodoesposible.com/api/Reverse

🧱Request body (JSON):
id: The Payphone transaction ID. This value is provided at the time of the transaction.

{
  "id": 33107661  // Payphone transaction ID
}

🧩Reverse with ID issued by the retailer

In this case, the ID given by the merchant to the transaction (clientTransactionID) is used.

🔗URL of the POST request:

https://pay.payphonetodoesposible.com/api/Reverse/Client


🧱Body request (JSON):

clientTransactionId: The ID that the merchant assigned to the transaction. clientTransactionId.

{
  "clientId": "200-628-77"  // Id sent by the merchant in the transaction
}

🔐Required Headers
For both requests, the following HTTP headers must be included:

🔸Authorization: bearer YOUR_TOKEN (Application authentication token, preceded by the word "Bearer". This token is the same token you used when initially preparing the transaction).
🔸Content-type: application/json (Data format: JSON).

📫Response to POST request

✅Successful response: If the reversal was successful, the response will be a boolean value:

true

❌Failed response: If the reverse side cannot be performed, a JSON object will be returned with an error message and an error code:

{
    "message": "Transaction does not exist, verify that the submitted identifier is correct.",
    "errorCode": 20
}

This error message indicates that the identifier provided is invalid or does not correspond to an existing transaction. It is important to verify that the correct identifier is being used before attempting the reverse side again.

Examples of POST requests for API reverse
Below are several examples of how to make POST requests:

🧱 API Reverse Examples

<?php
    //Payphone transaction ID or clientTransaction Id sent by the merchant.
    $id = 33107661;

    //Headers request
    $headers[] = 'Authorization: Bearer your_token' ;//Auth credentials
    $headers[] = 'Content-Type: application/json' ;//Application type 

    //Json body for the request
    $data = array(
        "id" => (int)$id
    );
    $objetoJSON = json_encode($data);

    //Start request curl: POST 
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://pay.payphonetodoesposible.com/api/Reverse");
    curl_setopt($curl, CURLOPT_POST, 1);

    curl_setopt($curl, CURLOPT_POSTFIELDS, $objetoJSON);    
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    //JSON response
    $curl_response = curl_exec($curl);
    //End of the request curl: POST
    curl_close($curl);


    //show result
    echo "<h1>Reverse</h1> <br>";

    $result= json_decode($curl_response);
    echo "Response : <pre>".json_encode($result,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT )."</pre>";
?>
<html lang="es">
    <head>
        <meta charset="utf-8">
        <title>Reverso con jQuery</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>   
        <script>  
            var id=33107661;

            $(document).ready(function() {
                $.ajax({
                    url: "https://pay.payphonetodoesposible.com/api/Reverse",
                    type: "POST",
                    headers: {
                    	"Content-Type": "application/json",
                    	"Authorization": "Bearer your_token"
                    },
                    data: JSON.stringify({ 
                        "id": id
                    }),
                    success: function(response) {
                        $("#resultado").html(
                            "Respuesta : <pre>" + JSON.stringify(response, null, 2) + "</pre>"
                        );
                    },
                    error: function(error) {
                        $("#resultado").html(
                            "Error en la solicitud : <pre>" + JSON.stringify(error, null, 2) + "</pre>"
                        );
                    }
                });
            });
        </script>
    </head>    
    <body>
        <h1>Ejemplo de Solicitud POST con jQuery</h1>
        <div id="resultado"></div>
    
    </body>
</html>
<html lang="es">
    <head>
        <meta charset="utf-8">
        <title>Reverse with Fetch</title> 
        <script>            
            const id=33107661;

            const  headers = {
                "Content-Type": "application/json",
                "Authorization": "Bearer your_token",
                "Referer": document.referrer
            };

            const bodyJSON = { 
                "id": id
            };

            const  url = "https://pay.payphonetodoesposible.com/api/Reverse";

            fetch(url, {
                method: "POST",
                headers: headers,
                body: JSON.stringify(bodyJSON)
            })
            .then((res) => res.json())
            .catch((error) => {
                // error message
                const jsonResult = document.createElement("pre");
                jsonResult.textContent = JSON.stringify(error, null, 2);

                const container = document.createElement("div");
                container.appendChild(jsonResult);
                
                document.body.appendChild(container);
            })
            .then((data) => {

                const jsonResult = document.createElement("pre");
                jsonResult.textContent = JSON.stringify(data, null, 2);

                // assign the response to div
                const container = document.createElement("div");
                container.appendChild(jsonResult);

                document.body.appendChild(container);
            });  
        </script>
    </head>    
    <body>
        <h1>Reverse using Fetch</h1>   
    </body>
</html>

📈Reverse with Payphone Business

1️⃣Access to the Sales Menu:

  • 🔸Log in to the Payphone Business platform and go to the Sales Menu.
  • 🔸In this menu, all transactions performed will be displayed.

2️⃣Selection of the Transaction to Reverse:

  • 🔸Locate the transaction to be reversed (reversed).
  • 🔸In the action's column, select the Reverse option associated with the corresponding transaction.


3️⃣Confirmation of Cancellation:

  • 🔸When you click on the Anull option, a confirmation message will appear on the screen asking you to verify if you are sure to anull the selected transaction by displaying the transaction number.
  • 🔸You will be presented with two options: Yes (to confirm) and No (to cancel the operation).

⚙️Procedure according to the Method of Payment:

  • 🔸If the original payment was made by credit or debit card, the system will prompt you to enter the card number used in the transaction.
  • 🔸If the payment was made through the personal Payphone application, the system will send a notification to the customer's application to accept or reject the annulment.

🏁Result of the Action:

  • ✅If the action is approved, either by the correct entry of the card number or by the acceptance of the mobile notification, the message "Annulment Approved" will be displayed on the screen.
  • If the action is rejected or not completed correctly (for example, if an incorrect card number is entered or if the notification is not accepted in the app), the message "Annulment Cancelled" will appear.

♻️Transaction status update:

  • 🔸Once the reversal is approved, the status of the transaction will be updated in the system.
  • 🔸The reversed amount will be reflected in the corresponding account balance, according to Payphone's policies.