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
Attribute | Data Type | Mandatory | Description | Constraints |
---|---|---|---|---|
merchantOrderId | String | Yes | The unique order ID assigned by the merchant. | Length should be less than 63 characters No special characters allowed except underscore “_” and hyphen “-“ |
amount | Long | Yes | Order amount in paisa. | Minimum value = 100 (in paise) i.e. 1 Re |
redirectUrl | String | No | URL where user will be redirected after success/failed payment. | |
metaInfo | Object | No | Additional details can be passed by the merchant | |
paymentModeConfig | Object | No | Used to dynamically enable only specific instruments on the checkout page |
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.common.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 checkoutPageUrl = standardCheckoutPayResponse.getRedirectUrl();
Example with paymentModeConfig:
- Either enabledPaymentModes or disabledPaymentModes should be passed. If both are present, then the API will throw error.
- The below example is shared with only enabledPaymentModes.
- For more details, refer here
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.common.models.MetaInfo;
import com.phonepe.sdk.pg.payments.v2.models.request.PaymentModeConfig;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.CardPaymentModeConstraint;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.CardType;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.NetBankingPaymentModeConstraint;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.PaymentModeConstraint;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.UpiCollectPaymentModeConstraint;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.UpiIntentPaymentModeConstraint;
import com.phonepe.sdk.pg.common.models.request.paymentmodeconstraints.UpiQrPaymentModeConstraint;
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();
Set < CardType > allowedCardTypes = new HashSet < > ();
allowedCardTypes.add(CardType.DEBIT_CARD);
allowedCardTypes.add(CardType.CREDIT_CARD);
PaymentModeConstraint cardPaymentModeConstraint = CardPaymentModeConstraint.builder()
.cardTypes(allowedCardTypes)
.build();
PaymentModeConstraint netbanking = NetBankingPaymentModeConstraint.builder().build();
PaymentModeConstraint upiIntent = UpiIntentPaymentModeConstraint.builder().build();
PaymentModeConstraint upiQr = UpiQrPaymentModeConstraint.builder().build();
PaymentModeConstraint upiCollect = UpiCollectPaymentModeConstraint.builder().build();
PaymentModeConfig paymentModeConfigEnabled = PaymentModeConfig.builder()
.enabledPaymentModes(Arrays.asList(cardPaymentModeConstraint, netbanking, upiIntent, upiQr))
.build();
StandardCheckoutPayRequest standardCheckoutPayRequest = StandardCheckoutPayRequest.builder()
.merchantOrderId(merchantOrderId)
.amount(amount)
.redirectUrl(redirectUrl)
.metaInfo(metaInfo)
.paymentModeConfig(paymentModeConfigEnabled)
.build();
StandardCheckoutPayResponse standardCheckoutPayResponse = client.pay(standardCheckoutPayRequest);
String checkoutPageUrl = 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:
Property | Type | Description |
---|---|---|
orderId | String | Order Id created by PhonePe |
state | String | State of the order. Initially it will be PENDING. |
expireAt | Long | Order expire date in epoch |
redirectUrl | String | URL for the PG Standard Checkout (merchant is supposed to redirect user to complete payment) |