1. Go to this page and download the library: Download phpcorelab/upi-gateway 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/ */
use PHPCoreLab\UpiGateway\DTOs\OrderPayload;
$order = new OrderPayload(
orderId: 'ORD-2024-001',
amountPaisa: 49900, // INR 499.00 — always in paise
customerName: 'Rahul Sharma',
customerPhone: '9876543210',
);
$qr = $gateway->createQr($order);
echo $qr->transactionId; // store this for polling
echo $qr->qrString; // render as QR image
use PHPCoreLab\UpiGateway\DTOs\PaymentState;
$status = $gateway->pollUntilDone(
transactionId: $qr->transactionId,
intervalMs: 3000,
maxAttempts: 20,
backoff: 'exponential',
onTick: fn($s, $i) => logger()->debug("Poll #{$i}: {$s->state->value}"),
);
if ($status->state === PaymentState::Success) {
// fulfil order
}
// In your background job:
$status = $gateway->checkStatus($transactionId);
if ($status->isTerminal()) {
// handle success / failure
}
// Otherwise re-queue with a delay.
$status = $gateway->handleWebhook(
rawBody: file_get_contents('php://input'),
headers: getallheaders(),
);
// WebhookVerificationException thrown on bad signature.
// Change provider (e.g. from admin panel):
$gateway->switchProvider('phonepe');
// Check current environment:
echo $gateway->getEnvironment()->value; // 'sandbox' or 'live'
use PHPCoreLab\UpiGateway\Contracts\UpiProviderInterface;
use PHPCoreLab\UpiGateway\Enums\Environment;
class CashfreeAdapter implements UpiProviderInterface
{
public function __construct(array $config, Environment $environment) { ... }
// implement generateQr, checkStatus, refund, parseWebhook, getName
}
$gateway->registerProvider('cashfree', new CashfreeAdapter($config, $gateway->getEnvironment()));
$gateway->switchProvider('cashfree');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.