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

marupay

v0.4.0

Published

A package for making payment transactions with different african payments gateways.

Downloads

18

Readme

CI npm version

Marupay SDK

The Marupay SDK is a npm library that provides an easy-to-use interface for integrating with the multiple payment systems.

This SDK offers

  • Edahab API
  • Waafi API

Installation

To use the Marupay SDK in your project, you can install it using npm:

npm install marupay

Usage

To get started, import the necessary modules and configure the SDK with your credentials. The following example demonstrates how to set up the SDK for both eDahab and Waafi:

import { config } from "dotenv";
import express from "express";
import { HandlerName, ConfigObject, getPaymentHandler, Currency } from "marupay";
import { env } from "process";

// Load environment variables from a .env file
config();

const app = express();
const port = 3002;

app.use(express.urlencoded({ extended: true }));

// Configuration for different payment handlers (e.g., edahab, waafi)
const paymentConfig: ConfigObject = {
  edahab: {
    apiKey: env.DAHAB_API_KEY!,
    secretKey: env.DAHAB_SECRET_KEY!,
    merchantId: env.DAHAB_AGENT_CODE!,
  },
  waafi: {
    apiKey: env.WAAFI_API_KEY!,
    secretKey: env.WAAFI_API_USER_ID!,
    merchantId: env.WAAFI_MERCHANT_KEY!,
  },
};

// Choose a payment handler
const chosenHandler: HandlerName = "edahab";

app.get("/purchase", async (req, res) => {
  try {
    // Get the payment handler based on the chosen handler
    const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);

    // Make a purchase request
    const paymentInfo = await handler.purchase({
      accountNumber: "+2526512312341", // must start with `+` followed by country code
      amount: 500,
      currency: Currency.SLSH,
      description: "Test purchase",
      // for web handlers, you can optionally provide a return URL
      returnUrl: "https://example.com/return",
    });

    res.send(paymentInfo);
  } catch (e) {
    console.log(e);
    res.status(500).send("Internal Server Error");
  }
});

app.get("/credit", async (req, res) => {
  try {
    // Get the payment handler based on the chosen handler
    const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);

    // Credit an account
    const paymentInfo = await handler.credit({
      accountNumber: "+2526512312341", // must start with `+` followed by country code
      amount: 1000,
      currency: Currency.SLSH,
      description: "Test credit",
    });

    res.send(paymentInfo);
  } catch (e) {
    console.log(e);
    res.status(500).send("Internal Server Error");
  }
});

app.listen(port, () => {
  console.log(`Server is listening at http://localhost:${port}`);
});

Responses

The credit and purchase methods both returns a PaymentInfo object. It'll return these details:

  • transactionId: This identifier is obtained from the vendor's transaction ID. It uniquely identifies the transaction in the vendor's system.

  • paymentStatus: The payment status is also retrieved from the vendor's response. It indicates the current status of the payment transaction in the vendor's system.

  • referenceId: The reference ID is specific to Marupay and is provided in Marupay's response. It serves as a unique identifier for the transaction within Marupay's system.

  • raw: This will return unfiltered response details from the vendor.

Examples

The provided examples demonstrate how to use the Marupay SDK for both purchase and credit transactions with eDahab and Waafi payment handlers. Customize the route handlers according to your application's needs.

Contributing

If you encounter any issues or have suggestions for improvements, feel free to contribute by opening issues or submitting pull requests on the GitHub repository.

Check here for full guide on how to contribute: https://docs.marupay.dev/contributing

License

This SDK is released under the MIT License. Feel free to use, modify, and distribute it as needed for your projects.