How to Integrate FamPay Gateway in PHP (Step-by-Step)
If you are building a PHP application and want to accept payments via FamPay (or FamApp), you quickly realize there is no official API provided for individual developers or students. That is where FamGateway steps in.
In this guide, I will show you exactly how to integrate FamPay into your PHP website using the FamGateway REST API to automate your UPI payment verifications.
Step 1: Get Your API Key
First, you need to register on FamGateway. Once registered, link your Gmail App Password so our stateless PHP engine can securely read your transactional receipts.
Head to the API Keys section in your dashboard and generate your merchant_id and api_key.
Step 2: Generate the Payment QR Code
When your customer reaches the checkout page, you need to display a UPI QR code. Send a cURL request from your PHP backend to FamGateway to create an order.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://famgateway.in/api/create-order.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'merchant_id' => 'YOUR_MERCHANT_ID',
'api_key' => 'YOUR_API_KEY',
'amount' => 150.00,
'customer_email' => 'customer@example.com'
]));
$response = curl_exec($ch);
$data = json_decode($response, true);
// Display the QR Code to your user
echo '<img src="' . $data['qr_url'] . '" alt="Pay via FamPay" />';
Step 3: Setup the Webhook Callback
FamGateway uses a highly scalable, stateless polling architecture. The moment the customer pays on their FamApp, our servers will instantly detect the payment and fire an HTTP POST request to your website.
Create a file named webhook.php on your server:
$input = file_get_contents('php://input');
$payload = json_decode($input, true);
if ($payload['status'] === 'success') {
$orderId = $payload['order_id'];
$amount = $payload['amount'];
$utr = $payload['utr'];
// Update your database: Mark order as PAID
$db->query("UPDATE orders SET status = 'paid' WHERE id = '$orderId'");
echo "OK";
}
Why Use FamGateway for PHP?
Unlike generic background daemons that require Node.js or root server access, FamGateway provides a pure REST API. It is designed to work flawlessly on basic shared cPanel hosting, meaning any PHP developer can integrate it in under 5 minutes without touching complicated server configurations.