npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

instamojo-payment-nodejs

v3.0.0

Published

Promise based Instamojo payment gateway integration for NodeJS

Downloads

625

Readme

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);
{
  "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);
{
  "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"
  }
}

Get single payment details

const PAYMENT_REQUEST_ID = "0cb066f9d3764c2fab6da469d8f613ss";
const PAYMENT_ID = "MOJO0816705N15845280";
const paymentDetails = await Instamojo.getOnePayedPaymentDetails(
  PAYMENT_REQUEST_ID,
  PAYMENT_ID
);
{
  "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"
  }
}

Get all payment requests

const response = await Instamojo.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,

{
  "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();
{
  "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");
{
  "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