1.1 Create an Order in Server🔗
Order is an important step in the payment process.
- An order should be created for every payment.
- You can create an order using the Orders API. It is a server-side API call. Know how to authenticate Orders API.
- The order_id received in the response should be passed to the checkout. This ties the Order with the payment and secures the request from being tampered.
Given below are the order states and the corresponding payment states:
Payment Stages | Order State | Payment State | Description |
---|---|---|---|
Stage I | created | created | The customer submits the payment information, which is sent to Razorpay. The payment in not processed at this stage. |
Stage II | attempted | authorized/failed | An order moves from created to attempted state when payment is first attempted. It remains in this state until a payment associated with the order is captured. |
Stage III | paid | captured | After the payment moves to the captured state, the order moves to the paid state.
|
Handy Tips
You can capture payments automatically with the one-time Payment Capture setting configuration on the Razorpay Dashboard.
GitHub & Documentation Links for SDKs🔗
Language | Git Hub Repo | Documentation Link |
---|---|---|
.NET | Github | Documentation |
Go | GitHub | Documentation |
Java | GitHub | Documentation |
NodeJS | GitHub | Documentation |
PHP | GitHub | Documentation |
Python | GitHub | Documentation |
Ruby | GitHub | Documentation |
API Sample Code🔗
Order is an important step in the payment process.
- An order should be created for every payment.
- You can create an order using the Orders API. It is a server-side API call. Know how to authenticate Orders API.
- The order_id received in the response should be passed to the checkout. This ties the Order with the payment and secures the request from being tampered.
API Sample Code🔗
The following is a sample API request and response for creating an order:
Copycurl -X POST https://api.razorpay.com/v1/orders
-U [YOUR_KEY_ID]:[YOUR_KEY_SECRET]
-H 'content-type:application/json'
-d '{
"amount": 500,
"currency": "INR",
"receipt": "qwsaq1",
"partial_payment": true,
"first_payment_min_amount": 230
}'
CopyRazorpayClient razorpay = new RazorpayClient("[YOUR_KEY_ID]", "[YOUR_KEY_SECRET]");
JSONObject orderRequest = new JSONObject();
orderRequest.put("amount", 50000); // amount in the smallest currency unit
orderRequest.put("currency", "INR");
orderRequest.put("receipt", "order_rcptid_11");
Order order = razorpay.Orders.create(orderRequest);
} catch (RazorpayException e) {
// Handle Exception
System.out.println(e.getMessage());
}
Copyimport razorpay
client = razorpay.Client(auth=("YOUR_ID", "YOUR_SECRET"))
DATA = {
"amount": 100,
"currency": "INR",
"receipt": "receipt#1",
"notes": {
"key1": "value3",
"key2": "value2"
}
}
client.order.create(data=DATA)
Copy$api = new Api($key_id, $secret);
$api->order->create(array('receipt' => '123', 'amount' => 100, 'currency' => 'INR', 'notes'=> array('key1'=> 'value3','key2'=> 'value2')));
CopyRazorpayClient client = new RazorpayClient(your_key_id, your_secret);
Dictionary<string, object> options = new Dictionary<string,object>();
options.Add("amount", 50000); // amount in the smallest currency unit
options.add("receipt", "order_rcptid_11");
options.add("currency", "INR");
Order order = client.Order.Create(options);
Copyrequire "razorpay"
Razorpay.setup('YOUR_KEY_ID', 'YOUR_SECRET')
options = amount: 50000, currency: 'INR', receipt: '<order_rcptid_11>'
order = Razorpay::Order.create
Copyvar instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' })
instance.orders.create({
amount: 50000,
currency: "INR",
receipt: "receipt#1",
notes: {
key1: "value3",
key2: "value2"
}
})
Copyimport ( razorpay "github.com/razorpay/razorpay-go" )
client := razorpay.NewClient("YOUR_KEY_ID", "YOUR_SECRET")
data := map[string]interface{}{
"amount": 50000,
"currency": "INR",
"receipt": "some_receipt_id"
}
body, err := client.Order.Create(data)
Copy{
"id": "order_IluGWxBm9U8zJ8",
"entity": "order",
"amount": 5000,
"amount_paid": 0,
"amount_due": 5000,
"currency": "INR",
"receipt": "rcptid_11",
"offer_id": null,
"status": "created",
"attempts": 0,
"notes": [],
"created_at": 1642662092
}
Request Parameters🔗
Here is the list of parameters for creating an order:
amount
mandatoryinteger
The transaction amount, expressed in the currency subunit, such as paise (in case of INR). For example, for an actual amount of ₹299.35, the value of this field should be29935
.currency
mandatorystring
The currency in which the transaction should be made. See the list of supported currencies. Length must be of 3 characters.receipt
optionalstring
Your receipt id for this order should be passed here. Maximum length 40 characters.notes
optionaljson object
Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. For example,"note_key": "Beam me up Scotty”
.partial_payment
optionalboolean
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
optionalinteger
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 as500000
. This parameter should be passed only ifpartial_payment
istrue
.
Know more about Orders API.
Error Response Parameters🔗
The error response parameters are available in the API Reference Guide.