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

tranxs

v1.0.2

Published

tranxs is a powerful and easy-to-use Node.js library for integrating M-Pesa payment services into your application. It provides seamless support for all major M-Pesa transactions, including STK Push, B2C, B2B, C2B, Reversal, Account Balance, and Transacti

Downloads

14

Readme

Tranxs

tranxs is a powerful and easy-to-use Node.js library for integrating M-Pesa payment services into your application. It provides seamless support for all major M-Pesa transactions, including STK Push, B2C, B2B, C2B, Reversal, Account Balance, and Transaction Status queries. Whether you're building a fintech application, e-commerce platform, or any system requiring mobile payments, tranxs simplifies M-Pesa's complex APIs with an intuitive interface.

Instllation

npm i tranxs

M-pesa STK-push example

Making STK push request

import { Mpesa } from "tranxs";
import dotenv from "dotenv";

dotenv.config();

const credentials = {
  CONSUMER_KEY: process.env.MPESA_CONSUMER_KEY,
  CONSUMER_SECRET: process.env.MPESA_CONSUMER_SECRET,
  BUSINESS_SHORT_CODE: process.env.MPESA_BUSINESS_SHORT_CODE,
  PASS_KEY: process.env.MPESA_PASS_KEY,
};

const transaction = new Mpesa(credentials, "production"); // or sandbox for sandbox applications
transaction
  .stkPush({
    phone: "0712345678",
    amount: 100,
    callbackUrl: "https://mydomain.com/callback",
  })
  .then((response) => {
    console.log("STK Push Response:", response);
  });

Expected Response

{
  "MerchantRequestID": "38d5-4ca6-b9c9-0240a9781f7a24954456",
  "CheckoutRequestID": "ws_CO_04102024170035818712028821",
  "ResponseCode": "0",
  "ResponseDescription": "Success. Request accepted for processing",
  "CustomerMessage": "Success. Request accepted for processing"
}

B2C EXAMPLE

Making a b2c request

import { Mpesa } from "tranxs";
import dotenv from "dotenv";

dotenv.config();

const b2c_credentials = {
  CONSUMER_KEY: process.env.SANDBOX_KEY,
  CONSUMER_SECRET: process.env.SANDBOX_SECRET,
  BUSINESS_SHORT_CODE: process.env.SANDBOX_BUSINESS_NUMBER,
  INITIATOR_PASSWORD: process.env.SANDBOX_B2C_INITIATOR_PASSWORD,
  INITIATOR_NAME: process.env.SANDBOX_B2C_INITIATOR_NAME,
};

const mpesa = new Mpesa(b2c_credentials, "sandbox"); // or production

mpesa
  .b2c({
    phone: "2547123456789",
    amount: 100,
    resultCallbackUrl: "https://mydomain.com/callback",
    queueTimeOutURL: "https://mydomain.com/timeout",
    commandID: "BusinessPayment",
  })
  .then((response) => {
    console.log(response);
  });

Expected response

{
  "ConversationID": "AG_20241004_20101e712a4c5b931e70",
  "OriginatorConversationID": "32f3b1ea-f0d7-4c99-b29e-5e3866cf75d6",
  "ResponseCode": "0",
  "ResponseDescription": "Accept the service request successfully."
}