Token
This method is used to initiate a payment via the PhonePe PG.
The pay() method is used to initiate an order via various instruments.
Request
| Parameter Name | Data Type | Mandatory | Description |
|---|---|---|---|
merchantOrderId | String | yes | Unique order ID generated by merchant |
amount | long | yes | Amount of order in Paisa |
contraints | List | No | Different type of constraints that must be applied to the payment |
authMode | String | yes | Default to 3DS |
encryptionKeyId | long | yes | KeyId of key which merchant uses to encrypt card number & cvv. |
encryptedToken | String | yes | Encrypted TOKEN number which merchant passes to process card transaction |
encryptedCvv | String | yes | Encrypted CVV of the card with which payment is being initiated. |
cryptogram | String | yes | The cryptogram fetched from the gateway where the card was tokenized. |
panSuffix | String | yes | Last four digits of card number |
cardHolderName | String | yes | Card Holder Name |
expiryMonth | String | yes | Token expiry month |
expiryYear | String | yes | Token expiry year |
merchantUserId | String | No | The unique identifier of the merchant user. It is used to associate the payment with a specific user. |
metaInfo | Object | No | Merchant defined meta info to store additional information. same data will be returned in status and callback response. • For udf1 to udf10, there is no constraint and Maximum length for Udf1-10 = 256 characters • For udf11 to udf15, alphanumeric values with _-+@. are allowed and Maximum length for Udf11-15 = 50 characters • It is mandatory to keep the parameter names udf1, udf2, etc., exactly as they are in the metainfo block. Renaming these key values will result in a production error. |
Sample Request
import com.phonepe.sdk.pg.common.models.MetaInfo;
import com.phonepe.sdk.pg.common.models.request.PgPaymentRequest;
import com.phonepe.sdk.pg.common.models.response.PgPaymentResponse;
import java.util.UUID;
import com.phonepe.sdk.pg.Env;
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 encryptedCvv = "<encryptedCvv>";
String authMode = "3DS";
String panSuffix = "7239";
String cryptogram = "<cryptogram>";
String encryptedToken = "<encryptedToken>";
String merchantUserId = "<merchantUserId>";
String cardHolderName = "<cardHolderName>";
String expiryYear = "2050";
String expiryMonth = "08";
MetaInfo metaInfo = MetaInfo.builder()
.udf1("free-text-value-1")
.udf2("free-text-value-2")
.udf3("free-text-value-3")
.udf4("free-text-value-4")
.udf5("free-text-value-5")
.udf6("free-text-value-6")
.udf7("free-text-value-7")
.udf8("free-text-value-8")
.udf9("free-text-value-9")
.udf10("free-text-value-10")
.udf11("ref_11")
.udf12("tag-12")
.udf13("user@13")
.udf14("code.14")
.udf15("val+15")
.build();
PgPaymentRequest pgPaymentRequest = PgPaymentRequest.TokenPayRequestBuilder()
.merchantOrderId(merchantOrderId)
.amount(amount)
.encryptionKeyId(encryptionKeyId)
.encryptedCvv(encryptedCvv)
.authMode(authMode)
.panSuffix(panSuffix)
.cryptogram(cryptogram)
.encryptedToken(encryptedToken)
.merchantUserId(merchantUserId)
.cardHolderName(cardHolderName)
.expiryMonth(expiryMonth)
.expiryYear(expiryYear)
.metaInfo(metaInfo)
.build();
PgPaymentResponse pgPaymentResponse = customCheckoutClient.pay(pgPaymentRequest);
String redirectUrl = pgPaymentResponse.getRedirectUrl();Extract the redirectUrl from the response received.
Response
| 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 | Redirect url to perform the transaction |