Initiate Payment

Pay

This method is used to initiate a payment via the PhonePe PG.

Merchants can use the StandardCheckoutPayRequest.builder() to create the request and the following are the attributes that merchant can pass.

Standard checkout Pay Request Builder

Builds Pay Page request.

Attributes

AttributeData TypeMandatoryDescriptionConstraints
merchantOrderIdStringYesThe unique order ID assigned by the merchant.1. merchantOrderId length should be less than 63 characters
2. No Special characters allowed except underscore “_” and hyphen “-“
amountNumberYesOrder amount in paisa.Minimum value = 100 (in paise)
redirectUrlStringNoURL where user will be redirected after success/failed payment.

Use the above information as shown in the example below

Example :

import { StandardCheckoutClient, Env, MetaInfo, StandardCheckoutPayRequest } from 'pg-sdk-node'; import { randomUUID } from 'crypto'; const clientId = "<clientId>"; const clientSecret = "<clientSecret>"; const clientVersion = 1; //insert your client version here const env = Env.SANDBOX; //change to Env.PRODUCTION when you go live const client = StandardCheckoutClient.getInstance(clientId, clientSecret, clientVersion, env); const merchantOrderId = randomUUID(); const amount = 100; const redirectUrl = "https://www.merchant.com/redirect"; const metaInfo = MetaInfo.builder() .udf1("udf1") .udf2("udf2") .build(); const request = StandardCheckoutPayRequest.builder() .merchantOrderId(merchantOrderId) .amount(amount) .redirectUrl(redirectUrl) .metaInfo(metaInfo) .build(); client.pay(request).then((response)=> { const checkoutPageUrl = response.redirectUrl; })

Returns :

The function returns a StandardCheckoutPayResponse object with the following properties:

StandardCheckoutPayResponse properties

Here is the response property table for the given model:

AttributeData TypeDescription
stateStringState of the order.
Expected value is PENDING
redirectUrlStringThe URL for the PG Standard Checkout (merchant is supposed to redirect user to complete payment)
orderIdStringPG generated internal order id
expireAtNumberOrder expiry date in epoch