-
Notifications
You must be signed in to change notification settings - Fork 111
Home
Instantiate the razorpay instance with key_id
& key_secret
. You can obtain the keys from the dashboard app (https://dashboard.razorpay.com/#/app/keys)
var instance = new Razorpay({
key_id: 'YOUR_KEY_ID',
key_secret: 'YOUR_KEY_SECRET'
})
The resources can be accessed via the instance. All the methods invocations follows the namespaced signature
// API signature
// {razorpayInstance}.{resourceName}.{methodName}(resourceId [, params])
// example
instance.payments.fetch(paymentId)
Every resource method returns a promise.
instance.payments.all({
from: '2016-08-01',
to: '2016-08-20'
}).then((response) => {
// handle success
}).catch((error) => {
// handle error
})
If you want to use callbacks instead of promises, every resource method will accept a callback function as a last parameter. The callback functions will behave as Error First Callbacks
instance.payments.all({
from: '2016-08-01',
to: '2016-08-20'
}, (error, response) => {
if (error) {
// handle error
} else {
// handle success
}
})
*
indicates mandatory field
Fetches payments list.
Name | Type | Description |
---|---|---|
from | timestamp | timestamp after which the payments were created |
to | timestamp | timestamp before which the payments were created |
count | integer | number of payments to fetch (default: 10) |
skip | integer | number of payments to be skipped (default: 0) |
Retrieves a particular payment.
Parameters:
Name | Type | Description |
---|---|---|
payment_id* | string | Id of the payment to be retrieved |
Capture a payment.
Parameters:
Name | Type | Description |
---|---|---|
paymentId* | string | Id of the payment to capture |
amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) |
currency | string | The currency of the payment (defaults to INR) |
Refund a payment.
Parameters:
Name | Type | Description |
---|---|---|
payment_id* | string | Id of the payment to refund |
amount | integer | The amount to be refunded (in paise) |
notes | object | A key-value pair |
Retrieves additional details about a payment which is a Bank Transfer
Parameters
Name | Type | Description |
---|---|---|
payment_id* | string | Id of the payment to be retrieved |
--
Fetches refunds list. If
payment_id
is passed, refunds of that particular payment is fetched
Parameters:
Name | Type | Description |
---|---|---|
payment_id | string | The payment id whose refunds are to be fetched |
from | timestamp | timestamp after which the payments were created |
to | timestamp | timestamp before which the payments were created |
count | integer | number of payments to fetch (default: 10) |
skip | boolean | number of payments to be skipped (default: 0) |
Fetches a refund.
Parameters:
Name | Type | Description |
---|---|---|
refund_id* | string | ID of the refund to be retrieved |
payment_id | string | The id of the payment whose refund is to be retrieved |
--
Create an order in razorpay
Parameters:
Name | Type | Description |
---|---|---|
amount* | integer | Amount of the order to be paid |
currency | string | Currency of the order. Currently only INR is supported. |
receipt* | string | Your system order reference id. |
payment_capture | boolean | Whether the payment should be captured automatically or not. Default false
|
notes | object | A key-value pair |
Fetches orders list
Parameters
Name | Type | Description |
---|---|---|
from | timestamp | timestamp after which the payments were created |
to | timestamp | timestamp before which the payments were created |
count | integer | number of payments to fetch (default: 10) |
skip | integer | number of payments to be skipped (default: 0) |
authorized | boolean | Orders for which payments are currently in authorized state. |
receipt | string | Orders with the provided value for receipt. |
Fetches a particular order
Parameters
Name | Type | Description |
---|---|---|
order_id* | string | The id of the order to be retrieved |
Fetches an order's payments
Parameters
Name | Type | Description |
---|---|---|
order_id* | string | The id of the order to be retrieved |
--
Create a customer
Parameters:
Name | Type | Description |
---|---|---|
name | string | Name of the customer |
email* | string | Email of the customer |
contact* | string | Contact number of the customer |
notes | object | A key-value pair |
Edit a customer
Parameters
Name | Type | Description |
---|---|---|
customer_id* | string | The id of the customer to be edited |
name | string | Name of the customer |
string | Email of the customer | |
contact | string | Contact number of the customer |
notes | object | A key-value pair |
Fetches a customer
Parameters
Name | Type | Description |
---|---|---|
customer_id* | string | The id of the customer to be retrieved |
Fetches all card tokens of a customer
Parameters
Name | Type | Description |
---|---|---|
customer_id* | string | The id of the customer whose card tokens has to be retrieved |
Fetches a particular card token of a customer
Parameters
Name | Type | Description |
---|---|---|
customer_id* | string | The id of the customer whose card token has to be retrieved |
token_id* | string | The id of the token to be retrieved |
Deletes the card token
Parameters
Name | Type | Description |
---|---|---|
customer_id* | string | The id of the customer whose card token has to be deleted |
token_id* | string | The id of the token to be deleted |
--
Fetch all transfers
Parameters
Name | Type | Description |
---|---|---|
payment_id | string | If sent in params, fetches all transfers created on the payment |
Fetch transfer by ID
Parameters
Name | Type | Description |
---|---|---|
transfer_id* | string | The id of the transfer to be fetched |
Edit transfer attributes
Parameters
Name | Type | Description |
---|---|---|
transfer_id* | string | The id of the transfer to be edited |
on_hold | boolean | Transfer on hold status |
on_hold_until | integer | Transfer settlement on hold until time |
notes | object | A key-value pair |
Create a new direct transfer
Create a transfer from a payment
Parameters
Name | Type | Description |
---|---|---|
payment_id* | string | The id of the payment to be transferred |
Reverse a transfer
Parameters
Name | Type | Description |
---|---|---|
transfer_id* | string | The id of the transfer to be reversed |
amount* | integer | Amount to reverse |
currency* | string | Currency code |
notes | object | A key-value pair |
Fetch all Virtual Accounts
Parameters
Name | Type | Description |
---|---|---|
from | timestamp | timestamp after which the Virtual Accounts were created |
to | timestamp | timestamp before which the Virtual Accounts were created |
count | integer | number of Virtual Accounts to fetch (default: 10) |
skip | integer | number of Virtual Accounts to be skipped (default: 0) |
Fetch a Virtual Account by ID
Parameters
Name | Type | Description |
---|---|---|
virtualAccountId* | string | The id of the Virtual Account to be fetched |
Create a Virtual Account
Parameters
Name | Type | Description |
---|---|---|
receiver_types | array | Array that defines what receivers are available for this Virtual Account |
notes | object | A key-value pair |
Close a Virtual Account
Parameters
Name | Type | Description |
---|---|---|
virtualAccountId* | string | The id of the Virtual Account to be closed |
Fetches payments for the given Virtual Account
Parameters
Name | Type | Description |
---|---|---|
virtualAccountId* | string | The id of the Virtual Account to be closed |
to get extra details about the payment, use payments.bankTransfer
api
--
Invoice entity gets used for both Payment Links and Invoices system. Few of the methods are only meaningful for Invoices system and calling those for against/for a Payment Link would throw Bad request error.
For Payment Links , please pass type
as link
for creation, updation and search APIs
Creates invoice of any type(invoice|link|ecod)
Parameters
All the parameters mentioned in the API Reference are supported
Patches given invoice with new attributes
Parameters
Please Refer API Reference
Issues drafted invoice
Name | Type | Description |
---|---|---|
invoiceId* | string | The id of the Invoice to be Issued |
Deletes drafted invoice
Parameters
Name | Type | Description |
---|---|---|
invoiceId* | string | The id of the Invoice to be Deleted |
Cancels issued invoice
Parameters
Name | Type | Description |
---|---|---|
invoiceId* | string | The id of the Invoice to be Cancelled |
Fetches invoice entity with given id
Parameters
Name | Type | Description |
---|---|---|
invoiceId* | string | The id of the Invoice to be Fetched |
Fetches multiple invoices with given query options
Parameters
All the parameters mentioned in the API Reference
Send/re-send notification for invoice by given medium
Parameters
Name | Type | Description |
---|---|---|
invoiceId* | string | The id of the Invoice |
medium* | string |
sms /email , Medium through which notification should be sent. |
--
Create a plan with given params
Parameters
Name | Type | Description |
---|---|---|
params | object | All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported |
Fetches plan details given Plan Id
Name | Type | Description |
---|---|---|
planId* | string | The id of the Plan to be Fetched. |
Fetches all plans with given params
Name | Type | Description |
---|---|---|
params | object | All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported |
--
Subscriptions allow you to charge a customer's card on a recurring basis. A subscription ties a customer to a particular plan you've created.
Create Subscription with the given params
Name | Type | Description |
---|---|---|
params | object | All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported |
Fetch a Subscription given Subcription ID
Name | Type | Description |
---|---|---|
subscriptionId* | string | The id of the Subscription to be Fetched. |
Get all Subscriptions
Name | Type | Description |
---|---|---|
params | object | All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported |
Cancel a subscription given id and optional cancelAtCycleEnd
Name | Type | Description |
---|---|---|
subscriptionId* | string | The id of the Subscription to be Fetched. |
cancelAtCycleEnd | boolean. | by default its false . for more info refer https://razorpay.com/docs/subscriptions/api/#cancelling-a-subscription
|
Creates addon for the given subscription with the given params
Name | Type | Description |
---|---|---|
subscriptionId* | string | The id of the Subscription to be Fetched. |
params | object | All parameters listed here https://razorpay.com/docs/subscriptions/api/#entity__ are supported |
--
To create an addon, use subscriptions.createAddon
api
Fetches addon given addon id
Name | Type | Description |
---|---|---|
addonId* | string | The id of the Addon to be Fetched. |
Deletes addon given addon id
Name | Type | Description |
---|---|---|
addonId* | string | The id of the Addon to be Fetched. |
--
Razorpay Webhooks
To validate Webhook signature, use the static method
Razorpay.validateWebhookSignature
Name | Type | Description |
---|---|---|
body* | string | The raw request body |
signature* | string | The signature sent in request Header X-Razorpay-Signature
|
secret* | string | The secret you used when creating the webhook on dashboard |
Sample Code using node http module
const http = require('http'),
razorpay = require("razorpay");
const mySecret = "123456";
const server = http.createServer((req, res) => {
let reqBody = "",
signature = req.headers["x-razorpay-signature"];
req.on("data", (data) => {
reqBody += data;
});
req.on("end", (data) => {
console.log("is signature valid");
console.log(razorpay.validateWebhookSignature(reqBody, signature, mySecret));
});
});
server.listen(8000);
/*
* tested with following values
* req body: {"a":1,"b":2,"c":{"d":3}}
* signature: "2fe04e22977002e6c7cb553adab8b460cb9e2a4970d5953cb27a8472752e3bbc"
* secret: "123456"
*/
/*
curl -X POST \
http://localhost:8000/ \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'X-Razorpay-Signature: 2fe04e22977002e6c7cb553adab8b460cb9e2a4970d5953cb27a8472752e3bbc' \
-d '{"a":1,"b":2,"c":{"d":3}}'
*/
--
If you have a Partner account. In order to authenticate and use the api as a particular merchant , please pass an extra header X-Razorpay-Account
and value acc_<account num>
Example:
var instance = new Razorpay({
key_id: '<your_partner_key>',
key_secret: '<your_partner_secret>',
headers: {
"X-Razorpay-Account": "<merchant_account_id>"
}
});
instance.orders.all().then(console.log).catch(console.error);