express-pay 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env ADDED
@@ -0,0 +1,3 @@
1
+ PAYNOW_INTEGRATION_ID=
2
+ PAYNOW_INTEGRATION_KEY=
3
+ RESULT_URL=
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  Hello Everyone👋,
2
2
 
3
- I am pleased to introduce you to the Paynow Integration Package. This package is a part of "PAYNOW" and aims to simplify the process of implementing EXPRESS CHECKOUT PAYMENTS using ECOCASH.
3
+ I am pleased to introduce you to the Paynow Integration Package. This package is a part of "PAYNOW" and aims to simplify the process of implementing EXPRESS CHECKOUT PAYMENTS using ECOCASH & One Money.
4
4
 
5
5
 
6
6
  - SETUP
7
7
 
8
- To set up the package, you simply need to run "npm i paynow_integration" and configure your keys from https://www.paynow.co.zw/home/businesshome in the .env file. Then, import the downloaded method into your file. Make sure to enter all required arguments for the function to work correctly and implement it as an asynchronous function.
8
+ To set up the package, you simply need to run "npm i express-pay" and configure your keys from https://www.paynow.co.zw/home/businesshome in the .env file. Then, import the downloaded method into your file. Make sure to enter all required arguments for the function to work correctly.
9
9
 
10
10
 
11
11
  - USAGE EXAMPLE
@@ -13,38 +13,42 @@ To set up the package, you simply need to run "npm i paynow_integration" and con
13
13
  .env VARIABLE NAMES
14
14
  PAYNOW_INTEGRATION_KEY=
15
15
  PAYNOW_INTEGRATION_ID=
16
+ RESULT_URL=
16
17
 
17
- const pay = require("paynow_integration");
18
+ const pay = require("express-pay");
18
19
 
19
20
  REQUIRED ARGUMENTS
20
21
  - Payee Contact (String)
21
22
  - Transaction Reference (String)
22
23
  - Amount (Number)
23
24
  - Customer Email (String)
24
- - Product Name (String)
25
+ - ISP (String)
25
26
 
