How to Integrate FamPay Gateway in PHP (Step-by-Step 2026 Developer Tutorial)
If you are developing a PHP application, an e-commerce storefront, or a membership portal in India and want to accept automated payments via FamPay (FamApp by Trio), you quickly discover that there is no official merchant API for individual creators. Aggregators like Razorpay require corporate entities and GST certificates, while manual UPI transfers leave you vulnerable to fake screenshot scams.
That is where FamGateway steps in. In this step-by-step 2026 guide, you will learn how to integrate automated FamPay UPI payments into any PHP website using either the official FamGateway PHP SDK or standard native PHP cURL requests, complete with cryptographic HMAC-SHA256 webhook verification.
Step 1: Obtain Your Free API Credentials
To begin, create your free account on FamGateway Registration:
- Navigate to Dashboard → Gmail Settings and enter your FamPay-linked Gmail address.
- Generate a 16-character Google App Password and save it.
- Enter your FamPay UPI ID (e.g.,
yourname@fam). - Go to the API Keys tab to copy your live private
api_key.
Step 2: Integration Method A — Official FamGateway PHP SDK
The simplest, cleanest way to integrate is using our official open-source PHP SDK (GitHub Repository).
You can install the SDK via Composer:
composer require aryanispe/famgateway-php-sdk
Or simply download FamGateway.php and include it directly in your project:
<?php
require_once 'FamGateway.php';
// Initialize SDK with your private API Key
$fg = new FamGateway("YOUR_FAMGATEWAY_API_KEY");
$amount = 499.00;
$redirectUrl = "https://yourwebsite.com/payment-success.php";
$customWebhook = "https://yourwebsite.com/webhook.php";
// Creates order session and immediately redirects buyer to Hosted Checkout
$fg->createPayment($amount, $redirectUrl, $customWebhook);
?>
Step 3: Integration Method B — Native Pure PHP cURL (Zero Dependencies)
If you prefer zero external dependencies, you can call our canonical REST API directly using standard PHP cURL functions:
<?php
$apiKey = 'YOUR_FAMGATEWAY_API_KEY';
$payload = json_encode([
'amount' => 499.00,
'customer_name' => 'Karan Sharma',
'redirect_url' => 'https://yourwebsite.com/payment-success.php',
'webhook_url' => 'https://yourwebsite.com/webhook.php'
]);
$ch = curl_init('https://famgateway.in/api/create-order');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-Api-Key: ' . $apiKey
],
CURLOPT_TIMEOUT => 15
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die("cURL Error: " . curl_error($ch));
}
curl_close($ch);
$data = json_decode($response, true);
if (($data['status'] ?? '') === 'success') {
$checkoutUrl = $data['data']['checkout_url'];
$qrImageUrl = $data['data']['qr_url'];
$upiIntent = $data['data']['upi_intent'];
// Option 1: Redirect buyer directly to FamGateway's hosted mobile checkout
header("Location: " . $checkoutUrl);
exit;
// Option 2: Embed $qrImageUrl directly into your custom checkout page
} else {
die("API Error: " . htmlspecialchars($data['message'] ?? 'Unknown failure'));
}
?>
Step 4: Handling Authenticated Webhooks (Instant Delivery)
When the customer pays in FamApp or any UPI app, FamGateway's stateless daemon verifies the payment in 3 to 5 seconds and dispatches an authenticated HTTP POST notification to your webhook URL.
Create a file named webhook.php on your server with cryptographic HMAC-SHA256 signature verification:
<?php
// webhook.php — Production Webhook Receiver
$apiKey = 'YOUR_FAMGATEWAY_API_KEY';
$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_FAMGATEWAY_SIGNATURE'] ?? '';
// 1. Validate signature using constant-time comparison
$expectedSignature = hash_hmac('sha256', $rawBody, $apiKey);
if (!hash_equals($expectedSignature, $signature)) {
http_response_code(401);
die(json_encode(['error' => 'Invalid HMAC signature']));
}
$payload = json_decode($rawBody, true);
// 2. Process verified payment event
if (($payload['status'] ?? '') === 'success') {
$orderId = $payload['order_id'];
$amount = (float)$payload['amount'];
$utr = $payload['utr'];
$senderName = $payload['sender_name'] ?? 'Buyer';
// Atomically unlock product or update database
// fulfillOrder($orderId, $utr, $amount);
http_response_code(200);
echo json_encode(['status' => 'acknowledged']);
exit;
}
http_response_code(400);
echo json_encode(['status' => 'ignored']);
?>
Step 5: Polling Payment Status from Frontend JavaScript
If you are displaying the QR code directly on your custom page, you can poll our fast status endpoint from client-side JavaScript every 3 to 5 seconds:
// Client-side Polling Example
const checkPaymentStatus = async (orderId) => {
try {
const response = await fetch(`https://famgateway.in/api/checkout-status.php?order_id=${orderId}`);
const result = await response.json();
if (result.status === 'success') {
window.location.href = '/order-complete.php?utr=' + result.utr;
}
} catch (err) {
console.error('Polling error:', err);
}
};
// Poll every 3 seconds
setInterval(() => checkPaymentStatus('fg_ORD_12345'), 3000);
Why PHP Developers Choose FamGateway
| Feature | FamGateway PHP Integration | Traditional Gateways |
|---|---|---|
| Transaction Commission | 0.0% (Free Forever) | 2.0% + 18% GST |
| Settlement Window | 0 Seconds (Direct UPI) | T+2 to T+3 Business Days |
| Government Legal Entity | MSME Reg: UDYAM-BR-28-0050000 | Requires Corporate GSTIN |
| Server Hosting Compatibility | Runs on Any Cheap Shared cPanel Host | Heavy SDKs & Node requirements |
Frequently Asked Questions (FAQ)
Is there an official PHP SDK for FamGateway?
Yes. You can install the official FamGateway PHP SDK via Composer (`composer require aryanispe/famgateway-php-sdk`), download the standalone FamGateway.php class from GitHub, or download the SDK zip package directly from our developer documentation.
What PHP extensions are required to run the integration?
The integration requires standard PHP 7.4+ or PHP 8.1+ with the default `curl`, `json`, `openssl`, and `hash` extensions enabled. It runs smoothly on any shared cPanel host without root permissions.
How does the PHP integration verify payments without GST or KYC?
FamGateway connects to your linked FamPay Gmail receipts via non-custodial IMAP and verifies incoming Bank UTRs in real-time, dispatching an instant HMAC-SHA256 signed webhook directly to your PHP server.
Can I poll order status in real-time if my server cannot receive webhooks?
Yes. You can poll our fast status endpoint (`GET /api/checkout-status.php?order_id={order_id}`) every 3 to 5 seconds from frontend JavaScript or backend cron workers to check if the transaction is paid.
Does the PHP integration generate official tax receipts for buyers?
Yes. FamGateway automatically generates an official Government MSME-certified PDF receipt (UDYAM-BR-28-0050000) attached to merchant emails and accessible via web download for every cleared payment.
Conclusion
Integrating FamPay into your PHP project takes less than 10 minutes and requires zero corporate bureaucracy. By leveraging FamGateway's stateless API and official PHP SDK, you deliver an automated, instant payment experience for your users with zero commission cuts.
Get Your Free FamPay API Key →
Related Developer Guides & Resources
How to Get Free FamPay API Key and Start Accepting Automated UPI Payments (2026 Developer Guide)
Step-by-step developer guide on getting a free FamPay API key from FamGateway. Learn how to create dynamic ...
How to Integrate FamPay UPI Payment Gateway in SMM Panels (Rental, Perfect Panel & SmartPanel)
Step-by-step developer guide to integrating FamPay UPI payment gateway in SMM panels (Rental, Perfect Panel...
How to Accept UPI Payments on WooCommerce Without GST or Current Account (2026 Guide)
Complete tutorial on accepting automated UPI payments on WooCommerce without GST or a commercial current ac...