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

mpesa-api-nodejs

v2.0.0

Published

Biblioteca em NodeJS para M-PESA (Moçambique)

Downloads

48

Readme

mpesa-api-nodejs

API escrita em NodeJS para M-PESA (Moçambique)

License: GPL v3

Esta API (Aplication programing interface), permite efectuar transações no m-pesa usando o NodeJS.

Instalação

npm install mpesa-api-nodejs

Implementação

Primeiramente crie uma conta no site https://developer.mpesa.vm.co.mz/ e obtenha a api key e o public key

const MpesaAPI = require("mpesa-api-nodejs");

const api_key = "";		// Aqui introduz a api key disponibilizada no site
const public_key = "";	// Aqui introduz o public key disponibilizado no site
const environment = "development"; // development/production
const ssl = true;		// True se pretende utilizar uma conexão segura (SSL)

// Inicialização e criação do objecto
const mpesa = MpesaAPI.init(api_key, public_key, environment, ssl);

Transferência business to client (de negócio para cliente)

Transferência de valor do agente para o clinte

const data = {
	value: 10,
	client_number: "258840000000",
	agent_id: 171717,
	transaction_reference: 1234567,
	third_party_reference: 33333
};

const response = await mpesa.b2c(data);

/* OR */

mpesa.b2c(data).then(response => {
	console.log(response);
}).catch(ex => console.log(ex));
Provável resposta caso bem sucedido
{
  "output_ResponseCode": "INS-0",
  "output_ResponseDesc": "Request processed successfully",
  "output_TransactionID": "wgzupjwc5mm9",
  "output_ConversationID": "ccf590fbfa1d4ff4a245b9c430a64220",
  "output_ThirdPartyReference": "33333"
}

Transferência client to business (de cliente para negócio)

Transferência de valor do cliente para o agente

const data = {
	value: 10,
	client_number: "258840000000",
	agent_id: 171717,
	transaction_reference: 1234567,
	third_party_reference: 33333
};

const response = await mpesa.c2b(data);

/* OR */

mpesa.c2b(data).then(response => {
	console.log(response);
}).catch(ex => console.log(ex));
Provável resposta caso bem sucedido
{
  "output_ResponseCode": "INS-0",
  "output_ResponseDesc": "Request processed successfully",
  "output_TransactionID": "3cr8whltpb6m",
  "output_ConversationID": "25230e0e20514ba790c1273b866e98d1",
  "output_ThirdPartyReference": "33333"
}

Transferência business to business (de negócio para negócio)

Transferência de valor de agente para agente

const data = {
	value: 10,
	agent_id: 171717,
	agent_receiver_id: 979797,
	transaction_reference: 1234567,
	third_party_reference: 33333
};

const response = await mpesa.b2b(data);

/* OR */

mpesa.b2b(data).then(response => {
	console.log(response);
}).catch(ex => console.log(ex));
Provável resposta caso bem sucedido
{
  "output_ResponseCode": "INS-0",
  "output_ResponseDesc": "Request processed successfully",
  "output_TransactionID": "wdv2x712xjsx",
  "output_ConversationID": "1f427e27529e410ea433c79a253d7281",
  "output_ThirdPartyReference": "33333"
}

Reversão de transação

const data = {
	value: 10,
	security_credential: "", // (Obrigatório)
	indicator_identifier: "", // (Obrigatório)
	transaction_id: "", // (Obrigatório) Id da transação a reverter
	agent_id: 171717, // (Obrigatório) Código do agente
	third_party_reference: 33333 // (Obrigatório) Esta referencia será usada para efectuar consulta das transações
};

const response = await mpesa.reversal(data);

/* OR */

mpesa.reversal(data).then(response => {
	console.log(response);
}).catch(ex => console.log(ex));
Provável resposta caso bem sucedido
{
  "output_ResponseCode": "INS-0",
  "output_ResponseDesc": "Request processed successfully",
  "output_TransactionID": "18c9kqgagz7h",
  "output_ConversationID": "2af1dce322394316917307c5320add6d",
  "output_ThirdPartyReference": "33333"
}

Estado da transação

const data = {
	transaction_id: "", // (Obrigatório) Id da transação a reverter
	agent_id: 171717, // (Obrigatório) Código do agente
	third_party_reference: 33333 // (Obrigatório) Esta referencia será usada para efectuar consulta das transações
};

const response = await mpesa.status(data);

/* OR */

mpesa.status(data).then(response => {
	console.log(response);
}).catch(ex => console.log(ex));
Provável resposta caso bem sucedido
{
  "output_ResponseCode": "INS-0",
  "output_ResponseDesc": "Request processed successfully",
  "output_ResponseTransactionStatus": "Completed",
  "output_ConversationID": "7552194cb219468fa8da3356eed77feb",
  "output_ThirdPartyReference": "33333"
}

Nome do cliente

O nome do cliente é retornado. Geralmente usado para confirmar se client_number introduzido está correcto.

Nota impotante: É impossível verificar o nome do cliente usando as credenciais de testes. É necessário obter credencias de produção para que possa visualizar o nome do cliente!

const data = {
	client_number: "258840000000", // (Obrigatório) Número do cliente
	agent_id: 171717, // (Obrigatório) Código do agente
	third_party_reference: 33333 // (Obrigatório) Esta referencia será usada para efectuar consulta das transações
};
const response = await mpesa.customer_name(data);

/* OR */

mpesa.customer_name(data).then(response => {
	console.log(response);
}).catch(ex => console.log(ex));
Provável resposta caso bem sucedido
{
  "output_ResponseCode": "INS-26",
  "output_ResponseDesc": "Not authorized",
  "output_ConversationID": "f4f9e06d93b7439eb79bd61c7de6f642",
  "output_ThirdPartyReference": "33333",
  "output_CustomerName": "N/A"
}