This API is used to create the payment.
Postman Collection
Click here to fork the PhonePe APIs Postman collection and start testing instantly.
Quick Links
Note:
To avoid transaction blocking in production, kindly check the below points:
- If you are using a personalised Chrome tab within their Android app, hindering URL retrieval. Please use SDK integration to resolve this issue.
- If you are launching PayPage in a new window or tab, resulting in the absence of a referrer, then either redirect or employ an iFrame for PayPage is essential.
- If you have implemented a no-referrer-policy then it leads to blank merchant URLs captured at our end. Please refrain from using it on the checkout page.
Host Details
Environment | Http Method | Value |
---|---|---|
UAT | POST | https://api-preprod.phonepe.com/apis/pg-sandbox |
PROD | POST | https://api.phonepe.com/apis/pg |
Endpoint
/checkout/v2/pay – Endpoint is common for UAT and Production.
Complete Host Details
Environment | Http Method | Value |
---|---|---|
UAT | POST | https://api-preprod.phonepe.com/apis/pg-sandbox/checkout/v2/pay |
PROD | POST | https://api.phonepe.com/apis/pg/checkout/v2/pay |
Note: Before initiating the payment, install the PhonePe Test App and make sure to Configure Template. Otherwise, you will get HTTP Error Code: 500.
Request Details
Request Headers
Header Name | Header Value | Description |
---|---|---|
Content-Type | application/json | |
Authorization | O-Bearer <access_token> | Pass access_token received in Authorization call |
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"
},
"paymentFlow": {
"type": "PG_CHECKOUT",
"message": "Payment message used for collect requests",
"merchantUrls": {
"redirectUrl": ""
}
}
}
Sample Request with Selected Instrument
{
"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>"
},
"paymentFlow": {
"type": "PG_CHECKOUT",
"message": "Payment message used for collect requests",
"merchantUrls": {
"redirectUrl": ""
},
"paymentModeConfig": {
"enabledPaymentModes": [
{
"type": "UPI_INTENT"
},
{
"type": "UPI_COLLECT"
},
{
"type": "UPI_QR"
},
{
"type": "NET_BANKING"
},
{
"type": "CARD",
"cardTypes": [
"DEBIT_CARD",
"CREDIT_CARD"
]
}
],
"disabledPaymentModes": [
{
"type": "UPI_INTENT"
},
{
"type": "UPI_COLLECT"
},
{
"type": "UPI_QR"
},
{
"type": "NET_BANKING"
},
{
"type": "CARD",
"cardTypes": [
"DEBIT_CARD",
"CREDIT_CARD"
]
}
]
}
}
}
Important Notes:
- Merchants should pass “paymentModeConfig” block only if the merchant wants to manage the instrument to be displayed on the checkout page. Otherwise, the “paymentModeConfig” block should be ignored which will show the default instruments enabled at PhonePe’s end.
- Either enabledPaymentModes or disabledPaymentModes is required, if both are present API will throw error.
- paymentModeConfig.enabledPaymentModes:
This will ensure the list of Instruments passed within the “enabledPaymentModes” block will only be shown on the Checkout Page while all other enabled instruments at PhonePe end won’t be displayed. - paymentModeConfig.disabledPaymentModes:
This will ensure the list of Instruments passed within the “disabledPaymentModes” block will not be shown on the Checkout Page while all other enabled instruments at PhonePe end will be displayed. - Special Case for the CARD instrument
Ensure to pass the cardTypes as well along with type.- If “enabledPaymentModes.type” = “CARD” but
“enabledPaymentModes.cardTypes” is not passed, then the Card option will be displayed based on the instrument enabled at PhonePe’s end [CreditCard (and/or) Debit Card]. - If “enabledPaymentModes.type” = “CARD” and
“enabledPaymentModes.cardTypes” = [“DEBIT_CARD”] is passed, then the Debit Card option only will be allowed on the PhonePe checkout. - If “disabledPaymentModes.type” = “CARD” but
“disabledPaymentModes.cardTypes” is not passed, then the Card option won’t be disabled and user will be displayed based on the instrument enabled at PhonePe’s end [CreditCard (and/or) Debit Card].
- If “disabledPaymentModes.type” = “CARD” and
“disabledPaymentModes.cardTypes” = [“DEBIT_CARD”] is passed, then the Debit Card option alone will be disabled on the PhonePe checkout. - If “disabledPaymentModes.type” = “CARD” and
“disabledPaymentModes.cardTypes” = [“DEBIT_CARD”, “CREDIT_CARD”] is passed, only then both Debit Card and Credit Card will be disabled on the PhonePe checkout.
- If “enabledPaymentModes.type” = “CARD” but
Request Parameters
Parameter Name | Data Type | Description | Mandatory (Yes/No) | Constraints |
merchantOrderId | STRING | Unique merchant order id generated by merchant | Yes | Max Length = 63 charactersNo Special characters allowed except underscore “_” and hyphen “-“ |
| LONG | Order expiry in seconds. If not passed, default value will be used. | No | Min Value = 300, Max Value = 3600 (in Seconds) Default Value = 1200 Secs (20 Mins) |
amount | LONG | Order amount in paisa | Yes | Min Value = 100 (In paise) |
metaInfo | OBJECT | Merchant defined meta info to store additional information.same data will be returned in status and callback response | No | |
metaInfo.udf1-4 | STRING | Merchant defined additional information | No | Max length = 256 characters |
paymentFlow | OBJECT | Additional details required by this flow | Yes | |
paymentFlow.type | STRING | Type of payment flow | Yes | Valued Allowed = [PG_CHECKOUT] |
paymentFlow.message | STRING | Payment message used for collect requests | No | |
paymentFlow.merchantUrls | OBJECT | Object to store different merchant Urls | Yes | |
paymentFlow.merchantUrls.redirectUrl | STRING | Url where user will be redirected after success/failed payment. | Yes | |
paymentModeConfig | OBJECT | Additional details to display only the selected instruments | Optional | Either enabledPaymentModes or disabledPaymentModes is required, if both are present API will throw error. |
Sample CURL Request
curl --location 'https://api-preprod.phonepe.com/apis/pg-sandbox/checkout/v2/pay' \
--header 'Content-Type: application/json' \
--header 'Authorization: O-Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmVzT24iOjE3MTIyNTM2MjU2NDQsIm1lcmNoYW50SWQiOiJWMlNVQlVBVCJ9.7aVzYI_f_77-bBicEcRNuYx093b2wCsgl_WFNkKqAPY' \
--data '{
"merchantOrderId": "TX123rrty34432456",
"amount": 1000,
"paymentFlow": {
"type": "PG_CHECKOUT",
"message": "Payment message used for collect requests",
"merchantUrls": {
"redirectUrl": "https://www.xyz.com/PGIntegration/"
}
}
}'
Sample Response
Response Headers:
Header Name | Header Value |
---|---|
Content-Type | application/json |
Response Payload:
Case 1: Order created successfully
Http Response Code: 200
{
"orderId": "OMO123456789",
"state": "PENDING",
"expireAt": 1703756259307,
"redirectUrl": "https://mercury-uat.phonepe.com/transact/uat_v2?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmVzT24iOjE3MjgyNTk1MzE0NzgsIm1lcmNoYW50SWQiOiJWUlVBVCIsIm1lcmNoYW50T3JkZXJJZCI6Ik1PLTlkMC1hNmMyYmY1ZWM4MmUifQ.Trj5fub__kJpQhzOlJttXl2UPruHE7fsbH5QWj-iy6E"
}
How to Initiate Payment
The JS Checkout bundle will handle the opening of pay page on the merchant’s page. Merchants can either opt for IFrame or Redirect mode.
- Invoke PayPage on Checkout Page
- In IFrame [Most Recommended]
- In Redirect Mode
<script src="https://mercury.phonepe.com/web/bundle/checkout.js"></script>
After including this script,
- the
PhonePeCheckout
object will be available to merchants, which they can use to invoke PayPage using the ‘transact’ function. - They can also use the
closePage
function to explicitly close the PayPage iFrame if invoked in iFrame mode.
Merchants must ensure to call the appropriate function and pass the necessary parameters to handle the PayPage flow on their checkout page.
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 Parameters
Field Name | Data Type | Description |
---|---|---|
orderId | String | PG generated internal order id |
state | String | State of the order created, Expected value is CREATED |
expiryAt | Long | Order expiry date in epoch (in milliseconds) |
redirectUrl | String | Url where merchant is supposed to redirect user to complete payment |