From 9020d173d10b826c3179c73e9a43c0ffe696122b Mon Sep 17 00:00:00 2001 From: Newton Munene Date: Wed, 15 May 2019 23:44:09 +0300 Subject: [PATCH 1/4] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e784f08..9551ac3 100644 --- a/README.md +++ b/README.md @@ -406,14 +406,14 @@ Mpesa.reversal({ ## RoadMap - [x] Basic Documentation -- [ ] Deploy to Npm +- [x] Deploy to Npm - [x] Migrate to Typescript -- [ ] Detailed Documentation +- [x] Detailed Documentation - [ ] Better Support for es5 - [ ] Unit tests - [ ] E2E Integration Tests -- [ ] Reduce functions -- [ ] Validators for inputs +- [x] Reduce functions +- [x] Validators for inputs ## Build From 0d8d8efdeb673bcd89096c20bed673f22f1a2329 Mon Sep 17 00:00:00 2001 From: Newton Munene Date: Thu, 16 May 2019 20:25:36 +0300 Subject: [PATCH 2/4] Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9551ac3..f43f27f 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,12 @@ You Will need a few things from Safaricom before development. ```javascript // import package -import { mpesa } from "mpesa-api"; +import { Mpesa } from "mpesa-api"; //OR -const mpesa = require("mpesa-api").mpesa; +const Mpesa = require("mpesa-api").Mpesa; // create a new instance of the api -const Mpesa = new mpesa(credentials, environment); +const mpesa = new Mpesa(credentials, environment); ``` A moment to explain the above. `credentials` should be an object containing key,secret,initiator_password and certificatepath as the properties. @@ -91,7 +91,7 @@ const environment = "production"; This API enables Business to Business (B2B) transactions between a business and another business. Use of this API requires a valid and verified B2B M-Pesa short code for the business initiating the transaction and the both businesses involved in the transaction. ```javascript -Mpesa.b2b({ +mpesa.b2b({ InitiatorName: "Initiator Name", Amount: 1000 /* 1000 is an example amount */, PartyA: "Party A", @@ -133,7 +133,7 @@ Mpesa.b2b({ This API enables Business to Customer (B2C) transactions between a company and customers who are the end-users of its products or services. Use of this API requires a valid and verified B2C M-Pesa Short code. ```javascript -Mpesa.b2c({ +mpesa.b2c({ InitiatorName: "Initiator Name", Amount: 1000 /* 1000 is an example amount */, PartyA: "Party A", @@ -177,7 +177,7 @@ The C2B Register URL API registers the 3rd party’s confirmation and validation M-Pesa completes or cancels the transaction depending on the validation response it receives from the 3rd party system. A confirmation request of the transaction is then sent by M-Pesa through the confirmation URL back to the 3rd party which then should respond with a success acknowledging the confirmation. ```javascript -Mpesa.c2bregister({ +mpesa.c2bregister({ ShortCode: "Short Code", ConfirmationURL: "Confirmation URL", ValidationURL: "Validation URL", @@ -203,7 +203,7 @@ Mpesa.c2bregister({ ##### Simulate ```javascript -Mpesa.c2bsimulate({ +mpesa.c2bsimulate({ ShortCode: 123456, Amount: 1000 /* 1000 is an example amount */, Msisdn: 254792123456, @@ -233,7 +233,7 @@ Mpesa.c2bsimulate({ The Account Balance API requests for the account balance of a shortcode. ```javascript -Mpesa.accountBalance({ +mpesa.accountBalance({ Initiator: "Initiator Name", PartyA: "Party A", IdentifierType: "Identifier Type", @@ -267,7 +267,7 @@ Mpesa.accountBalance({ Transaction Status API checks the status of a B2B, B2C and C2B APIs transactions. ```javascript -Mpesa.transactionStatus({ +mpesa.transactionStatus({ Initiator: "Initiator", TransactionID: "Transaction ID", PartyA: "Party A", @@ -305,7 +305,7 @@ Mpesa.transactionStatus({ Lipa na M-Pesa Online Payment API is used to initiate a M-Pesa transaction on behalf of a customer using STK Push. This is the same technique mySafaricom App uses whenever the app is used to make payments. ```javascript -Mpesa.lipanampesa({ +mpesa.lipanampesa({ BusinessShortCode: 123456, Amount: 1000 /* 1000 is an example amount */, PartyA: "Party A", @@ -342,7 +342,7 @@ Mpesa.lipanampesa({ #### Lipa na mpesa online query ```javascript -Mpesa.lipanampesaquery({ +mpesa.lipanampesaquery({ BusinessShortCode: 123456, CheckoutRequestID: "Checkout Request ID", passKey: "Lipa Na Mpesa Pass Key" @@ -368,7 +368,7 @@ Mpesa.lipanampesaquery({ Reverses a B2B, B2C or C2B M-Pesa transaction. ```javascript -Mpesa.reversal({ +mpesa.reversal({ Initiator: "Initiator", TransactionID: "Transaction ID", Amount: 1000 /* 1000 is an example amount */, From 2784aef43e1781aa8d6335b96b8368283ed9d3ad Mon Sep 17 00:00:00 2001 From: musebe Date: Thu, 16 May 2019 19:38:20 +0000 Subject: [PATCH 3/4] modified lipaNaMpesaOnline & added how to get your initiator password --- README.md | 189 +++++++++++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index f43f27f..e794265 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ You Will need a few things from Safaricom before development. ```javascript // import package -import { Mpesa } from "mpesa-api"; +import { Mpesa } from 'mpesa-api'; //OR -const Mpesa = require("mpesa-api").Mpesa; +const Mpesa = require('mpesa-api').Mpesa; // create a new instance of the api const mpesa = new Mpesa(credentials, environment); @@ -67,6 +67,8 @@ const credentials = { initiator_password: 'YOUR_INITIATOR_PASSWORD_HERE', certificatepath: 'keys/example.cert' }; +// For the initiator_password, use the security credential from the test credentials page.link :https://developer.safaricom.co.ke/test_credentials + // certificate path is otional. I've provided ceritificates for sandbox and production by default. If you choose not to include it Pass it as null. const credentials = { ..., @@ -77,9 +79,9 @@ const credentials = { Environment should be a string. It can be either 'production' or 'sandbox' ```javascript -const environment = "sandbox"; +const environment = 'sandbox'; //or -const environment = "production"; +const environment = 'production'; ``` ## Methods and Api Calls @@ -91,19 +93,20 @@ const environment = "production"; This API enables Business to Business (B2B) transactions between a business and another business. Use of this API requires a valid and verified B2B M-Pesa short code for the business initiating the transaction and the both businesses involved in the transaction. ```javascript -mpesa.b2b({ - InitiatorName: "Initiator Name", - Amount: 1000 /* 1000 is an example amount */, - PartyA: "Party A", - PartyB: "Party B", - AccountReference: "Account Reference", - QueueTimeOutURL: "Queue Timeout URL", - ResultURL: "Result URL", - CommandID: "Command ID" /* OPTIONAL */, - SenderIdentifierType: 4 /* OPTIONAL */, - RecieverIdentifierType: 4 /* OPTIONAL */, - Remarks: "Remarks" /* OPTIONAL */ -}) +mpesa + .b2b({ + InitiatorName: 'Initiator Name', + Amount: 1000 /* 1000 is an example amount */, + PartyA: 'Party A', + PartyB: 'Party B', + AccountReference: 'Account Reference', + QueueTimeOutURL: 'Queue Timeout URL', + ResultURL: 'Result URL', + CommandID: 'Command ID' /* OPTIONAL */, + SenderIdentifierType: 4 /* OPTIONAL */, + RecieverIdentifierType: 4 /* OPTIONAL */, + Remarks: 'Remarks' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg @@ -133,17 +136,18 @@ mpesa.b2b({ This API enables Business to Customer (B2C) transactions between a company and customers who are the end-users of its products or services. Use of this API requires a valid and verified B2C M-Pesa Short code. ```javascript -mpesa.b2c({ - InitiatorName: "Initiator Name", - Amount: 1000 /* 1000 is an example amount */, - PartyA: "Party A", - PartyB: "Party B", - QueueTimeOutURL: "Queue Timeout URL", - ResultURL: "Result URL", - CommandID: "Command ID" /* OPTIONAL */, - Occasion: "Occasion" /* OPTIONAL */, - Remarks: "Remarks" /* OPTIONAL */ -}) +mpesa + .b2c({ + InitiatorName: 'Initiator Name', + Amount: 1000 /* 1000 is an example amount */, + PartyA: 'Party A', + PartyB: 'Party B', + QueueTimeOutURL: 'Queue Timeout URL', + ResultURL: 'Result URL', + CommandID: 'Command ID' /* OPTIONAL */, + Occasion: 'Occasion' /* OPTIONAL */, + Remarks: 'Remarks' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg @@ -177,12 +181,13 @@ The C2B Register URL API registers the 3rd party’s confirmation and validation M-Pesa completes or cancels the transaction depending on the validation response it receives from the 3rd party system. A confirmation request of the transaction is then sent by M-Pesa through the confirmation URL back to the 3rd party which then should respond with a success acknowledging the confirmation. ```javascript -mpesa.c2bregister({ - ShortCode: "Short Code", - ConfirmationURL: "Confirmation URL", - ValidationURL: "Validation URL", - ResponseType: "Response Type" -}) +mpesa + .c2bregister({ + ShortCode: 'Short Code', + ConfirmationURL: 'Confirmation URL', + ValidationURL: 'Validation URL', + ResponseType: 'Response Type' + }) .then(response => { //Do something with the response //eg @@ -203,13 +208,14 @@ mpesa.c2bregister({ ##### Simulate ```javascript -mpesa.c2bsimulate({ - ShortCode: 123456, - Amount: 1000 /* 1000 is an example amount */, - Msisdn: 254792123456, - CommandID: "Command ID" /* OPTIONAL */, - BillRefNumber: "Bill Reference Number" /* OPTIONAL */ -}) +mpesa + .c2bsimulate({ + ShortCode: 123456, + Amount: 1000 /* 1000 is an example amount */, + Msisdn: 254792123456, + CommandID: 'Command ID' /* OPTIONAL */, + BillRefNumber: 'Bill Reference Number' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg @@ -233,15 +239,16 @@ mpesa.c2bsimulate({ The Account Balance API requests for the account balance of a shortcode. ```javascript -mpesa.accountBalance({ - Initiator: "Initiator Name", - PartyA: "Party A", - IdentifierType: "Identifier Type", - QueueTimeOutURL: "Queue Timeout URL", - ResultURL: "Result URL", - CommandID: "Command ID" /* OPTIONAL */, - Remarks: "Remarks" /* OPTIONAL */ -}) +mpesa + .accountBalance({ + Initiator: 'Initiator Name', + PartyA: 'Party A', + IdentifierType: 'Identifier Type', + QueueTimeOutURL: 'Queue Timeout URL', + ResultURL: 'Result URL', + CommandID: 'Command ID' /* OPTIONAL */, + Remarks: 'Remarks' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg @@ -267,17 +274,18 @@ mpesa.accountBalance({ Transaction Status API checks the status of a B2B, B2C and C2B APIs transactions. ```javascript -mpesa.transactionStatus({ - Initiator: "Initiator", - TransactionID: "Transaction ID", - PartyA: "Party A", - IdentifierType: "Identifier Type", - ResultURL: "Result URL", - QueueTimeOutURL: "Queue Timeout URL", - CommandID: "Command ID" /* OPTIONAL */, - Remarks: "Remarks" /* OPTIONAL */, - Occasion: "Occasion" /* OPTIONAL */ -}) +mpesa + .transactionStatus({ + Initiator: 'Initiator', + TransactionID: 'Transaction ID', + PartyA: 'Party A', + IdentifierType: 'Identifier Type', + ResultURL: 'Result URL', + QueueTimeOutURL: 'Queue Timeout URL', + CommandID: 'Command ID' /* OPTIONAL */, + Remarks: 'Remarks' /* OPTIONAL */, + Occasion: 'Occasion' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg @@ -305,17 +313,18 @@ mpesa.transactionStatus({ Lipa na M-Pesa Online Payment API is used to initiate a M-Pesa transaction on behalf of a customer using STK Push. This is the same technique mySafaricom App uses whenever the app is used to make payments. ```javascript -mpesa.lipanampesa({ - BusinessShortCode: 123456, - Amount: 1000 /* 1000 is an example amount */, - PartyA: "Party A", - PhoneNumber: "Phone Number", - CallBackURL: "CallBack URL", - AccountReference: "Account Reference", - passKey: "Lipa Na Mpesa Pass Key", - TransactionType: "Transaction Type" /* OPTIONAL */, - TransactionDesc: "Transaction Description" /* OPTIONAL */ -}) +mpesa + .lipaNaMpesaOnline({ + BusinessShortCode: 123456, + Amount: 1000 /* 1000 is an example amount */, + PartyA: 'Party A', + PhoneNumber: 'Phone Number', + CallBackURL: 'CallBack URL', + AccountReference: 'Account Reference', + passKey: 'Lipa Na Mpesa Pass Key', + TransactionType: 'Transaction Type' /* OPTIONAL */, + TransactionDesc: 'Transaction Description' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg @@ -342,11 +351,12 @@ mpesa.lipanampesa({ #### Lipa na mpesa online query ```javascript -mpesa.lipanampesaquery({ - BusinessShortCode: 123456, - CheckoutRequestID: "Checkout Request ID", - passKey: "Lipa Na Mpesa Pass Key" -}) +mpesa + .lipanampesaquery({ + BusinessShortCode: 123456, + CheckoutRequestID: 'Checkout Request ID', + passKey: 'Lipa Na Mpesa Pass Key' + }) .then(response => { //Do something with the response //eg @@ -368,18 +378,19 @@ mpesa.lipanampesaquery({ Reverses a B2B, B2C or C2B M-Pesa transaction. ```javascript -mpesa.reversal({ - Initiator: "Initiator", - TransactionID: "Transaction ID", - Amount: 1000 /* 1000 is an example amount */, - ReceiverParty: "Reciever Party", - ResultURL: "Result URL", - QueueTimeOutURL: "Queue Timeout URL", - CommandID: "Command ID" /* OPTIONAL */, - RecieverIdentifierType: 11 /* OPTIONAL */, - Remarks: "Remarks" /* OPTIONAL */, - Occasion: "Ocassion" /* OPTIONAL */ -}) +mpesa + .reversal({ + Initiator: 'Initiator', + TransactionID: 'Transaction ID', + Amount: 1000 /* 1000 is an example amount */, + ReceiverParty: 'Reciever Party', + ResultURL: 'Result URL', + QueueTimeOutURL: 'Queue Timeout URL', + CommandID: 'Command ID' /* OPTIONAL */, + RecieverIdentifierType: 11 /* OPTIONAL */, + Remarks: 'Remarks' /* OPTIONAL */, + Occasion: 'Ocassion' /* OPTIONAL */ + }) .then(response => { //Do something with the response //eg From 1a03a6f722133991e4a5eebce4c63c03b5e56a38 Mon Sep 17 00:00:00 2001 From: Newton Munene Date: Fri, 17 May 2019 08:56:37 +0300 Subject: [PATCH 4/4] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index e794265..40412f8 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,6 @@ const mpesa = new Mpesa(credentials, environment); A moment to explain the above. `credentials` should be an object containing key,secret,initiator_password and certificatepath as the properties. -You can get initiator password from Your Portal(production) or from test credentials(Sandbox). It will be the `Security Credential (Shortcode 1)`. - ```javascript //example const credentials = { @@ -75,6 +73,7 @@ const credentials = { certificatepath: null }; ``` +> You can get initiator password from Your Portal(production) or from test credentials(Sandbox). It will be the `Security Credential (Shortcode 1)`. Environment should be a string. It can be either 'production' or 'sandbox'