instamojo-payment-nodejs

3.0.0 • Public • Published

Promise based Instamojo NodeJs integrator

Promise based Instamojo payment gateway integrator for NodeJS based projects

  • No callback hell ✅
  • Clean, readable code with async-await 💖

Coverage

If you face any problems using this package, please create an issue on this repo OR even better, create a PR! 🙂

Installation

npm i instamojo-payment-nodejs // OR yarn add instamojo-payment-nodejs

APIs Available

  1. Setup keys
  2. Create a new payment request
  3. Get single payment request details
  4. Get single payment details
  5. Get all payment requests
  6. Initiate refund
  7. Get all refund requests
  8. Get single refund details with refundId

Setup keys

const Instamojo = require("instamojo-payment-nodejs");
 
Instamojo.isSandboxMode(true); // For testing
 
Instamojo.setKeys(API_KEY, AUTH_KEY);

Create new payment request

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

Get single payment request details

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": "john@doe.com",
        "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"
  }
}

Get single payment details

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": "john@doe.com",
      "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"
  }
}

Get all payment requests

const response = await Instamojo.getAllPaymentRequests();
Response from getAllPaymentRequests
{}

Initiate refund

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
}

Get all refund requests

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
}

Get single refund details with refundId

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
}


Road map:

  1. Create package with:

    1. ✅ Implement Sandbox mode for developers
    2. ✅ Create a payment request
    3. ✅ Write an easy-to-follow docs for package consumers
    4. ✅ Get Single payment request details
    5. ✅ Get Single payment details
    6. ✅ Get all payment requests
    7. ✅ Get all payments
  2. Refund

    1. ✅ Initiate refund
    2. ✅ Get all refund requests
    3. ✅ Get single refund details with refundId
  3. ✅ Reach code test coverage threshold 60%

  4. ✅ Reach code test coverage threshold 100%

Far

  1. Create GH Pages for usage Docs
  2. Implement TypeScript
  3. Build SWAGGER Docs for API testing or quick preview

Package Sidebar

Install

npm i instamojo-payment-nodejs

Weekly Downloads

99

Version

3.0.0

License

MIT

Unpacked Size

31.6 kB

Total Files

8

Last publish

Collaborators

  • codingcreate