D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
Filename :
payment_process.php
back
Copy
<?php $jayParsedAry = [ "merchantId" => 'M22X1YJKF28YF', "merchantTransactionId" => rand(111111, 999999), "merchantUserId" => 'MUID' . time(), "amount" => (1 * 100), "redirectUrl" => 'https://encodersunlimited.com/payform.php', // Post-payment URL "redirectMode" => "POST", "mobileNumber" => "9564136341", "paymentInstrument" => [ "type" => "PAY_PAGE" ] ]; $encode = json_encode($jayParsedAry); $encoded = base64_encode($encode); $key = '861d2daf-44c9-4fc2-861b-7795d01e450f'; // Provided API Key $key_index = 1; // KEY_INDEX $string = $encoded . "/pg/v1/pay" . $key; $sha256 = hash("sha256", $string); $final_x_header = $sha256 . '###' . $key_index; $url = "https://api.phonepe.com/apis/hermes/pg/v1/pay"; // Production URL $headers = [ "Content-Type: application/json", "accept: application/json", "X-VERIFY: " . $final_x_header, ]; $data = json_encode(['request' => $encoded]); $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_HEADER, true); $resp = curl_exec($curl); if (curl_errno($curl)) { echo 'cURL Error: ' . curl_error($curl); exit; } curl_close($curl); $responseParts = explode("\r\n\r\n", $resp, 2); $headers = $responseParts[0]; $body = $responseParts[1]; $response = json_decode($body); echo '<pre>'; print_r($response); // Print entire response for debugging echo '</pre>'; if (isset($response->data->instrumentResponse->redirectInfo->url)) { $redirectUrl = $response->data->instrumentResponse->redirectInfo->url; echo 'Redirect URL: ' . $redirectUrl; header('Location: ' . $redirectUrl); exit; } else { if (isset($response->code)) { echo 'Response Code: ' . $response->code . '<br>'; echo 'Response Message: ' . $response->message . '<br>'; } else { echo 'No response code found'; } }