26
- async function makePayment(){
27
- let result = pay("0770000000","Transaction_Reference",1.0,"test@gmail.com","Test Product");
28
- console.log(result);
27
+ function makePayment(){
28
+ pay("0770000000","Transaction_Reference",1.0,"test@gmail.com","onemoney"); // ISP ("onemoney"/"ecocash");
29
29
  }
30
-
31
30
  makePayment();
32
31
 
33
- Result Scenarios:
32
+ Create a webhook that will be used by paynow to POST Transaction Results
33
+ NodeJS API EXAMPLE
34
34
 
35
- - Paid = Transaction paid successfully
36
- - Cancelled = Transaction cancelled / Incorrect PIN
37
- - Timed Out = Transaction took long to be paid (NB - Timeout is 20seconds)
35
+ router.post("/transaction_results",(req,res)=>{
36
+ console.log(req.body);
37
+ })
38
38
 
39
+ Result Scenarios:
40
+ Paid:
41
+ reference=Test1&paynowreference=XXX&amount=0.10&status=Paid&pollurl=httpsXXX&hash=XXX
42
+ Cancelled:
43
+ reference=Test1&paynowreference=XXX&amount=0.10&status=Cancelled&pollurl=httpsXXX&hash=XXX
39
44
 
40
45
  - NB
41
- Please note that you should not push the .env file to your repositories with keys, as this could potentially allow others to access them. Instead, create environment variables on the hosting platform.
46
+ Please note that you should not push the .env file to your repo, as this could potentially allow others to access them. Instead, create environment variables on the hosting platform.
42
47
 
43
48
  - SUPPORT
44
-
45
49
  If you have any other questions or require support, please feel free to contact us via :
46
50
  email :lukemunyandu@gmail.com
47
51
  phone :+263 774 975 876
48
- WhatsApp :+263 781 327 381
52
+ WhatsApp :+263 781 327 381 / +263 779 999 175
49
53
 
50
54
  Thank you.
package/express_pay.js CHANGED
@@ -1,103 +1,21 @@
1
1
  const {Paynow} = require("paynow");
2
2
  require("dotenv").config();
3
- const axios = require("axios");
4
-
5
3
 
6
4
  const ID = process.env.PAYNOW_INTEGRATION_ID;
7
5
  const KEY = process.env.PAYNOW_INTEGRATION_KEY;
8
6
  let paynow = new Paynow(`${ID}`, `${KEY}`);
9
7
 
10
- module.exports = function Pay(Payee_Contact, Transaction_Reference,Transaction_Amount,Customer_Email,Product_Name) {
11
-
12
- const payment = paynow.createPayment(`${Transaction_Reference}`, `${Customer_Email}`);
13
- payment.add(`${Product_Name}`, `${Transaction_Amount}`);
14
- const maxTimeout = 30000;
15
-
16
- return paynow.sendMobile(payment, `${Payee_Contact}`, "ecocash")
17
- .then(async function (response) {
18
- let initStatus = "Sent";
19
- const startTime = Date.now();
20
-
21
- console.log("url",response.pollUrl);
22
-
23
- return new Promise((resolve, reject) => {
24
-
25
- const intervalId = setInterval(async () => {
26
- try {
27
-
28
- const result = await getTransactionStatus(response);
29
8
 
30
- if (result !== initStatus) {
31
- clearInterval(intervalId);
9
+ module.exports = function pay(Payee_Contact, Transaction_Reference,Transaction_Amount,Customer_Email,ISP) {
32
10
 
33
- if (result === "Paid") {
34
- resolve("Paid");
35
- } else if (result === "Cancelled") {
36
- resolve("Cancelled");
37
- }else if(result==="Sent"){
38
- resolve("Not Authorised");
39
- } else {
40
- resolve("Transaction failed")
41
- }
42
- } else if (Date.now() - startTime >= maxTimeout) {
43
- clearInterval(intervalId);
44
- resolve("Transaction timed out");
45
- }
46
- } catch (error) {
47
- clearInterval(intervalId);
48
- reject(error);
49
- }
50
- }, 2000);
51
- });
52
- });
53
- }
54
-
55
- //Deprecated Method
56
- // async function getTransactionStatus(response){
57
- // let requestOptions = {
58
- // method: 'GET',
59
- // redirect: 'follow'
60
- // };
61
- // try {
62
- // const response_1 = await fetch(`${response.pollUrl}`, requestOptions);
63
- // const result_1 = await response_1.text();
64
- // const resbody = `${result_1}`;
65
- // const start = resbody.indexOf('status=') + 'status='.length;
66
- // const end = resbody.indexOf('&', start);
67
- // const status = resbody.substring(start, end);
68
- // return status;
69
-
70
- // } catch (error) {
71
- // return console.log('error', error);
72
- // }
11
+ const payment = paynow.createPayment(Transaction_Reference, `${Customer_Email}`);
73
12
 
74
- // }
75
-
76
- async function getTransactionStatus(response){
13
+ paynow.resultUrl = process.env.RESULT_URL;
77
14
 
15
+ payment.add(Transaction_Reference, `${Transaction_Amount}`);
78
16
 
79
- try {
80
-
81
-
82
-
83
-
84
- const response_1 = await axios.get(`${response.pollUrl}`);
85
-
86
- const resbody = response_1.data;
87
-
88
-
89
- const start = resbody.indexOf('status=') + 'status='.length;
90
-
91
-
92
- const end = resbody.indexOf('&', start);
93
-
94
-
95
- const status = resbody.substring(start, end);
96
-
97
-
98
-
99
- return status;
100
- } catch (error) {
101
- return console.log('error', error);
102
- }
17
+ return paynow.sendMobile(payment, `${Payee_Contact}`, ISP)
18
+ .then(function (response) {
19
+ console.log(`${ISP} Response`,response);
20
+ });
103
21
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "express-pay",
3
- "version": "1.0.3",
4
- "description": "Node Package To Simplify Express Payments Via Ecocash",
3
+ "version": "1.0.5",
4
+ "description": "Node Package To Simplify Express Payments Via Ecocash & One Money",
5
5
  "main": "express_pay.js",
6
6
  "bin": "express_pay.js",
7
7
  "scripts": {