<?php
// Replace these with your actual PhonePe API credentials
$merchantId = 'PGTESTPAYUAT'; // sandbox or test merchantId
$apiKey="099eb0cd-02cf-4e2a-8aca-3e6c6aff0399"; // sandbox or test APIKEY
$redirectUrl = 'thank-you.php';
// Set transaction details
$name="Tutorials Website";
$email="info@tutorialswebsite.com";
$mobile=9999999999;
$amount = 10; // amount in INR
$description = 'Payment for Product/Service';
'merchantId' => $merchantId,
'merchantTransactionId' => "MT7850590068188104", // test transactionID
"merchantUserId"=>"MUID123",
'amount' => $amount*100,
'redirectUrl'=>$redirectUrl,
'redirectMode'=>"POST",
'callbackUrl'=>$redirectUrl,
"merchantOrderId"=>$order_id,
"mobileNumber"=>$mobile,
"message"=>$description,
"email"=>$email,
"shortName"=>$name,
"paymentInstrument"=> array( "type"=> "PAY_PAGE",
)
);
$salt_index = 1; //key index 1
$payload = $payloadMain . "/pg/v1/pay" . $apiKey;
$sha256 = hash("sha256", $payload); $final_x_header = $sha256 . '###' . $salt_index;
CURLOPT_URL => "https://a...content-available-to-author-only...e.com/apis/pg-sandbox/pg/v1/pay",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $request,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-VERIFY: " . $final_x_header,
"accept: application/json"
],
]);
if ($err) {
echo "cURL Error #:" . $err;
} else {
if(isset($res->success) && $res->success=='1'){ $paymentCode=$res->code;
$paymentMsg=$res->message;
$payUrl=$res->data->instrumentResponse->redirectInfo->url;
}
}
?>
PD9waHAKLy8gUmVwbGFjZSB0aGVzZSB3aXRoIHlvdXIgYWN0dWFsIFBob25lUGUgQVBJIGNyZWRlbnRpYWxzCiAKJG1lcmNoYW50SWQgPSAnUEdURVNUUEFZVUFUJzsgLy8gc2FuZGJveCBvci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