Server to Server (S2S) Integration support ONLY Non-3DS transactions
Prepare Payment Request
Set account credentials
<?php
//Merchant's account information
$merchantID = "JT01"; //Get MerchantID when opening account with 2C2P
$secretKey = "7jYcp4FxFdf0"; //Get SecretKey from 2C2P PGW Dashboard
Set transaction information
//Transaction Information
$desc = "2 days 1 night hotel room";
$uniqueTransactionCode = time();
$currencyCode = "702";
$amt = "000000000010";
$panCountry = "SG";
//Customer Information
$cardholderName = "John Doe";
Set encrypted card data
//Encrypted card data
$encCardData = $_POST['encryptedCardInfo'];
//Retrieve card information for merchant use if needed
$maskedCardNo = $_POST['maskedCardInfo'];
$expMonth = $_POST['expMonthCardInfo'];
$expYear = $_POST['expYearCardInfo'];
Merchant's backend code will receive credit card details encrypted.
"encryptedCardInfo" => "00acTPCs4oy2P52nolDsjc9FabG5/p6OqMzISvh8glP+qb5YgD7z7wCayBp9QW66CtAFENvqW/zZTgDBSKM8qz0W6sFx4TO6Uww58ar//VvDc5+OUz+JIAlQCPhewZN8IznxlyaBFvFLpvi+VugaUWo/Eow6kYalVuIj0MYg8OAccgU=U2FsdGVkX18jR/eUn9PmDT3MSuD3cmgWSovAztlaIPaE52l+fl3SJkU2+UhgJxZL"
Posted information to backend code
| Variable name | Description |
| encryptedCardInfo | Encrypted card data to be sent to 2C2P PGW |
| maskedCardInfo | Masked card number (first 6 and last 4 digit of the credit card) |
|
expMonthCardInfo |
Card expiry month |
| expYearCardInfo | Card expiry year |
Set payment request information
//Request Information
$version = "9.3";
//Construct signature string
$stringToHash = $version.$merchantID.$uniqueTransactionCode.$desc.$amt.$currencyCode.$panCountry.$cardholderName.$encCardData;
$hash = strtoupper(hash_hmac('sha1', $stringToHash ,$secretKey, false)); //Compute hash value
Construct payment request message
//Construct payment request message
$xml = "<PaymentRequest>
<version>$version</version>
<merchantID>$merchantID</merchantID>
<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
<desc>$desc</desc>
<amt>$amt</amt>
<currencyCode>$currencyCode</currencyCode>
<panCountry>$panCountry</panCountry>
<cardholderName>$cardholderName</cardholderName>
<encCardData>$encCardData</encCardData>
<secureHash>$hash</secureHash>
</PaymentRequest>";
$data = base64_encode($xml); //Convert payload to base64
$payload = urlencode($data); //encode with base64
Submit payment request form
include_once('HTTP.php');
include_once('pkcs7.php');
//Send authorization request
$http = new HTTP();
$response = $http->post("https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/Payment.aspx","paymentRequest=".$payload);
Read payment response
//Decrypt response and display
$pkcs7 = new pkcs7();
$response = $pkcs7->decrypt($response,"./keys/demo2.crt","./keys/demo2.pem","2c2p");
echo "Response:<br/><textarea style='width:100%;height:80px'>". $response."</textarea>";
?>
Complete Code
Copy & Paste below code to 'payment_3d.php' file, and put this file in your Web Server.
<?php
//Merchant's account information
$merchantID = "JT01"; //Get MerchantID when opening account with 2C2P
$secretKey = "7jYcp4FxFdf0"; //Get SecretKey from 2C2P PGW Dashboard
//Transaction Information
$desc = "2 days 1 night hotel room";
$uniqueTransactionCode = time();
$currencyCode = "702";
$amt = "000000000010";
$panCountry = "SG";
//Customer Information
$cardholderName = "John Doe";
//Encrypted card data
$encCardData = $_POST['encryptedCardInfo'];
//Retrieve card information for merchant use if needed
$maskedCardNo = $_POST['maskedCardInfo'];
$expMonth = $_POST['expMonthCardInfo'];
$expYear = $_POST['expYearCardInfo'];
//Request Information
$version = "9.3";
//Construct signature string
$stringToHash = $version.$merchantID.$uniqueTransactionCode.$desc.$amt.$currencyCode.$panCountry.$cardholderName.$encCardData;
$hash = strtoupper(hash_hmac('sha1', $stringToHash ,$secretKey, false)); //Compute hash value
//Construct payment request message
$xml = "<PaymentRequest>
<version>$version</version>
<merchantID>$merchantID</merchantID>
<uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
<desc>$desc</desc>
<amt>$amt</amt>
<currencyCode>$currencyCode</currencyCode>
<panCountry>$panCountry</panCountry>
<cardholderName>$cardholderName</cardholderName>
<encCardData>$encCardData</encCardData>
<secureHash>$hash</secureHash>
</PaymentRequest>";
$data = base64_encode($xml); //Convert payload to base64
$payload = urlencode($data); //encode with base64
include_once('HTTP.php');
include_once('pkcs7.php');
//Send authorization request
$http = new HTTP();
$response = $http->post("https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/Payment.aspx","paymentRequest=".$payload);
//Decrypt response and display
$pkcs7 = new pkcs7();
$response = $pkcs7->decrypt($response,"./keys/demo2.crt","./keys/demo2.pem","2c2p");
echo "Response:<br/><textarea style='width:100%;height:80px'>". $response."</textarea>";
?>
Comments
Please sign in to leave a comment.