0% found this document useful (0 votes)
188 views2 pages

Phonepe Project

This document contains PHP code to initiate a payment transaction and check the status of a transaction on the PhonePe payment gateway API. The first code block initiates a payment by making a POST request to the payment endpoint, passing transaction data in the request body and headers. It then redirects the user based on the response. The second code block checks a transaction status by making a GET request to the status endpoint, passing the merchant and transaction IDs in headers. It decodes and dumps the JSON response.

Uploaded by

cedex5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views2 pages

Phonepe Project

This document contains PHP code to initiate a payment transaction and check the status of a transaction on the PhonePe payment gateway API. The first code block initiates a payment by making a POST request to the payment endpoint, passing transaction data in the request body and headers. It then redirects the user based on the response. The second code block checks a transaction status by making a GET request to the status endpoint, passing the merchant and transaction IDs in headers. It decodes and dumps the JSON response.

Uploaded by

cedex5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php

{
$data = array (
'merchantId' => 'MERCHANTUAT',
'merchantTransactionId' => 'MT7850590068188103',
'merchantUserId' => 'MUID123',
'amount' => 10000,
'redirectUrl' => route('response'),
'redirectMode' => 'POST',
'callbackUrl' => route('response'),
'mobileNumber' => '9999999999',
'paymentInstrument' =>
array (
'type' => 'PAY_PAGE',
),
);

$encode = base64_encode(json_encode($data));

$saltKey = '';
$saltIndex = 1;

$string = $encode.'/pg/v1/pay'.$saltKey;
$sha256 = hash('sha256',$string);

$finalXHeader = $sha256.'###'.$saltIndex;

$response = Curl::to('https://api-preprod.phonepe.com/apis/merchant-
simulator/pg/v1/pay')
->withHeader('Content-Type:application/json')
->withHeader('X-VERIFY:'.$finalXHeader)
->withData(json_encode(['request' => $encode]))
->post();

$rData = json_decode($response);

return redirect()->to($rData->data->instrumentResponse->redirectInfo->url);

{
$input = $request->all();

$saltKey = '';
$saltIndex = 1;

$finalXHeader = hash('sha256','/pg/v1/status/'.$input['merchantId'].'/'.
$input['transactionId'].$saltKey).'###'.$saltIndex;

$response = Curl::to('https://api-preprod.phonepe.com/apis/merchant-
simulator/pg/v1/status/'.$input['merchantId'].'/'.$input['transactionId'])
->withHeader('Content-Type:application/json')
->withHeader('accept:application/json')
->withHeader('X-VERIFY:'.$finalXHeader)
->withHeader('X-MERCHANT-ID:'.$input['transactionId'])
->get();
dd(json_decode($response));
}
?>

You might also like