choco-one-click-payment 1.1.38 → 1.1.39
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/index.esm.js +7 -5
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3079,7 +3079,7 @@ function hn(e) {
|
|
|
3079
3079
|
}
|
|
3080
3080
|
function fn(e) {
|
|
3081
3081
|
var k, _, b, S, T;
|
|
3082
|
-
if (!lt(e)) return;
|
|
3082
|
+
if (e._destroyed || !lt(e)) return;
|
|
3083
3083
|
e.container.style.setProperty("--choco-widget-accent-color", e.config.color), e.container.classList.remove("choco-one-click-widget--visible");
|
|
3084
3084
|
const t = e.getAvailablePaymentMethods(), o = (k = e.checkoutContext) == null ? void 0 : k.data, i = e.config.currency || "KZT", s = (S = (b = (_ = o == null ? void 0 : o.balance) == null ? void 0 : _.data) == null ? void 0 : b.money) == null ? void 0 : S[i], u = s > 0 ? V(s, e.config.locale, e.config.currency) : null, a = (T = o == null ? void 0 : o.cashback) == null ? void 0 : T.data, l = (a == null ? void 0 : a.cashbackAmount) > 0 ? V(a.cashbackAmount, e.config.locale, e.config.currency) : null, f = e._getPayableAmount(), C = f < e.config.amount;
|
|
3085
3085
|
e.container.innerHTML = cn({
|
|
@@ -3114,7 +3114,7 @@ function fn(e) {
|
|
|
3114
3114
|
}), requestAnimationFrame(() => {
|
|
3115
3115
|
requestAnimationFrame(() => {
|
|
3116
3116
|
var I;
|
|
3117
|
-
(I = e.container) == null || I.classList.add("choco-one-click-widget--visible");
|
|
3117
|
+
e._destroyed || (I = e.container) == null || I.classList.add("choco-one-click-widget--visible");
|
|
3118
3118
|
});
|
|
3119
3119
|
});
|
|
3120
3120
|
}
|
|
@@ -3885,7 +3885,7 @@ class ie {
|
|
|
3885
3885
|
}
|
|
3886
3886
|
// ─── Конструктор ──────────────────────────────────────────────────────────────
|
|
3887
3887
|
constructor(t) {
|
|
3888
|
-
this.config = jt(t), this.accessToken = null, this.deviceId = ot(), this.apiUrl = vt(this.config.environment), this.translations = bt, this.checkoutContext = null, this.centrifuge = null, this.selectedPaymentMethod = null, this.selectedCoupon = null, this.useCoupon = !1, this.container = null, this.isOpen = !1, this.isPaymentSheetOpen = !1, this.isPaymentSheetEditMode = !1, this.loading = !1, this.disabled = !1, this.paymentMethodDisabled = !1, this.useBalance = !1, this.useBonuses = !1, this.addCardActionUrl = null, this.isAddCardViewOpen = !1, this.waitingForNewCardAction = !1, this.newCardActionRequiredTimeoutId = null, this._googlePayScriptPromise = null, this._googlePayButtonRenderVersion = 0, this._orderStatusPollingId = null, this._orderStatusResolved = !1, this._pendingDeleteMethod = null, this._pendingSuccessPayload = null, this._lifecycleListenersAttached = !1, this._boundAddCardMessage = null, this._boundKeyDown = (o) => kn(this, o), this._boundVisibilityChange = () => this._onVisibilityChange(), this._boundWindowFocus = () => this._onWindowFocus(), this._boundPageShow = () => this._onPageShow();
|
|
3888
|
+
this.config = jt(t), this.accessToken = null, this.deviceId = ot(), this.apiUrl = vt(this.config.environment), this.translations = bt, this.checkoutContext = null, this.centrifuge = null, this.selectedPaymentMethod = null, this.selectedCoupon = null, this.useCoupon = !1, this.container = null, this.isOpen = !1, this.isPaymentSheetOpen = !1, this.isPaymentSheetEditMode = !1, this.loading = !1, this.disabled = !1, this.paymentMethodDisabled = !1, this.useBalance = !1, this.useBonuses = !1, this.addCardActionUrl = null, this.isAddCardViewOpen = !1, this.waitingForNewCardAction = !1, this.newCardActionRequiredTimeoutId = null, this._googlePayScriptPromise = null, this._googlePayButtonRenderVersion = 0, this._orderStatusPollingId = null, this._orderStatusResolved = !1, this._pendingDeleteMethod = null, this._pendingSuccessPayload = null, this._lifecycleListenersAttached = !1, this._destroyed = !1, this._boundAddCardMessage = null, this._boundKeyDown = (o) => kn(this, o), this._boundVisibilityChange = () => this._onVisibilityChange(), this._boundWindowFocus = () => this._onWindowFocus(), this._boundPageShow = () => this._onPageShow();
|
|
3889
3889
|
}
|
|
3890
3890
|
// ─── Локализация ──────────────────────────────────────────────────────────────
|
|
3891
3891
|
t(t, o = {}) {
|
|
@@ -4101,14 +4101,15 @@ class ie {
|
|
|
4101
4101
|
return this.config.onError({ attributes: { message: this.t("errorMissingTrackClient") } }), !1;
|
|
4102
4102
|
if (this.accessToken = this._getAuthStorageValue("webPayToken"), !this.config.trackId && !this.accessToken)
|
|
4103
4103
|
return this.paymentMethodDisabled = !0, this._render(), !0;
|
|
4104
|
-
this.accessToken
|
|
4104
|
+
if (!this.accessToken && (await this._obtainTokenByRefreshOrTrackId(), this._destroyed))
|
|
4105
|
+
return !1;
|
|
4105
4106
|
try {
|
|
4106
4107
|
await this._fetchCheckoutContextWithRetry();
|
|
4107
4108
|
} catch (s) {
|
|
4108
4109
|
const u = s;
|
|
4109
4110
|
return this.config.onError({ attributes: { message: u.message } }), !1;
|
|
4110
4111
|
}
|
|
4111
|
-
await this._fetchCoupons();
|
|
4112
|
+
if (this._destroyed || (await this._fetchCoupons(), this._destroyed)) return !1;
|
|
4112
4113
|
const i = Ge(
|
|
4113
4114
|
(o = (t = this.checkoutContext) == null ? void 0 : t.data) == null ? void 0 : o.socket_connections,
|
|
4114
4115
|
(s) => nt(this, s)
|
|
@@ -4125,6 +4126,7 @@ class ie {
|
|
|
4125
4126
|
this.config.onCancel();
|
|
4126
4127
|
}
|
|
4127
4128
|
destroy() {
|
|
4129
|
+
this._destroyed = !0;
|
|
4128
4130
|
const t = document.getElementById("choco-one-click-widget");
|
|
4129
4131
|
t && (t.style.display = "none"), this._clearNewCardActionTimeout(), te(this), this._pendingSuccessPayload = null, this._detachLifecycleListeners(), this.isAddCardViewOpen && ae(this), this.centrifuge && (this.centrifuge.disconnect(), this.centrifuge = null), document.removeEventListener("keydown", this._boundKeyDown), this.container && (this.container.classList.remove("choco-one-click-widget--visible"), setTimeout(() => {
|
|
4130
4132
|
var o;
|
package/dist/index.js
CHANGED
|
@@ -283,7 +283,7 @@
|
|
|
283
283
|
<div class="choco-widget-bottom-bar-prerender">
|
|
284
284
|
<div class="choco-widget-payment-loading"></div>
|
|
285
285
|
</div>
|
|
286
|
-
`}function tn(e,t,o,i={}){return nt(e,t,o,i)}function nn(e){return Qe(e)}function rn(e){if(typeof document>"u")return{mountTarget:null,isEmbedded:!1};const t=e.config.containerSelector;if(t){const o=document.querySelector(t);if(o instanceof HTMLElement)return{mountTarget:o,isEmbedded:!0}}return{mountTarget:document.body,isEmbedded:!1}}function rt(e){if(typeof document>"u")return!1;e.container||(e.container=document.createElement("div"),e.container.id="choco-one-click-widget",e.container.className="choco-one-click-widget");const{mountTarget:t,isEmbedded:o}=rn(e);return t?(e.container.parentElement!==t&&t.appendChild(e.container),e.container.classList.toggle("choco-one-click-widget--embedded",o),!0):!1}function on(e){rt(e)&&(e.container.style.setProperty("--choco-widget-accent-color",e.config.color),e.container.innerHTML=en())}function sn(e){var k,_,b,S,T;if(
|
|
286
|
+
`}function tn(e,t,o,i={}){return nt(e,t,o,i)}function nn(e){return Qe(e)}function rn(e){if(typeof document>"u")return{mountTarget:null,isEmbedded:!1};const t=e.config.containerSelector;if(t){const o=document.querySelector(t);if(o instanceof HTMLElement)return{mountTarget:o,isEmbedded:!0}}return{mountTarget:document.body,isEmbedded:!1}}function rt(e){if(typeof document>"u")return!1;e.container||(e.container=document.createElement("div"),e.container.id="choco-one-click-widget",e.container.className="choco-one-click-widget");const{mountTarget:t,isEmbedded:o}=rn(e);return t?(e.container.parentElement!==t&&t.appendChild(e.container),e.container.classList.toggle("choco-one-click-widget--embedded",o),!0):!1}function on(e){rt(e)&&(e.container.style.setProperty("--choco-widget-accent-color",e.config.color),e.container.innerHTML=en())}function sn(e){var k,_,b,S,T;if(e._destroyed||!rt(e))return;e.container.style.setProperty("--choco-widget-accent-color",e.config.color),e.container.classList.remove("choco-one-click-widget--visible");const t=e.getAvailablePaymentMethods(),o=(k=e.checkoutContext)==null?void 0:k.data,i=e.config.currency||"KZT",s=(S=(b=(_=o==null?void 0:o.balance)==null?void 0:_.data)==null?void 0:b.money)==null?void 0:S[i],u=s>0?V(s,e.config.locale,e.config.currency):null,a=(T=o==null?void 0:o.cashback)==null?void 0:T.data,l=(a==null?void 0:a.cashbackAmount)>0?V(a.cashbackAmount,e.config.locale,e.config.currency):null,f=e._getPayableAmount(),C=f<e.config.amount;e.container.innerHTML=$t({amountFormatted:V(f,e.config.locale,e.config.currency),originalAmountFormatted:V(e.config.amount,e.config.locale,e.config.currency),showOriginalAmount:C,paymentMethod:e.selectedPaymentMethod,methods:t,selectedMethod:e.selectedPaymentMethod,balanceFormatted:u,useBalance:e.useBalance,bonuses:e.config.bonuses,useBonuses:e.useBonuses,coupon:e.selectedCoupon,useCoupon:e.useCoupon,couponDisabled:e._isCouponDisabled(),cashbackFormatted:l,disabled:e.disabled,paymentMethodDisabled:e.paymentMethodDisabled,loading:e.loading,t:(I,w)=>e.t(I,w),currency:i}),e._attachEventListeners(),e.isOpen=!0,e._emitUserEvent("one_click_pay_cta_rendered",{terminal_id:e.config.terminalId,project_id:e.config.projectId??e.config.clientId}),e._emitUserEvent("one_click_pay_method_resolved",{payment_method:e._getPaymentMethodForUserEvent()}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{var I;e._destroyed||(I=e.container)==null||I.classList.add("choco-one-click-widget--visible")})})}function le(e){var i;const t=(i=e.container)==null?void 0:i.querySelector(".choco-widget-payment-methods");if(!t)return;const o=e.getAvailablePaymentMethods();t.innerHTML=tn(o,e.selectedPaymentMethod,s=>e.t(s),{editMode:e.isPaymentSheetEditMode}),t.querySelectorAll("[data-action='delete-card']").forEach(s=>{s.addEventListener("click",u=>{u.stopPropagation();const a=JSON.parse(s.getAttribute("data-method")||"{}");ln(e,a)})}),t.querySelectorAll("[data-action='select-method']").forEach(s=>{s.addEventListener("click",u=>{const a=JSON.parse(u.currentTarget.getAttribute("data-method")||"{}");ct(e,a)})})}function ot(e){var s,u,a;const t=(s=e.container)==null?void 0:s.querySelector(".choco-widget-payment-method"),o=(u=e.container)==null?void 0:u.querySelector(".choco-widget-method-name"),i=(a=e.container)==null?void 0:a.querySelector(".choco-widget-method-icon-wrapper");t&&e.selectedPaymentMethod&&(t.className=`choco-widget-payment-method ${e.selectedPaymentMethod.type}`),o&&e.selectedPaymentMethod&&(o.className=`choco-widget-method-name ${e.selectedPaymentMethod.type}`,o.textContent=e.selectedPaymentMethod.label),i&&e.selectedPaymentMethod&&(i.className=`choco-widget-method-icon-wrapper ${e.selectedPaymentMethod.type}`,i.innerHTML=nn(e.selectedPaymentMethod)),st(e)}function Se(e){var k,_,b,S,T;const t=(k=e.container)==null?void 0:k.querySelector(".choco-widget-pay-button"),o=(_=e.container)==null?void 0:_.querySelector(".choco-widget-google-pay-amount"),i=(b=e.container)==null?void 0:b.querySelector(".choco-widget-google-pay-amount-label");let s=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-amount-value"),u=(T=e.container)==null?void 0:T.querySelector(".choco-widget-google-pay-amount-value-number");const a=e._getPayableAmount(),l=V(a,e.config.locale,e.config.currency),f=a<e.config.amount,C=V(e.config.amount,e.config.locale,e.config.currency);if(t&&(t.textContent=`${e.t("pay")} ${l}`,t.setAttribute("aria-label",`${e.t("pay")} ${l}`)),i&&(i.textContent=`${e.t("total")} ${l}`),!f){s==null||s.remove();return}!s&&o&&(s=document.createElement("div"),s.className="choco-widget-google-pay-amount-value",s.innerHTML=`${e.t("instead")} <span class="choco-widget-google-pay-amount-value-number"></span>`,o.appendChild(s),u=s.querySelector(".choco-widget-google-pay-amount-value-number")),u?u.textContent=C:s&&(s.textContent=`${e.t("instead")} ${C}`)}function st(e){var f,C,k,_,b,S,T,I,w,B;const t=((f=e.selectedPaymentMethod)==null?void 0:f.type)==="google_pay",o=((C=e.selectedPaymentMethod)==null?void 0:C.type)==="apple_pay",i=t||o,s=(k=e.container)==null?void 0:k.querySelector(".choco-widget-pay-button"),u=(_=e.container)==null?void 0:_.querySelector(".choco-widget-google-pay-amount"),a=(b=e.container)==null?void 0:b.querySelector(".choco-widget-google-pay-row"),l=(S=e.container)==null?void 0:S.querySelector(".choco-widget-apple-pay-row");if(s==null||s.classList.toggle("choco-widget-pay-button--hidden",i),u==null||u.classList.toggle("choco-widget-google-pay-amount--hidden",!i),a==null||a.classList.toggle("choco-widget-google-pay-row--hidden",!t),l==null||l.classList.toggle("choco-widget-apple-pay-row--hidden",!o),t){an(e);const v=(T=e.container)==null?void 0:T.querySelector('[data-action="apple-pay-button-slot"]');v&&(v.innerHTML="")}else if(o){e._googlePayButtonRenderVersion+=1;const v=(I=e.container)==null?void 0:I.querySelector('[data-action="google-pay-button-slot"]');v&&(v.innerHTML=""),cn(e)}else{e._googlePayButtonRenderVersion+=1;const v=(w=e.container)==null?void 0:w.querySelector('[data-action="google-pay-button-slot"]'),L=(B=e.container)==null?void 0:B.querySelector('[data-action="apple-pay-button-slot"]');v&&(v.innerHTML=""),L&&(L.innerHTML="")}Se(e),G(e)}async function an(e){var a,l,f,C,k;const t=(a=e.container)==null?void 0:a.querySelector('[data-action="google-pay-button-slot"]');if(!t||(t.innerHTML="",((l=e.selectedPaymentMethod)==null?void 0:l.type)!=="google_pay"))return;const o=++e._googlePayButtonRenderVersion;try{await e._loadGooglePaySdk()}catch{e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}if(o!==e._googlePayButtonRenderVersion)return;if(!((k=(C=(f=window.google)==null?void 0:f.payments)==null?void 0:C.api)!=null&&k.PaymentsClient)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const i=e.config.environment==="production",u=new window.google.payments.api.PaymentsClient({environment:i?"PRODUCTION":"TEST"}).createButton({onClick:()=>e.handlePayment(),buttonType:"pay",buttonColor:"black",buttonLocale:e.config.locale||"ru",buttonSizeMode:"fill"});u.classList.add("choco-widget-google-pay-button"),u.style.setProperty("width","100%","important"),u.style.setProperty("height","52px","important"),u.style.setProperty("min-height","52px","important"),u.style.setProperty("border-radius","12px","important"),u.style.setProperty("font-size","16px","important"),u.style.setProperty("font-weight","bold","important"),u.querySelectorAll("*").forEach(_=>{_.style.setProperty("border-radius","12px","important"),_.style.setProperty("font-weight","bold","important"),_.style.setProperty("font-size","16px","important")}),t.appendChild(u),G(e)}function cn(e){var u,a;const t=(u=e.container)==null?void 0:u.querySelector('[data-action="apple-pay-button-slot"]');if(!t||(t.innerHTML="",((a=e.selectedPaymentMethod)==null?void 0:a.type)!=="apple_pay"))return;const o=document.createElement("div");o.className="choco-widget-apple-pay-button-wrapper";const i=document.createElement("button");i.type="button",i.className="choco-widget-apple-pay-button choco-widget-apple-pay-button--native",i.setAttribute("aria-label","Оплатить с Apple Pay"),i.style.setProperty("width","100%","important"),i.style.setProperty("height","52px","important"),i.style.setProperty("min-height","52px","important"),i.style.setProperty("border-radius","12px","important"),i.style.setProperty("-webkit-appearance","-apple-pay-button"),i.style.setProperty("-apple-pay-button-type","buy"),i.style.setProperty("-apple-pay-button-style","black"),i.addEventListener("click",()=>e.handlePayment());const s=document.createElement("div");s.className="choco-widget-apple-pay-button-overlay",s.setAttribute("aria-hidden","true"),s.innerHTML=`
|
|
287
287
|
<span class="choco-widget-apple-pay-button-text">Оплатить с</span>
|
|
288
288
|
<span class="choco-widget-apple-pay-button-icon">
|
|
289
289
|
<svg width="52" height="24" viewBox="0 0 52 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -297,4 +297,4 @@
|
|
|
297
297
|
</defs>
|
|
298
298
|
</svg>
|
|
299
299
|
</span>
|
|
300
|
-
`,o.appendChild(i),o.appendChild(s),t.appendChild(o),G(e)}function it(e){var s;if(!e.selectedCoupon)return;const t=e._isCouponDisabled();t&&e.useCoupon&&(e.useCoupon=!1);const o=(s=e.container)==null?void 0:s.querySelector('[data-action="toggle-coupon"]');if(!o)return;o.classList.toggle("choco-widget-balance-toggle--disabled",t);const i=o.querySelector("input[type='checkbox']");i&&(i.disabled=t,t&&(i.checked=!1))}function ee(e){e.loading=!0,G(e)}function j(e){var _,b,S,T,I,w,B,v;e.loading=!1;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(b=e.container)==null?void 0:b.querySelector(".choco-widget-pay-button"),i=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-button-slot button"),s=(T=e.container)==null?void 0:T.querySelector(".choco-widget-apple-pay-button-slot button"),u=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-amount"),a=(w=e.container)==null?void 0:w.querySelector(".choco-widget-google-pay-row"),l=(B=e.container)==null?void 0:B.querySelector(".choco-widget-apple-pay-row"),f=(v=e.container)==null?void 0:v.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),k=e.paymentMethodDisabled||C;t&&(t.disabled=k),o&&(o.disabled=C,o.classList.remove("choco-widget-pay-button--loading")),i&&(i.disabled=C),s&&(s.disabled=C),u==null||u.classList.toggle("choco-widget-wallet-blocked",C),u==null||u.setAttribute("aria-disabled",String(C)),a==null||a.classList.toggle("choco-widget-wallet-blocked",C),a==null||a.setAttribute("aria-disabled",String(C)),l==null||l.classList.toggle("choco-widget-wallet-blocked",C),l==null||l.setAttribute("aria-disabled",String(C)),f==null||f.classList.remove("disabled")}function G(e){var _,b,S,T,I,w,B,v;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(b=e.container)==null?void 0:b.querySelector(".choco-widget-pay-button"),i=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-button-slot button"),s=(T=e.container)==null?void 0:T.querySelector(".choco-widget-apple-pay-button-slot button"),u=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-amount"),a=(w=e.container)==null?void 0:w.querySelector(".choco-widget-google-pay-row"),l=(B=e.container)==null?void 0:B.querySelector(".choco-widget-apple-pay-row"),f=(v=e.container)==null?void 0:v.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),k=e.paymentMethodDisabled||C;f==null||f.classList.toggle("disabled",C),t&&(t.disabled=k),o&&(o.disabled=C,o.classList.toggle("choco-widget-pay-button--loading",e.loading)),i&&(i.disabled=C),s&&(s.disabled=C),u==null||u.classList.toggle("choco-widget-wallet-blocked",C),u==null||u.setAttribute("aria-disabled",String(C)),a==null||a.classList.toggle("choco-widget-wallet-blocked",C),a==null||a.setAttribute("aria-disabled",String(C)),l==null||l.classList.toggle("choco-widget-wallet-blocked",C),l==null||l.setAttribute("aria-disabled",String(C))}function at(e){var o;if(e._isInteractionBlocked())return;const t=(o=e.container)==null?void 0:o.querySelector('[data-sheet="payment"]');t&&(t.classList.add("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!0,de(e))}function Z(e){var o;const t=(o=e.container)==null?void 0:o.querySelector('[data-sheet="payment"]');if(t){Pe(e);const i=t.querySelector(".choco-widget-sheet-content");i&&(i.style.transform="",i.classList.remove("choco-widget-sheet-content--dragging")),t.classList.remove("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!1,e.isPaymentSheetEditMode&&(e.isPaymentSheetEditMode=!1,le(e),de(e))}}function de(e){var f;const t=(f=e.container)==null?void 0:f.querySelector('[data-sheet="payment"]');if(!t)return;const o=t.querySelector(".choco-widget-sheet-title"),i=t.querySelector('[data-action="close-sheet"]'),s=t.querySelector('[data-action="edit-sheet"]'),u=t.querySelector('[data-action="previous-sheet"]'),l=e.getAvailablePaymentMethods().some(C=>C.type==="card");e.isPaymentSheetEditMode?(t.classList.add("choco-widget-payment-sheet--edit"),o&&(o.textContent=e.t("editCards")),i&&(i.style.display="none"),s&&(s.style.display="none"),u&&(u.style.display="")):(t.classList.remove("choco-widget-payment-sheet--edit"),t.classList.toggle("choco-widget-payment-sheet--no-cards",!l),o&&(o.textContent=e.t("paymentMethods")),i&&(i.style.display=""),s&&(s.style.display=l?"":"none"),u&&(u.style.display="none"))}function Me(e){if(!e.addCardActionUrl||!e.container)return;const t=e.container.querySelector('[data-sheet="add-card"]'),o=e.container.querySelector("#choco-widget-add-card-iframe");t&&o&&(o.src=e.addCardActionUrl,t.classList.add("choco-widget-payment-sheet--open"),t.style.display="flex",t.setAttribute("aria-hidden","false"),e.isAddCardViewOpen=!0,An(e))}function oe(e){var i,s;const t=(i=e.container)==null?void 0:i.querySelector('[data-sheet="add-card"]'),o=(s=e.container)==null?void 0:s.querySelector("#choco-widget-add-card-iframe");t&&(t.classList.remove("choco-widget-payment-sheet--open"),t.style.display="none",t.setAttribute("aria-hidden","true")),o&&(o.src="about:blank"),e.addCardActionUrl=null,e.isAddCardViewOpen=!1,un(e)}function An(e){e._boundAddCardMessage=t=>{var o;e.isAddCardViewOpen&&(o=t.data)!=null&&o.message&&t.origin==="https://rahmetapp.kz"&&ee(e)},window.addEventListener("message",e._boundAddCardMessage)}function un(e){e._boundAddCardMessage&&(window.removeEventListener("message",e._boundAddCardMessage),e._boundAddCardMessage=null)}function ln(e,t){var a;e._pendingDeleteMethod=t;const o=(a=e.container)==null?void 0:a.querySelector('[data-sheet="payment"]');if(!o)return;o.classList.add("choco-widget-payment-sheet--delete-confirm");const i=o.querySelector(".choco-widget-sheet-title"),s=o.querySelector('[data-action="edit-sheet"]'),u=o.querySelector('[data-action="previous-sheet"]');i&&(i.textContent=e.t("confirmDeleteCard")),s&&(s.style.display="none"),u&&(u.style.display="none")}function Pe(e){var o;e._pendingDeleteMethod=null,Ne(e,!1);const t=(o=e.container)==null?void 0:o.querySelector('[data-sheet="payment"]');t==null||t.classList.remove("choco-widget-payment-sheet--delete-confirm"),de(e)}function Ne(e,t){var u,a,l;const o=(u=e.container)==null?void 0:u.querySelector(".choco-widget-sheet-delete-confirm-actions"),i=(a=e.container)==null?void 0:a.querySelector('[data-action="confirm-delete-cancel"]'),s=(l=e.container)==null?void 0:l.querySelector('[data-action="confirm-delete-submit"]');o==null||o.classList.toggle("choco-widget-sheet-delete-confirm-actions--loading",t),i&&(i.disabled=t),s&&(s.disabled=t,s.classList.toggle("choco-widget-delete-confirm-btn--loading",t))}async function dn(e,t){var i,s;const o=t==null?void 0:t.cardId;if(!(!o||(t==null?void 0:t.type)!=="card"))try{await Nt(e.apiUrl,e._getApiConfig(),o),e.checkoutContext=await Le(e.apiUrl,e._getApiConfig()),((i=e.selectedPaymentMethod)==null?void 0:i.type)==="card"&&((s=e.selectedPaymentMethod)==null?void 0:s.cardId)===o&&(e.selectedPaymentMethod=_e(e.checkoutContext.data,e._getKaspiOptions()),e._emitPaymentMethodSelected(),ot(e)),le(e),e.config.onSuccess({message:e.t("cardDeleted")}),e.config.onCardDeleted&&e.config.onCardDeleted({cardId:o})}catch(u){e.config.onError({attributes:{message:(u==null?void 0:u.message)||e.t("paymentError")}})}}function ct(e,t){if(!e._isInteractionBlocked()){if(e.selectedPaymentMethod=t,e._emitPaymentMethodSelected(),t.type==="new_card"){e._emitUserEvent("one_click_pay_method_resolved",{payment_method:t.type}),Z(e),e.handlePayment();return}e._emitUserEvent("one_click_pay_method_resolved",{payment_method:e._getPaymentMethodForUserEvent()}),le(e),Z(e),ot(e)}}function At(e,t){var i;const o=t.type||((i=t.data)==null?void 0:i.type);if(!o){console.warn("Unknown event format:",t);return}switch(o){case"order.paid":e._orderStatusResolved=!0,te(e),lt(e,t);break;case"order.failed":e._orderStatusResolved=!0,te(e),dt(e,t);break;case"order.action_required":hn(e,t);break;default:console.warn("Unknown event type:",o)}}function te(e){e._orderStatusPollingId&&(clearInterval(e._orderStatusPollingId),e._orderStatusPollingId=null)}function se(e,t){te(e),e._orderStatusResolved=!1;const o=6e3,i=5;let s=0;const u=async()=>{if(!e._orderStatusResolved){if(s>=i){te(e),j(e),e.config.onError({attributes:{message:e.t("errorNoServerResponseRetry")}});return}s+=1;try{const{data:a}=await Xt(e.apiUrl,e._getApiConfig(),String(t)),l=a==null?void 0:a.status,f=(a==null?void 0:a.payload)||{};if(l==="success"){e._orderStatusResolved=!0,te(e),lt(e,{id:String(f.id||t),attributes:{amount:f.amount,paid_at:f.paid_at||""}});return}l==="fail"&&(e._orderStatusResolved=!0,te(e),dt(e,{id:String(f.id||t),attributes:{message:f.message||e.t("paymentError")}}))}catch(a){console.warn("[Polling] checkOrderStatus error:",a)}}};e._orderStatusPollingId=setInterval(u,o),u()}function De(){return typeof document>"u"?!1:document.hidden||document.visibilityState==="hidden"}function ut(e,t){j(e),e.config.onSuccess(t)}function Xe(e){if(!e._pendingSuccessPayload||De())return;const t=e._pendingSuccessPayload;e._pendingSuccessPayload=null,ut(e,t)}function lt(e,t){var s,u;e.isAddCardViewOpen&&oe(e);const o=t.attributes||((s=t.data)==null?void 0:s.attributes)||{},i={id:t.id||((u=t.data)==null?void 0:u.id),attributes:o};if(De()){e._pendingSuccessPayload=i;return}ut(e,i)}function dt(e,t){var i,s;e.isAddCardViewOpen&&oe(e),j(e);const o=t.attributes||((i=t.data)==null?void 0:i.attributes)||{};e.config.onError({id:t.id||((s=t.data)==null?void 0:s.id),attributes:o})}function hn(e,t){var u,a,l;const o=t.attributes||((u=t.data)==null?void 0:u.attributes)||{},i=o.action_link||o.action_url,s=o.action_url_type||o.action_type||"redirect";if(!i){console.error(e.t("errorActionUrlMissing")),e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,j(e),e.config.onError({attributes:{message:e.t("errorNoServerResponse")}}));return}if(e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout()),s==="inner"){e.addCardActionUrl=i,j(e),e._showAddCardView();return}if(((a=e.selectedPaymentMethod)==null?void 0:a.type)==="kaspi_pay"){const f=t.id||((l=t.data)==null?void 0:l.id);if(f&&!e._orderStatusResolved&&!e._orderStatusPollingId&&se(e,String(f)),typeof e.config.onKaspiLink=="function"){e.config.onKaspiLink({action_link:i,action_url:i,action_type:s,event:t});return}}window.location.href=i}async function fn(e){var o,i,s,u;if(!e.selectedPaymentMethod){e.config.onError({attributes:{message:e.t("errorPaymentMethodNotSelected")}});return}const{checkoutOptions:t}=e._getPaymentBreakdown();if(e._isBalanceFullyCoveringAmount()){ee(e);try{const a=await $e(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await ht(e);const l=(a==null?void 0:a.id)??((o=a==null?void 0:a.data)==null?void 0:o.id);return l&&se(e,String(l)),a}catch(a){throw j(e),e.config.onError({attributes:{message:e._resolveErrorMessage(a)}}),a}}if(e.selectedPaymentMethod.type==="new_card"){await gn(e,t);return}if(e.selectedPaymentMethod.type==="apple_pay"){await pn(e,t);return}if(e.selectedPaymentMethod.type==="google_pay"){await Cn(e,t);return}ee(e);try{const a=await $e(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await ht(e);const l=(a==null?void 0:a.id)??((i=a==null?void 0:a.data)==null?void 0:i.id);if(l&&se(e,String(l)),((s=e.selectedPaymentMethod)==null?void 0:s.type)==="kaspi_pay"){const f=(a==null?void 0:a.attributes)||((u=a==null?void 0:a.data)==null?void 0:u.attributes)||{},C=f.action_link||f.action_url,k=f.action_url_type||f.action_type||"redirect";if(C)return typeof e.config.onKaspiLink=="function"?(e.config.onKaspiLink({action_link:C,action_url:C,action_type:k,event:a}),a):(window.location.href=C,a)}return a}catch(a){throw j(e),e.config.onError({message:e._resolveErrorMessage(a)}),a}}async function ht(e){var t,o;if(!(((t=e.selectedPaymentMethod)==null?void 0:t.type)!=="card"||!((o=e.selectedPaymentMethod)!=null&&o.cardId)))try{await Dt(e.apiUrl,e._getApiConfig(),e.selectedPaymentMethod.cardId)}catch(i){console.warn("Failed to mark selected card as default:",i)}}async function gn(e,t){ee(e),e.waitingForNewCardAction=!0,e._setNewCardActionTimeout();try{await Ut(e.apiUrl,e._getApiConfig(),e.deviceId,t)}catch(o){e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout(),j(e),e.config.onError({attributes:{message:e._resolveErrorMessage(o)}}),console.error("New card payment error:",o)}}let ie=null;async function pn(e,t){const o=window.ApplePaySession;if(!o||!o.canMakePayments()){e.config.onError({attributes:{message:e.t("errorApplePayUnsupported")}});return}if(ie){try{ie.abort()}catch{}ie=null}const i={countryCode:e.config.currency==="GEL"?"GE":"KZ",currencyCode:e.config.currency,supportedNetworks:["visa","masterCard"],merchantCapabilities:["supports3DS"],total:{label:"Choco",amount:String(e._getPayableAmount()),type:"final"}},s=new o(3,i);ie=s,s.onvalidatemerchant=async u=>{var a,l;try{const f=await xt(e.apiUrl,e._getApiConfig(),u.validationURL),C=((l=(a=f==null?void 0:f.data)==null?void 0:a.attributes)==null?void 0:l.session)||f,k=JSON.parse(atob(C));s.completeMerchantValidation(k)}catch(f){console.error("Apple Pay session error:",f),s.abort(),e.config.onError({attributes:{message:e.t("errorApplePayInit")}})}},s.onpaymentauthorized=async u=>{var a;try{if(ee(e),typeof e.config.onBeforeCheckout=="function"){const C=await e.config.onBeforeCheckout();C&&typeof C=="object"&&Object.assign(e.config,C)}const l=await Ft(e.apiUrl,e._getApiConfig(),e.deviceId,u.payment,t);s.completePayment(o.STATUS_SUCCESS),ie=null;const f=(l==null?void 0:l.id)??((a=l==null?void 0:l.data)==null?void 0:a.id);f&&se(e,String(f))}catch(l){console.error("Apple Pay payment error:",l),s.completePayment(o.STATUS_FAILURE),j(e),e.config.onError({attributes:{message:e._resolveErrorMessage(l,"errorApplePayPayment")}})}},s.oncancel=()=>{ie=null,e.config.onCancel()},s.begin()}async function Cn(e,t){var w,B,v,L,O,F;const o=(w=e.checkoutContext)==null?void 0:w.data,i=((v=(B=o==null?void 0:o.payment_methods)==null?void 0:B.data)==null?void 0:v.attributes)||{},s=i.google_pay_settings||{};if(!(i.payment_method_google_pay==="enabled"||i.payment_method_google_pay===!0)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const a=s==null?void 0:s.gateway,l=s==null?void 0:s.merchant_id;if(!a||!l){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}const f=e.config.environment==="production",C=(s==null?void 0:s.merchant_name)||"Choco",k=s==null?void 0:s.google_merchant_id;if(f&&!k){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}if(e.config.isNativeAndroid){await yn(e,t,{gateway:a,gatewayMerchantId:l});return}const _=Number(e._getCheckoutAmount()).toFixed(2);try{await e._loadGooglePaySdk()}catch(N){console.error("Google Pay SDK load error:",N),e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const b=window.google;if(!(b!=null&&b.payments)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const S=[{type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:["VISA","MASTERCARD"],billingAddressRequired:!1},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:a,gatewayMerchantId:l}}}],T={apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:S,transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Итого",totalPrice:_,currencyCode:e.config.currency,countryCode:e.config.currency==="GEL"?"GE":"KZ"},merchantInfo:f?{merchantId:k,merchantName:C}:{merchantName:C}},I=new b.payments.api.PaymentsClient({environment:f?"PRODUCTION":"TEST"});try{const N=await I.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:S});if(!(N!=null&&N.result)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}ee(e);const q=await I.loadPaymentData(T),J=(O=(L=q==null?void 0:q.paymentMethodData)==null?void 0:L.tokenizationData)==null?void 0:O.token;if(!J)throw new Error(e.t("errorGooglePayPayment"));const x=JSON.parse(J),M=await et(e.apiUrl,e._getApiConfig(),e.deviceId,x,t),m=(M==null?void 0:M.id)??((F=M==null?void 0:M.data)==null?void 0:F.id);m&&se(e,String(m))}catch(N){j(e),N.statusCode==="CANCELED"?e.config.onCancel():(e.config.onError({attributes:{message:e._resolveErrorMessage(N,"errorGooglePayPayment")}}),console.error("Google Pay error:",N))}}async function yn(e,t,o){var i;if(!e.config.onPayWithGooglePay){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}ee(e);try{const s=await e.config.onPayWithGooglePay({amount:Number(e._getCheckoutAmount()),gateway:o.gateway,gatewayMerchantId:o.gatewayMerchantId}),u=JSON.parse(s),a=await et(e.apiUrl,e._getApiConfig(),e.deviceId,u,t),l=(a==null?void 0:a.id)??((i=a==null?void 0:a.data)==null?void 0:i.id);l&&se(e,String(l))}catch(s){j(e),s.statusCode==="CANCELED"?e.config.onCancel():(e.config.onError({attributes:{message:e._resolveErrorMessage(s,"errorGooglePayPayment")}}),console.error("Google Pay native error:",s))}}function mn(e){var a,l,f,C,k,_,b,S,T,I,w;const t=e.container;(a=t.querySelector('[data-action="pay"]'))==null||a.addEventListener("click",()=>e.handlePayment()),(l=t.querySelector('[data-action="change-method"]'))==null||l.addEventListener("click",()=>at(e)),t.querySelectorAll('[data-action="close"]').forEach(B=>B.addEventListener("click",()=>e.close())),(f=t.querySelector('[data-action="close-sheet"]'))==null||f.addEventListener("click",()=>{e._pendingDeleteMethod?Pe(e):Z(e)}),(C=t.querySelector('[data-action="edit-sheet"]'))==null||C.addEventListener("click",()=>{e.isPaymentSheetEditMode=!0,le(e),de(e)}),(k=t.querySelector('[data-action="previous-sheet"]'))==null||k.addEventListener("click",()=>{e.isPaymentSheetEditMode=!1,le(e),de(e)}),(_=t.querySelector('[data-action="close-add-card"]'))==null||_.addEventListener("click",()=>oe(e)),(b=t.querySelector('[data-action="confirm-delete-cancel"]'))==null||b.addEventListener("click",()=>Pe(e)),(S=t.querySelector('[data-action="confirm-delete-submit"]'))==null||S.addEventListener("click",()=>{if(e._pendingDeleteMethod){const B=e._pendingDeleteMethod;Ne(e,!0),dn(e,B).then(()=>Z(e)).finally(()=>Ne(e,!1))}}),t.querySelectorAll(".choco-widget-method-item").forEach(B=>{B.addEventListener("click",v=>{const L=JSON.parse(v.currentTarget.getAttribute("data-method")||"{}");ct(e,L)})});const o=t.querySelector('[data-sheet="payment"]');o&&(o.addEventListener("click",B=>{B.target===o&&Z(e)}),En(e,o));const i=t.querySelector('[data-action="toggle-balance"]');i&&((T=i.querySelector("input[type='checkbox']"))==null||T.addEventListener("change",B=>{e.useBalance=B.target.checked,it(e),e._updatePayButtonAmount()}));const s=t.querySelector('[data-action="toggle-bonuses"]');s&&((I=s.querySelector("input[type='checkbox']"))==null||I.addEventListener("change",B=>{e.useBonuses=B.target.checked,e.config.onAppliedBonus(e.useBonuses),it(e),e._updatePayButtonAmount()}));const u=t.querySelector('[data-action="toggle-coupon"]');u&&((w=u.querySelector("input[type='checkbox']"))==null||w.addEventListener("change",B=>{e.useCoupon=B.target.checked,e._updatePayButtonAmount()})),document.removeEventListener("keydown",e._boundKeyDown),document.addEventListener("keydown",e._boundKeyDown),st(e)}function bn(e,t){var o,i;e.isOpen&&(t.key==="Escape"&&(t.preventDefault(),e._pendingDeleteMethod?Pe(e):e.isAddCardViewOpen?oe(e):e.isPaymentSheetOpen?Z(e):e.close()),t.key==="Enter"&&((i=(o=t.target)==null?void 0:o.dataset)==null?void 0:i.action)==="pay"&&(t.preventDefault(),e.handlePayment()))}function En(e,t){const o=t.querySelector('[data-action="sheet-drag-handle"]'),i=t.querySelector(".choco-widget-sheet-content");if(!o||!i)return;const s=80;let u=0,a=0;const l=C=>{a=C.clientY;const k=Math.max(0,a-u);i.style.transform=`translateY(${k}px)`},f=C=>{o.releasePointerCapture(C.pointerId),o.removeEventListener("pointermove",l),o.removeEventListener("pointerup",f),o.removeEventListener("pointercancel",f);const k=Math.max(0,a-u);if(i.classList.remove("choco-widget-sheet-content--dragging"),k>=s){i.style.transform="translateY(100%)";const _=()=>{i.removeEventListener("transitionend",_),i.style.transform="",Z(e)};i.addEventListener("transitionend",_)}else i.style.transform=""};o.addEventListener("pointerdown",C=>{!e.isPaymentSheetOpen||C.button!==0||(C.preventDefault(),u=C.clientY,a=C.clientY,i.classList.add("choco-widget-sheet-content--dragging"),o.setPointerCapture(C.pointerId),o.addEventListener("pointermove",l),o.addEventListener("pointerup",f),o.addEventListener("pointercancel",f))})}class ne{static _getAuthStorageValue(t){return Ze(t)}static _setAuthStorageValue(t,o){Te(t,o)}static _removeAuthStorageValue(t){Ee(t)}static async logout(){tt()}constructor(t){this.config=Jt(t),this.accessToken=null,this.deviceId=je(),this.apiUrl=Et(this.config.environment),this.translations=Ae,this.checkoutContext=null,this.centrifuge=null,this.selectedPaymentMethod=null,this.selectedCoupon=null,this.useCoupon=!1,this.container=null,this.isOpen=!1,this.isPaymentSheetOpen=!1,this.isPaymentSheetEditMode=!1,this.loading=!1,this.disabled=!1,this.paymentMethodDisabled=!1,this.useBalance=!1,this.useBonuses=!1,this.addCardActionUrl=null,this.isAddCardViewOpen=!1,this.waitingForNewCardAction=!1,this.newCardActionRequiredTimeoutId=null,this._googlePayScriptPromise=null,this._googlePayButtonRenderVersion=0,this._orderStatusPollingId=null,this._orderStatusResolved=!1,this._pendingDeleteMethod=null,this._pendingSuccessPayload=null,this._lifecycleListenersAttached=!1,this._boundAddCardMessage=null,this._boundKeyDown=o=>bn(this,o),this._boundVisibilityChange=()=>this._onVisibilityChange(),this._boundWindowFocus=()=>this._onWindowFocus(),this._boundPageShow=()=>this._onPageShow()}t(t,o={}){var u;const i=this.config.locale||"ru",s=((u=this.translations[i])==null?void 0:u[t])||this.translations.ru[t];return typeof s!="string"?t:s.replace(/{(\w+)}/g,(a,l)=>Object.prototype.hasOwnProperty.call(o,l)?String(o[l]):a)}_resolveErrorMessage(t,o="paymentError"){return(t==null?void 0:t.message)||this.t(o)}_getApiConfig(){return{...this.config,accessToken:this.accessToken}}_isInteractionBlocked(){return this.disabled||this.loading}_getBalanceAmount(){var s,u,a,l;const t=(l=(a=(u=(s=this.checkoutContext)==null?void 0:s.data)==null?void 0:u.balance)==null?void 0:a.data)==null?void 0:l.money,o=this.config.currency||"KZT",i=Number(t==null?void 0:t[o]);return Number.isFinite(i)&&i>0?i:0}_getBonusesAmount(){var o;const t=Number((o=this.config.bonuses)==null?void 0:o.amount);return Number.isFinite(t)&&t>0?t:0}_getBonusesPercent(){var o;const t=Number((o=this.config.bonuses)==null?void 0:o.percent);return!Number.isFinite(t)||t<=0?0:t>=100?100:t}_getAvailableBonus(){var o;const t=Number((o=this.config.bonuses)==null?void 0:o.availableBonus);return Number.isFinite(t)&&t>0?t:0}_getCouponDiscount(){if(!this.useCoupon||!this.selectedCoupon||this._isCouponDisabled()||this.selectedCoupon.type==="coupon")return 0;const t=Number(this.selectedCoupon.reward_amount);return Number.isFinite(t)&&t>0?t:0}_getPaymentBreakdown(){const t=this.config.amount,o=this._getBalanceAmount(),i=this.useBalance?Math.min(o,t):0,s=t-i,u=this.useBalance&&i>=t,a=this.useBonuses?this._getAvailableBonus():0,l=Math.max(s-a,0),f=this._getCouponDiscount(),C=Math.max(l-f,0),k=this.useBalance?t:C,_=this.useBalance&&!u,S=this.useCoupon&&this.selectedCoupon&&!this._isCouponDisabled()?{id:this.selectedCoupon.voucher_id,template_id:this.selectedCoupon.template_id,type:this.selectedCoupon.type}:void 0;return{payableAmount:C,checkoutOptions:{checkoutAmount:k,forceBalanceMethod:u,useBalance:_,voucher:S}}}_getPayableAmount(){return this._getPaymentBreakdown().payableAmount}_isBalanceFullyCoveringAmount(){return this._getPaymentBreakdown().checkoutOptions.forceBalanceMethod}_getCheckoutAmount(){return this._getPaymentBreakdown().checkoutOptions.checkoutAmount??this.config.amount}_getPaymentMethodForUserEvent(){var t;return this._isBalanceFullyCoveringAmount()?"balance":((t=this.selectedPaymentMethod)==null?void 0:t.type)??null}_getKaspiOptions(){return{onlyKaspiAvailable:this.config.onlyKaspiAvailable,disableKaspi:this.config.disableKaspi,disableGooglePay:this.config.disableGooglePay}}_emitUserEvent(t,o={}){typeof this.config.onUserEvent=="function"&&this.config.onUserEvent({eventName:t,eventProperties:o})}_emitPaymentMethodSelected(t=this.selectedPaymentMethod){typeof this.config.onPaymentMethodSelected=="function"&&this.config.onPaymentMethodSelected(t||null)}_attachEventListeners(){mn(this)}_updatePayButtonAmount(){Se(this)}_showAddCardView(){Me(this)}_closeAddCardView(){oe(this)}_setNewCardActionTimeout(){this._clearNewCardActionTimeout(),this.newCardActionRequiredTimeoutId=setTimeout(()=>{this.waitingForNewCardAction&&(this.waitingForNewCardAction=!1,j(this),this.config.onError({attributes:{message:this.t("errorNoServerResponseRetry")}})),this.newCardActionRequiredTimeoutId=null},6e4)}_clearNewCardActionTimeout(){this.newCardActionRequiredTimeoutId&&(window.clearTimeout(this.newCardActionRequiredTimeoutId),this.newCardActionRequiredTimeoutId=null)}_saveTokensToStorage(t,o){Re(t,o)}_clearAuthStorage(){tt()}_getAuthStorageValue(t){return ne._getAuthStorageValue(t)}_setAuthStorageValue(t,o){ne._setAuthStorageValue(t,o)}_removeAuthStorageValue(t){ne._removeAuthStorageValue(t)}_loadGooglePaySdk(){var t,o;return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Google Pay SDK requires browser environment")):(o=(t=window.google)==null?void 0:t.payments)!=null&&o.api?Promise.resolve():this._googlePayScriptPromise?this._googlePayScriptPromise:(this._googlePayScriptPromise=new Promise((i,s)=>{const u=document.querySelector('script[data-choco-google-pay-sdk="true"]');if(u){u.addEventListener("load",()=>i(),{once:!0}),u.addEventListener("error",()=>s(new Error("Failed to load Google Pay SDK")),{once:!0});return}const a=document.createElement("script");a.src="https://pay.google.com/gp/p/js/pay.js",a.async=!0,a.defer=!0,a.setAttribute("data-choco-google-pay-sdk","true"),a.onload=()=>i(),a.onerror=()=>s(new Error("Failed to load Google Pay SDK")),document.head.appendChild(a)}).finally(()=>{var i,s;(s=(i=window.google)==null?void 0:i.payments)!=null&&s.api||(this._googlePayScriptPromise=null)}),this._googlePayScriptPromise)}_attachLifecycleListeners(){this._lifecycleListenersAttached||(document.addEventListener("visibilitychange",this._boundVisibilityChange),window.addEventListener("focus",this._boundWindowFocus),window.addEventListener("pageshow",this._boundPageShow),this._lifecycleListenersAttached=!0)}_detachLifecycleListeners(){this._lifecycleListenersAttached&&(document.removeEventListener("visibilitychange",this._boundVisibilityChange),window.removeEventListener("focus",this._boundWindowFocus),window.removeEventListener("pageshow",this._boundPageShow),this._lifecycleListenersAttached=!1)}_onVisibilityChange(){De()||Xe(this)}_onWindowFocus(){Xe(this)}_onPageShow(){Xe(this)}async _obtainTokenByRefreshOrTrackId(){await qt(this)}async _fetchCheckoutContextWithRetry(){try{this.checkoutContext=await Le(this.apiUrl,this._getApiConfig())}catch(t){if(t.status===401)this._removeAuthStorageValue("webPayToken"),await this._obtainTokenByRefreshOrTrackId(),this.checkoutContext=await Le(this.apiUrl,this._getApiConfig());else throw t}}async _fetchCoupons(){try{const t=await Ht(this.apiUrl,this._getApiConfig()),i=(Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[]).filter(s=>Number(s.reward_amount)>0).sort((s,u)=>s.sort_weight-u.sort_weight);this.selectedCoupon=i.length>0?i[0]:null,this.useCoupon=!1}catch{this.selectedCoupon=null,this.useCoupon=!1}}_isCouponDisabled(){if(!this.selectedCoupon)return!1;if(this.config.amount<this.selectedCoupon.min_pay_amount)return!0;const t=this._getBalanceAmount(),o=this.useBalance?Math.min(t,this.config.amount):0,i=this.config.amount-o,s=this.useBonuses?Math.min(this._getAvailableBonus(),i):0;return i-s<this.selectedCoupon.reward_amount}_prerender(){on(this)}_render(){sn(this)}async init(){var t,o;try{if(this._prerender(),this._attachLifecycleListeners(),!this.config.clientId)return this.config.onError({attributes:{message:this.t("errorMissingTrackClient")}}),!1;if(this.accessToken=this._getAuthStorageValue("webPayToken"),!this.config.trackId&&!this.accessToken)return this.paymentMethodDisabled=!0,this._render(),!0;this.accessToken||await this._obtainTokenByRefreshOrTrackId();try{await this._fetchCheckoutContextWithRetry()}catch(s){const u=s;return this.config.onError({attributes:{message:u.message}}),!1}await this._fetchCoupons();const i=We((o=(t=this.checkoutContext)==null?void 0:t.data)==null?void 0:o.socket_connections,s=>At(this,s));return i&&(this.centrifuge=i.centrifuge),this.selectedPaymentMethod=_e(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this._render(),!0}catch(i){return console.error(`${this.t("errorWidgetInit")}:`,i),this.config.onError({attributes:{message:i.message}}),!1}}close(){this.config.onCancel()}destroy(){const t=document.getElementById("choco-one-click-widget");t&&(t.style.display="none"),this._clearNewCardActionTimeout(),te(this),this._pendingSuccessPayload=null,this._detachLifecycleListeners(),this.isAddCardViewOpen&&oe(this),this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge=null),document.removeEventListener("keydown",this._boundKeyDown),this.container&&(this.container.classList.remove("choco-one-click-widget--visible"),setTimeout(()=>{var o;(o=this.container)==null||o.remove(),this.container=null},300)),this.isOpen=!1,this.isPaymentSheetOpen=!1,this.isAddCardViewOpen=!1,this.selectedPaymentMethod=null}getAvailablePaymentMethods(){var t;return(t=this.checkoutContext)!=null&&t.data?Lt(this.checkoutContext.data,o=>this.t(o),this._getKaspiOptions()):[]}async createOrder(){return fn(this)}async pay(){try{await this.createOrder()}catch(t){console.error(`${this.t("errorPaymentProcess")}:`,t)}}async handlePayment(){if(!this._isInteractionBlocked()){this._emitUserEvent("one_click_pay_cta_tapped",{payment_method:this._getPaymentMethodForUserEvent()});try{if(this.config.onConfirmPay){this.config.onConfirmPay(this.selectedPaymentMethod||null);return}await this.pay()}catch(t){console.error(`${this.t("errorPaymentProcess")}:`,t)}}}openPaymentSheet(){at(this)}closePaymentSheet(){Z(this)}async updateAmount(t){var o;if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new Error("amount must be a non-negative number");if(this.config.amount=t,this._isCouponDisabled()&&(this.useCoupon=!1),this.selectedCoupon){const i=this.isPaymentSheetOpen,s=this.isAddCardViewOpen;if(this._render(),G(this),i){const u=(o=this.container)==null?void 0:o.querySelector('[data-sheet="payment"]');u&&(u.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}s&&Me(this);return}Se(this)}async updateAvailableBonus(t){if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new Error("availableBonus must be a non-negative number");this.config.bonuses&&(this.config.bonuses.availableBonus=t),Se(this)}async updateLocale(t){if(typeof t!="string"||!this.translations[t])throw new Error(`Unsupported locale: ${t}`);if(this.config.locale=t,!this.container)return;const o=this.isPaymentSheetOpen,i=this.isAddCardViewOpen;if(this._render(),G(this),o){const s=this.container.querySelector('[data-sheet="payment"]');s&&(s.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}i&&Me(this)}async setLoading(t){this.loading=!!t,G(this)}async setDisabled(t){this.disabled=!!t,G(this)}async setPreorderId(t){this.config.preorderId=t}async setMerchantOrderId(t){this.config.merchantOrderId=t}async setIdempotencyKey(t){this.config.idempotencyKey=t}async logout(){await ne.logout(),this.accessToken=null}async updateTrackId(t){var o,i;if(this.config.trackId=t,!this.config.clientId)return this.config.onError({attributes:{message:this.t("errorMissingTrackClient")}}),!1;try{this._prerender(),await this._obtainTokenByRefreshOrTrackId();try{await this._fetchCheckoutContextWithRetry()}catch(u){const a=u;return this.config.onError({attributes:{message:a.message}}),!1}await this._fetchCoupons(),this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge=null);const s=We((i=(o=this.checkoutContext)==null?void 0:o.data)==null?void 0:i.socket_connections,u=>At(this,u));return s&&(this.centrifuge=s.centrifuge),this.selectedPaymentMethod=_e(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this.paymentMethodDisabled=!1,this._render(),!0}catch(s){return console.error(`${this.t("errorWidgetInit")}:`,s),this.config.onError({attributes:{message:s.message}}),!1}}async onConfirmPay(t){if(typeof t!="function")throw new Error("onConfirmPay callback must be a function");this.config.onConfirmPay=t}async onPaymentMethodSelected(t){if(typeof t!="function")throw new Error("onPaymentMethodSelected callback must be a function");this.config.onPaymentMethodSelected=t,this._emitPaymentMethodSelected()}async onKaspiLink(t){if(typeof t!="function")throw new Error("onKaspiLink callback must be a function");this.config.onKaspiLink=t}async onUserEvent(t){if(typeof t!="function")throw new Error("onUserEvent callback must be a function");this.config.onUserEvent=t}async onAppliedBonus(t){if(typeof t!="function")throw new Error("onAppliedBonus callback must be a function");this.config.onAppliedBonus=t}}return typeof window<"u"&&(window.ChocoOneClickWidget=ne),ne}));
|
|
300
|
+
`,o.appendChild(i),o.appendChild(s),t.appendChild(o),G(e)}function it(e){var s;if(!e.selectedCoupon)return;const t=e._isCouponDisabled();t&&e.useCoupon&&(e.useCoupon=!1);const o=(s=e.container)==null?void 0:s.querySelector('[data-action="toggle-coupon"]');if(!o)return;o.classList.toggle("choco-widget-balance-toggle--disabled",t);const i=o.querySelector("input[type='checkbox']");i&&(i.disabled=t,t&&(i.checked=!1))}function ee(e){e.loading=!0,G(e)}function j(e){var _,b,S,T,I,w,B,v;e.loading=!1;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(b=e.container)==null?void 0:b.querySelector(".choco-widget-pay-button"),i=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-button-slot button"),s=(T=e.container)==null?void 0:T.querySelector(".choco-widget-apple-pay-button-slot button"),u=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-amount"),a=(w=e.container)==null?void 0:w.querySelector(".choco-widget-google-pay-row"),l=(B=e.container)==null?void 0:B.querySelector(".choco-widget-apple-pay-row"),f=(v=e.container)==null?void 0:v.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),k=e.paymentMethodDisabled||C;t&&(t.disabled=k),o&&(o.disabled=C,o.classList.remove("choco-widget-pay-button--loading")),i&&(i.disabled=C),s&&(s.disabled=C),u==null||u.classList.toggle("choco-widget-wallet-blocked",C),u==null||u.setAttribute("aria-disabled",String(C)),a==null||a.classList.toggle("choco-widget-wallet-blocked",C),a==null||a.setAttribute("aria-disabled",String(C)),l==null||l.classList.toggle("choco-widget-wallet-blocked",C),l==null||l.setAttribute("aria-disabled",String(C)),f==null||f.classList.remove("disabled")}function G(e){var _,b,S,T,I,w,B,v;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(b=e.container)==null?void 0:b.querySelector(".choco-widget-pay-button"),i=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-button-slot button"),s=(T=e.container)==null?void 0:T.querySelector(".choco-widget-apple-pay-button-slot button"),u=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-amount"),a=(w=e.container)==null?void 0:w.querySelector(".choco-widget-google-pay-row"),l=(B=e.container)==null?void 0:B.querySelector(".choco-widget-apple-pay-row"),f=(v=e.container)==null?void 0:v.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),k=e.paymentMethodDisabled||C;f==null||f.classList.toggle("disabled",C),t&&(t.disabled=k),o&&(o.disabled=C,o.classList.toggle("choco-widget-pay-button--loading",e.loading)),i&&(i.disabled=C),s&&(s.disabled=C),u==null||u.classList.toggle("choco-widget-wallet-blocked",C),u==null||u.setAttribute("aria-disabled",String(C)),a==null||a.classList.toggle("choco-widget-wallet-blocked",C),a==null||a.setAttribute("aria-disabled",String(C)),l==null||l.classList.toggle("choco-widget-wallet-blocked",C),l==null||l.setAttribute("aria-disabled",String(C))}function at(e){var o;if(e._isInteractionBlocked())return;const t=(o=e.container)==null?void 0:o.querySelector('[data-sheet="payment"]');t&&(t.classList.add("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!0,de(e))}function Z(e){var o;const t=(o=e.container)==null?void 0:o.querySelector('[data-sheet="payment"]');if(t){Pe(e);const i=t.querySelector(".choco-widget-sheet-content");i&&(i.style.transform="",i.classList.remove("choco-widget-sheet-content--dragging")),t.classList.remove("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!1,e.isPaymentSheetEditMode&&(e.isPaymentSheetEditMode=!1,le(e),de(e))}}function de(e){var f;const t=(f=e.container)==null?void 0:f.querySelector('[data-sheet="payment"]');if(!t)return;const o=t.querySelector(".choco-widget-sheet-title"),i=t.querySelector('[data-action="close-sheet"]'),s=t.querySelector('[data-action="edit-sheet"]'),u=t.querySelector('[data-action="previous-sheet"]'),l=e.getAvailablePaymentMethods().some(C=>C.type==="card");e.isPaymentSheetEditMode?(t.classList.add("choco-widget-payment-sheet--edit"),o&&(o.textContent=e.t("editCards")),i&&(i.style.display="none"),s&&(s.style.display="none"),u&&(u.style.display="")):(t.classList.remove("choco-widget-payment-sheet--edit"),t.classList.toggle("choco-widget-payment-sheet--no-cards",!l),o&&(o.textContent=e.t("paymentMethods")),i&&(i.style.display=""),s&&(s.style.display=l?"":"none"),u&&(u.style.display="none"))}function Me(e){if(!e.addCardActionUrl||!e.container)return;const t=e.container.querySelector('[data-sheet="add-card"]'),o=e.container.querySelector("#choco-widget-add-card-iframe");t&&o&&(o.src=e.addCardActionUrl,t.classList.add("choco-widget-payment-sheet--open"),t.style.display="flex",t.setAttribute("aria-hidden","false"),e.isAddCardViewOpen=!0,An(e))}function oe(e){var i,s;const t=(i=e.container)==null?void 0:i.querySelector('[data-sheet="add-card"]'),o=(s=e.container)==null?void 0:s.querySelector("#choco-widget-add-card-iframe");t&&(t.classList.remove("choco-widget-payment-sheet--open"),t.style.display="none",t.setAttribute("aria-hidden","true")),o&&(o.src="about:blank"),e.addCardActionUrl=null,e.isAddCardViewOpen=!1,un(e)}function An(e){e._boundAddCardMessage=t=>{var o;e.isAddCardViewOpen&&(o=t.data)!=null&&o.message&&t.origin==="https://rahmetapp.kz"&&ee(e)},window.addEventListener("message",e._boundAddCardMessage)}function un(e){e._boundAddCardMessage&&(window.removeEventListener("message",e._boundAddCardMessage),e._boundAddCardMessage=null)}function ln(e,t){var a;e._pendingDeleteMethod=t;const o=(a=e.container)==null?void 0:a.querySelector('[data-sheet="payment"]');if(!o)return;o.classList.add("choco-widget-payment-sheet--delete-confirm");const i=o.querySelector(".choco-widget-sheet-title"),s=o.querySelector('[data-action="edit-sheet"]'),u=o.querySelector('[data-action="previous-sheet"]');i&&(i.textContent=e.t("confirmDeleteCard")),s&&(s.style.display="none"),u&&(u.style.display="none")}function Pe(e){var o;e._pendingDeleteMethod=null,Ne(e,!1);const t=(o=e.container)==null?void 0:o.querySelector('[data-sheet="payment"]');t==null||t.classList.remove("choco-widget-payment-sheet--delete-confirm"),de(e)}function Ne(e,t){var u,a,l;const o=(u=e.container)==null?void 0:u.querySelector(".choco-widget-sheet-delete-confirm-actions"),i=(a=e.container)==null?void 0:a.querySelector('[data-action="confirm-delete-cancel"]'),s=(l=e.container)==null?void 0:l.querySelector('[data-action="confirm-delete-submit"]');o==null||o.classList.toggle("choco-widget-sheet-delete-confirm-actions--loading",t),i&&(i.disabled=t),s&&(s.disabled=t,s.classList.toggle("choco-widget-delete-confirm-btn--loading",t))}async function dn(e,t){var i,s;const o=t==null?void 0:t.cardId;if(!(!o||(t==null?void 0:t.type)!=="card"))try{await Nt(e.apiUrl,e._getApiConfig(),o),e.checkoutContext=await Le(e.apiUrl,e._getApiConfig()),((i=e.selectedPaymentMethod)==null?void 0:i.type)==="card"&&((s=e.selectedPaymentMethod)==null?void 0:s.cardId)===o&&(e.selectedPaymentMethod=_e(e.checkoutContext.data,e._getKaspiOptions()),e._emitPaymentMethodSelected(),ot(e)),le(e),e.config.onSuccess({message:e.t("cardDeleted")}),e.config.onCardDeleted&&e.config.onCardDeleted({cardId:o})}catch(u){e.config.onError({attributes:{message:(u==null?void 0:u.message)||e.t("paymentError")}})}}function ct(e,t){if(!e._isInteractionBlocked()){if(e.selectedPaymentMethod=t,e._emitPaymentMethodSelected(),t.type==="new_card"){e._emitUserEvent("one_click_pay_method_resolved",{payment_method:t.type}),Z(e),e.handlePayment();return}e._emitUserEvent("one_click_pay_method_resolved",{payment_method:e._getPaymentMethodForUserEvent()}),le(e),Z(e),ot(e)}}function At(e,t){var i;const o=t.type||((i=t.data)==null?void 0:i.type);if(!o){console.warn("Unknown event format:",t);return}switch(o){case"order.paid":e._orderStatusResolved=!0,te(e),lt(e,t);break;case"order.failed":e._orderStatusResolved=!0,te(e),dt(e,t);break;case"order.action_required":hn(e,t);break;default:console.warn("Unknown event type:",o)}}function te(e){e._orderStatusPollingId&&(clearInterval(e._orderStatusPollingId),e._orderStatusPollingId=null)}function se(e,t){te(e),e._orderStatusResolved=!1;const o=6e3,i=5;let s=0;const u=async()=>{if(!e._orderStatusResolved){if(s>=i){te(e),j(e),e.config.onError({attributes:{message:e.t("errorNoServerResponseRetry")}});return}s+=1;try{const{data:a}=await Xt(e.apiUrl,e._getApiConfig(),String(t)),l=a==null?void 0:a.status,f=(a==null?void 0:a.payload)||{};if(l==="success"){e._orderStatusResolved=!0,te(e),lt(e,{id:String(f.id||t),attributes:{amount:f.amount,paid_at:f.paid_at||""}});return}l==="fail"&&(e._orderStatusResolved=!0,te(e),dt(e,{id:String(f.id||t),attributes:{message:f.message||e.t("paymentError")}}))}catch(a){console.warn("[Polling] checkOrderStatus error:",a)}}};e._orderStatusPollingId=setInterval(u,o),u()}function De(){return typeof document>"u"?!1:document.hidden||document.visibilityState==="hidden"}function ut(e,t){j(e),e.config.onSuccess(t)}function Xe(e){if(!e._pendingSuccessPayload||De())return;const t=e._pendingSuccessPayload;e._pendingSuccessPayload=null,ut(e,t)}function lt(e,t){var s,u;e.isAddCardViewOpen&&oe(e);const o=t.attributes||((s=t.data)==null?void 0:s.attributes)||{},i={id:t.id||((u=t.data)==null?void 0:u.id),attributes:o};if(De()){e._pendingSuccessPayload=i;return}ut(e,i)}function dt(e,t){var i,s;e.isAddCardViewOpen&&oe(e),j(e);const o=t.attributes||((i=t.data)==null?void 0:i.attributes)||{};e.config.onError({id:t.id||((s=t.data)==null?void 0:s.id),attributes:o})}function hn(e,t){var u,a,l;const o=t.attributes||((u=t.data)==null?void 0:u.attributes)||{},i=o.action_link||o.action_url,s=o.action_url_type||o.action_type||"redirect";if(!i){console.error(e.t("errorActionUrlMissing")),e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,j(e),e.config.onError({attributes:{message:e.t("errorNoServerResponse")}}));return}if(e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout()),s==="inner"){e.addCardActionUrl=i,j(e),e._showAddCardView();return}if(((a=e.selectedPaymentMethod)==null?void 0:a.type)==="kaspi_pay"){const f=t.id||((l=t.data)==null?void 0:l.id);if(f&&!e._orderStatusResolved&&!e._orderStatusPollingId&&se(e,String(f)),typeof e.config.onKaspiLink=="function"){e.config.onKaspiLink({action_link:i,action_url:i,action_type:s,event:t});return}}window.location.href=i}async function fn(e){var o,i,s,u;if(!e.selectedPaymentMethod){e.config.onError({attributes:{message:e.t("errorPaymentMethodNotSelected")}});return}const{checkoutOptions:t}=e._getPaymentBreakdown();if(e._isBalanceFullyCoveringAmount()){ee(e);try{const a=await $e(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await ht(e);const l=(a==null?void 0:a.id)??((o=a==null?void 0:a.data)==null?void 0:o.id);return l&&se(e,String(l)),a}catch(a){throw j(e),e.config.onError({attributes:{message:e._resolveErrorMessage(a)}}),a}}if(e.selectedPaymentMethod.type==="new_card"){await gn(e,t);return}if(e.selectedPaymentMethod.type==="apple_pay"){await pn(e,t);return}if(e.selectedPaymentMethod.type==="google_pay"){await Cn(e,t);return}ee(e);try{const a=await $e(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await ht(e);const l=(a==null?void 0:a.id)??((i=a==null?void 0:a.data)==null?void 0:i.id);if(l&&se(e,String(l)),((s=e.selectedPaymentMethod)==null?void 0:s.type)==="kaspi_pay"){const f=(a==null?void 0:a.attributes)||((u=a==null?void 0:a.data)==null?void 0:u.attributes)||{},C=f.action_link||f.action_url,k=f.action_url_type||f.action_type||"redirect";if(C)return typeof e.config.onKaspiLink=="function"?(e.config.onKaspiLink({action_link:C,action_url:C,action_type:k,event:a}),a):(window.location.href=C,a)}return a}catch(a){throw j(e),e.config.onError({message:e._resolveErrorMessage(a)}),a}}async function ht(e){var t,o;if(!(((t=e.selectedPaymentMethod)==null?void 0:t.type)!=="card"||!((o=e.selectedPaymentMethod)!=null&&o.cardId)))try{await Dt(e.apiUrl,e._getApiConfig(),e.selectedPaymentMethod.cardId)}catch(i){console.warn("Failed to mark selected card as default:",i)}}async function gn(e,t){ee(e),e.waitingForNewCardAction=!0,e._setNewCardActionTimeout();try{await Ut(e.apiUrl,e._getApiConfig(),e.deviceId,t)}catch(o){e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout(),j(e),e.config.onError({attributes:{message:e._resolveErrorMessage(o)}}),console.error("New card payment error:",o)}}let ie=null;async function pn(e,t){const o=window.ApplePaySession;if(!o||!o.canMakePayments()){e.config.onError({attributes:{message:e.t("errorApplePayUnsupported")}});return}if(ie){try{ie.abort()}catch{}ie=null}const i={countryCode:e.config.currency==="GEL"?"GE":"KZ",currencyCode:e.config.currency,supportedNetworks:["visa","masterCard"],merchantCapabilities:["supports3DS"],total:{label:"Choco",amount:String(e._getPayableAmount()),type:"final"}},s=new o(3,i);ie=s,s.onvalidatemerchant=async u=>{var a,l;try{const f=await xt(e.apiUrl,e._getApiConfig(),u.validationURL),C=((l=(a=f==null?void 0:f.data)==null?void 0:a.attributes)==null?void 0:l.session)||f,k=JSON.parse(atob(C));s.completeMerchantValidation(k)}catch(f){console.error("Apple Pay session error:",f),s.abort(),e.config.onError({attributes:{message:e.t("errorApplePayInit")}})}},s.onpaymentauthorized=async u=>{var a;try{if(ee(e),typeof e.config.onBeforeCheckout=="function"){const C=await e.config.onBeforeCheckout();C&&typeof C=="object"&&Object.assign(e.config,C)}const l=await Ft(e.apiUrl,e._getApiConfig(),e.deviceId,u.payment,t);s.completePayment(o.STATUS_SUCCESS),ie=null;const f=(l==null?void 0:l.id)??((a=l==null?void 0:l.data)==null?void 0:a.id);f&&se(e,String(f))}catch(l){console.error("Apple Pay payment error:",l),s.completePayment(o.STATUS_FAILURE),j(e),e.config.onError({attributes:{message:e._resolveErrorMessage(l,"errorApplePayPayment")}})}},s.oncancel=()=>{ie=null,e.config.onCancel()},s.begin()}async function Cn(e,t){var w,B,v,L,O,F;const o=(w=e.checkoutContext)==null?void 0:w.data,i=((v=(B=o==null?void 0:o.payment_methods)==null?void 0:B.data)==null?void 0:v.attributes)||{},s=i.google_pay_settings||{};if(!(i.payment_method_google_pay==="enabled"||i.payment_method_google_pay===!0)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const a=s==null?void 0:s.gateway,l=s==null?void 0:s.merchant_id;if(!a||!l){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}const f=e.config.environment==="production",C=(s==null?void 0:s.merchant_name)||"Choco",k=s==null?void 0:s.google_merchant_id;if(f&&!k){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}if(e.config.isNativeAndroid){await yn(e,t,{gateway:a,gatewayMerchantId:l});return}const _=Number(e._getCheckoutAmount()).toFixed(2);try{await e._loadGooglePaySdk()}catch(N){console.error("Google Pay SDK load error:",N),e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const b=window.google;if(!(b!=null&&b.payments)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const S=[{type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:["VISA","MASTERCARD"],billingAddressRequired:!1},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:a,gatewayMerchantId:l}}}],T={apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:S,transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Итого",totalPrice:_,currencyCode:e.config.currency,countryCode:e.config.currency==="GEL"?"GE":"KZ"},merchantInfo:f?{merchantId:k,merchantName:C}:{merchantName:C}},I=new b.payments.api.PaymentsClient({environment:f?"PRODUCTION":"TEST"});try{const N=await I.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:S});if(!(N!=null&&N.result)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}ee(e);const q=await I.loadPaymentData(T),J=(O=(L=q==null?void 0:q.paymentMethodData)==null?void 0:L.tokenizationData)==null?void 0:O.token;if(!J)throw new Error(e.t("errorGooglePayPayment"));const x=JSON.parse(J),M=await et(e.apiUrl,e._getApiConfig(),e.deviceId,x,t),m=(M==null?void 0:M.id)??((F=M==null?void 0:M.data)==null?void 0:F.id);m&&se(e,String(m))}catch(N){j(e),N.statusCode==="CANCELED"?e.config.onCancel():(e.config.onError({attributes:{message:e._resolveErrorMessage(N,"errorGooglePayPayment")}}),console.error("Google Pay error:",N))}}async function yn(e,t,o){var i;if(!e.config.onPayWithGooglePay){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}ee(e);try{const s=await e.config.onPayWithGooglePay({amount:Number(e._getCheckoutAmount()),gateway:o.gateway,gatewayMerchantId:o.gatewayMerchantId}),u=JSON.parse(s),a=await et(e.apiUrl,e._getApiConfig(),e.deviceId,u,t),l=(a==null?void 0:a.id)??((i=a==null?void 0:a.data)==null?void 0:i.id);l&&se(e,String(l))}catch(s){j(e),s.statusCode==="CANCELED"?e.config.onCancel():(e.config.onError({attributes:{message:e._resolveErrorMessage(s,"errorGooglePayPayment")}}),console.error("Google Pay native error:",s))}}function mn(e){var a,l,f,C,k,_,b,S,T,I,w;const t=e.container;(a=t.querySelector('[data-action="pay"]'))==null||a.addEventListener("click",()=>e.handlePayment()),(l=t.querySelector('[data-action="change-method"]'))==null||l.addEventListener("click",()=>at(e)),t.querySelectorAll('[data-action="close"]').forEach(B=>B.addEventListener("click",()=>e.close())),(f=t.querySelector('[data-action="close-sheet"]'))==null||f.addEventListener("click",()=>{e._pendingDeleteMethod?Pe(e):Z(e)}),(C=t.querySelector('[data-action="edit-sheet"]'))==null||C.addEventListener("click",()=>{e.isPaymentSheetEditMode=!0,le(e),de(e)}),(k=t.querySelector('[data-action="previous-sheet"]'))==null||k.addEventListener("click",()=>{e.isPaymentSheetEditMode=!1,le(e),de(e)}),(_=t.querySelector('[data-action="close-add-card"]'))==null||_.addEventListener("click",()=>oe(e)),(b=t.querySelector('[data-action="confirm-delete-cancel"]'))==null||b.addEventListener("click",()=>Pe(e)),(S=t.querySelector('[data-action="confirm-delete-submit"]'))==null||S.addEventListener("click",()=>{if(e._pendingDeleteMethod){const B=e._pendingDeleteMethod;Ne(e,!0),dn(e,B).then(()=>Z(e)).finally(()=>Ne(e,!1))}}),t.querySelectorAll(".choco-widget-method-item").forEach(B=>{B.addEventListener("click",v=>{const L=JSON.parse(v.currentTarget.getAttribute("data-method")||"{}");ct(e,L)})});const o=t.querySelector('[data-sheet="payment"]');o&&(o.addEventListener("click",B=>{B.target===o&&Z(e)}),En(e,o));const i=t.querySelector('[data-action="toggle-balance"]');i&&((T=i.querySelector("input[type='checkbox']"))==null||T.addEventListener("change",B=>{e.useBalance=B.target.checked,it(e),e._updatePayButtonAmount()}));const s=t.querySelector('[data-action="toggle-bonuses"]');s&&((I=s.querySelector("input[type='checkbox']"))==null||I.addEventListener("change",B=>{e.useBonuses=B.target.checked,e.config.onAppliedBonus(e.useBonuses),it(e),e._updatePayButtonAmount()}));const u=t.querySelector('[data-action="toggle-coupon"]');u&&((w=u.querySelector("input[type='checkbox']"))==null||w.addEventListener("change",B=>{e.useCoupon=B.target.checked,e._updatePayButtonAmount()})),document.removeEventListener("keydown",e._boundKeyDown),document.addEventListener("keydown",e._boundKeyDown),st(e)}function bn(e,t){var o,i;e.isOpen&&(t.key==="Escape"&&(t.preventDefault(),e._pendingDeleteMethod?Pe(e):e.isAddCardViewOpen?oe(e):e.isPaymentSheetOpen?Z(e):e.close()),t.key==="Enter"&&((i=(o=t.target)==null?void 0:o.dataset)==null?void 0:i.action)==="pay"&&(t.preventDefault(),e.handlePayment()))}function En(e,t){const o=t.querySelector('[data-action="sheet-drag-handle"]'),i=t.querySelector(".choco-widget-sheet-content");if(!o||!i)return;const s=80;let u=0,a=0;const l=C=>{a=C.clientY;const k=Math.max(0,a-u);i.style.transform=`translateY(${k}px)`},f=C=>{o.releasePointerCapture(C.pointerId),o.removeEventListener("pointermove",l),o.removeEventListener("pointerup",f),o.removeEventListener("pointercancel",f);const k=Math.max(0,a-u);if(i.classList.remove("choco-widget-sheet-content--dragging"),k>=s){i.style.transform="translateY(100%)";const _=()=>{i.removeEventListener("transitionend",_),i.style.transform="",Z(e)};i.addEventListener("transitionend",_)}else i.style.transform=""};o.addEventListener("pointerdown",C=>{!e.isPaymentSheetOpen||C.button!==0||(C.preventDefault(),u=C.clientY,a=C.clientY,i.classList.add("choco-widget-sheet-content--dragging"),o.setPointerCapture(C.pointerId),o.addEventListener("pointermove",l),o.addEventListener("pointerup",f),o.addEventListener("pointercancel",f))})}class ne{static _getAuthStorageValue(t){return Ze(t)}static _setAuthStorageValue(t,o){Te(t,o)}static _removeAuthStorageValue(t){Ee(t)}static async logout(){tt()}constructor(t){this.config=Jt(t),this.accessToken=null,this.deviceId=je(),this.apiUrl=Et(this.config.environment),this.translations=Ae,this.checkoutContext=null,this.centrifuge=null,this.selectedPaymentMethod=null,this.selectedCoupon=null,this.useCoupon=!1,this.container=null,this.isOpen=!1,this.isPaymentSheetOpen=!1,this.isPaymentSheetEditMode=!1,this.loading=!1,this.disabled=!1,this.paymentMethodDisabled=!1,this.useBalance=!1,this.useBonuses=!1,this.addCardActionUrl=null,this.isAddCardViewOpen=!1,this.waitingForNewCardAction=!1,this.newCardActionRequiredTimeoutId=null,this._googlePayScriptPromise=null,this._googlePayButtonRenderVersion=0,this._orderStatusPollingId=null,this._orderStatusResolved=!1,this._pendingDeleteMethod=null,this._pendingSuccessPayload=null,this._lifecycleListenersAttached=!1,this._destroyed=!1,this._boundAddCardMessage=null,this._boundKeyDown=o=>bn(this,o),this._boundVisibilityChange=()=>this._onVisibilityChange(),this._boundWindowFocus=()=>this._onWindowFocus(),this._boundPageShow=()=>this._onPageShow()}t(t,o={}){var u;const i=this.config.locale||"ru",s=((u=this.translations[i])==null?void 0:u[t])||this.translations.ru[t];return typeof s!="string"?t:s.replace(/{(\w+)}/g,(a,l)=>Object.prototype.hasOwnProperty.call(o,l)?String(o[l]):a)}_resolveErrorMessage(t,o="paymentError"){return(t==null?void 0:t.message)||this.t(o)}_getApiConfig(){return{...this.config,accessToken:this.accessToken}}_isInteractionBlocked(){return this.disabled||this.loading}_getBalanceAmount(){var s,u,a,l;const t=(l=(a=(u=(s=this.checkoutContext)==null?void 0:s.data)==null?void 0:u.balance)==null?void 0:a.data)==null?void 0:l.money,o=this.config.currency||"KZT",i=Number(t==null?void 0:t[o]);return Number.isFinite(i)&&i>0?i:0}_getBonusesAmount(){var o;const t=Number((o=this.config.bonuses)==null?void 0:o.amount);return Number.isFinite(t)&&t>0?t:0}_getBonusesPercent(){var o;const t=Number((o=this.config.bonuses)==null?void 0:o.percent);return!Number.isFinite(t)||t<=0?0:t>=100?100:t}_getAvailableBonus(){var o;const t=Number((o=this.config.bonuses)==null?void 0:o.availableBonus);return Number.isFinite(t)&&t>0?t:0}_getCouponDiscount(){if(!this.useCoupon||!this.selectedCoupon||this._isCouponDisabled()||this.selectedCoupon.type==="coupon")return 0;const t=Number(this.selectedCoupon.reward_amount);return Number.isFinite(t)&&t>0?t:0}_getPaymentBreakdown(){const t=this.config.amount,o=this._getBalanceAmount(),i=this.useBalance?Math.min(o,t):0,s=t-i,u=this.useBalance&&i>=t,a=this.useBonuses?this._getAvailableBonus():0,l=Math.max(s-a,0),f=this._getCouponDiscount(),C=Math.max(l-f,0),k=this.useBalance?t:C,_=this.useBalance&&!u,S=this.useCoupon&&this.selectedCoupon&&!this._isCouponDisabled()?{id:this.selectedCoupon.voucher_id,template_id:this.selectedCoupon.template_id,type:this.selectedCoupon.type}:void 0;return{payableAmount:C,checkoutOptions:{checkoutAmount:k,forceBalanceMethod:u,useBalance:_,voucher:S}}}_getPayableAmount(){return this._getPaymentBreakdown().payableAmount}_isBalanceFullyCoveringAmount(){return this._getPaymentBreakdown().checkoutOptions.forceBalanceMethod}_getCheckoutAmount(){return this._getPaymentBreakdown().checkoutOptions.checkoutAmount??this.config.amount}_getPaymentMethodForUserEvent(){var t;return this._isBalanceFullyCoveringAmount()?"balance":((t=this.selectedPaymentMethod)==null?void 0:t.type)??null}_getKaspiOptions(){return{onlyKaspiAvailable:this.config.onlyKaspiAvailable,disableKaspi:this.config.disableKaspi,disableGooglePay:this.config.disableGooglePay}}_emitUserEvent(t,o={}){typeof this.config.onUserEvent=="function"&&this.config.onUserEvent({eventName:t,eventProperties:o})}_emitPaymentMethodSelected(t=this.selectedPaymentMethod){typeof this.config.onPaymentMethodSelected=="function"&&this.config.onPaymentMethodSelected(t||null)}_attachEventListeners(){mn(this)}_updatePayButtonAmount(){Se(this)}_showAddCardView(){Me(this)}_closeAddCardView(){oe(this)}_setNewCardActionTimeout(){this._clearNewCardActionTimeout(),this.newCardActionRequiredTimeoutId=setTimeout(()=>{this.waitingForNewCardAction&&(this.waitingForNewCardAction=!1,j(this),this.config.onError({attributes:{message:this.t("errorNoServerResponseRetry")}})),this.newCardActionRequiredTimeoutId=null},6e4)}_clearNewCardActionTimeout(){this.newCardActionRequiredTimeoutId&&(window.clearTimeout(this.newCardActionRequiredTimeoutId),this.newCardActionRequiredTimeoutId=null)}_saveTokensToStorage(t,o){Re(t,o)}_clearAuthStorage(){tt()}_getAuthStorageValue(t){return ne._getAuthStorageValue(t)}_setAuthStorageValue(t,o){ne._setAuthStorageValue(t,o)}_removeAuthStorageValue(t){ne._removeAuthStorageValue(t)}_loadGooglePaySdk(){var t,o;return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Google Pay SDK requires browser environment")):(o=(t=window.google)==null?void 0:t.payments)!=null&&o.api?Promise.resolve():this._googlePayScriptPromise?this._googlePayScriptPromise:(this._googlePayScriptPromise=new Promise((i,s)=>{const u=document.querySelector('script[data-choco-google-pay-sdk="true"]');if(u){u.addEventListener("load",()=>i(),{once:!0}),u.addEventListener("error",()=>s(new Error("Failed to load Google Pay SDK")),{once:!0});return}const a=document.createElement("script");a.src="https://pay.google.com/gp/p/js/pay.js",a.async=!0,a.defer=!0,a.setAttribute("data-choco-google-pay-sdk","true"),a.onload=()=>i(),a.onerror=()=>s(new Error("Failed to load Google Pay SDK")),document.head.appendChild(a)}).finally(()=>{var i,s;(s=(i=window.google)==null?void 0:i.payments)!=null&&s.api||(this._googlePayScriptPromise=null)}),this._googlePayScriptPromise)}_attachLifecycleListeners(){this._lifecycleListenersAttached||(document.addEventListener("visibilitychange",this._boundVisibilityChange),window.addEventListener("focus",this._boundWindowFocus),window.addEventListener("pageshow",this._boundPageShow),this._lifecycleListenersAttached=!0)}_detachLifecycleListeners(){this._lifecycleListenersAttached&&(document.removeEventListener("visibilitychange",this._boundVisibilityChange),window.removeEventListener("focus",this._boundWindowFocus),window.removeEventListener("pageshow",this._boundPageShow),this._lifecycleListenersAttached=!1)}_onVisibilityChange(){De()||Xe(this)}_onWindowFocus(){Xe(this)}_onPageShow(){Xe(this)}async _obtainTokenByRefreshOrTrackId(){await qt(this)}async _fetchCheckoutContextWithRetry(){try{this.checkoutContext=await Le(this.apiUrl,this._getApiConfig())}catch(t){if(t.status===401)this._removeAuthStorageValue("webPayToken"),await this._obtainTokenByRefreshOrTrackId(),this.checkoutContext=await Le(this.apiUrl,this._getApiConfig());else throw t}}async _fetchCoupons(){try{const t=await Ht(this.apiUrl,this._getApiConfig()),i=(Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[]).filter(s=>Number(s.reward_amount)>0).sort((s,u)=>s.sort_weight-u.sort_weight);this.selectedCoupon=i.length>0?i[0]:null,this.useCoupon=!1}catch{this.selectedCoupon=null,this.useCoupon=!1}}_isCouponDisabled(){if(!this.selectedCoupon)return!1;if(this.config.amount<this.selectedCoupon.min_pay_amount)return!0;const t=this._getBalanceAmount(),o=this.useBalance?Math.min(t,this.config.amount):0,i=this.config.amount-o,s=this.useBonuses?Math.min(this._getAvailableBonus(),i):0;return i-s<this.selectedCoupon.reward_amount}_prerender(){on(this)}_render(){sn(this)}async init(){var t,o;try{if(this._prerender(),this._attachLifecycleListeners(),!this.config.clientId)return this.config.onError({attributes:{message:this.t("errorMissingTrackClient")}}),!1;if(this.accessToken=this._getAuthStorageValue("webPayToken"),!this.config.trackId&&!this.accessToken)return this.paymentMethodDisabled=!0,this._render(),!0;if(!this.accessToken&&(await this._obtainTokenByRefreshOrTrackId(),this._destroyed))return!1;try{await this._fetchCheckoutContextWithRetry()}catch(s){const u=s;return this.config.onError({attributes:{message:u.message}}),!1}if(this._destroyed||(await this._fetchCoupons(),this._destroyed))return!1;const i=We((o=(t=this.checkoutContext)==null?void 0:t.data)==null?void 0:o.socket_connections,s=>At(this,s));return i&&(this.centrifuge=i.centrifuge),this.selectedPaymentMethod=_e(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this._render(),!0}catch(i){return console.error(`${this.t("errorWidgetInit")}:`,i),this.config.onError({attributes:{message:i.message}}),!1}}close(){this.config.onCancel()}destroy(){this._destroyed=!0;const t=document.getElementById("choco-one-click-widget");t&&(t.style.display="none"),this._clearNewCardActionTimeout(),te(this),this._pendingSuccessPayload=null,this._detachLifecycleListeners(),this.isAddCardViewOpen&&oe(this),this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge=null),document.removeEventListener("keydown",this._boundKeyDown),this.container&&(this.container.classList.remove("choco-one-click-widget--visible"),setTimeout(()=>{var o;(o=this.container)==null||o.remove(),this.container=null},300)),this.isOpen=!1,this.isPaymentSheetOpen=!1,this.isAddCardViewOpen=!1,this.selectedPaymentMethod=null}getAvailablePaymentMethods(){var t;return(t=this.checkoutContext)!=null&&t.data?Lt(this.checkoutContext.data,o=>this.t(o),this._getKaspiOptions()):[]}async createOrder(){return fn(this)}async pay(){try{await this.createOrder()}catch(t){console.error(`${this.t("errorPaymentProcess")}:`,t)}}async handlePayment(){if(!this._isInteractionBlocked()){this._emitUserEvent("one_click_pay_cta_tapped",{payment_method:this._getPaymentMethodForUserEvent()});try{if(this.config.onConfirmPay){this.config.onConfirmPay(this.selectedPaymentMethod||null);return}await this.pay()}catch(t){console.error(`${this.t("errorPaymentProcess")}:`,t)}}}openPaymentSheet(){at(this)}closePaymentSheet(){Z(this)}async updateAmount(t){var o;if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new Error("amount must be a non-negative number");if(this.config.amount=t,this._isCouponDisabled()&&(this.useCoupon=!1),this.selectedCoupon){const i=this.isPaymentSheetOpen,s=this.isAddCardViewOpen;if(this._render(),G(this),i){const u=(o=this.container)==null?void 0:o.querySelector('[data-sheet="payment"]');u&&(u.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}s&&Me(this);return}Se(this)}async updateAvailableBonus(t){if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new Error("availableBonus must be a non-negative number");this.config.bonuses&&(this.config.bonuses.availableBonus=t),Se(this)}async updateLocale(t){if(typeof t!="string"||!this.translations[t])throw new Error(`Unsupported locale: ${t}`);if(this.config.locale=t,!this.container)return;const o=this.isPaymentSheetOpen,i=this.isAddCardViewOpen;if(this._render(),G(this),o){const s=this.container.querySelector('[data-sheet="payment"]');s&&(s.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}i&&Me(this)}async setLoading(t){this.loading=!!t,G(this)}async setDisabled(t){this.disabled=!!t,G(this)}async setPreorderId(t){this.config.preorderId=t}async setMerchantOrderId(t){this.config.merchantOrderId=t}async setIdempotencyKey(t){this.config.idempotencyKey=t}async logout(){await ne.logout(),this.accessToken=null}async updateTrackId(t){var o,i;if(this.config.trackId=t,!this.config.clientId)return this.config.onError({attributes:{message:this.t("errorMissingTrackClient")}}),!1;try{this._prerender(),await this._obtainTokenByRefreshOrTrackId();try{await this._fetchCheckoutContextWithRetry()}catch(u){const a=u;return this.config.onError({attributes:{message:a.message}}),!1}await this._fetchCoupons(),this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge=null);const s=We((i=(o=this.checkoutContext)==null?void 0:o.data)==null?void 0:i.socket_connections,u=>At(this,u));return s&&(this.centrifuge=s.centrifuge),this.selectedPaymentMethod=_e(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this.paymentMethodDisabled=!1,this._render(),!0}catch(s){return console.error(`${this.t("errorWidgetInit")}:`,s),this.config.onError({attributes:{message:s.message}}),!1}}async onConfirmPay(t){if(typeof t!="function")throw new Error("onConfirmPay callback must be a function");this.config.onConfirmPay=t}async onPaymentMethodSelected(t){if(typeof t!="function")throw new Error("onPaymentMethodSelected callback must be a function");this.config.onPaymentMethodSelected=t,this._emitPaymentMethodSelected()}async onKaspiLink(t){if(typeof t!="function")throw new Error("onKaspiLink callback must be a function");this.config.onKaspiLink=t}async onUserEvent(t){if(typeof t!="function")throw new Error("onUserEvent callback must be a function");this.config.onUserEvent=t}async onAppliedBonus(t){if(typeof t!="function")throw new Error("onAppliedBonus callback must be a function");this.config.onAppliedBonus=t}}return typeof window<"u"&&(window.ChocoOneClickWidget=ne),ne}));
|