Create SDK Order

Create Order SDK is specifically used to generate a token when your backend is in Java and you’re integrating with any PhonePe Mobile SDK.

Request

You can use the CreateSdkOrderRequest Builder to create the request. The following attributes can be configured in the request:

Parameter NameData TypeMandatory
(Yes/No)
Description
merchantOrderIdStringYesUnique merchant order id generated by merchant.
amountLongYesOrder amount in paisa
constraintsListYesDifferent type of constraints that must be applied to the payment.
Sample Request
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.models.request.AccountConstraint;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
import com.phonepe.sdk.pg.payments.v2.models.request.CreateSdkOrderRequest;
import com.phonepe.sdk.pg.payments.v2.models.response.CreateSdkOrderResponse;
import java.util.Arrays;
 
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = <clientVersion>;  //insert your client version here
Env env = Env.SANDBOX;      //change to Env.PRODUCTION when you go live
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = "<merchantOrderID>";
long amount = 100;
String accountNumber = "420200001892";
String ifsc = "ICIC0000041";
 
AccountConstraint constraints = AccountConstraint.builder()
        .ifsc(ifsc)
        .accountNumber(accountNumber)
        .build();
 
CreateSdkOrderRequest createSdkOrderRequest = CreateSdkOrderRequest.CustomCheckoutBuilder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .constraints(Arrays.asList(constraints))
        .build();
 
CreateSdkOrderResponse createSdkOrderResponse = customCheckoutClient.createSdkOrder(createSdkOrderRequest);
String token = createSdkOrderResponse.getToken();

Response

The function returns a CreateOrderResponse object with the following properties:

Parameters
Parameter NameData TypeDescription
orderIdStringOrder ID generated by PhonePe PG.
stateStringState of the Order. Initially it will be PENDING.
expireAtLongExpiry time in epoch.
tokenStringToken used to access the PG Page.
Is this article helpful?