@ahfl/unifiedpay 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/README.md +6 -0
- package/package.json +12 -0
- package/unifiedpay.js +85 -0
package/README.md
ADDED
package/package.json
ADDED
package/unifiedpay.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
}
|