@ahfl/unifiedpay 1.0.0 → 1.0.1
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/index.js +94 -0
- package/package.json +3 -3
- package/unifiedpay.js +0 -85
package/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
console.log(script);
|
|
21
|
+
document.head.appendChild(script);
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if("razorpayMerchantKey" in vendorDetails){
|
|
26
|
+
razorpayMerchantKey = vendorDetails.razorpayMerchantKey;
|
|
27
|
+
|
|
28
|
+
const script = document.createElement("script");
|
|
29
|
+
script.src = `https://checkout.razorpay.com/v1/checkout.js`;
|
|
30
|
+
console.log(script);
|
|
31
|
+
document.head.appendChild(script);
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function invokePaymentPage(paymentVendor, initiateTxnReq, initiateTxnResp){
|
|
38
|
+
switch(paymentVendor){
|
|
39
|
+
case 'paytm':
|
|
40
|
+
startPaytm(paytmMerchantKey, initiateTxnReq, initiateTxnResp);
|
|
41
|
+
break;
|
|
42
|
+
case 'razorpay':
|
|
43
|
+
startRazorpay(razorpayMerchantKey, initiateTxnReq, initiateTxnResp);
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
alert("Invalid Payment Vendor");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function startRazorpay(merchantKey, initiateTxnReq, initiateTxnResp){
|
|
51
|
+
|
|
52
|
+
var options = {
|
|
53
|
+
"key": merchantKey,
|
|
54
|
+
"amount": initiateTxnReq.amount,
|
|
55
|
+
"currency": "INR",
|
|
56
|
+
"order_id": initiateTxnResp.token,
|
|
57
|
+
"callback_url": initiateTxnReq.callbackUrl,
|
|
58
|
+
};
|
|
59
|
+
var rzp1 = new Razorpay(options);
|
|
60
|
+
rzp1.open();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function startPaytm(merchantKey, initiateTxnReq, initiateTxnResp){
|
|
64
|
+
|
|
65
|
+
const config = {
|
|
66
|
+
root: "",
|
|
67
|
+
flow: "DEFAULT",
|
|
68
|
+
data: {
|
|
69
|
+
orderId: initiateTxnReq.orderId,
|
|
70
|
+
token: initiateTxnResp.token,
|
|
71
|
+
tokenType: "TXN_TOKEN",
|
|
72
|
+
amount: initiateTxnReq.amount
|
|
73
|
+
},
|
|
74
|
+
handler: {
|
|
75
|
+
notifyMerchant: function (eventName, data) {
|
|
76
|
+
console.log("Event:", eventName, data);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
console.log(config);
|
|
81
|
+
|
|
82
|
+
Paytm.CheckoutJS.init(config).then(() => {
|
|
83
|
+
Paytm.CheckoutJS.invoke();
|
|
84
|
+
}).catch(err => {
|
|
85
|
+
console.error("Paytm Checkout init failed:", err);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
global.UnifiedPay = {
|
|
90
|
+
setupVendors,
|
|
91
|
+
invokePaymentPage
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
})(window);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahfl/unifiedpay",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "1.0.1",
|
|
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
|
-
}
|