ok
Direktori : /home2/selectio/www/tnpsctestbatch.com/ |
Current File : /home2/selectio/www/tnpsctestbatch.com/payment-redirect.php |
<?php ob_start(); $amount = $_GET['amount']; $order_id = $_GET['order_id']; $user_id = $_GET['user_id']; /*$amount = 1;*/ $merchantKey = 'e5cfe3f0-f812-4a71-a1d6-266a43a7186a'; // Live - TNPSC /*$merchantKey ='14fa5465-f8a7-443f-8477-f986b8fcfde9'; */ // Testing : 14fa5465-f8a7-443f-8477-f986b8fcfde9 /*$url = $booking_id; $encryptionKey = 'TTC'; $encryptedUrl = openssl_encrypt($url, 'aes-256-cbc', $encryptionKey, 0, $encryptionKey); $code = urlencode($encryptedUrl);*/ $encryptionKey = 'TNPSC'; // Generate a random IV (Initialization Vector) of 16 bytes $iv = openssl_random_pseudo_bytes(16); // URL to encrypt $url = $order_id; // Encrypt the URL $encryptedUrl = openssl_encrypt($url, 'aes-256-cbc', $encryptionKey, 0, $iv); // To pass both the IV and the encrypted URL, you can concatenate them $ivAndEncryptedUrl = $iv . $encryptedUrl; // Encode the combined string for safe URL use $code = urlencode(base64_encode($ivAndEncryptedUrl)); $data = array( "merchantId" => "M22Q7LA2RCPU4", // Live - TNPSC /* "merchantId" => "PGTESTPAYUAT77",*/ // Testing - TNPSC : PGTESTPAYUAT77 "merchantTransactionId" => bin2hex(random_bytes(6)), "merchantUserId" => "MU125", "amount" => $amount*100, "redirectUrl" => "https://tnpsctestbatch.com/order-complete.php?code=$order_id&amount=$amount&user_id=$user_id", "redirectMode" => "POST", "callbackUrl" => "https://tnpsctestbatch.com/order-complete.php?code=$order_id&amount=$amount&user_id=$user_id", "mobileNumber" => "9345854079", "paymentInstrument" => array( "type" => "PAY_PAGE" ) ); $payloadMain = base64_encode(json_encode($data)); $payload = $payloadMain."/pg/v1/pay".$merchantKey; $Checksum = hash('sha256', $payload); $Checksum = $Checksum.'###1'; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api.phonepe.com/apis/hermes/pg/v1/pay", // Live - Tnpsc /* CURLOPT_URL => "https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay",*/ // Testing - TNPSC CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode([ 'request' => $payloadMain ]), CURLOPT_HTTPHEADER => [ "Content-Type: application/json", "X-VERIFY: ".$Checksum, "accept: application/json" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { header('Location: paymentfailed.php?cURLError='.$err); } else { $responseData = json_decode($response, true); $url = $responseData['data']['instrumentResponse']['redirectInfo']['url']; header('Location: '.$url); } ?>