indiepay
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

indiepay

This is the server-side SDK for interacting with the Indie Pay API for initiating payment requests. This package has to be used only in case you are using the react-indiepay for performing checkout on your web app, so that you do not expose the AUTH_TOKEN and APP_ID for your project on the client side.

Installation

cd my-backend-app

npm i indiepay

Save the tokens in a .env file in your project:

INDIE_PAY_AUTH_TOKEN="<YOUR_INDIE_PAY_AUTH_TOKEN>"
INDIE_PAY_APP_ID="<YOUR_INDIE_PAY_APP_ID>"

NOTE: Never expose these tokens on your client side!


Initialise the IndiePay instance with the tokens:

import { IndiePay } from "indiepay";

const indiepay = new IndiePay({
  authToken: process.env.INDIE_PAY_AUTH_TOKEN,
  appID: process.env.INDIE_PAY_APP_ID,
});

Usage

Create a transaction request:

In order to create a transaction request, you need to provide some basic information related to the transaction. Refer to the following type definition for the TransactionRequest object:

export interface InitiateTransactionPayload {
  amount: number;
  currency: TCurrency;
  productInfo: TSDKProduct;
  metadata?: {
    [key: string]: any;
  };
}

The rest of the data like your Merchant VPA, Merchant Name, etc. will be fetched from the Indie Pay API using the appID provided during instantiation.

Make a call to the initiateTransactionRequest method of the IndiePay instance:

try {
  const txnRequestResp = await indiepay.initiateTransactionRequest({
    amount: 100.0,
    currency: "INR",
    productInfo: {
      title: "Test Product",
      description:
        "This is a description for the test product. A long and good descriptio",
      id: "1",
    },
  });

  // return txnRequestResp.transactionRequestID to client to be used by SDK
} catch (err) {
  console.error(err);
  // return 500 Internal Server Error
}

The payload returned by the initiateTransactionRequest method is of the type:

{
  transactionRequestID: string;
  message: string;
}

and the transactionRequestID should be sent to the client side to be used by the react-indiepay SDK.

Thats it! Integrate the client-side SDK to complete the process.

Last Step

Keep your backend ready to receive webhooks from Indie Pay.

Indie Pay will send a POST request to the webhook URL you provided with the following payload whenever you accept or reject an order. You can process subscriptions using the metadata, status, and order ID.

Kindly return a 200 OK response to the webhook request to avoid multiple retries. In case of a failure, Indie Pay will retry sending the webhook 3 times with an exponential backoff.

Thanks for using Indie Pay! 🚀

Package Sidebar

Install

npm i indiepay

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

20.7 kB

Total Files

12

Last publish

Collaborators

  • yash22arora