Payments in your app,
without guesswork.
Your backend creates an order. The customer pays at a hosted UPI checkout. Your backend confirms payment before fulfillment.
Create a merchant account, connect a supported receiving account, activate your plan and copy the API key from your dashboard. Store it as a server environment variable. All key-bearing requests belong on your backend; never put the key in browser code or a checkout URL.
Building a website checkout? Follow the step-by-step UPI website integration guide alongside this API reference.
Create an order
Send your INR price with X-API-Key. Amounts must be positive and have at most two decimal places. The API creates a ten-minute order and returns the hosted checkout path. FamPay Gmail matching may adjust the payable total by up to ₹0.20 so simultaneous orders to one receiver stay distinguishable. The hosted checkout shows this adjustment; your app must use data.amount as the exact payable total and keep data.requested_amount as your original price.
curl -X POST 'https://trustgateway.in/api/v1/orders/create' \
-H 'Content-Type: application/json' \
-H 'X-API-Key: YOUR_API_KEY' \
-d '{"amount":"499.00","note":"Order 1042","redirect_url":"https://merchant.example/payment/return"}'{"success":true,"data":{"order_id":"FAM...","status":"pending","amount":499.01,"requested_amount":499,"matching_adjustment":0.01,"checkout_url":"/checkout/FAM...","upi_url":"upi://pay?...","qr_url":"https://...","expires_at":"2026-10-08T12:10:00.000Z"}}Save data.order_id and data.amount next to your own order ID. Redirect the customer to https://trustgateway.in + data.checkout_url. You can also display the QR URL; scanning alone does not prove payment.
Confirm on your server
Call this endpoint with the same merchant key. It returns paid: false while pending or expired. Only authenticated merchant requests receive the detailed data object for a successful order.
curl 'https://trustgateway.in/api/v1/orders/status/ORDER_ID' \
-H 'X-API-Key: YOUR_API_KEY'{"status":"success","success":true,"paid":true,"data":{"order_id":"FAM...","status":"success","amount":"499.00","utr":"...","transaction_id":"...","signature":"..."}}Compare the returned order ID and amount to your own database. Treat paid: true as necessary, then fulfill once. A browser redirect, screenshot, QR scan or customer-provided UTR is not proof by itself.
Redirect after confirmed payment
Pass your own full HTTPS redirect_url in the create-order request. If you create a payment link in the merchant dashboard, enter the same URL in Return to your website after payment. Once checkout confirms payment, it shows success and navigates the customer to that exact URL after a short countdown. The customer can also choose Return to merchant. Pending and expired orders do not trigger a success redirect.
Keep your local order reference in your application session or a non-secret URL parameter that you control. Your return page must load the saved gateway order ID and check it with the authenticated status API before showing a paid result or delivering goods. The browser redirect is not a webhook or proof of payment. Never put the API key in the return URL.
Integrate from your backend
These examples run on your merchant server. Adapt saveOrder and fulfillOnce to your database and business logic.
// Merchant server (Node.js 18+)
const base = 'https://trustgateway.in';
const apiKey = process.env.TRUST_GATEWAY_API_KEY;
const created = await fetch(base + '/api/v1/orders/create', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
body: JSON.stringify({ amount: '499.00', note: 'Order 1042',
redirect_url: 'https://merchant.example/payment/return' })
});
const result = await created.json();
if (!created.ok || !result.success) throw new Error(result.message || 'Create failed');
await saveOrder({ localId: '1042', gatewayId: result.data.order_id,
requestedAmount: result.data.requested_amount, payableAmount: result.data.amount });
const checkoutUrl = new URL(result.data.checkout_url, base).href;
// Redirect your customer to checkoutUrl.
// Later, on your SERVER before fulfillment:
const checked = await fetch(base + '/api/v1/orders/status/' + encodeURIComponent(result.data.order_id), {
headers: { 'X-API-Key': apiKey }
});
const payment = await checked.json();
if (checked.ok && payment.paid === true && payment.data?.order_id === result.data.order_id &&
Number(payment.data.amount) === Number(result.data.amount)) {
await fulfillOnce('1042');
}<?php
// Merchant server (PHP 8+ with cURL)
$base = 'https://trustgateway.in';
$key = getenv('TRUST_GATEWAY_API_KEY');
$request = curl_init($base . '/api/v1/orders/create');
curl_setopt_array($request, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-API-Key: ' . $key],
CURLOPT_POSTFIELDS => json_encode(['amount' => '499.00', 'note' => 'Order 1042',
'redirect_url' => 'https://merchant.example/payment/return']),
CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($request);
$http = curl_getinfo($request, CURLINFO_HTTP_CODE);
if ($body === false || $http !== 201) { throw new RuntimeException('Create order failed'); }
$order = json_decode($body, true);
// Save $order['data']['order_id'] and $order['data']['amount'] (the payable total) first.
header('Location: ' . $base . $order['data']['checkout_url'], true, 302);
exit;Receive a signed webhook
Set a public HTTPS webhook URL in merchant settings, or pass callback_url when creating an API-key-authenticated order to set its destination just for that order. A verified payment sends payment.success via POST, with X-Gateway-Signature. The signature is HMAC-SHA256 over order_id|amount.toFixed(2)|status|utr-or-NONE, using the configured webhook secret or the merchant API key as fallback. Validate it with a constant-time comparison. Treat webhook delivery as a notification and use authenticated status as a recovery path if it is missed; delivery retries are not guaranteed.
import crypto from 'node:crypto';
// In your HTTPS webhook handler, after JSON parsing:
const event = req.body;
const signingSecret = process.env.TRUST_GATEWAY_WEBHOOK_SECRET || process.env.TRUST_GATEWAY_API_KEY;
const message = [event.order_id, Number(event.amount).toFixed(2), event.status, event.utr || 'NONE'].join('|');
const expected = crypto.createHmac('sha256', signingSecret).update(message).digest('hex');
const provided = req.get('X-Gateway-Signature') || '';
const valid = /^[a-f0-9]{64}$/i.test(provided) &&
crypto.timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(provided, 'hex'));
if (!valid || event.event !== 'payment.success') return res.sendStatus(401);
// Look up event.order_id in your DB; compare amount; fulfill only once.
res.sendStatus(200);Respond quickly with a 2xx status. Before fulfillment, match order ID and amount and make processing idempotent.
Handle failures deliberately
| Response | Meaning | Your action |
|---|---|---|
| 400 | Invalid amount or input | Correct the request; do not retry unchanged. |
| 403 | Inactive API key, subscription or route | Check merchant settings and plan. |
| 404 | Unknown order ID | Check the ID you saved at creation. |
| 409 | FamPay amount slots busy | Wait a few minutes; do not take payment without a new order. |
| 429 | Rate limit | Back off before retrying. |
| 5xx / timeout | Temporary failure | Check whether an order was created before retrying to avoid duplicates. |
Keep API keys in environment variables, rotate a leaked key, verify callback signatures, and never unlock goods or access based only on a customer-side success screen.
Legacy compatibility routes
Existing bots using /qr.php, /verify.php, /create_order.php and /payment_status.php can continue using them. For new projects use API v1 above. Legacy credentials in query strings are supported for compatibility but can leak through browser history or logs; send X-API-Key in a backend request where supported.
The legacy payment-status response is intended for checkout polling and should not be your sole fulfillment signal. Use authenticated API v1 status or a validated webhook.
Make your first test order.
Connect a receiving account, create an order from your server, and check its status after paying through the hosted checkout.
