Please refer to the Cashfree Docs for the complete API reference.
Node version 10.9.0 was used for this SDK.
const { PaymentGateway } = require('@cashfreepayments/cashfree-sdk');
// Instantiate Cashfree Payment Gateway
const pg = new PaymentGateway({
env: '<ENVIRONMENT>',
apiVersion: '<API_VERSION>',
appId: '<YOUR_APP_ID>',
secretKey: '<YOUR_SECRET_KEY>',
});
| Option | Required | Description |
| :--------- | :------: | :------------------------------------------------------------------: |
| env | true | Environment to be initialized. Must be one of TEST
or PRODUCTION
|
| apiVersion | true | Api version to be used. e.g. 1.0.0
|
| appId | true | Your application id which can be retreived from cashfree dashboard. |
| secretKey | true | Your secret key which can be retreived from cashfree dashboard. |
The response format for all requests is a JSON
object.
Whether a request succeeded is indicated by the HTTP status code. A 2xx status code indicates success, whereas a 4xx status code indicates failure. When a request fails, the response body is still JSON, but always contains the fields status
and message
(only if status is an error) which you can inspect to use for debugging. For example, trying to save an object with invalid keys will return the message:
| Parameter | Description |
| :-------- | :-----------------------------------------------: |
| status | status of API call. Values are - OK
and ERROR
|
| message | reason of failure when status is ERROR
|
Every method returns a promise which can be used:
const { PaymentGateway } = require('@cashfreepayments/cashfree-sdk');
const pg = new PaymentGateway({
env: '<ENVIRONMENT>',
apiVersion: '<API_VERSION>',
appId: '<YOUR_APP_ID>',
secretKey: '<YOUR_SECRET_KEY>',
});
pg.orders
.getLink({
orderId: '<ORDER_ID>',
})
.then((data) => console.log(data))
.catch((error) => console.error(error));
const { PaymentGateway } = require('@cashfreepayments/cashfree-sdk');
const pg = new PaymentGateway({
env: '<ENVIRONMENT>',
apiVersion: '<API_VERSION>',
appId: '<YOUR_APP_ID>',
secretKey: '<YOUR_SECRET_KEY>',
});
async function getOrderLink() {
try {
const response = await pg.orders.getLink({ orderId: '<ORDER_ID>' });
console.log(response);
} catch (e) {
console.error(e);
}
}
const { PaymentGateway } = require('@cashfreepayments/cashfree-sdk');
PaymentGateway.verifyCredentials({
env: '<ENVIRONMENT>', // must be one of [TEST / PRODUCTION]
appId: '<YOUR_APP_ID>',
secretKey: '<YOUR_SECRET_KEY>',
})
.then((data) => console.log(data))
.catch((error) => console.error(error));
Contains all APIs related to orders.
-
pg.orders .createOrders({ orderId: '<ORDER_ID>', // required orderAmount: '154', // required orderCurrency: 'INR', orderNote: 'Subscription', customerName: 'Test Name', // required customerPhone: '9111122222', // required customerEmail: 'johndoe@cashfree.com', // required sellerPhone: '', returnUrl: 'https://example.com/return', // required notifyUrl: 'https://example.com/notify', paymentModes: '', pc: '', }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.orders .getLink({ orderId: '<ORDER_ID>', // required }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.orders .getDetails({ orderId: '<ORDER_ID>', // required }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.orders .getStatus({ orderId: '<ORDER_ID>', // required }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.orders .triggerPaymentEmail({ orderId: '<ORDER_ID>', // required }) .then((data) => console.log(data)) .catch((error) => console.error(error));
Contains all APIs related to Transactions.
pg.transactions
.fetchTransactions({
startDate: '2019-01-01', // required
endDate: '2018-01-11', // required
txStatus: 'SUCCESS',
count: 2,
})
.then((data) => console.log(data))
.catch((error) => console.error(error));
Contains all APIs related to Refunds.
-
pg.refunds .initiateRefund({ orderId: '<ORDER_ID>', // required referenceId: '13307', // required refundAmount: '102.00', // required refundNote: 'Sample Refund note', // required refundType: '', refundType: '', mode: '', accountNo: '', ifsc: '', }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.refunds .fetchAllRefunds({ startDate: '2016-04-01', // required endDate: '2016-04-27', // required count: 2, }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.refunds .fetchSingleRefund({ refundId: '<REFUND_ID>', merchantRefundId: '1', // Provide refundId or merchantRefundId to get refund status }) .then((data) => console.log(data)) .catch((error) => console.error(error));
Contains all APIs related to Settlements.
-
pg.settlements .fetchAllSettlements({ startDate: '2016-04-01', // required endDate: '2016-04-30', // required count: 2, }) .then((data) => console.log(data)) .catch((error) => console.error(error));
-
pg.settlements .fetchSettlementById({ settlementId: '<SETTLEMENT_ID>', // required count: 2, }) .then((data) => console.log(data)) .catch((error) => console.error(error));