Easy Guide: Integrating PhonePe Payment Gateway on Your Website!
STEP 1:
composer require guzzlehttp/guzzle
STEP 2:
Phone Integration
Phone Pay Integration
With CURL
"merchantKEY",
"merchantTransactionId" => "MT785058104",
"merchantUserId" => "MUID123",
"amount" => $amount*100,
"redirectUrl" => "paymentsuccess.php",
"redirectMode" => "POST",
"callbackUrl" => "paymentsuccess.php",
"mobileNumber" => "9825454588",
"paymentInstrument" => array(
"type" => "PAY_PAGE"
)
);
// Convert the Payload to JSON and encode as Base64
$payloadMain = base64_encode(json_encode($data));
$payload = $payloadMain."/pg/v1/pay".$merchantKey;
$Checksum = hash('sha256', $payload);
$Checksum = $Checksum.'###YOURINDEXKEY';
//X-VERIFY - SHA256(base64 encoded payload + "/pg/v1/pay" + salt key) + ### + salt index
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-preprod.phonepe.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 => 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) {
// echo "cURL Error #:" . $err;
header('Location: paymentfailed.php?cURLError='.$err);
} else {
$responseData = json_decode($response, true);
$url = $responseData['data']['instrumentResponse']['redirectInfo']['url'];
header('Location: '.$url);
}
}
Payment Request Response Wityh Payment Gateway URL
Array ( [success] => 1 [code] => PAYMENT_INITIATED [message] => Payment initiated [data] => Array ( [merchantId] => MERCHANTUAT [merchantTransactionId] => MT785058104 [instrumentResponse] => Array ( [type] => PAY_PAGE [redirectInfo] => Array ( [url] => https://mercury-uat.phonepe.com/transact/simulator?token=BwDguDaJUIWnnpQ00uXbTv3mhxshgKVGO04bGjLHqbd [method] => GET ) ) ) )
Official Website = https://developer.phonepe.com/v1/reference/pay-api
If you want any help from my side please Email me on [email protected] OR WhatsApp Me On 6267465901
STEP 3:
// Check Payment Status
Document
";
echo "
";
print_r($_POST);
?>
Payment Status Response
PAYMENT_SUCCESS – MT785058104T2307280105189211924350 –
Array ( [code] => PAYMENT_SUCCESS [merchantId] => MERCHANTUAT [transactionId] => MT785058104 [amount] => 85700 [providerReferenceId] => T2307280105189211924350 [param1] => na [param2] => na [param3] => na [param4] => na [param5] => na [param6] => na [param7] => na [param8] => na [param9] => na [param10] => na [param11] => na [param12] => na [param13] => na [param14] => na [param15] => na [param16] => na [param17] => na [param18] => na [param19] => na [param20] => na [checksum] => 2ec420101ce340d500564d384adb5625accf5354bedcfa4588a9a4d915c2dbd0###1 )
Index2.php
By Using Package
"merchantID KEY",
"merchantTransactionId" => "MT785058104",
"merchantUserId" => "MUID123",
"amount" => $amount*100,
"redirectUrl" => "paymentsuccess.php",
"redirectMode" => "POST",
"callbackUrl" => "paymentsuccess.php",
"mobileNumber" => "9825454588",
"paymentInstrument" => array(
"type" => "PAY_PAGE"
)
);
// Convert the Payload to JSON and encode as Base64
$payloadMain = base64_encode(json_encode($data));
$payload = $payloadMain."/pg/v1/pay".$merchantKey;
$Checksum = hash('sha256', $payload);
$Checksum = $Checksum.'###1';
$response = $client->request('POST', 'https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay', [
'body' => '{"request":'.".$payloadMain.".'}',
'headers' => [
'Content-Type' => 'application/json',
'X-VERIFY' => "$Checksum",
'accept' => 'application/json',
],
]);
echo $response->getBody();
}
#HitPayIntegration #PaymentGatewayTutorial #SecureOnlinePayments
#PhonePeIntegration #PaymentGatewayTutorial #DigitalPaymentsIndia
“MARCHANTUAT”,
“merchantTransactionId” => “MT7850581089”,
“merchantUserId” => “MUID123”,
“amount” => $amount*100,
“redirectUrl” => “paymentsuccess.php”,
“redirectMode” => “POST”,
“callbackUrl” => “paymentsuccess.php”,
“mobileNumber” => “9825454588”,
“paymentInstrument” => array(
“type” => “PAY_PAGE”
)
);
// Convert the Payload to JSON and encode as Base64
$payloadMain = base64_encode(json_encode($data));
$payload = $payloadMain.”/pg/v1/pay”.$merchantKey;
$Checksum = hash(‘sha256′, $payload);
$Checksum = $Checksum.’###1’;
//X-VERIFY – SHA256(base64 encoded payload + “/pg/v1/pay” + salt key) + ### + salt index
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => “https://api-preprod.phonepe.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 => 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) {
// echo “cURL Error #:” . $err;
header(‘Location: paymentfailed.php?cURLError=’.$err);
} else {
echo $response;
echo $responseData = json_decode($response, true);
$url = $responseData[‘data’][‘instrumentResponse’][‘redirectInfo’][‘url’];
header(‘Location: ‘.$url);
}
}
?>
Phone Integration
Phone Pay Integration
Enter Amount
Pay Now
output: {
“success”: false,
“code”: “KEY_NOT_CONFIGURED”,
“message”: “Key not found for the merchant”,
“data”: {
}
}
Please Provide Your Merchant Key or email me
Warning: Undefined array key “data” in D:\xampp\htdocs\phonepe\index.php on line 82
Warning: Trying to access array offset on value of type null in D:\xampp\htdocs\phonepe\index.php on line 82
Warning: Trying to access array offset on value of type null in D:\xampp\htdocs\phonepe\index.php on line 82
Warning: Trying to access array offset on value of type null in D:\xampp\htdocs\phonepe\index.php on line 82
please share shorce code for phonepe geteway integration with C#
Same Error
Hello , I am recieving empty response or no response on check_payment_status page after successful transaction. Can you tell what it could be
Warning: Undefined array key “data” in D:\xampp\htdocs\phonepe\index.php on line 82
Warning: Trying to access array offset on value of type null in D:\xampp\htdocs\phonepe\index.php on line 82
Warning: Trying to access array offset on value of type null in D:\xampp\htdocs\phonepe\index.php on line 82
Warning: Trying to access array offset on value of type null in D:\xampp\htdocs\phonepe\index.php on line 82
Amit, Thank you very much for your blog and video.
I tried PhonePe integration but RESPONSE on success page is not getting any data.
Can you tell me what may be the reason?
How to pass custom parameters in REQUEST which we can get in RESPONSE?
I see there are param1, param2……….param20 in response but how to populate them?
{“success”:false,”code”:”KEY_NOT_CONFIGURED”,”message”:”Key not found for the merchant”,”data”:{}} i’
m getting this