@aikaara/chat-sdk 1.4.34 → 1.5.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/dist/{AikaaraLinkButton-Cxbk_vrf.mjs → AikaaraLinkButton-CnvirM17.mjs} +1 -1
- package/dist/{AikaaraLinkButton-BdjjiK9B.cjs → AikaaraLinkButton-DFT_nAv9.cjs} +1 -1
- package/dist/AikaaraPaymentLink-CL4O6gbc.mjs +263 -0
- package/dist/AikaaraPaymentLink-D_SZ081m.cjs +1 -0
- package/dist/{MountTenant-C7jZ30qM.mjs → MountTenant-YqTsrEgP.mjs} +2 -2
- package/dist/{MountTenant-CnfYUT2t.cjs → MountTenant-wJ3Clo04.cjs} +2 -2
- package/dist/cdn/aikaara-chat.iife.js +55 -55
- 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-C-GhGZ4c.cjs +0 -1
- package/dist/AikaaraPaymentLink-C82ApGKH.mjs +0 -155
package/dist/headless.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-wJ3Clo04.cjs");class s extends e.EventEmitter{registration=null;pendingEdits=[];constructor(t){super(),this.setupListeners(t)}registerForm(t){this.registration=t;const i=this.pendingEdits.filter(r=>r.entity_type===t.entityType&&String(r.entity_id)===String(t.entityId));if(i.length>0){for(const r of i)t.onFieldUpdate(r.fields),this.emit("edit:applied",{entityType:r.entity_type,entityId:r.entity_id,fields:r.fields});this.pendingEdits=this.pendingEdits.filter(r=>!(r.entity_type===t.entityType&&String(r.entity_id)===String(t.entityId)))}}unregisterForm(t,i){this.registration?.entityType===t&&String(this.registration?.entityId)===String(i)&&(this.registration=null)}get currentForm(){return this.registration}pushFieldUpdates(t,i,r){this.registration&&this.registration.entityType===t&&String(this.registration.entityId)===String(i)?(this.registration.onFieldUpdate(r),this.emit("edit:applied",{entityType:t,entityId:i,fields:r})):(this.pendingEdits.push({action:"edit_entity",entity_type:t,entity_id:i,fields:r}),this.emit("edit:pending",{entityType:t,entityId:i,fields:r}))}async requestSave(){if(!this.registration)return{success:!1,error:"No form registered"};try{return await this.registration.onSave(),this.emit("save:success",{entityType:this.registration.entityType,entityId:this.registration.entityId}),{success:!0}}catch(t){const i=t instanceof Error?t.message:"Save failed";return this.emit("save:error",{entityType:this.registration.entityType,entityId:this.registration.entityId,error:i}),{success:!1,error:i}}}async requestTest(t){if(!this.registration?.onTest)return{success:!1,error:"Current form does not support testing"};try{return await this.registration.onTest(t),{success:!0}}catch(i){return{success:!1,error:i instanceof Error?i.message:"Test failed"}}}setupListeners(t){t.on("action:edit_entity",i=>{this.pushFieldUpdates(i.entity_type,i.entity_id,i.fields)}),t.on("action:save_entity",i=>{this.requestSave()}),t.on("action:test_tool",i=>{this.emit("test:triggered",{toolId:i.tool_id,parameters:i.parameters}),this.requestTest(i.parameters)})}}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatClient=e.AikaaraChatClient;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.SessionAuthAdapter=e.SessionAuthAdapter;exports.SsoExchangeAdapter=e.SsoExchangeAdapter;exports.TiledeskTransport=e.TiledeskTransport;exports.TokenDiscoveryError=e.TokenDiscoveryError;exports.TokenDiscoveryReader=e.TokenDiscoveryReader;exports.clearPersistedConversationId=e.clearPersistedConversationId;exports.collectSsoCredentials=e.collectSsoCredentials;exports.createFetchUploadAdapter=e.createFetchUploadAdapter;exports.createPresigned3StepUploadAdapter=e.createPresigned3StepUploadAdapter;exports.createTiledeskHistoryAdapter=e.createTiledeskHistoryAdapter;exports.discoverToken=e.discoverToken;exports.extractTiledeskFileEnvelope=e.extractTiledeskFileEnvelope;exports.inferTiledeskRole=e.inferTiledeskRole;exports.isTiledeskSelfEcho=e.isTiledeskSelfEcho;exports.mountFromSlug=e.mountFromSlug;exports.mountTenantWidget=e.mount;exports.parseTiledeskTemplate=e.parseTiledeskTemplate;exports.runMethodSelectPreflight=e.runMethodSelectPreflight;exports.FormBridge=s;
|
package/dist/headless.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as s } from "./MountTenant-
|
|
2
|
-
import { A as p, b as l, k as g, C as c, l as h, m as y, M as u, S as m, n as f, T, o as S, p as _, q as v, s as E, t as C, u as F, v as k, w as A, x as I, y as x, z as U, B as q, D as M, F as b, G as w } from "./MountTenant-
|
|
1
|
+
import { E as s } from "./MountTenant-YqTsrEgP.mjs";
|
|
2
|
+
import { A as p, b as l, k as g, C as c, l as h, m as y, M as u, S as m, n as f, T, o as S, p as _, q as v, s as E, t as C, u as F, v as k, w as A, x as I, y as x, z as U, B as q, D as M, F as b, G as w } from "./MountTenant-YqTsrEgP.mjs";
|
|
3
3
|
class a extends s {
|
|
4
4
|
registration = null;
|
|
5
5
|
pendingEdits = [];
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-wJ3Clo04.cjs"),s=require("./headless.cjs");function l(a){e.registerComponents();const t=document.createElement("aikaara-chat-widget"),i={baseUrl:"base-url",userToken:"user-token",apiKey:"api-key",title:"title",subtitle:"subtitle",theme:"theme",primaryColor:"primary-color",position:"position",width:"width",height:"height",placeholder:"placeholder",welcomeMessage:"welcome-message",avatarUrl:"avatar-url"};for(const[o,n]of Object.entries(i)){const r=a[o];r!=null&&t.setAttribute(n,String(r))}return t.configure(a),document.body.appendChild(t),t}function d(){const a=document.querySelector("aikaara-chat-widget");a&&a.remove()}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatBubble=e.AikaaraChatBubble;exports.AikaaraChatClient=e.AikaaraChatClient;exports.AikaaraChatHeader=e.AikaaraChatHeader;exports.AikaaraChatInput=e.AikaaraChatInput;exports.AikaaraChatWidget=e.AikaaraChatWidget;exports.AikaaraErrorBanner=e.AikaaraErrorBanner;exports.AikaaraMessageBubble=e.AikaaraMessageBubble;exports.AikaaraMessageList=e.AikaaraMessageList;exports.AikaaraStreamingMessage=e.AikaaraStreamingMessage;exports.AikaaraTypingIndicator=e.AikaaraTypingIndicator;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.SessionAuthAdapter=e.SessionAuthAdapter;exports.SsoExchangeAdapter=e.SsoExchangeAdapter;exports.TiledeskTransport=e.TiledeskTransport;exports.TokenDiscoveryError=e.TokenDiscoveryError;exports.TokenDiscoveryReader=e.TokenDiscoveryReader;exports.clearPersistedConversationId=e.clearPersistedConversationId;exports.collectSsoCredentials=e.collectSsoCredentials;exports.createFetchUploadAdapter=e.createFetchUploadAdapter;exports.createPresigned3StepUploadAdapter=e.createPresigned3StepUploadAdapter;exports.createTiledeskHistoryAdapter=e.createTiledeskHistoryAdapter;exports.discoverToken=e.discoverToken;exports.extractTiledeskFileEnvelope=e.extractTiledeskFileEnvelope;exports.inferTiledeskRole=e.inferTiledeskRole;exports.isTiledeskSelfEcho=e.isTiledeskSelfEcho;exports.mountFromSlug=e.mountFromSlug;exports.mountTenantWidget=e.mount;exports.parseTiledeskTemplate=e.parseTiledeskTemplate;exports.registerComponents=e.registerComponents;exports.runMethodSelectPreflight=e.runMethodSelectPreflight;exports.FormBridge=s.FormBridge;exports.mount=l;exports.unmount=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as o } from "./MountTenant-
|
|
2
|
-
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as T, h as b, i as f, j as v, k as S, C as y, l as M, m as w, E, M as x, S as B, n as F, T as U, o as D, p as I, q as P, s as j, t as q, u as H, v as R, w as W, x as z, y as G, z as K, B as L, D as O, F as J, G as N } from "./MountTenant-
|
|
1
|
+
import { r as o } from "./MountTenant-YqTsrEgP.mjs";
|
|
2
|
+
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as T, h as b, i as f, j as v, k as S, C as y, l as M, m as w, E, M as x, S as B, n as F, T as U, o as D, p as I, q as P, s as j, t as q, u as H, v as R, w as W, x as z, y as G, z as K, B as L, D as O, F as J, G as N } from "./MountTenant-YqTsrEgP.mjs";
|
|
3
3
|
import { FormBridge as V } from "./headless.mjs";
|
|
4
4
|
function l(e) {
|
|
5
5
|
o();
|
package/dist/ui.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-wJ3Clo04.cjs");exports.AikaaraChat=a.AikaaraChat;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraComparePlans=a.AikaaraComparePlans;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraLinkModal=a.AikaaraLinkModal;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraModalAction=a.AikaaraModalAction;exports.AikaaraOptionList=a.AikaaraOptionList;exports.AikaaraSchemaForm=a.AikaaraSchemaForm;exports.AikaaraSmartEditModal=a.AikaaraSmartEditModal;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraSubmitAction=a.AikaaraSubmitAction;exports.AikaaraSystemPill=a.AikaaraSystemPill;exports.AikaaraTemplateRenderer=a.AikaaraTemplateRenderer;exports.AikaaraTextInput=a.AikaaraTextInput;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;
|
package/dist/ui.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as i, a as s, c as e, d as t, e as A, J as k, f as n, K as o, g as m, h as d, L as l, N as g, O as p, P as h, i as C, Q as M, R as b, U as c, V as u, j as S, r as I } from "./MountTenant-
|
|
1
|
+
import { I as i, a as s, c as e, d as t, e as A, J as k, f as n, K as o, g as m, h as d, L as l, N as g, O as p, P as h, i as C, Q as M, R as b, U as c, V as u, j as S, r as I } from "./MountTenant-YqTsrEgP.mjs";
|
|
2
2
|
export {
|
|
3
3
|
i as AikaaraChat,
|
|
4
4
|
s as AikaaraChatBubble,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="https://checkout.razorpay.com/v1/checkout.js";let u=null;function f(){return window}class h extends HTMLElement{shadow;payloadData=[];message="";paidIdx={};constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}setPayload(r,t){this.payloadData=Array.isArray(r)?r:[],this.message=t??"",this.render()}render(){const r=this.payloadData.filter(e=>!!e&&typeof e=="object"&&e.type==="link"&&typeof e.url=="string"),t=r.map((e,a)=>{const i=e.name||"Open link",o=!!this.paidIdx[a];return`<button class="link${o?" paid":""}" data-i="${a}" type="button"${o?" disabled":""}><span class="lbl">${k(o?"Paid":i)}</span>`+(o?'<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">${t}</div>`,this.shadow.querySelectorAll(".link").forEach(e=>{e.addEventListener("click",()=>{if(e.disabled)return;const a=Number(e.dataset.i||0),i=r[a];i&&this.handleClick(a,i)})})}handleClick(r,t){const e=b(t),a=f().__aikaara_descriptor__?.razorpay;if(!e||!a?.keyId){_(t.url,t.name||"Pay"),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:t.name||"link-click",attributes:{action:{type:"link",url:t.url,orderId:e||t.orderId,openedIn:"modal"}}},bubbles:!0,composed:!0}));return}w(a.preferredBanksUrl,e,a.preferredBanksMethod,a.preferredBanksHeaders).catch(i=>(console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI",i),[])).then(i=>g().then(()=>this.openRazorpay(r,e,a,i))).catch(i=>{console.error("[payment_link] Razorpay launch failed",i)})}openRazorpay(r,t,e,a){const i=f(),o=i.__aikaara_runtime__?.identity??{},c={key:e.keyId,order_id:t,name:e.name||i.__aikaara_descriptor__?.title||"Payment",prefill:{},handler:()=>{this.paidIdx[r]=!0,this.render()},modal:{ondismiss:()=>{}}};typeof o.mobile=="string"?c.prefill.contact=o.mobile:typeof o.phone=="string"&&(c.prefill.contact=o.phone),typeof o.email=="string"&&(c.prefill.email=o.email),typeof o.name=="string"?c.prefill.name=o.name:typeof o.userName=="string"&&(c.prefill.name=o.userName),Array.isArray(a)&&a.length&&(c.config={display:{blocks:{utib:{name:"Pay Using Preferred Netbanking",instruments:[{method:"netbanking",banks:a}]}},sequence:["block.utib","netbanking","card","upi"],preferences:{show_default_blocks:!0}}});const d=i.Razorpay;if(typeof d!="function")throw new Error("Razorpay Checkout script not available");const s=new d(c);s.on("payment.failed",l=>{console.warn("[payment_link] payment.failed",l?.error)}),s.open()}}function k(n){return String(n??"").replace(/[&<>]/g,r=>r==="&"?"&":r==="<"?"<":">")}function b(n){if(typeof n.orderId=="string"&&n.orderId)return n.orderId;try{const r=new URL(n.url,window.location.origin),t=r.searchParams.get("orderId")||r.searchParams.get("order_id");if(t)return t;if(r.hash&&r.hash.length>1){const e=new URLSearchParams(r.hash.replace(/^#/,"")),a=e.get("orderId")||e.get("order_id");if(a)return a}}catch{}return null}function g(){return typeof f().Razorpay=="function"?Promise.resolve():u||(u=new Promise((n,r)=>{const t=document.querySelector('script[data-aikaara-razorpay="1"]');if(t){t.addEventListener("load",()=>n()),t.addEventListener("error",()=>r(new Error("checkout.js failed to load")));return}const e=document.createElement("script");e.src=y,e.async=!0,e.dataset.aikaaraRazorpay="1",e.onload=()=>n(),e.onerror=()=>{u=null,r(new Error("checkout.js failed to load"))},document.head.appendChild(e)}),u)}function w(n,r,t,e){if(!n)return Promise.resolve([]);const a=String(t||"GET").toUpperCase()==="POST"?"POST":"GET",i=n.includes("{orderId}")?n.replace("{orderId}",encodeURIComponent(r)):n+(n.includes("?")?"&":"?")+"orderId="+encodeURIComponent(r),o=f().__aikaara_runtime__??{};return(typeof o.getSessionToken=="function"?o.getSessionToken():typeof o.getChatJwt=="function"?o.getChatJwt():Promise.resolve(null)).then(d=>{const s={Accept:"application/json",...e??{}};d&&(s.Authorization=`Bearer ${d}`);const l={method:a,headers:s,credentials:"omit"};return a==="POST"&&(s["Content-Type"]="application/json",l.body=JSON.stringify({orderId:r})),fetch(i,l)}).then(d=>{if(!d.ok)throw new Error(`preferred-banks ${d.status}`);return d.json()}).then(d=>{const s=d,l=s?.data&&typeof s.data=="object"&&!Array.isArray(s.data)?s.data:null;return(Array.isArray(d)?d:Array.isArray(s?.banks)?s.banks:Array.isArray(s?.data)?s.data:Array.isArray(l?.preferredPaymentBank)?l.preferredPaymentBank:Array.isArray(l?.banks)?l.banks:[]).map(p=>{if(typeof p=="string")return p;if(p&&typeof p=="object"){const m=p;return m.code||m.bankCode||m.bank_code||null}return null}).filter(p=>!!p)})}function _(n,r){if(!n)return;let t=document.querySelector("aikaara-link-modal");t||(t=document.createElement("aikaara-link-modal"),document.body.appendChild(t)),typeof t.show=="function"?t.show(n,r):window.open(n,"_blank","noopener,noreferrer")}function x(){typeof customElements>"u"||customElements.get("aikaara-template-payment-link")||customElements.define("aikaara-template-payment-link",h)}exports.AikaaraPaymentLink=h;exports.registerAikaaraPaymentLink=x;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
const h = "https://checkout.razorpay.com/v1/checkout.js";
|
|
2
|
-
let u = null;
|
|
3
|
-
function f() {
|
|
4
|
-
return window;
|
|
5
|
-
}
|
|
6
|
-
class y 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(r, t) {
|
|
17
|
-
this.payloadData = Array.isArray(r) ? r : [], this.message = t ?? "", this.render();
|
|
18
|
-
}
|
|
19
|
-
render() {
|
|
20
|
-
const r = this.payloadData.filter(
|
|
21
|
-
(e) => !!e && typeof e == "object" && e.type === "link" && typeof e.url == "string"
|
|
22
|
-
), t = r.map((e, a) => {
|
|
23
|
-
const i = e.name || "Open link", o = !!this.paidIdx[a];
|
|
24
|
-
return `<button class="link${o ? " paid" : ""}" data-i="${a}" type="button"${o ? " disabled" : ""}><span class="lbl">${k(o ? "Paid" : i)}</span>` + (o ? '<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">${t}</div>`, this.shadow.querySelectorAll(".link").forEach((e) => {
|
|
27
|
-
e.addEventListener("click", () => {
|
|
28
|
-
if (e.disabled) return;
|
|
29
|
-
const a = Number(e.dataset.i || 0), i = r[a];
|
|
30
|
-
i && this.handleClick(a, i);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
handleClick(r, t) {
|
|
35
|
-
const e = b(t), a = f().__aikaara_descriptor__?.razorpay;
|
|
36
|
-
if (!e || !a?.keyId) {
|
|
37
|
-
x(t.url, t.name || "Pay"), this.dispatchEvent(
|
|
38
|
-
new CustomEvent("template-action", {
|
|
39
|
-
detail: {
|
|
40
|
-
text: t.name || "link-click",
|
|
41
|
-
attributes: {
|
|
42
|
-
action: { type: "link", url: t.url, orderId: e || t.orderId, openedIn: "modal" }
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
bubbles: !0,
|
|
46
|
-
composed: !0
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
w(a.preferredBanksUrl, e, a.preferredBanksMethod, a.preferredBanksHeaders).catch((i) => (console.warn("[payment_link] preferred-banks fetch failed; continuing with default UI", i), [])).then((i) => g().then(() => this.openRazorpay(r, e, a, i))).catch((i) => {
|
|
52
|
-
console.error("[payment_link] Razorpay launch failed", i);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
openRazorpay(r, t, e, a) {
|
|
56
|
-
const i = f(), o = i.__aikaara_runtime__?.identity ?? {}, c = {
|
|
57
|
-
key: e.keyId,
|
|
58
|
-
order_id: t,
|
|
59
|
-
name: e.name || i.__aikaara_descriptor__?.title || "Payment",
|
|
60
|
-
prefill: {},
|
|
61
|
-
handler: () => {
|
|
62
|
-
this.paidIdx[r] = !0, this.render();
|
|
63
|
-
},
|
|
64
|
-
modal: {
|
|
65
|
-
// No auto-hide on dismiss: user can re-click Pay Now. Per spec,
|
|
66
|
-
// button only locks on confirmed success.
|
|
67
|
-
ondismiss: () => {
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
typeof o.mobile == "string" ? c.prefill.contact = o.mobile : typeof o.phone == "string" && (c.prefill.contact = o.phone), typeof o.email == "string" && (c.prefill.email = o.email), typeof o.name == "string" ? c.prefill.name = o.name : typeof o.userName == "string" && (c.prefill.name = o.userName), Array.isArray(a) && a.length && (c.config = {
|
|
72
|
-
display: {
|
|
73
|
-
blocks: {
|
|
74
|
-
utib: {
|
|
75
|
-
name: "Pay Using Preferred Netbanking",
|
|
76
|
-
instruments: [{ method: "netbanking", banks: a }]
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
sequence: ["block.utib", "netbanking", "card", "upi"],
|
|
80
|
-
preferences: { show_default_blocks: !0 }
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const d = i.Razorpay;
|
|
84
|
-
if (typeof d != "function")
|
|
85
|
-
throw new Error("Razorpay Checkout script not available");
|
|
86
|
-
const s = new d(c);
|
|
87
|
-
s.on("payment.failed", (l) => {
|
|
88
|
-
console.warn("[payment_link] payment.failed", l?.error);
|
|
89
|
-
}), s.open();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function k(n) {
|
|
93
|
-
return String(n ?? "").replace(/[&<>]/g, (r) => r === "&" ? "&" : r === "<" ? "<" : ">");
|
|
94
|
-
}
|
|
95
|
-
function b(n) {
|
|
96
|
-
if (typeof n.orderId == "string" && n.orderId) return n.orderId;
|
|
97
|
-
try {
|
|
98
|
-
const r = new URL(n.url, window.location.origin), t = r.searchParams.get("orderId") || r.searchParams.get("order_id");
|
|
99
|
-
if (t) return t;
|
|
100
|
-
if (r.hash && r.hash.length > 1) {
|
|
101
|
-
const e = new URLSearchParams(r.hash.replace(/^#/, "")), a = e.get("orderId") || e.get("order_id");
|
|
102
|
-
if (a) return a;
|
|
103
|
-
}
|
|
104
|
-
} catch {
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
function g() {
|
|
109
|
-
return typeof f().Razorpay == "function" ? Promise.resolve() : u || (u = new Promise((n, r) => {
|
|
110
|
-
const t = document.querySelector('script[data-aikaara-razorpay="1"]');
|
|
111
|
-
if (t) {
|
|
112
|
-
t.addEventListener("load", () => n()), t.addEventListener("error", () => r(new Error("checkout.js failed to load")));
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const e = document.createElement("script");
|
|
116
|
-
e.src = h, e.async = !0, e.dataset.aikaaraRazorpay = "1", e.onload = () => n(), e.onerror = () => {
|
|
117
|
-
u = null, r(new Error("checkout.js failed to load"));
|
|
118
|
-
}, document.head.appendChild(e);
|
|
119
|
-
}), u);
|
|
120
|
-
}
|
|
121
|
-
function w(n, r, t, e) {
|
|
122
|
-
if (!n) return Promise.resolve([]);
|
|
123
|
-
const a = String(t || "GET").toUpperCase() === "POST" ? "POST" : "GET", i = n.includes("{orderId}") ? n.replace("{orderId}", encodeURIComponent(r)) : n + (n.includes("?") ? "&" : "?") + "orderId=" + encodeURIComponent(r), o = f().__aikaara_runtime__ ?? {};
|
|
124
|
-
return (typeof o.getSessionToken == "function" ? o.getSessionToken() : typeof o.getChatJwt == "function" ? o.getChatJwt() : Promise.resolve(null)).then((d) => {
|
|
125
|
-
const s = { Accept: "application/json", ...e ?? {} };
|
|
126
|
-
d && (s.Authorization = `Bearer ${d}`);
|
|
127
|
-
const l = { method: a, headers: s, credentials: "omit" };
|
|
128
|
-
return a === "POST" && (s["Content-Type"] = "application/json", l.body = JSON.stringify({ orderId: r })), fetch(i, l);
|
|
129
|
-
}).then((d) => {
|
|
130
|
-
if (!d.ok) throw new Error(`preferred-banks ${d.status}`);
|
|
131
|
-
return d.json();
|
|
132
|
-
}).then((d) => {
|
|
133
|
-
const s = d, l = s?.data && typeof s.data == "object" && !Array.isArray(s.data) ? s.data : null;
|
|
134
|
-
return (Array.isArray(d) ? d : Array.isArray(s?.banks) ? s.banks : Array.isArray(s?.data) ? s.data : Array.isArray(l?.preferredPaymentBank) ? l.preferredPaymentBank : Array.isArray(l?.banks) ? l.banks : []).map((p) => {
|
|
135
|
-
if (typeof p == "string") return p;
|
|
136
|
-
if (p && typeof p == "object") {
|
|
137
|
-
const m = p;
|
|
138
|
-
return m.code || m.bankCode || m.bank_code || null;
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
}).filter((p) => !!p);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
function x(n, r) {
|
|
145
|
-
if (!n) return;
|
|
146
|
-
let t = document.querySelector("aikaara-link-modal");
|
|
147
|
-
t || (t = document.createElement("aikaara-link-modal"), document.body.appendChild(t)), typeof t.show == "function" ? t.show(n, r) : window.open(n, "_blank", "noopener,noreferrer");
|
|
148
|
-
}
|
|
149
|
-
function v() {
|
|
150
|
-
typeof customElements > "u" || customElements.get("aikaara-template-payment-link") || customElements.define("aikaara-template-payment-link", y);
|
|
151
|
-
}
|
|
152
|
-
export {
|
|
153
|
-
y as AikaaraPaymentLink,
|
|
154
|
-
v as registerAikaaraPaymentLink
|
|
155
|
-
};
|