@php function encryptData($plainData, $publicPEMKey) { $plainData=utf8_encode($plainData); $partialEncrypted = ''; $encryptionOk = openssl_public_encrypt($plainData, $partialEncrypted, $publicPEMKey,OPENSSL_PKCS1_PADDING); return base64_encode($partialEncrypted);//encoding the whole binary String as MIME base 64 } // $enc_key = file_get_contents("https://gateway.ecompk.com/lattliv.txt"); $enc_key = $key_values['public_key']; $enc_key = str_replace("-----BEGIN PUBLIC KEY-----",nl2br("-----BEGIN PUBLIC KEY-----"),$enc_key); $enc_key = str_replace("-----END PUBLIC KEY-----","-----END PUBLIC KEY-----",$enc_key); $enc_key = str_replace(".
", "", $enc_key); $orderItems = []; foreach($order['order']['line_items'] as $item){ $itemArray = [ 'ITEM_NAME' => encryptData($item['name'],$enc_key), 'QUANTITY' => encryptData($item['quantity'],$enc_key), 'UNIT_PRICE' => encryptData($item['price'],$enc_key), 'CATEGORY' => encryptData('NA',$enc_key), 'SUB_CATEGORY' => encryptData('NA',$enc_key) ]; array_push($orderItems, $itemArray); } $requestArrayTest = array ( 'USER_ID' => $key_values['merchant_id'], 'PASSWORD' => encryptData($key_values['merchant_password'],$enc_key), 'RETURN_URL' => encryptData($key_values['return_url'],$enc_key), 'CANCEL_URL' => encryptData($key_values['cancel_url'],$enc_key), 'CHANNEL' => encryptData($key_values['merchant_channel'],$enc_key), 'TRAN_TYPE' => encryptData('2',$enc_key), 'TYPE_ID' => encryptData('0',$enc_key), 'SHIPPING_DETAIL' => array ( 'NAME' => encryptData('Standard',$enc_key), 'DELIEVERY_DAYS' => encryptData('1',$enc_key),//modify if shipping days applicable 'SHIPPING_COST' => encryptData('0',$enc_key) ), 'ORDER' => array ( 'DISCOUNT_ON_TOTAL' => encryptData($order['order']['total_discounts'],$enc_key), 'SUBTOTAL' => encryptData($order['order']['total_price'],$enc_key), 'OrderSummaryDescription' => $orderItems ), 'ADDITIONAL_DATA' => array ( 'BILL_TO_FORENAME' => encryptData($order['order']['billing_address']['first_name'],$enc_key), 'BILL_TO_SURNAME' => encryptData($order['order']['billing_address']['last_name'],$enc_key), 'BILL_TO_EMAIL' => encryptData($order['order']['customer']['email'],$enc_key), 'BILL_TO_PHONE' => encryptData($order['order']['shipping_address']['phone'],$enc_key), 'BILL_TO_ADDRESS_LINE' => encryptData($order['order']['billing_address']['address1'],$enc_key), 'BILL_TO_ADDRESS_CITY' => encryptData($order['order']['billing_address']['city'],$enc_key), 'BILL_TO_ADDRESS_STATE' => encryptData('Sindh',$enc_key), 'BILL_TO_ADDRESS_COUNTRY' => encryptData($order['order']['billing_address']['country_code'],$enc_key), 'BILL_TO_ADDRESS_POSTAL_CODE' => encryptData($order['order']['billing_address']['zip'],$enc_key), 'SHIP_TO_FORENAME' => encryptData($order['order']['shipping_address']['first_name'],$enc_key), 'SHIP_TO_SURNAME' => encryptData($order['order']['shipping_address']['last_name'],$enc_key), 'SHIP_TO_PHONE' => encryptData($order['order']['shipping_address']['phone'],$enc_key), 'SHIP_TO_ADDRESS_LINE' => encryptData($order['order']['shipping_address']['address1'],$enc_key), 'SHIP_TO_ADDRESS_CITY' => encryptData($order['order']['shipping_address']['city'],$enc_key), 'SHIP_TO_ADDRESS_STATE' => encryptData('Sindh',$enc_key), 'SHIP_TO_ADDRESS_COUNTRY' => encryptData($order['order']['shipping_address']['country_code'],$enc_key), 'SHIP_TO_ADDRESS_POSTAL_CODE' => encryptData($order['order']['shipping_address']['zip'],$enc_key), 'CURRENCY' => encryptData('PKR',$enc_key), 'REFERENCE_NUMBER' => encryptData($order['order']['id'],$enc_key), 'CUSTOMER_ID' => encryptData($order['order']['customer']['first_name'],$enc_key), 'MerchantFields' => array ( 'MDD1' => encryptData('WC',$enc_key), 'MDD2' => encryptData('YES',$enc_key), 'MDD5' => encryptData($order['order']['customer']['first_name'],$enc_key), 'MDD6' => encryptData('Standard',$enc_key), 'MDD8' => encryptData($order['order']['billing_address']['country_code'],$enc_key), 'MDD20' => encryptData('NO',$enc_key), 'MDD3' => encryptData("cat 1, cat 2, cat 3", $enc_key), 'MDD4' => encryptData("item 1, item 2, item 3", $enc_key), 'MDD7' => encryptData(1, $enc_key) ), ), ); $requestJson = json_encode($requestArrayTest); function callAPInew($method, $url, $data, $islive, $useproxy, $proxy) { $curl = curl_init(); switch ($method){ case "POST": curl_setopt($curl, CURLOPT_POST, 1); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; case "PUT": curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; default: if ($data) $url = sprintf("%s?%s", $url, http_build_query($data)); } // OPTIONS: curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); if($islive == 1) { curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); } // PROXY if($useproxy == 1) { //$proxy = $proxy;//'http://proxy3.domestic.hbl.com:8080'; curl_setopt($curl, CURLOPT_PROXY, $proxy); } // EXECUTE: $result = curl_exec($curl); if(!$result){die("Connection Failure");} curl_close($curl); return $result; } $make_call = callAPInew('POST', $key_values['action_url'], $requestJson, 0, 0, 'http://proxy3.domestic.hbl.com:8080'); $outputArray = json_decode($make_call, true); if($outputArray['IsSuccess'] == true && $outputArray['ResponseCode'] == 0) { $sessionId = $outputArray['Data']['SESSION_ID']; header('location: '.$key_values['data_url'].base64_encode($sessionId)); exit; } @endphp