Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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 = "88888888";
- $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'];
- //Advance Payment Options
- $recurring = "Y"; //Enable / Disable RPP option
- $invoicePrefix = 'demo'.time(); //RPP transaction invoice prefix
- $recurringAmount = "000000100000"; //Recurring amount
- $allowAccumulate = "N"; //Allow failed authorization to be accumulated
- $maxAccumulateAmt = ""; //Maximum threshold of total accumulated amount
- // $recurringInterval = "5"; //Recurring interval by no of days
- $recurringCount = "0"; //Number of Recurring occurance
- $dateTime = new DateTime('today');
- $chargeNextDate = $dateTime->format("dmY"); //The date the first Recurring transaction should occur. format DDMMYYYY
- // recuring every first day of next month
- $dateTime->modify('first day of next month');
- $chargeOnDate = $dateTime->format("dm");
- //Request Information
- $version = "9.9";
- //Construct payment request message
- $xml = "<PaymentRequest>
- <merchantID>$merchantID</merchantID>
- <uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
- <desc>$desc</desc>
- <amt>$amt</amt>
- <currencyCode>$currencyCode</currencyCode>
- <panCountry>$panCountry</panCountry>
- <cardholderName>$cardholderName</cardholderName>
- <recurring>$recurring</recurring>
- <invoicePrefix>$invoicePrefix</invoicePrefix>
- <recurringAmount>$recurringAmount</recurringAmount>
- <allowAccumulate>$allowAccumulate</allowAccumulate>
- <maxAccumulateAmt>$maxAccumulateAmt</maxAccumulateAmt>
- <recurringCount>$recurringCount</recurringCount>
- <chargeNextDate>$chargeNextDate</chargeNextDate>
- <chargeOnDate>$chargeOnDate</chargeOnDate>
- <encCardData>$encCardData</encCardData>
- </PaymentRequest>";
- $paymentPayload = base64_encode($xml); //Convert payload to base64
- $signature = strtoupper(hash_hmac('sha256', $paymentPayload, $secretKey, false));
- $payloadXML = "<PaymentRequest>
- <version>$version</version>
- <payload>$paymentPayload</payload>
- <signature>$signature</signature>
- </PaymentRequest>";
- $payload = base64_encode($payloadXML); //encode with base64
- include_once('HTTP.php');
- //Send authorization request
- $http = new HTTP();
- $request = $http->post("https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/Payment.aspx","paymentRequest=".$payload);
- echo "Request:<br/><textarea style='width:100%;height:80px'>". $request."</textarea>";
- //decode response with base64
- $reponsePayLoadXML = base64_decode($request);
- //Parse ResponseXML
- $xmlObject =simplexml_load_string($reponsePayLoadXML) or die("Error: Cannot create object");
- //decode payload with base64 to get the Reponse
- $payloadxml = base64_decode($xmlObject->payload);
- echo "Response :<br/><textarea style='width:100%;height:80px'>". $payloadxml."</textarea>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement