Token


This flow enables card-on-file/tokenized card payments. Encryption and PCI-DSS compliance are mandatory.

⚠️ Security Requirement!


  • You must be PCI DSS certified to integrate with the Custom Card Flow.
  • Card Number and CVV must be encrypted using RSA 4096 with padding method RSA/ECB/PKCS1Padding.
  • The encryptionKey and encryptionKeyId will be provided at the MID level.
  • If operating with multiple MIDs, the encryption credentials will differ for each MID. Avoid hardcoding these values.
EnvironmentHTTP MethodAPI
SandboxPOSThttps://api-preprod.phonepe.com/apis/pg-sandbox/payments/v2/pay
ProductionPOSThttps://api.phonepe.com/apis/pg/payments/v2/pay

⚠️ Setup Required to Avoid Errors!


Before initiating a payment, install the PhonePe Test App and configure the payment template. Skipping this step may result in HTTP 500 errors.

Request Header
Header NameHeader ValueDescription
Content-Typeapplication/json
AuthorizationO-Bearer <access_token>Pass access_token received in Authorization call

⚠️ For Partner Integrations!


It is mandatory to include the X-MERCHANT-ID header with the MerchantID of the end merchant.

Request Parameters
Parameter NameData TypeMandatoryDescriptionConstraints
merchantUserIdStringNo
merchantOrderIdStringYesUnique merchant order id generated by merchant.Max Length = 63 charactersNo Special characters allowed except underscore “_” and hyphen “-“
amountLongYesOrder amount in paisa.Min Value = 100 (In paise)
expireAfterLongNoOrder expiry in seconds. If not passed default value will be used.Min Value = 300, Max Value = 5184000

Default Value (in Secs):
UPI QR: 480
UPI Intent : 600
UPI Collect: 480
Card : 720
NetBanking : 480
metaInfoObjectNoMerchant defined meta info to store additional information.same data will be returned in status and callback response.
deviceContext.deviceOSStringYesdevice OS required only in case of UPI_INTENTValues Allowed = [IOS, ANDROID]
deviceContext.merchantCallBackSchemeStringYesMerchant Callback Scheme. Required only in case targetApp = PHONEPE and deviceContext.deviceOS = IOS
paymentFlowObjectYesAdditional details required by this flow.
paymentMode.typeStringYesType of payment modeValues Allowed:
UPI_INTENT
UPI_COLLECT
UPI_QR
NET_BANKING
TOKEN
CARD
authModeStringYesDefaults to 3DS
merchantUrls.redirectUrlStringYesUrl where user will be redirected after completing the payment. Mandatory only for [NET_BANKING, TOKEN, CARD] Payment Mode.Valid Http url. 

The metaInfo object contains additional parameters, which are explained in the table below.

Request Parameters of metoInfo Object:
Parameter NameData TypeDescriptionMandatory (Yes/No)Constraints
metaInfo.udf1-15StringOptional details you can add for more informationNoMaximum length for Udf1-10 = 256 characters
Maximum length for Udf11-15 = 50 characters

⚠️ Do Not Rename metainfo Parameters!


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.

The tokenDetails object contains additional parameters, which are explained in the table below.

Request Parameters of tokenDetails Object:
Parameter NameData TypeMandatoryDescriptionConstraints
tokenDetails.encryptionKeyIdIntegerYesKeyId of key which merchant uses to encrypt card number/Token & CVV.
tokenDetails.encryptedTokenStringYesEncrypted TOKEN number which merchant passes to process card transaction.
Encryption Method: RSA 4096 with Padding: RSA/ECB/PKCS1Padding
tokenDetails.encryptedCvvStringYesEncrypted CVV of the card with which payment is being initiated.
Encryption Method: RSA 4096 with Padding: RSA/ECB/PKCS1Padding
tokenDetails.cryptogramStringYesThe cryptogram fetched from the gateway where the card was tokenized.
tokenDetails.panSuffixStringYesLast four digits of cardNumber.
tokenDetails.cardHolderNameStringNoCard Holder Name.
tokenDetails.expiry.monthStringYesToken expiry month.
tokenDetails.expiry.yearStringYesToken expiry year.
Sample Request
{
    "merchantOrderId": "TX123456",
    "amount": 1000,
    "expireAfter": 1200,
    "metaInfo": {
        "udf1": "<additional-information-1>",
        "udf2": "<additional-information-2>",
        "udf3": "<additional-information-3>",
        "udf4": "<additional-information-4>",
        "udf5": "<additional-information-5>",
        "udf6": "<additional-information-6>",
        "udf7": "<additional-information-7>",
        "udf8": "<additional-information-8>",
        "udf9": "<additional-information-9>",
        "udf10": "<additional-information-10>",
        "udf11": "<additional-information-11>",
        "udf12": "<additional-information-12>",
        "udf13": "<additional-information-13>",
        "udf14": "<additional-information-14>",
        "udf15": "<additional-information-15>"   
    },
    "paymentFlow": {
        "type": "PG",    
       "paymentMode" : {
            "type" : "TOKEN",
            "authMode": "3DS",
            "tokenDetails": {
                "encryptedToken": "<encryptedToken>",
                "encryptionKeyId": 122,
                "expiry": {
                    "month": "12",
                    "year": "2029"
                },
                "panSuffix": "<panSuffix>",
                "cardHolderName": "Dummy Name",
                "cryptogram": "<cryptogram>",
                "encryptedCvv": "<encryptedCvv>"
            },
            "merchantUserId": "dummyUser"            
        },
        "merchantUrls": {
            "redirectUrl": "<redirectUrl>"
        }  
    } 
}
Sample Response
{
"orderId": "OMO123456789",
"state": "PENDING",
"expireAt": 1703756259307,
"redirectUrl": ""
}
Field NameData TypeDescription
orderIdStringPG generated internal order id.
stateStringState of the order created, Expected value is CREATED.
expiryAtLongOrder expiry date in epoch (in milliseconds).
redirectUrlStringUrl where merchant is supposed to redirect user to complete payment.
headers
body params
Is this article helpful?