express-pay 1.0.4 → 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,46 +1,54 @@
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
12
12
 
13
- const pay = require("paynow_integration");
13
+ .env VARIABLE NAMES
14
+ PAYNOW_INTEGRATION_KEY=
15
+ PAYNOW_INTEGRATION_ID=
16
+ RESULT_URL=
17
+
18
+ const pay = require("express-pay");
14
19
 
15
20
  REQUIRED ARGUMENTS
16
21
  - Payee Contact (String)
17
22
  - Transaction Reference (String)
18
23
  - Amount (Number)
19
24
  - Customer Email (String)
20
- - Product Name (String)
25
+ - ISP (String)
21
26
 
22
- async function makePayment(){
23
- let result = pay("0770000000","Transaction_Reference",1.0,"test@gmail.com","Test Product");
24
- console.log(result);
27
+ function makePayment(){
28
+ pay("0770000000","Transaction_Reference",1.0,"test@gmail.com","onemoney"); // ISP ("onemoney"/"ecocash");
25
29
  }
26
-
27
30
  makePayment();
28
31
 
29
- Result Scenarios:
32
+ Create a webhook that will be used by paynow to POST Transaction Results
33
+ NodeJS API EXAMPLE
30
34
 
31
- - Paid = Transaction paid successfully
32
- - Cancelled = Transaction cancelled / Incorrect PIN
33
- - 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
+ })
34
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
35
44
 
36
45
  - 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.
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.
38
47
 
39
48
  - SUPPORT
40
-
41
49
  If you have any other questions or require support, please feel free to contact us via :
42
50
  email :lukemunyandu@gmail.com
43
51
  phone :+263 774 975 876
44
- WhatsApp :+263 781 327 381
52
+ WhatsApp :+263 781 327 381 / +263 779 999 175
45
53
 
46
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
- if (result !== initStatus) {
29
- clearInterval(intervalId);
9
+ module.exports = function pay(Payee_Contact, Transaction_Reference,Transaction_Amount,Customer_Email,ISP) {
30
10
 
31
- if (result === "Paid") {
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
- async function getTransactionStatus(response){
13
+ paynow.resultUrl = process.env.RESULT_URL;
54
14
 
15
+ payment.add(Transaction_Reference, `${Transaction_Amount}`);
55
16
 
56
- try {
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,7 +1,7 @@
1
1
  {
2
2
  "name": "express-pay",
3
- "version": "1.0.4",
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": {