AM GATEWAY API
Accept UPI payments in websites, apps and Telegram bots β verified automatically, money straight to your UPI ID.
Accept UPI in your app or Telegram bot
Three calls. Create an order, show the QR / payment link, wait until the status is PAID. Payments go straight to your own UPI ID β the gateway only verifies them.
- Connect FamPay in your dashboard. Your API key is created automatically.
- Create an order β you get
pay_url,qr_image_urland the exactamount. - Check the status every 3β5 seconds (or receive a webhook) β deliver when
PAID.
https://famgateway.vipsite.in/api/v1One prompt for the whole integration
Paste this into ChatGPT, Claude, Gemini or any coding assistant (or hand it to your developer). It contains everything: every endpoint, field, status, webhook signature rule and the expired-card handling β your assistant can build the full integration from it.
Read the prompt
Authentication
Send your key with every request. Use whichever your platform supports β all three work the same:
| Method | Example | Best for |
|---|---|---|
| Header | X-API-Key: YOUR_API_KEY | Servers, Python / Node / PHP bots |
| Bearer | Authorization: Bearer YOUR_API_KEY | HTTP libraries with auth helpers |
| URL parameter | ?api_key=YOUR_API_KEY | Bot builders that can only do a simple GET (TeleBotHost etc.) |
amg_live_ (older gram_ keys still work), test keys with amg_test_.Create order POST / GET
https://famgateway.vipsite.in/api/v1/orders/create
| Parameter | Required | Description |
|---|---|---|
amount | yes | Rupees, e.g. 99 or 99.50. Must be within your min/max limits. |
client_ref | no | Your own reference (invoice / Telegram user ID). Letters, numbers, - _ . : #, max 80. |
Idempotency-Key header | recommended | Same key again = the same order is returned (no duplicates if your bot retries). |
curl -X POST https://famgateway.vipsite.in/api/v1/orders/create \
-H "X-API-Key: YOUR_API_KEY" \
-H "Idempotency-Key: INV-1001" \
-d amount=99 -d client_ref=INV-1001https://famgateway.vipsite.in/api/v1/orders/create?api_key=YOUR_API_KEY&amount=99&client_ref=TG12345<?php
$ch = curl_init('https://famgateway.vipsite.in/api/v1/orders/create');
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ['X-API-Key: YOUR_API_KEY', 'Idempotency-Key: INV-1001'],
CURLOPT_POSTFIELDS => ['amount' => 99, 'client_ref' => 'INV-1001'],
]);
$res = json_decode(curl_exec($ch), true);
if (($res['status'] ?? '') === 'success') {
header('Location: ' . $res['data']['pay_url']); // or show $res['data']['qr_image_url']
}import requests
r = requests.post('https://famgateway.vipsite.in/api/v1/orders/create',
headers={'X-API-Key': 'YOUR_API_KEY', 'Idempotency-Key': 'INV-1001'},
data={'amount': 99, 'client_ref': 'INV-1001'}, timeout=15)
order = r.json()['data']
print(order['order_id'], order['amount'], order['pay_url'])const r = await fetch('https://famgateway.vipsite.in/api/v1/orders/create', {
method: 'POST',
headers: { 'X-API-Key': 'YOUR_API_KEY', 'Idempotency-Key': 'INV-1001',
'Content-Type': 'application/json' },
body: JSON.stringify({ amount: 99, client_ref: 'INV-1001' })
});
const { data } = await r.json();Response
{
"status": "success",
"request_id": "req_7f3aβ¦",
"data": {
"order_id": "AMG4EB00B3C1A2F",
"amount": "99.03",
"mode": "live",
"pay_url": "https://famgateway.vipsite.in/pay.php?o=AMG4EB00B3C1A2F",
"upi_link": "upi://pay?pa=you@fam&am=99.03&β¦",
"qr_image_url": "https://api.qrserver.com/v1/create-qr-code/?β¦",
"valid_seconds": 300,
"expires_at": "2026-11-01T18:57:00+05:30"
}
}data.amount (e.g. βΉ99.03), not the amount you asked for. A few paise are added so every open order is unique β that is how payments are matched automatically.| Field | Use it for |
|---|---|
pay_url | Hosted checkout page with QR, timer and live status. Best for Telegram buttons and websites. |
qr_image_url | Ready PNG of the QR β send it as a photo in Telegram (sendPhoto). |
upi_link | Draw your own QR. (Telegram buttons cannot open upi:// links β use pay_url.) |
Check status GET
https://famgateway.vipsite.in/api/v1/orders/status/{order_id}
curl https://famgateway.vipsite.in/api/v1/orders/status/AMG4EB00B3C1A2F -H "X-API-Key: YOUR_API_KEY"https://famgateway.vipsite.in/api/v1/orders/status/AMG4EB00B3C1A2F?api_key=YOUR_API_KEYr = requests.get('https://famgateway.vipsite.in/api/v1/orders/status/' + order_id,
headers={'X-API-Key': 'YOUR_API_KEY'}, timeout=10).json()
if r['data']['status'] == 'PAID':
deliver(order_id){
"status": true,
"message": "Payment verified successfully",
"data": {
"order_id": "AMG4EB00B3C1A2F",
"status": "PAID",
"amount": "99.03",
"utr": "768040076752",
"txn_id": "FMP1234567890",
"payer": "RAHUL KUMAR",
"paid_at": "2026-11-01T18:53:10+05:30"
}
}| data.status | Meaning | What to do |
|---|---|---|
| PENDING | Waiting for payment | Check again in 3β5 s |
| PAID | Verified β final | Deliver the product (once) |
| EXPIRED | Time ran out | Keep checking for ~3 more minutes (late payments are still matched), then create a new order |
| REVIEW | Needs a manual check | Tell the customer support is checking |
| FAILED | Marked failed by support | Do not deliver |
The status call answers instantly from the database; the gateway checks your FamApp emails in the background. Top-level status is true only for PAID.
Telegram bot integration
- Send
qr_image_urlas a photo and putpay_urlon a button (Telegram buttons can't openupi://). - Use
client_ref= Telegram user ID + message ID, and the same value asIdempotency-Key, so a double-tap never makes two orders. - Check status every 3β5 s until PAID, or for ~3 min after expiry. Keep a "delivered" list so you deliver once.
- Prefer webhooks for big bots β no polling at all.
import asyncio, aiohttp
from aiogram import Bot, Dispatcher, F
from aiogram.filters import Command
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
API = 'https://famgateway.vipsite.in/api/v1'
KEY = 'YOUR_API_KEY'
bot = Bot('BOT_TOKEN')
dp = Dispatcher()
delivered = set()
async def api(method, path, data=None, idem=None):
headers = {'X-API-Key': KEY}
if idem: headers['Idempotency-Key'] = idem
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=15)) as s:
async with s.request(method, API + path, headers=headers, data=data) as r:
return await r.json(content_type=None)
@dp.message(Command('buy'))
async def buy(m: Message):
ref = f'tg{m.from_user.id}-{m.message_id}'
res = await api('POST', '/orders/create', {'amount': 99, 'client_ref': ref}, idem=ref)
if res.get('status') != 'success':
return await m.answer('β ' + res.get('message', res.get('error', 'Payment error')))
d = res['data']
kb = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text='π³ Pay βΉ' + d['amount'], url=d['pay_url'])],
[InlineKeyboardButton(text='π Check payment', callback_data='chk:' + d['order_id'])]])
await m.answer_photo(d['qr_image_url'], reply_markup=kb,
caption=f"Pay exactly βΉ{d['amount']} (with paise)\nOrder: {d['order_id']}\nValid {d['valid_seconds'] // 60} min")
asyncio.create_task(watch(m.chat.id, d['order_id'], d['valid_seconds']))
async def deliver(chat_id, data):
if data['order_id'] in delivered: return
delivered.add(data['order_id'])
await bot.send_message(chat_id, f"β
Payment received βΉ{data['amount']}\nUTR: {data.get('utr') or '-'}")
# TODO: give the product here
async def watch(chat_id, oid, seconds):
for _ in range(seconds // 4 + 45): # + ~3 min grace for late payments
await asyncio.sleep(4)
r = await api('GET', f'/orders/status/{oid}')
st = (r.get('data') or {}).get('status')
if st == 'PAID': return await deliver(chat_id, r['data'])
if st in ('FAILED', 'REVIEW'): return await bot.send_message(chat_id, 'β οΈ Payment ' + st.lower() + '. Contact support.')
await bot.send_message(chat_id, 'β Order expired. Send /buy to try again.')
@dp.callback_query(F.data.startswith('chk:'))
async def check(c: CallbackQuery):
r = await api('GET', '/orders/status/' + c.data[4:])
d = r.get('data') or {}
if d.get('status') == 'PAID': await deliver(c.message.chat.id, d)
await c.answer('Status: ' + d.get('status', 'unknown'))
asyncio.run(dp.start_polling(bot))import requests
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
API, KEY = 'https://famgateway.vipsite.in/api/v1', 'YOUR_API_KEY'
H = {'X-API-Key': KEY}
async def buy(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
ref = f'tg{update.effective_user.id}-{update.message.message_id}'
res = requests.post(API + '/orders/create', headers={**H, 'Idempotency-Key': ref},
data={'amount': 99, 'client_ref': ref}, timeout=15).json()
if res.get('status') != 'success':
return await update.message.reply_text('β ' + res.get('message', 'error'))
d = res['data']
await update.message.reply_photo(d['qr_image_url'], caption=f"Pay exactly βΉ{d['amount']}\nOrder {d['order_id']}",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton('π³ Pay now', url=d['pay_url'])]]))
ctx.job_queue.run_repeating(poll, interval=4, first=4, data={'oid': d['order_id'], 'chat': update.effective_chat.id, 'n': 0})
async def poll(ctx: ContextTypes.DEFAULT_TYPE):
job = ctx.job; j = job.data; j['n'] += 1
d = requests.get(API + '/orders/status/' + j['oid'], headers=H, timeout=10).json().get('data', {})
if d.get('status') == 'PAID':
job.schedule_removal()
await ctx.bot.send_message(j['chat'], f"β
Paid βΉ{d['amount']} Β· UTR {d.get('utr')}")
elif j['n'] > 120: # ~8 minutes
job.schedule_removal()
await ctx.bot.send_message(j['chat'], 'β Order expired. /buy again.')
app = ApplicationBuilder().token('BOT_TOKEN').build() # pip install "python-telegram-bot[job-queue]"
app.add_handler(CommandHandler('buy', buy))
app.run_polling()const { Telegraf, Markup } = require('telegraf');
const API = 'https://famgateway.vipsite.in/api/v1', KEY = 'YOUR_API_KEY';
const bot = new Telegraf('BOT_TOKEN');
const delivered = new Set();
const api = async (path, opts = {}) => (await fetch(API + path, {
...opts, headers: { 'X-API-Key': KEY, ...(opts.headers || {}) }, signal: AbortSignal.timeout(15000) })).json();
bot.command('buy', async (ctx) => {
const ref = `tg${ctx.from.id}-${ctx.message.message_id}`;
const res = await api('/orders/create', { method: 'POST', headers: { 'Idempotency-Key': ref, 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: 99, client_ref: ref }) });
if (res.status !== 'success') return ctx.reply('β ' + (res.message || res.error));
const d = res.data;
await ctx.replyWithPhoto(d.qr_image_url, { caption: `Pay exactly βΉ${d.amount}\nOrder ${d.order_id}`,
...Markup.inlineKeyboard([[Markup.button.url('π³ Pay now', d.pay_url)]]) });
let n = 0;
const t = setInterval(async () => {
const r = await api('/orders/status/' + d.order_id).catch(() => null);
const st = r && r.data && r.data.status;
if (st === 'PAID' && !delivered.has(d.order_id)) { delivered.add(d.order_id); clearInterval(t); ctx.reply('β
Payment received!'); }
else if (++n > (d.valid_seconds / 4) + 45) { clearInterval(t); ctx.reply('β Expired. /buy again.'); }
}, 4000);
});
bot.launch();<?php
const API = 'https://famgateway.vipsite.in/api/v1';
const KEY = 'YOUR_API_KEY';
function amg(string $path, array $post = null, string $idem = ''): array {
$ch = curl_init(API . $path);
$h = ['X-API-Key: ' . KEY]; if ($idem) $h[] = 'Idempotency-Key: ' . $idem;
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_HTTPHEADER => $h]);
if ($post !== null) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); }
return json_decode((string)curl_exec($ch), true) ?: [];
}
// 1) when user taps Buy
$ref = 'tg' . $userId . '-' . $messageId;
$res = amg('/orders/create', ['amount' => 99, 'client_ref' => $ref], $ref);
$d = $res['data'];
// sendPhoto($chatId, $d['qr_image_url'], caption: "Pay βΉ{$d['amount']}", button: $d['pay_url']);
// save $d['order_id'] with the user in your DB
// 2) on "Check payment" button or every few seconds from cron
$st = amg('/orders/status/' . $orderId)['data']['status'] ?? '';
if ($st === 'PAID') { /* deliver once */ }STEP 1 β create the order (HTTP GET):
https://famgateway.vipsite.in/api/v1/orders/create?api_key=YOUR_API_KEY&amount=99&client_ref=USER_ID
Read from the JSON response:
data.order_id β save it for this user
data.amount β show this exact amount (e.g. 99.03)
data.qr_image_url β send as photo
data.pay_url β put on an inline URL button "Pay now"
STEP 2 β "Check payment" button (HTTP GET):
https://famgateway.vipsite.in/api/v1/orders/status/ORDER_ID?api_key=YOUR_API_KEY
Read data.status:
PAID β deliver (remember the order_id so you deliver only once)
PENDING β "Not received yet, try again in a few seconds"
EXPIRED β still check for 3 min, then ask to create a new order
Tips: use URL-encoding for client_ref, keep the API key only inside the bot code,
and don't create a new order on every button press β reuse the saved order_id.Webhooks
Set a webhook URL in Dashboard β Webhooks. When a payment is verified we POST a signed JSON event within seconds. Your endpoint must be public HTTPS, answer HTTP 2xx within 8 s and must not redirect. Failed deliveries are retried with exponential backoff.
| Header | Meaning |
|---|---|
X-AMG-Event | payment.success, payment.review, payment.failed, payment.expired, webhook.test |
X-AMG-Event-Id | Unique evt_β¦ β store it to ignore duplicates |
X-AMG-Timestamp | Unix time β reject if older than 5 minutes (replay protection) |
X-AMG-Signature | sha256= HMAC of timestamp + "." + raw body with your webhook secret |
<?php
$body = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_AMG_TIMESTAMP'] ?? '';
$sig = $_SERVER['HTTP_X_AMG_SIGNATURE'] ?? '';
$calc = 'sha256=' . hash_hmac('sha256', $ts . '.' . $body, 'YOUR_WEBHOOK_SECRET');
if (!hash_equals($calc, $sig) || abs(time() - (int)$ts) > 300) { http_response_code(401); exit; }
$event = json_decode($body, true);
if ($event['event'] === 'payment.success') {
$orderId = $event['data']['order_id']; // deliver once (check $event['id'] not processed before)
}
http_response_code(200);import hmac, hashlib, time
from flask import Flask, request
app = Flask(__name__)
SECRET = b'YOUR_WEBHOOK_SECRET'
@app.post('/amg-webhook')
def hook():
ts = request.headers.get('X-AMG-Timestamp', '')
sig = request.headers.get('X-AMG-Signature', '')
calc = 'sha256=' + hmac.new(SECRET, ts.encode() + b'.' + request.get_data(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(calc, sig) or abs(time.time() - int(ts or 0)) > 300:
return 'bad signature', 401
ev = request.get_json()
if ev['event'] == 'payment.success':
deliver(ev['data']['order_id'])
return 'ok'const crypto = require('crypto');
app.post('/amg-webhook', express.raw({ type: 'application/json' }), (req, res) => {
const ts = req.get('X-AMG-Timestamp'), sig = req.get('X-AMG-Signature') || '';
const calc = 'sha256=' + crypto.createHmac('sha256', 'YOUR_WEBHOOK_SECRET').update(ts + '.' + req.body).digest('hex');
if (calc.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(calc), Buffer.from(sig)) || Math.abs(Date.now() / 1000 - ts) > 300)
return res.status(401).end();
const ev = JSON.parse(req.body);
if (ev.event === 'payment.success') deliver(ev.data.order_id);
res.sendStatus(200);
});QR image & logo
qr_image_url is a ready PNG of the payment QR, drawn on the gateway server. It looks exactly like the QR on the hosted checkout page: the QR design you picked in Dashboard β QR & checkout, with a logo in the centre. Send it straight to sendPhoto β nothing to download or draw.
| Your setting | Centre of the QR |
|---|---|
| You uploaded your own logo | Your logo |
| You never uploaded one | The AM GATEWAY logo |
| You pressed Remove logo | Plain QR, no logo |
qr_image_urlsendPhotocustomer scanshttps://api.telegram.org/botBOT_TOKEN/sendPhoto?chat_id=CHAT_ID&photo=URL_ENCODED_qr_image_url&caption=Pay%20exactly%20%E2%82%B999.03import requests
BOT = 'https://api.telegram.org/botBOT_TOKEN'
def send_qr(chat_id, d): # d = response['data'] from /orders/create
return requests.post(BOT + '/sendPhoto', data={
'chat_id': chat_id,
'photo': d['qr_image_url'], # Telegram downloads it itself
'caption': f"Pay exactly βΉ{d['amount']}\nOrder {d['order_id']}",
}, timeout=15).json()async function sendQr(chatId, d) { // d = res.data from /orders/create
const r = await fetch(`https://api.telegram.org/botBOT_TOKEN/sendPhoto`, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chat_id: chatId, photo: d.qr_image_url,
caption: `Pay exactly βΉ${d.amount}\nOrder ${d.order_id}` }) });
return r.json();
}<?php
function send_qr(string $botToken, $chatId, array $d): array { // $d = response['data'] from /orders/create
$ch = curl_init("https://api.telegram.org/bot$botToken/sendPhoto");
curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_POSTFIELDS => [
'chat_id' => $chatId, 'photo' => $d['qr_image_url'],
'caption' => "Pay exactly βΉ{$d['amount']}\nOrder {$d['order_id']}"]]);
$r = json_decode((string)curl_exec($ch), true); curl_close($ch);
return $r ?: [];
}- Every order has its own QR (amount and order id are inside) β never reuse an old image for a new order.
- Optional:
?s=300β¦900changes the size in pixels (default 640).&dl=1forces a download. - If a bot builder cannot send photos from a URL, fetch
qr_image_urlyourself and upload the bytes as a file. - Changing your logo or design in the dashboard applies to every new QR immediately.
Payment links
Create a link in Dashboard β Payment links (fixed amount, or the customer types the amount) and share it anywhere β chat, social media, email. The customer opens it, taps Pay now and gets the normal checkout with your QR design and logo. Payments are verified automatically.
- Every tap creates a fresh order for you β it appears in Transactions with reference
link:β¦. - Your webhook fires exactly as for API orders, so the same delivery code works.
- Turn a link OFF any time; customers then see βLink not availableβ.
- Links respect your min/max amount, QR validity and daily limits.
Test mode
Use your amg_test_β¦ key: orders are created with "mode": "test", never matched to real money, and you can mark them paid yourself:
curl -X POST https://famgateway.vipsite.in/api/v1/test/pay/AMG4EB00B3C1A2F -H "X-API-Key: amg_test_β¦"This fires your webhook too, so you can test the whole bot flow without paying.
Errors
Errors return JSON with a message (or error) and a request_id β quote it to support.
| HTTP | Meaning | Fix |
|---|---|---|
| 400 | Missing / invalid parameter | Check amount, order_id, client_ref |
| 401 | Key missing, wrong, revoked, expired, or FamPay not connected | Copy the key again from the dashboard |
| 403 | Account suspended / endpoint not allowed for this key | Contact support |
| 404 | Order not found (or belongs to another account) | Use the order_id from your create response |
| 409 | Idempotency-Key reused with a different amount | Use a new key per order |
| 413 | Request too large | Send only the documented fields |
| 429 | Too many requests / daily quota | Wait Retry-After seconds; poll every 3β5 s, not faster |
| 503 | Maintenance | Retry in a minute |
Limits & speed
- Create and status calls answer from the database β typically well under 200 ms on normal hosting.
- Payment verification normally takes 3β10 s after the customer pays (it depends on when FamApp's email arrives).
- Rate limit: shown in the
X-RateLimit-Limit/X-RateLimit-Remainingheaders (default 120 requests/min per account). - Use HTTPS and a 10β15 s timeout. Retry network errors with the same
Idempotency-Key. - Public health check:
GET https://famgateway.vipsite.in/api/v1/health
FAQ
Why is the amount βΉ99.03 instead of βΉ99?
Each open order gets a unique amount so the gateway can tell payments apart automatically. Always ask the customer to pay the exact amount shown.
Customer paid but status is still PENDING
Wait up to a minute. If the customer paid a different amount or after the order expired (+3 min grace), it will not match β contact support with the UTR.
Can I keep using autoqr.php / autoverify.php?
Yes. Old URLs and old keys keep working with the same response format.
Do you hold my money?
No. Customers pay your own UPI ID directly. The gateway only verifies the payment.