Skip to Content
Docs

Add to checkout

Integrate UPI payments using Pay.com.js or the REST API.

You can accept UPI payments in three ways:

  • Universal checkout: Pay.com.js displays UPI in its payment form.
  • Headless checkout: You build your own checkout UI, and Pay.com.js starts the UPI payment when the customer selects it.
  • Server-to-server: You create the charge from your server and redirect the customer to UPI.

Before you start, ask your account manager to enable UPI for your account, then turn it on in the Pay.com dashboard.

Universal checkout

Universal checkout displays UPI in its payment form when the payment session includes it.

  1. 1

    Create a payment session

    On your server, create a payment session with POST /v1/sessions/payment and include "upi" in payment_method_types.

    {
      "amount": 5000,
      "currency": "usd",
      "customer_reference_id": "cust-001",
      "payment_method_types": ["card", "upi"]
    }

    Amounts are in the currency's minor unit, so 5000 is $50.00. customer_reference_id is your own ID for the customer, and it's required. Return the session's client_secret to your page.

  2. 2

    Display the checkout

    On your page, initialize Pay.com.js with the client_secret and mount Universal checkout, as in Universal checkout. No method-specific configuration is required.

  3. 3

    Handle the result

    When the customer selects UPI and clicks Pay, Pay.com.js opens UPI in a new tab. Meanwhile, your page asks the customer to finish there. If they close the tab, Pay.com.js keeps waiting for the payment's outcome.

    When the customer finishes, Pay.com.js calls onSuccess if the payment succeeded, onPending if its result isn't final yet, or onFailure if it failed. Fulfill the order when you receive the charge.succeeded webhook event.

Headless checkout

With Headless checkout, you build your own checkout UI, and Pay.com.js starts the UPI payment when the customer selects it.

  1. 1

    Create a payment session

    Create the payment session on your server as in Universal checkout, with "upi" in payment_method_types, and initialize Pay.com.js with its client_secret.

  2. 2

    Check that UPI is available

    Call checkout.getPaymentMethods(), and show your UPI button only when the list includes it. Don't use checkout.canMakePayments() for this, because it reports only Apple Pay and Google Pay.

    const methods = await checkout.getPaymentMethods()
    const upi = methods.find((method) => method.paymentMethodType === 'upi')
  3. 3

    Start the payment

    When the customer selects UPI, call checkout.headless() with 'upi'.

    try {
      await checkout.headless('upi')
    } catch (error) {
      // onFailure receives the error details too.
    }

    Pay.com.js opens UPI in a new tab. Meanwhile, your page asks the customer to finish there. If they close the tab, Pay.com.js keeps waiting for the payment's outcome.

    When the customer finishes, Pay.com.js calls onSuccess if the payment succeeded, onPending if its result isn't final yet, or onFailure if it failed. Fulfill the order when you receive the charge.succeeded webhook event.

Server-to-server

From your server, a UPI payment takes three steps: create the charge, create a linked authentication session to obtain the redirect URL, and redirect the customer to UPI.

  1. 1

    Create the charge

    Send POST /v1/charges with source_data.type set to "upi". UPI requires the customer's country in source_data.billing_details.address.country. Depending on your account configuration, it can also require the customer's full name, and sometimes their email, phone, and full address (line, city, state, and postal code), so send every billing detail you have.

    {
      "amount": 5000,
      "currency": "usd",
      "source_data": {
        "type": "upi",
        "billing_details": {
          "name": "Rahul Sharma",
          "address": {
            "country": "IN"
          }
        }
      },
      "customer_reference_id": "cust-001",
      "reference": "order-12345",
      "description": "Order #12345"
    }

    The charge's status is requires_authentication until the customer approves the payment.

  2. 2

    Create a linked authentication session

    Send POST /v1/sessions/authentication/linked with the charge's id as resource and the return_url to return the customer to. confirm defaults to true, so Pay.com completes the charge when the customer approves it. Each charge supports one linked authentication session.

    {
      "resource": "chrg_702172227948251136",
      "return_url": "https://your-site.com/payment/complete"
    }
  3. 3

    Redirect the customer

    Send the customer to the session's url with a full-page redirect. After they approve or cancel the payment, UPI redirects them back to your return_url. Fulfill the order when you receive the charge.succeeded webhook event, and handle charge.failed as a canceled or declined payment.

Testing

Test against https://api.sandbox.pay.com/v1 with your sk-pay-com-sandbox- API key. Test transactions never move real funds. See Environments. UPI must be enabled on your sandbox account before you can test. Contact your account manager if it isn't enabled yet.

Sandbox behavior

In the sandbox, Pay.com opens a mock authenticator instead of the real UPI payment page. The mock authenticator shows the payment details and two buttons: Approve and Deny.

  • SDK integration: the mock authenticator opens in a new tab. After you click Approve or Deny, a screen appears while Pay.com processes the result, and Pay.com.js then reports the outcome on your page.
  • Server-to-server integration: the linked authentication session returns a redirect url. Opening this URL in a browser loads the mock authenticator as a full page.

The mock authenticator displays these details:

  • Authentication required for (amount and currency)
  • Consumer (the customer name from billing_details.name)
  • Payment ID (the internal charge reference)
  • Payment method: UPI

In the live environment (sessions and API calls on https://api.pay.com/v1 with an sk-pay-com-live- key), the customer is redirected to the real UPI payment page to scan a QR code or enter their UPI ID and authorize the payment.

Test scenarios

Use the mock authenticator's buttons to simulate each outcome.

ScenarioTest actionExpected result
Successful paymentClick Approve in the mock authenticator"Authorising your payment" processing screen appears, then charge moves to succeeded. charge.succeeded webhook fires. SDK onSuccess callback fires.
Failed paymentClick Deny in the mock authenticator"Authorising your payment" processing screen appears, then charge moves to failed. charge.failed webhook fires. SDK onFailure callback fires with the message: "Your payment method has been declined: The payment was declined by your bank. Please retry or use a different payment method."
Customer abandonsClose the mock authenticator window without clicking either buttonCharge stays in requires_authentication.
Was this page helpful?