@aikaara/chat-sdk 1.5.0 → 1.5.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.
- package/dist/{AikaaraLinkButton-BU0Njp0Y.cjs → AikaaraLinkButton-BQB_myLX.cjs} +1 -1
- package/dist/{AikaaraLinkButton--vcUguMg.mjs → AikaaraLinkButton-DHQbtHiT.mjs} +1 -1
- package/dist/AikaaraPaymentLink-CL4O6gbc.mjs +263 -0
- package/dist/AikaaraPaymentLink-D_SZ081m.cjs +1 -0
- package/dist/{MountTenant-TQ5sAymp.cjs → MountTenant-DYzXut6V.cjs} +36 -36
- package/dist/{MountTenant-CdW5PnSv.mjs → MountTenant-nlS1ZOcJ.mjs} +622 -586
- package/dist/cdn/aikaara-chat.iife.js +53 -53
- package/dist/headless.cjs +1 -1
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/ui.cjs +1 -1
- package/dist/ui.mjs +1 -1
- package/package.json +1 -1
- package/dist/AikaaraPaymentLink-D-tyM5fI.mjs +0 -217
- package/dist/AikaaraPaymentLink-Dq3uDB0c.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./MountTenant-DYzXut6V.cjs");class l extends HTMLElement{shadow;payload=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setPayload(e){this.payload=e,this.render()}render(){const e=this.payload;this.shadow.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
:host { display: block; margin-top: 8px; }
|
|
4
4
|
button {
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
const k = "https://checkout.razorpay.com/v1/checkout.js";
|
|
2
|
+
let m = null;
|
|
3
|
+
function y() {
|
|
4
|
+
return window;
|
|
5
|
+
}
|
|
6
|
+
class w extends HTMLElement {
|
|
7
|
+
shadow;
|
|
8
|
+
payloadData = [];
|
|
9
|
+
message = "";
|
|
10
|
+
// Per-payload-index lock so a successful payment disables only that
|
|
11
|
+
// button (other rows in the same template remain clickable).
|
|
12
|
+
paidIdx = {};
|
|
13
|
+
constructor() {
|
|
14
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
15
|
+
}
|
|
16
|
+
setPayload(t, n) {
|
|
17
|
+
this.payloadData = Array.isArray(t) ? t : [], this.message = n ?? "", this.render();
|
|
18
|
+
}
|
|
19
|
+
render() {
|
|
20
|
+
const t = this.payloadData.filter(
|
|
21
|
+
(e) => !!e && typeof e == "object" && e.type === "link" && typeof e.url == "string"
|
|
22
|
+
), n = t.map((e, s) => {
|
|
23
|
+
const o = e.name || "Open link", r = !!this.paidIdx[s];
|
|
24
|
+
return `<button class="link${r ? " paid" : ""}" data-i="${s}" type="button"${r ? " disabled" : ""}><span class="lbl">${g(r ? "Paid" : o)}</span>` + (r ? '<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5 L7 12 L13 5"/></svg>' : '<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 11 L11 5 M6 5 H11 V10"/></svg>') + "</button>";
|
|
25
|
+
}).join("");
|
|
26
|
+
this.shadow.innerHTML = "<style>:host { display:block; margin:6px 0; font-family:inherit; }.bubble { padding:12px 16px; border-radius:14px; background:var(--aikaara-bot-bubble-bg, #d8e5f5); color:var(--aikaara-bot-bubble-text, #1a2845); font-size:14px; line-height:1.55; margin-bottom:10px; }.links { display:flex; flex-direction:column; gap:8px; }.link { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 22px; border:1.5px solid var(--aikaara-primary, #1849a9); background:var(--aikaara-primary, #1849a9); color:var(--aikaara-primary-contrast, #fff); border-radius:24px; font-size:14px; font-weight:600; cursor:pointer; font-family:inherit; text-decoration:none; transition: filter 120ms; width:150px; align-self:flex-start; }.link:hover:not(:disabled) { filter: brightness(0.94); }.link.paid, .link:disabled { background:#e7f5ec; color:#0e7c3a; border-color:#0e7c3a; cursor:default; }.icon { width:13px; height:13px; }</style>" + (this.message ? `<div class="bubble">${this.message}</div>` : "") + `<div class="links">${n}</div>`, this.shadow.querySelectorAll(".link").forEach((e) => {
|
|
27
|
+
e.addEventListener("click", () => {
|
|
28
|
+
if (e.disabled) return;
|
|
29
|
+
const s = Number(e.dataset.i || 0), o = t[s];
|
|
30
|
+
o && this.handleClick(s, o);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
handleClick(t, n) {
|
|
35
|
+
const e = b(n), s = y().__aikaara_descriptor__, o = s?.partnerPayment, r = s?.razorpay;
|
|
36
|
+
if (e && o?.paymentLinkUrl) {
|
|
37
|
+
this.openPartnerPaymentLink(t, e, n, o);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!e || !r?.keyId) {
|
|
41
|
+
I(n.url, n.name || "Pay"), this.dispatchEvent(
|
|
42
|
+
new CustomEvent("template-action", {
|
|
43
|
+
detail: {
|
|
44
|
+
text: n.name || "link-click",
|
|
45
|
+
attributes: {
|
|
46
|
+
action: { type: "link", url: n.url, orderId: e || n.orderId, openedIn: "modal" }
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
bubbles: !0,
|
|
50
|
+
composed: !0
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
_(r.preferredBanksUrl, e, r.preferredBanksMethod, r.preferredBanksHeaders).catch((c) => (console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI", c), [])).then((c) => P().then(() => this.openRazorpay(t, e, r, c))).catch((c) => {
|
|
56
|
+
console.error("[payment_link] Razorpay launch failed", c);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
openPartnerPaymentLink(t, n, e, s) {
|
|
60
|
+
v(n, s).then((o) => {
|
|
61
|
+
if (!o) {
|
|
62
|
+
f("Failed to generate payment link, please try again later");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const r = (o.paymentStatus ?? "").toLowerCase();
|
|
66
|
+
if (r === "paid" || r === "success" || r === "completed") {
|
|
67
|
+
this.paidIdx[t] = !0, this.render(), f("Payment already completed");
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const c = o.vendorPaymentLink;
|
|
71
|
+
if (!c) {
|
|
72
|
+
f("Failed to generate payment link, please try again later");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const l = navigator.userAgent.toLowerCase();
|
|
76
|
+
if (l.includes("iphone") || l.includes("ipad") || l.includes("ipod")) {
|
|
77
|
+
window.location.href = c;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const d = x(c);
|
|
81
|
+
if (!d) {
|
|
82
|
+
window.open(c, "_blank"), f("Allow popups for the best payment experience");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.dispatchEvent(
|
|
86
|
+
new CustomEvent("template-action", {
|
|
87
|
+
detail: {
|
|
88
|
+
text: e.name || "link-click",
|
|
89
|
+
attributes: {
|
|
90
|
+
action: { type: "partner-payment", url: c, orderId: n, openedIn: "popup" }
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
bubbles: !0,
|
|
94
|
+
composed: !0
|
|
95
|
+
})
|
|
96
|
+
), C(d, s.checkoutOrigin, {
|
|
97
|
+
onSuccess: () => {
|
|
98
|
+
this.paidIdx[t] = !0, this.render();
|
|
99
|
+
},
|
|
100
|
+
onError: (p) => {
|
|
101
|
+
f(p || "Payment failed, please try again");
|
|
102
|
+
},
|
|
103
|
+
onClose: () => {
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}).catch((o) => {
|
|
107
|
+
console.error("[payment_link] partner payment link fetch failed", o), f("Failed to generate payment link, please try again later");
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
openRazorpay(t, n, e, s) {
|
|
111
|
+
const o = y(), r = o.__aikaara_runtime__?.identity ?? {}, c = {
|
|
112
|
+
key: e.keyId,
|
|
113
|
+
order_id: n,
|
|
114
|
+
name: e.name || o.__aikaara_descriptor__?.title || "Payment",
|
|
115
|
+
prefill: {},
|
|
116
|
+
handler: () => {
|
|
117
|
+
this.paidIdx[t] = !0, this.render();
|
|
118
|
+
},
|
|
119
|
+
modal: {
|
|
120
|
+
// No auto-hide on dismiss: user can re-click Pay Now. Per spec,
|
|
121
|
+
// button only locks on confirmed success.
|
|
122
|
+
ondismiss: () => {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
typeof r.mobile == "string" ? c.prefill.contact = r.mobile : typeof r.phone == "string" && (c.prefill.contact = r.phone), typeof r.email == "string" && (c.prefill.email = r.email), typeof r.name == "string" ? c.prefill.name = r.name : typeof r.userName == "string" && (c.prefill.name = r.userName), Array.isArray(s) && s.length && (c.config = {
|
|
127
|
+
display: {
|
|
128
|
+
blocks: {
|
|
129
|
+
utib: {
|
|
130
|
+
name: "Pay Using Preferred Netbanking",
|
|
131
|
+
instruments: [{ method: "netbanking", banks: s }]
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
sequence: ["block.utib", "netbanking", "card", "upi"],
|
|
135
|
+
preferences: { show_default_blocks: !0 }
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const l = o.Razorpay;
|
|
139
|
+
if (typeof l != "function")
|
|
140
|
+
throw new Error("Razorpay Checkout script not available");
|
|
141
|
+
const i = new l(c);
|
|
142
|
+
i.on("payment.failed", (d) => {
|
|
143
|
+
console.warn("[payment_link] payment.failed", d?.error);
|
|
144
|
+
}), i.open();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function g(a) {
|
|
148
|
+
return String(a ?? "").replace(/[&<>]/g, (t) => t === "&" ? "&" : t === "<" ? "<" : ">");
|
|
149
|
+
}
|
|
150
|
+
function b(a) {
|
|
151
|
+
if (typeof a.orderId == "string" && a.orderId) return a.orderId;
|
|
152
|
+
try {
|
|
153
|
+
const t = new URL(a.url, window.location.origin), n = t.searchParams.get("orderId") || t.searchParams.get("order_id");
|
|
154
|
+
if (n) return n;
|
|
155
|
+
if (t.hash && t.hash.length > 1) {
|
|
156
|
+
const e = new URLSearchParams(t.hash.replace(/^#/, "")), s = e.get("orderId") || e.get("order_id");
|
|
157
|
+
if (s) return s;
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
function P() {
|
|
164
|
+
return typeof y().Razorpay == "function" ? Promise.resolve() : m || (m = new Promise((a, t) => {
|
|
165
|
+
const n = document.querySelector('script[data-aikaara-razorpay="1"]');
|
|
166
|
+
if (n) {
|
|
167
|
+
n.addEventListener("load", () => a()), n.addEventListener("error", () => t(new Error("checkout.js failed to load")));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const e = document.createElement("script");
|
|
171
|
+
e.src = k, e.async = !0, e.dataset.aikaaraRazorpay = "1", e.onload = () => a(), e.onerror = () => {
|
|
172
|
+
m = null, t(new Error("checkout.js failed to load"));
|
|
173
|
+
}, document.head.appendChild(e);
|
|
174
|
+
}), m);
|
|
175
|
+
}
|
|
176
|
+
function _(a, t, n, e) {
|
|
177
|
+
if (!a) return Promise.resolve([]);
|
|
178
|
+
const s = String(n || "GET").toUpperCase() === "POST" ? "POST" : "GET", o = a.includes("{orderId}") ? a.replace("{orderId}", encodeURIComponent(t)) : a + (a.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(t), r = y().__aikaara_runtime__ ?? {};
|
|
179
|
+
return (typeof r.getSessionToken == "function" ? r.getSessionToken() : typeof r.getChatJwt == "function" ? r.getChatJwt() : Promise.resolve(null)).then((l) => {
|
|
180
|
+
const i = { Accept: "application/json", ...e ?? {} };
|
|
181
|
+
l && (i.Authorization = `Bearer ${l}`);
|
|
182
|
+
const d = { method: s, headers: i, credentials: "omit" };
|
|
183
|
+
return s === "POST" && (i["Content-Type"] = "application/json", d.body = JSON.stringify({ orderId: t })), fetch(o, d);
|
|
184
|
+
}).then((l) => {
|
|
185
|
+
if (!l.ok) throw new Error(`preferred-banks ${l.status}`);
|
|
186
|
+
return l.json();
|
|
187
|
+
}).then((l) => {
|
|
188
|
+
const i = l, d = i?.data && typeof i.data == "object" && !Array.isArray(i.data) ? i.data : null;
|
|
189
|
+
return (Array.isArray(l) ? l : Array.isArray(i?.banks) ? i.banks : Array.isArray(i?.data) ? i.data : Array.isArray(d?.preferredPaymentBank) ? d.preferredPaymentBank : Array.isArray(d?.banks) ? d.banks : []).map((u) => {
|
|
190
|
+
if (typeof u == "string") return u;
|
|
191
|
+
if (u && typeof u == "object") {
|
|
192
|
+
const h = u;
|
|
193
|
+
return h.code || h.bankCode || h.bank_code || null;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}).filter((u) => !!u);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async function v(a, t) {
|
|
200
|
+
const n = String(t.method || "GET").toUpperCase() === "POST" ? "POST" : "GET", e = t.paymentLinkUrl, s = e.includes("{orderId}") ? e.replace("{orderId}", encodeURIComponent(a)) : e + (e.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(a), o = y().__aikaara_runtime__ ?? {}, r = typeof o.getSessionToken == "function" ? await o.getSessionToken() : typeof o.getChatJwt == "function" ? await o.getChatJwt() : null, c = { Accept: "application/json", ...t.headers ?? {} };
|
|
201
|
+
r && (c.Authorization = `Bearer ${r}`);
|
|
202
|
+
const l = { method: n, headers: c, credentials: "omit" };
|
|
203
|
+
n === "POST" && (c["Content-Type"] = "application/json", l.body = JSON.stringify({ orderId: a }));
|
|
204
|
+
const i = await fetch(s, l);
|
|
205
|
+
if (!i.ok) throw new Error(`partner-payment-link ${i.status}`);
|
|
206
|
+
const p = (await i.json())?.data;
|
|
207
|
+
return !p || typeof p.vendorPaymentLink != "string" ? null : { vendorPaymentLink: p.vendorPaymentLink, paymentStatus: p.paymentStatus ?? "" };
|
|
208
|
+
}
|
|
209
|
+
function x(a) {
|
|
210
|
+
const e = window.screenX + Math.round((window.outerWidth - 520) / 2), s = window.screenY + Math.round((window.outerHeight - 680) / 2);
|
|
211
|
+
return window.open(
|
|
212
|
+
a,
|
|
213
|
+
"taxbuddy_payment",
|
|
214
|
+
`width=520,height=680,left=${e},top=${s},scrollbars=yes,resizable=yes`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
function C(a, t, n) {
|
|
218
|
+
let e = !1;
|
|
219
|
+
function s() {
|
|
220
|
+
clearInterval(c), window.removeEventListener("message", r);
|
|
221
|
+
}
|
|
222
|
+
function o(l) {
|
|
223
|
+
e || (e = !0, s(), l());
|
|
224
|
+
}
|
|
225
|
+
function r(l) {
|
|
226
|
+
if (t && l.origin !== t) return;
|
|
227
|
+
const i = l.data;
|
|
228
|
+
if (!(!i || typeof i != "object")) {
|
|
229
|
+
if (i.type === "payment-completed" && i.success === !0) {
|
|
230
|
+
o(() => n.onSuccess());
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
i.type === "payment-error" && i.success === !1 && o(() => n.onError(i.error ?? "Payment failed"));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const c = setInterval(() => {
|
|
237
|
+
a.closed && o(() => n.onClose());
|
|
238
|
+
}, 500);
|
|
239
|
+
window.addEventListener("message", r);
|
|
240
|
+
}
|
|
241
|
+
function f(a) {
|
|
242
|
+
try {
|
|
243
|
+
const t = document.querySelector("aikaara-error-banner");
|
|
244
|
+
if (t && typeof t.show == "function") {
|
|
245
|
+
t.show(a);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
} catch {
|
|
249
|
+
}
|
|
250
|
+
console.warn("[payment_link]", a);
|
|
251
|
+
}
|
|
252
|
+
function I(a, t) {
|
|
253
|
+
if (!a) return;
|
|
254
|
+
let n = document.querySelector("aikaara-link-modal");
|
|
255
|
+
n || (n = document.createElement("aikaara-link-modal"), document.body.appendChild(n)), typeof n.show == "function" ? n.show(a, t) : window.open(a, "_blank", "noopener,noreferrer");
|
|
256
|
+
}
|
|
257
|
+
function S() {
|
|
258
|
+
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link", w);
|
|
259
|
+
}
|
|
260
|
+
export {
|
|
261
|
+
w as AikaaraPaymentLink,
|
|
262
|
+
S as registerAikaaraPaymentLink
|
|
263
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="https://checkout.razorpay.com/v1/checkout.js";let m=null;function y(){return window}class k extends HTMLElement{shadow;payloadData=[];message="";paidIdx={};constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}setPayload(t,n){this.payloadData=Array.isArray(t)?t:[],this.message=n??"",this.render()}render(){const t=this.payloadData.filter(e=>!!e&&typeof e=="object"&&e.type==="link"&&typeof e.url=="string"),n=t.map((e,s)=>{const o=e.name||"Open link",r=!!this.paidIdx[s];return`<button class="link${r?" paid":""}" data-i="${s}" type="button"${r?" disabled":""}><span class="lbl">${w(r?"Paid":o)}</span>`+(r?'<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5 L7 12 L13 5"/></svg>':'<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M5 11 L11 5 M6 5 H11 V10"/></svg>')+"</button>"}).join("");this.shadow.innerHTML="<style>:host { display:block; margin:6px 0; font-family:inherit; }.bubble { padding:12px 16px; border-radius:14px; background:var(--aikaara-bot-bubble-bg, #d8e5f5); color:var(--aikaara-bot-bubble-text, #1a2845); font-size:14px; line-height:1.55; margin-bottom:10px; }.links { display:flex; flex-direction:column; gap:8px; }.link { display:inline-flex; align-items:center; justify-content:center; gap:8px; padding:11px 22px; border:1.5px solid var(--aikaara-primary, #1849a9); background:var(--aikaara-primary, #1849a9); color:var(--aikaara-primary-contrast, #fff); border-radius:24px; font-size:14px; font-weight:600; cursor:pointer; font-family:inherit; text-decoration:none; transition: filter 120ms; width:150px; align-self:flex-start; }.link:hover:not(:disabled) { filter: brightness(0.94); }.link.paid, .link:disabled { background:#e7f5ec; color:#0e7c3a; border-color:#0e7c3a; cursor:default; }.icon { width:13px; height:13px; }</style>"+(this.message?`<div class="bubble">${this.message}</div>`:"")+`<div class="links">${n}</div>`,this.shadow.querySelectorAll(".link").forEach(e=>{e.addEventListener("click",()=>{if(e.disabled)return;const s=Number(e.dataset.i||0),o=t[s];o&&this.handleClick(s,o)})})}handleClick(t,n){const e=b(n),s=y().__aikaara_descriptor__,o=s?.partnerPayment,r=s?.razorpay;if(e&&o?.paymentLinkUrl){this.openPartnerPaymentLink(t,e,n,o);return}if(!e||!r?.keyId){S(n.url,n.name||"Pay"),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:n.name||"link-click",attributes:{action:{type:"link",url:n.url,orderId:e||n.orderId,openedIn:"modal"}}},bubbles:!0,composed:!0}));return}_(r.preferredBanksUrl,e,r.preferredBanksMethod,r.preferredBanksHeaders).catch(c=>(console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI",c),[])).then(c=>P().then(()=>this.openRazorpay(t,e,r,c))).catch(c=>{console.error("[payment_link] Razorpay launch failed",c)})}openPartnerPaymentLink(t,n,e,s){v(n,s).then(o=>{if(!o){f("Failed to generate payment link, please try again later");return}const r=(o.paymentStatus??"").toLowerCase();if(r==="paid"||r==="success"||r==="completed"){this.paidIdx[t]=!0,this.render(),f("Payment already completed");return}const c=o.vendorPaymentLink;if(!c){f("Failed to generate payment link, please try again later");return}const l=navigator.userAgent.toLowerCase();if(l.includes("iphone")||l.includes("ipad")||l.includes("ipod")){window.location.href=c;return}const d=x(c);if(!d){window.open(c,"_blank"),f("Allow popups for the best payment experience");return}this.dispatchEvent(new CustomEvent("template-action",{detail:{text:e.name||"link-click",attributes:{action:{type:"partner-payment",url:c,orderId:n,openedIn:"popup"}}},bubbles:!0,composed:!0})),C(d,s.checkoutOrigin,{onSuccess:()=>{this.paidIdx[t]=!0,this.render()},onError:p=>{f(p||"Payment failed, please try again")},onClose:()=>{}})}).catch(o=>{console.error("[payment_link] partner payment link fetch failed",o),f("Failed to generate payment link, please try again later")})}openRazorpay(t,n,e,s){const o=y(),r=o.__aikaara_runtime__?.identity??{},c={key:e.keyId,order_id:n,name:e.name||o.__aikaara_descriptor__?.title||"Payment",prefill:{},handler:()=>{this.paidIdx[t]=!0,this.render()},modal:{ondismiss:()=>{}}};typeof r.mobile=="string"?c.prefill.contact=r.mobile:typeof r.phone=="string"&&(c.prefill.contact=r.phone),typeof r.email=="string"&&(c.prefill.email=r.email),typeof r.name=="string"?c.prefill.name=r.name:typeof r.userName=="string"&&(c.prefill.name=r.userName),Array.isArray(s)&&s.length&&(c.config={display:{blocks:{utib:{name:"Pay Using Preferred Netbanking",instruments:[{method:"netbanking",banks:s}]}},sequence:["block.utib","netbanking","card","upi"],preferences:{show_default_blocks:!0}}});const l=o.Razorpay;if(typeof l!="function")throw new Error("Razorpay Checkout script not available");const i=new l(c);i.on("payment.failed",d=>{console.warn("[payment_link] payment.failed",d?.error)}),i.open()}}function w(a){return String(a??"").replace(/[&<>]/g,t=>t==="&"?"&":t==="<"?"<":">")}function b(a){if(typeof a.orderId=="string"&&a.orderId)return a.orderId;try{const t=new URL(a.url,window.location.origin),n=t.searchParams.get("orderId")||t.searchParams.get("order_id");if(n)return n;if(t.hash&&t.hash.length>1){const e=new URLSearchParams(t.hash.replace(/^#/,"")),s=e.get("orderId")||e.get("order_id");if(s)return s}}catch{}return null}function P(){return typeof y().Razorpay=="function"?Promise.resolve():m||(m=new Promise((a,t)=>{const n=document.querySelector('script[data-aikaara-razorpay="1"]');if(n){n.addEventListener("load",()=>a()),n.addEventListener("error",()=>t(new Error("checkout.js failed to load")));return}const e=document.createElement("script");e.src=g,e.async=!0,e.dataset.aikaaraRazorpay="1",e.onload=()=>a(),e.onerror=()=>{m=null,t(new Error("checkout.js failed to load"))},document.head.appendChild(e)}),m)}function _(a,t,n,e){if(!a)return Promise.resolve([]);const s=String(n||"GET").toUpperCase()==="POST"?"POST":"GET",o=a.includes("{orderId}")?a.replace("{orderId}",encodeURIComponent(t)):a+(a.includes("?")?"&":"?")+"orderId="+encodeURIComponent(t),r=y().__aikaara_runtime__??{};return(typeof r.getSessionToken=="function"?r.getSessionToken():typeof r.getChatJwt=="function"?r.getChatJwt():Promise.resolve(null)).then(l=>{const i={Accept:"application/json",...e??{}};l&&(i.Authorization=`Bearer ${l}`);const d={method:s,headers:i,credentials:"omit"};return s==="POST"&&(i["Content-Type"]="application/json",d.body=JSON.stringify({orderId:t})),fetch(o,d)}).then(l=>{if(!l.ok)throw new Error(`preferred-banks ${l.status}`);return l.json()}).then(l=>{const i=l,d=i?.data&&typeof i.data=="object"&&!Array.isArray(i.data)?i.data:null;return(Array.isArray(l)?l:Array.isArray(i?.banks)?i.banks:Array.isArray(i?.data)?i.data:Array.isArray(d?.preferredPaymentBank)?d.preferredPaymentBank:Array.isArray(d?.banks)?d.banks:[]).map(u=>{if(typeof u=="string")return u;if(u&&typeof u=="object"){const h=u;return h.code||h.bankCode||h.bank_code||null}return null}).filter(u=>!!u)})}async function v(a,t){const n=String(t.method||"GET").toUpperCase()==="POST"?"POST":"GET",e=t.paymentLinkUrl,s=e.includes("{orderId}")?e.replace("{orderId}",encodeURIComponent(a)):e+(e.includes("?")?"&":"?")+"orderId="+encodeURIComponent(a),o=y().__aikaara_runtime__??{},r=typeof o.getSessionToken=="function"?await o.getSessionToken():typeof o.getChatJwt=="function"?await o.getChatJwt():null,c={Accept:"application/json",...t.headers??{}};r&&(c.Authorization=`Bearer ${r}`);const l={method:n,headers:c,credentials:"omit"};n==="POST"&&(c["Content-Type"]="application/json",l.body=JSON.stringify({orderId:a}));const i=await fetch(s,l);if(!i.ok)throw new Error(`partner-payment-link ${i.status}`);const p=(await i.json())?.data;return!p||typeof p.vendorPaymentLink!="string"?null:{vendorPaymentLink:p.vendorPaymentLink,paymentStatus:p.paymentStatus??""}}function x(a){const e=window.screenX+Math.round((window.outerWidth-520)/2),s=window.screenY+Math.round((window.outerHeight-680)/2);return window.open(a,"taxbuddy_payment",`width=520,height=680,left=${e},top=${s},scrollbars=yes,resizable=yes`)}function C(a,t,n){let e=!1;function s(){clearInterval(c),window.removeEventListener("message",r)}function o(l){e||(e=!0,s(),l())}function r(l){if(t&&l.origin!==t)return;const i=l.data;if(!(!i||typeof i!="object")){if(i.type==="payment-completed"&&i.success===!0){o(()=>n.onSuccess());return}i.type==="payment-error"&&i.success===!1&&o(()=>n.onError(i.error??"Payment failed"))}}const c=setInterval(()=>{a.closed&&o(()=>n.onClose())},500);window.addEventListener("message",r)}function f(a){try{const t=document.querySelector("aikaara-error-banner");if(t&&typeof t.show=="function"){t.show(a);return}}catch{}console.warn("[payment_link]",a)}function S(a,t){if(!a)return;let n=document.querySelector("aikaara-link-modal");n||(n=document.createElement("aikaara-link-modal"),document.body.appendChild(n)),typeof n.show=="function"?n.show(a,t):window.open(a,"_blank","noopener,noreferrer")}function I(){typeof customElements>"u"||customElements.get("aikaara-template-payment-link")||customElements.define("aikaara-template-payment-link",k)}exports.AikaaraPaymentLink=k;exports.registerAikaaraPaymentLink=I;
|