@ahfl/unifiedpay 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/index.js +89 -0
  2. package/package.json +3 -3
  3. package/unifiedpay.js +0 -85
package/index.js ADDED
@@ -0,0 +1,89 @@
1
+ (function(global){
2
+
3
+ let paytmMerchantKey = "";
4
+ let razorpayMerchantKey = "";
5
+
6
+ function setupVendors(vendorDetails){
7
+
8
+ if("paytmMerchantKey" in vendorDetails){
9
+ paytmMerchantKey = vendorDetails.paytmMerchantKey;
10
+
11
+ const script = document.createElement("script");
12
+ let host = "";
13
+ if(vendorDetails.env == "production"){
14
+ host = "secure.paytmpayments.com";
15
+ }else{
16
+ host = "securestage.paytmpayments.com";
17
+ }
18
+ script.src = `https://${host}/merchantpgpui/checkoutjs/merchants/${vendorDetails.paytmMerchantKey}.js`;
19
+ script.type = "application/javascript"
20
+ document.head.appendChild(script);
21
+
22
+ }
23
+
24
+ if("razorpayMerchantKey" in vendorDetails){
25
+ razorpayMerchantKey = vendorDetails.razorpayMerchantKey;
26
+
27
+ const script = document.createElement("script");
28
+ script.src = `https://checkout.razorpay.com/v1/checkout.js`;
29
+ document.head.appendChild(script);
30
+
31
+ }
32
+
33
+ }
34
+
35
+ function invokePaymentPage(paymentVendor, initiateTxnReq, initiateTxnResp){
36
+ switch(paymentVendor){
37
+ case 'paytm':
38
+ startPaytm(paytmMerchantKey, initiateTxnReq, initiateTxnResp);
39
+ break;
40
+ case 'razorpay':
41
+ startRazorpay(razorpayMerchantKey, initiateTxnReq, initiateTxnResp);
42
+ break;
43
+ default:
44
+ alert("Invalid Payment Vendor");
45
+ }
46
+ }
47
+
48
+ function startRazorpay(merchantKey, initiateTxnReq, initiateTxnResp){
49
+
50
+ var options = {
51
+ "key": merchantKey,
52
+ "amount": initiateTxnReq.amount,
53
+ "currency": "INR",
54
+ "order_id": initiateTxnResp.token,
55
+ "callback_url": initiateTxnReq.callbackUrl,
56
+ };
57
+ var rzp1 = new Razorpay(options);
58
+ rzp1.open();
59
+ }
60
+
61
+ function startPaytm(merchantKey, initiateTxnReq, initiateTxnResp){
62
+
63
+ const config = {
64
+ root: "",
65
+ flow: "DEFAULT",
66
+ data: {
67
+ orderId: initiateTxnReq.orderId,
68
+ token: initiateTxnResp.token,
69
+ tokenType: "TXN_TOKEN",
70
+ amount: initiateTxnReq.amount
71
+ },
72
+ handler: {
73
+ notifyMerchant: function (eventName, data) {
74
+ }
75
+ }
76
+ };
77
+
78
+ Paytm.CheckoutJS.init(config).then(() => {
79
+ Paytm.CheckoutJS.invoke();
80
+ }).catch(err => {
81
+ });
82
+ }
83
+
84
+ global.UnifiedPay = {
85
+ setupVendors,
86
+ invokePaymentPage
87
+ }
88
+
89
+ })(window);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ahfl/unifiedpay",
3
- "version": "1.0.0",
4
- "main": "unifiedpay.js",
3
+ "version": "1.0.2",
4
+ "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
7
7
  },
8
8
  "keywords": [],
9
9
  "author": "",
10
10
  "license": "ISC",
11
- "description": ""
11
+ "description": "Install:"
12
12
  }
package/unifiedpay.js DELETED
@@ -1,85 +0,0 @@
1
- let paytmMerchantKey = "";
2
- let razorpayMerchantKey = "";
3
-
4
- export function setupVendors(vendorDetails){
5
-
6
- if("paytmMerchantKey" in vendorDetails){
7
- paytmMerchantKey = vendorDetails.paytmMerchantKey;
8
-
9
- const script = document.createElement("script");
10
- let host = "";
11
- if(vendorDetails.env == "production"){
12
- host = "secure.paytmpayments.com";
13
- }else{
14
- host = "securestage.paytmpayments.com";
15
- }
16
- script.src = `https://${host}/merchantpgpui/checkoutjs/merchants/${vendorDetails.paytmMerchantKey}.js`;
17
- script.type = "application/javascript"
18
- console.log(script);
19
- document.head.appendChild(script);
20
-
21
- }
22
-
23
- if("razorpayMerchantKey" in vendorDetails){
24
- razorpayMerchantKey = vendorDetails.razorpayMerchantKey;
25
-
26
- const script = document.createElement("script");
27
- script.src = `https://checkout.razorpay.com/v1/checkout.js`;
28
- console.log(script);
29
- document.head.appendChild(script);
30
-
31
- }
32
-
33
- }
34
-
35
- export function invokePaymentPage(paymentVendor, initiateTxnReq, initiateTxnResp){
36
- switch(paymentVendor){
37
- case 'paytm':
38
- startPaytm(paytmMerchantKey, initiateTxnReq, initiateTxnResp);
39
- break;
40
- case 'razorpay':
41
- startRazorpay(razorpayMerchantKey, initiateTxnReq, initiateTxnResp);
42
- break;
43
- default:
44
- alert("Invalid Payment Vendor");
45
- }
46
- }
47
-
48
- function startRazorpay(merchantKey, initiateTxnReq, initiateTxnResp){
49
-
50
- var options = {
51
- "key": merchantKey,
52
- "amount": initiateTxnReq.amount,
53
- "currency": "INR",
54
- "order_id": initiateTxnResp.token,
55
- "callback_url": initiateTxnReq.callbackUrl,
56
- };
57
- var rzp1 = new Razorpay(options);
58
- rzp1.open();
59
- }
60
-
61
- function startPaytm(merchantKey, initiateTxnReq, initiateTxnResp){
62
-
63
- const config = {
64
- root: "",
65
- flow: "DEFAULT",
66
- data: {
67
- orderId: initiateTxnReq.orderId,
68
- token: initiateTxnResp.token,
69
- tokenType: "TXN_TOKEN",
70
- amount: initiateTxnReq.amount
71
- },
72
- handler: {
73
- notifyMerchant: function (eventName, data) {
74
- console.log("Event:", eventName, data);
75
- }
76
- }
77
- };
78
- console.log(config);
79
-
80
- Paytm.CheckoutJS.init(config).then(() => {
81
- Paytm.CheckoutJS.invoke();
82
- }).catch(err => {
83
- console.error("Paytm Checkout init failed:", err);
84
- });
85
- }