express-pay 1.0.2 → 1.0.3
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/README.md +7 -5
- package/express_pay.js +53 -16
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
Hello Everyone👋,
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
I am pleased to introduce you to the Express Pay. 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.
|
|
6
4
|
|
|
7
5
|
|
|
8
6
|
- SETUP
|
|
9
7
|
|
|
10
|
-
To set up the package, you simply need to run "npm i
|
|
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.
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
- USAGE EXAMPLE
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
.env VARIABLE NAMES
|
|
14
|
+
PAYNOW_INTEGRATION_KEY=
|
|
15
|
+
PAYNOW_INTEGRATION_ID=
|
|
16
|
+
|
|
17
|
+
const pay = require("paynow_integration");
|
|
16
18
|
|
|
17
19
|
REQUIRED ARGUMENTS
|
|
18
20
|
- Payee Contact (String)
|
package/express_pay.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const {Paynow} = require("paynow");
|
|
2
2
|
require("dotenv").config();
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
const ID = process.env.PAYNOW_INTEGRATION_ID;
|
|
5
7
|
const KEY = process.env.PAYNOW_INTEGRATION_KEY;
|
|
@@ -9,13 +11,15 @@ module.exports = function Pay(Payee_Contact, Transaction_Reference,Transaction_A
|
|
|
9
11
|
|
|
10
12
|
const payment = paynow.createPayment(`${Transaction_Reference}`, `${Customer_Email}`);
|
|
11
13
|
payment.add(`${Product_Name}`, `${Transaction_Amount}`);
|
|
12
|
-
const maxTimeout =
|
|
14
|
+
const maxTimeout = 30000;
|
|
13
15
|
|
|
14
16
|
return paynow.sendMobile(payment, `${Payee_Contact}`, "ecocash")
|
|
15
17
|
.then(async function (response) {
|
|
16
18
|
let initStatus = "Sent";
|
|
17
19
|
const startTime = Date.now();
|
|
18
20
|
|
|
21
|
+
console.log("url",response.pollUrl);
|
|
22
|
+
|
|
19
23
|
return new Promise((resolve, reject) => {
|
|
20
24
|
|
|
21
25
|
const intervalId = setInterval(async () => {
|
|
@@ -30,6 +34,8 @@ module.exports = function Pay(Payee_Contact, Transaction_Reference,Transaction_A
|
|
|
30
34
|
resolve("Paid");
|
|
31
35
|
} else if (result === "Cancelled") {
|
|
32
36
|
resolve("Cancelled");
|
|
37
|
+
}else if(result==="Sent"){
|
|
38
|
+
resolve("Not Authorised");
|
|
33
39
|
} else {
|
|
34
40
|
resolve("Transaction failed")
|
|
35
41
|
}
|
|
@@ -46,21 +52,52 @@ module.exports = function Pay(Payee_Contact, Transaction_Reference,Transaction_A
|
|
|
46
52
|
});
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
// }
|
|
73
|
+
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
async function getTransactionStatus(response){
|
|
77
|
+
|
|
78
|
+
|
|
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;
|
|
62
100
|
} catch (error) {
|
|
63
|
-
|
|
101
|
+
return console.log('error', error);
|
|
64
102
|
}
|
|
65
|
-
|
|
66
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-pay",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Node Package To Simplify Express Payments Via Ecocash",
|
|
5
5
|
"main": "express_pay.js",
|
|
6
6
|
"bin": "express_pay.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/Luke-Tembani/Express-Pay#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"axios": "^1.4.0",
|
|
27
28
|
"dotenv": "^16.0.3",
|
|
28
29
|
"paynow": "^1.0.9"
|
|
29
30
|
}
|