To add UPI payments to a website, you need more than a QR image. Your server must create an order for the correct price, send the customer to checkout, and verify the exact order before delivering a product or marking an invoice paid. This guide shows that flow using the current Trust Gateway API v1. It is written for a website with a backend; a static site needs a small server or serverless function to keep its API key private.
- Set up a supported receiving account and API key in Trust Gateway.
- Your server creates an order and stores the returned order ID and payable amount.
- Your customer pays at the hosted UPI checkout.
- Your server checks the authenticated order status and fulfils that local order only once.
Before you start: account and receiving route
Create a Trust Gateway merchant account, review the available subscription, and connect a supported receiving source in Connect Merchant. The dashboard currently offers FamPay, BharatPe and Paytm connection paths; setup and verification differ by source. Check the receiving UPI identity and run a small end-to-end payment before accepting customer orders. A “Connected” badge means settings were saved, not that a live payment has passed verification.
Generate an API key in your merchant workspace and save it in a server environment variable named TRUST_GATEWAY_API_KEY. The key must never be included in a browser bundle, HTML page, public repository or checkout URL. See the API quickstart for the current requirements.
What happens between your website and checkout?
| Step | Your website | Trust Gateway |
|---|---|---|
| Price | Looks up the product and amount on your server | Receives the amount in the create-order request |
| Order | Stores its own order ID with the gateway order ID | Returns a checkout path and exact payable amount |
| Payment | Sends the customer to hosted checkout | Shows a UPI QR and supported app handoff |
| Result | Checks authenticated status before fulfilment | Reports pending, success or another current state |
Calculate the price from a trusted product catalog on your server. Do not accept an editable browser amount as the final charge. A payment link from the dashboard is a simpler option if you need to share a fixed checkout without writing an API integration.
1. Create a UPI order from your server
Send a POST request to /api/v1/orders/create with X-API-Key. This minimal cURL example creates an order for ₹499.00. In an application, substitute the amount calculated by your own backend.
curl -X POST 'https://trustgateway.in/api/v1/orders/create' \
-H 'Content-Type: application/json' \
-H 'X-API-Key: YOUR_SERVER_SIDE_API_KEY' \
-d '{"amount":"499.00","note":"Order 1042"}'
A successful create request returns HTTP 201 and a data object with order_id, amount, requested_amount, checkout_url and expires_at. Store the gateway order_id, exact data.amount and your own order ID together. The hosted checkout uses the returned payable amount. For FamPay, that amount can differ by up to ₹0.20 from the requested price to help distinguish concurrent orders; do not silently replace it with your original price. The create-order reference lists the full response and error cases.
2. Send the customer to hosted checkout
After saving that mapping, redirect the browser to https://trustgateway.in plus the returned data.checkout_url. The customer can scan the order QR or use the UPI app handoff. Show your own order reference on your return page so support can trace the attempt, but do not display your API key there.
An open checkout, QR scan, UPI app launch or return to your website is not proof that money reached the receiving account. The checkout can remain pending, expire or need review. Keep your local order in a pending state until a verified result is available.
3. Verify the exact payment on your backend
Call GET /api/v1/orders/status/:order_id with the merchant API key from your server. Do this when the customer returns and whenever an order needs reconciliation. A verified successful response has paid: true and authenticated order details. Compare data.order_id and data.amount with the values you stored at creation; fulfil only the matching local order.
curl 'https://trustgateway.in/api/v1/orders/status/ORDER_ID' \
-H 'X-API-Key: YOUR_SERVER_SIDE_API_KEY'
Your fulfilment transition should be idempotent: repeated status checks or notifications must not ship twice, grant the same licence twice or credit a balance twice. Use a database update guarded by the local order's unpaid state, or a unique fulfilment record. The status endpoint documentation includes response fields and a server-side example.
4. Add webhooks for faster notification
A webhook is optional for the basic flow. If you configure a public HTTPS callback, Trust Gateway can send a payment.success notification after verification. Validate X-Gateway-Signature with your server-side secret, then compare its order ID and payable amount with your database before fulfilment. Keep authenticated status lookup as a recovery path because a callback can be late or missed. Follow the exact signing contract; signing raw JSON is not equivalent.
5. Test these cases before launch
- Pending: open checkout without paying; your website must not deliver anything.
- Success: make a controlled low-value payment and compare the receiving-account record, gateway order ID and your local order.
- Expiry: let an unpaid request expire; create a fresh order instead of recycling its checkout.
- Two buyers: create two same-priced orders near the same time and confirm each payment settles only its own order.
- Repeated checks: refresh the return page and process any repeated webhook; fulfilment should happen once.
- Failure: handle
403,409,429and timeouts without declaring payment successful.
Do not use screenshots, customer-entered UTRs or a redirect URL alone as a success signal. If a gateway cannot confidently match a payment, keep the order pending and investigate with its reference. For route-specific setup, see the Paytm connection guide or the complete payment flow.
Common integration questions
Can I integrate Trust Gateway into a static website?
Yes, if you add a backend or serverless function for creating and checking orders. Browser-only code cannot safely hold your API key.
Can I show the QR inside my own website?
The create-order response includes QR and UPI URLs, but you still need to show the returned exact amount and confirm the order server-side. The hosted checkout handles those display steps for you and is the simpler starting point.
Do I need webhooks?
No. Authenticated status lookup can confirm an order without a webhook. Webhooks can reduce the delay between verification and your app learning the result, but should not be the only recovery mechanism.
How soon will payment show as successful?
Verification timing depends on the receiving connection and whether its payment signal can be matched to this order. Do not promise an instant result or fulfil while the order is pending.
For copyable Node.js and PHP examples, use the developer documentation. For a narrower checklist covering your first API order, read create your first Trust Gateway order.
