choco-one-click-payment 1.1.56 → 1.1.58
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 +25 -29
- package/dist/index.js +3 -3
- package/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -5305,7 +5305,7 @@ function Si(e) {
|
|
|
5305
5305
|
transport: li,
|
|
5306
5306
|
stackParser: Ii,
|
|
5307
5307
|
integrations: [],
|
|
5308
|
-
release: "1.1.
|
|
5308
|
+
release: "1.1.58",
|
|
5309
5309
|
environment: e.environment || "production"
|
|
5310
5310
|
}), n = new ue();
|
|
5311
5311
|
n.setClient(t), n.setTags(e), t.init(), Tt = n;
|
|
@@ -5755,10 +5755,10 @@ function zi(e) {
|
|
|
5755
5755
|
dr(e) && (e.container.style.setProperty("--choco-widget-accent-color", e.config.color), e.container.innerHTML = Hi());
|
|
5756
5756
|
}
|
|
5757
5757
|
function Ki(e) {
|
|
5758
|
-
var
|
|
5758
|
+
var m, b, I, B, Q;
|
|
5759
5759
|
if (e._destroyed || !dr(e)) return;
|
|
5760
5760
|
e.container.style.setProperty("--choco-widget-accent-color", e.config.color), e.container.classList.remove("choco-one-click-widget--visible");
|
|
5761
|
-
const t = e.getAvailablePaymentMethods(), n = (
|
|
5761
|
+
const t = e.getAvailablePaymentMethods(), n = (m = e.checkoutContext) == null ? void 0 : m.data, r = e.config.currency || "KZT", o = (B = (I = (b = n == null ? void 0 : n.balance) == null ? void 0 : b.data) == null ? void 0 : I.money) == null ? void 0 : B[r], i = !e.config.disableUseBalance && o > 0 ? $(o, e.config.locale, e.config.currency) : null, c = (Q = n == null ? void 0 : n.cashback) == null ? void 0 : Q.data, u = (c == null ? void 0 : c.cashbackAmount) > 0 ? $(c.cashbackAmount, e.config.locale, e.config.currency) : null, l = e._getPayableAmount(), h = l < e.config.amount;
|
|
5762
5762
|
e.container.innerHTML = Xi({
|
|
5763
5763
|
amountFormatted: $(l, e.config.locale, e.config.currency),
|
|
5764
5764
|
originalAmountFormatted: $(
|
|
@@ -5787,17 +5787,17 @@ function Ki(e) {
|
|
|
5787
5787
|
e.config.locale,
|
|
5788
5788
|
e.config.currency
|
|
5789
5789
|
),
|
|
5790
|
-
t: (
|
|
5790
|
+
t: (S, P) => e.t(S, P),
|
|
5791
5791
|
currency: r
|
|
5792
5792
|
}), e._attachEventListeners(), e.isOpen = !0, e._emitUserEvent("one_click_pay_cta_rendered", {
|
|
5793
5793
|
terminal_id: e.config.terminalId,
|
|
5794
5794
|
project_id: e.config.projectId ?? e.config.clientId
|
|
5795
|
-
})
|
|
5796
|
-
|
|
5797
|
-
}), requestAnimationFrame(() => {
|
|
5795
|
+
});
|
|
5796
|
+
const y = e._getPaymentMethodForUserEvent();
|
|
5797
|
+
y != null && e._emitUserEvent("one_click_pay_method_resolved", { payment_method: y }), requestAnimationFrame(() => {
|
|
5798
5798
|
requestAnimationFrame(() => {
|
|
5799
|
-
var
|
|
5800
|
-
e._destroyed || (
|
|
5799
|
+
var S;
|
|
5800
|
+
e._destroyed || (S = e.container) == null || S.classList.add("choco-one-click-widget--visible");
|
|
5801
5801
|
});
|
|
5802
5802
|
});
|
|
5803
5803
|
}
|
|
@@ -6085,15 +6085,13 @@ async function $i(e, t) {
|
|
|
6085
6085
|
}
|
|
6086
6086
|
}
|
|
6087
6087
|
function gr(e, t) {
|
|
6088
|
-
if (
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
}
|
|
6093
|
-
e._emitUserEvent("one_click_pay_method_resolved", {
|
|
6094
|
-
payment_method: e._getPaymentMethodForUserEvent()
|
|
6095
|
-
}), ke(e), ce(e), fr(e);
|
|
6088
|
+
if (e._isInteractionBlocked()) return;
|
|
6089
|
+
if (e.selectedPaymentMethod = t, e._emitPaymentMethodSelected(), t.type === "new_card") {
|
|
6090
|
+
e._emitUserEvent("one_click_pay_method_resolved", { payment_method: t.type }), ce(e), e.handlePayment();
|
|
6091
|
+
return;
|
|
6096
6092
|
}
|
|
6093
|
+
const n = e._getPaymentMethodForUserEvent();
|
|
6094
|
+
n != null && e._emitUserEvent("one_click_pay_method_resolved", { payment_method: n }), ke(e), ce(e), fr(e);
|
|
6097
6095
|
}
|
|
6098
6096
|
function On(e, t) {
|
|
6099
6097
|
var r;
|
|
@@ -6866,19 +6864,17 @@ class Ce {
|
|
|
6866
6864
|
}
|
|
6867
6865
|
}
|
|
6868
6866
|
async handlePayment() {
|
|
6869
|
-
if (
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
return;
|
|
6877
|
-
}
|
|
6878
|
-
await this.pay();
|
|
6879
|
-
} catch (t) {
|
|
6880
|
-
console.error(`${this.t("errorPaymentProcess")}:`, t);
|
|
6867
|
+
if (this._isInteractionBlocked()) return;
|
|
6868
|
+
const t = this._getPaymentMethodForUserEvent();
|
|
6869
|
+
t != null && this._emitUserEvent("one_click_pay_cta_tapped", { payment_method: t });
|
|
6870
|
+
try {
|
|
6871
|
+
if (this.config.onConfirmPay) {
|
|
6872
|
+
this.config.onConfirmPay(this.selectedPaymentMethod || null);
|
|
6873
|
+
return;
|
|
6881
6874
|
}
|
|
6875
|
+
await this.pay();
|
|
6876
|
+
} catch (n) {
|
|
6877
|
+
console.error(`${this.t("errorPaymentProcess")}:`, n);
|
|
6882
6878
|
}
|
|
6883
6879
|
}
|
|
6884
6880
|
openPaymentSheet() {
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
`);for(let u=r;u<c.length;u++){const l=c[u];if(l.length>1024)continue;const h=ln.test(l)?l.replace(ln,"$1"):l;if(!h.match(/\S*Error: /)){for(const y of t){const m=y(h);if(m){i.push(m);break}}if(i.length>=un+o)break}}return zr(i.slice(o))}}function zr(e){if(!e.length)return[];const t=Array.from(e);return/sentryWrapped/.test(Ge(t).function||"")&&t.pop(),t.reverse(),An.test(Ge(t).function||"")&&(t.pop(),An.test(Ge(t).function||"")&&t.pop()),t.slice(0,un).map(n=>({...n,filename:n.filename||Ge(t).filename,function:n.function||me}))}function Ge(e){return e[e.length-1]||{}}const mt="<anonymous>";function Kr(e){try{return!e||typeof e!="function"?mt:e.name||mt}catch{return mt}}function Ct(){return bt(j),j}function bt(e){const t=e.__SENTRY__=e.__SENTRY__||{};return t.version=t.version||de,t[de]=t[de]||{}}const dn=Object.prototype.toString;function fn(e){switch(dn.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object WebAssembly.Exception]":return!0;default:return Ve(e,Error)}}function Qe(e,t){return dn.call(e)===`[object ${t}]`}function hn(e){return Qe(e,"ErrorEvent")}function pn(e){return Qe(e,"DOMError")}function Gr(e){return Qe(e,"DOMException")}function gn(e){return Qe(e,"String")}function Et(e){return typeof e=="object"&&e!==null&&"__sentry_template_string__"in e&&"__sentry_template_values__"in e}function Wr(e){return e===null||Et(e)||typeof e!="object"&&typeof e!="function"}function Ce(e){return Qe(e,"Object")}function We(e){return typeof Event<"u"&&Ve(e,Event)}function Yr(e){return typeof Element<"u"&&Ve(e,Element)}function Ye(e){return!!(e&&e.then&&typeof e.then=="function")}function Vr(e){return Ce(e)&&"nativeEvent"in e&&"preventDefault"in e&&"stopPropagation"in e}function Ve(e,t){try{return e instanceof t}catch{return!1}}function Zr(e){return!!(typeof e=="object"&&e!==null&&(e.__isVue||e._isVue))}const $r=j,eo=80;function to(e,t={}){if(!e)return"<unknown>";try{let n=e;const r=5,o=[];let i=0,c=0;const u=" > ",l=u.length;let h;const y=Array.isArray(t)?t:t.keyAttrs,m=!Array.isArray(t)&&t.maxStringLength||eo;for(;n&&i++<r&&(h=no(n,y),!(h==="html"||i>1&&c+o.length*l+h.length>=m));)o.push(h),c+=h.length,n=n.parentNode;return o.reverse().join(u)}catch{return"<unknown>"}}function no(e,t){const n=e,r=[];if(!n||!n.tagName)return"";if($r.HTMLElement&&n instanceof HTMLElement&&n.dataset){if(n.dataset.sentryComponent)return n.dataset.sentryComponent;if(n.dataset.sentryElement)return n.dataset.sentryElement}r.push(n.tagName.toLowerCase());const o=t&&t.length?t.filter(c=>n.getAttribute(c)).map(c=>[c,n.getAttribute(c)]):null;if(o&&o.length)o.forEach(c=>{r.push(`[${c[0]}="${c[1]}"]`)});else{n.id&&r.push(`#${n.id}`);const c=n.className;if(c&&gn(c)){const u=c.split(/\s+/);for(const l of u)r.push(`.${l}`)}}const i=["aria-label","type","name","title","alt"];for(const c of i){const u=n.getAttribute(c);u&&r.push(`[${c}="${u}"]`)}return r.join("")}function ke(e,t=0){return typeof e!="string"||t===0||e.length<=t?e:`${e.slice(0,t)}...`}function yn(e,t,n){try{Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0})}catch{yt&&N.log(`Failed to add non-enumerable property "${t}" to object`,e)}}function mn(e){if(fn(e))return{message:e.message,name:e.name,stack:e.stack,...bn(e)};if(We(e)){const t={type:e.type,target:Cn(e.target),currentTarget:Cn(e.currentTarget),...bn(e)};return typeof CustomEvent<"u"&&Ve(e,CustomEvent)&&(t.detail=e.detail),t}else return e}function Cn(e){try{return Yr(e)?to(e):Object.prototype.toString.call(e)}catch{return"<unknown>"}}function bn(e){if(typeof e=="object"&&e!==null){const t={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}else return{}}function ro(e,t=40){const n=Object.keys(mn(e));n.sort();const r=n[0];if(!r)return"[object has no keys]";if(r.length>=t)return ke(r,t);for(let o=n.length;o>0;o--){const i=n.slice(0,o).join(", ");if(!(i.length>t))return o===n.length?i:ke(i,t)}return""}function Y(e){return vt(e,new Map)}function vt(e,t){if(oo(e)){const n=t.get(e);if(n!==void 0)return n;const r={};t.set(e,r);for(const o of Object.getOwnPropertyNames(e))typeof e[o]<"u"&&(r[o]=vt(e[o],t));return r}if(Array.isArray(e)){const n=t.get(e);if(n!==void 0)return n;const r=[];return t.set(e,r),e.forEach(o=>{r.push(vt(o,t))}),r}return e}function oo(e){if(!Ce(e))return!1;try{const t=Object.getPrototypeOf(e).constructor.name;return!t||t==="Object"}catch{return!0}}const En=1e3;function Ze(){return Date.now()/En}function so(){const{performance:e}=j;if(!e||!e.now)return Ze;const t=Date.now()-e.now(),n=e.timeOrigin==null?t:e.timeOrigin;return()=>(n+e.now())/En}const vn=so();(()=>{const{performance:e}=j;if(!e||!e.now)return;const t=3600*1e3,n=e.now(),r=Date.now(),o=e.timeOrigin?Math.abs(e.timeOrigin+n-r):t,i=o<t,c=e.timing&&e.timing.navigationStart,l=typeof c=="number"?Math.abs(c+n-r):t,h=l<t;return i||h?o<=l?e.timeOrigin:c:r})();function ee(){const e=j,t=e.crypto||e.msCrypto;let n=()=>Math.random()*16;try{if(t&&t.randomUUID)return t.randomUUID().replace(/-/g,"");t&&t.getRandomValues&&(n=()=>{const r=new Uint8Array(1);return t.getRandomValues(r),r[0]})}catch{}return("10000000100040008000"+1e11).replace(/[018]/g,r=>(r^(n()&15)>>r/4).toString(16))}function io(e){return e.exception&&e.exception.values?e.exception.values[0]:void 0}function In(e,t,n){const r=e.exception=e.exception||{},o=r.values=r.values||[],i=o[0]=o[0]||{};i.value||(i.value=t||""),i.type||(i.type="Error")}function Pe(e,t){const n=io(e);if(!n)return;const r={type:"generic",handled:!0},o=n.mechanism;if(n.mechanism={...r,...o,...t},t&&"data"in t){const i={...o&&o.data,...t.data};n.mechanism.data=i}}function Bn(e){if(ao(e))return!0;try{yn(e,"__sentry_captured__",!0)}catch{}return!1}function ao(e){try{return e.__sentry_captured__}catch{}}var re;(function(e){e[e.PENDING=0]="PENDING";const n=1;e[e.RESOLVED=n]="RESOLVED";const r=2;e[e.REJECTED=r]="REJECTED"})(re||(re={}));function fe(e){return new W(t=>{t(e)})}function $e(e){return new W((t,n)=>{n(e)})}class W{constructor(t){W.prototype.__init.call(this),W.prototype.__init2.call(this),W.prototype.__init3.call(this),W.prototype.__init4.call(this),this._state=re.PENDING,this._handlers=[];try{t(this._resolve,this._reject)}catch(n){this._reject(n)}}then(t,n){return new W((r,o)=>{this._handlers.push([!1,i=>{if(!t)r(i);else try{r(t(i))}catch(c){o(c)}},i=>{if(!n)o(i);else try{r(n(i))}catch(c){o(c)}}]),this._executeHandlers()})}catch(t){return this.then(n=>n,t)}finally(t){return new W((n,r)=>{let o,i;return this.then(c=>{i=!1,o=c,t&&t()},c=>{i=!0,o=c,t&&t()}).then(()=>{if(i){r(o);return}n(o)})})}__init(){this._resolve=t=>{this._setResult(re.RESOLVED,t)}}__init2(){this._reject=t=>{this._setResult(re.REJECTED,t)}}__init3(){this._setResult=(t,n)=>{if(this._state===re.PENDING){if(Ye(n)){n.then(this._resolve,this._reject);return}this._state=t,this._value=n,this._executeHandlers()}}}__init4(){this._executeHandlers=()=>{if(this._state===re.PENDING)return;const t=this._handlers.slice();this._handlers=[],t.forEach(n=>{n[0]||(this._state===re.RESOLVED&&n[1](this._value),this._state===re.REJECTED&&n[2](this._value),n[0]=!0)})}}}function It(e,t={}){if(t.user&&(!e.ipAddress&&t.user.ip_address&&(e.ipAddress=t.user.ip_address),!e.did&&!t.did&&(e.did=t.user.id||t.user.email||t.user.username)),e.timestamp=t.timestamp||vn(),t.abnormal_mechanism&&(e.abnormal_mechanism=t.abnormal_mechanism),t.ignoreDuration&&(e.ignoreDuration=t.ignoreDuration),t.sid&&(e.sid=t.sid.length===32?t.sid:ee()),t.init!==void 0&&(e.init=t.init),!e.did&&t.did&&(e.did=`${t.did}`),typeof t.started=="number"&&(e.started=t.started),e.ignoreDuration)e.duration=void 0;else if(typeof t.duration=="number")e.duration=t.duration;else{const n=e.timestamp-e.started;e.duration=n>=0?n:0}t.release&&(e.release=t.release),t.environment&&(e.environment=t.environment),!e.ipAddress&&t.ipAddress&&(e.ipAddress=t.ipAddress),!e.userAgent&&t.userAgent&&(e.userAgent=t.userAgent),typeof t.errors=="number"&&(e.errors=t.errors),t.status&&(e.status=t.status)}function Sn(){return ee()}function Bt(){return ee().substring(16)}function et(e,t,n=2){if(!t||typeof t!="object"||n<=0)return t;if(e&&t&&Object.keys(t).length===0)return e;const r={...e};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=et(r[o],t[o],n-1));return r}const St="_sentrySpan";function _n(e,t){t?yn(e,St,t):delete e[St]}function Qn(e){return e[St]}const co=100;class _t{constructor(){this._notifyingListeners=!1,this._scopeListeners=[],this._eventProcessors=[],this._breadcrumbs=[],this._attachments=[],this._user={},this._tags={},this._extra={},this._contexts={},this._sdkProcessingMetadata={},this._propagationContext={traceId:Sn(),spanId:Bt()}}clone(){const t=new _t;return t._breadcrumbs=[...this._breadcrumbs],t._tags={...this._tags},t._extra={...this._extra},t._contexts={...this._contexts},this._contexts.flags&&(t._contexts.flags={values:[...this._contexts.flags.values]}),t._user=this._user,t._level=this._level,t._session=this._session,t._transactionName=this._transactionName,t._fingerprint=this._fingerprint,t._eventProcessors=[...this._eventProcessors],t._requestSession=this._requestSession,t._attachments=[...this._attachments],t._sdkProcessingMetadata={...this._sdkProcessingMetadata},t._propagationContext={...this._propagationContext},t._client=this._client,t._lastEventId=this._lastEventId,_n(t,Qn(this)),t}setClient(t){this._client=t}setLastEventId(t){this._lastEventId=t}getClient(){return this._client}lastEventId(){return this._lastEventId}addScopeListener(t){this._scopeListeners.push(t)}addEventProcessor(t){return this._eventProcessors.push(t),this}setUser(t){return this._user=t||{email:void 0,id:void 0,ip_address:void 0,username:void 0},this._session&&It(this._session,{user:t}),this._notifyScopeListeners(),this}getUser(){return this._user}getRequestSession(){return this._requestSession}setRequestSession(t){return this._requestSession=t,this}setTags(t){return this._tags={...this._tags,...t},this._notifyScopeListeners(),this}setTag(t,n){return this._tags={...this._tags,[t]:n},this._notifyScopeListeners(),this}setExtras(t){return this._extra={...this._extra,...t},this._notifyScopeListeners(),this}setExtra(t,n){return this._extra={...this._extra,[t]:n},this._notifyScopeListeners(),this}setFingerprint(t){return this._fingerprint=t,this._notifyScopeListeners(),this}setLevel(t){return this._level=t,this._notifyScopeListeners(),this}setTransactionName(t){return this._transactionName=t,this._notifyScopeListeners(),this}setContext(t,n){return n===null?delete this._contexts[t]:this._contexts[t]=n,this._notifyScopeListeners(),this}setSession(t){return t?this._session=t:delete this._session,this._notifyScopeListeners(),this}getSession(){return this._session}update(t){if(!t)return this;const n=typeof t=="function"?t(this):t,[r,o]=n instanceof ce?[n.getScopeData(),n.getRequestSession()]:Ce(n)?[t,t.requestSession]:[],{tags:i,extra:c,user:u,contexts:l,level:h,fingerprint:y=[],propagationContext:m}=r||{};return this._tags={...this._tags,...i},this._extra={...this._extra,...c},this._contexts={...this._contexts,...l},u&&Object.keys(u).length&&(this._user=u),h&&(this._level=h),y.length&&(this._fingerprint=y),m&&(this._propagationContext=m),o&&(this._requestSession=o),this}clear(){return this._breadcrumbs=[],this._tags={},this._extra={},this._user={},this._contexts={},this._level=void 0,this._transactionName=void 0,this._fingerprint=void 0,this._requestSession=void 0,this._session=void 0,_n(this,void 0),this._attachments=[],this.setPropagationContext({traceId:Sn()}),this._notifyScopeListeners(),this}addBreadcrumb(t,n){const r=typeof n=="number"?n:co;if(r<=0)return this;const o={timestamp:Ze(),...t};return this._breadcrumbs.push(o),this._breadcrumbs.length>r&&(this._breadcrumbs=this._breadcrumbs.slice(-r),this._client&&this._client.recordDroppedEvent("buffer_overflow","log_item")),this._notifyScopeListeners(),this}getLastBreadcrumb(){return this._breadcrumbs[this._breadcrumbs.length-1]}clearBreadcrumbs(){return this._breadcrumbs=[],this._notifyScopeListeners(),this}addAttachment(t){return this._attachments.push(t),this}clearAttachments(){return this._attachments=[],this}getScopeData(){return{breadcrumbs:this._breadcrumbs,attachments:this._attachments,contexts:this._contexts,tags:this._tags,extra:this._extra,user:this._user,level:this._level,fingerprint:this._fingerprint||[],eventProcessors:this._eventProcessors,propagationContext:this._propagationContext,sdkProcessingMetadata:this._sdkProcessingMetadata,transactionName:this._transactionName,span:Qn(this)}}setSDKProcessingMetadata(t){return this._sdkProcessingMetadata=et(this._sdkProcessingMetadata,t,2),this}setPropagationContext(t){return this._propagationContext={spanId:Bt(),...t},this}getPropagationContext(){return this._propagationContext}captureException(t,n){const r=n&&n.event_id?n.event_id:ee();if(!this._client)return N.warn("No client configured on scope - will not capture exception!"),r;const o=new Error("Sentry syntheticException");return this._client.captureException(t,{originalException:t,syntheticException:o,...n,event_id:r},this),r}captureMessage(t,n,r){const o=r&&r.event_id?r.event_id:ee();if(!this._client)return N.warn("No client configured on scope - will not capture message!"),o;const i=new Error(t);return this._client.captureMessage(t,n,{originalException:t,syntheticException:i,...r,event_id:o},this),o}captureEvent(t,n){const r=n&&n.event_id?n.event_id:ee();return this._client?(this._client.captureEvent(t,{...n,event_id:r},this),r):(N.warn("No client configured on scope - will not capture event!"),r)}_notifyScopeListeners(){this._notifyingListeners||(this._notifyingListeners=!0,this._scopeListeners.forEach(t=>{t(this)}),this._notifyingListeners=!1)}}const ce=_t;function uo(){return ze("defaultCurrentScope",()=>new ce)}function lo(){return ze("defaultIsolationScope",()=>new ce)}class Ao{constructor(t,n){let r;t?r=t:r=new ce;let o;n?o=n:o=new ce,this._stack=[{scope:r}],this._isolationScope=o}withScope(t){const n=this._pushScope();let r;try{r=t(n)}catch(o){throw this._popScope(),o}return Ye(r)?r.then(o=>(this._popScope(),o),o=>{throw this._popScope(),o}):(this._popScope(),r)}getClient(){return this.getStackTop().client}getScope(){return this.getStackTop().scope}getIsolationScope(){return this._isolationScope}getStackTop(){return this._stack[this._stack.length-1]}_pushScope(){const t=this.getScope().clone();return this._stack.push({client:this.getClient(),scope:t}),t}_popScope(){return this._stack.length<=1?!1:!!this._stack.pop()}}function be(){const e=Ct(),t=bt(e);return t.stack=t.stack||new Ao(uo(),lo())}function fo(e){return be().withScope(e)}function ho(e,t){const n=be();return n.withScope(()=>(n.getStackTop().scope=e,t(e)))}function kn(e){return be().withScope(()=>e(be().getIsolationScope()))}function po(){return{withIsolationScope:kn,withScope:fo,withSetScope:ho,withSetIsolationScope:(e,t)=>kn(t),getCurrentScope:()=>be().getScope(),getIsolationScope:()=>be().getIsolationScope()}}function Pn(e){const t=bt(e);return t.acs?t.acs:po()}function wn(){const e=Ct();return Pn(e).getCurrentScope()}function go(){const e=Ct();return Pn(e).getIsolationScope()}function yo(){return ze("globalScope",()=>new ce)}function Qt(){return wn().getClient()}function mo(e){const t=e.getPropagationContext(),{traceId:n,spanId:r,parentSpanId:o}=t;return Y({trace_id:n,span_id:r,parent_span_id:o})}const Co="_sentryMetrics";function bo(e){const t=e[Co];if(!t)return;const n={};for(const[,[r,o]]of t)(n[r]||(n[r]=[])).push(Y(o));return n}const Eo="sentry.source",vo="sentry.sample_rate",Io="sentry.op",Bo="sentry.origin",So=0,_o=1,Qo="sentry-",ko=/^sentry-/;function Po(e){const t=wo(e);if(!t)return;const n=Object.entries(t).reduce((r,[o,i])=>{if(o.match(ko)){const c=o.slice(Qo.length);r[c]=i}return r},{});if(Object.keys(n).length>0)return n}function wo(e){if(!(!e||!gn(e)&&!Array.isArray(e)))return Array.isArray(e)?e.reduce((t,n)=>{const r=Tn(n);return Object.entries(r).forEach(([o,i])=>{t[o]=i}),t},{}):Tn(e)}function Tn(e){return e.split(",").map(t=>t.split("=").map(n=>decodeURIComponent(n.trim()))).reduce((t,[n,r])=>(n&&r&&(t[n]=r),t),{})}const To=1;let Ln=!1;function Lo(e){const{spanId:t,traceId:n,isRemote:r}=e.spanContext(),o=r?t:kt(e).parent_span_id,i=r?Bt():t;return Y({parent_span_id:o,span_id:i,trace_id:n})}function Rn(e){return typeof e=="number"?On(e):Array.isArray(e)?e[0]+e[1]/1e9:e instanceof Date?On(e.getTime()):vn()}function On(e){return e>9999999999?e/1e3:e}function kt(e){if(Oo(e))return e.getSpanJSON();try{const{spanId:t,traceId:n}=e.spanContext();if(Ro(e)){const{attributes:r,startTime:o,name:i,endTime:c,parentSpanId:u,status:l}=e;return Y({span_id:t,trace_id:n,data:r,description:i,parent_span_id:u,start_timestamp:Rn(o),timestamp:Rn(c)||void 0,status:Do(l),op:r[Io],origin:r[Bo],_metrics_summary:bo(e)})}return{span_id:t,trace_id:n}}catch{return{}}}function Ro(e){const t=e;return!!t.attributes&&!!t.startTime&&!!t.name&&!!t.endTime&&!!t.status}function Oo(e){return typeof e.getSpanJSON=="function"}function No(e){const{traceFlags:t}=e.spanContext();return t===To}function Do(e){if(!(!e||e.code===So))return e.code===_o?"ok":e.message||"unknown_error"}const Mo="_sentryRootSpan";function Nn(e){return e[Mo]||e}function xo(){Ln||(Ke(()=>{console.warn("[Sentry] Deprecation warning: Returning null from `beforeSendSpan` will be disallowed from SDK version 9.0.0 onwards. The callback will only support mutating spans. To drop certain spans, configure the respective integrations directly.")}),Ln=!0)}function Uo(e){if(typeof __SENTRY_TRACING__=="boolean"&&!__SENTRY_TRACING__)return!1;const t=Qt(),n=t&&t.getOptions();return!!n&&(n.enableTracing||"tracesSampleRate"in n||"tracesSampler"in n)}const Dn="production",Fo="_frozenDsc";function Mn(e,t){const n=t.getOptions(),{publicKey:r}=t.getDsn()||{},o=Y({environment:n.environment||Dn,release:n.release,public_key:r,trace_id:e});return t.emit("createDsc",o),o}function Xo(e,t){const n=t.getPropagationContext();return n.dsc||Mn(n.traceId,e)}function Ho(e){const t=Qt();if(!t)return{};const n=Nn(e),r=n[Fo];if(r)return r;const o=n.spanContext().traceState,i=o&&o.get("sentry.dsc"),c=i&&Po(i);if(c)return c;const u=Mn(e.spanContext().traceId,t),l=kt(n),h=l.data||{},y=h[vo];y!=null&&(u.sample_rate=`${y}`);const m=h[Eo],b=l.description;return m!=="url"&&b&&(u.transaction=b),Uo()&&(u.sampled=String(No(n))),t.emit("createDsc",u,n),u}function jo(e){if(typeof e=="boolean")return Number(e);const t=typeof e=="string"?parseFloat(e):e;if(typeof t!="number"||isNaN(t)||t<0||t>1){U&&N.warn(`[Tracing] Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got ${JSON.stringify(e)} of type ${JSON.stringify(typeof e)}.`);return}return t}const Jo=/^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;function qo(e){return e==="http"||e==="https"}function tt(e,t=!1){const{host:n,path:r,pass:o,port:i,projectId:c,protocol:u,publicKey:l}=e;return`${u}://${l}${t&&o?`:${o}`:""}@${n}${i?`:${i}`:""}/${r&&`${r}/`}${c}`}function zo(e){const t=Jo.exec(e);if(!t){Ke(()=>{console.error(`Invalid Sentry Dsn: ${e}`)});return}const[n,r,o="",i="",c="",u=""]=t.slice(1);let l="",h=u;const y=h.split("/");if(y.length>1&&(l=y.slice(0,-1).join("/"),h=y.pop()),h){const m=h.match(/^\d+/);m&&(h=m[0])}return xn({host:i,pass:o,path:l,projectId:h,port:c,protocol:n,publicKey:r})}function xn(e){return{protocol:e.protocol,publicKey:e.publicKey||"",pass:e.pass||"",host:e.host,port:e.port||"",path:e.path||"",projectId:e.projectId}}function Ko(e){if(!yt)return!0;const{port:t,projectId:n,protocol:r}=e;return["protocol","publicKey","host","projectId"].find(c=>e[c]?!1:(N.error(`Invalid Sentry Dsn: ${c} missing`),!0))?!1:n.match(/^\d+$/)?qo(r)?t&&isNaN(parseInt(t,10))?(N.error(`Invalid Sentry Dsn: Invalid port ${t}`),!1):!0:(N.error(`Invalid Sentry Dsn: Invalid protocol ${r}`),!1):(N.error(`Invalid Sentry Dsn: Invalid projectId ${n}`),!1)}function Go(e){const t=typeof e=="string"?zo(e):xn(e);if(!(!t||!Ko(t)))return t}function Wo(){const e=typeof WeakSet=="function",t=e?new WeakSet:[];function n(o){if(e)return t.has(o)?!0:(t.add(o),!1);for(let i=0;i<t.length;i++)if(t[i]===o)return!0;return t.push(o),!1}function r(o){if(e)t.delete(o);else for(let i=0;i<t.length;i++)if(t[i]===o){t.splice(i,1);break}}return[n,r]}function oe(e,t=100,n=1/0){try{return Pt("",e,t,n)}catch(r){return{ERROR:`**non-serializable** (${r})`}}}function Un(e,t=3,n=100*1024){const r=oe(e,t);return $o(r)>n?Un(e,t-1,n):r}function Pt(e,t,n=1/0,r=1/0,o=Wo()){const[i,c]=o;if(t==null||["boolean","string"].includes(typeof t)||typeof t=="number"&&Number.isFinite(t))return t;const u=Yo(e,t);if(!u.startsWith("[object "))return u;if(t.__sentry_skip_normalization__)return t;const l=typeof t.__sentry_override_normalization_depth__=="number"?t.__sentry_override_normalization_depth__:n;if(l===0)return u.replace("object ","");if(i(t))return"[Circular ~]";const h=t;if(h&&typeof h.toJSON=="function")try{const I=h.toJSON();return Pt("",I,l-1,r,o)}catch{}const y=Array.isArray(t)?[]:{};let m=0;const b=mn(t);for(const I in b){if(!Object.prototype.hasOwnProperty.call(b,I))continue;if(m>=r){y[I]="[MaxProperties ~]";break}const B=b[I];y[I]=Pt(I,B,l-1,r,o),m++}return c(t),y}function Yo(e,t){try{if(e==="domain"&&t&&typeof t=="object"&&t._events)return"[Domain]";if(e==="domainEmitter")return"[DomainEmitter]";if(typeof global<"u"&&t===global)return"[Global]";if(typeof window<"u"&&t===window)return"[Window]";if(typeof document<"u"&&t===document)return"[Document]";if(Zr(t))return"[VueViewModel]";if(Vr(t))return"[SyntheticEvent]";if(typeof t=="number"&&!Number.isFinite(t))return`[${t}]`;if(typeof t=="function")return`[Function: ${Kr(t)}]`;if(typeof t=="symbol")return`[${String(t)}]`;if(typeof t=="bigint")return`[BigInt: ${String(t)}]`;const n=Vo(t);return/^HTML(\w*)Element$/.test(n)?`[HTMLElement: ${n}]`:`[object ${n}]`}catch(n){return`**non-serializable** (${n})`}}function Vo(e){const t=Object.getPrototypeOf(e);return t?t.constructor.name:"null prototype"}function Zo(e){return~-encodeURI(e).split(/%..|./).length}function $o(e){return Zo(JSON.stringify(e))}function we(e,t=[]){return[e,t]}function es(e,t){const[n,r]=e;return[n,[...r,t]]}function Fn(e,t){const n=e[1];for(const r of n){const o=r[0].type;if(t(r,o))return!0}return!1}function wt(e){return j.__SENTRY__&&j.__SENTRY__.encodePolyfill?j.__SENTRY__.encodePolyfill(e):new TextEncoder().encode(e)}function ts(e){const[t,n]=e;let r=JSON.stringify(t);function o(i){typeof r=="string"?r=typeof i=="string"?r+i:[wt(r),i]:r.push(typeof i=="string"?wt(i):i)}for(const i of n){const[c,u]=i;if(o(`
|
|
6
6
|
${JSON.stringify(c)}
|
|
7
7
|
`),typeof u=="string"||u instanceof Uint8Array)o(u);else{let l;try{l=JSON.stringify(u)}catch{l=JSON.stringify(oe(u))}o(l)}}return typeof r=="string"?r:ns(r)}function ns(e){const t=e.reduce((o,i)=>o+i.length,0),n=new Uint8Array(t);let r=0;for(const o of e)n.set(o,r),r+=o.length;return n}function rs(e){const t=typeof e.data=="string"?wt(e.data):e.data;return[Y({type:"attachment",length:t.length,filename:e.filename,content_type:e.contentType,attachment_type:e.attachmentType}),t]}const os={session:"session",sessions:"session",attachment:"attachment",transaction:"transaction",event:"error",client_report:"internal",user_report:"default",profile:"profile",profile_chunk:"profile",replay_event:"replay",replay_recording:"replay",check_in:"monitor",feedback:"feedback",span:"span",statsd:"metric_bucket",raw_security:"security"};function Xn(e){return os[e]}function Hn(e){if(!e||!e.sdk)return;const{name:t,version:n}=e.sdk;return{name:t,version:n}}function ss(e,t,n,r){const o=e.sdkProcessingMetadata&&e.sdkProcessingMetadata.dynamicSamplingContext;return{event_id:e.event_id,sent_at:new Date().toISOString(),...t&&{sdk:t},...!!n&&r&&{dsn:tt(r)},...o&&{trace:Y({...o})}}}function is(e,t){return t&&(e.sdk=e.sdk||{},e.sdk.name=e.sdk.name||t.name,e.sdk.version=e.sdk.version||t.version,e.sdk.integrations=[...e.sdk.integrations||[],...t.integrations||[]],e.sdk.packages=[...e.sdk.packages||[],...t.packages||[]]),e}function as(e,t,n,r){const o=Hn(n),i={sent_at:new Date().toISOString(),...o&&{sdk:o},...!!r&&t&&{dsn:tt(t)}},c="aggregates"in e?[{type:"sessions"},e]:[{type:"session"},e.toJSON()];return we(i,[c])}function cs(e,t,n,r){const o=Hn(n),i=e.type&&e.type!=="replay_event"?e.type:"event";is(e,n&&n.sdk);const c=ss(e,o,r,t);return delete e.sdkProcessingMetadata,we(c,[[{type:i},e]])}function Tt(e,t,n,r=0){return new W((o,i)=>{const c=e[r];if(t===null||typeof c!="function")o(t);else{const u=c({...t},n);U&&c.id&&u===null&&N.log(`Event processor "${c.id}" dropped event`),Ye(u)?u.then(l=>Tt(e,l,n,r+1).then(o)).then(null,i):Tt(e,u,n,r+1).then(o).then(null,i)}})}let nt,jn,rt;function us(e){const t=j._sentryDebugIds;if(!t)return{};const n=Object.keys(t);return rt&&n.length===jn||(jn=n.length,rt=n.reduce((r,o)=>{nt||(nt={});const i=nt[o];if(i)r[i[0]]=i[1];else{const c=e(o);for(let u=c.length-1;u>=0;u--){const l=c[u],h=l&&l.filename,y=t[o];if(h&&y){r[h]=y,nt[o]=[h,y];break}}}return r},{})),rt}function ls(e,t){const{fingerprint:n,span:r,breadcrumbs:o,sdkProcessingMetadata:i}=t;As(e,t),r&&hs(e,r),ps(e,n),ds(e,o),fs(e,i)}function Jn(e,t){const{extra:n,tags:r,user:o,contexts:i,level:c,sdkProcessingMetadata:u,breadcrumbs:l,fingerprint:h,eventProcessors:y,attachments:m,propagationContext:b,transactionName:I,span:B}=t;ot(e,"extra",n),ot(e,"tags",r),ot(e,"user",o),ot(e,"contexts",i),e.sdkProcessingMetadata=et(e.sdkProcessingMetadata,u,2),c&&(e.level=c),I&&(e.transactionName=I),B&&(e.span=B),l.length&&(e.breadcrumbs=[...e.breadcrumbs,...l]),h.length&&(e.fingerprint=[...e.fingerprint,...h]),y.length&&(e.eventProcessors=[...e.eventProcessors,...y]),m.length&&(e.attachments=[...e.attachments,...m]),e.propagationContext={...e.propagationContext,...b}}function ot(e,t,n){e[t]=et(e[t],n,1)}function As(e,t){const{extra:n,tags:r,user:o,contexts:i,level:c,transactionName:u}=t,l=Y(n);l&&Object.keys(l).length&&(e.extra={...l,...e.extra});const h=Y(r);h&&Object.keys(h).length&&(e.tags={...h,...e.tags});const y=Y(o);y&&Object.keys(y).length&&(e.user={...y,...e.user});const m=Y(i);m&&Object.keys(m).length&&(e.contexts={...m,...e.contexts}),c&&(e.level=c),u&&e.type!=="transaction"&&(e.transaction=u)}function ds(e,t){const n=[...e.breadcrumbs||[],...t];e.breadcrumbs=n.length?n:void 0}function fs(e,t){e.sdkProcessingMetadata={...e.sdkProcessingMetadata,...t}}function hs(e,t){e.contexts={trace:Lo(t),...e.contexts},e.sdkProcessingMetadata={dynamicSamplingContext:Ho(t),...e.sdkProcessingMetadata};const n=Nn(t),r=kt(n).description;r&&!e.transaction&&e.type==="transaction"&&(e.transaction=r)}function ps(e,t){e.fingerprint=e.fingerprint?Array.isArray(e.fingerprint)?e.fingerprint:[e.fingerprint]:[],t&&(e.fingerprint=e.fingerprint.concat(t)),e.fingerprint&&!e.fingerprint.length&&delete e.fingerprint}function gs(e,t,n,r,o,i){const{normalizeDepth:c=3,normalizeMaxBreadth:u=1e3}=e,l={...t,event_id:t.event_id||n.event_id||ee(),timestamp:t.timestamp||Ze()},h=n.integrations||e.integrations.map(S=>S.name);ys(l,e),bs(l,h),o&&o.emit("applyFrameMetadata",t),t.type===void 0&&ms(l,e.stackParser);const y=vs(r,n.captureContext);n.mechanism&&Pe(l,n.mechanism);const m=o?o.getEventProcessors():[],b=yo().getScopeData();if(i){const S=i.getScopeData();Jn(b,S)}if(y){const S=y.getScopeData();Jn(b,S)}const I=[...n.attachments||[],...b.attachments];I.length&&(n.attachments=I),ls(l,b);const B=[...m,...b.eventProcessors];return Tt(B,l,n).then(S=>(S&&Cs(S),typeof c=="number"&&c>0?Es(S,c,u):S))}function ys(e,t){const{environment:n,release:r,dist:o,maxValueLength:i=250}=t;e.environment=e.environment||n||Dn,!e.release&&r&&(e.release=r),!e.dist&&o&&(e.dist=o),e.message&&(e.message=ke(e.message,i));const c=e.exception&&e.exception.values&&e.exception.values[0];c&&c.value&&(c.value=ke(c.value,i));const u=e.request;u&&u.url&&(u.url=ke(u.url,i))}function ms(e,t){const n=us(t);try{e.exception.values.forEach(r=>{r.stacktrace.frames.forEach(o=>{n&&o.filename&&(o.debug_id=n[o.filename])})})}catch{}}function Cs(e){const t={};try{e.exception.values.forEach(r=>{r.stacktrace.frames.forEach(o=>{o.debug_id&&(o.abs_path?t[o.abs_path]=o.debug_id:o.filename&&(t[o.filename]=o.debug_id),delete o.debug_id)})})}catch{}if(Object.keys(t).length===0)return;e.debug_meta=e.debug_meta||{},e.debug_meta.images=e.debug_meta.images||[];const n=e.debug_meta.images;Object.entries(t).forEach(([r,o])=>{n.push({type:"sourcemap",code_file:r,debug_id:o})})}function bs(e,t){t.length>0&&(e.sdk=e.sdk||{},e.sdk.integrations=[...e.sdk.integrations||[],...t])}function Es(e,t,n){if(!e)return null;const r={...e,...e.breadcrumbs&&{breadcrumbs:e.breadcrumbs.map(o=>({...o,...o.data&&{data:oe(o.data,t,n)}}))},...e.user&&{user:oe(e.user,t,n)},...e.contexts&&{contexts:oe(e.contexts,t,n)},...e.extra&&{extra:oe(e.extra,t,n)}};return e.contexts&&e.contexts.trace&&r.contexts&&(r.contexts.trace=e.contexts.trace,e.contexts.trace.data&&(r.contexts.trace.data=oe(e.contexts.trace.data,t,n))),e.spans&&(r.spans=e.spans.map(o=>({...o,...o.data&&{data:oe(o.data,t,n)}}))),e.contexts&&e.contexts.flags&&r.contexts&&(r.contexts.flags=oe(e.contexts.flags,3,n)),r}function vs(e,t){if(!t)return e;const n=e?e.clone():new ce;return n.update(t),n}const Is="7";function Bs(e){const t=e.protocol?`${e.protocol}:`:"",n=e.port?`:${e.port}`:"";return`${t}//${e.host}${n}${e.path?`/${e.path}`:""}/api/`}function Ss(e){return`${Bs(e)}${e.projectId}/envelope/`}function _s(e,t){const n={sentry_version:Is};return e.publicKey&&(n.sentry_key=e.publicKey),t&&(n.sentry_client=`${t.name}/${t.version}`),new URLSearchParams(n).toString()}function Qs(e,t,n){return t||`${Ss(e)}?${_s(e,n)}`}const qn=[];function ks(e,t){const n={};return t.forEach(r=>{r&&Kn(e,r,n)}),n}function zn(e,t){for(const n of t)n&&n.afterAllSetup&&n.afterAllSetup(e)}function Kn(e,t,n){if(n[t.name]){U&&N.log(`Integration skipped because it was already installed: ${t.name}`);return}if(n[t.name]=t,qn.indexOf(t.name)===-1&&typeof t.setupOnce=="function"&&(t.setupOnce(),qn.push(t.name)),t.setup&&typeof t.setup=="function"&&t.setup(e),typeof t.preprocessEvent=="function"){const r=t.preprocessEvent.bind(t);e.on("preprocessEvent",(o,i)=>r(o,i,e))}if(typeof t.processEvent=="function"){const r=t.processEvent.bind(t),o=Object.assign((i,c)=>r(i,c,e),{id:t.name});e.addEventProcessor(o)}U&&N.log(`Integration installed: ${t.name}`)}function Ps(e,t,n){const r=[{type:"client_report"},{timestamp:Ze(),discarded_events:e}];return we(t?{dsn:t}:{},[r])}class V extends Error{constructor(t,n="warn"){super(t),this.message=t,this.logLevel=n}}const Gn="Not capturing exception because it's already been captured.";class ws{constructor(t){if(this._options=t,this._integrations={},this._numProcessing=0,this._outcomes={},this._hooks={},this._eventProcessors=[],t.dsn?this._dsn=Go(t.dsn):U&&N.warn("No DSN provided, client will not send events."),this._dsn){const o=Qs(this._dsn,t.tunnel,t._metadata?t._metadata.sdk:void 0);this._transport=t.transport({tunnel:this._options.tunnel,recordDroppedEvent:this.recordDroppedEvent.bind(this),...t.transportOptions,url:o})}const r=["enableTracing","tracesSampleRate","tracesSampler"].find(o=>o in t&&t[o]==null);r&&Ke(()=>{console.warn(`[Sentry] Deprecation warning: \`${r}\` is set to undefined, which leads to tracing being enabled. In v9, a value of \`undefined\` will result in tracing being disabled.`)})}captureException(t,n,r){const o=ee();if(Bn(t))return U&&N.log(Gn),o;const i={event_id:o,...n};return this._process(this.eventFromException(t,i).then(c=>this._captureEvent(c,i,r))),i.event_id}captureMessage(t,n,r,o){const i={event_id:ee(),...r},c=Et(t)?t:String(t),u=Wr(t)?this.eventFromMessage(c,n,i):this.eventFromException(t,i);return this._process(u.then(l=>this._captureEvent(l,i,o))),i.event_id}captureEvent(t,n,r){const o=ee();if(n&&n.originalException&&Bn(n.originalException))return U&&N.log(Gn),o;const i={event_id:o,...n},u=(t.sdkProcessingMetadata||{}).capturedSpanScope;return this._process(this._captureEvent(t,i,u||r)),i.event_id}captureSession(t){typeof t.release!="string"?U&&N.warn("Discarded session because of missing or non-string release"):(this.sendSession(t),It(t,{init:!1}))}getDsn(){return this._dsn}getOptions(){return this._options}getSdkMetadata(){return this._options._metadata}getTransport(){return this._transport}flush(t){const n=this._transport;return n?(this.emit("flush"),this._isClientDoneProcessing(t).then(r=>n.flush(t).then(o=>r&&o))):fe(!0)}close(t){return this.flush(t).then(n=>(this.getOptions().enabled=!1,this.emit("close"),n))}getEventProcessors(){return this._eventProcessors}addEventProcessor(t){this._eventProcessors.push(t)}init(){(this._isEnabled()||this._options.integrations.some(({name:t})=>t.startsWith("Spotlight")))&&this._setupIntegrations()}getIntegrationByName(t){return this._integrations[t]}addIntegration(t){const n=this._integrations[t.name];Kn(this,t,this._integrations),n||zn(this,[t])}sendEvent(t,n={}){this.emit("beforeSendEvent",t,n);let r=cs(t,this._dsn,this._options._metadata,this._options.tunnel);for(const i of n.attachments||[])r=es(r,rs(i));const o=this.sendEnvelope(r);o&&o.then(i=>this.emit("afterSendEvent",t,i),null)}sendSession(t){const n=as(t,this._dsn,this._options._metadata,this._options.tunnel);this.sendEnvelope(n)}recordDroppedEvent(t,n,r){if(this._options.sendClientReports){const o=typeof r=="number"?r:1,i=`${t}:${n}`;U&&N.log(`Recording outcome: "${i}"${o>1?` (${o} times)`:""}`),this._outcomes[i]=(this._outcomes[i]||0)+o}}on(t,n){const r=this._hooks[t]=this._hooks[t]||[];return r.push(n),()=>{const o=r.indexOf(n);o>-1&&r.splice(o,1)}}emit(t,...n){const r=this._hooks[t];r&&r.forEach(o=>o(...n))}sendEnvelope(t){return this.emit("beforeEnvelope",t),this._isEnabled()&&this._transport?this._transport.send(t).then(null,n=>(U&&N.error("Error while sending envelope:",n),n)):(U&&N.error("Transport disabled"),fe({}))}_setupIntegrations(){const{integrations:t}=this._options;this._integrations=ks(this,t),zn(this,t)}_updateSessionFromEvent(t,n){let r=n.level==="fatal",o=!1;const i=n.exception&&n.exception.values;if(i){o=!0;for(const l of i){const h=l.mechanism;if(h&&h.handled===!1){r=!0;break}}}const c=t.status==="ok";(c&&t.errors===0||c&&r)&&(It(t,{...r&&{status:"crashed"},errors:t.errors||Number(o||r)}),this.captureSession(t))}_isClientDoneProcessing(t){return new W(n=>{let r=0;const o=1,i=setInterval(()=>{this._numProcessing==0?(clearInterval(i),n(!0)):(r+=o,t&&r>=t&&(clearInterval(i),n(!1)))},o)})}_isEnabled(){return this.getOptions().enabled!==!1&&this._transport!==void 0}_prepareEvent(t,n,r=wn(),o=go()){const i=this.getOptions(),c=Object.keys(this._integrations);return!n.integrations&&c.length>0&&(n.integrations=c),this.emit("preprocessEvent",t,n),t.type||o.setLastEventId(t.event_id||n.event_id),gs(i,t,n,r,this,o).then(u=>{if(u===null)return u;u.contexts={trace:mo(r),...u.contexts};const l=Xo(this,r);return u.sdkProcessingMetadata={dynamicSamplingContext:l,...u.sdkProcessingMetadata},u})}_captureEvent(t,n={},r){return this._processEvent(t,n,r).then(o=>o.event_id,o=>{U&&(o instanceof V&&o.logLevel==="log"?N.log(o.message):N.warn(o))})}_processEvent(t,n,r){const o=this.getOptions(),{sampleRate:i}=o,c=Yn(t),u=Wn(t),l=t.type||"error",h=`before send for type \`${l}\``,y=typeof i>"u"?void 0:jo(i);if(u&&typeof y=="number"&&Math.random()>y)return this.recordDroppedEvent("sample_rate","error",t),$e(new V(`Discarding event because it's not included in the random sample (sampling rate = ${i})`,"log"));const m=l==="replay_event"?"replay":l,I=(t.sdkProcessingMetadata||{}).capturedSpanIsolationScope;return this._prepareEvent(t,n,r,I).then(B=>{if(B===null)throw this.recordDroppedEvent("event_processor",m,t),new V("An event processor returned `null`, will not send event.","log");if(n.data&&n.data.__sentry__===!0)return B;const S=Ls(this,o,B,n);return Ts(S,h)}).then(B=>{if(B===null){if(this.recordDroppedEvent("before_send",m,t),c){const k=1+(t.spans||[]).length;this.recordDroppedEvent("before_send","span",k)}throw new V(`${h} returned \`null\`, will not send event.`,"log")}const Q=r&&r.getSession();if(!c&&Q&&this._updateSessionFromEvent(Q,B),c){const P=B.sdkProcessingMetadata&&B.sdkProcessingMetadata.spanCountBeforeProcessing||0,k=B.spans?B.spans.length:0,R=P-k;R>0&&this.recordDroppedEvent("before_send","span",R)}const S=B.transaction_info;if(c&&S&&B.transaction!==t.transaction){const P="custom";B.transaction_info={...S,source:P}}return this.sendEvent(B,n),B}).then(null,B=>{throw B instanceof V?B:(this.captureException(B,{data:{__sentry__:!0},originalException:B}),new V(`Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.
|
|
8
|
-
Reason: ${B}`))})}_process(t){this._numProcessing++,t.then(n=>(this._numProcessing--,n),n=>(this._numProcessing--,n))}_clearOutcomes(){const t=this._outcomes;return this._outcomes={},Object.entries(t).map(([n,r])=>{const[o,i]=n.split(":");return{reason:o,category:i,quantity:r}})}_flushOutcomes(){U&&N.log("Flushing outcomes...");const t=this._clearOutcomes();if(t.length===0){U&&N.log("No outcomes to send");return}if(!this._dsn){U&&N.log("No dsn provided, will not send outcomes");return}U&&N.log("Sending outcomes:",t);const n=Ps(t,this._options.tunnel&&tt(this._dsn));this.sendEnvelope(n)}}function Ts(e,t){const n=`${t} must return \`null\` or a valid event.`;if(Ye(e))return e.then(r=>{if(!Ce(r)&&r!==null)throw new V(n);return r},r=>{throw new V(`${t} rejected with ${r}`)});if(!Ce(e)&&e!==null)throw new V(n);return e}function Ls(e,t,n,r){const{beforeSend:o,beforeSendTransaction:i,beforeSendSpan:c}=t;if(Wn(n)&&o)return o(n,r);if(Yn(n)){if(n.spans&&c){const u=[];for(const l of n.spans){const h=c(l);h?u.push(h):(xo(),e.recordDroppedEvent("before_send","span"))}n.spans=u}if(i){if(n.spans){const u=n.spans.length;n.sdkProcessingMetadata={...n.sdkProcessingMetadata,spanCountBeforeProcessing:u}}return i(n,r)}}return n}function Wn(e){return e.type===void 0}function Yn(e){return e.type==="transaction"}function Rs(e){const t=[];function n(){return e===void 0||t.length<e}function r(c){return t.splice(t.indexOf(c),1)[0]||Promise.resolve(void 0)}function o(c){if(!n())return $e(new V("Not adding Promise because buffer limit was reached."));const u=c();return t.indexOf(u)===-1&&t.push(u),u.then(()=>r(u)).then(null,()=>r(u).then(null,()=>{})),u}function i(c){return new W((u,l)=>{let h=t.length;if(!h)return u(!0);const y=setTimeout(()=>{c&&c>0&&u(!1)},c);t.forEach(m=>{fe(m).then(()=>{--h||(clearTimeout(y),u(!0))},l)})})}return{$:t,add:o,drain:i}}const Os=60*1e3;function Ns(e,t=Date.now()){const n=parseInt(`${e}`,10);if(!isNaN(n))return n*1e3;const r=Date.parse(`${e}`);return isNaN(r)?Os:r-t}function Ds(e,t){return e[t]||e.all||0}function Ms(e,t,n=Date.now()){return Ds(e,t)>n}function xs(e,{statusCode:t,headers:n},r=Date.now()){const o={...e},i=n&&n["x-sentry-rate-limits"],c=n&&n["retry-after"];if(i)for(const u of i.trim().split(",")){const[l,h,,,y]=u.split(":",5),m=parseInt(l,10),b=(isNaN(m)?60:m)*1e3;if(!h)o.all=r+b;else for(const I of h.split(";"))I==="metric_bucket"?(!y||y.split(";").includes("custom"))&&(o[I]=r+b):o[I]=r+b}else c?o.all=r+Ns(c,r):t===429&&(o.all=r+60*1e3);return o}const Us=64;function Fs(e,t,n=Rs(e.bufferSize||Us)){let r={};const o=c=>n.drain(c);function i(c){const u=[];if(Fn(c,(m,b)=>{const I=Xn(b);if(Ms(r,I)){const B=Vn(m,b);e.recordDroppedEvent("ratelimit_backoff",I,B)}else u.push(m)}),u.length===0)return fe({});const l=we(c[0],u),h=m=>{Fn(l,(b,I)=>{const B=Vn(b,I);e.recordDroppedEvent(m,Xn(I),B)})},y=()=>t({body:ts(l)}).then(m=>(m.statusCode!==void 0&&(m.statusCode<200||m.statusCode>=300)&&U&&N.warn(`Sentry responded with status code ${m.statusCode} to sent event.`),r=xs(r,m),m),m=>{throw h("network_error"),m});return n.add(y).then(m=>m,m=>{if(m instanceof V)return U&&N.error("Skipped sending event because buffer is full."),h("queue_overflow"),fe({});throw m})}return{send:i,flush:o}}function Vn(e,t){if(!(t!=="event"&&t!=="transaction"))return Array.isArray(e)?e[1]:void 0}function Xs(e,t,n=[t],r="npm"){const o=e._metadata||{};o.sdk||(o.sdk={name:`sentry.javascript.${t}`,packages:n.map(i=>({name:`${r}:@sentry/${i}`,version:de})),version:de}),e._metadata=o}function Hs(e){return e&&/^function\s+\w+\(\)\s+\{\s+\[native code\]\s+\}$/.test(e.toString())}function js(){return"npm"}const st=j,Js=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__;function Zn(e,t){const n=Rt(e,t),r={type:Ws(t),value:Ys(t)};return n.length&&(r.stacktrace={frames:n}),r.type===void 0&&r.value===""&&(r.value="Unrecoverable error caught"),r}function qs(e,t,n,r){const o=Qt(),i=o&&o.getOptions().normalizeDepth,c=ni(t),u={__serialized__:Un(t,i)};if(c)return{exception:{values:[Zn(e,c)]},extra:u};const l={exception:{values:[{type:We(t)?t.constructor.name:r?"UnhandledRejection":"Error",value:ei(t,{isUnhandledRejection:r})}]},extra:u};if(n){const h=Rt(e,n);h.length&&(l.exception.values[0].stacktrace={frames:h})}return l}function Lt(e,t){return{exception:{values:[Zn(e,t)]}}}function Rt(e,t){const n=t.stacktrace||t.stack||"",r=Ks(t),o=Gs(t);try{return e(n,r,o)}catch{}return[]}const zs=/Minified React error #\d+;/i;function Ks(e){return e&&zs.test(e.message)?1:0}function Gs(e){return typeof e.framesToPop=="number"?e.framesToPop:0}function $n(e){return typeof WebAssembly<"u"&&typeof WebAssembly.Exception<"u"?e instanceof WebAssembly.Exception:!1}function Ws(e){const t=e&&e.name;return!t&&$n(e)?e.message&&Array.isArray(e.message)&&e.message.length==2?e.message[0]:"WebAssembly.Exception":t}function Ys(e){const t=e&&e.message;return t?t.error&&typeof t.error.message=="string"?t.error.message:$n(e)&&Array.isArray(e.message)&&e.message.length==2?e.message[1]:t:"No error message"}function Vs(e,t,n,r){const o=n&&n.syntheticException||void 0,i=$s(e,t,o,r);return Pe(i),i.level="error",n&&n.event_id&&(i.event_id=n.event_id),fe(i)}function Zs(e,t,n="info",r,o){const i=r&&r.syntheticException||void 0,c=Ot(e,t,i,o);return c.level=n,r&&r.event_id&&(c.event_id=r.event_id),fe(c)}function $s(e,t,n,r,o){let i;if(hn(t)&&t.error)return Lt(e,t.error);if(pn(t)||Gr(t)){const c=t;if("stack"in t)i=Lt(e,t);else{const u=c.name||(pn(c)?"DOMError":"DOMException"),l=c.message?`${u}: ${c.message}`:u;i=Ot(e,l,n,r),In(i,l)}return"code"in c&&(i.tags={...i.tags,"DOMException.code":`${c.code}`}),i}return fn(t)?Lt(e,t):Ce(t)||We(t)?(i=qs(e,t,n,o),Pe(i,{synthetic:!0}),i):(i=Ot(e,t,n,r),In(i,`${t}`),Pe(i,{synthetic:!0}),i)}function Ot(e,t,n,r){const o={};if(r&&n){const i=Rt(e,n);i.length&&(o.exception={values:[{value:t,stacktrace:{frames:i}}]}),Pe(o,{synthetic:!0})}if(Et(t)){const{__sentry_template_string__:i,__sentry_template_values__:c}=t;return o.logentry={message:i,params:c},o}return o.message=t,o}function ei(e,{isUnhandledRejection:t}){const n=ro(e),r="exception";return hn(e)?`Event \`ErrorEvent\` captured as ${r} with message \`${e.message}\``:We(e)?`Event \`${ti(e)}\` (type=${e.type}) captured as ${r}`:`Object captured as ${r} with keys: ${n}`}function ti(e){try{const t=Object.getPrototypeOf(e);return t?t.constructor.name:void 0}catch{}}function ni(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const n=e[t];if(n instanceof Error)return n}}function ri(e,{metadata:t,tunnel:n,dsn:r}){const o={event_id:e.event_id,sent_at:new Date().toISOString(),...t&&t.sdk&&{sdk:{name:t.sdk.name,version:t.sdk.version}},...!!n&&!!r&&{dsn:tt(r)}},i=oi(e);return we(o,[i])}function oi(e){return[{type:"user_report"},e]}class si extends ws{constructor(t){const n={parentSpanIsAlwaysRootSpan:!0,...t},r=st.SENTRY_SDK_SOURCE||js();Xs(n,"browser",["browser"],r),super(n),n.sendClientReports&&st.document&&st.document.addEventListener("visibilitychange",()=>{st.document.visibilityState==="hidden"&&this._flushOutcomes()})}eventFromException(t,n){return Vs(this._options.stackParser,t,n,this._options.attachStacktrace)}eventFromMessage(t,n="info",r){return Zs(this._options.stackParser,t,n,r,this._options.attachStacktrace)}captureUserFeedback(t){if(!this._isEnabled()){Js&&N.warn("SDK not enabled, will not capture user feedback.");return}const n=ri(t,{metadata:this.getSdkMetadata(),dsn:this.getDsn(),tunnel:this.getOptions().tunnel});this.sendEnvelope(n)}_prepareEvent(t,n,r){return t.platform=t.platform||"javascript",super._prepareEvent(t,n,r)}}const ii=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,it=j,at={};function ai(e){const t=at[e];if(t)return t;let n=it[e];if(Hs(n))return at[e]=n.bind(it);const r=it.document;if(r&&typeof r.createElement=="function")try{const o=r.createElement("iframe");o.hidden=!0,r.head.appendChild(o);const i=o.contentWindow;i&&i[e]&&(n=i[e]),r.head.removeChild(o)}catch(o){ii&&N.warn(`Could not create sandbox iframe for ${e} check, bailing to window.${e}: `,o)}return n&&(at[e]=n.bind(it))}function er(e){at[e]=void 0}function ci(e,t=ai("fetch")){let n=0,r=0;function o(i){const c=i.body.length;n+=c,r++;const u={body:i.body,method:"POST",referrerPolicy:"origin",headers:e.headers,keepalive:n<=6e4&&r<15,...e.fetchOptions};if(!t)return er("fetch"),$e("No fetch implementation available");try{return t(e.url,u).then(l=>(n-=c,r--,{statusCode:l.status,headers:{"x-sentry-rate-limits":l.headers.get("X-Sentry-Rate-Limits"),"retry-after":l.headers.get("Retry-After")}}))}catch(l){return er("fetch"),n-=c,r--,$e(l)}}return Fs(e,o)}const ui=30,li=50;function Nt(e,t,n,r){const o={filename:e,function:t==="<anonymous>"?me:t,in_app:!0};return n!==void 0&&(o.lineno=n),r!==void 0&&(o.colno=r),o}const Ai=/^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i,di=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,fi=/\((\S*)(?::(\d+))(?::(\d+))\)/,hi=[ui,e=>{const t=Ai.exec(e);if(t){const[,r,o,i]=t;return Nt(r,me,+o,+i)}const n=di.exec(e);if(n){if(n[2]&&n[2].indexOf("eval")===0){const c=fi.exec(n[2]);c&&(n[2]=c[1],n[3]=c[2],n[4]=c[3])}const[o,i]=tr(n[1]||me,n[2]);return Nt(i,o,n[3]?+n[3]:void 0,n[4]?+n[4]:void 0)}}],pi=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,gi=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,yi=qr(...[hi,[li,e=>{const t=pi.exec(e);if(t){if(t[3]&&t[3].indexOf(" > eval")>-1){const i=gi.exec(t[3]);i&&(t[1]=t[1]||"eval",t[3]=i[1],t[4]=i[2],t[5]="")}let r=t[3],o=t[1]||me;return[o,r]=tr(o,r),Nt(r,o,t[4]?+t[4]:void 0,t[5]?+t[5]:void 0)}}]]),tr=(e,t)=>{const n=e.indexOf("safari-extension")!==-1,r=e.indexOf("safari-web-extension")!==-1;return n||r?[e.indexOf("@")!==-1?e.split("@")[0]:me,n?`safari-extension:${t}`:`safari-web-extension:${t}`]:[e,t]},mi="https://bbed26c9265c425abb56ff9d3728183e@sentry.chocodev.kz/302";let Dt=null;function Ci(e){const t=new si({dsn:mi,transport:ci,stackParser:yi,integrations:[],release:"1.1.56",environment:e.environment||"production"}),n=new ce;n.setClient(t),n.setTags(e),t.init(),Dt=n}function se(e,t){Dt&&Dt.captureException(e,t?{captureContext:{extra:t}}:void 0)}function ct(e,t){pt("webPayToken",e),t&&pt("webPayRefreshToken",t)}function nr(){He("webPayToken"),He("webPayRefreshToken")}async function bi(e){const t=tn("webPayRefreshToken");if(t&&e.config.clientId)try{const n=await Nr(e.apiUrl,e.config.clientId,t,e.config.country);ct(n.access_token,n.refresh_token),e.accessToken=n.access_token;return}catch{He("webPayRefreshToken")}if(!e.config.clientId){e.config.onError({attributes:{message:e.t("errorMissingTrackClient")}});return}if(!e.config.trackId&&typeof e.config.onRequestNewTrackId=="function"&&(e.config.trackId=await e.config.onRequestNewTrackId()),!e.config.trackId){e.config.onError({attributes:{message:e.t("errorMissingTrackClient")}});return}try{const n=await nn(e.apiUrl,e.config.clientId,e.config.trackId,e.config.country);ct(n.access_token,n.refresh_token),e.accessToken=n.access_token}catch(n){if(typeof e.config.onRequestNewTrackId=="function"){e.config.trackId=await e.config.onRequestNewTrackId();const r=await nn(e.apiUrl,e.config.clientId,e.config.trackId,e.config.country);ct(r.access_token,r.refresh_token),e.accessToken=r.access_token}else throw n}}const Ei={kaspi_pay:`<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
Reason: ${B}`))})}_process(t){this._numProcessing++,t.then(n=>(this._numProcessing--,n),n=>(this._numProcessing--,n))}_clearOutcomes(){const t=this._outcomes;return this._outcomes={},Object.entries(t).map(([n,r])=>{const[o,i]=n.split(":");return{reason:o,category:i,quantity:r}})}_flushOutcomes(){U&&N.log("Flushing outcomes...");const t=this._clearOutcomes();if(t.length===0){U&&N.log("No outcomes to send");return}if(!this._dsn){U&&N.log("No dsn provided, will not send outcomes");return}U&&N.log("Sending outcomes:",t);const n=Ps(t,this._options.tunnel&&tt(this._dsn));this.sendEnvelope(n)}}function Ts(e,t){const n=`${t} must return \`null\` or a valid event.`;if(Ye(e))return e.then(r=>{if(!Ce(r)&&r!==null)throw new V(n);return r},r=>{throw new V(`${t} rejected with ${r}`)});if(!Ce(e)&&e!==null)throw new V(n);return e}function Ls(e,t,n,r){const{beforeSend:o,beforeSendTransaction:i,beforeSendSpan:c}=t;if(Wn(n)&&o)return o(n,r);if(Yn(n)){if(n.spans&&c){const u=[];for(const l of n.spans){const h=c(l);h?u.push(h):(xo(),e.recordDroppedEvent("before_send","span"))}n.spans=u}if(i){if(n.spans){const u=n.spans.length;n.sdkProcessingMetadata={...n.sdkProcessingMetadata,spanCountBeforeProcessing:u}}return i(n,r)}}return n}function Wn(e){return e.type===void 0}function Yn(e){return e.type==="transaction"}function Rs(e){const t=[];function n(){return e===void 0||t.length<e}function r(c){return t.splice(t.indexOf(c),1)[0]||Promise.resolve(void 0)}function o(c){if(!n())return $e(new V("Not adding Promise because buffer limit was reached."));const u=c();return t.indexOf(u)===-1&&t.push(u),u.then(()=>r(u)).then(null,()=>r(u).then(null,()=>{})),u}function i(c){return new W((u,l)=>{let h=t.length;if(!h)return u(!0);const y=setTimeout(()=>{c&&c>0&&u(!1)},c);t.forEach(m=>{fe(m).then(()=>{--h||(clearTimeout(y),u(!0))},l)})})}return{$:t,add:o,drain:i}}const Os=60*1e3;function Ns(e,t=Date.now()){const n=parseInt(`${e}`,10);if(!isNaN(n))return n*1e3;const r=Date.parse(`${e}`);return isNaN(r)?Os:r-t}function Ds(e,t){return e[t]||e.all||0}function Ms(e,t,n=Date.now()){return Ds(e,t)>n}function xs(e,{statusCode:t,headers:n},r=Date.now()){const o={...e},i=n&&n["x-sentry-rate-limits"],c=n&&n["retry-after"];if(i)for(const u of i.trim().split(",")){const[l,h,,,y]=u.split(":",5),m=parseInt(l,10),b=(isNaN(m)?60:m)*1e3;if(!h)o.all=r+b;else for(const I of h.split(";"))I==="metric_bucket"?(!y||y.split(";").includes("custom"))&&(o[I]=r+b):o[I]=r+b}else c?o.all=r+Ns(c,r):t===429&&(o.all=r+60*1e3);return o}const Us=64;function Fs(e,t,n=Rs(e.bufferSize||Us)){let r={};const o=c=>n.drain(c);function i(c){const u=[];if(Fn(c,(m,b)=>{const I=Xn(b);if(Ms(r,I)){const B=Vn(m,b);e.recordDroppedEvent("ratelimit_backoff",I,B)}else u.push(m)}),u.length===0)return fe({});const l=we(c[0],u),h=m=>{Fn(l,(b,I)=>{const B=Vn(b,I);e.recordDroppedEvent(m,Xn(I),B)})},y=()=>t({body:ts(l)}).then(m=>(m.statusCode!==void 0&&(m.statusCode<200||m.statusCode>=300)&&U&&N.warn(`Sentry responded with status code ${m.statusCode} to sent event.`),r=xs(r,m),m),m=>{throw h("network_error"),m});return n.add(y).then(m=>m,m=>{if(m instanceof V)return U&&N.error("Skipped sending event because buffer is full."),h("queue_overflow"),fe({});throw m})}return{send:i,flush:o}}function Vn(e,t){if(!(t!=="event"&&t!=="transaction"))return Array.isArray(e)?e[1]:void 0}function Xs(e,t,n=[t],r="npm"){const o=e._metadata||{};o.sdk||(o.sdk={name:`sentry.javascript.${t}`,packages:n.map(i=>({name:`${r}:@sentry/${i}`,version:de})),version:de}),e._metadata=o}function Hs(e){return e&&/^function\s+\w+\(\)\s+\{\s+\[native code\]\s+\}$/.test(e.toString())}function js(){return"npm"}const st=j,Js=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__;function Zn(e,t){const n=Rt(e,t),r={type:Ws(t),value:Ys(t)};return n.length&&(r.stacktrace={frames:n}),r.type===void 0&&r.value===""&&(r.value="Unrecoverable error caught"),r}function qs(e,t,n,r){const o=Qt(),i=o&&o.getOptions().normalizeDepth,c=ni(t),u={__serialized__:Un(t,i)};if(c)return{exception:{values:[Zn(e,c)]},extra:u};const l={exception:{values:[{type:We(t)?t.constructor.name:r?"UnhandledRejection":"Error",value:ei(t,{isUnhandledRejection:r})}]},extra:u};if(n){const h=Rt(e,n);h.length&&(l.exception.values[0].stacktrace={frames:h})}return l}function Lt(e,t){return{exception:{values:[Zn(e,t)]}}}function Rt(e,t){const n=t.stacktrace||t.stack||"",r=Ks(t),o=Gs(t);try{return e(n,r,o)}catch{}return[]}const zs=/Minified React error #\d+;/i;function Ks(e){return e&&zs.test(e.message)?1:0}function Gs(e){return typeof e.framesToPop=="number"?e.framesToPop:0}function $n(e){return typeof WebAssembly<"u"&&typeof WebAssembly.Exception<"u"?e instanceof WebAssembly.Exception:!1}function Ws(e){const t=e&&e.name;return!t&&$n(e)?e.message&&Array.isArray(e.message)&&e.message.length==2?e.message[0]:"WebAssembly.Exception":t}function Ys(e){const t=e&&e.message;return t?t.error&&typeof t.error.message=="string"?t.error.message:$n(e)&&Array.isArray(e.message)&&e.message.length==2?e.message[1]:t:"No error message"}function Vs(e,t,n,r){const o=n&&n.syntheticException||void 0,i=$s(e,t,o,r);return Pe(i),i.level="error",n&&n.event_id&&(i.event_id=n.event_id),fe(i)}function Zs(e,t,n="info",r,o){const i=r&&r.syntheticException||void 0,c=Ot(e,t,i,o);return c.level=n,r&&r.event_id&&(c.event_id=r.event_id),fe(c)}function $s(e,t,n,r,o){let i;if(hn(t)&&t.error)return Lt(e,t.error);if(pn(t)||Gr(t)){const c=t;if("stack"in t)i=Lt(e,t);else{const u=c.name||(pn(c)?"DOMError":"DOMException"),l=c.message?`${u}: ${c.message}`:u;i=Ot(e,l,n,r),In(i,l)}return"code"in c&&(i.tags={...i.tags,"DOMException.code":`${c.code}`}),i}return fn(t)?Lt(e,t):Ce(t)||We(t)?(i=qs(e,t,n,o),Pe(i,{synthetic:!0}),i):(i=Ot(e,t,n,r),In(i,`${t}`),Pe(i,{synthetic:!0}),i)}function Ot(e,t,n,r){const o={};if(r&&n){const i=Rt(e,n);i.length&&(o.exception={values:[{value:t,stacktrace:{frames:i}}]}),Pe(o,{synthetic:!0})}if(Et(t)){const{__sentry_template_string__:i,__sentry_template_values__:c}=t;return o.logentry={message:i,params:c},o}return o.message=t,o}function ei(e,{isUnhandledRejection:t}){const n=ro(e),r="exception";return hn(e)?`Event \`ErrorEvent\` captured as ${r} with message \`${e.message}\``:We(e)?`Event \`${ti(e)}\` (type=${e.type}) captured as ${r}`:`Object captured as ${r} with keys: ${n}`}function ti(e){try{const t=Object.getPrototypeOf(e);return t?t.constructor.name:void 0}catch{}}function ni(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const n=e[t];if(n instanceof Error)return n}}function ri(e,{metadata:t,tunnel:n,dsn:r}){const o={event_id:e.event_id,sent_at:new Date().toISOString(),...t&&t.sdk&&{sdk:{name:t.sdk.name,version:t.sdk.version}},...!!n&&!!r&&{dsn:tt(r)}},i=oi(e);return we(o,[i])}function oi(e){return[{type:"user_report"},e]}class si extends ws{constructor(t){const n={parentSpanIsAlwaysRootSpan:!0,...t},r=st.SENTRY_SDK_SOURCE||js();Xs(n,"browser",["browser"],r),super(n),n.sendClientReports&&st.document&&st.document.addEventListener("visibilitychange",()=>{st.document.visibilityState==="hidden"&&this._flushOutcomes()})}eventFromException(t,n){return Vs(this._options.stackParser,t,n,this._options.attachStacktrace)}eventFromMessage(t,n="info",r){return Zs(this._options.stackParser,t,n,r,this._options.attachStacktrace)}captureUserFeedback(t){if(!this._isEnabled()){Js&&N.warn("SDK not enabled, will not capture user feedback.");return}const n=ri(t,{metadata:this.getSdkMetadata(),dsn:this.getDsn(),tunnel:this.getOptions().tunnel});this.sendEnvelope(n)}_prepareEvent(t,n,r){return t.platform=t.platform||"javascript",super._prepareEvent(t,n,r)}}const ii=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,it=j,at={};function ai(e){const t=at[e];if(t)return t;let n=it[e];if(Hs(n))return at[e]=n.bind(it);const r=it.document;if(r&&typeof r.createElement=="function")try{const o=r.createElement("iframe");o.hidden=!0,r.head.appendChild(o);const i=o.contentWindow;i&&i[e]&&(n=i[e]),r.head.removeChild(o)}catch(o){ii&&N.warn(`Could not create sandbox iframe for ${e} check, bailing to window.${e}: `,o)}return n&&(at[e]=n.bind(it))}function er(e){at[e]=void 0}function ci(e,t=ai("fetch")){let n=0,r=0;function o(i){const c=i.body.length;n+=c,r++;const u={body:i.body,method:"POST",referrerPolicy:"origin",headers:e.headers,keepalive:n<=6e4&&r<15,...e.fetchOptions};if(!t)return er("fetch"),$e("No fetch implementation available");try{return t(e.url,u).then(l=>(n-=c,r--,{statusCode:l.status,headers:{"x-sentry-rate-limits":l.headers.get("X-Sentry-Rate-Limits"),"retry-after":l.headers.get("Retry-After")}}))}catch(l){return er("fetch"),n-=c,r--,$e(l)}}return Fs(e,o)}const ui=30,li=50;function Nt(e,t,n,r){const o={filename:e,function:t==="<anonymous>"?me:t,in_app:!0};return n!==void 0&&(o.lineno=n),r!==void 0&&(o.colno=r),o}const Ai=/^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i,di=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,fi=/\((\S*)(?::(\d+))(?::(\d+))\)/,hi=[ui,e=>{const t=Ai.exec(e);if(t){const[,r,o,i]=t;return Nt(r,me,+o,+i)}const n=di.exec(e);if(n){if(n[2]&&n[2].indexOf("eval")===0){const c=fi.exec(n[2]);c&&(n[2]=c[1],n[3]=c[2],n[4]=c[3])}const[o,i]=tr(n[1]||me,n[2]);return Nt(i,o,n[3]?+n[3]:void 0,n[4]?+n[4]:void 0)}}],pi=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,gi=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,yi=qr(...[hi,[li,e=>{const t=pi.exec(e);if(t){if(t[3]&&t[3].indexOf(" > eval")>-1){const i=gi.exec(t[3]);i&&(t[1]=t[1]||"eval",t[3]=i[1],t[4]=i[2],t[5]="")}let r=t[3],o=t[1]||me;return[o,r]=tr(o,r),Nt(r,o,t[4]?+t[4]:void 0,t[5]?+t[5]:void 0)}}]]),tr=(e,t)=>{const n=e.indexOf("safari-extension")!==-1,r=e.indexOf("safari-web-extension")!==-1;return n||r?[e.indexOf("@")!==-1?e.split("@")[0]:me,n?`safari-extension:${t}`:`safari-web-extension:${t}`]:[e,t]},mi="https://bbed26c9265c425abb56ff9d3728183e@sentry.chocodev.kz/302";let Dt=null;function Ci(e){const t=new si({dsn:mi,transport:ci,stackParser:yi,integrations:[],release:"1.1.58",environment:e.environment||"production"}),n=new ce;n.setClient(t),n.setTags(e),t.init(),Dt=n}function se(e,t){Dt&&Dt.captureException(e,t?{captureContext:{extra:t}}:void 0)}function ct(e,t){pt("webPayToken",e),t&&pt("webPayRefreshToken",t)}function nr(){He("webPayToken"),He("webPayRefreshToken")}async function bi(e){const t=tn("webPayRefreshToken");if(t&&e.config.clientId)try{const n=await Nr(e.apiUrl,e.config.clientId,t,e.config.country);ct(n.access_token,n.refresh_token),e.accessToken=n.access_token;return}catch{He("webPayRefreshToken")}if(!e.config.clientId){e.config.onError({attributes:{message:e.t("errorMissingTrackClient")}});return}if(!e.config.trackId&&typeof e.config.onRequestNewTrackId=="function"&&(e.config.trackId=await e.config.onRequestNewTrackId()),!e.config.trackId){e.config.onError({attributes:{message:e.t("errorMissingTrackClient")}});return}try{const n=await nn(e.apiUrl,e.config.clientId,e.config.trackId,e.config.country);ct(n.access_token,n.refresh_token),e.accessToken=n.access_token}catch(n){if(typeof e.config.onRequestNewTrackId=="function"){e.config.trackId=await e.config.onRequestNewTrackId();const r=await nn(e.apiUrl,e.config.clientId,e.config.trackId,e.config.country);ct(r.access_token,r.refresh_token),e.accessToken=r.access_token}else throw n}}const Ei={kaspi_pay:`<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
9
9
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.89711 8.50443C10.4185 8.72365 10.6242 9.56386 10.7471 10.3459L10.7816 10.5699L10.8557 11.0301C11.0006 11.9088 11.303 13.7327 11.303 14.6845C11.303 14.9224 11.2806 15.105 11.2396 15.2053C11.1713 15.3599 10.9724 15.5082 10.6978 15.6319C10.0332 15.7846 9.33863 15.8671 8.62315 15.8671C8.54739 15.8671 8.47285 15.8637 8.39805 15.8616C8.10889 15.785 7.89156 15.657 7.77649 15.4821C7.42905 14.9542 7.40812 13.7781 7.40116 12.4037L7.40037 12.2443L7.39755 11.8324C7.38623 10.3774 7.37651 9.1229 7.94288 8.67272C8.16223 8.49957 8.47392 8.44225 8.89711 8.50443ZM5.58009 11.6722C5.90978 11.6548 6.12181 13.1684 6.16441 14.3162C6.19427 15.1152 6.10438 15.4439 5.96084 15.5619C5.79833 15.5113 5.63864 15.4565 5.48128 15.397C5.3763 15.219 5.29607 14.9389 5.2451 14.5721C5.08947 13.4193 5.22466 11.6925 5.58009 11.6722ZM13.8455 13.934C13.825 14.0391 13.796 14.1204 13.7602 14.1889C13.4783 14.4 13.1821 14.5938 12.872 14.7682C12.7733 14.7837 12.6856 14.7729 12.6427 14.7053C12.2318 14.0314 12.0775 11.9173 12.4752 11.7333C12.9936 11.4995 13.9224 13.5685 13.8455 13.934ZM8.50042 0C13.1296 0 16.8941 3.42166 16.9979 7.67934L17 7.82651V7.89454C16.9915 9.81778 16.2332 11.5773 14.9839 12.9392C14.9386 12.918 14.8559 12.8486 14.7062 12.6395C14.5512 12.4293 13.2148 10.5096 13.2148 8.30946C13.2148 7.87768 13.8816 7.20318 14.4717 6.61114C14.9128 6.16562 15.3306 5.74539 15.4845 5.4151C15.6804 4.98892 15.5433 4.69134 15.3265 4.59047C15.1302 4.50082 14.8355 4.56621 14.6287 4.90904C14.2893 5.46389 14.1805 5.56758 13.6855 5.93882C13.1984 6.30986 12.424 6.68338 12.424 6.19988C12.424 5.93882 12.8553 5.34757 13.0684 4.93314C13.286 4.51408 13.0515 4.21072 12.6022 4.21072C11.7198 4.21072 11.1341 5.2598 11.1341 5.62326C11.1341 5.98642 11.3229 6.03813 11.3229 6.46104C11.3229 6.88713 10.3548 7.4398 9.44281 7.4398C8.56481 7.4398 8.05566 7.27394 7.8447 6.80665L7.81777 6.74105L7.75678 6.57266C7.54046 5.98255 7.38528 5.55458 7.11514 5.10733C6.9717 4.87081 6.75038 4.70684 6.55897 4.56257C6.30881 4.38121 6.17902 4.21421 6.15193 4.08967C6.12696 3.96611 6.11352 3.73326 6.54117 3.19648C6.96793 2.66277 7.02775 2.25958 6.81418 2.05153C6.73678 1.97752 6.60482 1.93011 6.43535 1.93011C6.13562 1.93011 5.71912 2.07834 5.2899 2.48551C4.62267 3.12364 5.00146 3.72951 5.00146 3.99548C5.00146 4.26127 4.87922 4.41162 4.47882 4.77323C4.07547 5.13644 3.93627 5.44783 3.89014 6.69935C3.87247 7.3442 3.75079 7.71539 3.64156 8.04453C3.54718 8.33302 3.46038 8.60425 3.45569 8.99611C3.44822 9.43038 3.52566 9.71023 3.61604 10.0331C3.70477 10.3316 3.79902 10.6736 3.8594 11.2456C3.95544 12.1312 3.92205 12.8792 3.74744 13.6437L3.70084 13.8353L3.68995 13.8903C3.65419 14.0247 3.61168 14.1879 3.55423 14.249C1.4029 12.8228 0 10.4936 0 7.86072C0 3.51974 3.80561 0 8.50042 0Z" fill="#F14635"/>
|
|
10
10
|
</svg>
|
|
11
11
|
`,new_card:`<svg width="21" height="12" viewBox="0 0 21 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -298,7 +298,7 @@ Reason: ${B}`))})}_process(t){this._numProcessing++,t.then(n=>(this._numProcessi
|
|
|
298
298
|
<div class="choco-widget-bottom-bar-prerender">
|
|
299
299
|
<div class="choco-widget-payment-loading"></div>
|
|
300
300
|
</div>
|
|
301
|
-
`}function Ti(e,t,n,r={}){return rr(e,t,n,r)}function Li(e){return ut(e)}function Ri(e){if(typeof document>"u")return{mountTarget:null,isEmbedded:!1};const t=e.config.containerSelector;if(t){const n=document.querySelector(t);if(n instanceof HTMLElement)return{mountTarget:n,isEmbedded:!0}}return{mountTarget:document.body,isEmbedded:!1}}function or(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:n}=Ri(e);return t?(e.container.parentElement!==t&&t.appendChild(e.container),e.container.classList.toggle("choco-one-click-widget--embedded",n),!0):!1}function Oi(e){or(e)&&(e.container.style.setProperty("--choco-widget-accent-color",e.config.color),e.container.innerHTML=wi())}function Ni(e){var
|
|
301
|
+
`}function Ti(e,t,n,r={}){return rr(e,t,n,r)}function Li(e){return ut(e)}function Ri(e){if(typeof document>"u")return{mountTarget:null,isEmbedded:!1};const t=e.config.containerSelector;if(t){const n=document.querySelector(t);if(n instanceof HTMLElement)return{mountTarget:n,isEmbedded:!0}}return{mountTarget:document.body,isEmbedded:!1}}function or(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:n}=Ri(e);return t?(e.container.parentElement!==t&&t.appendChild(e.container),e.container.classList.toggle("choco-one-click-widget--embedded",n),!0):!1}function Oi(e){or(e)&&(e.container.style.setProperty("--choco-widget-accent-color",e.config.color),e.container.innerHTML=wi())}function Ni(e){var m,b,I,B,Q;if(e._destroyed||!or(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(),n=(m=e.checkoutContext)==null?void 0:m.data,r=e.config.currency||"KZT",o=(B=(I=(b=n==null?void 0:n.balance)==null?void 0:b.data)==null?void 0:I.money)==null?void 0:B[r],i=!e.config.disableUseBalance&&o>0?Z(o,e.config.locale,e.config.currency):null,c=(Q=n==null?void 0:n.cashback)==null?void 0:Q.data,u=(c==null?void 0:c.cashbackAmount)>0?Z(c.cashbackAmount,e.config.locale,e.config.currency):null,l=e._getPayableAmount(),h=l<e.config.amount;e.container.innerHTML=Pi({amountFormatted:Z(l,e.config.locale,e.config.currency),originalAmountFormatted:Z(e.config.amount,e.config.locale,e.config.currency),showOriginalAmount:h,paymentMethod:e.selectedPaymentMethod,methods:t,selectedMethod:e.selectedPaymentMethod,balanceFormatted:i,useBalance:e.useBalance,bonuses:e.config.bonuses,useBonuses:e.useBonuses,coupon:e.selectedCoupon,useCoupon:e.useCoupon,couponDisabled:e._isCouponDisabled(),cashbackFormatted:u,disabled:e.disabled,paymentMethodDisabled:e.paymentMethodDisabled,loading:e.loading,showFreedomBtn:!e.config.isFridge&&e.config.onFreedomLink!==null,freedomAmountFormatted:Z(Math.round(l*.94),e.config.locale,e.config.currency),t:(S,P)=>e.t(S,P),currency:r}),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});const y=e._getPaymentMethodForUserEvent();y!=null&&e._emitUserEvent("one_click_pay_method_resolved",{payment_method:y}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{var S;e._destroyed||(S=e.container)==null||S.classList.add("choco-one-click-widget--visible")})})}function Te(e){var r;const t=(r=e.container)==null?void 0:r.querySelector(".choco-widget-payment-methods");if(!t)return;const n=e.getAvailablePaymentMethods();t.innerHTML=Ti(n,e.selectedPaymentMethod,o=>e.t(o),{editMode:e.isPaymentSheetEditMode}),t.querySelectorAll("[data-action='delete-card']").forEach(o=>{o.addEventListener("click",i=>{i.stopPropagation();const c=JSON.parse(o.getAttribute("data-method")||"{}");Fi(e,c)})}),t.querySelectorAll("[data-action='select-method']").forEach(o=>{o.addEventListener("click",i=>{const c=JSON.parse(i.currentTarget.getAttribute("data-method")||"{}");ur(e,c)})})}function sr(e){var o,i,c;const t=(o=e.container)==null?void 0:o.querySelector(".choco-widget-payment-method"),n=(i=e.container)==null?void 0:i.querySelector(".choco-widget-method-name"),r=(c=e.container)==null?void 0:c.querySelector(".choco-widget-method-icon-wrapper");t&&e.selectedPaymentMethod&&(t.className=`choco-widget-payment-method ${e.selectedPaymentMethod.type}`),n&&e.selectedPaymentMethod&&(n.className=`choco-widget-method-name ${e.selectedPaymentMethod.type}`,n.textContent=e.selectedPaymentMethod.label),r&&e.selectedPaymentMethod&&(r.className=`choco-widget-method-icon-wrapper ${e.selectedPaymentMethod.type}`,r.innerHTML=Li(e.selectedPaymentMethod)),ir(e)}function lt(e){var m,b,I,B,Q,S;const t=(m=e.container)==null?void 0:m.querySelector(".choco-widget-pay-button"),n=(b=e.container)==null?void 0:b.querySelector(".choco-widget-google-pay-amount"),r=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-amount-label");let o=(B=e.container)==null?void 0:B.querySelector(".choco-widget-google-pay-amount-value"),i=(Q=e.container)==null?void 0:Q.querySelector(".choco-widget-google-pay-amount-value-number");const c=e._getPayableAmount(),u=Z(c,e.config.locale,e.config.currency),l=c<e.config.amount,h=Z(e.config.amount,e.config.locale,e.config.currency);if(t){const P=e.paymentMethodDisabled?e.t("login"):`${e.t("pay")} ${u}`;t.textContent=P,t.setAttribute("aria-label",P)}const y=(S=e.container)==null?void 0:S.querySelector(".choco-widget-freedom-card-btn");if(y&&(y.textContent=`от ${Z(Math.round(c*.94),e.config.locale,e.config.currency)} по карте Freedom`),r&&(r.textContent=`${e.t("total")} ${u}`),!l){o==null||o.remove();return}!o&&n&&(o=document.createElement("div"),o.className="choco-widget-google-pay-amount-value",o.innerHTML=`${e.t("instead")} <span class="choco-widget-google-pay-amount-value-number"></span>`,n.appendChild(o),i=o.querySelector(".choco-widget-google-pay-amount-value-number")),i?i.textContent=h:o&&(o.textContent=`${e.t("instead")} ${h}`)}function ir(e){var l,h,y,m,b,I,B,Q,S,P;const t=((l=e.selectedPaymentMethod)==null?void 0:l.type)==="google_pay",n=((h=e.selectedPaymentMethod)==null?void 0:h.type)==="apple_pay",r=t||n,o=(y=e.container)==null?void 0:y.querySelector(".choco-widget-pay-button"),i=(m=e.container)==null?void 0:m.querySelector(".choco-widget-google-pay-amount"),c=(b=e.container)==null?void 0:b.querySelector(".choco-widget-google-pay-row"),u=(I=e.container)==null?void 0:I.querySelector(".choco-widget-apple-pay-row");if(o==null||o.classList.toggle("choco-widget-pay-button--hidden",r),i==null||i.classList.toggle("choco-widget-google-pay-amount--hidden",!r),c==null||c.classList.toggle("choco-widget-google-pay-row--hidden",!t),u==null||u.classList.toggle("choco-widget-apple-pay-row--hidden",!n),t){Di(e);const k=(B=e.container)==null?void 0:B.querySelector('[data-action="apple-pay-button-slot"]');k&&(k.innerHTML="")}else if(n){e._googlePayButtonRenderVersion+=1;const k=(Q=e.container)==null?void 0:Q.querySelector('[data-action="google-pay-button-slot"]');k&&(k.innerHTML=""),Mi(e)}else{e._googlePayButtonRenderVersion+=1;const k=(S=e.container)==null?void 0:S.querySelector('[data-action="google-pay-button-slot"]'),R=(P=e.container)==null?void 0:P.querySelector('[data-action="apple-pay-button-slot"]');k&&(k.innerHTML=""),R&&(R.innerHTML="")}lt(e),ue(e)}async function Di(e){var c,u,l,h,y;const t=(c=e.container)==null?void 0:c.querySelector('[data-action="google-pay-button-slot"]');if(!t||(t.innerHTML="",((u=e.selectedPaymentMethod)==null?void 0:u.type)!=="google_pay"))return;const n=++e._googlePayButtonRenderVersion;try{await e._loadGooglePaySdk()}catch{e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}if(n!==e._googlePayButtonRenderVersion)return;if(!((y=(h=(l=window.google)==null?void 0:l.payments)==null?void 0:h.api)!=null&&y.PaymentsClient)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const r=e.config.environment==="production",i=new window.google.payments.api.PaymentsClient({environment:r?"PRODUCTION":"TEST"}).createButton({onClick:()=>e.handlePayment(),buttonType:"pay",buttonColor:"black",buttonLocale:e.config.locale||"ru",buttonSizeMode:"fill"});i.classList.add("choco-widget-google-pay-button"),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("font-size","16px","important"),i.style.setProperty("font-weight","bold","important"),i.querySelectorAll("*").forEach(m=>{m.style.setProperty("border-radius","12px","important"),m.style.setProperty("font-weight","bold","important"),m.style.setProperty("font-size","16px","important")}),t.appendChild(i),ue(e)}function Mi(e){var i,c;const t=(i=e.container)==null?void 0:i.querySelector('[data-action="apple-pay-button-slot"]');if(!t||(t.innerHTML="",((c=e.selectedPaymentMethod)==null?void 0:c.type)!=="apple_pay"))return;const n=document.createElement("div");n.className="choco-widget-apple-pay-button-wrapper";const r=document.createElement("button");r.type="button",r.className="choco-widget-apple-pay-button choco-widget-apple-pay-button--native",r.setAttribute("aria-label","Оплатить с Apple Pay"),r.style.setProperty("width","100%","important"),r.style.setProperty("height","52px","important"),r.style.setProperty("min-height","52px","important"),r.style.setProperty("border-radius","12px","important"),r.style.setProperty("-webkit-appearance","-apple-pay-button"),r.style.setProperty("-apple-pay-button-type","buy"),r.style.setProperty("-apple-pay-button-style","black"),r.addEventListener("click",()=>e.handlePayment());const o=document.createElement("div");o.className="choco-widget-apple-pay-button-overlay",o.setAttribute("aria-hidden","true"),o.innerHTML=`
|
|
302
302
|
<span class="choco-widget-apple-pay-button-text">Оплатить с</span>
|
|
303
303
|
<span class="choco-widget-apple-pay-button-icon">
|
|
304
304
|
<svg width="52" height="24" viewBox="0 0 52 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -312,4 +312,4 @@ Reason: ${B}`))})}_process(t){this._numProcessing++,t.then(n=>(this._numProcessi
|
|
|
312
312
|
</defs>
|
|
313
313
|
</svg>
|
|
314
314
|
</span>
|
|
315
|
-
`,n.appendChild(r),n.appendChild(o),t.appendChild(n),ue(e)}function ar(e){var o;if(!e.selectedCoupon)return;const t=e._isCouponDisabled();t&&e.useCoupon&&(e.useCoupon=!1);const n=(o=e.container)==null?void 0:o.querySelector('[data-action="toggle-coupon"]');if(!n)return;n.classList.toggle("choco-widget-balance-toggle--disabled",t);const r=n.querySelector("input[type='checkbox']");r&&(r.disabled=t,t&&(r.checked=!1))}function he(e){e.loading=!0,ue(e)}function q(e){var m,b,I,B,Q,S,P,k;e.loading=!1;const t=(m=e.container)==null?void 0:m.querySelector(".choco-widget-payment-method"),n=(b=e.container)==null?void 0:b.querySelector(".choco-widget-pay-button"),r=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-button-slot button"),o=(B=e.container)==null?void 0:B.querySelector(".choco-widget-apple-pay-button-slot button"),i=(Q=e.container)==null?void 0:Q.querySelector(".choco-widget-google-pay-amount"),c=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-row"),u=(P=e.container)==null?void 0:P.querySelector(".choco-widget-apple-pay-row"),l=(k=e.container)==null?void 0:k.querySelector(".choco-widget-balance-section"),h=e._isInteractionBlocked(),y=e.paymentMethodDisabled||h;t&&(t.disabled=y),n&&(n.disabled=h,n.classList.remove("choco-widget-pay-button--loading")),r&&(r.disabled=h),o&&(o.disabled=h),i==null||i.classList.toggle("choco-widget-wallet-blocked",h),i==null||i.setAttribute("aria-disabled",String(h)),c==null||c.classList.toggle("choco-widget-wallet-blocked",h),c==null||c.setAttribute("aria-disabled",String(h)),u==null||u.classList.toggle("choco-widget-wallet-blocked",h),u==null||u.setAttribute("aria-disabled",String(h)),l==null||l.classList.remove("disabled")}function ue(e){var b,I,B,Q,S,P,k,R,L;const t=(b=e.container)==null?void 0:b.querySelector(".choco-widget-payment-method"),n=(I=e.container)==null?void 0:I.querySelector(".choco-widget-pay-button"),r=(B=e.container)==null?void 0:B.querySelector(".choco-widget-freedom-card-btn"),o=(Q=e.container)==null?void 0:Q.querySelector(".choco-widget-google-pay-button-slot button"),i=(S=e.container)==null?void 0:S.querySelector(".choco-widget-apple-pay-button-slot button"),c=(P=e.container)==null?void 0:P.querySelector(".choco-widget-google-pay-amount"),u=(k=e.container)==null?void 0:k.querySelector(".choco-widget-google-pay-row"),l=(R=e.container)==null?void 0:R.querySelector(".choco-widget-apple-pay-row"),h=(L=e.container)==null?void 0:L.querySelector(".choco-widget-balance-section"),y=e._isInteractionBlocked(),m=e.paymentMethodDisabled||y;h==null||h.classList.toggle("disabled",y),t&&(t.disabled=m),n&&(n.disabled=y,n.classList.toggle("choco-widget-pay-button--loading",e.loading)),r&&(r.disabled=y),o&&(o.disabled=y),i&&(i.disabled=y),c==null||c.classList.toggle("choco-widget-wallet-blocked",y),c==null||c.setAttribute("aria-disabled",String(y)),u==null||u.classList.toggle("choco-widget-wallet-blocked",y),u==null||u.setAttribute("aria-disabled",String(y)),l==null||l.classList.toggle("choco-widget-wallet-blocked",y),l==null||l.setAttribute("aria-disabled",String(y))}function cr(e){var n;if(e._isInteractionBlocked())return;const t=(n=e.container)==null?void 0:n.querySelector('[data-sheet="payment"]');t&&(t.classList.add("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!0,Le(e))}function le(e){var n;const t=(n=e.container)==null?void 0:n.querySelector('[data-sheet="payment"]');if(t){At(e);const r=t.querySelector(".choco-widget-sheet-content");r&&(r.style.transform="",r.classList.remove("choco-widget-sheet-content--dragging")),t.classList.remove("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!1,e.isPaymentSheetEditMode&&(e.isPaymentSheetEditMode=!1,Te(e),Le(e))}}function Le(e){var l;const t=(l=e.container)==null?void 0:l.querySelector('[data-sheet="payment"]');if(!t)return;const n=t.querySelector(".choco-widget-sheet-title"),r=t.querySelector('[data-action="close-sheet"]'),o=t.querySelector('[data-action="edit-sheet"]'),i=t.querySelector('[data-action="previous-sheet"]'),u=e.getAvailablePaymentMethods().some(h=>h.type==="card");e.isPaymentSheetEditMode?(t.classList.add("choco-widget-payment-sheet--edit"),n&&(n.textContent=e.t("editCards")),r&&(r.style.display="none"),o&&(o.style.display="none"),i&&(i.style.display="")):(t.classList.remove("choco-widget-payment-sheet--edit"),t.classList.toggle("choco-widget-payment-sheet--no-cards",!u),n&&(n.textContent=e.t("paymentMethods")),r&&(r.style.display=""),o&&(o.style.display=u?"":"none"),i&&(i.style.display="none"))}function xt(e){if(!e.addCardActionUrl||!e.container)return;const t=e.container.querySelector('[data-sheet="add-card"]'),n=e.container.querySelector("#choco-widget-add-card-iframe");t&&n&&(n.src=e.addCardActionUrl,t.classList.add("choco-widget-payment-sheet--open"),t.style.display="flex",t.setAttribute("aria-hidden","false"),e.isAddCardViewOpen=!0,xi(e))}function Ee(e){var r,o;const t=(r=e.container)==null?void 0:r.querySelector('[data-sheet="add-card"]'),n=(o=e.container)==null?void 0:o.querySelector("#choco-widget-add-card-iframe");t&&(t.classList.remove("choco-widget-payment-sheet--open"),t.style.display="none",t.setAttribute("aria-hidden","true")),n&&(n.src="about:blank"),e.addCardActionUrl=null,e.isAddCardViewOpen=!1,Ui(e)}function xi(e){e._boundAddCardMessage=t=>{var n;e.isAddCardViewOpen&&(n=t.data)!=null&&n.message&&t.origin==="https://rahmetapp.kz"&&he(e)},window.addEventListener("message",e._boundAddCardMessage)}function Ui(e){e._boundAddCardMessage&&(window.removeEventListener("message",e._boundAddCardMessage),e._boundAddCardMessage=null)}function Fi(e,t){var c;e._pendingDeleteMethod=t;const n=(c=e.container)==null?void 0:c.querySelector('[data-sheet="payment"]');if(!n)return;n.classList.add("choco-widget-payment-sheet--delete-confirm");const r=n.querySelector(".choco-widget-sheet-title"),o=n.querySelector('[data-action="edit-sheet"]'),i=n.querySelector('[data-action="previous-sheet"]');r&&(r.textContent=e.t("confirmDeleteCard")),o&&(o.style.display="none"),i&&(i.style.display="none")}function At(e){var n;e._pendingDeleteMethod=null,Ut(e,!1);const t=(n=e.container)==null?void 0:n.querySelector('[data-sheet="payment"]');t==null||t.classList.remove("choco-widget-payment-sheet--delete-confirm"),Le(e)}function Ut(e,t){var i,c,u;const n=(i=e.container)==null?void 0:i.querySelector(".choco-widget-sheet-delete-confirm-actions"),r=(c=e.container)==null?void 0:c.querySelector('[data-action="confirm-delete-cancel"]'),o=(u=e.container)==null?void 0:u.querySelector('[data-action="confirm-delete-submit"]');n==null||n.classList.toggle("choco-widget-sheet-delete-confirm-actions--loading",t),r&&(r.disabled=t),o&&(o.disabled=t,o.classList.toggle("choco-widget-delete-confirm-btn--loading",t))}async function Xi(e,t){var r,o;const n=t==null?void 0:t.cardId;if(!(!n||(t==null?void 0:t.type)!=="card"))try{await Dr(e.apiUrl,e._getApiConfig(),n),e.checkoutContext=await gt(e.apiUrl,e._getApiConfig()),((r=e.selectedPaymentMethod)==null?void 0:r.type)==="card"&&((o=e.selectedPaymentMethod)==null?void 0:o.cardId)===n&&(e.selectedPaymentMethod=ht(e.checkoutContext.data,e._getKaspiOptions()),e._emitPaymentMethodSelected(),sr(e)),Te(e),e.config.onSuccess({message:e.t("cardDeleted")}),e.config.onCardDeleted&&e.config.onCardDeleted({cardId:n})}catch(i){e.config.onError({attributes:{message:(i==null?void 0:i.message)||e.t("paymentError")}})}}function ur(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}),le(e),e.handlePayment();return}e._emitUserEvent("one_click_pay_method_resolved",{payment_method:e._getPaymentMethodForUserEvent()}),Te(e),le(e),sr(e)}}function lr(e,t){var r;const n=t.type||((r=t.data)==null?void 0:r.type);if(!n){console.warn("Unknown event format:",t);return}switch(n){case"order.paid":e._orderStatusResolved=!0,pe(e),dr(e,t);break;case"order.failed":e._orderStatusResolved=!0,pe(e),fr(e,t);break;case"order.action_required":Hi(e,t);break;default:console.warn("Unknown event type:",n)}}function pe(e){e._orderStatusPollingId&&(clearInterval(e._orderStatusPollingId),e._orderStatusPollingId=null)}function ve(e,t){pe(e),e._orderStatusResolved=!1;const n=6e3,r=5;let o=0;const i=async()=>{if(!e._orderStatusResolved){if(o>=r){pe(e),q(e),e.config.onError({attributes:{message:e.t("errorNoServerResponseRetry")}});return}o+=1;try{const{data:c}=await xr(e.apiUrl,e._getApiConfig(),String(t)),u=c==null?void 0:c.status,l=(c==null?void 0:c.payload)||{};if(u==="success"){e._orderStatusResolved=!0,pe(e),dr(e,{id:String(l.id||t),attributes:{amount:l.amount,paid_at:l.paid_at||""}});return}u==="fail"&&(e._orderStatusResolved=!0,pe(e),fr(e,{id:String(l.id||t),attributes:{message:l.message||e.t("paymentError")}}))}catch(c){console.warn("[Polling] checkOrderStatus error:",c)}}};e._orderStatusPollingId=setInterval(i,n),i()}function Ft(){return typeof document>"u"?!1:document.hidden||document.visibilityState==="hidden"}function Ar(e,t){q(e),e.config.onSuccess(t)}function Xt(e){if(!e._pendingSuccessPayload||Ft())return;const t=e._pendingSuccessPayload;e._pendingSuccessPayload=null,Ar(e,t)}function dr(e,t){var o,i;e.isAddCardViewOpen&&Ee(e);const n=t.attributes||((o=t.data)==null?void 0:o.attributes)||{},r={id:t.id||((i=t.data)==null?void 0:i.id),attributes:n};if(Ft()){e._pendingSuccessPayload=r;return}Ar(e,r)}function fr(e,t){var r,o;e.isAddCardViewOpen&&Ee(e),q(e);const n=t.attributes||((r=t.data)==null?void 0:r.attributes)||{};e.config.onError({id:t.id||((o=t.data)==null?void 0:o.id),attributes:n})}function Hi(e,t){var i,c,u;const n=t.attributes||((i=t.data)==null?void 0:i.attributes)||{},r=n.action_link||n.action_url,o=n.action_url_type||n.action_type||"redirect";if(!r){console.error(e.t("errorActionUrlMissing")),e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,q(e),e.config.onError({attributes:{message:e.t("errorNoServerResponse")}}));return}if(e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout()),o==="inner"){e.addCardActionUrl=r,q(e),e._showAddCardView();return}if(((c=e.selectedPaymentMethod)==null?void 0:c.type)==="kaspi_pay"){const l=t.id||((u=t.data)==null?void 0:u.id);if(l&&!e._orderStatusResolved&&!e._orderStatusPollingId&&ve(e,String(l)),typeof e.config.onKaspiLink=="function"){e.config.onKaspiLink({action_link:r,action_url:r,action_type:o,event:t});return}}window.location.href=r}async function ji(e){var n,r,o,i,c;if(!e.selectedPaymentMethod){e.config.onError({attributes:{message:e.t("errorPaymentMethodNotSelected")}});return}const{checkoutOptions:t}=e._getPaymentBreakdown();if(e._isBalanceFullyCoveringAmount()){he(e);try{const u=await rn(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await hr(e);const l=(u==null?void 0:u.id)??((n=u==null?void 0:u.data)==null?void 0:n.id);return l&&ve(e,String(l)),u}catch(u){throw q(e),se(u,{paymentMethod:"balance"}),e.config.onError({attributes:{message:e._resolveErrorMessage(u)}}),u}}if(e.selectedPaymentMethod.type==="new_card"){await Ji(e,t);return}if(e.selectedPaymentMethod.type==="apple_pay"){await qi(e,t);return}if(e.selectedPaymentMethod.type==="google_pay"){await zi(e,t);return}he(e);try{const u=await rn(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await hr(e);const l=(u==null?void 0:u.id)??((r=u==null?void 0:u.data)==null?void 0:r.id);if(l&&ve(e,String(l)),((o=e.selectedPaymentMethod)==null?void 0:o.type)==="kaspi_pay"){const h=(u==null?void 0:u.attributes)||((i=u==null?void 0:u.data)==null?void 0:i.attributes)||{},y=h.action_link||h.action_url,m=h.action_url_type||h.action_type||"redirect";if(y)return typeof e.config.onKaspiLink=="function"?(e.config.onKaspiLink({action_link:y,action_url:y,action_type:m,event:u}),u):(window.location.href=y,u)}return u}catch(u){throw q(e),se(u,{paymentMethod:((c=e.selectedPaymentMethod)==null?void 0:c.type)||"card"}),e.config.onError({message:e._resolveErrorMessage(u)}),u}}async function hr(e){var t,n;if(!(((t=e.selectedPaymentMethod)==null?void 0:t.type)!=="card"||!((n=e.selectedPaymentMethod)!=null&&n.cardId)))try{await Mr(e.apiUrl,e._getApiConfig(),e.selectedPaymentMethod.cardId)}catch(r){console.warn("Failed to mark selected card as default:",r)}}async function Ji(e,t){he(e),e.waitingForNewCardAction=!0,e._setNewCardActionTimeout();try{await Ur(e.apiUrl,e._getApiConfig(),e.deviceId,t)}catch(n){e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout(),q(e),se(n,{paymentMethod:"new_card"}),e.config.onError({attributes:{message:e._resolveErrorMessage(n)}}),console.error("New card payment error:",n)}}let Re=null;async function qi(e,t){const n=window.ApplePaySession;if(!n||!n.canMakePayments()){e.config.onError({attributes:{message:e.t("errorApplePayUnsupported")}});return}if(Re)return;he(e);const r={countryCode:e.config.currency==="GEL"?"GE":"KZ",currencyCode:e.config.currency,supportedNetworks:["visa","masterCard"],merchantCapabilities:["supports3DS"],total:{label:e.config.merchantName||"Choco",amount:String(e._getPayableAmount()),type:"final"}},o=new n(3,r);Re=o,o.onvalidatemerchant=async i=>{var c,u;try{let l;try{l=await on(e.apiUrl,e._getApiConfig(),i.validationURL)}catch(m){if(m.status===401)await e._obtainTokenByRefreshOrTrackId(),l=await on(e.apiUrl,e._getApiConfig(),i.validationURL);else throw m}const h=((u=(c=l==null?void 0:l.data)==null?void 0:c.attributes)==null?void 0:u.session)||l,y=JSON.parse(atob(h));o.completeMerchantValidation(y)}catch(l){console.error("Apple Pay session error:",l),se(l,{paymentMethod:"apple_pay",phase:"merchant_validation"}),q(e),o.abort(),e.config.onError({attributes:{message:e.t("errorApplePayInit")}})}},o.onpaymentauthorized=async i=>{var c;try{if(typeof e.config.onBeforeCheckout=="function"){const h=await e.config.onBeforeCheckout();h&&typeof h=="object"&&Object.assign(e.config,h)}const u=await Xr(e.apiUrl,e._getApiConfig(),e.deviceId,i.payment,t);o.completePayment(n.STATUS_SUCCESS),Re=null;const l=(u==null?void 0:u.id)??((c=u==null?void 0:u.data)==null?void 0:c.id);l&&!e._orderStatusResolved&&ve(e,String(l))}catch(u){console.error("Apple Pay payment error:",u),se(u,{paymentMethod:"apple_pay",phase:"payment_authorized"}),o.completePayment(n.STATUS_FAILURE),Re=null,q(e),e.config.onError({attributes:{message:e._resolveErrorMessage(u,"errorApplePayPayment")}})}},o.oncancel=()=>{var i;if(Re=null,q(e),((i=e.selectedPaymentMethod)==null?void 0:i.type)==="apple_pay"){e.config.onError({attributes:{message:e.t("errorApplePayInterrupted")}});return}e.config.onCancel()},o.begin()}async function zi(e,t){var S,P,k,R,L,z;const n=(S=e.checkoutContext)==null?void 0:S.data,r=((k=(P=n==null?void 0:n.payment_methods)==null?void 0:P.data)==null?void 0:k.attributes)||{},o=r.google_pay_settings||{};if(!(r.payment_method_google_pay==="enabled"||r.payment_method_google_pay===!0)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const c=o==null?void 0:o.gateway,u=o==null?void 0:o.merchant_id;if(!c||!u){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}const l=e.config.environment==="production",h=(o==null?void 0:o.merchant_name)||"Choco",y=o==null?void 0:o.google_merchant_id;if(l&&!y){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}if(e.config.isNativeAndroid){await Ki(e,t,{gateway:c,gatewayMerchantId:u});return}const m=Number(e._getCheckoutAmount()).toFixed(2);try{await e._loadGooglePaySdk()}catch(D){console.error("Google Pay SDK load error:",D),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 I=[{type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:["VISA","MASTERCARD"],billingAddressRequired:!1},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:c,gatewayMerchantId:u}}}],B={apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:I,transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Итого",totalPrice:m,currencyCode:e.config.currency,countryCode:e.config.currency==="GEL"?"GE":"KZ"},merchantInfo:l?{merchantId:y,merchantName:h}:{merchantName:h}},Q=new b.payments.api.PaymentsClient({environment:l?"PRODUCTION":"TEST"});try{const D=await Q.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:I});if(!(D!=null&&D.result)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}he(e);const G=await Q.loadPaymentData(B),K=(L=(R=G==null?void 0:G.paymentMethodData)==null?void 0:R.tokenizationData)==null?void 0:L.token;if(!K)throw new Error(e.t("errorGooglePayPayment"));const J=JSON.parse(K),M=await sn(e.apiUrl,e._getApiConfig(),e.deviceId,J,t),v=(M==null?void 0:M.id)??((z=M==null?void 0:M.data)==null?void 0:z.id);v&&ve(e,String(v))}catch(D){q(e),D.statusCode==="CANCELED"?e.config.onCancel():(se(D,{paymentMethod:"google_pay"}),e.config.onError({attributes:{message:e._resolveErrorMessage(D,"errorGooglePayPayment")}}),console.error("Google Pay error:",D))}}async function Ki(e,t,n){var r;if(!e.config.onPayWithGooglePay){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}he(e);try{const o=await e.config.onPayWithGooglePay({amount:Number(e._getCheckoutAmount()),gateway:n.gateway,gatewayMerchantId:n.gatewayMerchantId}),i=JSON.parse(o),c=await sn(e.apiUrl,e._getApiConfig(),e.deviceId,i,t),u=(c==null?void 0:c.id)??((r=c==null?void 0:c.data)==null?void 0:r.id);u&&ve(e,String(u))}catch(o){q(e),o.statusCode==="CANCELED"?e.config.onCancel():(se(o,{paymentMethod:"google_pay_native"}),e.config.onError({attributes:{message:e._resolveErrorMessage(o,"errorGooglePayPayment")}}),console.error("Google Pay native error:",o))}}function Gi(e){var c,u,l,h,y,m,b,I,B,Q,S,P;const t=e.container;(c=t.querySelector('[data-action="freedom-card"]'))==null||c.addEventListener("click",()=>{e.config.onFreedomLink&&e.config.onFreedomLink()}),(u=t.querySelector('[data-action="pay"]'))==null||u.addEventListener("click",()=>e.handlePayment()),(l=t.querySelector('[data-action="change-method"]'))==null||l.addEventListener("click",()=>cr(e)),t.querySelectorAll('[data-action="close"]').forEach(k=>k.addEventListener("click",()=>e.close())),(h=t.querySelector('[data-action="close-sheet"]'))==null||h.addEventListener("click",()=>{e._pendingDeleteMethod?At(e):le(e)}),(y=t.querySelector('[data-action="edit-sheet"]'))==null||y.addEventListener("click",()=>{e.isPaymentSheetEditMode=!0,Te(e),Le(e)}),(m=t.querySelector('[data-action="previous-sheet"]'))==null||m.addEventListener("click",()=>{e.isPaymentSheetEditMode=!1,Te(e),Le(e)}),(b=t.querySelector('[data-action="close-add-card"]'))==null||b.addEventListener("click",()=>Ee(e)),(I=t.querySelector('[data-action="confirm-delete-cancel"]'))==null||I.addEventListener("click",()=>At(e)),(B=t.querySelector('[data-action="confirm-delete-submit"]'))==null||B.addEventListener("click",()=>{if(e._pendingDeleteMethod){const k=e._pendingDeleteMethod;Ut(e,!0),Xi(e,k).then(()=>le(e)).finally(()=>Ut(e,!1))}}),t.querySelectorAll(".choco-widget-method-item").forEach(k=>{k.addEventListener("click",R=>{const L=JSON.parse(R.currentTarget.getAttribute("data-method")||"{}");ur(e,L)})});const n=t.querySelector('[data-sheet="payment"]');n&&(n.addEventListener("click",k=>{k.target===n&&le(e)}),Yi(e,n));const r=t.querySelector('[data-action="toggle-balance"]');r&&((Q=r.querySelector("input[type='checkbox']"))==null||Q.addEventListener("change",k=>{e.useBalance=k.target.checked,ar(e),e._updatePayButtonAmount()}));const o=t.querySelector('[data-action="toggle-bonuses"]');o&&((S=o.querySelector("input[type='checkbox']"))==null||S.addEventListener("change",k=>{e.useBonuses=k.target.checked,e.config.onAppliedBonus(e.useBonuses),ar(e),e._updatePayButtonAmount()}));const i=t.querySelector('[data-action="toggle-coupon"]');i&&((P=i.querySelector("input[type='checkbox']"))==null||P.addEventListener("change",k=>{e.useCoupon=k.target.checked,e._updatePayButtonAmount(),e._emitCouponSuppressingCashback()})),document.removeEventListener("keydown",e._boundKeyDown),document.addEventListener("keydown",e._boundKeyDown),ir(e)}function Wi(e,t){var n,r;e.isOpen&&(t.key==="Escape"&&(t.preventDefault(),e._pendingDeleteMethod?At(e):e.isAddCardViewOpen?Ee(e):e.isPaymentSheetOpen?le(e):e.close()),t.key==="Enter"&&((r=(n=t.target)==null?void 0:n.dataset)==null?void 0:r.action)==="pay"&&(t.preventDefault(),e.handlePayment()))}function Yi(e,t){const n=t.querySelector('[data-action="sheet-drag-handle"]'),r=t.querySelector(".choco-widget-sheet-content");if(!n||!r)return;const o=80;let i=0,c=0;const u=h=>{c=h.clientY;const y=Math.max(0,c-i);r.style.transform=`translateY(${y}px)`},l=h=>{n.releasePointerCapture(h.pointerId),n.removeEventListener("pointermove",u),n.removeEventListener("pointerup",l),n.removeEventListener("pointercancel",l);const y=Math.max(0,c-i);if(r.classList.remove("choco-widget-sheet-content--dragging"),y>=o){r.style.transform="translateY(100%)";const m=()=>{r.removeEventListener("transitionend",m),r.style.transform="",le(e)};r.addEventListener("transitionend",m)}else r.style.transform=""};n.addEventListener("pointerdown",h=>{!e.isPaymentSheetOpen||h.button!==0||(h.preventDefault(),i=h.clientY,c=h.clientY,r.classList.add("choco-widget-sheet-content--dragging"),n.setPointerCapture(h.pointerId),n.addEventListener("pointermove",u),n.addEventListener("pointerup",l),n.addEventListener("pointercancel",l))})}class ge{static _getAuthStorageValue(t){return tn(t)}static _setAuthStorageValue(t,n){pt(t,n)}static _removeAuthStorageValue(t){He(t)}static async logout(){nr()}constructor(t){this.config=Hr(t),this.accessToken=null,this.deviceId=Gt(),this.apiUrl=vr(this.config.environment),this.translations=Se,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=n=>Wi(this,n),this._boundVisibilityChange=()=>this._onVisibilityChange(),this._boundWindowFocus=()=>this._onWindowFocus(),this._boundPageShow=()=>this._onPageShow(),Ci({clientId:String(this.config.clientId),terminalId:String(this.config.terminalId),environment:this.config.environment})}t(t,n={}){var i;const r=this.config.locale||"ru",o=((i=this.translations[r])==null?void 0:i[t])||this.translations.ru[t];return typeof o!="string"?t:o.replace(/{(\w+)}/g,(c,u)=>Object.prototype.hasOwnProperty.call(n,u)?String(n[u]):c)}_resolveErrorMessage(t,n="paymentError"){return(t==null?void 0:t.message)||this.t(n)}_getApiConfig(){return{...this.config,accessToken:this.accessToken}}_isInteractionBlocked(){return this.disabled||this.loading}_getBalanceAmount(){var o,i,c,u;const t=(u=(c=(i=(o=this.checkoutContext)==null?void 0:o.data)==null?void 0:i.balance)==null?void 0:c.data)==null?void 0:u.money,n=this.config.currency||"KZT",r=Number(t==null?void 0:t[n]);return Number.isFinite(r)&&r>0?r:0}_getBonusesAmount(){var n;const t=Number((n=this.config.bonuses)==null?void 0:n.amount);return Number.isFinite(t)&&t>0?t:0}_getBonusesPercent(){var n;const t=Number((n=this.config.bonuses)==null?void 0:n.percent);return!Number.isFinite(t)||t<=0?0:t>=100?100:t}_getAvailableBonus(){var n;const t=Number((n=this.config.bonuses)==null?void 0:n.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,n=this._getBalanceAmount(),r=this.useBalance?Math.min(n,t):0,o=t-r,i=this.useBalance&&r>=t,c=this.useBonuses?this._getAvailableBonus():0,u=Math.max(o-c,0),l=this._getCouponDiscount(),h=Math.max(u-l,0),y=this.useBalance?t:h,m=this.useBalance&&!i,I=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:h,checkoutOptions:{checkoutAmount:y,forceBalanceMethod:i,useBalance:m,voucher:I}}}_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,n={}){typeof this.config.onUserEvent=="function"&&this.config.onUserEvent({eventName:t,eventProperties:n})}_emitPaymentMethodSelected(t=this.selectedPaymentMethod){typeof this.config.onPaymentMethodSelected=="function"&&this.config.onPaymentMethodSelected(t||null)}_emitCouponSuppressingCashback(){var n;const t=this.useCoupon&&((n=this.selectedCoupon)==null?void 0:n.suppresses_cashback)===!0;this.config.onCouponSuppressingCashback(t)}_attachEventListeners(){Gi(this)}_updatePayButtonAmount(){lt(this)}_showAddCardView(){xt(this)}_closeAddCardView(){Ee(this)}_setNewCardActionTimeout(){this._clearNewCardActionTimeout(),this.newCardActionRequiredTimeoutId=setTimeout(()=>{this.waitingForNewCardAction&&(this.waitingForNewCardAction=!1,q(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,n){ct(t,n)}_clearAuthStorage(){nr()}_getAuthStorageValue(t){return ge._getAuthStorageValue(t)}_setAuthStorageValue(t,n){ge._setAuthStorageValue(t,n)}_removeAuthStorageValue(t){ge._removeAuthStorageValue(t)}_loadGooglePaySdk(){var t,n;return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Google Pay SDK requires browser environment")):(n=(t=window.google)==null?void 0:t.payments)!=null&&n.api?Promise.resolve():this._googlePayScriptPromise?this._googlePayScriptPromise:(this._googlePayScriptPromise=new Promise((r,o)=>{const i=document.querySelector('script[data-choco-google-pay-sdk="true"]');if(i){i.addEventListener("load",()=>r(),{once:!0}),i.addEventListener("error",()=>o(new Error("Failed to load Google Pay SDK")),{once:!0});return}const c=document.createElement("script");c.src="https://pay.google.com/gp/p/js/pay.js",c.async=!0,c.defer=!0,c.setAttribute("data-choco-google-pay-sdk","true"),c.onload=()=>r(),c.onerror=()=>o(new Error("Failed to load Google Pay SDK")),document.head.appendChild(c)}).finally(()=>{var r,o;(o=(r=window.google)==null?void 0:r.payments)!=null&&o.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(){Ft()||Xt(this)}_onWindowFocus(){Xt(this)}_onPageShow(){Xt(this)}async _obtainTokenByRefreshOrTrackId(){await bi(this)}async _fetchCheckoutContextWithRetry(){try{this.checkoutContext=await gt(this.apiUrl,this._getApiConfig())}catch(t){if(t.status===401)this._removeAuthStorageValue("webPayToken"),await this._obtainTokenByRefreshOrTrackId(),this.checkoutContext=await gt(this.apiUrl,this._getApiConfig());else throw t}}async _fetchCoupons(){try{const t=await Fr(this.apiUrl,this._getApiConfig()),r=(Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[]).filter(o=>Number(o.reward_amount)>0).sort((o,i)=>o.sort_weight-i.sort_weight);this.selectedCoupon=r.length>0?r[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(),n=this.useBalance?Math.min(t,this.config.amount):0,r=this.config.amount-n,o=this.useBonuses?Math.min(this._getAvailableBonus(),r):0;return r-o<this.selectedCoupon.reward_amount}_prerender(){Oi(this)}_render(){Ni(this)}async init(){var t,n;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(o){const i=o;return this.config.onError({attributes:{message:i.message}}),!1}if(this._destroyed||(await this._fetchCoupons(),this._emitCouponSuppressingCashback(),this._destroyed))return!1;const r=Vt((n=(t=this.checkoutContext)==null?void 0:t.data)==null?void 0:n.socket_connections,o=>lr(this,o));return r&&(this.centrifuge=r.centrifuge),this.selectedPaymentMethod=ht(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this._render(),!0}catch(r){return console.error(`${this.t("errorWidgetInit")}:`,r),se(r,{phase:"init"}),this.config.onError({attributes:{message:r.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(),pe(this),this._pendingSuccessPayload=null,this._detachLifecycleListeners(),this.isAddCardViewOpen&&Ee(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 n;(n=this.container)==null||n.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?Rr(this.checkoutContext.data,n=>this.t(n),this._getKaspiOptions()):[]}async createOrder(){return ji(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(){cr(this)}closePaymentSheet(){le(this)}async updateAmount(t){var n;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 r=this.isPaymentSheetOpen,o=this.isAddCardViewOpen;if(this._render(),ue(this),r){const i=(n=this.container)==null?void 0:n.querySelector('[data-sheet="payment"]');i&&(i.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}o&&xt(this);return}lt(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),lt(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 n=this.isPaymentSheetOpen,r=this.isAddCardViewOpen;if(this._render(),ue(this),n){const o=this.container.querySelector('[data-sheet="payment"]');o&&(o.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}r&&xt(this)}async setLoading(t){this.loading=!!t,ue(this)}async setDisabled(t){this.disabled=!!t,ue(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 ge.logout(),this.accessToken=null}async updateTrackId(t){var n,r;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(i){const c=i;return this.config.onError({attributes:{message:c.message}}),!1}await this._fetchCoupons(),this._emitCouponSuppressingCashback(),this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge=null);const o=Vt((r=(n=this.checkoutContext)==null?void 0:n.data)==null?void 0:r.socket_connections,i=>lr(this,i));return o&&(this.centrifuge=o.centrifuge),this.selectedPaymentMethod=ht(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this.paymentMethodDisabled=!1,this._render(),!0}catch(o){return console.error(`${this.t("errorWidgetInit")}:`,o),se(o,{phase:"updateTrackId"}),this.config.onError({attributes:{message:o.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 onFreedomLink(t){if(typeof t!="function")throw new Error("onFreedomLink callback must be a function");this.config.onFreedomLink=t}async onAppliedBonus(t){if(typeof t!="function")throw new Error("onAppliedBonus callback must be a function");this.config.onAppliedBonus=t}async onCouponSuppressingCashback(t){if(typeof t!="function")throw new Error("onCouponSuppressingCashback callback must be a function");this.config.onCouponSuppressingCashback=t}}return typeof window<"u"&&(window.ChocoOneClickWidget=ge),ge}));
|
|
315
|
+
`,n.appendChild(r),n.appendChild(o),t.appendChild(n),ue(e)}function ar(e){var o;if(!e.selectedCoupon)return;const t=e._isCouponDisabled();t&&e.useCoupon&&(e.useCoupon=!1);const n=(o=e.container)==null?void 0:o.querySelector('[data-action="toggle-coupon"]');if(!n)return;n.classList.toggle("choco-widget-balance-toggle--disabled",t);const r=n.querySelector("input[type='checkbox']");r&&(r.disabled=t,t&&(r.checked=!1))}function he(e){e.loading=!0,ue(e)}function q(e){var m,b,I,B,Q,S,P,k;e.loading=!1;const t=(m=e.container)==null?void 0:m.querySelector(".choco-widget-payment-method"),n=(b=e.container)==null?void 0:b.querySelector(".choco-widget-pay-button"),r=(I=e.container)==null?void 0:I.querySelector(".choco-widget-google-pay-button-slot button"),o=(B=e.container)==null?void 0:B.querySelector(".choco-widget-apple-pay-button-slot button"),i=(Q=e.container)==null?void 0:Q.querySelector(".choco-widget-google-pay-amount"),c=(S=e.container)==null?void 0:S.querySelector(".choco-widget-google-pay-row"),u=(P=e.container)==null?void 0:P.querySelector(".choco-widget-apple-pay-row"),l=(k=e.container)==null?void 0:k.querySelector(".choco-widget-balance-section"),h=e._isInteractionBlocked(),y=e.paymentMethodDisabled||h;t&&(t.disabled=y),n&&(n.disabled=h,n.classList.remove("choco-widget-pay-button--loading")),r&&(r.disabled=h),o&&(o.disabled=h),i==null||i.classList.toggle("choco-widget-wallet-blocked",h),i==null||i.setAttribute("aria-disabled",String(h)),c==null||c.classList.toggle("choco-widget-wallet-blocked",h),c==null||c.setAttribute("aria-disabled",String(h)),u==null||u.classList.toggle("choco-widget-wallet-blocked",h),u==null||u.setAttribute("aria-disabled",String(h)),l==null||l.classList.remove("disabled")}function ue(e){var b,I,B,Q,S,P,k,R,L;const t=(b=e.container)==null?void 0:b.querySelector(".choco-widget-payment-method"),n=(I=e.container)==null?void 0:I.querySelector(".choco-widget-pay-button"),r=(B=e.container)==null?void 0:B.querySelector(".choco-widget-freedom-card-btn"),o=(Q=e.container)==null?void 0:Q.querySelector(".choco-widget-google-pay-button-slot button"),i=(S=e.container)==null?void 0:S.querySelector(".choco-widget-apple-pay-button-slot button"),c=(P=e.container)==null?void 0:P.querySelector(".choco-widget-google-pay-amount"),u=(k=e.container)==null?void 0:k.querySelector(".choco-widget-google-pay-row"),l=(R=e.container)==null?void 0:R.querySelector(".choco-widget-apple-pay-row"),h=(L=e.container)==null?void 0:L.querySelector(".choco-widget-balance-section"),y=e._isInteractionBlocked(),m=e.paymentMethodDisabled||y;h==null||h.classList.toggle("disabled",y),t&&(t.disabled=m),n&&(n.disabled=y,n.classList.toggle("choco-widget-pay-button--loading",e.loading)),r&&(r.disabled=y),o&&(o.disabled=y),i&&(i.disabled=y),c==null||c.classList.toggle("choco-widget-wallet-blocked",y),c==null||c.setAttribute("aria-disabled",String(y)),u==null||u.classList.toggle("choco-widget-wallet-blocked",y),u==null||u.setAttribute("aria-disabled",String(y)),l==null||l.classList.toggle("choco-widget-wallet-blocked",y),l==null||l.setAttribute("aria-disabled",String(y))}function cr(e){var n;if(e._isInteractionBlocked())return;const t=(n=e.container)==null?void 0:n.querySelector('[data-sheet="payment"]');t&&(t.classList.add("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!0,Le(e))}function le(e){var n;const t=(n=e.container)==null?void 0:n.querySelector('[data-sheet="payment"]');if(t){At(e);const r=t.querySelector(".choco-widget-sheet-content");r&&(r.style.transform="",r.classList.remove("choco-widget-sheet-content--dragging")),t.classList.remove("choco-widget-payment-sheet--open"),e.isPaymentSheetOpen=!1,e.isPaymentSheetEditMode&&(e.isPaymentSheetEditMode=!1,Te(e),Le(e))}}function Le(e){var l;const t=(l=e.container)==null?void 0:l.querySelector('[data-sheet="payment"]');if(!t)return;const n=t.querySelector(".choco-widget-sheet-title"),r=t.querySelector('[data-action="close-sheet"]'),o=t.querySelector('[data-action="edit-sheet"]'),i=t.querySelector('[data-action="previous-sheet"]'),u=e.getAvailablePaymentMethods().some(h=>h.type==="card");e.isPaymentSheetEditMode?(t.classList.add("choco-widget-payment-sheet--edit"),n&&(n.textContent=e.t("editCards")),r&&(r.style.display="none"),o&&(o.style.display="none"),i&&(i.style.display="")):(t.classList.remove("choco-widget-payment-sheet--edit"),t.classList.toggle("choco-widget-payment-sheet--no-cards",!u),n&&(n.textContent=e.t("paymentMethods")),r&&(r.style.display=""),o&&(o.style.display=u?"":"none"),i&&(i.style.display="none"))}function xt(e){if(!e.addCardActionUrl||!e.container)return;const t=e.container.querySelector('[data-sheet="add-card"]'),n=e.container.querySelector("#choco-widget-add-card-iframe");t&&n&&(n.src=e.addCardActionUrl,t.classList.add("choco-widget-payment-sheet--open"),t.style.display="flex",t.setAttribute("aria-hidden","false"),e.isAddCardViewOpen=!0,xi(e))}function Ee(e){var r,o;const t=(r=e.container)==null?void 0:r.querySelector('[data-sheet="add-card"]'),n=(o=e.container)==null?void 0:o.querySelector("#choco-widget-add-card-iframe");t&&(t.classList.remove("choco-widget-payment-sheet--open"),t.style.display="none",t.setAttribute("aria-hidden","true")),n&&(n.src="about:blank"),e.addCardActionUrl=null,e.isAddCardViewOpen=!1,Ui(e)}function xi(e){e._boundAddCardMessage=t=>{var n;e.isAddCardViewOpen&&(n=t.data)!=null&&n.message&&t.origin==="https://rahmetapp.kz"&&he(e)},window.addEventListener("message",e._boundAddCardMessage)}function Ui(e){e._boundAddCardMessage&&(window.removeEventListener("message",e._boundAddCardMessage),e._boundAddCardMessage=null)}function Fi(e,t){var c;e._pendingDeleteMethod=t;const n=(c=e.container)==null?void 0:c.querySelector('[data-sheet="payment"]');if(!n)return;n.classList.add("choco-widget-payment-sheet--delete-confirm");const r=n.querySelector(".choco-widget-sheet-title"),o=n.querySelector('[data-action="edit-sheet"]'),i=n.querySelector('[data-action="previous-sheet"]');r&&(r.textContent=e.t("confirmDeleteCard")),o&&(o.style.display="none"),i&&(i.style.display="none")}function At(e){var n;e._pendingDeleteMethod=null,Ut(e,!1);const t=(n=e.container)==null?void 0:n.querySelector('[data-sheet="payment"]');t==null||t.classList.remove("choco-widget-payment-sheet--delete-confirm"),Le(e)}function Ut(e,t){var i,c,u;const n=(i=e.container)==null?void 0:i.querySelector(".choco-widget-sheet-delete-confirm-actions"),r=(c=e.container)==null?void 0:c.querySelector('[data-action="confirm-delete-cancel"]'),o=(u=e.container)==null?void 0:u.querySelector('[data-action="confirm-delete-submit"]');n==null||n.classList.toggle("choco-widget-sheet-delete-confirm-actions--loading",t),r&&(r.disabled=t),o&&(o.disabled=t,o.classList.toggle("choco-widget-delete-confirm-btn--loading",t))}async function Xi(e,t){var r,o;const n=t==null?void 0:t.cardId;if(!(!n||(t==null?void 0:t.type)!=="card"))try{await Dr(e.apiUrl,e._getApiConfig(),n),e.checkoutContext=await gt(e.apiUrl,e._getApiConfig()),((r=e.selectedPaymentMethod)==null?void 0:r.type)==="card"&&((o=e.selectedPaymentMethod)==null?void 0:o.cardId)===n&&(e.selectedPaymentMethod=ht(e.checkoutContext.data,e._getKaspiOptions()),e._emitPaymentMethodSelected(),sr(e)),Te(e),e.config.onSuccess({message:e.t("cardDeleted")}),e.config.onCardDeleted&&e.config.onCardDeleted({cardId:n})}catch(i){e.config.onError({attributes:{message:(i==null?void 0:i.message)||e.t("paymentError")}})}}function ur(e,t){if(e._isInteractionBlocked())return;if(e.selectedPaymentMethod=t,e._emitPaymentMethodSelected(),t.type==="new_card"){e._emitUserEvent("one_click_pay_method_resolved",{payment_method:t.type}),le(e),e.handlePayment();return}const n=e._getPaymentMethodForUserEvent();n!=null&&e._emitUserEvent("one_click_pay_method_resolved",{payment_method:n}),Te(e),le(e),sr(e)}function lr(e,t){var r;const n=t.type||((r=t.data)==null?void 0:r.type);if(!n){console.warn("Unknown event format:",t);return}switch(n){case"order.paid":e._orderStatusResolved=!0,pe(e),dr(e,t);break;case"order.failed":e._orderStatusResolved=!0,pe(e),fr(e,t);break;case"order.action_required":Hi(e,t);break;default:console.warn("Unknown event type:",n)}}function pe(e){e._orderStatusPollingId&&(clearInterval(e._orderStatusPollingId),e._orderStatusPollingId=null)}function ve(e,t){pe(e),e._orderStatusResolved=!1;const n=6e3,r=5;let o=0;const i=async()=>{if(!e._orderStatusResolved){if(o>=r){pe(e),q(e),e.config.onError({attributes:{message:e.t("errorNoServerResponseRetry")}});return}o+=1;try{const{data:c}=await xr(e.apiUrl,e._getApiConfig(),String(t)),u=c==null?void 0:c.status,l=(c==null?void 0:c.payload)||{};if(u==="success"){e._orderStatusResolved=!0,pe(e),dr(e,{id:String(l.id||t),attributes:{amount:l.amount,paid_at:l.paid_at||""}});return}u==="fail"&&(e._orderStatusResolved=!0,pe(e),fr(e,{id:String(l.id||t),attributes:{message:l.message||e.t("paymentError")}}))}catch(c){console.warn("[Polling] checkOrderStatus error:",c)}}};e._orderStatusPollingId=setInterval(i,n),i()}function Ft(){return typeof document>"u"?!1:document.hidden||document.visibilityState==="hidden"}function Ar(e,t){q(e),e.config.onSuccess(t)}function Xt(e){if(!e._pendingSuccessPayload||Ft())return;const t=e._pendingSuccessPayload;e._pendingSuccessPayload=null,Ar(e,t)}function dr(e,t){var o,i;e.isAddCardViewOpen&&Ee(e);const n=t.attributes||((o=t.data)==null?void 0:o.attributes)||{},r={id:t.id||((i=t.data)==null?void 0:i.id),attributes:n};if(Ft()){e._pendingSuccessPayload=r;return}Ar(e,r)}function fr(e,t){var r,o;e.isAddCardViewOpen&&Ee(e),q(e);const n=t.attributes||((r=t.data)==null?void 0:r.attributes)||{};e.config.onError({id:t.id||((o=t.data)==null?void 0:o.id),attributes:n})}function Hi(e,t){var i,c,u;const n=t.attributes||((i=t.data)==null?void 0:i.attributes)||{},r=n.action_link||n.action_url,o=n.action_url_type||n.action_type||"redirect";if(!r){console.error(e.t("errorActionUrlMissing")),e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,q(e),e.config.onError({attributes:{message:e.t("errorNoServerResponse")}}));return}if(e.waitingForNewCardAction&&(e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout()),o==="inner"){e.addCardActionUrl=r,q(e),e._showAddCardView();return}if(((c=e.selectedPaymentMethod)==null?void 0:c.type)==="kaspi_pay"){const l=t.id||((u=t.data)==null?void 0:u.id);if(l&&!e._orderStatusResolved&&!e._orderStatusPollingId&&ve(e,String(l)),typeof e.config.onKaspiLink=="function"){e.config.onKaspiLink({action_link:r,action_url:r,action_type:o,event:t});return}}window.location.href=r}async function ji(e){var n,r,o,i,c;if(!e.selectedPaymentMethod){e.config.onError({attributes:{message:e.t("errorPaymentMethodNotSelected")}});return}const{checkoutOptions:t}=e._getPaymentBreakdown();if(e._isBalanceFullyCoveringAmount()){he(e);try{const u=await rn(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await hr(e);const l=(u==null?void 0:u.id)??((n=u==null?void 0:u.data)==null?void 0:n.id);return l&&ve(e,String(l)),u}catch(u){throw q(e),se(u,{paymentMethod:"balance"}),e.config.onError({attributes:{message:e._resolveErrorMessage(u)}}),u}}if(e.selectedPaymentMethod.type==="new_card"){await Ji(e,t);return}if(e.selectedPaymentMethod.type==="apple_pay"){await qi(e,t);return}if(e.selectedPaymentMethod.type==="google_pay"){await zi(e,t);return}he(e);try{const u=await rn(e.apiUrl,e._getApiConfig(),e.deviceId,e.selectedPaymentMethod,t);await hr(e);const l=(u==null?void 0:u.id)??((r=u==null?void 0:u.data)==null?void 0:r.id);if(l&&ve(e,String(l)),((o=e.selectedPaymentMethod)==null?void 0:o.type)==="kaspi_pay"){const h=(u==null?void 0:u.attributes)||((i=u==null?void 0:u.data)==null?void 0:i.attributes)||{},y=h.action_link||h.action_url,m=h.action_url_type||h.action_type||"redirect";if(y)return typeof e.config.onKaspiLink=="function"?(e.config.onKaspiLink({action_link:y,action_url:y,action_type:m,event:u}),u):(window.location.href=y,u)}return u}catch(u){throw q(e),se(u,{paymentMethod:((c=e.selectedPaymentMethod)==null?void 0:c.type)||"card"}),e.config.onError({message:e._resolveErrorMessage(u)}),u}}async function hr(e){var t,n;if(!(((t=e.selectedPaymentMethod)==null?void 0:t.type)!=="card"||!((n=e.selectedPaymentMethod)!=null&&n.cardId)))try{await Mr(e.apiUrl,e._getApiConfig(),e.selectedPaymentMethod.cardId)}catch(r){console.warn("Failed to mark selected card as default:",r)}}async function Ji(e,t){he(e),e.waitingForNewCardAction=!0,e._setNewCardActionTimeout();try{await Ur(e.apiUrl,e._getApiConfig(),e.deviceId,t)}catch(n){e.waitingForNewCardAction=!1,e._clearNewCardActionTimeout(),q(e),se(n,{paymentMethod:"new_card"}),e.config.onError({attributes:{message:e._resolveErrorMessage(n)}}),console.error("New card payment error:",n)}}let Re=null;async function qi(e,t){const n=window.ApplePaySession;if(!n||!n.canMakePayments()){e.config.onError({attributes:{message:e.t("errorApplePayUnsupported")}});return}if(Re)return;he(e);const r={countryCode:e.config.currency==="GEL"?"GE":"KZ",currencyCode:e.config.currency,supportedNetworks:["visa","masterCard"],merchantCapabilities:["supports3DS"],total:{label:e.config.merchantName||"Choco",amount:String(e._getPayableAmount()),type:"final"}},o=new n(3,r);Re=o,o.onvalidatemerchant=async i=>{var c,u;try{let l;try{l=await on(e.apiUrl,e._getApiConfig(),i.validationURL)}catch(m){if(m.status===401)await e._obtainTokenByRefreshOrTrackId(),l=await on(e.apiUrl,e._getApiConfig(),i.validationURL);else throw m}const h=((u=(c=l==null?void 0:l.data)==null?void 0:c.attributes)==null?void 0:u.session)||l,y=JSON.parse(atob(h));o.completeMerchantValidation(y)}catch(l){console.error("Apple Pay session error:",l),se(l,{paymentMethod:"apple_pay",phase:"merchant_validation"}),q(e),o.abort(),e.config.onError({attributes:{message:e.t("errorApplePayInit")}})}},o.onpaymentauthorized=async i=>{var c;try{if(typeof e.config.onBeforeCheckout=="function"){const h=await e.config.onBeforeCheckout();h&&typeof h=="object"&&Object.assign(e.config,h)}const u=await Xr(e.apiUrl,e._getApiConfig(),e.deviceId,i.payment,t);o.completePayment(n.STATUS_SUCCESS),Re=null;const l=(u==null?void 0:u.id)??((c=u==null?void 0:u.data)==null?void 0:c.id);l&&!e._orderStatusResolved&&ve(e,String(l))}catch(u){console.error("Apple Pay payment error:",u),se(u,{paymentMethod:"apple_pay",phase:"payment_authorized"}),o.completePayment(n.STATUS_FAILURE),Re=null,q(e),e.config.onError({attributes:{message:e._resolveErrorMessage(u,"errorApplePayPayment")}})}},o.oncancel=()=>{var i;if(Re=null,q(e),((i=e.selectedPaymentMethod)==null?void 0:i.type)==="apple_pay"){e.config.onError({attributes:{message:e.t("errorApplePayInterrupted")}});return}e.config.onCancel()},o.begin()}async function zi(e,t){var S,P,k,R,L,z;const n=(S=e.checkoutContext)==null?void 0:S.data,r=((k=(P=n==null?void 0:n.payment_methods)==null?void 0:P.data)==null?void 0:k.attributes)||{},o=r.google_pay_settings||{};if(!(r.payment_method_google_pay==="enabled"||r.payment_method_google_pay===!0)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}const c=o==null?void 0:o.gateway,u=o==null?void 0:o.merchant_id;if(!c||!u){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}const l=e.config.environment==="production",h=(o==null?void 0:o.merchant_name)||"Choco",y=o==null?void 0:o.google_merchant_id;if(l&&!y){e.config.onError({attributes:{message:e.t("errorGooglePaySettingsUnavailable")}});return}if(e.config.isNativeAndroid){await Ki(e,t,{gateway:c,gatewayMerchantId:u});return}const m=Number(e._getCheckoutAmount()).toFixed(2);try{await e._loadGooglePaySdk()}catch(D){console.error("Google Pay SDK load error:",D),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 I=[{type:"CARD",parameters:{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:["VISA","MASTERCARD"],billingAddressRequired:!1},tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:c,gatewayMerchantId:u}}}],B={apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:I,transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Итого",totalPrice:m,currencyCode:e.config.currency,countryCode:e.config.currency==="GEL"?"GE":"KZ"},merchantInfo:l?{merchantId:y,merchantName:h}:{merchantName:h}},Q=new b.payments.api.PaymentsClient({environment:l?"PRODUCTION":"TEST"});try{const D=await Q.isReadyToPay({apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:I});if(!(D!=null&&D.result)){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}he(e);const G=await Q.loadPaymentData(B),K=(L=(R=G==null?void 0:G.paymentMethodData)==null?void 0:R.tokenizationData)==null?void 0:L.token;if(!K)throw new Error(e.t("errorGooglePayPayment"));const J=JSON.parse(K),M=await sn(e.apiUrl,e._getApiConfig(),e.deviceId,J,t),v=(M==null?void 0:M.id)??((z=M==null?void 0:M.data)==null?void 0:z.id);v&&ve(e,String(v))}catch(D){q(e),D.statusCode==="CANCELED"?e.config.onCancel():(se(D,{paymentMethod:"google_pay"}),e.config.onError({attributes:{message:e._resolveErrorMessage(D,"errorGooglePayPayment")}}),console.error("Google Pay error:",D))}}async function Ki(e,t,n){var r;if(!e.config.onPayWithGooglePay){e.config.onError({attributes:{message:e.t("errorGooglePayUnsupported")}});return}he(e);try{const o=await e.config.onPayWithGooglePay({amount:Number(e._getCheckoutAmount()),gateway:n.gateway,gatewayMerchantId:n.gatewayMerchantId}),i=JSON.parse(o),c=await sn(e.apiUrl,e._getApiConfig(),e.deviceId,i,t),u=(c==null?void 0:c.id)??((r=c==null?void 0:c.data)==null?void 0:r.id);u&&ve(e,String(u))}catch(o){q(e),o.statusCode==="CANCELED"?e.config.onCancel():(se(o,{paymentMethod:"google_pay_native"}),e.config.onError({attributes:{message:e._resolveErrorMessage(o,"errorGooglePayPayment")}}),console.error("Google Pay native error:",o))}}function Gi(e){var c,u,l,h,y,m,b,I,B,Q,S,P;const t=e.container;(c=t.querySelector('[data-action="freedom-card"]'))==null||c.addEventListener("click",()=>{e.config.onFreedomLink&&e.config.onFreedomLink()}),(u=t.querySelector('[data-action="pay"]'))==null||u.addEventListener("click",()=>e.handlePayment()),(l=t.querySelector('[data-action="change-method"]'))==null||l.addEventListener("click",()=>cr(e)),t.querySelectorAll('[data-action="close"]').forEach(k=>k.addEventListener("click",()=>e.close())),(h=t.querySelector('[data-action="close-sheet"]'))==null||h.addEventListener("click",()=>{e._pendingDeleteMethod?At(e):le(e)}),(y=t.querySelector('[data-action="edit-sheet"]'))==null||y.addEventListener("click",()=>{e.isPaymentSheetEditMode=!0,Te(e),Le(e)}),(m=t.querySelector('[data-action="previous-sheet"]'))==null||m.addEventListener("click",()=>{e.isPaymentSheetEditMode=!1,Te(e),Le(e)}),(b=t.querySelector('[data-action="close-add-card"]'))==null||b.addEventListener("click",()=>Ee(e)),(I=t.querySelector('[data-action="confirm-delete-cancel"]'))==null||I.addEventListener("click",()=>At(e)),(B=t.querySelector('[data-action="confirm-delete-submit"]'))==null||B.addEventListener("click",()=>{if(e._pendingDeleteMethod){const k=e._pendingDeleteMethod;Ut(e,!0),Xi(e,k).then(()=>le(e)).finally(()=>Ut(e,!1))}}),t.querySelectorAll(".choco-widget-method-item").forEach(k=>{k.addEventListener("click",R=>{const L=JSON.parse(R.currentTarget.getAttribute("data-method")||"{}");ur(e,L)})});const n=t.querySelector('[data-sheet="payment"]');n&&(n.addEventListener("click",k=>{k.target===n&&le(e)}),Yi(e,n));const r=t.querySelector('[data-action="toggle-balance"]');r&&((Q=r.querySelector("input[type='checkbox']"))==null||Q.addEventListener("change",k=>{e.useBalance=k.target.checked,ar(e),e._updatePayButtonAmount()}));const o=t.querySelector('[data-action="toggle-bonuses"]');o&&((S=o.querySelector("input[type='checkbox']"))==null||S.addEventListener("change",k=>{e.useBonuses=k.target.checked,e.config.onAppliedBonus(e.useBonuses),ar(e),e._updatePayButtonAmount()}));const i=t.querySelector('[data-action="toggle-coupon"]');i&&((P=i.querySelector("input[type='checkbox']"))==null||P.addEventListener("change",k=>{e.useCoupon=k.target.checked,e._updatePayButtonAmount(),e._emitCouponSuppressingCashback()})),document.removeEventListener("keydown",e._boundKeyDown),document.addEventListener("keydown",e._boundKeyDown),ir(e)}function Wi(e,t){var n,r;e.isOpen&&(t.key==="Escape"&&(t.preventDefault(),e._pendingDeleteMethod?At(e):e.isAddCardViewOpen?Ee(e):e.isPaymentSheetOpen?le(e):e.close()),t.key==="Enter"&&((r=(n=t.target)==null?void 0:n.dataset)==null?void 0:r.action)==="pay"&&(t.preventDefault(),e.handlePayment()))}function Yi(e,t){const n=t.querySelector('[data-action="sheet-drag-handle"]'),r=t.querySelector(".choco-widget-sheet-content");if(!n||!r)return;const o=80;let i=0,c=0;const u=h=>{c=h.clientY;const y=Math.max(0,c-i);r.style.transform=`translateY(${y}px)`},l=h=>{n.releasePointerCapture(h.pointerId),n.removeEventListener("pointermove",u),n.removeEventListener("pointerup",l),n.removeEventListener("pointercancel",l);const y=Math.max(0,c-i);if(r.classList.remove("choco-widget-sheet-content--dragging"),y>=o){r.style.transform="translateY(100%)";const m=()=>{r.removeEventListener("transitionend",m),r.style.transform="",le(e)};r.addEventListener("transitionend",m)}else r.style.transform=""};n.addEventListener("pointerdown",h=>{!e.isPaymentSheetOpen||h.button!==0||(h.preventDefault(),i=h.clientY,c=h.clientY,r.classList.add("choco-widget-sheet-content--dragging"),n.setPointerCapture(h.pointerId),n.addEventListener("pointermove",u),n.addEventListener("pointerup",l),n.addEventListener("pointercancel",l))})}class ge{static _getAuthStorageValue(t){return tn(t)}static _setAuthStorageValue(t,n){pt(t,n)}static _removeAuthStorageValue(t){He(t)}static async logout(){nr()}constructor(t){this.config=Hr(t),this.accessToken=null,this.deviceId=Gt(),this.apiUrl=vr(this.config.environment),this.translations=Se,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=n=>Wi(this,n),this._boundVisibilityChange=()=>this._onVisibilityChange(),this._boundWindowFocus=()=>this._onWindowFocus(),this._boundPageShow=()=>this._onPageShow(),Ci({clientId:String(this.config.clientId),terminalId:String(this.config.terminalId),environment:this.config.environment})}t(t,n={}){var i;const r=this.config.locale||"ru",o=((i=this.translations[r])==null?void 0:i[t])||this.translations.ru[t];return typeof o!="string"?t:o.replace(/{(\w+)}/g,(c,u)=>Object.prototype.hasOwnProperty.call(n,u)?String(n[u]):c)}_resolveErrorMessage(t,n="paymentError"){return(t==null?void 0:t.message)||this.t(n)}_getApiConfig(){return{...this.config,accessToken:this.accessToken}}_isInteractionBlocked(){return this.disabled||this.loading}_getBalanceAmount(){var o,i,c,u;const t=(u=(c=(i=(o=this.checkoutContext)==null?void 0:o.data)==null?void 0:i.balance)==null?void 0:c.data)==null?void 0:u.money,n=this.config.currency||"KZT",r=Number(t==null?void 0:t[n]);return Number.isFinite(r)&&r>0?r:0}_getBonusesAmount(){var n;const t=Number((n=this.config.bonuses)==null?void 0:n.amount);return Number.isFinite(t)&&t>0?t:0}_getBonusesPercent(){var n;const t=Number((n=this.config.bonuses)==null?void 0:n.percent);return!Number.isFinite(t)||t<=0?0:t>=100?100:t}_getAvailableBonus(){var n;const t=Number((n=this.config.bonuses)==null?void 0:n.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,n=this._getBalanceAmount(),r=this.useBalance?Math.min(n,t):0,o=t-r,i=this.useBalance&&r>=t,c=this.useBonuses?this._getAvailableBonus():0,u=Math.max(o-c,0),l=this._getCouponDiscount(),h=Math.max(u-l,0),y=this.useBalance?t:h,m=this.useBalance&&!i,I=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:h,checkoutOptions:{checkoutAmount:y,forceBalanceMethod:i,useBalance:m,voucher:I}}}_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,n={}){typeof this.config.onUserEvent=="function"&&this.config.onUserEvent({eventName:t,eventProperties:n})}_emitPaymentMethodSelected(t=this.selectedPaymentMethod){typeof this.config.onPaymentMethodSelected=="function"&&this.config.onPaymentMethodSelected(t||null)}_emitCouponSuppressingCashback(){var n;const t=this.useCoupon&&((n=this.selectedCoupon)==null?void 0:n.suppresses_cashback)===!0;this.config.onCouponSuppressingCashback(t)}_attachEventListeners(){Gi(this)}_updatePayButtonAmount(){lt(this)}_showAddCardView(){xt(this)}_closeAddCardView(){Ee(this)}_setNewCardActionTimeout(){this._clearNewCardActionTimeout(),this.newCardActionRequiredTimeoutId=setTimeout(()=>{this.waitingForNewCardAction&&(this.waitingForNewCardAction=!1,q(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,n){ct(t,n)}_clearAuthStorage(){nr()}_getAuthStorageValue(t){return ge._getAuthStorageValue(t)}_setAuthStorageValue(t,n){ge._setAuthStorageValue(t,n)}_removeAuthStorageValue(t){ge._removeAuthStorageValue(t)}_loadGooglePaySdk(){var t,n;return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Google Pay SDK requires browser environment")):(n=(t=window.google)==null?void 0:t.payments)!=null&&n.api?Promise.resolve():this._googlePayScriptPromise?this._googlePayScriptPromise:(this._googlePayScriptPromise=new Promise((r,o)=>{const i=document.querySelector('script[data-choco-google-pay-sdk="true"]');if(i){i.addEventListener("load",()=>r(),{once:!0}),i.addEventListener("error",()=>o(new Error("Failed to load Google Pay SDK")),{once:!0});return}const c=document.createElement("script");c.src="https://pay.google.com/gp/p/js/pay.js",c.async=!0,c.defer=!0,c.setAttribute("data-choco-google-pay-sdk","true"),c.onload=()=>r(),c.onerror=()=>o(new Error("Failed to load Google Pay SDK")),document.head.appendChild(c)}).finally(()=>{var r,o;(o=(r=window.google)==null?void 0:r.payments)!=null&&o.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(){Ft()||Xt(this)}_onWindowFocus(){Xt(this)}_onPageShow(){Xt(this)}async _obtainTokenByRefreshOrTrackId(){await bi(this)}async _fetchCheckoutContextWithRetry(){try{this.checkoutContext=await gt(this.apiUrl,this._getApiConfig())}catch(t){if(t.status===401)this._removeAuthStorageValue("webPayToken"),await this._obtainTokenByRefreshOrTrackId(),this.checkoutContext=await gt(this.apiUrl,this._getApiConfig());else throw t}}async _fetchCoupons(){try{const t=await Fr(this.apiUrl,this._getApiConfig()),r=(Array.isArray(t)?t:Array.isArray(t==null?void 0:t.data)?t.data:[]).filter(o=>Number(o.reward_amount)>0).sort((o,i)=>o.sort_weight-i.sort_weight);this.selectedCoupon=r.length>0?r[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(),n=this.useBalance?Math.min(t,this.config.amount):0,r=this.config.amount-n,o=this.useBonuses?Math.min(this._getAvailableBonus(),r):0;return r-o<this.selectedCoupon.reward_amount}_prerender(){Oi(this)}_render(){Ni(this)}async init(){var t,n;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(o){const i=o;return this.config.onError({attributes:{message:i.message}}),!1}if(this._destroyed||(await this._fetchCoupons(),this._emitCouponSuppressingCashback(),this._destroyed))return!1;const r=Vt((n=(t=this.checkoutContext)==null?void 0:t.data)==null?void 0:n.socket_connections,o=>lr(this,o));return r&&(this.centrifuge=r.centrifuge),this.selectedPaymentMethod=ht(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this._render(),!0}catch(r){return console.error(`${this.t("errorWidgetInit")}:`,r),se(r,{phase:"init"}),this.config.onError({attributes:{message:r.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(),pe(this),this._pendingSuccessPayload=null,this._detachLifecycleListeners(),this.isAddCardViewOpen&&Ee(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 n;(n=this.container)==null||n.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?Rr(this.checkoutContext.data,n=>this.t(n),this._getKaspiOptions()):[]}async createOrder(){return ji(this)}async pay(){try{await this.createOrder()}catch(t){console.error(`${this.t("errorPaymentProcess")}:`,t)}}async handlePayment(){if(this._isInteractionBlocked())return;const t=this._getPaymentMethodForUserEvent();t!=null&&this._emitUserEvent("one_click_pay_cta_tapped",{payment_method:t});try{if(this.config.onConfirmPay){this.config.onConfirmPay(this.selectedPaymentMethod||null);return}await this.pay()}catch(n){console.error(`${this.t("errorPaymentProcess")}:`,n)}}openPaymentSheet(){cr(this)}closePaymentSheet(){le(this)}async updateAmount(t){var n;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 r=this.isPaymentSheetOpen,o=this.isAddCardViewOpen;if(this._render(),ue(this),r){const i=(n=this.container)==null?void 0:n.querySelector('[data-sheet="payment"]');i&&(i.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}o&&xt(this);return}lt(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),lt(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 n=this.isPaymentSheetOpen,r=this.isAddCardViewOpen;if(this._render(),ue(this),n){const o=this.container.querySelector('[data-sheet="payment"]');o&&(o.classList.add("choco-widget-payment-sheet--open"),this.isPaymentSheetOpen=!0)}r&&xt(this)}async setLoading(t){this.loading=!!t,ue(this)}async setDisabled(t){this.disabled=!!t,ue(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 ge.logout(),this.accessToken=null}async updateTrackId(t){var n,r;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(i){const c=i;return this.config.onError({attributes:{message:c.message}}),!1}await this._fetchCoupons(),this._emitCouponSuppressingCashback(),this.centrifuge&&(this.centrifuge.disconnect(),this.centrifuge=null);const o=Vt((r=(n=this.checkoutContext)==null?void 0:n.data)==null?void 0:r.socket_connections,i=>lr(this,i));return o&&(this.centrifuge=o.centrifuge),this.selectedPaymentMethod=ht(this.checkoutContext.data,this._getKaspiOptions()),this._emitPaymentMethodSelected(),this.paymentMethodDisabled=!1,this._render(),!0}catch(o){return console.error(`${this.t("errorWidgetInit")}:`,o),se(o,{phase:"updateTrackId"}),this.config.onError({attributes:{message:o.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 onFreedomLink(t){if(typeof t!="function")throw new Error("onFreedomLink callback must be a function");this.config.onFreedomLink=t}async onAppliedBonus(t){if(typeof t!="function")throw new Error("onAppliedBonus callback must be a function");this.config.onAppliedBonus=t}async onCouponSuppressingCashback(t){if(typeof t!="function")throw new Error("onCouponSuppressingCashback callback must be a function");this.config.onCouponSuppressingCashback=t}}return typeof window<"u"&&(window.ChocoOneClickWidget=ge),ge}));
|
package/index.d.ts
CHANGED
|
@@ -143,8 +143,8 @@ export interface ChocoOneClickConfig {
|
|
|
143
143
|
* Callback для пользовательских событий виджета.
|
|
144
144
|
* Виджет эмитит события:
|
|
145
145
|
* - one_click_pay_cta_rendered
|
|
146
|
-
* - one_click_pay_method_resolved
|
|
147
|
-
* - one_click_pay_cta_tapped
|
|
146
|
+
* - one_click_pay_method_resolved (только когда метод оплаты определён)
|
|
147
|
+
* - one_click_pay_cta_tapped (только когда метод оплаты определён)
|
|
148
148
|
*/
|
|
149
149
|
onUserEvent?: (event: UserEventPayload) => void;
|
|
150
150
|
|