2. Create an Order

To process any payment on Cashfree PG, the merchant needs to create an order in the cashfree system.

❗️

Order creation must happen from your backend (as this API uses your secret key). Please do not call this directly from your mobile application.

Cashfree provides two environments, one being the sandbox environment for developers to test the payment flow & responses and the other being production environment which gets shipped to production. The URL for these are -
Production -> https://api.cashfree.com/pg/orders
Sandbox -> https://sandbox.cashfree.com/pg/orders

Note: Please see the description of the request below.

Order creation request description

curl -XPOST -H 'Content-Type: application/json'
-H 'x-client-id: "YOUR APP ID GOES HERE"'
-H 'x-client-secret: "YOUR SECRET KEY GOES HERE'
-H 'x-api-version: "2022-09-01"'
-H 'x-request-id: "developer_name"'
-d '{
    "order_amount": 1.00,
    "order_id": "order_id"
    "order_currency": "INR",
    "customer_details": {
        "customer_id": "customer_id",
        "customer_name": "customer_name",
        "customer_email": "customer_email",
        "customer_phone": "customer_phone"
    },
    "order_meta": {
        "notify_url": "https://test.cashfree.com"
    },
    "order_note": "some order note here",
}' 'https://sandbox.cashfree.com/pg/orders'
{
    "cf_order_id": 514853406,
    "order_id": "order_id",
    "entity": "order",
    "order_currency": "INR",
    "order_amount": 1.00,
    "order_expiry_time": "2021-08-22T13:09:23+05:30",
    "customer_details": {
        "customer_id": "customer_id",
        "customer_name": "customer_name",
        "customer_email": "customer_email",
        "customer_phone": "customer_phone"
    },
    "order_meta": {
        "return_url": "https://test.cashfree.com"
        "notify_url": "https://test.cashfree.com"
        "payment_methods": null
    },
    "settlements": {
        "url": "settlements_url"
    },
    "payments": {
        "url": "payments_url"
    },
    "refunds": {
        "url": "refunds_url"
    },
    "order_status": "ACTIVE",
    "payment_session_id": "session_V7z6rNXpYJxPfRkozFQ7MpL12nzrpSjS4qWcAHA19OWJHzA3I9vZiawsnN1JCrKzpb_1s-pZkxExeDb15UA9TVcz60IJuVecBQbv_LqbRVBh", // This is the payment_session_id that has to be sent to the SDK
    "order_note": "some order note here"
}

Use test API keys for creating order in Sandbox/test environment and prod API keys for creating order in prod environment. Refer here to know how to generate or view API keys.

If the order creation is successful you will receive a 200 response and the order entity in response. This order entity contains relevant details for the order.

We recommend that you store the following parameters at your end order_id, cf_order_id , payment_session_id, and the order_status.

Note: The payment_session_id contains all the order details and has to be sent to the SDK while initiating the payment.

📘

Please refer our [Order Creation] (https://docs.cashfree.com/docs/create-order) for details regarding parameters and more.

Create order in production environment

Use Prod API keys for creating order in prod environment and follow the above mentioned steps. Refer here to know how to generate or view prod API keys.

You also need to whitelist your android package on Cashfree Payments system. Refer here to know how to do Whitelisting.

Please note that prod environment can be accessed only when PG is activated for your account.