choco-one-click-payment 1.1.32 → 1.1.33

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 CHANGED
@@ -4061,7 +4061,7 @@ class ie {
4061
4061
  async _fetchCoupons() {
4062
4062
  try {
4063
4063
  const t = await xt(this.apiUrl, this._getApiConfig()), i = (Array.isArray(t) ? t : Array.isArray(t == null ? void 0 : t.data) ? t.data : []).filter((s) => s.is_available && Number(s.reward_amount) > 0).sort((s, u) => s.sort_weight - u.sort_weight);
4064
- this.selectedCoupon = i.length > 0 ? i[0] : null, this.useCoupon = this.selectedCoupon !== null;
4064
+ this.selectedCoupon = i.length > 0 ? i[0] : null, this.useCoupon = !1;
4065
4065
  } catch {
4066
4066
  this.selectedCoupon = null, this.useCoupon = !1;
4067
4067
  }
package/dist/index.js CHANGED
@@ -297,4 +297,4 @@
297
297
  </defs>
298
298
  </svg>
299
299
  </span>
300
- `,o.appendChild(i),o.appendChild(s),t.appendChild(o),ee(e)}function $(e){e.loading=!0,ee(e)}function j(e){var _,E,P,T,B,k,b,w;e.loading=!1;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(E=e.container)==null?void 0:E.querySelector(".choco-widget-pay-button"),i=(P=e.container)==null?void 0:P.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=(B=e.container)==null?void 0:B.querySelector(".choco-widget-google-pay-amount"),a=(k=e.container)==null?void 0:k.querySelector(".choco-widget-google-pay-row"),l=(b=e.container)==null?void 0:b.querySelector(".choco-widget-apple-pay-row"),f=(w=e.container)==null?void 0:w.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),S=e.paymentMethodDisabled||C;t&&(t.disabled=S),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 ee(e){var _,E,P,T,B,k,b,w;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(E=e.container)==null?void 0:E.querySelector(".choco-widget-pay-button"),i=(P=e.container)==null?void 0:P.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=(B=e.container)==null?void 0:B.querySelector(".choco-widget-google-pay-amount"),a=(k=e.container)==null?void 0:k.querySelector(".choco-widget-google-pay-row"),l=(b=e.container)==null?void 0:b.querySelector(".choco-widget-apple-pay-row"),f=(w=e.container)==null?void 0:w.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),S=e.paymentMethodDisabled||C;f==null||f.classList.toggle("disabled",C),t&&(t.disabled=S),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 st(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 G(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 it(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,cn(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,An(e)}function cn(e){e._boundAddCardMessage=t=>{var o;e.isAddCardViewOpen&&(o=t.data)!=null&&o.message&&t.origin==="https://rahmetapp.kz"&&$(e)},window.addEventListener("message",e._boundAddCardMessage)}function An(e){e._boundAddCardMessage&&(window.removeEventListener("message",e._boundAddCardMessage),e._boundAddCardMessage=null)}function un(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,Me(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 Me(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 ln(e,t){var i,s;const o=t==null?void 0:t.cardId;if(!(!o||(t==null?void 0:t.type)!=="card"))try{await Mt(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(),rt(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 at(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}),G(e),e.handlePayment();return}e._emitUserEvent("one_click_pay_method_resolved",{payment_method:e._getPaymentMethodForUserEvent()}),le(e),G(e),rt(e)}}function ct(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),ut(e,t);break;case"order.failed":e._orderStatusResolved=!0,te(e),lt(e,t);break;case"order.action_required":dn(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 Dt(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),ut(e,{id:String(f.id||t),attributes:{amount:f.amount,paid_at:f.paid_at||""}});return}l==="fail"&&(e._orderStatusResolved=!0,te(e),lt(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 Ne(){return typeof document>"u"?!1:document.hidden||document.visibilityState==="hidden"}function At(e,t){j(e),e.config.onSuccess(t)}function De(e){if(!e._pendingSuccessPayload||Ne())return;const t=e._pendingSuccessPayload;e._pendingSuccessPayload=null,At(e,t)}function ut(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(Ne()){e._pendingSuccessPayload=i;return}At(e,i)}function lt(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 dn(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 hn(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()){$(e);try{const a=await Ze(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await dt(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 fn(e,t);return}if(e.selectedPaymentMethod.type==="apple_pay"){await gn(e,t);return}if(e.selectedPaymentMethod.type==="google_pay"){await pn(e,t);return}$(e);try{const a=await Ze(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await dt(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,S=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:S,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 dt(e){var t,o;if(!(((t=e.selectedPaymentMethod)==null?void 0:t.type)!=="card"||!((o=e.selectedPaymentMethod)!=null&&o.cardId)))try{await Nt(e.apiUrl,e._getApiConfig(),e.selectedPaymentMethod.cardId)}catch(i){console.warn("Failed to mark selected card as default:",i)}}async function fn(e,t){$(e),e.waitingForNewCardAction=!0,e._setNewCardActionTimeout();try{await Xt(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 gn(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 Ht(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,S=JSON.parse(atob(C));s.completeMerchantValidation(S)}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($(e),typeof e.config.onBeforeCheckout=="function"){const C=await e.config.onBeforeCheckout();C&&typeof C=="object"&&Object.assign(e.config,C)}const l=await xt(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 pn(e,t){var k,b,w,L,O,J;const o=(k=e.checkoutContext)==null?void 0:k.data,i=((w=(b=o==null?void 0:o.payment_methods)==null?void 0:b.data)==null?void 0:w.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",S=s==null?void 0:s.google_merchant_id;if(f&&!S){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}if(e.config.isNativeAndroid){await Cn(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 E=window.google;if(!(E!=null&&E.payments)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const P=[{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:P,transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Итого",totalPrice:_,currencyCode:e.config.currency,countryCode:e.config.currency==="GEL"?"GE":"KZ"},merchantInfo:f?{merchantId:S,merchantName:C}:{merchantName:C}},B=new E.payments.api.PaymentsClient({environment:f?"PRODUCTION":"TEST"});try{const N=await B.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:P});if(!(N!=null&&N.result)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}$(e);const q=await B.loadPaymentData(T),F=(O=(L=q==null?void 0:q.paymentMethodData)==null?void 0:L.tokenizationData)==null?void 0:O.token;if(!F)throw new Error(e.t("errorGooglePayPayment"));const x=JSON.parse(F),M=await $e(e.apiUrl,e._getApiConfig(),e.deviceId,x,t),m=(M==null?void 0:M.id)??((J=M==null?void 0:M.data)==null?void 0:J.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 Cn(e,t,o){var i;if(!e.config.onPayWithGooglePay){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}$(e);try{const s=await e.config.onPayWithGooglePay({amount:Number(e._getCheckoutAmount()),gateway:o.gateway,gatewayMerchantId:o.gatewayMerchantId}),u=JSON.parse(s),a=await $e(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 yn(e){var a,l,f,C,S,_,E,P,T,B,k;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",()=>st(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):G(e)}),(C=t.querySelector('[data-action="edit-sheet"]'))==null||C.addEventListener("click",()=>{e.isPaymentSheetEditMode=!0,le(e),de(e)}),(S=t.querySelector('[data-action="previous-sheet"]'))==null||S.addEventListener("click",()=>{e.isPaymentSheetEditMode=!1,le(e),de(e)}),(_=t.querySelector('[data-action="close-add-card"]'))==null||_.addEventListener("click",()=>oe(e)),(E=t.querySelector('[data-action="confirm-delete-cancel"]'))==null||E.addEventListener("click",()=>Pe(e)),(P=t.querySelector('[data-action="confirm-delete-submit"]'))==null||P.addEventListener("click",()=>{if(e._pendingDeleteMethod){const b=e._pendingDeleteMethod;Me(e,!0),ln(e,b).then(()=>G(e)).finally(()=>Me(e,!1))}}),t.querySelectorAll(".choco-widget-method-item").forEach(b=>{b.addEventListener("click",w=>{const L=JSON.parse(w.currentTarget.getAttribute("data-method")||"{}");at(e,L)})});const o=t.querySelector('[data-sheet="payment"]');o&&(o.addEventListener("click",b=>{b.target===o&&G(e)}),bn(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,e._updatePayButtonAmount()}));const s=t.querySelector('[data-action="toggle-bonuses"]');s&&((B=s.querySelector("input[type='checkbox']"))==null||B.addEventListener("change",b=>{e.useBonuses=b.target.checked,e.config.onAppliedBonus(e.useBonuses),e._updatePayButtonAmount()}));const u=t.querySelector('[data-action="toggle-coupon"]');u&&((k=u.querySelector("input[type='checkbox']"))==null||k.addEventListener("change",b=>{e.useCoupon=b.target.checked,e._updatePayButtonAmount()})),document.removeEventListener("keydown",e._boundKeyDown),document.addEventListener("keydown",e._boundKeyDown),ot(e)}function mn(e,t){var o,i;e.isOpen&&(t.key==="Escape"&&(t.preventDefault(),e._pendingDeleteMethod?Pe(e):e.isAddCardViewOpen?oe(e):e.isPaymentSheetOpen?G(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 bn(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 S=Math.max(0,a-u);i.style.transform=`translateY(${S}px)`},f=C=>{o.releasePointerCapture(C.pointerId),o.removeEventListener("pointermove",l),o.removeEventListener("pointerup",f),o.removeEventListener("pointercancel",f);const S=Math.max(0,a-u);if(i.classList.remove("choco-widget-sheet-content--dragging"),S>=s){i.style.transform="translateY(100%)";const _=()=>{i.removeEventListener("transitionend",_),i.style.transform="",G(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 Ge(t)}static _setAuthStorageValue(t,o){Te(t,o)}static _removeAuthStorageValue(t){Ee(t)}static async logout(){et()}constructor(t){this.config=Ft(t),this.accessToken=null,this.deviceId=qe(),this.apiUrl=bt(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=>mn(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.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),S=this.useBalance?t:C,_=this.useBalance&&!u,E=this.useCoupon&&this.selectedCoupon?{id:this.selectedCoupon.voucher_id,template_id:this.selectedCoupon.template_id,type:this.selectedCoupon.type}:void 0;return{payableAmount:C,checkoutOptions:{checkoutAmount:S,forceBalanceMethod:u,useBalance:_,voucher:E}}}_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(){yn(this)}_updatePayButtonAmount(){Se(this)}_showAddCardView(){it(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(){et()}_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(){Ne()||De(this)}_onWindowFocus(){De(this)}_onPageShow(){De(this)}async _obtainTokenByRefreshOrTrackId(){await Jt(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 Ut(this.apiUrl,this._getApiConfig()),i=(Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[]).filter(s=>s.is_available&&Number(s.reward_amount)>0).sort((s,u)=>s.sort_weight-u.sort_weight);this.selectedCoupon=i.length>0?i[0]:null,this.useCoupon=this.selectedCoupon!==null}catch{this.selectedCoupon=null,this.useCoupon=!1}}_prerender(){rn(this)}_render(){on(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=Ke((o=(t=this.checkoutContext)==null?void 0:t.data)==null?void 0:o.socket_connections,s=>ct(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?Tt(this.checkoutContext.data,o=>this.t(o),this._getKaspiOptions()):[]}async createOrder(){return hn(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(){st(this)}closePaymentSheet(){G(this)}async updateAmount(t){if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new Error("amount must be a non-negative number");this.config.amount=t,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(),ee(this),o){const s=this.container.querySelector('[data-sheet="payment"]');s&&(s.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}i&&it(this)}async setLoading(t){this.loading=!!t,ee(this)}async setDisabled(t){this.disabled=!!t,ee(this)}async setPreorderId(t){this.config.preorderId=t}async setMerchantOrderId(t){this.config.merchantOrderId=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=Ke((i=(o=this.checkoutContext)==null?void 0:o.data)==null?void 0:i.socket_connections,u=>ct(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),ee(e)}function $(e){e.loading=!0,ee(e)}function j(e){var _,E,P,T,B,k,b,w;e.loading=!1;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(E=e.container)==null?void 0:E.querySelector(".choco-widget-pay-button"),i=(P=e.container)==null?void 0:P.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=(B=e.container)==null?void 0:B.querySelector(".choco-widget-google-pay-amount"),a=(k=e.container)==null?void 0:k.querySelector(".choco-widget-google-pay-row"),l=(b=e.container)==null?void 0:b.querySelector(".choco-widget-apple-pay-row"),f=(w=e.container)==null?void 0:w.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),S=e.paymentMethodDisabled||C;t&&(t.disabled=S),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 ee(e){var _,E,P,T,B,k,b,w;const t=(_=e.container)==null?void 0:_.querySelector(".choco-widget-payment-method"),o=(E=e.container)==null?void 0:E.querySelector(".choco-widget-pay-button"),i=(P=e.container)==null?void 0:P.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=(B=e.container)==null?void 0:B.querySelector(".choco-widget-google-pay-amount"),a=(k=e.container)==null?void 0:k.querySelector(".choco-widget-google-pay-row"),l=(b=e.container)==null?void 0:b.querySelector(".choco-widget-apple-pay-row"),f=(w=e.container)==null?void 0:w.querySelector(".choco-widget-balance-section"),C=e._isInteractionBlocked(),S=e.paymentMethodDisabled||C;f==null||f.classList.toggle("disabled",C),t&&(t.disabled=S),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 st(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 G(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 it(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,cn(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,An(e)}function cn(e){e._boundAddCardMessage=t=>{var o;e.isAddCardViewOpen&&(o=t.data)!=null&&o.message&&t.origin==="https://rahmetapp.kz"&&$(e)},window.addEventListener("message",e._boundAddCardMessage)}function An(e){e._boundAddCardMessage&&(window.removeEventListener("message",e._boundAddCardMessage),e._boundAddCardMessage=null)}function un(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,Me(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 Me(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 ln(e,t){var i,s;const o=t==null?void 0:t.cardId;if(!(!o||(t==null?void 0:t.type)!=="card"))try{await Mt(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(),rt(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 at(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}),G(e),e.handlePayment();return}e._emitUserEvent("one_click_pay_method_resolved",{payment_method:e._getPaymentMethodForUserEvent()}),le(e),G(e),rt(e)}}function ct(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),ut(e,t);break;case"order.failed":e._orderStatusResolved=!0,te(e),lt(e,t);break;case"order.action_required":dn(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 Dt(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),ut(e,{id:String(f.id||t),attributes:{amount:f.amount,paid_at:f.paid_at||""}});return}l==="fail"&&(e._orderStatusResolved=!0,te(e),lt(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 Ne(){return typeof document>"u"?!1:document.hidden||document.visibilityState==="hidden"}function At(e,t){j(e),e.config.onSuccess(t)}function De(e){if(!e._pendingSuccessPayload||Ne())return;const t=e._pendingSuccessPayload;e._pendingSuccessPayload=null,At(e,t)}function ut(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(Ne()){e._pendingSuccessPayload=i;return}At(e,i)}function lt(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 dn(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 hn(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()){$(e);try{const a=await Ze(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await dt(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 fn(e,t);return}if(e.selectedPaymentMethod.type==="apple_pay"){await gn(e,t);return}if(e.selectedPaymentMethod.type==="google_pay"){await pn(e,t);return}$(e);try{const a=await Ze(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await dt(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,S=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:S,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 dt(e){var t,o;if(!(((t=e.selectedPaymentMethod)==null?void 0:t.type)!=="card"||!((o=e.selectedPaymentMethod)!=null&&o.cardId)))try{await Nt(e.apiUrl,e._getApiConfig(),e.selectedPaymentMethod.cardId)}catch(i){console.warn("Failed to mark selected card as default:",i)}}async function fn(e,t){$(e),e.waitingForNewCardAction=!0,e._setNewCardActionTimeout();try{await Xt(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 gn(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 Ht(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,S=JSON.parse(atob(C));s.completeMerchantValidation(S)}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($(e),typeof e.config.onBeforeCheckout=="function"){const C=await e.config.onBeforeCheckout();C&&typeof C=="object"&&Object.assign(e.config,C)}const l=await xt(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 pn(e,t){var k,b,w,L,O,J;const o=(k=e.checkoutContext)==null?void 0:k.data,i=((w=(b=o==null?void 0:o.payment_methods)==null?void 0:b.data)==null?void 0:w.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",S=s==null?void 0:s.google_merchant_id;if(f&&!S){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}if(e.config.isNativeAndroid){await Cn(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 E=window.google;if(!(E!=null&&E.payments)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const P=[{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:P,transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Итого",totalPrice:_,currencyCode:e.config.currency,countryCode:e.config.currency==="GEL"?"GE":"KZ"},merchantInfo:f?{merchantId:S,merchantName:C}:{merchantName:C}},B=new E.payments.api.PaymentsClient({environment:f?"PRODUCTION":"TEST"});try{const N=await B.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:P});if(!(N!=null&&N.result)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}$(e);const q=await B.loadPaymentData(T),F=(O=(L=q==null?void 0:q.paymentMethodData)==null?void 0:L.tokenizationData)==null?void 0:O.token;if(!F)throw new Error(e.t("errorGooglePayPayment"));const x=JSON.parse(F),M=await $e(e.apiUrl,e._getApiConfig(),e.deviceId,x,t),m=(M==null?void 0:M.id)??((J=M==null?void 0:M.data)==null?void 0:J.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 Cn(e,t,o){var i;if(!e.config.onPayWithGooglePay){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}$(e);try{const s=await e.config.onPayWithGooglePay({amount:Number(e._getCheckoutAmount()),gateway:o.gateway,gatewayMerchantId:o.gatewayMerchantId}),u=JSON.parse(s),a=await $e(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 yn(e){var a,l,f,C,S,_,E,P,T,B,k;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",()=>st(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):G(e)}),(C=t.querySelector('[data-action="edit-sheet"]'))==null||C.addEventListener("click",()=>{e.isPaymentSheetEditMode=!0,le(e),de(e)}),(S=t.querySelector('[data-action="previous-sheet"]'))==null||S.addEventListener("click",()=>{e.isPaymentSheetEditMode=!1,le(e),de(e)}),(_=t.querySelector('[data-action="close-add-card"]'))==null||_.addEventListener("click",()=>oe(e)),(E=t.querySelector('[data-action="confirm-delete-cancel"]'))==null||E.addEventListener("click",()=>Pe(e)),(P=t.querySelector('[data-action="confirm-delete-submit"]'))==null||P.addEventListener("click",()=>{if(e._pendingDeleteMethod){const b=e._pendingDeleteMethod;Me(e,!0),ln(e,b).then(()=>G(e)).finally(()=>Me(e,!1))}}),t.querySelectorAll(".choco-widget-method-item").forEach(b=>{b.addEventListener("click",w=>{const L=JSON.parse(w.currentTarget.getAttribute("data-method")||"{}");at(e,L)})});const o=t.querySelector('[data-sheet="payment"]');o&&(o.addEventListener("click",b=>{b.target===o&&G(e)}),bn(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,e._updatePayButtonAmount()}));const s=t.querySelector('[data-action="toggle-bonuses"]');s&&((B=s.querySelector("input[type='checkbox']"))==null||B.addEventListener("change",b=>{e.useBonuses=b.target.checked,e.config.onAppliedBonus(e.useBonuses),e._updatePayButtonAmount()}));const u=t.querySelector('[data-action="toggle-coupon"]');u&&((k=u.querySelector("input[type='checkbox']"))==null||k.addEventListener("change",b=>{e.useCoupon=b.target.checked,e._updatePayButtonAmount()})),document.removeEventListener("keydown",e._boundKeyDown),document.addEventListener("keydown",e._boundKeyDown),ot(e)}function mn(e,t){var o,i;e.isOpen&&(t.key==="Escape"&&(t.preventDefault(),e._pendingDeleteMethod?Pe(e):e.isAddCardViewOpen?oe(e):e.isPaymentSheetOpen?G(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 bn(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 S=Math.max(0,a-u);i.style.transform=`translateY(${S}px)`},f=C=>{o.releasePointerCapture(C.pointerId),o.removeEventListener("pointermove",l),o.removeEventListener("pointerup",f),o.removeEventListener("pointercancel",f);const S=Math.max(0,a-u);if(i.classList.remove("choco-widget-sheet-content--dragging"),S>=s){i.style.transform="translateY(100%)";const _=()=>{i.removeEventListener("transitionend",_),i.style.transform="",G(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 Ge(t)}static _setAuthStorageValue(t,o){Te(t,o)}static _removeAuthStorageValue(t){Ee(t)}static async logout(){et()}constructor(t){this.config=Ft(t),this.accessToken=null,this.deviceId=qe(),this.apiUrl=bt(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=>mn(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.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),S=this.useBalance?t:C,_=this.useBalance&&!u,E=this.useCoupon&&this.selectedCoupon?{id:this.selectedCoupon.voucher_id,template_id:this.selectedCoupon.template_id,type:this.selectedCoupon.type}:void 0;return{payableAmount:C,checkoutOptions:{checkoutAmount:S,forceBalanceMethod:u,useBalance:_,voucher:E}}}_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(){yn(this)}_updatePayButtonAmount(){Se(this)}_showAddCardView(){it(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(){et()}_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(){Ne()||De(this)}_onWindowFocus(){De(this)}_onPageShow(){De(this)}async _obtainTokenByRefreshOrTrackId(){await Jt(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 Ut(this.apiUrl,this._getApiConfig()),i=(Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[]).filter(s=>s.is_available&&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}}_prerender(){rn(this)}_render(){on(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=Ke((o=(t=this.checkoutContext)==null?void 0:t.data)==null?void 0:o.socket_connections,s=>ct(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?Tt(this.checkoutContext.data,o=>this.t(o),this._getKaspiOptions()):[]}async createOrder(){return hn(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(){st(this)}closePaymentSheet(){G(this)}async updateAmount(t){if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new Error("amount must be a non-negative number");this.config.amount=t,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(),ee(this),o){const s=this.container.querySelector('[data-sheet="payment"]');s&&(s.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}i&&it(this)}async setLoading(t){this.loading=!!t,ee(this)}async setDisabled(t){this.disabled=!!t,ee(this)}async setPreorderId(t){this.config.preorderId=t}async setMerchantOrderId(t){this.config.merchantOrderId=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=Ke((i=(o=this.checkoutContext)==null?void 0:o.data)==null?void 0:i.socket_connections,u=>ct(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}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "choco-one-click-payment",
3
- "version": "1.1.32",
3
+ "version": "1.1.33",
4
4
  "description": "Встраиваемый виджет для быстрой оплаты с bottom sheet интерфейсом",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",