PHP code example of fayyaztech / phonepe-gateway-pg-v2

1. Go to this page and download the library: Download fayyaztech/phonepe-gateway-pg-v2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fayyaztech / phonepe-gateway-pg-v2 example snippets


use fayyaztech\PhonePeGatewayPGV2\PhonePe;

// Initialize with environment (UAT/PROD)
$phonepe = new PhonePe(
    client_id: 'YOUR_CLIENT_ID',
    client_secret: 'YOUR_CLIENT_SECRET',
    mode: PhonePe::MODE_UAT,  // Use MODE_PROD for production
    debug: true
);

// Initiate Payment
$response = $phonepe->initiatePayment(
    merchantOrderId: 'ORDER' . time(),
    amount: 100 * 100,  // Amount in paise
    redirectUrl: 'https://your-domain.com/redirect'
);

// Get payment URL
if (isset($response['orderId'])) {
    $paymentUrl = $response['redirectUrl'];
    // Redirect user to $paymentUrl
}

// Initiate Payment
$response = $phonepe->initiatePayment(
    merchantOrderId: 'ORDER123',
    amount: 1000,
    redirectUrl: 'https://your-domain.com/redirect',
    metaInfo: ['udf1' => 'value1'],
    enabledPaymentModes: [
        ['type' => 'UPI_INTENT']
    ]
);

// Check Payment Status
$status = $phonepe->getOrderStatus('ORDER123');

// Process Refund
$refund = $phonepe->initiateRefund(
    merchantRefundId: 'REFUND123',
    originalMerchantOrderId: 'ORDER123',
    amount: 1000
);

// Check Refund Status
$refundStatus = $phonepe->getRefundStatus('REFUND123');

[
    ['type' => 'UPI_INTENT'],
    ['type' => 'UPI_COLLECT'],
    ['type' => 'UPI_QR'],
    ['type' => 'NET_BANKING'],
    ['type' => 'CARD', 'cardTypes' => ['DEBIT_CARD', 'CREDIT_CARD']]
]

use fayyaztech\PhonePeGatewayPGV2\PhonePeApiException;

try {
    $response = $phonepe->initiatePayment(...);
} catch (PhonePeApiException $e) {
    echo $e->getMessage();
}

$phonepe = new PhonePe(
    client_id: 'YOUR_CLIENT_ID',
    client_secret: 'YOUR_CLIENT_SECRET',
    mode: PhonePe::MODE_UAT,
    debug: true
);

$phonepe = new PhonePe(
    client_id: 'TEST_CLIENT_ID',
    client_secret: 'TEST_CLIENT_SECRET',
    mode: PhonePe::MODE_UAT
);