Create Order with Java SDK
The Create SDK Order is used to generate a payment token when the backend is built in Java and integrated with any PhonePe Mobile SDK. This token enables secure payment processing within the mobile app.
Request
Use the CreateSdkOrderRequest Builder to create the request and the following are the attributes that you can pass:
| Parameter Name | Data Type | Mandatory (Yes/No) | Description | Constraints |
merchantOrderId | String | Yes | Unique order ID generated by you | Max length: 63 characters, no special characters except “_” and “-” |
amount | Long | Yes | Order amount in paisa | Minimum value: 100 (in paisa) |
disablePaymentRetry | Boolean | No | Setting this filed to true will disable retries on standard checkout payment page. | |
redirectUrl | String | No | URL to which the user will be redirected after the payment (success or failure) |
Sample Request
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
StandardCheckoutClient client = StandardCheckoutClient.getInstance(clientId, clientSecret,
clientVersion, env);
String merchantOrderId = UUID.randomUUID()
.toString();
long amount = 100;
String redirectUrl = "https://www.merchant.com/redirect";
CreateSdkOrderRequest createSdkOrderRequest = CreateSdkOrderRequest.StandardCheckoutBuilder()
.merchantOrderId(merchantOrderId)
.amount(amount)
.disablePaymentRetry(true) // If you want to disable payment retries set this parameter to true
.redirectUrl(redirectUrl)
.build();
CreateSdkOrderResponse createSdkOrderResponse = client.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 by your app to initiate order. |
What’s Next?
Now that you have understood how to generate a payment token when the backend is built in Java and integrated with any PhonePe Mobile SDK. Let’s proceed to check the status of the order.