-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c64ce4d
commit e09af2a
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ENV=sandbox # sandbox or production refer to mpesa api docs | ||
PUBLIC_KEY= | ||
API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
build | ||
|
||
docs | ||
node-modules | ||
coverage | ||
|
||
.idea | ||
/examples/http-client.private.env.json | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# PESA DEMO | ||
### Node js app to showcase openpesa-js plugin. | ||
|
||
## HOW TO RUN | ||
1. Make sure you are within this demo app directory **yourpath/examples/pesa-demo** and then run the following command to install dependencies: | ||
|
||
```sh | ||
npm install | ||
|
||
or | ||
|
||
yarn (incase you want to use yarn) | ||
``` | ||
|
||
2. Make a copy of .env.example to .env by running the below command | ||
|
||
```sh | ||
cp .env.example .env | ||
``` | ||
3. Then update your .env file with your value provided from mpesa api | ||
|
||
```env | ||
ENV=sandbox | ||
PUBLIC_KEY=your_public_key | ||
API_KEY=your_api_key | ||
``` | ||
|
||
4. Finally run the demo app to get results | ||
|
||
```sh | ||
npm start | ||
or | ||
yarn start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { Pesa } = require('@openpesa/pesa-js'); | ||
const dotenv = require('dotenv'); | ||
|
||
dotenv.config(); | ||
|
||
let environment = process.env.ENV; | ||
let publicKey = process.env.PUBLIC_KEY; | ||
let apiKey = process.env.API_KEY; | ||
|
||
let pesa = new Pesa( | ||
{ | ||
api_key: apiKey, | ||
public_key: publicKey, | ||
}, | ||
environment, | ||
); | ||
|
||
let data = { | ||
input_Amount: 12000, | ||
input_CustomerMSISDN: '000000000001', | ||
input_Country: 'TZN', | ||
input_Currency: 'TZS', | ||
input_ServiceProviderCode: '000000', | ||
input_TransactionReference: 'T12347Z', | ||
input_ThirdPartyConversationID: '4e9b774d1da34af78412a598cbc28f5d', | ||
input_PurchasedItemsDesc: 'Test Three Item', | ||
}; | ||
|
||
pesa.c2b(data) | ||
.then((data) => { | ||
console.log(data); | ||
}) | ||
.catch((er) => { | ||
console.log(er.data); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "pesa-demo", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"@openpesa/pesa-js": "^0.0.3", | ||
"dotenv": "^16.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@openpesa/pesa-js@^0.0.3": | ||
version "0.0.3" | ||
resolved "https://registry.yarnpkg.com/@openpesa/pesa-js/-/pesa-js-0.0.3.tgz#39110ff2288bb606d6c7b448624aacfbbf50e9cb" | ||
integrity sha512-MeO3voEy7PDg6uKIFNrQnJIVWypwwFw5qVpXHNP1EMXwBFIbpDo+yT15VA/D6y73y5IRHdFyGYpSaygVizM02g== | ||
dependencies: | ||
axios "^0.21.0" | ||
|
||
axios@^0.21.0: | ||
version "0.21.1" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" | ||
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== | ||
dependencies: | ||
follow-redirects "^1.10.0" | ||
|
||
dotenv@^16.0.3: | ||
version "16.0.3" | ||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" | ||
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ== | ||
|
||
follow-redirects@^1.10.0: | ||
version "1.14.1" | ||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43" | ||
integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg== |