Single Integration API

Create Order and Payments in a single API call.


You can now create an order along with a payment using a single API for Cards and ACH Direct Debit. Given below are details and examples for these payment methods followed by steps to integrate S2S JSON API and accept payments using

and .

Cards

The following API will create a payment with card as the payment method:

curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/orders \
-H "Content-Type: application/json" \
-d {
"amount": 50000,
"currency": "",
"receipt": "receipt#1",
"notes": {
"key1": "value3",
"key2": "value2"
},
"partial_payment": true,
"customer_id": "cust_E9penp7VGhT5yt",
"products": [],
"payment_config": {
"capture": "automatic",
"capture_options": {
"automatic_expiry_period": 12,
"manual_expiry_period": 7200,
"refund_speed": "optimum"
}
},
"payment": {
"amount": 100,
"email": "john.smith@example.com",
"contact": "+11234567890",
"method": "card",
"notes": {
"key1": "value3",
"key2": "value2"
},
"card": {
"number": "4916 3338 9663 2957",
"name": "John Smith",
"expiry_month": "11",
"expiry_year": "35",
"cvv": "100"
},
"authentication": {
"authentication_channel": "browser"
},
"browser": {
"java_enabled": false,
"javascript_enabled": false,
"timezone_offset": 11,
"color_depth": 23,
"screen_width": 23,
"screen_height": 100
},
"ip": "105.106.107.108",
"referer": "https://merchansite.com/example/paybill"
},
"user_agent": "Mozilla/5.0"
}

amount

mandatory

integer The amount for which the order was created in currency subunits. For example, for an amount of $299. The same amount will be used for the payment creation. For the partial payment scenario, we will use the amount specified in the payment request object in case.

currency

mandatory

string The currency in which the transaction should be made. Length must be of 3 characters.

receipt

optional

string Receipt number that corresponds to this order. Can have a maximum length of 40 characters and has to be unique.

partial_payment

optional

boolean Indicates whether the customer can make a partial payment. Possible values:

  • true: The customer can make partial payments.
  • false (default): The customer cannot make partial payments.

first_payment_min_amount

optional

integer Minimum amount that must be paid by the customer as the first partial payment. For example, if an amount of $7,000, is to be received from the customer in two installments of #1 - $5,000, #2 - $2,000, then you can set this value as 500000. This parameter should be passed only if partial_payment is true.

customer_id

optional

string Unique identifier of the customer.

payment_config

optional

array Payment capture settings for the payment. The options sent here override the

configured using the Dashboard.

capture

mandatory

string Option to automatically capture payment. Possible values:

  • automatic: Payments are auto-captured according to the configurations specified in the capture_options array.
  • manual: You have to manually capture payments using our or from the .

capture_options

optional

array Use this array to determine the expiry period for automatic and

of payments and the refund speed in the case of non-capture.

automatic_expiry_period

mandatory if capture = automatic

integer Time in minutes till when payments in the authorized state should be auto-captured. Minimum value 12 minutes. This parameter is mandatory only if the value of capture parameter is automatic.

manual_expiry_period

optional

integer Time in minutes till when you can manually capture payments in the authorized state.

  • Must be equal to or greater than the automatic_expiry_period value.
  • Default value 7200 minutes.
  • Maximum value 7200 minutes.
  • Payments in the authorized state after the manual_expiry_period are auto-refunded.

refund_speed

mandatory

string Refund speed for payments that were not captured (automatically or manually). Possible values:

payment

mandatory

object Details of the payment.

amount

optional

integer The amount for which the order was created in currency subunits. For example, for an amount of $299. The same amount will be used for the payment creation. For the partial payment scenario, we will use the amount specified in the payment request object in case.

email

mandatory

string Email address of the customer. The maximum length supported is 40 characters.

contact

mandatory

integer Phone number of the customer. The maximum length supported is 15 characters, inclusive of country code.

ip

mandatory

string The customer's IP address.

method

mandatory

string Name of the payment method. For example, card.

card

mandatory

object Details associated with the card.

number

string Unformatted card number.

name

