{"id":578,"date":"2026-11-06T07:15:00","date_gmt":"2026-11-06T07:15:00","guid":{"rendered":"https:\/\/paymentsetu.com\/blog\/?p=578"},"modified":"2026-11-06T07:15:00","modified_gmt":"2026-11-06T07:15:00","slug":"upi-payment-integration-nodejs","status":"publish","type":"post","link":"https:\/\/paymentsetu.com\/blog\/upi-payment-integration-nodejs\/","title":{"rendered":"UPI Payment Integration in Node.js: Express Example"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">UPI payment integration in node js is straightforward when your server owns the order, amount and payment confirmation flow. This Express example creates a PaymentSetu order, sends the customer to its hosted QR page, verifies the raw webhook body with HMAC, and uses order status as a server-side fallback.<\/p>\n\n\n\n<aside class=\"ap-card\" aria-label=\"PaymentSetu Pro\">\n<span class=\"ap-card__badge\">Recommended<\/span>\n<div class=\"ap-card__body\"><p class=\"ap-card__name\">PaymentSetu Pro<\/p><p class=\"ap-card__best\">Best for growing WooCommerce \/ WHMCS stores and service businesses with up to 1,000 UPI payments a month (most popular)<\/p><ul class=\"ap-card__features\"><li>1,000 credits (1 credit = 1 successful payment verified)<\/li><li>0% commission, direct-to-bank UPI settlement<\/li><li>Dynamic QR, webhooks and API access<\/li><li>WooCommerce and WHMCS plugins<\/li><li>Priority support<\/li><\/ul><\/div>\n<div class=\"ap-card__side\"><p class=\"ap-card__price\">\u20b9999 <small>Most popular \u00b7 \u20b9999 \/ 30 days \u00b7 1,000 verified payments<\/small><\/p><a class=\"ap-card__btn\" href=\"https:\/\/paymentsetu.com\/auth\/register\">Get Pro \u2192<\/a><\/div>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">What you will build<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The completed flow has one checkout route, one webhook route and one fallback check:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>Your Node.js server creates a unique order with the amount in integer paisa.<\/li>\n\n\n<li>PaymentSetu returns a <code>payment_url<\/code> for the order\u2019s hosted QR checkout.<\/li>\n\n\n<li>The customer pays by UPI directly into your connected Paytm Business or PhonePe Business merchant account.<\/li>\n\n\n<li>PaymentSetu matches the payment and sends an HMAC-signed JSON webhook.<\/li>\n\n\n<li>Your server validates the event, checks the order and amount, then marks the order paid once.<\/li>\n\n\n<li>A return page or scheduled job can call <code>GET \/api\/order_status\/{client_txn_id}<\/code> if it needs to reconcile an order.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">PaymentSetu is a payment verification service, not a payment gateway. It does not hold the money; the customer pays your own connected merchant account, while PaymentSetu matches the transaction to the order and notifies your application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The important implementation detail is the webhook parser. Express\u2019s normal JSON parser gives you a JavaScript object, but HMAC verification must use the exact bytes received over the network. Express documents <code>express.raw()<\/code> as the middleware that puts the request body in a <code>Buffer<\/code>, which is what the webhook route needs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Set up the Node.js project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the API key and webhook secret must stay on your server, while the browser only receives a payment URL and an order identifier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use Node.js 18 or newer if you want the built-in <code>fetch()<\/code> API. Node\u2019s documentation lists <code>fetch()<\/code> as available without the experimental flag from Node 18. Install Express and create an environment file outside source control:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir upi-node-checkout\ncd upi-node-checkout\nnpm init -y\nnpm install express<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set the project to use ES modules by adding this field to <code>package.json<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"type\": \"module\",\n  \"scripts\": {\n    \"start\": \"node server.js\"\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>.env<\/code> through your process manager or shell. The example reads environment variables directly, so use a secrets manager or a deployment setting if your host provides one:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PAYMENTSETU_API_KEY=replace-with-your-api-key\nPAYMENTSETU_WEBHOOK_SECRET=replace-with-your-webhook-secret\nPAYMENTSETU_API_BASE_URL=https:\/\/paymentsetu.com\/api\nPORT=3000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/paymentsetu.com\/developer\/api-documentation\">PaymentSetu API documentation<\/a> is the source of truth for the credentials and webhook values shown in your account. If your account uses the API key itself to sign webhooks, set <code>PAYMENTSETU_WEBHOOK_SECRET<\/code> to that same server-side value. Never put either secret in frontend JavaScript, a mobile bundle or a public repository.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You also need an orders table or repository with at least these fields:<\/p>\n\n\n\n<figure class=\"wp-block-table ap-table\"><table><thead><tr><th>Field<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr class=\"ap-win\"><td><code>order_id<\/code><\/td><td>Your unique reference, also sent to PaymentSetu<\/td><\/tr><tr><td><code>amount_paise<\/code><\/td><td>The server-calculated amount expected for the order<\/td><\/tr><tr><td><code>status<\/code><\/td><td>Start at <code>pending<\/code>, then transition to <code>paid<\/code> once<\/td><\/tr><tr><td><code>txn_utr<\/code><\/td><td>The UTR recorded from the verified payment event<\/td><\/tr><tr><td><code>webhook_event_id<\/code><\/td><td>A unique event or transaction reference for idempotency<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For the snippets below, <code>orders.createPending<\/code>, <code>orders.findById<\/code>, <code>orders.markPaidOnce<\/code> and <code>fulfilOrder<\/code> represent your database and fulfilment layer. Replace them with Prisma, Sequelize, Knex, MongoDB or your own repository methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Create an order with fetch<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the same server-generated reference links the customer\u2019s QR payment, webhook and local order record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Calculate the amount from your product or cart data on the server. Do not trust a hidden form field or a price sent by the browser. PaymentSetu expects an integer amount in paisa, so \u20b9249 becomes <code>24900<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>server.js<\/code> with the API helper and checkout route below. The route accepts an internal <code>cartId<\/code>; it does not accept an amount from the customer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import express from 'express';\n\nconst app = express();\nconst port = Number(process.env.PORT || 3000);\nconst apiKey = process.env.PAYMENTSETU_API_KEY;\nconst webhookSecret = process.env.PAYMENTSETU_WEBHOOK_SECRET || apiKey;\nconst apiBaseUrl = process.env.PAYMENTSETU_API_BASE_URL || 'https:\/\/paymentsetu.com\/api';\n\nif (!apiKey || !webhookSecret) {\n  throw new Error('PaymentSetu credentials are not configured');\n}\n\nasync function paymentSetuRequest(path, options = {}) {\n  const response = await fetch(`${apiBaseUrl}${path}`, {\n    ...options,\n    headers: {\n      Accept: 'application\/json',\n      Authorization: `Bearer ${apiKey}`,\n      ...(options.body ? { 'Content-Type': 'application\/json' } : {}),\n      ...options.headers\n    }\n  });\n\n  const text = await response.text();\n  let body;\n\n  try {\n    body = text ? JSON.parse(text) : {};\n  } catch {\n    throw new Error(`PaymentSetu returned non-JSON (${response.status})`);\n  }\n\n  if (!response.ok || body.status === false) {\n    throw new Error(body.msg || `PaymentSetu request failed (${response.status})`);\n  }\n\n  return body;\n}\n\n\/\/ Replace this with your real product, cart and database lookup.\nasync function loadCartFromDatabase(cartId) {\n  if (!cartId) return null;\n\n  return {\n    cartId,\n    orderId: `ORDER-${cartId}-${Date.now()}`,\n    amountPaise: 24900,\n    customerName: 'Asha Sharma',\n    customerEmail: 'asha@example.com',\n    customerMobile: '9876543210'\n  };\n}\n\n\/\/ JSON parsing is scoped to this route, so the webhook can keep its raw body.\napp.post('\/checkout\/create-order', express.json(), async (req, res, next) =&gt; {\n  try {\n    const cart = await loadCartFromDatabase(req.body.cartId);\n    if (!cart) return res.status(404).json({ error: 'Cart not found' });\n\n    \/\/ Save pending status before the external request.\n    \/\/ await orders.createPending(cart);\n\n    const result = await paymentSetuRequest('\/create_order', {\n      method: 'POST',\n      body: JSON.stringify({\n        order_id: cart.orderId,\n        amount: cart.amountPaise,\n        redirect_url: 'https:\/\/example.com\/payment-return',\n        customer_name: cart.customerName,\n        customer_email: cart.customerEmail,\n        customer_mobile: cart.customerMobile,\n        remarks: `Order ${cart.orderId}`\n      })\n    });\n\n    \/\/ Return only what the browser needs. Keep the bearer key on this server.\n    res.status(201).json({\n      orderId: cart.orderId,\n      paymentUrl: result.payment_url\n    });\n  } catch (error) {\n    next(error);\n  }\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your frontend can POST <code>{ \"cartId\": \"cart-123\" }<\/code> to <code>\/checkout\/create-order<\/code> and redirect the browser to the returned <code>paymentUrl<\/code>. The hosted page displays the QR for that order. Do not treat the redirect back to <code>redirect_url<\/code> as proof of payment; a customer can close the tab, revisit the URL or return before your server has received the webhook.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: your database has a pending order, the API response has <code>status: true<\/code> and a <code>payment_url<\/code>, and no API key appears in the browser response or page source.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Put the raw-body webhook before JSON parsing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: parsing JSON and serialising it again can change whitespace, escaping or key order. Even though the visible data is the same, the bytes are different and the HMAC will not match.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Register the webhook route with <code>express.raw({ type: 'application\/json' })<\/code>. It must run before a global <code>app.use(express.json())<\/code> middleware. The current Express API documents the <code>verify<\/code> callback and raw <code>Buffer<\/code> behaviour in its <a href=\"https:\/\/expressjs.com\/en\/api.html#express.raw\" target=\"_blank\" rel=\"noopener\"><code>express.raw()<\/code> reference<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { createHmac, timingSafeEqual } from 'node:crypto';\n\nfunction sameHexDigest(expectedHex, receivedHex) {\n  if (!\/^[a-f0-9]{64}$\/i.test(receivedHex)) return false;\n\n  const expected = Buffer.from(expectedHex, 'hex');\n  const received = Buffer.from(receivedHex, 'hex');\n\n  return expected.length === received.length &amp;&amp; timingSafeEqual(expected, received);\n}\n\nfunction verifyPaymentSetuWebhook(rawBody, timestamp, receivedSignature) {\n  if (!timestamp || !\/^\\d+$\/.test(timestamp)) return false;\n\n  \/\/ Reject stale signed requests. Keep the window aligned with your API contract.\n  if (Math.abs(Date.now() \/ 1000 - Number(timestamp)) &gt; 300) return false;\n\n  const signedMessage = `${timestamp}.${rawBody.toString('utf8')}`;\n  const expectedSignature = createHmac('sha256', webhookSecret)\n    .update(signedMessage)\n    .digest('hex');\n\n  return sameHexDigest(expectedSignature, receivedSignature);\n}\n\n\/\/ This route must appear before app.use(express.json()).\napp.post(\n  '\/webhooks\/paymentsetu',\n  express.raw({ type: 'application\/json', limit: '100kb' }),\n  async (req, res, next) =&gt; {\n    try {\n      const rawBody = req.body;\n      const timestamp = req.get('X-PaymentSetu-Timestamp') || '';\n      const signature = req.get('X-PaymentSetu-Signature') || '';\n\n      if (!Buffer.isBuffer(rawBody)) {\n        return res.status(400).json({ error: 'Expected a raw JSON body' });\n      }\n\n      if (!verifyPaymentSetuWebhook(rawBody, timestamp, signature)) {\n        return res.status(401).json({ error: 'Invalid webhook signature' });\n      }\n\n      let event;\n      try {\n        event = JSON.parse(rawBody.toString('utf8'));\n      } catch {\n        return res.status(400).json({ error: 'Invalid JSON' });\n      }\n\n      const orderId = String(event.order_id || '');\n      const status = String(event.status || '').toLowerCase();\n      const amountPaise = Number(event.amount);\n      const utr = String(event.txn_utr || '');\n      const eventId = String(event.event_id || event.txn_utr || '');\n\n      if (!orderId || !Number.isInteger(amountPaise) || !utr) {\n        return res.status(400).json({ error: 'Incomplete payment event' });\n      }\n\n      const order = await orders.findById(orderId);\n      if (!order || order.amountPaise !== amountPaise) {\n        return res.status(400).json({ error: 'Order or amount does not match' });\n      }\n\n      if (status === 'success') {\n        \/\/ This database operation must be atomic and safe to call twice.\n        const changed = await orders.markPaidOnce(orderId, {\n          utr,\n          eventId,\n          amountPaise\n        });\n\n        if (changed) {\n          await fulfilOrder(orderId);\n        }\n      }\n\n      return res.status(200).json({ status: true });\n    } catch (error) {\n      next(error);\n    }\n  }\n);\n\napp.use(express.json());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The event is parsed only after the signature passes. The <a href=\"https:\/\/nodejs.org\/api\/crypto.html\" target=\"_blank\" rel=\"noopener\">Node.js crypto documentation<\/a> describes <code>createHmac()<\/code> and <code>timingSafeEqual()<\/code>; the latter requires buffers of equal length, which is why the helper checks that the received value is a 64-character hexadecimal SHA-256 digest first.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The example assumes that the signed message is <code>timestamp.raw_json_body<\/code>, matching the PaymentSetu webhook contract. Use the exact header names and digest format shown in your account\u2019s API documentation. If the documented format includes a prefix such as <code>sha256=<\/code>, remove only that documented prefix before the length check; do not trim or re-encode the payload.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Verify the order and mark it paid once<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: a valid signature proves the message was signed with the shared secret, but your application must still prove that the event belongs to the expected local order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The handler should apply these checks in order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>Confirm the body is raw bytes and the timestamp is within the accepted window.<\/li>\n\n\n<li>Verify the HMAC before reading payment fields.<\/li>\n\n\n<li>Parse the JSON and find the local order by your saved <code>order_id<\/code>.<\/li>\n\n\n<li>Compare the event amount with the server-calculated amount in paisa.<\/li>\n\n\n<li>Require a successful status and a transaction UTR before fulfilment.<\/li>\n\n\n<li>Record the UTR or event ID with a unique database constraint.<\/li>\n\n\n<li>Change <code>pending<\/code> to <code>paid<\/code> atomically, then fulfil only if that transition changed one row.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><code>markPaidOnce()<\/code> should never overwrite a paid order with a different amount or UTR. If the same signed event is delivered again, it should return <code>false<\/code>; your route can acknowledge it with HTTP 200 without sending a second email, download, booking confirmation or account credit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The webhook is the normal confirmation path. PaymentSetu matches the UTR and amount to the dynamic QR or order, then sends the signed notification. A browser message such as \u201cpayment submitted\u201d and a screenshot are not substitutes for the server-side checks above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Add an order-status fallback<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: a fallback lets your return page or a reconciliation worker ask the API about an order when the customer returns before your webhook handler has completed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call the status endpoint from Node.js, never from browser code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async function getPaymentStatus(clientTxnId) {\n  return paymentSetuRequest(\n    `\/order_status\/${encodeURIComponent(clientTxnId)}`,\n    { method: 'GET' }\n  );\n}\n\nasync function reconcilePendingOrder(order) {\n  const result = await getPaymentStatus(order.orderId);\n\n  \/\/ Map the documented response fields to your local status model.\n  \/\/ Do the same amount, UTR and idempotency checks as the webhook path.\n  const payment = result.data || result;\n  const status = String(payment.status || '').toLowerCase();\n\n  if (status !== 'success') return { state: 'pending' };\n\n  const amountPaise = Number(payment.amount);\n  const utr = String(payment.txn_utr || '');\n  if (amountPaise !== order.amountPaise || !utr) {\n    return { state: 'review' };\n  }\n\n  const changed = await orders.markPaidOnce(order.orderId, {\n    amountPaise,\n    utr,\n    eventId: utr\n  });\n\n  if (changed) await fulfilOrder(order.orderId);\n  return { state: 'paid' };\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Keep the response-to-model mapping in one adapter because the API response shape can vary by integration version. Do not mark an order paid just because the HTTP request returned 200; inspect the documented payment status and match the identifier, amount and UTR to your local record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also call <code>GET \/api\/check_credits<\/code> with the same bearer authentication from an admin-only health check. The Pro plan includes 1,000 credits, and one credit represents one successful payment verified. PaymentSetu Pro is <strong>\u20b9999 per 30 days<\/strong>, with 0% commission on payments, dynamic QR, webhooks, API access, a unified dashboard, real-time notifications and priority support. See the current <a href=\"https:\/\/paymentsetu.com\/#pricing\">PaymentSetu pricing<\/a> before choosing a plan.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Test the complete Express flow<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: an integration is complete only when creation, QR payment, signed delivery, duplicate delivery and reconciliation all produce the expected local state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a separate test order and walk through this checklist:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>POST a cart ID to <code>\/checkout\/create-order<\/code> and confirm that your database stores <code>pending<\/code> before the API call.<\/li>\n\n\n<li>Confirm that the response contains a <code>paymentUrl<\/code> and that the API key is absent from it.<\/li>\n\n\n<li>Open the hosted page, scan the QR and complete the UPI payment.<\/li>\n\n\n<li>Confirm the webhook endpoint receives <code>X-PaymentSetu-Timestamp<\/code> and <code>X-PaymentSetu-Signature<\/code>.<\/li>\n\n\n<li>Confirm the route sees <code>Buffer.isBuffer(req.body) === true<\/code> before JSON parsing.<\/li>\n\n\n<li>Confirm a valid event matches the local order ID and integer paisa amount.<\/li>\n\n\n<li>Confirm the order becomes paid once and stores the UTR.<\/li>\n\n\n<li>Replay the same signed request in a safe test environment; confirm no second fulfilment occurs.<\/li>\n\n\n<li>Alter one byte or use the wrong secret; confirm the endpoint returns 401 and changes no order.<\/li>\n\n\n<li>Call the order-status endpoint for a pending test record and confirm your fallback uses the same idempotent update.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Do not log the API key, webhook secret or complete payment payload in production logs. Log a request ID, local order ID, event ID and high-level outcome instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Node.js webhook integrations<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">The signature is always invalid<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check that the webhook route is before <code>express.json()<\/code>, <code>req.body<\/code> is a <code>Buffer<\/code>, and the HMAC input is exactly <code>timestamp + '.' + raw body<\/code>. Check the secret, header spelling, timestamp units and digest encoding. Do not call <code>JSON.stringify(JSON.parse(rawBody))<\/code> before hashing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The API rejects the amount<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Send integer paisa from trusted server-side cart data. \u20b9100 is <code>10000<\/code>; a formatted value such as <code>\u20b9100<\/code>, <code>100.00<\/code> or a client-supplied amount should not be sent as the order amount.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The customer returns but the order is still pending<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The return URL is navigation, not confirmation. Inspect webhook delivery and server logs, then call <code>GET \/api\/order_status\/{client_txn_id}<\/code> from your backend. Keep the local order pending until a trusted response matches the saved order and amount.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The same order is fulfilled twice<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Make the paid transition conditional on <code>status = pending<\/code> and give the UTR or event ID a unique constraint. Return success for a repeated valid event after the first transaction has already been recorded.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>req.body<\/code> is an object instead of a Buffer<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The webhook request was parsed by JSON middleware first, or its <code>Content-Type<\/code> did not match <code>application\/json<\/code>. Move the route-level <code>express.raw()<\/code> before the global parser and confirm that the sender uses the content type expected by the route.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use Node.js fetch for the PaymentSetu API?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Node\u2019s built-in <code>fetch()<\/code> is available without the experimental flag from Node 18. Keep the call on your server so the bearer API key is never sent to the browser.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is PaymentSetu a payment gateway for Node.js?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. PaymentSetu is a payment verification service. The customer pays directly into your connected Paytm Business or PhonePe Business merchant account, and PaymentSetu matches the payment to your order before sending the webhook.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why must Express read the raw webhook body?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The signature is calculated from the exact request bytes. Parsing JSON and serialising it again can alter whitespace or key order, so calculate the HMAC from the <code>Buffer<\/code> created by <code>express.raw()<\/code> and parse only after the signature is valid.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should my return URL mark an order paid?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A return URL is controlled by the customer\u2019s browser and can arrive before server-side verification. Use the verified, amount-matched webhook as the normal confirmation path and the server-side order-status endpoint for reconciliation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to build the QR image in Node.js?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>POST \/api\/create_order<\/code> returns a <code>payment_url<\/code> for the hosted QR checkout. Your server can redirect the customer to that URL, while your webhook handles the verified order update.<\/p>\n\n\n\n<aside class=\"ap-cta\" aria-label=\"Add verified UPI checkout\"><div class=\"ap-cta__content\"><p class=\"ap-cta__eyebrow\">Start with Node.js<\/p><p class=\"ap-cta__title\">Add verified UPI checkout<\/p><p class=\"ap-cta__text\">Create dynamic QR orders and confirm them with signed Express webhooks.<\/p><\/div><a class=\"ap-cta__btn\" href=\"https:\/\/paymentsetu.com\/auth\/register\">Create your account<\/a><\/aside>\n\n\n\n<p class=\"wp-block-paragraph\">DONE upi-payment-integration-nodejs words=1891<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Can I use Node.js fetch for the PaymentSetu API?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Node\u2019s built-in fetch() is available without the experimental flag from Node 18. Keep the call on your server so the bearer API key is never sent to the browser.\"}}, {\"@type\": \"Question\", \"name\": \"Is PaymentSetu a payment gateway for Node.js?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. PaymentSetu is a payment verification service. The customer pays directly into your connected Paytm Business or PhonePe Business merchant account, and PaymentSetu matches the payment to your order before sending the webhook.\"}}, {\"@type\": \"Question\", \"name\": \"Why must Express read the raw webhook body?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"The signature is calculated from the exact request bytes. Parsing JSON and serialising it again can alter whitespace or key order, so calculate the HMAC from the Buffer created by express.raw() and parse only after the signature is valid.\"}}, {\"@type\": \"Question\", \"name\": \"Should my return URL mark an order paid?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A return URL is controlled by the customer\u2019s browser and can arrive before server-side verification. Use the verified, amount-matched webhook as the normal confirmation path and the server-side order-status endpoint for reconciliation.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need to build the QR image in Node.js?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. POST \/api\/create_order returns a payment_url for the hosted QR checkout. Your server can redirect the customer to that URL, while your webhook handles the verified order update. DONE upi-payment-integration-nodejs words=1891\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Learn upi payment integration in node js with Express, order creation, hosted QR checkout, raw-body HMAC webhooks and status fallback for your site.","protected":false},"author":1,"featured_media":577,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[29],"tags":[110,147,130,30,28],"class_list":["post-578","post","type-post","status-publish","format-standard","has-post-thumbnail","category-upi-payment-verification","tag-api-integration","tag-express","tag-nodejs","tag-upi","tag-webhooks","cs-entry"],"_links":{"self":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts\/578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/comments?post=578"}],"version-history":[{"count":1,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts\/578\/revisions"}],"predecessor-version":[{"id":787,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts\/578\/revisions\/787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/media\/577"}],"wp:attachment":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/media?parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/categories?post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/tags?post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}