This is specifically used to generate a order token when the user’s backend is in NodeJs and they are using any Mobile SDK.
SDK setup
Used to fetch the Order token required by the frontend app to init pay requests.
Merchants can use the CreateSdkOrderRequest.StandardCheckoutBuilder()
to create the request and the following are the attributes that merchant can pass.
SDK Order Request Builder
Builds SDK order request.
Attributes
Parameter name | Data Type | Mandatory | Description | Constraints |
---|---|---|---|---|
merchantOrderId | String | Yes | Unique merchant id generated by merchant | Max Length = 63 characters |
amount | Number | Yes | Amount in paisa | Minimum value = 100 (in paise) |
redirectUrl | String | Yes | The URL to which the user should be redirected after the payment is completed |
Example :
import { StandardCheckoutClient, Env, CreateSdkOrderRequest } 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 = 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
})
Returns :
The function returns a CreateOrderResponse
object with the following properties:
Property | Data Type | Description |
---|---|---|
orderId | String | Order ID generated by PhonePe |
state | String | State of the Order. Initially it will be PENDING |
expireAt | Number | Expiry time in epoch |
token | String | Token to be used by the merchant app to initiate order |