diff --git a/examples/pesa-demo/.env.example b/examples/pesa-demo/.env.example new file mode 100644 index 0000000..6acd01a --- /dev/null +++ b/examples/pesa-demo/.env.example @@ -0,0 +1,3 @@ +ENV=sandbox # sandbox or production refer to mpesa api docs +PUBLIC_KEY= +API_KEY= diff --git a/examples/pesa-demo/.gitignore b/examples/pesa-demo/.gitignore new file mode 100644 index 0000000..0b55736 --- /dev/null +++ b/examples/pesa-demo/.gitignore @@ -0,0 +1,10 @@ +build + +docs +node-modules +coverage + +.idea +/examples/http-client.private.env.json + +.env \ No newline at end of file diff --git a/examples/pesa-demo/README.md b/examples/pesa-demo/README.md new file mode 100644 index 0000000..3a6da76 --- /dev/null +++ b/examples/pesa-demo/README.md @@ -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 + ``` \ No newline at end of file diff --git a/examples/pesa-demo/index.js b/examples/pesa-demo/index.js new file mode 100644 index 0000000..bddef3f --- /dev/null +++ b/examples/pesa-demo/index.js @@ -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); + }); diff --git a/examples/pesa-demo/package.json b/examples/pesa-demo/package.json new file mode 100644 index 0000000..9731f7a --- /dev/null +++ b/examples/pesa-demo/package.json @@ -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" + } +} diff --git a/examples/pesa-demo/yarn.lock b/examples/pesa-demo/yarn.lock new file mode 100644 index 0000000..ce90771 --- /dev/null +++ b/examples/pesa-demo/yarn.lock @@ -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==