Create Order SDK Integration
This is specifically used to generate a token when the user’s backend is in JAVA and they are using any Mobile SDK.
Merchants can use the CreateSdkOrderRequest Builder to create the request and the following are the attributes that merchant can pass.
SDK Order Request Builder
Parameters
Parameter name | Data Type | Mandatory | Description | Constraints |
---|---|---|---|---|
merchantOrderId | String | Yes | Unique merchant order id generated by merchant | Max Length = 63 characters |
amount | Long | Yes | Amount of order in Paisa | Min value = 100 (in paise), Max value = order amount |
redirectUrl | String | Yes | The URL to which the user should be redirected after the payment is completed |
Example Usage :
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.StandardCheckoutClient;
import com.phonepe.sdk.pg.payments.v2.models.request.CreateSdkOrderRequest;
import com.phonepe.sdk.pg.payments.v2.models.response.CreateSdkOrderResponse;
import java.util.UUID;
String clientId = "<clientId>";
String clientSecret = "<clientSecret>";
Integer clientVersion = 1; //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)
.redirectUrl(redirectUrl)
.build();
CreateSdkOrderResponse createSdkOrderResponse = client.createSdkOrder(createSdkOrderRequest);
String token = createSdkOrderResponse.getToken();
Returns :
The function returns a CreateOrderResponse
object with the following properties:
Attribute | Data Type | Description |
---|---|---|
orderId | String | Order ID generated by PhonePe |
state | String | State of the Order. Initially it will be PENDING |
expireAt | Long | Expiry time in epoch |
token | String | Token used by the merchant app to initiate order |