@bigcommerce/checkout-sdk 1.863.0 → 1.864.0

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.
@@ -1,2 +1,2 @@
1
- import{createRequestSender as e,createTimeout as t}from"@bigcommerce/request-sender";import{createFormPoster as i}from"@bigcommerce/form-poster";import{combineReducers as n,composeReducers as o,createAction as r,createDataStore as a,createErrorAction as s,deepFreeze as d}from"@bigcommerce/data-store";import{difference as c,filter as u,find as l,findIndex as h,flatMap as p,identity as m,includes as g,isArray as y,isEmpty as f,isEqual as v,isMatch as S,isNil as C,isObject as I,isPlainObject as _,keyBy as w,keys as b,last as E,map as P,max as O,memoize as A,noop as T,omit as k,omitBy as R,pick as D,pickBy as M,reduce as N,round as L,some as z,transform as U,uniq as F,uniqueId as B,values as x,without as q}from"lodash";import{Observable as j,Subject as G,concat as H,defer as V,empty as Y,from as W,fromEvent as $,merge as K,of as Z,throwError as Q}from"rxjs";import{catchError as J,delay as X,filter as ee,map as te,retryWhen as ie,shareReplay as ne,switchMap as oe,take as re}from"rxjs/operators";import{memoize as ae,memoizeOne as se}from"@bigcommerce/memoize";import{createSelector as de}from"reselect";import{ScriptLoader as ce,createScriptLoader as ue,getScriptLoader as le}from"@bigcommerce/script-loader";import{stringifyUrl as he}from"query-string";import{supportsPopups as pe}from"@braintree/browser-detection";import{createClient as me}from"@bigcommerce/bigpay-client";import{creditCardType as ge,number as ye}from"card-validator";import{default as fe}from"shallowequal";var ve={d:(e,t)=>{for(var i in t)ve.o(t,i)&&!ve.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},Se={};ve.r(Se),ve.d(Se,{createAmazonPayV2ButtonStrategy:()=>Oo,createApplePayButtonStrategy:()=>rr,createBigCommercePaymentsAlternativeMethodsButtonStrategy:()=>Dr,createBigCommercePaymentsButtonStrategy:()=>wr,createBigCommercePaymentsPayLaterButtonStrategy:()=>Tr,createBigCommercePaymentsVenmoButtonStrategy:()=>Lr,createBoltButtonStrategy:()=>Gr,createBraintreePaypalButtonStrategy:()=>da,createBraintreePaypalCreditButtonStrategy:()=>ha,createBraintreeVenmoButtonStrategy:()=>Ia,createBraintreeVisaCheckoutButtonStrategy:()=>ga,createGooglePayAdyenV2ButtonStrategy:()=>rs,createGooglePayAdyenV3ButtonStrategy:()=>as,createGooglePayAuthorizeDotNetButtonStrategy:()=>ds,createGooglePayBigCommercePaymentsButtonStrategy:()=>os,createGooglePayBraintreeButtonStrategy:()=>Ka,createGooglePayCheckoutComButtonStrategy:()=>ps,createGooglePayCybersourceButtonStrategy:()=>gs,createGooglePayOrbitalButtonStrategy:()=>fs,createGooglePayPayPalCommerceButtonStrategy:()=>ts,createGooglePayStripeButtonStrategy:()=>Ns,createGooglePayTdOnlineMartButtonStrategy:()=>xs,createGooglePayWorldpayAccessButtonStrategy:()=>zs,createLinkV2ButtonStrategy:()=>Zd,createPayPalCommerceAlternativeMethodsButtonStrategy:()=>Td,createPayPalCommerceButtonStrategy:()=>nd,createPayPalCommerceCreditButtonStrategy:()=>sd,createPayPalCommerceVenmoButtonStrategy:()=>ud,createPaypalExpressButtonStrategy:()=>Bd});class Ce extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}const Ie={body:{},headers:{},status:0};class _e extends Ce{constructor(e,{message:t,errors:i}={}){const{body:n,headers:o,status:r}=e||Ie;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=n,this.headers=o,this.status=r,this.errors=i||[]}}class we extends _e{constructor(e){super(e,{message:"There is a problem processing your payment. Please try again later."}),this.name="PaymentMethodInvalidError",this.type="payment_method_invalid"}}class be extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}const Ee={body:{},headers:{},status:0};class Pe extends be{constructor(e,{message:t,errors:i}={}){const{body:n,headers:o,status:r}=e||Ee;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=n,this.headers=o,this.status=r,this.errors=i||[]}}class Oe extends Pe{constructor(e,t){super(e,{message:t||"An unexpected error has occurred. The checkout process cannot continue as a result."}),this.name="UnrecoverableError",this.type="unrecoverable"}}function Ae(e){return e.reduce((e,t)=>t?[...e,t]:e,[]).join(" ")}function Te(e,t){const{body:i}=e,{errors:n=[]}=i;return new Pe(e,{message:ke(n)||t,errors:n})}function ke(e){if(Array.isArray(e))return e.reduce((e,t)=>t&&t.message?[...e,t.message]:e,[]).join(" ")}class Re extends Pe{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}class De{constructor(){this._factoryMethods={},this.register("default",(e,t)=>new Pe(e,{message:t})),this.register("internal",(e,t)=>function(e,t){const{body:i}=e,{errors:n=[]}=i;return new Pe(e,{message:Ae(n)||i.detail||i.title||t,errors:n.length?n.map(e=>({code:i.type,message:e})):[{code:i.type,message:i.detail||i.title}]})}(e,t)),this.register("storefront",(e,t)=>function(e,t){const{body:i}=e;return new Pe(e,{message:t||i.detail||i.title,errors:[{code:i.code||i.type,message:i.detail||i.title}]})}(e,t)),this.register("payment",(e,t)=>Te(e,t)),this.register("timeout",e=>new Re(e))}register(e,t){this._factoryMethods[e]=t}createError(e,t){return(this._factoryMethods[this._getType(e)]||this._factoryMethods.default)(e,t)}_getType(e){if(0===e.status)return"timeout";if(this._isStorefrontErrorResponseBody(e.body))return"storefront";if(this._isInternalErrorResponseBody(e.body)){const t=E(e.body.type.split("/"));return t&&this._factoryMethods[t]?t:"internal"}const t=E(e.body&&e.body.errors);return t&&t.code&&this._factoryMethods[t.code]?t.code:"payment"}_isStorefrontErrorResponseBody(e){const t=e;return!this._isInternalErrorResponseBody(e)&&"string"==typeof t.title&&"string"==typeof t.type&&"number"==typeof t.status&&"string"==typeof t.detail}_isInternalErrorResponseBody(e){const t=e;return"object"==typeof t.errors&&"string"==typeof t.title&&"string"==typeof t.type&&"number"==typeof t.status}}var Me,Ne,Le,ze,Ue;function Fe(e,t){return Array.isArray(e)?e.map(e=>Fe(e,t)):_(e)?U(R(e,t),(e,i,n)=>{e[n]=Fe(i,t)},{}):e}function Be(e,t){return function(e){return e.type===Le.ClearError}(t)?Fe(e,e=>e===t.payload):e}function xe(e,t,i){return e===t||(e&&t&&"object"==typeof e&&"object"==typeof t?Array.isArray(e)&&Array.isArray(t)?function(e,t,i){if(e.length!==t.length)return!1;for(let n=0,o=e.length;n<o;n++)if(!xe(e[n],t[n],i))return!1;return!0}(e,t,i):!Array.isArray(e)&&!Array.isArray(t)&&(e instanceof Date&&t instanceof Date?function(e,t){return e.getTime()===t.getTime()}(e,t):!(e instanceof Date||t instanceof Date)&&(e instanceof RegExp&&t instanceof RegExp?function(e,t){return e.toString()===t.toString()}(e,t):!(e instanceof RegExp||t instanceof RegExp)&&function(e,t,i){const n=i&&i.keyFilter,o=n?Object.keys(e).filter(n):Object.keys(e),r=n?Object.keys(t).filter(n):Object.keys(t);if(o.length!==r.length)return!1;for(let n=0,r=o.length;n<r;n++){const r=o[n];if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!xe(e[r],t[r],i))return!1}return!0}(e,t,i))):e===t)}function qe(e,t){return void 0===t||xe(e,t)?e:t}function je(e,t,i){return e&&Object.prototype.hasOwnProperty.call(e,t)&&xe(e[t],i)?e:Object.assign(Object.assign({},e),{[t]:i})}!function(e){e.LoadCheckoutRequested="LOAD_CHECKOUT_REQUESTED",e.LoadCheckoutSucceeded="LOAD_CHECKOUT_SUCCEEDED",e.LoadCheckoutFailed="LOAD_CHECKOUT_FAILED",e.UpdateCheckoutRequested="UPDATE_CHECKOUT_REQUESTED",e.UpdateCheckoutSucceeded="UPDATE_CHECKOUT_SUCCEEDED",e.UpdateCheckoutFailed="UPDATE_CHECKOUT_FAILED"}(Me||(Me={})),function(e){e.HydrateInitialState="HYDRATE_INITIAL_STATE"}(Ne||(Ne={})),function(e){e.ClearError="CLEAR_ERROR"}(Le||(Le={})),function(e){e.UpdateSubscriptionsRequested="UPDATE_SUBSCRIPTIONS_REQUESTED",e.UpdateSubscriptionsSucceeded="UPDATE_SUBSCRIPTIONS_SUCCEEDED",e.UpdateSubscriptionsFailed="UPDATE_SUBSCRIPTIONS_FAILED"}(ze||(ze={})),function(e){e.UpdateBillingAddressRequested="UPDATE_BILLING_ADDRESS_REQUESTED",e.UpdateBillingAddressSucceeded="UPDATE_BILLING_ADDRESS_SUCCEEDED",e.UpdateBillingAddressFailed="UPDATE_BILLING_ADDRESS_FAILED",e.ContinueAsGuestRequested="CONTINUE_AS_GUEST_REQUESTED",e.ContinueAsGuestSucceeded="CONTINUE_AS_GUEST_SUCCEEDED",e.ContinueAsGuestFailed="CONTINUE_AS_GUEST_FAILED"}(Ue||(Ue={}));const Ge={errors:{},statuses:{}};function He(e=Ge,t){return n({data:Ve,errors:o(Ye,Be),statuses:We})(e,t)}function Ve(e,t){var i,n;switch(t.type){case Ue.UpdateBillingAddressSucceeded:case Ue.ContinueAsGuestSucceeded:case Me.LoadCheckoutSucceeded:return qe(e,t.payload&&t.payload.billingAddress);case Ne.HydrateInitialState:return qe(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.billingAddress);default:return e}}function Ye(e=Ge.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:return je(e,"loadError",t.payload);case Ue.UpdateBillingAddressRequested:case Ue.UpdateBillingAddressSucceeded:return je(e,"updateError",void 0);case Ue.UpdateBillingAddressFailed:return je(e,"updateError",t.payload);case ze.UpdateSubscriptionsRequested:case ze.UpdateSubscriptionsSucceeded:case Ue.ContinueAsGuestRequested:case Ue.ContinueAsGuestSucceeded:return je(e,"continueAsGuestError",void 0);case ze.UpdateSubscriptionsFailed:case Ue.ContinueAsGuestFailed:return je(e,"continueAsGuestError",t.payload);default:return e}}function We(e=Ge.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Me.LoadCheckoutSucceeded:case Me.LoadCheckoutFailed:return je(e,"isLoading",!1);case Ue.UpdateBillingAddressRequested:return je(e,"isUpdating",!0);case Ue.UpdateBillingAddressFailed:case Ue.UpdateBillingAddressSucceeded:return je(e,"isUpdating",!1);case Ue.ContinueAsGuestRequested:case ze.UpdateSubscriptionsRequested:return je(e,"isContinuingAsGuest",!0);case ze.UpdateSubscriptionsSucceeded:case ze.UpdateSubscriptionsFailed:case Ue.ContinueAsGuestFailed:case Ue.ContinueAsGuestSucceeded:return je(e,"isContinuingAsGuest",!1);default:return e}}function $e(e){return _(e)}const Ke=function e(t,i,n){const{matchObject:o=(e,t)=>void 0!==e.id&&e.id===t.id}=n||{};if(!t)return i;if(!i||t===i)return t;let r=0,a=0;const s=(e,t,i)=>(r+=e===t?1:0,a+=e===i?1:0,e),d=i.map((i,n)=>{const r=t&&t[n];return $e(r)&&$e(i)?o(r,i)?s(Ze(r,i),r,i):s(qe(r,i),r,i):y(r)&&y(i)?s(e(r,i),r,i):s(qe(r,i),r,i)});return r===i.length&&t&&t.length===i.length?t:a===i.length?i:d},Ze=function e(t,i){return t?i&&t!==i?Object.keys(i).reduce((t,n)=>{const o=t[n],r=i[n];return $e(o)&&$e(r)?je(t,n,e(o,r)):y(o)&&y(r)?je(t,n,Ke(o,r)):je(t,n,r)},t):t:i};var Qe,Je,Xe;!function(e){e.ApplyCouponRequested="APPLY_COUPON_REQUESTED",e.ApplyCouponSucceeded="APPLY_COUPON_SUCCEEDED",e.ApplyCouponFailed="APPLY_COUPON_FAILED",e.RemoveCouponRequested="REMOVE_COUPON_REQUESTED",e.RemoveCouponSucceeded="REMOVE_COUPON_SUCCEEDED",e.RemoveCouponFailed="REMOVE_COUPON_FAILED"}(Qe||(Qe={})),function(e){e.ApplyGiftCertificateRequested="APPLY_GIFT_CERTIFICATE_REQUESTED",e.ApplyGiftCertificateSucceeded="APPLY_GIFT_CERTIFICATE_SUCCEEDED",e.ApplyGiftCertificateFailed="APPLY_GIFT_CERTIFICATE_FAILED",e.RemoveGiftCertificateRequested="REMOVE_GIFT_CERTIFICATE_REQUESTED",e.RemoveGiftCertificateSucceeded="REMOVE_GIFT_CERTIFICATE_SUCCEEDED",e.RemoveGiftCertificateFailed="REMOVE_GIFT_CERTIFICATE_FAILED"}(Je||(Je={})),function(e){e.CreateConsignmentsRequested="CREATE_CONSIGNMENTS_REQUESTED",e.CreateConsignmentsSucceeded="CREATE_CONSIGNMENTS_SUCCEEDED",e.CreateConsignmentsFailed="CREATE_CONSIGNMENTS_FAILED",e.UpdateConsignmentRequested="UPDATE_CONSIGNMENT_REQUESTED",e.UpdateConsignmentSucceeded="UPDATE_CONSIGNMENT_SUCCEEDED",e.UpdateConsignmentFailed="UPDATE_CONSIGNMENT_FAILED",e.DeleteConsignmentRequested="DELETE_CONSIGNMENT_REQUESTED",e.DeleteConsignmentSucceeded="DELETE_CONSIGNMENT_SUCCEEDED",e.DeleteConsignmentFailed="DELETE_CONSIGNMENT_FAILED",e.UpdateShippingOptionRequested="UPDATE_SHIPPING_OPTION_REQUESTED",e.UpdateShippingOptionSucceeded="UPDATE_SHIPPING_OPTION_SUCCEEDED",e.UpdateShippingOptionFailed="UPDATE_SHIPPING_OPTION_FAILED",e.LoadShippingOptionsRequested="LOAD_SHIPPING_OPTIONS_REQUESTED",e.LoadShippingOptionsSucceeded="LOAD_SHIPPING_OPTIONS_SUCCEEDED",e.LoadShippingOptionsFailed="LOAD_SHIPPING_OPTIONS_FAILED"}(Xe||(Xe={}));const et={errors:{},statuses:{}};function tt(e=et,t){return n({data:it,errors:o(ot,Be),statuses:nt})(e,t)}function it(e,t){var i,n;switch(t.type){case Ue.UpdateBillingAddressSucceeded:case Me.LoadCheckoutSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Xe.LoadShippingOptionsSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Ze(e,t.payload&&t.payload.cart);case Ne.HydrateInitialState:return Ze(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.cart);default:return e}}function nt(e=et.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Me.LoadCheckoutFailed:case Me.LoadCheckoutSucceeded:return je(e,"isLoading",!1);default:return e}}function ot(e=et.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:return je(e,"loadError",t.payload);default:return e}}var rt;!function(e){e.InitializeButtonFailed="INITIALIZE_BUTTON_FAILED",e.InitializeButtonRequested="INITIALIZE_BUTTON_REQUESTED",e.InitializeButtonSucceeded="INITIALIZE_BUTTON_SUCCEEDED",e.DeinitializeButtonFailed="DEINITIALIZE_BUTTON_FAILED",e.DeinitializeButtonRequested="DEINITIALIZE_BUTTON_REQUESTED",e.DeinitializeButtonSucceeded="DEINITIALIZE_BUTTON_SUCCEEDED"}(rt||(rt={}));const at={data:{},errors:{},statuses:{}},st={initializedContainers:{}},dt={},ct={};function ut(e=at,t){return t.meta&&t.meta.methodId?n({data:n({[t.meta.methodId]:lt}),errors:n({[t.meta.methodId]:ht}),statuses:n({[t.meta.methodId]:pt})})(e,t):e}function lt(e=st,t){switch(t.type){case rt.InitializeButtonSucceeded:return t.meta&&t.meta.containerId?Ze(e,{initializedContainers:{[t.meta.containerId]:!0}}):e;case rt.DeinitializeButtonSucceeded:return je(e,"initializedContainers",{})}return e}function ht(e=dt,t){switch(t.type){case rt.InitializeButtonRequested:case rt.InitializeButtonSucceeded:return je(e,"initializeError",void 0);case rt.InitializeButtonFailed:return je(e,"initializeError",t.payload);case rt.DeinitializeButtonRequested:case rt.DeinitializeButtonSucceeded:return je(e,"deinitializeError",void 0);case rt.DeinitializeButtonFailed:return je(e,"deinitializeError",t.payload);default:return e}}function pt(e=ct,t){switch(t.type){case rt.InitializeButtonRequested:return je(e,"isInitializing",!0);case rt.InitializeButtonFailed:case rt.InitializeButtonSucceeded:return je(e,"isInitializing",!1);case rt.DeinitializeButtonRequested:return je(e,"isDeinitializing",!0);case rt.DeinitializeButtonFailed:case rt.DeinitializeButtonSucceeded:return je(e,"isDeinitializing",!1);default:return e}}var mt;!function(e){e.LoadConfigRequested="LOAD_CONFIG_REQUESTED",e.LoadConfigSucceeded="LOAD_CONFIG_SUCCEEDED",e.LoadConfigFailed="LOAD_CONFIG_FAILED"}(mt||(mt={}));const gt={meta:{},errors:{},statuses:{}};function yt(e=gt,t){return n({data:ft,errors:o(vt,Be),statuses:St})(e,t)}function ft(e,t){var i;switch(t.type){case mt.LoadConfigSucceeded:return Ze(e,t.payload);case Ne.HydrateInitialState:return Ze(e,null===(i=t.payload)||void 0===i?void 0:i.config);default:return e}}function vt(e=gt.errors,t){switch(t.type){case mt.LoadConfigSucceeded:return je(e,"loadError",void 0);case mt.LoadConfigFailed:return je(e,"loadError",t.payload);default:return e}}function St(e=gt.statuses,t){switch(t.type){case mt.LoadConfigRequested:return je(e,"isLoading",!0);case mt.LoadConfigSucceeded:case mt.LoadConfigFailed:return je(e,"isLoading",!1);default:return e}}var Ct;!function(e){e.LoadOrderRequested="LOAD_ORDER_REQUESTED",e.LoadOrderSucceeded="LOAD_ORDER_SUCCEEDED",e.LoadOrderFailed="LOAD_ORDER_FAILED",e.LoadOrderPaymentsRequested="LOAD_ORDER_PAYMENTS_REQUESTED",e.LoadOrderPaymentsSucceeded="LOAD_ORDER_PAYMENTS_SUCCEEDED",e.LoadOrderPaymentsFailed="LOAD_ORDER_PAYMENTS_FAILED",e.SubmitOrderRequested="SUBMIT_ORDER_REQUESTED",e.SubmitOrderSucceeded="SUBMIT_ORDER_SUCCEEDED",e.SubmitOrderFailed="SUBMIT_ORDER_FAILED",e.FinalizeOrderRequested="FINALIZE_ORDER_REQUESTED",e.FinalizeOrderSucceeded="FINALIZE_ORDER_SUCCEEDED",e.FinalizeOrderFailed="FINALIZE_ORDER_FAILED"}(Ct||(Ct={}));const It={errors:{},statuses:{}};function _t(e=It,t){return n({data:wt,errors:o(bt,Be),statuses:Et})(e,t)}function wt(e,t){var i,n;switch(t.type){case Me.LoadCheckoutSucceeded:case Qe.ApplyCouponSucceeded:case Xe.UpdateShippingOptionSucceeded:case Qe.RemoveCouponSucceeded:case Ct.LoadOrderSucceeded:return Ke(e,t.payload&&t.payload.coupons);case Ne.HydrateInitialState:return Ke(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.coupons);default:return e}}function bt(e={},t){switch(t.type){case Qe.ApplyCouponRequested:case Qe.ApplyCouponSucceeded:return je(e,"applyCouponError",void 0);case Qe.ApplyCouponFailed:return je(e,"applyCouponError",t.payload);case Qe.RemoveCouponRequested:case Qe.RemoveCouponSucceeded:return je(e,"removeCouponError",void 0);case Qe.RemoveCouponFailed:return je(e,"removeCouponError",t.payload);default:return e}}function Et(e={},t){switch(t.type){case Qe.ApplyCouponRequested:return je(e,"isApplyingCoupon",!0);case Qe.ApplyCouponSucceeded:case Qe.ApplyCouponFailed:return je(e,"isApplyingCoupon",!1);case Qe.RemoveCouponRequested:return je(e,"isRemovingCoupon",!0);case Qe.RemoveCouponSucceeded:case Qe.RemoveCouponFailed:return je(e,"isRemovingCoupon",!1);default:return e}}const Pt={errors:{},statuses:{}};function Ot(e=Pt,t){return n({data:At,errors:o(Tt,Be),statuses:kt})(e,t)}function At(e,t){var i,n;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Ke(e,t.payload&&t.payload.giftCertificates);case Ne.HydrateInitialState:return Ke(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.giftCertificates);default:return e}}function Tt(e=Pt.errors,t){switch(t.type){case Je.ApplyGiftCertificateRequested:case Je.ApplyGiftCertificateSucceeded:return je(e,"applyGiftCertificateError",void 0);case Je.ApplyGiftCertificateFailed:return je(e,"applyGiftCertificateError",t.payload);case Je.RemoveGiftCertificateRequested:case Je.RemoveGiftCertificateSucceeded:return je(e,"removeGiftCertificateError",void 0);case Je.RemoveGiftCertificateFailed:return je(e,"removeGiftCertificateError",t.payload);default:return e}}function kt(e=Pt.statuses,t){switch(t.type){case Je.ApplyGiftCertificateRequested:return je(e,"isApplyingGiftCertificate",!0);case Je.ApplyGiftCertificateSucceeded:case Je.ApplyGiftCertificateFailed:return je(e,"isApplyingGiftCertificate",!1);case Je.RemoveGiftCertificateRequested:return je(e,"isRemovingGiftCertificate",!0);case Je.RemoveGiftCertificateSucceeded:case Je.RemoveGiftCertificateFailed:return je(e,"isRemovingGiftCertificate",!1);default:return e}}var Rt;!function(e){e.SignInCustomerRequested="SIGN_IN_CUSTOMER_REQUESTED",e.SignInCustomerSucceeded="SIGN_IN_CUSTOMER_SUCCEEDED",e.SignInCustomerFailed="SIGN_IN_CUSTOMER_FAILED",e.SignOutCustomerRequested="SIGN_OUT_CUSTOMER_REQUESTED",e.SignOutCustomerSucceeded="SIGN_OUT_CUSTOMER_SUCCEEDED",e.SignOutCustomerFailed="SIGN_OUT_CUSTOMER_FAILED",e.CreateCustomerRequested="CREATE_CUSTOMER_REQUESTED",e.CreateCustomerSucceeded="CREATE_CUSTOMER_SUCCEEDED",e.CreateCustomerFailed="CREATE_CUSTOMER_FAILED",e.CreateCustomerAddressRequested="CREATE_CUSTOMER_ADDRESS_REQUESTED",e.CreateCustomerAddressSucceeded="CREATE_CUSTOMER_ADDRESS_SUCCEEDED",e.CreateCustomerAddressFailed="CREATE_CUSTOMER_ADDRESS_FAILED",e.StripeLinkAuthenticated="STRIPE_LINK_AUTHENTICATED"}(Rt||(Rt={}));const Dt={errors:{},statuses:{}};function Mt(e=Dt,t){return n({data:Nt,errors:o(Lt,Be),statuses:zt})(e,t)}function Nt(e,t){var i,n;switch(t.type){case Ue.ContinueAsGuestSucceeded:case Me.LoadCheckoutSucceeded:return Ze(e,t.payload&&t.payload.customer);case Rt.CreateCustomerAddressSucceeded:return Ze(e,t.payload);case Ne.HydrateInitialState:return Ze(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.customer);default:return e}}function Lt(e=Dt.errors,t){switch(t.type){case Rt.CreateCustomerRequested:case Rt.CreateCustomerSucceeded:return je(e,"createError",void 0);case Rt.CreateCustomerFailed:return je(e,"createError",t.payload);case Rt.CreateCustomerAddressRequested:case Rt.CreateCustomerAddressSucceeded:return je(e,"createAddressError",void 0);case Rt.CreateCustomerAddressFailed:return je(e,"createAddressError",t.payload);default:return e}}function zt(e=Dt.statuses,t){switch(t.type){case Rt.CreateCustomerRequested:return je(e,"isCreating",!0);case Rt.CreateCustomerFailed:case Rt.CreateCustomerSucceeded:return je(e,"isCreating",!1);case Rt.CreateCustomerAddressRequested:return je(e,"isCreatingAddress",!0);case Rt.CreateCustomerAddressFailed:case Rt.CreateCustomerAddressSucceeded:return je(e,"isCreatingAddress",!1);default:return e}}var Ut;!function(e){e.SignInFailed="CUSTOMER_STRATEGY_SIGN_IN_FAILED",e.SignInRequested="CUSTOMER_STRATEGY_SIGN_IN_REQUESTED",e.SignInSucceeded="CUSTOMER_STRATEGY_SIGN_IN_SUCCEEDED",e.SignOutFailed="CUSTOMER_STRATEGY_SIGN_OUT_FAILED",e.SignOutRequested="CUSTOMER_STRATEGY_SIGN_OUT_REQUESTED",e.SignOutSucceeded="CUSTOMER_STRATEGY_SIGN_OUT_SUCCEEDED",e.ExecutePaymentMethodCheckoutFailed="CUSTOMER_STRATEGY_EXECUTE_PAYMENT_METHOD_CHECKOUT_FAILED",e.ExecutePaymentMethodCheckoutRequested="CUSTOMER_STRATEGY_EXECUTE_PAYMENT_METHOD_CHECKOUT_REQUESTED",e.ExecutePaymentMethodCheckoutSucceeded="CUSTOMER_STRATEGY_EXECUTE_PAYMENT_METHOD_CHECKOUT_SUCCEEDED",e.InitializeFailed="CUSTOMER_STRATEGY_INITIALIZE_FAILED",e.InitializeRequested="CUSTOMER_STRATEGY_INITIALIZE_REQUESTED",e.InitializeSucceeded="CUSTOMER_STRATEGY_INITIALIZE_SUCCEEDED",e.DeinitializeFailed="CUSTOMER_STRATEGY_DEINITIALIZE_FAILED",e.DeinitializeRequested="CUSTOMER_STRATEGY_DEINITIALIZE_REQUESTED",e.DeinitializeSucceeded="CUSTOMER_STRATEGY_DEINITIALIZE_SUCCEEDED",e.WidgetInteractionStarted="CUSTOMER_STRATEGY_WIDGET_INTERACTION_STARTED",e.WidgetInteractionFinished="CUSTOMER_STRATEGY_WIDGET_INTERACTION_FINISHED",e.WidgetInteractionFailed="CUSTOMER_STRATEGY_WIDGET_INTERACTION_FAILED"}(Ut||(Ut={}));const Ft={data:{},errors:{},statuses:{}};function Bt(e=Ft,t){return n({data:xt,errors:o(qt,Be),statuses:jt})(e,t)}function xt(e=Ft.data,t){switch(t.type){case Ut.InitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case Ut.DeinitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!1}})}return e}function qt(e=Ft.errors,t){switch(t.type){case Ut.InitializeRequested:case Ut.InitializeSucceeded:return Ze(e,{initializeErrors:Object.assign({},e.initializeErrors),initializeMethodId:e.initializeMethodId?e.initializeMethodId:void 0});case Ut.InitializeFailed:return Ze(e,{initializeErrors:Object.assign(Object.assign({},e.initializeErrors),{[t.meta&&t.meta.methodId]:t.payload}),initializeMethodId:t.meta&&t.meta.methodId});case Ut.DeinitializeRequested:case Ut.DeinitializeSucceeded:return Ze(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case Ut.DeinitializeFailed:return Ze(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.SignInRequested:case Ut.SignInSucceeded:return Ze(e,{signInError:void 0,signInMethodId:void 0});case Ut.SignInFailed:return Ze(e,{signInError:t.payload,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignOutRequested:case Ut.SignOutSucceeded:return Ze(e,{signOutError:void 0,signOutMethodId:void 0});case Ut.SignOutFailed:return Ze(e,{signOutError:t.payload,signOutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutRequested:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Ze(e,{executePaymentMethodCheckoutError:void 0,executePaymentMethodCheckoutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutFailed:return Ze(e,{executePaymentMethodCheckoutError:t.payload,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.WidgetInteractionStarted:case Ut.WidgetInteractionFinished:return Ze(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case Ut.WidgetInteractionFailed:return Ze(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function jt(e=Ft.statuses,t){switch(t.type){case Ut.InitializeRequested:return Ze(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case Ut.InitializeFailed:case Ut.InitializeSucceeded:return Ze(e,{isInitializing:!1,initializeMethodId:void 0});case Ut.DeinitializeRequested:return Ze(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.DeinitializeFailed:case Ut.DeinitializeSucceeded:return Ze(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case Ut.SignInRequested:return Ze(e,{isSigningIn:!0,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignInFailed:case Ut.SignInSucceeded:return Ze(e,{isSigningIn:!1,signInMethodId:void 0});case Ut.SignOutRequested:return Ze(e,{isSigningOut:!0,signOutMethodId:t.meta&&t.meta.methodId});case Ut.SignOutFailed:case Ut.SignOutSucceeded:return Ze(e,{isSigningOut:!1,signOutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutRequested:return Ze(e,{isExecutingPaymentMethodCheckout:!0,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutFailed:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Ze(e,{isExecutingPaymentMethodCheckout:!1,executePaymentMethodCheckoutMethodId:void 0});case Ut.WidgetInteractionStarted:return Ze(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case Ut.WidgetInteractionFinished:case Ut.WidgetInteractionFailed:return Ze(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Gt;!function(e){e.LoadExtensionsRequested="LOAD_EXTENSIONS_REQUESTED",e.LoadExtensionsSucceeded="LOAD_EXTENSIONS_SUCCEEDED",e.LoadExtensionsFailed="LOAD_EXTENSIONS_FAILED",e.RenderExtensionRequested="RENDER_EXTENSION_REQUESTED",e.RenderExtensionSucceeded="RENDER_EXTENSION_SUCCEEDED",e.RenderExtensionFailed="RENDER_EXTENSION_FAILED"}(Gt||(Gt={}));const Ht={errors:{},statuses:{}};function Vt(e=Ht,t){return n({data:Yt,errors:o(Wt,Be),statuses:$t})(e,t)}function Yt(e,t){var i;return t.type===Gt.LoadExtensionsSucceeded?Ke(e,t.payload):t.type===Ne.HydrateInitialState?Ke(e,null===(i=t.payload)||void 0===i?void 0:i.extensions):e}function Wt(e=Ht.errors,t){switch(t.type){case Gt.LoadExtensionsRequested:case Gt.LoadExtensionsSucceeded:return je(e,"loadError",void 0);case Gt.RenderExtensionRequested:case Gt.RenderExtensionSucceeded:return je(e,"renderError",void 0);case Gt.LoadExtensionsFailed:return je(e,"loadError",t.payload);case Gt.RenderExtensionFailed:return je(e,"renderError",t.payload);default:return e}}function $t(e=Ht.statuses,t){switch(t.type){case Gt.LoadExtensionsRequested:return je(e,"isLoading",!0);case Gt.LoadExtensionsSucceeded:case Gt.LoadExtensionsFailed:return je(e,"isLoading",!1);default:return e}}var Kt;!function(e){e.LoadFormFieldsRequested="LOAD_FORM_FIELDS_REQUESTED",e.LoadFormFieldsSucceeded="LOAD_FORM_FIELDS_SUCCEEDED",e.LoadFormFieldsFailed="LOAD_FORM_FIELDS_FAILED"}(Kt||(Kt={}));const Zt={errors:{},statuses:{}};function Qt(e=Zt,t){return n({data:Jt,errors:o(Xt,Be),statuses:ei})(e,t)}function Jt(e,t){var i;switch(t.type){case Kt.LoadFormFieldsSucceeded:return Ze(e,t.payload);case Ne.HydrateInitialState:return Ze(e,null===(i=t.payload)||void 0===i?void 0:i.formFields);default:return e}}function Xt(e=Zt.errors,t){switch(t.type){case Kt.LoadFormFieldsSucceeded:return je(e,"loadError",void 0);case Kt.LoadFormFieldsFailed:return je(e,"loadError",t.payload);default:return e}}function ei(e=Zt.statuses,t){switch(t.type){case Kt.LoadFormFieldsRequested:return je(e,"isLoading",!0);case Kt.LoadFormFieldsSucceeded:case Kt.LoadFormFieldsFailed:return je(e,"isLoading",!1);default:return e}}var ti;!function(e){e.LoadCountriesRequested="LOAD_COUNTRIES_REQUESTED",e.LoadCountriesSucceeded="LOAD_COUNTRIES_SUCCEEDED",e.LoadCountriesFailed="LOAD_COUNTRIES_FAILED"}(ti||(ti={}));const ii={errors:{},statuses:{}};function ni(e=ii,t){return n({data:oi,errors:o(ri,Be),statuses:ai})(e,t)}function oi(e,t){return t.type===ti.LoadCountriesSucceeded?Ke(e,t.payload):e}function ri(e=ii.errors,t){switch(t.type){case ti.LoadCountriesRequested:case ti.LoadCountriesSucceeded:return je(e,"loadError",void 0);case ti.LoadCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function ai(e=ii.statuses,t){switch(t.type){case ti.LoadCountriesRequested:return je(e,"isLoading",!0);case ti.LoadCountriesSucceeded:case ti.LoadCountriesFailed:return je(e,"isLoading",!1);default:return e}}const si={errors:{},meta:{},statuses:{}};function di(e=si,t){return n({data:ci,errors:o(li,Be),meta:ui,statuses:hi})(e,t)}function ci(e,t){switch(t.type){case Ct.LoadOrderSucceeded:case Ct.LoadOrderPaymentsSucceeded:return Ze(e,k(t.payload,["billingAddress","coupons"]));default:return e}}function ui(e,t){switch(t.type){case Ct.FinalizeOrderSucceeded:case Ct.SubmitOrderSucceeded:return Ze(e,Object.assign(Object.assign({},t.meta),{callbackUrl:t.payload&&t.payload.order.callbackUrl,orderToken:t.payload&&t.payload.order.token,payment:t.payload&&t.payload.order&&t.payload.order.payment}));default:return e}}function li(e=si.errors,t){switch(t.type){case Ct.LoadOrderRequested:case Ct.LoadOrderSucceeded:case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderPaymentsRequested:return je(e,"loadError",void 0);case Ct.LoadOrderFailed:case Ct.LoadOrderPaymentsFailed:return je(e,"loadError",t.payload);default:return e}}function hi(e=si.statuses,t){switch(t.type){case Ct.LoadOrderRequested:case Ct.LoadOrderPaymentsRequested:return je(e,"isLoading",!0);case Ct.LoadOrderSucceeded:case Ct.LoadOrderFailed:case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderPaymentsFailed:return je(e,"isLoading",!1);default:return e}}const pi={};function mi(e=pi,t){return n({data:gi})(e,t)}function gi(e,t){switch(t.type){case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderSucceeded:return qe(e,t.payload&&t.payload.billingAddress);default:return e}}var yi,fi;function vi(e={},t){return n({data:Si})(e,t)}function Si(e,t){return t.type===yi.SubmitPaymentSucceeded?t.payload:e}!function(e){e.SubmitPaymentRequested="SUBMIT_PAYMENT_REQUESTED",e.SubmitPaymentSucceeded="SUBMIT_PAYMENT_SUCCEEDED",e.SubmitPaymentFailed="SUBMIT_PAYMENT_FAILED",e.InitializeOffsitePaymentRequested="INITIALIZE_OFFSITE_PAYMENT_REQUESTED",e.InitializeOffsitePaymentSucceeded="INITIALIZE_OFFSITE_PAYMENT_SUCCEEDED",e.InitializeOffsitePaymentFailed="INITIALIZE_OFFSITE_PAYMENT_FAILED"}(yi||(yi={})),function(e){e.LoadPaymentMethodRequested="LOAD_PAYMENT_METHOD_REQUESTED",e.LoadPaymentMethodSucceeded="LOAD_PAYMENT_METHOD_SUCCEEDED",e.LoadPaymentMethodFailed="LOAD_PAYMENT_METHOD_FAILED",e.LoadPaymentMethodsRequested="LOAD_PAYMENT_METHODS_REQUESTED",e.LoadPaymentMethodsSucceeded="LOAD_PAYMENT_METHODS_SUCCEEDED",e.LoadPaymentMethodsFailed="LOAD_PAYMENT_METHODS_FAILED"}(fi||(fi={}));const Ci={errors:{},statuses:{}};function Ii(e=Ci,t){return n({data:_i,errors:o(bi,Be),meta:wi,statuses:Ei})(e,t)}function _i(e,t){switch(t.type){case fi.LoadPaymentMethodSucceeded:return function(e,t,i){if(!t)return e;const n=D(t,"id"),o="object"==typeof i?M(i):i||n,r=h(e,o),a=[...e];if(-1===r)a.push(t);else{const i=e[r];a[r]=$e(i)&&$e(t)?Ze(i,t):t}return a}(e||[],t.payload,t.payload&&{id:t.payload.id,gateway:t.payload.gateway});case fi.LoadPaymentMethodsSucceeded:return Ke(e,t.payload,{matchObject:(e,t)=>e.id===t.id&&e.gateway===t.gateway});default:return e}}function wi(e,t){return t.type===fi.LoadPaymentMethodsSucceeded?Ze(e,t.meta):e}function bi(e=Ci.errors,t){switch(t.type){case fi.LoadPaymentMethodsRequested:case fi.LoadPaymentMethodsSucceeded:return je(e,"loadError",void 0);case fi.LoadPaymentMethodsFailed:return je(e,"loadError",t.payload);case fi.LoadPaymentMethodRequested:case fi.LoadPaymentMethodSucceeded:return Ze(e,{loadMethodId:void 0,loadMethodError:void 0});case fi.LoadPaymentMethodFailed:return Ze(e,{loadMethodId:t.meta.methodId,loadMethodError:t.payload});default:return e}}function Ei(e=Ci.statuses,t){switch(t.type){case fi.LoadPaymentMethodsRequested:return je(e,"isLoading",!0);case fi.LoadPaymentMethodsSucceeded:case fi.LoadPaymentMethodsFailed:return je(e,"isLoading",!1);case fi.LoadPaymentMethodRequested:return Ze(e,{isLoadingMethod:!0,loadMethodId:t.meta.methodId});case fi.LoadPaymentMethodSucceeded:case fi.LoadPaymentMethodFailed:return Ze(e,{isLoadingMethod:!1,loadMethodId:void 0});default:return e}}var Pi;!function(e){e.ExecuteFailed="PAYMENT_STRATEGY_EXECUTE_FAILED",e.ExecuteRequested="PAYMENT_STRATEGY_EXECUTE_REQUESTED",e.ExecuteSucceeded="PAYMENT_STRATEGY_EXECUTE_SUCCEEDED",e.FinalizeFailed="PAYMENT_STRATEGY_FINALIZE_FAILED",e.FinalizeRequested="PAYMENT_STRATEGY_FINALIZE_REQUESTED",e.FinalizeSucceeded="PAYMENT_STRATEGY_FINALIZE_SUCCEEDED",e.InitializeFailed="PAYMENT_STRATEGY_INITIALIZE_FAILED",e.InitializeRequested="PAYMENT_STRATEGY_INITIALIZE_REQUESTED",e.InitializeSucceeded="PAYMENT_STRATEGY_INITIALIZE_SUCCEEDED",e.DeinitializeFailed="PAYMENT_STRATEGY_DEINITIALIZE_FAILED",e.DeinitializeRequested="PAYMENT_STRATEGY_DEINITIALIZE_REQUESTED",e.DeinitializeSucceeded="PAYMENT_STRATEGY_DEINITIALIZE_SUCCEEDED",e.WidgetInteractionStarted="PAYMENT_STRATEGY_WIDGET_INTERACTION_STARTED",e.WidgetInteractionFinished="PAYMENT_STRATEGY_WIDGET_INTERACTION_FINISHED",e.WidgetInteractionFailed="PAYMENT_STRATEGY_WIDGET_INTERACTION_FAILED"}(Pi||(Pi={}));const Oi={data:{},errors:{},statuses:{}};function Ai(e=Oi,t){return n({data:Ti,errors:o(ki,Be),statuses:Ri})(e,t)}function Ti(e=Oi.data,t){switch(t.type){case Pi.InitializeSucceeded:if(t.meta){const{methodId:i,gatewayId:n}=t.meta,o=n?`${i}.${n}`:i;return Ze(e,{[o]:{isInitialized:!0}})}break;case Pi.DeinitializeSucceeded:if(t.meta){const{methodId:i,gatewayId:n}=t.meta,o=n?`${i}.${n}`:i;return Ze(e,{[o]:{isInitialized:!1}})}}return e}function ki(e=Oi.errors,t){switch(t.type){case Pi.InitializeRequested:case Pi.InitializeSucceeded:return Ze(e,{initializeError:void 0,initializeMethodId:void 0});case Pi.InitializeFailed:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{initializeError:t.payload,initializeMethodId:i})}case Pi.DeinitializeRequested:case Pi.DeinitializeSucceeded:return Ze(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case Pi.DeinitializeFailed:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{deinitializeError:t.payload,deinitializeMethodId:i})}case Pi.ExecuteRequested:case Pi.ExecuteSucceeded:return Ze(e,{executeError:void 0,executeMethodId:void 0});case Pi.ExecuteFailed:return Ze(e,{executeError:t.payload,executeMethodId:t.meta&&t.meta.methodId});case Pi.FinalizeRequested:case Pi.FinalizeSucceeded:return Ze(e,{finalizeError:void 0,finalizeMethodId:void 0});case Pi.FinalizeFailed:return Ze(e,{finalizeError:t.payload,finalizeMethodId:t.meta&&t.meta.methodId});case Pi.WidgetInteractionStarted:case Pi.WidgetInteractionFinished:return Ze(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case Pi.WidgetInteractionFailed:return Ze(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function Ri(e=Oi.statuses,t){switch(t.type){case Pi.InitializeRequested:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{isInitializing:!0,initializeMethodId:i})}case Pi.InitializeFailed:case Pi.InitializeSucceeded:return Ze(e,{isInitializing:!1,initializeMethodId:void 0});case Pi.DeinitializeRequested:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{isDeinitializing:!0,deinitializeMethodId:i})}case Pi.DeinitializeFailed:case Pi.DeinitializeSucceeded:return Ze(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case Pi.ExecuteRequested:return Ze(e,{isExecuting:!0,executeMethodId:t.meta&&t.meta.methodId});case Pi.ExecuteFailed:case Pi.ExecuteSucceeded:return Ze(e,{isExecuting:!1,executeMethodId:void 0});case Pi.FinalizeRequested:return Ze(e,{isFinalizing:!0,finalizeMethodId:t.meta&&t.meta.methodId});case Pi.FinalizeFailed:case Pi.FinalizeSucceeded:return Ze(e,{isFinalizing:!1,finalizeMethodId:void 0});case Pi.WidgetInteractionStarted:return Ze(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case Pi.WidgetInteractionFinished:case Pi.WidgetInteractionFailed:return Ze(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Di;!function(e){e.UpdatePaymentProviderCustomer="UPDATE_PAYMENT_PROVIDER_CUSTOMER"}(Di||(Di={}));const Mi={data:{}};function Ni(e=Mi,t){return n({data:Li})(e,t)}function Li(e=Mi.data,t){return t.type===Di.UpdatePaymentProviderCustomer?Ze(e,t.payload):e}var zi;!function(e){e.LoadInstrumentsRequested="LOAD_INSTRUMENTS_REQUESTED",e.LoadInstrumentsSucceeded="LOAD_INSTRUMENTS_SUCCEEDED",e.LoadInstrumentsFailed="LOAD_INSTRUMENTS_FAILED",e.DeleteInstrumentRequested="DELETE_INSTRUMENT_REQUESTED",e.DeleteInstrumentSucceeded="DELETE_INSTRUMENT_SUCCEEDED",e.DeleteInstrumentFailed="DELETE_INSTRUMENT_FAILED"}(zi||(zi={}));const Ui={data:[],errors:{},statuses:{}};function Fi(e=Ui,t){return n({data:Bi,errors:o(qi,Be),meta:xi,statuses:ji})(e,t)}function Bi(e=Ui.data,t){return t.type===zi.LoadInstrumentsSucceeded?Ke(e,t.payload&&t.payload.vaultedInstruments||[]):e}function xi(e,t){switch(t.type){case zi.LoadInstrumentsSucceeded:case zi.DeleteInstrumentSucceeded:return Ze(e,t.meta);default:return e}}function qi(e=Ui.errors,t){switch(t.type){case zi.LoadInstrumentsRequested:case zi.LoadInstrumentsSucceeded:return je(e,"loadError",void 0);case zi.DeleteInstrumentRequested:case zi.DeleteInstrumentSucceeded:return Ze(e,{deleteError:void 0,failedInstrument:void 0});case zi.LoadInstrumentsFailed:return je(e,"loadError",t.payload);case zi.DeleteInstrumentFailed:return Ze(e,{deleteError:t.payload,failedInstrument:t.meta.instrumentId});default:return e}}function ji(e=Ui.statuses,t){switch(t.type){case zi.LoadInstrumentsRequested:return je(e,"isLoading",!0);case zi.DeleteInstrumentRequested:return Ze(e,{isDeleting:!0,deletingInstrument:t.meta.instrumentId});case zi.LoadInstrumentsSucceeded:case zi.LoadInstrumentsFailed:return je(e,"isLoading",!1);case zi.DeleteInstrumentSucceeded:case zi.DeleteInstrumentFailed:return Ze(e,{isDeleting:!1,deletingInstrument:void 0});default:return e}}var Gi;!function(e){e.ForgetCheckoutRemoteCustomerRequested="FORGET_CHECKOUT_REMOTE_CUSTOMER_REQUESTED",e.ForgetCheckoutRemoteCustomerSucceeded="FORGET_CHECKOUT_REMOTE_CUSTOMER_SUCCEEDED",e.ForgetCheckoutRemoteCustomerFailed="FORGET_CHECKOUT_REMOTE_CUSTOMER_FAILED",e.InitializeRemoteBillingRequested="INITIALIZE_REMOTE_BILLING_REQUESTED",e.InitializeRemoteBillingSucceeded="INITIALIZE_REMOTE_BILLING_SUCCEEDED",e.InitializeRemoteBillingFailed="INITIALIZE_REMOTE_BILLING_FAILED",e.InitializeRemoteShippingRequested="INITIALIZE_REMOTE_SHIPPING_REQUESTED",e.InitializeRemoteShippingSucceeded="INITIALIZE_REMOTE_SHIPPING_SUCCEEDED",e.InitializeRemoteShippingFailed="INITIALIZE_REMOTE_SHIPPING_FAILED",e.InitializeRemotePaymentRequested="INITIALIZE_REMOTE_PAYMENT_REQUESTED",e.InitializeRemotePaymentSucceeded="INITIALIZE_REMOTE_PAYMENT_SUCCEEDED",e.InitializeRemotePaymentFailed="INITIALIZE_REMOTE_PAYMENT_FAILED",e.LoadRemoteSettingsRequested="LOAD_REMOTE_SETTINGS_REQUESTED",e.LoadRemoteSettingsSucceeded="LOAD_REMOTE_SETTINGS_SUCCEEDED",e.LoadRemoteSettingsFailed="LOAD_REMOTE_SETTINGS_FAILED",e.SignOutRemoteCustomerRequested="SIGN_OUT_REMOTE_CUSTOMER_REQUESTED",e.SignOutRemoteCustomerSucceeded="SIGN_OUT_REMOTE_CUSTOMER_SUCCEEDED",e.SignOutRemoteCustomerFailed="SIGN_OUT_REMOTE_CUSTOMER_FAILED",e.UpdateRemoteCheckout="UPDATE_REMOTE_CHECKOUT"}(Gi||(Gi={}));const Hi={data:{}};function Vi(e=Hi,t){return t.meta&&t.meta.methodId?n({data:n({[t.meta.methodId]:Yi})})(e,t):e}function Yi(e,t){switch(t.type){case Gi.InitializeRemoteBillingSucceeded:return je(e,"billing",t.payload&&t.payload.billing);case Gi.InitializeRemoteShippingSucceeded:return je(e,"shipping",t.payload&&t.payload.shipping);case Gi.LoadRemoteSettingsSucceeded:return je(e,"settings",t.payload);case Gi.UpdateRemoteCheckout:return Ze(e,t.payload);default:return e}}const Wi={errors:{updateShippingOptionError:{},updateError:{},deleteError:{}},statuses:{isUpdating:{},isUpdatingShippingOption:{},isDeleting:{}}};function $i(e=Wi,t){return n({data:Ki,errors:o(Zi,Be),statuses:Qi})(e,t)}function Ki(e,t){var i,n;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.LoadShippingOptionsSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:return Ke(e,t.payload&&t.payload.consignments);case Rt.SignOutCustomerSucceeded:return Ke(e,[]);case Ne.HydrateInitialState:return Ke(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.consignments);default:return e}}function Zi(e=Wi.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:case Xe.LoadShippingOptionsSucceeded:case Xe.LoadShippingOptionsRequested:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:case Xe.LoadShippingOptionsFailed:return je(e,"loadError",t.payload);case Xe.CreateConsignmentsRequested:case Xe.CreateConsignmentsSucceeded:return je(e,"createError",void 0);case Xe.CreateConsignmentsFailed:return je(e,"createError",t.payload);case Xe.UpdateConsignmentSucceeded:case Xe.UpdateConsignmentRequested:return t.meta?Ze(e,{updateError:{[t.meta.id]:void 0}}):e;case Xe.UpdateConsignmentFailed:return t.meta?Ze(e,{updateError:{[t.meta.id]:t.payload}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentRequested:return t.meta?Ze(e,{deleteError:{[t.meta.id]:void 0}}):e;case Xe.DeleteConsignmentFailed:return t.meta?Ze(e,{deleteError:{[t.meta.id]:t.payload}}):e;case Xe.UpdateShippingOptionRequested:case Xe.UpdateShippingOptionSucceeded:return t.meta?Ze(e,{updateShippingOptionError:{[t.meta.id]:void 0}}):e;case Xe.UpdateShippingOptionFailed:return t.meta?Ze(e,{updateShippingOptionError:{[t.meta.id]:t.payload}}):e;default:return e}}function Qi(e=Wi.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Xe.LoadShippingOptionsRequested:return je(e,"isLoadingShippingOptions",!0);case Me.LoadCheckoutSucceeded:case Me.LoadCheckoutFailed:return je(e,"isLoading",!1);case Xe.LoadShippingOptionsSucceeded:case Xe.LoadShippingOptionsFailed:return je(e,"isLoadingShippingOptions",!1);case Xe.CreateConsignmentsRequested:return je(e,"isCreating",!0);case Xe.CreateConsignmentsSucceeded:case Xe.CreateConsignmentsFailed:return je(e,"isCreating",!1);case Xe.UpdateConsignmentRequested:return t.meta?Ze(e,{isUpdating:{[t.meta.id]:!0}}):e;case Xe.UpdateConsignmentSucceeded:case Xe.UpdateConsignmentFailed:return t.meta?Ze(e,{isUpdating:{[t.meta.id]:!1}}):e;case Xe.DeleteConsignmentRequested:return t.meta?Ze(e,{isDeleting:{[t.meta.id]:!0}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentFailed:return t.meta?Ze(e,{isDeleting:{[t.meta.id]:!1}}):e;case Xe.UpdateShippingOptionRequested:return t.meta?Ze(e,{isUpdatingShippingOption:{[t.meta.id]:!0}}):e;case Xe.UpdateShippingOptionSucceeded:case Xe.UpdateShippingOptionFailed:return t.meta?Ze(e,{isUpdatingShippingOption:{[t.meta.id]:!1}}):e;default:return e}}function Ji(e,t){const i={};return Object.keys(e).forEach(n=>{const o=e[n],r=t?`${t}.${n}`:n;"object"==typeof o?Object.assign(i,Ji(o,r)):i[r]=o}),i}function Xi(e){return Object.keys(e).sort().reduce((t,i)=>Object.assign(Object.assign({},t),{[i]:e[i]}),{})}var en;!function(e){e.LoadPickupOptionsRequested="LOAD_PICKUP_OPTIONS_REQUESTED",e.LoadPickupOptionsSucceeded="LOAD_PICKUP_OPTIONS_SUCCEEDED",e.LoadPickupOptionsFailed="LOAD_PICKUP_OPTIONS_FAILED"}(en||(en={}));const tn={errors:{},statuses:{}};function nn(e=tn,t){return n({data:on,errors:o(rn,Be),statuses:an})(e,t)}function on(e,t){if(t.type!==en.LoadPickupOptionsSucceeded)return e;if(t.meta){const i=Xi(Ji({consignmentId:t.meta.consignmentId,searchArea:t.meta.searchArea}));return je(e,btoa(`${JSON.stringify(i)}`),t.payload)}}function rn(e=tn.errors,t){switch(t.type){case en.LoadPickupOptionsRequested:case en.LoadPickupOptionsSucceeded:return je(e,"loadError",void 0);case en.LoadPickupOptionsFailed:return je(e,"loadError",t.payload);default:return e}}function an(e=tn.statuses,t){switch(t.type){case en.LoadPickupOptionsRequested:return je(e,"isLoading",!0);case en.LoadPickupOptionsSucceeded:case en.LoadPickupOptionsFailed:return je(e,"isLoading",!1);default:return e}}var sn;!function(e){e.LoadShippingCountriesRequested="LOAD_SHIPPING_COUNTRIES_REQUESTED",e.LoadShippingCountriesSucceeded="LOAD_SHIPPING_COUNTRIES_SUCCEEDED",e.LoadShippingCountriesFailed="LOAD_SHIPPING_COUNTRIES_FAILED"}(sn||(sn={}));const dn={errors:{},statuses:{}};function cn(e=dn,t){return n({data:un,errors:o(ln,Be),statuses:hn})(e,t)}function un(e,t){return t.type===sn.LoadShippingCountriesSucceeded?Ke(e,t.payload):e}function ln(e=dn.errors,t){switch(t.type){case sn.LoadShippingCountriesRequested:case sn.LoadShippingCountriesSucceeded:return je(e,"loadError",void 0);case sn.LoadShippingCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function hn(e=dn.statuses,t){switch(t.type){case sn.LoadShippingCountriesRequested:return je(e,"isLoading",!0);case sn.LoadShippingCountriesSucceeded:case sn.LoadShippingCountriesFailed:return je(e,"isLoading",!1);default:return e}}var pn;!function(e){e.UpdateAddressFailed="SHIPPING_STRATEGY_UPDATE_ADDRESS_FAILED",e.UpdateAddressRequested="SHIPPING_STRATEGY_UPDATE_ADDRESS_REQUESTED",e.UpdateAddressSucceeded="SHIPPING_STRATEGY_UPDATE_ADDRESS_SUCCEEDED",e.SelectOptionFailed="SHIPPING_STRATEGY_SELECT_OPTION_FAILED",e.SelectOptionRequested="SHIPPING_STRATEGY_SELECT_OPTION_REQUESTED",e.SelectOptionSucceeded="SHIPPING_STRATEGY_SELECT_OPTION_SUCCEEDED",e.InitializeFailed="SHIPPING_STRATEGY_INITIALIZE_FAILED",e.InitializeRequested="SHIPPING_STRATEGY_INITIALIZE_REQUESTED",e.InitializeSucceeded="SHIPPING_STRATEGY_INITIALIZE_SUCCEEDED",e.DeinitializeFailed="SHIPPING_STRATEGY_DEINITIALIZE_FAILED",e.DeinitializeRequested="SHIPPING_STRATEGY_DEINITIALIZE_REQUESTED",e.DeinitializeSucceeded="SHIPPING_STRATEGY_DEINITIALIZE_SUCCEEDED",e.WidgetInteractionStarted="SHIPPING_STRATEGY_WIDGET_INTERACTION_STARTED",e.WidgetInteractionFinished="SHIPPING_STRATEGY_WIDGET_INTERACTION_FINISHED",e.WidgetInteractionFailed="SHIPPING_STRATEGY_WIDGET_INTERACTION_FAILED"}(pn||(pn={}));const mn={data:{},errors:{},statuses:{}};function gn(e=mn,t){return n({data:yn,errors:o(fn,Be),statuses:vn})(e,t)}function yn(e=mn.data,t){switch(t.type){case pn.InitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case pn.DeinitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!1}})}return e}function fn(e=mn.errors,t){switch(t.type){case pn.InitializeRequested:case pn.InitializeSucceeded:return Ze(e,{initializeError:void 0,initializeMethodId:void 0});case pn.InitializeFailed:return Ze(e,{initializeError:t.payload,initializeMethodId:t.meta&&t.meta.methodId});case pn.DeinitializeRequested:case pn.DeinitializeSucceeded:return Ze(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case pn.DeinitializeFailed:return Ze(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case pn.UpdateAddressRequested:case pn.UpdateAddressSucceeded:return Ze(e,{updateAddressError:void 0,updateAddressMethodId:void 0});case pn.UpdateAddressFailed:return Ze(e,{updateAddressError:t.payload,updateAddressMethodId:t.meta&&t.meta.methodId});case pn.SelectOptionRequested:case pn.SelectOptionSucceeded:return Ze(e,{selectOptionError:void 0,selectOptionMethodId:void 0});case pn.SelectOptionFailed:return Ze(e,{selectOptionError:t.payload,selectOptionMethodId:t.meta&&t.meta.methodId});case pn.WidgetInteractionStarted:case pn.WidgetInteractionFinished:return Ze(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case pn.WidgetInteractionFailed:return Ze(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta&&t.meta.methodId});default:return e}}function vn(e=mn.statuses,t){switch(t.type){case pn.InitializeRequested:return Ze(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case pn.InitializeFailed:case pn.InitializeSucceeded:return Ze(e,{isInitializing:!1,initializeMethodId:void 0});case pn.DeinitializeRequested:return Ze(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case pn.DeinitializeFailed:case pn.DeinitializeSucceeded:return Ze(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case pn.UpdateAddressRequested:return Ze(e,{isUpdatingAddress:!0,updateAddressMethodId:t.meta&&t.meta.methodId});case pn.UpdateAddressFailed:case pn.UpdateAddressSucceeded:return Ze(e,{isUpdatingAddress:!1,updateAddressMethodId:void 0});case pn.SelectOptionRequested:return Ze(e,{isSelectingOption:!0,selectOptionMethodId:t.meta&&t.meta.methodId});case pn.SelectOptionFailed:case pn.SelectOptionSucceeded:return Ze(e,{isSelectingOption:!1,selectOptionMethodId:void 0});case pn.WidgetInteractionStarted:return Ze(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta&&t.meta.methodId});case pn.WidgetInteractionFinished:case pn.WidgetInteractionFailed:return Ze(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Sn;!function(e){e.SendSignInEmailRequested="SEND_SIGNIN_EMAIL_REQUESTED",e.SendSignInEmailSucceeded="SEND_SIGNIN_EMAIL_SUCCEEDED",e.SendSignInEmailFailed="SEND_SIGNIN_EMAIL_FAILED"}(Sn||(Sn={}));const Cn={errors:{},statuses:{}};function In(e=Cn,t){return n({data:_n,errors:o(wn,Be),statuses:bn})(e,t)}function _n(e,t){return t.type===Sn.SendSignInEmailSucceeded?Ze(e,t.payload):e}function wn(e=Cn.errors,t){switch(t.type){case Sn.SendSignInEmailRequested:case Sn.SendSignInEmailSucceeded:return je(e,"sendError",void 0);case Sn.SendSignInEmailFailed:return je(e,"sendError",t.payload);default:return e}}function bn(e=Cn.statuses,t){switch(t.type){case Sn.SendSignInEmailRequested:return je(e,"isSending",!0);case Sn.SendSignInEmailFailed:case Sn.SendSignInEmailSucceeded:return je(e,"isSending",!1);default:return e}}var En;!function(e){e.ApplyStoreCreditRequested="APPLY_STORE_CREDIT_REQUESTED",e.ApplyStoreCreditSucceeded="APPLY_STORE_CREDIT_SUCCEEDED",e.ApplyStoreCreditFailed="APPLY_STORE_CREDIT_FAILED"}(En||(En={}));const Pn={errors:{},statuses:{}};function On(e=Pn,t){return n({errors:o(An,Be),statuses:Tn})(e,t)}function An(e=Pn.errors,t){switch(t.type){case En.ApplyStoreCreditRequested:case En.ApplyStoreCreditSucceeded:return je(e,"applyError",void 0);case En.ApplyStoreCreditFailed:return je(e,"applyError",t.payload);default:return e}}function Tn(e=Pn.statuses,t){switch(t.type){case En.ApplyStoreCreditRequested:return je(e,"isApplying",!0);case En.ApplyStoreCreditSucceeded:case En.ApplyStoreCreditFailed:return je(e,"isApplying",!1);default:return e}}const kn={errors:{},statuses:{}};function Rn(e=kn,t){return n({errors:o(Dn,Be),statuses:Mn})(e,t)}function Dn(e=kn.errors,t){switch(t.type){case ze.UpdateSubscriptionsRequested:case ze.UpdateSubscriptionsSucceeded:return je(e,"updateError",void 0);case ze.UpdateSubscriptionsFailed:return je(e,"updateError",t.payload);default:return e}}function Mn(e=kn.statuses,t){switch(t.type){case ze.UpdateSubscriptionsRequested:return je(e,"isUpdating",!0);case ze.UpdateSubscriptionsFailed:case ze.UpdateSubscriptionsSucceeded:return je(e,"isUpdating",!1);default:return e}}var Nn;!function(e){e.InitializeFailed="SPAM_PROTECTION_INITIALIZE_FAILED",e.InitializeSucceeded="SPAM_PROTECTION_INITIALIZE_SUCCEEDED",e.InitializeRequested="SPAM_PROTECTION_INITIALIZE_REQUESTED",e.VerifyCheckoutRequested="SPAM_PROTECTION_CHECKOUT_VERIFY_REQUESTED",e.VerifyCheckoutSucceeded="SPAM_PROTECTION_CHECKOUT_VERIFY_SUCCEEDED",e.VerifyCheckoutFailed="SPAM_PROTECTION_CHECKOUT_VERIFY_FAILED",e.ExecuteRequested="SPAM_PROTECTION_EXECUTE_REQUESTED",e.ExecuteSucceeded="SPAM_PROTECTION_EXECUTE_SUCCEEDED",e.ExecuteFailed="SPAM_PROTECTION_EXECUTE_FAILED"}(Nn||(Nn={}));const Ln={errors:{},statuses:{}};function zn(e=Ln,t){return n({data:Un,errors:o(Fn,Be),statuses:Bn})(e,t)}function Un(e,t){var i;switch(t.type){case Me.LoadCheckoutSucceeded:case Me.UpdateCheckoutSucceeded:case En.ApplyStoreCreditSucceeded:case Ue.UpdateBillingAddressSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Xe.LoadShippingOptionsSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:case Nn.VerifyCheckoutSucceeded:return Ze(e,k(t.payload,["billingAddress","cart","consignments","customer","coupons","giftCertificates"]));case Ct.SubmitOrderSucceeded:return je(e,"orderId",t.payload&&t.payload.order.orderId);case Ne.HydrateInitialState:return Ze(e,k(null===(i=t.payload)||void 0===i?void 0:i.checkout,["billingAddress","cart","consignments","customer","coupons","giftCertificates"]));default:return e}}function Fn(e=Ln.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:return je(e,"loadError",t.payload);case Me.UpdateCheckoutRequested:case Me.UpdateCheckoutSucceeded:return je(e,"updateError",void 0);case Me.UpdateCheckoutFailed:return je(e,"updateError",t.payload);default:return e}}function Bn(e=Ln.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Me.LoadCheckoutFailed:case Me.LoadCheckoutSucceeded:return je(e,"isLoading",!1);case Me.UpdateCheckoutRequested:return je(e,"isUpdating",!0);case Me.UpdateCheckoutFailed:case Me.UpdateCheckoutSucceeded:return je(e,"isUpdating",!1);case Nn.ExecuteRequested:return je(e,"isExecutingSpamCheck",!0);case Nn.ExecuteFailed:case Nn.ExecuteSucceeded:return je(e,"isExecutingSpamCheck",!1);default:return e}}var xn;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentProviderCustomer=13]="MissingPaymentProviderCustomer",e[e.MissingPaymentRedirectUrl=14]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=15]="MissingPaymentStatus",e[e.MissingPaymentToken=16]="MissingPaymentToken",e[e.MissingShippingAddress=17]="MissingShippingAddress"}(xn||(xn={}));class qn extends be{constructor(e){super(function(e){switch(e){case xn.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case xn.MissingCart:return"Unable to proceed because cart data is unavailable.";case xn.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case xn.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case xn.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case xn.MissingCheckoutConfig:case xn.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case xn.MissingOrder:return"Unable to proceed because order data is unavailable.";case xn.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case xn.MissingPayment:return"Unable to proceed because payment data is unavailable.";case xn.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case xn.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case xn.MissingPaymentProviderCustomer:return"Unable to proceed because payment provider customer is unavailable.";case xn.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(e)),this.subtype=e,this.name="MissingDataError",this.type="missing_data"}}const jn=(Gn=de,(...e)=>{const t=e.pop();return Gn(...e,(...e)=>{const i=t(...e);return"function"==typeof i?ae(i):i})});var Gn;function Hn(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}function Vn(e){return function(e){const t=Object.create(e);return function(e,t){let i=Object.getPrototypeOf(e);for(;i;)t(i),i=Object.getPrototypeOf(i)}(e,i=>{Object.getOwnPropertyNames(i).forEach(i=>{"constructor"!==i&&"function"==typeof t[i]&&"_"!==i.charAt(0)&&(t[i]=((e,t)=>(...i)=>d(e[t].call(e,...i)))(e,i))})}),t}(e)}const Yn={"mollie.credit_card":{provider:"mollie",method:"credit_card"},"adyenv2.scheme":{provider:"adyenv2",method:"scheme"},"adyenv3.scheme":{provider:"adyenv3",method:"scheme"},"adyenv2.bcmc":{provider:"adyenv2",method:"bcmc"},"adyenv2.ideal":{provider:"adyenv2",method:"ideal"},"adyenv2.sepadirectdebit":{provider:"adyenv2",method:"sepadirectdebit"},"adyenv2.directEbanking":{provider:"adyenv2",method:"directEbanking"},"adyenv2.giropay":{provider:"adyenv2",method:"giropay"},braintree:{provider:"braintree",method:"credit_card"},braintreepaypal:{provider:"braintree",method:"paypal"},braintreeach:{provider:"braintree",method:"ach"},authorizenet:{provider:"authorizenet",method:"credit_card"},elavon:{provider:"elavon",method:"credit_card"},checkoutcom:{provider:"checkoutcom",method:"credit_card"},"checkoutcom.credit_card":{provider:"checkoutcom",method:"credit_card"},"checkoutcom.card":{provider:"checkoutcom",method:"card"},sagepay:{provider:"sagepay",method:"credit_card"},stripe:{provider:"stripe",method:"credit_card"},"stripev3.card":{provider:"stripev3",method:"card"},"stripeupe.card":{provider:"stripeupe",method:"card"},cybersource:{provider:"cybersource",method:"credit_card"},cybersourcev2:{provider:"cybersourcev2",method:"credit_card"},bnz:{provider:"bnz",method:"credit_card"},converge:{provider:"converge",method:"credit_card"},bluesnapv2:{provider:"bluesnapv2",method:"credit_card"},"bluesnapdirect.credit_card":{provider:"bluesnapdirect",method:"credit_card"},"bluesnapdirect.ecp":{provider:"bluesnapdirect",method:"ecp"},"bluesnapdirect.sepa_direct_debit":{provider:"bluesnapdirect",method:"sepa_direct_debit"},orbital:{provider:"orbital",method:"credit_card"},paymetric:{provider:"paymetric",method:"credit_card"},bolt:{provider:"bolt",method:"credit_card"},"barclaycard.credit_card":{provider:"barclaycard",method:"credit_card"},moneris:{provider:"moneris",method:"credit_card"},cba_mpgs:{provider:"cba_mpgs",method:"credit_card"},worldpayaccess:{provider:"worldpayaccess",method:"credit_card"},squarev2:{provider:"squarev2",method:"credit_card"},paypalcommercecreditcards:{provider:"paypalcommerce",method:"credit_card"},paypalcommerce:{provider:"paypalcommerce",method:"paypal"},bigcommerce_payments_creditcards:{provider:"bigcommerce_payments",method:"credit_card"},bigcommerce_payments:{provider:"bigcommerce_payments",method:"paypal"},tdonlinemart:{provider:"tdonlinemart",method:"credit_card"}};function Wn(e){return M({firstName:e.firstName,lastName:e.lastName,company:e.company,address1:e.address1,address2:e.address2,city:e.city,stateOrProvince:e.stateOrProvince,countryCode:e.countryCode,postalCode:e.postalCode,phone:e.phone,customFields:e.customFields},m)}const $n={errors:{},statuses:{}};function Kn(){const e=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingBillingAddress))),i=jn(e=>e.errors.updateError,e=>()=>e),n=jn(e=>e.errors.continueAsGuestError,e=>()=>e),o=jn(e=>e.errors.loadError,e=>()=>e),r=jn(e=>!!e.statuses.isUpdating,e=>()=>e),a=jn(e=>!!e.statuses.isContinuingAsGuest,e=>()=>e),s=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((d=Ge)=>({getBillingAddress:e(d),getBillingAddressOrThrow:t(d),getUpdateError:i(d),getContinueAsGuestError:n(d),getLoadError:o(d),isUpdating:r(d),isContinuingAsGuest:a(d),isLoading:s(d)}))}(),t=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingCart))),i=jn(e=>e.errors.loadError,e=>()=>e),n=jn(e=>!!e.statuses.isLoading,e=>()=>e),o=jn(e=>{var t;return null===(t=e.data)||void 0===t?void 0:t.locale},e=>()=>e);return se((r=et)=>({getCart:e(r),getCartOrThrow:t(r),getLoadError:i(r),isLoading:n(r),getLocale:o(r)}))}(),i=function(){const e=jn(e=>e,e=>()=>e),t=jn(e=>e.statuses,e=>ae(t=>{if(t){const i=e[t];return!0===(i&&i.isInitializing)}return z(e,{isInitializing:!0})})),i=jn(e=>e.data,e=>ae((t,i)=>{const n=e[t];return!!n&&(i?!0===n.initializedContainers[i]:z(n.initializedContainers,e=>!0===e))})),n=jn(e=>e.statuses,e=>ae(t=>{if(t){const i=e[t];return!0===(i&&i.isDeinitializing)}return z(e,{isDeinitializing:!0})})),o=jn(e=>e.errors,e=>ae(t=>{const i=t?e[t]:l(x(e),e=>!(!e||!e.initializeError));return i&&i.initializeError})),r=jn(e=>e.errors,e=>ae(t=>{const i=t?e[t]:l(x(e),e=>!(!e||!e.deinitializeError));return i&&i.deinitializeError}));return se((a=at)=>({getState:e(a),isInitializing:t(a),isInitialized:i(a),isDeinitializing:n(a),getInitializeError:o(a),getDeinitializeError:r(a)}))}(),n=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.data,e=>t=>{if(!e)return;const{flashMessages:i}=e.context;return i?void 0!==t?i.filter(({type:e})=>t===e):i:void 0}),i=jn(e=>e.data,(e,{formState:t})=>t&&t.data,(e,t={customerAccount:[],shippingAddress:[],billingAddress:[]})=>()=>e?Object.assign(Object.assign({},e.storeConfig),{formFields:t}):void 0),n=jn(i,e=>()=>Hn(e(),()=>new qn(xn.MissingCheckoutConfig))),o=jn(e=>e.data&&e.data.context,e=>()=>e),r=jn(e=>e.meta&&e.meta.externalSource,e=>()=>e),a=jn(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.host},e=>()=>e),s=jn(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.locale},e=>()=>e),d=jn(e=>e.meta&&e.meta.variantIdentificationToken,e=>()=>e),c=jn(e=>e.errors.loadError,e=>()=>e),u=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((l=gt,h)=>({getConfig:e(l),getFlashMessages:t(l),getStoreConfig:i(l,{formState:h}),getStoreConfigOrThrow:n(l,{formState:h}),getContextConfig:o(l),getExternalSource:r(l),getHost:a(l),getLocale:s(l),getVariantIdentificationToken:d(l),getLoadError:c(l),isLoading:u(l)}))}(),o=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.loadError,e=>()=>e),i=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((n=ii)=>({getCountries:e(n),getLoadError:t(n),isLoading:i(n)}))}(),r=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.removeCouponError,e=>()=>e),i=jn(e=>e.errors.applyCouponError,e=>()=>e),n=jn(e=>!!e.statuses.isApplyingCoupon,e=>()=>e),o=jn(e=>!!e.statuses.isRemovingCoupon,e=>()=>e);return se((r=It)=>({getCoupons:e(r),getRemoveError:t(r),getApplyError:i(r),isApplying:n(r),isRemoving:o(r)}))}(),a=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingCustomer))),i=jn(e=>e.errors.createError,e=>()=>e),n=jn(e=>!!e.statuses.isCreating,e=>()=>e),o=jn(e=>e.errors.createAddressError,e=>()=>e),r=jn(e=>!!e.statuses.isCreatingAddress,e=>()=>e);return se((a=Dt)=>({getCustomer:e(a),getCustomerOrThrow:t(a),getCreateAccountError:i(a),isCreatingCustomerAccount:n(a),getCreateAddressError:o(a),isCreatingCustomerAddress:r(a)}))}(),s=function(){const e=jn(e=>e.errors.signInMethodId,e=>e.errors.signInError,(e,t)=>i=>{if(!i||e===i)return t}),t=jn(e=>e.errors.signOutMethodId,e=>e.errors.signOutError,(e,t)=>i=>{if(!i||e===i)return t}),i=jn(e=>e.errors.executePaymentMethodCheckoutMethodId,e=>e.errors.executePaymentMethodCheckoutError,(e,t)=>i=>{if(!i||e===i)return t}),n=jn(e=>e.errors.initializeMethodId,e=>e.errors.initializeErrors,(e,t)=>i=>{if(e&&t)return i?t[i]:t[e]}),o=jn(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>i=>{if(!i||e===i)return t}),r=jn(e=>e.statuses.signInMethodId,e=>e.statuses.isSigningIn,(e,t)=>i=>!(i&&e!==i||!t)),a=jn(e=>e.statuses.signOutMethodId,e=>e.statuses.isSigningOut,(e,t)=>i=>!(i&&e!==i||!t)),s=jn(e=>e.statuses.executePaymentMethodCheckoutMethodId,e=>e.statuses.isExecutingPaymentMethodCheckout,(e,t)=>i=>!(i&&e!==i||!t)),d=jn(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>i=>!(i&&e!==i||!t)),c=jn(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),u=jn(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>i=>!(i&&e!==i||!t));return se((l=Ft)=>({getSignInError:e(l),getSignOutError:t(l),getExecutePaymentMethodCheckoutError:i(l),getInitializeError:n(l),getWidgetInteractionError:o(l),isSigningIn:r(l),isSigningOut:a(l),isExecutingPaymentMethodCheckout:s(l),isInitializing:d(l),isInitialized:c(l),isWidgetInteracting:u(l)}))}(),d=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.removeGiftCertificateError,e=>()=>e),i=jn(e=>e.errors.applyGiftCertificateError,e=>()=>e),n=jn(e=>!!e.statuses.isApplyingGiftCertificate,e=>()=>e),o=jn(e=>!!e.statuses.isRemovingGiftCertificate,e=>()=>e);return se((r=Pt)=>({getGiftCertificates:e(r),getRemoveError:t(r),getApplyError:i(r),isApplying:n(r),isRemoving:o(r)}))}(),c=function(){const e=jn(e=>e.data,e=>t=>{if(!e)return;const i=t.gateway?`${t.gateway}.${t.id}`:t.id,n=Yn[i];return n?u(e,n):[]}),t=jn(e=>e.data,(e=[])=>t=>{const i=x(Yn);return e.find(e=>e.bigpayToken===t&&"card"===e.type&&i.some(t=>S(e,t)))}),i=jn(t,e=>t=>Hn(e(t),()=>new qn(xn.MissingPaymentInstrument))),n=jn(e=>e.data,e=>()=>{if(e)return p(Yn,t=>u(e,e=>S(e,t)))}),o=jn(e=>e.meta,e=>()=>e),r=jn(e=>e.errors.loadError,e=>()=>e),a=jn(e=>e.errors.failedInstrument,e=>e.errors.deleteError,(e,t)=>i=>{if(!i||e===i)return t}),s=jn(e=>e.statuses.isLoading,e=>()=>!!e),d=jn(e=>e.statuses.deletingInstrument,e=>e.statuses.isDeleting,(e,t)=>i=>!(i&&e!==i||!t));return se((c=Ui)=>({getCardInstrument:t(c),getCardInstrumentOrThrow:i(c),getInstruments:n(c),getInstrumentsByPaymentMethod:e(c),getInstrumentsMeta:o(c),getLoadError:r(c),getDeleteError:a(c),isLoading:s(c),isDeleting:d(c)}))}(),h=function(){const e=jn(e=>e.data,e=>(t=[],i)=>{const n=l(t,{code:i});return(e?e.shippingAddress:[]).map(e=>r(e,t,n))}),t=jn(e=>e.data,e=>(t=[],i)=>{const n=l(t,{code:i});return(e?e.billingAddress:[]).map(e=>r(e,t,n))}),i=jn(e=>e.data,e=>()=>e?e.customerAccount:[]),n=jn(e=>e.errors.loadError,e=>()=>e),o=jn(e=>!!e.statuses.isLoading,e=>()=>e);function r(e,t,i){return"countryCode"===e.name?function(e,t=[],i){if(!t.length)return e;const{code:n=""}=i||{},o=t.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{options:{items:o},default:n,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,t,i):"stateOrProvince"===e.name?function(e,t){const{subdivisions:i=[],requiresState:n}=t||{};if(!i.length)return Object.assign(Object.assign({},e),{required:null!=n&&n});const o=i.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{name:"stateOrProvinceCode",options:{items:o},required:null==n||n,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,i):"postalCode"===e.name?function(e,t){const{hasPostalCodes:i=[]}=t||{};return void 0===i?e:Object.assign(Object.assign({},e),{required:Boolean(i)})}(e,i):e}return se((r=Zt)=>({getShippingAddressFields:e(r),getBillingAddressFields:t(r),getCustomerAccountFields:i(r),getLoadError:n(r),isLoading:o(r)}))}(),m=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.meta,e=>()=>e),i=jn(e=>e.data,e=>(t,i)=>l(e,i?{id:t,gateway:i}:{id:t})),n=jn(i,e=>(t,i)=>Hn(e(t,i),()=>new qn(xn.MissingPaymentMethod))),o=jn(e=>e.errors.loadError,e=>()=>e),r=jn(e=>e.errors.loadMethodId,e=>e.errors.loadMethodError,(e,t)=>i=>{if(!i||e===i)return t}),a=jn(e=>e.statuses.isLoading,e=>()=>!!e),s=jn(e=>e.statuses.loadMethodId,e=>e.statuses.isLoadingMethod,(e,t)=>i=>!(i&&e!==i||!t));return se((d=Ci)=>({getPaymentMethods:e(d),getPaymentMethodsMeta:t(d),getPaymentMethod:i(d),getPaymentMethodOrThrow:n(d),getLoadError:o(d),getLoadMethodError:r(d),isLoading:a(d),isLoadingMethod:s(d)}))}(),g=function(){const e=jn(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>i=>{if(!i||e===i)return t}),t=jn(e=>e.errors.executeMethodId,e=>e.errors.executeError,(e,t)=>i=>{if(!i||e===i)return t}),i=jn(e=>e.errors.finalizeMethodId,e=>e.errors.finalizeError,(e,t)=>i=>{if(!i||e===i)return t}),n=jn(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>i=>{if(!i||e===i)return t}),o=jn(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>i=>!(i&&e!==i||!t)),r=jn(e=>e.data,e=>t=>{const i=t.gatewayId?`${t.methodId}.${t.gatewayId}`:t.methodId;return!(!e[i]||!e[i].isInitialized)}),a=jn(e=>e.statuses.executeMethodId,e=>e.statuses.isExecuting,(e,t)=>i=>!(i&&e!==i||!t)),s=jn(e=>e.statuses.finalizeMethodId,e=>e.statuses.isFinalizing,(e,t)=>i=>!(i&&e!==i||!t)),d=jn(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>i=>!(i&&e!==i||!t));return se((c=Oi)=>({getInitializeError:e(c),getExecuteError:t(c),getFinalizeError:i(c),getWidgetInteractingError:n(c),isInitializing:o(c),isInitialized:r(c),isExecuting:a(c),isFinalizing:s(c),isWidgetInteracting:d(c)}))}(),y=function(){const e=jn(e=>e.data,e=>(t,i)=>{if(!e)return;const n=Xi(Ji({consignmentId:t,searchArea:i})),o=btoa(`${JSON.stringify(n)}`);return e[o]}),t=jn(e=>e.errors.loadError,e=>()=>e),i=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((n=tn)=>({getPickupOptions:e(n),getLoadError:t(n),isLoading:i(n)}))}(),f=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentProviderCustomer)));return se((i=Mi)=>({getPaymentProviderCustomer:e(i),getPaymentProviderCustomerOrThrow:t(i)}))}(),C=function(){const e=jn(e=>e.data,e=>t=>e[t]);return se((t=Hi)=>({getCheckout:e(t)}))}(),I=function(){const e=jn(e=>e.data,e=>()=>{const t=null==e?void 0:e.find(e=>!e.selectedPickupOption);return null==t?void 0:t.shippingAddress}),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingShippingAddress))),i=jn(e=>e.data,e=>()=>{const t=null==e?void 0:e.filter(e=>!e.selectedPickupOption);return t?t.map(e=>e.shippingAddress):[]}),n=jn(i,e=>()=>Hn(e(),()=>new qn(xn.MissingShippingAddress)));return se((o=Wi)=>({getShippingAddress:e(o),getShippingAddressOrThrow:t(o),getShippingAddresses:i(o),getShippingAddressesOrThrow:n(o)}))}(),_=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.loadError,e=>()=>e),i=jn(e=>e.statuses.isLoading,e=>()=>!!e);return se((n=dn)=>({getShippingCountries:e(n),getLoadError:t(n),isLoading:i(n)}))}(),w=function(){const e=jn(e=>e.errors.updateAddressMethodId,e=>e.errors.updateAddressError,(e,t)=>i=>{if(!i||e===i)return t}),t=jn(e=>e.errors.selectOptionMethodId,e=>e.errors.selectOptionError,(e,t)=>i=>{if(!i||e===i)return t}),i=jn(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>i=>{if(!i||e===i)return t}),n=jn(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>i=>{if(!i||e===i)return t}),o=jn(e=>e.statuses.updateAddressMethodId,e=>e.statuses.isUpdatingAddress,(e,t)=>i=>!(i&&e!==i||!t)),r=jn(e=>e.statuses.selectOptionMethodId,e=>e.statuses.isSelectingOption,(e,t)=>i=>!(i&&e!==i||!t)),a=jn(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>i=>!(i&&e!==i||!t)),s=jn(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),d=jn(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>i=>!(i&&e!==i||!t));return se((c=mn)=>({getUpdateAddressError:e(c),getSelectOptionError:t(c),getInitializeError:i(c),getWidgetInteractionError:n(c),isUpdatingAddress:o(c),isSelectingOption:r(c),isInitializing:a(c),isInitialized:s(c),isWidgetInteracting:d(c)}))}(),b=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingConsignments))),i=jn(e=>e.data,e=>t=>{if(e&&e.length)return l(e,{id:t})}),n=jn(e=>e.data,e=>t=>{if(e&&e.length)return l(e,e=>{return i=e.shippingAddress,n=t,v(Wn(i),Wn(n));var i,n})}),o=jn(e=>e.data,e=>()=>{if(e&&e.length)return e[0].selectedShippingOption}),r=jn(e=>e.errors.loadError,e=>()=>e),a=jn(e=>e.errors.createError,e=>()=>e),s=jn(e=>e.errors.loadShippingOptionsError,e=>()=>e),d=jn(e,(e,{cart:t})=>t.getCart,(e,t)=>()=>{const i=t();if(!i)return[];const n=(e()||[]).reduce((e,t)=>e.concat(t.lineItemIds),[]);return(i.lineItems.physicalItems||[]).filter(e=>n.indexOf(e.id)<0)}),c=jn(e=>e.errors.updateError,e=>t=>t?e[t]:l(e)),u=jn(e=>e.errors.deleteError,e=>t=>t?e[t]:l(e)),h=jn(n,c,a,(e,t,i)=>n=>{const o=e(n);return o?t(o.id):i()}),p=jn(e=>e.errors.updateShippingOptionError,e=>t=>t?e[t]:l(e)),m=jn(e=>e.statuses.isLoading,e=>()=>!0===e),g=jn(e=>e.statuses.isLoadingShippingOptions,e=>()=>!0===e),y=jn(e=>e.statuses.isCreating,e=>()=>!0===e),f=jn(e=>e.statuses.isUpdating,e=>t=>t?!0===e[t]:!0===l(e)),S=jn(e=>e.statuses.isDeleting,e=>t=>t?!0===e[t]:!0===l(e)),C=jn(n,f,y,(e,t,i)=>n=>{const o=e(n);return o?t(o.id):i()}),I=jn(e=>e.statuses.isUpdatingShippingOption,e=>t=>t?!0===e[t]:!0===l(e));return se((l=Wi,v)=>({getConsignments:e(l),getConsignmentsOrThrow:t(l),getConsignmentById:i(l),getConsignmentByAddress:n(l),getShippingOption:o(l),getLoadError:r(l),getCreateError:a(l),getLoadShippingOptionsError:s(l),getUnassignedItems:d(l,{cart:v}),getUpdateError:c(l),getDeleteError:u(l),getItemAssignmentError:h(l),getUpdateShippingOptionError:p(l),isLoading:m(l),isLoadingShippingOptions:g(l),isCreating:y(l),isUpdating:f(l),isDeleting:S(l),isAssigningItems:C(l),isUpdatingShippingOption:I(l)}))}(),E=function(){const e=jn(e=>e.data,(e,{billingAddress:t})=>t.getBillingAddress,(e,{cart:t})=>t.getCart,(e,{customer:t})=>t.getCustomer,(e,{consignments:t})=>t.getConsignments,(e,{coupons:t})=>t.getCoupons,(e,{giftCertificates:t})=>t.getGiftCertificates,(e,t,i,n,o,r,a)=>()=>{const s=t(),d=i(),c=n(),u=o()||[],l=r()||[],h=a()||[];if(e&&d&&c)return Object.assign(Object.assign({},e),{billingAddress:s,cart:d,customer:c,consignments:u,coupons:l,giftCertificates:h})}),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingCheckout))),i=jn(e,e=>t=>{const i=e();if(!i)return;const n=i.grandTotal||0,o=i.customer.storeCredit||0;return t?Math.max(n-o,0):i.outstandingBalance}),n=jn(e=>e.errors.loadError,e=>()=>e),o=jn(e=>e.errors.updateError,e=>()=>e),r=jn(e=>e.statuses.isExecutingSpamCheck,e=>()=>!0===e),a=jn(e=>e.statuses.isLoading,e=>()=>!0===e),s=jn(e=>e.statuses.isUpdating,e=>()=>!0===e);return se((d=Ln,c,u,l,h,p,m)=>({getCheckout:e(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getCheckoutOrThrow:t(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getOutstandingBalance:i(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getLoadError:n(d),getUpdateError:o(d),isExecutingSpamCheck:r(d),isLoading:a(d),isUpdating:s(d)}))}(),P=function(){const e=jn(e=>e.data,(e,{billingAddress:t})=>t.getOrderBillingAddress(),(e,{coupons:t})=>t.getCoupons(),(e,t,i=[])=>()=>{if(e&&t)return Object.assign(Object.assign({},e),{billingAddress:t,coupons:i})}),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingOrder))),i=jn(e=>e.meta,e=>()=>e),n=jn(e=>e.errors.loadError,e=>()=>e),o=jn(e=>{var t;return null===(t=e.data)||void 0===t?void 0:t.payments},(e=[])=>t=>{const i=e.find(({providerId:e})=>e===t);return null==i?void 0:i.paymentId}),r=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((a=si,s,d)=>({getOrder:e(a,{billingAddress:s,coupons:d}),getOrderOrThrow:t(a,{billingAddress:s,coupons:d}),getOrderMeta:i(a),getLoadError:n(a),getPaymentId:o(a),isLoading:r(a)}))}(),O=function(){const e=jn(e=>e.data,e=>()=>e);return se((t=pi)=>({getOrderBillingAddress:e(t)}))}(),A=function(){const e=jn(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.payment}),t=jn(({order:e})=>e.getOrder,e=>()=>{const t=e();return l(t&&t.payments,({providerId:e})=>"giftcertificate"!==e&&"storecredit"!==e)}),i=jn(({checkout:e})=>e.getCheckout,e=>()=>{const t=e();return l(t&&t.payments,({providerType:e})=>"PAYMENT_TYPE_HOSTED"===e)}),n=jn(e,i,t,(e,t,i)=>()=>{const n=e();if(n&&n.id)return{providerId:n.id,gatewayId:n.gateway};const o=t()||i();return o&&o.providerId?{providerId:o.providerId,gatewayId:o.gatewayId}:void 0}),o=jn(n,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentId))),r=jn(e,i,t,(e,t,i)=>()=>{const n=e();if(n&&n.status)return n.status.replace("PAYMENT_STATUS_","");const o=t()||i();return o?o.detail.step:void 0}),a=jn(r,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentStatus))),s=jn(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.token}),d=jn(s,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentToken))),c=jn(e,e=>()=>{const t=e();return t&&t.redirectUrl}),u=jn(c,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentRedirectUrl))),h=jn(({checkout:e})=>e.getOutstandingBalance,e=>(t=!1)=>{const i=e(t);return!!i&&i>0}),p=jn(r,e=>t=>!(!t||!t.nonce)||"ACKNOWLEDGE"===e()||"FINALIZE"===e());return se((e,t)=>({getPaymentId:n({checkout:e,order:t}),getPaymentIdOrThrow:o({checkout:e,order:t}),getPaymentStatus:r({checkout:e,order:t}),getPaymentStatusOrThrow:a({checkout:e,order:t}),getPaymentToken:s({checkout:e,order:t}),getPaymentTokenOrThrow:d({checkout:e,order:t}),getPaymentRedirectUrl:c({checkout:e,order:t}),getPaymentRedirectUrlOrThrow:u({checkout:e,order:t}),isPaymentDataRequired:h({checkout:e,order:t}),isPaymentDataSubmitted:p({checkout:e,order:t})}))}(),T=function(){const e=jn(e=>e.errors.applyError,e=>()=>e),t=jn(e=>!!e.statuses.isApplying,e=>()=>e);return se((i=$n)=>({getApplyError:e(i),isApplying:t(i)}))}(),k=function(){const e=jn(e=>e.errors.updateError,e=>()=>e),t=jn(e=>!!e.statuses.isUpdating,e=>()=>e);return se((i=kn)=>({getUpdateError:e(i),isUpdating:t(i)}))}(),R=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.sendError,e=>()=>e),i=jn(e=>!!e.statuses.isSending,e=>()=>e);return se((n=Cn)=>({getEmail:e(n),getSendError:t(n),isSending:i(n)}))}(),D=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.data,e=>t=>null==e?void 0:e.find(e=>e.region===t)),i=jn(e=>e.errors.loadError,e=>()=>e),n=jn(e=>e.statuses.isLoading,e=>()=>!!e);return se((o=Ht)=>({getExtensions:e(o),getExtensionByRegion:t(o),getLoadError:i(o),isLoading:n(o)}))}();return(u,l={})=>{const p=e(u.billingAddress),v=t(u.cart),S=i(u.checkoutButton),M=o(u.countries),N=r(u.coupons),L=a(u.customer),z=s(u.customerStrategies),U=D(u.extensions),F=h(u.formFields),B=d(u.giftCertificates),x=c(u.instruments),q=O(u.orderBillingAddress),j=m(u.paymentMethods),G=f(u.paymentProviderCustomer),H=g(u.paymentStrategies),V=y(u.pickupOptions),Y=C(u.remoteCheckout),W=I(u.consignments),$=_(u.shippingCountries),K=w(u.shippingStrategies),Z=k(u.subscriptions),Q=T(u.storeCredit),J=R(u.signInEmail),X=b(u.consignments,v),ee=E(u.checkout,p,v,X,N,L,B),te=P(u.order,q,N),ie=A(ee,te),ne={billingAddress:p,cart:v,checkout:ee,checkoutButton:S,config:n(u.config,u.formFields),consignments:X,countries:M,coupons:N,customer:L,customerStrategies:z,extensions:U,form:F,giftCertificates:B,instruments:x,order:te,orderBillingAddress:q,payment:ie,paymentMethods:j,paymentProviderCustomer:G,paymentStrategies:H,pickupOptions:V,remoteCheckout:Y,shippingAddress:W,shippingCountries:$,shippingStrategies:K,signInEmail:J,subscriptions:Z,storeCredit:Q};return l.shouldWarnMutation?function(e){return Object.keys(e).reduce((t,i)=>(t[i]=Vn(e[i]),t),{})}(ne):ne}}function Zn(e={},t){const i=(s=function(){const e=new De;return["catalog_only","empty_cart","invalid_order_id","invalid_order_token","missing_order_token","missing_provider_token","missing_shipping_method","order_completion_error","order_could_not_be_finalized_error","order_create_failed","provider_fatal_error","provider_setup_error","stock_too_low"].forEach(t=>{e.register(t,(e,t)=>new Oe(e,t))}),e.register("invalid_payment_provider",e=>new we(e)),e.register("payment_config_not_found",e=>new we(e)),e}(),e=>W(e).pipe(J(e=>{if(e instanceof Error||e.payload instanceof Error)throw e;if((t=e.payload)&&"object"==typeof t&&["body","headers","status","statusText"].every(e=>Object.prototype.hasOwnProperty.call(t,e))){const t=e.payload.body&&e.payload.body.detail;throw Object.assign(Object.assign({},e),{payload:s.createError(e.payload,t)})}var t;throw e}))),o=Kn(),r=n({billingAddress:He,cart:tt,checkout:zn,checkoutButton:ut,config:yt,consignments:$i,countries:ni,coupons:_t,customer:Mt,customerStrategies:Bt,extensions:Vt,formFields:Qt,giftCertificates:Ot,instruments:Fi,orderBillingAddress:mi,order:di,payment:vi,paymentMethods:Ii,paymentStrategies:Ai,pickupOptions:nn,paymentProviderCustomer:Ni,remoteCheckout:Vi,shippingCountries:cn,shippingStrategies:gn,signInEmail:In,subscriptions:Rn,storeCredit:On});var s;return a(r,e,Object.assign({actionTransformer:i,stateTransformer:e=>o(e)},t))}var Qn,Jn;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentRedirectUrl=13]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=14]="MissingPaymentStatus",e[e.MissingPaymentToken=15]="MissingPaymentToken",e[e.MissingShippingAddress=16]="MissingShippingAddress"}(Qn||(Qn={}));class Xn extends Ce{constructor(e){super(function(e){switch(e){case Qn.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case Qn.MissingCart:return"Unable to proceed because cart data is unavailable.";case Qn.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case Qn.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case Qn.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case Qn.MissingCheckoutConfig:case Qn.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case Qn.MissingOrder:return"Unable to proceed because order data is unavailable.";case Qn.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case Qn.MissingPayment:return"Unable to proceed because payment data is unavailable.";case Qn.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case Qn.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case Qn.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(e)),this.subtype=e,this.name="MissingDataError",this.type="missing_data"}}function eo(e){return t=e.lineItems.physicalItems.filter(e=>!e.addedByPromotion),N(t,(e,t)=>e+t.quantity,0);var t}function to(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}!function(e){e[e.CheckoutButtonNotInitialized=0]="CheckoutButtonNotInitialized",e[e.CustomerNotInitialized=1]="CustomerNotInitialized",e[e.PaymentNotInitialized=2]="PaymentNotInitialized",e[e.ShippingNotInitialized=3]="ShippingNotInitialized",e[e.SpamProtectionNotInitialized=4]="SpamProtectionNotInitialized"}(Jn||(Jn={}));class io extends Ce{constructor(e){super(function(e){switch(e){case Jn.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Jn.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Jn.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Jn.SpamProtectionNotInitialized:return"Unable to proceed because the checkout spam protection has not been initialized.";default:return"Unable to proceed because the required component has not been initialized."}}(e)),this.subtype=e,this.name="NotInitializedError",this.type="not_initialized"}}const no={de:"eu",jp:"fe",uk:"eu",us:"na"};var oo,ro,ao,so,co,uo;!function(e){e.en_US="en_US",e.en_GB="en_GB",e.de_DE="de_DE",e.fr_FR="fr_FR",e.it_IT="it_IT",e.es_ES="es_ES",e.ja_JP="ja_JP"}(oo||(oo={})),function(e){e.Home="Home",e.Product="Product",e.Cart="Cart",e.Checkout="Checkout",e.Other="Other"}(ro||(ro={})),function(e){e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.JPY="JPY"}(ao||(ao={})),function(e){e.PayAndShip="PayAndShip",e.PayOnly="PayOnly"}(so||(so={})),function(e){e.Gold="Gold",e.LightGray="LightGray",e.DarkGray="DarkGray"}(co||(co={})),function(e){e.C0001="C0001"}(uo||(uo={}));var lo=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ho{constructor(e){this.amazonPayV2ScriptLoader=e}initialize(e){return lo(this,void 0,void 0,function*(){this.amazonPayV2SDK=yield this.amazonPayV2ScriptLoader.load(e),this.buttonParentContainer=this.buttonParentContainer||this.createAmazonPayButtonParentContainer()})}deinitialize(){var e;return this.amazonPayV2Button=void 0,null===(e=this.buttonParentContainer)||void 0===e||e.remove(),this.buttonParentContainer=void 0,this.amazonPayV2SDK=void 0,Promise.resolve()}bindButton(e,t,i){this.getAmazonPayV2SDK().Pay.bindChangeAction(`#${e}`,{amazonCheckoutSessionId:t,changeAction:i})}createButton(e,t){this.amazonPayV2Button=this.getAmazonPayV2SDK().Pay.renderButton(`#${e}`,t)}prepareCheckout(e){const t=this.prepareRequestConfig(e);this.getAmazonPayV2Button().onClick(()=>{this.getAmazonPayV2Button().initCheckout(t)})}prepareCheckoutWithCreationRequestConfig(e){this.getAmazonPayV2Button().onClick(()=>lo(this,void 0,void 0,function*(){const t=yield e();if(t){const e=this.prepareRequestConfig(t.createCheckoutSessionConfig,t.estimatedOrderAmount,t.productType);this.getAmazonPayV2Button().initCheckout(e)}}))}signout(){return lo(this,void 0,void 0,function*(){return this.amazonPayV2SDK&&this.amazonPayV2SDK.Pay.signout(),Promise.resolve()})}renderAmazonPayButton({buttonColor:e,checkoutState:t,containerId:i,decoupleCheckoutInitiation:n=!1,methodId:o,options:r,placement:a,isButtonMicroTextDisabled:s=!1}){const d=document.querySelector(`#${i}`);if(!d)return;const{id:c}=d.appendChild(this.getButtonParentContainer());r&&s&&(r.design=uo.C0001);const u=null!=r?r:this.getAmazonPayV2ButtonOptions(t,o,a,n,e);return this.createButton(c,u),this.getButtonParentContainer()}updateBuyNowFlowFlag(e){this.isBuyNowFlow=Boolean(e)}isPh4Enabled(e,t){const i=!!e["PROJECT-3483.amazon_pay_ph4"],n=!!e["INT-6885.amazon_pay_ph4_us_only"];return i&&n?"US"===t:i}prepareRequestConfig(e,t,i){const{publicKeyId:n}=e,o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["publicKeyId"]);return Object.assign(Object.assign({createCheckoutSessionConfig:this.isEnvironmentSpecific(n)?o:e},t&&{estimatedOrderAmount:t}),i&&{productType:i})}createAmazonPayButtonParentContainer(){const e=Math.random().toString(16).substr(-4),t=document.createElement("div");return t.id=`amazonpay_button_parent_container_${e}`,t}getAmazonPayV2ButtonOptions(e,t,i,n=!1,o=co.Gold){var r;const{getCart:a,getCheckout:s,getStoreConfigOrThrow:d,getPaymentMethodOrThrow:c}=this.getCheckoutState(e),{config:{merchantId:u,testMode:l},initializationData:h}=c(t);if(!h)throw new Xn(Qn.MissingPaymentMethod);const{checkoutLanguage:p,checkoutSessionMethod:m,createCheckoutSessionConfig:g,extractAmazonCheckoutSessionId:y,ledgerCurrency:f,publicKeyId:v="",isButtonMicroTextDisabled:S}=h;if(!u||!f)throw new Xn(Qn.MissingPaymentMethod);const C=Object.assign({merchantId:u,ledgerCurrency:f,checkoutLanguage:p,placement:i,buttonColor:o},S?{design:uo.C0001}:{});if(this.isBuyNowFlow)return Object.assign(Object.assign({},C),{sandbox:!!l});const I=a();C.productType=I&&0===eo(I)?so.PayOnly:so.PayAndShip;const{checkoutSettings:{features:_},storeProfile:{shopPath:w,storeCountryCode:b}}=d();if(this.isPh4Enabled(_,b)){if(!g)throw new Xn(Qn.MissingPaymentMethod);const e=null===(r=s())||void 0===r?void 0:r.outstandingBalance.toString(),t=null==I?void 0:I.currency.code,i=Object.assign({},C);let o;return this.isEnvironmentSpecific(v)?(i.publicKeyId=v,o=g):(i.sandbox=!!l,o=Object.assign(Object.assign({},g),{publicKeyId:v})),n||(i.createCheckoutSessionConfig=o),e&&t&&(i.estimatedOrderAmount={amount:e,currencyCode:t}),i}const E={method:m,url:`${w}/remote-checkout/${t}/payment-session`,extractAmazonCheckoutSessionId:y};return Object.assign(Object.assign({},C),{createCheckoutSession:E,sandbox:!!l})}isEnvironmentSpecific(e){return/^(SANDBOX|LIVE)/.test(e)}getAmazonPayV2SDK(){return this.getOrThrow(this.amazonPayV2SDK)}getButtonParentContainer(){return this.getOrThrow(this.buttonParentContainer)}getAmazonPayV2Button(){return this.getOrThrow(this.amazonPayV2Button)}getOrThrow(e){return to(e,()=>new io(Jn.PaymentNotInitialized))}getCheckoutState(e){return"object"==typeof(t=e)&&null!==t&&"cart"in t&&"checkout"in t&&"config"in t&&"paymentMethods"in t?{getCart:e.cart.getCart,getCheckout:e.checkout.getCheckout,getStoreConfigOrThrow:e.config.getStoreConfigOrThrow,getPaymentMethodOrThrow:t=>e.paymentMethods.getPaymentMethodOrThrow(t)}:e;var t}}class po extends Ce{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}class mo{constructor(e,t=window){this.scriptLoader=e,this.windowWithAmazonPay=t}load(e){return t=this,i=void 0,o=function*(){const{initializationData:t}=e,i=(null==t?void 0:t.region)||"us",n=no[i];if(yield this.scriptLoader.loadScript(`https://static-${n}.payments-amazon.com/checkout.js`),!this.windowWithAmazonPay.amazon)throw new po;return this.windowWithAmazonPay.amazon},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}}function go(e,t){return Object.assign(e,{resolveIds:t})}class yo extends Ce{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class fo extends Ce{constructor(e){super(e||"An unexpected error has occurred during buy now cart creation process. Please try again later."),this.name="BuyNowCartCreationError",this.type="buy_now_cart_creation_error"}}class vo extends Ce{constructor(e){super(e||"An unexpected error has occurred during config creation process. Please try again later."),this.name="AmazonPayV2ConfigCreationError",this.type="amazon_pay_v2_config_creation_error"}}function So(e){return e instanceof Object&&"buyNowInitializeOptions"in e}var Co=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Io{constructor(e,t,i){this.paymentIntegrationService=e,this.amazonPayV2PaymentProcessor=t,this.amazonPayV2ConfigRequestSender=i}initialize(e){var t;return Co(this,void 0,void 0,function*(){const{methodId:i,containerId:n,amazonpay:o}=e,{buttonColor:r}=o||{};if(!i||!n)throw new yo('Unable to proceed because "methodId" or "containerId" argument is not provided.');const{getPaymentMethodOrThrow:a}=this.paymentIntegrationService.getState(),s=a(i),{initializationData:d}=s;yield this.amazonPayV2PaymentProcessor.initialize(s),o||(yield this.paymentIntegrationService.loadDefaultCheckout());const c=So(o)?void 0:o;So(o)&&"function"==typeof(null===(t=o.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody)&&(this._buyNowInitializeOptions=o.buyNowInitializeOptions,this.amazonPayV2PaymentProcessor.updateBuyNowFlowFlag(!0)),this.amazonPayV2PaymentProcessor.renderAmazonPayButton({checkoutState:this.paymentIntegrationService.getState(),containerId:n,methodId:i,options:c,placement:ro.Cart,buttonColor:r,isButtonMicroTextDisabled:null==d?void 0:d.isButtonMicroTextDisabled}),this._buyNowInitializeOptions&&this.amazonPayV2PaymentProcessor.prepareCheckoutWithCreationRequestConfig(this._getCheckoutCreationRequestConfig.bind(this))})}deinitialize(){return this.amazonPayV2PaymentProcessor.deinitialize()}_createBuyNowCartOrThrow(){var e,t;return Co(this,void 0,void 0,function*(){const i=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!i)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(i)}catch(e){throw new fo}})}_createCheckoutConfig(e){return Co(this,void 0,void 0,function*(){try{const t=(yield this.amazonPayV2ConfigRequestSender.createCheckoutConfig(e)).body,{payload:i,public_key:n}=t,o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["payload","public_key"]);return Object.assign({payloadJSON:i,publicKeyId:n},o)}catch(e){throw new vo}})}_getCheckoutCreationRequestConfig(){return Co(this,void 0,void 0,function*(){const e=yield this._createBuyNowCartOrThrow(),t={amount:String(e.baseAmount),currencyCode:e.currency.code};return{createCheckoutSessionConfig:yield this._createCheckoutConfig(e.id),estimatedOrderAmount:t,productType:0===eo(e)?so.PayOnly:so.PayAndShip}})}}const _o="This API endpoint is for internal use only and may change in the future";var wo;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(wo||(wo={}));const bo=wo,Eo={"X-Checkout-SDK-Version":"1.863.0"};class Po{constructor(e){this._requestSender=e}createCheckoutConfig(e){const t={cartId:e},i=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return this._requestSender.post("/api/storefront/payment/amazonpay",{headers:i,body:t})}}const Oo=go(t=>{const i=e(),n=new Po(i),o=new ho(new mo(le()));return new Io(t,o,n)},[{id:"amazonpay"}]);function Ao(e,t,i=!0){var n;return null!==(n=e[t])&&void 0!==n?n:i}const To="3.128.0",ko="3.123.2",Ro="3.106.0";class Do{constructor(e){this.paymentIntegrationService=e,this.braintreeWindow=window}getSDKVersion(){const e=this.paymentIntegrationService.getState().getStoreConfig(),t=(null==e?void 0:e.checkoutSettings.features)||{};return this.getPreloadedSDKVersion()||(Ao(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?To:Ao(t,"PAYPAL-5636.update_braintree_sdk_version")?ko:Ro)}getPreloadedSDKVersion(){const e=this.braintreeWindow.braintree;if(e){const t=l(Object.values(e),e=>!!e.VERSION);return null==t?void 0:t.VERSION}}}class Mo extends Ce{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var No,Lo,zo,Uo,Fo,Bo,xo;function qo(e){return Boolean("object"==typeof e&&null!==e&&("type"in e||"message"in e||"code"in e))}!function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(No||(No={})),function(e){e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED"}(Lo||(Lo={})),function(e){e.TRUSTLY="trustly"}(zo||(zo={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="cancelled",e.UNRECOGNIZED="unrecognized"}(Uo||(Uo={})),function(e){e.Customer="CUSTOMER",e.Merchant="MERCHANT",e.Network="NETWORK",e.Internal="INTERNAL",e.Unknown="UNKNOWN"}(Fo||(Fo={})),function(e){e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED"}(Bo||(Bo={})),function(e){e.Visa="visa",e.Mastercard="mastercard",e.AmericanExpress="american-express",e.DinersClub="diners-club",e.Discover="discover",e.Jcb="jcb",e.UnionPay="union-pay",e.Maestro="maestro",e.Elo="elo",e.Mir="mir",e.Hiper="hiper",e.Hipercard="hipercard"}(xo||(xo={}));var jo,Go,Ho,Vo=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Yo{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return Vo(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return Vo(this,void 0,void 0,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=yield t.create({authorization:e})}return this.client})}getDataCollectorOrThrow(e){return Vo(this,void 0,void 0,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadDataCollector(),n=Object.assign({client:t,kount:!0},e);this.dataCollector=yield i.create(n)}catch(e){if(qo(e)&&e.code===Bo.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return Vo(this,void 0,void 0,function*(){if(!this.googlePayment){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadGooglePayment()]);this.googlePayment=yield t.create({client:e})}return this.googlePayment})}getBraintreeThreeDS(){return Vo(this,void 0,void 0,function*(){if(!this.threeDS){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]);this.threeDS=yield t.create({client:e,version:2})}return this.threeDS})}getBraintreeLocalPayment(e){return Vo(this,void 0,void 0,function*(){if(!this.braintreeLocalPayment){const[t,i]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((n,o)=>{i.create({client:t,merchantAccountId:e},(e,t)=>{e&&o(e),n(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return Vo(this,void 0,void 0,function*(){if(!this.usBankAccount){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadUsBankAccount();this.usBankAccount=yield t.create({client:e})}return this.usBankAccount})}getBraintreeVisaCheckout(){return this.visaCheckout||(this.visaCheckout=Promise.all([this.getClient(),this.braintreeScriptLoader.loadVisaCheckout()]).then(([e,t])=>t.create({client:e}))),this.visaCheckout}getVisaCheckoutSdk(e){return Vo(this,void 0,void 0,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return Vo(this,void 0,void 0,function*(){if(!this.braintreeVenmo){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadVenmoCheckout(),i={client:e,allowDesktop:!0,paymentMethodUsage:"multi_use"},n=yield t.create(i);if(!n.isBrowserSupported())throw new Mo;this.braintreeVenmo=n}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new io(Jn.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}!function(e){e.Sandbox="sandbox",e.Production="production"}(jo||(jo={})),function(e){e.Client="client",e.DataCollector="dataCollector",e.Fastlane="fastlane",e.GooglePayment="googlePayment",e.HostedFields="hostedFields",e.LocalPayment="localPayment",e.Paypal="paypal",e.PaypalCheckout="paypalCheckout",e.ThreeDSecure="threeDSecure",e.UsBankAccount="usBankAccount",e.Venmo="venmo",e.VisaCheckout="visaCheckout"}(Go||(Go={})),function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(Ho||(Ho={}));const Wo={[Ro]:{[Go.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[Go.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[Go.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[Go.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[Go.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[Go.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[Go.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[Go.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[Go.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[Go.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[Go.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[Go.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[ko]:{[Go.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[Go.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[Go.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[Go.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[Go.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[Go.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[Go.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[Go.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[Go.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[Go.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[Go.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[Go.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[To]:{[Go.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[Go.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[Go.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[Go.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[Go.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[Go.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[Go.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[Go.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[Go.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[Go.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[Go.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[Go.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var $o,Ko=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Zo{constructor(e,t,i){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=i}loadClient(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.Client,"client.min.js")})}loadFastlane(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.Paypal,"paypal.min.js")})}loadLocalPayment(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.GooglePayment,"google-payment.min.js")})}load3DS(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(Go.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(Go.Venmo,"venmo.min.js")}loadHostedFields(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return Ko(this,void 0,void 0,function*(){if(this.braintreeHostWindow.V)return this.braintreeHostWindow.V;const t=e?"sha384-0eu1s1GtqzXlL9DtLgmwzC5WWlEH/ADRM0n38cVQkvtT+W/gey96rcb1LwuUOPDm":"sha384-1f1csvP3ZFxg4dILH1GaY4LHlZ0oX7Rk83rxmLlwbnIi4TM0NYzXoev1VoEiVDS6";return this.scriptLoader.loadScript(`//${e?"sandbox-":""}assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js`,{async:!0,attributes:{integrity:t,crossorigin:"anonymous"}}).then(()=>{if(!this.braintreeHostWindow.V)throw new po;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return Ko(this,void 0,void 0,function*(){let i=this.getBraintreeModule(e);if(i)return i;const n=this.braintreeSDKVersionManager.getSDKVersion(),o=`//js.braintreegateway.com/web/${n}/js/${t}`,r=n in Wo?this.getIntegrityValuesByModuleName(e,n):void 0;if(yield this.scriptLoader.loadScript(o,r?{async:!0,attributes:{integrity:r,crossorigin:"anonymous"}}:void 0),i=this.getBraintreeModule(e),!i)throw new po;return i})}getBraintreeModule(e){var t;return null===(t=this.braintreeHostWindow.braintree)||void 0===t?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const i=Wo[t][e];if(!i)throw new Error("Unexpected fileName value");return i}}class Qo extends Ce{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}!function(e){e.BRAINTREE="braintree",e.BRAINTREE_FASTLANE="braintreeacceleratedcheckout"}($o||($o={}));var Jo,Xo,er=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};!function(e){e.Subtotal="Subtotal",e.Shipping="Shipping"}(Jo||(Jo={})),function(e){e.Black="black",e.White="white",e.WhiteBorder="white-border"}(Xo||(Xo={}));class tr{constructor(e,t,i,n,o){this._requestSender=e,this._paymentIntegrationService=t,this._sessionFactory=i,this._braintreeSdk=n,this._applePayScriptLoader=o,this._onAuthorizeCallback=T,this._subTotalLabel=Jo.Subtotal,this._shippingLabel=Jo.Shipping}initialize(e){var t,i;return er(this,void 0,void 0,function*(){const{methodId:n,containerId:o,applepay:r}=e;if(!n||!r)throw new Xn(Qn.MissingPaymentMethod);yield this._applePayScriptLoader.loadSdk();const{onPaymentAuthorize:a,buyNowInitializeOptions:s,requiresShipping:d}=r;this._requiresShipping=d,this._buyNowInitializeOptions=s,this._onAuthorizeCallback=a,s||(yield this._paymentIntegrationService.loadDefaultCheckout()),yield this._paymentIntegrationService.loadPaymentMethod(n);const c=this._paymentIntegrationService.getState();return this._paymentMethod=c.getPaymentMethodOrThrow(n),c.getCart()&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection()),(null===(t=this._paymentMethod.initializationData)||void 0===t?void 0:t.gateway)===$o.BRAINTREE&&this._paymentMethod.clientToken&&this._braintreeSdk.initialize(this._paymentMethod.clientToken),this._applePayButton=this._createButton(o,null===(i=this._paymentMethod.initializationData)||void 0===i?void 0:i.styleOption),this._applePayButton.addEventListener("click",this._handleWalletButtonClick.bind(this)),Promise.resolve()})}deinitialize(){return Promise.resolve()}_createButton(e,t){const i=document.getElementById(e);if(!i)throw new yo("Unable to create wallet button without valid container ID.");const n=this._createApplePayButtonElement(t);return i.appendChild(n),n}_createApplePayButtonElement(e){const t=document.createElement("apple-pay-button");return t.setAttribute("buttonstyle",(e=>{switch(e){case Xo.White:return"white";case Xo.WhiteBorder:return"white-outline";case Xo.Black:default:return"black"}})(e)),t.setAttribute("type","plain"),t.setAttribute("style","--apple-pay-button-width: 100%; --apple-pay-button-height: 40px; --apple-pay-button-border-radius: 4px;"),t}_handleWalletButtonClick(e){var t;return er(this,void 0,void 0,function*(){if(e.preventDefault(),!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xn(Qn.MissingPaymentMethod);if(this._buyNowInitializeOptions&&"function"==typeof this._buyNowInitializeOptions.getBuyNowCartRequestBody){const{countryCode:e,currencyCode:i,merchantCapabilities:n,supportedNetworks:o,storeName:r}=this._paymentMethod.initializationData,a=this._getRequestWithEmptyTotal(e,i,o,n);this._requiresShipping&&(null===(t=a.requiredShippingContactFields)||void 0===t||t.push("postalAddress"));const s=this._sessionFactory.create(a);this._handleApplePayEvents(s,this._paymentMethod,r),s.begin()}else{const e=this._paymentIntegrationService.getState(),t=e.getCartOrThrow(),i=e.getStoreConfigOrThrow(),n=e.getCheckoutOrThrow(),o=this._getBaseRequest(t,n,i,this._paymentMethod),r=this._sessionFactory.create(o);this._handleApplePayEvents(r,this._paymentMethod,i.storeProfile.storeName),r.begin()}})}_getRequestWithEmptyTotal(e,t,i,n){return{countryCode:e,currencyCode:t,supportedNetworks:i,merchantCapabilities:n,total:{label:"",amount:"0",type:"pending"},requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"]}}_getBaseRequest(e,t,i,n){var o;const{storeProfile:{storeCountryCode:r,storeName:a}}=i,{currency:{code:s,decimalPlaces:d}}=e,{initializationData:{merchantCapabilities:c,supportedNetworks:u}}=n,l=e.lineItems.physicalItems.length>0,h={requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"],countryCode:r,currencyCode:s,merchantCapabilities:c,supportedNetworks:u,lineItems:[],total:l?{label:a,amount:`${t.grandTotal.toFixed(d)}`,type:"pending"}:{label:a,amount:`${t.grandTotal.toFixed(d)}`,type:"final"}};if(l)null===(o=h.requiredShippingContactFields)||void 0===o||o.push("postalAddress");else{const e=[{label:this._subTotalLabel,amount:`${t.subtotal.toFixed(d)}`}];t.taxes.forEach(t=>e.push({label:t.name,amount:`${t.amount.toFixed(d)}`})),h.lineItems=e}return h}_handleApplePayEvents(e,t,i){e.onvalidatemerchant=i=>er(this,void 0,void 0,function*(){try{const{body:n}=yield this._onValidateMerchant(t,i);e.completeMerchantValidation(n)}catch(e){throw new Error("Merchant validation failed")}}),this._buyNowInitializeOptions&&!this._requiresShipping&&(e.onpaymentmethodselected=()=>er(this,void 0,void 0,function*(){yield this._createBuyNowCart(),this._handlePaymentMethodSelected(e)})),e.onshippingcontactselected=t=>er(this,void 0,void 0,function*(){this._buyNowInitializeOptions&&this._requiresShipping&&(yield this._createBuyNowCart()),yield this._handleShippingContactSelected(e,i,t)}),e.onshippingmethodselected=t=>er(this,void 0,void 0,function*(){yield this._handleShippingMethodSelected(e,i,t)}),e.oncancel=()=>er(this,void 0,void 0,function*(){try{const e=`/remote-checkout/${t.id}/signout`;return yield this._requestSender.get(e),yield this._paymentIntegrationService.loadCheckout()}catch(e){throw new Qo}}),e.onpaymentauthorized=i=>er(this,void 0,void 0,function*(){return this._onPaymentAuthorized(i,e,t)})}_createBuyNowCart(){var e,t;return er(this,void 0,void 0,function*(){try{const i=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!i)throw new Xn(Qn.MissingCart);const n=yield this._paymentIntegrationService.createBuyNowCart(i);yield this._paymentIntegrationService.loadCheckout(n.id);const o=this._paymentIntegrationService.getState(),{shouldExecuteSpamCheck:r}=o.getCheckoutOrThrow();r&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection())}catch(e){throw new fo}})}_handlePaymentMethodSelected(e){const t=this._paymentIntegrationService.getState(),i=t.getCartOrThrow(),n=t.getStoreConfigOrThrow(),o=t.getCheckoutOrThrow();if(!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xn(Qn.MissingPaymentMethod);const r=this._getBaseRequest(i,o,n,this._paymentMethod);delete r.total.type,e.completePaymentMethodSelection({newTotal:r.total,newLineItems:r.lineItems})}_handleShippingContactSelected(e,t,i){var n;return er(this,void 0,void 0,function*(){const o=this._transformContactToAddress(i.shippingContact);try{yield this._paymentIntegrationService.updateShippingAddress(o)}catch(t){throw e.abort(),new Error("Shipping address update failed")}let r=this._paymentIntegrationService.getState();const{currency:{decimalPlaces:a}}=r.getCartOrThrow();let s=r.getCheckoutOrThrow();const d=null===(n=s.consignments[0].selectedShippingOption)||void 0===n?void 0:n.id,c=s.consignments[0].availableShippingOptions,u=null==c?void 0:c.find(({id:e})=>e===d),l=null==c?void 0:c.filter(e=>e.id!==d),h=u?[{label:u.description,amount:`${u.cost.toFixed(a)}`,detail:u.additionalDescription,identifier:u.id}]:[];if(l&&[...l.filter(e=>e.isRecommended),...l.filter(e=>!e.isRecommended)].forEach(e=>h.push({label:e.description,amount:`${e.cost.toFixed(a)}`,detail:e.additionalDescription,identifier:e.id})),!(c instanceof Array))throw new Error("Shipping options not available.");if(0===c.length)return void e.completeShippingContactSelection(ApplePaySession.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,[],{type:"pending",label:t,amount:`${s.grandTotal.toFixed(a)}`},[]);const p=c.find(e=>e.isRecommended),m=p?p.id:c[0].id,g=u?u.id:m;try{yield this._updateShippingOption(g)}catch(e){throw new Error("Shipping options update failed")}r=this._paymentIntegrationService.getState(),s=r.getCheckoutOrThrow(),e.completeShippingContactSelection({newShippingMethods:h,newTotal:{type:"final",label:t,amount:`${s.grandTotal.toFixed(a)}`},newLineItems:this._getUpdatedLineItems(s,a)})})}_handleShippingMethodSelected(e,t,i){return er(this,void 0,void 0,function*(){const{shippingMethod:{identifier:n}}=i;try{yield this._updateShippingOption(n)}catch(t){throw e.abort(),new Error("Shipping option selection update failed.")}const o=this._paymentIntegrationService.getState(),{currency:{decimalPlaces:r}}=o.getCartOrThrow(),a=o.getCheckoutOrThrow();e.completeShippingMethodSelection({newTotal:{type:"final",label:t,amount:`${a.grandTotal.toFixed(r)}`},newLineItems:this._getUpdatedLineItems(a,r)})})}_getUpdatedLineItems(e,t){const i=[{label:this._subTotalLabel,amount:`${e.subtotal.toFixed(t)}`}];return e.taxes.forEach(e=>i.push({label:e.name,amount:`${e.amount.toFixed(t)}`})),i.push({label:this._shippingLabel,amount:`${e.shippingCostTotal.toFixed(t)}`}),i}_updateShippingOption(e){return er(this,void 0,void 0,function*(){return this._paymentIntegrationService.selectShippingOption(e)})}_onValidateMerchant(e,t){return er(this,void 0,void 0,function*(){const i=[`validationUrl=${t.validationURL}`,`merchantIdentifier=${e.initializationData.merchantId}`,`displayName=${e.initializationData.storeName}`,`domainName=${window.location.hostname}`].join("&");return this._requestSender.post(`${e.initializationData.paymentsUrl}/api/public/v1/payments/applepay/validate_merchant`,{credentials:!1,headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded","X-XSRF-TOKEN":null},body:i})})}_onPaymentAuthorized(e,t,i){var n;return er(this,void 0,void 0,function*(){const{token:o,billingContact:r,shippingContact:a}=e.payment,s=this._paymentIntegrationService.getState().getCartOrThrow().lineItems.physicalItems.length>0;let d;(null===(n=i.initializationData)||void 0===n?void 0:n.gateway)===$o.BRAINTREE&&(d=yield this._getBraintreeDeviceData());const c={methodId:i.id,paymentData:{deviceSessionId:d,formattedPayload:{apple_pay_token:{payment_data:o.paymentData,payment_method:o.paymentMethod,transaction_id:o.transactionIdentifier}}}},u=this._transformContactToAddress(r),l=this._transformContactToAddress(a),h=null==a?void 0:a.emailAddress,p=(null==a?void 0:a.phoneNumber)||"";try{return yield this._paymentIntegrationService.updateBillingAddress(Object.assign(Object.assign({},u),{email:h,phone:p})),s&&(yield this._paymentIntegrationService.updateShippingAddress(l)),yield this._paymentIntegrationService.submitOrder({useStoreCredit:!1}),yield this._paymentIntegrationService.submitPayment(c),t.completePayment(ApplePaySession.STATUS_SUCCESS),this._onAuthorizeCallback()}catch(e){throw t.completePayment(ApplePaySession.STATUS_FAILURE),new Error("Payment cannot complete")}})}_transformContactToAddress(e){return{firstName:(null==e?void 0:e.givenName)||"",lastName:(null==e?void 0:e.familyName)||"",city:(null==e?void 0:e.locality)||"",company:"",address1:(null==e?void 0:e.addressLines)&&e.addressLines[0]||"",address2:(null==e?void 0:e.addressLines)&&e.addressLines[1]||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCode:(null==e?void 0:e.countryCode)||"",phone:(null==e?void 0:e.phoneNumber)||"",stateOrProvince:(null==e?void 0:e.administrativeArea)||"",stateOrProvinceCode:(null==e?void 0:e.administrativeArea)||"",customFields:[]}}_getBraintreeDeviceData(){return er(this,void 0,void 0,function*(){try{const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e}catch(e){}})}}function ir(e){if(!function(e){return"ApplePaySession"in e}(e))throw new Error("Apple pay is not supported")}class nr{create(e){return ir(window),new ApplePaySession(1,e)}}class or{constructor(e){this.scriptLoader=e,this.sdkVersion="1.latest"}loadSdk(){return e=this,t=void 0,n=function*(){(function(e){return"ApplePaySDK"in e})(window)||(yield this.scriptLoader.loadScript(`https://applepay.cdn-apple.com/jsapi/${this.sdkVersion}/apple-pay-sdk.js`),ir(window))},new((i=void 0)||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())});var e,t,i,n}}const rr=go(t=>{const{getHost:i}=t.getState(),n=new Do(t);return new tr(e({host:i()}),t,new nr,new Yo(new Zo(le(),window,n)),new or(new ce))},[{id:"applepay"}]);var ar,sr,dr,cr,ur,lr,hr,pr;!function(e){e.BuyNow="BUY_NOW"}(ar||(ar={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(sr||(sr={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(dr||(dr={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(cr||(cr={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ur||(ur={})),function(e){e.pill="pill",e.rect="rect"}(lr||(lr={})),function(e){e.OXXO="oxxo"}(hr||(hr={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(pr||(pr={}));var mr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class gr{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=i,this.bigCommercePaymentsScriptLoader=n}loadPayPalSdk(e,t,i,n){return mr(this,void 0,void 0,function*(){const o=this.paymentIntegrationService.getState(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(a,r,i,n),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new po;return this.paypalSdk}createBuyNowCartOrThrow(e){return mr(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}})}createOrder(e,t){return mr(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:i},t));return n})}createOrderCardFields(e,t){return mr(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n,setupToken:o}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:i},t));return Object.assign({orderId:n},o?{setupToken:o}:{})})}updateOrder(){return mr(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),i=e.getConsignmentsOrThrow()[0];try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:i.availableShippingOptions,cartId:t.id,selectedShippingOption:i.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return mr(this,void 0,void 0,function*(){try{const{status:i}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return i}catch(e){throw new _e}})}tokenizePayment(e,t){const i=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xn(Qn.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===ar.BuyNow&&{cart_id:i.id}))}submitPayment(e,t,i){return mr(this,void 0,void 0,function*(){const n={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:n},i?{gatewayId:i}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],i=t.availableShippingOptions||[],n=i.find(e=>e.isRecommended),o=(e?i.find(t=>t.id===e):i.find(e=>{var i;return e.id===(null===(i=t.selectedShippingOption)||void 0===i?void 0:i.id)}))||n||i[0];if(!o)throw new Error("Your order can't be shipped to this address");return o}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,i;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(i=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===i?void 0:i.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:i}=e,{address:n,name:{full_name:o}}=i[0].shipping,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.join(" "),email:t.email_address,address1:n.address_line_1,address2:n.address_line_2,city:n.admin_area_2,countryCode:n.country_code,postalCode:n.postal_code,stateOrProvinceCode:n.admin_area_1})}getValidButtonStyle(e){const{color:t,height:i,label:n,shape:o}=e||{},r={color:t&&ur[t]?t:void 0,height:this.getValidHeight(i),label:n&&cr[n]?n:void 0,shape:o&&lr[o]?o:void 0};return R(r,C)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var yr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class fr{constructor(e){this.requestSender=e}createOrder(e,t){return yr(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e){return yr(this,void 0,void 0,function*(){const t=e,i=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:i,body:t})).body})}getOrderStatus(e="bigcommerce_payments",t){return yr(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var vr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Sr{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return vr(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,i);return this.loadPayPalSDK(o,n)})}loadPayPalSDK(e,t=!1){return vr(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),i=this.transformConfig(e.attributes),n=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(n,{async:!0,attributes:i})}if(!this.window.paypal)throw new po;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,i=!0){const{id:n,clientToken:o,initializationData:r}=e;if(!(null==r?void 0:r.clientId))throw new Xn(Qn.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:u,isVenmoEnabled:l,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:p,isDeveloperModeApplicable:m,availableAlternativePaymentMethods:g=[],enabledAlternativePaymentMethods:y=[],isGooglePayEnabled:f}=r,v=h||i,S="bigcommerce_payments_creditcards"===n,C=S?["card"]:[],I=S?[]:["card"],_=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],b=l?["venmo"]:[],E=l?[]:["venmo"],P=g.filter(e=>!y.includes(e)),O=f?["googlepay"]:[],A=i?["card-fields"]:[],T=this.filterFundingOptions([...I,...w,...E,...P]),k=this.filterFundingOptions([...C,..._,...b,...y]);return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":k.length>0?k:void 0,"disable-funding":T.length>0?T:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...O,...A],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":o}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}const Cr=t=>{const{getHost:n}=t.getState();return new gr(i(),t,new fr(e({host:n()})),new Sr(le()))};var Ir=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class _r{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){var t;return Ir(this,void 0,void 0,function*(){const{bigcommerce_payments:i,containerId:n,methodId:o}=e,r=Boolean(null==i?void 0:i.buyNowInitializeOptions);if(!o)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(r&&!i.currencyCode)throw new yo('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(r&&"function"!=typeof(null===(t=i.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');r||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=r?i.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(o,a,!1),this.renderButton(n,o,i,r)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i,n){var o,r;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:c}=i,u=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:h,isAppSwitchEnabled:p}=l.initializationData||{},m=Object.assign(Object.assign({},!n&&this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)}),g={onClick:()=>this.handleClick(a),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},y=Object.assign(Object.assign({},!p&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,d)}),f=Object.assign(Object.assign(Object.assign({fundingSource:u.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(s)},m),a&&g),h&&y),v=u.Buttons(f);v.isEligible()?(null===(o=v.hasReturned)||void 0===o?void 0:o.call(v))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(r=v.resume)||void 0===r||r.call(v):v.render(`#${e}`):c&&"function"==typeof c?c():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Ir(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return Ir(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Ir(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return Ir(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}isPaypalCommerceAppSwitchEnabled(e){var t,i;return null!==(i=null===(t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.isAppSwitchEnabled)&&void 0!==i&&i}}const wr=go(e=>new _r(e,Cr(e)),[{id:"bigcommerce_payments"}]);var br=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Er{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,i){return br(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const n=this.getPayPalFastlaneSdkConfiguration(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypalFastlaneSdk)throw new po}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,i,n){return br(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||n){const n=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i);yield this.loadPayPalSdk(n)}if(!this.window.paypalGooglePay)throw new po;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return br(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new po}return this.window.paypalApms})}getPayPalMessages(e,t){return br(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new po;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return br(this,void 0,void 0,function*(){const i=this.transformConfig(e),n=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(i).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:n})})}getPayPalFastlaneSdkConfiguration(e,t,i){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:r},attributes:{"data-client-metadata-id":i.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":n}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i=!0){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=o,h=u||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":n,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=i,l=this.filterFundingOptions(u),h=this.filterFundingOptions(c.filter(e=>!u.includes(e)));return{options:Object.assign({"client-id":o,"merchant-id":r,"enable-funding":l.length>0?l:void 0,"disable-funding":h.length>0?h:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:n},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}const Pr=function({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t};var Or=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ar{constructor(e,t,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.payPalSdkHelper=i}initialize(e){return Or(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r,messagingContainerId:a}=t||{},s=!!o;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(s&&!r)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments_paylater.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');s||(yield this.paymentIntegrationService.loadDefaultCheckout());const d=this.paymentIntegrationService.getState(),c=s?r:d.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n,c,!1),this.renderButton(i,n,t);const u=a&&document.getElementById(a);if(c&&u){const e=d.getPaymentMethodOrThrow(n),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},i=t&&t.find(({id:e})=>"cart"===e);if(!(null==i?void 0:i.status))return;u.removeAttribute("data-pp-style-logo-type"),u.removeAttribute("data-pp-style-logo-position"),u.removeAttribute("data-pp-style-text-color"),u.removeAttribute("data-pp-style-text-size");const o=yield this.payPalSdkHelper.getPayPalMessages(e,c);this.renderMessages(o,a,i)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onComplete:r,onEligibilityFailure:a}=i,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:c}=d.initializationData||{},u={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,r)},p=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let m=!1;p.forEach(t=>{if(!m){const i=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o)},u),n&&l),c&&h),r=s.Buttons(i);r.isEligible()?(r.render(`#${e}`),m=!0):a&&"function"==typeof a&&a()}}),m||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Or(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return Or(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Or(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return Or(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}renderMessages(e,t,i){const n={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:Pr(i)};e.Messages(n).render(`#${t}`)}}const Tr=go(e=>new Ar(e,Cr(e),new Er(ue())),[{id:"bigcommerce_payments_paylater"}]);var kr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Rr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return kr(this,void 0,void 0,function*(){const{bigcommerce_payments_apms:t,containerId:i,methodId:n}=e,{apm:o,buyNowInitializeOptions:r,currencyCode:a}=t||{},s=!!r;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');if(!o)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms.apm" argument is not provided.');if(s&&!a)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');s||(yield this.paymentIntegrationService.loadDefaultCheckout());const d=s?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n,d,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{apm:n,buyNowInitializeOptions:o,style:r,onEligibilityFailure:a}=i,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(n))throw new yo('Unable to initialize PayPal button because "options.bigcommerce_payments_apms.apm" argument is not valid funding source.');const d={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:n,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},d),o&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return kr(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Dr=go(e=>new Rr(e,Cr(e)),[{id:"bigcommerce_payments_apms"}]);var Mr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Nr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Mr(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r}=t||{},a=!!o;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(a&&!r)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments_venmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?r:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n,s,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onEligibilityFailure:r}=i,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(o)},d),n&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):r&&"function"==typeof r?r():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===ur.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return Mr(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Lr=go(e=>new Nr(e,Cr(e)),[{id:"bigcommerce_payments_venmo"}]);class zr extends Ce{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Ur,Fr,Br;!function(e){e.SandboxMode="bolt_sandbox",e.StagingMode="bolt_staging",e.DevelopmentMode="bolt_development"}(Ur||(Ur={})),function(e){e.Small="small",e.Medium="medium",e.Large="large"}(Fr||(Fr={})),function(e){e.Pill="pill",e.Rect="rect"}(Br||(Br={}));class xr{constructor(e,t,i=window){this.paymentIntegrationService=e,this.boltScriptLoader=t,this.boltHostWindow=i}initialize(e){return t=this,i=void 0,o=function*(){const{bolt:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,style:r}=t||{};if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bolt" argument is not provided.');if(!Boolean(o))throw new zr("Only buy now flow is implemented for Bolt button");if(!(null==o?void 0:o.storefrontApiToken)||"string"!=typeof o.storefrontApiToken)throw new yo('Unable to initialize payment because "options.storefrontApiToken" argument is not provided.');const a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n),{initializationData:s,config:d}=a,{publishableKey:c,developerConfig:u}=s||{};yield this.boltScriptLoader.loadBoltClient(c,d.testMode,u,"BigCommerce",o.storefrontApiToken),this.renderButton(i,a,r)},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}deinitialize(){return Promise.resolve()}renderButton(e,t,i){var n;"function"==typeof(null===(n=this.boltHostWindow.BoltConnect)||void 0===n?void 0:n.setupProductPageCheckout)&&(this.addButtonContainer(e,t,i),this.boltHostWindow.BoltConnect.setupProductPageCheckout())}addButtonContainer(e,t,i){const n=document.getElementById(e);if(!n)return;const o=document.createElement("div"),r=document.createElement("object");o.setAttribute("id","product-page-checkout-wrapper"),o.setAttribute("class","bolt-button-wrapper"),o.setAttribute("style","display:none"),o.setAttribute("data-tid","product-page-checkout-wrapper"),r.setAttribute("data",this.getBoltObjectData(t,i)),r.setAttribute("class","bolt-product-checkout-button"),o.append(r),n.innerHTML="",n.append(o)}getBoltObjectData(e,t){const{initializationData:i,config:n}=e,{publishableKey:o,developerConfig:r}=i||{},a=this.boltScriptLoader.getDomainURL(!!n.testMode,r),s=this.getButtonHeight(null==t?void 0:t.size),d=this.getButtonBorderRadius(null==t?void 0:t.shape,s);return he({url:`https://${a}/v1/checkout_button`,query:{publishable_key:o,variant:"ppc",height:s,border_radius:d}})}getButtonHeight(e){if(e)switch(e){case Fr.Small:return 25;case Fr.Large:return 45;case Fr.Medium:default:return 40}}getButtonBorderRadius(e,t){if(e)switch(e){case Br.Pill:return t?Math.round(t/2):void 0;case Br.Rect:default:return 4}}}var qr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class jr{constructor(e,t=window){this.scriptLoader=e,this.boltHostWindow=t}loadBoltClient(e,t,i,n,o){return qr(this,void 0,void 0,function*(){if(this.boltHostWindow.BoltCheckout)return this.boltHostWindow.BoltCheckout;if(!e)throw new yo('Unable to initialize payment because "publishableKey" argument is not provided.');if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,i)}/connect-bigcommerce.js`,this.getScriptOptions("bolt-connect",e,n,o)),yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,i)}/track.js`,this.getScriptOptions("bolt-track",e)),!this.boltHostWindow.BoltCheckout)throw new po;return this.boltHostWindow.BoltCheckout})}loadBoltEmbedded(e,t,i){return qr(this,void 0,void 0,function*(){if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,i)}/embed.js`,{async:!0,attributes:{id:"bolt-embedded"}}),!this.boltHostWindow.Bolt)throw new po;return this.boltHostWindow.Bolt(e)})}getDomainURL(e,t){if(!e)return"connect.bolt.com";if(t)switch(t.developerMode){case Ur.StagingMode:return"connect-staging.bolt.com";case Ur.DevelopmentMode:return`connect.${t.developerDomain}`}return"connect-sandbox.bolt.com"}getScriptOptions(e,t,i,n){return{async:!0,attributes:Object.assign(Object.assign({id:e,"data-publishable-key":t},i&&{"data-shopping-cart-id":i}),n&&{"data-storefront-api-token":n})}}}const Gr=go(e=>new xr(e,new jr(le())),[{id:"bolt"}]);class Hr extends yo{constructor(e){let t="Unable to submit payment for the order because the payload is invalid.";e&&(t=`${t} Make sure the following fields are provided correctly: ${e.join(", ")}.`),super(t),this.name="PaymentArgumentInvalidError"}}class Vr extends Ce{constructor(e,t){super(t||"Unable to proceed because the payment form contains invalid data."),this.details=e,this.name="PaymentInvalidFormError",this.type="payment_invalid_form"}}class Yr{constructor(e){const t=new Promise((e,t)=>{this.cancel=t});this.promise=Promise.race([e,t])}}let Wr=null;const $r=["buttons","messages"];var Kr,Zr,Qr,Jr,Xr,ea;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(Kr||(Kr={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Zr||(Zr={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(Qr||(Qr={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Jr||(Jr={})),function(e){e.PILL="pill",e.RECT="rect"}(Xr||(Xr={})),function(e){e.CART="cart",e.HOME="homepage",e.PAYMENT="payment",e.PRODUCT="product"}(ea||(ea={}));var ta=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ia{constructor(e,t,i){this.braintreeScriptLoader=e,this.braintreeHostWindow=t,this.overlay=i,this.dataCollectors={}}initialize(e,t){this.clientToken=e,this.threeDSecureOptions=t}getBraintreeFastlane(e,t,i){return ta(this,void 0,void 0,function*(){if(t&&(window.localStorage.setItem("axoEnv","sandbox"),window.localStorage.setItem("fastlaneEnv","sandbox")),!this.braintreeHostWindow.braintreeFastlane){const t=this.getClientTokenOrThrow(),n=yield this.getClient(),o=yield this.getSessionId(e),r=yield this.braintreeScriptLoader.loadFastlane(),a={root:{backgroundColorPrimary:"transparent"}};this.braintreeHostWindow.braintreeFastlane=yield r.create({authorization:t,client:n,deviceData:o,styles:i||a})}return this.braintreeHostWindow.braintreeFastlane})}getClient(){return ta(this,void 0,void 0,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=t.create({authorization:e})}return this.client})}getPaypal(){return this.braintreePaypal||(this.braintreePaypal=Promise.all([this.getClient(),this.braintreeScriptLoader.loadPaypal()]).then(([e,t])=>t.create({client:e}))),this.braintreePaypal}paypal(e){var{shouldSaveInstrument:t}=e,i=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["shouldSaveInstrument"]);const n=pe();return this.getPaypal().then(e=>{var o;return n&&(null===(o=this.overlay)||void 0===o||o.show({onClick:()=>e.focusWindow()})),e.tokenize(Object.assign({enableShippingAddress:!0,flow:t?"vault":"checkout",useraction:"commit"},i))}).then(e=>{var t;return null===(t=this.overlay)||void 0===t||t.remove(),e}).catch(e=>{var t;throw null===(t=this.overlay)||void 0===t||t.remove(),e})}getPaypalCheckout(e,t,i){return ta(this,void 0,void 0,function*(){const n=yield this.getClient(),o=yield this.braintreeScriptLoader.loadPaypalCheckout(),r={client:n};return this.paypalCheckout=yield o.create(r,(n,o)=>{var r;if(n)return i(n);const a=Object.assign(Object.assign({currency:e.currency},e.isCreditEnabled&&{"enable-funding":"paylater"}),{components:$r.toString(),intent:e.intent,commit:null===(r=e.commit)||void 0===r||r});this.braintreeHostWindow.paypal?t(o):function(e,t){return Wr||(Wr=new Promise((i,n)=>{e.loadPayPalSDK(t,t=>{t?(Wr=null,n(t)):i(e)})})),Wr}(o,a).then(()=>t(o))}),this.paypalCheckout})}getDataCollector(e){return ta(this,void 0,void 0,function*(){const t=(null==e?void 0:e.paypal)?"paypal":"default";let i=this.dataCollectors[t];if(!i){try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),o=Object.assign({client:t,kount:!0},e);i=yield n.create(o)}catch(e){if(!qo(e)||"DATA_COLLECTOR_KOUNT_NOT_ENABLED"!==e.code)throw e;i={deviceData:void 0,teardown:()=>Promise.resolve()}}this.dataCollectors[t]=i}return i})}getBraintreeEnv(e=!1){return e?jo.Sandbox:jo.Production}mapToBraintreeShippingAddressOverride(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}mapToLegacyShippingAddress(e){const{email:t,phone:i,shippingAddress:n}=e,o=(null==n?void 0:n.recipientName)||"",[r,a]=o.split(" ");return{email:t,first_name:r||"",last_name:a||"",phone_number:i,address_line_1:null==n?void 0:n.line1,address_line_2:null==n?void 0:n.line2,city:null==n?void 0:n.city,state:null==n?void 0:n.state,country_code:null==n?void 0:n.countryCode,postal_code:null==n?void 0:n.postalCode}}mapToLegacyBillingAddress(e){const{billingAddress:t,email:i,firstName:n,lastName:o,phone:r,shippingAddress:a}=e,s=t||a;return{email:i,first_name:n,last_name:o,phone_number:r,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}removeElement(e){const t=e&&document.getElementById(e);t&&t.remove()}getSessionId(e){return ta(this,void 0,void 0,function*(){const{deviceData:t}=yield this.getDataCollector({riskCorrelationId:e});return t})}teardown(){return ta(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollectors.default),yield this.teardownModule(this.dataCollectors.paypal),this.dataCollectors={},yield this.teardownModule(this.paypalCheckout),this.paypalCheckout=void 0})}get3DS(){return ta(this,void 0,void 0,function*(){return this.threeDS||(this.threeDS=Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]).then(([e,t])=>t.create({client:e,version:2}))),this.threeDS})}getVenmoCheckout(e){return ta(this,void 0,void 0,function*(){if(!this.venmoCheckout){const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadVenmoCheckout(),n=Object.assign({client:t,allowDesktop:!0,paymentMethodUsage:"multi_use"},e||{});this.venmoCheckout=yield new Promise((e,t)=>{i.create(n,(i,n)=>i?t(i):n.isBrowserSupported()?void e(n):t(new Mo))})}return this.venmoCheckout})}verifyCard(e,t,i){return ta(this,void 0,void 0,function*(){const n=yield this.tokenizeCard(e,t);return this.challenge3DSVerification(n,i)})}tokenizeCard(e,t){return ta(this,void 0,void 0,function*(){const{paymentData:i}=e;if(!function(e){if("object"!=typeof e||null===e)return!1;const t=e;return"object"==typeof t.ccExpiry&&null!==t.ccExpiry&&"string"==typeof t.ccNumber&&"string"==typeof t.ccName}(i))throw new Hr(["payment.paymentData"]);const n=this.getErrorsRequiredFields(i);if(!f(n))throw new Vr(n);const o=this.mapToCreditCard(i,t),r=yield this.getClient(),{creditCards:a}=yield r.request(o);return{nonce:a[0].nonce,bin:a[0].details.bin}})}challenge3DSVerification(e,t){return ta(this,void 0,void 0,function*(){const i=yield this.get3DS();return this.present3DSChallenge(i,t,e)})}teardownModule(e){return e?e.teardown():Promise.resolve()}getClientTokenOrThrow(){if(!this.clientToken)throw new io(Jn.PaymentNotInitialized);return this.clientToken}getErrorsRequiredFields(e){const{ccNumber:t,ccExpiry:i}=e,n={};return t||(n.ccNumber=[{message:"Credit card number is required",type:"required"}]),i||(n.ccExpiry=[{message:"Expiration date is required",type:"required"}]),n}mapToCreditCard(e,t){return{data:{creditCard:{cardholderName:e.ccName,number:e.ccNumber,cvv:e.ccCvv,expirationDate:`${e.ccExpiry.month}/${e.ccExpiry.year}`,options:{validate:!1},billingAddress:t&&{countryCodeAlpha2:t.countryCode,locality:t.city,countryName:t.country,postalCode:t.postalCode,streetAddress:t.address2?`${t.address1} ${t.address2}`:t.address1}}},endpoint:"payment_methods/credit_cards",method:"post"}}present3DSChallenge(e,t,i){const{nonce:n,bin:o}=i;if(!this.threeDSecureOptions||!n)throw new io(Jn.PaymentNotInitialized);const{addFrame:r,removeFrame:a,challengeRequested:s=!0,additionalInformation:d}=this.threeDSecureOptions,c=()=>ta(this,void 0,void 0,function*(){const t=yield e.cancelVerifyCard();return l.cancel(new Qo),t}),u=t.toFixed(2),l=new Yr(e.verifyCard({addFrame:(e,t)=>{r&&r(e,t,c)},amount:Number(u),bin:o,challengeRequested:s,nonce:n,removeFrame:a,onLookupComplete:(e,t)=>{t()},collectDeviceData:!0,additionalInformation:d}));return l.promise}}function na(e){const{color:t,fundingicons:i,height:n=40,layout:o,shape:r,size:a,tagline:s}=e||{},d={color:t,fundingicons:i,height:oa(n),layout:o,shape:r||"rect",size:a,tagline:s};return R(d,C)}function oa(e){const t=Number(e);return!t||Number.isNaN(t)?40:t>55?55:t<25?25:t}function ra(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}var aa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class sa{constructor(e,t,i,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=i,this.braintreeHostWindow=n}initialize(e){return aa(this,void 0,void 0,function*(){const{braintreepaypal:t,containerId:i,methodId:n}=e;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let o,r=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new yo('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');o=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow().currency.code;const a=r.getPaymentMethodOrThrow(n),{clientToken:s,config:d,initializationData:c}=a;if(!s||!c)throw new Xn(Qn.MissingPaymentMethod);const u={currency:o,intent:c.intent,isCreditEnabled:c.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(u,e=>{this.renderPayPalButton(e,t,i,n,!!d.testMode)},e=>this.handleError(e,i,t.onError))})}deinitialize(){return aa(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,i,n,o){const{style:r,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:d}=t,{paypal:c}=this.braintreeHostWindow;if(c){const u=c.Buttons({env:o?"sandbox":"production",fundingSource:c.FUNDING.PAYPAL,style:na(r),createOrder:()=>this.setupPayment(e,t,n),onApprove:t=>this.tokenizePayment(t,e,n,a,s)});u.isEligible()?u.render(`#${i}`):d&&"function"==typeof d&&d()}else this.braintreeIntegrationService.removeElement(i)}setupPayment(e,t,i){var n;return aa(this,void 0,void 0,function*(){const{onPaymentError:o,shippingAddress:r,buyNowInitializeOptions:a}=t;try{const o="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==o?void 0:o.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(i),u=o?o.cartAmount:s.getCartOrThrow().cartAmount,l=o?t.currencyCode:s.getCartOrThrow().currency.code,h=r||(null==d?void 0:d.addresses[0]),p=h?ra(h):void 0;return yield e.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,shippingAddressOverride:p,amount:u,currency:l,offerCredit:!1,intent:null===(n=c.initializationData)||void 0===n?void 0:n.intent})}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}tokenizePayment(e,t,i,n,o){return aa(this,void 0,void 0,function*(){try{const{deviceData:o}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:a,nonce:s}=r,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:i,action:n?"process_payment":"set_external_checkout",nonce:s,device_data:o,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),r}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}createBuyNowCart(e){return aa(this,void 0,void 0,function*(){if(!e)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new fo}})}handleError(e,t,i){if(this.braintreeIntegrationService.removeElement(t),!i||!qo(e))throw e;i(e)}}const da=go(e=>{const t=window,n=new Do(e),o=new ia(new Zo(le(),t,n),t);return new sa(e,i(),o,t)},[{id:"braintreepaypal"}]);class ca{constructor(e){this.paymentIntegrationService=e,this.braintreeHostWindow=window}render(e,t,i){const n=t&&document.getElementById(t);if(this.braintreeHostWindow.paypal&&n){const o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow(),a=o.getBillingAddressOrThrow(),s=o.getPaymentMethodOrThrow(e);if(!s.initializationData)return;const{paypalBNPLConfiguration:d=[]}=s.initializationData,c=i===ea.PAYMENT?"checkout":i,u=d&&d.find(({id:e})=>e===c);if(!u||!u.status)return;i===ea.CART&&(n.removeAttribute("data-pp-style-logo-type"),n.removeAttribute("data-pp-style-logo-position"),n.removeAttribute("data-pp-style-text-color"),n.removeAttribute("data-pp-style-text-size")),this.braintreeHostWindow.paypal.Messages({amount:r.cartAmount,buyerCountry:a.countryCode,placement:i,style:this.getPaypalMessagesStylesFromBNPLConfig(u)}).render(`#${t}`)}}getPaypalMessagesStylesFromBNPLConfig({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t}}var ua=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class la{constructor(e,t,i,n,o){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=i,this.braintreeMessages=n,this.braintreeHostWindow=o}initialize(e){var t,i;return ua(this,void 0,void 0,function*(){const{braintreepaypalcredit:n,containerId:o,methodId:r}=e;if(!r)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!o)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let a,s=this.paymentIntegrationService.getState();if(n.buyNowInitializeOptions){if(!n.currencyCode)throw new yo('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');a=n.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),s=this.paymentIntegrationService.getState(),a=s.getCartOrThrow().currency.code;const d=s.getPaymentMethodOrThrow(r),{clientToken:c,config:u,initializationData:l}=d;if(!c||!l)throw new Xn(Qn.MissingPaymentMethod);const h={currency:a,intent:l.intent,isCreditEnabled:l.isCreditEnabled,commit:!1},p=Ao(null!==(i=null===(t=s.getStoreConfig())||void 0===t?void 0:t.checkoutSettings.features)&&void 0!==i?i:{},"PAYPAL-5663.hide_braintree_card_banner_implementation_in_checkout_sdk");this.braintreeIntegrationService.initialize(c),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{!p&&n.messagingContainerId&&this.renderPayPalMessages(r,n.messagingContainerId),this.renderPayPalButton(e,n,o,r,!!u.testMode)},e=>this.handleError(e,o,n.onError))})}deinitialize(){return ua(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalMessages(e,t){this.braintreeMessages.render(e,t,ea.CART)}renderPayPalButton(e,t,i,n,o){const{style:r,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:d}=t,{paypal:c}=this.braintreeHostWindow;let u=!1;c&&[c.FUNDING.PAYLATER,c.FUNDING.CREDIT].forEach(l=>{const h=l===c.FUNDING.CREDIT?Object.assign({label:Jr.CREDIT},na(r)):na(r);if(!u){const r=c.Buttons({env:o?"sandbox":"production",fundingSource:l,style:h,createOrder:()=>this.setupPayment(e,t,n),onApprove:t=>this.tokenizePayment(t,e,n,a,s)});r.isEligible()?(r.render(`#${i}`),u=!0):c.FUNDING.CREDIT&&d&&"function"==typeof d&&d()}}),c&&u||this.braintreeIntegrationService.removeElement(i)}setupPayment(e,t,i){var n;return ua(this,void 0,void 0,function*(){const{onPaymentError:o,shippingAddress:r,buyNowInitializeOptions:a}=t;try{const o="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==o?void 0:o.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(i),u=o?o.cartAmount:s.getCartOrThrow().cartAmount,l=o?t.currencyCode:s.getCartOrThrow().currency.code,h=r||(null==d?void 0:d.addresses[0]),p=h?ra(h):void 0;return yield e.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,shippingAddressOverride:p,amount:u,currency:l,offerCredit:!0,intent:null===(n=c.initializationData)||void 0===n?void 0:n.intent})}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}tokenizePayment(e,t,i,n,o){return ua(this,void 0,void 0,function*(){try{const{deviceData:o}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:a,nonce:s}=r,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:i,action:n?"process_payment":"set_external_checkout",nonce:s,device_data:o,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),r}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}createBuyNowCart(e){return ua(this,void 0,void 0,function*(){if(!e)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new fo}})}handleError(e,t,i){if(this.braintreeIntegrationService.removeElement(t),!i||!qo(e))throw e;i(e)}}const ha=go(e=>{const t=window,n=new Do(e),o=new ia(new Zo(le(),t,n),t),r=new ca(e);return new la(e,i(),o,r,t)},[{id:"braintreepaypalcredit"}]);var pa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ma{constructor(e,t,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=i}initialize(e){return pa(this,void 0,void 0,function*(){const{containerId:t,methodId:i}=e;if(!i)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const n=this.paymentIntegrationService.getState(),{clientToken:o,initializationData:r,config:a}=n.getPaymentMethodOrThrow(i);if(!o||!r)throw new Xn(Qn.MissingPaymentMethod);this.braintreeSdk.initialize(o);const s=yield this.braintreeSdk.getBraintreeVisaCheckout(),{currency:{code:d},cartAmount:c}=n.getCartOrThrow(),u=yield this.braintreeSdk.getVisaCheckoutSdk(a.testMode),l=s.createInitOptions({paymentRequest:{currencyCode:d,subtotal:String(c)},settings:{shipping:{collectShipping:!0}}});this.createSignInButton(t),yield u.init(l),u.on("payment.success",e=>pa(this,void 0,void 0,function*(){yield this.paymentSuccess(s,e)}))})}deinitialize(){return Promise.resolve()}paymentSuccess(e,t){return pa(this,void 0,void 0,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const i=this.paymentIntegrationService.getState(),n=i.getShippingAddress(),o=i.getBillingAddress(),{shippingAddress:r=this.toVisaCheckoutAddress(n),billingAddress:a=this.toVisaCheckoutAddress(o)}=e;return this.postForm(Object.assign(Object.assign({},e),{shippingAddress:r,billingAddress:a}),t)})})}postForm(e,t){const{userData:i,billingAddress:n,shippingAddress:o,details:r}=e,{userEmail:a}=i,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:r.cardType,number:r.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,n)),shipping_address:JSON.stringify(this.getAddress(a,o))})}toVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}createSignInButton(e){const t=document.querySelector(`#${e}`);if(!t)throw new Error("Need a container to place the button");return this.insertVisaCheckoutButton(t)}insertVisaCheckoutButton(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-end",t.innerHTML='\n <img\n alt="Visa Checkout"\n class="v-button"\n role="button"\n src="https://secure.checkout.visa.com/wallet-services-web/xo/button.png?acceptCanadianVisaDebit=false&cobrand=true&height=34&width=178"\n />\n <a class="v-learn v-learn-default" style="text-align: right; display: block; font-size: 10px; color: #003366;" href="#" data-locale="en_US">Tell Me More</a>',e.appendChild(t),t}}const ga=go(e=>{const t=window,n=new Do(e),o=new Yo(new Zo(le(),t,n));return new ma(e,i(),o)},[{id:"braintreevisacheckout"}]);function ya(e){const{billingAddress:t,email:i,firstName:n,lastName:o,phone:r,shippingAddress:a}=e,s=t||a;return{email:i,first_name:n,last_name:o,phone_number:r,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}function fa(e){const{email:t,phone:i,shippingAddress:n}=e,o=(null==n?void 0:n.recipientName)||"",[r,a]=o.split(" ");return{email:t,first_name:r||"",last_name:a||"",phone_number:i,address_line_1:null==n?void 0:n.line1,address_line_2:null==n?void 0:n.line2,city:null==n?void 0:n.city,state:null==n?void 0:n.state,country_code:null==n?void 0:n.countryCode,postal_code:null==n?void 0:n.postalCode}}var va=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};const Sa=e=>{const{color:t,height:i}=e;return{backgroundColor:(n=t||"",n===Qr.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("/app/assets/img/payment-providers/venmo-logo-${t===Qr.WHITE?Qr.BLUE:Qr.WHITE}.svg")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${i||40}px`,minWidth:"150px",height:"100%",width:"100%",border:t===Qr.WHITE?"1px solid black":"none"};var n};class Ca{constructor(e,t,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=i,this.onError=T}initialize(e){return va(this,void 0,void 0,function*(){const{braintreevenmo:t,containerId:i,methodId:n}=e;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');const o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n),{clientToken:r,initializationData:a}=o,{paymentButtonStyles:s}=a,{cartButtonStyles:d}=s||{},c=(null==t?void 0:t.style)||d;if(!r||!a)throw new Xn(Qn.MissingPaymentMethod);if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadDefaultCheckout(),this.onError=(null==t?void 0:t.onError)||this.handleError,this.braintreeSdk.initialize(r);try{const e=yield this.braintreeSdk.getVenmoCheckoutOrThrow();this.renderVenmoButton(e,i,null==t?void 0:t.buyNowInitializeOptions,c)}catch(e){(function(e){return"object"==typeof e&&null!==e&&"name"in e&&"BraintreeError"===e.name}(e)||function(e){return e instanceof Mo}(e))&&this.handleInitializationVenmoError(e,i)}})}deinitialize(){return va(this,void 0,void 0,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}handleError(e){throw new Error(e.message)}createBuyNowCart(e){return va(this,void 0,void 0,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=null==e?void 0:e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}}})}handleInitializationVenmoError(e,t){return this.removeVenmoContainer(t),this.onError(e)}removeVenmoContainer(e){const t=document.getElementById(e);t&&t.remove()}renderVenmoButton(e,t,i,n){const o=document.getElementById(t),{color:r}=n||{};if(!o)throw new yo("Unable to create wallet button without valid container ID.");o.setAttribute("aria-label","Venmo"),Object.assign(o.style,Sa(n||{})),o.addEventListener("click",()=>va(this,void 0,void 0,function*(){o.setAttribute("disabled","true");const t=yield this.createBuyNowCart(i);e.tokenize&&e.tokenize((e,i)=>va(this,void 0,void 0,function*(){o.removeAttribute("disabled"),e&&this.onError(e),yield this.handlePostForm(i,null==t?void 0:t.id)}))})),r===Qr.BLUE&&(o.addEventListener("mouseenter",()=>{o.style.backgroundColor="#0a7fc2"}),o.addEventListener("mouseleave",()=>{o.style.backgroundColor=Sa(n||{}).backgroundColor}))}handlePostForm(e,t){return va(this,void 0,void 0,function*(){const{deviceData:i}=yield this.braintreeSdk.getDataCollectorOrThrow(),{nonce:n,details:o}=e;this.formPoster.postForm("/checkout.php",Object.assign({nonce:n,provider:"braintreevenmo",payment_type:"paypal",device_data:i,action:"set_external_checkout",billing_address:JSON.stringify(ya(o)),shipping_address:JSON.stringify(fa(o))},t&&{cart_id:t}))})}}const Ia=go(e=>{const t=window,n=le(),o=new Do(e),r=new Zo(n,t,o),a=new Yo(r);return new Ca(e,i(),a)},[{id:"braintreevenmo"}]);var _a;!function(e){e.ADYEN_V2="googlepayadyenv2",e.ADYEN_V3="googlepayadyenv3",e.AUTHORIZE_NET="googlepayauthorizenet",e.BNZ="googlepaybnz",e.BRAINTREE="googlepaybraintree",e.PAYPAL_COMMERCE="googlepaypaypalcommerce",e.BIGCOMMERCE_PAYMENTS="googlepay_bigcommerce_payments",e.CHECKOUT_COM="googlepaycheckoutcom",e.CYBERSOURCE_V2="googlepaycybersourcev2",e.ORBITAL="googlepayorbital",e.STRIPE="googlepaystripe",e.STRIPE_UPE="googlepaystripeupe",e.STRIPE_OCS="googlepaystripeocs",e.WORLDPAY_ACCESS="googlepayworldpayaccess",e.TD_ONLINE_MART="googlepaytdonlinemart"}(_a||(_a={}));const wa=function(e,t,i){return t&&i?ba(0,t,i):function(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(i=>{const n=Object.getOwnPropertyDescriptor(e.prototype,i);n&&"constructor"!==i&&Object.defineProperty(t.prototype,i,ba(e.prototype,i,n))}),t}(e)};function ba(e,t,i){if("function"!=typeof i.value)return i;let n=i.value;return{get(){const e=n.bind(this);return Object.defineProperty(this,t,Object.assign(Object.assign({},i),{value:e})),e},set(e){n=e}}}class Ea{constructor(e){if(!e)throw new Error("Currency settings missing");const{decimalPlaces:t,symbolLocation:i,symbol:n,thousandsSeparator:o,decimalSeparator:r}=e;if("string"!=typeof i||"string"!=typeof n||"string"!=typeof o||"string"!=typeof r||"string"!=typeof t)throw new yo("Invalid currency settings provided");this._decimalPlaces=parseInt(t,10),this._symbolLocation=i,this._symbol=n,this._thousandsSeparator=o,this._decimalSeparator=r}format(e){if("number"!=typeof e)throw new yo("Invalid amount provided");const t=this._formatNumber(e),i=this._formatCurrency(t);return e<0?`-${i}`:i}_formatNumber(e){const t=Math.abs(e),[i,n=""]=this._toFixed(t,this._decimalPlaces).split("."),o=i.replace(/\B(?=(\d{3})+(?!\d))/g,this._thousandsSeparator);return this._decimalPlaces<1?o:[o,n].join(this._decimalSeparator)}_formatCurrency(e){return"left"===this._symbolLocation.toLowerCase()?`${this._symbol}${e}`:`${e}${this._symbol}`}_toFixed(e,t){return(+`${Math.round(+`${e}e${t}`)}e${-t}`).toFixed(t)}}let Pa=class{constructor(e){this._storeConfig=e,this._customerFormatter=new Ea(this._storeConfig.shopperCurrency),this._storeFormatter=new Ea(this._storeConfig.currency)}toCustomerCurrency(e){const t=this._storeConfig.shopperCurrency.exchangeRate;return this._customerFormatter.format(e*t)}toStoreCurrency(e){return this._storeFormatter.format(e)}};Pa=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([wa],Pa);const Oa=Pa;var Aa,Ta,ka,Ra,Da,Ma,Na,La,za;function Ua(e){return e in Ma}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(Aa||(Aa={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Ta||(Ta={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ka||(ka={})),function(e){e.pill="pill",e.rect="rect"}(Ra||(Ra={})),function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(Da||(Da={})),function(e){e.AMEX="AMEX",e.DISCOVER="DISCOVER",e.INTERAC="INTERAC",e.JCB="JCB",e.MC="MASTERCARD",e.VISA="VISA"}(Ma||(Ma={})),function(e){e.OFFER="OFFER",e.PAYMENT_AUTHORIZATION="PAYMENT_AUTHORIZATION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.SHIPPING_OPTION="SHIPPING_OPTION"}(Na||(Na={})),function(e){e.OFFER_INVALID="OFFER_INVALID",e.PAYMENT_DATA_INVALID="PAYMENT_DATA_INVALID",e.SHIPPING_ADDRESS_INVALID="SHIPPING_ADDRESS_INVALID",e.SHIPPING_ADDRESS_UNSERVICEABLE="SHIPPING_ADDRESS_UNSERVICEABLE",e.SHIPPING_OPTION_INVALID="SHIPPING_OPTION_INVALID",e.OTHER_ERROR="OTHER_ERROR"}(La||(La={})),function(e){e.INITIALIZE="INITIALIZE",e.SHIPPING_OPTION="SHIPPING_OPTION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.OFFER="OFFER"}(za||(za={}));var Fa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ba{constructor(e,t){this._gatewayIdentifier=e,this._paymentIntegrationService=t,this._isBuyNowFlow=!1,this._shouldRequestShipping=!0}mapToShippingAddressRequestBody({shippingAddress:e}){if(!e)return;const{company:t="",phone:i=""}=this._paymentIntegrationService.getState().getShippingAddress()||{};return this._mapToAddressRequestBody(e,t,i)}mapToBillingAddressRequestBody(e){const{billingAddress:t}=e.paymentMethodData.info;if(!t)return;const{company:i="",phone:n="",email:o,customFields:r=[]}=this._paymentIntegrationService.getState().getBillingAddress()||{};return Object.assign(Object.assign({},this._mapToAddressRequestBody(t,i,n,r)),{email:o||e.email})}mapToExternalCheckoutData(e){var t;const{paymentMethodData:{tokenizationData:{token:i},info:{cardNetwork:n,cardDetails:o}}}=e;if(!i)throw new Xn(Qn.MissingPaymentToken);return Promise.resolve(Object.assign({nonce:i,card_information:{type:n,number:o}},this._isBuyNowFlow&&{cart_id:null===(t=this._paymentIntegrationService.getState().getCart())||void 0===t?void 0:t.id}))}getRequiredData(){var e;return Fa(this,void 0,void 0,function*(){const t={emailRequired:!0};if(!this._isShippingAddressRequired())return t;const i=yield this._paymentIntegrationService.loadShippingCountries(),n=null===(e=i.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code);return Object.assign(Object.assign({},t),{shippingAddressRequired:!0,shippingAddressParameters:Object.assign({phoneNumberRequired:!0},n&&{allowedCountryCodes:n}),shippingOptionRequired:!0})})}getCallbackIntents(){return this._isShippingAddressRequired()?[Na.OFFER,Na.SHIPPING_ADDRESS,Na.SHIPPING_OPTION]:[Na.OFFER]}getCallbackTriggers(){return{availableTriggers:[za.INITIALIZE,za.SHIPPING_ADDRESS,za.SHIPPING_OPTION,za.OFFER],initializationTrigger:[za.INITIALIZE],addressChangeTriggers:[za.INITIALIZE,za.SHIPPING_ADDRESS],shippingOptionsChangeTriggers:[za.SHIPPING_OPTION],offerChangeTriggers:[za.OFFER]}}getNonce(e){var t;const i=null===(t=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.nonce;if(!i)throw new Xn(Qn.MissingPaymentToken);return Promise.resolve(i)}extraPaymentData(){return Promise.resolve(void 0)}getMerchantInfo(){const{googleMerchantName:e,googleMerchantId:t,platformToken:i}=this.getGooglePayInitializationData();return{merchantName:e,merchantId:t,authJwt:i}}getTransactionInfo(){let e;if(this._isBuyNowFlow)e=this._getCurrencyCodeOrThrow();else{const{getCartOrThrow:t}=this._paymentIntegrationService.getState();e=t().currency.code}const t=this.getGooglePayInitializationData().storeCountry;return Object.assign(Object.assign({},t&&{countryCode:t}),{currencyCode:e,totalPriceStatus:Da.ESTIMATED,totalPrice:"0"})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData().gatewayMerchantId;if(!e)throw new yo("Unable to proceed, gatewayMerchantId is missing.");return{gateway:this._gatewayIdentifier,gatewayMerchantId:e}}getCardParameters(){return{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:this.getPaymentMethod().supportedCards.filter(Ua).map(e=>Ma[e]),billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}initialize(e,t,i){return this._getPaymentMethodFn=e,this._isBuyNowFlow=Boolean(t),this._currencyCode=i,this._isBuyNowFlow&&this._getCurrencyCodeOrThrow(),Promise.resolve()}handleShippingAddressChange(e){var t,i,n,o;return Fa(this,void 0,void 0,function*(){e&&(e.name=e.name||"",e.address1=e.address1||"");const r=this.mapToShippingAddressRequestBody({shippingAddress:e});r&&(yield this._paymentIntegrationService.updateShippingAddress(r));const a=this._paymentIntegrationService.getState(),s=a.getConsignments();if(!(null==s?void 0:s[0]))return;const d=s[0],c=a.getStoreConfigOrThrow();this._currencyService||(this._currencyService=new Oa(c));const u=(d.availableShippingOptions||[]).map(this._getGooglePayShippingOption.bind(this)),l=null===(t=d.availableShippingOptions)||void 0===t?void 0:t.find(e=>e.isRecommended);if(u.length){const e=(null===(i=d.selectedShippingOption)||void 0===i?void 0:i.id)||(null==l?void 0:l.id)||(null===(n=u[0])||void 0===n?void 0:n.id);return!(null===(o=d.selectedShippingOption)||void 0===o?void 0:o.id)&&u[0]&&(yield this.handleShippingOptionChange((null==l?void 0:l.id)||u[0].id)),{defaultSelectedOptionId:e,shippingOptions:u}}})}handleShippingOptionChange(e){return Fa(this,void 0,void 0,function*(){if("shipping_option_unselected"!==e)return this._paymentIntegrationService.selectShippingOption(e)})}getTotalPrice(){const{getCheckoutOrThrow:e,getCartOrThrow:t}=this._paymentIntegrationService.getState(),{decimalPlaces:i}=t().currency;return L(e().outstandingBalance,i).toFixed(i)}handleCoupons(e){return Fa(this,void 0,void 0,function*(){const{redemptionCodes:t=[]}=e,{offers:i}=this.getAppliedCoupons();let n;return yield t.reduce((e,t)=>Fa(this,void 0,void 0,function*(){if(yield e,i.some(({redemptionCode:e})=>e===t))return;const o=yield this.applyCoupon(t);o&&(n=o)}),Promise.resolve()),yield i.reduce((e,i)=>Fa(this,void 0,void 0,function*(){yield e,t.includes(i.redemptionCode)||(yield this._paymentIntegrationService.removeCoupon(i.redemptionCode))}),Promise.resolve()),{newOfferInfo:this.getAppliedCoupons(),error:n}})}getAppliedCoupons(){const e=this._paymentIntegrationService.getState(),{coupons:t}=e.getCheckout()||{};return{offers:(t||[]).map(e=>{const{displayName:t,code:i}=e;return{redemptionCode:i,description:t}})}}applyCoupon(e){return Fa(this,void 0,void 0,function*(){let t;try{yield this._paymentIntegrationService.applyCoupon(e)}catch(e){return e instanceof Error&&(t={reason:La.OFFER_INVALID,message:e.message,intent:za.OFFER}),t}})}setShouldRequestShipping(e){this._shouldRequestShipping=e}getGooglePayInitializationData(){return to(this.getPaymentMethod().initializationData,()=>new yo("Missing initialization data."))}getPaymentMethod(){return to(this._getPaymentMethodFn,()=>new io(Jn.PaymentNotInitialized))()}getGatewayIdentifier(){return this._gatewayIdentifier}setGatewayIdentifier(e){this._gatewayIdentifier=e||this.getGatewayIdentifier()}_isShippingAddressRequired(){const{getCartOrThrow:e,getStoreConfigOrThrow:t,getShippingAddress:i}=this._paymentIntegrationService.getState(),n=t();let o;return o=Ao(n.checkoutSettings.features,"PI-4290.google_pay_require_shipping_address")?this._shouldRequestShipping:void 0===i(),o&&(r=e(),a=n,!!r&&(!!r.lineItems.physicalItems.some(e=>e.isShippingRequired)||!(!a||!r.lineItems.customItems)&&r.lineItems.customItems.length>0));var r,a}_mapToAddressRequestBody(e,t,i,n){const{name:o,address1:r,address2:a,address3:s,locality:d,administrativeArea:c,countryCode:u,postalCode:l,phoneNumber:h}=e,[p,m]=this._getFirstAndLastName(o);return{firstName:p,lastName:m,company:t,address1:r,address2:`${a} ${s}`.trim(),city:d||c,stateOrProvince:c,stateOrProvinceCode:c,countryCode:u,postalCode:l,phone:h||i,customFields:n||[]}}_getFirstAndLastName(e){const t=e.split(" ");return 1===t.length?[e,""]:[t.slice(0,-1).join(" "),t[t.length-1]]}_getCurrencyCodeOrThrow(){return to(this._currencyCode,()=>new yo('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}_getGooglePayShippingOption({id:e,cost:t,description:i,additionalDescription:n}){var o;const r=null===(o=this._currencyService)||void 0===o?void 0:o.toCustomerCurrency(t);return this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-3540.googlepay_new_shipping_options_description"]?{id:e,label:`${r||t} ${i}`,description:n}:{id:e,label:i,description:r||t}}}var xa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class qa extends Ba{constructor(e,t){super("braintree",e),this._braintreeSdk=t,this._methodId=_a.BRAINTREE,this._service=e}initialize(e,t,i){const n=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return xa(this,void 0,void 0,function*(){yield n.initialize.call(this,e,t,i);let o=n.getPaymentMethod.call(this);if(o.clientToken||(o=(yield this._service.loadPaymentMethod(this._methodId)).getPaymentMethodOrThrow(this._methodId)),!o.clientToken||!o.initializationData)throw new Xn(Qn.MissingPaymentMethod);return this._braintreeSdk.initialize(o.clientToken),this._braintreeGooglePayment=yield this._braintreeSdk.getBraintreeGooglePayment(),Promise.resolve()})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});var i;return xa(this,void 0,void 0,function*(){const n=yield t.getNonce.call(this,e),{clientToken:o,initializationData:r}=t.getPaymentMethod.call(this);if(!o||!r||!(null===(i=r.card_information)||void 0===i?void 0:i.bin))throw new Xn(Qn.MissingPaymentMethod);const{isThreeDSecureEnabled:a,card_information:{bin:s,isNetworkTokenized:d}}=r;if(a&&!d){const e=yield this._braintreeSdk.getBraintreeThreeDS(),{orderAmount:t}=this._service.getState().getOrderOrThrow();return(yield this._braintreePresent3DSChallenge(e,t,n,s)).nonce}return n})}extraPaymentData(){return xa(this,void 0,void 0,function*(){return{deviceSessionId:yield this._getBraintreeDeviceData()}})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return xa(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);let n;try{n=JSON.parse(i.nonce)}catch(e){throw new yo("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"androidPayCards"in e}(e))throw new Xn(Qn.MissingPaymentToken)}(n),i.nonce=n.androidPayCards[0].nonce,i.card_information.bin=n.androidPayCards[0].details.bin,i.card_information.isNetworkTokenized=n.androidPayCards[0].details.isNetworkTokenized,i})}getCardParameters(){return super.getCardParameters()}getPaymentGatewayParameters(){const e=Object.create(null,{getMerchantInfo:{get:()=>super.getMerchantInfo},getTransactionInfo:{get:()=>super.getTransactionInfo},getRequiredData:{get:()=>super.getRequiredData}});return xa(this,void 0,void 0,function*(){return this.getBraintreeGooglePayment().createPaymentDataRequest(Object.assign({merchantInfo:e.getMerchantInfo.call(this),transactionInfo:e.getTransactionInfo.call(this),cardRequirements:{billingAddressRequired:!0,billingAddressFormat:"FULL"}},yield e.getRequiredData.call(this))).paymentMethodTokenizationParameters.parameters})}getBraintreeGooglePayment(){if(!this._braintreeGooglePayment)throw new Xn(Qn.MissingPaymentMethod);return this._braintreeGooglePayment}_getBraintreeDeviceData(){return xa(this,void 0,void 0,function*(){const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e})}_braintreePresent3DSChallenge(e,t,i,n){return new Yr(e.verifyCard({amount:t,bin:n,nonce:i,onLookupComplete:(e,t)=>{t()}})).promise}}class ja extends Ce{constructor(e){super(e||"Unable to proceed because the client library of a payment method has thrown an unexpected error."),this.name="PaymentMethodFailedError",this.type="payment_method_client_invalid"}}var Ga=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ha{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t,i;return Ga(this,void 0,void 0,function*(){if(!e.methodId||(n=e.methodId,!Object.values(_a).includes(n)))throw new yo('Unable to proceed because "methodId" is not a valid key.');var n;if(this._methodId=e.methodId,!e.containerId)throw new yo('Unable to proceed because "containerId" is not a valid key.');const o=e[this._getMethodOrThrow()];if(!o)throw new yo("Unable to proceed without valid options.");const{buyNowInitializeOptions:r,currencyCode:a,buttonColor:s,buttonType:d,onError:c}=o;let u,l=this._paymentIntegrationService.getState();try{u=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}catch(e){l=yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodOrThrow()),u=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}if(this._countryCode=null===(t=u.initializationData)||void 0===t?void 0:t.storeCountry,r){if(!a)throw new yo('Unable to initialize payment because "options.currencyCode" argument is not provided.');this._currencyCode=a,this._buyNowInitializeOptions=r,yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions(),!!r,a)}else yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions());this._paymentButton=null!==(i=this._paymentButton)&&void 0!==i?i:this._googlePayPaymentProcessor.addPaymentButton(e.containerId,{buttonColor:null!=s?s:"default",buttonType:null!=d?d:"plain",onClick:this._handleClick(c)})})}deinitialize(){var e;return null===(e=this._paymentButton)||void 0===e||e.remove(),this._paymentButton=void 0,this._methodId=void 0,Promise.resolve()}_handleClick(e){return t=>Ga(this,void 0,void 0,function*(){t.preventDefault();try{this._buyNowInitializeOptions?yield this._createBuyNowCartOrThrow(this._buyNowInitializeOptions):yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(t){let i=t;if(function(e){return"object"==typeof e&&null!==e&&"statusCode"in e}(t)){if("CANCELED"===t.statusCode)throw new Qo;i=new ja(JSON.stringify(t))}throw null==e||e(new ja("An error occurred while requesting your Google Pay payment details.")),i}})}_interactWithPaymentSheet(){var e;return Ga(this,void 0,void 0,function*(){const t=yield this._googlePayPaymentProcessor.showPaymentSheet(),i=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(t),n=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(t),o="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;i&&(yield this._paymentIntegrationService.updateBillingAddress(i)),n&&!(null===(e=this._buyNowCart)||void 0===e?void 0:e.lineItems.digitalItems.length)&&(yield this._paymentIntegrationService.updateShippingAddress(n)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodOrThrow(),t,o)})}_getGooglePayClientOptions(){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:e,shippingAddress:t,shippingOptionData:i,offerData:n})=>Ga(this,void 0,void 0,function*(){const{availableTriggers:o,addressChangeTriggers:r,shippingOptionsChangeTriggers:a,offerChangeTriggers:s}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!o.includes(e))return;const d=r.includes(e)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(t):void 0;a.includes(e)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(i.id));const{newOfferInfo:c,error:u}=s.includes(e)?yield this._googlePayPaymentProcessor.handleCoupons(n):{},l=u;return this._buyNowInitializeOptions?this._getBuyNowTransactionInfo(d,c,l):this._getTransactionInfo(d,c,l)})}}}_createBuyNowCartOrThrow(e){return Ga(this,void 0,void 0,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=e.getBuyNowCartRequestBody();try{this._buyNowCart=yield this._paymentIntegrationService.createBuyNowCart(t),yield this._paymentIntegrationService.loadCheckout(this._buyNowCart.id)}catch(e){if("string"==typeof e)throw new fo(e);throw e}}})}_getBuyNowTransactionInfo(e,t,i){if(!this._buyNowCart)return;const{cartAmount:n}=this._buyNowCart,o=this._googlePayPaymentProcessor.getTotalPrice();return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:this._getCurrencyCodeOrThrow(),totalPrice:o||String(n),totalPriceStatus:Da.FINAL})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),i&&{error:i})}_getTransactionInfo(e,t,i){return Ga(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadCheckout();const n=this._googlePayPaymentProcessor.getTotalPrice(),{code:o}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:o,totalPriceStatus:Da.FINAL,totalPrice:n})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),i&&{error:i})})}_getMethodOrThrow(){return to(this._methodId,()=>new io(Jn.PaymentNotInitialized))}_getCurrencyCodeOrThrow(){return to(this._currencyCode,()=>new yo('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}}var Va=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ya{constructor(e,t,i,n){this._scriptLoader=e,this._gateway=t,this._requestSender=i,this._formPoster=n,this._baseRequest={apiVersion:2,apiVersionMinor:0}}initialize(e,t,i,n){return Va(this,void 0,void 0,function*(){this._paymentsClient=yield this._scriptLoader.getGooglePaymentsClient(e().config.testMode,t),yield this._gateway.initialize(e,i,n),this._buildButtonPayloads()})}initializeWidget(){return Va(this,void 0,void 0,function*(){yield this._buildWidgetPayloads(),yield this._determineReadinessToPay(),this._prefetchGooglePaymentData()})}getNonce(e){return this._gateway.getNonce(e)}extraPaymentData(){return Va(this,void 0,void 0,function*(){return this._gateway.extraPaymentData()})}addPaymentButton(e,t){const i=document.querySelector(`#${e}`);if(!i)return;const n=this._getPaymentsClient().createButton(Object.assign(Object.assign({},t),{allowedPaymentMethods:[this._getBaseCardPaymentMethod()]}));return i.appendChild(n)}showPaymentSheet(){return Va(this,void 0,void 0,function*(){const e=this._getPaymentDataRequest();return this._getPaymentsClient().loadPaymentData(e)})}setExternalCheckoutXhr(e,t){return Va(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t)})}setExternalCheckoutForm(e,t,i){return Va(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t,!0,i)})}mapToBillingAddressRequestBody(e){return this._gateway.mapToBillingAddressRequestBody(e)}mapToShippingAddressRequestBody(e){return this._gateway.mapToShippingAddressRequestBody(e)}processAdditionalAction(e,t){return"processAdditionalAction"in this._gateway?this._gateway.processAdditionalAction(e,t):Promise.reject(e)}signOut(e){return Va(this,void 0,void 0,function*(){yield this._requestSender.get(`/remote-checkout/${e}/signout`)})}getCallbackTriggers(){return this._gateway.getCallbackTriggers()}setShouldRequestShipping(e){return this._gateway.setShouldRequestShipping(e)}handleShippingAddressChange(e){return Va(this,void 0,void 0,function*(){return this._gateway.handleShippingAddressChange(e)})}handleShippingOptionChange(e){return Va(this,void 0,void 0,function*(){yield this._gateway.handleShippingOptionChange(e)})}handleCoupons(e){return Va(this,void 0,void 0,function*(){return this._gateway.handleCoupons(e)})}getTotalPrice(){return this._gateway.getTotalPrice()}_setExternalCheckout(e,t,i=!1,n){return Va(this,void 0,void 0,function*(){const o="/checkout.php",r=Object.assign({action:"set_external_checkout",provider:e},yield this._gateway.mapToExternalCheckoutData(t));if(i)return new Promise(e=>{this._formPoster.postForm(n?`${n}/checkout`:o,Object.assign(Object.assign({},r),{card_information:JSON.stringify(r.card_information)}),e)});yield this._requestSender.post(o,{headers:Object.assign({Accept:"text/html","Content-Type":"application/x-www-form-urlencoded"},Eo),body:r})})}_prefetchGooglePaymentData(){const e=this._getPaymentDataRequest();e.transactionInfo=this._gateway.getTransactionInfo(),this._getPaymentsClient().prefetchPaymentData(e)}_determineReadinessToPay(){return Va(this,void 0,void 0,function*(){try{const{result:e}=yield this._getPaymentsClient().isReadyToPay(this._getIsReadyToPayRequest());if(!1===e)throw new ja("Google Pay is not supported by the current device and browser, please try another payment method.")}catch(e){if(e instanceof ja)throw e;throw new ja}})}_buildButtonPayloads(){this._baseCardPaymentMethod={type:"CARD",parameters:this._gateway.getCardParameters()}}_buildWidgetPayloads(){return Va(this,void 0,void 0,function*(){const e=this._getBaseCardPaymentMethod();this._cardPaymentMethod=Object.assign(Object.assign({},e),{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:yield this._gateway.getPaymentGatewayParameters()}}),this._paymentDataRequest=Object.assign(Object.assign(Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[this._cardPaymentMethod],transactionInfo:this._gateway.getTransactionInfo(),merchantInfo:this._gateway.getMerchantInfo()}),yield this._gateway.getRequiredData()),{callbackIntents:this._gateway.getCallbackIntents(),offerInfo:this._gateway.getAppliedCoupons()}),this._isReadyToPayRequest=Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[e]})})}_getBaseCardPaymentMethod(){return this._getOrThrow(this._baseCardPaymentMethod)}_getPaymentDataRequest(){return this._getOrThrow(this._paymentDataRequest)}_getIsReadyToPayRequest(){return this._getOrThrow(this._isReadyToPayRequest)}_getPaymentsClient(){return this._getOrThrow(this._paymentsClient)}_getOrThrow(e){return to(e,()=>new io(Jn.PaymentNotInitialized))}}class Wa{constructor(e){this._scriptLoader=e,this._window=window}getGooglePaymentsClient(e=!1,t){return i=this,n=void 0,r=function*(){if(yield this._scriptLoader.loadScript("https://pay.google.com/gp/p/js/pay.js"),!this._window.google)throw new po;return void 0===this._paymentsClient&&(this._paymentsClient=new this._window.google.payments.api.PaymentsClient(Object.assign({environment:e?"TEST":"PRODUCTION"},null!=t?t:{}))),this._paymentsClient},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}function $a(){return new Wa(le())}const Ka=go(t=>{const n=e(),o=window,r=new Do(t),a=new Yo(new Zo(le(),o,r));return new Ha(t,new Ya($a(),new qa(t,a),n,i()))},[{id:"googlepaybraintree"}]);var Za=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Qa{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,i){return Za(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const n=this.getPayPalFastlaneSdkConfiguration(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypalFastlaneSdk)throw new po}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,i,n){return Za(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||n){const n=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i);yield this.loadPayPalSdk(n)}if(!this.window.paypalGooglePay)throw new po;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return Za(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new po}return this.window.paypalApms})}getPayPalMessages(e,t){return Za(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new po;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return Za(this,void 0,void 0,function*(){const i=this.transformConfig(e),n=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(i).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:n})})}getPayPalFastlaneSdkConfiguration(e,t,i){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:r},attributes:{"data-client-metadata-id":i.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":n}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i=!0){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=o,h=u||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":n,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=i,l=u,h=c.filter(e=>!u.includes(e));return{options:Object.assign({"client-id":o,"merchant-id":r,"enable-funding":l.length>0?l:void 0,"disable-funding":h.length>0?h:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:n},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}function Ja(e){if(!function(e){return!!e.initializationData&&"attributionId"in e.initializationData&&"isVenmoEnabled"in e.initializationData&&"isGooglePayEnabled"in e.initializationData&&"isPayPalCreditAvailable"in e.initializationData}(e))throw new Xn(Qn.MissingPaymentMethod)}var Xa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class es extends Ba{constructor(e,t){super("paypalsb",e),this.payPalCommerceSdk=t,this.service=e}initialize(e,t,i){const n=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,r,a,s,d;return Xa(this,void 0,void 0,function*(){const c=null!==(r=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==r?r:i;if(!c)throw new Xn(Qn.MissingPaymentMethod);yield n.initialize.call(this,e,t,c);const u=n.getPaymentMethod.call(this);if(!u.initializationData)throw new Xn(Qn.MissingPaymentMethod);Ja(u);const l=yield this.payPalCommerceSdk.getPayPalGooglePaySdk(u,c);this.googlepayConfig=yield l.Googlepay().config();const{allowedPaymentMethods:h}=this.googlepayConfig;this.setGatewayIdentifier(null===(d=null===(s=null===(a=h[0])||void 0===a?void 0:a.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===d?void 0:d.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Xa(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i})}}const ts=go(t=>new Ha(t,new Ya($a(),new es(t,new Qa(le())),e(),i())),[{id:"googlepaypaypalcommerce"}]);var is=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ns extends Ba{constructor(e,t){super("googlepay_bigcommerce_payments",e),this.payPalSdkHelper=t,this.service=e}initialize(e,t,i){const n=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,r,a,s,d;return is(this,void 0,void 0,function*(){const c=null!==(r=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==r?r:i;if(!c)throw new Xn(Qn.MissingPaymentMethod);yield n.initialize.call(this,e,t,c);const u=n.getPaymentMethod.call(this);if(!u.initializationData)throw new Xn(Qn.MissingPaymentMethod);Ja(u);const l=yield this.payPalSdkHelper.getPayPalGooglePaySdk(u,c);this.googlepayConfig=yield l.Googlepay().config();const{allowedPaymentMethods:h}=this.googlepayConfig;this.setGatewayIdentifier(null===(d=null===(s=null===(a=h[0])||void 0===a?void 0:a.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===d?void 0:d.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return is(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i})}}const os=go(t=>new Ha(t,new Ya($a(),new ns(t,new Er(le())),e(),i())),[{id:"googlepay_bigcommerce_payments"}]),rs=go(t=>{const n=e();return new Ha(t,new Ya($a(),new Ba("adyen",t),n,i()))},[{id:"googlepayadyenv2"}]),as=go(t=>{const n=e();return new Ha(t,new Ya($a(),new Ba("adyen",t),n,i()))},[{id:"googlepayadyenv3"}]);class ss extends Ba{constructor(e){super("authorizenet",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return function(e){if(!function(e){return"paymentGatewayId"in e}(e))throw new Xn(Qn.MissingPaymentMethod)}(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.paymentGatewayId}}}const ds=go(t=>new Ha(t,new Ya($a(),new ss(t),e(),i())),[{id:"googlepayauthorizenet"}]),cs=e=>"object"==typeof e&&null!==e&&"body"in e;function us(e){if(!function(e){return"checkoutcomkey"in e}(e))throw new Xn(Qn.MissingPaymentMethod)}var ls=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class hs extends Ba{constructor(e,t){super("checkoutltd",e),this._requestSender=t}processAdditionalAction(e){return new Promise((t,i)=>{if(cs(e)&&function(e){var t;if("object"!=typeof e||null===e)return!1;const i=e;return"string"==typeof(null===(t=i.three_ds_result)||void 0===t?void 0:t.acs_url)&&"string"==typeof i.three_ds_result.code}(e.body)&&"three_d_secure_required"===e.body.three_ds_result.code)return window.location.assign(e.body.three_ds_result.acs_url);i(e)})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return ls(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);let n;try{n=JSON.parse(i.nonce)}catch(e){throw new yo("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"protocolVersion"in e&&"signature"in e&&"signedMessage"in e}(e))throw new Xn(Qn.MissingPaymentToken)}(n),i.nonce=yield this._tokenize(n),i})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return us(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.checkoutcomkey}}_tokenize(e){return ls(this,void 0,void 0,function*(){const t=this.getPaymentMethod().config.testMode?"https://api.sandbox.checkout.com/tokens":"https://api.checkout.com/tokens",i=this.getGooglePayInitializationData();us(i);const{body:n}=yield this._requestSender.post(t,{credentials:!1,body:{type:"googlepay",token_data:e},headers:{Authorization:i.checkoutcomkey,"Content-Type":bo.Json,"X-XSRF-TOKEN":null}});return n.token})}}const ps=go(t=>{const n=e();return new Ha(t,new Ya($a(),new hs(t,n),n,i()))},[{id:"googlepaycheckoutcom"}]);class ms extends Ba{constructor(e){super("cybersource",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}const gs=go(t=>new Ha(t,new Ya($a(),new ms(t),e(),i())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]);class ys extends Ba{constructor(e){super("chase",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}const fs=go(t=>new Ha(t,new Ya($a(),new ys(t),e(),i())),[{id:"googlepayorbital"}]);var vs,Ss,Cs,Is,_s,ws,bs,Es,Ps,Os;!function(e){e.SHIPPING="shipping",e.BILLING="billing"}(vs||(vs={})),function(e){e.SPLIT="split",e.FULL="full",e.ORGANIZATION="organization"}(Ss||(Ss={})),function(e){e.SUCCESS="success",e.ERROR="error"}(Cs||(Cs={})),function(e){e.CreditCard="card",e.Link="link",e.EPS="eps",e.GRABPAY="grabpay",e.BANCONTACT="bancontact",e.IDEAL="ideal",e.ALIPAY="alipay",e.KLARNA="klarna",e.OCS="optimized_checkout"}(Is||(Is={})),function(e){e.NEVER="never",e.AUTO="auto",e.ALWAYS="always",e.PAYMENT="payment",e.IF_REQUIRED="if_required"}(_s||(_s={})),function(e){e.V3="v3",e.ACACIA="acacia",e.BASIL="basil",e.CLOVER="clover"}(ws||(ws={})),function(e){e.PAYMENT="payment",e.AUTHENTICATION="linkAuthentication",e.SHIPPING="address",e.EXPRESS_CHECKOUT="expressCheckout"}(bs||(bs={})),function(e){e.REQUIRES_PAYMENT_METHOD="requires_payment_method",e.REQUIRES_CONFIRMATION="requires_confirmation",e.REQUIRES_ACTION="requires_action",e.PROCESSING="processing",e.SUCCEEDED="succeeded",e.CANCELED="canceled"}(Es||(Es={})),function(e){e.CLICK="click",e.CHANGE="change",e.READY="ready",e.SHIPPING_ADDRESS_CHANGE="shippingaddresschange",e.SHIPPING_RATE_CHANGE="shippingratechange",e.CONFIRM="confirm",e.CANCEL="cancel",e.LOADER_START="loaderstart"}(Ps||(Ps={})),function(e){e.ON_SESSION="on_session",e.OFF_SESSION="off_session"}(Os||(Os={}));var As=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ts{constructor(e,t=window){this.scriptLoader=e,this.stripeWindow=t}getStripeClient(e,t,i,n,o){return As(this,void 0,void 0,function*(){if(this.stripeWindow.bcStripeClient)return this.stripeWindow.bcStripeClient;const r=yield this.load(i),{stripePublishableKey:a,stripeConnectedAccount:s}=e,d=r(a,Object.assign(Object.assign(Object.assign(Object.assign({},s?{stripeAccount:s}:{}),t?{locale:t}:{}),n?{betas:n}:{}),o?{apiVersion:o}:{}));return Object.assign(this.stripeWindow,{bcStripeClient:d}),d})}getElements(e,t){return As(this,void 0,void 0,function*(){let i=this.stripeWindow.bcStripeElements;return i?yield this.updateStripeElements(t):(i=e.elements(t),Object.assign(this.stripeWindow,{bcStripeElements:i})),i})}updateStripeElements(e){return As(this,void 0,void 0,function*(){const t=this.stripeWindow.bcStripeElements;t&&(t.update(e),yield t.fetchUpdates())})}getCheckoutSession(e,t){return As(this,void 0,void 0,function*(){let i=this.stripeWindow.bcStripeCheckoutSession;return i||(i=yield e.initCheckout(t),Object.assign(this.stripeWindow,{bcStripeCheckoutSession:i})),i})}load(e){return As(this,void 0,void 0,function*(){if(!this.stripeWindow.Stripe&&(yield this.scriptLoader.loadScript(this.getScriptUrl(e)),!this.stripeWindow.Stripe))throw new po;return this.stripeWindow.Stripe})}getScriptUrl(e){return e&&e!==ws.V3?`https://js.stripe.com/${e}/stripe.js`:"https://js.stripe.com/v3/"}}const ks=["payment_element_beta_2","alipay_pm_beta_1","link_default_integration_beta_1","shipping_address_element_beta_1","address_element_beta_1"];function Rs(e){if(!function(e){return"stripeConnectedAccount"in e&&"stripePublishableKey"in e&&"stripeVersion"in e}(e))throw new Xn(Qn.MissingPaymentMethod)}var Ds=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ms extends Ba{constructor(e,t){super("stripe",e),this.paymentIntegrationService=e,this.scriptLoader=t}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Ds(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);let n;try{n=JSON.parse(i.nonce)}catch(e){throw new yo("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"id"in e}(e))throw new Xn(Qn.MissingPaymentToken)}(n),i.nonce=n.id,i})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();Rs(e);const{stripeVersion:t,stripePublishableKey:i,stripeConnectedAccount:n}=e;return{gateway:this.getGatewayIdentifier(),"stripe:version":t,"stripe:publishableKey":`${i}/${n}`}}processAdditionalAction(e,t){var i;return Ds(this,void 0,void 0,function*(){if(!t)throw new Hr(["payment"]);if(!cs(e)||("object"!=typeof(n=e.body)||null===n||!("three_ds_result"in n)||!("errors"in n)))throw e;var n;if(z(e.body.errors,{code:"three_d_secure_required"})){const n=this.getGooglePayInitializationData();Rs(n),this.stripeUPEClient=yield this.loadStripeJs(n,t);const o=e.body.three_ds_result.token;let r,a=!1;try{r=yield this.stripeUPEClient.confirmCardPayment(o)}catch(e){try{r=yield this.stripeUPEClient.retrievePaymentIntent(o)}catch(e){a=!0}}if(null==r?void 0:r.error){if(this._throwDisplayableStripeError(r.error),this._isCancellationError(r.error))throw new Qo;throw new ja}if(!(null==r?void 0:r.paymentIntent)&&!a)throw new _e;return this.paymentIntegrationService.submitPayment({methodId:t,paymentData:{nonce:(null===(i=null==r?void 0:r.paymentIntent)||void 0===i?void 0:i.id)||o}})}throw e})}loadStripeJs(e,t){return Ds(this,void 0,void 0,function*(){if(this.stripeUPEClient)return this.stripeUPEClient;const i=this.paymentIntegrationService.getState().getCartLocale();return"googlepaystripeocs"===t&&e.useNewStripeJsVersion?this.scriptLoader.getStripeClient(e,i,ws.CLOVER):this.scriptLoader.getStripeClient(e,i,ws.V3,ks,"2020-03-02;alipay_beta=v1;link_beta=v1")})}_isCancellationError(e){var t,i;return e&&-1!==(null===(i=null===(t=e.payment_intent.last_payment_error)||void 0===t?void 0:t.message)||void 0===i?void 0:i.indexOf("canceled"))}_throwDisplayableStripeError(e){if(g(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}}const Ns=go(t=>new Ha(t,new Ya($a(),new Ms(t,new Ts(le())),e(),i())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]);class Ls extends Ba{constructor(e){super("worldpay",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}const zs=go(t=>new Ha(t,new Ya($a(),new Ls(t),e(),i())),[{id:"googlepayworldpayaccess"}]);function Us(){const{navigator:e}=window;let t;return t=e.language?e.language:e.userLanguage,{color_depth:window.screen.colorDepth||24,java_enabled:"function"==typeof e.javaEnabled&&e.javaEnabled(),language:t,screen_height:window.screen.height,screen_width:window.screen.width,time_zone_offset:(new Date).getTimezoneOffset().toString()}}var Fs=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Bs extends Ba{constructor(e,t){super("worldlinena",e),this.formPoster=t}extraPaymentData(){return Fs(this,void 0,void 0,function*(){return Promise.resolve({browser_info:Us()})})}processAdditionalAction(e){return Fs(this,void 0,void 0,function*(){if(!function(e){return cs(e)&&(t=e.body,I(t)&&"object"==typeof t&&"errors"in t&&"three_ds_result"in t&&y(t.errors)&&z(t.errors,{code:"three_d_secure_required"}));var t}(e))throw e;const{three_ds_result:t}=e.body,{acs_url:i,payer_auth_request:n,merchant_data:o}=t||{};if(!i||!n||!o)throw new Hr(["formUrl","threeDSSessionData","creq"]);return new Promise(e=>{this.formPoster.postForm(i,{threeDSSessionData:n,creq:o},e,"_top")})})}}const xs=go(t=>new Ha(t,new Ya($a(),new Bs(t,i()),e(),i())),[{id:"googlepaytdonlinemart"}]);var qs,js,Gs,Hs,Vs,Ys,Ws;!function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(qs||(qs={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(js||(js={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Gs||(Gs={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(Hs||(Hs={})),function(e){e.pill="pill",e.rect="rect"}(Vs||(Vs={})),(Ys||(Ys={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Ws||(Ws={}));var $s=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ks{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=i,this.paypalCommerceScriptLoader=n}loadPayPalSdk(e,t,i,n){return $s(this,void 0,void 0,function*(){const o=this.paymentIntegrationService.getState(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,r,i,n),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new po;return this.paypalSdk}createBuyNowCartOrThrow(e){return $s(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}})}createOrder(e,t){return $s(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:i},t));return n})}createOrderCardFields(e,t){return $s(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n,setupToken:o}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:i},t));return Object.assign({orderId:n},o?{setupToken:o}:{})})}updateOrder(){return $s(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),i=e.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:i.availableShippingOptions,cartId:t.id,selectedShippingOption:i.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return $s(this,void 0,void 0,function*(){try{const{status:i}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return i}catch(e){throw new _e}})}tokenizePayment(e,t){const i=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xn(Qn.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===ar.BuyNow&&{cart_id:i.id}))}submitPayment(e,t,i){return $s(this,void 0,void 0,function*(){const n={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:n},i?{gatewayId:i}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],i=t.availableShippingOptions||[],n=i.find(e=>e.isRecommended),o=(e?i.find(t=>t.id===e):i.find(e=>{var i;return e.id===(null===(i=t.selectedShippingOption)||void 0===i?void 0:i.id)}))||n||i[0];if(!o)throw new Error("Your order can't be shipped to this address");return o}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,i;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(i=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===i?void 0:i.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:i}=e,{address:n,name:{full_name:o}}=i[0].shipping,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.join(" "),email:t.email_address,address1:n.address_line_1,address2:n.address_line_2,city:n.admin_area_2,countryCode:n.country_code,postalCode:n.postal_code,stateOrProvinceCode:n.admin_area_1})}getValidButtonStyle(e){const{color:t,height:i,label:n,shape:o}=e||{},r={color:t&&Hs[t]?t:void 0,height:this.getValidHeight(i),label:n&&Gs[n]?n:void 0,shape:o&&Vs[o]?o:void 0};return R(r,C)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var Zs=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Qs{constructor(e){this.requestSender=e}createOrder(e,t){return Zs(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e){return Zs(this,void 0,void 0,function*(){const t=e,i=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:i,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return Zs(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var Js=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Xs{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return Js(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,i);return this.loadPayPalSDK(o,n)})}loadPayPalSDK(e,t=!1){return Js(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),i=this.transformConfig(e.attributes),n=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(n,{async:!0,attributes:i})}if(!this.window.paypal)throw new po;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,i=!0){const{id:n,clientToken:o,initializationData:r}=e;if(!(null==r?void 0:r.clientId))throw new Xn(Qn.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:u,isVenmoEnabled:l,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:p,isDeveloperModeApplicable:m,availableAlternativePaymentMethods:g=[],enabledAlternativePaymentMethods:y=[],isGooglePayEnabled:f}=r,v=h||i,S="paypalcommercecreditcards"===n,C=S?["card"]:[],I=p?["credit","paylater"]:[],_=l?["venmo"]:[],w=f?["googlepay"]:[],b=i?["card-fields"]:[],E=[...S?[]:["card"],...p?[]:["credit","paylater"],...l?[]:["venmo"],...g.filter(e=>!y.includes(e))],P=[...C,...I,..._,...y];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":P.length>0?P:void 0,"disable-funding":E.length>0?E:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...w,...b],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":o}}}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}const ed=t=>{const{getHost:n}=t.getState();return new Ks(i(),t,new Qs(e({host:n()})),new Xs(le()))};var td=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class id{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){var t;return td(this,void 0,void 0,function*(){const{paypalcommerce:i,containerId:n,methodId:o}=e,r=Boolean(null==i?void 0:i.buyNowInitializeOptions);if(!o)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(r&&!i.currencyCode)throw new yo('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(r&&"function"!=typeof(null===(t=i.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');r||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=r?i.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(o,a,!1),this.renderButton(n,o,i,r)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i,n){var o,r;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:c}=i,u=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:h,isAppSwitchEnabled:p}=l.initializationData||{},m=Object.assign(Object.assign({},!n&&this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommerce"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)}),g={onClick:()=>this.handleClick(a),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},y=Object.assign(Object.assign({},!p&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,d)}),f=Object.assign(Object.assign(Object.assign({fundingSource:u.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(s)},m),a&&g),h&&y),v=u.Buttons(f);v.isEligible()?(null===(o=v.hasReturned)||void 0===o?void 0:o.call(v))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(r=v.resume)||void 0===r||r.call(v):v.render(`#${e}`):c&&"function"==typeof c?c():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return td(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return td(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return td(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return td(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}isPaypalCommerceAppSwitchEnabled(e){var t;return(null===(t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.isAppSwitchEnabled)||!1}}const nd=go(e=>new id(e,ed(e)),[{id:"paypalcommerce"}]),od=function({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t};var rd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ad{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i}initialize(e){var t;return rd(this,void 0,void 0,function*(){const{paypalcommercecredit:i,containerId:n,methodId:o}=e,{buyNowInitializeOptions:r,currencyCode:a,messagingContainerId:s}=i||{},d=!!r;if(!o)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(d&&!a)throw new yo('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(d&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommercecredit.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');d||(yield this.paymentIntegrationService.loadDefaultCheckout());const c=this.paymentIntegrationService.getState(),u=d?a:c.getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(o,u,!1),this.renderButton(n,o,i);const l=c.getStoreConfigOrThrow().checkoutSettings.features;if(null!==(t=l["PAYPAL-5557.Hide_ppc_banner_implementation"])&&void 0!==t&&t)return;const h=s&&document.getElementById(s);if(u&&h){const e=c.getPaymentMethodOrThrow(o),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},i=t&&t.find(({id:e})=>"cart"===e);if(!(null==i?void 0:i.status))return;h.removeAttribute("data-pp-style-logo-type"),h.removeAttribute("data-pp-style-logo-position"),h.removeAttribute("data-pp-style-text-color"),h.removeAttribute("data-pp-style-text-size");const n=yield this.paypalCommerceSdk.getPayPalMessages(e,u);this.renderMessages(n,s,i)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onComplete:r,onEligibilityFailure:a}=i,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:c,isAppSwitchEnabled:u}=d.initializationData||{},l={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},h={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},p=Object.assign(Object.assign({},!u&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,r)}),m=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let g=!1;m.forEach(t=>{if(!g){const i=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o)},l),n&&h),c&&p),r=s.Buttons(i);r.isEligible()?(r.render(`#${e}`),g=!0):a&&"function"==typeof a&&a()}}),g||this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return rd(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return rd(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return rd(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return rd(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}renderMessages(e,t,i){const n={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:od(i)};e.Messages(n).render(`#${t}`)}}const sd=go(e=>new ad(e,ed(e),new Qa(ue())),[{id:"paypalcommercecredit"}]);var dd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class cd{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return dd(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r}=t||{},a=!!o;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(a&&!r)throw new yo('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommercevenmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?r:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(n,s,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onEligibilityFailure:r}=i,a=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(o)},d),n&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):r&&"function"==typeof r?r():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===Hs.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return dd(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ud=go(e=>new cd(e,ed(e)),[{id:"paypalcommercevenmo"}]);var ld,hd,pd,md,gd,yd,fd,vd,Sd,Cd,Id=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class _d{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return Id(this,void 0,void 0,function*(){if(!this.window.paypal||n){const n=this.getPayPalSdkScriptConfigOrThrow(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypal)throw new po}return this.window.paypal})}getPayPalFastlaneSdk(e,t,i){return Id(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const n=this.getPayPalFastlaneSdkConfiguration(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypalFastlaneSdk)throw new po}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,i,n){return Id(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||n){const n=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i);yield this.loadPayPalSdk(n)}if(!this.window.paypalGooglePay)throw new po;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return Id(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new po}return this.window.paypalApms})}getPayPalMessages(e,t){return Id(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new po;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return Id(this,void 0,void 0,function*(){const i=this.transformConfig(e),n=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(i).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:n})})}getPayPalSdkScriptConfigOrThrow(e,t,i=!0){const{id:n,clientToken:o,initializationData:r}=e;if(!r||!r.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:u,isVenmoEnabled:l,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:p,isDeveloperModeApplicable:m,availableAlternativePaymentMethods:g=[],enabledAlternativePaymentMethods:y=[],isGooglePayEnabled:f}=r,v=h||i,S="paypalcommercecreditcards"===n||"bigcommerce_payments_creditcards"===n,C=S?["card"]:[],I=p?["credit","paylater"]:[],_=l?["venmo"]:[],w=f?["googlepay"]:[],b=i?["card-fields"]:[],E=[...S?[]:["card"],...p?[]:["credit","paylater"],...l?[]:["venmo"],...g.filter(e=>!y.includes(e))],P=[...C,...I,..._,...y];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":P.length>0?P:void 0,"disable-funding":E.length>0?E:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...w,...b],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":o}}}getPayPalFastlaneSdkConfiguration(e,t,i){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:r},attributes:{"data-client-metadata-id":i.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":n}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i=!0){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=o,h=u||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":n,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=i,l=u,h=c.filter(e=>!u.includes(e));return{options:Object.assign({"client-id":o,"merchant-id":r,"enable-funding":l.length>0?l:void 0,"disable-funding":h.length>0?h:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:n},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(ld||(ld={})),function(e){e.Always="SCA_ALWAYS"}(hd||(hd={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(pd||(pd={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(md||(md={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(gd||(gd={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(yd||(yd={})),function(e){e.pill="pill",e.rect="rect"}(fd||(fd={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(vd||(vd={})),(Sd||(Sd={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Cd||(Cd={}));var wd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class bd{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=i,this.paypalSdkLoader=n}loadPayPalSdk(e,t,i,n){return wd(this,void 0,void 0,function*(){const o=this.paymentIntegrationService.getState(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(a,r,i,n),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new po;return this.paypalSdk}createBuyNowCartOrThrow(e){return wd(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}})}createOrder(e,t){return wd(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:i},t));return n})}createOrderCardFields(e,t){return wd(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n,setupToken:o}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:i},t));return Object.assign({orderId:n},o?{setupToken:o}:{})})}updateOrder(e){return wd(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),i=t.getCartOrThrow(),n=t.getConsignmentsOrThrow()[0];try{yield this.paypalRequestSender.updateOrder(e,{availableShippingOptions:n.availableShippingOptions,cartId:i.id,selectedShippingOption:n.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return wd(this,void 0,void 0,function*(){try{const{status:i}=yield this.paypalRequestSender.getOrderStatus(e,t);return i}catch(e){throw new _e}})}tokenizePayment(e,t){const i=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xn(Qn.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===ar.BuyNow&&{cart_id:i.id}))}submitPayment(e,t,i){return wd(this,void 0,void 0,function*(){const n={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:n},i?{gatewayId:i}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],i=t.availableShippingOptions||[],n=i.find(e=>e.isRecommended),o=(e?i.find(t=>t.id===e):i.find(e=>{if(t.selectedShippingOption){const i=t.selectedShippingOption.id;return e.id===i}return!1}))||n||i[0];if(!o)throw new Error("Your order can't be shipped to this address");return o}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,i;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(i=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===i?void 0:i.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:i}=e,{address:n,name:{full_name:o}}=i[0].shipping,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.join(" "),email:t.email_address,address1:n.address_line_1,address2:n.address_line_2,city:n.admin_area_2,countryCode:n.country_code,postalCode:n.postal_code,stateOrProvinceCode:n.admin_area_1})}getValidButtonStyle(e={}){const{color:t,height:i,label:n,shape:o}=e,r={color:t&&yd[t]?t:void 0,height:this.getValidHeight(i),label:n&&gd[n]?n:void 0,shape:o&&fd[o]?o:void 0};return R(r,C)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var Ed=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Pd{constructor(e){this.requestSender=e}createOrder(e,t){return Ed(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e,t){return Ed(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.put(i,{headers:o,body:n})).body})}getOrderStatus(e,t){return Ed(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var Od=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ad{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}initialize(e){return Od(this,void 0,void 0,function*(){const{paypalcommercealternativemethods:t,containerId:i,methodId:n}=e,{apm:o,buyNowInitializeOptions:r,currencyCode:a}=t||{},s=!!r;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');if(!o)throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods.apm" argument is not provided.');if(s&&!a)throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');s||(yield this.paymentIntegrationService.loadDefaultCheckout());const d=s?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(n,d,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{apm:n,buyNowInitializeOptions:o,style:r,onEligibilityFailure:a}=i,s=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(n))throw new yo('Unable to initialize PayPal button because "options.paypalcommercealternativemethods.apm" argument is not valid funding source.');const d={createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercealternativemethod"),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:n,style:this.paypalIntegrationService.getValidButtonStyle(r)},d),o&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.paypalIntegrationService.removeElement(e)}handleClick(e){return Od(this,void 0,void 0,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Td=go(t=>new Ad(t,(t=>{const{getHost:n}=t.getState();return new bd(i(),t,new Pd(e({host:n()})),new _d(ue()))})(t)),[{id:"paypalcommercealternativemethods"}]);var kd,Rd,Dd,Md,Nd,Ld;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(kd||(kd={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Rd||(Rd={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black"}(Dd||(Dd={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Md||(Md={})),function(e){e.PILL="pill",e.RECT="rect"}(Nd||(Nd={})),function(e){e.ACKNOWLEDGE="ACKNOWLEDGE",e.FINALIZE="FINALIZE",e.INITIALIZE="INITIALIZE"}(Ld||(Ld={}));var zd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ud{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalExpressScriptLoader=t,this.formPoster=i}initialize(e){return zd(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!e.paypal)throw new yo;if(!t.config.merchantId)throw new Xn(Qn.MissingPaymentMethod);const i=yield this.paypalExpressScriptLoader.loadPaypalSDK(t.config.merchantId);this.renderButton(e,i)})}deinitialize(){return Promise.resolve()}renderButton(e,t){const{containerId:i,methodId:n,paypal:o}=e,{allowCredit:r,clientId:a,onPaymentError:s,shouldProcessPayment:d,style:c}=o,u=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!u.config.merchantId)throw new Xn(Qn.MissingPaymentMethod);const l=u.config.merchantId,h=u.config.testMode?"sandbox":"production",p={[h]:a},m=t.FUNDING.CREDIT||"credit",g=r?[m]:[],y=r?[]:[m];return t.Button.render({env:h,client:p,commit:d,funding:{allowed:g,disallowed:y},style:this.getStyle(c),payment:(e,t)=>this.setupPayment(l,t,s),onAuthorize:(e,t)=>this.tokenizePayment(e,n,t,d)},i)}getStyle(e){const{color:t,fundingicons:i,label:n,layout:o,shape:r,size:a,tagline:s}=e||{};return{color:t,fundingicons:i,label:n,layout:o,shape:r||Nd.RECT,size:"small"===a?Rd.RESPONSIVE:a,tagline:s}}setupPayment(e,t,i){return zd(this,void 0,void 0,function*(){if(!t)throw new io(Jn.CheckoutButtonNotInitialized);try{const i=yield this.paymentIntegrationService.loadDefaultCheckout(),{id:n}=i.getCartOrThrow(),o=i.getHost()||"";return(yield t.request.post(`${o}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:n},{headers:Object.assign({"X-API-INTERNAL":_o},Eo)})).id}catch(e){throw i&&e instanceof Ce&&i(e),e}})}tokenizePayment(e,t,i,n){return zd(this,void 0,void 0,function*(){if(!i)throw new io(Jn.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new Xn(Qn.MissingPayment);const o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),r=yield i.payment.get(e.paymentID);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:o.id,action:n?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(r.payer.payer_info)})})}}class Fd{constructor(e){this.scriptLoader=e,this.window=window}loadPaypalSDK(e=""){return t=this,i=void 0,o=function*(){const t=Object.assign({async:!0,attributes:{"data-merchant-id":e}},e&&{attributes:{"data-merchant-id":e}});if(yield this.scriptLoader.loadScript("//www.paypalobjects.com/api/checkout.min.js",t),!this.window.paypal)throw new po;return this.window.paypal},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}}const Bd=go(e=>new Ud(e,new Fd(le()),i()),[{id:"paypalexpress"}]);var xd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class qd{constructor(e,t){this.paymentIntegrationService=e,this.scriptLoader=t,this.isMounted=!1}deinitialize(){var e;null===(e=this.checkoutEventsUnsubscribe)||void 0===e||e.call(this),this.isMounted=!1}initCheckoutEventsSubscription(e,t,i,n){this.checkoutEventsUnsubscribe=this.paymentIntegrationService.subscribe(()=>xd(this,void 0,void 0,function*(){var o;const r=null==n?void 0:n.getElement(bs.PAYMENT);if(r){try{yield this.updateStripePaymentIntent(e,t)}catch(e){return this.isMounted&&(r.unmount(),this.isMounted=!1),void(e instanceof Error&&(null===(o=i.onError)||void 0===o||o.call(i,e)))}this.isMounted||(yield null==n?void 0:n.fetchUpdates(),this.mountElement(r,i.containerId))}}),e=>{var t;return null===(t=e.getCheckout())||void 0===t?void 0:t.outstandingBalance},e=>{var t;return null===(t=e.getCheckout())||void 0===t?void 0:t.coupons})}mountElement(e,t){document.getElementById(t)&&(e.mount(`#${t}`),this.isMounted=!0)}mapAppearanceVariables(e){return{colorPrimary:e.fieldInnerShadow,colorBackground:e.fieldBackground,colorText:e.labelText,colorDanger:e.fieldErrorText,colorTextSecondary:e.labelText,colorTextPlaceholder:e.fieldPlaceholderText,colorIcon:e.fieldPlaceholderText}}mapInputAppearanceRules(e){return{borderColor:e.fieldBorder,color:e.fieldText,boxShadow:e.fieldInnerShadow}}throwStripeError(e){if("object"==typeof(t=e)&&null!==t&&"type"in t&&(this.throwDisplayableStripeError(e),this.isCancellationError(e)))throw new Qo;var t;throw new ja}throwDisplayableStripeError(e){if(g(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}isCancellationError(e){var t;const i=null===(t=null==e?void 0:e.payment_intent.last_payment_error)||void 0===t?void 0:t.message;return!!i&&-1!==i.indexOf("canceled")}throwPaymentConfirmationProceedMessage(){throw new ja("We've received your order and are processing your payment. Once the payment is verified, your order will be completed. We will send you an email when it's completed. Please note, this process may take a few minutes depending on the processing times of your chosen method.")}isPaymentCompleted(e,t){return xd(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState(),n=i.getPaymentMethodOrThrow(e),{features:o}=i.getStoreConfigOrThrow().checkoutSettings;if(!n.clientToken||!t||!o["PI-626.Block_unnecessary_payment_confirmation_for_StripeUPE"])return!1;const{paymentIntent:r}=yield t.retrievePaymentIntent(n.clientToken);return(null==r?void 0:r.status)===Es.SUCCEEDED})}mapStripePaymentData(e,t,i=!1){const n=this.paymentIntegrationService.getState().getBillingAddress(),{firstName:o="",lastName:r="",email:a=""}=n||{},s=this._mapStripeAddress(n);if(!e)throw new io(Jn.PaymentNotInitialized);if(!(a&&s&&s.city&&s.country&&o&&r))throw new Xn(Qn.MissingBillingAddress);return{elements:e,redirect:_s.IF_REQUIRED,confirmParams:Object.assign({payment_method_data:Object.assign(Object.assign({},i?{allow_redisplay:"always"}:{}),{billing_details:{email:a,address:s,name:`${o} ${r}`}})},t&&{return_url:t})}}isAdditionalActionError(e){return z(e,{code:"additional_action_required"})}isRedirectAction(e){const{type:t,data:{redirect_url:i}}=e;return"redirect_to_url"===t&&!!i}isOnPageAdditionalAction(e){const{type:t,data:{token:i}}=e;return"additional_action_requires_payment_method"===t&&!!i}updateStripePaymentIntent(e,t){return xd(this,void 0,void 0,function*(){const i=yield this.paymentIntegrationService.loadPaymentMethod(e,{params:{method:t}}),{clientToken:n}=i.getPaymentMethodOrThrow(t);n&&this.scriptLoader.updateStripeElements({clientSecret:n})})}getStripeJsVersion(e){return e.useNewStripeJsVersion?ws.CLOVER:ws.V3}_mapStripeAddress(e){if(e){const{city:t,address1:i,address2:n,countryCode:o,postalCode:r,stateOrProvinceCode:a}=e;return Object.assign({city:t,country:o,postal_code:r,line1:i,line2:n},a?{state:a}:{})}throw new Xn(Qn.MissingBillingAddress)}}const jd={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Gd={position:"fixed","background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},Hd="embedded-checkout-loading-indicator-rotation";class Vd{constructor(e){this.styles=Object.assign(Object.assign({},jd),e&&e.styles),this.containerStyles=Object.assign({},e&&e.containerStyles),this.defineAnimation(),this.container=this.buildContainer(),this.indicator=this.buildIndicator(),this.container.appendChild(this.indicator)}show(e){if(e){const t=document.getElementById(e);if(!t)throw new Error("Unable to attach the loading indicator because the parent ID is not valid.");t.appendChild(this.container)}this.container.style.visibility="visible",this.container.style.opacity="1"}hide(){const e=()=>{this.container.style.visibility="hidden",this.container.removeEventListener("transitionend",e)};this.container.addEventListener("transitionend",e),this.container.style.opacity="0"}buildContainer(){const e=document.createElement("div");return e.style.display="block",e.style.bottom="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.position="absolute",e.style.right="0",e.style.top="0",e.style.transition="all 250ms ease-out",e.style.opacity="0",this.setStyleAttribute(e,this.containerStyles),e}buildIndicator(){const e=document.createElement("div");return e.style.display="block",e.style.width=`${this.styles.size}px`,e.style.height=`${this.styles.size}px`,e.style.borderRadius=`${this.styles.size}px`,e.style.border="solid 1px",e.style.borderColor=`${this.styles.backgroundColor} ${this.styles.backgroundColor} ${this.styles.color} ${this.styles.color}`,e.style.margin="0 auto",e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top="50%",e.style.transform="translateY(-50%) rotate(0deg)",e.style.transformStyle="preserve-3d",e.style.animation=`${Hd} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(i=>{e.style.setProperty(i,t[i])})}defineAnimation(){var e;if(document.getElementById(Hd))return;const t=document.createElement("style");t.id=Hd,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${Hd} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}class Yd{constructor(e){this._decimalPlaces=e}toInteger(e){return Math.round(e*Math.pow(10,this._decimalPlaces))}}const Wd=["AC","AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CV","CW","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MK","ML","MM","MN","MO","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SZ","TA","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","US","UY","UZ","VA","VC","VE","VG","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW","ZZ"];var $d=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Kd{constructor(e,t,i,n){this.paymentIntegrationService=e,this.scriptLoader=t,this.stripeIntegrationService=i,this.loadingIndicator=n}initialize(e){return $d(this,void 0,void 0,function*(){const{stripeocs:t,containerId:i}=e||{};if(!t||!i)throw new io(Jn.PaymentNotInitialized);const{methodId:n,gatewayId:o}=t;if(!n||!o)throw new Xn(Qn.MissingPaymentMethod);const r=yield this.paymentIntegrationService.loadPaymentMethod(o,{params:{method:n}}),a=r.getPaymentMethodOrThrow(n,o),{loadingContainerId:s,buttonHeight:d,onComplete:c}=t;if(this._loadingIndicatorContainer=s,this._onComplete=c,!function(e){return"object"==typeof e&&null!==e&&"initializationData"in e&&void 0!==e.initializationData&&null!==e.initializationData&&"object"==typeof e.initializationData&&"stripePublishableKey"in e.initializationData&&"stripeConnectedAccount"in e.initializationData&&"shopperLanguage"in e.initializationData&&void 0!==e.initializationData.stripePublishableKey&&void 0!==e.initializationData.stripeConnectedAccount&&void 0!==e.initializationData.shopperLanguage}(a))throw new Xn(Qn.MissingPaymentMethod);const{initializationData:u}=a,{captureMethod:l}=u,h=this.stripeIntegrationService.getStripeJsVersion(u);return this._captureMethod=l,this._stripeClient=yield this.scriptLoader.getStripeClient(u,r.getCartLocale(),h),yield this.paymentIntegrationService.loadDefaultCheckout(),yield this._mountExpressCheckoutElement(n,i,this._stripeClient,d),Promise.resolve()})}signIn(){return Promise.resolve()}signOut(){return Promise.resolve()}executePaymentMethodCheckout(){return Promise.resolve()}deinitialize(){return Promise.resolve()}_mountExpressCheckoutElement(e,t,i,n=40){return $d(this,void 0,void 0,function*(){const o=this._shouldRequireShippingAddress(),r=Object.assign(Object.assign(Object.assign({shippingAddressRequired:o},o?{allowedShippingCountries:yield this._getAvailableCountries()}:{}),o?{shippingRates:[{id:"_",amount:0,displayName:"Pending rates"}]}:{}),{billingAddressRequired:!0,emailRequired:!0,phoneNumberRequired:!0,paymentMethods:{link:_s.AUTO,applePay:_s.NEVER,googlePay:_s.NEVER,amazonPay:_s.NEVER,paypal:_s.NEVER,klarna:_s.NEVER},buttonHeight:n}),{cartAmount:a=1}=this.paymentIntegrationService.getState().getCart()||{},s=Object.assign({mode:"payment",amount:this._toCents(a),currency:this._getCurrency()},this._captureMethod?{captureMethod:this._captureMethod}:{});this._stripeElements=i.elements(s),this._linkV2Element=this._stripeElements.create(bs.EXPRESS_CHECKOUT,r),this._linkV2Element.mount(`#${t}`),this._initializeEvents(this._linkV2Element,e)})}_initializeEvents(e,t){this._shouldRequireShippingAddress()&&(e.on(Ps.SHIPPING_ADDRESS_CHANGE,e=>$d(this,void 0,void 0,function*(){return this._onShippingAddressChange(e)})),e.on(Ps.SHIPPING_RATE_CHANGE,e=>$d(this,void 0,void 0,function*(){return this._onShippingRateChange(e)}))),e.on(Ps.CONFIRM,e=>$d(this,void 0,void 0,function*(){return this._onConfirm(e,t)})),e.on(Ps.CANCEL,this._onCancel)}_onShippingAddressChange(e){return $d(this,void 0,void 0,function*(){if(!("address"in e))return;const t=e.address,i={firstName:"",lastName:"",phone:"",company:"",address1:"",address2:"",city:(null==t?void 0:t.city)||"",countryCode:(null==t?void 0:t.country)||"",postalCode:(null==t?void 0:t.postal_code)||"",stateOrProvince:(null==t?void 0:t.state)||"",stateOrProvinceCode:(null==t?void 0:t.state)||"",customFields:[]};yield this.paymentIntegrationService.updateShippingAddress(i);const n=yield this._getAvailableShippingOptions();yield this._updateDisplayedPrice(),(null==n?void 0:n.length)?e.resolve({shippingRates:n}):e.reject()})}_onCancel(){throw new Qo}_onShippingRateChange(e){return $d(this,void 0,void 0,function*(){if("shippingRate"in e){const{shippingRate:t}=e;yield this._handleShippingOptionChange(null==t?void 0:t.id),yield this._updateDisplayedPrice(),e.resolve({})}})}_onConfirm(e,t){return $d(this,void 0,void 0,function*(){if("billingDetails"in e&&"shippingAddress"in e&&this._stripeClient&&this._stripeElements){yield this._updateShippingAndBillingAddress(e),yield this.paymentIntegrationService.submitOrder();const i=this._getPaymentPayload(t);try{yield this.paymentIntegrationService.submitPayment(i)}catch(e){yield this._processAdditionalAction(e,t)}}return Promise.resolve()})}_updateShippingAndBillingAddress(e){var t,i,n,o,r,a,s,d;return $d(this,void 0,void 0,function*(){const c=this._shouldRequireShippingAddress(),u=(null===(i=null===(t=e.shippingAddress)||void 0===t?void 0:t.name)||void 0===i?void 0:i.split(" ")[0])||(null===(o=null===(n=e.billingDetails)||void 0===n?void 0:n.name)||void 0===o?void 0:o.split(" ")[0])||"",l=(null===(a=null===(r=e.shippingAddress)||void 0===r?void 0:r.name)||void 0===a?void 0:a.split(" ")[1])||(null===(d=null===(s=e.billingDetails)||void 0===s?void 0:s.name)||void 0===d?void 0:d.split(" ")[1])||"";if(c){const t=this._mapShippingAddress(e.shippingAddress,e.billingDetails,u,l);yield this.paymentIntegrationService.updateShippingAddress(t)}const h=this._mapBillingAddress(e.shippingAddress,e.billingDetails,u,l);yield this.paymentIntegrationService.updateBillingAddress(h)})}_mapShippingAddress(e,t,i,n){var o,r,a,s,d,c,u;return{firstName:i,lastName:n,phone:(null==t?void 0:t.phone)||"",company:"",address1:(null===(o=null==e?void 0:e.address)||void 0===o?void 0:o.line1)||"",address2:(null===(r=null==e?void 0:e.address)||void 0===r?void 0:r.line2)||"",city:(null===(a=null==e?void 0:e.address)||void 0===a?void 0:a.city)||"",countryCode:(null===(s=null==e?void 0:e.address)||void 0===s?void 0:s.country)||"",postalCode:(null===(d=null==e?void 0:e.address)||void 0===d?void 0:d.postal_code)||"",stateOrProvince:(null===(c=null==e?void 0:e.address)||void 0===c?void 0:c.state)||"",stateOrProvinceCode:(null===(u=null==e?void 0:e.address)||void 0===u?void 0:u.state)||"",customFields:[]}}_mapBillingAddress(e,t,i,n){var o,r,a,s,d,c;return{email:(null==t?void 0:t.email)||"",firstName:i,lastName:n,phone:(null==t?void 0:t.phone)||"",company:"",address1:(null===(o=null==t?void 0:t.address)||void 0===o?void 0:o.line1)||"",address2:"",city:(null===(r=null==t?void 0:t.address)||void 0===r?void 0:r.city)||"",countryCode:(null===(a=null==t?void 0:t.address)||void 0===a?void 0:a.country)||"",postalCode:(null===(s=null==t?void 0:t.address)||void 0===s?void 0:s.postal_code)||"",stateOrProvince:(null===(d=null==t?void 0:t.address)||void 0===d?void 0:d.state)||"",stateOrProvinceCode:(null===(c=null==e?void 0:e.address)||void 0===c?void 0:c.state)||"",customFields:[]}}_processAdditionalAction(e,t){return $d(this,void 0,void 0,function*(){if(!cs(e)||!this.stripeIntegrationService.isAdditionalActionError(e.body.errors))throw e;if(!this._stripeClient||!this._stripeElements)throw new io(Jn.PaymentNotInitialized);const{data:i}=e.body.additional_action_required,{token:n}=i,{paymentIntent:o}=yield this._confirmStripePaymentOrThrow(i,t),r=this._getPaymentPayload(t,(null==o?void 0:o.id)||n);try{this._toggleLoadingIndicator(!0),yield this.paymentIntegrationService.submitPayment(r),yield this._completeCheckoutFlow()}catch(e){this.stripeIntegrationService.throwPaymentConfirmationProceedMessage()}finally{this._toggleLoadingIndicator(!1)}})}_confirmStripePaymentOrThrow(e,t){var i,n,o;return $d(this,void 0,void 0,function*(){const{token:r,redirect_url:a}=e,s=this.stripeIntegrationService.mapStripePaymentData(this._stripeElements,a);let d;try{const e=(yield this.stripeIntegrationService.isPaymentCompleted(t,this._stripeClient))?yield null===(o=this._stripeClient)||void 0===o?void 0:o.retrievePaymentIntent(r||""):yield null===(i=this._stripeClient)||void 0===i?void 0:i.confirmPayment({elements:s.elements,clientSecret:r,redirect:_s.IF_REQUIRED,confirmParams:{return_url:null===(n=s.confirmParams)||void 0===n?void 0:n.return_url}});if(d=null==e?void 0:e.error,d||!(null==e?void 0:e.paymentIntent))throw new ja;return e}catch(e){return this.stripeIntegrationService.throwStripeError(d)}})}_completeCheckoutFlow(){return $d(this,void 0,void 0,function*(){return"function"==typeof this._onComplete?this._onComplete():(window.location.replace("/checkout/order-confirmation"),Promise.resolve())})}_getPaymentPayload(e,t){var i;const n=(null===(i=this.paymentIntegrationService.getState().getCart())||void 0===i?void 0:i.id)||"";return{methodId:e,paymentData:{formattedPayload:Object.assign(Object.assign({cart_id:n},t?{credit_card_token:{token:t}}:{}),{confirm:!1,method:Is.Link})}}}_shouldRequireShippingAddress(){const{getCart:e}=this.paymentIntegrationService.getState(),{lineItems:t}=e()||{};return!!(null==t?void 0:t.physicalItems.length)}_updateDisplayedPrice(){return $d(this,void 0,void 0,function*(){this._stripeElements&&this._stripeElements.update({currency:this._getCurrency(),mode:"payment",amount:yield this._getTotalPrice()})})}_getCurrency(){var e;if(!this._currencyCode){const t=null===(e=this.paymentIntegrationService.getState().getCart())||void 0===e?void 0:e.currency;t&&(this._currencyCode=t.code.toLowerCase())}return this._currencyCode}_getTotalPrice(){var e;return $d(this,void 0,void 0,function*(){yield this.paymentIntegrationService.loadCheckout();const{getCheckoutOrThrow:t,getCart:i}=this.paymentIntegrationService.getState(),{decimalPlaces:n}=(null===(e=i())||void 0===e?void 0:e.currency)||{},o=L(t().outstandingBalance,n).toFixed(n);return this._toCents(+o)})}_getAvailableCountries(){var e;return $d(this,void 0,void 0,function*(){const t=yield this.paymentIntegrationService.loadShippingCountries();return((null===(e=t.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code))||[]).filter(e=>Wd.includes(e))})}_getAvailableShippingOptions(){var e,t;return $d(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getConsignments();if(!(null==i?void 0:i[0]))return;const n=i[0],o=(n.availableShippingOptions||[]).map(this._getStripeShippingOption.bind(this)),r=null===(e=n.selectedShippingOption)||void 0===e?void 0:e.id;return r?o.sort(e=>e.id===r?-1:0):yield this._handleShippingOptionChange(null===(t=o[0])||void 0===t?void 0:t.id),o})}_getStripeShippingOption({id:e,cost:t,description:i}){return{id:e,displayName:i,amount:this._toCents(t)}}_handleShippingOptionChange(e){return $d(this,void 0,void 0,function*(){if(e&&"shipping_option_unselected"!==e)return this.paymentIntegrationService.selectShippingOption(e)})}_getAmountTransformer(){if(this._amountTransformer)return this._amountTransformer;const{getCart:e}=this.paymentIntegrationService.getState(),{currency:t}=e()||{};return t?new Yd(t.decimalPlaces):void 0}_toCents(e){const t=Math.round(100*e),i=this._getAmountTransformer();return i?i.toInteger(e):t}_toggleLoadingIndicator(e){e&&this._loadingIndicatorContainer?this.loadingIndicator.show(this._loadingIndicatorContainer):this.loadingIndicator.hide()}}const Zd=go(e=>{const t=new Ts(le()),i=new Vd({containerStyles:Gd});return new Kd(e,t,new qd(e,t),i)},[{id:"stripeocs"}]);function Qd(e,t,i){const n=new WeakMap;function o(e){return(...i)=>{const o=i[i.length-1],{useCache:r}=(a=o)&&"boolean"==typeof a.useCache?o:{useCache:!1};var a;if(!r)return e.call(this,...i);const s=n.get(this)||{};var d;return n.get(this)||n.set(this,s),s[t]||(s[t]=(d=e,ae(function(...e){const t=d.call(this,...e);return t instanceof j?W(t).pipe(ne()):"function"==typeof t?ae(e=>W(t(e)).pipe(ne()),{isEqual:v}):t},{isEqual:v}))),s[t].call(this,...i)}}return{get(){if("function"!=typeof i.value)throw new Error("Decorator should be used in functions");const e=o.call(this,i.value);return Object.defineProperty(this,t,Object.assign(Object.assign({},i),{value:e})),e}}}const Jd=e=>!!e;class Xd{constructor(e){this._requestSender=e}loadPaymentMethodsById(e,t){return i=>new j(n=>{var o;const a=null===(o=i.getState().cart.getCart())||void 0===o?void 0:o.id,s=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);n.next(r(fi.LoadPaymentMethodsRequested)),Promise.all(e.map(e=>{return i=this,n=void 0,r=function*(){try{return(yield this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:s}))).body}catch(e){return}},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r})).then(e=>{const t=e.filter(Jd);n.next(r(fi.LoadPaymentMethodsSucceeded,t)),n.complete()}).catch(e=>{n.next(r(fi.LoadPaymentMethodsFailed,e)),n.complete()})})}loadPaymentMethods(e){return t=>j.create(i=>{const n=t.getState().cart.getCartOrThrow();i.next(r(fi.LoadPaymentMethodsRequested)),this._requestSender.loadPaymentMethods(Object.assign(Object.assign({},e),{params:Object.assign(Object.assign({},null==e?void 0:e.params),{cartId:n.id})})).then(e=>{const t={deviceSessionId:e.headers["x-device-session-id"],sessionHash:e.headers["x-session-hash"]},n=e.body;i.next(r(fi.LoadPaymentMethodsSucceeded,n,t)),i.complete()}).catch(e=>{i.error(s(fi.LoadPaymentMethodsFailed,e))})})}loadPaymentMethod(e,t){return i=>j.create(n=>{var o;const a=null===(o=i.getState().cart.getCart())||void 0===o?void 0:o.id,d=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);n.next(r(fi.LoadPaymentMethodRequested,void 0,{methodId:e})),this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:d})).then(t=>{n.next(r(fi.LoadPaymentMethodSucceeded,t.body,{methodId:e})),n.complete()}).catch(t=>{n.error(s(fi.LoadPaymentMethodFailed,t,{methodId:e}))})})}}var ec;(function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)})([Qd],Xd.prototype,"loadPaymentMethod",null),function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(ec||(ec={}));const tc=ec,ic="This API endpoint is for internal use only and may change in the future",nc={"X-Checkout-SDK-Version":"1.863.0"};class oc{constructor(e){this._requestSender=e}loadPaymentMethods({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/payments",{timeout:e,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc),params:t})}loadPaymentMethod(e,{timeout:t,params:i}={}){const n=`/api/storefront/payments/${e}`;return this._requestSender.get(n,{timeout:t,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc),params:i})}}function rc(e,t,i){return(n=t)&&n.type&&n.error?H(Z(t),Q(s(e,t.payload,i))):Q(s(e,t,i));var n}class ac extends be{constructor(e){super(e||"Unable to continue as a guest because the customer is already signed in."),this.name="UnableToContinueAsGuestError",this.type="unable_to_continue_as_guest"}}class sc{constructor(e,t){this._requestSender=e,this._subscriptionActionCreator=t}continueAsGuest(e,t){return i=>{const n=i.getState(),o=n.checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);const a=n.customer.getCustomer();if(a&&!a.isGuest)throw new ac;const s=n.billingAddress.getBillingAddress();let d;if(s){const{country:t}=s,i=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(s,["country"]);d=Object.assign(Object.assign({},i),e)}else d=e;const c=!f(s);return K(H(Z(r(Ue.ContinueAsGuestRequested)),V(()=>{return e=this,i=void 0,a=function*(){const{body:e}=yield this._createOrUpdateBillingAddress(o.id,d,c,t);return r(Ue.ContinueAsGuestSucceeded,e)},new((n=void 0)||(n=Promise))(function(t,o){function r(e){try{d(a.next(e))}catch(e){o(e)}}function s(e){try{d(a.throw(e))}catch(e){o(e)}}function d(e){var i;e.done?t(e.value):(i=e.value,i instanceof n?i:new n(function(e){e(i)})).then(r,s)}d((a=a.apply(e,i||[])).next())});var e,i,n,a})).pipe(J(e=>rc(Ue.ContinueAsGuestFailed,e))),this._updateCustomerConsent(e,t))}}updateAddress(e,t){return i=>j.create(n=>{const o=i.getState(),a=o.checkout.getCheckout();if(!a)throw new qn(xn.MissingCheckout);n.next(r(Ue.UpdateBillingAddressRequested));const d=o.billingAddress.getBillingAddress(),c=!f(d),u=Object.assign(Object.assign({},e),{email:void 0===e.email&&d?d.email:e.email});d&&d.id&&(u.id=d.id),this._createOrUpdateBillingAddress(a.id,u,c,t).then(({body:e})=>{n.next(r(Ue.UpdateBillingAddressSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Ue.UpdateBillingAddressFailed,e))})})}_updateCustomerConsent({email:e,acceptsAbandonedCartEmails:t,acceptsMarketingNewsletter:i},n){return null==t&&null==i?Y():this._subscriptionActionCreator.updateSubscriptions({email:e,acceptsMarketingNewsletter:i||!1,acceptsAbandonedCartEmails:t||!1},n)}_createOrUpdateBillingAddress(e,t,i,n){return i?this._requestSender.updateAddress(e,t,n):this._requestSender.createAddress(e,t,n)}}class dc extends be{constructor(e){super(e||"Your checkout could not be processed because your cart is empty. Please add items to your cart and try again."),this.name="EmptyCartError",this.type="empty_cart"}}const cc={include:["cart.lineItems.physicalItems.options","cart.lineItems.physicalItems.stockPosition","cart.lineItems.digitalItems.options","cart.lineItems.digitalItems.stockPosition","customer","promotions.banners"].join(",")};class uc{constructor(e){this._requestSender=e}createAddress(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/billing-address`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(n,{body:t,params:cc,headers:o,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}updateAddress(e,t,{timeout:i}={}){const{id:n}=t,o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["id"]),r=`/api/storefront/checkouts/${e}/billing-address/${n}`,a=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.put(r,{params:cc,body:o,headers:a,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class lc{constructor(e){this._requestSender=e}createBuyNowCart(e,{timeout:t}={}){const i=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post("/api/storefront/carts",{body:e,headers:i,timeout:t})}}class hc{constructor(e,t,i){this._checkoutRequestSender=e,this._configActionCreator=t,this._formFieldsActionCreator=i}loadCheckout(e,t){return()=>H(Z(r(Me.LoadCheckoutRequested)),K(this._configActionCreator.loadConfig({useCache:!0,timeout:null==t?void 0:t.timeout,params:{checkoutId:e}}),this._formFieldsActionCreator.loadFormFields({useCache:!0,timeout:null==t?void 0:t.timeout})),V(()=>this._checkoutRequestSender.loadCheckout(e,t).then(({body:e})=>r(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(e))))).pipe(J(e=>rc(Me.LoadCheckoutFailed,e)))}loadDefaultCheckout(e){return t=>H(Z(r(Me.LoadCheckoutRequested)),K(this._configActionCreator.loadConfig({useCache:!0,timeout:null==e?void 0:e.timeout}),this._formFieldsActionCreator.loadFormFields({useCache:!0,timeout:null==e?void 0:e.timeout})),V(()=>{return i=this,n=void 0,a=function*(){const i=t.getState().config.getContextConfig();if(!i||!i.checkoutId)throw new qn(xn.MissingCheckoutConfig);const{body:n}=yield this._checkoutRequestSender.loadCheckout(i.checkoutId,e);return r(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(n))},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(e=>rc(Me.LoadCheckoutFailed,e)))}updateCheckout(e,t){return i=>new j(n=>{const o=i.getState().checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);n.next(r(Me.UpdateCheckoutRequested)),this._checkoutRequestSender.updateCheckout(o.id,e,t).then(({body:e})=>{n.next(r(Me.UpdateCheckoutSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Me.UpdateCheckoutFailed,e))})})}loadCurrentCheckout(e){return t=>{const i=t.getState().checkout.getCheckout();if(!i)throw new qn(xn.MissingCheckout);return this.loadCheckout(i.id,e)(t)}}hydrateInitialState(e){return{type:Ne.HydrateInitialState,payload:e}}_transformCustomerAddresses(e){return Object.assign(Object.assign({},e),{customer:Object.assign(Object.assign({},e.customer),{addresses:e.customer.addresses.map(e=>Object.assign(Object.assign({},e),{shouldSaveAddress:!1}))})})}}function pc(e){return F(e).join(",")}function mc(e,t=[]){return Array.isArray(t)?pc([...e,...t]):function(e,t){const i=b(M(t,e=>!e)),n=b(u(t));return pc([...c(e,i),...n])}(e,t)}const gc=["cart.lineItems.physicalItems.options","cart.lineItems.physicalItems.stockPosition","cart.lineItems.digitalItems.options","cart.lineItems.digitalItems.stockPosition","customer","customer.customerGroup","payments","promotions.banners"];class yc extends Pe{constructor(e){super(e,{message:e.body.title}),this.name="CheckoutNotAvailableError",this.type="checkout_not_available"}}class fc{constructor(e){this._requestSender=e}loadCheckout(e,{params:{include:t}={},timeout:i}={}){const n=`/api/storefront/checkout/${e}`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.get(n,{params:{include:mc(gc,t)},headers:o,timeout:i}).catch(e=>{if(e.status>=400&&e.status<500)throw new yc(e);throw e})}updateCheckout(e,t,{params:{include:i}={},timeout:n}={}){const o=`/api/storefront/checkout/${e}`,r=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.put(o,{params:{include:mc(gc,i)},body:t,headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class vc{isEqual(e,t){return v(this._normalize(e),this._normalize(t))}_normalize(e){return{cartAmount:e.cartAmount,currency:e.currency,id:e.id,lineItems:{digitalItems:e.lineItems.digitalItems.slice().sort((e,t)=>`${e.productId}${e.variantId}`.localeCompare(`${t.productId}${t.variantId}`)).map(e=>({extendedSalePrice:e.extendedSalePrice,productId:e.productId,quantity:e.quantity,variantId:e.variantId})),giftCertificates:e.lineItems.giftCertificates.slice().sort((e,t)=>`${e.id}`.localeCompare(`${t.id}`)).map(e=>({amount:e.amount,recipient:e.recipient})),physicalItems:e.lineItems.physicalItems.slice().sort((e,t)=>`${e.productId}${e.variantId}`.localeCompare(`${t.productId}${t.variantId}`)).map(e=>({extendedSalePrice:e.extendedSalePrice,productId:e.productId,quantity:e.quantity,variantId:e.variantId,giftWrapping:e.giftWrapping}))}}}}class Sc extends be{constructor(e,t){super("An update to your shopping cart has been detected and your available shipping costs have been updated."),this.name="CartChangedError",this.type="cart_changed",this.data={previous:e,updated:t}}}class Cc{constructor(e){this._checkoutRequestSender=e}validate(e,t){if(!e)throw new qn(xn.MissingCheckout);return this._checkoutRequestSender.loadCheckout(e.id,t).then(t=>{const i=new vc;if(!(e.outstandingBalance===t.body.outstandingBalance&&this._compareCoupons(e.coupons,t.body.coupons)&&this._compareGiftCertificates(e.giftCertificates,t.body.giftCertificates)&&i.isEqual(e.cart,t.body.cart)))throw new Sc(this._getComparableCheckout(e),this._getComparableCheckout(t.body))})}_compareCoupons(e,t){return v(P(e,"code"),P(t,"code"))}_compareGiftCertificates(e,t){return v(P(e,"code"),P(t,"code"))}_getComparableCheckout(e){const{cart:t,coupons:i,giftCertificates:n,outstandingBalance:o}=e;return{cart:{cartAmount:t.cartAmount,currency:t.currency,lineItems:t.lineItems},coupons:i,giftCertificates:n,outstandingBalance:o}}}var Ic;class _c{constructor(e){this._configRequestSender=e}loadConfig(e){return j.create(t=>{t.next(r(mt.LoadConfigRequested)),this._configRequestSender.loadConfig(e).then(e=>{t.next(r(mt.LoadConfigSucceeded,e.body)),t.complete()}).catch(e=>{t.error(s(mt.LoadConfigFailed,e))})})}}!function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)}([Qd],_c.prototype,"loadConfig",null);class wc{constructor(e){this._requestSender=e}loadConfig({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/checkout-settings",{timeout:e,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc),params:t}).catch(e=>{if(e.status>=400&&e.status<500)throw new yc(e);throw e})}}class bc{constructor(e){this._couponRequestSender=e}applyCoupon(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);n.next(r(Qe.ApplyCouponRequested)),this._couponRequestSender.applyCoupon(o.id,e,t).then(({body:e})=>{n.next(r(Qe.ApplyCouponSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Qe.ApplyCouponFailed,e))})})}removeCoupon(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);n.next(r(Qe.RemoveCouponRequested)),this._couponRequestSender.removeCoupon(o.id,e,t).then(({body:e})=>{n.next(r(Qe.RemoveCouponSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Qe.RemoveCouponFailed,e))})})}}!function(e){e.AvailableShippingOptions="consignments.availableShippingOptions",e.PhysicalItemsCategoryNames="cart.lineItems.physicalItems.categoryNames",e.DigitalItemsCategoryNames="cart.lineItems.digitalItems.categoryNames"}(Ic||(Ic={}));class Ec{constructor(e){this._requestSender=e}applyCoupon(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/coupons`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(n,{headers:o,timeout:i,params:{include:pc([...gc,Ic.AvailableShippingOptions])},body:{couponCode:t}}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}removeCoupon(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/coupons/${t}`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.delete(n,{headers:o,timeout:i,params:{include:pc([...gc,Ic.AvailableShippingOptions])}}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}function Pc(e){const t=e;return"object"==typeof t&&"object"==typeof t.payload&&"string"==typeof t.payload.token}class Oc{constructor(e,t,i){this._customerRequestSender=e,this._checkoutActionCreator=t,this._spamProtectionActionCreator=i}createCustomer(e,t){return i=>{const n=i.getState().config.getStoreConfigOrThrow(),{isStorefrontSpamProtectionEnabled:o}=n.checkoutSettings,a=n=>W(this._customerRequestSender.createAccount(Object.assign(Object.assign({},e),{token:n}),t)).pipe(oe(()=>H(this._checkoutActionCreator.loadCurrentCheckout(t)(i),Z(r(Rt.CreateCustomerSucceeded)))));return H(Z(r(Rt.CreateCustomerRequested)),o?W(this._spamProtectionActionCreator.execute()(i)).pipe(oe(e=>{var t;return Pc(e)?H(Z(e),a(null===(t=e.payload)||void 0===t?void 0:t.token)):Z(e)})):a()).pipe(J(e=>rc(Rt.CreateCustomerFailed,e)))}}createAddress(e,t){return H(Z(r(Rt.CreateCustomerAddressRequested)),V(()=>{return i=this,n=void 0,a=function*(){const{body:i}=yield this._customerRequestSender.createAddress(e,t);return r(Rt.CreateCustomerAddressSucceeded,i)},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(e=>rc(Rt.CreateCustomerAddressFailed,e)))}signInCustomer(e,t){return i=>{const n=i.getState().checkout.getCheckoutOrThrow(),o=n.cart.source===ar.BuyNow?n.id:void 0;return H(Z(r(Rt.SignInCustomerRequested)),W(this._customerRequestSender.signInCustomer(Object.assign(Object.assign({},e),{cartId:o}),t)).pipe(oe(({body:e})=>e.data.persistentCartRetrievalInformation?H(this._checkoutActionCreator.loadCheckout(e.data.persistentCartRetrievalInformation.id,t)(i),Z(r(Rt.SignInCustomerSucceeded,e.data))):H(this._checkoutActionCreator.loadCurrentCheckout(t)(i),Z(r(Rt.SignInCustomerSucceeded,e.data)))))).pipe(J(e=>rc(Rt.SignInCustomerFailed,e)))}}signOutCustomer(e){return t=>{const i=t.getState().checkout.getCheckoutOrThrow(),n=i.cart.source===ar.BuyNow?i.id:void 0;return H(Z(r(Rt.SignOutCustomerRequested)),W(this._customerRequestSender.signOutCustomer(e,n)).pipe(oe(({body:i})=>H(this._checkoutActionCreator.loadCurrentCheckout(e)(t),Z(r(Rt.SignOutCustomerSucceeded,i.data)))))).pipe(J(e=>rc(Rt.SignOutCustomerFailed,e)))}}}class Ac{constructor(e){this._requestSender=e}createAccount(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer",{timeout:t,headers:nc,body:e})}createAddress(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer-address",{timeout:t,headers:nc,body:e})}signInCustomer(e,{timeout:t}={}){return this._requestSender.post("/internalapi/v1/checkout/customer",{timeout:t,headers:nc,body:e})}signOutCustomer({timeout:e}={},t){return this._requestSender.delete("/internalapi/v1/checkout/customer",Object.assign({timeout:e,headers:nc},t&&{body:{cartId:t}}))}}class Tc{constructor(e){this._formFieldsRequestSender=e}loadFormFields(e){return H(Z(r(Kt.LoadFormFieldsRequested)),V(()=>{return t=this,i=void 0,o=function*(){const{body:t}=yield this._formFieldsRequestSender.loadFields(e);return r(Kt.LoadFormFieldsSucceeded,t)},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o})).pipe(J(e=>rc(Kt.LoadFormFieldsFailed,e)))}}!function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)}([Qd],Tc.prototype,"loadFormFields",null);class kc{constructor(e){this._requestSender=e}loadFields({timeout:e}={}){return this._requestSender.get("/api/storefront/form-fields",{timeout:e,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc)})}}class Rc extends be{constructor(e){super(e||"Unable to proceed because the required element is unexpectedly detached from the page."),this.name="UnexpectedDetachmentError",this.type="unexpected_detachment"}}class Dc{constructor(e){this._mutationObserver=e}ensurePresence(e,t){return i=this,n=void 0,r=function*(){const i=new Yr(t),n=this._mutationObserver.create(t=>{t.forEach(t=>{0!==Array.from(t.removedNodes).filter(t=>e.some(e=>t===e||t.contains(e))).length&&i.cancel(new Rc)})});n.observe(document.body,{childList:!0,subtree:!0});try{const e=yield i.promise;return n.disconnect(),e}catch(e){throw n.disconnect(),e}},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}class Mc{constructor(e=window){this._window=e}create(e){return new this._window.MutationObserver(e)}}class Nc extends be{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}function Lc(e){if(!/^(https?:)?\/\//.test(e))throw new Nc("The provided URL must be absolute.");const t=document.createElement("a");t.href=e;const i=t.port&&-1!==e.indexOf(`${t.hostname}:${t.port}`)?t.port:"";return{hash:t.hash,hostname:t.hostname,href:t.href,origin:`${t.protocol}//${t.hostname}${i?`:${i}`:""}`,pathname:t.pathname,port:i,protocol:t.protocol,search:t.search}}function zc(e,t){return e.type===t}class Uc{constructor(e,t,i){this._targetWindow=t,this._context=i,this._targetOrigin="*"===e?"*":Lc(e).origin}post(e,t){const i=this._targetWindow;if(window===i)return;if(!i)throw new Error("Unable to post message because target window is not set.");const n=t&&$(window,"message").pipe(ee(e=>e.origin===this._targetOrigin&&zc(e.data,e.data.type)&&-1!==[t.successType,t.errorType].indexOf(e.data.type)),te(e=>{if(t.errorType===e.data.type)throw e.data;return e.data}),re(1)).toPromise();return i.postMessage(Object.assign(Object.assign({},e),{context:this._context}),this._targetOrigin),n}setTarget(e){this._targetWindow=e}setContext(e){this._context=e}}class Fc{constructor(e){var t;this._sourceOrigins=[Lc(e).origin,(t=Lc(e),Lc(0===t.hostname.indexOf("www")?t.href:t.href.replace(t.hostname,`www.${t.hostname}`))).origin],this._isListening=!1,this._listeners={}}listen(){this._isListening||(this._isListening=!0,window.addEventListener("message",this._handleMessage))}stopListen(){this._isListening&&(this._isListening=!1,window.removeEventListener("message",this._handleMessage))}addListener(e,t){let i=this._listeners[e];i||(this._listeners[e]=i=[]),-1===i.indexOf(t)&&i.push(t)}removeListener(e,t){const i=this._listeners[e];if(!i)return;const n=i.indexOf(t);n>=0&&i.splice(n,1)}trigger(e,t){const i=this._listeners[e.type];i&&i.forEach(i=>t?i(e,t):i(e))}_handleMessage(e){if(-1===this._sourceOrigins.indexOf(e.origin)||!zc(e.data,e.data.type))return;const t=e.data,{context:i}=t,n=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["context"]);this.trigger(n,i)}}!function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)}([wa],Fc.prototype,"_handleMessage",null);class Bc extends be{constructor(){super("You haven't complete our spam protection challenge. Please try again."),this.name="SpamProtectionChallengeNotCompletedError",this.type="spam_protection_challenge_not_completed"}}class xc extends be{constructor(){super("Please complete our human verification challenge and try again."),this.name="CardingProtectionChallengeNotCompletedError",this.type="carding_protection_challenge_not_completed"}}class qc extends be{constructor(){super("We were not able to verify that you are not a robot. Please try again."),this.name="CardingProtectionFailedError",this.type="carding_protection_failed"}}var jc,Gc,Hc,Vc=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Yc{constructor(e){this._googleRecaptcha=e}handle(e,t){return Vc(this,void 0,void 0,function*(){return"string"==typeof e?this.handleWithRecaptchaSitekey(e,t):this.handleWithPaymentHumanVerificationRequestError(e)})}handleWithPaymentHumanVerificationRequestError(e){return Vc(this,void 0,void 0,function*(){if(!this._isPaymentHumanVerificationRequest(e))throw e;return yield this._initialize(e.body.additional_action_required.data.key),this._performRecaptcha()})}handleWithRecaptchaSitekey(e,t){return Vc(this,void 0,void 0,function*(){if("recaptcha_v2"!==e)throw Error("Human verification method is not supported.");if(!t)throw Error("Recaptcha site key is missing.");return yield this._initialize(t),this._performRecaptcha()})}_performRecaptcha(){return this._googleRecaptcha.execute().pipe(re(1)).pipe(oe(({error:e,token:t})=>Vc(this,void 0,void 0,function*(){if(e instanceof Bc)throw new xc;if(e||!t)throw new qc;return{type:"recaptcha_v2_verification",data:{human_verification_token:t}}}))).toPromise()}_initialize(e){const t="cardingProtectionContainer";let i=document.getElementById(t);return i&&i.parentNode&&i.parentNode.removeChild(i),i=document.createElement("div"),i.setAttribute("id",t),document.body.appendChild(i),this._googleRecaptcha.load(t,e)}_isPaymentHumanVerificationRequest(e){const{additional_action_required:t,status:i}=e.body||{};return"additional_action_required"===i&&t&&"recaptcha_v2_verification"===t.type}}!function(e){e[e.CheckoutButtonNotInitialized=0]="CheckoutButtonNotInitialized",e[e.CustomerNotInitialized=1]="CustomerNotInitialized",e[e.PaymentNotInitialized=2]="PaymentNotInitialized",e[e.ShippingNotInitialized=3]="ShippingNotInitialized",e[e.SpamProtectionNotInitialized=4]="SpamProtectionNotInitialized"}(jc||(jc={}));class Wc extends be{constructor(e){super(function(e){switch(e){case jc.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case jc.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case jc.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case jc.SpamProtectionNotInitialized:return"Unable to proceed because the checkout spam protection has not been initialized.";default:return"Unable to proceed because the required component has not been initialized."}}(e)),this.subtype=e,this.name="NotInitializedError",this.type="not_initialized"}}class $c extends be{constructor(){super("We were not able to complete your spam protection verification. Please try again."),this.name="SpamProtectionFailedError",this.type="spam_protection_failed"}}class Kc extends be{constructor(){super("Spam protection is not loaded. Please try again."),this.name="SpamProtectionNotLoadedError",this.type="spam_protection_failed"}}class Zc{constructor(e,t){this.googleRecaptchaScriptLoader=e,this.mutationObserverFactory=t,this._memoized=ae((e,t,i)=>{const n=new G;if(!i)throw new Error;return this._widgetId=e.render(i.id,{sitekey:t,size:"invisible",callback:()=>{n.next({token:e.getResponse(this._widgetId)}),e.reset(this._widgetId)},"error-callback":()=>{n.next({error:new $c})}}),n},{isEqual:(e,t)=>e===t})}load(e,t){return this.googleRecaptchaScriptLoader.load().then(i=>{i&&(this._event$=this._memoized(i,t,document.getElementById(e)),this._recaptcha=i)}).catch(e=>{throw e})}reset(e){var t;const i=document.getElementById(e);null==i||i.remove(),null===(t=this._recaptcha)||void 0===t||t.reset(this._widgetId)}execute(){return V(()=>{const e=this._event$,t=this._recaptcha;if(!e||!t)throw new Wc(jc.SpamProtectionNotInitialized);return V(()=>{const e=document.querySelector('iframe[src*="bframe"]');return e?Z(e):Q(new Kc)}).pipe(ie(e=>e.pipe(X(250),oe((e,t)=>t<28?Z(e):Q(e)))),oe(i=>(this._watchRecaptchaChallengeWindow(e,i),t.execute(this._widgetId),e)),J(e=>Z({error:e})))})}_watchRecaptchaChallengeWindow(e,t){const i=t.parentElement;if(!i)throw new Kc;const n=i.parentElement;if(!n)throw new Kc;this.mutationObserverFactory.create(()=>{"hidden"===n.style.visibility&&e.next({error:new Bc})}).observe(n,{attributes:!0,attributeFilter:["style"]})}}class Qc{constructor(e,t=window){this._scriptLoader=e,this._window=t}load(){return this._loadPromise||(this._loadPromise=this._loadScript()),this._loadPromise}_loadScript(){const e="initRecaptcha",t=[`onload=${e}`,"render=explicit"].join("&");return new Promise((i,n)=>{this._window[e]=()=>i(this._window.grecaptcha),this._scriptLoader.loadScript(`//www.google.com/recaptcha/api.js?${t}`).catch(e=>{this._loadPromise=void 0,n(e)})})}}function Jc(e){return new Zc(new Qc(e),new Mc)}class Xc extends be{constructor(e){super(e||"Unable to proceed due to invalid configuration provided for the hosted payment form."),this.name="InvalidHostedFormConfigError",this.type="invalid_hosted_form_config"}}class eu extends be{constructor(e){super(e||"Unable to proceed due to an unknown error with the hosted payment form."),this.name="InvalidHostedFormError",this.type="invalid_hosted_form"}}class tu extends be{constructor(e){super(["Unable to proceed due to invalid user input values",...p(x(e),e=>P(e,({message:e})=>e))].join(". ")),this.errors=e,this.name="InvalidHostedFormValueError",this.type="invalid_hosted_form_value"}}!function(e){e.AttachRequested="HOSTED_FIELD:ATTACH_REQUESTED",e.SubmitRequested="HOSTED_FIELD:SUBMITTED_REQUESTED",e.ValidateRequested="HOSTED_FIELD:VALIDATE_REQUESTED",e.StoredCardRequested="HOSTED_FIELD:STORED_CARD_REQUESTED"}(Gc||(Gc={})),function(e){e.AttachSucceeded="HOSTED_INPUT:ATTACH_SUCCEEDED",e.AttachFailed="HOSTED_INPUT:ATTACH_FAILED",e.BinChanged="HOSTED_INPUT:BIN_CHANGED",e.Blurred="HOSTED_INPUT:BLURRED",e.Changed="HOSTED_INPUT:CHANGED",e.CardTypeChanged="HOSTED_INPUT:CARD_TYPE_CHANGED",e.Entered="HOSTED_INPUT:ENTERED",e.Focused="HOSTED_INPUT:FOCUSED",e.SubmitSucceeded="HOSTED_INPUT:SUBMIT_SUCCEEDED",e.SubmitFailed="HOSTED_INPUT:SUBMIT_FAILED",e.Validated="HOSTED_INPUT:VALIDATED",e.StoredCardSucceeded="HOSTED_INPUT:STORED_CARD_SUCCEEDED",e.StoredCardFailed="HOSTED_INPUT:STORED_CARD_FAILED"}(Hc||(Hc={}));var iu=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class nu{constructor(e,t,i,n,o,r,a,s,d,c){this._type=e,this._containerId=t,this._placeholder=i,this._accessibilityLabel=n,this._styles=o,this._eventPoster=r,this._eventListener=a,this._detachmentObserver=s,this._checkoutId=d,this._cardInstrument=c,this._iframe=document.createElement("iframe");const u=this._checkoutId?`/checkout/payment/hosted-field?version=1.863.0&checkoutId=${this._checkoutId}`:"/checkout/payment/hosted-field?version=1.863.0";this._iframe.src=u,this._iframe.style.border="none",this._iframe.style.height="100%",this._iframe.style.overflow="hidden",this._iframe.style.width="100%"}getType(){return this._type}attach(){return iu(this,void 0,void 0,function*(){const e=document.getElementById(this._containerId);if(!e)throw new Xc("Unable to proceed because the provided container ID is not valid.");e.appendChild(this._iframe),this._eventListener.listen();const t=$(this._iframe,"load").pipe(oe(({target:e})=>iu(this,void 0,void 0,function*(){const t=e&&e.contentWindow;if(!t)throw new Error("The content window of the iframe cannot be accessed.");this._eventPoster.setTarget(t),yield this._eventPoster.post({type:Gc.AttachRequested,payload:{accessibilityLabel:this._accessibilityLabel,cardInstrument:this._cardInstrument,fontUrls:this._getFontUrls(),placeholder:this._placeholder,styles:this._styles,origin:document.location.origin,type:this._type}},{successType:Hc.AttachSucceeded,errorType:Hc.AttachFailed})})),re(1)).toPromise();yield this._detachmentObserver.ensurePresence([this._iframe],t)})}detach(){this._iframe.parentElement&&(this._iframe.parentElement.removeChild(this._iframe),this._eventListener.stopListen())}submitForm(e,t){return iu(this,void 0,void 0,function*(){try{const i=this._eventPoster.post({type:Gc.SubmitRequested,payload:{fields:e,data:t}},{successType:Hc.SubmitSucceeded,errorType:Hc.SubmitFailed});return yield this._detachmentObserver.ensurePresence([this._iframe],i)}catch(e){if(this._isSubmitErrorEvent(e)){if("hosted_form_error"===e.payload.error.code)throw new eu(e.payload.error.message);if(e.payload.response)throw Te(e.payload.response);throw new Error(e.payload.error.message)}throw e}})}submitStoredCardForm(e,t){return iu(this,void 0,void 0,function*(){const i=this._eventPoster.post({type:Gc.StoredCardRequested,payload:{fields:e,data:t}},{successType:Hc.StoredCardSucceeded,errorType:Hc.StoredCardFailed});return this._detachmentObserver.ensurePresence([this._iframe],i)})}validateForm(){return iu(this,void 0,void 0,function*(){const e=this._eventPoster.post({type:Gc.ValidateRequested},{successType:Hc.Validated}),{payload:t}=yield this._detachmentObserver.ensurePresence([this._iframe],e);if(!t.isValid)throw new tu(t.errors)})}_getFontUrls(){const e="fonts.googleapis.com",t=document.querySelectorAll(`link[href*='${e}'][rel='stylesheet']`);return Array.prototype.slice.call(t).filter(t=>Lc(t.href).hostname===e).filter(e=>x(this._styles).map(e=>e&&e.fontFamily).filter(e=>"string"==typeof e).some(t=>t.split(/,\s/).some(t=>-1!==e.href.indexOf(t.replace(" ","+"))))).map(e=>e.href)}_isSubmitErrorEvent(e){return e.type===Hc.SubmitFailed}}var ou=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ru{constructor(e,t,i,n,o){this._fields=e,this._eventListener=t,this._payloadTransformer=i,this._eventCallbacks=n,this._paymentHumanVerificationHandler=o,this._handleEnter=({payload:e})=>ou(this,void 0,void 0,function*(){try{yield this.validate()}catch(e){if(e instanceof Error&&"InvalidHostedFormValueError"!==e.name)throw e}const{onEnter:t=T}=this._eventCallbacks;t(e)});const{onBlur:r=T,onCardTypeChange:a=T,onFocus:s=T,onValidate:d=T}=this._eventCallbacks;this._eventListener.addListener(Hc.Blurred,({payload:e})=>r(e)),this._eventListener.addListener(Hc.CardTypeChanged,({payload:e})=>a(e)),this._eventListener.addListener(Hc.Focused,({payload:e})=>s(e)),this._eventListener.addListener(Hc.Validated,({payload:e})=>d(e)),this._eventListener.addListener(Hc.Entered,this._handleEnter),this._eventListener.addListener(Hc.CardTypeChanged,({payload:e})=>this._cardType=e.cardType),this._eventListener.addListener(Hc.BinChanged,({payload:e})=>this._bin=e.bin)}getBin(){return this._bin}getCardType(){return this._cardType}attach(){return ou(this,void 0,void 0,function*(){this._eventListener.listen();const e=this._getFirstField(),t=q(this._fields,e);yield e.attach(),yield Promise.all(t.map(e=>e.attach()))})}detach(){this._eventListener.stopListen(),this._fields.forEach(e=>{e.detach()})}submit(e,t){return ou(this,void 0,void 0,function*(){try{return yield this._getFirstField().submitForm(this._fields.map(e=>e.getType()),this._payloadTransformer.transform(e,t))}catch(t){const i=yield this._paymentHumanVerificationHandler.handle(t);return yield this._getFirstField().submitForm(this._fields.map(e=>e.getType()),this._payloadTransformer.transform(e,i))}})}submitStoredCard(e){return ou(this,void 0,void 0,function*(){return this._getFirstField().submitStoredCardForm(e.fields,e.data)})}validate(){return ou(this,void 0,void 0,function*(){return this._getFirstField().validateForm()})}_getFirstField(){const e=this._fields[0];if(!e)throw new Xc("Unable to proceed because the payment form has no field defined.");return e}}function au(e){return Boolean(e.instrumentId)}class su{constructor(e){this._store=e}transform(e,t){const i=this._store.getState(),n=i.checkout.getCheckout(),o=i.config.getConfig(),r=i.instruments.getInstrumentsMeta(),a=i.order.getOrder(),s=i.order.getOrderMeta(),d=k(e.paymentData,"ccExpiry","ccName","ccNumber","ccCvv"),c=i.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),u=i.paymentMethods.getPaymentMethodsMeta(),l=r&&d&&au(d)?`${i.payment.getPaymentToken()}, ${r.vaultAccessToken}`:i.payment.getPaymentToken();if(!l)throw new qn(xn.MissingPaymentToken);return{additionalAction:t,authToken:l,checkout:n,config:o,order:a,orderMeta:s,payment:d,paymentMethod:c,paymentMethodMeta:u}}}class du{constructor(e){this._store=e}create(e,t,i){const n=Object.keys(t.fields).reduce((n,o)=>{const r=t.fields[o];return r?[...n,new nu(o,r.containerId,r.placeholder||"",r.accessibilityLabel||"",t.styles||{},new Uc(e),new Fc(e),new Dc(new Mc),i,"instrumentId"in r?this._getCardInstrument(r.instrumentId):void 0)]:n},[]);return new ru(n,new Fc(e),new su(this._store),D(t,"onBlur","onEnter","onFocus","onCardTypeChange","onValidate"),new Yc(Jc(ue())))}_getCardInstrument(e){const{instruments:{getCardInstrument:t}}=this._store.getState(),i=t(e);if(!i)throw new qn(xn.MissingPaymentInstrument);return i}}class cu extends be{constructor(){super("You haven't complete our spam check. Please try again."),this.name="SpamProtectionNotCompletedError",this.type="spam_protection_not_completed"}}class uu{constructor(e,t){this._orderRequestSender=e,this._checkoutValidator=t}loadOrder(e,t){return new j(i=>{i.next(r(Ct.LoadOrderRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{i.next(r(Ct.LoadOrderSucceeded,e.body)),i.complete()}).catch(e=>{i.error(s(Ct.LoadOrderFailed,e))})})}loadOrderPayments(e,t){return new j(i=>{i.next(r(Ct.LoadOrderPaymentsRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{i.next(r(Ct.LoadOrderPaymentsSucceeded,e.body)),i.complete()}).catch(e=>{i.error(s(Ct.LoadOrderPaymentsFailed,e))})})}loadCurrentOrder(e){return t=>V(()=>{const i=this._getCurrentOrderId(t.getState());if(!i)throw new qn(xn.MissingOrderId);return this.loadOrder(i,e)})}submitOrder(e,t){return i=>H(Z(r(Ct.SubmitOrderRequested)),V(()=>{const n=i.getState(),o=n.config.getExternalSource(),a=n.config.getVariantIdentificationToken(),s=n.checkout.getCheckout();if(!s)throw new qn(xn.MissingCheckout);if(s.shouldExecuteSpamCheck)throw new cu;return W(this._checkoutValidator.validate(s,t).then(()=>this._orderRequestSender.submitOrder(this._mapToOrderRequestBody(null!=e?e:{},s.id,s.customerMessage,o),Object.assign(Object.assign({},t),{headers:{checkoutVariant:a}})))).pipe(oe(e=>H(this.loadOrder(e.body.data.order.orderId,t),Z(r(Ct.SubmitOrderSucceeded,e.body.data,Object.assign(Object.assign({},e.body.meta),{token:e.headers.token}))))))}).pipe(J(e=>rc(Ct.SubmitOrderFailed,e))))}finalizeOrder(e,t){return H(Z(r(Ct.FinalizeOrderRequested)),W(this._orderRequestSender.finalizeOrder(e,t)).pipe(oe(i=>H(this.loadOrder(e,t),Z(r(Ct.FinalizeOrderSucceeded,i.body.data)))))).pipe(J(e=>rc(Ct.FinalizeOrderFailed,e)))}_getCurrentOrderId(e){const t=e.order.getOrder(),i=e.checkout.getCheckout();return t&&t.orderId||i&&i.orderId}_mapToOrderRequestBody(e,t,i,n){const{payment:o}=e,r=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["payment"]);return o?Object.assign(Object.assign({},r),{cartId:t,customerMessage:i,externalSource:n,payment:{paymentData:o.paymentData,name:o.methodId,gateway:o.gatewayId}}):Object.assign(Object.assign({},r),{cartId:t,customerMessage:i,externalSource:n})}}class lu extends be{constructor(e){super(e||"Your checkout could not be processed because some details have changed. Please review your order and try again."),this.name="CartConsistencyError",this.type="cart_consistency"}}class hu extends be{constructor(e){super(e||"The tax provider is unavailable."),this.name="OrderTaxProviderUnavailableError",this.type="tax_provider_unavailable"}}class pu extends be{constructor(e){super(e),this.name="MissingShippingMethodError",this.type="missing_shipping_method"}}class mu extends be{constructor(e){super(e),this.name="InvalidShippingAddressError",this.type="invalid_shipping_address"}}class gu{constructor(e){this._requestSender=e}loadOrder(e,{timeout:t}={}){const i=`/api/storefront/orders/${e}`,n=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.get(i,{params:{include:pc(["payments","lineItems.physicalItems.socialMedia","lineItems.physicalItems.options","lineItems.physicalItems.categories","lineItems.digitalItems.socialMedia","lineItems.digitalItems.options","lineItems.digitalItems.categories"])},headers:n,timeout:t})}submitOrder(e,{headers:t,timeout:i}={}){return this._requestSender.post("/internalapi/v1/checkout/order",{body:e,headers:R(Object.assign({"X-Checkout-Variant":t&&t.checkoutVariant},nc),C),timeout:i}).catch(e=>{if("tax_provider_unavailable"===e.body.type)throw new hu;if("cart_has_changed"===e.body.type)throw new lu;if("missing_shipping_method"===e.body.type)throw new pu(e.body.detail);if("invalid_shipping_address"===e.body.type)throw new mu(e.body.detail);if("empty_cart"===e.body.type)throw new dc;throw e})}finalizeOrder(e,{timeout:t}={}){const i=`/internalapi/v1/checkout/order/${e}`;return this._requestSender.post(i,{timeout:t,headers:nc})}}class yu{constructor(e,t,i,n){this._paymentRequestSender=e,this._orderActionCreator=t,this._paymentRequestTransformer=i,this._paymentHumanVerificationHandler=n,this.initializeOffsitePayment=({methodId:e,gatewayId:t,instrumentId:i,target:n,promise:o,shouldSaveInstrument:a,shouldSetAsDefaultInstrument:s})=>d=>{let c;i?c={formattedPayload:{bigpay_token:i}}:a&&(c={formattedPayload:{vault_payment_instrument:a,set_as_default_stored_instrument:s||null}});const u=this._paymentRequestTransformer.transform({gatewayId:t,methodId:e,paymentData:c},d.getState());return H(Z(r(yi.InitializeOffsitePaymentRequested)),Promise.race([this._paymentRequestSender.initializeOffsitePayment(u,n),o].filter(Boolean)).then(()=>r(yi.InitializeOffsitePaymentSucceeded))).pipe(J(e=>rc(yi.InitializeOffsitePaymentFailed,e)))}}submitPayment(e){return t=>H(Z(r(yi.SubmitPaymentRequested)),V(()=>{return i=this,n=void 0,r=function*(){try{return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(e,t.getState()))}catch(i){const n=yield this._paymentHumanVerificationHandler.handle(i);return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(Object.assign(Object.assign({},e),{additionalAction:n}),t.getState()))}},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}).pipe(oe(({body:e})=>H(this._orderActionCreator.loadCurrentOrder()(t),Z(r(yi.SubmitPaymentSucceeded,e)))))).pipe(J(e=>rc(yi.SubmitPaymentFailed,e)))}}class fu{constructor(e){this._client=e}submitPayment(e){return new Promise((t,i)=>{this._client.submitPayment(e,(e,n)=>{e?i(this._transformResponse(e)):t(this._transformResponse(n))})})}initializeOffsitePayment(e,t){return new Promise(()=>{this._client.initializeOffsitePayment(e,null,t)})}_transformResponse(e){return{headers:e.headers,body:e.data,status:e.status,statusText:e.statusText}}}function vu(e,t){let i;return function(e){return void 0!==e.id}(e)?i=e.id:t&&t.length&&(i=t[0].id),{id:i,firstName:e.firstName,lastName:e.lastName,company:e.company,addressLine1:e.address1,addressLine2:e.address2,city:e.city,province:e.stateOrProvince,provinceCode:e.stateOrProvinceCode,postCode:e.postalCode,country:e.country,countryCode:e.countryCode,phone:e.phone,customFields:e.customFields}}const Su=["per_item_discount","percentage_discount","per_total_discount","shipping_discount","free_shipping"];function Cu(e){return{code:e.code,discount:e.displayName,discountType:Su.indexOf(e.couponType)}}function Iu(e){return{code:e.code,discountedAmount:e.used,remainingBalance:e.remaining,giftCertificate:{balance:e.balance,code:e.code,purchaseDate:e.purchaseDate}}}function _u(e){const t=[];return(e||[]).forEach(e=>{(e.banners||[]).forEach(e=>{t.push({placeholders:[],discountType:null,message:"",messageHtml:e.text})})}),t}function wu(e,t,i="id"){return Object.keys(e).reduce((n,o)=>[...n,...e[o].map(e=>"giftCertificates"===o?function(e,t){const i=new Yd(t);return{id:e.id,imageUrl:"",name:e.name,amount:e.amount,amountAfterDiscount:e.amount,discount:0,integerAmount:i.toInteger(e.amount),integerAmountAfterDiscount:i.toInteger(e.amount),integerUnitPrice:i.toInteger(e.amount),integerUnitPriceAfterDiscount:i.toInteger(e.amount),integerDiscount:0,quantity:1,sender:e.sender,recipient:e.recipient,type:"ItemGiftCertificateEntity",attributes:[],variantId:null}}(e,t):function(e,t,i,n="id"){const o=new Yd(i);return{id:e[n],imageUrl:e.imageUrl,amount:e.extendedListPrice,amountAfterDiscount:e.extendedSalePrice,discount:e.discountAmount,integerAmount:o.toInteger(e.extendedListPrice),integerAmountAfterDiscount:o.toInteger(e.extendedSalePrice),integerDiscount:o.toInteger(e.discountAmount),integerUnitPrice:o.toInteger(e.listPrice),integerUnitPriceAfterDiscount:o.toInteger(e.salePrice),downloadsPageUrl:e.downloadPageUrl,name:e.name,quantity:e.quantity,brand:e.brand,sku:e.sku,categoryNames:e.categoryNames,variantId:e.variantId,productId:e.productId,attributes:(e.options||[]).map(e=>({name:e.name,value:e.value})),addedByPromotion:e.addedByPromotion,type:t}}(e,function(e){switch(e){case"physicalItems":return"ItemPhysicalEntity";case"digitalItems":return"ItemDigitalEntity";case"giftCertificates":return"ItemGiftCertificateEntity";default:return""}}(o),t,i))],[])}function bu(e){const t=e.cart.currency.decimalPlaces,i=new Yd(t);return{id:e.cart.id,items:wu(e.cart.lineItems,t),currency:e.cart.currency.code,coupon:{discountedAmount:N(e.cart.coupons,(e,t)=>e+t.discountedAmount,0),coupons:e.cart.coupons.map(Cu)},discount:{amount:e.cart.discountAmount,integerAmount:i.toInteger(e.cart.discountAmount)},discountNotifications:_u(e.promotions),giftCertificate:{totalDiscountedAmount:N(e.giftCertificates,(e,t)=>e+t.used,0),appliedGiftCertificates:w(e.giftCertificates.map(Iu),"code")},shipping:{amount:e.shippingCostTotal,integerAmount:i.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:i.toInteger(e.shippingCostBeforeDiscount),required:z(e.cart.lineItems.physicalItems,e=>e.isShippingRequired)},subtotal:{amount:e.subtotal,integerAmount:i.toInteger(e.subtotal)},storeCredit:{amount:e.customer?e.customer.storeCredit:0},taxSubtotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:i.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.grandTotal,integerAmount:i.toInteger(e.grandTotal)}}}var Eu;!function(e){e.APPLEPAY="applepay",e.AMAZON_PAY_V2="amazonpay",e.BRAINTREE_PAYPAL="braintreepaypal",e.BRAINTREE_VENMO="braintreevenmo",e.BRAINTREE_PAYPAL_CREDIT="braintreepaypalcredit",e.GOOGLEPAY_ADYENV2="googlepayadyenv2",e.GOOGLEPAY_ADYENV3="googlepayadyenv3",e.GOOGLEPAY_AUTHORIZENET="googlepayauthorizenet",e.GOOGLEPAY_BNZ="googlepaybnz",e.GOOGLEPAY_BRAINTREE="googlepaybraintree",e.GOOGLEPAY_CHECKOUTCOM="googlepaycheckoutcom",e.GOOGLEPAY_CYBERSOURCEV2="googlepaycybersourcev2",e.GOOGLEPAY_ORBITAL="googlepayorbital",e.GOOGLEPAY_STRIPE="googlepaystripe",e.GOOGLEPAY_STRIPEUPE="googlepaystripeupe",e.GOOGLEPAY_WORLDPAYACCESS="googlepayworldpayaccess",e.PAYPALEXPRESS="paypalexpress"}(Eu||(Eu={}));const Pu=Eu;function Ou(e,t){const i=e.firstName||t.firstName||"",n=e.lastName||t.lastName||"";return{addresses:(e.addresses||[]).map(e=>vu(e)),customerId:e.id,isGuest:e.isGuest,storeCredit:e.storeCredit,email:e.email||t.email||"",firstName:i,lastName:n,name:e.fullName||[i,n].join(" "),customerGroupName:e.customerGroup&&e.customerGroup.name}}class Au{format(e){const[t="",i=""]=e.split(new RegExp("\\s*/\\s*")),n=t.slice(0,2),o=4===i.length?i.slice(-2):i?i.slice(0,2):t.slice(2);return e.length<2?t:e.length>3&&!o?n:`${n} / ${o}`}toObject(e){const[t="",i=""]=e.split(new RegExp("\\s*/\\s*"));return/^\d+$/.test(t)&&/^\d+$/.test(i)?{month:1===t.length?`0${t}`:t.slice(0,2),year:2===i.length?`20${i}`:i.slice(0,4)}:{month:"",year:""}}}class Tu{format(e){const{card:t}=ye(e);if(!t)return e;const i=O(ge(e).map(e=>O(e.lengths))),n=this.unformat(e).slice(0,i);return t.gaps.filter(e=>n.length>e).reduce((e,t,i)=>[e.slice(0,t+i),e.slice(t+i)].join(" "),n)}unformat(e){const{card:t}=ye(e);return t?e.replace(new RegExp(" ","g"),""):e}}function ku(e,t={}){const i=e.currency.decimalPlaces,n=new Yd(i);return{id:e.orderId,items:wu(e.lineItems,e.currency.decimalPlaces,"productId"),orderId:e.orderId,currency:e.currency.code,customerCanBeCreated:e.customerCanBeCreated,payment:Mu(e.payments,t.payment),subtotal:{amount:e.baseAmount,integerAmount:n.toInteger(e.baseAmount)},coupon:{discountedAmount:N(e.coupons,(e,t)=>e+t.discountedAmount,0),coupons:e.coupons.map(Cu)},discount:{amount:e.discountAmount,integerAmount:n.toInteger(e.discountAmount)},token:t.orderToken,callbackUrl:t.callbackUrl,discountNotifications:[],giftCertificate:Du(e.payments),socialData:Lu(e),status:e.status,hasDigitalItems:e.hasDigitalItems,isDownloadable:e.isDownloadable,isComplete:e.isComplete,shipping:{amount:e.shippingCostTotal,integerAmount:n.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:n.toInteger(e.shippingCostBeforeDiscount)},storeCredit:{amount:Ru(e.payments)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:n.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:n.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.orderAmount,integerAmount:e.orderAmountAsInteger}}}function Ru(e){const t=l(e,{providerId:"storecredit"});return t?t.amount:0}function Du(e){const t=u(e,{providerId:"giftcertificate"});return{totalDiscountedAmount:N(t,(e,t)=>t.amount+e,0),appliedGiftCertificates:w(t.map(e=>({code:e.detail.code,discountedAmount:e.amount,remainingBalance:e.detail.remaining,giftCertificate:{balance:e.amount+e.detail.remaining,code:e.detail.code,purchaseDate:""}})),"code")}}function Mu(e,t={}){const i=l(e,Nu);return i?{id:i.providerId,status:(n=i.detail.step,`PAYMENT_STATUS_${n}`),helpText:i.detail.instructions,returnUrl:t.returnUrl}:{};var n}function Nu(e){return"giftcertificate"!==e.providerId&&"storecredit"!==e.providerId}function Lu(e){const t={};return[...e.lineItems.physicalItems,...e.lineItems.digitalItems].forEach(e=>{var i;t[e.id]=(i=e,["fb","tw","gp"].reduce((e,t)=>{const n=i.socialMedia&&l(i.socialMedia,e=>e.code===t);return n?(e[t]={name:i.name,description:i.name,image:i.imageUrl,url:n.link,shareText:n.text,sharingLink:n.link,channelName:n.channel,channelCode:n.code},e):e},{}))}),t}function zu(e,t){return{description:e.description,module:e.type,price:e.cost,id:e.id,selected:t,isRecommended:e.isRecommended,imageUrl:e.imageUrl,transitTime:e.transitTime}}class Uu{constructor(){this._cardExpiryFormatter=new Au,this._cardNumberFormatter=new Tu}transform(e,t){const i=t.billingAddress.getBillingAddress(),n=t.checkout.getCheckout(),o=t.customer.getCustomer(),r=t.order.getOrder(),a=t.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),s=this._mapShippingAddress(t,a),d=t.consignments.getConsignments(),c=t.consignments.getShippingOption(),u=t.config.getStoreConfig(),l=t.config.getContextConfig(),h=t.instruments.getInstrumentsMeta(),p=t.paymentMethods.getPaymentMethodsMeta(),m=t.order.getOrderMeta(),g=o&&i&&Ou(o,i),y=h&&e.paymentData&&(au(e.paymentData)||function(e){const t=e.formattedPayload;return!!t&&("string"==typeof t.bigpay_token||Boolean(t.bigpay_token&&t.bigpay_token.token))}(e.paymentData))?`${t.payment.getPaymentToken()}, ${h.vaultAccessToken}`:t.payment.getPaymentToken();if(!y)throw new qn(xn.MissingPaymentToken);return{additionalAction:e.additionalAction,authToken:y,customer:g,billingAddress:i&&vu(i),shippingAddress:s&&vu(s,d),shippingOption:c&&zu(c,!0),cart:n&&bu(n),order:r&&ku(r,m),orderMeta:m,payment:e.paymentData,paymentMethod:a&&this._transformPaymentMethod(a),quoteMeta:{request:Object.assign(Object.assign({},p),{geoCountryCode:l&&l.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:D(u&&u.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}}transformWithHostedFormData(e,t,i){const{additionalAction:n,authToken:o,checkout:r,config:a,order:s,orderMeta:d,payment:c={},paymentMethod:u,paymentMethodMeta:l}=t,h=r&&r.consignments[0],p=h&&h.shippingAddress,m=h&&h.selectedShippingOption;return{additionalAction:n,authToken:o,paymentMethod:u&&this._transformPaymentMethod(u),customer:s&&s.billingAddress&&r&&Ou(r.customer,s.billingAddress),billingAddress:s&&s.billingAddress&&vu(s.billingAddress),shippingAddress:p&&r&&vu(p,r.consignments),shippingOption:m&&zu(m,!0),cart:r&&bu(r),order:s&&ku(s,d),orderMeta:d,payment:this._transformHostedInputValues(e,c,i),quoteMeta:{request:Object.assign(Object.assign({},l),{geoCountryCode:a&&a.context.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:a&&D(a.storeConfig.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}}_transformPaymentMethod(e){return"multi-option"!==e.method||e.gateway?e.initializationData&&e.initializationData.gateway?Object.assign(Object.assign({},e),{id:e.initializationData.gateway}):e.id===Pu.BRAINTREE_VENMO?Object.assign(Object.assign({},e),{id:Pu.BRAINTREE_PAYPAL}):e:Object.assign(Object.assign({},e),{gateway:e.id})}_transformHostedInputValues(e,t,i){return"instrumentId"in t?Object.assign(Object.assign({},t),{ccCvv:e.cardCodeVerification,ccNumber:e.cardNumberVerification&&this._cardNumberFormatter.unformat(e.cardNumberVerification),hostedFormNonce:i}):Object.assign(Object.assign({},t),{ccCvv:e.cardCode,ccExpiry:this._cardExpiryFormatter.toObject(e.cardExpiry||""),ccName:e.cardName||"",ccNumber:this._cardNumberFormatter.unformat(e.cardNumber||""),hostedFormNonce:i})}_mapShippingAddress(e,t){var i,n,o,r;if(t){const a=null===(n=null===(i=t.initializationData)||void 0===i?void 0:i.bopis)||void 0===n?void 0:n.enabled,s=null===(r=null===(o=t.initializationData)||void 0===o?void 0:o.bopis)||void 0===r?void 0:r.requiredAddress,d=e.consignments.getConsignments(),c=null==d?void 0:d.every(e=>e.selectedPickupOption);if(a&&c&&"none"===s)return}return e.shippingAddress.getShippingAddress()}}class Fu{updatePaymentProviderCustomer(e){return Z(r(Di.UpdatePaymentProviderCustomer,e))}}class Bu{widgetInteraction(e,t){const i={methodId:t&&t.methodId};return H(Z(r(Pi.WidgetInteractionStarted,void 0,i)),V(()=>e().then(()=>r(Pi.WidgetInteractionFinished,void 0,i)))).pipe(J(e=>rc(Pi.WidgetInteractionFailed,e,i)))}}class xu{constructor(e,t){this._remoteCheckoutRequestSender=e,this._checkoutActionCreator=t}initializeBilling(e,t,i){return j.create(n=>{n.next(r(Gi.InitializeRemoteBillingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeBilling(e,t,i).then(({body:t={}})=>{n.next(r(Gi.InitializeRemoteBillingSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Gi.InitializeRemoteBillingFailed,t,{methodId:e}))})})}initializeShipping(e,t,i){return j.create(n=>{n.next(r(Gi.InitializeRemoteShippingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeShipping(e,t,i).then(({body:t={}})=>{n.next(r(Gi.InitializeRemoteShippingSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Gi.InitializeRemoteShippingFailed,t,{methodId:e}))})})}initializePayment(e,t,i){return j.create(n=>{n.next(r(Gi.InitializeRemotePaymentRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializePayment(e,t,i).then(({body:t={}})=>{n.next(r(Gi.InitializeRemotePaymentSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Gi.InitializeRemotePaymentFailed,t,{methodId:e}))})})}loadSettings(e,t){return j.create(i=>{i.next(r(Gi.LoadRemoteSettingsRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.loadSettings(e,t).then(({body:t})=>{i.next(r(Gi.LoadRemoteSettingsSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Gi.LoadRemoteSettingsFailed,t,{methodId:e}))})})}signOut(e,t){return j.create(i=>{i.next(r(Gi.SignOutRemoteCustomerRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.signOut(e,t).then(()=>{i.next(r(Gi.SignOutRemoteCustomerSucceeded,void 0,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Gi.SignOutRemoteCustomerFailed,t,{methodId:e}))})})}forgetCheckout(e,t){return H(Z(r(Gi.ForgetCheckoutRemoteCustomerRequested,void 0,{methodId:e})),V(()=>{return i=this,n=void 0,a=function*(){return yield this._remoteCheckoutRequestSender.forgetCheckout(t),yield this._checkoutActionCreator.loadCurrentCheckout(),r(Gi.ForgetCheckoutRemoteCustomerSucceeded,void 0,{methodId:e})},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(t=>rc(Gi.ForgetCheckoutRemoteCustomerFailed,t,{methodId:e})))}updateCheckout(e,t){return r(Gi.UpdateRemoteCheckout,t,{methodId:e})}}class qu{constructor(e){this._requestSender=e}initializeBilling(e,t,{timeout:i}={}){const n=`/remote-checkout/${e}/billing`;return this._requestSender.get(n,{params:t,timeout:i,headers:nc})}initializeShipping(e,t,{timeout:i}={}){const n=`/remote-checkout/${e}/shipping`;return this._requestSender.get(n,{params:t,timeout:i,headers:nc})}initializePayment(e,t,{timeout:i}={}){const n=`/remote-checkout/${e}/payment`;return this._requestSender.get(n,{params:t,timeout:i,headers:nc})}loadSettings(e,{timeout:t}={}){const i=`/remote-checkout/${e}/settings`;return this._requestSender.get(i,{timeout:t,headers:nc})}signOut(e,{timeout:t}={}){const i=`/remote-checkout/${e}/signout`;return this._requestSender.get(i,{timeout:t,headers:nc})}generateToken({timeout:e}={}){return this._requestSender.get("/remote-checkout-token",{timeout:e,headers:nc})}trackAuthorizationEvent({timeout:e}={}){return this._requestSender.post("/remote-checkout/events/shopper-checkout-service-provider-authorization-requested",{timeout:e,headers:nc})}forgetCheckout({timeout:e}={}){return this._requestSender.post("/remote-checkout/forget-checkout",{timeout:e,headers:nc})}}class ju{constructor(e,t){this._consignmentRequestSender=e,this._checkoutRequestSender=t}unassignItemsByAddress(e,t){return i=>{const n=i.getState();if(!n.checkout.getCheckout())throw new qn(xn.MissingCheckout);const o=this._consignmentHasAddress(e)?e.address:e.shippingAddress,r=n.consignments.getConsignmentByAddress(o);if(!r)throw new Nc("No consignment found for the specified address");const a=this._removeLineItems(e.lineItems,r,n.cart.getCart());return a.length?this.updateConsignment({id:r.id,address:o,lineItems:a},t)(i):this.deleteConsignment(r.id,t)(i)}}assignItemsByAddress(e,t){return i=>{const n=i.getState(),o=this._consignmentHasAddress(e)?e.address:e.shippingAddress,r=n.consignments.getConsignmentByAddress(o);return this._createOrUpdateConsignment({id:r&&r.id,address:o,lineItems:this._addLineItems(e.lineItems,r,n.cart.getCart())},t)(i)}}selectShippingOption(e,t){return i=>j.create(n=>{const o=i.getState(),a=o.checkout.getCheckout(),d=o.consignments.getConsignments();if(!a)throw new qn(xn.MissingCheckout);if(!d||!d.length)throw new qn(xn.MissingConsignments);const c={id:d[0].id,shippingOptionId:e},u={id:d[0].id};n.next(r(Xe.UpdateShippingOptionRequested,void 0,u)),this._consignmentRequestSender.updateConsignment(a.id,c,t).then(({body:e})=>{n.next(r(Xe.UpdateShippingOptionSucceeded,e,u)),n.complete()}).catch(e=>{n.error(s(Xe.UpdateShippingOptionFailed,e,u))})})}loadShippingOptions(e){return t=>j.create(i=>{const n=t.getState().checkout.getCheckout();if(!n)throw new qn(xn.MissingCheckout);i.next(r(Xe.LoadShippingOptionsRequested)),this._checkoutRequestSender.loadCheckout(n.id,Object.assign(Object.assign({},e),{params:{include:[Ic.AvailableShippingOptions]}})).then(({body:e})=>{i.next(r(Xe.LoadShippingOptionsSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Xe.LoadShippingOptionsFailed,e))})})}updateAddress(e,t){return i=>{const n=this._getUpdateAddressRequestBody(e,i),o=i.getState().consignments.getConsignments();return o&&o.length&&(n.id=o[0].id),this._createOrUpdateConsignment(n,t)(i)}}createConsignments(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o||!o.id)throw new qn(xn.MissingCheckout);n.next(r(Xe.CreateConsignmentsRequested)),this._consignmentRequestSender.createConsignments(o.id,e,t).then(({body:e})=>{n.next(r(Xe.CreateConsignmentsSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Xe.CreateConsignmentsFailed,e))})})}updateConsignment(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o||!o.id)throw new qn(xn.MissingCheckout);const a={id:e.id};n.next(r(Xe.UpdateConsignmentRequested,void 0,a)),this._consignmentRequestSender.updateConsignment(o.id,e,t).then(({body:e})=>{n.next(r(Xe.UpdateConsignmentSucceeded,e,a)),n.complete()}).catch(e=>{n.error(s(Xe.UpdateConsignmentFailed,e,a))})})}deleteConsignment(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout(),a={id:e};if(!o||!o.id)throw new qn(xn.MissingCheckout);n.next(r(Xe.DeleteConsignmentRequested,void 0,a)),this._consignmentRequestSender.deleteConsignment(o.id,e,t).then(({body:e})=>{n.next(r(Xe.DeleteConsignmentSucceeded,e,a)),n.complete()}).catch(e=>{n.error(s(Xe.DeleteConsignmentFailed,e,a))})})}updateShippingOption(e,t){return i=>j.create(n=>{var o;const a=i.getState().checkout.getCheckout(),d=i.getState().consignments.getConsignmentById(e.id);if((null===(o=null==d?void 0:d.selectedShippingOption)||void 0===o?void 0:o.id)===e.shippingOptionId)return void n.complete();if(!a||!a.id)throw new qn(xn.MissingCheckout);const c={id:e.id};n.next(r(Xe.UpdateShippingOptionRequested,void 0,c)),this._consignmentRequestSender.updateConsignment(a.id,e,t).then(({body:e})=>{n.next(r(Xe.UpdateShippingOptionSucceeded,e,c)),n.complete()}).catch(e=>{n.error(s(Xe.UpdateShippingOptionFailed,e,c))})})}_createOrUpdateConsignment(e,t){return i=>{const n=i.getState().checkout.getCheckout();if(!n||!n.id)throw new qn(xn.MissingCheckout);return this._isUpdateConsignmentRequest(e)?this.updateConsignment(e,t)(i):this.createConsignments([e],t)(i)}}_getUpdateAddressRequestBody(e,t){const i=t.getState().cart.getCart();if(!i)throw new qn(xn.MissingCart);const{physicalItems:n,customItems:o=[]}=i.lineItems;return{address:e,lineItems:[...n,...o].map(e=>({itemId:e.id,quantity:e.quantity}))}}_removeLineItems(e,t,i){if(!i)throw new qn(xn.MissingCart);return this._hydrateLineItems(t.lineItemIds,i).map(t=>{const i=l(e,e=>e.itemId===t.itemId);return Object.assign(Object.assign({},t),{quantity:i?t.quantity-i.quantity:t.quantity})}).filter(e=>e.quantity>0)}_addLineItems(e,t,i){if(!t)return e;if(!i)throw new qn(xn.MissingCart);return e.concat(this._hydrateLineItems(t.lineItemIds,i)).filter(e=>e.quantity>0)}_hydrateLineItems(e,t){return e.map(e=>{const i=l(t.lineItems.physicalItems,t=>t.id===e);return{itemId:e,quantity:i?i.quantity:0}})}_isUpdateConsignmentRequest(e){return!!e.id}_consignmentHasAddress(e){return"object"==typeof e&&"address"in e}}const Gu=["consignments.availableShippingOptions","cart.lineItems.physicalItems.options","cart.lineItems.physicalItems.stockPosition","cart.lineItems.digitalItems.options","cart.lineItems.digitalItems.stockPosition","customer","promotions.banners"];class Hu{constructor(e){this._requestSender=e}createConsignments(e,t,{timeout:i,params:{include:n}={}}={}){const o=`/api/storefront/checkouts/${e}/consignments`,r=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(o,{body:t,params:{include:mc(Gu,n)},headers:r,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}updateConsignment(e,t,{timeout:i,params:{include:n}={}}={}){const{id:o}=t,r=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["id"]),a=`/api/storefront/checkouts/${e}/consignments/${o}`,s=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.put(a,{body:r,params:{include:mc(Gu,n)},headers:s,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}deleteConsignment(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/consignments/${t}`,o=Object.assign({Accept:tc.JsonV1},nc),r=pc(Gu);return this._requestSender.delete(n,{params:{include:r},headers:o,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class Vu{constructor(e,t){this._shippingCountryRequestSender=e,this._store=t}loadCountries(e){const{checkout:t}=this._store.getState(),i=t.getCheckout(),n=i?i.channelId:null;return j.create(t=>{t.next(r(sn.LoadShippingCountriesRequested)),this._shippingCountryRequestSender.loadCountries(n,e).then(e=>{t.next(r(sn.LoadShippingCountriesSucceeded,e.body.data)),t.complete()}).catch(e=>{t.error(s(sn.LoadShippingCountriesFailed,e))})})}}class Yu{constructor(e,t){this._requestSender=e,this._config=t}loadCountries(e,{timeout:t}={}){const i="/internalapi/v1/shipping/countries"+(e?`?channel_id=${e}`:""),n=Object.assign({"Accept-Language":this._config.locale},nc);return this._requestSender.get(i,{headers:n,timeout:t})}}var Wu=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class $u{constructor(e,t){this._googleRecaptcha=e,this._requestSender=t}initialize(e){return t=>H(Z(r(Nn.InitializeRequested,void 0)),V(()=>Wu(this,void 0,void 0,function*(){const i=e?e.containerId:"spamProtectionContainer";if(document.getElementById(i)&&this._googleRecaptcha.reset(i),!e&&!document.getElementById(i)){const e=document.createElement("div");e.setAttribute("id",i),document.body.appendChild(e)}const n=t.getState().config.getStoreConfigOrThrow().checkoutSettings.googleRecaptchaSitekey;return yield this._googleRecaptcha.load(i,n),r(Nn.InitializeSucceeded)}))).pipe(J(e=>rc(Nn.InitializeFailed,e)))}verifyCheckoutSpamProtection(){return e=>V(()=>{const t=e.getState().checkout.getCheckout();if(!t)throw new qn(xn.MissingCheckout);return H(Z(r(Nn.VerifyCheckoutRequested)),W(this.execute()(e)).pipe(oe(e=>Pc(e)&&e.payload?W(this._requestSender.validate(t.id,e.payload.token)).pipe(oe(({body:t})=>H(Z(e),Z(r(Nn.VerifyCheckoutSucceeded,t))))):Z(e)))).pipe(J(e=>rc(Nn.VerifyCheckoutFailed,e)))})}execute(){return e=>H(Z(r(Nn.ExecuteRequested)),this.initialize()(e),this._googleRecaptcha.execute().pipe(re(1)).pipe(oe(({error:e,token:t})=>Wu(this,void 0,void 0,function*(){if(e instanceof Bc)throw e;if(e||!t)throw new $c;return r(Nn.ExecuteSucceeded,{token:t})})))).pipe(J(e=>rc(Nn.ExecuteFailed,e)))}}class Ku{constructor(e){this._requestSender=e}validate(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/spam-protection`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(n,{body:{token:t},headers:o,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class Zu{constructor(e){this._storeCreditRequestSender=e}applyStoreCredit(e,t){return i=>H(Z(r(En.ApplyStoreCreditRequested)),V(()=>{return n=this,o=void 0,s=function*(){const n=i.getState().checkout.getCheckout();if(!n)throw new qn(xn.MissingCheckout);const{body:o}=yield e?this._storeCreditRequestSender.applyStoreCredit(n.id,t):this._storeCreditRequestSender.removeStoreCredit(n.id,t);return r(En.ApplyStoreCreditSucceeded,o)},new((a=void 0)||(a=Promise))(function(e,t){function i(e){try{d(s.next(e))}catch(e){t(e)}}function r(e){try{d(s.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(i,r)}d((s=s.apply(n,o||[])).next())});var n,o,a,s})).pipe(J(e=>rc(En.ApplyStoreCreditFailed,e)))}}class Qu{constructor(e){this._requestSender=e}applyStoreCredit(e,{timeout:t}={}){const i=`/api/storefront/checkouts/${e}/store-credit`,n=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(i,{headers:n,timeout:t,params:{include:pc(gc)}})}removeStoreCredit(e,{timeout:t}={}){const i=`/api/storefront/checkouts/${e}/store-credit`,n=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.delete(i,{headers:n,timeout:t,params:{include:pc(gc)}})}}class Ju extends Pe{constructor(e){super(e),this.name="UpdateSubscriptionsError",this.type="update_subscriptions"}}class Xu{constructor(e){this._subscriptionsRequestSender=e}updateSubscriptions(e,t){return H(Z(r(ze.UpdateSubscriptionsRequested)),V(()=>{return i=this,n=void 0,a=function*(){const{body:i}=yield this._subscriptionsRequestSender.updateSubscriptions(e,t);return r(ze.UpdateSubscriptionsSucceeded,i)},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(e=>rc(ze.UpdateSubscriptionsFailed,new Ju(e))))}}class el{constructor(e){this._requestSender=e}updateSubscriptions(e,{timeout:t}={}){const i=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post("/api/storefront/subscriptions",{body:e,headers:i,timeout:t})}}const tl=A(e=>Array.isArray(e)?e.map(e=>il(e)):$e(e)?Object.keys(e).reduce((t,i)=>Object.assign(Object.assign({},t),{[i]:il(e[i])}),{}):e);tl.cache=new WeakMap;const il=e=>"object"==typeof e&&null!==e?tl(e):e;function nl(e){return(...t)=>il(e(...t))}function ol({billingAddress:{getBillingAddress:e,getBillingAddressOrThrow:t},cart:{getCart:i,getCartOrThrow:n,getLocale:o},checkout:{getCheckout:r,getCheckoutOrThrow:a,getOutstandingBalance:s},config:{getContextConfig:d,getHost:c,getLocale:u,getStoreConfig:l,getStoreConfigOrThrow:h,getConfig:p},consignments:{getConsignments:m,getConsignmentsOrThrow:g},countries:{getCountries:y},customer:{getCustomer:f,getCustomerOrThrow:v},instruments:{getCardInstrument:S,getCardInstrumentOrThrow:C,getInstruments:I,getInstrumentsMeta:_},order:{getOrder:w,getOrderOrThrow:b,getOrderMeta:E},payment:{getPaymentToken:P,getPaymentTokenOrThrow:O,getPaymentId:A,getPaymentIdOrThrow:T,getPaymentStatus:k,getPaymentStatusOrThrow:R,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:M,isPaymentDataRequired:N},paymentMethods:{getPaymentMethod:L,getPaymentMethodOrThrow:z,getPaymentMethodsMeta:U},paymentProviderCustomer:{getPaymentProviderCustomer:F,getPaymentProviderCustomerOrThrow:B},paymentStrategies:{isInitialized:x},shippingAddress:{getShippingAddress:q,getShippingAddressOrThrow:j,getShippingAddresses:G,getShippingAddressesOrThrow:H},shippingCountries:{getShippingCountries:V}}){return{getHost:nl(c),getLocale:nl(u),getCartLocale:nl(o),getBillingAddress:nl(e),getBillingAddressOrThrow:nl(t),getCart:nl(i),getCartOrThrow:nl(n),getCheckout:nl(r),getCheckoutOrThrow:nl(a),getCountries:nl(y),getStoreConfig:nl(l),getStoreConfigOrThrow:nl(h),getConfig:nl(p),getConsignments:nl(m),getConsignmentsOrThrow:nl(g),getContextConfig:nl(d),getCustomer:nl(f),getCustomerOrThrow:nl(v),getCardInstrument:nl(S),getInstruments:nl(I),getCardInstrumentOrThrow:nl(C),getOrder:nl(w),getOrderOrThrow:nl(b),getOrderMeta:nl(E),getInstrumentsMeta:nl(_),getPaymentToken:P,getPaymentTokenOrThrow:O,getPaymentId:A,getPaymentIdOrThrow:T,getPaymentStatus:k,getPaymentStatusOrThrow:R,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:M,getPaymentMethod:nl(L),getPaymentMethodOrThrow:nl(z),getPaymentMethodsMeta:nl(U),getPaymentProviderCustomer:nl(F),getPaymentProviderCustomerOrThrow:nl(B),getShippingAddress:nl(q),getShippingAddressOrThrow:nl(j),getShippingAddresses:nl(G),getShippingAddressesOrThrow:nl(H),getShippingCountries:nl(V),getOutstandingBalance:nl(s),isPaymentDataRequired:N,isPaymentMethodInitialized:x}}var rl,al=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class sl{constructor(e,t,i,n,o,r,a,s,d,c,u,l,h,p,m,g,y,f,v,S){this._store=e,this._storeProjectionFactory=t,this._checkoutActionCreator=i,this._checkoutValidator=n,this._hostedFormFactory=o,this._orderActionCreator=r,this._billingAddressActionCreator=a,this._consignmentActionCreator=s,this._paymentMethodActionCreator=d,this._paymentActionCreator=c,this._paymentHumanVerificationHandler=u,this._customerActionCreator=l,this._cartRequestSender=h,this._storeCreditActionCreator=p,this._couponActionCreator=m,this._spamProtectionActionCreator=g,this._paymentProviderCustomerActionCreator=y,this._shippingCountryActionCreator=f,this._remoteCheckoutActionCreator=v,this._paymentStrategyWidgetActionCreator=S,this._storeProjection=this._storeProjectionFactory.create(this._store)}createHostedForm(e,t){const i=this._storeProjection.getState().getCheckoutOrThrow().id;return this._hostedFormFactory.create(e,t,i)}subscribe(e,...t){return this._storeProjection.subscribe(e,...t)}getState(){return this._storeProjection.getState()}initializeOffsitePayment(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.initializeOffsitePayment(e)),this._storeProjection.getState()})}loadCheckout(e){return al(this,void 0,void 0,function*(){return e?yield this._store.dispatch(this._checkoutActionCreator.loadCheckout(e)):yield this._store.dispatch(this._checkoutActionCreator.loadCurrentCheckout()),this._storeProjection.getState()})}loadDefaultCheckout(){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()),this._storeProjection.getState()})}loadPaymentMethod(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethod(e,t)),this._storeProjection.getState()})}loadPaymentMethods(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethods(e)),this._storeProjection.getState()})}submitOrder(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.submitOrder(e,t)),this._storeProjection.getState()})}submitPayment(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.submitPayment(e)),this._storeProjection.getState()})}finalizeOrder(e){return al(this,void 0,void 0,function*(){const{order:{getOrderOrThrow:t}}=this._store.getState();return yield this._store.dispatch(this._orderActionCreator.finalizeOrder(t().orderId,e)),this._storeProjection.getState()})}updateBillingAddress(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._billingAddressActionCreator.updateAddress(e)),this._storeProjection.getState()})}updateShippingAddress(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.updateAddress(e)),this._storeProjection.getState()})}selectShippingOption(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.selectShippingOption(e,t)),this._storeProjection.getState()})}signInCustomer(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signInCustomer(e,t)),this._storeProjection.getState()})}signOutCustomer(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signOutCustomer(e)),this._storeProjection.getState()})}createBuyNowCart(e,t){return al(this,void 0,void 0,function*(){const{body:i}=yield this._cartRequestSender.createBuyNowCart(e,t);return i})}applyStoreCredit(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._storeCreditActionCreator.applyStoreCredit(e,t)),this._storeProjection.getState()})}applyCoupon(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.applyCoupon(e,t)),this._storeProjection.getState()})}removeCoupon(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.removeCoupon(e,t)),this._storeProjection.getState()})}verifyCheckoutSpamProtection(){return al(this,void 0,void 0,function*(){const{checkout:e}=this._store.getState(),{shouldExecuteSpamCheck:t}=e.getCheckoutOrThrow();return t&&(yield this._store.dispatch(this._spamProtectionActionCreator.verifyCheckoutSpamProtection())),this._storeProjection.getState()})}loadCurrentOrder(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.loadCurrentOrder(e)),this._storeProjection.getState()})}updatePaymentProviderCustomer(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentProviderCustomerActionCreator.updatePaymentProviderCustomer(e)),this._storeProjection.getState()})}loadShippingCountries(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._shippingCountryActionCreator.loadCountries(e)),this._storeProjection.getState()})}deleteConsignment(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.deleteConsignment(e,t)),this._storeProjection.getState()})}initializePayment(e,t,i){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.initializePayment(e,t,i)),this._storeProjection.getState()})}forgetCheckout(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.forgetCheckout(e,t)),this._storeProjection.getState()})}remoteCheckoutSignOut(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.signOut(e,t)),this._storeProjection.getState()})}validateCheckout(e,t){return al(this,void 0,void 0,function*(){yield this._checkoutValidator.validate(e,t)})}handlePaymentHumanVerification(e,t){return al(this,void 0,void 0,function*(){return"string"==typeof e?this._paymentHumanVerificationHandler.handle(e,null!=t?t:""):this._paymentHumanVerificationHandler.handle(e)})}widgetInteraction(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentStrategyWidgetActionCreator.widgetInteraction(e),{queueId:"widgetInteraction"}),this._storeProjection.getState()})}}!function(e){e.Synchronize="SYNCHRONIZE"}(rl||(rl={}));class dl{constructor(e){this._transformSelectors=e}create(e){return function(e,t){const i=a((e,t)=>t.type===rl.Synchronize?t.payload:e,e.getState(),{stateTransformer:t});return e.subscribe(e=>{i.dispatch(r(rl.Synchronize,e))},{initial:!1}),i}(e,this._transformSelectors)}}const cl=e=>{const t=B(e);return document.getElementById(t)?cl(e):t};function ul(e){return Object.prototype.hasOwnProperty.call(e,"cacheKey")}class ll{constructor(e){this._lastId=0,this._map={maps:[]},this._usedMaps=[],this._options=Object.assign({maxSize:0,isEqual:fe,onExpire:T},e)}getKey(...e){const t=this._resolveMap(...e),{index:i,parentMap:n}=t;let{map:o}=t;return o&&o.cacheKey?o.usedCount++:o=this._generateMap(n,e.slice(i)),this._removeLeastUsedMap(o),o.cacheKey}getUsedCount(...e){const{map:t}=this._resolveMap(...e);return t?t.usedCount:0}_resolveMap(...e){let t=0,i=this._map;for(;i.maps.length;){let n=!1;for(let o=0;o<i.maps.length;o++){const r=i.maps[o];if(this._options.isEqual(r.value,e[t])){if(i.maps.unshift(...i.maps.splice(o,1)),(0===e.length||t===e.length-1)&&ul(r))return{index:t,map:r,parentMap:i};n=!0,i=r,t++;break}}if(!n)break}return{index:t,parentMap:i}}_generateMap(e,t){let i,n=0,o=e;do{i={maps:[],parentMap:o,usedCount:1,value:t[n]},o.maps.unshift(i),o=i,n++}while(n<t.length);const r=i;return r.cacheKey=""+ ++this._lastId,r}_removeLeastUsedMap(e){if(!this._options.maxSize)return;const t=this._usedMaps.indexOf(e);if(this._usedMaps.splice(-1===t?0:t,-1===t?0:1,e),this._usedMaps.length<=this._options.maxSize)return;const i=this._usedMaps.pop();i&&(this._removeMap(i),this._options.onExpire(i.cacheKey))}_removeMap(e){e.parentMap&&(e.parentMap.maps.splice(e.parentMap.maps.indexOf(e),1),function(e){return Object.prototype.hasOwnProperty.call(e,"parentMap")}(e.parentMap)||this._removeMap(e.parentMap))}}function hl(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(i=>{const n=Object.getOwnPropertyDescriptor(e.prototype,i);n&&"constructor"!==i&&Object.defineProperty(t.prototype,i,function(e,t,i){if("function"!=typeof i.value)return i;let n=new ll,o=i.value,r=ae(o);return wa(e,t,{get(){const e=(...e)=>{const t=r.call(this,...e);if(1===n.getUsedCount(...e))return t;const i=o.call(this,...e);return xe(i,t,{keyFilter:e=>!function(e){return 0===`${e}`.indexOf("$$")||0===`${e}`.indexOf("_")}(e)})?t:(r.cache.set(n.getKey(...e),i),i)};return Object.defineProperty(this,t,Object.assign(Object.assign({},i),{value:e})),e},set(e){n=new ll,o=e,r=ae(o)}})}(e.prototype,i,n))}),t}let pl=class{constructor(e){this._checkoutButton=e.checkoutButton}getInitializeButtonError(e){return this._checkoutButton.getInitializeError(e)}getDeinitializeButtonError(e){return this._checkoutButton.getDeinitializeError(e)}};pl=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([hl],pl);const ml=pl;let gl=class{constructor(e){this._checkoutButton=e.checkoutButton}isInitializingButton(e){return this._checkoutButton.isInitializing(e)}isDeinitializingButton(e){return this._checkoutButton.isDeinitializing(e)}};gl=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([hl],gl);const yl=gl;function fl(e){return{errors:new ml(e),statuses:new yl(e)}}let vl=class{constructor(e,t){this._store=e,this._buttonStrategyActionCreator=t,this._state=fl(this._store.getState()),this._store.subscribe(e=>{this._state=fl(e)})}getState(){return this._state}subscribe(e,...t){return this._store.subscribe(()=>e(this.getState()),e=>e.checkoutButton.getState(),...t.map(e=>t=>e(fl(t))))}initializeButton(e){const t=(i=e.containerId,/^\w[\w\-\:\.]*$/.test(i)?[e.containerId]:function(e,t){const i=document.querySelectorAll(e);if(!i.length)throw new Nc(`Unable to find any element with the specified selector: ${e}`);return Array.prototype.slice.call(i).map(e=>(e.id||(e.id=cl(t)),e.id))}(e.containerId,`${e.methodId}-container`));var i;return Promise.all(t.map(t=>{const i=this._buttonStrategyActionCreator.initialize(Object.assign(Object.assign({},e),{containerId:t})),n=`checkoutButtonStrategy:${e.methodId}:${t}`;return this._store.dispatch(i,{queueId:n})})).then(()=>this.getState())}deinitializeButton(e){const t=this._buttonStrategyActionCreator.deinitialize(e),i=`checkoutButtonStrategy:${e.methodId}`;return this._store.dispatch(t,{queueId:i}).then(()=>this.getState())}};vl=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([wa],vl);const Sl=vl;class Cl{constructor(e,t,i){this._registry=e,this._registryV2=t,this._paymentMethodActionCreator=i}initialize(e){return t=>{const i={methodId:e.methodId,containerId:e.containerId};if(t.getState().checkoutButton.isInitialized(e.methodId,e.containerId))return Y();const n=e.currencyCode?{params:{currencyCode:e.currencyCode}}:{},o=Object.assign(Object.assign({},n),{timeout:e.timeout,useCache:!0});return H(Z(r(rt.InitializeButtonRequested,void 0,i)),this._paymentMethodActionCreator.loadPaymentMethod(e.methodId,o)(t),V(()=>this._getStrategy(e.methodId).initialize(e).then(()=>r(rt.InitializeButtonSucceeded,void 0,i)))).pipe(J(e=>rc(rt.InitializeButtonFailed,e,i)))}}deinitialize(e){return t=>{const i={methodId:e.methodId};return t.getState().checkoutButton.isInitialized(e.methodId)?H(Z(r(rt.DeinitializeButtonRequested,void 0,i)),V(()=>this._getStrategy(e.methodId).deinitialize().then(()=>r(rt.DeinitializeButtonSucceeded,void 0,i)))).pipe(J(e=>rc(rt.DeinitializeButtonFailed,e,i))):Y()}}_getStrategy(e){let t;try{t=this._registryV2.get({id:e})}catch(i){t=this._registry.get(e)}return t}}class Il{constructor(e){var t,i,n;this._factories={},this._instances={},this._defaultToken=null!==(t=null==e?void 0:e.defaultToken)&&void 0!==t?t:"default",this._useFallback=null===(i=null==e?void 0:e.useFallback)||void 0===i||i,this._tokenResolver=null!==(n=null==e?void 0:e.tokenResolver)&&void 0!==n?n:e=>e}get(e,t){try{return this._getInstance(e||this._defaultToken,t||e||this._defaultToken)}catch(e){if(!this._useFallback)throw e;return this._getInstance(this._defaultToken,t||this._defaultToken)}}getFactory(e,t){const i=this._tokenResolver(e,Object.keys(this._factories),t);return i?this._factories[i]:void 0}register(e,t){if(this._hasFactory(e))throw new Nc(`'${e}' is already registered.`);this._factories[e]=t}_hasFactory(e){return!!this._factories[e]}_hasInstance(e){return!!this._instances[e]}_getInstance(e,t){if(!this._hasInstance(t)){const i=this.getFactory(e);if(!i)throw new Nc(`'${e}' is not registered.`);this._instances[t]=i()}return this._instances[t]}}class _l extends be{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var wl,bl,El,Pl,Ol;class Al{constructor(e){this._scriptLoader=e,this._window=window}loadPaypal(e=""){return t=this,i=void 0,o=function*(){const t="//www.paypalobjects.com/api/checkout.min.js",i={async:!0,attributes:{"data-merchant-id":e}};if(e?yield this._scriptLoader.loadScript(t,i):yield this._scriptLoader.loadScript(t),!this._window.paypal)throw new _l;return this._window.paypal},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}}!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(wl||(wl={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(bl||(bl={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(El||(El={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Pl||(Pl={})),function(e){e.PILL="pill",e.RECT="rect"}(Ol||(Ol={}));class Tl{constructor(e,t,i,n,o=""){this._store=e,this._checkoutActionCreator=t,this._paypalScriptLoader=i,this._formPoster=n,this._host=o}initialize(e){const t=e.paypal,i=this._store.getState(),n=this._paymentMethod=i.paymentMethods.getPaymentMethod(e.methodId);if(!t)throw new Nc;if(!n)throw new qn(xn.MissingPaymentMethod);return this._paypalScriptLoader.loadPaypal(n.config.merchantId).then(i=>{var o,r;if(!n||!n.config.merchantId)throw new qn(xn.MissingPaymentMethod);const a=n.config.merchantId,s=n.config.testMode?"sandbox":"production",d={[s]:t.clientId},c=i.FUNDING.CREDIT||"credit",u=t.allowCredit?[c]:[],l=t.allowCredit?[]:[c];return i.Button.render({env:s,client:d,commit:t.shouldProcessPayment,funding:{allowed:u,disallowed:l},style:Object.assign(Object.assign({shape:Ol.RECT},D(t.style,"layout","color","label","shape","tagline","fundingicons")),{size:"paypalexpress"===n.id&&"small"===(null===(o=t.style)||void 0===o?void 0:o.size)?bl.RESPONSIVE:null===(r=t.style)||void 0===r?void 0:r.size}),payment:(e,i)=>this._setupPayment(a,i,t.onPaymentError),onAuthorize:(e,i)=>this._tokenizePayment(e,i,t.shouldProcessPayment,t.onAuthorizeError)},e.containerId)})}deinitialize(){return this._paymentMethod=void 0,Promise.resolve()}_setupPayment(e,t,i){if(!t)throw new Wc(jc.CheckoutButtonNotInitialized);return this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()).then(i=>{const n=i.cart.getCart(),o=n?n.id:"";return t.request.post(`${this._host}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:o},{headers:Object.assign({"X-API-INTERNAL":ic},nc)})}).then(e=>e.id).catch(e=>{throw i&&i(e),e})}_tokenizePayment(e,t,i,n){if(!this._paymentMethod)throw new Wc(jc.CheckoutButtonNotInitialized);if(!t)throw new Wc(jc.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new qn(xn.MissingPayment);const o=this._paymentMethod.id;return t.payment.get(e.paymentID).then(t=>{this._formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:o,action:i?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(t.payer.payer_info)})})}}function kl(e){return e&&"resolveIds"in e}function Rl(){try{return"production"}catch(e){return"development"}}class Dl{constructor(e){this._console=e}log(...e){this._logToConsole("log",...e)}info(...e){this._logToConsole("info",...e)}warn(...e){this._logToConsole("warn",...e)}error(...e){this._logToConsole("error",...e)}debug(...e){this._logToConsole("debug",...e)}_logToConsole(e,...t){this._console&&this._console[e]&&this._console[e].call(this._console,...t)}}class Ml{log(){}info(){}warn(){}error(){}debug(){}}const Nl=function(e=!0){return e?new Dl(console):new Ml}("test"!==Rl());class Ll{constructor(e=!1){this._useFallback=e,this._registry=new Il({tokenResolver:this._resolveToken.bind(this),defaultToken:this._encodeToken({default:!0}),useFallback:this._useFallback})}get(e){return this._registry.get(this._encodeToken(e))}getFactory(e,t){try{return this._registry.getFactory(this._encodeToken(e),t)}catch(e){return}}getUseFallback(){return this._useFallback}register(e,t){this._registry.register(this._encodeToken(e),t)}_encodeToken(e){return btoa(JSON.stringify(e))}_decodeToken(e){return JSON.parse(atob(e))}_resolveToken(e,t,i){var n;const o=this._decodeToken(e),r=[];t.forEach(e=>{const t=this._decodeToken(e),i={token:e,matches:0,default:!1};for(const[e,n]of Object.entries(t)){if(e in o&&o[e]!==n){i.matches=0;break}e in o&&o[e]===n&&i.matches++,"default"===e&&!0===n&&(i.default=!0)}r.push(i)});const a=r.sort((e,t)=>t.matches-e.matches).filter(e=>e.matches>0);a.length>1&&a[0].matches===a[1].matches&&"development"===Rl()&&Nl.warn("The provided query matches at least two strategies with the same specificity. This warning can be resolved by making their resolve ID more specific.");const s=a[0];if(i&&(null==s?void 0:s.matches)!==Object.keys(o).length)throw new Error("Unable to resolve to a registered token with the provided token.");if(s&&s.token)return s.token;if(this._useFallback){const e=null===(n=r.find(e=>e.default))||void 0===n?void 0:n.token;if(e)return e}throw new Error("Unable to resolve to a registered token with the provided token.")}}function zl(t){const{host:n}=null!=t?t:{},o=Zn({config:{meta:{host:null==t?void 0:t.host,locale:null==t?void 0:t.locale},errors:{},statuses:{}}}),r=e({host:n}),a=i({host:n}),s=function(e,t){const i=new Ll;for(const[,n]of Object.entries(t))if(kl(n))for(const t of n.resolveIds)i.register(t,()=>n(e));return i}(function(t){const{config:{getHost:i,getLocale:n}}=t.getState(),o=e({host:i()}),r=new dl(ol),a=new hc(new fc(o),new _c(new wc(o)),new Tc(new kc(o))),s=new Cc(new fc(o)),d=new du(t),c=new uu(new gu(o),new Cc(new fc(o))),u=new sc(new uc(o),new Xu(new el(o))),l=new ju(new Hu(o),new fc(o)),h=new Xd(new oc(o)),p=new yu(new fu(function(e){const t=me();return e.subscribe(e=>{const i=e.config.getStoreConfig();i&&t.setHost(i.paymentSettings.bigpayBaseUrl)},e=>e.config.getStoreConfig()),t}(t)),c,new Uu,new Yc(Jc(ue()))),m=new Yc(Jc(ue())),g=new Oc(new Ac(o),a,new $u(Jc(ue()),new Ku(o))),y=new Zu(new Qu(o)),f=new bc(new Ec(o)),v=Jc(ue()),S=new Ku(o),C=new $u(v,S),I=new lc(o),_=new Fu,w=new Vu(new Yu(o,{locale:n()}),t),b=new xu(new qu(o),a),E=new Bu;return new sl(t,r,a,s,d,c,u,l,h,p,m,g,I,y,f,C,_,w,b,E)}(o),Se);return new Sl(o,new Cl(function(e,t,i,n){const o=new Il,r=le(),a=new fc(t),s=new hc(a,new _c(new wc(t)),new Tc(new kc(t)));return o.register(Pu.PAYPALEXPRESS,()=>new Tl(e,s,new Al(r),i,n)),o}(o,r,a,n),s,new Xd(new oc(r))))}export{zl as createCheckoutButtonInitializer,t as createTimeout};
1
+ import{createRequestSender as e,createTimeout as t}from"@bigcommerce/request-sender";import{createFormPoster as i}from"@bigcommerce/form-poster";import{combineReducers as n,composeReducers as o,createAction as r,createDataStore as a,createErrorAction as s,deepFreeze as d}from"@bigcommerce/data-store";import{difference as c,filter as u,find as l,findIndex as h,flatMap as p,identity as m,includes as g,isArray as y,isEmpty as f,isEqual as v,isMatch as S,isNil as C,isObject as I,isPlainObject as _,keyBy as w,keys as b,last as E,map as P,max as O,memoize as A,noop as T,omit as k,omitBy as R,pick as D,pickBy as M,reduce as N,round as L,some as z,transform as U,uniq as F,uniqueId as B,values as x,without as q}from"lodash";import{Observable as j,Subject as G,concat as H,defer as V,empty as Y,from as W,fromEvent as $,merge as K,of as Z,throwError as Q}from"rxjs";import{catchError as J,delay as X,filter as ee,map as te,retryWhen as ie,shareReplay as ne,switchMap as oe,take as re}from"rxjs/operators";import{memoize as ae,memoizeOne as se}from"@bigcommerce/memoize";import{createSelector as de}from"reselect";import{ScriptLoader as ce,createScriptLoader as ue,getScriptLoader as le}from"@bigcommerce/script-loader";import{stringifyUrl as he}from"query-string";import{supportsPopups as pe}from"@braintree/browser-detection";import{createClient as me}from"@bigcommerce/bigpay-client";import{creditCardType as ge,number as ye}from"card-validator";import{default as fe}from"shallowequal";var ve={d:(e,t)=>{for(var i in t)ve.o(t,i)&&!ve.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},Se={};ve.r(Se),ve.d(Se,{createAmazonPayV2ButtonStrategy:()=>Oo,createApplePayButtonStrategy:()=>rr,createBigCommercePaymentsAlternativeMethodsButtonStrategy:()=>Dr,createBigCommercePaymentsButtonStrategy:()=>wr,createBigCommercePaymentsPayLaterButtonStrategy:()=>Tr,createBigCommercePaymentsVenmoButtonStrategy:()=>Lr,createBoltButtonStrategy:()=>Gr,createBraintreePaypalButtonStrategy:()=>da,createBraintreePaypalCreditButtonStrategy:()=>ha,createBraintreeVenmoButtonStrategy:()=>Ia,createBraintreeVisaCheckoutButtonStrategy:()=>ga,createGooglePayAdyenV2ButtonStrategy:()=>rs,createGooglePayAdyenV3ButtonStrategy:()=>as,createGooglePayAuthorizeDotNetButtonStrategy:()=>ds,createGooglePayBigCommercePaymentsButtonStrategy:()=>os,createGooglePayBraintreeButtonStrategy:()=>Ka,createGooglePayCheckoutComButtonStrategy:()=>ps,createGooglePayCybersourceButtonStrategy:()=>gs,createGooglePayOrbitalButtonStrategy:()=>fs,createGooglePayPayPalCommerceButtonStrategy:()=>ts,createGooglePayStripeButtonStrategy:()=>Ns,createGooglePayTdOnlineMartButtonStrategy:()=>xs,createGooglePayWorldpayAccessButtonStrategy:()=>zs,createLinkV2ButtonStrategy:()=>Zd,createPayPalCommerceAlternativeMethodsButtonStrategy:()=>Td,createPayPalCommerceButtonStrategy:()=>nd,createPayPalCommerceCreditButtonStrategy:()=>sd,createPayPalCommerceVenmoButtonStrategy:()=>ud,createPaypalExpressButtonStrategy:()=>Bd});class Ce extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}const Ie={body:{},headers:{},status:0};class _e extends Ce{constructor(e,{message:t,errors:i}={}){const{body:n,headers:o,status:r}=e||Ie;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=n,this.headers=o,this.status=r,this.errors=i||[]}}class we extends _e{constructor(e){super(e,{message:"There is a problem processing your payment. Please try again later."}),this.name="PaymentMethodInvalidError",this.type="payment_method_invalid"}}class be extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}const Ee={body:{},headers:{},status:0};class Pe extends be{constructor(e,{message:t,errors:i}={}){const{body:n,headers:o,status:r}=e||Ee;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=n,this.headers=o,this.status=r,this.errors=i||[]}}class Oe extends Pe{constructor(e,t){super(e,{message:t||"An unexpected error has occurred. The checkout process cannot continue as a result."}),this.name="UnrecoverableError",this.type="unrecoverable"}}function Ae(e){return e.reduce((e,t)=>t?[...e,t]:e,[]).join(" ")}function Te(e,t){const{body:i}=e,{errors:n=[]}=i;return new Pe(e,{message:ke(n)||t,errors:n})}function ke(e){if(Array.isArray(e))return e.reduce((e,t)=>t&&t.message?[...e,t.message]:e,[]).join(" ")}class Re extends Pe{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}class De{constructor(){this._factoryMethods={},this.register("default",(e,t)=>new Pe(e,{message:t})),this.register("internal",(e,t)=>function(e,t){const{body:i}=e,{errors:n=[]}=i;return new Pe(e,{message:Ae(n)||i.detail||i.title||t,errors:n.length?n.map(e=>({code:i.type,message:e})):[{code:i.type,message:i.detail||i.title}]})}(e,t)),this.register("storefront",(e,t)=>function(e,t){const{body:i}=e;return new Pe(e,{message:t||i.detail||i.title,errors:[{code:i.code||i.type,message:i.detail||i.title}]})}(e,t)),this.register("payment",(e,t)=>Te(e,t)),this.register("timeout",e=>new Re(e))}register(e,t){this._factoryMethods[e]=t}createError(e,t){return(this._factoryMethods[this._getType(e)]||this._factoryMethods.default)(e,t)}_getType(e){if(0===e.status)return"timeout";if(this._isStorefrontErrorResponseBody(e.body))return"storefront";if(this._isInternalErrorResponseBody(e.body)){const t=E(e.body.type.split("/"));return t&&this._factoryMethods[t]?t:"internal"}const t=E(e.body&&e.body.errors);return t&&t.code&&this._factoryMethods[t.code]?t.code:"payment"}_isStorefrontErrorResponseBody(e){const t=e;return!this._isInternalErrorResponseBody(e)&&"string"==typeof t.title&&"string"==typeof t.type&&"number"==typeof t.status&&"string"==typeof t.detail}_isInternalErrorResponseBody(e){const t=e;return"object"==typeof t.errors&&"string"==typeof t.title&&"string"==typeof t.type&&"number"==typeof t.status}}var Me,Ne,Le,ze,Ue;function Fe(e,t){return Array.isArray(e)?e.map(e=>Fe(e,t)):_(e)?U(R(e,t),(e,i,n)=>{e[n]=Fe(i,t)},{}):e}function Be(e,t){return function(e){return e.type===Le.ClearError}(t)?Fe(e,e=>e===t.payload):e}function xe(e,t,i){return e===t||(e&&t&&"object"==typeof e&&"object"==typeof t?Array.isArray(e)&&Array.isArray(t)?function(e,t,i){if(e.length!==t.length)return!1;for(let n=0,o=e.length;n<o;n++)if(!xe(e[n],t[n],i))return!1;return!0}(e,t,i):!Array.isArray(e)&&!Array.isArray(t)&&(e instanceof Date&&t instanceof Date?function(e,t){return e.getTime()===t.getTime()}(e,t):!(e instanceof Date||t instanceof Date)&&(e instanceof RegExp&&t instanceof RegExp?function(e,t){return e.toString()===t.toString()}(e,t):!(e instanceof RegExp||t instanceof RegExp)&&function(e,t,i){const n=i&&i.keyFilter,o=n?Object.keys(e).filter(n):Object.keys(e),r=n?Object.keys(t).filter(n):Object.keys(t);if(o.length!==r.length)return!1;for(let n=0,r=o.length;n<r;n++){const r=o[n];if(!Object.prototype.hasOwnProperty.call(t,r))return!1;if(!xe(e[r],t[r],i))return!1}return!0}(e,t,i))):e===t)}function qe(e,t){return void 0===t||xe(e,t)?e:t}function je(e,t,i){return e&&Object.prototype.hasOwnProperty.call(e,t)&&xe(e[t],i)?e:Object.assign(Object.assign({},e),{[t]:i})}!function(e){e.LoadCheckoutRequested="LOAD_CHECKOUT_REQUESTED",e.LoadCheckoutSucceeded="LOAD_CHECKOUT_SUCCEEDED",e.LoadCheckoutFailed="LOAD_CHECKOUT_FAILED",e.UpdateCheckoutRequested="UPDATE_CHECKOUT_REQUESTED",e.UpdateCheckoutSucceeded="UPDATE_CHECKOUT_SUCCEEDED",e.UpdateCheckoutFailed="UPDATE_CHECKOUT_FAILED"}(Me||(Me={})),function(e){e.HydrateInitialState="HYDRATE_INITIAL_STATE"}(Ne||(Ne={})),function(e){e.ClearError="CLEAR_ERROR"}(Le||(Le={})),function(e){e.UpdateSubscriptionsRequested="UPDATE_SUBSCRIPTIONS_REQUESTED",e.UpdateSubscriptionsSucceeded="UPDATE_SUBSCRIPTIONS_SUCCEEDED",e.UpdateSubscriptionsFailed="UPDATE_SUBSCRIPTIONS_FAILED"}(ze||(ze={})),function(e){e.UpdateBillingAddressRequested="UPDATE_BILLING_ADDRESS_REQUESTED",e.UpdateBillingAddressSucceeded="UPDATE_BILLING_ADDRESS_SUCCEEDED",e.UpdateBillingAddressFailed="UPDATE_BILLING_ADDRESS_FAILED",e.ContinueAsGuestRequested="CONTINUE_AS_GUEST_REQUESTED",e.ContinueAsGuestSucceeded="CONTINUE_AS_GUEST_SUCCEEDED",e.ContinueAsGuestFailed="CONTINUE_AS_GUEST_FAILED"}(Ue||(Ue={}));const Ge={errors:{},statuses:{}};function He(e=Ge,t){return n({data:Ve,errors:o(Ye,Be),statuses:We})(e,t)}function Ve(e,t){var i,n;switch(t.type){case Ue.UpdateBillingAddressSucceeded:case Ue.ContinueAsGuestSucceeded:case Me.LoadCheckoutSucceeded:return qe(e,t.payload&&t.payload.billingAddress);case Ne.HydrateInitialState:return qe(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.billingAddress);default:return e}}function Ye(e=Ge.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:return je(e,"loadError",t.payload);case Ue.UpdateBillingAddressRequested:case Ue.UpdateBillingAddressSucceeded:return je(e,"updateError",void 0);case Ue.UpdateBillingAddressFailed:return je(e,"updateError",t.payload);case ze.UpdateSubscriptionsRequested:case ze.UpdateSubscriptionsSucceeded:case Ue.ContinueAsGuestRequested:case Ue.ContinueAsGuestSucceeded:return je(e,"continueAsGuestError",void 0);case ze.UpdateSubscriptionsFailed:case Ue.ContinueAsGuestFailed:return je(e,"continueAsGuestError",t.payload);default:return e}}function We(e=Ge.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Me.LoadCheckoutSucceeded:case Me.LoadCheckoutFailed:return je(e,"isLoading",!1);case Ue.UpdateBillingAddressRequested:return je(e,"isUpdating",!0);case Ue.UpdateBillingAddressFailed:case Ue.UpdateBillingAddressSucceeded:return je(e,"isUpdating",!1);case Ue.ContinueAsGuestRequested:case ze.UpdateSubscriptionsRequested:return je(e,"isContinuingAsGuest",!0);case ze.UpdateSubscriptionsSucceeded:case ze.UpdateSubscriptionsFailed:case Ue.ContinueAsGuestFailed:case Ue.ContinueAsGuestSucceeded:return je(e,"isContinuingAsGuest",!1);default:return e}}function $e(e){return _(e)}const Ke=function e(t,i,n){const{matchObject:o=(e,t)=>void 0!==e.id&&e.id===t.id}=n||{};if(!t)return i;if(!i||t===i)return t;let r=0,a=0;const s=(e,t,i)=>(r+=e===t?1:0,a+=e===i?1:0,e),d=i.map((i,n)=>{const r=t&&t[n];return $e(r)&&$e(i)?o(r,i)?s(Ze(r,i),r,i):s(qe(r,i),r,i):y(r)&&y(i)?s(e(r,i),r,i):s(qe(r,i),r,i)});return r===i.length&&t&&t.length===i.length?t:a===i.length?i:d},Ze=function e(t,i){return t?i&&t!==i?Object.keys(i).reduce((t,n)=>{const o=t[n],r=i[n];return $e(o)&&$e(r)?je(t,n,e(o,r)):y(o)&&y(r)?je(t,n,Ke(o,r)):je(t,n,r)},t):t:i};var Qe,Je,Xe;!function(e){e.ApplyCouponRequested="APPLY_COUPON_REQUESTED",e.ApplyCouponSucceeded="APPLY_COUPON_SUCCEEDED",e.ApplyCouponFailed="APPLY_COUPON_FAILED",e.RemoveCouponRequested="REMOVE_COUPON_REQUESTED",e.RemoveCouponSucceeded="REMOVE_COUPON_SUCCEEDED",e.RemoveCouponFailed="REMOVE_COUPON_FAILED"}(Qe||(Qe={})),function(e){e.ApplyGiftCertificateRequested="APPLY_GIFT_CERTIFICATE_REQUESTED",e.ApplyGiftCertificateSucceeded="APPLY_GIFT_CERTIFICATE_SUCCEEDED",e.ApplyGiftCertificateFailed="APPLY_GIFT_CERTIFICATE_FAILED",e.RemoveGiftCertificateRequested="REMOVE_GIFT_CERTIFICATE_REQUESTED",e.RemoveGiftCertificateSucceeded="REMOVE_GIFT_CERTIFICATE_SUCCEEDED",e.RemoveGiftCertificateFailed="REMOVE_GIFT_CERTIFICATE_FAILED"}(Je||(Je={})),function(e){e.CreateConsignmentsRequested="CREATE_CONSIGNMENTS_REQUESTED",e.CreateConsignmentsSucceeded="CREATE_CONSIGNMENTS_SUCCEEDED",e.CreateConsignmentsFailed="CREATE_CONSIGNMENTS_FAILED",e.UpdateConsignmentRequested="UPDATE_CONSIGNMENT_REQUESTED",e.UpdateConsignmentSucceeded="UPDATE_CONSIGNMENT_SUCCEEDED",e.UpdateConsignmentFailed="UPDATE_CONSIGNMENT_FAILED",e.DeleteConsignmentRequested="DELETE_CONSIGNMENT_REQUESTED",e.DeleteConsignmentSucceeded="DELETE_CONSIGNMENT_SUCCEEDED",e.DeleteConsignmentFailed="DELETE_CONSIGNMENT_FAILED",e.UpdateShippingOptionRequested="UPDATE_SHIPPING_OPTION_REQUESTED",e.UpdateShippingOptionSucceeded="UPDATE_SHIPPING_OPTION_SUCCEEDED",e.UpdateShippingOptionFailed="UPDATE_SHIPPING_OPTION_FAILED",e.LoadShippingOptionsRequested="LOAD_SHIPPING_OPTIONS_REQUESTED",e.LoadShippingOptionsSucceeded="LOAD_SHIPPING_OPTIONS_SUCCEEDED",e.LoadShippingOptionsFailed="LOAD_SHIPPING_OPTIONS_FAILED"}(Xe||(Xe={}));const et={errors:{},statuses:{}};function tt(e=et,t){return n({data:it,errors:o(ot,Be),statuses:nt})(e,t)}function it(e,t){var i,n;switch(t.type){case Ue.UpdateBillingAddressSucceeded:case Me.LoadCheckoutSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Xe.LoadShippingOptionsSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Ze(e,t.payload&&t.payload.cart);case Ne.HydrateInitialState:return Ze(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.cart);default:return e}}function nt(e=et.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Me.LoadCheckoutFailed:case Me.LoadCheckoutSucceeded:return je(e,"isLoading",!1);default:return e}}function ot(e=et.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:return je(e,"loadError",t.payload);default:return e}}var rt;!function(e){e.InitializeButtonFailed="INITIALIZE_BUTTON_FAILED",e.InitializeButtonRequested="INITIALIZE_BUTTON_REQUESTED",e.InitializeButtonSucceeded="INITIALIZE_BUTTON_SUCCEEDED",e.DeinitializeButtonFailed="DEINITIALIZE_BUTTON_FAILED",e.DeinitializeButtonRequested="DEINITIALIZE_BUTTON_REQUESTED",e.DeinitializeButtonSucceeded="DEINITIALIZE_BUTTON_SUCCEEDED"}(rt||(rt={}));const at={data:{},errors:{},statuses:{}},st={initializedContainers:{}},dt={},ct={};function ut(e=at,t){return t.meta&&t.meta.methodId?n({data:n({[t.meta.methodId]:lt}),errors:n({[t.meta.methodId]:ht}),statuses:n({[t.meta.methodId]:pt})})(e,t):e}function lt(e=st,t){switch(t.type){case rt.InitializeButtonSucceeded:return t.meta&&t.meta.containerId?Ze(e,{initializedContainers:{[t.meta.containerId]:!0}}):e;case rt.DeinitializeButtonSucceeded:return je(e,"initializedContainers",{})}return e}function ht(e=dt,t){switch(t.type){case rt.InitializeButtonRequested:case rt.InitializeButtonSucceeded:return je(e,"initializeError",void 0);case rt.InitializeButtonFailed:return je(e,"initializeError",t.payload);case rt.DeinitializeButtonRequested:case rt.DeinitializeButtonSucceeded:return je(e,"deinitializeError",void 0);case rt.DeinitializeButtonFailed:return je(e,"deinitializeError",t.payload);default:return e}}function pt(e=ct,t){switch(t.type){case rt.InitializeButtonRequested:return je(e,"isInitializing",!0);case rt.InitializeButtonFailed:case rt.InitializeButtonSucceeded:return je(e,"isInitializing",!1);case rt.DeinitializeButtonRequested:return je(e,"isDeinitializing",!0);case rt.DeinitializeButtonFailed:case rt.DeinitializeButtonSucceeded:return je(e,"isDeinitializing",!1);default:return e}}var mt;!function(e){e.LoadConfigRequested="LOAD_CONFIG_REQUESTED",e.LoadConfigSucceeded="LOAD_CONFIG_SUCCEEDED",e.LoadConfigFailed="LOAD_CONFIG_FAILED"}(mt||(mt={}));const gt={meta:{},errors:{},statuses:{}};function yt(e=gt,t){return n({data:ft,errors:o(vt,Be),statuses:St})(e,t)}function ft(e,t){var i;switch(t.type){case mt.LoadConfigSucceeded:return Ze(e,t.payload);case Ne.HydrateInitialState:return Ze(e,null===(i=t.payload)||void 0===i?void 0:i.config);default:return e}}function vt(e=gt.errors,t){switch(t.type){case mt.LoadConfigSucceeded:return je(e,"loadError",void 0);case mt.LoadConfigFailed:return je(e,"loadError",t.payload);default:return e}}function St(e=gt.statuses,t){switch(t.type){case mt.LoadConfigRequested:return je(e,"isLoading",!0);case mt.LoadConfigSucceeded:case mt.LoadConfigFailed:return je(e,"isLoading",!1);default:return e}}var Ct;!function(e){e.LoadOrderRequested="LOAD_ORDER_REQUESTED",e.LoadOrderSucceeded="LOAD_ORDER_SUCCEEDED",e.LoadOrderFailed="LOAD_ORDER_FAILED",e.LoadOrderPaymentsRequested="LOAD_ORDER_PAYMENTS_REQUESTED",e.LoadOrderPaymentsSucceeded="LOAD_ORDER_PAYMENTS_SUCCEEDED",e.LoadOrderPaymentsFailed="LOAD_ORDER_PAYMENTS_FAILED",e.SubmitOrderRequested="SUBMIT_ORDER_REQUESTED",e.SubmitOrderSucceeded="SUBMIT_ORDER_SUCCEEDED",e.SubmitOrderFailed="SUBMIT_ORDER_FAILED",e.FinalizeOrderRequested="FINALIZE_ORDER_REQUESTED",e.FinalizeOrderSucceeded="FINALIZE_ORDER_SUCCEEDED",e.FinalizeOrderFailed="FINALIZE_ORDER_FAILED"}(Ct||(Ct={}));const It={errors:{},statuses:{}};function _t(e=It,t){return n({data:wt,errors:o(bt,Be),statuses:Et})(e,t)}function wt(e,t){var i,n;switch(t.type){case Me.LoadCheckoutSucceeded:case Qe.ApplyCouponSucceeded:case Xe.UpdateShippingOptionSucceeded:case Qe.RemoveCouponSucceeded:case Ct.LoadOrderSucceeded:return Ke(e,t.payload&&t.payload.coupons);case Ne.HydrateInitialState:return Ke(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.coupons);default:return e}}function bt(e={},t){switch(t.type){case Qe.ApplyCouponRequested:case Qe.ApplyCouponSucceeded:return je(e,"applyCouponError",void 0);case Qe.ApplyCouponFailed:return je(e,"applyCouponError",t.payload);case Qe.RemoveCouponRequested:case Qe.RemoveCouponSucceeded:return je(e,"removeCouponError",void 0);case Qe.RemoveCouponFailed:return je(e,"removeCouponError",t.payload);default:return e}}function Et(e={},t){switch(t.type){case Qe.ApplyCouponRequested:return je(e,"isApplyingCoupon",!0);case Qe.ApplyCouponSucceeded:case Qe.ApplyCouponFailed:return je(e,"isApplyingCoupon",!1);case Qe.RemoveCouponRequested:return je(e,"isRemovingCoupon",!0);case Qe.RemoveCouponSucceeded:case Qe.RemoveCouponFailed:return je(e,"isRemovingCoupon",!1);default:return e}}const Pt={errors:{},statuses:{}};function Ot(e=Pt,t){return n({data:At,errors:o(Tt,Be),statuses:kt})(e,t)}function At(e,t){var i,n;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Ke(e,t.payload&&t.payload.giftCertificates);case Ne.HydrateInitialState:return Ke(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.giftCertificates);default:return e}}function Tt(e=Pt.errors,t){switch(t.type){case Je.ApplyGiftCertificateRequested:case Je.ApplyGiftCertificateSucceeded:return je(e,"applyGiftCertificateError",void 0);case Je.ApplyGiftCertificateFailed:return je(e,"applyGiftCertificateError",t.payload);case Je.RemoveGiftCertificateRequested:case Je.RemoveGiftCertificateSucceeded:return je(e,"removeGiftCertificateError",void 0);case Je.RemoveGiftCertificateFailed:return je(e,"removeGiftCertificateError",t.payload);default:return e}}function kt(e=Pt.statuses,t){switch(t.type){case Je.ApplyGiftCertificateRequested:return je(e,"isApplyingGiftCertificate",!0);case Je.ApplyGiftCertificateSucceeded:case Je.ApplyGiftCertificateFailed:return je(e,"isApplyingGiftCertificate",!1);case Je.RemoveGiftCertificateRequested:return je(e,"isRemovingGiftCertificate",!0);case Je.RemoveGiftCertificateSucceeded:case Je.RemoveGiftCertificateFailed:return je(e,"isRemovingGiftCertificate",!1);default:return e}}var Rt;!function(e){e.SignInCustomerRequested="SIGN_IN_CUSTOMER_REQUESTED",e.SignInCustomerSucceeded="SIGN_IN_CUSTOMER_SUCCEEDED",e.SignInCustomerFailed="SIGN_IN_CUSTOMER_FAILED",e.SignOutCustomerRequested="SIGN_OUT_CUSTOMER_REQUESTED",e.SignOutCustomerSucceeded="SIGN_OUT_CUSTOMER_SUCCEEDED",e.SignOutCustomerFailed="SIGN_OUT_CUSTOMER_FAILED",e.CreateCustomerRequested="CREATE_CUSTOMER_REQUESTED",e.CreateCustomerSucceeded="CREATE_CUSTOMER_SUCCEEDED",e.CreateCustomerFailed="CREATE_CUSTOMER_FAILED",e.CreateCustomerAddressRequested="CREATE_CUSTOMER_ADDRESS_REQUESTED",e.CreateCustomerAddressSucceeded="CREATE_CUSTOMER_ADDRESS_SUCCEEDED",e.CreateCustomerAddressFailed="CREATE_CUSTOMER_ADDRESS_FAILED",e.StripeLinkAuthenticated="STRIPE_LINK_AUTHENTICATED"}(Rt||(Rt={}));const Dt={errors:{},statuses:{}};function Mt(e=Dt,t){return n({data:Nt,errors:o(Lt,Be),statuses:zt})(e,t)}function Nt(e,t){var i,n;switch(t.type){case Ue.ContinueAsGuestSucceeded:case Me.LoadCheckoutSucceeded:return Ze(e,t.payload&&t.payload.customer);case Rt.CreateCustomerAddressSucceeded:return Ze(e,t.payload);case Ne.HydrateInitialState:return Ze(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.customer);default:return e}}function Lt(e=Dt.errors,t){switch(t.type){case Rt.CreateCustomerRequested:case Rt.CreateCustomerSucceeded:return je(e,"createError",void 0);case Rt.CreateCustomerFailed:return je(e,"createError",t.payload);case Rt.CreateCustomerAddressRequested:case Rt.CreateCustomerAddressSucceeded:return je(e,"createAddressError",void 0);case Rt.CreateCustomerAddressFailed:return je(e,"createAddressError",t.payload);default:return e}}function zt(e=Dt.statuses,t){switch(t.type){case Rt.CreateCustomerRequested:return je(e,"isCreating",!0);case Rt.CreateCustomerFailed:case Rt.CreateCustomerSucceeded:return je(e,"isCreating",!1);case Rt.CreateCustomerAddressRequested:return je(e,"isCreatingAddress",!0);case Rt.CreateCustomerAddressFailed:case Rt.CreateCustomerAddressSucceeded:return je(e,"isCreatingAddress",!1);default:return e}}var Ut;!function(e){e.SignInFailed="CUSTOMER_STRATEGY_SIGN_IN_FAILED",e.SignInRequested="CUSTOMER_STRATEGY_SIGN_IN_REQUESTED",e.SignInSucceeded="CUSTOMER_STRATEGY_SIGN_IN_SUCCEEDED",e.SignOutFailed="CUSTOMER_STRATEGY_SIGN_OUT_FAILED",e.SignOutRequested="CUSTOMER_STRATEGY_SIGN_OUT_REQUESTED",e.SignOutSucceeded="CUSTOMER_STRATEGY_SIGN_OUT_SUCCEEDED",e.ExecutePaymentMethodCheckoutFailed="CUSTOMER_STRATEGY_EXECUTE_PAYMENT_METHOD_CHECKOUT_FAILED",e.ExecutePaymentMethodCheckoutRequested="CUSTOMER_STRATEGY_EXECUTE_PAYMENT_METHOD_CHECKOUT_REQUESTED",e.ExecutePaymentMethodCheckoutSucceeded="CUSTOMER_STRATEGY_EXECUTE_PAYMENT_METHOD_CHECKOUT_SUCCEEDED",e.InitializeFailed="CUSTOMER_STRATEGY_INITIALIZE_FAILED",e.InitializeRequested="CUSTOMER_STRATEGY_INITIALIZE_REQUESTED",e.InitializeSucceeded="CUSTOMER_STRATEGY_INITIALIZE_SUCCEEDED",e.DeinitializeFailed="CUSTOMER_STRATEGY_DEINITIALIZE_FAILED",e.DeinitializeRequested="CUSTOMER_STRATEGY_DEINITIALIZE_REQUESTED",e.DeinitializeSucceeded="CUSTOMER_STRATEGY_DEINITIALIZE_SUCCEEDED",e.WidgetInteractionStarted="CUSTOMER_STRATEGY_WIDGET_INTERACTION_STARTED",e.WidgetInteractionFinished="CUSTOMER_STRATEGY_WIDGET_INTERACTION_FINISHED",e.WidgetInteractionFailed="CUSTOMER_STRATEGY_WIDGET_INTERACTION_FAILED"}(Ut||(Ut={}));const Ft={data:{},errors:{},statuses:{}};function Bt(e=Ft,t){return n({data:xt,errors:o(qt,Be),statuses:jt})(e,t)}function xt(e=Ft.data,t){switch(t.type){case Ut.InitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case Ut.DeinitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!1}})}return e}function qt(e=Ft.errors,t){switch(t.type){case Ut.InitializeRequested:case Ut.InitializeSucceeded:return Ze(e,{initializeErrors:Object.assign({},e.initializeErrors),initializeMethodId:e.initializeMethodId?e.initializeMethodId:void 0});case Ut.InitializeFailed:return Ze(e,{initializeErrors:Object.assign(Object.assign({},e.initializeErrors),{[t.meta&&t.meta.methodId]:t.payload}),initializeMethodId:t.meta&&t.meta.methodId});case Ut.DeinitializeRequested:case Ut.DeinitializeSucceeded:return Ze(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case Ut.DeinitializeFailed:return Ze(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.SignInRequested:case Ut.SignInSucceeded:return Ze(e,{signInError:void 0,signInMethodId:void 0});case Ut.SignInFailed:return Ze(e,{signInError:t.payload,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignOutRequested:case Ut.SignOutSucceeded:return Ze(e,{signOutError:void 0,signOutMethodId:void 0});case Ut.SignOutFailed:return Ze(e,{signOutError:t.payload,signOutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutRequested:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Ze(e,{executePaymentMethodCheckoutError:void 0,executePaymentMethodCheckoutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutFailed:return Ze(e,{executePaymentMethodCheckoutError:t.payload,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.WidgetInteractionStarted:case Ut.WidgetInteractionFinished:return Ze(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case Ut.WidgetInteractionFailed:return Ze(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function jt(e=Ft.statuses,t){switch(t.type){case Ut.InitializeRequested:return Ze(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case Ut.InitializeFailed:case Ut.InitializeSucceeded:return Ze(e,{isInitializing:!1,initializeMethodId:void 0});case Ut.DeinitializeRequested:return Ze(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.DeinitializeFailed:case Ut.DeinitializeSucceeded:return Ze(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case Ut.SignInRequested:return Ze(e,{isSigningIn:!0,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignInFailed:case Ut.SignInSucceeded:return Ze(e,{isSigningIn:!1,signInMethodId:void 0});case Ut.SignOutRequested:return Ze(e,{isSigningOut:!0,signOutMethodId:t.meta&&t.meta.methodId});case Ut.SignOutFailed:case Ut.SignOutSucceeded:return Ze(e,{isSigningOut:!1,signOutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutRequested:return Ze(e,{isExecutingPaymentMethodCheckout:!0,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutFailed:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Ze(e,{isExecutingPaymentMethodCheckout:!1,executePaymentMethodCheckoutMethodId:void 0});case Ut.WidgetInteractionStarted:return Ze(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case Ut.WidgetInteractionFinished:case Ut.WidgetInteractionFailed:return Ze(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Gt;!function(e){e.LoadExtensionsRequested="LOAD_EXTENSIONS_REQUESTED",e.LoadExtensionsSucceeded="LOAD_EXTENSIONS_SUCCEEDED",e.LoadExtensionsFailed="LOAD_EXTENSIONS_FAILED",e.RenderExtensionRequested="RENDER_EXTENSION_REQUESTED",e.RenderExtensionSucceeded="RENDER_EXTENSION_SUCCEEDED",e.RenderExtensionFailed="RENDER_EXTENSION_FAILED"}(Gt||(Gt={}));const Ht={errors:{},statuses:{}};function Vt(e=Ht,t){return n({data:Yt,errors:o(Wt,Be),statuses:$t})(e,t)}function Yt(e,t){var i;return t.type===Gt.LoadExtensionsSucceeded?Ke(e,t.payload):t.type===Ne.HydrateInitialState?Ke(e,null===(i=t.payload)||void 0===i?void 0:i.extensions):e}function Wt(e=Ht.errors,t){switch(t.type){case Gt.LoadExtensionsRequested:case Gt.LoadExtensionsSucceeded:return je(e,"loadError",void 0);case Gt.RenderExtensionRequested:case Gt.RenderExtensionSucceeded:return je(e,"renderError",void 0);case Gt.LoadExtensionsFailed:return je(e,"loadError",t.payload);case Gt.RenderExtensionFailed:return je(e,"renderError",t.payload);default:return e}}function $t(e=Ht.statuses,t){switch(t.type){case Gt.LoadExtensionsRequested:return je(e,"isLoading",!0);case Gt.LoadExtensionsSucceeded:case Gt.LoadExtensionsFailed:return je(e,"isLoading",!1);default:return e}}var Kt;!function(e){e.LoadFormFieldsRequested="LOAD_FORM_FIELDS_REQUESTED",e.LoadFormFieldsSucceeded="LOAD_FORM_FIELDS_SUCCEEDED",e.LoadFormFieldsFailed="LOAD_FORM_FIELDS_FAILED"}(Kt||(Kt={}));const Zt={errors:{},statuses:{}};function Qt(e=Zt,t){return n({data:Jt,errors:o(Xt,Be),statuses:ei})(e,t)}function Jt(e,t){var i;switch(t.type){case Kt.LoadFormFieldsSucceeded:return Ze(e,t.payload);case Ne.HydrateInitialState:return Ze(e,null===(i=t.payload)||void 0===i?void 0:i.formFields);default:return e}}function Xt(e=Zt.errors,t){switch(t.type){case Kt.LoadFormFieldsSucceeded:return je(e,"loadError",void 0);case Kt.LoadFormFieldsFailed:return je(e,"loadError",t.payload);default:return e}}function ei(e=Zt.statuses,t){switch(t.type){case Kt.LoadFormFieldsRequested:return je(e,"isLoading",!0);case Kt.LoadFormFieldsSucceeded:case Kt.LoadFormFieldsFailed:return je(e,"isLoading",!1);default:return e}}var ti;!function(e){e.LoadCountriesRequested="LOAD_COUNTRIES_REQUESTED",e.LoadCountriesSucceeded="LOAD_COUNTRIES_SUCCEEDED",e.LoadCountriesFailed="LOAD_COUNTRIES_FAILED"}(ti||(ti={}));const ii={errors:{},statuses:{}};function ni(e=ii,t){return n({data:oi,errors:o(ri,Be),statuses:ai})(e,t)}function oi(e,t){return t.type===ti.LoadCountriesSucceeded?Ke(e,t.payload):e}function ri(e=ii.errors,t){switch(t.type){case ti.LoadCountriesRequested:case ti.LoadCountriesSucceeded:return je(e,"loadError",void 0);case ti.LoadCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function ai(e=ii.statuses,t){switch(t.type){case ti.LoadCountriesRequested:return je(e,"isLoading",!0);case ti.LoadCountriesSucceeded:case ti.LoadCountriesFailed:return je(e,"isLoading",!1);default:return e}}const si={errors:{},meta:{},statuses:{}};function di(e=si,t){return n({data:ci,errors:o(li,Be),meta:ui,statuses:hi})(e,t)}function ci(e,t){switch(t.type){case Ct.LoadOrderSucceeded:case Ct.LoadOrderPaymentsSucceeded:return Ze(e,k(t.payload,["billingAddress","coupons"]));default:return e}}function ui(e,t){switch(t.type){case Ct.FinalizeOrderSucceeded:case Ct.SubmitOrderSucceeded:return Ze(e,Object.assign(Object.assign({},t.meta),{callbackUrl:t.payload&&t.payload.order.callbackUrl,orderToken:t.payload&&t.payload.order.token,payment:t.payload&&t.payload.order&&t.payload.order.payment}));default:return e}}function li(e=si.errors,t){switch(t.type){case Ct.LoadOrderRequested:case Ct.LoadOrderSucceeded:case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderPaymentsRequested:return je(e,"loadError",void 0);case Ct.LoadOrderFailed:case Ct.LoadOrderPaymentsFailed:return je(e,"loadError",t.payload);default:return e}}function hi(e=si.statuses,t){switch(t.type){case Ct.LoadOrderRequested:case Ct.LoadOrderPaymentsRequested:return je(e,"isLoading",!0);case Ct.LoadOrderSucceeded:case Ct.LoadOrderFailed:case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderPaymentsFailed:return je(e,"isLoading",!1);default:return e}}const pi={};function mi(e=pi,t){return n({data:gi})(e,t)}function gi(e,t){switch(t.type){case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderSucceeded:return qe(e,t.payload&&t.payload.billingAddress);default:return e}}var yi,fi;function vi(e={},t){return n({data:Si})(e,t)}function Si(e,t){return t.type===yi.SubmitPaymentSucceeded?t.payload:e}!function(e){e.SubmitPaymentRequested="SUBMIT_PAYMENT_REQUESTED",e.SubmitPaymentSucceeded="SUBMIT_PAYMENT_SUCCEEDED",e.SubmitPaymentFailed="SUBMIT_PAYMENT_FAILED",e.InitializeOffsitePaymentRequested="INITIALIZE_OFFSITE_PAYMENT_REQUESTED",e.InitializeOffsitePaymentSucceeded="INITIALIZE_OFFSITE_PAYMENT_SUCCEEDED",e.InitializeOffsitePaymentFailed="INITIALIZE_OFFSITE_PAYMENT_FAILED"}(yi||(yi={})),function(e){e.LoadPaymentMethodRequested="LOAD_PAYMENT_METHOD_REQUESTED",e.LoadPaymentMethodSucceeded="LOAD_PAYMENT_METHOD_SUCCEEDED",e.LoadPaymentMethodFailed="LOAD_PAYMENT_METHOD_FAILED",e.LoadPaymentMethodsRequested="LOAD_PAYMENT_METHODS_REQUESTED",e.LoadPaymentMethodsSucceeded="LOAD_PAYMENT_METHODS_SUCCEEDED",e.LoadPaymentMethodsFailed="LOAD_PAYMENT_METHODS_FAILED"}(fi||(fi={}));const Ci={errors:{},statuses:{}};function Ii(e=Ci,t){return n({data:_i,errors:o(bi,Be),meta:wi,statuses:Ei})(e,t)}function _i(e,t){switch(t.type){case fi.LoadPaymentMethodSucceeded:return function(e,t,i){if(!t)return e;const n=D(t,"id"),o="object"==typeof i?M(i):i||n,r=h(e,o),a=[...e];if(-1===r)a.push(t);else{const i=e[r];a[r]=$e(i)&&$e(t)?Ze(i,t):t}return a}(e||[],t.payload,t.payload&&{id:t.payload.id,gateway:t.payload.gateway});case fi.LoadPaymentMethodsSucceeded:return Ke(e,t.payload,{matchObject:(e,t)=>e.id===t.id&&e.gateway===t.gateway});default:return e}}function wi(e,t){return t.type===fi.LoadPaymentMethodsSucceeded?Ze(e,t.meta):e}function bi(e=Ci.errors,t){switch(t.type){case fi.LoadPaymentMethodsRequested:case fi.LoadPaymentMethodsSucceeded:return je(e,"loadError",void 0);case fi.LoadPaymentMethodsFailed:return je(e,"loadError",t.payload);case fi.LoadPaymentMethodRequested:case fi.LoadPaymentMethodSucceeded:return Ze(e,{loadMethodId:void 0,loadMethodError:void 0});case fi.LoadPaymentMethodFailed:return Ze(e,{loadMethodId:t.meta.methodId,loadMethodError:t.payload});default:return e}}function Ei(e=Ci.statuses,t){switch(t.type){case fi.LoadPaymentMethodsRequested:return je(e,"isLoading",!0);case fi.LoadPaymentMethodsSucceeded:case fi.LoadPaymentMethodsFailed:return je(e,"isLoading",!1);case fi.LoadPaymentMethodRequested:return Ze(e,{isLoadingMethod:!0,loadMethodId:t.meta.methodId});case fi.LoadPaymentMethodSucceeded:case fi.LoadPaymentMethodFailed:return Ze(e,{isLoadingMethod:!1,loadMethodId:void 0});default:return e}}var Pi;!function(e){e.ExecuteFailed="PAYMENT_STRATEGY_EXECUTE_FAILED",e.ExecuteRequested="PAYMENT_STRATEGY_EXECUTE_REQUESTED",e.ExecuteSucceeded="PAYMENT_STRATEGY_EXECUTE_SUCCEEDED",e.FinalizeFailed="PAYMENT_STRATEGY_FINALIZE_FAILED",e.FinalizeRequested="PAYMENT_STRATEGY_FINALIZE_REQUESTED",e.FinalizeSucceeded="PAYMENT_STRATEGY_FINALIZE_SUCCEEDED",e.InitializeFailed="PAYMENT_STRATEGY_INITIALIZE_FAILED",e.InitializeRequested="PAYMENT_STRATEGY_INITIALIZE_REQUESTED",e.InitializeSucceeded="PAYMENT_STRATEGY_INITIALIZE_SUCCEEDED",e.DeinitializeFailed="PAYMENT_STRATEGY_DEINITIALIZE_FAILED",e.DeinitializeRequested="PAYMENT_STRATEGY_DEINITIALIZE_REQUESTED",e.DeinitializeSucceeded="PAYMENT_STRATEGY_DEINITIALIZE_SUCCEEDED",e.WidgetInteractionStarted="PAYMENT_STRATEGY_WIDGET_INTERACTION_STARTED",e.WidgetInteractionFinished="PAYMENT_STRATEGY_WIDGET_INTERACTION_FINISHED",e.WidgetInteractionFailed="PAYMENT_STRATEGY_WIDGET_INTERACTION_FAILED"}(Pi||(Pi={}));const Oi={data:{},errors:{},statuses:{}};function Ai(e=Oi,t){return n({data:Ti,errors:o(ki,Be),statuses:Ri})(e,t)}function Ti(e=Oi.data,t){switch(t.type){case Pi.InitializeSucceeded:if(t.meta){const{methodId:i,gatewayId:n}=t.meta,o=n?`${i}.${n}`:i;return Ze(e,{[o]:{isInitialized:!0}})}break;case Pi.DeinitializeSucceeded:if(t.meta){const{methodId:i,gatewayId:n}=t.meta,o=n?`${i}.${n}`:i;return Ze(e,{[o]:{isInitialized:!1}})}}return e}function ki(e=Oi.errors,t){switch(t.type){case Pi.InitializeRequested:case Pi.InitializeSucceeded:return Ze(e,{initializeError:void 0,initializeMethodId:void 0});case Pi.InitializeFailed:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{initializeError:t.payload,initializeMethodId:i})}case Pi.DeinitializeRequested:case Pi.DeinitializeSucceeded:return Ze(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case Pi.DeinitializeFailed:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{deinitializeError:t.payload,deinitializeMethodId:i})}case Pi.ExecuteRequested:case Pi.ExecuteSucceeded:return Ze(e,{executeError:void 0,executeMethodId:void 0});case Pi.ExecuteFailed:return Ze(e,{executeError:t.payload,executeMethodId:t.meta&&t.meta.methodId});case Pi.FinalizeRequested:case Pi.FinalizeSucceeded:return Ze(e,{finalizeError:void 0,finalizeMethodId:void 0});case Pi.FinalizeFailed:return Ze(e,{finalizeError:t.payload,finalizeMethodId:t.meta&&t.meta.methodId});case Pi.WidgetInteractionStarted:case Pi.WidgetInteractionFinished:return Ze(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case Pi.WidgetInteractionFailed:return Ze(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function Ri(e=Oi.statuses,t){switch(t.type){case Pi.InitializeRequested:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{isInitializing:!0,initializeMethodId:i})}case Pi.InitializeFailed:case Pi.InitializeSucceeded:return Ze(e,{isInitializing:!1,initializeMethodId:void 0});case Pi.DeinitializeRequested:{let i=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:n}=t.meta;i=n?`${e}.${n}`:e}return Ze(e,{isDeinitializing:!0,deinitializeMethodId:i})}case Pi.DeinitializeFailed:case Pi.DeinitializeSucceeded:return Ze(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case Pi.ExecuteRequested:return Ze(e,{isExecuting:!0,executeMethodId:t.meta&&t.meta.methodId});case Pi.ExecuteFailed:case Pi.ExecuteSucceeded:return Ze(e,{isExecuting:!1,executeMethodId:void 0});case Pi.FinalizeRequested:return Ze(e,{isFinalizing:!0,finalizeMethodId:t.meta&&t.meta.methodId});case Pi.FinalizeFailed:case Pi.FinalizeSucceeded:return Ze(e,{isFinalizing:!1,finalizeMethodId:void 0});case Pi.WidgetInteractionStarted:return Ze(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case Pi.WidgetInteractionFinished:case Pi.WidgetInteractionFailed:return Ze(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Di;!function(e){e.UpdatePaymentProviderCustomer="UPDATE_PAYMENT_PROVIDER_CUSTOMER"}(Di||(Di={}));const Mi={data:{}};function Ni(e=Mi,t){return n({data:Li})(e,t)}function Li(e=Mi.data,t){return t.type===Di.UpdatePaymentProviderCustomer?Ze(e,t.payload):e}var zi;!function(e){e.LoadInstrumentsRequested="LOAD_INSTRUMENTS_REQUESTED",e.LoadInstrumentsSucceeded="LOAD_INSTRUMENTS_SUCCEEDED",e.LoadInstrumentsFailed="LOAD_INSTRUMENTS_FAILED",e.DeleteInstrumentRequested="DELETE_INSTRUMENT_REQUESTED",e.DeleteInstrumentSucceeded="DELETE_INSTRUMENT_SUCCEEDED",e.DeleteInstrumentFailed="DELETE_INSTRUMENT_FAILED"}(zi||(zi={}));const Ui={data:[],errors:{},statuses:{}};function Fi(e=Ui,t){return n({data:Bi,errors:o(qi,Be),meta:xi,statuses:ji})(e,t)}function Bi(e=Ui.data,t){return t.type===zi.LoadInstrumentsSucceeded?Ke(e,t.payload&&t.payload.vaultedInstruments||[]):e}function xi(e,t){switch(t.type){case zi.LoadInstrumentsSucceeded:case zi.DeleteInstrumentSucceeded:return Ze(e,t.meta);default:return e}}function qi(e=Ui.errors,t){switch(t.type){case zi.LoadInstrumentsRequested:case zi.LoadInstrumentsSucceeded:return je(e,"loadError",void 0);case zi.DeleteInstrumentRequested:case zi.DeleteInstrumentSucceeded:return Ze(e,{deleteError:void 0,failedInstrument:void 0});case zi.LoadInstrumentsFailed:return je(e,"loadError",t.payload);case zi.DeleteInstrumentFailed:return Ze(e,{deleteError:t.payload,failedInstrument:t.meta.instrumentId});default:return e}}function ji(e=Ui.statuses,t){switch(t.type){case zi.LoadInstrumentsRequested:return je(e,"isLoading",!0);case zi.DeleteInstrumentRequested:return Ze(e,{isDeleting:!0,deletingInstrument:t.meta.instrumentId});case zi.LoadInstrumentsSucceeded:case zi.LoadInstrumentsFailed:return je(e,"isLoading",!1);case zi.DeleteInstrumentSucceeded:case zi.DeleteInstrumentFailed:return Ze(e,{isDeleting:!1,deletingInstrument:void 0});default:return e}}var Gi;!function(e){e.ForgetCheckoutRemoteCustomerRequested="FORGET_CHECKOUT_REMOTE_CUSTOMER_REQUESTED",e.ForgetCheckoutRemoteCustomerSucceeded="FORGET_CHECKOUT_REMOTE_CUSTOMER_SUCCEEDED",e.ForgetCheckoutRemoteCustomerFailed="FORGET_CHECKOUT_REMOTE_CUSTOMER_FAILED",e.InitializeRemoteBillingRequested="INITIALIZE_REMOTE_BILLING_REQUESTED",e.InitializeRemoteBillingSucceeded="INITIALIZE_REMOTE_BILLING_SUCCEEDED",e.InitializeRemoteBillingFailed="INITIALIZE_REMOTE_BILLING_FAILED",e.InitializeRemoteShippingRequested="INITIALIZE_REMOTE_SHIPPING_REQUESTED",e.InitializeRemoteShippingSucceeded="INITIALIZE_REMOTE_SHIPPING_SUCCEEDED",e.InitializeRemoteShippingFailed="INITIALIZE_REMOTE_SHIPPING_FAILED",e.InitializeRemotePaymentRequested="INITIALIZE_REMOTE_PAYMENT_REQUESTED",e.InitializeRemotePaymentSucceeded="INITIALIZE_REMOTE_PAYMENT_SUCCEEDED",e.InitializeRemotePaymentFailed="INITIALIZE_REMOTE_PAYMENT_FAILED",e.LoadRemoteSettingsRequested="LOAD_REMOTE_SETTINGS_REQUESTED",e.LoadRemoteSettingsSucceeded="LOAD_REMOTE_SETTINGS_SUCCEEDED",e.LoadRemoteSettingsFailed="LOAD_REMOTE_SETTINGS_FAILED",e.SignOutRemoteCustomerRequested="SIGN_OUT_REMOTE_CUSTOMER_REQUESTED",e.SignOutRemoteCustomerSucceeded="SIGN_OUT_REMOTE_CUSTOMER_SUCCEEDED",e.SignOutRemoteCustomerFailed="SIGN_OUT_REMOTE_CUSTOMER_FAILED",e.UpdateRemoteCheckout="UPDATE_REMOTE_CHECKOUT"}(Gi||(Gi={}));const Hi={data:{}};function Vi(e=Hi,t){return t.meta&&t.meta.methodId?n({data:n({[t.meta.methodId]:Yi})})(e,t):e}function Yi(e,t){switch(t.type){case Gi.InitializeRemoteBillingSucceeded:return je(e,"billing",t.payload&&t.payload.billing);case Gi.InitializeRemoteShippingSucceeded:return je(e,"shipping",t.payload&&t.payload.shipping);case Gi.LoadRemoteSettingsSucceeded:return je(e,"settings",t.payload);case Gi.UpdateRemoteCheckout:return Ze(e,t.payload);default:return e}}const Wi={errors:{updateShippingOptionError:{},updateError:{},deleteError:{}},statuses:{isUpdating:{},isUpdatingShippingOption:{},isDeleting:{}}};function $i(e=Wi,t){return n({data:Ki,errors:o(Zi,Be),statuses:Qi})(e,t)}function Ki(e,t){var i,n;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.LoadShippingOptionsSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:return Ke(e,t.payload&&t.payload.consignments);case Rt.SignOutCustomerSucceeded:return Ke(e,[]);case Ne.HydrateInitialState:return Ke(e,null===(n=null===(i=t.payload)||void 0===i?void 0:i.checkout)||void 0===n?void 0:n.consignments);default:return e}}function Zi(e=Wi.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:case Xe.LoadShippingOptionsSucceeded:case Xe.LoadShippingOptionsRequested:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:case Xe.LoadShippingOptionsFailed:return je(e,"loadError",t.payload);case Xe.CreateConsignmentsRequested:case Xe.CreateConsignmentsSucceeded:return je(e,"createError",void 0);case Xe.CreateConsignmentsFailed:return je(e,"createError",t.payload);case Xe.UpdateConsignmentSucceeded:case Xe.UpdateConsignmentRequested:return t.meta?Ze(e,{updateError:{[t.meta.id]:void 0}}):e;case Xe.UpdateConsignmentFailed:return t.meta?Ze(e,{updateError:{[t.meta.id]:t.payload}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentRequested:return t.meta?Ze(e,{deleteError:{[t.meta.id]:void 0}}):e;case Xe.DeleteConsignmentFailed:return t.meta?Ze(e,{deleteError:{[t.meta.id]:t.payload}}):e;case Xe.UpdateShippingOptionRequested:case Xe.UpdateShippingOptionSucceeded:return t.meta?Ze(e,{updateShippingOptionError:{[t.meta.id]:void 0}}):e;case Xe.UpdateShippingOptionFailed:return t.meta?Ze(e,{updateShippingOptionError:{[t.meta.id]:t.payload}}):e;default:return e}}function Qi(e=Wi.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Xe.LoadShippingOptionsRequested:return je(e,"isLoadingShippingOptions",!0);case Me.LoadCheckoutSucceeded:case Me.LoadCheckoutFailed:return je(e,"isLoading",!1);case Xe.LoadShippingOptionsSucceeded:case Xe.LoadShippingOptionsFailed:return je(e,"isLoadingShippingOptions",!1);case Xe.CreateConsignmentsRequested:return je(e,"isCreating",!0);case Xe.CreateConsignmentsSucceeded:case Xe.CreateConsignmentsFailed:return je(e,"isCreating",!1);case Xe.UpdateConsignmentRequested:return t.meta?Ze(e,{isUpdating:{[t.meta.id]:!0}}):e;case Xe.UpdateConsignmentSucceeded:case Xe.UpdateConsignmentFailed:return t.meta?Ze(e,{isUpdating:{[t.meta.id]:!1}}):e;case Xe.DeleteConsignmentRequested:return t.meta?Ze(e,{isDeleting:{[t.meta.id]:!0}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentFailed:return t.meta?Ze(e,{isDeleting:{[t.meta.id]:!1}}):e;case Xe.UpdateShippingOptionRequested:return t.meta?Ze(e,{isUpdatingShippingOption:{[t.meta.id]:!0}}):e;case Xe.UpdateShippingOptionSucceeded:case Xe.UpdateShippingOptionFailed:return t.meta?Ze(e,{isUpdatingShippingOption:{[t.meta.id]:!1}}):e;default:return e}}function Ji(e,t){const i={};return Object.keys(e).forEach(n=>{const o=e[n],r=t?`${t}.${n}`:n;"object"==typeof o?Object.assign(i,Ji(o,r)):i[r]=o}),i}function Xi(e){return Object.keys(e).sort().reduce((t,i)=>Object.assign(Object.assign({},t),{[i]:e[i]}),{})}var en;!function(e){e.LoadPickupOptionsRequested="LOAD_PICKUP_OPTIONS_REQUESTED",e.LoadPickupOptionsSucceeded="LOAD_PICKUP_OPTIONS_SUCCEEDED",e.LoadPickupOptionsFailed="LOAD_PICKUP_OPTIONS_FAILED"}(en||(en={}));const tn={errors:{},statuses:{}};function nn(e=tn,t){return n({data:on,errors:o(rn,Be),statuses:an})(e,t)}function on(e,t){if(t.type!==en.LoadPickupOptionsSucceeded)return e;if(t.meta){const i=Xi(Ji({consignmentId:t.meta.consignmentId,searchArea:t.meta.searchArea}));return je(e,btoa(`${JSON.stringify(i)}`),t.payload)}}function rn(e=tn.errors,t){switch(t.type){case en.LoadPickupOptionsRequested:case en.LoadPickupOptionsSucceeded:return je(e,"loadError",void 0);case en.LoadPickupOptionsFailed:return je(e,"loadError",t.payload);default:return e}}function an(e=tn.statuses,t){switch(t.type){case en.LoadPickupOptionsRequested:return je(e,"isLoading",!0);case en.LoadPickupOptionsSucceeded:case en.LoadPickupOptionsFailed:return je(e,"isLoading",!1);default:return e}}var sn;!function(e){e.LoadShippingCountriesRequested="LOAD_SHIPPING_COUNTRIES_REQUESTED",e.LoadShippingCountriesSucceeded="LOAD_SHIPPING_COUNTRIES_SUCCEEDED",e.LoadShippingCountriesFailed="LOAD_SHIPPING_COUNTRIES_FAILED"}(sn||(sn={}));const dn={errors:{},statuses:{}};function cn(e=dn,t){return n({data:un,errors:o(ln,Be),statuses:hn})(e,t)}function un(e,t){return t.type===sn.LoadShippingCountriesSucceeded?Ke(e,t.payload):e}function ln(e=dn.errors,t){switch(t.type){case sn.LoadShippingCountriesRequested:case sn.LoadShippingCountriesSucceeded:return je(e,"loadError",void 0);case sn.LoadShippingCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function hn(e=dn.statuses,t){switch(t.type){case sn.LoadShippingCountriesRequested:return je(e,"isLoading",!0);case sn.LoadShippingCountriesSucceeded:case sn.LoadShippingCountriesFailed:return je(e,"isLoading",!1);default:return e}}var pn;!function(e){e.UpdateAddressFailed="SHIPPING_STRATEGY_UPDATE_ADDRESS_FAILED",e.UpdateAddressRequested="SHIPPING_STRATEGY_UPDATE_ADDRESS_REQUESTED",e.UpdateAddressSucceeded="SHIPPING_STRATEGY_UPDATE_ADDRESS_SUCCEEDED",e.SelectOptionFailed="SHIPPING_STRATEGY_SELECT_OPTION_FAILED",e.SelectOptionRequested="SHIPPING_STRATEGY_SELECT_OPTION_REQUESTED",e.SelectOptionSucceeded="SHIPPING_STRATEGY_SELECT_OPTION_SUCCEEDED",e.InitializeFailed="SHIPPING_STRATEGY_INITIALIZE_FAILED",e.InitializeRequested="SHIPPING_STRATEGY_INITIALIZE_REQUESTED",e.InitializeSucceeded="SHIPPING_STRATEGY_INITIALIZE_SUCCEEDED",e.DeinitializeFailed="SHIPPING_STRATEGY_DEINITIALIZE_FAILED",e.DeinitializeRequested="SHIPPING_STRATEGY_DEINITIALIZE_REQUESTED",e.DeinitializeSucceeded="SHIPPING_STRATEGY_DEINITIALIZE_SUCCEEDED",e.WidgetInteractionStarted="SHIPPING_STRATEGY_WIDGET_INTERACTION_STARTED",e.WidgetInteractionFinished="SHIPPING_STRATEGY_WIDGET_INTERACTION_FINISHED",e.WidgetInteractionFailed="SHIPPING_STRATEGY_WIDGET_INTERACTION_FAILED"}(pn||(pn={}));const mn={data:{},errors:{},statuses:{}};function gn(e=mn,t){return n({data:yn,errors:o(fn,Be),statuses:vn})(e,t)}function yn(e=mn.data,t){switch(t.type){case pn.InitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case pn.DeinitializeSucceeded:return Ze(e,{[t.meta&&t.meta.methodId]:{isInitialized:!1}})}return e}function fn(e=mn.errors,t){switch(t.type){case pn.InitializeRequested:case pn.InitializeSucceeded:return Ze(e,{initializeError:void 0,initializeMethodId:void 0});case pn.InitializeFailed:return Ze(e,{initializeError:t.payload,initializeMethodId:t.meta&&t.meta.methodId});case pn.DeinitializeRequested:case pn.DeinitializeSucceeded:return Ze(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case pn.DeinitializeFailed:return Ze(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case pn.UpdateAddressRequested:case pn.UpdateAddressSucceeded:return Ze(e,{updateAddressError:void 0,updateAddressMethodId:void 0});case pn.UpdateAddressFailed:return Ze(e,{updateAddressError:t.payload,updateAddressMethodId:t.meta&&t.meta.methodId});case pn.SelectOptionRequested:case pn.SelectOptionSucceeded:return Ze(e,{selectOptionError:void 0,selectOptionMethodId:void 0});case pn.SelectOptionFailed:return Ze(e,{selectOptionError:t.payload,selectOptionMethodId:t.meta&&t.meta.methodId});case pn.WidgetInteractionStarted:case pn.WidgetInteractionFinished:return Ze(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case pn.WidgetInteractionFailed:return Ze(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta&&t.meta.methodId});default:return e}}function vn(e=mn.statuses,t){switch(t.type){case pn.InitializeRequested:return Ze(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case pn.InitializeFailed:case pn.InitializeSucceeded:return Ze(e,{isInitializing:!1,initializeMethodId:void 0});case pn.DeinitializeRequested:return Ze(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case pn.DeinitializeFailed:case pn.DeinitializeSucceeded:return Ze(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case pn.UpdateAddressRequested:return Ze(e,{isUpdatingAddress:!0,updateAddressMethodId:t.meta&&t.meta.methodId});case pn.UpdateAddressFailed:case pn.UpdateAddressSucceeded:return Ze(e,{isUpdatingAddress:!1,updateAddressMethodId:void 0});case pn.SelectOptionRequested:return Ze(e,{isSelectingOption:!0,selectOptionMethodId:t.meta&&t.meta.methodId});case pn.SelectOptionFailed:case pn.SelectOptionSucceeded:return Ze(e,{isSelectingOption:!1,selectOptionMethodId:void 0});case pn.WidgetInteractionStarted:return Ze(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta&&t.meta.methodId});case pn.WidgetInteractionFinished:case pn.WidgetInteractionFailed:return Ze(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Sn;!function(e){e.SendSignInEmailRequested="SEND_SIGNIN_EMAIL_REQUESTED",e.SendSignInEmailSucceeded="SEND_SIGNIN_EMAIL_SUCCEEDED",e.SendSignInEmailFailed="SEND_SIGNIN_EMAIL_FAILED"}(Sn||(Sn={}));const Cn={errors:{},statuses:{}};function In(e=Cn,t){return n({data:_n,errors:o(wn,Be),statuses:bn})(e,t)}function _n(e,t){return t.type===Sn.SendSignInEmailSucceeded?Ze(e,t.payload):e}function wn(e=Cn.errors,t){switch(t.type){case Sn.SendSignInEmailRequested:case Sn.SendSignInEmailSucceeded:return je(e,"sendError",void 0);case Sn.SendSignInEmailFailed:return je(e,"sendError",t.payload);default:return e}}function bn(e=Cn.statuses,t){switch(t.type){case Sn.SendSignInEmailRequested:return je(e,"isSending",!0);case Sn.SendSignInEmailFailed:case Sn.SendSignInEmailSucceeded:return je(e,"isSending",!1);default:return e}}var En;!function(e){e.ApplyStoreCreditRequested="APPLY_STORE_CREDIT_REQUESTED",e.ApplyStoreCreditSucceeded="APPLY_STORE_CREDIT_SUCCEEDED",e.ApplyStoreCreditFailed="APPLY_STORE_CREDIT_FAILED"}(En||(En={}));const Pn={errors:{},statuses:{}};function On(e=Pn,t){return n({errors:o(An,Be),statuses:Tn})(e,t)}function An(e=Pn.errors,t){switch(t.type){case En.ApplyStoreCreditRequested:case En.ApplyStoreCreditSucceeded:return je(e,"applyError",void 0);case En.ApplyStoreCreditFailed:return je(e,"applyError",t.payload);default:return e}}function Tn(e=Pn.statuses,t){switch(t.type){case En.ApplyStoreCreditRequested:return je(e,"isApplying",!0);case En.ApplyStoreCreditSucceeded:case En.ApplyStoreCreditFailed:return je(e,"isApplying",!1);default:return e}}const kn={errors:{},statuses:{}};function Rn(e=kn,t){return n({errors:o(Dn,Be),statuses:Mn})(e,t)}function Dn(e=kn.errors,t){switch(t.type){case ze.UpdateSubscriptionsRequested:case ze.UpdateSubscriptionsSucceeded:return je(e,"updateError",void 0);case ze.UpdateSubscriptionsFailed:return je(e,"updateError",t.payload);default:return e}}function Mn(e=kn.statuses,t){switch(t.type){case ze.UpdateSubscriptionsRequested:return je(e,"isUpdating",!0);case ze.UpdateSubscriptionsFailed:case ze.UpdateSubscriptionsSucceeded:return je(e,"isUpdating",!1);default:return e}}var Nn;!function(e){e.InitializeFailed="SPAM_PROTECTION_INITIALIZE_FAILED",e.InitializeSucceeded="SPAM_PROTECTION_INITIALIZE_SUCCEEDED",e.InitializeRequested="SPAM_PROTECTION_INITIALIZE_REQUESTED",e.VerifyCheckoutRequested="SPAM_PROTECTION_CHECKOUT_VERIFY_REQUESTED",e.VerifyCheckoutSucceeded="SPAM_PROTECTION_CHECKOUT_VERIFY_SUCCEEDED",e.VerifyCheckoutFailed="SPAM_PROTECTION_CHECKOUT_VERIFY_FAILED",e.ExecuteRequested="SPAM_PROTECTION_EXECUTE_REQUESTED",e.ExecuteSucceeded="SPAM_PROTECTION_EXECUTE_SUCCEEDED",e.ExecuteFailed="SPAM_PROTECTION_EXECUTE_FAILED"}(Nn||(Nn={}));const Ln={errors:{},statuses:{}};function zn(e=Ln,t){return n({data:Un,errors:o(Fn,Be),statuses:Bn})(e,t)}function Un(e,t){var i;switch(t.type){case Me.LoadCheckoutSucceeded:case Me.UpdateCheckoutSucceeded:case En.ApplyStoreCreditSucceeded:case Ue.UpdateBillingAddressSucceeded:case Qe.ApplyCouponSucceeded:case Qe.RemoveCouponSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Xe.LoadShippingOptionsSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:case Nn.VerifyCheckoutSucceeded:return Ze(e,k(t.payload,["billingAddress","cart","consignments","customer","coupons","giftCertificates"]));case Ct.SubmitOrderSucceeded:return je(e,"orderId",t.payload&&t.payload.order.orderId);case Ne.HydrateInitialState:return Ze(e,k(null===(i=t.payload)||void 0===i?void 0:i.checkout,["billingAddress","cart","consignments","customer","coupons","giftCertificates"]));default:return e}}function Fn(e=Ln.errors,t){switch(t.type){case Me.LoadCheckoutRequested:case Me.LoadCheckoutSucceeded:return je(e,"loadError",void 0);case Me.LoadCheckoutFailed:return je(e,"loadError",t.payload);case Me.UpdateCheckoutRequested:case Me.UpdateCheckoutSucceeded:return je(e,"updateError",void 0);case Me.UpdateCheckoutFailed:return je(e,"updateError",t.payload);default:return e}}function Bn(e=Ln.statuses,t){switch(t.type){case Me.LoadCheckoutRequested:return je(e,"isLoading",!0);case Me.LoadCheckoutFailed:case Me.LoadCheckoutSucceeded:return je(e,"isLoading",!1);case Me.UpdateCheckoutRequested:return je(e,"isUpdating",!0);case Me.UpdateCheckoutFailed:case Me.UpdateCheckoutSucceeded:return je(e,"isUpdating",!1);case Nn.ExecuteRequested:return je(e,"isExecutingSpamCheck",!0);case Nn.ExecuteFailed:case Nn.ExecuteSucceeded:return je(e,"isExecutingSpamCheck",!1);default:return e}}var xn;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentProviderCustomer=13]="MissingPaymentProviderCustomer",e[e.MissingPaymentRedirectUrl=14]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=15]="MissingPaymentStatus",e[e.MissingPaymentToken=16]="MissingPaymentToken",e[e.MissingShippingAddress=17]="MissingShippingAddress"}(xn||(xn={}));class qn extends be{constructor(e){super(function(e){switch(e){case xn.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case xn.MissingCart:return"Unable to proceed because cart data is unavailable.";case xn.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case xn.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case xn.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case xn.MissingCheckoutConfig:case xn.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case xn.MissingOrder:return"Unable to proceed because order data is unavailable.";case xn.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case xn.MissingPayment:return"Unable to proceed because payment data is unavailable.";case xn.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case xn.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case xn.MissingPaymentProviderCustomer:return"Unable to proceed because payment provider customer is unavailable.";case xn.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(e)),this.subtype=e,this.name="MissingDataError",this.type="missing_data"}}const jn=(Gn=de,(...e)=>{const t=e.pop();return Gn(...e,(...e)=>{const i=t(...e);return"function"==typeof i?ae(i):i})});var Gn;function Hn(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}function Vn(e){return function(e){const t=Object.create(e);return function(e,t){let i=Object.getPrototypeOf(e);for(;i;)t(i),i=Object.getPrototypeOf(i)}(e,i=>{Object.getOwnPropertyNames(i).forEach(i=>{"constructor"!==i&&"function"==typeof t[i]&&"_"!==i.charAt(0)&&(t[i]=((e,t)=>(...i)=>d(e[t].call(e,...i)))(e,i))})}),t}(e)}const Yn={"mollie.credit_card":{provider:"mollie",method:"credit_card"},"adyenv2.scheme":{provider:"adyenv2",method:"scheme"},"adyenv3.scheme":{provider:"adyenv3",method:"scheme"},"adyenv2.bcmc":{provider:"adyenv2",method:"bcmc"},"adyenv2.ideal":{provider:"adyenv2",method:"ideal"},"adyenv2.sepadirectdebit":{provider:"adyenv2",method:"sepadirectdebit"},"adyenv2.directEbanking":{provider:"adyenv2",method:"directEbanking"},"adyenv2.giropay":{provider:"adyenv2",method:"giropay"},braintree:{provider:"braintree",method:"credit_card"},braintreepaypal:{provider:"braintree",method:"paypal"},braintreeach:{provider:"braintree",method:"ach"},authorizenet:{provider:"authorizenet",method:"credit_card"},elavon:{provider:"elavon",method:"credit_card"},checkoutcom:{provider:"checkoutcom",method:"credit_card"},"checkoutcom.credit_card":{provider:"checkoutcom",method:"credit_card"},"checkoutcom.card":{provider:"checkoutcom",method:"card"},sagepay:{provider:"sagepay",method:"credit_card"},stripe:{provider:"stripe",method:"credit_card"},"stripev3.card":{provider:"stripev3",method:"card"},"stripeupe.card":{provider:"stripeupe",method:"card"},cybersource:{provider:"cybersource",method:"credit_card"},cybersourcev2:{provider:"cybersourcev2",method:"credit_card"},bnz:{provider:"bnz",method:"credit_card"},converge:{provider:"converge",method:"credit_card"},bluesnapv2:{provider:"bluesnapv2",method:"credit_card"},"bluesnapdirect.credit_card":{provider:"bluesnapdirect",method:"credit_card"},"bluesnapdirect.ecp":{provider:"bluesnapdirect",method:"ecp"},"bluesnapdirect.sepa_direct_debit":{provider:"bluesnapdirect",method:"sepa_direct_debit"},orbital:{provider:"orbital",method:"credit_card"},paymetric:{provider:"paymetric",method:"credit_card"},bolt:{provider:"bolt",method:"credit_card"},"barclaycard.credit_card":{provider:"barclaycard",method:"credit_card"},moneris:{provider:"moneris",method:"credit_card"},cba_mpgs:{provider:"cba_mpgs",method:"credit_card"},worldpayaccess:{provider:"worldpayaccess",method:"credit_card"},squarev2:{provider:"squarev2",method:"credit_card"},paypalcommercecreditcards:{provider:"paypalcommerce",method:"credit_card"},paypalcommerce:{provider:"paypalcommerce",method:"paypal"},bigcommerce_payments_creditcards:{provider:"bigcommerce_payments",method:"credit_card"},bigcommerce_payments:{provider:"bigcommerce_payments",method:"paypal"},tdonlinemart:{provider:"tdonlinemart",method:"credit_card"}};function Wn(e){return M({firstName:e.firstName,lastName:e.lastName,company:e.company,address1:e.address1,address2:e.address2,city:e.city,stateOrProvince:e.stateOrProvince,countryCode:e.countryCode,postalCode:e.postalCode,phone:e.phone,customFields:e.customFields},m)}const $n={errors:{},statuses:{}};function Kn(){const e=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingBillingAddress))),i=jn(e=>e.errors.updateError,e=>()=>e),n=jn(e=>e.errors.continueAsGuestError,e=>()=>e),o=jn(e=>e.errors.loadError,e=>()=>e),r=jn(e=>!!e.statuses.isUpdating,e=>()=>e),a=jn(e=>!!e.statuses.isContinuingAsGuest,e=>()=>e),s=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((d=Ge)=>({getBillingAddress:e(d),getBillingAddressOrThrow:t(d),getUpdateError:i(d),getContinueAsGuestError:n(d),getLoadError:o(d),isUpdating:r(d),isContinuingAsGuest:a(d),isLoading:s(d)}))}(),t=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingCart))),i=jn(e=>e.errors.loadError,e=>()=>e),n=jn(e=>!!e.statuses.isLoading,e=>()=>e),o=jn(e=>{var t;return null===(t=e.data)||void 0===t?void 0:t.locale},e=>()=>e);return se((r=et)=>({getCart:e(r),getCartOrThrow:t(r),getLoadError:i(r),isLoading:n(r),getLocale:o(r)}))}(),i=function(){const e=jn(e=>e,e=>()=>e),t=jn(e=>e.statuses,e=>ae(t=>{if(t){const i=e[t];return!0===(i&&i.isInitializing)}return z(e,{isInitializing:!0})})),i=jn(e=>e.data,e=>ae((t,i)=>{const n=e[t];return!!n&&(i?!0===n.initializedContainers[i]:z(n.initializedContainers,e=>!0===e))})),n=jn(e=>e.statuses,e=>ae(t=>{if(t){const i=e[t];return!0===(i&&i.isDeinitializing)}return z(e,{isDeinitializing:!0})})),o=jn(e=>e.errors,e=>ae(t=>{const i=t?e[t]:l(x(e),e=>!(!e||!e.initializeError));return i&&i.initializeError})),r=jn(e=>e.errors,e=>ae(t=>{const i=t?e[t]:l(x(e),e=>!(!e||!e.deinitializeError));return i&&i.deinitializeError}));return se((a=at)=>({getState:e(a),isInitializing:t(a),isInitialized:i(a),isDeinitializing:n(a),getInitializeError:o(a),getDeinitializeError:r(a)}))}(),n=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.data,e=>t=>{if(!e)return;const{flashMessages:i}=e.context;return i?void 0!==t?i.filter(({type:e})=>t===e):i:void 0}),i=jn(e=>e.data,(e,{formState:t})=>t&&t.data,(e,t={customerAccount:[],shippingAddress:[],billingAddress:[]})=>()=>e?Object.assign(Object.assign({},e.storeConfig),{formFields:t}):void 0),n=jn(i,e=>()=>Hn(e(),()=>new qn(xn.MissingCheckoutConfig))),o=jn(e=>e.data&&e.data.context,e=>()=>e),r=jn(e=>e.meta&&e.meta.externalSource,e=>()=>e),a=jn(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.host},e=>()=>e),s=jn(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.locale},e=>()=>e),d=jn(e=>e.meta&&e.meta.variantIdentificationToken,e=>()=>e),c=jn(e=>e.errors.loadError,e=>()=>e),u=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((l=gt,h)=>({getConfig:e(l),getFlashMessages:t(l),getStoreConfig:i(l,{formState:h}),getStoreConfigOrThrow:n(l,{formState:h}),getContextConfig:o(l),getExternalSource:r(l),getHost:a(l),getLocale:s(l),getVariantIdentificationToken:d(l),getLoadError:c(l),isLoading:u(l)}))}(),o=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.loadError,e=>()=>e),i=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((n=ii)=>({getCountries:e(n),getLoadError:t(n),isLoading:i(n)}))}(),r=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.removeCouponError,e=>()=>e),i=jn(e=>e.errors.applyCouponError,e=>()=>e),n=jn(e=>!!e.statuses.isApplyingCoupon,e=>()=>e),o=jn(e=>!!e.statuses.isRemovingCoupon,e=>()=>e);return se((r=It)=>({getCoupons:e(r),getRemoveError:t(r),getApplyError:i(r),isApplying:n(r),isRemoving:o(r)}))}(),a=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingCustomer))),i=jn(e=>e.errors.createError,e=>()=>e),n=jn(e=>!!e.statuses.isCreating,e=>()=>e),o=jn(e=>e.errors.createAddressError,e=>()=>e),r=jn(e=>!!e.statuses.isCreatingAddress,e=>()=>e);return se((a=Dt)=>({getCustomer:e(a),getCustomerOrThrow:t(a),getCreateAccountError:i(a),isCreatingCustomerAccount:n(a),getCreateAddressError:o(a),isCreatingCustomerAddress:r(a)}))}(),s=function(){const e=jn(e=>e.errors.signInMethodId,e=>e.errors.signInError,(e,t)=>i=>{if(!i||e===i)return t}),t=jn(e=>e.errors.signOutMethodId,e=>e.errors.signOutError,(e,t)=>i=>{if(!i||e===i)return t}),i=jn(e=>e.errors.executePaymentMethodCheckoutMethodId,e=>e.errors.executePaymentMethodCheckoutError,(e,t)=>i=>{if(!i||e===i)return t}),n=jn(e=>e.errors.initializeMethodId,e=>e.errors.initializeErrors,(e,t)=>i=>{if(e&&t)return i?t[i]:t[e]}),o=jn(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>i=>{if(!i||e===i)return t}),r=jn(e=>e.statuses.signInMethodId,e=>e.statuses.isSigningIn,(e,t)=>i=>!(i&&e!==i||!t)),a=jn(e=>e.statuses.signOutMethodId,e=>e.statuses.isSigningOut,(e,t)=>i=>!(i&&e!==i||!t)),s=jn(e=>e.statuses.executePaymentMethodCheckoutMethodId,e=>e.statuses.isExecutingPaymentMethodCheckout,(e,t)=>i=>!(i&&e!==i||!t)),d=jn(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>i=>!(i&&e!==i||!t)),c=jn(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),u=jn(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>i=>!(i&&e!==i||!t));return se((l=Ft)=>({getSignInError:e(l),getSignOutError:t(l),getExecutePaymentMethodCheckoutError:i(l),getInitializeError:n(l),getWidgetInteractionError:o(l),isSigningIn:r(l),isSigningOut:a(l),isExecutingPaymentMethodCheckout:s(l),isInitializing:d(l),isInitialized:c(l),isWidgetInteracting:u(l)}))}(),d=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.removeGiftCertificateError,e=>()=>e),i=jn(e=>e.errors.applyGiftCertificateError,e=>()=>e),n=jn(e=>!!e.statuses.isApplyingGiftCertificate,e=>()=>e),o=jn(e=>!!e.statuses.isRemovingGiftCertificate,e=>()=>e);return se((r=Pt)=>({getGiftCertificates:e(r),getRemoveError:t(r),getApplyError:i(r),isApplying:n(r),isRemoving:o(r)}))}(),c=function(){const e=jn(e=>e.data,e=>t=>{if(!e)return;const i=t.gateway?`${t.gateway}.${t.id}`:t.id,n=Yn[i];return n?u(e,n):[]}),t=jn(e=>e.data,(e=[])=>t=>{const i=x(Yn);return e.find(e=>e.bigpayToken===t&&"card"===e.type&&i.some(t=>S(e,t)))}),i=jn(t,e=>t=>Hn(e(t),()=>new qn(xn.MissingPaymentInstrument))),n=jn(e=>e.data,e=>()=>{if(e)return p(Yn,t=>u(e,e=>S(e,t)))}),o=jn(e=>e.meta,e=>()=>e),r=jn(e=>e.errors.loadError,e=>()=>e),a=jn(e=>e.errors.failedInstrument,e=>e.errors.deleteError,(e,t)=>i=>{if(!i||e===i)return t}),s=jn(e=>e.statuses.isLoading,e=>()=>!!e),d=jn(e=>e.statuses.deletingInstrument,e=>e.statuses.isDeleting,(e,t)=>i=>!(i&&e!==i||!t));return se((c=Ui)=>({getCardInstrument:t(c),getCardInstrumentOrThrow:i(c),getInstruments:n(c),getInstrumentsByPaymentMethod:e(c),getInstrumentsMeta:o(c),getLoadError:r(c),getDeleteError:a(c),isLoading:s(c),isDeleting:d(c)}))}(),h=function(){const e=jn(e=>e.data,e=>(t=[],i)=>{const n=l(t,{code:i});return(e?e.shippingAddress:[]).map(e=>r(e,t,n))}),t=jn(e=>e.data,e=>(t=[],i)=>{const n=l(t,{code:i});return(e?e.billingAddress:[]).map(e=>r(e,t,n))}),i=jn(e=>e.data,e=>()=>e?e.customerAccount:[]),n=jn(e=>e.errors.loadError,e=>()=>e),o=jn(e=>!!e.statuses.isLoading,e=>()=>e);function r(e,t,i){return"countryCode"===e.name?function(e,t=[],i){if(!t.length)return e;const{code:n=""}=i||{},o=t.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{options:{items:o},default:n,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,t,i):"stateOrProvince"===e.name?function(e,t){const{subdivisions:i=[],requiresState:n}=t||{};if(!i.length)return Object.assign(Object.assign({},e),{required:null!=n&&n});const o=i.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{name:"stateOrProvinceCode",options:{items:o},required:null==n||n,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,i):"postalCode"===e.name?function(e,t){const{hasPostalCodes:i=[]}=t||{};return void 0===i?e:Object.assign(Object.assign({},e),{required:Boolean(i)})}(e,i):e}return se((r=Zt)=>({getShippingAddressFields:e(r),getBillingAddressFields:t(r),getCustomerAccountFields:i(r),getLoadError:n(r),isLoading:o(r)}))}(),m=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.meta,e=>()=>e),i=jn(e=>e.data,e=>(t,i)=>l(e,i?{id:t,gateway:i}:{id:t})),n=jn(i,e=>(t,i)=>Hn(e(t,i),()=>new qn(xn.MissingPaymentMethod))),o=jn(e=>e.errors.loadError,e=>()=>e),r=jn(e=>e.errors.loadMethodId,e=>e.errors.loadMethodError,(e,t)=>i=>{if(!i||e===i)return t}),a=jn(e=>e.statuses.isLoading,e=>()=>!!e),s=jn(e=>e.statuses.loadMethodId,e=>e.statuses.isLoadingMethod,(e,t)=>i=>!(i&&e!==i||!t));return se((d=Ci)=>({getPaymentMethods:e(d),getPaymentMethodsMeta:t(d),getPaymentMethod:i(d),getPaymentMethodOrThrow:n(d),getLoadError:o(d),getLoadMethodError:r(d),isLoading:a(d),isLoadingMethod:s(d)}))}(),g=function(){const e=jn(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>i=>{if(!i||e===i)return t}),t=jn(e=>e.errors.executeMethodId,e=>e.errors.executeError,(e,t)=>i=>{if(!i||e===i)return t}),i=jn(e=>e.errors.finalizeMethodId,e=>e.errors.finalizeError,(e,t)=>i=>{if(!i||e===i)return t}),n=jn(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>i=>{if(!i||e===i)return t}),o=jn(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>i=>!(i&&e!==i||!t)),r=jn(e=>e.data,e=>t=>{const i=t.gatewayId?`${t.methodId}.${t.gatewayId}`:t.methodId;return!(!e[i]||!e[i].isInitialized)}),a=jn(e=>e.statuses.executeMethodId,e=>e.statuses.isExecuting,(e,t)=>i=>!(i&&e!==i||!t)),s=jn(e=>e.statuses.finalizeMethodId,e=>e.statuses.isFinalizing,(e,t)=>i=>!(i&&e!==i||!t)),d=jn(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>i=>!(i&&e!==i||!t));return se((c=Oi)=>({getInitializeError:e(c),getExecuteError:t(c),getFinalizeError:i(c),getWidgetInteractingError:n(c),isInitializing:o(c),isInitialized:r(c),isExecuting:a(c),isFinalizing:s(c),isWidgetInteracting:d(c)}))}(),y=function(){const e=jn(e=>e.data,e=>(t,i)=>{if(!e)return;const n=Xi(Ji({consignmentId:t,searchArea:i})),o=btoa(`${JSON.stringify(n)}`);return e[o]}),t=jn(e=>e.errors.loadError,e=>()=>e),i=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((n=tn)=>({getPickupOptions:e(n),getLoadError:t(n),isLoading:i(n)}))}(),f=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentProviderCustomer)));return se((i=Mi)=>({getPaymentProviderCustomer:e(i),getPaymentProviderCustomerOrThrow:t(i)}))}(),C=function(){const e=jn(e=>e.data,e=>t=>e[t]);return se((t=Hi)=>({getCheckout:e(t)}))}(),I=function(){const e=jn(e=>e.data,e=>()=>{const t=null==e?void 0:e.find(e=>!e.selectedPickupOption);return null==t?void 0:t.shippingAddress}),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingShippingAddress))),i=jn(e=>e.data,e=>()=>{const t=null==e?void 0:e.filter(e=>!e.selectedPickupOption);return t?t.map(e=>e.shippingAddress):[]}),n=jn(i,e=>()=>Hn(e(),()=>new qn(xn.MissingShippingAddress)));return se((o=Wi)=>({getShippingAddress:e(o),getShippingAddressOrThrow:t(o),getShippingAddresses:i(o),getShippingAddressesOrThrow:n(o)}))}(),_=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.loadError,e=>()=>e),i=jn(e=>e.statuses.isLoading,e=>()=>!!e);return se((n=dn)=>({getShippingCountries:e(n),getLoadError:t(n),isLoading:i(n)}))}(),w=function(){const e=jn(e=>e.errors.updateAddressMethodId,e=>e.errors.updateAddressError,(e,t)=>i=>{if(!i||e===i)return t}),t=jn(e=>e.errors.selectOptionMethodId,e=>e.errors.selectOptionError,(e,t)=>i=>{if(!i||e===i)return t}),i=jn(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>i=>{if(!i||e===i)return t}),n=jn(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>i=>{if(!i||e===i)return t}),o=jn(e=>e.statuses.updateAddressMethodId,e=>e.statuses.isUpdatingAddress,(e,t)=>i=>!(i&&e!==i||!t)),r=jn(e=>e.statuses.selectOptionMethodId,e=>e.statuses.isSelectingOption,(e,t)=>i=>!(i&&e!==i||!t)),a=jn(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>i=>!(i&&e!==i||!t)),s=jn(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),d=jn(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>i=>!(i&&e!==i||!t));return se((c=mn)=>({getUpdateAddressError:e(c),getSelectOptionError:t(c),getInitializeError:i(c),getWidgetInteractionError:n(c),isUpdatingAddress:o(c),isSelectingOption:r(c),isInitializing:a(c),isInitialized:s(c),isWidgetInteracting:d(c)}))}(),b=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingConsignments))),i=jn(e=>e.data,e=>t=>{if(e&&e.length)return l(e,{id:t})}),n=jn(e=>e.data,e=>t=>{if(e&&e.length)return l(e,e=>{return i=e.shippingAddress,n=t,v(Wn(i),Wn(n));var i,n})}),o=jn(e=>e.data,e=>()=>{if(e&&e.length)return e[0].selectedShippingOption}),r=jn(e=>e.errors.loadError,e=>()=>e),a=jn(e=>e.errors.createError,e=>()=>e),s=jn(e=>e.errors.loadShippingOptionsError,e=>()=>e),d=jn(e,(e,{cart:t})=>t.getCart,(e,t)=>()=>{const i=t();if(!i)return[];const n=(e()||[]).reduce((e,t)=>e.concat(t.lineItemIds),[]);return(i.lineItems.physicalItems||[]).filter(e=>n.indexOf(e.id)<0)}),c=jn(e=>e.errors.updateError,e=>t=>t?e[t]:l(e)),u=jn(e=>e.errors.deleteError,e=>t=>t?e[t]:l(e)),h=jn(n,c,a,(e,t,i)=>n=>{const o=e(n);return o?t(o.id):i()}),p=jn(e=>e.errors.updateShippingOptionError,e=>t=>t?e[t]:l(e)),m=jn(e=>e.statuses.isLoading,e=>()=>!0===e),g=jn(e=>e.statuses.isLoadingShippingOptions,e=>()=>!0===e),y=jn(e=>e.statuses.isCreating,e=>()=>!0===e),f=jn(e=>e.statuses.isUpdating,e=>t=>t?!0===e[t]:!0===l(e)),S=jn(e=>e.statuses.isDeleting,e=>t=>t?!0===e[t]:!0===l(e)),C=jn(n,f,y,(e,t,i)=>n=>{const o=e(n);return o?t(o.id):i()}),I=jn(e=>e.statuses.isUpdatingShippingOption,e=>t=>t?!0===e[t]:!0===l(e));return se((l=Wi,v)=>({getConsignments:e(l),getConsignmentsOrThrow:t(l),getConsignmentById:i(l),getConsignmentByAddress:n(l),getShippingOption:o(l),getLoadError:r(l),getCreateError:a(l),getLoadShippingOptionsError:s(l),getUnassignedItems:d(l,{cart:v}),getUpdateError:c(l),getDeleteError:u(l),getItemAssignmentError:h(l),getUpdateShippingOptionError:p(l),isLoading:m(l),isLoadingShippingOptions:g(l),isCreating:y(l),isUpdating:f(l),isDeleting:S(l),isAssigningItems:C(l),isUpdatingShippingOption:I(l)}))}(),E=function(){const e=jn(e=>e.data,(e,{billingAddress:t})=>t.getBillingAddress,(e,{cart:t})=>t.getCart,(e,{customer:t})=>t.getCustomer,(e,{consignments:t})=>t.getConsignments,(e,{coupons:t})=>t.getCoupons,(e,{giftCertificates:t})=>t.getGiftCertificates,(e,t,i,n,o,r,a)=>()=>{const s=t(),d=i(),c=n(),u=o()||[],l=r()||[],h=a()||[];if(e&&d&&c)return Object.assign(Object.assign({},e),{billingAddress:s,cart:d,customer:c,consignments:u,coupons:l,giftCertificates:h})}),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingCheckout))),i=jn(e,e=>t=>{const i=e();if(!i)return;const n=i.grandTotal||0,o=i.customer.storeCredit||0;return t?Math.max(n-o,0):i.outstandingBalance}),n=jn(e=>e.errors.loadError,e=>()=>e),o=jn(e=>e.errors.updateError,e=>()=>e),r=jn(e=>e.statuses.isExecutingSpamCheck,e=>()=>!0===e),a=jn(e=>e.statuses.isLoading,e=>()=>!0===e),s=jn(e=>e.statuses.isUpdating,e=>()=>!0===e);return se((d=Ln,c,u,l,h,p,m)=>({getCheckout:e(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getCheckoutOrThrow:t(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getOutstandingBalance:i(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getLoadError:n(d),getUpdateError:o(d),isExecutingSpamCheck:r(d),isLoading:a(d),isUpdating:s(d)}))}(),P=function(){const e=jn(e=>e.data,(e,{billingAddress:t})=>t.getOrderBillingAddress(),(e,{coupons:t})=>t.getCoupons(),(e,t,i=[])=>()=>{if(e&&t)return Object.assign(Object.assign({},e),{billingAddress:t,coupons:i})}),t=jn(e,e=>()=>Hn(e(),()=>new qn(xn.MissingOrder))),i=jn(e=>e.meta,e=>()=>e),n=jn(e=>e.errors.loadError,e=>()=>e),o=jn(e=>{var t;return null===(t=e.data)||void 0===t?void 0:t.payments},(e=[])=>t=>{const i=e.find(({providerId:e})=>e===t);return null==i?void 0:i.paymentId}),r=jn(e=>!!e.statuses.isLoading,e=>()=>e);return se((a=si,s,d)=>({getOrder:e(a,{billingAddress:s,coupons:d}),getOrderOrThrow:t(a,{billingAddress:s,coupons:d}),getOrderMeta:i(a),getLoadError:n(a),getPaymentId:o(a),isLoading:r(a)}))}(),O=function(){const e=jn(e=>e.data,e=>()=>e);return se((t=pi)=>({getOrderBillingAddress:e(t)}))}(),A=function(){const e=jn(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.payment}),t=jn(({order:e})=>e.getOrder,e=>()=>{const t=e();return l(t&&t.payments,({providerId:e})=>"giftcertificate"!==e&&"storecredit"!==e)}),i=jn(({checkout:e})=>e.getCheckout,e=>()=>{const t=e();return l(t&&t.payments,({providerType:e})=>"PAYMENT_TYPE_HOSTED"===e)}),n=jn(e,i,t,(e,t,i)=>()=>{const n=e();if(n&&n.id)return{providerId:n.id,gatewayId:n.gateway};const o=t()||i();return o&&o.providerId?{providerId:o.providerId,gatewayId:o.gatewayId}:void 0}),o=jn(n,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentId))),r=jn(e,i,t,(e,t,i)=>()=>{const n=e();if(n&&n.status)return n.status.replace("PAYMENT_STATUS_","");const o=t()||i();return o?o.detail.step:void 0}),a=jn(r,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentStatus))),s=jn(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.token}),d=jn(s,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentToken))),c=jn(e,e=>()=>{const t=e();return t&&t.redirectUrl}),u=jn(c,e=>()=>Hn(e(),()=>new qn(xn.MissingPaymentRedirectUrl))),h=jn(({checkout:e})=>e.getOutstandingBalance,e=>(t=!1)=>{const i=e(t);return!!i&&i>0}),p=jn(r,e=>t=>!(!t||!t.nonce)||"ACKNOWLEDGE"===e()||"FINALIZE"===e());return se((e,t)=>({getPaymentId:n({checkout:e,order:t}),getPaymentIdOrThrow:o({checkout:e,order:t}),getPaymentStatus:r({checkout:e,order:t}),getPaymentStatusOrThrow:a({checkout:e,order:t}),getPaymentToken:s({checkout:e,order:t}),getPaymentTokenOrThrow:d({checkout:e,order:t}),getPaymentRedirectUrl:c({checkout:e,order:t}),getPaymentRedirectUrlOrThrow:u({checkout:e,order:t}),isPaymentDataRequired:h({checkout:e,order:t}),isPaymentDataSubmitted:p({checkout:e,order:t})}))}(),T=function(){const e=jn(e=>e.errors.applyError,e=>()=>e),t=jn(e=>!!e.statuses.isApplying,e=>()=>e);return se((i=$n)=>({getApplyError:e(i),isApplying:t(i)}))}(),k=function(){const e=jn(e=>e.errors.updateError,e=>()=>e),t=jn(e=>!!e.statuses.isUpdating,e=>()=>e);return se((i=kn)=>({getUpdateError:e(i),isUpdating:t(i)}))}(),R=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.errors.sendError,e=>()=>e),i=jn(e=>!!e.statuses.isSending,e=>()=>e);return se((n=Cn)=>({getEmail:e(n),getSendError:t(n),isSending:i(n)}))}(),D=function(){const e=jn(e=>e.data,e=>()=>e),t=jn(e=>e.data,e=>t=>null==e?void 0:e.find(e=>e.region===t)),i=jn(e=>e.errors.loadError,e=>()=>e),n=jn(e=>e.statuses.isLoading,e=>()=>!!e);return se((o=Ht)=>({getExtensions:e(o),getExtensionByRegion:t(o),getLoadError:i(o),isLoading:n(o)}))}();return(u,l={})=>{const p=e(u.billingAddress),v=t(u.cart),S=i(u.checkoutButton),M=o(u.countries),N=r(u.coupons),L=a(u.customer),z=s(u.customerStrategies),U=D(u.extensions),F=h(u.formFields),B=d(u.giftCertificates),x=c(u.instruments),q=O(u.orderBillingAddress),j=m(u.paymentMethods),G=f(u.paymentProviderCustomer),H=g(u.paymentStrategies),V=y(u.pickupOptions),Y=C(u.remoteCheckout),W=I(u.consignments),$=_(u.shippingCountries),K=w(u.shippingStrategies),Z=k(u.subscriptions),Q=T(u.storeCredit),J=R(u.signInEmail),X=b(u.consignments,v),ee=E(u.checkout,p,v,X,N,L,B),te=P(u.order,q,N),ie=A(ee,te),ne={billingAddress:p,cart:v,checkout:ee,checkoutButton:S,config:n(u.config,u.formFields),consignments:X,countries:M,coupons:N,customer:L,customerStrategies:z,extensions:U,form:F,giftCertificates:B,instruments:x,order:te,orderBillingAddress:q,payment:ie,paymentMethods:j,paymentProviderCustomer:G,paymentStrategies:H,pickupOptions:V,remoteCheckout:Y,shippingAddress:W,shippingCountries:$,shippingStrategies:K,signInEmail:J,subscriptions:Z,storeCredit:Q};return l.shouldWarnMutation?function(e){return Object.keys(e).reduce((t,i)=>(t[i]=Vn(e[i]),t),{})}(ne):ne}}function Zn(e={},t){const i=(s=function(){const e=new De;return["catalog_only","empty_cart","invalid_order_id","invalid_order_token","missing_order_token","missing_provider_token","missing_shipping_method","order_completion_error","order_could_not_be_finalized_error","order_create_failed","provider_fatal_error","provider_setup_error","stock_too_low"].forEach(t=>{e.register(t,(e,t)=>new Oe(e,t))}),e.register("invalid_payment_provider",e=>new we(e)),e.register("payment_config_not_found",e=>new we(e)),e}(),e=>W(e).pipe(J(e=>{if(e instanceof Error||e.payload instanceof Error)throw e;if((t=e.payload)&&"object"==typeof t&&["body","headers","status","statusText"].every(e=>Object.prototype.hasOwnProperty.call(t,e))){const t=e.payload.body&&e.payload.body.detail;throw Object.assign(Object.assign({},e),{payload:s.createError(e.payload,t)})}var t;throw e}))),o=Kn(),r=n({billingAddress:He,cart:tt,checkout:zn,checkoutButton:ut,config:yt,consignments:$i,countries:ni,coupons:_t,customer:Mt,customerStrategies:Bt,extensions:Vt,formFields:Qt,giftCertificates:Ot,instruments:Fi,orderBillingAddress:mi,order:di,payment:vi,paymentMethods:Ii,paymentStrategies:Ai,pickupOptions:nn,paymentProviderCustomer:Ni,remoteCheckout:Vi,shippingCountries:cn,shippingStrategies:gn,signInEmail:In,subscriptions:Rn,storeCredit:On});var s;return a(r,e,Object.assign({actionTransformer:i,stateTransformer:e=>o(e)},t))}var Qn,Jn;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentRedirectUrl=13]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=14]="MissingPaymentStatus",e[e.MissingPaymentToken=15]="MissingPaymentToken",e[e.MissingShippingAddress=16]="MissingShippingAddress"}(Qn||(Qn={}));class Xn extends Ce{constructor(e){super(function(e){switch(e){case Qn.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case Qn.MissingCart:return"Unable to proceed because cart data is unavailable.";case Qn.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case Qn.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case Qn.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case Qn.MissingCheckoutConfig:case Qn.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case Qn.MissingOrder:return"Unable to proceed because order data is unavailable.";case Qn.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case Qn.MissingPayment:return"Unable to proceed because payment data is unavailable.";case Qn.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case Qn.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case Qn.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(e)),this.subtype=e,this.name="MissingDataError",this.type="missing_data"}}function eo(e){return t=e.lineItems.physicalItems.filter(e=>!e.addedByPromotion),N(t,(e,t)=>e+t.quantity,0);var t}function to(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}!function(e){e[e.CheckoutButtonNotInitialized=0]="CheckoutButtonNotInitialized",e[e.CustomerNotInitialized=1]="CustomerNotInitialized",e[e.PaymentNotInitialized=2]="PaymentNotInitialized",e[e.ShippingNotInitialized=3]="ShippingNotInitialized",e[e.SpamProtectionNotInitialized=4]="SpamProtectionNotInitialized"}(Jn||(Jn={}));class io extends Ce{constructor(e){super(function(e){switch(e){case Jn.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Jn.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Jn.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Jn.SpamProtectionNotInitialized:return"Unable to proceed because the checkout spam protection has not been initialized.";default:return"Unable to proceed because the required component has not been initialized."}}(e)),this.subtype=e,this.name="NotInitializedError",this.type="not_initialized"}}const no={de:"eu",jp:"fe",uk:"eu",us:"na"};var oo,ro,ao,so,co,uo;!function(e){e.en_US="en_US",e.en_GB="en_GB",e.de_DE="de_DE",e.fr_FR="fr_FR",e.it_IT="it_IT",e.es_ES="es_ES",e.ja_JP="ja_JP"}(oo||(oo={})),function(e){e.Home="Home",e.Product="Product",e.Cart="Cart",e.Checkout="Checkout",e.Other="Other"}(ro||(ro={})),function(e){e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.JPY="JPY"}(ao||(ao={})),function(e){e.PayAndShip="PayAndShip",e.PayOnly="PayOnly"}(so||(so={})),function(e){e.Gold="Gold",e.LightGray="LightGray",e.DarkGray="DarkGray"}(co||(co={})),function(e){e.C0001="C0001"}(uo||(uo={}));var lo=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ho{constructor(e){this.amazonPayV2ScriptLoader=e}initialize(e){return lo(this,void 0,void 0,function*(){this.amazonPayV2SDK=yield this.amazonPayV2ScriptLoader.load(e),this.buttonParentContainer=this.buttonParentContainer||this.createAmazonPayButtonParentContainer()})}deinitialize(){var e;return this.amazonPayV2Button=void 0,null===(e=this.buttonParentContainer)||void 0===e||e.remove(),this.buttonParentContainer=void 0,this.amazonPayV2SDK=void 0,Promise.resolve()}bindButton(e,t,i){this.getAmazonPayV2SDK().Pay.bindChangeAction(`#${e}`,{amazonCheckoutSessionId:t,changeAction:i})}createButton(e,t){this.amazonPayV2Button=this.getAmazonPayV2SDK().Pay.renderButton(`#${e}`,t)}prepareCheckout(e){const t=this.prepareRequestConfig(e);this.getAmazonPayV2Button().onClick(()=>{this.getAmazonPayV2Button().initCheckout(t)})}prepareCheckoutWithCreationRequestConfig(e){this.getAmazonPayV2Button().onClick(()=>lo(this,void 0,void 0,function*(){const t=yield e();if(t){const e=this.prepareRequestConfig(t.createCheckoutSessionConfig,t.estimatedOrderAmount,t.productType);this.getAmazonPayV2Button().initCheckout(e)}}))}signout(){return lo(this,void 0,void 0,function*(){return this.amazonPayV2SDK&&this.amazonPayV2SDK.Pay.signout(),Promise.resolve()})}renderAmazonPayButton({buttonColor:e,checkoutState:t,containerId:i,decoupleCheckoutInitiation:n=!1,methodId:o,options:r,placement:a,isButtonMicroTextDisabled:s=!1}){const d=document.querySelector(`#${i}`);if(!d)return;const{id:c}=d.appendChild(this.getButtonParentContainer());r&&s&&(r.design=uo.C0001);const u=null!=r?r:this.getAmazonPayV2ButtonOptions(t,o,a,n,e);return this.createButton(c,u),this.getButtonParentContainer()}updateBuyNowFlowFlag(e){this.isBuyNowFlow=Boolean(e)}isPh4Enabled(e,t){const i=!!e["PROJECT-3483.amazon_pay_ph4"],n=!!e["INT-6885.amazon_pay_ph4_us_only"];return i&&n?"US"===t:i}prepareRequestConfig(e,t,i){const{publicKeyId:n}=e,o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["publicKeyId"]);return Object.assign(Object.assign({createCheckoutSessionConfig:this.isEnvironmentSpecific(n)?o:e},t&&{estimatedOrderAmount:t}),i&&{productType:i})}createAmazonPayButtonParentContainer(){const e=Math.random().toString(16).substr(-4),t=document.createElement("div");return t.id=`amazonpay_button_parent_container_${e}`,t}getAmazonPayV2ButtonOptions(e,t,i,n=!1,o=co.Gold){var r;const{getCart:a,getCheckout:s,getStoreConfigOrThrow:d,getPaymentMethodOrThrow:c}=this.getCheckoutState(e),{config:{merchantId:u,testMode:l},initializationData:h}=c(t);if(!h)throw new Xn(Qn.MissingPaymentMethod);const{checkoutLanguage:p,checkoutSessionMethod:m,createCheckoutSessionConfig:g,extractAmazonCheckoutSessionId:y,ledgerCurrency:f,publicKeyId:v="",isButtonMicroTextDisabled:S}=h;if(!u||!f)throw new Xn(Qn.MissingPaymentMethod);const C=Object.assign({merchantId:u,ledgerCurrency:f,checkoutLanguage:p,placement:i,buttonColor:o},S?{design:uo.C0001}:{});if(this.isBuyNowFlow)return Object.assign(Object.assign({},C),{sandbox:!!l});const I=a();C.productType=I&&0===eo(I)?so.PayOnly:so.PayAndShip;const{checkoutSettings:{features:_},storeProfile:{shopPath:w,storeCountryCode:b}}=d();if(this.isPh4Enabled(_,b)){if(!g)throw new Xn(Qn.MissingPaymentMethod);const e=null===(r=s())||void 0===r?void 0:r.outstandingBalance.toString(),t=null==I?void 0:I.currency.code,i=Object.assign({},C);let o;return this.isEnvironmentSpecific(v)?(i.publicKeyId=v,o=g):(i.sandbox=!!l,o=Object.assign(Object.assign({},g),{publicKeyId:v})),n||(i.createCheckoutSessionConfig=o),e&&t&&(i.estimatedOrderAmount={amount:e,currencyCode:t}),i}const E={method:m,url:`${w}/remote-checkout/${t}/payment-session`,extractAmazonCheckoutSessionId:y};return Object.assign(Object.assign({},C),{createCheckoutSession:E,sandbox:!!l})}isEnvironmentSpecific(e){return/^(SANDBOX|LIVE)/.test(e)}getAmazonPayV2SDK(){return this.getOrThrow(this.amazonPayV2SDK)}getButtonParentContainer(){return this.getOrThrow(this.buttonParentContainer)}getAmazonPayV2Button(){return this.getOrThrow(this.amazonPayV2Button)}getOrThrow(e){return to(e,()=>new io(Jn.PaymentNotInitialized))}getCheckoutState(e){return"object"==typeof(t=e)&&null!==t&&"cart"in t&&"checkout"in t&&"config"in t&&"paymentMethods"in t?{getCart:e.cart.getCart,getCheckout:e.checkout.getCheckout,getStoreConfigOrThrow:e.config.getStoreConfigOrThrow,getPaymentMethodOrThrow:t=>e.paymentMethods.getPaymentMethodOrThrow(t)}:e;var t}}class po extends Ce{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}class mo{constructor(e,t=window){this.scriptLoader=e,this.windowWithAmazonPay=t}load(e){return t=this,i=void 0,o=function*(){const{initializationData:t}=e,i=(null==t?void 0:t.region)||"us",n=no[i];if(yield this.scriptLoader.loadScript(`https://static-${n}.payments-amazon.com/checkout.js`),!this.windowWithAmazonPay.amazon)throw new po;return this.windowWithAmazonPay.amazon},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}}function go(e,t){return Object.assign(e,{resolveIds:t})}class yo extends Ce{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class fo extends Ce{constructor(e){super(e||"An unexpected error has occurred during buy now cart creation process. Please try again later."),this.name="BuyNowCartCreationError",this.type="buy_now_cart_creation_error"}}class vo extends Ce{constructor(e){super(e||"An unexpected error has occurred during config creation process. Please try again later."),this.name="AmazonPayV2ConfigCreationError",this.type="amazon_pay_v2_config_creation_error"}}function So(e){return e instanceof Object&&"buyNowInitializeOptions"in e}var Co=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Io{constructor(e,t,i){this.paymentIntegrationService=e,this.amazonPayV2PaymentProcessor=t,this.amazonPayV2ConfigRequestSender=i}initialize(e){var t;return Co(this,void 0,void 0,function*(){const{methodId:i,containerId:n,amazonpay:o}=e,{buttonColor:r}=o||{};if(!i||!n)throw new yo('Unable to proceed because "methodId" or "containerId" argument is not provided.');const{getPaymentMethodOrThrow:a}=this.paymentIntegrationService.getState(),s=a(i),{initializationData:d}=s;yield this.amazonPayV2PaymentProcessor.initialize(s),o||(yield this.paymentIntegrationService.loadDefaultCheckout());const c=So(o)?void 0:o;So(o)&&"function"==typeof(null===(t=o.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody)&&(this._buyNowInitializeOptions=o.buyNowInitializeOptions,this.amazonPayV2PaymentProcessor.updateBuyNowFlowFlag(!0)),this.amazonPayV2PaymentProcessor.renderAmazonPayButton({checkoutState:this.paymentIntegrationService.getState(),containerId:n,methodId:i,options:c,placement:ro.Cart,buttonColor:r,isButtonMicroTextDisabled:null==d?void 0:d.isButtonMicroTextDisabled}),this._buyNowInitializeOptions&&this.amazonPayV2PaymentProcessor.prepareCheckoutWithCreationRequestConfig(this._getCheckoutCreationRequestConfig.bind(this))})}deinitialize(){return this.amazonPayV2PaymentProcessor.deinitialize()}_createBuyNowCartOrThrow(){var e,t;return Co(this,void 0,void 0,function*(){const i=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!i)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(i)}catch(e){throw new fo}})}_createCheckoutConfig(e){return Co(this,void 0,void 0,function*(){try{const t=(yield this.amazonPayV2ConfigRequestSender.createCheckoutConfig(e)).body,{payload:i,public_key:n}=t,o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["payload","public_key"]);return Object.assign({payloadJSON:i,publicKeyId:n},o)}catch(e){throw new vo}})}_getCheckoutCreationRequestConfig(){return Co(this,void 0,void 0,function*(){const e=yield this._createBuyNowCartOrThrow(),t={amount:String(e.baseAmount),currencyCode:e.currency.code};return{createCheckoutSessionConfig:yield this._createCheckoutConfig(e.id),estimatedOrderAmount:t,productType:0===eo(e)?so.PayOnly:so.PayAndShip}})}}const _o="This API endpoint is for internal use only and may change in the future";var wo;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(wo||(wo={}));const bo=wo,Eo={"X-Checkout-SDK-Version":"1.864.0"};class Po{constructor(e){this._requestSender=e}createCheckoutConfig(e){const t={cartId:e},i=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return this._requestSender.post("/api/storefront/payment/amazonpay",{headers:i,body:t})}}const Oo=go(t=>{const i=e(),n=new Po(i),o=new ho(new mo(le()));return new Io(t,o,n)},[{id:"amazonpay"}]);function Ao(e,t,i=!0){var n;return null!==(n=e[t])&&void 0!==n?n:i}const To="3.128.0",ko="3.123.2",Ro="3.106.0";class Do{constructor(e){this.paymentIntegrationService=e,this.braintreeWindow=window}getSDKVersion(){const e=this.paymentIntegrationService.getState().getStoreConfig(),t=(null==e?void 0:e.checkoutSettings.features)||{};return this.getPreloadedSDKVersion()||(Ao(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?To:Ao(t,"PAYPAL-5636.update_braintree_sdk_version")?ko:Ro)}getPreloadedSDKVersion(){const e=this.braintreeWindow.braintree;if(e){const t=l(Object.values(e),e=>!!e.VERSION);return null==t?void 0:t.VERSION}}}class Mo extends Ce{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var No,Lo,zo,Uo,Fo,Bo,xo;function qo(e){return Boolean("object"==typeof e&&null!==e&&("type"in e||"message"in e||"code"in e))}!function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(No||(No={})),function(e){e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED"}(Lo||(Lo={})),function(e){e.TRUSTLY="trustly"}(zo||(zo={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="cancelled",e.UNRECOGNIZED="unrecognized"}(Uo||(Uo={})),function(e){e.Customer="CUSTOMER",e.Merchant="MERCHANT",e.Network="NETWORK",e.Internal="INTERNAL",e.Unknown="UNKNOWN"}(Fo||(Fo={})),function(e){e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED"}(Bo||(Bo={})),function(e){e.Visa="visa",e.Mastercard="mastercard",e.AmericanExpress="american-express",e.DinersClub="diners-club",e.Discover="discover",e.Jcb="jcb",e.UnionPay="union-pay",e.Maestro="maestro",e.Elo="elo",e.Mir="mir",e.Hiper="hiper",e.Hipercard="hipercard"}(xo||(xo={}));var jo,Go,Ho,Vo=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Yo{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return Vo(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return Vo(this,void 0,void 0,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=yield t.create({authorization:e})}return this.client})}getDataCollectorOrThrow(e){return Vo(this,void 0,void 0,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadDataCollector(),n=Object.assign({client:t,kount:!0},e);this.dataCollector=yield i.create(n)}catch(e){if(qo(e)&&e.code===Bo.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return Vo(this,void 0,void 0,function*(){if(!this.googlePayment){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadGooglePayment()]);this.googlePayment=yield t.create({client:e})}return this.googlePayment})}getBraintreeThreeDS(){return Vo(this,void 0,void 0,function*(){if(!this.threeDS){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]);this.threeDS=yield t.create({client:e,version:2})}return this.threeDS})}getBraintreeLocalPayment(e){return Vo(this,void 0,void 0,function*(){if(!this.braintreeLocalPayment){const[t,i]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((n,o)=>{i.create({client:t,merchantAccountId:e},(e,t)=>{e&&o(e),n(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return Vo(this,void 0,void 0,function*(){if(!this.usBankAccount){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadUsBankAccount();this.usBankAccount=yield t.create({client:e})}return this.usBankAccount})}getBraintreeVisaCheckout(){return this.visaCheckout||(this.visaCheckout=Promise.all([this.getClient(),this.braintreeScriptLoader.loadVisaCheckout()]).then(([e,t])=>t.create({client:e}))),this.visaCheckout}getVisaCheckoutSdk(e){return Vo(this,void 0,void 0,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return Vo(this,void 0,void 0,function*(){if(!this.braintreeVenmo){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadVenmoCheckout(),i={client:e,allowDesktop:!0,paymentMethodUsage:"multi_use"},n=yield t.create(i);if(!n.isBrowserSupported())throw new Mo;this.braintreeVenmo=n}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new io(Jn.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}!function(e){e.Sandbox="sandbox",e.Production="production"}(jo||(jo={})),function(e){e.Client="client",e.DataCollector="dataCollector",e.Fastlane="fastlane",e.GooglePayment="googlePayment",e.HostedFields="hostedFields",e.LocalPayment="localPayment",e.Paypal="paypal",e.PaypalCheckout="paypalCheckout",e.ThreeDSecure="threeDSecure",e.UsBankAccount="usBankAccount",e.Venmo="venmo",e.VisaCheckout="visaCheckout"}(Go||(Go={})),function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(Ho||(Ho={}));const Wo={[Ro]:{[Go.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[Go.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[Go.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[Go.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[Go.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[Go.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[Go.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[Go.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[Go.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[Go.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[Go.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[Go.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[ko]:{[Go.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[Go.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[Go.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[Go.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[Go.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[Go.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[Go.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[Go.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[Go.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[Go.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[Go.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[Go.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[To]:{[Go.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[Go.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[Go.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[Go.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[Go.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[Go.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[Go.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[Go.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[Go.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[Go.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[Go.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[Go.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var $o,Ko=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Zo{constructor(e,t,i){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=i}loadClient(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.Client,"client.min.js")})}loadFastlane(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.Paypal,"paypal.min.js")})}loadLocalPayment(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.GooglePayment,"google-payment.min.js")})}load3DS(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(Go.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(Go.Venmo,"venmo.min.js")}loadHostedFields(){return Ko(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(Go.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return Ko(this,void 0,void 0,function*(){if(this.braintreeHostWindow.V)return this.braintreeHostWindow.V;const t=e?"sha384-0eu1s1GtqzXlL9DtLgmwzC5WWlEH/ADRM0n38cVQkvtT+W/gey96rcb1LwuUOPDm":"sha384-1f1csvP3ZFxg4dILH1GaY4LHlZ0oX7Rk83rxmLlwbnIi4TM0NYzXoev1VoEiVDS6";return this.scriptLoader.loadScript(`//${e?"sandbox-":""}assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js`,{async:!0,attributes:{integrity:t,crossorigin:"anonymous"}}).then(()=>{if(!this.braintreeHostWindow.V)throw new po;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return Ko(this,void 0,void 0,function*(){let i=this.getBraintreeModule(e);if(i)return i;const n=this.braintreeSDKVersionManager.getSDKVersion(),o=`//js.braintreegateway.com/web/${n}/js/${t}`,r=n in Wo?this.getIntegrityValuesByModuleName(e,n):void 0;if(yield this.scriptLoader.loadScript(o,r?{async:!0,attributes:{integrity:r,crossorigin:"anonymous"}}:void 0),i=this.getBraintreeModule(e),!i)throw new po;return i})}getBraintreeModule(e){var t;return null===(t=this.braintreeHostWindow.braintree)||void 0===t?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const i=Wo[t][e];if(!i)throw new Error("Unexpected fileName value");return i}}class Qo extends Ce{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}!function(e){e.BRAINTREE="braintree",e.BRAINTREE_FASTLANE="braintreeacceleratedcheckout"}($o||($o={}));var Jo,Xo,er=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};!function(e){e.Subtotal="Subtotal",e.Shipping="Shipping"}(Jo||(Jo={})),function(e){e.Black="black",e.White="white",e.WhiteBorder="white-border"}(Xo||(Xo={}));class tr{constructor(e,t,i,n,o){this._requestSender=e,this._paymentIntegrationService=t,this._sessionFactory=i,this._braintreeSdk=n,this._applePayScriptLoader=o,this._onAuthorizeCallback=T,this._subTotalLabel=Jo.Subtotal,this._shippingLabel=Jo.Shipping}initialize(e){var t,i;return er(this,void 0,void 0,function*(){const{methodId:n,containerId:o,applepay:r}=e;if(!n||!r)throw new Xn(Qn.MissingPaymentMethod);yield this._applePayScriptLoader.loadSdk();const{onPaymentAuthorize:a,buyNowInitializeOptions:s,requiresShipping:d}=r;this._requiresShipping=d,this._buyNowInitializeOptions=s,this._onAuthorizeCallback=a,s||(yield this._paymentIntegrationService.loadDefaultCheckout()),yield this._paymentIntegrationService.loadPaymentMethod(n);const c=this._paymentIntegrationService.getState();return this._paymentMethod=c.getPaymentMethodOrThrow(n),c.getCart()&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection()),(null===(t=this._paymentMethod.initializationData)||void 0===t?void 0:t.gateway)===$o.BRAINTREE&&this._paymentMethod.clientToken&&this._braintreeSdk.initialize(this._paymentMethod.clientToken),this._applePayButton=this._createButton(o,null===(i=this._paymentMethod.initializationData)||void 0===i?void 0:i.styleOption),this._applePayButton.addEventListener("click",this._handleWalletButtonClick.bind(this)),Promise.resolve()})}deinitialize(){return Promise.resolve()}_createButton(e,t){const i=document.getElementById(e);if(!i)throw new yo("Unable to create wallet button without valid container ID.");const n=this._createApplePayButtonElement(t);return i.appendChild(n),n}_createApplePayButtonElement(e){const t=document.createElement("apple-pay-button");return t.setAttribute("buttonstyle",(e=>{switch(e){case Xo.White:return"white";case Xo.WhiteBorder:return"white-outline";case Xo.Black:default:return"black"}})(e)),t.setAttribute("type","plain"),t.setAttribute("style","--apple-pay-button-width: 100%; --apple-pay-button-height: 40px; --apple-pay-button-border-radius: 4px;"),t}_handleWalletButtonClick(e){var t;return er(this,void 0,void 0,function*(){if(e.preventDefault(),!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xn(Qn.MissingPaymentMethod);if(this._buyNowInitializeOptions&&"function"==typeof this._buyNowInitializeOptions.getBuyNowCartRequestBody){const{countryCode:e,currencyCode:i,merchantCapabilities:n,supportedNetworks:o,storeName:r}=this._paymentMethod.initializationData,a=this._getRequestWithEmptyTotal(e,i,o,n);this._requiresShipping&&(null===(t=a.requiredShippingContactFields)||void 0===t||t.push("postalAddress"));const s=this._sessionFactory.create(a);this._handleApplePayEvents(s,this._paymentMethod,r),s.begin()}else{const e=this._paymentIntegrationService.getState(),t=e.getCartOrThrow(),i=e.getStoreConfigOrThrow(),n=e.getCheckoutOrThrow(),o=this._getBaseRequest(t,n,i,this._paymentMethod),r=this._sessionFactory.create(o);this._handleApplePayEvents(r,this._paymentMethod,i.storeProfile.storeName),r.begin()}})}_getRequestWithEmptyTotal(e,t,i,n){return{countryCode:e,currencyCode:t,supportedNetworks:i,merchantCapabilities:n,total:{label:"",amount:"0",type:"pending"},requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"]}}_getBaseRequest(e,t,i,n){var o;const{storeProfile:{storeCountryCode:r,storeName:a}}=i,{currency:{code:s,decimalPlaces:d}}=e,{initializationData:{merchantCapabilities:c,supportedNetworks:u}}=n,l=e.lineItems.physicalItems.length>0,h={requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"],countryCode:r,currencyCode:s,merchantCapabilities:c,supportedNetworks:u,lineItems:[],total:l?{label:a,amount:`${t.grandTotal.toFixed(d)}`,type:"pending"}:{label:a,amount:`${t.grandTotal.toFixed(d)}`,type:"final"}};if(l)null===(o=h.requiredShippingContactFields)||void 0===o||o.push("postalAddress");else{const e=[{label:this._subTotalLabel,amount:`${t.subtotal.toFixed(d)}`}];t.taxes.forEach(t=>e.push({label:t.name,amount:`${t.amount.toFixed(d)}`})),h.lineItems=e}return h}_handleApplePayEvents(e,t,i){e.onvalidatemerchant=i=>er(this,void 0,void 0,function*(){try{const{body:n}=yield this._onValidateMerchant(t,i);e.completeMerchantValidation(n)}catch(e){throw new Error("Merchant validation failed")}}),this._buyNowInitializeOptions&&!this._requiresShipping&&(e.onpaymentmethodselected=()=>er(this,void 0,void 0,function*(){yield this._createBuyNowCart(),this._handlePaymentMethodSelected(e)})),e.onshippingcontactselected=t=>er(this,void 0,void 0,function*(){this._buyNowInitializeOptions&&this._requiresShipping&&(yield this._createBuyNowCart()),yield this._handleShippingContactSelected(e,i,t)}),e.onshippingmethodselected=t=>er(this,void 0,void 0,function*(){yield this._handleShippingMethodSelected(e,i,t)}),e.oncancel=()=>er(this,void 0,void 0,function*(){try{const e=`/remote-checkout/${t.id}/signout`;return yield this._requestSender.get(e),yield this._paymentIntegrationService.loadCheckout()}catch(e){throw new Qo}}),e.onpaymentauthorized=i=>er(this,void 0,void 0,function*(){return this._onPaymentAuthorized(i,e,t)})}_createBuyNowCart(){var e,t;return er(this,void 0,void 0,function*(){try{const i=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!i)throw new Xn(Qn.MissingCart);const n=yield this._paymentIntegrationService.createBuyNowCart(i);yield this._paymentIntegrationService.loadCheckout(n.id);const o=this._paymentIntegrationService.getState(),{shouldExecuteSpamCheck:r}=o.getCheckoutOrThrow();r&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection())}catch(e){throw new fo}})}_handlePaymentMethodSelected(e){const t=this._paymentIntegrationService.getState(),i=t.getCartOrThrow(),n=t.getStoreConfigOrThrow(),o=t.getCheckoutOrThrow();if(!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xn(Qn.MissingPaymentMethod);const r=this._getBaseRequest(i,o,n,this._paymentMethod);delete r.total.type,e.completePaymentMethodSelection({newTotal:r.total,newLineItems:r.lineItems})}_handleShippingContactSelected(e,t,i){var n;return er(this,void 0,void 0,function*(){const o=this._transformContactToAddress(i.shippingContact);try{yield this._paymentIntegrationService.updateShippingAddress(o)}catch(t){throw e.abort(),new Error("Shipping address update failed")}let r=this._paymentIntegrationService.getState();const{currency:{decimalPlaces:a}}=r.getCartOrThrow();let s=r.getCheckoutOrThrow();const d=null===(n=s.consignments[0].selectedShippingOption)||void 0===n?void 0:n.id,c=s.consignments[0].availableShippingOptions,u=null==c?void 0:c.find(({id:e})=>e===d),l=null==c?void 0:c.filter(e=>e.id!==d),h=u?[{label:u.description,amount:`${u.cost.toFixed(a)}`,detail:u.additionalDescription,identifier:u.id}]:[];if(l&&[...l.filter(e=>e.isRecommended),...l.filter(e=>!e.isRecommended)].forEach(e=>h.push({label:e.description,amount:`${e.cost.toFixed(a)}`,detail:e.additionalDescription,identifier:e.id})),!(c instanceof Array))throw new Error("Shipping options not available.");if(0===c.length)return void e.completeShippingContactSelection(ApplePaySession.STATUS_INVALID_SHIPPING_POSTAL_ADDRESS,[],{type:"pending",label:t,amount:`${s.grandTotal.toFixed(a)}`},[]);const p=c.find(e=>e.isRecommended),m=p?p.id:c[0].id,g=u?u.id:m;try{yield this._updateShippingOption(g)}catch(e){throw new Error("Shipping options update failed")}r=this._paymentIntegrationService.getState(),s=r.getCheckoutOrThrow(),e.completeShippingContactSelection({newShippingMethods:h,newTotal:{type:"final",label:t,amount:`${s.grandTotal.toFixed(a)}`},newLineItems:this._getUpdatedLineItems(s,a)})})}_handleShippingMethodSelected(e,t,i){return er(this,void 0,void 0,function*(){const{shippingMethod:{identifier:n}}=i;try{yield this._updateShippingOption(n)}catch(t){throw e.abort(),new Error("Shipping option selection update failed.")}const o=this._paymentIntegrationService.getState(),{currency:{decimalPlaces:r}}=o.getCartOrThrow(),a=o.getCheckoutOrThrow();e.completeShippingMethodSelection({newTotal:{type:"final",label:t,amount:`${a.grandTotal.toFixed(r)}`},newLineItems:this._getUpdatedLineItems(a,r)})})}_getUpdatedLineItems(e,t){const i=[{label:this._subTotalLabel,amount:`${e.subtotal.toFixed(t)}`}];return e.taxes.forEach(e=>i.push({label:e.name,amount:`${e.amount.toFixed(t)}`})),i.push({label:this._shippingLabel,amount:`${e.shippingCostTotal.toFixed(t)}`}),i}_updateShippingOption(e){return er(this,void 0,void 0,function*(){return this._paymentIntegrationService.selectShippingOption(e)})}_onValidateMerchant(e,t){return er(this,void 0,void 0,function*(){const i=[`validationUrl=${t.validationURL}`,`merchantIdentifier=${e.initializationData.merchantId}`,`displayName=${e.initializationData.storeName}`,`domainName=${window.location.hostname}`].join("&");return this._requestSender.post(`${e.initializationData.paymentsUrl}/api/public/v1/payments/applepay/validate_merchant`,{credentials:!1,headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded","X-XSRF-TOKEN":null},body:i})})}_onPaymentAuthorized(e,t,i){var n;return er(this,void 0,void 0,function*(){const{token:o,billingContact:r,shippingContact:a}=e.payment,s=this._paymentIntegrationService.getState().getCartOrThrow().lineItems.physicalItems.length>0;let d;(null===(n=i.initializationData)||void 0===n?void 0:n.gateway)===$o.BRAINTREE&&(d=yield this._getBraintreeDeviceData());const c={methodId:i.id,paymentData:{deviceSessionId:d,formattedPayload:{apple_pay_token:{payment_data:o.paymentData,payment_method:o.paymentMethod,transaction_id:o.transactionIdentifier}}}},u=this._transformContactToAddress(r),l=this._transformContactToAddress(a),h=null==a?void 0:a.emailAddress,p=(null==a?void 0:a.phoneNumber)||"";try{return yield this._paymentIntegrationService.updateBillingAddress(Object.assign(Object.assign({},u),{email:h,phone:p})),s&&(yield this._paymentIntegrationService.updateShippingAddress(l)),yield this._paymentIntegrationService.submitOrder({useStoreCredit:!1}),yield this._paymentIntegrationService.submitPayment(c),t.completePayment(ApplePaySession.STATUS_SUCCESS),this._onAuthorizeCallback()}catch(e){throw t.completePayment(ApplePaySession.STATUS_FAILURE),new Error("Payment cannot complete")}})}_transformContactToAddress(e){return{firstName:(null==e?void 0:e.givenName)||"",lastName:(null==e?void 0:e.familyName)||"",city:(null==e?void 0:e.locality)||"",company:"",address1:(null==e?void 0:e.addressLines)&&e.addressLines[0]||"",address2:(null==e?void 0:e.addressLines)&&e.addressLines[1]||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCode:(null==e?void 0:e.countryCode)||"",phone:(null==e?void 0:e.phoneNumber)||"",stateOrProvince:(null==e?void 0:e.administrativeArea)||"",stateOrProvinceCode:(null==e?void 0:e.administrativeArea)||"",customFields:[]}}_getBraintreeDeviceData(){return er(this,void 0,void 0,function*(){try{const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e}catch(e){}})}}function ir(e){if(!function(e){return"ApplePaySession"in e}(e))throw new Error("Apple pay is not supported")}class nr{create(e){return ir(window),new ApplePaySession(1,e)}}class or{constructor(e){this.scriptLoader=e,this.sdkVersion="1.latest"}loadSdk(){return e=this,t=void 0,n=function*(){(function(e){return"ApplePaySDK"in e})(window)||(yield this.scriptLoader.loadScript(`https://applepay.cdn-apple.com/jsapi/${this.sdkVersion}/apple-pay-sdk.js`),ir(window))},new((i=void 0)||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())});var e,t,i,n}}const rr=go(t=>{const{getHost:i}=t.getState(),n=new Do(t);return new tr(e({host:i()}),t,new nr,new Yo(new Zo(le(),window,n)),new or(new ce))},[{id:"applepay"}]);var ar,sr,dr,cr,ur,lr,hr,pr;!function(e){e.BuyNow="BUY_NOW"}(ar||(ar={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(sr||(sr={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(dr||(dr={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(cr||(cr={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ur||(ur={})),function(e){e.pill="pill",e.rect="rect"}(lr||(lr={})),function(e){e.OXXO="oxxo"}(hr||(hr={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(pr||(pr={}));var mr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class gr{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=i,this.bigCommercePaymentsScriptLoader=n}loadPayPalSdk(e,t,i,n){return mr(this,void 0,void 0,function*(){const o=this.paymentIntegrationService.getState(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(a,r,i,n),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new po;return this.paypalSdk}createBuyNowCartOrThrow(e){return mr(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}})}createOrder(e,t){return mr(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:i},t));return n})}createOrderCardFields(e,t){return mr(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n,setupToken:o}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:i},t));return Object.assign({orderId:n},o?{setupToken:o}:{})})}updateOrder(){return mr(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),i=e.getConsignmentsOrThrow()[0];try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:i.availableShippingOptions,cartId:t.id,selectedShippingOption:i.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return mr(this,void 0,void 0,function*(){try{const{status:i}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return i}catch(e){throw new _e}})}tokenizePayment(e,t){const i=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xn(Qn.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===ar.BuyNow&&{cart_id:i.id}))}submitPayment(e,t,i){return mr(this,void 0,void 0,function*(){const n={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:n},i?{gatewayId:i}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],i=t.availableShippingOptions||[],n=i.find(e=>e.isRecommended),o=(e?i.find(t=>t.id===e):i.find(e=>{var i;return e.id===(null===(i=t.selectedShippingOption)||void 0===i?void 0:i.id)}))||n||i[0];if(!o)throw new Error("Your order can't be shipped to this address");return o}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,i;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(i=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===i?void 0:i.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:i}=e,{address:n,name:{full_name:o}}=i[0].shipping,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.join(" "),email:t.email_address,address1:n.address_line_1,address2:n.address_line_2,city:n.admin_area_2,countryCode:n.country_code,postalCode:n.postal_code,stateOrProvinceCode:n.admin_area_1})}getValidButtonStyle(e){const{color:t,height:i,label:n,shape:o}=e||{},r={color:t&&ur[t]?t:void 0,height:this.getValidHeight(i),label:n&&cr[n]?n:void 0,shape:o&&lr[o]?o:void 0};return R(r,C)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var yr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class fr{constructor(e){this.requestSender=e}createOrder(e,t){return yr(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e){return yr(this,void 0,void 0,function*(){const t=e,i=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:i,body:t})).body})}getOrderStatus(e="bigcommerce_payments",t){return yr(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var vr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Sr{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return vr(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,i);return this.loadPayPalSDK(o,n)})}loadPayPalSDK(e,t=!1){return vr(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),i=this.transformConfig(e.attributes),n=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(n,{async:!0,attributes:i})}if(!this.window.paypal)throw new po;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,i=!0){const{id:n,clientToken:o,initializationData:r}=e;if(!(null==r?void 0:r.clientId))throw new Xn(Qn.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:u,isVenmoEnabled:l,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:p,isDeveloperModeApplicable:m,availableAlternativePaymentMethods:g=[],enabledAlternativePaymentMethods:y=[],isGooglePayEnabled:f}=r,v=h||i,S="bigcommerce_payments_creditcards"===n,C=S?["card"]:[],I=S?[]:["card"],_=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],b=l?["venmo"]:[],E=l?[]:["venmo"],P=g.filter(e=>!y.includes(e)),O=f?["googlepay"]:[],A=i?["card-fields"]:[],T=this.filterFundingOptions([...I,...w,...E,...P]),k=this.filterFundingOptions([...C,..._,...b,...y]);return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":k.length>0?k:void 0,"disable-funding":T.length>0?T:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...O,...A],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":o}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}const Cr=t=>{const{getHost:n}=t.getState();return new gr(i(),t,new fr(e({host:n()})),new Sr(le()))};var Ir=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class _r{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){var t;return Ir(this,void 0,void 0,function*(){const{bigcommerce_payments:i,containerId:n,methodId:o}=e,r=Boolean(null==i?void 0:i.buyNowInitializeOptions);if(!o)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(r&&!i.currencyCode)throw new yo('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(r&&"function"!=typeof(null===(t=i.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');r||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=r?i.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(o,a,!1),this.renderButton(n,o,i,r)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i,n){var o,r;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:c}=i,u=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:h,isAppSwitchEnabled:p}=l.initializationData||{},m=Object.assign(Object.assign({},!n&&this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)}),g={onClick:()=>this.handleClick(a),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},y=Object.assign(Object.assign({},!p&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,d)}),f=Object.assign(Object.assign(Object.assign({fundingSource:u.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(s)},m),a&&g),h&&y),v=u.Buttons(f);v.isEligible()?(null===(o=v.hasReturned)||void 0===o?void 0:o.call(v))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(r=v.resume)||void 0===r||r.call(v):v.render(`#${e}`):c&&"function"==typeof c?c():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Ir(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return Ir(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Ir(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return Ir(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}isPaypalCommerceAppSwitchEnabled(e){var t,i;return null!==(i=null===(t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.isAppSwitchEnabled)&&void 0!==i&&i}}const wr=go(e=>new _r(e,Cr(e)),[{id:"bigcommerce_payments"}]);var br=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Er{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,i){return br(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const n=this.getPayPalFastlaneSdkConfiguration(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypalFastlaneSdk)throw new po}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,i,n){return br(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||n){const n=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i);yield this.loadPayPalSdk(n)}if(!this.window.paypalGooglePay)throw new po;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return br(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new po}return this.window.paypalApms})}getPayPalMessages(e,t){return br(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new po;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return br(this,void 0,void 0,function*(){const i=this.transformConfig(e),n=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(i).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:n})})}getPayPalFastlaneSdkConfiguration(e,t,i){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:r},attributes:{"data-client-metadata-id":i.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":n}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i=!0){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=o,h=u||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":n,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=i,l=this.filterFundingOptions(u),h=this.filterFundingOptions(c.filter(e=>!u.includes(e)));return{options:Object.assign({"client-id":o,"merchant-id":r,"enable-funding":l.length>0?l:void 0,"disable-funding":h.length>0?h:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:n},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}const Pr=function({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t};var Or=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ar{constructor(e,t,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.payPalSdkHelper=i}initialize(e){return Or(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r,messagingContainerId:a}=t||{},s=!!o;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(s&&!r)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments_paylater.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');s||(yield this.paymentIntegrationService.loadDefaultCheckout());const d=this.paymentIntegrationService.getState(),c=s?r:d.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n,c,!1),this.renderButton(i,n,t);const u=a&&document.getElementById(a);if(c&&u){const e=d.getPaymentMethodOrThrow(n),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},i=t&&t.find(({id:e})=>"cart"===e);if(!(null==i?void 0:i.status))return;u.removeAttribute("data-pp-style-logo-type"),u.removeAttribute("data-pp-style-logo-position"),u.removeAttribute("data-pp-style-text-color"),u.removeAttribute("data-pp-style-text-size");const o=yield this.payPalSdkHelper.getPayPalMessages(e,c);this.renderMessages(o,a,i)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onComplete:r,onEligibilityFailure:a}=i,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:c}=d.initializationData||{},u={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,r)},p=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let m=!1;p.forEach(t=>{if(!m){const i=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o)},u),n&&l),c&&h),r=s.Buttons(i);r.isEligible()?(r.render(`#${e}`),m=!0):a&&"function"==typeof a&&a()}}),m||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Or(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return Or(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Or(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return Or(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}renderMessages(e,t,i){const n={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:Pr(i)};e.Messages(n).render(`#${t}`)}}const Tr=go(e=>new Ar(e,Cr(e),new Er(ue())),[{id:"bigcommerce_payments_paylater"}]);var kr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Rr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return kr(this,void 0,void 0,function*(){const{bigcommerce_payments_apms:t,containerId:i,methodId:n}=e,{apm:o,buyNowInitializeOptions:r,currencyCode:a}=t||{},s=!!r;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');if(!o)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms.apm" argument is not provided.');if(s&&!a)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments_apms.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');s||(yield this.paymentIntegrationService.loadDefaultCheckout());const d=s?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n,d,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{apm:n,buyNowInitializeOptions:o,style:r,onEligibilityFailure:a}=i,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(n))throw new yo('Unable to initialize PayPal button because "options.bigcommerce_payments_apms.apm" argument is not valid funding source.');const d={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:n,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},d),o&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return kr(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Dr=go(e=>new Rr(e,Cr(e)),[{id:"bigcommerce_payments_apms"}]);var Mr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Nr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Mr(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r}=t||{},a=!!o;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(a&&!r)throw new yo('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.bigcommerce_payments_venmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?r:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n,s,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onEligibilityFailure:r}=i,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(o)},d),n&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):r&&"function"==typeof r?r():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===ur.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return Mr(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Lr=go(e=>new Nr(e,Cr(e)),[{id:"bigcommerce_payments_venmo"}]);class zr extends Ce{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Ur,Fr,Br;!function(e){e.SandboxMode="bolt_sandbox",e.StagingMode="bolt_staging",e.DevelopmentMode="bolt_development"}(Ur||(Ur={})),function(e){e.Small="small",e.Medium="medium",e.Large="large"}(Fr||(Fr={})),function(e){e.Pill="pill",e.Rect="rect"}(Br||(Br={}));class xr{constructor(e,t,i=window){this.paymentIntegrationService=e,this.boltScriptLoader=t,this.boltHostWindow=i}initialize(e){return t=this,i=void 0,o=function*(){const{bolt:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,style:r}=t||{};if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.bolt" argument is not provided.');if(!Boolean(o))throw new zr("Only buy now flow is implemented for Bolt button");if(!(null==o?void 0:o.storefrontApiToken)||"string"!=typeof o.storefrontApiToken)throw new yo('Unable to initialize payment because "options.storefrontApiToken" argument is not provided.');const a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n),{initializationData:s,config:d}=a,{publishableKey:c,developerConfig:u}=s||{};yield this.boltScriptLoader.loadBoltClient(c,d.testMode,u,"BigCommerce",o.storefrontApiToken),this.renderButton(i,a,r)},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}deinitialize(){return Promise.resolve()}renderButton(e,t,i){var n;"function"==typeof(null===(n=this.boltHostWindow.BoltConnect)||void 0===n?void 0:n.setupProductPageCheckout)&&(this.addButtonContainer(e,t,i),this.boltHostWindow.BoltConnect.setupProductPageCheckout())}addButtonContainer(e,t,i){const n=document.getElementById(e);if(!n)return;const o=document.createElement("div"),r=document.createElement("object");o.setAttribute("id","product-page-checkout-wrapper"),o.setAttribute("class","bolt-button-wrapper"),o.setAttribute("style","display:none"),o.setAttribute("data-tid","product-page-checkout-wrapper"),r.setAttribute("data",this.getBoltObjectData(t,i)),r.setAttribute("class","bolt-product-checkout-button"),o.append(r),n.innerHTML="",n.append(o)}getBoltObjectData(e,t){const{initializationData:i,config:n}=e,{publishableKey:o,developerConfig:r}=i||{},a=this.boltScriptLoader.getDomainURL(!!n.testMode,r),s=this.getButtonHeight(null==t?void 0:t.size),d=this.getButtonBorderRadius(null==t?void 0:t.shape,s);return he({url:`https://${a}/v1/checkout_button`,query:{publishable_key:o,variant:"ppc",height:s,border_radius:d}})}getButtonHeight(e){if(e)switch(e){case Fr.Small:return 25;case Fr.Large:return 45;case Fr.Medium:default:return 40}}getButtonBorderRadius(e,t){if(e)switch(e){case Br.Pill:return t?Math.round(t/2):void 0;case Br.Rect:default:return 4}}}var qr=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class jr{constructor(e,t=window){this.scriptLoader=e,this.boltHostWindow=t}loadBoltClient(e,t,i,n,o){return qr(this,void 0,void 0,function*(){if(this.boltHostWindow.BoltCheckout)return this.boltHostWindow.BoltCheckout;if(!e)throw new yo('Unable to initialize payment because "publishableKey" argument is not provided.');if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,i)}/connect-bigcommerce.js`,this.getScriptOptions("bolt-connect",e,n,o)),yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,i)}/track.js`,this.getScriptOptions("bolt-track",e)),!this.boltHostWindow.BoltCheckout)throw new po;return this.boltHostWindow.BoltCheckout})}loadBoltEmbedded(e,t,i){return qr(this,void 0,void 0,function*(){if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,i)}/embed.js`,{async:!0,attributes:{id:"bolt-embedded"}}),!this.boltHostWindow.Bolt)throw new po;return this.boltHostWindow.Bolt(e)})}getDomainURL(e,t){if(!e)return"connect.bolt.com";if(t)switch(t.developerMode){case Ur.StagingMode:return"connect-staging.bolt.com";case Ur.DevelopmentMode:return`connect.${t.developerDomain}`}return"connect-sandbox.bolt.com"}getScriptOptions(e,t,i,n){return{async:!0,attributes:Object.assign(Object.assign({id:e,"data-publishable-key":t},i&&{"data-shopping-cart-id":i}),n&&{"data-storefront-api-token":n})}}}const Gr=go(e=>new xr(e,new jr(le())),[{id:"bolt"}]);class Hr extends yo{constructor(e){let t="Unable to submit payment for the order because the payload is invalid.";e&&(t=`${t} Make sure the following fields are provided correctly: ${e.join(", ")}.`),super(t),this.name="PaymentArgumentInvalidError"}}class Vr extends Ce{constructor(e,t){super(t||"Unable to proceed because the payment form contains invalid data."),this.details=e,this.name="PaymentInvalidFormError",this.type="payment_invalid_form"}}class Yr{constructor(e){const t=new Promise((e,t)=>{this.cancel=t});this.promise=Promise.race([e,t])}}let Wr=null;const $r=["buttons","messages"];var Kr,Zr,Qr,Jr,Xr,ea;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(Kr||(Kr={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Zr||(Zr={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(Qr||(Qr={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Jr||(Jr={})),function(e){e.PILL="pill",e.RECT="rect"}(Xr||(Xr={})),function(e){e.CART="cart",e.HOME="homepage",e.PAYMENT="payment",e.PRODUCT="product"}(ea||(ea={}));var ta=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ia{constructor(e,t,i){this.braintreeScriptLoader=e,this.braintreeHostWindow=t,this.overlay=i,this.dataCollectors={}}initialize(e,t){this.clientToken=e,this.threeDSecureOptions=t}getBraintreeFastlane(e,t,i){return ta(this,void 0,void 0,function*(){if(t&&(window.localStorage.setItem("axoEnv","sandbox"),window.localStorage.setItem("fastlaneEnv","sandbox")),!this.braintreeHostWindow.braintreeFastlane){const t=this.getClientTokenOrThrow(),n=yield this.getClient(),o=yield this.getSessionId(e),r=yield this.braintreeScriptLoader.loadFastlane(),a={root:{backgroundColorPrimary:"transparent"}};this.braintreeHostWindow.braintreeFastlane=yield r.create({authorization:t,client:n,deviceData:o,styles:i||a})}return this.braintreeHostWindow.braintreeFastlane})}getClient(){return ta(this,void 0,void 0,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=t.create({authorization:e})}return this.client})}getPaypal(){return this.braintreePaypal||(this.braintreePaypal=Promise.all([this.getClient(),this.braintreeScriptLoader.loadPaypal()]).then(([e,t])=>t.create({client:e}))),this.braintreePaypal}paypal(e){var{shouldSaveInstrument:t}=e,i=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["shouldSaveInstrument"]);const n=pe();return this.getPaypal().then(e=>{var o;return n&&(null===(o=this.overlay)||void 0===o||o.show({onClick:()=>e.focusWindow()})),e.tokenize(Object.assign({enableShippingAddress:!0,flow:t?"vault":"checkout",useraction:"commit"},i))}).then(e=>{var t;return null===(t=this.overlay)||void 0===t||t.remove(),e}).catch(e=>{var t;throw null===(t=this.overlay)||void 0===t||t.remove(),e})}getPaypalCheckout(e,t,i){return ta(this,void 0,void 0,function*(){const n=yield this.getClient(),o=yield this.braintreeScriptLoader.loadPaypalCheckout(),r={client:n};return this.paypalCheckout=yield o.create(r,(n,o)=>{var r;if(n)return i(n);const a=Object.assign(Object.assign({currency:e.currency},e.isCreditEnabled&&{"enable-funding":"paylater"}),{components:$r.toString(),intent:e.intent,commit:null===(r=e.commit)||void 0===r||r});this.braintreeHostWindow.paypal?t(o):function(e,t){return Wr||(Wr=new Promise((i,n)=>{e.loadPayPalSDK(t,t=>{t?(Wr=null,n(t)):i(e)})})),Wr}(o,a).then(()=>t(o))}),this.paypalCheckout})}getDataCollector(e){return ta(this,void 0,void 0,function*(){const t=(null==e?void 0:e.paypal)?"paypal":"default";let i=this.dataCollectors[t];if(!i){try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),o=Object.assign({client:t,kount:!0},e);i=yield n.create(o)}catch(e){if(!qo(e)||"DATA_COLLECTOR_KOUNT_NOT_ENABLED"!==e.code)throw e;i={deviceData:void 0,teardown:()=>Promise.resolve()}}this.dataCollectors[t]=i}return i})}getBraintreeEnv(e=!1){return e?jo.Sandbox:jo.Production}mapToBraintreeShippingAddressOverride(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}mapToLegacyShippingAddress(e){const{email:t,phone:i,shippingAddress:n}=e,o=(null==n?void 0:n.recipientName)||"",[r,a]=o.split(" ");return{email:t,first_name:r||"",last_name:a||"",phone_number:i,address_line_1:null==n?void 0:n.line1,address_line_2:null==n?void 0:n.line2,city:null==n?void 0:n.city,state:null==n?void 0:n.state,country_code:null==n?void 0:n.countryCode,postal_code:null==n?void 0:n.postalCode}}mapToLegacyBillingAddress(e){const{billingAddress:t,email:i,firstName:n,lastName:o,phone:r,shippingAddress:a}=e,s=t||a;return{email:i,first_name:n,last_name:o,phone_number:r,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}removeElement(e){const t=e&&document.getElementById(e);t&&t.remove()}getSessionId(e){return ta(this,void 0,void 0,function*(){const{deviceData:t}=yield this.getDataCollector({riskCorrelationId:e});return t})}teardown(){return ta(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollectors.default),yield this.teardownModule(this.dataCollectors.paypal),this.dataCollectors={},yield this.teardownModule(this.paypalCheckout),this.paypalCheckout=void 0})}get3DS(){return ta(this,void 0,void 0,function*(){return this.threeDS||(this.threeDS=Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]).then(([e,t])=>t.create({client:e,version:2}))),this.threeDS})}getVenmoCheckout(e){return ta(this,void 0,void 0,function*(){if(!this.venmoCheckout){const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadVenmoCheckout(),n=Object.assign({client:t,allowDesktop:!0,paymentMethodUsage:"multi_use"},e||{});this.venmoCheckout=yield new Promise((e,t)=>{i.create(n,(i,n)=>i?t(i):n.isBrowserSupported()?void e(n):t(new Mo))})}return this.venmoCheckout})}verifyCard(e,t,i){return ta(this,void 0,void 0,function*(){const n=yield this.tokenizeCard(e,t);return this.challenge3DSVerification(n,i)})}tokenizeCard(e,t){return ta(this,void 0,void 0,function*(){const{paymentData:i}=e;if(!function(e){if("object"!=typeof e||null===e)return!1;const t=e;return"object"==typeof t.ccExpiry&&null!==t.ccExpiry&&"string"==typeof t.ccNumber&&"string"==typeof t.ccName}(i))throw new Hr(["payment.paymentData"]);const n=this.getErrorsRequiredFields(i);if(!f(n))throw new Vr(n);const o=this.mapToCreditCard(i,t),r=yield this.getClient(),{creditCards:a}=yield r.request(o);return{nonce:a[0].nonce,bin:a[0].details.bin}})}challenge3DSVerification(e,t){return ta(this,void 0,void 0,function*(){const i=yield this.get3DS();return this.present3DSChallenge(i,t,e)})}teardownModule(e){return e?e.teardown():Promise.resolve()}getClientTokenOrThrow(){if(!this.clientToken)throw new io(Jn.PaymentNotInitialized);return this.clientToken}getErrorsRequiredFields(e){const{ccNumber:t,ccExpiry:i}=e,n={};return t||(n.ccNumber=[{message:"Credit card number is required",type:"required"}]),i||(n.ccExpiry=[{message:"Expiration date is required",type:"required"}]),n}mapToCreditCard(e,t){return{data:{creditCard:{cardholderName:e.ccName,number:e.ccNumber,cvv:e.ccCvv,expirationDate:`${e.ccExpiry.month}/${e.ccExpiry.year}`,options:{validate:!1},billingAddress:t&&{countryCodeAlpha2:t.countryCode,locality:t.city,countryName:t.country,postalCode:t.postalCode,streetAddress:t.address2?`${t.address1} ${t.address2}`:t.address1}}},endpoint:"payment_methods/credit_cards",method:"post"}}present3DSChallenge(e,t,i){const{nonce:n,bin:o}=i;if(!this.threeDSecureOptions||!n)throw new io(Jn.PaymentNotInitialized);const{addFrame:r,removeFrame:a,challengeRequested:s=!0,additionalInformation:d}=this.threeDSecureOptions,c=()=>ta(this,void 0,void 0,function*(){const t=yield e.cancelVerifyCard();return l.cancel(new Qo),t}),u=t.toFixed(2),l=new Yr(e.verifyCard({addFrame:(e,t)=>{r&&r(e,t,c)},amount:Number(u),bin:o,challengeRequested:s,nonce:n,removeFrame:a,onLookupComplete:(e,t)=>{t()},collectDeviceData:!0,additionalInformation:d}));return l.promise}}function na(e){const{color:t,fundingicons:i,height:n=40,layout:o,shape:r,size:a,tagline:s}=e||{},d={color:t,fundingicons:i,height:oa(n),layout:o,shape:r||"rect",size:a,tagline:s};return R(d,C)}function oa(e){const t=Number(e);return!t||Number.isNaN(t)?40:t>55?55:t<25?25:t}function ra(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}var aa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class sa{constructor(e,t,i,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=i,this.braintreeHostWindow=n}initialize(e){return aa(this,void 0,void 0,function*(){const{braintreepaypal:t,containerId:i,methodId:n}=e;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let o,r=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new yo('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');o=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow().currency.code;const a=r.getPaymentMethodOrThrow(n),{clientToken:s,config:d,initializationData:c}=a;if(!s||!c)throw new Xn(Qn.MissingPaymentMethod);const u={currency:o,intent:c.intent,isCreditEnabled:c.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(u,e=>{this.renderPayPalButton(e,t,i,n,!!d.testMode)},e=>this.handleError(e,i,t.onError))})}deinitialize(){return aa(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,i,n,o){const{style:r,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:d}=t,{paypal:c}=this.braintreeHostWindow;if(c){const u=c.Buttons({env:o?"sandbox":"production",fundingSource:c.FUNDING.PAYPAL,style:na(r),createOrder:()=>this.setupPayment(e,t,n),onApprove:t=>this.tokenizePayment(t,e,n,a,s)});u.isEligible()?u.render(`#${i}`):d&&"function"==typeof d&&d()}else this.braintreeIntegrationService.removeElement(i)}setupPayment(e,t,i){var n;return aa(this,void 0,void 0,function*(){const{onPaymentError:o,shippingAddress:r,buyNowInitializeOptions:a}=t;try{const o="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==o?void 0:o.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(i),u=o?o.cartAmount:s.getCartOrThrow().cartAmount,l=o?t.currencyCode:s.getCartOrThrow().currency.code,h=r||(null==d?void 0:d.addresses[0]),p=h?ra(h):void 0;return yield e.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,shippingAddressOverride:p,amount:u,currency:l,offerCredit:!1,intent:null===(n=c.initializationData)||void 0===n?void 0:n.intent})}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}tokenizePayment(e,t,i,n,o){return aa(this,void 0,void 0,function*(){try{const{deviceData:o}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:a,nonce:s}=r,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:i,action:n?"process_payment":"set_external_checkout",nonce:s,device_data:o,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),r}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}createBuyNowCart(e){return aa(this,void 0,void 0,function*(){if(!e)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new fo}})}handleError(e,t,i){if(this.braintreeIntegrationService.removeElement(t),!i||!qo(e))throw e;i(e)}}const da=go(e=>{const t=window,n=new Do(e),o=new ia(new Zo(le(),t,n),t);return new sa(e,i(),o,t)},[{id:"braintreepaypal"}]);class ca{constructor(e){this.paymentIntegrationService=e,this.braintreeHostWindow=window}render(e,t,i){const n=t&&document.getElementById(t);if(this.braintreeHostWindow.paypal&&n){const o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow(),a=o.getBillingAddressOrThrow(),s=o.getPaymentMethodOrThrow(e);if(!s.initializationData)return;const{paypalBNPLConfiguration:d=[]}=s.initializationData,c=i===ea.PAYMENT?"checkout":i,u=d&&d.find(({id:e})=>e===c);if(!u||!u.status)return;i===ea.CART&&(n.removeAttribute("data-pp-style-logo-type"),n.removeAttribute("data-pp-style-logo-position"),n.removeAttribute("data-pp-style-text-color"),n.removeAttribute("data-pp-style-text-size")),this.braintreeHostWindow.paypal.Messages({amount:r.cartAmount,buyerCountry:a.countryCode,placement:i,style:this.getPaypalMessagesStylesFromBNPLConfig(u)}).render(`#${t}`)}}getPaypalMessagesStylesFromBNPLConfig({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t}}var ua=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class la{constructor(e,t,i,n,o){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=i,this.braintreeMessages=n,this.braintreeHostWindow=o}initialize(e){var t,i;return ua(this,void 0,void 0,function*(){const{braintreepaypalcredit:n,containerId:o,methodId:r}=e;if(!r)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!o)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let a,s=this.paymentIntegrationService.getState();if(n.buyNowInitializeOptions){if(!n.currencyCode)throw new yo('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');a=n.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),s=this.paymentIntegrationService.getState(),a=s.getCartOrThrow().currency.code;const d=s.getPaymentMethodOrThrow(r),{clientToken:c,config:u,initializationData:l}=d;if(!c||!l)throw new Xn(Qn.MissingPaymentMethod);const h={currency:a,intent:l.intent,isCreditEnabled:l.isCreditEnabled,commit:!1},p=Ao(null!==(i=null===(t=s.getStoreConfig())||void 0===t?void 0:t.checkoutSettings.features)&&void 0!==i?i:{},"PAYPAL-5663.hide_braintree_card_banner_implementation_in_checkout_sdk");this.braintreeIntegrationService.initialize(c),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{!p&&n.messagingContainerId&&this.renderPayPalMessages(r,n.messagingContainerId),this.renderPayPalButton(e,n,o,r,!!u.testMode)},e=>this.handleError(e,o,n.onError))})}deinitialize(){return ua(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalMessages(e,t){this.braintreeMessages.render(e,t,ea.CART)}renderPayPalButton(e,t,i,n,o){const{style:r,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:d}=t,{paypal:c}=this.braintreeHostWindow;let u=!1;c&&[c.FUNDING.PAYLATER,c.FUNDING.CREDIT].forEach(l=>{const h=l===c.FUNDING.CREDIT?Object.assign({label:Jr.CREDIT},na(r)):na(r);if(!u){const r=c.Buttons({env:o?"sandbox":"production",fundingSource:l,style:h,createOrder:()=>this.setupPayment(e,t,n),onApprove:t=>this.tokenizePayment(t,e,n,a,s)});r.isEligible()?(r.render(`#${i}`),u=!0):c.FUNDING.CREDIT&&d&&"function"==typeof d&&d()}}),c&&u||this.braintreeIntegrationService.removeElement(i)}setupPayment(e,t,i){var n;return ua(this,void 0,void 0,function*(){const{onPaymentError:o,shippingAddress:r,buyNowInitializeOptions:a}=t;try{const o="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==o?void 0:o.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(i),u=o?o.cartAmount:s.getCartOrThrow().cartAmount,l=o?t.currencyCode:s.getCartOrThrow().currency.code,h=r||(null==d?void 0:d.addresses[0]),p=h?ra(h):void 0;return yield e.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,shippingAddressOverride:p,amount:u,currency:l,offerCredit:!0,intent:null===(n=c.initializationData)||void 0===n?void 0:n.intent})}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}tokenizePayment(e,t,i,n,o){return ua(this,void 0,void 0,function*(){try{const{deviceData:o}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:a,nonce:s}=r,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:i,action:n?"process_payment":"set_external_checkout",nonce:s,device_data:o,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),r}catch(e){throw o&&(qo(e)||e instanceof Ce)&&o(e),e}})}createBuyNowCart(e){return ua(this,void 0,void 0,function*(){if(!e)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new fo}})}handleError(e,t,i){if(this.braintreeIntegrationService.removeElement(t),!i||!qo(e))throw e;i(e)}}const ha=go(e=>{const t=window,n=new Do(e),o=new ia(new Zo(le(),t,n),t),r=new ca(e);return new la(e,i(),o,r,t)},[{id:"braintreepaypalcredit"}]);var pa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ma{constructor(e,t,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=i}initialize(e){return pa(this,void 0,void 0,function*(){const{containerId:t,methodId:i}=e;if(!i)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const n=this.paymentIntegrationService.getState(),{clientToken:o,initializationData:r,config:a}=n.getPaymentMethodOrThrow(i);if(!o||!r)throw new Xn(Qn.MissingPaymentMethod);this.braintreeSdk.initialize(o);const s=yield this.braintreeSdk.getBraintreeVisaCheckout(),{currency:{code:d},cartAmount:c}=n.getCartOrThrow(),u=yield this.braintreeSdk.getVisaCheckoutSdk(a.testMode),l=s.createInitOptions({paymentRequest:{currencyCode:d,subtotal:String(c)},settings:{shipping:{collectShipping:!0}}});this.createSignInButton(t),yield u.init(l),u.on("payment.success",e=>pa(this,void 0,void 0,function*(){yield this.paymentSuccess(s,e)}))})}deinitialize(){return Promise.resolve()}paymentSuccess(e,t){return pa(this,void 0,void 0,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const i=this.paymentIntegrationService.getState(),n=i.getShippingAddress(),o=i.getBillingAddress(),{shippingAddress:r=this.toVisaCheckoutAddress(n),billingAddress:a=this.toVisaCheckoutAddress(o)}=e;return this.postForm(Object.assign(Object.assign({},e),{shippingAddress:r,billingAddress:a}),t)})})}postForm(e,t){const{userData:i,billingAddress:n,shippingAddress:o,details:r}=e,{userEmail:a}=i,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:r.cardType,number:r.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,n)),shipping_address:JSON.stringify(this.getAddress(a,o))})}toVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}createSignInButton(e){const t=document.querySelector(`#${e}`);if(!t)throw new Error("Need a container to place the button");return this.insertVisaCheckoutButton(t)}insertVisaCheckoutButton(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-end",t.innerHTML='\n <img\n alt="Visa Checkout"\n class="v-button"\n role="button"\n src="https://secure.checkout.visa.com/wallet-services-web/xo/button.png?acceptCanadianVisaDebit=false&cobrand=true&height=34&width=178"\n />\n <a class="v-learn v-learn-default" style="text-align: right; display: block; font-size: 10px; color: #003366;" href="#" data-locale="en_US">Tell Me More</a>',e.appendChild(t),t}}const ga=go(e=>{const t=window,n=new Do(e),o=new Yo(new Zo(le(),t,n));return new ma(e,i(),o)},[{id:"braintreevisacheckout"}]);function ya(e){const{billingAddress:t,email:i,firstName:n,lastName:o,phone:r,shippingAddress:a}=e,s=t||a;return{email:i,first_name:n,last_name:o,phone_number:r,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}function fa(e){const{email:t,phone:i,shippingAddress:n}=e,o=(null==n?void 0:n.recipientName)||"",[r,a]=o.split(" ");return{email:t,first_name:r||"",last_name:a||"",phone_number:i,address_line_1:null==n?void 0:n.line1,address_line_2:null==n?void 0:n.line2,city:null==n?void 0:n.city,state:null==n?void 0:n.state,country_code:null==n?void 0:n.countryCode,postal_code:null==n?void 0:n.postalCode}}var va=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};const Sa=e=>{const{color:t,height:i}=e;return{backgroundColor:(n=t||"",n===Qr.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("/app/assets/img/payment-providers/venmo-logo-${t===Qr.WHITE?Qr.BLUE:Qr.WHITE}.svg")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${i||40}px`,minWidth:"150px",height:"100%",width:"100%",border:t===Qr.WHITE?"1px solid black":"none"};var n};class Ca{constructor(e,t,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=i,this.onError=T}initialize(e){return va(this,void 0,void 0,function*(){const{braintreevenmo:t,containerId:i,methodId:n}=e;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');const o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n),{clientToken:r,initializationData:a}=o,{paymentButtonStyles:s}=a,{cartButtonStyles:d}=s||{},c=(null==t?void 0:t.style)||d;if(!r||!a)throw new Xn(Qn.MissingPaymentMethod);if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadDefaultCheckout(),this.onError=(null==t?void 0:t.onError)||this.handleError,this.braintreeSdk.initialize(r);try{const e=yield this.braintreeSdk.getVenmoCheckoutOrThrow();this.renderVenmoButton(e,i,null==t?void 0:t.buyNowInitializeOptions,c)}catch(e){(function(e){return"object"==typeof e&&null!==e&&"name"in e&&"BraintreeError"===e.name}(e)||function(e){return e instanceof Mo}(e))&&this.handleInitializationVenmoError(e,i)}})}deinitialize(){return va(this,void 0,void 0,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}handleError(e){throw new Error(e.message)}createBuyNowCart(e){return va(this,void 0,void 0,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=null==e?void 0:e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}}})}handleInitializationVenmoError(e,t){return this.removeVenmoContainer(t),this.onError(e)}removeVenmoContainer(e){const t=document.getElementById(e);t&&t.remove()}renderVenmoButton(e,t,i,n){const o=document.getElementById(t),{color:r}=n||{};if(!o)throw new yo("Unable to create wallet button without valid container ID.");o.setAttribute("aria-label","Venmo"),Object.assign(o.style,Sa(n||{})),o.addEventListener("click",()=>va(this,void 0,void 0,function*(){o.setAttribute("disabled","true");const t=yield this.createBuyNowCart(i);e.tokenize&&e.tokenize((e,i)=>va(this,void 0,void 0,function*(){o.removeAttribute("disabled"),e&&this.onError(e),yield this.handlePostForm(i,null==t?void 0:t.id)}))})),r===Qr.BLUE&&(o.addEventListener("mouseenter",()=>{o.style.backgroundColor="#0a7fc2"}),o.addEventListener("mouseleave",()=>{o.style.backgroundColor=Sa(n||{}).backgroundColor}))}handlePostForm(e,t){return va(this,void 0,void 0,function*(){const{deviceData:i}=yield this.braintreeSdk.getDataCollectorOrThrow(),{nonce:n,details:o}=e;this.formPoster.postForm("/checkout.php",Object.assign({nonce:n,provider:"braintreevenmo",payment_type:"paypal",device_data:i,action:"set_external_checkout",billing_address:JSON.stringify(ya(o)),shipping_address:JSON.stringify(fa(o))},t&&{cart_id:t}))})}}const Ia=go(e=>{const t=window,n=le(),o=new Do(e),r=new Zo(n,t,o),a=new Yo(r);return new Ca(e,i(),a)},[{id:"braintreevenmo"}]);var _a;!function(e){e.ADYEN_V2="googlepayadyenv2",e.ADYEN_V3="googlepayadyenv3",e.AUTHORIZE_NET="googlepayauthorizenet",e.BNZ="googlepaybnz",e.BRAINTREE="googlepaybraintree",e.PAYPAL_COMMERCE="googlepaypaypalcommerce",e.BIGCOMMERCE_PAYMENTS="googlepay_bigcommerce_payments",e.CHECKOUT_COM="googlepaycheckoutcom",e.CYBERSOURCE_V2="googlepaycybersourcev2",e.ORBITAL="googlepayorbital",e.STRIPE="googlepaystripe",e.STRIPE_UPE="googlepaystripeupe",e.STRIPE_OCS="googlepaystripeocs",e.WORLDPAY_ACCESS="googlepayworldpayaccess",e.TD_ONLINE_MART="googlepaytdonlinemart"}(_a||(_a={}));const wa=function(e,t,i){return t&&i?ba(0,t,i):function(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(i=>{const n=Object.getOwnPropertyDescriptor(e.prototype,i);n&&"constructor"!==i&&Object.defineProperty(t.prototype,i,ba(e.prototype,i,n))}),t}(e)};function ba(e,t,i){if("function"!=typeof i.value)return i;let n=i.value;return{get(){const e=n.bind(this);return Object.defineProperty(this,t,Object.assign(Object.assign({},i),{value:e})),e},set(e){n=e}}}class Ea{constructor(e){if(!e)throw new Error("Currency settings missing");const{decimalPlaces:t,symbolLocation:i,symbol:n,thousandsSeparator:o,decimalSeparator:r}=e;if("string"!=typeof i||"string"!=typeof n||"string"!=typeof o||"string"!=typeof r||"string"!=typeof t)throw new yo("Invalid currency settings provided");this._decimalPlaces=parseInt(t,10),this._symbolLocation=i,this._symbol=n,this._thousandsSeparator=o,this._decimalSeparator=r}format(e){if("number"!=typeof e)throw new yo("Invalid amount provided");const t=this._formatNumber(e),i=this._formatCurrency(t);return e<0?`-${i}`:i}_formatNumber(e){const t=Math.abs(e),[i,n=""]=this._toFixed(t,this._decimalPlaces).split("."),o=i.replace(/\B(?=(\d{3})+(?!\d))/g,this._thousandsSeparator);return this._decimalPlaces<1?o:[o,n].join(this._decimalSeparator)}_formatCurrency(e){return"left"===this._symbolLocation.toLowerCase()?`${this._symbol}${e}`:`${e}${this._symbol}`}_toFixed(e,t){return(+`${Math.round(+`${e}e${t}`)}e${-t}`).toFixed(t)}}let Pa=class{constructor(e){this._storeConfig=e,this._customerFormatter=new Ea(this._storeConfig.shopperCurrency),this._storeFormatter=new Ea(this._storeConfig.currency)}toCustomerCurrency(e){const t=this._storeConfig.shopperCurrency.exchangeRate;return this._customerFormatter.format(e*t)}toStoreCurrency(e){return this._storeFormatter.format(e)}};Pa=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([wa],Pa);const Oa=Pa;var Aa,Ta,ka,Ra,Da,Ma,Na,La,za;function Ua(e){return e in Ma}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(Aa||(Aa={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Ta||(Ta={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ka||(ka={})),function(e){e.pill="pill",e.rect="rect"}(Ra||(Ra={})),function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(Da||(Da={})),function(e){e.AMEX="AMEX",e.DISCOVER="DISCOVER",e.INTERAC="INTERAC",e.JCB="JCB",e.MC="MASTERCARD",e.VISA="VISA"}(Ma||(Ma={})),function(e){e.OFFER="OFFER",e.PAYMENT_AUTHORIZATION="PAYMENT_AUTHORIZATION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.SHIPPING_OPTION="SHIPPING_OPTION"}(Na||(Na={})),function(e){e.OFFER_INVALID="OFFER_INVALID",e.PAYMENT_DATA_INVALID="PAYMENT_DATA_INVALID",e.SHIPPING_ADDRESS_INVALID="SHIPPING_ADDRESS_INVALID",e.SHIPPING_ADDRESS_UNSERVICEABLE="SHIPPING_ADDRESS_UNSERVICEABLE",e.SHIPPING_OPTION_INVALID="SHIPPING_OPTION_INVALID",e.OTHER_ERROR="OTHER_ERROR"}(La||(La={})),function(e){e.INITIALIZE="INITIALIZE",e.SHIPPING_OPTION="SHIPPING_OPTION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.OFFER="OFFER"}(za||(za={}));var Fa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ba{constructor(e,t){this._gatewayIdentifier=e,this._paymentIntegrationService=t,this._isBuyNowFlow=!1,this._shouldRequestShipping=!0}mapToShippingAddressRequestBody({shippingAddress:e}){if(!e)return;const{company:t="",phone:i=""}=this._paymentIntegrationService.getState().getShippingAddress()||{};return this._mapToAddressRequestBody(e,t,i)}mapToBillingAddressRequestBody(e){const{billingAddress:t}=e.paymentMethodData.info;if(!t)return;const{company:i="",phone:n="",email:o,customFields:r=[]}=this._paymentIntegrationService.getState().getBillingAddress()||{};return Object.assign(Object.assign({},this._mapToAddressRequestBody(t,i,n,r)),{email:o||e.email})}mapToExternalCheckoutData(e){var t;const{paymentMethodData:{tokenizationData:{token:i},info:{cardNetwork:n,cardDetails:o}}}=e;if(!i)throw new Xn(Qn.MissingPaymentToken);return Promise.resolve(Object.assign({nonce:i,card_information:{type:n,number:o}},this._isBuyNowFlow&&{cart_id:null===(t=this._paymentIntegrationService.getState().getCart())||void 0===t?void 0:t.id}))}getRequiredData(){var e;return Fa(this,void 0,void 0,function*(){const t={emailRequired:!0};if(!this._isShippingAddressRequired())return t;const i=yield this._paymentIntegrationService.loadShippingCountries(),n=null===(e=i.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code);return Object.assign(Object.assign({},t),{shippingAddressRequired:!0,shippingAddressParameters:Object.assign({phoneNumberRequired:!0},n&&{allowedCountryCodes:n}),shippingOptionRequired:!0})})}getCallbackIntents(){return this._isShippingAddressRequired()?[Na.OFFER,Na.SHIPPING_ADDRESS,Na.SHIPPING_OPTION]:[Na.OFFER]}getCallbackTriggers(){return{availableTriggers:[za.INITIALIZE,za.SHIPPING_ADDRESS,za.SHIPPING_OPTION,za.OFFER],initializationTrigger:[za.INITIALIZE],addressChangeTriggers:[za.INITIALIZE,za.SHIPPING_ADDRESS],shippingOptionsChangeTriggers:[za.SHIPPING_OPTION],offerChangeTriggers:[za.OFFER]}}getNonce(e){var t;const i=null===(t=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.nonce;if(!i)throw new Xn(Qn.MissingPaymentToken);return Promise.resolve(i)}extraPaymentData(){return Promise.resolve(void 0)}getMerchantInfo(){const{googleMerchantName:e,googleMerchantId:t,platformToken:i}=this.getGooglePayInitializationData();return{merchantName:e,merchantId:t,authJwt:i}}getTransactionInfo(){let e;if(this._isBuyNowFlow)e=this._getCurrencyCodeOrThrow();else{const{getCartOrThrow:t}=this._paymentIntegrationService.getState();e=t().currency.code}const t=this.getGooglePayInitializationData().storeCountry;return Object.assign(Object.assign({},t&&{countryCode:t}),{currencyCode:e,totalPriceStatus:Da.ESTIMATED,totalPrice:"0"})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData().gatewayMerchantId;if(!e)throw new yo("Unable to proceed, gatewayMerchantId is missing.");return{gateway:this._gatewayIdentifier,gatewayMerchantId:e}}getCardParameters(){return{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:this.getPaymentMethod().supportedCards.filter(Ua).map(e=>Ma[e]),billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}initialize(e,t,i){return this._getPaymentMethodFn=e,this._isBuyNowFlow=Boolean(t),this._currencyCode=i,this._isBuyNowFlow&&this._getCurrencyCodeOrThrow(),Promise.resolve()}handleShippingAddressChange(e){var t,i,n,o;return Fa(this,void 0,void 0,function*(){e&&(e.name=e.name||"",e.address1=e.address1||"");const r=this.mapToShippingAddressRequestBody({shippingAddress:e});r&&(yield this._paymentIntegrationService.updateShippingAddress(r));const a=this._paymentIntegrationService.getState(),s=a.getConsignments();if(!(null==s?void 0:s[0]))return;const d=s[0],c=a.getStoreConfigOrThrow();this._currencyService||(this._currencyService=new Oa(c));const u=(d.availableShippingOptions||[]).map(this._getGooglePayShippingOption.bind(this)),l=null===(t=d.availableShippingOptions)||void 0===t?void 0:t.find(e=>e.isRecommended);if(u.length){const e=(null===(i=d.selectedShippingOption)||void 0===i?void 0:i.id)||(null==l?void 0:l.id)||(null===(n=u[0])||void 0===n?void 0:n.id);return!(null===(o=d.selectedShippingOption)||void 0===o?void 0:o.id)&&u[0]&&(yield this.handleShippingOptionChange((null==l?void 0:l.id)||u[0].id)),{defaultSelectedOptionId:e,shippingOptions:u}}})}handleShippingOptionChange(e){return Fa(this,void 0,void 0,function*(){if("shipping_option_unselected"!==e)return this._paymentIntegrationService.selectShippingOption(e)})}getTotalPrice(){const{getCheckoutOrThrow:e,getCartOrThrow:t}=this._paymentIntegrationService.getState(),{decimalPlaces:i}=t().currency;return L(e().outstandingBalance,i).toFixed(i)}handleCoupons(e){return Fa(this,void 0,void 0,function*(){const{redemptionCodes:t=[]}=e,{offers:i}=this.getAppliedCoupons();let n;return yield t.reduce((e,t)=>Fa(this,void 0,void 0,function*(){if(yield e,i.some(({redemptionCode:e})=>e===t))return;const o=yield this.applyCoupon(t);o&&(n=o)}),Promise.resolve()),yield i.reduce((e,i)=>Fa(this,void 0,void 0,function*(){yield e,t.includes(i.redemptionCode)||(yield this._paymentIntegrationService.removeCoupon(i.redemptionCode))}),Promise.resolve()),{newOfferInfo:this.getAppliedCoupons(),error:n}})}getAppliedCoupons(){const e=this._paymentIntegrationService.getState(),{coupons:t}=e.getCheckout()||{};return{offers:(t||[]).map(e=>{const{displayName:t,code:i}=e;return{redemptionCode:i,description:t}})}}applyCoupon(e){return Fa(this,void 0,void 0,function*(){let t;try{yield this._paymentIntegrationService.applyCoupon(e)}catch(e){return e instanceof Error&&(t={reason:La.OFFER_INVALID,message:e.message,intent:za.OFFER}),t}})}setShouldRequestShipping(e){this._shouldRequestShipping=e}getGooglePayInitializationData(){return to(this.getPaymentMethod().initializationData,()=>new yo("Missing initialization data."))}getPaymentMethod(){return to(this._getPaymentMethodFn,()=>new io(Jn.PaymentNotInitialized))()}getGatewayIdentifier(){return this._gatewayIdentifier}setGatewayIdentifier(e){this._gatewayIdentifier=e||this.getGatewayIdentifier()}_isShippingAddressRequired(){const{getCartOrThrow:e,getStoreConfigOrThrow:t,getShippingAddress:i}=this._paymentIntegrationService.getState(),n=t();let o;return o=Ao(n.checkoutSettings.features,"PI-4290.google_pay_require_shipping_address")?this._shouldRequestShipping:void 0===i(),o&&(r=e(),a=n,!!r&&(!!r.lineItems.physicalItems.some(e=>e.isShippingRequired)||!(!a||!r.lineItems.customItems)&&r.lineItems.customItems.length>0));var r,a}_mapToAddressRequestBody(e,t,i,n){const{name:o,address1:r,address2:a,address3:s,locality:d,administrativeArea:c,countryCode:u,postalCode:l,phoneNumber:h}=e,[p,m]=this._getFirstAndLastName(o);return{firstName:p,lastName:m,company:t,address1:r,address2:`${a} ${s}`.trim(),city:d||c,stateOrProvince:c,stateOrProvinceCode:c,countryCode:u,postalCode:l,phone:h||i,customFields:n||[]}}_getFirstAndLastName(e){const t=e.split(" ");return 1===t.length?[e,""]:[t.slice(0,-1).join(" "),t[t.length-1]]}_getCurrencyCodeOrThrow(){return to(this._currencyCode,()=>new yo('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}_getGooglePayShippingOption({id:e,cost:t,description:i,additionalDescription:n}){var o;const r=null===(o=this._currencyService)||void 0===o?void 0:o.toCustomerCurrency(t);return this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-3540.googlepay_new_shipping_options_description"]?{id:e,label:`${r||t} ${i}`,description:n}:{id:e,label:i,description:r||t}}}var xa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class qa extends Ba{constructor(e,t){super("braintree",e),this._braintreeSdk=t,this._methodId=_a.BRAINTREE,this._service=e}initialize(e,t,i){const n=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return xa(this,void 0,void 0,function*(){yield n.initialize.call(this,e,t,i);let o=n.getPaymentMethod.call(this);if(o.clientToken||(o=(yield this._service.loadPaymentMethod(this._methodId)).getPaymentMethodOrThrow(this._methodId)),!o.clientToken||!o.initializationData)throw new Xn(Qn.MissingPaymentMethod);return this._braintreeSdk.initialize(o.clientToken),this._braintreeGooglePayment=yield this._braintreeSdk.getBraintreeGooglePayment(),Promise.resolve()})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});var i;return xa(this,void 0,void 0,function*(){const n=yield t.getNonce.call(this,e),{clientToken:o,initializationData:r}=t.getPaymentMethod.call(this);if(!o||!r||!(null===(i=r.card_information)||void 0===i?void 0:i.bin))throw new Xn(Qn.MissingPaymentMethod);const{isThreeDSecureEnabled:a,card_information:{bin:s,isNetworkTokenized:d}}=r;if(a&&!d){const e=yield this._braintreeSdk.getBraintreeThreeDS(),{orderAmount:t}=this._service.getState().getOrderOrThrow();return(yield this._braintreePresent3DSChallenge(e,t,n,s)).nonce}return n})}extraPaymentData(){return xa(this,void 0,void 0,function*(){return{deviceSessionId:yield this._getBraintreeDeviceData()}})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return xa(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);let n;try{n=JSON.parse(i.nonce)}catch(e){throw new yo("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"androidPayCards"in e}(e))throw new Xn(Qn.MissingPaymentToken)}(n),i.nonce=n.androidPayCards[0].nonce,i.card_information.bin=n.androidPayCards[0].details.bin,i.card_information.isNetworkTokenized=n.androidPayCards[0].details.isNetworkTokenized,i})}getCardParameters(){return super.getCardParameters()}getPaymentGatewayParameters(){const e=Object.create(null,{getMerchantInfo:{get:()=>super.getMerchantInfo},getTransactionInfo:{get:()=>super.getTransactionInfo},getRequiredData:{get:()=>super.getRequiredData}});return xa(this,void 0,void 0,function*(){return this.getBraintreeGooglePayment().createPaymentDataRequest(Object.assign({merchantInfo:e.getMerchantInfo.call(this),transactionInfo:e.getTransactionInfo.call(this),cardRequirements:{billingAddressRequired:!0,billingAddressFormat:"FULL"}},yield e.getRequiredData.call(this))).paymentMethodTokenizationParameters.parameters})}getBraintreeGooglePayment(){if(!this._braintreeGooglePayment)throw new Xn(Qn.MissingPaymentMethod);return this._braintreeGooglePayment}_getBraintreeDeviceData(){return xa(this,void 0,void 0,function*(){const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e})}_braintreePresent3DSChallenge(e,t,i,n){return new Yr(e.verifyCard({amount:t,bin:n,nonce:i,onLookupComplete:(e,t)=>{t()}})).promise}}class ja extends Ce{constructor(e){super(e||"Unable to proceed because the client library of a payment method has thrown an unexpected error."),this.name="PaymentMethodFailedError",this.type="payment_method_client_invalid"}}var Ga=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ha{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t,i;return Ga(this,void 0,void 0,function*(){if(!e.methodId||(n=e.methodId,!Object.values(_a).includes(n)))throw new yo('Unable to proceed because "methodId" is not a valid key.');var n;if(this._methodId=e.methodId,!e.containerId)throw new yo('Unable to proceed because "containerId" is not a valid key.');const o=e[this._getMethodOrThrow()];if(!o)throw new yo("Unable to proceed without valid options.");const{buyNowInitializeOptions:r,currencyCode:a,buttonColor:s,buttonType:d,onError:c}=o;let u,l=this._paymentIntegrationService.getState();try{u=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}catch(e){l=yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodOrThrow()),u=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}if(this._countryCode=null===(t=u.initializationData)||void 0===t?void 0:t.storeCountry,r){if(!a)throw new yo('Unable to initialize payment because "options.currencyCode" argument is not provided.');this._currencyCode=a,this._buyNowInitializeOptions=r,yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions(),!!r,a)}else yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions());this._paymentButton=null!==(i=this._paymentButton)&&void 0!==i?i:this._googlePayPaymentProcessor.addPaymentButton(e.containerId,{buttonColor:null!=s?s:"default",buttonType:null!=d?d:"plain",onClick:this._handleClick(c)})})}deinitialize(){var e;return null===(e=this._paymentButton)||void 0===e||e.remove(),this._paymentButton=void 0,this._methodId=void 0,Promise.resolve()}_handleClick(e){return t=>Ga(this,void 0,void 0,function*(){t.preventDefault();try{this._buyNowInitializeOptions?yield this._createBuyNowCartOrThrow(this._buyNowInitializeOptions):yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(t){let i=t;if(function(e){return"object"==typeof e&&null!==e&&"statusCode"in e}(t)){if("CANCELED"===t.statusCode)throw new Qo;i=new ja(JSON.stringify(t))}throw null==e||e(new ja("An error occurred while requesting your Google Pay payment details.")),i}})}_interactWithPaymentSheet(){var e;return Ga(this,void 0,void 0,function*(){const t=yield this._googlePayPaymentProcessor.showPaymentSheet(),i=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(t),n=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(t),o="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;i&&(yield this._paymentIntegrationService.updateBillingAddress(i)),n&&!(null===(e=this._buyNowCart)||void 0===e?void 0:e.lineItems.digitalItems.length)&&(yield this._paymentIntegrationService.updateShippingAddress(n)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodOrThrow(),t,o)})}_getGooglePayClientOptions(){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:e,shippingAddress:t,shippingOptionData:i,offerData:n})=>Ga(this,void 0,void 0,function*(){const{availableTriggers:o,addressChangeTriggers:r,shippingOptionsChangeTriggers:a,offerChangeTriggers:s}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!o.includes(e))return;const d=r.includes(e)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(t):void 0;a.includes(e)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(i.id));const{newOfferInfo:c,error:u}=s.includes(e)?yield this._googlePayPaymentProcessor.handleCoupons(n):{},l=u;return this._buyNowInitializeOptions?this._getBuyNowTransactionInfo(d,c,l):this._getTransactionInfo(d,c,l)})}}}_createBuyNowCartOrThrow(e){return Ga(this,void 0,void 0,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=e.getBuyNowCartRequestBody();try{this._buyNowCart=yield this._paymentIntegrationService.createBuyNowCart(t),yield this._paymentIntegrationService.loadCheckout(this._buyNowCart.id)}catch(e){if("string"==typeof e)throw new fo(e);throw e}}})}_getBuyNowTransactionInfo(e,t,i){if(!this._buyNowCart)return;const{cartAmount:n}=this._buyNowCart,o=this._googlePayPaymentProcessor.getTotalPrice();return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:this._getCurrencyCodeOrThrow(),totalPrice:o||String(n),totalPriceStatus:Da.FINAL})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),i&&{error:i})}_getTransactionInfo(e,t,i){return Ga(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadCheckout();const n=this._googlePayPaymentProcessor.getTotalPrice(),{code:o}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:o,totalPriceStatus:Da.FINAL,totalPrice:n})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),i&&{error:i})})}_getMethodOrThrow(){return to(this._methodId,()=>new io(Jn.PaymentNotInitialized))}_getCurrencyCodeOrThrow(){return to(this._currencyCode,()=>new yo('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}}var Va=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ya{constructor(e,t,i,n){this._scriptLoader=e,this._gateway=t,this._requestSender=i,this._formPoster=n,this._baseRequest={apiVersion:2,apiVersionMinor:0}}initialize(e,t,i,n){return Va(this,void 0,void 0,function*(){this._paymentsClient=yield this._scriptLoader.getGooglePaymentsClient(e().config.testMode,t),yield this._gateway.initialize(e,i,n),this._buildButtonPayloads()})}initializeWidget(){return Va(this,void 0,void 0,function*(){yield this._buildWidgetPayloads(),yield this._determineReadinessToPay(),this._prefetchGooglePaymentData()})}getNonce(e){return this._gateway.getNonce(e)}extraPaymentData(){return Va(this,void 0,void 0,function*(){return this._gateway.extraPaymentData()})}addPaymentButton(e,t){const i=document.querySelector(`#${e}`);if(!i)return;const n=this._getPaymentsClient().createButton(Object.assign(Object.assign({},t),{allowedPaymentMethods:[this._getBaseCardPaymentMethod()]}));return i.appendChild(n)}showPaymentSheet(){return Va(this,void 0,void 0,function*(){const e=this._getPaymentDataRequest();return this._getPaymentsClient().loadPaymentData(e)})}setExternalCheckoutXhr(e,t){return Va(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t)})}setExternalCheckoutForm(e,t,i){return Va(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t,!0,i)})}mapToBillingAddressRequestBody(e){return this._gateway.mapToBillingAddressRequestBody(e)}mapToShippingAddressRequestBody(e){return this._gateway.mapToShippingAddressRequestBody(e)}processAdditionalAction(e,t){return"processAdditionalAction"in this._gateway?this._gateway.processAdditionalAction(e,t):Promise.reject(e)}signOut(e){return Va(this,void 0,void 0,function*(){yield this._requestSender.get(`/remote-checkout/${e}/signout`)})}getCallbackTriggers(){return this._gateway.getCallbackTriggers()}setShouldRequestShipping(e){return this._gateway.setShouldRequestShipping(e)}handleShippingAddressChange(e){return Va(this,void 0,void 0,function*(){return this._gateway.handleShippingAddressChange(e)})}handleShippingOptionChange(e){return Va(this,void 0,void 0,function*(){yield this._gateway.handleShippingOptionChange(e)})}handleCoupons(e){return Va(this,void 0,void 0,function*(){return this._gateway.handleCoupons(e)})}getTotalPrice(){return this._gateway.getTotalPrice()}_setExternalCheckout(e,t,i=!1,n){return Va(this,void 0,void 0,function*(){const o="/checkout.php",r=Object.assign({action:"set_external_checkout",provider:e},yield this._gateway.mapToExternalCheckoutData(t));if(i)return new Promise(e=>{this._formPoster.postForm(n?`${n}/checkout`:o,Object.assign(Object.assign({},r),{card_information:JSON.stringify(r.card_information)}),e)});yield this._requestSender.post(o,{headers:Object.assign({Accept:"text/html","Content-Type":"application/x-www-form-urlencoded"},Eo),body:r})})}_prefetchGooglePaymentData(){const e=this._getPaymentDataRequest();e.transactionInfo=this._gateway.getTransactionInfo(),this._getPaymentsClient().prefetchPaymentData(e)}_determineReadinessToPay(){return Va(this,void 0,void 0,function*(){try{const{result:e}=yield this._getPaymentsClient().isReadyToPay(this._getIsReadyToPayRequest());if(!1===e)throw new ja("Google Pay is not supported by the current device and browser, please try another payment method.")}catch(e){if(e instanceof ja)throw e;throw new ja}})}_buildButtonPayloads(){this._baseCardPaymentMethod={type:"CARD",parameters:this._gateway.getCardParameters()}}_buildWidgetPayloads(){return Va(this,void 0,void 0,function*(){const e=this._getBaseCardPaymentMethod();this._cardPaymentMethod=Object.assign(Object.assign({},e),{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:yield this._gateway.getPaymentGatewayParameters()}}),this._paymentDataRequest=Object.assign(Object.assign(Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[this._cardPaymentMethod],transactionInfo:this._gateway.getTransactionInfo(),merchantInfo:this._gateway.getMerchantInfo()}),yield this._gateway.getRequiredData()),{callbackIntents:this._gateway.getCallbackIntents(),offerInfo:this._gateway.getAppliedCoupons()}),this._isReadyToPayRequest=Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[e]})})}_getBaseCardPaymentMethod(){return this._getOrThrow(this._baseCardPaymentMethod)}_getPaymentDataRequest(){return this._getOrThrow(this._paymentDataRequest)}_getIsReadyToPayRequest(){return this._getOrThrow(this._isReadyToPayRequest)}_getPaymentsClient(){return this._getOrThrow(this._paymentsClient)}_getOrThrow(e){return to(e,()=>new io(Jn.PaymentNotInitialized))}}class Wa{constructor(e){this._scriptLoader=e,this._window=window}getGooglePaymentsClient(e=!1,t){return i=this,n=void 0,r=function*(){if(yield this._scriptLoader.loadScript("https://pay.google.com/gp/p/js/pay.js"),!this._window.google)throw new po;return void 0===this._paymentsClient&&(this._paymentsClient=new this._window.google.payments.api.PaymentsClient(Object.assign({environment:e?"TEST":"PRODUCTION"},null!=t?t:{}))),this._paymentsClient},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}function $a(){return new Wa(le())}const Ka=go(t=>{const n=e(),o=window,r=new Do(t),a=new Yo(new Zo(le(),o,r));return new Ha(t,new Ya($a(),new qa(t,a),n,i()))},[{id:"googlepaybraintree"}]);var Za=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Qa{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,i){return Za(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const n=this.getPayPalFastlaneSdkConfiguration(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypalFastlaneSdk)throw new po}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,i,n){return Za(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||n){const n=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i);yield this.loadPayPalSdk(n)}if(!this.window.paypalGooglePay)throw new po;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return Za(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new po}return this.window.paypalApms})}getPayPalMessages(e,t){return Za(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new po;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return Za(this,void 0,void 0,function*(){const i=this.transformConfig(e),n=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(i).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:n})})}getPayPalFastlaneSdkConfiguration(e,t,i){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:r},attributes:{"data-client-metadata-id":i.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":n}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i=!0){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=o,h=u||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":n,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=i,l=u,h=c.filter(e=>!u.includes(e));return{options:Object.assign({"client-id":o,"merchant-id":r,"enable-funding":l.length>0?l:void 0,"disable-funding":h.length>0?h:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:n},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}function Ja(e){if(!function(e){return!!e.initializationData&&"attributionId"in e.initializationData&&"isVenmoEnabled"in e.initializationData&&"isGooglePayEnabled"in e.initializationData&&"isPayPalCreditAvailable"in e.initializationData}(e))throw new Xn(Qn.MissingPaymentMethod)}var Xa=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class es extends Ba{constructor(e,t){super("paypalsb",e),this.payPalCommerceSdk=t,this.service=e}initialize(e,t,i){const n=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,r,a,s,d;return Xa(this,void 0,void 0,function*(){const c=null!==(r=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==r?r:i;if(!c)throw new Xn(Qn.MissingPaymentMethod);yield n.initialize.call(this,e,t,c);const u=n.getPaymentMethod.call(this);if(!u.initializationData)throw new Xn(Qn.MissingPaymentMethod);Ja(u);const l=yield this.payPalCommerceSdk.getPayPalGooglePaySdk(u,c);this.googlepayConfig=yield l.Googlepay().config();const{allowedPaymentMethods:h}=this.googlepayConfig;this.setGatewayIdentifier(null===(d=null===(s=null===(a=h[0])||void 0===a?void 0:a.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===d?void 0:d.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Xa(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i})}}const ts=go(t=>new Ha(t,new Ya($a(),new es(t,new Qa(le())),e(),i())),[{id:"googlepaypaypalcommerce"}]);var is=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ns extends Ba{constructor(e,t){super("googlepay_bigcommerce_payments",e),this.payPalSdkHelper=t,this.service=e}initialize(e,t,i){const n=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,r,a,s,d;return is(this,void 0,void 0,function*(){const c=null!==(r=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==r?r:i;if(!c)throw new Xn(Qn.MissingPaymentMethod);yield n.initialize.call(this,e,t,c);const u=n.getPaymentMethod.call(this);if(!u.initializationData)throw new Xn(Qn.MissingPaymentMethod);Ja(u);const l=yield this.payPalSdkHelper.getPayPalGooglePaySdk(u,c);this.googlepayConfig=yield l.Googlepay().config();const{allowedPaymentMethods:h}=this.googlepayConfig;this.setGatewayIdentifier(null===(d=null===(s=null===(a=h[0])||void 0===a?void 0:a.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===d?void 0:d.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return is(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i})}}const os=go(t=>new Ha(t,new Ya($a(),new ns(t,new Er(le())),e(),i())),[{id:"googlepay_bigcommerce_payments"}]),rs=go(t=>{const n=e();return new Ha(t,new Ya($a(),new Ba("adyen",t),n,i()))},[{id:"googlepayadyenv2"}]),as=go(t=>{const n=e();return new Ha(t,new Ya($a(),new Ba("adyen",t),n,i()))},[{id:"googlepayadyenv3"}]);class ss extends Ba{constructor(e){super("authorizenet",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return function(e){if(!function(e){return"paymentGatewayId"in e}(e))throw new Xn(Qn.MissingPaymentMethod)}(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.paymentGatewayId}}}const ds=go(t=>new Ha(t,new Ya($a(),new ss(t),e(),i())),[{id:"googlepayauthorizenet"}]),cs=e=>"object"==typeof e&&null!==e&&"body"in e;function us(e){if(!function(e){return"checkoutcomkey"in e}(e))throw new Xn(Qn.MissingPaymentMethod)}var ls=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class hs extends Ba{constructor(e,t){super("checkoutltd",e),this._requestSender=t}processAdditionalAction(e){return new Promise((t,i)=>{if(cs(e)&&function(e){var t;if("object"!=typeof e||null===e)return!1;const i=e;return"string"==typeof(null===(t=i.three_ds_result)||void 0===t?void 0:t.acs_url)&&"string"==typeof i.three_ds_result.code}(e.body)&&"three_d_secure_required"===e.body.three_ds_result.code)return window.location.assign(e.body.three_ds_result.acs_url);i(e)})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return ls(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);let n;try{n=JSON.parse(i.nonce)}catch(e){throw new yo("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"protocolVersion"in e&&"signature"in e&&"signedMessage"in e}(e))throw new Xn(Qn.MissingPaymentToken)}(n),i.nonce=yield this._tokenize(n),i})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return us(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.checkoutcomkey}}_tokenize(e){return ls(this,void 0,void 0,function*(){const t=this.getPaymentMethod().config.testMode?"https://api.sandbox.checkout.com/tokens":"https://api.checkout.com/tokens",i=this.getGooglePayInitializationData();us(i);const{body:n}=yield this._requestSender.post(t,{credentials:!1,body:{type:"googlepay",token_data:e},headers:{Authorization:i.checkoutcomkey,"Content-Type":bo.Json,"X-XSRF-TOKEN":null}});return n.token})}}const ps=go(t=>{const n=e();return new Ha(t,new Ya($a(),new hs(t,n),n,i()))},[{id:"googlepaycheckoutcom"}]);class ms extends Ba{constructor(e){super("cybersource",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}const gs=go(t=>new Ha(t,new Ya($a(),new ms(t),e(),i())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]);class ys extends Ba{constructor(e){super("chase",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}const fs=go(t=>new Ha(t,new Ya($a(),new ys(t),e(),i())),[{id:"googlepayorbital"}]);var vs,Ss,Cs,Is,_s,ws,bs,Es,Ps,Os;!function(e){e.SHIPPING="shipping",e.BILLING="billing"}(vs||(vs={})),function(e){e.SPLIT="split",e.FULL="full",e.ORGANIZATION="organization"}(Ss||(Ss={})),function(e){e.SUCCESS="success",e.ERROR="error"}(Cs||(Cs={})),function(e){e.CreditCard="card",e.Link="link",e.EPS="eps",e.GRABPAY="grabpay",e.BANCONTACT="bancontact",e.IDEAL="ideal",e.ALIPAY="alipay",e.KLARNA="klarna",e.OCS="optimized_checkout"}(Is||(Is={})),function(e){e.NEVER="never",e.AUTO="auto",e.ALWAYS="always",e.PAYMENT="payment",e.IF_REQUIRED="if_required"}(_s||(_s={})),function(e){e.V3="v3",e.ACACIA="acacia",e.BASIL="basil",e.CLOVER="clover"}(ws||(ws={})),function(e){e.PAYMENT="payment",e.AUTHENTICATION="linkAuthentication",e.SHIPPING="address",e.EXPRESS_CHECKOUT="expressCheckout"}(bs||(bs={})),function(e){e.REQUIRES_PAYMENT_METHOD="requires_payment_method",e.REQUIRES_CONFIRMATION="requires_confirmation",e.REQUIRES_ACTION="requires_action",e.PROCESSING="processing",e.SUCCEEDED="succeeded",e.CANCELED="canceled"}(Es||(Es={})),function(e){e.CLICK="click",e.CHANGE="change",e.READY="ready",e.SHIPPING_ADDRESS_CHANGE="shippingaddresschange",e.SHIPPING_RATE_CHANGE="shippingratechange",e.CONFIRM="confirm",e.CANCEL="cancel",e.LOADER_START="loaderstart"}(Ps||(Ps={})),function(e){e.ON_SESSION="on_session",e.OFF_SESSION="off_session"}(Os||(Os={}));var As=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ts{constructor(e,t=window){this.scriptLoader=e,this.stripeWindow=t}getStripeClient(e,t,i,n,o){return As(this,void 0,void 0,function*(){if(this.stripeWindow.bcStripeClient)return this.stripeWindow.bcStripeClient;const r=yield this.load(i),{stripePublishableKey:a,stripeConnectedAccount:s}=e,d=r(a,Object.assign(Object.assign(Object.assign(Object.assign({},s?{stripeAccount:s}:{}),t?{locale:t}:{}),n?{betas:n}:{}),o?{apiVersion:o}:{}));return Object.assign(this.stripeWindow,{bcStripeClient:d}),d})}getElements(e,t){return As(this,void 0,void 0,function*(){let i=this.stripeWindow.bcStripeElements;return i?yield this.updateStripeElements(t):(i=e.elements(t),Object.assign(this.stripeWindow,{bcStripeElements:i})),i})}updateStripeElements(e){return As(this,void 0,void 0,function*(){const t=this.stripeWindow.bcStripeElements;t&&(t.update(e),yield t.fetchUpdates())})}getCheckoutSession(e,t){return As(this,void 0,void 0,function*(){let i=this.stripeWindow.bcStripeCheckoutSession;return i||(i=yield e.initCheckout(t),Object.assign(this.stripeWindow,{bcStripeCheckoutSession:i})),i})}load(e){return As(this,void 0,void 0,function*(){if(!this.stripeWindow.Stripe&&(yield this.scriptLoader.loadScript(this.getScriptUrl(e)),!this.stripeWindow.Stripe))throw new po;return this.stripeWindow.Stripe})}getScriptUrl(e){return e&&e!==ws.V3?`https://js.stripe.com/${e}/stripe.js`:"https://js.stripe.com/v3/"}}const ks=["payment_element_beta_2","alipay_pm_beta_1","link_default_integration_beta_1","shipping_address_element_beta_1","address_element_beta_1"];function Rs(e){if(!function(e){return"stripeConnectedAccount"in e&&"stripePublishableKey"in e&&"stripeVersion"in e}(e))throw new Xn(Qn.MissingPaymentMethod)}var Ds=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ms extends Ba{constructor(e,t){super("stripe",e),this.paymentIntegrationService=e,this.scriptLoader=t}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Ds(this,void 0,void 0,function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);let n;try{n=JSON.parse(i.nonce)}catch(e){throw new yo("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"id"in e}(e))throw new Xn(Qn.MissingPaymentToken)}(n),i.nonce=n.id,i})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();Rs(e);const{stripeVersion:t,stripePublishableKey:i,stripeConnectedAccount:n}=e;return{gateway:this.getGatewayIdentifier(),"stripe:version":t,"stripe:publishableKey":`${i}/${n}`}}processAdditionalAction(e,t){var i;return Ds(this,void 0,void 0,function*(){if(!t)throw new Hr(["payment"]);if(!cs(e)||("object"!=typeof(n=e.body)||null===n||!("three_ds_result"in n)||!("errors"in n)))throw e;var n;if(z(e.body.errors,{code:"three_d_secure_required"})){const n=this.getGooglePayInitializationData();Rs(n),this.stripeUPEClient=yield this.loadStripeJs(n,t);const o=e.body.three_ds_result.token;let r,a=!1;try{r=yield this.stripeUPEClient.confirmCardPayment(o)}catch(e){try{r=yield this.stripeUPEClient.retrievePaymentIntent(o)}catch(e){a=!0}}if(null==r?void 0:r.error){if(this._throwDisplayableStripeError(r.error),this._isCancellationError(r.error))throw new Qo;throw new ja}if(!(null==r?void 0:r.paymentIntent)&&!a)throw new _e;return this.paymentIntegrationService.submitPayment({methodId:t,paymentData:{nonce:(null===(i=null==r?void 0:r.paymentIntent)||void 0===i?void 0:i.id)||o}})}throw e})}loadStripeJs(e,t){return Ds(this,void 0,void 0,function*(){if(this.stripeUPEClient)return this.stripeUPEClient;const i=this.paymentIntegrationService.getState().getCartLocale();return"googlepaystripeocs"===t&&e.useNewStripeJsVersion?this.scriptLoader.getStripeClient(e,i,ws.CLOVER):this.scriptLoader.getStripeClient(e,i,ws.V3,ks,"2020-03-02;alipay_beta=v1;link_beta=v1")})}_isCancellationError(e){var t,i;return e&&-1!==(null===(i=null===(t=e.payment_intent.last_payment_error)||void 0===t?void 0:t.message)||void 0===i?void 0:i.indexOf("canceled"))}_throwDisplayableStripeError(e){if(g(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}}const Ns=go(t=>new Ha(t,new Ya($a(),new Ms(t,new Ts(le())),e(),i())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]);class Ls extends Ba{constructor(e){super("worldpay",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return i=this,n=void 0,r=function*(){const i=yield t.mapToExternalCheckoutData.call(this,e);return i.nonce=btoa(i.nonce),i},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}const zs=go(t=>new Ha(t,new Ya($a(),new Ls(t),e(),i())),[{id:"googlepayworldpayaccess"}]);function Us(){const{navigator:e}=window;let t;return t=e.language?e.language:e.userLanguage,{color_depth:window.screen.colorDepth||24,java_enabled:"function"==typeof e.javaEnabled&&e.javaEnabled(),language:t,screen_height:window.screen.height,screen_width:window.screen.width,time_zone_offset:(new Date).getTimezoneOffset().toString()}}var Fs=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Bs extends Ba{constructor(e,t){super("worldlinena",e),this.formPoster=t}extraPaymentData(){return Fs(this,void 0,void 0,function*(){return Promise.resolve({browser_info:Us()})})}processAdditionalAction(e){return Fs(this,void 0,void 0,function*(){if(!function(e){return cs(e)&&(t=e.body,I(t)&&"object"==typeof t&&"errors"in t&&"three_ds_result"in t&&y(t.errors)&&z(t.errors,{code:"three_d_secure_required"}));var t}(e))throw e;const{three_ds_result:t}=e.body,{acs_url:i,payer_auth_request:n,merchant_data:o}=t||{};if(!i||!n||!o)throw new Hr(["formUrl","threeDSSessionData","creq"]);return new Promise(e=>{this.formPoster.postForm(i,{threeDSSessionData:n,creq:o},e,"_top")})})}}const xs=go(t=>new Ha(t,new Ya($a(),new Bs(t,i()),e(),i())),[{id:"googlepaytdonlinemart"}]);var qs,js,Gs,Hs,Vs,Ys,Ws;!function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(qs||(qs={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(js||(js={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Gs||(Gs={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(Hs||(Hs={})),function(e){e.pill="pill",e.rect="rect"}(Vs||(Vs={})),(Ys||(Ys={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Ws||(Ws={}));var $s=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ks{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=i,this.paypalCommerceScriptLoader=n}loadPayPalSdk(e,t,i,n){return $s(this,void 0,void 0,function*(){const o=this.paymentIntegrationService.getState(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,r,i,n),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new po;return this.paypalSdk}createBuyNowCartOrThrow(e){return $s(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}})}createOrder(e,t){return $s(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:i},t));return n})}createOrderCardFields(e,t){return $s(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n,setupToken:o}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:i},t));return Object.assign({orderId:n},o?{setupToken:o}:{})})}updateOrder(){return $s(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),i=e.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:i.availableShippingOptions,cartId:t.id,selectedShippingOption:i.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return $s(this,void 0,void 0,function*(){try{const{status:i}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return i}catch(e){throw new _e}})}tokenizePayment(e,t){const i=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xn(Qn.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===ar.BuyNow&&{cart_id:i.id}))}submitPayment(e,t,i){return $s(this,void 0,void 0,function*(){const n={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:n},i?{gatewayId:i}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],i=t.availableShippingOptions||[],n=i.find(e=>e.isRecommended),o=(e?i.find(t=>t.id===e):i.find(e=>{var i;return e.id===(null===(i=t.selectedShippingOption)||void 0===i?void 0:i.id)}))||n||i[0];if(!o)throw new Error("Your order can't be shipped to this address");return o}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,i;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(i=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===i?void 0:i.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:i}=e,{address:n,name:{full_name:o}}=i[0].shipping,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.join(" "),email:t.email_address,address1:n.address_line_1,address2:n.address_line_2,city:n.admin_area_2,countryCode:n.country_code,postalCode:n.postal_code,stateOrProvinceCode:n.admin_area_1})}getValidButtonStyle(e){const{color:t,height:i,label:n,shape:o}=e||{},r={color:t&&Hs[t]?t:void 0,height:this.getValidHeight(i),label:n&&Gs[n]?n:void 0,shape:o&&Vs[o]?o:void 0};return R(r,C)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var Zs=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Qs{constructor(e){this.requestSender=e}createOrder(e,t){return Zs(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e){return Zs(this,void 0,void 0,function*(){const t=e,i=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:i,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return Zs(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var Js=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Xs{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return Js(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,i);return this.loadPayPalSDK(o,n)})}loadPayPalSDK(e,t=!1){return Js(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),i=this.transformConfig(e.attributes),n=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(n,{async:!0,attributes:i})}if(!this.window.paypal)throw new po;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,i=!0){const{id:n,clientToken:o,initializationData:r}=e;if(!(null==r?void 0:r.clientId))throw new Xn(Qn.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:u,isVenmoEnabled:l,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:p,isDeveloperModeApplicable:m,availableAlternativePaymentMethods:g=[],enabledAlternativePaymentMethods:y=[],isGooglePayEnabled:f}=r,v=h||i,S="paypalcommercecreditcards"===n,C=S?["card"]:[],I=p?["credit","paylater"]:[],_=l?["venmo"]:[],w=f?["googlepay"]:[],b=i?["card-fields"]:[],E=[...S?[]:["card"],...p?[]:["credit","paylater"],...l?[]:["venmo"],...g.filter(e=>!y.includes(e))],P=[...C,...I,..._,...y];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":P.length>0?P:void 0,"disable-funding":E.length>0?E:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...w,...b],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":o}}}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}const ed=t=>{const{getHost:n}=t.getState();return new Ks(i(),t,new Qs(e({host:n()})),new Xs(le()))};var td=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class id{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){var t;return td(this,void 0,void 0,function*(){const{paypalcommerce:i,containerId:n,methodId:o}=e,r=Boolean(null==i?void 0:i.buyNowInitializeOptions);if(!o)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(r&&!i.currencyCode)throw new yo('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(r&&"function"!=typeof(null===(t=i.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');r||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=r?i.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(o,a,!1),this.renderButton(n,o,i,r)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i,n){var o,r;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:c}=i,u=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:h,isAppSwitchEnabled:p}=l.initializationData||{},m=Object.assign(Object.assign({},!n&&this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommerce"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)}),g={onClick:()=>this.handleClick(a),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},y=Object.assign(Object.assign({},!p&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,d)}),f=Object.assign(Object.assign(Object.assign({fundingSource:u.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(s)},m),a&&g),h&&y),v=u.Buttons(f);v.isEligible()?(null===(o=v.hasReturned)||void 0===o?void 0:o.call(v))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(r=v.resume)||void 0===r||r.call(v):v.render(`#${e}`):c&&"function"==typeof c?c():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return td(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return td(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return td(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return td(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}isPaypalCommerceAppSwitchEnabled(e){var t;return(null===(t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.isAppSwitchEnabled)||!1}}const nd=go(e=>new id(e,ed(e)),[{id:"paypalcommerce"}]),od=function({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t};var rd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ad{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i}initialize(e){var t;return rd(this,void 0,void 0,function*(){const{paypalcommercecredit:i,containerId:n,methodId:o}=e,{buyNowInitializeOptions:r,currencyCode:a,messagingContainerId:s}=i||{},d=!!r;if(!o)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(d&&!a)throw new yo('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(d&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommercecredit.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');d||(yield this.paymentIntegrationService.loadDefaultCheckout());const c=this.paymentIntegrationService.getState(),u=d?a:c.getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(o,u,!1),this.renderButton(n,o,i);const l=c.getStoreConfigOrThrow().checkoutSettings.features;if(null!==(t=l["PAYPAL-5557.Hide_ppc_banner_implementation"])&&void 0!==t&&t)return;const h=s&&document.getElementById(s);if(u&&h){const e=c.getPaymentMethodOrThrow(o),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},i=t&&t.find(({id:e})=>"cart"===e);if(!(null==i?void 0:i.status))return;h.removeAttribute("data-pp-style-logo-type"),h.removeAttribute("data-pp-style-logo-position"),h.removeAttribute("data-pp-style-text-color"),h.removeAttribute("data-pp-style-text-size");const n=yield this.paypalCommerceSdk.getPayPalMessages(e,u);this.renderMessages(n,s,i)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onComplete:r,onEligibilityFailure:a}=i,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:c,isAppSwitchEnabled:u}=d.initializationData||{},l={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},h={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},p=Object.assign(Object.assign({},!u&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,r)}),m=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let g=!1;m.forEach(t=>{if(!g){const i=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o)},l),n&&h),c&&p),r=s.Buttons(i);r.isEligible()?(r.render(`#${e}`),g=!0):a&&"function"==typeof a&&a()}}),g||this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return rd(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return rd(this,void 0,void 0,function*(){if(!e.orderID)throw new Xn(Qn.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return rd(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return rd(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}renderMessages(e,t,i){const n={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:od(i)};e.Messages(n).render(`#${t}`)}}const sd=go(e=>new ad(e,ed(e),new Qa(ue())),[{id:"paypalcommercecredit"}]);var dd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class cd{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return dd(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r}=t||{},a=!!o;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(a&&!r)throw new yo('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommercevenmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?r:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(n,s,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{buyNowInitializeOptions:n,style:o,onEligibilityFailure:r}=i,a=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(o)},d),n&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):r&&"function"==typeof r?r():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===Hs.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return dd(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ud=go(e=>new cd(e,ed(e)),[{id:"paypalcommercevenmo"}]);var ld,hd,pd,md,gd,yd,fd,vd,Sd,Cd,Id=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class _d{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return Id(this,void 0,void 0,function*(){if(!this.window.paypal||n){const n=this.getPayPalSdkScriptConfigOrThrow(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypal)throw new po}return this.window.paypal})}getPayPalFastlaneSdk(e,t,i){return Id(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const n=this.getPayPalFastlaneSdkConfiguration(e,t,i);if(yield this.loadPayPalSdk(n),!this.window.paypalFastlaneSdk)throw new po}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,i,n){return Id(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||n){const n=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i);yield this.loadPayPalSdk(n)}if(!this.window.paypalGooglePay)throw new po;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return Id(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new po}return this.window.paypalApms})}getPayPalMessages(e,t){return Id(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new po;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return Id(this,void 0,void 0,function*(){const i=this.transformConfig(e),n=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(i).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:n})})}getPayPalSdkScriptConfigOrThrow(e,t,i=!0){const{id:n,clientToken:o,initializationData:r}=e;if(!r||!r.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:u,isVenmoEnabled:l,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:p,isDeveloperModeApplicable:m,availableAlternativePaymentMethods:g=[],enabledAlternativePaymentMethods:y=[],isGooglePayEnabled:f}=r,v=h||i,S="paypalcommercecreditcards"===n||"bigcommerce_payments_creditcards"===n,C=S?["card"]:[],I=p?["credit","paylater"]:[],_=l?["venmo"]:[],w=f?["googlepay"]:[],b=i?["card-fields"]:[],E=[...S?[]:["card"],...p?[]:["credit","paylater"],...l?[]:["venmo"],...g.filter(e=>!y.includes(e))],P=[...C,...I,..._,...y];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":P.length>0?P:void 0,"disable-funding":E.length>0?E:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...w,...b],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":o}}}getPayPalFastlaneSdkConfiguration(e,t,i){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:r},attributes:{"data-client-metadata-id":i.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":n}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,i=!0){const{clientToken:n,initializationData:o}=e;if(!o||!o.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=o,h=u||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":n,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=i,l=u,h=c.filter(e=>!u.includes(e));return{options:Object.assign({"client-id":o,"merchant-id":r,"enable-funding":l.length>0?l:void 0,"disable-funding":h.length>0?h:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:n},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new Xn(Qn.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}transformConfig(e){let t={};return Object.keys(e).forEach(i=>{const n=e[i];null==n||""===n||Array.isArray(n)&&0===n.length||(t=Object.assign(Object.assign({},t),{[i]:Array.isArray(n)?n.join(","):n}))}),t}}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(ld||(ld={})),function(e){e.Always="SCA_ALWAYS"}(hd||(hd={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(pd||(pd={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(md||(md={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(gd||(gd={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(yd||(yd={})),function(e){e.pill="pill",e.rect="rect"}(fd||(fd={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(vd||(vd={})),(Sd||(Sd={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Cd||(Cd={}));var wd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class bd{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=i,this.paypalSdkLoader=n}loadPayPalSdk(e,t,i,n){return wd(this,void 0,void 0,function*(){const o=this.paymentIntegrationService.getState(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(a,r,i,n),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new po;return this.paypalSdk}createBuyNowCartOrThrow(e){return wd(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xn(Qn.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new fo}})}createOrder(e,t){return wd(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:i},t));return n})}createOrderCardFields(e,t){return wd(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:n,setupToken:o}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:i},t));return Object.assign({orderId:n},o?{setupToken:o}:{})})}updateOrder(e){return wd(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),i=t.getCartOrThrow(),n=t.getConsignmentsOrThrow()[0];try{yield this.paypalRequestSender.updateOrder(e,{availableShippingOptions:n.availableShippingOptions,cartId:i.id,selectedShippingOption:n.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return wd(this,void 0,void 0,function*(){try{const{status:i}=yield this.paypalRequestSender.getOrderStatus(e,t);return i}catch(e){throw new _e}})}tokenizePayment(e,t){const i=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xn(Qn.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===ar.BuyNow&&{cart_id:i.id}))}submitPayment(e,t,i){return wd(this,void 0,void 0,function*(){const n={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:n},i?{gatewayId:i}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],i=t.availableShippingOptions||[],n=i.find(e=>e.isRecommended),o=(e?i.find(t=>t.id===e):i.find(e=>{if(t.selectedShippingOption){const i=t.selectedShippingOption.id;return e.id===i}return!1}))||n||i[0];if(!o)throw new Error("Your order can't be shipped to this address");return o}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,i;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(i=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===i?void 0:i.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:i}=e,{address:n,name:{full_name:o}}=i[0].shipping,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.join(" "),email:t.email_address,address1:n.address_line_1,address2:n.address_line_2,city:n.admin_area_2,countryCode:n.country_code,postalCode:n.postal_code,stateOrProvinceCode:n.admin_area_1})}getValidButtonStyle(e={}){const{color:t,height:i,label:n,shape:o}=e,r={color:t&&yd[t]?t:void 0,height:this.getValidHeight(i),label:n&&gd[n]?n:void 0,shape:o&&fd[o]?o:void 0};return R(r,C)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var Ed=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Pd{constructor(e){this.requestSender=e}createOrder(e,t){return Ed(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e,t){return Ed(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.put(i,{headers:o,body:n})).body})}getOrderStatus(e,t){return Ed(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":_o,"Content-Type":bo.Json},Eo);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var Od=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ad{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}initialize(e){return Od(this,void 0,void 0,function*(){const{paypalcommercealternativemethods:t,containerId:i,methodId:n}=e,{apm:o,buyNowInitializeOptions:r,currencyCode:a}=t||{},s=!!r;if(!n)throw new yo('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new yo('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');if(!o)throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods.apm" argument is not provided.');if(s&&!a)throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new yo('Unable to initialize payment because "options.paypalcommercealternativemethods.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');s||(yield this.paymentIntegrationService.loadDefaultCheckout());const d=s?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(n,d,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{apm:n,buyNowInitializeOptions:o,style:r,onEligibilityFailure:a}=i,s=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(n))throw new yo('Unable to initialize PayPal button because "options.paypalcommercealternativemethods.apm" argument is not valid funding source.');const d={createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercealternativemethod"),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:n,style:this.paypalIntegrationService.getValidButtonStyle(r)},d),o&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.paypalIntegrationService.removeElement(e)}handleClick(e){return Od(this,void 0,void 0,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Td=go(t=>new Ad(t,(t=>{const{getHost:n}=t.getState();return new bd(i(),t,new Pd(e({host:n()})),new _d(ue()))})(t)),[{id:"paypalcommercealternativemethods"}]);var kd,Rd,Dd,Md,Nd,Ld;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(kd||(kd={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Rd||(Rd={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black"}(Dd||(Dd={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Md||(Md={})),function(e){e.PILL="pill",e.RECT="rect"}(Nd||(Nd={})),function(e){e.ACKNOWLEDGE="ACKNOWLEDGE",e.FINALIZE="FINALIZE",e.INITIALIZE="INITIALIZE"}(Ld||(Ld={}));var zd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Ud{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalExpressScriptLoader=t,this.formPoster=i}initialize(e){return zd(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!e.paypal)throw new yo;if(!t.config.merchantId)throw new Xn(Qn.MissingPaymentMethod);const i=yield this.paypalExpressScriptLoader.loadPaypalSDK(t.config.merchantId);this.renderButton(e,i)})}deinitialize(){return Promise.resolve()}renderButton(e,t){const{containerId:i,methodId:n,paypal:o}=e,{allowCredit:r,clientId:a,onPaymentError:s,shouldProcessPayment:d,style:c}=o,u=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!u.config.merchantId)throw new Xn(Qn.MissingPaymentMethod);const l=u.config.merchantId,h=u.config.testMode?"sandbox":"production",p={[h]:a},m=t.FUNDING.CREDIT||"credit",g=r?[m]:[],y=r?[]:[m];return t.Button.render({env:h,client:p,commit:d,funding:{allowed:g,disallowed:y},style:this.getStyle(c),payment:(e,t)=>this.setupPayment(l,t,s),onAuthorize:(e,t)=>this.tokenizePayment(e,n,t,d)},i)}getStyle(e){const{color:t,fundingicons:i,label:n,layout:o,shape:r,size:a,tagline:s}=e||{};return{color:t,fundingicons:i,label:n,layout:o,shape:r||Nd.RECT,size:"small"===a?Rd.RESPONSIVE:a,tagline:s}}setupPayment(e,t,i){return zd(this,void 0,void 0,function*(){if(!t)throw new io(Jn.CheckoutButtonNotInitialized);try{const i=yield this.paymentIntegrationService.loadDefaultCheckout(),{id:n}=i.getCartOrThrow(),o=i.getHost()||"";return(yield t.request.post(`${o}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:n},{headers:Object.assign({"X-API-INTERNAL":_o},Eo)})).id}catch(e){throw i&&e instanceof Ce&&i(e),e}})}tokenizePayment(e,t,i,n){return zd(this,void 0,void 0,function*(){if(!i)throw new io(Jn.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new Xn(Qn.MissingPayment);const o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),r=yield i.payment.get(e.paymentID);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:o.id,action:n?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(r.payer.payer_info)})})}}class Fd{constructor(e){this.scriptLoader=e,this.window=window}loadPaypalSDK(e=""){return t=this,i=void 0,o=function*(){const t=Object.assign({async:!0,attributes:{"data-merchant-id":e}},e&&{attributes:{"data-merchant-id":e}});if(yield this.scriptLoader.loadScript("//www.paypalobjects.com/api/checkout.min.js",t),!this.window.paypal)throw new po;return this.window.paypal},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}}const Bd=go(e=>new Ud(e,new Fd(le()),i()),[{id:"paypalexpress"}]);var xd=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class qd{constructor(e,t){this.paymentIntegrationService=e,this.scriptLoader=t,this.isMounted=!1}deinitialize(){var e;null===(e=this.checkoutEventsUnsubscribe)||void 0===e||e.call(this),this.isMounted=!1}initCheckoutEventsSubscription(e,t,i,n){this.checkoutEventsUnsubscribe=this.paymentIntegrationService.subscribe(()=>xd(this,void 0,void 0,function*(){var o;const r=null==n?void 0:n.getElement(bs.PAYMENT);if(r){try{yield this.updateStripePaymentIntent(e,t)}catch(e){return this.isMounted&&(r.unmount(),this.isMounted=!1),void(e instanceof Error&&(null===(o=i.onError)||void 0===o||o.call(i,e)))}this.isMounted||(yield null==n?void 0:n.fetchUpdates(),this.mountElement(r,i.containerId))}}),e=>{var t;return null===(t=e.getCheckout())||void 0===t?void 0:t.outstandingBalance},e=>{var t;return null===(t=e.getCheckout())||void 0===t?void 0:t.coupons})}mountElement(e,t){document.getElementById(t)&&(e.mount(`#${t}`),this.isMounted=!0)}mapAppearanceVariables(e){return{colorPrimary:e.fieldInnerShadow,colorBackground:e.fieldBackground,colorText:e.labelText,colorDanger:e.fieldErrorText,colorTextSecondary:e.labelText,colorTextPlaceholder:e.fieldPlaceholderText,colorIcon:e.fieldPlaceholderText}}mapInputAppearanceRules(e){return{borderColor:e.fieldBorder,color:e.fieldText,boxShadow:e.fieldInnerShadow}}throwStripeError(e){if("object"==typeof(t=e)&&null!==t&&"type"in t&&(this.throwDisplayableStripeError(e),this.isCancellationError(e)))throw new Qo;var t;throw new ja}throwDisplayableStripeError(e){if(g(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}isCancellationError(e){var t;const i=null===(t=null==e?void 0:e.payment_intent.last_payment_error)||void 0===t?void 0:t.message;return!!i&&-1!==i.indexOf("canceled")}throwPaymentConfirmationProceedMessage(){throw new ja("We've received your order and are processing your payment. Once the payment is verified, your order will be completed. We will send you an email when it's completed. Please note, this process may take a few minutes depending on the processing times of your chosen method.")}isPaymentCompleted(e,t){return xd(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState(),n=i.getPaymentMethodOrThrow(e),{features:o}=i.getStoreConfigOrThrow().checkoutSettings;if(!n.clientToken||!t||!o["PI-626.Block_unnecessary_payment_confirmation_for_StripeUPE"])return!1;const{paymentIntent:r}=yield t.retrievePaymentIntent(n.clientToken);return(null==r?void 0:r.status)===Es.SUCCEEDED})}mapStripePaymentData(e,t,i=!1){const n=this.paymentIntegrationService.getState().getBillingAddress(),{firstName:o="",lastName:r="",email:a=""}=n||{},s=this._mapStripeAddress(n);if(!e)throw new io(Jn.PaymentNotInitialized);if(!(a&&s&&s.city&&s.country&&o&&r))throw new Xn(Qn.MissingBillingAddress);return{elements:e,redirect:_s.IF_REQUIRED,confirmParams:Object.assign({payment_method_data:Object.assign(Object.assign({},i?{allow_redisplay:"always"}:{}),{billing_details:{email:a,address:s,name:`${o} ${r}`}})},t&&{return_url:t})}}isAdditionalActionError(e){return z(e,{code:"additional_action_required"})}isRedirectAction(e){const{type:t,data:{redirect_url:i}}=e;return"redirect_to_url"===t&&!!i}isOnPageAdditionalAction(e){const{type:t,data:{token:i}}=e;return"additional_action_requires_payment_method"===t&&!!i}updateStripePaymentIntent(e,t){return xd(this,void 0,void 0,function*(){const i=yield this.paymentIntegrationService.loadPaymentMethod(e,{params:{method:t}}),{clientToken:n}=i.getPaymentMethodOrThrow(t);n&&this.scriptLoader.updateStripeElements({clientSecret:n})})}getStripeJsVersion(e){return e.useNewStripeJsVersion?ws.CLOVER:ws.V3}_mapStripeAddress(e){if(e){const{city:t,address1:i,address2:n,countryCode:o,postalCode:r,stateOrProvinceCode:a}=e;return Object.assign({city:t,country:o,postal_code:r,line1:i,line2:n},a?{state:a}:{})}throw new Xn(Qn.MissingBillingAddress)}}const jd={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Gd={position:"fixed","background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},Hd="embedded-checkout-loading-indicator-rotation";class Vd{constructor(e){this.styles=Object.assign(Object.assign({},jd),e&&e.styles),this.containerStyles=Object.assign({},e&&e.containerStyles),this.defineAnimation(),this.container=this.buildContainer(),this.indicator=this.buildIndicator(),this.container.appendChild(this.indicator)}show(e){if(e){const t=document.getElementById(e);if(!t)throw new Error("Unable to attach the loading indicator because the parent ID is not valid.");t.appendChild(this.container)}this.container.style.visibility="visible",this.container.style.opacity="1"}hide(){const e=()=>{this.container.style.visibility="hidden",this.container.removeEventListener("transitionend",e)};this.container.addEventListener("transitionend",e),this.container.style.opacity="0"}buildContainer(){const e=document.createElement("div");return e.style.display="block",e.style.bottom="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.position="absolute",e.style.right="0",e.style.top="0",e.style.transition="all 250ms ease-out",e.style.opacity="0",this.setStyleAttribute(e,this.containerStyles),e}buildIndicator(){const e=document.createElement("div");return e.style.display="block",e.style.width=`${this.styles.size}px`,e.style.height=`${this.styles.size}px`,e.style.borderRadius=`${this.styles.size}px`,e.style.border="solid 1px",e.style.borderColor=`${this.styles.backgroundColor} ${this.styles.backgroundColor} ${this.styles.color} ${this.styles.color}`,e.style.margin="0 auto",e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top="50%",e.style.transform="translateY(-50%) rotate(0deg)",e.style.transformStyle="preserve-3d",e.style.animation=`${Hd} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(i=>{e.style.setProperty(i,t[i])})}defineAnimation(){var e;if(document.getElementById(Hd))return;const t=document.createElement("style");t.id=Hd,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${Hd} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}class Yd{constructor(e){this._decimalPlaces=e}toInteger(e){return Math.round(e*Math.pow(10,this._decimalPlaces))}}const Wd=["AC","AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CV","CW","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MK","ML","MM","MN","MO","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SZ","TA","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","US","UY","UZ","VA","VC","VE","VG","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW","ZZ"];var $d=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Kd{constructor(e,t,i,n){this.paymentIntegrationService=e,this.scriptLoader=t,this.stripeIntegrationService=i,this.loadingIndicator=n}initialize(e){return $d(this,void 0,void 0,function*(){const{stripeocs:t,containerId:i}=e||{};if(!t||!i)throw new io(Jn.PaymentNotInitialized);const{methodId:n,gatewayId:o}=t;if(!n||!o)throw new Xn(Qn.MissingPaymentMethod);const r=yield this.paymentIntegrationService.loadPaymentMethod(o,{params:{method:n}}),a=r.getPaymentMethodOrThrow(n,o),{loadingContainerId:s,buttonHeight:d,onComplete:c}=t;if(this._loadingIndicatorContainer=s,this._onComplete=c,!function(e){return"object"==typeof e&&null!==e&&"initializationData"in e&&void 0!==e.initializationData&&null!==e.initializationData&&"object"==typeof e.initializationData&&"stripePublishableKey"in e.initializationData&&"stripeConnectedAccount"in e.initializationData&&"shopperLanguage"in e.initializationData&&void 0!==e.initializationData.stripePublishableKey&&void 0!==e.initializationData.stripeConnectedAccount&&void 0!==e.initializationData.shopperLanguage}(a))throw new Xn(Qn.MissingPaymentMethod);const{initializationData:u}=a,{captureMethod:l}=u,h=this.stripeIntegrationService.getStripeJsVersion(u);return this._captureMethod=l,this._stripeClient=yield this.scriptLoader.getStripeClient(u,r.getCartLocale(),h),yield this.paymentIntegrationService.loadDefaultCheckout(),yield this._mountExpressCheckoutElement(n,i,this._stripeClient,d),Promise.resolve()})}signIn(){return Promise.resolve()}signOut(){return Promise.resolve()}executePaymentMethodCheckout(){return Promise.resolve()}deinitialize(){return Promise.resolve()}_mountExpressCheckoutElement(e,t,i,n=40){return $d(this,void 0,void 0,function*(){const o=this._shouldRequireShippingAddress(),r=Object.assign(Object.assign(Object.assign({shippingAddressRequired:o},o?{allowedShippingCountries:yield this._getAvailableCountries()}:{}),o?{shippingRates:[{id:"_",amount:0,displayName:"Pending rates"}]}:{}),{billingAddressRequired:!0,emailRequired:!0,phoneNumberRequired:!0,paymentMethods:{link:_s.AUTO,applePay:_s.NEVER,googlePay:_s.NEVER,amazonPay:_s.NEVER,paypal:_s.NEVER,klarna:_s.NEVER},buttonHeight:n}),{cartAmount:a=1}=this.paymentIntegrationService.getState().getCart()||{},s=Object.assign({mode:"payment",amount:this._toCents(a),currency:this._getCurrency()},this._captureMethod?{captureMethod:this._captureMethod}:{});this._stripeElements=i.elements(s),this._linkV2Element=this._stripeElements.create(bs.EXPRESS_CHECKOUT,r),this._linkV2Element.mount(`#${t}`),this._initializeEvents(this._linkV2Element,e)})}_initializeEvents(e,t){this._shouldRequireShippingAddress()&&(e.on(Ps.SHIPPING_ADDRESS_CHANGE,e=>$d(this,void 0,void 0,function*(){return this._onShippingAddressChange(e)})),e.on(Ps.SHIPPING_RATE_CHANGE,e=>$d(this,void 0,void 0,function*(){return this._onShippingRateChange(e)}))),e.on(Ps.CONFIRM,e=>$d(this,void 0,void 0,function*(){return this._onConfirm(e,t)})),e.on(Ps.CANCEL,this._onCancel)}_onShippingAddressChange(e){return $d(this,void 0,void 0,function*(){if(!("address"in e))return;const t=e.address,i={firstName:"",lastName:"",phone:"",company:"",address1:"",address2:"",city:(null==t?void 0:t.city)||"",countryCode:(null==t?void 0:t.country)||"",postalCode:(null==t?void 0:t.postal_code)||"",stateOrProvince:(null==t?void 0:t.state)||"",stateOrProvinceCode:(null==t?void 0:t.state)||"",customFields:[]};yield this.paymentIntegrationService.updateShippingAddress(i);const n=yield this._getAvailableShippingOptions();yield this._updateDisplayedPrice(),(null==n?void 0:n.length)?e.resolve({shippingRates:n}):e.reject()})}_onCancel(){throw new Qo}_onShippingRateChange(e){return $d(this,void 0,void 0,function*(){if("shippingRate"in e){const{shippingRate:t}=e;yield this._handleShippingOptionChange(null==t?void 0:t.id),yield this._updateDisplayedPrice(),e.resolve({})}})}_onConfirm(e,t){return $d(this,void 0,void 0,function*(){if("billingDetails"in e&&"shippingAddress"in e&&this._stripeClient&&this._stripeElements){yield this._updateShippingAndBillingAddress(e),yield this.paymentIntegrationService.submitOrder();const i=this._getPaymentPayload(t);try{yield this.paymentIntegrationService.submitPayment(i)}catch(e){yield this._processAdditionalAction(e,t)}}return Promise.resolve()})}_updateShippingAndBillingAddress(e){var t,i,n,o,r,a,s,d;return $d(this,void 0,void 0,function*(){const c=this._shouldRequireShippingAddress(),u=(null===(i=null===(t=e.shippingAddress)||void 0===t?void 0:t.name)||void 0===i?void 0:i.split(" ")[0])||(null===(o=null===(n=e.billingDetails)||void 0===n?void 0:n.name)||void 0===o?void 0:o.split(" ")[0])||"",l=(null===(a=null===(r=e.shippingAddress)||void 0===r?void 0:r.name)||void 0===a?void 0:a.split(" ")[1])||(null===(d=null===(s=e.billingDetails)||void 0===s?void 0:s.name)||void 0===d?void 0:d.split(" ")[1])||"";if(c){const t=this._mapShippingAddress(e.shippingAddress,e.billingDetails,u,l);yield this.paymentIntegrationService.updateShippingAddress(t)}const h=this._mapBillingAddress(e.shippingAddress,e.billingDetails,u,l);yield this.paymentIntegrationService.updateBillingAddress(h)})}_mapShippingAddress(e,t,i,n){var o,r,a,s,d,c,u;return{firstName:i,lastName:n,phone:(null==t?void 0:t.phone)||"",company:"",address1:(null===(o=null==e?void 0:e.address)||void 0===o?void 0:o.line1)||"",address2:(null===(r=null==e?void 0:e.address)||void 0===r?void 0:r.line2)||"",city:(null===(a=null==e?void 0:e.address)||void 0===a?void 0:a.city)||"",countryCode:(null===(s=null==e?void 0:e.address)||void 0===s?void 0:s.country)||"",postalCode:(null===(d=null==e?void 0:e.address)||void 0===d?void 0:d.postal_code)||"",stateOrProvince:(null===(c=null==e?void 0:e.address)||void 0===c?void 0:c.state)||"",stateOrProvinceCode:(null===(u=null==e?void 0:e.address)||void 0===u?void 0:u.state)||"",customFields:[]}}_mapBillingAddress(e,t,i,n){var o,r,a,s,d,c;return{email:(null==t?void 0:t.email)||"",firstName:i,lastName:n,phone:(null==t?void 0:t.phone)||"",company:"",address1:(null===(o=null==t?void 0:t.address)||void 0===o?void 0:o.line1)||"",address2:"",city:(null===(r=null==t?void 0:t.address)||void 0===r?void 0:r.city)||"",countryCode:(null===(a=null==t?void 0:t.address)||void 0===a?void 0:a.country)||"",postalCode:(null===(s=null==t?void 0:t.address)||void 0===s?void 0:s.postal_code)||"",stateOrProvince:(null===(d=null==t?void 0:t.address)||void 0===d?void 0:d.state)||"",stateOrProvinceCode:(null===(c=null==e?void 0:e.address)||void 0===c?void 0:c.state)||"",customFields:[]}}_processAdditionalAction(e,t){return $d(this,void 0,void 0,function*(){if(!cs(e)||!this.stripeIntegrationService.isAdditionalActionError(e.body.errors))throw e;if(!this._stripeClient||!this._stripeElements)throw new io(Jn.PaymentNotInitialized);const{data:i}=e.body.additional_action_required,{token:n}=i,{paymentIntent:o}=yield this._confirmStripePaymentOrThrow(i,t),r=this._getPaymentPayload(t,(null==o?void 0:o.id)||n);try{this._toggleLoadingIndicator(!0),yield this.paymentIntegrationService.submitPayment(r),yield this._completeCheckoutFlow()}catch(e){this.stripeIntegrationService.throwPaymentConfirmationProceedMessage()}finally{this._toggleLoadingIndicator(!1)}})}_confirmStripePaymentOrThrow(e,t){var i,n,o;return $d(this,void 0,void 0,function*(){const{token:r,redirect_url:a}=e,s=this.stripeIntegrationService.mapStripePaymentData(this._stripeElements,a);let d;try{const e=(yield this.stripeIntegrationService.isPaymentCompleted(t,this._stripeClient))?yield null===(o=this._stripeClient)||void 0===o?void 0:o.retrievePaymentIntent(r||""):yield null===(i=this._stripeClient)||void 0===i?void 0:i.confirmPayment({elements:s.elements,clientSecret:r,redirect:_s.IF_REQUIRED,confirmParams:{return_url:null===(n=s.confirmParams)||void 0===n?void 0:n.return_url}});if(d=null==e?void 0:e.error,d||!(null==e?void 0:e.paymentIntent))throw new ja;return e}catch(e){return this.stripeIntegrationService.throwStripeError(d)}})}_completeCheckoutFlow(){return $d(this,void 0,void 0,function*(){return"function"==typeof this._onComplete?this._onComplete():(window.location.replace("/checkout/order-confirmation"),Promise.resolve())})}_getPaymentPayload(e,t){var i;const n=(null===(i=this.paymentIntegrationService.getState().getCart())||void 0===i?void 0:i.id)||"";return{methodId:e,paymentData:{formattedPayload:Object.assign(Object.assign({cart_id:n},t?{credit_card_token:{token:t}}:{}),{confirm:!1,method:Is.Link})}}}_shouldRequireShippingAddress(){const{getCart:e}=this.paymentIntegrationService.getState(),{lineItems:t}=e()||{};return!!(null==t?void 0:t.physicalItems.length)}_updateDisplayedPrice(){return $d(this,void 0,void 0,function*(){this._stripeElements&&this._stripeElements.update({currency:this._getCurrency(),mode:"payment",amount:yield this._getTotalPrice()})})}_getCurrency(){var e;if(!this._currencyCode){const t=null===(e=this.paymentIntegrationService.getState().getCart())||void 0===e?void 0:e.currency;t&&(this._currencyCode=t.code.toLowerCase())}return this._currencyCode}_getTotalPrice(){var e;return $d(this,void 0,void 0,function*(){yield this.paymentIntegrationService.loadCheckout();const{getCheckoutOrThrow:t,getCart:i}=this.paymentIntegrationService.getState(),{decimalPlaces:n}=(null===(e=i())||void 0===e?void 0:e.currency)||{},o=L(t().outstandingBalance,n).toFixed(n);return this._toCents(+o)})}_getAvailableCountries(){var e;return $d(this,void 0,void 0,function*(){const t=yield this.paymentIntegrationService.loadShippingCountries();return((null===(e=t.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code))||[]).filter(e=>Wd.includes(e))})}_getAvailableShippingOptions(){var e,t;return $d(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState().getConsignments();if(!(null==i?void 0:i[0]))return;const n=i[0],o=(n.availableShippingOptions||[]).map(this._getStripeShippingOption.bind(this)),r=null===(e=n.selectedShippingOption)||void 0===e?void 0:e.id;return r?o.sort(e=>e.id===r?-1:0):yield this._handleShippingOptionChange(null===(t=o[0])||void 0===t?void 0:t.id),o})}_getStripeShippingOption({id:e,cost:t,description:i}){return{id:e,displayName:i,amount:this._toCents(t)}}_handleShippingOptionChange(e){return $d(this,void 0,void 0,function*(){if(e&&"shipping_option_unselected"!==e)return this.paymentIntegrationService.selectShippingOption(e)})}_getAmountTransformer(){if(this._amountTransformer)return this._amountTransformer;const{getCart:e}=this.paymentIntegrationService.getState(),{currency:t}=e()||{};return t?new Yd(t.decimalPlaces):void 0}_toCents(e){const t=Math.round(100*e),i=this._getAmountTransformer();return i?i.toInteger(e):t}_toggleLoadingIndicator(e){e&&this._loadingIndicatorContainer?this.loadingIndicator.show(this._loadingIndicatorContainer):this.loadingIndicator.hide()}}const Zd=go(e=>{const t=new Ts(le()),i=new Vd({containerStyles:Gd});return new Kd(e,t,new qd(e,t),i)},[{id:"stripeocs"}]);function Qd(e,t,i){const n=new WeakMap;function o(e){return(...i)=>{const o=i[i.length-1],{useCache:r}=(a=o)&&"boolean"==typeof a.useCache?o:{useCache:!1};var a;if(!r)return e.call(this,...i);const s=n.get(this)||{};var d;return n.get(this)||n.set(this,s),s[t]||(s[t]=(d=e,ae(function(...e){const t=d.call(this,...e);return t instanceof j?W(t).pipe(ne()):"function"==typeof t?ae(e=>W(t(e)).pipe(ne()),{isEqual:v}):t},{isEqual:v}))),s[t].call(this,...i)}}return{get(){if("function"!=typeof i.value)throw new Error("Decorator should be used in functions");const e=o.call(this,i.value);return Object.defineProperty(this,t,Object.assign(Object.assign({},i),{value:e})),e}}}const Jd=e=>!!e;class Xd{constructor(e){this._requestSender=e}loadPaymentMethodsById(e,t){return i=>new j(n=>{var o;const a=null===(o=i.getState().cart.getCart())||void 0===o?void 0:o.id,s=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);n.next(r(fi.LoadPaymentMethodsRequested)),Promise.all(e.map(e=>{return i=this,n=void 0,r=function*(){try{return(yield this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:s}))).body}catch(e){return}},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r})).then(e=>{const t=e.filter(Jd);n.next(r(fi.LoadPaymentMethodsSucceeded,t)),n.complete()}).catch(e=>{n.next(r(fi.LoadPaymentMethodsFailed,e)),n.complete()})})}loadPaymentMethods(e){return t=>j.create(i=>{const n=t.getState().cart.getCartOrThrow();i.next(r(fi.LoadPaymentMethodsRequested)),this._requestSender.loadPaymentMethods(Object.assign(Object.assign({},e),{params:Object.assign(Object.assign({},null==e?void 0:e.params),{cartId:n.id})})).then(e=>{const t={deviceSessionId:e.headers["x-device-session-id"],sessionHash:e.headers["x-session-hash"]},n=e.body;i.next(r(fi.LoadPaymentMethodsSucceeded,n,t)),i.complete()}).catch(e=>{i.error(s(fi.LoadPaymentMethodsFailed,e))})})}loadPaymentMethod(e,t){return i=>j.create(n=>{var o;const a=null===(o=i.getState().cart.getCart())||void 0===o?void 0:o.id,d=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);n.next(r(fi.LoadPaymentMethodRequested,void 0,{methodId:e})),this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:d})).then(t=>{n.next(r(fi.LoadPaymentMethodSucceeded,t.body,{methodId:e})),n.complete()}).catch(t=>{n.error(s(fi.LoadPaymentMethodFailed,t,{methodId:e}))})})}}var ec;(function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)})([Qd],Xd.prototype,"loadPaymentMethod",null),function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(ec||(ec={}));const tc=ec,ic="This API endpoint is for internal use only and may change in the future",nc={"X-Checkout-SDK-Version":"1.864.0"};class oc{constructor(e){this._requestSender=e}loadPaymentMethods({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/payments",{timeout:e,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc),params:t})}loadPaymentMethod(e,{timeout:t,params:i}={}){const n=`/api/storefront/payments/${e}`;return this._requestSender.get(n,{timeout:t,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc),params:i})}}function rc(e,t,i){return(n=t)&&n.type&&n.error?H(Z(t),Q(s(e,t.payload,i))):Q(s(e,t,i));var n}class ac extends be{constructor(e){super(e||"Unable to continue as a guest because the customer is already signed in."),this.name="UnableToContinueAsGuestError",this.type="unable_to_continue_as_guest"}}class sc{constructor(e,t){this._requestSender=e,this._subscriptionActionCreator=t}continueAsGuest(e,t){return i=>{const n=i.getState(),o=n.checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);const a=n.customer.getCustomer();if(a&&!a.isGuest)throw new ac;const s=n.billingAddress.getBillingAddress();let d;if(s){const{country:t}=s,i=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(s,["country"]);d=Object.assign(Object.assign({},i),e)}else d=e;const c=!f(s);return K(H(Z(r(Ue.ContinueAsGuestRequested)),V(()=>{return e=this,i=void 0,a=function*(){const{body:e}=yield this._createOrUpdateBillingAddress(o.id,d,c,t);return r(Ue.ContinueAsGuestSucceeded,e)},new((n=void 0)||(n=Promise))(function(t,o){function r(e){try{d(a.next(e))}catch(e){o(e)}}function s(e){try{d(a.throw(e))}catch(e){o(e)}}function d(e){var i;e.done?t(e.value):(i=e.value,i instanceof n?i:new n(function(e){e(i)})).then(r,s)}d((a=a.apply(e,i||[])).next())});var e,i,n,a})).pipe(J(e=>rc(Ue.ContinueAsGuestFailed,e))),this._updateCustomerConsent(e,t))}}updateAddress(e,t){return i=>j.create(n=>{const o=i.getState(),a=o.checkout.getCheckout();if(!a)throw new qn(xn.MissingCheckout);n.next(r(Ue.UpdateBillingAddressRequested));const d=o.billingAddress.getBillingAddress(),c=!f(d),u=Object.assign(Object.assign({},e),{email:void 0===e.email&&d?d.email:e.email});d&&d.id&&(u.id=d.id),this._createOrUpdateBillingAddress(a.id,u,c,t).then(({body:e})=>{n.next(r(Ue.UpdateBillingAddressSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Ue.UpdateBillingAddressFailed,e))})})}_updateCustomerConsent({email:e,acceptsAbandonedCartEmails:t,acceptsMarketingNewsletter:i},n){return null==t&&null==i?Y():this._subscriptionActionCreator.updateSubscriptions({email:e,acceptsMarketingNewsletter:i||!1,acceptsAbandonedCartEmails:t||!1},n)}_createOrUpdateBillingAddress(e,t,i,n){return i?this._requestSender.updateAddress(e,t,n):this._requestSender.createAddress(e,t,n)}}class dc extends be{constructor(e){super(e||"Your checkout could not be processed because your cart is empty. Please add items to your cart and try again."),this.name="EmptyCartError",this.type="empty_cart"}}const cc={include:["cart.lineItems.physicalItems.options","cart.lineItems.physicalItems.stockPosition","cart.lineItems.digitalItems.options","cart.lineItems.digitalItems.stockPosition","customer","promotions.banners"].join(",")};class uc{constructor(e){this._requestSender=e}createAddress(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/billing-address`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(n,{body:t,params:cc,headers:o,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}updateAddress(e,t,{timeout:i}={}){const{id:n}=t,o=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["id"]),r=`/api/storefront/checkouts/${e}/billing-address/${n}`,a=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.put(r,{params:cc,body:o,headers:a,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class lc{constructor(e){this._requestSender=e}createBuyNowCart(e,{timeout:t}={}){const i=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post("/api/storefront/carts",{body:e,headers:i,timeout:t})}}class hc{constructor(e,t,i){this._checkoutRequestSender=e,this._configActionCreator=t,this._formFieldsActionCreator=i}loadCheckout(e,t){return()=>H(Z(r(Me.LoadCheckoutRequested)),K(this._configActionCreator.loadConfig({useCache:!0,timeout:null==t?void 0:t.timeout,params:{checkoutId:e}}),this._formFieldsActionCreator.loadFormFields({useCache:!0,timeout:null==t?void 0:t.timeout})),V(()=>this._checkoutRequestSender.loadCheckout(e,t).then(({body:e})=>r(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(e))))).pipe(J(e=>rc(Me.LoadCheckoutFailed,e)))}loadDefaultCheckout(e){return t=>H(Z(r(Me.LoadCheckoutRequested)),K(this._configActionCreator.loadConfig({useCache:!0,timeout:null==e?void 0:e.timeout}),this._formFieldsActionCreator.loadFormFields({useCache:!0,timeout:null==e?void 0:e.timeout})),V(()=>{return i=this,n=void 0,a=function*(){const i=t.getState().config.getContextConfig();if(!i||!i.checkoutId)throw new qn(xn.MissingCheckoutConfig);const{body:n}=yield this._checkoutRequestSender.loadCheckout(i.checkoutId,e);return r(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(n))},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(e=>rc(Me.LoadCheckoutFailed,e)))}updateCheckout(e,t){return i=>new j(n=>{const o=i.getState().checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);n.next(r(Me.UpdateCheckoutRequested)),this._checkoutRequestSender.updateCheckout(o.id,e,t).then(({body:e})=>{n.next(r(Me.UpdateCheckoutSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Me.UpdateCheckoutFailed,e))})})}loadCurrentCheckout(e){return t=>{const i=t.getState().checkout.getCheckout();if(!i)throw new qn(xn.MissingCheckout);return this.loadCheckout(i.id,e)(t)}}hydrateInitialState(e){return{type:Ne.HydrateInitialState,payload:e}}_transformCustomerAddresses(e){return Object.assign(Object.assign({},e),{customer:Object.assign(Object.assign({},e.customer),{addresses:e.customer.addresses.map(e=>Object.assign(Object.assign({},e),{shouldSaveAddress:!1}))})})}}function pc(e){return F(e).join(",")}function mc(e,t=[]){return Array.isArray(t)?pc([...e,...t]):function(e,t){const i=b(M(t,e=>!e)),n=b(u(t));return pc([...c(e,i),...n])}(e,t)}const gc=["cart.lineItems.physicalItems.options","cart.lineItems.physicalItems.stockPosition","cart.lineItems.digitalItems.options","cart.lineItems.digitalItems.stockPosition","customer","customer.customerGroup","payments","promotions.banners"];class yc extends Pe{constructor(e){super(e,{message:e.body.title}),this.name="CheckoutNotAvailableError",this.type="checkout_not_available"}}class fc{constructor(e){this._requestSender=e}loadCheckout(e,{params:{include:t}={},timeout:i}={}){const n=`/api/storefront/checkout/${e}`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.get(n,{params:{include:mc(gc,t)},headers:o,timeout:i}).catch(e=>{if(e.status>=400&&e.status<500)throw new yc(e);throw e})}updateCheckout(e,t,{params:{include:i}={},timeout:n}={}){const o=`/api/storefront/checkout/${e}`,r=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.put(o,{params:{include:mc(gc,i)},body:t,headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class vc{isEqual(e,t){return v(this._normalize(e),this._normalize(t))}_normalize(e){return{cartAmount:e.cartAmount,currency:e.currency,id:e.id,lineItems:{digitalItems:e.lineItems.digitalItems.slice().sort((e,t)=>`${e.productId}${e.variantId}`.localeCompare(`${t.productId}${t.variantId}`)).map(e=>({extendedSalePrice:e.extendedSalePrice,productId:e.productId,quantity:e.quantity,variantId:e.variantId})),giftCertificates:e.lineItems.giftCertificates.slice().sort((e,t)=>`${e.id}`.localeCompare(`${t.id}`)).map(e=>({amount:e.amount,recipient:e.recipient})),physicalItems:e.lineItems.physicalItems.slice().sort((e,t)=>`${e.productId}${e.variantId}`.localeCompare(`${t.productId}${t.variantId}`)).map(e=>({extendedSalePrice:e.extendedSalePrice,productId:e.productId,quantity:e.quantity,variantId:e.variantId,giftWrapping:e.giftWrapping}))}}}}class Sc extends be{constructor(e,t){super("An update to your shopping cart has been detected and your available shipping costs have been updated."),this.name="CartChangedError",this.type="cart_changed",this.data={previous:e,updated:t}}}class Cc{constructor(e){this._checkoutRequestSender=e}validate(e,t){if(!e)throw new qn(xn.MissingCheckout);return this._checkoutRequestSender.loadCheckout(e.id,t).then(t=>{const i=new vc;if(!(e.outstandingBalance===t.body.outstandingBalance&&this._compareCoupons(e.coupons,t.body.coupons)&&this._compareGiftCertificates(e.giftCertificates,t.body.giftCertificates)&&i.isEqual(e.cart,t.body.cart)))throw new Sc(this._getComparableCheckout(e),this._getComparableCheckout(t.body))})}_compareCoupons(e,t){return v(P(e,"code"),P(t,"code"))}_compareGiftCertificates(e,t){return v(P(e,"code"),P(t,"code"))}_getComparableCheckout(e){const{cart:t,coupons:i,giftCertificates:n,outstandingBalance:o}=e;return{cart:{cartAmount:t.cartAmount,currency:t.currency,lineItems:t.lineItems},coupons:i,giftCertificates:n,outstandingBalance:o}}}var Ic;class _c{constructor(e){this._configRequestSender=e}loadConfig(e){return j.create(t=>{t.next(r(mt.LoadConfigRequested)),this._configRequestSender.loadConfig(e).then(e=>{t.next(r(mt.LoadConfigSucceeded,e.body)),t.complete()}).catch(e=>{t.error(s(mt.LoadConfigFailed,e))})})}}!function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)}([Qd],_c.prototype,"loadConfig",null);class wc{constructor(e){this._requestSender=e}loadConfig({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/checkout-settings",{timeout:e,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc),params:t}).catch(e=>{if(e.status>=400&&e.status<500)throw new yc(e);throw e})}}class bc{constructor(e){this._couponRequestSender=e}applyCoupon(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);n.next(r(Qe.ApplyCouponRequested)),this._couponRequestSender.applyCoupon(o.id,e,t).then(({body:e})=>{n.next(r(Qe.ApplyCouponSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Qe.ApplyCouponFailed,e))})})}removeCoupon(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o)throw new qn(xn.MissingCheckout);n.next(r(Qe.RemoveCouponRequested)),this._couponRequestSender.removeCoupon(o.id,e,t).then(({body:e})=>{n.next(r(Qe.RemoveCouponSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Qe.RemoveCouponFailed,e))})})}}!function(e){e.AvailableShippingOptions="consignments.availableShippingOptions",e.PhysicalItemsCategoryNames="cart.lineItems.physicalItems.categoryNames",e.DigitalItemsCategoryNames="cart.lineItems.digitalItems.categoryNames"}(Ic||(Ic={}));class Ec{constructor(e){this._requestSender=e}applyCoupon(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/coupons`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(n,{headers:o,timeout:i,params:{include:pc([...gc,Ic.AvailableShippingOptions])},body:{couponCode:t}}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}removeCoupon(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/coupons/${t}`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.delete(n,{headers:o,timeout:i,params:{include:pc([...gc,Ic.AvailableShippingOptions])}}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}function Pc(e){const t=e;return"object"==typeof t&&"object"==typeof t.payload&&"string"==typeof t.payload.token}class Oc{constructor(e,t,i){this._customerRequestSender=e,this._checkoutActionCreator=t,this._spamProtectionActionCreator=i}createCustomer(e,t){return i=>{const n=i.getState().config.getStoreConfigOrThrow(),{isStorefrontSpamProtectionEnabled:o}=n.checkoutSettings,a=n=>W(this._customerRequestSender.createAccount(Object.assign(Object.assign({},e),{token:n}),t)).pipe(oe(()=>H(this._checkoutActionCreator.loadCurrentCheckout(t)(i),Z(r(Rt.CreateCustomerSucceeded)))));return H(Z(r(Rt.CreateCustomerRequested)),o?W(this._spamProtectionActionCreator.execute()(i)).pipe(oe(e=>{var t;return Pc(e)?H(Z(e),a(null===(t=e.payload)||void 0===t?void 0:t.token)):Z(e)})):a()).pipe(J(e=>rc(Rt.CreateCustomerFailed,e)))}}createAddress(e,t){return H(Z(r(Rt.CreateCustomerAddressRequested)),V(()=>{return i=this,n=void 0,a=function*(){const{body:i}=yield this._customerRequestSender.createAddress(e,t);return r(Rt.CreateCustomerAddressSucceeded,i)},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(e=>rc(Rt.CreateCustomerAddressFailed,e)))}signInCustomer(e,t){return i=>{const n=i.getState().checkout.getCheckoutOrThrow(),o=n.cart.source===ar.BuyNow?n.id:void 0;return H(Z(r(Rt.SignInCustomerRequested)),W(this._customerRequestSender.signInCustomer(Object.assign(Object.assign({},e),{cartId:o}),t)).pipe(oe(({body:e})=>e.data.persistentCartRetrievalInformation?H(this._checkoutActionCreator.loadCheckout(e.data.persistentCartRetrievalInformation.id,t)(i),Z(r(Rt.SignInCustomerSucceeded,e.data))):H(this._checkoutActionCreator.loadCurrentCheckout(t)(i),Z(r(Rt.SignInCustomerSucceeded,e.data)))))).pipe(J(e=>rc(Rt.SignInCustomerFailed,e)))}}signOutCustomer(e){return t=>{const i=t.getState().checkout.getCheckoutOrThrow(),n=i.cart.source===ar.BuyNow?i.id:void 0;return H(Z(r(Rt.SignOutCustomerRequested)),W(this._customerRequestSender.signOutCustomer(e,n)).pipe(oe(({body:i})=>H(this._checkoutActionCreator.loadCurrentCheckout(e)(t),Z(r(Rt.SignOutCustomerSucceeded,i.data)))))).pipe(J(e=>rc(Rt.SignOutCustomerFailed,e)))}}}class Ac{constructor(e){this._requestSender=e}createAccount(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer",{timeout:t,headers:nc,body:e})}createAddress(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer-address",{timeout:t,headers:nc,body:e})}signInCustomer(e,{timeout:t}={}){return this._requestSender.post("/internalapi/v1/checkout/customer",{timeout:t,headers:nc,body:e})}signOutCustomer({timeout:e}={},t){return this._requestSender.delete("/internalapi/v1/checkout/customer",Object.assign({timeout:e,headers:nc},t&&{body:{cartId:t}}))}}class Tc{constructor(e){this._formFieldsRequestSender=e}loadFormFields(e){return H(Z(r(Kt.LoadFormFieldsRequested)),V(()=>{return t=this,i=void 0,o=function*(){const{body:t}=yield this._formFieldsRequestSender.loadFields(e);return r(Kt.LoadFormFieldsSucceeded,t)},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o})).pipe(J(e=>rc(Kt.LoadFormFieldsFailed,e)))}}!function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)}([Qd],Tc.prototype,"loadFormFields",null);class kc{constructor(e){this._requestSender=e}loadFields({timeout:e}={}){return this._requestSender.get("/api/storefront/form-fields",{timeout:e,headers:Object.assign({Accept:tc.JsonV1,"X-API-INTERNAL":ic},nc)})}}class Rc extends be{constructor(e){super(e||"Unable to proceed because the required element is unexpectedly detached from the page."),this.name="UnexpectedDetachmentError",this.type="unexpected_detachment"}}class Dc{constructor(e){this._mutationObserver=e}ensurePresence(e,t){return i=this,n=void 0,r=function*(){const i=new Yr(t),n=this._mutationObserver.create(t=>{t.forEach(t=>{0!==Array.from(t.removedNodes).filter(t=>e.some(e=>t===e||t.contains(e))).length&&i.cancel(new Rc)})});n.observe(document.body,{childList:!0,subtree:!0});try{const e=yield i.promise;return n.disconnect(),e}catch(e){throw n.disconnect(),e}},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}}class Mc{constructor(e=window){this._window=e}create(e){return new this._window.MutationObserver(e)}}class Nc extends be{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}function Lc(e){if(!/^(https?:)?\/\//.test(e))throw new Nc("The provided URL must be absolute.");const t=document.createElement("a");t.href=e;const i=t.port&&-1!==e.indexOf(`${t.hostname}:${t.port}`)?t.port:"";return{hash:t.hash,hostname:t.hostname,href:t.href,origin:`${t.protocol}//${t.hostname}${i?`:${i}`:""}`,pathname:t.pathname,port:i,protocol:t.protocol,search:t.search}}function zc(e,t){return e.type===t}class Uc{constructor(e,t,i){this._targetWindow=t,this._context=i,this._targetOrigin="*"===e?"*":Lc(e).origin}post(e,t){const i=this._targetWindow;if(window===i)return;if(!i)throw new Error("Unable to post message because target window is not set.");const n=t&&$(window,"message").pipe(ee(e=>e.origin===this._targetOrigin&&zc(e.data,e.data.type)&&-1!==[t.successType,t.errorType].indexOf(e.data.type)),te(e=>{if(t.errorType===e.data.type)throw e.data;return e.data}),re(1)).toPromise();return i.postMessage(Object.assign(Object.assign({},e),{context:this._context}),this._targetOrigin),n}setTarget(e){this._targetWindow=e}setContext(e){this._context=e}}class Fc{constructor(e){var t;this._sourceOrigins=[Lc(e).origin,(t=Lc(e),Lc(0===t.hostname.indexOf("www")?t.href:t.href.replace(t.hostname,`www.${t.hostname}`))).origin],this._isListening=!1,this._listeners={}}listen(){this._isListening||(this._isListening=!0,window.addEventListener("message",this._handleMessage))}stopListen(){this._isListening&&(this._isListening=!1,window.removeEventListener("message",this._handleMessage))}addListener(e,t){let i=this._listeners[e];i||(this._listeners[e]=i=[]),-1===i.indexOf(t)&&i.push(t)}removeListener(e,t){const i=this._listeners[e];if(!i)return;const n=i.indexOf(t);n>=0&&i.splice(n,1)}trigger(e,t){const i=this._listeners[e.type];i&&i.forEach(i=>t?i(e,t):i(e))}_handleMessage(e){if(-1===this._sourceOrigins.indexOf(e.origin)||!zc(e.data,e.data.type))return;const t=e.data,{context:i}=t,n=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["context"]);this.trigger(n,i)}}!function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);r>3&&a&&Object.defineProperty(t,i,a)}([wa],Fc.prototype,"_handleMessage",null);class Bc extends be{constructor(){super("You haven't complete our spam protection challenge. Please try again."),this.name="SpamProtectionChallengeNotCompletedError",this.type="spam_protection_challenge_not_completed"}}class xc extends be{constructor(){super("Please complete our human verification challenge and try again."),this.name="CardingProtectionChallengeNotCompletedError",this.type="carding_protection_challenge_not_completed"}}class qc extends be{constructor(){super("We were not able to verify that you are not a robot. Please try again."),this.name="CardingProtectionFailedError",this.type="carding_protection_failed"}}var jc,Gc,Hc,Vc=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class Yc{constructor(e){this._googleRecaptcha=e}handle(e,t){return Vc(this,void 0,void 0,function*(){return"string"==typeof e?this.handleWithRecaptchaSitekey(e,t):this.handleWithPaymentHumanVerificationRequestError(e)})}handleWithPaymentHumanVerificationRequestError(e){return Vc(this,void 0,void 0,function*(){if(!this._isPaymentHumanVerificationRequest(e))throw e;return yield this._initialize(e.body.additional_action_required.data.key),this._performRecaptcha()})}handleWithRecaptchaSitekey(e,t){return Vc(this,void 0,void 0,function*(){if("recaptcha_v2"!==e)throw Error("Human verification method is not supported.");if(!t)throw Error("Recaptcha site key is missing.");return yield this._initialize(t),this._performRecaptcha()})}_performRecaptcha(){return this._googleRecaptcha.execute().pipe(re(1)).pipe(oe(({error:e,token:t})=>Vc(this,void 0,void 0,function*(){if(e instanceof Bc)throw new xc;if(e||!t)throw new qc;return{type:"recaptcha_v2_verification",data:{human_verification_token:t}}}))).toPromise()}_initialize(e){const t="cardingProtectionContainer";let i=document.getElementById(t);return i&&i.parentNode&&i.parentNode.removeChild(i),i=document.createElement("div"),i.setAttribute("id",t),document.body.appendChild(i),this._googleRecaptcha.load(t,e)}_isPaymentHumanVerificationRequest(e){const{additional_action_required:t,status:i}=e.body||{};return"additional_action_required"===i&&t&&"recaptcha_v2_verification"===t.type}}!function(e){e[e.CheckoutButtonNotInitialized=0]="CheckoutButtonNotInitialized",e[e.CustomerNotInitialized=1]="CustomerNotInitialized",e[e.PaymentNotInitialized=2]="PaymentNotInitialized",e[e.ShippingNotInitialized=3]="ShippingNotInitialized",e[e.SpamProtectionNotInitialized=4]="SpamProtectionNotInitialized"}(jc||(jc={}));class Wc extends be{constructor(e){super(function(e){switch(e){case jc.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case jc.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case jc.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case jc.SpamProtectionNotInitialized:return"Unable to proceed because the checkout spam protection has not been initialized.";default:return"Unable to proceed because the required component has not been initialized."}}(e)),this.subtype=e,this.name="NotInitializedError",this.type="not_initialized"}}class $c extends be{constructor(){super("We were not able to complete your spam protection verification. Please try again."),this.name="SpamProtectionFailedError",this.type="spam_protection_failed"}}class Kc extends be{constructor(){super("Spam protection is not loaded. Please try again."),this.name="SpamProtectionNotLoadedError",this.type="spam_protection_failed"}}class Zc{constructor(e,t){this.googleRecaptchaScriptLoader=e,this.mutationObserverFactory=t,this._memoized=ae((e,t,i)=>{const n=new G;if(!i)throw new Error;return this._widgetId=e.render(i.id,{sitekey:t,size:"invisible",callback:()=>{n.next({token:e.getResponse(this._widgetId)}),e.reset(this._widgetId)},"error-callback":()=>{n.next({error:new $c})}}),n},{isEqual:(e,t)=>e===t})}load(e,t){return this.googleRecaptchaScriptLoader.load().then(i=>{i&&(this._event$=this._memoized(i,t,document.getElementById(e)),this._recaptcha=i)}).catch(e=>{throw e})}reset(e){var t;const i=document.getElementById(e);null==i||i.remove(),null===(t=this._recaptcha)||void 0===t||t.reset(this._widgetId)}execute(){return V(()=>{const e=this._event$,t=this._recaptcha;if(!e||!t)throw new Wc(jc.SpamProtectionNotInitialized);return V(()=>{const e=document.querySelector('iframe[src*="bframe"]');return e?Z(e):Q(new Kc)}).pipe(ie(e=>e.pipe(X(250),oe((e,t)=>t<28?Z(e):Q(e)))),oe(i=>(this._watchRecaptchaChallengeWindow(e,i),t.execute(this._widgetId),e)),J(e=>Z({error:e})))})}_watchRecaptchaChallengeWindow(e,t){const i=t.parentElement;if(!i)throw new Kc;const n=i.parentElement;if(!n)throw new Kc;this.mutationObserverFactory.create(()=>{"hidden"===n.style.visibility&&e.next({error:new Bc})}).observe(n,{attributes:!0,attributeFilter:["style"]})}}class Qc{constructor(e,t=window){this._scriptLoader=e,this._window=t}load(){return this._loadPromise||(this._loadPromise=this._loadScript()),this._loadPromise}_loadScript(){const e="initRecaptcha",t=[`onload=${e}`,"render=explicit"].join("&");return new Promise((i,n)=>{this._window[e]=()=>i(this._window.grecaptcha),this._scriptLoader.loadScript(`//www.google.com/recaptcha/api.js?${t}`).catch(e=>{this._loadPromise=void 0,n(e)})})}}function Jc(e){return new Zc(new Qc(e),new Mc)}class Xc extends be{constructor(e){super(e||"Unable to proceed due to invalid configuration provided for the hosted payment form."),this.name="InvalidHostedFormConfigError",this.type="invalid_hosted_form_config"}}class eu extends be{constructor(e){super(e||"Unable to proceed due to an unknown error with the hosted payment form."),this.name="InvalidHostedFormError",this.type="invalid_hosted_form"}}class tu extends be{constructor(e){super(["Unable to proceed due to invalid user input values",...p(x(e),e=>P(e,({message:e})=>e))].join(". ")),this.errors=e,this.name="InvalidHostedFormValueError",this.type="invalid_hosted_form_value"}}!function(e){e.AttachRequested="HOSTED_FIELD:ATTACH_REQUESTED",e.SubmitRequested="HOSTED_FIELD:SUBMITTED_REQUESTED",e.ValidateRequested="HOSTED_FIELD:VALIDATE_REQUESTED",e.StoredCardRequested="HOSTED_FIELD:STORED_CARD_REQUESTED"}(Gc||(Gc={})),function(e){e.AttachSucceeded="HOSTED_INPUT:ATTACH_SUCCEEDED",e.AttachFailed="HOSTED_INPUT:ATTACH_FAILED",e.BinChanged="HOSTED_INPUT:BIN_CHANGED",e.Blurred="HOSTED_INPUT:BLURRED",e.Changed="HOSTED_INPUT:CHANGED",e.CardTypeChanged="HOSTED_INPUT:CARD_TYPE_CHANGED",e.Entered="HOSTED_INPUT:ENTERED",e.Focused="HOSTED_INPUT:FOCUSED",e.SubmitSucceeded="HOSTED_INPUT:SUBMIT_SUCCEEDED",e.SubmitFailed="HOSTED_INPUT:SUBMIT_FAILED",e.Validated="HOSTED_INPUT:VALIDATED",e.StoredCardSucceeded="HOSTED_INPUT:STORED_CARD_SUCCEEDED",e.StoredCardFailed="HOSTED_INPUT:STORED_CARD_FAILED"}(Hc||(Hc={}));var iu=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class nu{constructor(e,t,i,n,o,r,a,s,d,c){this._type=e,this._containerId=t,this._placeholder=i,this._accessibilityLabel=n,this._styles=o,this._eventPoster=r,this._eventListener=a,this._detachmentObserver=s,this._checkoutId=d,this._cardInstrument=c,this._iframe=document.createElement("iframe");const u=this._checkoutId?`/checkout/payment/hosted-field?version=1.864.0&checkoutId=${this._checkoutId}`:"/checkout/payment/hosted-field?version=1.864.0";this._iframe.src=u,this._iframe.style.border="none",this._iframe.style.height="100%",this._iframe.style.overflow="hidden",this._iframe.style.width="100%"}getType(){return this._type}attach(){return iu(this,void 0,void 0,function*(){const e=document.getElementById(this._containerId);if(!e)throw new Xc("Unable to proceed because the provided container ID is not valid.");e.appendChild(this._iframe),this._eventListener.listen();const t=$(this._iframe,"load").pipe(oe(({target:e})=>iu(this,void 0,void 0,function*(){const t=e&&e.contentWindow;if(!t)throw new Error("The content window of the iframe cannot be accessed.");this._eventPoster.setTarget(t),yield this._eventPoster.post({type:Gc.AttachRequested,payload:{accessibilityLabel:this._accessibilityLabel,cardInstrument:this._cardInstrument,fontUrls:this._getFontUrls(),placeholder:this._placeholder,styles:this._styles,origin:document.location.origin,type:this._type}},{successType:Hc.AttachSucceeded,errorType:Hc.AttachFailed})})),re(1)).toPromise();yield this._detachmentObserver.ensurePresence([this._iframe],t)})}detach(){this._iframe.parentElement&&(this._iframe.parentElement.removeChild(this._iframe),this._eventListener.stopListen())}submitForm(e,t){return iu(this,void 0,void 0,function*(){try{const i=this._eventPoster.post({type:Gc.SubmitRequested,payload:{fields:e,data:t}},{successType:Hc.SubmitSucceeded,errorType:Hc.SubmitFailed});return yield this._detachmentObserver.ensurePresence([this._iframe],i)}catch(e){if(this._isSubmitErrorEvent(e)){if("hosted_form_error"===e.payload.error.code)throw new eu(e.payload.error.message);if(e.payload.response)throw Te(e.payload.response);throw new Error(e.payload.error.message)}throw e}})}submitStoredCardForm(e,t){return iu(this,void 0,void 0,function*(){const i=this._eventPoster.post({type:Gc.StoredCardRequested,payload:{fields:e,data:t}},{successType:Hc.StoredCardSucceeded,errorType:Hc.StoredCardFailed});return this._detachmentObserver.ensurePresence([this._iframe],i)})}validateForm(){return iu(this,void 0,void 0,function*(){const e=this._eventPoster.post({type:Gc.ValidateRequested},{successType:Hc.Validated}),{payload:t}=yield this._detachmentObserver.ensurePresence([this._iframe],e);if(!t.isValid)throw new tu(t.errors)})}_getFontUrls(){const e="fonts.googleapis.com",t=document.querySelectorAll(`link[href*='${e}'][rel='stylesheet']`);return Array.prototype.slice.call(t).filter(t=>Lc(t.href).hostname===e).filter(e=>x(this._styles).map(e=>e&&e.fontFamily).filter(e=>"string"==typeof e).some(t=>t.split(/,\s/).some(t=>-1!==e.href.indexOf(t.replace(" ","+"))))).map(e=>e.href)}_isSubmitErrorEvent(e){return e.type===Hc.SubmitFailed}}var ou=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class ru{constructor(e,t,i,n,o){this._fields=e,this._eventListener=t,this._payloadTransformer=i,this._eventCallbacks=n,this._paymentHumanVerificationHandler=o,this._handleEnter=({payload:e})=>ou(this,void 0,void 0,function*(){try{yield this.validate()}catch(e){if(e instanceof Error&&"InvalidHostedFormValueError"!==e.name)throw e}const{onEnter:t=T}=this._eventCallbacks;t(e)});const{onBlur:r=T,onCardTypeChange:a=T,onFocus:s=T,onValidate:d=T}=this._eventCallbacks;this._eventListener.addListener(Hc.Blurred,({payload:e})=>r(e)),this._eventListener.addListener(Hc.CardTypeChanged,({payload:e})=>a(e)),this._eventListener.addListener(Hc.Focused,({payload:e})=>s(e)),this._eventListener.addListener(Hc.Validated,({payload:e})=>d(e)),this._eventListener.addListener(Hc.Entered,this._handleEnter),this._eventListener.addListener(Hc.CardTypeChanged,({payload:e})=>this._cardType=e.cardType),this._eventListener.addListener(Hc.BinChanged,({payload:e})=>this._bin=e.bin)}getBin(){return this._bin}getCardType(){return this._cardType}attach(){return ou(this,void 0,void 0,function*(){this._eventListener.listen();const e=this._getFirstField(),t=q(this._fields,e);yield e.attach(),yield Promise.all(t.map(e=>e.attach()))})}detach(){this._eventListener.stopListen(),this._fields.forEach(e=>{e.detach()})}submit(e,t){return ou(this,void 0,void 0,function*(){try{return yield this._getFirstField().submitForm(this._fields.map(e=>e.getType()),this._payloadTransformer.transform(e,t))}catch(t){const i=yield this._paymentHumanVerificationHandler.handle(t);return yield this._getFirstField().submitForm(this._fields.map(e=>e.getType()),this._payloadTransformer.transform(e,i))}})}submitStoredCard(e){return ou(this,void 0,void 0,function*(){return this._getFirstField().submitStoredCardForm(e.fields,e.data)})}validate(){return ou(this,void 0,void 0,function*(){return this._getFirstField().validateForm()})}_getFirstField(){const e=this._fields[0];if(!e)throw new Xc("Unable to proceed because the payment form has no field defined.");return e}}function au(e){return Boolean(e.instrumentId)}class su{constructor(e){this._store=e}transform(e,t){const i=this._store.getState(),n=i.checkout.getCheckout(),o=i.config.getConfig(),r=i.instruments.getInstrumentsMeta(),a=i.order.getOrder(),s=i.order.getOrderMeta(),d=k(e.paymentData,"ccExpiry","ccName","ccNumber","ccCvv"),c=i.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),u=i.paymentMethods.getPaymentMethodsMeta(),l=r&&d&&au(d)?`${i.payment.getPaymentToken()}, ${r.vaultAccessToken}`:i.payment.getPaymentToken();if(!l)throw new qn(xn.MissingPaymentToken);return{additionalAction:t,authToken:l,checkout:n,config:o,order:a,orderMeta:s,payment:d,paymentMethod:c,paymentMethodMeta:u}}}class du{constructor(e){this._store=e}create(e,t,i){const n=Object.keys(t.fields).reduce((n,o)=>{const r=t.fields[o];return r?[...n,new nu(o,r.containerId,r.placeholder||"",r.accessibilityLabel||"",t.styles||{},new Uc(e),new Fc(e),new Dc(new Mc),i,"instrumentId"in r?this._getCardInstrument(r.instrumentId):void 0)]:n},[]);return new ru(n,new Fc(e),new su(this._store),D(t,"onBlur","onEnter","onFocus","onCardTypeChange","onValidate"),new Yc(Jc(ue())))}_getCardInstrument(e){const{instruments:{getCardInstrument:t}}=this._store.getState(),i=t(e);if(!i)throw new qn(xn.MissingPaymentInstrument);return i}}class cu extends be{constructor(){super("You haven't complete our spam check. Please try again."),this.name="SpamProtectionNotCompletedError",this.type="spam_protection_not_completed"}}class uu{constructor(e,t){this._orderRequestSender=e,this._checkoutValidator=t}loadOrder(e,t){return new j(i=>{i.next(r(Ct.LoadOrderRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{i.next(r(Ct.LoadOrderSucceeded,e.body)),i.complete()}).catch(e=>{i.error(s(Ct.LoadOrderFailed,e))})})}loadOrderPayments(e,t){return new j(i=>{i.next(r(Ct.LoadOrderPaymentsRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{i.next(r(Ct.LoadOrderPaymentsSucceeded,e.body)),i.complete()}).catch(e=>{i.error(s(Ct.LoadOrderPaymentsFailed,e))})})}loadCurrentOrder(e){return t=>V(()=>{const i=this._getCurrentOrderId(t.getState());if(!i)throw new qn(xn.MissingOrderId);return this.loadOrder(i,e)})}submitOrder(e,t){return i=>H(Z(r(Ct.SubmitOrderRequested)),V(()=>{const n=i.getState(),o=n.config.getExternalSource(),a=n.config.getVariantIdentificationToken(),s=n.checkout.getCheckout();if(!s)throw new qn(xn.MissingCheckout);if(s.shouldExecuteSpamCheck)throw new cu;return W(this._checkoutValidator.validate(s,t).then(()=>this._orderRequestSender.submitOrder(this._mapToOrderRequestBody(null!=e?e:{},s.id,s.customerMessage,o),Object.assign(Object.assign({},t),{headers:{checkoutVariant:a}})))).pipe(oe(e=>H(this.loadOrder(e.body.data.order.orderId,t),Z(r(Ct.SubmitOrderSucceeded,e.body.data,Object.assign(Object.assign({},e.body.meta),{token:e.headers.token}))))))}).pipe(J(e=>rc(Ct.SubmitOrderFailed,e))))}finalizeOrder(e,t){return H(Z(r(Ct.FinalizeOrderRequested)),W(this._orderRequestSender.finalizeOrder(e,t)).pipe(oe(i=>H(this.loadOrder(e,t),Z(r(Ct.FinalizeOrderSucceeded,i.body.data)))))).pipe(J(e=>rc(Ct.FinalizeOrderFailed,e)))}_getCurrentOrderId(e){const t=e.order.getOrder(),i=e.checkout.getCheckout();return t&&t.orderId||i&&i.orderId}_mapToOrderRequestBody(e,t,i,n){const{payment:o}=e,r=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["payment"]);return o?Object.assign(Object.assign({},r),{cartId:t,customerMessage:i,externalSource:n,payment:{paymentData:o.paymentData,name:o.methodId,gateway:o.gatewayId}}):Object.assign(Object.assign({},r),{cartId:t,customerMessage:i,externalSource:n})}}class lu extends be{constructor(e){super(e||"Your checkout could not be processed because some details have changed. Please review your order and try again."),this.name="CartConsistencyError",this.type="cart_consistency"}}class hu extends be{constructor(e){super(e||"The tax provider is unavailable."),this.name="OrderTaxProviderUnavailableError",this.type="tax_provider_unavailable"}}class pu extends be{constructor(e){super(e),this.name="MissingShippingMethodError",this.type="missing_shipping_method"}}class mu extends be{constructor(e){super(e),this.name="InvalidShippingAddressError",this.type="invalid_shipping_address"}}class gu{constructor(e){this._requestSender=e}loadOrder(e,{timeout:t}={}){const i=`/api/storefront/orders/${e}`,n=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.get(i,{params:{include:pc(["payments","lineItems.physicalItems.socialMedia","lineItems.physicalItems.options","lineItems.physicalItems.categories","lineItems.digitalItems.socialMedia","lineItems.digitalItems.options","lineItems.digitalItems.categories"])},headers:n,timeout:t})}submitOrder(e,{headers:t,timeout:i}={}){return this._requestSender.post("/internalapi/v1/checkout/order",{body:e,headers:R(Object.assign({"X-Checkout-Variant":t&&t.checkoutVariant},nc),C),timeout:i}).catch(e=>{if("tax_provider_unavailable"===e.body.type)throw new hu;if("cart_has_changed"===e.body.type)throw new lu;if("missing_shipping_method"===e.body.type)throw new pu(e.body.detail);if("invalid_shipping_address"===e.body.type)throw new mu(e.body.detail);if("empty_cart"===e.body.type)throw new dc;throw e})}finalizeOrder(e,{timeout:t}={}){const i=`/internalapi/v1/checkout/order/${e}`;return this._requestSender.post(i,{timeout:t,headers:nc})}}class yu{constructor(e,t,i,n){this._paymentRequestSender=e,this._orderActionCreator=t,this._paymentRequestTransformer=i,this._paymentHumanVerificationHandler=n,this.initializeOffsitePayment=({methodId:e,gatewayId:t,instrumentId:i,target:n,promise:o,shouldSaveInstrument:a,shouldSetAsDefaultInstrument:s})=>d=>{let c;i?c={formattedPayload:{bigpay_token:i}}:a&&(c={formattedPayload:{vault_payment_instrument:a,set_as_default_stored_instrument:s||null}});const u=this._paymentRequestTransformer.transform({gatewayId:t,methodId:e,paymentData:c},d.getState());return H(Z(r(yi.InitializeOffsitePaymentRequested)),Promise.race([this._paymentRequestSender.initializeOffsitePayment(u,n),o].filter(Boolean)).then(()=>r(yi.InitializeOffsitePaymentSucceeded))).pipe(J(e=>rc(yi.InitializeOffsitePaymentFailed,e)))}}submitPayment(e){return t=>H(Z(r(yi.SubmitPaymentRequested)),V(()=>{return i=this,n=void 0,r=function*(){try{return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(e,t.getState()))}catch(i){const n=yield this._paymentHumanVerificationHandler.handle(i);return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(Object.assign(Object.assign({},e),{additionalAction:n}),t.getState()))}},new((o=void 0)||(o=Promise))(function(e,t){function a(e){try{d(r.next(e))}catch(e){t(e)}}function s(e){try{d(r.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(a,s)}d((r=r.apply(i,n||[])).next())});var i,n,o,r}).pipe(oe(({body:e})=>H(this._orderActionCreator.loadCurrentOrder()(t),Z(r(yi.SubmitPaymentSucceeded,e)))))).pipe(J(e=>rc(yi.SubmitPaymentFailed,e)))}}class fu{constructor(e){this._client=e}submitPayment(e){return new Promise((t,i)=>{this._client.submitPayment(e,(e,n)=>{e?i(this._transformResponse(e)):t(this._transformResponse(n))})})}initializeOffsitePayment(e,t){return new Promise(()=>{this._client.initializeOffsitePayment(e,null,t)})}_transformResponse(e){return{headers:e.headers,body:e.data,status:e.status,statusText:e.statusText}}}function vu(e,t){let i;return function(e){return void 0!==e.id}(e)?i=e.id:t&&t.length&&(i=t[0].id),{id:i,firstName:e.firstName,lastName:e.lastName,company:e.company,addressLine1:e.address1,addressLine2:e.address2,city:e.city,province:e.stateOrProvince,provinceCode:e.stateOrProvinceCode,postCode:e.postalCode,country:e.country,countryCode:e.countryCode,phone:e.phone,customFields:e.customFields}}const Su=["per_item_discount","percentage_discount","per_total_discount","shipping_discount","free_shipping"];function Cu(e){return{code:e.code,discount:e.displayName,discountType:Su.indexOf(e.couponType)}}function Iu(e){return{code:e.code,discountedAmount:e.used,remainingBalance:e.remaining,giftCertificate:{balance:e.balance,code:e.code,purchaseDate:e.purchaseDate}}}function _u(e){const t=[];return(e||[]).forEach(e=>{(e.banners||[]).forEach(e=>{t.push({placeholders:[],discountType:null,message:"",messageHtml:e.text})})}),t}function wu(e,t,i="id"){return Object.keys(e).reduce((n,o)=>[...n,...e[o].map(e=>"giftCertificates"===o?function(e,t){const i=new Yd(t);return{id:e.id,imageUrl:"",name:e.name,amount:e.amount,amountAfterDiscount:e.amount,discount:0,integerAmount:i.toInteger(e.amount),integerAmountAfterDiscount:i.toInteger(e.amount),integerUnitPrice:i.toInteger(e.amount),integerUnitPriceAfterDiscount:i.toInteger(e.amount),integerDiscount:0,quantity:1,sender:e.sender,recipient:e.recipient,type:"ItemGiftCertificateEntity",attributes:[],variantId:null}}(e,t):function(e,t,i,n="id"){const o=new Yd(i);return{id:e[n],imageUrl:e.imageUrl,amount:e.extendedListPrice,amountAfterDiscount:e.extendedSalePrice,discount:e.discountAmount,integerAmount:o.toInteger(e.extendedListPrice),integerAmountAfterDiscount:o.toInteger(e.extendedSalePrice),integerDiscount:o.toInteger(e.discountAmount),integerUnitPrice:o.toInteger(e.listPrice),integerUnitPriceAfterDiscount:o.toInteger(e.salePrice),downloadsPageUrl:e.downloadPageUrl,name:e.name,quantity:e.quantity,brand:e.brand,sku:e.sku,categoryNames:e.categoryNames,variantId:e.variantId,productId:e.productId,attributes:(e.options||[]).map(e=>({name:e.name,value:e.value})),addedByPromotion:e.addedByPromotion,type:t}}(e,function(e){switch(e){case"physicalItems":return"ItemPhysicalEntity";case"digitalItems":return"ItemDigitalEntity";case"giftCertificates":return"ItemGiftCertificateEntity";default:return""}}(o),t,i))],[])}function bu(e){const t=e.cart.currency.decimalPlaces,i=new Yd(t);return{id:e.cart.id,items:wu(e.cart.lineItems,t),currency:e.cart.currency.code,coupon:{discountedAmount:N(e.cart.coupons,(e,t)=>e+t.discountedAmount,0),coupons:e.cart.coupons.map(Cu)},discount:{amount:e.cart.discountAmount,integerAmount:i.toInteger(e.cart.discountAmount)},discountNotifications:_u(e.promotions),giftCertificate:{totalDiscountedAmount:N(e.giftCertificates,(e,t)=>e+t.used,0),appliedGiftCertificates:w(e.giftCertificates.map(Iu),"code")},shipping:{amount:e.shippingCostTotal,integerAmount:i.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:i.toInteger(e.shippingCostBeforeDiscount),required:z(e.cart.lineItems.physicalItems,e=>e.isShippingRequired)},subtotal:{amount:e.subtotal,integerAmount:i.toInteger(e.subtotal)},storeCredit:{amount:e.customer?e.customer.storeCredit:0},taxSubtotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:i.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.grandTotal,integerAmount:i.toInteger(e.grandTotal)}}}var Eu;!function(e){e.APPLEPAY="applepay",e.AMAZON_PAY_V2="amazonpay",e.BRAINTREE_PAYPAL="braintreepaypal",e.BRAINTREE_VENMO="braintreevenmo",e.BRAINTREE_PAYPAL_CREDIT="braintreepaypalcredit",e.GOOGLEPAY_ADYENV2="googlepayadyenv2",e.GOOGLEPAY_ADYENV3="googlepayadyenv3",e.GOOGLEPAY_AUTHORIZENET="googlepayauthorizenet",e.GOOGLEPAY_BNZ="googlepaybnz",e.GOOGLEPAY_BRAINTREE="googlepaybraintree",e.GOOGLEPAY_CHECKOUTCOM="googlepaycheckoutcom",e.GOOGLEPAY_CYBERSOURCEV2="googlepaycybersourcev2",e.GOOGLEPAY_ORBITAL="googlepayorbital",e.GOOGLEPAY_STRIPE="googlepaystripe",e.GOOGLEPAY_STRIPEUPE="googlepaystripeupe",e.GOOGLEPAY_WORLDPAYACCESS="googlepayworldpayaccess",e.PAYPALEXPRESS="paypalexpress"}(Eu||(Eu={}));const Pu=Eu;function Ou(e,t){const i=e.firstName||t.firstName||"",n=e.lastName||t.lastName||"";return{addresses:(e.addresses||[]).map(e=>vu(e)),customerId:e.id,isGuest:e.isGuest,storeCredit:e.storeCredit,email:e.email||t.email||"",firstName:i,lastName:n,name:e.fullName||[i,n].join(" "),customerGroupName:e.customerGroup&&e.customerGroup.name}}class Au{format(e){const[t="",i=""]=e.split(new RegExp("\\s*/\\s*")),n=t.slice(0,2),o=4===i.length?i.slice(-2):i?i.slice(0,2):t.slice(2);return e.length<2?t:e.length>3&&!o?n:`${n} / ${o}`}toObject(e){const[t="",i=""]=e.split(new RegExp("\\s*/\\s*"));return/^\d+$/.test(t)&&/^\d+$/.test(i)?{month:1===t.length?`0${t}`:t.slice(0,2),year:2===i.length?`20${i}`:i.slice(0,4)}:{month:"",year:""}}}class Tu{format(e){const{card:t}=ye(e);if(!t)return e;const i=O(ge(e).map(e=>O(e.lengths))),n=this.unformat(e).slice(0,i);return t.gaps.filter(e=>n.length>e).reduce((e,t,i)=>[e.slice(0,t+i),e.slice(t+i)].join(" "),n)}unformat(e){const{card:t}=ye(e);return t?e.replace(new RegExp(" ","g"),""):e}}function ku(e,t={}){const i=e.currency.decimalPlaces,n=new Yd(i);return{id:e.orderId,items:wu(e.lineItems,e.currency.decimalPlaces,"productId"),orderId:e.orderId,currency:e.currency.code,customerCanBeCreated:e.customerCanBeCreated,payment:Mu(e.payments,t.payment),subtotal:{amount:e.baseAmount,integerAmount:n.toInteger(e.baseAmount)},coupon:{discountedAmount:N(e.coupons,(e,t)=>e+t.discountedAmount,0),coupons:e.coupons.map(Cu)},discount:{amount:e.discountAmount,integerAmount:n.toInteger(e.discountAmount)},token:t.orderToken,callbackUrl:t.callbackUrl,discountNotifications:[],giftCertificate:Du(e.payments),socialData:Lu(e),status:e.status,hasDigitalItems:e.hasDigitalItems,isDownloadable:e.isDownloadable,isComplete:e.isComplete,shipping:{amount:e.shippingCostTotal,integerAmount:n.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:n.toInteger(e.shippingCostBeforeDiscount)},storeCredit:{amount:Ru(e.payments)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:n.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:n.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.orderAmount,integerAmount:e.orderAmountAsInteger}}}function Ru(e){const t=l(e,{providerId:"storecredit"});return t?t.amount:0}function Du(e){const t=u(e,{providerId:"giftcertificate"});return{totalDiscountedAmount:N(t,(e,t)=>t.amount+e,0),appliedGiftCertificates:w(t.map(e=>({code:e.detail.code,discountedAmount:e.amount,remainingBalance:e.detail.remaining,giftCertificate:{balance:e.amount+e.detail.remaining,code:e.detail.code,purchaseDate:""}})),"code")}}function Mu(e,t={}){const i=l(e,Nu);return i?{id:i.providerId,status:(n=i.detail.step,`PAYMENT_STATUS_${n}`),helpText:i.detail.instructions,returnUrl:t.returnUrl}:{};var n}function Nu(e){return"giftcertificate"!==e.providerId&&"storecredit"!==e.providerId}function Lu(e){const t={};return[...e.lineItems.physicalItems,...e.lineItems.digitalItems].forEach(e=>{var i;t[e.id]=(i=e,["fb","tw","gp"].reduce((e,t)=>{const n=i.socialMedia&&l(i.socialMedia,e=>e.code===t);return n?(e[t]={name:i.name,description:i.name,image:i.imageUrl,url:n.link,shareText:n.text,sharingLink:n.link,channelName:n.channel,channelCode:n.code},e):e},{}))}),t}function zu(e,t){return{description:e.description,module:e.type,price:e.cost,id:e.id,selected:t,isRecommended:e.isRecommended,imageUrl:e.imageUrl,transitTime:e.transitTime}}class Uu{constructor(){this._cardExpiryFormatter=new Au,this._cardNumberFormatter=new Tu}transform(e,t){const i=t.billingAddress.getBillingAddress(),n=t.checkout.getCheckout(),o=t.customer.getCustomer(),r=t.order.getOrder(),a=t.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),s=this._mapShippingAddress(t,a),d=t.consignments.getConsignments(),c=t.consignments.getShippingOption(),u=t.config.getStoreConfig(),l=t.config.getContextConfig(),h=t.instruments.getInstrumentsMeta(),p=t.paymentMethods.getPaymentMethodsMeta(),m=t.order.getOrderMeta(),g=o&&i&&Ou(o,i),y=h&&e.paymentData&&(au(e.paymentData)||function(e){const t=e.formattedPayload;return!!t&&("string"==typeof t.bigpay_token||Boolean(t.bigpay_token&&t.bigpay_token.token))}(e.paymentData))?`${t.payment.getPaymentToken()}, ${h.vaultAccessToken}`:t.payment.getPaymentToken();if(!y)throw new qn(xn.MissingPaymentToken);return{additionalAction:e.additionalAction,authToken:y,customer:g,billingAddress:i&&vu(i),shippingAddress:s&&vu(s,d),shippingOption:c&&zu(c,!0),cart:n&&bu(n),order:r&&ku(r,m),orderMeta:m,payment:e.paymentData,paymentMethod:a&&this._transformPaymentMethod(a),quoteMeta:{request:Object.assign(Object.assign({},p),{geoCountryCode:l&&l.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:D(u&&u.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}}transformWithHostedFormData(e,t,i){const{additionalAction:n,authToken:o,checkout:r,config:a,order:s,orderMeta:d,payment:c={},paymentMethod:u,paymentMethodMeta:l}=t,h=r&&r.consignments[0],p=h&&h.shippingAddress,m=h&&h.selectedShippingOption;return{additionalAction:n,authToken:o,paymentMethod:u&&this._transformPaymentMethod(u),customer:s&&s.billingAddress&&r&&Ou(r.customer,s.billingAddress),billingAddress:s&&s.billingAddress&&vu(s.billingAddress),shippingAddress:p&&r&&vu(p,r.consignments),shippingOption:m&&zu(m,!0),cart:r&&bu(r),order:s&&ku(s,d),orderMeta:d,payment:this._transformHostedInputValues(e,c,i),quoteMeta:{request:Object.assign(Object.assign({},l),{geoCountryCode:a&&a.context.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:a&&D(a.storeConfig.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}}_transformPaymentMethod(e){return"multi-option"!==e.method||e.gateway?e.initializationData&&e.initializationData.gateway?Object.assign(Object.assign({},e),{id:e.initializationData.gateway}):e.id===Pu.BRAINTREE_VENMO?Object.assign(Object.assign({},e),{id:Pu.BRAINTREE_PAYPAL}):e:Object.assign(Object.assign({},e),{gateway:e.id})}_transformHostedInputValues(e,t,i){return"instrumentId"in t?Object.assign(Object.assign({},t),{ccCvv:e.cardCodeVerification,ccNumber:e.cardNumberVerification&&this._cardNumberFormatter.unformat(e.cardNumberVerification),hostedFormNonce:i}):Object.assign(Object.assign({},t),{ccCvv:e.cardCode,ccExpiry:this._cardExpiryFormatter.toObject(e.cardExpiry||""),ccName:e.cardName||"",ccNumber:this._cardNumberFormatter.unformat(e.cardNumber||""),hostedFormNonce:i})}_mapShippingAddress(e,t){var i,n,o,r;if(t){const a=null===(n=null===(i=t.initializationData)||void 0===i?void 0:i.bopis)||void 0===n?void 0:n.enabled,s=null===(r=null===(o=t.initializationData)||void 0===o?void 0:o.bopis)||void 0===r?void 0:r.requiredAddress,d=e.consignments.getConsignments(),c=null==d?void 0:d.every(e=>e.selectedPickupOption);if(a&&c&&"none"===s)return}return e.shippingAddress.getShippingAddress()}}class Fu{updatePaymentProviderCustomer(e){return Z(r(Di.UpdatePaymentProviderCustomer,e))}}class Bu{widgetInteraction(e,t){const i={methodId:t&&t.methodId};return H(Z(r(Pi.WidgetInteractionStarted,void 0,i)),V(()=>e().then(()=>r(Pi.WidgetInteractionFinished,void 0,i)))).pipe(J(e=>rc(Pi.WidgetInteractionFailed,e,i)))}}class xu{constructor(e,t){this._remoteCheckoutRequestSender=e,this._checkoutActionCreator=t}initializeBilling(e,t,i){return j.create(n=>{n.next(r(Gi.InitializeRemoteBillingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeBilling(e,t,i).then(({body:t={}})=>{n.next(r(Gi.InitializeRemoteBillingSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Gi.InitializeRemoteBillingFailed,t,{methodId:e}))})})}initializeShipping(e,t,i){return j.create(n=>{n.next(r(Gi.InitializeRemoteShippingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeShipping(e,t,i).then(({body:t={}})=>{n.next(r(Gi.InitializeRemoteShippingSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Gi.InitializeRemoteShippingFailed,t,{methodId:e}))})})}initializePayment(e,t,i){return j.create(n=>{n.next(r(Gi.InitializeRemotePaymentRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializePayment(e,t,i).then(({body:t={}})=>{n.next(r(Gi.InitializeRemotePaymentSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Gi.InitializeRemotePaymentFailed,t,{methodId:e}))})})}loadSettings(e,t){return j.create(i=>{i.next(r(Gi.LoadRemoteSettingsRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.loadSettings(e,t).then(({body:t})=>{i.next(r(Gi.LoadRemoteSettingsSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Gi.LoadRemoteSettingsFailed,t,{methodId:e}))})})}signOut(e,t){return j.create(i=>{i.next(r(Gi.SignOutRemoteCustomerRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.signOut(e,t).then(()=>{i.next(r(Gi.SignOutRemoteCustomerSucceeded,void 0,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Gi.SignOutRemoteCustomerFailed,t,{methodId:e}))})})}forgetCheckout(e,t){return H(Z(r(Gi.ForgetCheckoutRemoteCustomerRequested,void 0,{methodId:e})),V(()=>{return i=this,n=void 0,a=function*(){return yield this._remoteCheckoutRequestSender.forgetCheckout(t),yield this._checkoutActionCreator.loadCurrentCheckout(),r(Gi.ForgetCheckoutRemoteCustomerSucceeded,void 0,{methodId:e})},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(t=>rc(Gi.ForgetCheckoutRemoteCustomerFailed,t,{methodId:e})))}updateCheckout(e,t){return r(Gi.UpdateRemoteCheckout,t,{methodId:e})}}class qu{constructor(e){this._requestSender=e}initializeBilling(e,t,{timeout:i}={}){const n=`/remote-checkout/${e}/billing`;return this._requestSender.get(n,{params:t,timeout:i,headers:nc})}initializeShipping(e,t,{timeout:i}={}){const n=`/remote-checkout/${e}/shipping`;return this._requestSender.get(n,{params:t,timeout:i,headers:nc})}initializePayment(e,t,{timeout:i}={}){const n=`/remote-checkout/${e}/payment`;return this._requestSender.get(n,{params:t,timeout:i,headers:nc})}loadSettings(e,{timeout:t}={}){const i=`/remote-checkout/${e}/settings`;return this._requestSender.get(i,{timeout:t,headers:nc})}signOut(e,{timeout:t}={}){const i=`/remote-checkout/${e}/signout`;return this._requestSender.get(i,{timeout:t,headers:nc})}generateToken({timeout:e}={}){return this._requestSender.get("/remote-checkout-token",{timeout:e,headers:nc})}trackAuthorizationEvent({timeout:e}={}){return this._requestSender.post("/remote-checkout/events/shopper-checkout-service-provider-authorization-requested",{timeout:e,headers:nc})}forgetCheckout({timeout:e}={}){return this._requestSender.post("/remote-checkout/forget-checkout",{timeout:e,headers:nc})}}class ju{constructor(e,t){this._consignmentRequestSender=e,this._checkoutRequestSender=t}unassignItemsByAddress(e,t){return i=>{const n=i.getState();if(!n.checkout.getCheckout())throw new qn(xn.MissingCheckout);const o=this._consignmentHasAddress(e)?e.address:e.shippingAddress,r=n.consignments.getConsignmentByAddress(o);if(!r)throw new Nc("No consignment found for the specified address");const a=this._removeLineItems(e.lineItems,r,n.cart.getCart());return a.length?this.updateConsignment({id:r.id,address:o,lineItems:a},t)(i):this.deleteConsignment(r.id,t)(i)}}assignItemsByAddress(e,t){return i=>{const n=i.getState(),o=this._consignmentHasAddress(e)?e.address:e.shippingAddress,r=n.consignments.getConsignmentByAddress(o);return this._createOrUpdateConsignment({id:r&&r.id,address:o,lineItems:this._addLineItems(e.lineItems,r,n.cart.getCart())},t)(i)}}selectShippingOption(e,t){return i=>j.create(n=>{const o=i.getState(),a=o.checkout.getCheckout(),d=o.consignments.getConsignments();if(!a)throw new qn(xn.MissingCheckout);if(!d||!d.length)throw new qn(xn.MissingConsignments);const c={id:d[0].id,shippingOptionId:e},u={id:d[0].id};n.next(r(Xe.UpdateShippingOptionRequested,void 0,u)),this._consignmentRequestSender.updateConsignment(a.id,c,t).then(({body:e})=>{n.next(r(Xe.UpdateShippingOptionSucceeded,e,u)),n.complete()}).catch(e=>{n.error(s(Xe.UpdateShippingOptionFailed,e,u))})})}loadShippingOptions(e){return t=>j.create(i=>{const n=t.getState().checkout.getCheckout();if(!n)throw new qn(xn.MissingCheckout);i.next(r(Xe.LoadShippingOptionsRequested)),this._checkoutRequestSender.loadCheckout(n.id,Object.assign(Object.assign({},e),{params:{include:[Ic.AvailableShippingOptions]}})).then(({body:e})=>{i.next(r(Xe.LoadShippingOptionsSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Xe.LoadShippingOptionsFailed,e))})})}updateAddress(e,t){return i=>{const n=this._getUpdateAddressRequestBody(e,i),o=i.getState().consignments.getConsignments();return o&&o.length&&(n.id=o[0].id),this._createOrUpdateConsignment(n,t)(i)}}createConsignments(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o||!o.id)throw new qn(xn.MissingCheckout);n.next(r(Xe.CreateConsignmentsRequested)),this._consignmentRequestSender.createConsignments(o.id,e,t).then(({body:e})=>{n.next(r(Xe.CreateConsignmentsSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Xe.CreateConsignmentsFailed,e))})})}updateConsignment(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout();if(!o||!o.id)throw new qn(xn.MissingCheckout);const a={id:e.id};n.next(r(Xe.UpdateConsignmentRequested,void 0,a)),this._consignmentRequestSender.updateConsignment(o.id,e,t).then(({body:e})=>{n.next(r(Xe.UpdateConsignmentSucceeded,e,a)),n.complete()}).catch(e=>{n.error(s(Xe.UpdateConsignmentFailed,e,a))})})}deleteConsignment(e,t){return i=>j.create(n=>{const o=i.getState().checkout.getCheckout(),a={id:e};if(!o||!o.id)throw new qn(xn.MissingCheckout);n.next(r(Xe.DeleteConsignmentRequested,void 0,a)),this._consignmentRequestSender.deleteConsignment(o.id,e,t).then(({body:e})=>{n.next(r(Xe.DeleteConsignmentSucceeded,e,a)),n.complete()}).catch(e=>{n.error(s(Xe.DeleteConsignmentFailed,e,a))})})}updateShippingOption(e,t){return i=>j.create(n=>{var o;const a=i.getState().checkout.getCheckout(),d=i.getState().consignments.getConsignmentById(e.id);if((null===(o=null==d?void 0:d.selectedShippingOption)||void 0===o?void 0:o.id)===e.shippingOptionId)return void n.complete();if(!a||!a.id)throw new qn(xn.MissingCheckout);const c={id:e.id};n.next(r(Xe.UpdateShippingOptionRequested,void 0,c)),this._consignmentRequestSender.updateConsignment(a.id,e,t).then(({body:e})=>{n.next(r(Xe.UpdateShippingOptionSucceeded,e,c)),n.complete()}).catch(e=>{n.error(s(Xe.UpdateShippingOptionFailed,e,c))})})}_createOrUpdateConsignment(e,t){return i=>{const n=i.getState().checkout.getCheckout();if(!n||!n.id)throw new qn(xn.MissingCheckout);return this._isUpdateConsignmentRequest(e)?this.updateConsignment(e,t)(i):this.createConsignments([e],t)(i)}}_getUpdateAddressRequestBody(e,t){const i=t.getState().cart.getCart();if(!i)throw new qn(xn.MissingCart);const{physicalItems:n,customItems:o=[]}=i.lineItems;return{address:e,lineItems:[...n,...o].map(e=>({itemId:e.id,quantity:e.quantity}))}}_removeLineItems(e,t,i){if(!i)throw new qn(xn.MissingCart);return this._hydrateLineItems(t.lineItemIds,i).map(t=>{const i=l(e,e=>e.itemId===t.itemId);return Object.assign(Object.assign({},t),{quantity:i?t.quantity-i.quantity:t.quantity})}).filter(e=>e.quantity>0)}_addLineItems(e,t,i){if(!t)return e;if(!i)throw new qn(xn.MissingCart);return e.concat(this._hydrateLineItems(t.lineItemIds,i)).filter(e=>e.quantity>0)}_hydrateLineItems(e,t){return e.map(e=>{const i=l(t.lineItems.physicalItems,t=>t.id===e);return{itemId:e,quantity:i?i.quantity:0}})}_isUpdateConsignmentRequest(e){return!!e.id}_consignmentHasAddress(e){return"object"==typeof e&&"address"in e}}const Gu=["consignments.availableShippingOptions","cart.lineItems.physicalItems.options","cart.lineItems.physicalItems.stockPosition","cart.lineItems.digitalItems.options","cart.lineItems.digitalItems.stockPosition","customer","promotions.banners"];class Hu{constructor(e){this._requestSender=e}createConsignments(e,t,{timeout:i,params:{include:n}={}}={}){const o=`/api/storefront/checkouts/${e}/consignments`,r=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(o,{body:t,params:{include:mc(Gu,n)},headers:r,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}updateConsignment(e,t,{timeout:i,params:{include:n}={}}={}){const{id:o}=t,r=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(t,["id"]),a=`/api/storefront/checkouts/${e}/consignments/${o}`,s=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.put(a,{body:r,params:{include:mc(Gu,n)},headers:s,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}deleteConsignment(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/consignments/${t}`,o=Object.assign({Accept:tc.JsonV1},nc),r=pc(Gu);return this._requestSender.delete(n,{params:{include:r},headers:o,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class Vu{constructor(e,t){this._shippingCountryRequestSender=e,this._store=t}loadCountries(e){const{checkout:t}=this._store.getState(),i=t.getCheckout(),n=i?i.channelId:null;return j.create(t=>{t.next(r(sn.LoadShippingCountriesRequested)),this._shippingCountryRequestSender.loadCountries(n,e).then(e=>{t.next(r(sn.LoadShippingCountriesSucceeded,e.body.data)),t.complete()}).catch(e=>{t.error(s(sn.LoadShippingCountriesFailed,e))})})}}class Yu{constructor(e,t){this._requestSender=e,this._config=t}loadCountries(e,{timeout:t}={}){const i="/internalapi/v1/shipping/countries"+(e?`?channel_id=${e}`:""),n=Object.assign({"Accept-Language":this._config.locale},nc);return this._requestSender.get(i,{headers:n,timeout:t})}}var Wu=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class $u{constructor(e,t){this._googleRecaptcha=e,this._requestSender=t}initialize(e){return t=>H(Z(r(Nn.InitializeRequested,void 0)),V(()=>Wu(this,void 0,void 0,function*(){const i=e?e.containerId:"spamProtectionContainer";if(document.getElementById(i)&&this._googleRecaptcha.reset(i),!e&&!document.getElementById(i)){const e=document.createElement("div");e.setAttribute("id",i),document.body.appendChild(e)}const n=t.getState().config.getStoreConfigOrThrow().checkoutSettings.googleRecaptchaSitekey;return yield this._googleRecaptcha.load(i,n),r(Nn.InitializeSucceeded)}))).pipe(J(e=>rc(Nn.InitializeFailed,e)))}verifyCheckoutSpamProtection(){return e=>V(()=>{const t=e.getState().checkout.getCheckout();if(!t)throw new qn(xn.MissingCheckout);return H(Z(r(Nn.VerifyCheckoutRequested)),W(this.execute()(e)).pipe(oe(e=>Pc(e)&&e.payload?W(this._requestSender.validate(t.id,e.payload.token)).pipe(oe(({body:t})=>H(Z(e),Z(r(Nn.VerifyCheckoutSucceeded,t))))):Z(e)))).pipe(J(e=>rc(Nn.VerifyCheckoutFailed,e)))})}execute(){return e=>H(Z(r(Nn.ExecuteRequested)),this.initialize()(e),this._googleRecaptcha.execute().pipe(re(1)).pipe(oe(({error:e,token:t})=>Wu(this,void 0,void 0,function*(){if(e instanceof Bc)throw e;if(e||!t)throw new $c;return r(Nn.ExecuteSucceeded,{token:t})})))).pipe(J(e=>rc(Nn.ExecuteFailed,e)))}}class Ku{constructor(e){this._requestSender=e}validate(e,t,{timeout:i}={}){const n=`/api/storefront/checkouts/${e}/spam-protection`,o=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(n,{body:{token:t},headers:o,timeout:i}).catch(e=>{if("empty_cart"===e.body.type)throw new dc;throw e})}}class Zu{constructor(e){this._storeCreditRequestSender=e}applyStoreCredit(e,t){return i=>H(Z(r(En.ApplyStoreCreditRequested)),V(()=>{return n=this,o=void 0,s=function*(){const n=i.getState().checkout.getCheckout();if(!n)throw new qn(xn.MissingCheckout);const{body:o}=yield e?this._storeCreditRequestSender.applyStoreCredit(n.id,t):this._storeCreditRequestSender.removeStoreCredit(n.id,t);return r(En.ApplyStoreCreditSucceeded,o)},new((a=void 0)||(a=Promise))(function(e,t){function i(e){try{d(s.next(e))}catch(e){t(e)}}function r(e){try{d(s.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(i,r)}d((s=s.apply(n,o||[])).next())});var n,o,a,s})).pipe(J(e=>rc(En.ApplyStoreCreditFailed,e)))}}class Qu{constructor(e){this._requestSender=e}applyStoreCredit(e,{timeout:t}={}){const i=`/api/storefront/checkouts/${e}/store-credit`,n=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post(i,{headers:n,timeout:t,params:{include:pc(gc)}})}removeStoreCredit(e,{timeout:t}={}){const i=`/api/storefront/checkouts/${e}/store-credit`,n=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.delete(i,{headers:n,timeout:t,params:{include:pc(gc)}})}}class Ju extends Pe{constructor(e){super(e),this.name="UpdateSubscriptionsError",this.type="update_subscriptions"}}class Xu{constructor(e){this._subscriptionsRequestSender=e}updateSubscriptions(e,t){return H(Z(r(ze.UpdateSubscriptionsRequested)),V(()=>{return i=this,n=void 0,a=function*(){const{body:i}=yield this._subscriptionsRequestSender.updateSubscriptions(e,t);return r(ze.UpdateSubscriptionsSucceeded,i)},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{d(a.next(e))}catch(e){t(e)}}function s(e){try{d(a.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof o?i:new o(function(e){e(i)})).then(r,s)}d((a=a.apply(i,n||[])).next())});var i,n,o,a})).pipe(J(e=>rc(ze.UpdateSubscriptionsFailed,new Ju(e))))}}class el{constructor(e){this._requestSender=e}updateSubscriptions(e,{timeout:t}={}){const i=Object.assign({Accept:tc.JsonV1},nc);return this._requestSender.post("/api/storefront/subscriptions",{body:e,headers:i,timeout:t})}}const tl=A(e=>Array.isArray(e)?e.map(e=>il(e)):$e(e)?Object.keys(e).reduce((t,i)=>Object.assign(Object.assign({},t),{[i]:il(e[i])}),{}):e);tl.cache=new WeakMap;const il=e=>"object"==typeof e&&null!==e?tl(e):e;function nl(e){return(...t)=>il(e(...t))}function ol({billingAddress:{getBillingAddress:e,getBillingAddressOrThrow:t},cart:{getCart:i,getCartOrThrow:n,getLocale:o},checkout:{getCheckout:r,getCheckoutOrThrow:a,getOutstandingBalance:s},config:{getContextConfig:d,getHost:c,getLocale:u,getStoreConfig:l,getStoreConfigOrThrow:h,getConfig:p},consignments:{getConsignments:m,getConsignmentsOrThrow:g},countries:{getCountries:y},customer:{getCustomer:f,getCustomerOrThrow:v},instruments:{getCardInstrument:S,getCardInstrumentOrThrow:C,getInstruments:I,getInstrumentsMeta:_},order:{getOrder:w,getOrderOrThrow:b,getOrderMeta:E},payment:{getPaymentToken:P,getPaymentTokenOrThrow:O,getPaymentId:A,getPaymentIdOrThrow:T,getPaymentStatus:k,getPaymentStatusOrThrow:R,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:M,isPaymentDataRequired:N},paymentMethods:{getPaymentMethod:L,getPaymentMethodOrThrow:z,getPaymentMethodsMeta:U},paymentProviderCustomer:{getPaymentProviderCustomer:F,getPaymentProviderCustomerOrThrow:B},paymentStrategies:{isInitialized:x},shippingAddress:{getShippingAddress:q,getShippingAddressOrThrow:j,getShippingAddresses:G,getShippingAddressesOrThrow:H},shippingCountries:{getShippingCountries:V}}){return{getHost:nl(c),getLocale:nl(u),getCartLocale:nl(o),getBillingAddress:nl(e),getBillingAddressOrThrow:nl(t),getCart:nl(i),getCartOrThrow:nl(n),getCheckout:nl(r),getCheckoutOrThrow:nl(a),getCountries:nl(y),getStoreConfig:nl(l),getStoreConfigOrThrow:nl(h),getConfig:nl(p),getConsignments:nl(m),getConsignmentsOrThrow:nl(g),getContextConfig:nl(d),getCustomer:nl(f),getCustomerOrThrow:nl(v),getCardInstrument:nl(S),getInstruments:nl(I),getCardInstrumentOrThrow:nl(C),getOrder:nl(w),getOrderOrThrow:nl(b),getOrderMeta:nl(E),getInstrumentsMeta:nl(_),getPaymentToken:P,getPaymentTokenOrThrow:O,getPaymentId:A,getPaymentIdOrThrow:T,getPaymentStatus:k,getPaymentStatusOrThrow:R,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:M,getPaymentMethod:nl(L),getPaymentMethodOrThrow:nl(z),getPaymentMethodsMeta:nl(U),getPaymentProviderCustomer:nl(F),getPaymentProviderCustomerOrThrow:nl(B),getShippingAddress:nl(q),getShippingAddressOrThrow:nl(j),getShippingAddresses:nl(G),getShippingAddressesOrThrow:nl(H),getShippingCountries:nl(V),getOutstandingBalance:nl(s),isPaymentDataRequired:N,isPaymentMethodInitialized:x}}var rl,al=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(a,s)}d((n=n.apply(e,t||[])).next())})};class sl{constructor(e,t,i,n,o,r,a,s,d,c,u,l,h,p,m,g,y,f,v,S){this._store=e,this._storeProjectionFactory=t,this._checkoutActionCreator=i,this._checkoutValidator=n,this._hostedFormFactory=o,this._orderActionCreator=r,this._billingAddressActionCreator=a,this._consignmentActionCreator=s,this._paymentMethodActionCreator=d,this._paymentActionCreator=c,this._paymentHumanVerificationHandler=u,this._customerActionCreator=l,this._cartRequestSender=h,this._storeCreditActionCreator=p,this._couponActionCreator=m,this._spamProtectionActionCreator=g,this._paymentProviderCustomerActionCreator=y,this._shippingCountryActionCreator=f,this._remoteCheckoutActionCreator=v,this._paymentStrategyWidgetActionCreator=S,this._storeProjection=this._storeProjectionFactory.create(this._store)}createHostedForm(e,t){const i=this._storeProjection.getState().getCheckoutOrThrow().id;return this._hostedFormFactory.create(e,t,i)}subscribe(e,...t){return this._storeProjection.subscribe(e,...t)}getState(){return this._storeProjection.getState()}initializeOffsitePayment(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.initializeOffsitePayment(e)),this._storeProjection.getState()})}loadCheckout(e){return al(this,void 0,void 0,function*(){return e?yield this._store.dispatch(this._checkoutActionCreator.loadCheckout(e)):yield this._store.dispatch(this._checkoutActionCreator.loadCurrentCheckout()),this._storeProjection.getState()})}loadDefaultCheckout(){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()),this._storeProjection.getState()})}loadPaymentMethod(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethod(e,t)),this._storeProjection.getState()})}loadPaymentMethods(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethods(e)),this._storeProjection.getState()})}submitOrder(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.submitOrder(e,t)),this._storeProjection.getState()})}submitPayment(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.submitPayment(e)),this._storeProjection.getState()})}finalizeOrder(e){return al(this,void 0,void 0,function*(){const{order:{getOrderOrThrow:t}}=this._store.getState();return yield this._store.dispatch(this._orderActionCreator.finalizeOrder(t().orderId,e)),this._storeProjection.getState()})}updateBillingAddress(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._billingAddressActionCreator.updateAddress(e)),this._storeProjection.getState()})}updateShippingAddress(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.updateAddress(e)),this._storeProjection.getState()})}selectShippingOption(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.selectShippingOption(e,t)),this._storeProjection.getState()})}signInCustomer(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signInCustomer(e,t)),this._storeProjection.getState()})}signOutCustomer(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signOutCustomer(e)),this._storeProjection.getState()})}createBuyNowCart(e,t){return al(this,void 0,void 0,function*(){const{body:i}=yield this._cartRequestSender.createBuyNowCart(e,t);return i})}applyStoreCredit(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._storeCreditActionCreator.applyStoreCredit(e,t)),this._storeProjection.getState()})}applyCoupon(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.applyCoupon(e,t)),this._storeProjection.getState()})}removeCoupon(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.removeCoupon(e,t)),this._storeProjection.getState()})}verifyCheckoutSpamProtection(){return al(this,void 0,void 0,function*(){const{checkout:e}=this._store.getState(),{shouldExecuteSpamCheck:t}=e.getCheckoutOrThrow();return t&&(yield this._store.dispatch(this._spamProtectionActionCreator.verifyCheckoutSpamProtection())),this._storeProjection.getState()})}loadCurrentOrder(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.loadCurrentOrder(e)),this._storeProjection.getState()})}updatePaymentProviderCustomer(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentProviderCustomerActionCreator.updatePaymentProviderCustomer(e)),this._storeProjection.getState()})}loadShippingCountries(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._shippingCountryActionCreator.loadCountries(e)),this._storeProjection.getState()})}deleteConsignment(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.deleteConsignment(e,t)),this._storeProjection.getState()})}initializePayment(e,t,i){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.initializePayment(e,t,i)),this._storeProjection.getState()})}forgetCheckout(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.forgetCheckout(e,t)),this._storeProjection.getState()})}remoteCheckoutSignOut(e,t){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.signOut(e,t)),this._storeProjection.getState()})}validateCheckout(e,t){return al(this,void 0,void 0,function*(){yield this._checkoutValidator.validate(e,t)})}handlePaymentHumanVerification(e,t){return al(this,void 0,void 0,function*(){return"string"==typeof e?this._paymentHumanVerificationHandler.handle(e,null!=t?t:""):this._paymentHumanVerificationHandler.handle(e)})}widgetInteraction(e){return al(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentStrategyWidgetActionCreator.widgetInteraction(e),{queueId:"widgetInteraction"}),this._storeProjection.getState()})}}!function(e){e.Synchronize="SYNCHRONIZE"}(rl||(rl={}));class dl{constructor(e){this._transformSelectors=e}create(e){return function(e,t){const i=a((e,t)=>t.type===rl.Synchronize?t.payload:e,e.getState(),{stateTransformer:t});return e.subscribe(e=>{i.dispatch(r(rl.Synchronize,e))},{initial:!1}),i}(e,this._transformSelectors)}}const cl=e=>{const t=B(e);return document.getElementById(t)?cl(e):t};function ul(e){return Object.prototype.hasOwnProperty.call(e,"cacheKey")}class ll{constructor(e){this._lastId=0,this._map={maps:[]},this._usedMaps=[],this._options=Object.assign({maxSize:0,isEqual:fe,onExpire:T},e)}getKey(...e){const t=this._resolveMap(...e),{index:i,parentMap:n}=t;let{map:o}=t;return o&&o.cacheKey?o.usedCount++:o=this._generateMap(n,e.slice(i)),this._removeLeastUsedMap(o),o.cacheKey}getUsedCount(...e){const{map:t}=this._resolveMap(...e);return t?t.usedCount:0}_resolveMap(...e){let t=0,i=this._map;for(;i.maps.length;){let n=!1;for(let o=0;o<i.maps.length;o++){const r=i.maps[o];if(this._options.isEqual(r.value,e[t])){if(i.maps.unshift(...i.maps.splice(o,1)),(0===e.length||t===e.length-1)&&ul(r))return{index:t,map:r,parentMap:i};n=!0,i=r,t++;break}}if(!n)break}return{index:t,parentMap:i}}_generateMap(e,t){let i,n=0,o=e;do{i={maps:[],parentMap:o,usedCount:1,value:t[n]},o.maps.unshift(i),o=i,n++}while(n<t.length);const r=i;return r.cacheKey=""+ ++this._lastId,r}_removeLeastUsedMap(e){if(!this._options.maxSize)return;const t=this._usedMaps.indexOf(e);if(this._usedMaps.splice(-1===t?0:t,-1===t?0:1,e),this._usedMaps.length<=this._options.maxSize)return;const i=this._usedMaps.pop();i&&(this._removeMap(i),this._options.onExpire(i.cacheKey))}_removeMap(e){e.parentMap&&(e.parentMap.maps.splice(e.parentMap.maps.indexOf(e),1),function(e){return Object.prototype.hasOwnProperty.call(e,"parentMap")}(e.parentMap)||this._removeMap(e.parentMap))}}function hl(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(i=>{const n=Object.getOwnPropertyDescriptor(e.prototype,i);n&&"constructor"!==i&&Object.defineProperty(t.prototype,i,function(e,t,i){if("function"!=typeof i.value)return i;let n=new ll,o=i.value,r=ae(o);return wa(e,t,{get(){const e=(...e)=>{const t=r.call(this,...e);if(1===n.getUsedCount(...e))return t;const i=o.call(this,...e);return xe(i,t,{keyFilter:e=>!function(e){return 0===`${e}`.indexOf("$$")||0===`${e}`.indexOf("_")}(e)})?t:(r.cache.set(n.getKey(...e),i),i)};return Object.defineProperty(this,t,Object.assign(Object.assign({},i),{value:e})),e},set(e){n=new ll,o=e,r=ae(o)}})}(e.prototype,i,n))}),t}let pl=class{constructor(e){this._checkoutButton=e.checkoutButton}getInitializeButtonError(e){return this._checkoutButton.getInitializeError(e)}getDeinitializeButtonError(e){return this._checkoutButton.getDeinitializeError(e)}};pl=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([hl],pl);const ml=pl;let gl=class{constructor(e){this._checkoutButton=e.checkoutButton}isInitializingButton(e){return this._checkoutButton.isInitializing(e)}isDeinitializingButton(e){return this._checkoutButton.isDeinitializing(e)}};gl=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([hl],gl);const yl=gl;function fl(e){return{errors:new ml(e),statuses:new yl(e)}}let vl=class{constructor(e,t){this._store=e,this._buttonStrategyActionCreator=t,this._state=fl(this._store.getState()),this._store.subscribe(e=>{this._state=fl(e)})}getState(){return this._state}subscribe(e,...t){return this._store.subscribe(()=>e(this.getState()),e=>e.checkoutButton.getState(),...t.map(e=>t=>e(fl(t))))}initializeButton(e){const t=(i=e.containerId,/^\w[\w\-\:\.]*$/.test(i)?[e.containerId]:function(e,t){const i=document.querySelectorAll(e);if(!i.length)throw new Nc(`Unable to find any element with the specified selector: ${e}`);return Array.prototype.slice.call(i).map(e=>(e.id||(e.id=cl(t)),e.id))}(e.containerId,`${e.methodId}-container`));var i;return Promise.all(t.map(t=>{const i=this._buttonStrategyActionCreator.initialize(Object.assign(Object.assign({},e),{containerId:t})),n=`checkoutButtonStrategy:${e.methodId}:${t}`;return this._store.dispatch(i,{queueId:n})})).then(()=>this.getState())}deinitializeButton(e){const t=this._buttonStrategyActionCreator.deinitialize(e),i=`checkoutButtonStrategy:${e.methodId}`;return this._store.dispatch(t,{queueId:i}).then(()=>this.getState())}};vl=function(e,t,i,n){var o,r=arguments.length,a=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(t,i,a):o(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}([wa],vl);const Sl=vl;class Cl{constructor(e,t,i){this._registry=e,this._registryV2=t,this._paymentMethodActionCreator=i}initialize(e){return t=>{const i={methodId:e.methodId,containerId:e.containerId};if(t.getState().checkoutButton.isInitialized(e.methodId,e.containerId))return Y();const n=e.currencyCode?{params:{currencyCode:e.currencyCode}}:{},o=Object.assign(Object.assign({},n),{timeout:e.timeout,useCache:!0});return H(Z(r(rt.InitializeButtonRequested,void 0,i)),this._paymentMethodActionCreator.loadPaymentMethod(e.methodId,o)(t),V(()=>this._getStrategy(e.methodId).initialize(e).then(()=>r(rt.InitializeButtonSucceeded,void 0,i)))).pipe(J(e=>rc(rt.InitializeButtonFailed,e,i)))}}deinitialize(e){return t=>{const i={methodId:e.methodId};return t.getState().checkoutButton.isInitialized(e.methodId)?H(Z(r(rt.DeinitializeButtonRequested,void 0,i)),V(()=>this._getStrategy(e.methodId).deinitialize().then(()=>r(rt.DeinitializeButtonSucceeded,void 0,i)))).pipe(J(e=>rc(rt.DeinitializeButtonFailed,e,i))):Y()}}_getStrategy(e){let t;try{t=this._registryV2.get({id:e})}catch(i){t=this._registry.get(e)}return t}}class Il{constructor(e){var t,i,n;this._factories={},this._instances={},this._defaultToken=null!==(t=null==e?void 0:e.defaultToken)&&void 0!==t?t:"default",this._useFallback=null===(i=null==e?void 0:e.useFallback)||void 0===i||i,this._tokenResolver=null!==(n=null==e?void 0:e.tokenResolver)&&void 0!==n?n:e=>e}get(e,t){try{return this._getInstance(e||this._defaultToken,t||e||this._defaultToken)}catch(e){if(!this._useFallback)throw e;return this._getInstance(this._defaultToken,t||this._defaultToken)}}getFactory(e,t){const i=this._tokenResolver(e,Object.keys(this._factories),t);return i?this._factories[i]:void 0}register(e,t){if(this._hasFactory(e))throw new Nc(`'${e}' is already registered.`);this._factories[e]=t}_hasFactory(e){return!!this._factories[e]}_hasInstance(e){return!!this._instances[e]}_getInstance(e,t){if(!this._hasInstance(t)){const i=this.getFactory(e);if(!i)throw new Nc(`'${e}' is not registered.`);this._instances[t]=i()}return this._instances[t]}}class _l extends be{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var wl,bl,El,Pl,Ol;class Al{constructor(e){this._scriptLoader=e,this._window=window}loadPaypal(e=""){return t=this,i=void 0,o=function*(){const t="//www.paypalobjects.com/api/checkout.min.js",i={async:!0,attributes:{"data-merchant-id":e}};if(e?yield this._scriptLoader.loadScript(t,i):yield this._scriptLoader.loadScript(t),!this._window.paypal)throw new _l;return this._window.paypal},new((n=void 0)||(n=Promise))(function(e,r){function a(e){try{d(o.next(e))}catch(e){r(e)}}function s(e){try{d(o.throw(e))}catch(e){r(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof n?i:new n(function(e){e(i)})).then(a,s)}d((o=o.apply(t,i||[])).next())});var t,i,n,o}}!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(wl||(wl={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(bl||(bl={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(El||(El={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Pl||(Pl={})),function(e){e.PILL="pill",e.RECT="rect"}(Ol||(Ol={}));class Tl{constructor(e,t,i,n,o=""){this._store=e,this._checkoutActionCreator=t,this._paypalScriptLoader=i,this._formPoster=n,this._host=o}initialize(e){const t=e.paypal,i=this._store.getState(),n=this._paymentMethod=i.paymentMethods.getPaymentMethod(e.methodId);if(!t)throw new Nc;if(!n)throw new qn(xn.MissingPaymentMethod);return this._paypalScriptLoader.loadPaypal(n.config.merchantId).then(i=>{var o,r;if(!n||!n.config.merchantId)throw new qn(xn.MissingPaymentMethod);const a=n.config.merchantId,s=n.config.testMode?"sandbox":"production",d={[s]:t.clientId},c=i.FUNDING.CREDIT||"credit",u=t.allowCredit?[c]:[],l=t.allowCredit?[]:[c];return i.Button.render({env:s,client:d,commit:t.shouldProcessPayment,funding:{allowed:u,disallowed:l},style:Object.assign(Object.assign({shape:Ol.RECT},D(t.style,"layout","color","label","shape","tagline","fundingicons")),{size:"paypalexpress"===n.id&&"small"===(null===(o=t.style)||void 0===o?void 0:o.size)?bl.RESPONSIVE:null===(r=t.style)||void 0===r?void 0:r.size}),payment:(e,i)=>this._setupPayment(a,i,t.onPaymentError),onAuthorize:(e,i)=>this._tokenizePayment(e,i,t.shouldProcessPayment,t.onAuthorizeError)},e.containerId)})}deinitialize(){return this._paymentMethod=void 0,Promise.resolve()}_setupPayment(e,t,i){if(!t)throw new Wc(jc.CheckoutButtonNotInitialized);return this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()).then(i=>{const n=i.cart.getCart(),o=n?n.id:"";return t.request.post(`${this._host}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:o},{headers:Object.assign({"X-API-INTERNAL":ic},nc)})}).then(e=>e.id).catch(e=>{throw i&&i(e),e})}_tokenizePayment(e,t,i,n){if(!this._paymentMethod)throw new Wc(jc.CheckoutButtonNotInitialized);if(!t)throw new Wc(jc.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new qn(xn.MissingPayment);const o=this._paymentMethod.id;return t.payment.get(e.paymentID).then(t=>{this._formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:o,action:i?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(t.payer.payer_info)})})}}function kl(e){return e&&"resolveIds"in e}function Rl(){try{return"production"}catch(e){return"development"}}class Dl{constructor(e){this._console=e}log(...e){this._logToConsole("log",...e)}info(...e){this._logToConsole("info",...e)}warn(...e){this._logToConsole("warn",...e)}error(...e){this._logToConsole("error",...e)}debug(...e){this._logToConsole("debug",...e)}_logToConsole(e,...t){this._console&&this._console[e]&&this._console[e].call(this._console,...t)}}class Ml{log(){}info(){}warn(){}error(){}debug(){}}const Nl=function(e=!0){return e?new Dl(console):new Ml}("test"!==Rl());class Ll{constructor(e=!1){this._useFallback=e,this._registry=new Il({tokenResolver:this._resolveToken.bind(this),defaultToken:this._encodeToken({default:!0}),useFallback:this._useFallback})}get(e){return this._registry.get(this._encodeToken(e))}getFactory(e,t){try{return this._registry.getFactory(this._encodeToken(e),t)}catch(e){return}}getUseFallback(){return this._useFallback}register(e,t){this._registry.register(this._encodeToken(e),t)}_encodeToken(e){return btoa(JSON.stringify(e))}_decodeToken(e){return JSON.parse(atob(e))}_resolveToken(e,t,i){var n;const o=this._decodeToken(e),r=[];t.forEach(e=>{const t=this._decodeToken(e),i={token:e,matches:0,default:!1};for(const[e,n]of Object.entries(t)){if(e in o&&o[e]!==n){i.matches=0;break}e in o&&o[e]===n&&i.matches++,"default"===e&&!0===n&&(i.default=!0)}r.push(i)});const a=r.sort((e,t)=>t.matches-e.matches).filter(e=>e.matches>0);a.length>1&&a[0].matches===a[1].matches&&"development"===Rl()&&Nl.warn("The provided query matches at least two strategies with the same specificity. This warning can be resolved by making their resolve ID more specific.");const s=a[0];if(i&&(null==s?void 0:s.matches)!==Object.keys(o).length)throw new Error("Unable to resolve to a registered token with the provided token.");if(s&&s.token)return s.token;if(this._useFallback){const e=null===(n=r.find(e=>e.default))||void 0===n?void 0:n.token;if(e)return e}throw new Error("Unable to resolve to a registered token with the provided token.")}}function zl(t){const{host:n}=null!=t?t:{},o=Zn({config:{meta:{host:null==t?void 0:t.host,locale:null==t?void 0:t.locale},errors:{},statuses:{}}}),r=e({host:n}),a=i({host:n}),s=function(e,t){const i=new Ll;for(const[,n]of Object.entries(t))if(kl(n))for(const t of n.resolveIds)i.register(t,()=>n(e));return i}(function(t){const{config:{getHost:i,getLocale:n}}=t.getState(),o=e({host:i()}),r=new dl(ol),a=new hc(new fc(o),new _c(new wc(o)),new Tc(new kc(o))),s=new Cc(new fc(o)),d=new du(t),c=new uu(new gu(o),new Cc(new fc(o))),u=new sc(new uc(o),new Xu(new el(o))),l=new ju(new Hu(o),new fc(o)),h=new Xd(new oc(o)),p=new yu(new fu(function(e){const t=me();return e.subscribe(e=>{const i=e.config.getStoreConfig();i&&t.setHost(i.paymentSettings.bigpayBaseUrl)},e=>e.config.getStoreConfig()),t}(t)),c,new Uu,new Yc(Jc(ue()))),m=new Yc(Jc(ue())),g=new Oc(new Ac(o),a,new $u(Jc(ue()),new Ku(o))),y=new Zu(new Qu(o)),f=new bc(new Ec(o)),v=Jc(ue()),S=new Ku(o),C=new $u(v,S),I=new lc(o),_=new Fu,w=new Vu(new Yu(o,{locale:n()}),t),b=new xu(new qu(o),a),E=new Bu;return new sl(t,r,a,s,d,c,u,l,h,p,m,g,I,y,f,C,_,w,b,E)}(o),Se);return new Sl(o,new Cl(function(e,t,i,n){const o=new Il,r=le(),a=new fc(t),s=new hc(a,new _c(new wc(t)),new Tc(new kc(t)));return o.register(Pu.PAYPALEXPRESS,()=>new Tl(e,s,new Al(r),i,n)),o}(o,r,a,n),s,new Xd(new oc(r))))}export{zl as createCheckoutButtonInitializer,t as createTimeout};
2
2
  //# sourceMappingURL=checkout-button.js.map