Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.48 KB | None | 0 0
  1. <?php
  2.  
  3. $merchantId = "1ed7f693-fb13-4f0a-b31b-a3e01ed8c79e";
  4. $merchantAccountId = "d177df6e-8fe8-4a99-ac51-7aeb1459b17d";
  5. $merchantAccountUserName = "CRIP.TO26216261bb0c";
  6. $merchantAccountPassword = "5feccc29b0974d6e99bf1ede7d424c8d";
  7. $key = "9181d29aafe6761b";
  8.  
  9. $encryptedAccountUsername = encryptDataInBase64($merchantAccountUserName,$key);
  10. $encryptedAccountPassword = encryptDataInBase64($merchantAccountPassword,$key);
  11. $merchantIdHash = hashDataInBase64($merchantId);
  12. $merchantAccountIdHash = hashDataInBase64($merchantAccountId);
  13.  
  14. $requestTime = date('Y-m-d H:i:s');
  15. $signature = null;
  16. $lang = "en";
  17.  
  18. $transactionInfo = [
  19.     'apiVersion' => '1.0.0',
  20.     'requestId'=> 'DEMOREQ'.rand(),
  21.     'txSource'=> '1',
  22.     'recurrentType'=> '1',
  23.     'perform3DS'=> '0',
  24.     'orderData'=> [
  25.         'orderId'=> 'DEMOREQORDERID'.rand(),
  26.         'orderDescription'=> 'test order',
  27.         'amount'=> '10',
  28.         'currencyCode'=> 'USD',
  29.         'billingAddress'=> [
  30.             "firstName"=>"kunal",
  31.             "lastName"=>"kunal",
  32.             "address1"=>"hadapsar",
  33.             "address2"=>"hadapsar",
  34.             "city"=>"Pune",
  35.             "zipcode"=>"12345",
  36.             "stateCode"=>"MH",
  37.             "countryCode"=>"IN",
  38.             "mobile"=>"1234567890",
  39.             "phone"=>"12345678",
  40.             "email"=>"test@gmail.com",
  41.             "fax"=>"+49 9131 23 28732"
  42.         ],
  43.         "shippingAddress"=> null,
  44.         "personalAddress"=> null,
  45.     ],
  46.     "statementText"=>"Demo website payment",
  47.     "cancelUrl"=>"https://pluscapitals.com/",
  48.     "returnUrl"=>"https://pluscapitals.com/",
  49.     "notificationUrl"=>"https://pluscapitals.com/",
  50. ];
  51.  
  52. $signature = createSignature(generateSignature(), $key);
  53.  
  54. // echo $encryptedAccountUsername."<br>";
  55. // echo $encryptedAccountPassword."<br>";
  56. // echo $merchantIdHash."<br>";
  57. // echo $merchantAccountIdHash."<br>";
  58.  
  59. $array = [
  60.     'requestTime'=> $requestTime,
  61.     'merchantIdHash'=> $merchantIdHash,
  62.     'merchantAccountIdHash'=> $merchantAccountIdHash,
  63.     'encryptedAccountUsername'=> $encryptedAccountUsername,
  64.     'encryptedAccountPassword'=> $encryptedAccountPassword,
  65.     'signature'=> $signature,
  66.     'lang'=> $lang,
  67.     'transactionInfo'=> $transactionInfo
  68. ];
  69.  
  70. $json = json_encode($array);
  71. $base64Json = base64_encode($json);
  72.  
  73. //FROM DOCUMENTATION - Encryption - (AES-128-ECB-PKCS5Padding)
  74. //FOR encryptedAccountUsername and encryptedAccountPassword
  75. function encryptDataInBase64($input, $key){
  76.     $alg = MCRYPT_RIJNDAEL_128;
  77.     $mode = MCRYPT_MODE_ECB;
  78.     $block_size = mcrypt_get_block_size($alg, $mode);
  79.     $pad = $block_size - (strlen($input) % $block_size);
  80.     $input .= str_repeat(chr($pad), $pad); 
  81.     $crypttext = mcrypt_encrypt($alg, $key, $input , $mode);
  82.     $encryptDataInBase64 = base64_encode($crypttext);
  83.     return $encryptDataInBase64;
  84. }
  85.  
  86. //FROM DOCUMENTATION - SHA256 IN BASE64
  87. //FOR merchantIdHash and merchantAccountIdHash
  88. function hashDataInBase64($input){
  89.     $output = hash('sha256',$input,true);
  90.     $hashDataInBase64 = base64_encode($output);
  91.     return $hashDataInBase64;
  92. }
  93.  
  94. //FROM DOCUMENTATION - GENERATE SIGNATURE
  95. function createSignature($input,$key){
  96.         $alg = MCRYPT_RIJNDAEL_128;
  97.         $mode = MCRYPT_MODE_ECB;
  98.         $block_size = mcrypt_get_block_size($alg, $mode);
  99.         $pad = $block_size - (strlen($input) % $block_size);
  100.         $input .= str_repeat(chr($pad), $pad); 
  101.         $crypttext = mcrypt_encrypt($alg,$key, $input , $mode);    
  102.         $output = hash('sha256',$crypttext,true);
  103.         $signature = base64_encode($output);
  104.         return $signature ;
  105. }
  106.  
  107.  
  108. function generateSignature(){
  109.     global $requestTime,$merchantIdHash,$merchantAccountIdHash,$encryptedAccountUsername,$encryptedAccountPassword,$transactionInfo;
  110.     $str = "";
  111.     $str.=$requestTime.
  112.     $str.=$merchantIdHash;
  113.     $str.=$merchantAccountIdHash;
  114.     $str.=$encryptedAccountUsername;
  115.     $str.=$encryptedAccountPassword;
  116.     $str.=$transactionInfo['apiVersion'];
  117.     $str.=$transactionInfo['requestId'];
  118.     $str.=$transactionInfo['txSource'];
  119.     $str.=$transactionInfo['recurrentType'];
  120.     $str.=$transactionInfo['orderData']['orderId'];
  121.     $str.=$transactionInfo['orderData']['orderDescription'];
  122.     $str.=$transactionInfo['orderData']['amount'];
  123.     $str.=$transactionInfo['orderData']['currencyCode'];
  124.     $str.=$transactionInfo['orderData']['billingAddress']['firstName'];
  125.     $str.=$transactionInfo['orderData']['billingAddress']['lastName'];
  126.     $str.=$transactionInfo['orderData']['billingAddress']['address1'];
  127.     $str.=$transactionInfo['orderData']['billingAddress']['address2'];
  128.     $str.=$transactionInfo['orderData']['billingAddress']['city'];
  129.     $str.=$transactionInfo['orderData']['billingAddress']['zipcode'];
  130.     $str.=$transactionInfo['orderData']['billingAddress']['stateCode'];
  131.     $str.=$transactionInfo['orderData']['billingAddress']['countryCode'];
  132.     $str.=$transactionInfo['orderData']['billingAddress']['mobile'];
  133.     $str.=$transactionInfo['orderData']['billingAddress']['phone'];
  134.     $str.=$transactionInfo['orderData']['billingAddress']['email'];
  135.     $str.=$transactionInfo['orderData']['billingAddress']['fax'];
  136.     $str.=$transactionInfo['statementText'];
  137.     $str.=$transactionInfo['cancelUrl'];
  138.     $str.=$transactionInfo['returnUrl'];
  139.     $str.=$transactionInfo['notificationUrl'];
  140.     return $str;
  141. }
  142.  
  143. ?>
  144.  
  145. <html>
  146. <head>
  147. <body OnLoad="AutoSubmitForm();">
  148. <form name="payForm" id="payForm" action="https://securemasterpay.com/FE/rest/tx/purchase/w/execute" method="POST">
  149. <input type="hidden" name="request" value="<?php echo $base64Json ?>">
  150. <script>
  151. function AutoSubmitForm() {    
  152.     console.log("submit form");
  153.     document.payForm.submit();
  154. }
  155. </script>
  156. <h3>Transaction is in progress. Please wait...</h3>
  157. </body>
  158. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement