express-pay 1.0.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/Example.txt ADDED
@@ -0,0 +1,14 @@
1
+ const pay = require("paynow_integration");
2
+
3
+ async function makePayment(){
4
+ let result = await pay("0770000000","Transaction_Reference",1.0,"test@gmail.com");
5
+ console.log(result);
6
+ }
7
+
8
+ makePayment();
9
+
10
+ Result Scenarios:
11
+
12
+ - Paid = Transaction paid successfully
13
+ - Cancelled = Transaction cancelled / Incorrect PIN
14
+ - Timed Out = Transaction took long to be paid (NB - Timeout is 20seconds)
package/README.md ADDED
@@ -0,0 +1,46 @@
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.
package/express_pay.js ADDED
@@ -0,0 +1,66 @@
1
+ const {Paynow} = require("paynow");
2
+ require("dotenv").config();
3
+
4
+ const ID = process.env.PAYNOW_INTEGRATION_ID;
5
+ const KEY = process.env.PAYNOW_INTEGRATION_KEY;
6
+ let paynow = new Paynow(`${ID}`, `${KEY}`);
7
+
8
+ module.exports = function Pay(Payee_Contact, Transaction_Reference,Transaction_Amount,Customer_Email,Product_Name) {
9
+
10
+ const payment = paynow.createPayment(`${Transaction_Reference}`, `${Customer_Email}`);
11
+ payment.add(`${Product_Name}`, `${Transaction_Amount}`);
12
+ const maxTimeout = 20000;
13
+
14
+ return paynow.sendMobile(payment, `${Payee_Contact}`, "ecocash")
15
+ .then(async function (response) {
16
+ let initStatus = "Sent";
17
+ const startTime = Date.now();
18
+
19
+ return new Promise((resolve, reject) => {
20
+
21
+ const intervalId = setInterval(async () => {
22
+ try {
23
+
24
+ const result = await getTransactionStatus(response);
25
+
26
+ if (result !== initStatus) {
27
+ clearInterval(intervalId);
28
+
29
+ if (result === "Paid") {
30
+ resolve("Paid");
31
+ } else if (result === "Cancelled") {
32
+ resolve("Cancelled");
33
+ } else {
34
+ resolve("Transaction failed")
35
+ }
36
+ } else if (Date.now() - startTime >= maxTimeout) {
37
+ clearInterval(intervalId);
38
+ resolve("Transaction timed out");
39
+ }
40
+ } catch (error) {
41
+ clearInterval(intervalId);
42
+ reject(error);
43
+ }
44
+ }, 2000);
45
+ });
46
+ });
47
+ }
48
+
49
+ async function getTransactionStatus(response){
50
+ let requestOptions = {
51
+ method: 'GET',
52
+ redirect: 'follow'
53
+ };
54
+ try {
55
+ const response_1 = await fetch(`${response.pollUrl}`, requestOptions);
56
+ const result_1 = await response_1.text();
57
+ const resbody = `${result_1}`;
58
+ const start = resbody.indexOf('status=') + 'status='.length;
59
+ const end = resbody.indexOf('&', start);
60
+ const status = resbody.substring(start, end);
61
+ return status;
62
+ } catch (error) {
63
+ return console.log('error', error);
64
+ }
65
+
66
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "express-pay",
3
+ "version": "1.0.0",
4
+ "description": "Node Package To Simplify Express Payments Via Ecocash",
5
+ "main": "express_pay.js",
6
+ "bin": "express_pay.js",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Luke-Tembani/Express-Pay.git"
13
+ },
14
+ "keywords": [
15
+ "Express",
16
+ "Pay",
17
+ "Ecocash",
18
+ "Zimbabwe"
19
+ ],
20
+ "author": "Luke Tembani",
21
+ "license": "ISC",
22
+ "bugs": {
23
+ "url": "https://github.com/Luke-Tembani/Express-Pay/issues"
24
+ },
25
+ "homepage": "https://github.com/Luke-Tembani/Express-Pay#readme"
26
+ }