Create Payment

This API is used to create the payment.

anchor image
Copied !

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:

  1. If you are using a personalised Chrome tab within their Android app, hindering URL retrieval. Please use SDK integration to resolve this issue.
  2. 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.
  3. 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

EnvironmentHttp MethodValue
UATPOSThttps://api-preprod.phonepe.com/apis/pg-sandbox
PRODPOSThttps://api.phonepe.com/apis/pg

Endpoint

/checkout/v2/pay – Endpoint is common for UAT and Production.

Complete Host Details

EnvironmentHttp MethodValue
UATPOSThttps://api-preprod.phonepe.com/apis/pg-sandbox/checkout/v2/pay
PRODPOSThttps://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.

anchor image
Copied !

Request Headers

Header NameHeader ValueDescription
Content-Typeapplication/json
AuthorizationO-Bearer <access_token>Pass access_token received in Authorization call
anchor image
Copied !
{ "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": "" } } }
anchor image
Copied !
{ "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.
anchor image
Copied !
Parameter NameData TypeDescriptionMandatory (Yes/No)Constraints
merchantOrderIdSTRINGUnique merchant order id generated by merchantYesMax Length = 63 charactersNo Special characters allowed except underscore “_” and hyphen “-“
expireAfterLONGOrder expiry in seconds. If not passed, default value will be used.NoMin Value = 300, Max Value = 3600 (in Seconds)
Default Value = 1200 Secs (20 Mins)
amountLONGOrder amount in paisaYesMin Value = 100 (In paise)
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 
paymentFlowOBJECTAdditional details required by this flowYes
paymentFlow.typeSTRINGType of payment flowYesValued Allowed = [PG_CHECKOUT]
paymentFlow.messageSTRINGPayment message used for collect requestsNo
paymentFlow.merchantUrlsOBJECTObject to store different merchant UrlsYes
paymentFlow.merchantUrls.redirectUrlSTRINGUrl where user will be redirected after success/failed payment.Yes
paymentModeConfigOBJECTAdditional details to display only the selected instrumentsOptionalEither enabledPaymentModes or disabledPaymentModes is required, if both are present API will throw error.
anchor image
Copied !
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/" } } }'
anchor image
Copied !

Response Headers:

Header NameHeader Value
Content-Typeapplication/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" }
anchor image
Copied !

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.

<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." }
anchor image
Copied !
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