Received Response on Backend
To receive response on backend, you need to setup in 2c2p merchant admin panel.
Login to the merchant admin. Go to Account > Options > Payment Result URL. Add the URL at Server-to-server 3DS API - Backend return URL.
The payment processing system will send back encrypted Payment Response XML message to the predefined merchant's return URL using HTTP Form Post
method. The form tag name of the encrypted payment response will be paymentResponse
.
The following is the example code snippet in C# on how to receive payment response from 2C2P system.
string encryptedPaymentResponse = "";
encryptedPaymentResponse = Request.Form["paymentResponse"];
The following is the example code snippet in PHP on how to receive payment response from 2C2P system.
$encryptedPaymentResponse = "";
$encryptedPaymentResponse = _REQUEST["paymentResponse"];
Decrypting
Decrypt the payment response using merchant's private key and interpret the result. The following example use 2C2P .Net framework dll to decrypt the payment response.
In C#
SinaptIQPKCS7.PKCS7 pkcs7 = new SinaptIQPKCS7.PKCS7();
string encryptedPaymentResponse =
"MIIE2wYJKoZIhvcNAQcDoIIEzDCCBMgCAQAxggFAMIIBPAIBADAkMBYxFDASBgNVBAMTC1NpbmFwdEl
RIENBAgoeg+bBAAAAAAAMMA0GCSqGSIb3DQEBAQUABIIBAGfvpnQI07oTmL+Mmfdpf6ms+h+2w4+rs0k
q/8/U049Poy5aUl9mwwVKgx1OksFgsYj7+R7CrXR6MvK/P49eFl+wFVtHRS0VxfAQLo3ja+GpqRdMd2o
akkPVJ/AK1VWooli07pzDxdixjN5DDBuRH+mBrV+G1js8eymgpIx1PmNPL9zyGZmiXvurT3xg91amWJQ
/+bfJ2pmBBlMqs+cav5oTJ7v1eoQPzFK+8CvA+dSyZK7hSkGT1gciPVwhCQW7xAIfB/6tR0p2/hgZXlY
nZOn+PbNMozD1/pqPNQjnfW4WG9SsLPiplycLhF7fpJ3dch+RHhBPGkcw19Ow0SeS3TEwggN9Bgkqhki
G9w0BBwEwFAYIKoZIhvcNAwcECPkjkibE353SgIIDWGz3MSEQo0dBJd542O/O3R4Ro7MsK/DhKJyvHG8
aX1AJOYHcMe7XcFCH19jFZFiT0lPM11iHS+XJpz91lSZ8ZAhoaoKt0EbQh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7.decryptMessage(encryptedPaymentResponse, pkcs7.getPrivateCert("D:/2C2P/Application/2C2P-RandD/demo2.2c2p.com(2c2p).pfx", "2c2p"));
In PHP
<?php
//to use this library create a folder for temporary file in the same location as pkcs7.php with named 'tmp'.
include('pkcs7.php');
//public and private keys
$publicKey = "demo2_2c2p.crt";
$privateKey = "demo2_2c2p.pem";
$privateKeyPass = "2c2p";
$encrypt_text = "encrypted message"; //message returned by 2c2p PGW
$decrypted = $pkcs7->decrypt($encrypt_text,$publicKey,$privateKey,$privateKeyPass); //to decrypt
echo $decrypted;
?>
Decrypted XML will be like following example XML :
<PaymentResponse>
<version></version>
<timeStamp></timeStamp>
<merchantID></merchantID>
<respCode></respCode>
<pan></pan>
<amt></amt>
<uniqueTransactionCode></uniqueTransactionCode>
<tranRef></tranRef>
<approvalCode></approvalCode>
<refNumber></refNumber>
<eci></eci>
<dateTime></dateTime>
<status></status>
<failReason></failReason>
<userDefined1></userDefined1>
<userDefined2></userDefined2>
<userDefined3></userDefined3>
<userDefined4></userDefined4>
<userDefined5></userDefined5>
<storeCardUniqueID></storeCardUniqueID>
<recurringUniqueID></recurringUniqueID>
<paymentChannel></paymentChannel>
<backendInvoice></backendInvoice>
<paidChannel></paidChannel>
<paidAgent></paidAgent>
<IssuerCountry></IssuerCountry>
<BankName></BankName>
<hashValue></hashValue>
</PaymentResponse>
You can check detail response at Backend Response in reference.