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.

You can use CreateSdkOrderRequest.StandardCheckoutBuilder() to create the request. You can pass the following attributes.

Parameter NameData TypeMandatory
(Yes/No)
DescriptionConstraints
merchantOrderIdStringYesUnique order ID assigned by you.Max Length = 63 characters
amountIntegerYesOrder amount in paisa.Minimum value: 100 (in paisa)
redirectUrlStringYesURL 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
})

The function returns a CreateOrderResponse object with the following properties:

PropertyData TypeDescription
orderIdStringOrder ID generated by PhonePe PG.
stateStringState of the Order. Initially it will be PENDING.
expireAtNumberExpiry time in epoch.
tokenStringToken used by the merchant UI to initiate order.

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.

Is this article helpful?