string Name of the cardholder.

expiry_month

string Expiry month for the card in MM format.

expiry_year

string Expiry year for the card in YY format.

cvv

string CVV printed on the back of the card.

referrer

optional

string Referrer header passed by the client's browser.

user_agent

optional

string The User-Agent header of the user's browser. The default value will be passed by Razorpay if not provided by you.

Descriptions for the response parameters are present in the

.

ACH Direct Debit

The following API will create a payment with ach as the payment method:

curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/payments/create/json \
-H "content-type: application/json" \
-d '{
"amount": 50000,
"currency": "",
"receipt": "receipt#1",
"notes": {
"key1": "value3",
"key2": "value2"
},
"partial_payment": true,
"customer_id": "cust_E9penp7VGhT5yt",
"products": [],
"payment_config": {
"capture": "automatic",
"capture_options": {
"automatic_expiry_period": 12,
"manual_expiry_period": 7200,
"refund_speed": "optimum"
}
},
"payment": {
"amount": 50000,
"email": "john.smith@example.com",
"contact": "+11234567890",
"method": "ach",
"notes": {
"key1": "value3",
"key2": "value2"
},
"bank_account": {
"account_number": "000000001234",
"name": "John Smith",
"bank_code": "122105278",
"bank_code_category": "routing_number",
"account_type": "personal_savings"
},
"billing_address": {
"line1": "Block",
"line2": "Street",
"city": "San Jose",
"state": "California",
"postal_code": "33154"
}
}
}'
{
"razorpay_payment_id": "pay_29QQoUBi66xm2f",
"razorpay_order_id": "order_GAWN9beXgaqRyO",
"razorpay_signature": "9ef4dffbfd84f1318f6ae648f114332d8401e0949a3d"
}

amount

mandatory

integer The amount for which the order was created in currency subunits. For example, for an amount of $299, enter 29900. The same amount will be used for the payment creation. For the partial payment scenario, we will use the amount specified in the payment request object in case.

currency

mandatory

string The currency in which the transaction should be made. Length must be of 3 characters.

receipt

optional

string Receipt number that corresponds to this order. Can have a maximum length of 40 characters and has to be unique.

partial_payment

optional

boolean Indicates whether the customer can make a partial payment. Possible values:

  • true: The customer can make partial payments.
  • false (default): The customer cannot make partial payments.

first_payment_min_amount

optional

integer Minimum amount that must be paid by the customer as the first partial payment. For example, if an amount of $7,000, is to be received from the customer in two installments of #1 - $5,000, #2 - $2,000, then you can set this value as 500000. This parameter should be passed only if partial_payment is true.

customer_id

optional

string Unique identifier of the customer.

payment_config

optional

array Payment capture settings for the payment. The options sent here override the

configured using the Dashboard.

capture

mandatory

string Option to automatically capture payment. Possible values:

  • automatic: Payments are auto-captured according to the configurations specified in the capture_options array.
  • manual: You have to manually capture payments using our or from the .

capture_options

optional

array Use this array to determine the expiry period for automatic and

of payments and the refund speed in the case of non-capture.

automatic_expiry_period

mandatory if capture = automatic

integer Time in minutes till when payments in the authorized state should be auto-captured. Minimum value 12 minutes. This parameter is mandatory only if the value of capture parameter is automatic.

manual_expiry_period

optional

integer Time in minutes till when you can manually capture payments in the authorized state.

  • Must be equal to or greater than the automatic_expiry_period value.
  • Default value 7200 minutes.
  • Maximum value 7200 minutes.
  • Payments in the authorized state after the manual_expiry_period are auto-refunded.

refund_speed

mandatory

string Refund speed for payments that were not captured (automatically or manually). Possible values:

payment

mandatory

object Details of the payment.

amount

optional

integer The amount for which the order was created in currency subunits. For example, for an amount of $299, enter 29900. The same amount will be used for the payment creation. For the partial payment scenario, we will use the amount specified in the payment request object in case.

email

mandatory

string Email address of the customer. The maximum length supported is 40 characters.

contact

mandatory

