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
Attribute | Data Type | Mandatory | Description | Constraints |
---|---|---|---|---|
merchantOrderId | String | Yes | The 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 “-“ |
amount | Number | Yes | Order amount in paisa. | Minimum value = 100 (in paise) |
redirectUrl | String | No | URL 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:
Attribute | Data Type | Description |
---|---|---|
state | String | State of the order. Expected value is PENDING |
redirectUrl | String | The URL for the PG Standard Checkout (merchant is supposed to redirect user to complete payment) |
orderId | String | PG generated internal order id |
expireAt | Number | Order expiry date in epoch |