Create Order with Node.js SDK
Create SDK Order is to generate an order token when your backend is in Node.js and you’re integrating with any mobile app. This lets your frontend app get the Order token it needs to start the payment requests.
Request
You can use CreateSdkOrderRequest.StandardCheckoutBuilder() to create the request. You can pass the following attributes.
| Parameter Name | Data Type | Mandatory (Yes/No) | Description | Constraints |
merchantOrderId | String | Yes | Unique order ID assigned by you. | Max Length = 63 characters |
amount | Integer | Yes | Order amount in paisa. | Minimum value: 100 (in paisa) |
redirectUrl | String | Yes | URL to which the user will be redirected after the payment (success or failure). |
Sample Request
import { StandardCheckoutClient, Env, CreateSdkOrderRequest } 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 = 1000;
const redirectUrl = "https://redirectUrl.com";
const request = CreateSdkOrderRequest.StandardCheckoutBuilder()
.merchantOrderId(merchantOrderId)
.amount(amount)
.redirectUrl(redirectUrl)
.build();
client.createSdkOrder(request).then((response) => {
const token = response.token
})Response
The function returns a CreateOrderResponse object with the following properties:
| Property | Data Type | Description |
orderId | String | Order ID generated by PhonePe PG. |
state | String | State of the Order. Initially it will be PENDING. |
expireAt | Number | Expiry time in epoch. |
| token | String | Token used by the merchant UI to initiate order. |
What’s Next?
Now that you have understood how to generate a payment token when the backend is built in Node.js and integrated with any PhonePe Mobile SDK. Let’s proceed to check the status of the order.