Home / Documentation
DEVELOPER DOCUMENTATION · API V1

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.

Before you start

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.

01 / CREATE ORDER

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.

POST /api/v1/orders/create
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"}'
201 Example response
{"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.

02 / CHECK STATUS

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.

GET /api/v1/orders/status/:order_id
curl 'https://trustgateway.in/api/v1/orders/status/ORDER_ID' \
  -H 'X-API-Key: YOUR_API_KEY'
200 Successful payment response
{"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.

RETURN TO YOUR WEBSITE

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.

03 / COPYABLE EXAMPLES

Integrate from your backend

These examples run on your merchant server. Adapt saveOrder and fulfillOnce to your database and business logic.

NODE Node.js 18+ example
// 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 PHP 8+ example
<?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;
04 / AUTOMATE

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.

NODE Verify X-Gateway-Signature
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.

05 / OPERATIONS

Handle failures deliberately

ResponseMeaningYour action
400Invalid amount or inputCorrect the request; do not retry unchanged.
403Inactive API key, subscription or routeCheck merchant settings and plan.
404Unknown order IDCheck the ID you saved at creation.
409FamPay amount slots busyWait a few minutes; do not take payment without a new order.
429Rate limitBack off before retrying.
5xx / timeoutTemporary failureCheck 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.

06 / EXISTING INTEGRATIONS

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.

NEXT STEP

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.

Get started ↗