Initiate Payment ( TPV Flow )

anchor image
Copied !

This doc outlines the steps to integrate PhonePe PG for custom checkout experience.

anchor image
Copied !

This API is used to generate access token which will be used to make further API calls, below are the steps for the same:

API DETAILS:

POST https://api-preprod.phonepe.com/apis/pg-sandbox/v1/oauth/token

anchor image
Copied !

Request Headers

Header NameHeader Value
Content-Typeapplication/x-www-form-urlencoded

Request Parameters

Parameter NameDescription
client_idClient ID shared by PhonePe
client_versionIn case of simulator, client_version value should be 1.
In case of production, use the value as received in credentials email.
client_secretClient secret shared by PhonePe
grant_typeclient_credentials

Send the above Headers and payload to the below API using HTTP POST method :

POST – https://api-preprod.phonepe.com/apis/pg-sandbox/v1/oauth/token

Sample CURL :

curl --location 'https://api-preprod.phonepe.com/apis/pg-sandbox/v1/oauth/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'client_id=V2SUBUAT_2403281706165571071834' \ --data-urlencode 'client_version=1' \ --data-urlencode 'client_secret=MWQyMjUxMmMtM2RlYi00ZTQwLTg1ZjUtOTI1NDFlOGY1YWNk' \ --data-urlencode 'grant_type=V2PGTESTUAT'

NOTE : Above CURL has only the dummy data, please refer to the request headers and parameters table above to generate the payload and headers.

Sample Response from the API :

{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmVzT24iOjE3MTIyNTM2MjU2NDQsIm1lcmNoYW50SWQiOiJWMlNVQlVBVCJ9.7aVzYI_f_77-bBicEcRNuYx093b2wCsgl_WFNkKqAPY", "encrypted_access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmVzT24iOjE3MTIyNTM2MjU2NDQsIm1lcmNoYW50SWQiOiJWMlNVQlVBVCJ9.7aVzYI_f_77-bBicEcRNuYx093b2wCsgl_WFNkKqAPY", "expires_in": null, "issued_at": 1711629025, "expires_at": 1712253625, "session_expires_at": 1712253625, "token_type": "O-Bearer" }

Use the above access token to initiate the payment process as specified below :

anchor image
Copied !

This API is used to initiate the payment : 

API Details : 

POST https://api-preprod.phonepe.com/apis/pg-sandbox/payments/v2/pay

anchor image
Copied !

Request Headers

Header NameHeader Value
Content-Typeapplication/json
AuthorizationO-Bearer <merchant-auth-token>

Request Parameters

Parameter NameData TypeDescriptionMandatory (Yes/No)Constraints
merchantOrderIdSTRINGUnique merchant order id generated by merchantYesMax Length = 63 charactersNo Special characters allowed except underscore “_” and hyphen “-“
amountLONGOrder amount in paisaYesMin Value = 1
expireAfterLONGOrder expiry in seconds. If not passed default value will be used.NoMin Value = 300, Max Value = 5184000
metaInfoOBJECTMerchant defined meta info to store additional information.same data will be returned in status and callback response No
metaInfo.udf1-4STRINGMerchant defined additional informationNoMax length = 256 characters 
constraintSTRINGDifferent type of constraints that must be applied to the payment.No
constraints.typeSTRINGType of constraint to applyNoValues Allowed = [ACCOUNT]
deviceContext.deviceOSSTRINGdevice OS required only in case of UPI_INTENTNoValues Allowed = [IOS, ANDROID]
deviceContext.merchantCallBackSchemeSTRINGMerchant Callback Scheme. Required only in case targetApp = PHONEPE and deviceContext.deviceOS = IOSNo
paymentFlowOBJECTAdditional details required by this flowYes
paymentFlow.typeSTRINGType of payment flowYesValued Allowed = [PG_CHECKOUT]
paymentModeOBJECTObject containing details for mode of paymentsYes
paymentMode.typeSTRINGType of payment modeYesValues Allowed = [UPI_INTENT, UPI_COLLECT, UPI_QR, NET_BANKING, TOKEN, CARD]
merchantUrls.redirectUrlSTRINGUrl where user will be redirected after completing the payment. Mandatory only for [NET_BANKING, TOKEN, CARD] Payment ModeYesValid Http url. 

Sample Request Body:

Pay using UPI_INTENT

{ "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>" }, "constraints": [ { "type": "ACCOUNT" "accountNumber": "420200001892", "ifsc": "ICIC0000041" } ], "deviceContext": { "deviceOS": "IOS", "merchantCallBackScheme": "" }, "paymentFlow": { "type": "PG", "paymentMode" : { "type" : "UPI_INTENT", "targetApp" : "PHONEPE" // PHONEPE, GPAY, PAYTM, null } } }

Extra parameters for UPI INTENT

Field NameData TypeMandatoryDescription
targetAppapplication/jsonNoTarget app to use. Allowed Values = [PHONEPE, GPAY, PAYTM]

Pay using UPI_COLLECT

{ "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>" }, "constraints": [ { "type": "ACCOUNT" "accountNumber": "420200001892", "ifsc": "ICIC0000041" } ], "paymentFlow": { "type": "PG", "paymentMode" : { "type" : "UPI_COLLECT", "details" : { "type" : "VPA", "vpa" : "abcd@ybl" }, "message" : "some message from merchant to populate" } } }

Extra parameters for UPI COLLECT

Field NameData TypeMandatoryDescription
collectPaymentDetailsObjectYesObject containing collect payment details
collectPaymentDetails.typeStringYesType of collect payment details. Allowed Values = [VPA, PHONE_NUMBER]
collectPaymentDetails.vpaStringYesVPA against which collect request need to be raised (Use when type = VPA)
collectPaymentDetails.phoneNumberStringYesPhone number against which collect request need to be raised (Use when type = PHONE_NUMBER)
messageStringYesMessage to show in collect request

Pay using UPI_QR

{ "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>" }, "constraints": [ { "type": "ACCOUNT" "accountNumber": "420200001892", "ifsc": "ICIC0000041" } ], "paymentFlow": { "type": "PG", "paymentMode" : { "type" : "UPI_QR" } } }

Pay using NET_BANKING

{ "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>" }, "constraints": [ { "type": "ACCOUNT" "accountNumber": "420200001892", "ifsc": "ICIC0000041" } ], "paymentFlow": { "type": "PG", "paymentMode" : { "type" : "NET_BANKING", "bankId" : "HDFC", "merchantUserId": "" }, "merchantUrls": { "redirectUrl": "<redirectUrl>" } } }

Extra parameters for NET_BANKING

Field NameData TypeMandatoryDescription
bankIdStringYesBank id from where payment will be completed.

Pay using TOKEN

{ "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>" }, "constraint": [ { "type": "ACCOUNT" "accountNumber": "420200001892", "ifsc": "ICIC0000041" } ], "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>" } } }

Extra parameters for TOKEN

Field NameData TypeMandatoryDescription
authModeStringYesDefaults to 3DS
tokenDetails.encryptionKeyIdIntegerYesKeyId of key which merchant uses to encrypt card number & cvv.
tokenDetails.encryptedTokenStringYesEncrypted TOKEN number which merchant passes to process card transaction.
tokenDetails.encryptedCvvStringYesEncrypted CVV of the card with which payment is being initiated.
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
merchantUserIdStringNo

Pay using CARD

{ "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>" }, "constraint": [ { "type": "ACCOUNT" "accountNumber": "420200001892", "ifsc": "ICIC0000041" } ], "paymentFlow": { "type": "PG", "paymentMode" : { "type": "CARD", "authMode": "3DS", "cardDetails": { "encryptedCardNumber": "<encryptedCardNumber>", "encryptionKeyId": 1, "cardHolderName": "Dummy Name", "expiry": { "month": "12", "year": "2029" }, "encryptedCvv": "<encryptedCvv>" }, "merchantUserId": "dummyUser" }, "merchantUrls": { "redirectUrl": "<redirectUrl>" } } }

Response from the API : 

Response Headers:

Header NameHeader Value
Content-Typeapplication/json

Response Payload:

Case 1: Success Response

Http Response Code: 200

UPI_INTENT

{ "orderId": "OMO123456789", "state": "PENDING", "expireAt": 1703756259307, "intentUrl" : "ppe://url" }

UPI_COLLECT

{ "orderId": "OMO123456789", "state": "PENDING", "expireAt": 1703756259307 }

UPI_QR

{ "orderId": "OMO123456789", "state": "PENDING", "expireAt": 1703756259307, "intentUrl": "ppe://url", "qrData": "" }

NET_BANKING / CARD / TOKEN

{ "orderId": "OMO123456789", "state": "PENDING", "expireAt": 1703756259307, "redirectUrl": "" }

Case 2: Order with same merchant order id is already present and not in CREATED state

Http Response Code: 400

{ "code": "BAD_REQUEST", "message": "Please check the inputs you have provided." }

Case 3: Internal Server Error

Http Response code: 500

{ "code": "INTERNAL_SERVER_ERROR", "message": "There is an error trying to process your transaction at the moment. Please try again in a while." }

Response Field Details:

Field NameData TypeDescription
orderIdStringPG generated internal order id
stateStringState of the order created, Expected value is CREATED
expiryAtLongOrder expiry date in epoch
redirectUrlStringUrl where merchant is supposed to redirect user to complete payment
intentUrlStringIntent url (Present in case of UPI_INTENT or UPI_QR)