How to Integrate PhonePe Payment Gateway in PHP Website Using PhonePe PHP SDK

How to Integrate PhonePe Payment Gateway in PHP Website

PhonePe payment gateway Integration in php website now too easy with using composer that help to less code and better integration with handle Exception in website easily.

For PhonePe Integration first you need to Register with PhonePe Merchant and get access for MerchantId, SaltKey, SaltIndex which help to Integrate PhonePe on website. https://www.phonepe.com/business-solutions/payment-gateway/register/

PhonePe Credentials

When you register with PhonePe for Website you get MerchantId, SaltKey, SaltIndex its Use for call PhonePe API.

Follow Basic Step for Integrating PhonePe on Website:

Run PhonePe Payment Gateway Composer

composer require dwivedianuj9118/phonepe-payment-gateway dev-main

Creating Php File and Import vendor autoload

<?php
use Dwivedianuj9118\PhonePePaymentGateway\PhonePe;
require __DIR__ . ‘/vendor/autoload.php’;
?>

Initialise PhonePe Class with Construct Variable

<?php
$config = new PhonePe(‘PHONEPE_MERCHANTID’,’PHONEPE_SALTKEY’,PHONEPE_SALTINDEX);

?>

PhonePe Payment request Payload

<?php
$merchantTransactionId=’MUID’ . substr(uniqid(), -6);
$merchantOrderId=’Order’.mt_rand(1000,99999);
$amount=100;//In Paisa 
$redirectUrl=”https://papayacoders.in/”;
$mode=”UAT”;// UAT or PRODUCTION
$callbackUrl=”https://papayacoders.in/”;
$mobileNumber=XXXXXXXXXX;

?>

Initialise PaymentCall() Function with all Parameter

<?php

$data=$config->PaymentCall(“$merchantTransactionId”,”$merchantOrderId”,”$amount”,”$redirectUrl”,”$callbackUrl”,”$mobileNumber”,”$mode”);
?>

Complete PHP code to Integrate PhonePe Payment Gateway

<?php
use Dwivedianuj9118\PhonePePaymentGateway\PhonePe;
require __DIR__ . ‘/vendor/autoload.php’;
$config = new PhonePe(‘PHONEPE_MERCHANTID’,’PHONEPE_SALTKEY’,PHONEPE_SALTINDEX);
$merchantTransactionId=’MUID’ . substr(uniqid(), -6);
$merchantOrderId=’Order’.mt_rand(1000,99999);
$amount=100;//In Paisa 
$redirectUrl=”success.php”;
$mode=”UAT”;// UAT or PRODUCTION
$callbackUrl=”success.php”;
$mobileNumber=XXXXXXXXXX;
$data=$config->PaymentCall(“$merchantTransactionId”,”$merchantOrderId”,”$amount”,”$redirectUrl”,”$callbackUrl”,”$mobileNumber”,”$mode”);
header(‘Location:’. $data[‘url’]);
?>

PhonePe TEST API Key For UAT mode

MerchantID: ATMOSTUAT

SaltKey: 58a63b64-574d-417a-9214-066bee1e4caa

SaltInde: 1

Get Response From PhonePe callback url

first create sucess.php file and write that code

<?php
if(isset($_POST['code']) && !empty($_POST['code']) && $_POST['code']=="PAYMENT_ERROR"){
    echo "Txn id: ".$_POST['transactionId']." Status : ".$_POST['code'];
}else{
    echo "Txn id: ".$_POST['transactionId']." Status : ".$_POST['code'];
}
?>

When you change UAT mode to PRODUCTION to replace ‘YOUR_API_KEY’, ‘YOUR_MERCHANT_ID’, ‘YOUR_ORDER_ID’, ‘YOUR_REDIRECT_URL’, and other placeholders with your actual credentials and data.

This is PhonePe Payment Gateway SDK for the PhonePe API.

UI FLOW

Standard Checkout
Standard Checkout
Standard Checkout
Standard Checkout
Standard Checkout
Standard Checkout

About PhonePe

PhonePe is India’s most trusted digital payment partner. To help you with your business, we have launched PhonePe Payment Gateway. This helps you seamlessly process 100% online payments from your customers and is absolutely secure. We are also equipped to handle large-scale transactions with best-in-class success rates.

What PhonePe offer?

Flexible integration: Our pre-built checkout integration fits easily into any business requirement. User-friendly SDKs & Plugins: Integrate easily across any web platform and mobile applications Wide range of Payment methods: Accept payments through debit/credit cards, UPI, and net banking. User-friendly dashboard: Efficiently manage and track your transactions, settlements, refunds, and customer issues.

Tags :

Latest Post

Your Cart

No Item Found
Subtotal0.00
Shipping0.00
Tax0.00
Total0.00
0