integer Phone number of the customer. The maximum length supported is 15 characters, inclusive of country code.

ip

mandatory

string The customer's IP address.

method

mandatory

string Name of the payment method. For example, ach.

bank_account

mandatory

object Bank account details.

account_number

mandatory

string Customer's bank account number.

name

mandatory

string Account holder's name as per bank records.

bank_code

mandatory

string The ACH routing number of the bank account.

bank_code_category

mandatory

string The category of bank code. Must be routing_number for ACH payments.

account_type

mandatory

string Type of bank account. Possible values:

  • personal_savings: Individual savings account.
  • personal_checking: Individual current account.
  • business_savings: Business savings account.
  • business_checking: Business current account.

billing_address

optional

json object This will have details about the billing address of the customer/user.

line1

optional

string Address Line 1 of the address.

line2

optional

string Address Line 2 of the address.

city

optional

string City of the address. For example, San Jose.

state

optional

string Name of the state. For example, California.

postal_code

optional

string Postal code of the state. For example, 33514.

referrer

optional

string Referrer header passed by the client's browser.

user_agent

optional

string The User-Agent header of the user's browser. The default value will be passed by Razorpay if not provided by you.

Descriptions for the response parameters are present in the

.

Response Parameters

If the payment request is valid, the response contains the following fields.

receipt

string Receipt number that corresponds to this order. Can have a maximum length of 40 characters and has to be unique.

status

string Status of the order. Possible values:

  • attempted: An order moves from created to attempted state when a payment is first attempted on it. It remains in the attempted state till one payment associated with that order is captured.
  • created: When you create an order it is in the created state. It stays in this state till a payment is attempted on it.
  • paid: After the successful capture of the payment, the order moves to the paid state. No further payment requests are permitted once the order moves to the paid state. The order stays in the paid state even if the payment associated with the order is refunded.

id

string The unique identifier of the order.

amount

integer The amount for which the order was created, in currency subunits. For example, for an amount of $299, enter 29900.

created_at

integer Indicates the Unix timestamp when this order was created.

amount_paid

integer Indicates the amount paid for the order.

amount_due

integer Indicates the amount due for the order.

currency

string The currency in which the transaction was made. See the

. Length must be of 3 characters.

offer_id

string The unique identifier of the created offer.

attempts

string The number of payment attempts, successful and failed, that have been made against this order.

transfers

string Details regarding the transfer.

notes

object Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each.

payment_workflow

array Details regarding the payment.

id

string Unique identifier of the payment.

next

array A list of action objects available to you to continue the payment process. Present when the payment requires further processing.

action

string An indication of the next step available to you to continue the payment process. Possible values:

  • redirect: Use this URL to redirect the customer to submit the OTP on the bank page.

url

string URL endpoint where Razorpay will submit the final payment status.

1.1 Handle Payment Success and Error Events

Once a customer completes the payment, a POST request is made to the callback_url provided in the payment request. The data contained in this request will depend on whether the payment was a success or a failure.

If the payment made by the customer is successful, the following fields are sent:

  • razorpay_payment_id
  • razorpay_order_id
  • razorpay_signature
{
"razorpay_payment_id": "pay_29QQoUBi66xm2f",
"razorpay_order_id": "order_9A33XWu170gUtm",
"razorpay_signature": "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d"
}

If the payment has failed, the callback will contain details of the error. Refer to

for details.

Given below is a sample error code you will receive when the order fails.

{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "The amount must be atleast INR 1.00",
"source": "business",
"step": "order_create",
"reason": "input_validation_failed",
"metadata": {},
"field": "amount"
}
}

Given below is a sample error code you will receive when the payment fails.

Watch Out!

You can use the order id present in the metadata for additional payment attempts on the order without creating a new one.

{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "Authentication failed due to incorrect OTP",
"field": null,
"source": "customer",
"step": "payment_authentication",
"reason": "invalid_otp",
"metadata": {
"order_id": "order_EKwxwAgItmmXdp"
}
}
}

The following error occurs when the order was processed, payment was created in Razorpay but failed at gateway level.

