Promise based Instamojo payment gateway integrator for NodeJS based projects
- No callback hell ✅
- Clean, readable code with async-await 💖
If you face any problems using this package, please create an issue on this repo OR even better, create a PR! 🙂
npm i instamojo-payment-nodejs // OR yarn add instamojo-payment-nodejs
- Setup keys
- Create a new payment request
- Get single payment request details
- Get single payment details
- Get all payment requests
- Initiate refund
- Get all refund requests
- Get single refund details with
refundId
const Instamojo = require("instamojo-payment-nodejs");
Instamojo.isSandboxMode(true); // For testing
Instamojo.setKeys(API_KEY, AUTH_KEY);
const options = {
purpose: "Product name", // REQUIRED
amount: 20, // REQUIRED and must be > ₹3 (3 INR)
currency: "INR",
buyer_name: "",
email: "",
phone: null,
send_email: false,
send_sms: false,
allow_repeated_payments: false,
webhook: "",
redirect_url: "",
};
const paymentData = Instamojo.PaymentData(options);
const response = await Instamojo.createNewPaymentRequest(paymentData);
Response from createNewPaymentRequest
{
"success": true,
"payment_request": {
"id": 0cb066f9d3764c2fab6da469d8f613ss,
"phone": null,
"email": "",
"buyer_name": "",
"amount": "20.00",
"purpose": "Product name",
"expires_at": null,
"status": "Pending",
"send_sms": false,
"send_email": false,
"sms_status": null,
"email_status": null,
"shorturl": null,
"longurl": "https://test.instamojo.com/@user/0cb066f9d3764c2fab6da469d8f613ss",
"redirect_url": "",
"webhook": "",
"allow_repeated_payments": false,
"customer_id": null,
"created_at": "2020-08-16T08:26:26.382335Z",
"modified_at": "2020-08-16T08:26:26.382353Z"
}
}
const PAYMENT_REQUEST_ID = "0cb066f9d3764c2fab6da469d8f613ss";
const status = await Instamojo.getPaymentRequestStatus(PAYMENT_REQUEST_ID);
Status from getPaymentRequestStatus
{
"success": true,
"payment_request": {
"id": "0cb066f9d3764c2fab6da469d8f613ss",
"phone": null,
"email": "",
"buyer_name": "",
"amount": "20.00",
"purpose": "Product name",
"expires_at": null,
"status": "Completed",
"send_sms": false,
"send_email": false,
"sms_status": null,
"email_status": null,
"shorturl": null,
"longurl": "https://test.instamojo.com/@USER/0cb066f9d3764c2fab6da469d8f613ss",
"redirect_url": "",
"webhook": "",
"payments": [
{
"payment_id": "MOJO0816705N15845280",
"status": "Credit",
"currency": "INR",
"amount": "20.00",
"buyer_name": "John Doe",
"buyer_phone": "+919900000000",
"buyer_email": "[email protected]",
"shipping_address": null,
"shipping_city": null,
"shipping_state": null,
"shipping_zip": null,
"shipping_country": null,
"quantity": 1,
"unit_price": "20.00",
"fees": "0.38",
"variants": [],
"custom_fields": {},
"affiliate_commission": "0",
"payment_request": "https://test.instamojo.com/api/1.1/payment-requests/0cb066f9d3764c2fab6da469d8f613ss/",
"instrument_type": "NETBANKING",
"billing_instrument": "Domestic Netbanking Regular",
"tax_invoice_id": "",
"failure": null,
"payout": null,
"created_at": "2020-08-16T08:34:29.939734Z"
}
],
"allow_repeated_payments": false,
"customer_id": null,
"created_at": "2020-08-16T08:26:26.382335Z",
"modified_at": "2020-08-16T08:34:40.470238Z"
}
}
const PAYMENT_REQUEST_ID = "0cb066f9d3764c2fab6da469d8f613ss";
const PAYMENT_ID = "MOJO0816705N15845280";
const paymentDetails = await Instamojo.getOnePayedPaymentDetails(
PAYMENT_REQUEST_ID,
PAYMENT_ID
);
paymentDetails from getOnePayedPaymentDetails
{
"success": true,
"payment_request": {
"id": "0cb066f9d3764c2fab6da469d8f613ss",
"phone": null,
"email": "",
"buyer_name": "",
"amount": "20.00",
"purpose": "Product name",
"expires_at": null,
"status": "Completed",
"send_sms": false,
"send_email": false,
"sms_status": null,
"email_status": null,
"shorturl": null,
"longurl": "https://test.instamojo.com/@USER/0cb066f9d3764c2fab6da469d8f613ss",
"redirect_url": "",
"webhook": "",
"payment": {
"payment_id": "MOJO0816705N15845280",
"status": "Credit",
"currency": "INR",
"amount": "20.00",
"buyer_name": "John Doe",
"buyer_phone": "+919900000000",
"buyer_email": "[email protected]",
"shipping_address": null,
"shipping_city": null,
"shipping_state": null,
"shipping_zip": null,
"shipping_country": null,
"quantity": 1,
"unit_price": "20.00",
"fees": "0.38",
"variants": [],
"custom_fields": {},
"affiliate_commission": "0",
"payment_request": "https://test.instamojo.com/api/1.1/payment-requests/0cb066f9d3764c2fab6da469d8f613ss/",
"instrument_type": "NETBANKING",
"billing_instrument": "Domestic Netbanking Regular",
"tax_invoice_id": "",
"failure": null,
"payout": null,
"created_at": "2020-08-16T08:34:29.939734Z"
},
"allow_repeated_payments": false,
"customer_id": null,
"created_at": "2020-08-16T08:26:26.382335Z",
"modified_at": "2020-08-16T08:34:40.470238Z"
}
}
const response = await Instamojo.getAllPaymentRequests();
Response from getAllPaymentRequests
{}
const refundInstance = new Instamojo.RefundRequestOptions({
payment_id: "MOJO0816705N15845280",
type: "RFD", // Refer below section
body: "Reason for refund",
});
refundInstance.setOptionalRefundAmount(99);
const refundResponse = await Instamojo.initiateRefund(
refundInstance.getObject()
);
Valid values for type parameter:
RFD
: Duplicate/delayed payment.TNR
: Product/service no longer available.QFL
: Customer not satisfied.QNR
: Product lost/damaged.EWN
: Digital download issue.TAN
: Event was canceled/changed.PTH
: Problem not described above.
For more, refer: https://docs.instamojo.com/docs/creating-a-refund,
Response from initiateRefund
{
"refund": {
"id": "C5c0751269",
"payment_id": "MOJO5a06005J21512197",
"status": "Refunded",
"type": "QFL",
"body": "Customer isn't satisfied with the quality",
"refund_amount": "2500.00",
"total_amount": "2500.00",
"created_at": "2015-12-07T11:01:37.640Z"
},
"success": true
}
const response = await Instamojo.getAllRefunds();
Response from getAllRefunds
{
"refunds": [
{
"id": "C5c0751269",
"payment_id": "MOJO5a06005J21512197",
"status": "Refunded",
"type": "QFL",
"body": "Customer isn't satisfied with the quality",
"refund_amount": "2500.00",
"total_amount": "2500.00",
"created_at": "2015-12-07T11:01:37.640Z"
}
],
"success": true
}
const response = await Instamojo.getRefundDetails("C5c0751272");
Response from getRefundDetails
{
"refund": {
"id": "C5c0751272",
"payment_id": "MOJO5a06005J21512197",
"status": "Refunded",
"type": "QFL",
"body": "Customer isn't satisfied with the quality",
"refund_amount": "2500.00",
"total_amount": "2500.00",
"created_at": "2015-12-07T11:04:09.500Z"
},
"success": true
}
-
Create package with:
- ✅ Implement Sandbox mode for developers
- ✅ Create a payment request
- ✅ Write an easy-to-follow docs for package consumers
- ✅ Get Single payment request details
- ✅ Get Single payment details
- ✅ Get all payment requests
- ✅ Get all payments
-
Refund
- ✅ Initiate refund
- ✅ Get all refund requests
- ✅ Get single refund details with refundId
-
✅ Reach code test coverage threshold 60%
-
✅ Reach code test coverage threshold 100%
- Create GH Pages for usage Docs
- Implement TypeScript
- Build SWAGGER Docs for API testing or quick preview