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 Name | Data Type | Mandatory (Yes/No) | Description |
merchantOrderId | String | Yes | Unique merchant order id generated by merchant. |
amount | Long | Yes | Order amount in paisa |
| List | Yes | Different 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 Name | Data Type | Description |
orderId | String | Order ID generated by PhonePe PG. |
state | String | State of the Order. Initially it will be PENDING. |
expireAt | Long | Expiry time in epoch. |
token | String | Token used to access the PG Page. |