{
"error": {
"code": "GATEWAY_ERROR",
"description": "Authentication failed due to incorrect OTP",
"field": null,
"source": "customer",
"step": "payment_authentication",
"reason": "gateway failure",
"metadata": {
"order_id": "order_EKwxwAgItmmXdp",
"payment_id": "pay_TKwxwAgItmmXdp"
}
}
}

1.2 Retry/Re-Attempt Request

Use the following sample code example to make a retry request using Order id and Receipt in the request.

curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET] \
-X POST https://api.razorpay.com/v1/orders \
-H "Content-Type: application/json" \
-d{
"id": "order_EKwxwAgItmmXdp",
"payment": {
"amount": 100,
"currency": "",
"method": "card",
"card": {
"number": "4916 3338 9663 2957",
"name": "John Smith",
"expiry_month": "11",
"expiry_year": "30",
"cvv": "100"
},
"notes": {
"key1": "value3",
"key2": "value2"
}
}
}
{
"id": "order_EKwxwAgItmmXdp",
"status": "attempted",
"receipt": "receipt#1",
"notes": {
"key1": "value3",
"key2": "value2"
},
"created_at": 1582628071,
"amount": 50000,
"amount_paid": 0,
"amount_due": 50000,
"currency": "",
"offer_id": null,
"attempts": 1,
"transfers": [],
"payment_workflow": {
"id": "pay_FVmAstJWfsD3SO",
"next": [
{
"action": "redirect",
"url": "https://api.razorpay.com/v1/payments/pay_FVmAstJWfsD3SO/authorize"
},
{
"action": "otp_generate",
"url": "https://api.razorpay.com/v1/payments/pay_FVmAstJWfsD3SO/otp_generate?track_id=FVmAtLUe9XZSGM&key_id=<YOUR_KEY_ID>"
}
]
}
}

1.3 Verify Payment Signature

Signature verification is a mandatory step to ensure that the callback is sent by Razorpay. The razorpay_signature contained in the callback can be regenerated by your system and verified as follows.

Create a string to be hashed using the razorpay_payment_id contained in the callback and the Order ID generated in the first step, separated by a |. Hash this string using SHA256 and your API Secret.

generated_signature = hmac_sha256(order_id + "|" + razorpay_payment_id, secret);
if (generated_signature == razorpay_signature) {
payment is successful
}

/**
* This class defines common routines for generating
* authentication signatures for Razorpay Webhook requests.
*/
public class Signature
{
private static final String HMAC_SHA256_ALGORITHM = "HmacSHA256";
/**
* Computes RFC 2104-compliant HMAC signature.
* * @param data
* The data to be signed.
* @param key
* The signing key.
* @return
* The Base64-encoded RFC 2104-compliant HMAC signature.
* @throws
* java.security.SignatureException when signature generation fails
*/
public static String calculateRFC2104HMAC(String data, String secret)
throws java.security.SignatureException
{
String result;
try {
// get an hmac_sha256 key from the raw secret bytes
SecretKeySpec signingKey = new SecretKeySpec(secret.getBytes(), HMAC_SHA256_ALGORITHM);
// get an hmac_sha256 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance(HMAC_SHA256_ALGORITHM);
mac.init(signingKey);
// compute the hmac on input data bytes
byte[] rawHmac = mac.doFinal(data.getBytes());
// base64-encode the hmac
result = DatatypeConverter.printHexBinary(rawHmac).toLowerCase();
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
return result;
}
}

1.4 Integrate Payments Rainy Day Kit

Use Payments Rainy Day kit to overcome payments exceptions such as:

1.5 Verify Payment Status

Handy Tips

On the Razorpay Dashboard, ensure that the payment status is captured. Refer to the payment capture settings page to know how to

.

You can track the payment status in three ways:

To verify the payment status from the Razorpay Dashboard:

  1. Log in to the Razorpay Dashboard and navigate to TransactionsPayments.
  2. Check if a Payment Id has been generated and note the status. In case of a successful payment, the status is marked as Captured.


Is this integration guide useful?

ON THIS PAGE