Skip to content
Umang Galaiya edited this page Mar 6, 2019 · 23 revisions

Documentation

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
  }
})

Resources

* indicates mandatory field

Payments

instance.payments.all({from, to, count, skip})

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)

instance.payments.fetch(payment_id)

Retrieves a particular payment.

Parameters:

Name Type Description
payment_id* string Id of the payment to be retrieved

instance.payments.capture(payment_id, amount, currency)

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)

instance.payments.refund(payment_id, {amount, notes})

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

instance.payments.bankTransfer(paymentId)

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

--

Refunds

instance.refunds.all({from, to, count, skip, payment_id})

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)

instance.refunds.fetch(refund_id, {payment_id})

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

--

Orders

instance.orders.create({amount, currency, receipt, payment_capture, notes})

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

instance.orders.all({from, to, count, skip, authorized, receipt})

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.

instance.orders.fetch(order_id)

Fetches a particular order

Parameters

Name Type Description
order_id* string The id of the order to be retrieved

instance.orders.fetchPayments(order_id)

Fetches an order's payments

Parameters

Name Type Description
order_id* string The id of the order to be retrieved

--

Customers

instance.customers.create({name, email, contact, notes})

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

instance.customers.edit(customer_id, {name, email, contact, notes})

Edit a customer

Parameters

Name Type Description
customer_id* string The id of the customer to be edited
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

instance.customers.fetch(customer_id)

Fetches a customer

Parameters

Name Type Description
customer_id* string The id of the customer to be retrieved

instance.customers.fetchTokens(customer_id)

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

instance.customers.fetchToken(customer_id, token_id)

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

instance.customers.deleteToken(customer_id, token_id)

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

--

Transfers

instance.transfers.all({params})

Fetch all transfers

Parameters

Name Type Description
payment_id string If sent in params, fetches all transfers created on the payment

instance.transfers.fetch(transfer_id)

Fetch transfer by ID

Parameters

Name Type Description
transfer_id* string The id of the transfer to be fetched

instance.transfers.edit(transfer_id, {on_hold, on_hold_until, notes})

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

instance.transfers.create({params})

Create a new direct transfer

instance.payments.transfer(payment_id, {params})

Create a transfer from a payment

Parameters

Name Type Description
payment_id* string The id of the payment to be transferred

instance.transfers.reverse(transfer_id, {amount, currency, notes})

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

Virtual Accounts

instance.virtualAccounts.all({params})

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)

instance.virtualAccounts.fetch(virtualAccountId)

Fetch a Virtual Account by ID

Parameters

Name Type Description
virtualAccountId* string The id of the Virtual Account to be fetched

instance.virtualAccounts.create({params})

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

instance.virtualAccounts.close(virtualAccountId)

Close a Virtual Account

Parameters

Name Type Description
virtualAccountId* string The id of the Virtual Account to be closed

instance.virtualAccounts.fetchPayments(virtualAccountId)

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

--

Invoices

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

instance.invoices.create(params)

Creates invoice of any type(invoice|link|ecod)

Parameters

All the parameters mentioned in the API Reference are supported

instance.invoices.edit(params)

Patches given invoice with new attributes

Parameters

Please Refer API Reference

instance.invoices.issue(invoiceId)

Issues drafted invoice

Name Type Description
invoiceId* string The id of the Invoice to be Issued

instance.invoices.delete(invoiceId)

Deletes drafted invoice

Parameters

Name Type Description
invoiceId* string The id of the Invoice to be Deleted

instance.invoices.cancel(invoiceId)

Cancels issued invoice

Parameters

Name Type Description
invoiceId* string The id of the Invoice to be Cancelled

instance.invoices.fetch(invoiceId)

Fetches invoice entity with given id

Parameters

Name Type Description
invoiceId* string The id of the Invoice to be Fetched

instance.invoices.all(params)

Fetches multiple invoices with given query options

Parameters

All the parameters mentioned in the API Reference

instance.invoices.notifyBy(invoiceId, medium)

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.

--

Plans

instance.plans.create(params)

Create a plan with given params

Parameters

Name Type Description
params object All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported

instance.plans.fetch(planId)

Fetches plan details given Plan Id

Name Type Description
planId* string The id of the Plan to be Fetched.

instance.plans.all(params)

Fetches all plans with given params

Name Type Description
params object All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported

--

Subscriptions

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.

instance.subscriptions.create(params)

Create Subscription with the given params

Name Type Description
params object All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported

instance.subscriptions.fetch(subscriptionId)

Fetch a Subscription given Subcription ID

Name Type Description
subscriptionId* string The id of the Subscription to be Fetched.

instance.subscriptions.all(params)

Get all Subscriptions

Name Type Description
params object All keys listed here https://razorpay.com/docs/subscriptions/api/ are supported

instance.subscriptions.cancel(subscriptionId, cancelAtCycleEnd)

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

instance.subscriptions.createAddon(subscriptionId, params)

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

--

Addons

To create an addon, use subscriptions.createAddon api

instance.addons.fetch(addonId)

Fetches addon given addon id

Name Type Description
addonId* string The id of the Addon to be Fetched.

instance.addons.delete(addonId)

Deletes addon given addon id

Name Type Description
addonId* string The id of the Addon to be Fetched.

--

Webhooks

Razorpay Webhooks

Razorpay.validateWebhookSignature(body, signature, secret)

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}}'
*/

--

Partner Auth

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);
Clone this wiki locally