How to Integrate FamPay Gateway in PHP (Step-by-Step)
If you are building a PHP application and want to accept payments via FamPay (FamApp by Trio), you quickly realize there is no public API provided for individual developers or student builders. That is where FamGateway steps in.
In this guide, you will learn how to integrate FamPay into your PHP website using either our lightweight REST API or the official FamGateway PHP SDK with secure HMAC-SHA256 webhook verification.
Step 1: Get Your API Key
First, register on FamGateway. Once registered, connect your FamPay-linked Gmail with a Google App Password and add your FamPay UPI ID (e.g., yourname@fam).
Navigate to the API Keys section in your dashboard to copy your live api_key.
Step 2: Install the PHP SDK or Use cURL
You can install the official SDK via Composer:
composer require aryanispe/famgateway-php-sdk
Or create a direct checkout order using standard PHP cURL:
<?php
$apiKey = 'YOUR_API_KEY';
$amount = 499.00;
$redirectUrl = urlencode('https://yourwebsite.com/payment-success.php');
$response = file_get_contents("https://famgateway.in/api/qr.php?api_key={$apiKey}&amount={$amount}&redirect_url={$redirectUrl}");
$order = json_decode($response, true)['data'];
// Redirect customer to Hosted Checkout
header("Location: " . $order['checkout_url']);
exit;
checkout_url provides a mobile-optimized payment screen with dynamic UPI QR and automated instant verification. Alternatively, you can embed $order['qr_url'] directly as an image tag in your custom UI.
Step 3: Setup the Secure Webhook Handler
When the customer completes the UPI payment, FamGateway's backend daemon verifies the receipt in real-time and dispatches a signed HTTP POST webhook to your server.
Create a file named webhook.php on your server with HMAC signature verification:
<?php
$apiKey = 'YOUR_API_KEY';
$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_FAMGATEWAY_SIGNATURE'] ?? '';
// Verify HMAC-SHA256 signature
$expectedSignature = hash_hmac('sha256', $rawBody, $apiKey);
if (!hash_equals($expectedSignature, $signature)) {
http_response_code(401);
die('Unauthorized — Invalid Signature');
}
$event = json_decode($rawBody, true);
if ($event['event'] === 'payment.success') {
$orderId = $event['order_id'];
$amount = $event['amount'];
$utr = $event['utr'];
// Fulfill the order in your database
// e.g. updateOrderStatus($orderId, 'paid', $utr);
echo "OK";
}
Why Use FamGateway for PHP?
- Zero GST & No Corporate Documents: Ideal for student developers, freelancers, and indie builders.
- 0% Platform Fees: 100% of customer funds settle directly into your personal FamPay UPI ID.
- Shared Hosting Compatible: Works out-of-the-box on standard cPanel PHP hosting without Node.js or root server dependencies.
View Complete Developer Documentation & SDK Examples →
Related Developer Guides & Resources
FamApp by Trio (FamX) API: How to Accept Automated Payments on Website
Learn how to connect your FamApp by Trio (FamX) Spending Account to your website or Discord bot with instan...
How FamGateway™ Webhooks Work: Architecture, HMAC-SHA256 Security & Instant Delivery
Deep technical dive into the FamGateway webhook engine: HMAC-SHA256 cryptographic signatures, asynchronous ...
What is FamPay? Complete Guide to FamApp by Trio, UPI & Payments (2026)
Everything you need to know about FamPay (FamApp by Trio) in 2026: What is FamPay, how it works, under 18 a...