D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
Filename :
payment.php
back
Copy
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Extract form data $firstName = $_POST['first_name']; $lastName = $_POST['last_name']; $email = $_POST['email']; $phoneNumber = $_POST['phone_number']; $amount = $_POST['Amount']; $choiceCompany = $_POST['choice_company']; $services = $_POST['services']; $message = $_POST['message']; $privacyPolicyAccept = isset($_POST['privacy_policy_accept']) ? $_POST['privacy_policy_accept'] : ''; // Validate the privacy policy checkbox if ($privacyPolicyAccept != '1') { die('You must agree to the terms and conditions.'); } // Payment initiation $jayParsedAry = [ "merchantId" => 'M22X1YJKF28YF', "merchantTransactionId" => rand(111111, 999999), "merchantUserId" => 'MUID' . time(), "amount" => ($amount * 100), "redirectUrl" => 'https://encodersunlimited.com/payform.php', "redirectMode" => "POST", "mobileNumber" => $phoneNumber, "paymentInstrument" => [ "type" => "PAY_PAGE" ] ]; $encode = json_encode($jayParsedAry); $encoded = base64_encode($encode); $key = '861d2daf-44c9-4fc2-861b-7795d01e450f'; $key_index = 1; $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)) { die('cURL Error: ' . curl_error($curl)); } curl_close($curl); $responseParts = explode("\r\n\r\n", $resp, 2); $headers = $responseParts[0]; $body = $responseParts[1]; $response = json_decode($body); if (isset($response->data->instrumentResponse->redirectInfo->url)) { $redirectUrl = $response->data->instrumentResponse->redirectInfo->url; header('Location: ' . $redirectUrl); exit; } else { echo 'Error: Invalid response structure or API response'; } } else { echo 'Invalid request method.'; }