Customer Return

After payment processing, the customer will be presented with a result page containing a link to return to the merchant site. This link is a form that will generate an HTTP POST request towards the ctrlRedirectURL address.

This POST request has a field called data that contains the JSON data structure described in the Payment Status Response section.

This data structure is encrypted in AES 128bits with PKCS#5 padding.
The key for the encryption is the merchantToken.

The merchant just has to decrypt the data field with his merchant token to be able to get the status of the payment.


Note:

The merchantToken and the data strings are both encoded in URL safe mode BASE64 and must be decoded before decryption.

Note:

The POST request also has a field customer that contains the customerToken transmitted during the Transaction creation response. This gives the possibility to merchant website that can not maintain a session to retrieve the related transaction.


Code samples

     
    use PayXpert\Connect2Pay\Connect2PayClient;

    session_start();
    // We restore from the session the token info
    $merchantToken = $_SESSION['merchantToken'];

    if ($merchantToken != null) {
        // Extract data received from the payment page
        $data = $_POST["data"];

        if ($data != null) {
        // Setup the client and decrypt the redirect Status
        $c2pClient = new Connect2PayClient($url, $originator, $password);

        if ($c2pClient->handleRedirectStatus($data, $merchantToken)) {
            // Get the PaymentStatus object
            $status = $c2pClient->getStatus();

            $errorCode = $status->getErrorCode();
            $merchantData = $status->getCtrlCustomData();

            // errorCode = 000 => payment is successful
            if ($errorCode == '000') {
            // Display the payment confirmation page
            } else {
            // Display the payment error page
            }
        }
        }
    }

    // If here, display the error page
    // ...
                        
 
    // Instantiate the client and handle the return
    Connect2payClient c2p = new Connect2payClient("https://paiement.payzone.ma", "123456", 
    "GreatP4ssw0rd");
    PaymentStatusResponse response = null;
    try {
        // request must be the body of the received request as a string
        // We restore merchantToken from the session
        response = c2p.handleRedirectStatus(request,merchantToken);
    } catch (Exception e) {
        logger.error("Ooops, an error occurred handling the return: " + e.getMessage());
        // Handle the error...
    }

    if (response != null && ResultCode.SUCCESS.equals(response.getCode()) {
        // Check the payment status: 000 means success
        if ("000".equals(response.getErrorCode()) {
        // Handle the payment success case
        // Redirect user to "thank you page"
        return "Payment OK";
        } else {
        // Handle the payment failure case
        // Redirect user to "payment failed page"
        return "Payment NOK";
        }
    } else {
        // Handle the failure
        out.write(CallbackStatusResponse.getDefaultFailureResponse().toJson()) // out is the output stream
    }
                          
 
    const paymentPage = require("payxpert")("123456", "GreatP4ssw0rd").connect2pay;

    // request must be the body of the received request as a string
    // We restore merchantToken from the session

    let result = paymentPage.handleRedirectStatus(encryptedData, merchantToken);

    if (result.errorCode == "000") {
            // Handle the payment success case
            // Redirect user to "thank you page"
            return "Payment OK";
    } else {
            // Handle the payment failure case
            // Redirect user to "payment failed page"
            return "Payment failed";
    }
    
 
    // request must be the body of the received request as a string
    // We restore merchantToken from the session

    var result = Connect2PayClient.HandleRedirectStatus(request, merchantToken);

    if (result.errorCode == "000") {
            // Handle the payment success case
            // Redirect user to "thank you page"
            return "Payment OK";
    } else {
            // Handle the payment failure case
            // Redirect user to "payment failed page"
            return "Payment failed";
    }
                            
                            

© Payzone | 2022