Initiate Payment

This method is used to initiate a payment via the PhonePe PG.

Merchants can use the StandardCheckoutPayRequest.builder() to create the request and the following are the attributes that merchant can pass.

Attributes

AttributeData TypeMandatoryDescriptionConstraints
merchantOrderIdStringYesThe unique order ID assigned by the merchant.Length should be less than 63 characters
No special characters allowed except underscore “_” and hyphen “-“
amountLongYesOrder amount in paisa.Minimum value = 100 (in paise) i.e. 1 Re
redirectUrlStringNoURL where user will be redirected after success/failed payment.

Example:

import java.util.UUID;
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.payments.v2.StandardCheckoutClient;
import com.phonepe.sdk.pg.payments.v2.models.request.StandardCheckoutPayRequest;
import com.phonepe.sdk.pg.payments.v2.models.response.StandardCheckoutPayResponse;
import com.phonepe.sdk.pg.commom.models.MetaInfo;
 
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://redirectUrl.com";
MetaInfo metaInfo = MetaInfo.builder()
            .udf1("udf1")
            .udf2("udf2")
            .udf3("udf3")
            .udf4("udf4")
            .udf5("udf5")
            .build();
 
StandardCheckoutPayRequest standardCheckoutPayRequest = StandardCheckoutPayRequest.builder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .redirectUrl(redirecturl)
        .metaInfo(metaInfo)
        .build();
 
StandardCheckoutPayResponse standardCheckoutPayResponse = client.pay(standardCheckoutPayRequest);
String redirectUrlForUI = standardCheckoutPayResponse.getRedirectUrl();

Returns:

The function returns a StandardCheckoutPayResponse object with the following properties:

StandardCheckoutPayResponse Properties:

Here is the response property table for the given model:

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
redirectUrlStringURL for the PG Standard Checkout (merchant is supposed to redirect user to complete payment)