Initiate Payment with Node.js SDK
The Initiate Payment step allows you to start a payment transaction by creating a payment request with essential details like order ID, amount, and redirect URL. This request prepares the transaction on PhonePe’s platform and generates a redirect URL where users complete their payment securely.
Request
Use to create the payment request. Below are the key attributes you can set:StandardCheckoutPayRequest.build_request()
| Parameter Name | Data Type | Mandatory (Yes/No) | Description | Constraints |
| String | Yes | Unique order ID assigned by you | Max length: 63 characters, no special characters except “_” and “-” |
| Long | Yes | Order amount in paisa | Minimum value: 100 (in paisa) |
metaInfo | Object | No | Meta information is defined by you to store additional information. The same data will be returned in status and callback response. | |
metaInfo.udf1-5 | String | No | Optional details you can add for more information. | Maximum length = 256 characters |
| String | No | URL to which the user will be redirected after the payment (success or failure) | |
| expireAfter | Long | No | Set a orders expiry time in seconds. | |
| message | String | No | Payment message shown in APP for collect requests. |
Sample Request
import { StandardCheckoutClient, Env, MetaInfo, StandardCheckoutPayRequest } from 'pg-sdk-node';
import { randomUUID } from 'crypto';
const clientId = "<clientId>";
const clientSecret = "<clientSecret>";
const clientVersion = <clientVersion>; //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; // Amount in paise (100 = ₹1.00)
const metaInfo = MetaInfo.builder()
.udf1("udf1")
.udf2("udf2")
.udf3("udf3")
.build();
const orderRequest = CreateSdkOrderRequest.StandardCheckoutBuilder()
.merchantOrderId(merchantOrderId)
.amount(amount)
.metaInfo(metaInfo)
.redirectUrl("https://www.merchant.com/redirect")
.expireAfter(3600)
.message("Message that will be shown for UPI collect transaction")
.build();
client.pay(request).then((response)=> {
const checkoutPageUrl = response.redirectUrl;
})Response
The function returns a StandardCheckoutPayResponse object with the following properties:
| Attribute | Data Type | Description |
state | String | State of the order created, expected value is PENDING. |
redirect_url | String | URL for the PhonePe Payment Gateway Standard Checkout page. This is the URL to which the user should be redirected for payment. |
order_id | String | A unique internal order ID generated by PhonePe PG. |
expire_at | String | Order expiry timestamp in epoch. |
What’s Next?
After using the pay method to initiate a payment via the PhonePe PG, you can create a payment request and start the payment process. The next step is to create the order SDK.
Proceed to the next section to learn how to Create Order SDK .