Cards

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

The pay() method is used to initiate an order via various instruments.

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringyesUnique order ID generated by merchant
amountlongyesAmount of order in Paisa
contraintsListNoDifferent type of constraints that must be applied to the payment
authModeStringyesDefault to 3DS
encryptionKeyIdlongyesKeyId of key which merchant uses to encrypt card number & cvv.
encryptedCardNumberStringyesEncrypted 16-Digit Card Number entered by the user.
encryptedCvvStringyesEncrypted CVV of the card with which payment is being initiated.
cardHolderNameStringNoCard Holder Name
expiryMonthStringyesToken expiry month
expiryYearStringyesToken expiry year
merchantUserIdStringNoThe unique identifier of the merchant user. It is used to associate the payment with a specific user.
Sample Request
import com.phonepe.sdk.pg.Env;
import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import com.phonepe.sdk.pg.payments.v2.CustomCheckoutClient;
 
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
 
CustomCheckoutClient customCheckoutClient = CustomCheckoutClient.getInstance(clientId, clientSecret,
        clientVersion, env);
 
String merchantOrderId = UUID.randomUUID().toString();
long amount = 100;
long encryptionKeyId = 10;
String authMode = "3DS";
String encryptedCardNumber = "<encryptedCardNumber>";
String encryptedCvv = "<encryptedCvv>";
String merchantUserId = "<merchantUserId>";
String cardHolderName = "<cardHolderName>";
String expiryYear = "2052";
String expiryMonth = "08";
 
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.CardPayRequestBuilder()
        .merchantOrderId(merchantOrderId)
        .amount(amount)
        .encryptionKeyId(encryptionKeyId)
        .encryptedCvv(encryptedCvv)
        .authMode(authMode)
        .encryptedCardNumber(encryptedCardNumber)
        .merchantUserId(merchantUserId)
        .cardHolderName(cardHolderName)
        .expiryMonth(expiryMonth)
        .expiryYear(expiryYear)
        .build();
 
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String redirectUrl = pgPaymentResponse.getRedirectUrl();

Extract the redirectUrl from the response received

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
redirectUrlStringRedirect url to perform the transaction
Is this article helpful?