Developer guide

Add UPI checkout to your website or online store. Customer money goes straight to your UPI ID. Trust Pay never holds funds.

How it works

  1. Your site creates an order (amount in paise, your order number).
  2. The customer pays with any UPI app (intent button on mobile, QR on desktop) and taps I have paid. Their name and the UPI reference (last 4 or all 12 digits) are optional.
  3. The order becomes submitted. You get a payment.submitted webhook and a notification in the Trust Pay app.
  4. You check your bank/UPI app and tap Money received (or use Got paid? in the app to find the order by amount). The order becomes paid and you get a payment.paid webhook. Ship the order now.
Only treat an order as paid after payment.paid. submitted is the customer's claim until you confirm it.

1. Pay button (no backend needed)

Paste on any page. Use your public key from App → Account → Website.

<script src="https://pay.sarvasriconsultancy.com/trustpay.js"></script>

<button onclick="TrustPay.pay({
  key: 'tp_pub_xxxxxxxx',
  amount: 49900,                 // paise → ₹499.00
  receipt: 'ORDER-1001',         // your order number
  description: 'Order #1001',
  customer: { name: 'Ravi', phone: '9876543210', email: 'ravi@example.com' },
  onPending: function (p) { /* customer paid, you are verifying */ },
  onSuccess: function (p) { /* you confirmed: p.id, p.status === 'paid' */ },
  onFailure: function (p) { /* marked not received / expired */ },
  onClose:   function (p) { }
})">Pay ₹499</button>

<!-- Or with no JavaScript at all: -->
<button data-trustpay-key="tp_pub_xxxxxxxx" data-amount="49900" data-receipt="ORDER-1001">Pay ₹499</button>

Because the amount is set in the browser, a customer could change it. Always compare the paid amount with your order total (it is in the webhook and in the app) before shipping. For full protection, use server orders.

2. Server-created orders (recommended for online stores)

Create the order on your server with HTTP Basic auth public_key:secret_key. Never put the secret key in browser code.

curl -X POST https://pay.sarvasriconsultancy.com/api/v1/orders \
  -u tp_pub_xxxx:tp_sec_xxxx \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 129900,
    "receipt": "ORDER-1002",
    "description": "Order #1002",
    "customer": { "name": "Asha", "phone": "9876543210", "email": "asha@example.com" },
    "callback_url": "https://yourshop.com/order/1002/thank-you"
  }'

Response:

{
  "id": "pay_8kQmT3xR...",
  "amount": 1299, "amount_paise": 129900, "currency": "INR",
  "status": "created",
  "receipt": "ORDER-1002",
  "checkout_url": "https://pay.sarvasriconsultancy.com/pay/pay_8kQmT3xR...",
  "expires_at": 1764060000000, ...
}

Then either redirect the customer to checkout_url (they come back to callback_url?trustpay_payment_id=…&trustpay_status=…&receipt=…), or open it as a pop-up on your page:

<script src="https://pay.sarvasriconsultancy.com/trustpay.js"></script>
<script>
  TrustPay.open('pay_8kQmT3xR...', {
    onPending: function () { location.href = '/order/1002/pending' },
    onSuccess: function () { location.href = '/order/1002/thank-you' }
  });
</script>

Node.js

const auth = Buffer.from(process.env.TP_PUBLIC + ':' + process.env.TP_SECRET).toString('base64');
const r = await fetch('https://pay.sarvasriconsultancy.com/api/v1/orders', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: 'Basic ' + auth },
  body: JSON.stringify({ amount: 129900, receipt: 'ORDER-1002', callback_url: 'https://yourshop.com/thanks' })
});
const order = await r.json();   // redirect to order.checkout_url

PHP

$ch = curl_init('https://pay.sarvasriconsultancy.com/api/v1/orders');
curl_setopt_array($ch, [
  CURLOPT_USERPWD => TP_PUBLIC . ':' . TP_SECRET,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
  CURLOPT_POSTFIELDS => json_encode(['amount' => 129900, 'receipt' => 'ORDER-1002', 'callback_url' => 'https://yourshop.com/thanks']),
  CURLOPT_RETURNTRANSFER => true,
]);
$order = json_decode(curl_exec($ch), true);
header('Location: ' . $order['checkout_url']);

3. Webhooks

Set your webhook URL in App → Account → Website. We send a POST with JSON for each event:

Headers:
  X-TrustPay-Event: payment.paid
  X-TrustPay-Signature: <hex HMAC-SHA256 of the raw body, key = your secret key>

Body:
{
  "event": "payment.paid",          // payment.submitted | payment.paid | payment.rejected
  "created_at": 1764058000000,
  "payment": { "id": "pay_...", "amount_paise": 129900, "status": "paid", "receipt": "ORDER-1002", "utr": "431256789012", ... }
}

Verify the signature before trusting it. Reply with any 2xx status. Failed deliveries are retried after 10 s, 1 min, 5 min and 30 min.

// Node.js (Express) — use the RAW body
app.post('/trustpay-webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const sig = crypto.createHmac('sha256', process.env.TP_SECRET).update(req.body).digest('hex');
  if (sig !== req.get('X-TrustPay-Signature')) return res.sendStatus(401);
  const { event, payment } = JSON.parse(req.body);
  if (event === 'payment.paid') markOrderPaid(payment.receipt, payment.amount_paise, payment.utr);
  res.sendStatus(200);
});

// PHP
$raw = file_get_contents('php://input');
$sig = hash_hmac('sha256', $raw, TP_SECRET);
if (!hash_equals($sig, $_SERVER['HTTP_X_TRUSTPAY_SIGNATURE'] ?? '')) { http_response_code(401); exit; }
$data = json_decode($raw, true);
if ($data['event'] === 'payment.paid') { /* mark order paid */ }

Check order status

curl https://pay.sarvasriconsultancy.com/api/v1/orders/pay_8kQmT3xR... -u tp_pub_xxxx:tp_sec_xxxx

WooCommerce (WordPress)

Ask Sarvasri Consultancy Pvt. Ltd. for the Trust Pay for WooCommerce plugin zip. Install it from WordPress → Plugins → Add New → Upload, then go to WooCommerce → Settings → Payments → Trust Pay UPI, and paste your keys. Set your webhook URL to https://yourshop.com/?wc-api=trustpay.

Reference

StatusMeaning
createdWaiting for the customer to pay
submittedCustomer says they paid (utr / utr_last4 may be empty); waiting for your confirmation
paidYou confirmed the money arrived — fulfil the order
rejectedYou marked it as not received
expiredNot paid in time (website orders: 30 minutes, payment links: 7 days)

Limits: ₹1 to ₹1,00,000 per order. Need the Business plan. Support: support@sarvasriconsultancy.com