<?php
$pageTitle = "How to Integrate FamPay Gateway in PHP (Step-by-Step) | FamGateway";
$blogKicker = "Developer Guide";
include 'includes/blog-header.php';
?>
<p>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 <strong>FamGateway</strong> steps in.</p>
        
        <p>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.</p>

        <h2>Step 1: Get Your API Key</h2>
        <p>First, you need to register on <a href="https://famgateway.in" style="color:#2563eb;font-weight:600;">FamGateway</a>. Once registered, link your Gmail App Password so our stateless PHP engine can securely read your transactional receipts.</p>
        <p>Head to the <strong>API Keys</strong> section in your dashboard and generate your <code>merchant_id</code> and <code>api_key</code>.</p>

        <h2>Step 2: Generate the Payment QR Code</h2>
        <p>When your customer reaches the checkout page, you need to display a UPI QR code. Send a <code>cURL</code> request from your PHP backend to FamGateway to create an order.</p>

<pre><code>$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 '&lt;img src="' . $data['qr_url'] . '" alt="Pay via FamPay" /&gt;';
</code></pre>

        <h2>Step 3: Setup the Webhook Callback</h2>
        <p>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.</p>
        <p>Create a file named <code>webhook.php</code> on your server:</p>

<pre><code>$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";
}
</code></pre>

        <div class="highlight-box">
            <strong>Security Tip:</strong> Always verify the payment amount matches the expected amount in your database before fulfilling the order.
        </div>

        <h2>Why Use FamGateway for PHP?</h2>
        <p>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.</p>

        <!-- Founder & Author Bio Block -->

<?php include 'includes/blog-footer.php'; ?>
