express-pay 1.0.4 → 1.1.0
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 +3 -0
- package/README +54 -0
- package/express_pay.js +8 -67
- package/package.json +4 -4
- package/README.md +0 -46
package/.env
ADDED
package/README
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Hello Everyone👋,
|
|
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 & One Money.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
- SETUP
|
|
7
|
+
|
|
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
|
+
|
|
10
|
+
|
|
11
|
+
- USAGE EXAMPLE
|
|
12
|
+
|
|
13
|
+
.env VARIABLE NAMES
|
|
14
|
+
- PAYNOW_INTEGRATION_KEY=
|
|
15
|
+
- PAYNOW_INTEGRATION_ID=
|
|
16
|
+
- RESULT_URL=
|
|
17
|
+
|
|
18
|
+
const pay = require("express-pay");
|
|
19
|
+
|
|
20
|
+
REQUIRED ARGUMENTS
|
|
21
|
+
- Payee Contact (String)
|
|
22
|
+
- Transaction Reference (String)
|
|
23
|
+
- Amount (Number)
|
|
24
|
+
- Customer Email (String)
|
|
25
|
+
- ISP (String)
|
|
26
|
+
|
|
27
|
+
function makePayment(){
|
|
28
|
+
pay("0770000000","Transaction_Reference",1.0,"test@gmail.com","onemoney"); // ISP ("onemoney"/"ecocash");
|
|
29
|
+
}
|
|
30
|
+
makePayment();
|
|
31
|
+
|
|
32
|
+
Create a webhook that will be used by paynow to POST Transaction Results
|
|
33
|
+
NodeJS API EXAMPLE
|
|
34
|
+
|
|
35
|
+
router.post("/transaction_results",(req,res)=>{
|
|
36
|
+
console.log(req.body);
|
|
37
|
+
})
|
|
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
|
|
44
|
+
|
|
45
|
+
- NB
|
|
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.
|
|
47
|
+
|
|
48
|
+
- SUPPORT
|
|
49
|
+
If you have any other questions or require support, please feel free to contact us via :
|
|
50
|
+
email :lukemunyandu@gmail.com
|
|
51
|
+
phone :+263 774 975 876
|
|
52
|
+
WhatsApp :+263 781 327 381 / +263 779 999 175
|
|
53
|
+
|
|
54
|
+
Thank you.
|
package/express_pay.js
CHANGED
|
@@ -1,80 +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
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
|
|
23
|
-
const intervalId = setInterval(async () => {
|
|
24
|
-
try {
|
|
25
|
-
|
|
26
|
-
const result = await getTransactionStatus(response);
|
|
27
8
|
|
|
28
|
-
|
|
29
|
-
clearInterval(intervalId);
|
|
9
|
+
module.exports = function pay(Payee_Contact, Transaction_Reference,Transaction_Amount,Customer_Email,ISP) {
|
|
30
10
|
|
|
31
|
-
|
|
32
|
-
resolve("Paid");
|
|
33
|
-
} else if (result === "Cancelled") {
|
|
34
|
-
resolve("Cancelled");
|
|
35
|
-
}else if(result==="Sent"){
|
|
36
|
-
resolve("Not Authorised");
|
|
37
|
-
} else {
|
|
38
|
-
resolve("Transaction failed")
|
|
39
|
-
}
|
|
40
|
-
} else if (Date.now() - startTime >= maxTimeout) {
|
|
41
|
-
clearInterval(intervalId);
|
|
42
|
-
resolve("Transaction timed out");
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
clearInterval(intervalId);
|
|
46
|
-
reject(error);
|
|
47
|
-
}
|
|
48
|
-
}, 2000);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
11
|
+
const payment = paynow.createPayment(Transaction_Reference, `${Customer_Email}`);
|
|
52
12
|
|
|
53
|
-
|
|
13
|
+
paynow.resultUrl = process.env.RESULT_URL;
|
|
54
14
|
|
|
15
|
+
payment.add(Transaction_Reference, `${Transaction_Amount}`);
|
|
55
16
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const response_1 = await axios.get(`${response.pollUrl}`);
|
|
62
|
-
|
|
63
|
-
const resbody = response_1.data;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const start = resbody.indexOf('status=') + 'status='.length;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const end = resbody.indexOf('&', start);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const status = resbody.substring(start, end);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return status;
|
|
77
|
-
} catch (error) {
|
|
78
|
-
return console.log('error', error);
|
|
79
|
-
}
|
|
17
|
+
return paynow.sendMobile(payment, `${Payee_Contact}`, ISP)
|
|
18
|
+
.then(function (response) {
|
|
19
|
+
console.log(`${ISP} Response`,response);
|
|
20
|
+
});
|
|
80
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-pay",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Node Package To Simplify Express Payments Via Ecocash",
|
|
5
5
|
"main": "express_pay.js",
|
|
6
6
|
"bin": "express_pay.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/Luke-Tembani/Express-Pay#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^1.
|
|
28
|
-
"dotenv": "^
|
|
29
|
-
"paynow": "^
|
|
27
|
+
"axios": "^1.16.0",
|
|
28
|
+
"dotenv": "^17.4.2",
|
|
29
|
+
"paynow": "^2.2.2"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/README.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
Hello Everyone👋,
|
|
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.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
- SETUP
|
|
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.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- USAGE EXAMPLE
|
|
12
|
-
|
|
13
|
-
const pay = require("paynow_integration");
|
|
14
|
-
|
|
15
|
-
REQUIRED ARGUMENTS
|
|
16
|
-
- Payee Contact (String)
|
|
17
|
-
- Transaction Reference (String)
|
|
18
|
-
- Amount (Number)
|
|
19
|
-
- Customer Email (String)
|
|
20
|
-
- Product Name (String)
|
|
21
|
-
|
|
22
|
-
async function makePayment(){
|
|
23
|
-
let result = pay("0770000000","Transaction_Reference",1.0,"test@gmail.com","Test Product");
|
|
24
|
-
console.log(result);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
makePayment();
|
|
28
|
-
|
|
29
|
-
Result Scenarios:
|
|
30
|
-
|
|
31
|
-
- Paid = Transaction paid successfully
|
|
32
|
-
- Cancelled = Transaction cancelled / Incorrect PIN
|
|
33
|
-
- Timed Out = Transaction took long to be paid (NB - Timeout is 20seconds)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
- NB
|
|
37
|
-
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.
|
|
38
|
-
|
|
39
|
-
- SUPPORT
|
|
40
|
-
|
|
41
|
-
If you have any other questions or require support, please feel free to contact us via :
|
|
42
|
-
email :lukemunyandu@gmail.com
|
|
43
|
-
phone :+263 774 975 876
|
|
44
|
-
WhatsApp :+263 781 327 381
|
|
45
|
-
|
|
46
|
-
Thank you.
|