Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $merchantId = "1ed7f693-fb13-4f0a-b31b-a3e01ed8c79e";
- $merchantAccountId = "d177df6e-8fe8-4a99-ac51-7aeb1459b17d";
- $merchantAccountUserName = "CRIP.TO26216261bb0c";
- $merchantAccountPassword = "5feccc29b0974d6e99bf1ede7d424c8d";
- $key = "9181d29aafe6761b";
- $encryptedAccountUsername = encryptDataInBase64($merchantAccountUserName,$key);
- $encryptedAccountPassword = encryptDataInBase64($merchantAccountPassword,$key);
- $merchantIdHash = hashDataInBase64($merchantId);
- $merchantAccountIdHash = hashDataInBase64($merchantAccountId);
- $requestTime = date('Y-m-d H:i:s');
- $signature = null;
- $lang = "en";
- $transactionInfo = [
- 'apiVersion' => '1.0.0',
- 'requestId'=> 'DEMOREQ'.rand(),
- 'txSource'=> '1',
- 'recurrentType'=> '1',
- 'perform3DS'=> '0',
- 'orderData'=> [
- 'orderId'=> 'DEMOREQORDERID'.rand(),
- 'orderDescription'=> 'test order',
- 'amount'=> '10',
- 'currencyCode'=> 'USD',
- 'billingAddress'=> [
- "firstName"=>"kunal",
- "lastName"=>"kunal",
- "address1"=>"hadapsar",
- "address2"=>"hadapsar",
- "city"=>"Pune",
- "zipcode"=>"12345",
- "stateCode"=>"MH",
- "countryCode"=>"IN",
- "mobile"=>"1234567890",
- "phone"=>"12345678",
- "email"=>"test@gmail.com",
- "fax"=>"+49 9131 23 28732"
- ],
- "shippingAddress"=> null,
- "personalAddress"=> null,
- ],
- "statementText"=>"Demo website payment",
- "cancelUrl"=>"https://pluscapitals.com/",
- "returnUrl"=>"https://pluscapitals.com/",
- "notificationUrl"=>"https://pluscapitals.com/",
- ];
- $signature = createSignature(generateSignature(), $key);
- // echo $encryptedAccountUsername."<br>";
- // echo $encryptedAccountPassword."<br>";
- // echo $merchantIdHash."<br>";
- // echo $merchantAccountIdHash."<br>";
- $array = [
- 'requestTime'=> $requestTime,
- 'merchantIdHash'=> $merchantIdHash,
- 'merchantAccountIdHash'=> $merchantAccountIdHash,
- 'encryptedAccountUsername'=> $encryptedAccountUsername,
- 'encryptedAccountPassword'=> $encryptedAccountPassword,
- 'signature'=> $signature,
- 'lang'=> $lang,
- 'transactionInfo'=> $transactionInfo
- ];
- $json = json_encode($array);
- $base64Json = base64_encode($json);
- //FROM DOCUMENTATION - Encryption - (AES-128-ECB-PKCS5Padding)
- //FOR encryptedAccountUsername and encryptedAccountPassword
- function encryptDataInBase64($input, $key){
- $alg = MCRYPT_RIJNDAEL_128;
- $mode = MCRYPT_MODE_ECB;
- $block_size = mcrypt_get_block_size($alg, $mode);
- $pad = $block_size - (strlen($input) % $block_size);
- $input .= str_repeat(chr($pad), $pad);
- $crypttext = mcrypt_encrypt($alg, $key, $input , $mode);
- $encryptDataInBase64 = base64_encode($crypttext);
- return $encryptDataInBase64;
- }
- //FROM DOCUMENTATION - SHA256 IN BASE64
- //FOR merchantIdHash and merchantAccountIdHash
- function hashDataInBase64($input){
- $output = hash('sha256',$input,true);
- $hashDataInBase64 = base64_encode($output);
- return $hashDataInBase64;
- }
- //FROM DOCUMENTATION - GENERATE SIGNATURE
- function createSignature($input,$key){
- $alg = MCRYPT_RIJNDAEL_128;
- $mode = MCRYPT_MODE_ECB;
- $block_size = mcrypt_get_block_size($alg, $mode);
- $pad = $block_size - (strlen($input) % $block_size);
- $input .= str_repeat(chr($pad), $pad);
- $crypttext = mcrypt_encrypt($alg,$key, $input , $mode);
- $output = hash('sha256',$crypttext,true);
- $signature = base64_encode($output);
- return $signature ;
- }
- function generateSignature(){
- global $requestTime,$merchantIdHash,$merchantAccountIdHash,$encryptedAccountUsername,$encryptedAccountPassword,$transactionInfo;
- $str = "";
- $str.=$requestTime.
- $str.=$merchantIdHash;
- $str.=$merchantAccountIdHash;
- $str.=$encryptedAccountUsername;
- $str.=$encryptedAccountPassword;
- $str.=$transactionInfo['apiVersion'];
- $str.=$transactionInfo['requestId'];
- $str.=$transactionInfo['txSource'];
- $str.=$transactionInfo['recurrentType'];
- $str.=$transactionInfo['orderData']['orderId'];
- $str.=$transactionInfo['orderData']['orderDescription'];
- $str.=$transactionInfo['orderData']['amount'];
- $str.=$transactionInfo['orderData']['currencyCode'];
- $str.=$transactionInfo['orderData']['billingAddress']['firstName'];
- $str.=$transactionInfo['orderData']['billingAddress']['lastName'];
- $str.=$transactionInfo['orderData']['billingAddress']['address1'];
- $str.=$transactionInfo['orderData']['billingAddress']['address2'];
- $str.=$transactionInfo['orderData']['billingAddress']['city'];
- $str.=$transactionInfo['orderData']['billingAddress']['zipcode'];
- $str.=$transactionInfo['orderData']['billingAddress']['stateCode'];
- $str.=$transactionInfo['orderData']['billingAddress']['countryCode'];
- $str.=$transactionInfo['orderData']['billingAddress']['mobile'];
- $str.=$transactionInfo['orderData']['billingAddress']['phone'];
- $str.=$transactionInfo['orderData']['billingAddress']['email'];
- $str.=$transactionInfo['orderData']['billingAddress']['fax'];
- $str.=$transactionInfo['statementText'];
- $str.=$transactionInfo['cancelUrl'];
- $str.=$transactionInfo['returnUrl'];
- $str.=$transactionInfo['notificationUrl'];
- return $str;
- }
- ?>
- <html>
- <head>
- <body OnLoad="AutoSubmitForm();">
- <form name="payForm" id="payForm" action="https://securemasterpay.com/FE/rest/tx/purchase/w/execute" method="POST">
- <input type="hidden" name="request" value="<?php echo $base64Json ?>">
- <script>
- function AutoSubmitForm() {
- console.log("submit form");
- document.payForm.submit();
- }
- </script>
- <h3>Transaction is in progress. Please wait...</h3>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement