Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.40 KB | None | 0 0
  1. <?php
  2.     //Merchant's account information
  3.     $merchantID = "JT01";       //Get MerchantID when opening account with 2C2P
  4.     $secretKey = "7jYcp4FxFdf0";    //Get SecretKey from 2C2P PGW Dashboard
  5.  
  6.     //Transaction Information
  7.     $desc = "2 days 1 night hotel room";
  8.     $uniqueTransactionCode = "88888888";
  9.     $currencyCode = "702";
  10.     $amt  = "000000000010";
  11.     $panCountry = "SG";
  12.  
  13.     //Customer Information
  14.     $cardholderName = "John Doe";
  15.  
  16.     //Encrypted card data
  17.     $encCardData = $_POST['encryptedCardInfo'];
  18.  
  19.     //Retrieve card information for merchant use if needed
  20.     $maskedCardNo = $_POST['maskedCardInfo'];
  21.     $expMonth = $_POST['expMonthCardInfo'];
  22.     $expYear = $_POST['expYearCardInfo'];
  23.  
  24.     //Advance Payment Options
  25.     $recurring = "Y";               //Enable / Disable RPP option
  26.     $invoicePrefix = 'demo'.time();         //RPP transaction invoice prefix
  27.     $recurringAmount = "000000100000";      //Recurring amount
  28.     $allowAccumulate = "N";             //Allow failed authorization to be accumulated
  29.     $maxAccumulateAmt = "";             //Maximum threshold of total accumulated amount
  30.     // $recurringInterval = "5";            //Recurring interval by no of days
  31.     $recurringCount = "0";              //Number of Recurring occurance
  32.  
  33.  
  34.     $dateTime = new DateTime('today');
  35.     $chargeNextDate = $dateTime->format("dmY"); //The date the first Recurring transaction should occur. format DDMMYYYY
  36.  
  37.     // recuring every first day of next month
  38.     $dateTime->modify('first day of next month');
  39.     $chargeOnDate = $dateTime->format("dm");
  40.  
  41.  
  42.     //Request Information
  43.     $version = "9.9";  
  44.    
  45.     //Construct payment request message
  46.     $xml = "<PaymentRequest>
  47.         <merchantID>$merchantID</merchantID>
  48.         <uniqueTransactionCode>$uniqueTransactionCode</uniqueTransactionCode>
  49.         <desc>$desc</desc>
  50.         <amt>$amt</amt>
  51.         <currencyCode>$currencyCode</currencyCode>  
  52.         <panCountry>$panCountry</panCountry>
  53.         <cardholderName>$cardholderName</cardholderName>
  54.         <recurring>$recurring</recurring>
  55.         <invoicePrefix>$invoicePrefix</invoicePrefix>
  56.         <recurringAmount>$recurringAmount</recurringAmount>
  57.         <allowAccumulate>$allowAccumulate</allowAccumulate>
  58.         <maxAccumulateAmt>$maxAccumulateAmt</maxAccumulateAmt>
  59.         <recurringCount>$recurringCount</recurringCount>
  60.         <chargeNextDate>$chargeNextDate</chargeNextDate>
  61.         <chargeOnDate>$chargeOnDate</chargeOnDate>
  62.         <encCardData>$encCardData</encCardData>
  63.         </PaymentRequest>";
  64.     $paymentPayload = base64_encode($xml); //Convert payload to base64
  65.     $signature = strtoupper(hash_hmac('sha256', $paymentPayload, $secretKey, false));
  66.     $payloadXML = "<PaymentRequest>
  67.           <version>$version</version>
  68.           <payload>$paymentPayload</payload>
  69.           <signature>$signature</signature>
  70.           </PaymentRequest>";
  71.     $payload = base64_encode($payloadXML); //encode with base64
  72.    
  73.     include_once('HTTP.php');
  74.  
  75.     //Send authorization request
  76.     $http = new HTTP();
  77.     $request = $http->post("https://demo2.2c2p.com/2C2PFrontEnd/SecurePayment/Payment.aspx","paymentRequest=".$payload);
  78.     echo "Request:<br/><textarea style='width:100%;height:80px'>". $request."</textarea>";  
  79.    
  80.     //decode response with base64
  81.     $reponsePayLoadXML = base64_decode($request);
  82.    
  83.     //Parse ResponseXML
  84.     $xmlObject =simplexml_load_string($reponsePayLoadXML) or die("Error: Cannot create object");
  85.    
  86.     //decode payload with base64 to get the Reponse
  87.     $payloadxml = base64_decode($xmlObject->payload);
  88.     echo "Response :<br/><textarea style='width:100%;height:80px'>". $payloadxml."</textarea>";
  89.  
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement