@bigcommerce/checkout-sdk 1.817.0 → 1.818.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 n}from"@bigcommerce/form-poster";import{combineReducers as i,composeReducers as r,createAction as o,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 D,pick as R,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 Q,throwError as Z}from"rxjs";import{catchError as J,delay as X,filter as ee,map as te,retryWhen as ne,shareReplay as ie,switchMap as re,take as oe}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 n in t)ve.o(t,n)&&!ve.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},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:()=>Pr,createApplePayButtonStrategy:()=>ro,createBigCommercePaymentsAlternativeMethodsButtonStrategy:()=>Ro,createBigCommercePaymentsButtonStrategy:()=>wo,createBigCommercePaymentsPayLaterButtonStrategy:()=>To,createBigCommercePaymentsVenmoButtonStrategy:()=>Lo,createBoltButtonStrategy:()=>Go,createBraintreePaypalButtonStrategy:()=>sa,createBraintreePaypalCreditButtonStrategy:()=>la,createBraintreeVenmoButtonStrategy:()=>Ca,createBraintreeVisaCheckoutButtonStrategy:()=>ma,createGooglePayAdyenV2ButtonStrategy:()=>rs,createGooglePayAdyenV3ButtonStrategy:()=>os,createGooglePayAuthorizeDotNetButtonStrategy:()=>ss,createGooglePayBigCommercePaymentsButtonStrategy:()=>is,createGooglePayBraintreeButtonStrategy:()=>$a,createGooglePayCheckoutComButtonStrategy:()=>hs,createGooglePayCybersourceButtonStrategy:()=>ms,createGooglePayOrbitalButtonStrategy:()=>ys,createGooglePayPayPalCommerceButtonStrategy:()=>es,createGooglePayStripeButtonStrategy:()=>_s,createGooglePayTdOnlineMartButtonStrategy:()=>As,createGooglePayWorldpayAccessButtonStrategy:()=>bs,createPayPalCommerceAlternativeMethodsButtonStrategy:()=>td,createPayPalCommerceButtonStrategy:()=>Vs,createPayPalCommerceCreditButtonStrategy:()=>Ks,createPayPalCommerceVenmoButtonStrategy:()=>Js,createPaypalExpressButtonStrategy:()=>ld});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:n}={}){const{body:i,headers:r,status:o}=e||Ie;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}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:n}={}){const{body:i,headers:r,status:o}=e||Ee;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}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:n}=e,{errors:i=[]}=n;return new Pe(e,{message:ke(i)||t,errors:i})}function ke(e){if(Array.isArray(e))return e.reduce((e,t)=>t&&t.message?[...e,t.message]:e,[]).join(" ")}class De extends Pe{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}class Re{constructor(){this._factoryMethods={},this.register("default",(e,t)=>new Pe(e,{message:t})),this.register("internal",(e,t)=>function(e,t){const{body:n}=e,{errors:i=[]}=n;return new Pe(e,{message:Ae(i)||n.detail||n.title||t,errors:i.length?i.map(e=>({code:n.type,message:e})):[{code:n.type,message:n.detail||n.title}]})}(e,t)),this.register("storefront",(e,t)=>function(e,t){const{body:n}=e;return new Pe(e,{message:t||n.detail||n.title,errors:[{code:n.code||n.type,message:n.detail||n.title}]})}(e,t)),this.register("payment",(e,t)=>Te(e,t)),this.register("timeout",e=>new De(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(D(e,t),(e,n,i)=>{e[i]=Fe(n,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,n){return e===t||(e&&t&&"object"==typeof e&&"object"==typeof t?Array.isArray(e)&&Array.isArray(t)?function(e,t,n){if(e.length!==t.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!xe(e[i],t[i],n))return!1;return!0}(e,t,n):!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,n){const i=n&&n.keyFilter,r=i?Object.keys(e).filter(i):Object.keys(e),o=i?Object.keys(t).filter(i):Object.keys(t);if(r.length!==o.length)return!1;for(let i=0,o=r.length;i<o;i++){const o=r[i];if(!Object.prototype.hasOwnProperty.call(t,o))return!1;if(!xe(e[o],t[o],n))return!1}return!0}(e,t,n))):e===t)}function qe(e,t){return void 0===t||xe(e,t)?e:t}function je(e,t,n){return e&&Object.prototype.hasOwnProperty.call(e,t)&&xe(e[t],n)?e:Object.assign(Object.assign({},e),{[t]:n})}!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 i({data:Ve,errors:r(Ye,Be),statuses:We})(e,t)}function Ve(e,t){var n,i;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===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.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,n,i){const{matchObject:r=(e,t)=>void 0!==e.id&&e.id===t.id}=i||{};if(!t)return n;if(!n||t===n)return t;let o=0,a=0;const s=(e,t,n)=>(o+=e===t?1:0,a+=e===n?1:0,e),d=n.map((n,i)=>{const o=t&&t[i];return $e(o)&&$e(n)?r(o,n)?s(Qe(o,n),o,n):s(qe(o,n),o,n):y(o)&&y(n)?s(e(o,n),o,n):s(qe(o,n),o,n)});return o===n.length&&t&&t.length===n.length?t:a===n.length?n:d},Qe=function e(t,n){return t?n&&t!==n?Object.keys(n).reduce((t,i)=>{const r=t[i],o=n[i];return $e(r)&&$e(o)?je(t,i,e(r,o)):y(r)&&y(o)?je(t,i,Ke(r,o)):je(t,i,o)},t):t:n};var Ze,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"}(Ze||(Ze={})),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 i({data:nt,errors:r(rt,Be),statuses:it})(e,t)}function nt(e,t){var n,i;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 Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Qe(e,t.payload&&t.payload.cart);case Ne.HydrateInitialState:return Qe(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.cart);default:return e}}function it(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 rt(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 ot;!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"}(ot||(ot={}));const at={data:{},errors:{},statuses:{}},st={initializedContainers:{}},dt={},ct={};function ut(e=at,t){return t.meta&&t.meta.methodId?i({data:i({[t.meta.methodId]:lt}),errors:i({[t.meta.methodId]:ht}),statuses:i({[t.meta.methodId]:pt})})(e,t):e}function lt(e=st,t){switch(t.type){case ot.InitializeButtonSucceeded:return t.meta&&t.meta.containerId?Qe(e,{initializedContainers:{[t.meta.containerId]:!0}}):e;case ot.DeinitializeButtonSucceeded:return je(e,"initializedContainers",{})}return e}function ht(e=dt,t){switch(t.type){case ot.InitializeButtonRequested:case ot.InitializeButtonSucceeded:return je(e,"initializeError",void 0);case ot.InitializeButtonFailed:return je(e,"initializeError",t.payload);case ot.DeinitializeButtonRequested:case ot.DeinitializeButtonSucceeded:return je(e,"deinitializeError",void 0);case ot.DeinitializeButtonFailed:return je(e,"deinitializeError",t.payload);default:return e}}function pt(e=ct,t){switch(t.type){case ot.InitializeButtonRequested:return je(e,"isInitializing",!0);case ot.InitializeButtonFailed:case ot.InitializeButtonSucceeded:return je(e,"isInitializing",!1);case ot.DeinitializeButtonRequested:return je(e,"isDeinitializing",!0);case ot.DeinitializeButtonFailed:case ot.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 i({data:ft,errors:r(vt,Be),statuses:St})(e,t)}function ft(e,t){var n;switch(t.type){case mt.LoadConfigSucceeded:return Qe(e,t.payload);case Ne.HydrateInitialState:return Qe(e,null===(n=t.payload)||void 0===n?void 0:n.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 i({data:wt,errors:r(bt,Be),statuses:Et})(e,t)}function wt(e,t){var n,i;switch(t.type){case Me.LoadCheckoutSucceeded:case Ze.ApplyCouponSucceeded:case Xe.UpdateShippingOptionSucceeded:case Ze.RemoveCouponSucceeded:case Ct.LoadOrderSucceeded:return Ke(e,t.payload&&t.payload.coupons);case Ne.HydrateInitialState:return Ke(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.coupons);default:return e}}function bt(e={},t){switch(t.type){case Ze.ApplyCouponRequested:case Ze.ApplyCouponSucceeded:return je(e,"applyCouponError",void 0);case Ze.ApplyCouponFailed:return je(e,"applyCouponError",t.payload);case Ze.RemoveCouponRequested:case Ze.RemoveCouponSucceeded:return je(e,"removeCouponError",void 0);case Ze.RemoveCouponFailed:return je(e,"removeCouponError",t.payload);default:return e}}function Et(e={},t){switch(t.type){case Ze.ApplyCouponRequested:return je(e,"isApplyingCoupon",!0);case Ze.ApplyCouponSucceeded:case Ze.ApplyCouponFailed:return je(e,"isApplyingCoupon",!1);case Ze.RemoveCouponRequested:return je(e,"isRemovingCoupon",!0);case Ze.RemoveCouponSucceeded:case Ze.RemoveCouponFailed:return je(e,"isRemovingCoupon",!1);default:return e}}const Pt={errors:{},statuses:{}};function Ot(e=Pt,t){return i({data:At,errors:r(Tt,Be),statuses:kt})(e,t)}function At(e,t){var n,i;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Ke(e,t.payload&&t.payload.giftCertificates);case Ne.HydrateInitialState:return Ke(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.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 Dt;!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"}(Dt||(Dt={}));const Rt={errors:{},statuses:{}};function Mt(e=Rt,t){return i({data:Nt,errors:r(Lt,Be),statuses:zt})(e,t)}function Nt(e,t){var n,i;switch(t.type){case Ue.ContinueAsGuestSucceeded:case Me.LoadCheckoutSucceeded:return Qe(e,t.payload&&t.payload.customer);case Dt.CreateCustomerAddressSucceeded:return Qe(e,t.payload);case Ne.HydrateInitialState:return Qe(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.customer);default:return e}}function Lt(e=Rt.errors,t){switch(t.type){case Dt.CreateCustomerRequested:case Dt.CreateCustomerSucceeded:return je(e,"createError",void 0);case Dt.CreateCustomerFailed:return je(e,"createError",t.payload);case Dt.CreateCustomerAddressRequested:case Dt.CreateCustomerAddressSucceeded:return je(e,"createAddressError",void 0);case Dt.CreateCustomerAddressFailed:return je(e,"createAddressError",t.payload);default:return e}}function zt(e=Rt.statuses,t){switch(t.type){case Dt.CreateCustomerRequested:return je(e,"isCreating",!0);case Dt.CreateCustomerFailed:case Dt.CreateCustomerSucceeded:return je(e,"isCreating",!1);case Dt.CreateCustomerAddressRequested:return je(e,"isCreatingAddress",!0);case Dt.CreateCustomerAddressFailed:case Dt.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 i({data:xt,errors:r(qt,Be),statuses:jt})(e,t)}function xt(e=Ft.data,t){switch(t.type){case Ut.InitializeSucceeded:return Qe(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case Ut.DeinitializeSucceeded:return Qe(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 Qe(e,{initializeErrors:Object.assign({},e.initializeErrors),initializeMethodId:e.initializeMethodId?e.initializeMethodId:void 0});case Ut.InitializeFailed:return Qe(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 Qe(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case Ut.DeinitializeFailed:return Qe(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.SignInRequested:case Ut.SignInSucceeded:return Qe(e,{signInError:void 0,signInMethodId:void 0});case Ut.SignInFailed:return Qe(e,{signInError:t.payload,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignOutRequested:case Ut.SignOutSucceeded:return Qe(e,{signOutError:void 0,signOutMethodId:void 0});case Ut.SignOutFailed:return Qe(e,{signOutError:t.payload,signOutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutRequested:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Qe(e,{executePaymentMethodCheckoutError:void 0,executePaymentMethodCheckoutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutFailed:return Qe(e,{executePaymentMethodCheckoutError:t.payload,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.WidgetInteractionStarted:case Ut.WidgetInteractionFinished:return Qe(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case Ut.WidgetInteractionFailed:return Qe(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function jt(e=Ft.statuses,t){switch(t.type){case Ut.InitializeRequested:return Qe(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case Ut.InitializeFailed:case Ut.InitializeSucceeded:return Qe(e,{isInitializing:!1,initializeMethodId:void 0});case Ut.DeinitializeRequested:return Qe(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.DeinitializeFailed:case Ut.DeinitializeSucceeded:return Qe(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case Ut.SignInRequested:return Qe(e,{isSigningIn:!0,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignInFailed:case Ut.SignInSucceeded:return Qe(e,{isSigningIn:!1,signInMethodId:void 0});case Ut.SignOutRequested:return Qe(e,{isSigningOut:!0,signOutMethodId:t.meta&&t.meta.methodId});case Ut.SignOutFailed:case Ut.SignOutSucceeded:return Qe(e,{isSigningOut:!1,signOutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutRequested:return Qe(e,{isExecutingPaymentMethodCheckout:!0,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutFailed:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Qe(e,{isExecutingPaymentMethodCheckout:!1,executePaymentMethodCheckoutMethodId:void 0});case Ut.WidgetInteractionStarted:return Qe(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case Ut.WidgetInteractionFinished:case Ut.WidgetInteractionFailed:return Qe(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 i({data:Yt,errors:r(Wt,Be),statuses:$t})(e,t)}function Yt(e,t){var n;return t.type===Gt.LoadExtensionsSucceeded?Ke(e,t.payload):t.type===Ne.HydrateInitialState?Ke(e,null===(n=t.payload)||void 0===n?void 0:n.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 Qt={errors:{},statuses:{}};function Zt(e=Qt,t){return i({data:Jt,errors:r(Xt,Be),statuses:en})(e,t)}function Jt(e,t){var n;switch(t.type){case Kt.LoadFormFieldsSucceeded:return Qe(e,t.payload);case Ne.HydrateInitialState:return Qe(e,null===(n=t.payload)||void 0===n?void 0:n.formFields);default:return e}}function Xt(e=Qt.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 en(e=Qt.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 tn;!function(e){e.LoadCountriesRequested="LOAD_COUNTRIES_REQUESTED",e.LoadCountriesSucceeded="LOAD_COUNTRIES_SUCCEEDED",e.LoadCountriesFailed="LOAD_COUNTRIES_FAILED"}(tn||(tn={}));const nn={errors:{},statuses:{}};function rn(e=nn,t){return i({data:on,errors:r(an,Be),statuses:sn})(e,t)}function on(e,t){return t.type===tn.LoadCountriesSucceeded?Ke(e,t.payload):e}function an(e=nn.errors,t){switch(t.type){case tn.LoadCountriesRequested:case tn.LoadCountriesSucceeded:return je(e,"loadError",void 0);case tn.LoadCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function sn(e=nn.statuses,t){switch(t.type){case tn.LoadCountriesRequested:return je(e,"isLoading",!0);case tn.LoadCountriesSucceeded:case tn.LoadCountriesFailed:return je(e,"isLoading",!1);default:return e}}const dn={errors:{},meta:{},statuses:{}};function cn(e=dn,t){return i({data:un,errors:r(hn,Be),meta:ln,statuses:pn})(e,t)}function un(e,t){switch(t.type){case Ct.LoadOrderSucceeded:case Ct.LoadOrderPaymentsSucceeded:return Qe(e,k(t.payload,["billingAddress","coupons"]));default:return e}}function ln(e,t){switch(t.type){case Ct.FinalizeOrderSucceeded:case Ct.SubmitOrderSucceeded:return Qe(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 hn(e=dn.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 pn(e=dn.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 mn={};function gn(e=mn,t){return i({data:yn})(e,t)}function yn(e,t){switch(t.type){case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderSucceeded:return qe(e,t.payload&&t.payload.billingAddress);default:return e}}var fn,vn;function Sn(e={},t){return i({data:Cn})(e,t)}function Cn(e,t){return t.type===fn.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"}(fn||(fn={})),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"}(vn||(vn={}));const In={errors:{},statuses:{}};function _n(e=In,t){return i({data:wn,errors:r(En,Be),meta:bn,statuses:Pn})(e,t)}function wn(e,t){switch(t.type){case vn.LoadPaymentMethodSucceeded:return function(e,t,n){if(!t)return e;const i=R(t,"id"),r="object"==typeof n?M(n):n||i,o=h(e,r),a=[...e];if(-1===o)a.push(t);else{const n=e[o];a[o]=$e(n)&&$e(t)?Qe(n,t):t}return a}(e||[],t.payload,t.payload&&{id:t.payload.id,gateway:t.payload.gateway});case vn.LoadPaymentMethodsSucceeded:return Ke(e,t.payload,{matchObject:(e,t)=>e.id===t.id&&e.gateway===t.gateway});default:return e}}function bn(e,t){return t.type===vn.LoadPaymentMethodsSucceeded?Qe(e,t.meta):e}function En(e=In.errors,t){switch(t.type){case vn.LoadPaymentMethodsRequested:case vn.LoadPaymentMethodsSucceeded:return je(e,"loadError",void 0);case vn.LoadPaymentMethodsFailed:return je(e,"loadError",t.payload);case vn.LoadPaymentMethodRequested:case vn.LoadPaymentMethodSucceeded:return Qe(e,{loadMethodId:void 0,loadMethodError:void 0});case vn.LoadPaymentMethodFailed:return Qe(e,{loadMethodId:t.meta.methodId,loadMethodError:t.payload});default:return e}}function Pn(e=In.statuses,t){switch(t.type){case vn.LoadPaymentMethodsRequested:return je(e,"isLoading",!0);case vn.LoadPaymentMethodsSucceeded:case vn.LoadPaymentMethodsFailed:return je(e,"isLoading",!1);case vn.LoadPaymentMethodRequested:return Qe(e,{isLoadingMethod:!0,loadMethodId:t.meta.methodId});case vn.LoadPaymentMethodSucceeded:case vn.LoadPaymentMethodFailed:return Qe(e,{isLoadingMethod:!1,loadMethodId:void 0});default:return e}}var On;!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"}(On||(On={}));const An={data:{},errors:{},statuses:{}};function Tn(e=An,t){return i({data:kn,errors:r(Dn,Be),statuses:Rn})(e,t)}function kn(e=An.data,t){switch(t.type){case On.InitializeSucceeded:if(t.meta){const{methodId:n,gatewayId:i}=t.meta,r=i?`${n}.${i}`:n;return Qe(e,{[r]:{isInitialized:!0}})}break;case On.DeinitializeSucceeded:if(t.meta){const{methodId:n,gatewayId:i}=t.meta,r=i?`${n}.${i}`:n;return Qe(e,{[r]:{isInitialized:!1}})}}return e}function Dn(e=An.errors,t){switch(t.type){case On.InitializeRequested:case On.InitializeSucceeded:return Qe(e,{initializeError:void 0,initializeMethodId:void 0});case On.InitializeFailed:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{initializeError:t.payload,initializeMethodId:n})}case On.DeinitializeRequested:case On.DeinitializeSucceeded:return Qe(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case On.DeinitializeFailed:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{deinitializeError:t.payload,deinitializeMethodId:n})}case On.ExecuteRequested:case On.ExecuteSucceeded:return Qe(e,{executeError:void 0,executeMethodId:void 0});case On.ExecuteFailed:return Qe(e,{executeError:t.payload,executeMethodId:t.meta&&t.meta.methodId});case On.FinalizeRequested:case On.FinalizeSucceeded:return Qe(e,{finalizeError:void 0,finalizeMethodId:void 0});case On.FinalizeFailed:return Qe(e,{finalizeError:t.payload,finalizeMethodId:t.meta&&t.meta.methodId});case On.WidgetInteractionStarted:case On.WidgetInteractionFinished:return Qe(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case On.WidgetInteractionFailed:return Qe(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function Rn(e=An.statuses,t){switch(t.type){case On.InitializeRequested:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{isInitializing:!0,initializeMethodId:n})}case On.InitializeFailed:case On.InitializeSucceeded:return Qe(e,{isInitializing:!1,initializeMethodId:void 0});case On.DeinitializeRequested:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{isDeinitializing:!0,deinitializeMethodId:n})}case On.DeinitializeFailed:case On.DeinitializeSucceeded:return Qe(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case On.ExecuteRequested:return Qe(e,{isExecuting:!0,executeMethodId:t.meta&&t.meta.methodId});case On.ExecuteFailed:case On.ExecuteSucceeded:return Qe(e,{isExecuting:!1,executeMethodId:void 0});case On.FinalizeRequested:return Qe(e,{isFinalizing:!0,finalizeMethodId:t.meta&&t.meta.methodId});case On.FinalizeFailed:case On.FinalizeSucceeded:return Qe(e,{isFinalizing:!1,finalizeMethodId:void 0});case On.WidgetInteractionStarted:return Qe(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case On.WidgetInteractionFinished:case On.WidgetInteractionFailed:return Qe(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Mn;!function(e){e.UpdatePaymentProviderCustomer="UPDATE_PAYMENT_PROVIDER_CUSTOMER"}(Mn||(Mn={}));const Nn={data:{}};function Ln(e=Nn,t){return i({data:zn})(e,t)}function zn(e=Nn.data,t){return t.type===Mn.UpdatePaymentProviderCustomer?Qe(e,t.payload):e}var Un;!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"}(Un||(Un={}));const Fn={data:[],errors:{},statuses:{}};function Bn(e=Fn,t){return i({data:xn,errors:r(jn,Be),meta:qn,statuses:Gn})(e,t)}function xn(e=Fn.data,t){return t.type===Un.LoadInstrumentsSucceeded?Ke(e,t.payload&&t.payload.vaultedInstruments||[]):e}function qn(e,t){switch(t.type){case Un.LoadInstrumentsSucceeded:case Un.DeleteInstrumentSucceeded:return Qe(e,t.meta);default:return e}}function jn(e=Fn.errors,t){switch(t.type){case Un.LoadInstrumentsRequested:case Un.LoadInstrumentsSucceeded:return je(e,"loadError",void 0);case Un.DeleteInstrumentRequested:case Un.DeleteInstrumentSucceeded:return Qe(e,{deleteError:void 0,failedInstrument:void 0});case Un.LoadInstrumentsFailed:return je(e,"loadError",t.payload);case Un.DeleteInstrumentFailed:return Qe(e,{deleteError:t.payload,failedInstrument:t.meta.instrumentId});default:return e}}function Gn(e=Fn.statuses,t){switch(t.type){case Un.LoadInstrumentsRequested:return je(e,"isLoading",!0);case Un.DeleteInstrumentRequested:return Qe(e,{isDeleting:!0,deletingInstrument:t.meta.instrumentId});case Un.LoadInstrumentsSucceeded:case Un.LoadInstrumentsFailed:return je(e,"isLoading",!1);case Un.DeleteInstrumentSucceeded:case Un.DeleteInstrumentFailed:return Qe(e,{isDeleting:!1,deletingInstrument:void 0});default:return e}}var Hn;!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"}(Hn||(Hn={}));const Vn={data:{}};function Yn(e=Vn,t){return t.meta&&t.meta.methodId?i({data:i({[t.meta.methodId]:Wn})})(e,t):e}function Wn(e,t){switch(t.type){case Hn.InitializeRemoteBillingSucceeded:return je(e,"billing",t.payload&&t.payload.billing);case Hn.InitializeRemoteShippingSucceeded:return je(e,"shipping",t.payload&&t.payload.shipping);case Hn.LoadRemoteSettingsSucceeded:return je(e,"settings",t.payload);case Hn.UpdateRemoteCheckout:return Qe(e,t.payload);default:return e}}const $n={errors:{updateShippingOptionError:{},updateError:{},deleteError:{}},statuses:{isUpdating:{},isUpdatingShippingOption:{},isDeleting:{}}};function Kn(e=$n,t){return i({data:Qn,errors:r(Zn,Be),statuses:Jn})(e,t)}function Qn(e,t){var n,i;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.LoadShippingOptionsSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:return Ke(e,t.payload&&t.payload.consignments);case Dt.SignOutCustomerSucceeded:return Ke(e,[]);case Ne.HydrateInitialState:return Ke(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.consignments);default:return e}}function Zn(e=$n.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?Qe(e,{updateError:{[t.meta.id]:void 0}}):e;case Xe.UpdateConsignmentFailed:return t.meta?Qe(e,{updateError:{[t.meta.id]:t.payload}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentRequested:return t.meta?Qe(e,{deleteError:{[t.meta.id]:void 0}}):e;case Xe.DeleteConsignmentFailed:return t.meta?Qe(e,{deleteError:{[t.meta.id]:t.payload}}):e;case Xe.UpdateShippingOptionRequested:case Xe.UpdateShippingOptionSucceeded:return t.meta?Qe(e,{updateShippingOptionError:{[t.meta.id]:void 0}}):e;case Xe.UpdateShippingOptionFailed:return t.meta?Qe(e,{updateShippingOptionError:{[t.meta.id]:t.payload}}):e;default:return e}}function Jn(e=$n.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?Qe(e,{isUpdating:{[t.meta.id]:!0}}):e;case Xe.UpdateConsignmentSucceeded:case Xe.UpdateConsignmentFailed:return t.meta?Qe(e,{isUpdating:{[t.meta.id]:!1}}):e;case Xe.DeleteConsignmentRequested:return t.meta?Qe(e,{isDeleting:{[t.meta.id]:!0}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentFailed:return t.meta?Qe(e,{isDeleting:{[t.meta.id]:!1}}):e;case Xe.UpdateShippingOptionRequested:return t.meta?Qe(e,{isUpdatingShippingOption:{[t.meta.id]:!0}}):e;case Xe.UpdateShippingOptionSucceeded:case Xe.UpdateShippingOptionFailed:return t.meta?Qe(e,{isUpdatingShippingOption:{[t.meta.id]:!1}}):e;default:return e}}function Xn(e,t){const n={};return Object.keys(e).forEach(i=>{const r=e[i],o=t?`${t}.${i}`:i;"object"==typeof r?Object.assign(n,Xn(r,o)):n[o]=r}),n}function ei(e){return Object.keys(e).sort().reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e[n]}),{})}var ti;!function(e){e.LoadPickupOptionsRequested="LOAD_PICKUP_OPTIONS_REQUESTED",e.LoadPickupOptionsSucceeded="LOAD_PICKUP_OPTIONS_SUCCEEDED",e.LoadPickupOptionsFailed="LOAD_PICKUP_OPTIONS_FAILED"}(ti||(ti={}));const ni={errors:{},statuses:{}};function ii(e=ni,t){return i({data:ri,errors:r(oi,Be),statuses:ai})(e,t)}function ri(e,t){if(t.type!==ti.LoadPickupOptionsSucceeded)return e;if(t.meta){const n=ei(Xn({consignmentId:t.meta.consignmentId,searchArea:t.meta.searchArea}));return je(e,btoa(`${JSON.stringify(n)}`),t.payload)}}function oi(e=ni.errors,t){switch(t.type){case ti.LoadPickupOptionsRequested:case ti.LoadPickupOptionsSucceeded:return je(e,"loadError",void 0);case ti.LoadPickupOptionsFailed:return je(e,"loadError",t.payload);default:return e}}function ai(e=ni.statuses,t){switch(t.type){case ti.LoadPickupOptionsRequested:return je(e,"isLoading",!0);case ti.LoadPickupOptionsSucceeded:case ti.LoadPickupOptionsFailed:return je(e,"isLoading",!1);default:return e}}var si;!function(e){e.LoadShippingCountriesRequested="LOAD_SHIPPING_COUNTRIES_REQUESTED",e.LoadShippingCountriesSucceeded="LOAD_SHIPPING_COUNTRIES_SUCCEEDED",e.LoadShippingCountriesFailed="LOAD_SHIPPING_COUNTRIES_FAILED"}(si||(si={}));const di={errors:{},statuses:{}};function ci(e=di,t){return i({data:ui,errors:r(li,Be),statuses:hi})(e,t)}function ui(e,t){return t.type===si.LoadShippingCountriesSucceeded?Ke(e,t.payload):e}function li(e=di.errors,t){switch(t.type){case si.LoadShippingCountriesRequested:case si.LoadShippingCountriesSucceeded:return je(e,"loadError",void 0);case si.LoadShippingCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function hi(e=di.statuses,t){switch(t.type){case si.LoadShippingCountriesRequested:return je(e,"isLoading",!0);case si.LoadShippingCountriesSucceeded:case si.LoadShippingCountriesFailed:return je(e,"isLoading",!1);default:return e}}var pi;!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"}(pi||(pi={}));const mi={data:{},errors:{},statuses:{}};function gi(e=mi,t){return i({data:yi,errors:r(fi,Be),statuses:vi})(e,t)}function yi(e=mi.data,t){switch(t.type){case pi.InitializeSucceeded:return Qe(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case pi.DeinitializeSucceeded:return Qe(e,{[t.meta&&t.meta.methodId]:{isInitialized:!1}})}return e}function fi(e=mi.errors,t){switch(t.type){case pi.InitializeRequested:case pi.InitializeSucceeded:return Qe(e,{initializeError:void 0,initializeMethodId:void 0});case pi.InitializeFailed:return Qe(e,{initializeError:t.payload,initializeMethodId:t.meta&&t.meta.methodId});case pi.DeinitializeRequested:case pi.DeinitializeSucceeded:return Qe(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case pi.DeinitializeFailed:return Qe(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case pi.UpdateAddressRequested:case pi.UpdateAddressSucceeded:return Qe(e,{updateAddressError:void 0,updateAddressMethodId:void 0});case pi.UpdateAddressFailed:return Qe(e,{updateAddressError:t.payload,updateAddressMethodId:t.meta&&t.meta.methodId});case pi.SelectOptionRequested:case pi.SelectOptionSucceeded:return Qe(e,{selectOptionError:void 0,selectOptionMethodId:void 0});case pi.SelectOptionFailed:return Qe(e,{selectOptionError:t.payload,selectOptionMethodId:t.meta&&t.meta.methodId});case pi.WidgetInteractionStarted:case pi.WidgetInteractionFinished:return Qe(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case pi.WidgetInteractionFailed:return Qe(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta&&t.meta.methodId});default:return e}}function vi(e=mi.statuses,t){switch(t.type){case pi.InitializeRequested:return Qe(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case pi.InitializeFailed:case pi.InitializeSucceeded:return Qe(e,{isInitializing:!1,initializeMethodId:void 0});case pi.DeinitializeRequested:return Qe(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case pi.DeinitializeFailed:case pi.DeinitializeSucceeded:return Qe(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case pi.UpdateAddressRequested:return Qe(e,{isUpdatingAddress:!0,updateAddressMethodId:t.meta&&t.meta.methodId});case pi.UpdateAddressFailed:case pi.UpdateAddressSucceeded:return Qe(e,{isUpdatingAddress:!1,updateAddressMethodId:void 0});case pi.SelectOptionRequested:return Qe(e,{isSelectingOption:!0,selectOptionMethodId:t.meta&&t.meta.methodId});case pi.SelectOptionFailed:case pi.SelectOptionSucceeded:return Qe(e,{isSelectingOption:!1,selectOptionMethodId:void 0});case pi.WidgetInteractionStarted:return Qe(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta&&t.meta.methodId});case pi.WidgetInteractionFinished:case pi.WidgetInteractionFailed:return Qe(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Si;!function(e){e.SendSignInEmailRequested="SEND_SIGNIN_EMAIL_REQUESTED",e.SendSignInEmailSucceeded="SEND_SIGNIN_EMAIL_SUCCEEDED",e.SendSignInEmailFailed="SEND_SIGNIN_EMAIL_FAILED"}(Si||(Si={}));const Ci={errors:{},statuses:{}};function Ii(e=Ci,t){return i({data:_i,errors:r(wi,Be),statuses:bi})(e,t)}function _i(e,t){return t.type===Si.SendSignInEmailSucceeded?Qe(e,t.payload):e}function wi(e=Ci.errors,t){switch(t.type){case Si.SendSignInEmailRequested:case Si.SendSignInEmailSucceeded:return je(e,"sendError",void 0);case Si.SendSignInEmailFailed:return je(e,"sendError",t.payload);default:return e}}function bi(e=Ci.statuses,t){switch(t.type){case Si.SendSignInEmailRequested:return je(e,"isSending",!0);case Si.SendSignInEmailFailed:case Si.SendSignInEmailSucceeded:return je(e,"isSending",!1);default:return e}}var Ei;!function(e){e.ApplyStoreCreditRequested="APPLY_STORE_CREDIT_REQUESTED",e.ApplyStoreCreditSucceeded="APPLY_STORE_CREDIT_SUCCEEDED",e.ApplyStoreCreditFailed="APPLY_STORE_CREDIT_FAILED"}(Ei||(Ei={}));const Pi={errors:{},statuses:{}};function Oi(e=Pi,t){return i({errors:r(Ai,Be),statuses:Ti})(e,t)}function Ai(e=Pi.errors,t){switch(t.type){case Ei.ApplyStoreCreditRequested:case Ei.ApplyStoreCreditSucceeded:return je(e,"applyError",void 0);case Ei.ApplyStoreCreditFailed:return je(e,"applyError",t.payload);default:return e}}function Ti(e=Pi.statuses,t){switch(t.type){case Ei.ApplyStoreCreditRequested:return je(e,"isApplying",!0);case Ei.ApplyStoreCreditSucceeded:case Ei.ApplyStoreCreditFailed:return je(e,"isApplying",!1);default:return e}}const ki={errors:{},statuses:{}};function Di(e=ki,t){return i({errors:r(Ri,Be),statuses:Mi})(e,t)}function Ri(e=ki.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 Mi(e=ki.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 Ni;!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"}(Ni||(Ni={}));const Li={errors:{},statuses:{}};function zi(e=Li,t){return i({data:Ui,errors:r(Fi,Be),statuses:Bi})(e,t)}function Ui(e,t){var n;switch(t.type){case Me.LoadCheckoutSucceeded:case Me.UpdateCheckoutSucceeded:case Ei.ApplyStoreCreditSucceeded:case Ue.UpdateBillingAddressSucceeded:case Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Xe.LoadShippingOptionsSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:case Ni.VerifyCheckoutSucceeded:return Qe(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 Qe(e,k(null===(n=t.payload)||void 0===n?void 0:n.checkout,["billingAddress","cart","consignments","customer","coupons","giftCertificates"]));default:return e}}function Fi(e=Li.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 Bi(e=Li.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 Ni.ExecuteRequested:return je(e,"isExecutingSpamCheck",!0);case Ni.ExecuteFailed:case Ni.ExecuteSucceeded:return je(e,"isExecutingSpamCheck",!1);default:return e}}var xi;!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"}(xi||(xi={}));class qi extends be{constructor(e){super(function(e){switch(e){case xi.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case xi.MissingCart:return"Unable to proceed because cart data is unavailable.";case xi.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case xi.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case xi.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case xi.MissingCheckoutConfig:case xi.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case xi.MissingOrder:return"Unable to proceed because order data is unavailable.";case xi.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case xi.MissingPayment:return"Unable to proceed because payment data is unavailable.";case xi.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case xi.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case xi.MissingPaymentProviderCustomer:return"Unable to proceed because payment provider customer is unavailable.";case xi.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 ji=(Gi=de,(...e)=>{const t=e.pop();return Gi(...e,(...e)=>{const n=t(...e);return"function"==typeof n?ae(n):n})});var Gi;function Hi(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}function Vi(e){return function(e){const t=Object.create(e);return function(e,t){let n=Object.getPrototypeOf(e);for(;n;)t(n),n=Object.getPrototypeOf(n)}(e,n=>{Object.getOwnPropertyNames(n).forEach(n=>{"constructor"!==n&&"function"==typeof t[n]&&"_"!==n.charAt(0)&&(t[n]=((e,t)=>(...n)=>d(e[t].call(e,...n)))(e,n))})}),t}(e)}const Yi={"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"},barclays:{provider:"barclays",method:"credit_card"},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 Wi(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 $i={errors:{},statuses:{}};function Ki(){const e=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingBillingAddress))),n=ji(e=>e.errors.updateError,e=>()=>e),i=ji(e=>e.errors.continueAsGuestError,e=>()=>e),r=ji(e=>e.errors.loadError,e=>()=>e),o=ji(e=>!!e.statuses.isUpdating,e=>()=>e),a=ji(e=>!!e.statuses.isContinuingAsGuest,e=>()=>e),s=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((d=Ge)=>({getBillingAddress:e(d),getBillingAddressOrThrow:t(d),getUpdateError:n(d),getContinueAsGuestError:i(d),getLoadError:r(d),isUpdating:o(d),isContinuingAsGuest:a(d),isLoading:s(d)}))}(),t=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingCart))),n=ji(e=>e.errors.loadError,e=>()=>e),i=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((r=et)=>({getCart:e(r),getCartOrThrow:t(r),getLoadError:n(r),isLoading:i(r)}))}(),n=function(){const e=ji(e=>e,e=>()=>e),t=ji(e=>e.statuses,e=>ae(t=>{if(t){const n=e[t];return!0===(n&&n.isInitializing)}return z(e,{isInitializing:!0})})),n=ji(e=>e.data,e=>ae((t,n)=>{const i=e[t];return!!i&&(n?!0===i.initializedContainers[n]:z(i.initializedContainers,e=>!0===e))})),i=ji(e=>e.statuses,e=>ae(t=>{if(t){const n=e[t];return!0===(n&&n.isDeinitializing)}return z(e,{isDeinitializing:!0})})),r=ji(e=>e.errors,e=>ae(t=>{const n=t?e[t]:l(x(e),e=>!(!e||!e.initializeError));return n&&n.initializeError})),o=ji(e=>e.errors,e=>ae(t=>{const n=t?e[t]:l(x(e),e=>!(!e||!e.deinitializeError));return n&&n.deinitializeError}));return se((a=at)=>({getState:e(a),isInitializing:t(a),isInitialized:n(a),isDeinitializing:i(a),getInitializeError:r(a),getDeinitializeError:o(a)}))}(),i=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.data,e=>t=>{if(!e)return;const{flashMessages:n}=e.context;return n?void 0!==t?n.filter(({type:e})=>t===e):n:void 0}),n=ji(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),i=ji(n,e=>()=>Hi(e(),()=>new qi(xi.MissingCheckoutConfig))),r=ji(e=>e.data&&e.data.context,e=>()=>e),o=ji(e=>e.meta&&e.meta.externalSource,e=>()=>e),a=ji(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.host},e=>()=>e),s=ji(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.locale},e=>()=>e),d=ji(e=>e.meta&&e.meta.variantIdentificationToken,e=>()=>e),c=ji(e=>e.errors.loadError,e=>()=>e),u=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((l=gt,h)=>({getConfig:e(l),getFlashMessages:t(l),getStoreConfig:n(l,{formState:h}),getStoreConfigOrThrow:i(l,{formState:h}),getContextConfig:r(l),getExternalSource:o(l),getHost:a(l),getLocale:s(l),getVariantIdentificationToken:d(l),getLoadError:c(l),isLoading:u(l)}))}(),r=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.loadError,e=>()=>e),n=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((i=nn)=>({getCountries:e(i),getLoadError:t(i),isLoading:n(i)}))}(),o=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.removeCouponError,e=>()=>e),n=ji(e=>e.errors.applyCouponError,e=>()=>e),i=ji(e=>!!e.statuses.isApplyingCoupon,e=>()=>e),r=ji(e=>!!e.statuses.isRemovingCoupon,e=>()=>e);return se((o=It)=>({getCoupons:e(o),getRemoveError:t(o),getApplyError:n(o),isApplying:i(o),isRemoving:r(o)}))}(),a=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingCustomer))),n=ji(e=>e.errors.createError,e=>()=>e),i=ji(e=>!!e.statuses.isCreating,e=>()=>e),r=ji(e=>e.errors.createAddressError,e=>()=>e),o=ji(e=>!!e.statuses.isCreatingAddress,e=>()=>e);return se((a=Rt)=>({getCustomer:e(a),getCustomerOrThrow:t(a),getCreateAccountError:n(a),isCreatingCustomerAccount:i(a),getCreateAddressError:r(a),isCreatingCustomerAddress:o(a)}))}(),s=function(){const e=ji(e=>e.errors.signInMethodId,e=>e.errors.signInError,(e,t)=>n=>{if(!n||e===n)return t}),t=ji(e=>e.errors.signOutMethodId,e=>e.errors.signOutError,(e,t)=>n=>{if(!n||e===n)return t}),n=ji(e=>e.errors.executePaymentMethodCheckoutMethodId,e=>e.errors.executePaymentMethodCheckoutError,(e,t)=>n=>{if(!n||e===n)return t}),i=ji(e=>e.errors.initializeMethodId,e=>e.errors.initializeErrors,(e,t)=>n=>{if(e&&t)return n?t[n]:t[e]}),r=ji(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>n=>{if(!n||e===n)return t}),o=ji(e=>e.statuses.signInMethodId,e=>e.statuses.isSigningIn,(e,t)=>n=>!(n&&e!==n||!t)),a=ji(e=>e.statuses.signOutMethodId,e=>e.statuses.isSigningOut,(e,t)=>n=>!(n&&e!==n||!t)),s=ji(e=>e.statuses.executePaymentMethodCheckoutMethodId,e=>e.statuses.isExecutingPaymentMethodCheckout,(e,t)=>n=>!(n&&e!==n||!t)),d=ji(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>n=>!(n&&e!==n||!t)),c=ji(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),u=ji(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>n=>!(n&&e!==n||!t));return se((l=Ft)=>({getSignInError:e(l),getSignOutError:t(l),getExecutePaymentMethodCheckoutError:n(l),getInitializeError:i(l),getWidgetInteractionError:r(l),isSigningIn:o(l),isSigningOut:a(l),isExecutingPaymentMethodCheckout:s(l),isInitializing:d(l),isInitialized:c(l),isWidgetInteracting:u(l)}))}(),d=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.removeGiftCertificateError,e=>()=>e),n=ji(e=>e.errors.applyGiftCertificateError,e=>()=>e),i=ji(e=>!!e.statuses.isApplyingGiftCertificate,e=>()=>e),r=ji(e=>!!e.statuses.isRemovingGiftCertificate,e=>()=>e);return se((o=Pt)=>({getGiftCertificates:e(o),getRemoveError:t(o),getApplyError:n(o),isApplying:i(o),isRemoving:r(o)}))}(),c=function(){const e=ji(e=>e.data,e=>t=>{if(!e)return;const n=t.gateway?`${t.gateway}.${t.id}`:t.id,i=Yi[n];return i?u(e,i):[]}),t=ji(e=>e.data,(e=[])=>t=>{const n=x(Yi);return e.find(e=>e.bigpayToken===t&&"card"===e.type&&n.some(t=>S(e,t)))}),n=ji(t,e=>t=>Hi(e(t),()=>new qi(xi.MissingPaymentInstrument))),i=ji(e=>e.data,e=>()=>{if(e)return p(Yi,t=>u(e,e=>S(e,t)))}),r=ji(e=>e.meta,e=>()=>e),o=ji(e=>e.errors.loadError,e=>()=>e),a=ji(e=>e.errors.failedInstrument,e=>e.errors.deleteError,(e,t)=>n=>{if(!n||e===n)return t}),s=ji(e=>e.statuses.isLoading,e=>()=>!!e),d=ji(e=>e.statuses.deletingInstrument,e=>e.statuses.isDeleting,(e,t)=>n=>!(n&&e!==n||!t));return se((c=Fn)=>({getCardInstrument:t(c),getCardInstrumentOrThrow:n(c),getInstruments:i(c),getInstrumentsByPaymentMethod:e(c),getInstrumentsMeta:r(c),getLoadError:o(c),getDeleteError:a(c),isLoading:s(c),isDeleting:d(c)}))}(),h=function(){const e=ji(e=>e.data,e=>(t=[],n)=>{const i=l(t,{code:n});return(e?e.shippingAddress:[]).map(e=>o(e,t,i))}),t=ji(e=>e.data,e=>(t=[],n)=>{const i=l(t,{code:n});return(e?e.billingAddress:[]).map(e=>o(e,t,i))}),n=ji(e=>e.data,e=>()=>e?e.customerAccount:[]),i=ji(e=>e.errors.loadError,e=>()=>e),r=ji(e=>!!e.statuses.isLoading,e=>()=>e);function o(e,t,n){return"countryCode"===e.name?function(e,t=[],n){if(!t.length)return e;const{code:i=""}=n||{},r=t.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{options:{items:r},default:i,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,t,n):"stateOrProvince"===e.name?function(e,t){const{subdivisions:n=[],requiresState:i}=t||{};if(!n.length)return Object.assign(Object.assign({},e),{required:null!=i&&i});const r=n.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{name:"stateOrProvinceCode",options:{items:r},required:null==i||i,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,n):"postalCode"===e.name?function(e,t){const{hasPostalCodes:n=[]}=t||{};return void 0===n?e:Object.assign(Object.assign({},e),{required:Boolean(n)})}(e,n):e}return se((o=Qt)=>({getShippingAddressFields:e(o),getBillingAddressFields:t(o),getCustomerAccountFields:n(o),getLoadError:i(o),isLoading:r(o)}))}(),m=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.meta,e=>()=>e),n=ji(e=>e.data,e=>(t,n)=>l(e,n?{id:t,gateway:n}:{id:t})),i=ji(n,e=>(t,n)=>Hi(e(t,n),()=>new qi(xi.MissingPaymentMethod))),r=ji(e=>e.errors.loadError,e=>()=>e),o=ji(e=>e.errors.loadMethodId,e=>e.errors.loadMethodError,(e,t)=>n=>{if(!n||e===n)return t}),a=ji(e=>e.statuses.isLoading,e=>()=>!!e),s=ji(e=>e.statuses.loadMethodId,e=>e.statuses.isLoadingMethod,(e,t)=>n=>!(n&&e!==n||!t));return se((d=In)=>({getPaymentMethods:e(d),getPaymentMethodsMeta:t(d),getPaymentMethod:n(d),getPaymentMethodOrThrow:i(d),getLoadError:r(d),getLoadMethodError:o(d),isLoading:a(d),isLoadingMethod:s(d)}))}(),g=function(){const e=ji(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>n=>{if(!n||e===n)return t}),t=ji(e=>e.errors.executeMethodId,e=>e.errors.executeError,(e,t)=>n=>{if(!n||e===n)return t}),n=ji(e=>e.errors.finalizeMethodId,e=>e.errors.finalizeError,(e,t)=>n=>{if(!n||e===n)return t}),i=ji(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>n=>{if(!n||e===n)return t}),r=ji(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>n=>!(n&&e!==n||!t)),o=ji(e=>e.data,e=>t=>{const n=t.gatewayId?`${t.methodId}.${t.gatewayId}`:t.methodId;return!(!e[n]||!e[n].isInitialized)}),a=ji(e=>e.statuses.executeMethodId,e=>e.statuses.isExecuting,(e,t)=>n=>!(n&&e!==n||!t)),s=ji(e=>e.statuses.finalizeMethodId,e=>e.statuses.isFinalizing,(e,t)=>n=>!(n&&e!==n||!t)),d=ji(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>n=>!(n&&e!==n||!t));return se((c=An)=>({getInitializeError:e(c),getExecuteError:t(c),getFinalizeError:n(c),getWidgetInteractingError:i(c),isInitializing:r(c),isInitialized:o(c),isExecuting:a(c),isFinalizing:s(c),isWidgetInteracting:d(c)}))}(),y=function(){const e=ji(e=>e.data,e=>(t,n)=>{if(!e)return;const i=ei(Xn({consignmentId:t,searchArea:n})),r=btoa(`${JSON.stringify(i)}`);return e[r]}),t=ji(e=>e.errors.loadError,e=>()=>e),n=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((i=ni)=>({getPickupOptions:e(i),getLoadError:t(i),isLoading:n(i)}))}(),f=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentProviderCustomer)));return se((n=Nn)=>({getPaymentProviderCustomer:e(n),getPaymentProviderCustomerOrThrow:t(n)}))}(),C=function(){const e=ji(e=>e.data,e=>t=>e[t]);return se((t=Vn)=>({getCheckout:e(t)}))}(),I=function(){const e=ji(e=>e.data,e=>()=>{const t=null==e?void 0:e.find(e=>!e.selectedPickupOption);return null==t?void 0:t.shippingAddress}),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingShippingAddress))),n=ji(e=>e.data,e=>()=>{const t=null==e?void 0:e.filter(e=>!e.selectedPickupOption);return t?t.map(e=>e.shippingAddress):[]}),i=ji(n,e=>()=>Hi(e(),()=>new qi(xi.MissingShippingAddress)));return se((r=$n)=>({getShippingAddress:e(r),getShippingAddressOrThrow:t(r),getShippingAddresses:n(r),getShippingAddressesOrThrow:i(r)}))}(),_=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.loadError,e=>()=>e),n=ji(e=>e.statuses.isLoading,e=>()=>!!e);return se((i=di)=>({getShippingCountries:e(i),getLoadError:t(i),isLoading:n(i)}))}(),w=function(){const e=ji(e=>e.errors.updateAddressMethodId,e=>e.errors.updateAddressError,(e,t)=>n=>{if(!n||e===n)return t}),t=ji(e=>e.errors.selectOptionMethodId,e=>e.errors.selectOptionError,(e,t)=>n=>{if(!n||e===n)return t}),n=ji(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>n=>{if(!n||e===n)return t}),i=ji(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>n=>{if(!n||e===n)return t}),r=ji(e=>e.statuses.updateAddressMethodId,e=>e.statuses.isUpdatingAddress,(e,t)=>n=>!(n&&e!==n||!t)),o=ji(e=>e.statuses.selectOptionMethodId,e=>e.statuses.isSelectingOption,(e,t)=>n=>!(n&&e!==n||!t)),a=ji(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>n=>!(n&&e!==n||!t)),s=ji(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),d=ji(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>n=>!(n&&e!==n||!t));return se((c=mi)=>({getUpdateAddressError:e(c),getSelectOptionError:t(c),getInitializeError:n(c),getWidgetInteractionError:i(c),isUpdatingAddress:r(c),isSelectingOption:o(c),isInitializing:a(c),isInitialized:s(c),isWidgetInteracting:d(c)}))}(),b=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingConsignments))),n=ji(e=>e.data,e=>t=>{if(e&&e.length)return l(e,{id:t})}),i=ji(e=>e.data,e=>t=>{if(e&&e.length)return l(e,e=>{return n=e.shippingAddress,i=t,v(Wi(n),Wi(i));var n,i})}),r=ji(e=>e.data,e=>()=>{if(e&&e.length)return e[0].selectedShippingOption}),o=ji(e=>e.errors.loadError,e=>()=>e),a=ji(e=>e.errors.createError,e=>()=>e),s=ji(e=>e.errors.loadShippingOptionsError,e=>()=>e),d=ji(e,(e,{cart:t})=>t.getCart,(e,t)=>()=>{const n=t();if(!n)return[];const i=(e()||[]).reduce((e,t)=>e.concat(t.lineItemIds),[]);return(n.lineItems.physicalItems||[]).filter(e=>i.indexOf(e.id)<0)}),c=ji(e=>e.errors.updateError,e=>t=>t?e[t]:l(e)),u=ji(e=>e.errors.deleteError,e=>t=>t?e[t]:l(e)),h=ji(i,c,a,(e,t,n)=>i=>{const r=e(i);return r?t(r.id):n()}),p=ji(e=>e.errors.updateShippingOptionError,e=>t=>t?e[t]:l(e)),m=ji(e=>e.statuses.isLoading,e=>()=>!0===e),g=ji(e=>e.statuses.isLoadingShippingOptions,e=>()=>!0===e),y=ji(e=>e.statuses.isCreating,e=>()=>!0===e),f=ji(e=>e.statuses.isUpdating,e=>t=>t?!0===e[t]:!0===l(e)),S=ji(e=>e.statuses.isDeleting,e=>t=>t?!0===e[t]:!0===l(e)),C=ji(i,f,y,(e,t,n)=>i=>{const r=e(i);return r?t(r.id):n()}),I=ji(e=>e.statuses.isUpdatingShippingOption,e=>t=>t?!0===e[t]:!0===l(e));return se((l=$n,v)=>({getConsignments:e(l),getConsignmentsOrThrow:t(l),getConsignmentById:n(l),getConsignmentByAddress:i(l),getShippingOption:r(l),getLoadError:o(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=ji(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,n,i,r,o,a)=>()=>{const s=t(),d=n(),c=i(),u=r()||[],l=o()||[],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=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingCheckout))),n=ji(e,e=>t=>{const n=e();if(!n)return;const i=n.grandTotal||0,r=n.customer.storeCredit||0;return t?Math.max(i-r,0):n.outstandingBalance}),i=ji(e=>e.errors.loadError,e=>()=>e),r=ji(e=>e.errors.updateError,e=>()=>e),o=ji(e=>e.statuses.isExecutingSpamCheck,e=>()=>!0===e),a=ji(e=>e.statuses.isLoading,e=>()=>!0===e),s=ji(e=>e.statuses.isUpdating,e=>()=>!0===e);return se((d=Li,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:n(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getLoadError:i(d),getUpdateError:r(d),isExecutingSpamCheck:o(d),isLoading:a(d),isUpdating:s(d)}))}(),P=function(){const e=ji(e=>e.data,(e,{billingAddress:t})=>t.getOrderBillingAddress(),(e,{coupons:t})=>t.getCoupons(),(e,t,n=[])=>()=>{if(e&&t)return Object.assign(Object.assign({},e),{billingAddress:t,coupons:n})}),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingOrder))),n=ji(e=>e.meta,e=>()=>e),i=ji(e=>e.errors.loadError,e=>()=>e),r=ji(e=>{var t;return null===(t=e.data)||void 0===t?void 0:t.payments},(e=[])=>t=>{const n=e.find(({providerId:e})=>e===t);return null==n?void 0:n.paymentId}),o=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((a=dn,s,d)=>({getOrder:e(a,{billingAddress:s,coupons:d}),getOrderOrThrow:t(a,{billingAddress:s,coupons:d}),getOrderMeta:n(a),getLoadError:i(a),getPaymentId:r(a),isLoading:o(a)}))}(),O=function(){const e=ji(e=>e.data,e=>()=>e);return se((t=mn)=>({getOrderBillingAddress:e(t)}))}(),A=function(){const e=ji(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.payment}),t=ji(({order:e})=>e.getOrder,e=>()=>{const t=e();return l(t&&t.payments,({providerId:e})=>"giftcertificate"!==e&&"storecredit"!==e)}),n=ji(({checkout:e})=>e.getCheckout,e=>()=>{const t=e();return l(t&&t.payments,({providerType:e})=>"PAYMENT_TYPE_HOSTED"===e)}),i=ji(e,n,t,(e,t,n)=>()=>{const i=e();if(i&&i.id)return{providerId:i.id,gatewayId:i.gateway};const r=t()||n();return r&&r.providerId?{providerId:r.providerId,gatewayId:r.gatewayId}:void 0}),r=ji(i,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentId))),o=ji(e,n,t,(e,t,n)=>()=>{const i=e();if(i&&i.status)return i.status.replace("PAYMENT_STATUS_","");const r=t()||n();return r?r.detail.step:void 0}),a=ji(o,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentStatus))),s=ji(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.token}),d=ji(s,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentToken))),c=ji(e,e=>()=>{const t=e();return t&&t.redirectUrl}),u=ji(c,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentRedirectUrl))),h=ji(({checkout:e})=>e.getOutstandingBalance,e=>(t=!1)=>{const n=e(t);return!!n&&n>0}),p=ji(o,e=>t=>!(!t||!t.nonce)||"ACKNOWLEDGE"===e()||"FINALIZE"===e());return se((e,t)=>({getPaymentId:i({checkout:e,order:t}),getPaymentIdOrThrow:r({checkout:e,order:t}),getPaymentStatus:o({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=ji(e=>e.errors.applyError,e=>()=>e),t=ji(e=>!!e.statuses.isApplying,e=>()=>e);return se((n=$i)=>({getApplyError:e(n),isApplying:t(n)}))}(),k=function(){const e=ji(e=>e.errors.updateError,e=>()=>e),t=ji(e=>!!e.statuses.isUpdating,e=>()=>e);return se((n=ki)=>({getUpdateError:e(n),isUpdating:t(n)}))}(),D=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.sendError,e=>()=>e),n=ji(e=>!!e.statuses.isSending,e=>()=>e);return se((i=Ci)=>({getEmail:e(i),getSendError:t(i),isSending:n(i)}))}(),R=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.data,e=>t=>null==e?void 0:e.find(e=>e.region===t)),n=ji(e=>e.errors.loadError,e=>()=>e),i=ji(e=>e.statuses.isLoading,e=>()=>!!e);return se((r=Ht)=>({getExtensions:e(r),getExtensionByRegion:t(r),getLoadError:n(r),isLoading:i(r)}))}();return(u,l={})=>{const p=e(u.billingAddress),v=t(u.cart),S=n(u.checkoutButton),M=r(u.countries),N=o(u.coupons),L=a(u.customer),z=s(u.customerStrategies),U=R(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),Q=k(u.subscriptions),Z=T(u.storeCredit),J=D(u.signInEmail),X=b(u.consignments,v),ee=E(u.checkout,p,v,X,N,L,B),te=P(u.order,q,N),ne=A(ee,te),ie={billingAddress:p,cart:v,checkout:ee,checkoutButton:S,config:i(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:ne,paymentMethods:j,paymentProviderCustomer:G,paymentStrategies:H,pickupOptions:V,remoteCheckout:Y,shippingAddress:W,shippingCountries:$,shippingStrategies:K,signInEmail:J,subscriptions:Q,storeCredit:Z};return l.shouldWarnMutation?function(e){return Object.keys(e).reduce((t,n)=>(t[n]=Vi(e[n]),t),{})}(ie):ie}}function Qi(e={},t){const n=(s=function(){const e=new Re;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}))),r=Ki(),o=i({billingAddress:He,cart:tt,checkout:zi,checkoutButton:ut,config:yt,consignments:Kn,countries:rn,coupons:_t,customer:Mt,customerStrategies:Bt,extensions:Vt,formFields:Zt,giftCertificates:Ot,instruments:Bn,orderBillingAddress:gn,order:cn,payment:Sn,paymentMethods:_n,paymentStrategies:Tn,pickupOptions:ii,paymentProviderCustomer:Ln,remoteCheckout:Yn,shippingCountries:ci,shippingStrategies:gi,signInEmail:Ii,subscriptions:Di,storeCredit:Oi});var s;return a(o,e,Object.assign({actionTransformer:n,stateTransformer:e=>r(e)},t))}var Zi,Ji;!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"}(Zi||(Zi={}));class Xi extends Ce{constructor(e){super(function(e){switch(e){case Zi.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case Zi.MissingCart:return"Unable to proceed because cart data is unavailable.";case Zi.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case Zi.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case Zi.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case Zi.MissingCheckoutConfig:case Zi.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case Zi.MissingOrder:return"Unable to proceed because order data is unavailable.";case Zi.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case Zi.MissingPayment:return"Unable to proceed because payment data is unavailable.";case Zi.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case Zi.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case Zi.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 er(e){return t=e.lineItems.physicalItems.filter(e=>!e.addedByPromotion),N(t,(e,t)=>e+t.quantity,0);var t}function tr(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"}(Ji||(Ji={}));class nr extends Ce{constructor(e){super(function(e){switch(e){case Ji.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Ji.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Ji.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Ji.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 ir={de:"eu",jp:"fe",uk:"eu",us:"na"};var rr,or,ar,sr,dr,cr;!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"}(rr||(rr={})),function(e){e.Home="Home",e.Product="Product",e.Cart="Cart",e.Checkout="Checkout",e.Other="Other"}(or||(or={})),function(e){e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.JPY="JPY"}(ar||(ar={})),function(e){e.PayAndShip="PayAndShip",e.PayOnly="PayOnly"}(sr||(sr={})),function(e){e.Gold="Gold",e.LightGray="LightGray",e.DarkGray="DarkGray"}(dr||(dr={})),function(e){e.C0001="C0001"}(cr||(cr={}));var ur=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class lr{constructor(e){this.amazonPayV2ScriptLoader=e}initialize(e){return ur(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,n){this.getAmazonPayV2SDK().Pay.bindChangeAction(`#${e}`,{amazonCheckoutSessionId:t,changeAction:n})}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(()=>ur(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 ur(this,void 0,void 0,function*(){return this.amazonPayV2SDK&&this.amazonPayV2SDK.Pay.signout(),Promise.resolve()})}renderAmazonPayButton({buttonColor:e,checkoutState:t,containerId:n,decoupleCheckoutInitiation:i=!1,methodId:r,options:o,placement:a,isButtonMicroTextDisabled:s=!1}){const d=document.querySelector(`#${n}`);if(!d)return;const{id:c}=d.appendChild(this.getButtonParentContainer());o&&s&&(o.design=cr.C0001);const u=null!=o?o:this.getAmazonPayV2ButtonOptions(t,r,a,i,e);return this.createButton(c,u),this.getButtonParentContainer()}updateBuyNowFlowFlag(e){this.isBuyNowFlow=Boolean(e)}isPh4Enabled(e,t){const n=!!e["PROJECT-3483.amazon_pay_ph4"],i=!!e["INT-6885.amazon_pay_ph4_us_only"];return n&&i?"US"===t:n}prepareRequestConfig(e,t,n){const{publicKeyId:i}=e,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["publicKeyId"]);return Object.assign(Object.assign({createCheckoutSessionConfig:this.isEnvironmentSpecific(i)?r:e},t&&{estimatedOrderAmount:t}),n&&{productType:n})}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,n,i=!1,r=dr.Gold){var o;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 Xi(Zi.MissingPaymentMethod);const{checkoutLanguage:p,checkoutSessionMethod:m,createCheckoutSessionConfig:g,extractAmazonCheckoutSessionId:y,ledgerCurrency:f,publicKeyId:v="",isButtonMicroTextDisabled:S}=h;if(!u||!f)throw new Xi(Zi.MissingPaymentMethod);const C=Object.assign({merchantId:u,ledgerCurrency:f,checkoutLanguage:p,placement:n,buttonColor:r},S?{design:cr.C0001}:{});if(this.isBuyNowFlow)return Object.assign(Object.assign({},C),{sandbox:!!l});const I=a();C.productType=I&&0===er(I)?sr.PayOnly:sr.PayAndShip;const{checkoutSettings:{features:_},storeProfile:{shopPath:w,storeCountryCode:b}}=d();if(this.isPh4Enabled(_,b)){if(!g)throw new Xi(Zi.MissingPaymentMethod);const e=null===(o=s())||void 0===o?void 0:o.outstandingBalance.toString(),t=null==I?void 0:I.currency.code,n=Object.assign({},C);let r;return this.isEnvironmentSpecific(v)?(n.publicKeyId=v,r=g):(n.sandbox=!!l,r=Object.assign(Object.assign({},g),{publicKeyId:v})),i||(n.createCheckoutSessionConfig=r),e&&t&&(n.estimatedOrderAmount={amount:e,currencyCode:t}),n}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 tr(e,()=>new nr(Ji.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 hr 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 pr{constructor(e,t=window){this.scriptLoader=e,this.windowWithAmazonPay=t}load(e){return t=this,n=void 0,r=function*(){const{initializationData:t}=e,n=(null==t?void 0:t.region)||"us",i=ir[n];if(yield this.scriptLoader.loadScript(`https://static-${i}.payments-amazon.com/checkout.js`),!this.windowWithAmazonPay.amazon)throw new hr;return this.windowWithAmazonPay.amazon},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}}function mr(e,t){return Object.assign(e,{resolveIds:t})}class gr extends Ce{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class yr 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 fr 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 vr(e){return e instanceof Object&&"buyNowInitializeOptions"in e}var Sr=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Cr{constructor(e,t,n){this.paymentIntegrationService=e,this.amazonPayV2PaymentProcessor=t,this.amazonPayV2ConfigRequestSender=n}initialize(e){var t;return Sr(this,void 0,void 0,function*(){const{methodId:n,containerId:i,amazonpay:r}=e,{buttonColor:o}=r||{};if(!n||!i)throw new gr('Unable to proceed because "methodId" or "containerId" argument is not provided.');const{getPaymentMethodOrThrow:a}=this.paymentIntegrationService.getState(),s=a(n),{initializationData:d}=s;yield this.amazonPayV2PaymentProcessor.initialize(s),r||(yield this.paymentIntegrationService.loadDefaultCheckout());const c=vr(r)?void 0:r;vr(r)&&"function"==typeof(null===(t=r.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody)&&(this._buyNowInitializeOptions=r.buyNowInitializeOptions,this.amazonPayV2PaymentProcessor.updateBuyNowFlowFlag(!0)),this.amazonPayV2PaymentProcessor.renderAmazonPayButton({checkoutState:this.paymentIntegrationService.getState(),containerId:i,methodId:n,options:c,placement:or.Cart,buttonColor:o,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 Sr(this,void 0,void 0,function*(){const n=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!n)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(n)}catch(e){throw new yr}})}_createCheckoutConfig(e){return Sr(this,void 0,void 0,function*(){try{const t=(yield this.amazonPayV2ConfigRequestSender.createCheckoutConfig(e)).body,{payload:n,public_key:i}=t,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["payload","public_key"]);return Object.assign({payloadJSON:n,publicKeyId:i},r)}catch(e){throw new fr}})}_getCheckoutCreationRequestConfig(){return Sr(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===er(e)?sr.PayOnly:sr.PayAndShip}})}}const Ir="This API endpoint is for internal use only and may change in the future";var _r;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(_r||(_r={}));const wr=_r,br={"X-Checkout-SDK-Version":"1.817.0"};class Er{constructor(e){this._requestSender=e}createCheckoutConfig(e){const t={cartId:e},n=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return this._requestSender.post("/api/storefront/payment/amazonpay",{headers:n,body:t})}}const Pr=mr(t=>{const n=e(),i=new Er(n),r=new lr(new pr(le()));return new Cr(t,r,i)},[{id:"amazonpay"}]);function Or(e,t,n=!0){var i;return null!==(i=e[t])&&void 0!==i?i:n}const Ar="3.128.0",Tr="3.123.2",kr="3.106.0";class Dr{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()||(Or(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?Ar:Or(t,"PAYPAL-5636.update_braintree_sdk_version")?Tr:kr)}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 Rr extends Ce{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var Mr,Nr,Lr,zr,Ur,Fr,Br;function xr(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"}(Mr||(Mr={})),function(e){e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED"}(Nr||(Nr={})),function(e){e.TRUSTLY="trustly"}(Lr||(Lr={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="cancelled",e.UNRECOGNIZED="unrecognized"}(zr||(zr={})),function(e){e.Customer="CUSTOMER",e.Merchant="MERCHANT",e.Network="NETWORK",e.Internal="INTERNAL",e.Unknown="UNKNOWN"}(Ur||(Ur={})),function(e){e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED"}(Fr||(Fr={})),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"}(Br||(Br={}));var qr,jr,Gr,Hr=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Vr{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return Hr(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return Hr(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 Hr(this,void 0,void 0,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),i=Object.assign({client:t,kount:!0},e);this.dataCollector=yield n.create(i)}catch(e){if(xr(e)&&e.code===Fr.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return Hr(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 Hr(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 Hr(this,void 0,void 0,function*(){if(!this.braintreeLocalPayment){const[t,n]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((i,r)=>{n.create({client:t,merchantAccountId:e},(e,t)=>{e&&r(e),i(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return Hr(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 Hr(this,void 0,void 0,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return Hr(this,void 0,void 0,function*(){if(!this.braintreeVenmo){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadVenmoCheckout(),n={client:e,allowDesktop:!0,paymentMethodUsage:"multi_use"},i=yield t.create(n);if(!i.isBrowserSupported())throw new Rr;this.braintreeVenmo=i}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new nr(Ji.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}!function(e){e.Sandbox="sandbox",e.Production="production"}(qr||(qr={})),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"}(jr||(jr={})),function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(Gr||(Gr={}));const Yr={[kr]:{[jr.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[jr.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[jr.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[jr.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[jr.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[jr.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[jr.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[jr.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[jr.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[jr.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[jr.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[jr.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[Tr]:{[jr.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[jr.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[jr.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[jr.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[jr.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[jr.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[jr.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[jr.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[jr.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[jr.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[jr.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[jr.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[Ar]:{[jr.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[jr.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[jr.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[jr.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[jr.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[jr.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[jr.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[jr.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[jr.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[jr.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[jr.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[jr.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var Wr,$r=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Kr{constructor(e,t,n){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=n}loadClient(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.Client,"client.min.js")})}loadFastlane(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.Paypal,"paypal.min.js")})}loadLocalPayment(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.GooglePayment,"google-payment.min.js")})}load3DS(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(jr.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(jr.Venmo,"venmo.min.js")}loadHostedFields(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return $r(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 hr;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return $r(this,void 0,void 0,function*(){let n=this.getBraintreeModule(e);if(n)return n;const i=this.braintreeSDKVersionManager.getSDKVersion(),r=`//js.braintreegateway.com/web/${i}/js/${t}`,o=i in Yr?this.getIntegrityValuesByModuleName(e,i):void 0;if(yield this.scriptLoader.loadScript(r,o?{async:!0,attributes:{integrity:o,crossorigin:"anonymous"}}:void 0),n=this.getBraintreeModule(e),!n)throw new hr;return n})}getBraintreeModule(e){var t;return null===(t=this.braintreeHostWindow.braintree)||void 0===t?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const n=Yr[t][e];if(!n)throw new Error("Unexpected fileName value");return n}}class Qr 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"}(Wr||(Wr={}));var Zr,Jr,Xr=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};!function(e){e.Subtotal="Subtotal",e.Shipping="Shipping"}(Zr||(Zr={})),function(e){e.Black="black",e.White="white",e.WhiteBorder="white-border"}(Jr||(Jr={}));class eo{constructor(e,t,n,i,r){this._requestSender=e,this._paymentIntegrationService=t,this._sessionFactory=n,this._braintreeSdk=i,this._applePayScriptLoader=r,this._onAuthorizeCallback=T,this._subTotalLabel=Zr.Subtotal,this._shippingLabel=Zr.Shipping}initialize(e){var t,n;return Xr(this,void 0,void 0,function*(){const{methodId:i,containerId:r,applepay:o}=e;if(!i||!o)throw new Xi(Zi.MissingPaymentMethod);yield this._applePayScriptLoader.loadSdk();const{onPaymentAuthorize:a,buyNowInitializeOptions:s,requiresShipping:d}=o;this._requiresShipping=d,this._buyNowInitializeOptions=s,this._onAuthorizeCallback=a,s||(yield this._paymentIntegrationService.loadDefaultCheckout()),yield this._paymentIntegrationService.loadPaymentMethod(i);const c=this._paymentIntegrationService.getState();return this._paymentMethod=c.getPaymentMethodOrThrow(i),c.getCart()&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection()),(null===(t=this._paymentMethod.initializationData)||void 0===t?void 0:t.gateway)===Wr.BRAINTREE&&(yield this._initializeBraintreeSdk()),this._applePayButton=this._createButton(r,null===(n=this._paymentMethod.initializationData)||void 0===n?void 0:n.styleOption),this._applePayButton.addEventListener("click",this._handleWalletButtonClick.bind(this)),Promise.resolve()})}deinitialize(){return Promise.resolve()}_createButton(e,t){const n=document.getElementById(e);if(!n)throw new gr("Unable to create wallet button without valid container ID.");const i=this._createApplePayButtonElement(t);return n.appendChild(i),i}_createApplePayButtonElement(e){const t=document.createElement("apple-pay-button");return t.setAttribute("buttonstyle",(e=>{switch(e){case Jr.White:return"white";case Jr.WhiteBorder:return"white-outline";case Jr.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 Xr(this,void 0,void 0,function*(){if(e.preventDefault(),!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xi(Zi.MissingPaymentMethod);if(this._buyNowInitializeOptions&&"function"==typeof this._buyNowInitializeOptions.getBuyNowCartRequestBody){const{countryCode:e,currencyCode:n,merchantCapabilities:i,supportedNetworks:r,storeName:o}=this._paymentMethod.initializationData,a=this._getRequestWithEmptyTotal(e,n,r,i);this._requiresShipping&&(null===(t=a.requiredShippingContactFields)||void 0===t||t.push("postalAddress"));const s=this._sessionFactory.create(a);this._handleApplePayEvents(s,this._paymentMethod,o),s.begin()}else{const e=this._paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getStoreConfigOrThrow(),i=e.getCheckoutOrThrow(),r=this._getBaseRequest(t,i,n,this._paymentMethod),o=this._sessionFactory.create(r);this._handleApplePayEvents(o,this._paymentMethod,n.storeProfile.storeName),o.begin()}})}_getRequestWithEmptyTotal(e,t,n,i){return{countryCode:e,currencyCode:t,supportedNetworks:n,merchantCapabilities:i,total:{label:"",amount:"0",type:"pending"},requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"]}}_getBaseRequest(e,t,n,i){var r;const{storeProfile:{storeCountryCode:o,storeName:a}}=n,{currency:{code:s,decimalPlaces:d}}=e,{initializationData:{merchantCapabilities:c,supportedNetworks:u}}=i,l=e.lineItems.physicalItems.length>0,h={requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"],countryCode:o,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===(r=h.requiredShippingContactFields)||void 0===r||r.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,n){e.onvalidatemerchant=n=>Xr(this,void 0,void 0,function*(){try{const{body:i}=yield this._onValidateMerchant(t,n);e.completeMerchantValidation(i)}catch(e){throw new Error("Merchant validation failed")}}),this._buyNowInitializeOptions&&!this._requiresShipping&&(e.onpaymentmethodselected=()=>Xr(this,void 0,void 0,function*(){yield this._createBuyNowCart(),this._handlePaymentMethodSelected(e)})),e.onshippingcontactselected=t=>Xr(this,void 0,void 0,function*(){this._buyNowInitializeOptions&&this._requiresShipping&&(yield this._createBuyNowCart()),yield this._handleShippingContactSelected(e,n,t)}),e.onshippingmethodselected=t=>Xr(this,void 0,void 0,function*(){yield this._handleShippingMethodSelected(e,n,t)}),e.oncancel=()=>Xr(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 Qr}}),e.onpaymentauthorized=n=>Xr(this,void 0,void 0,function*(){return this._onPaymentAuthorized(n,e,t)})}_createBuyNowCart(){var e,t;return Xr(this,void 0,void 0,function*(){try{const n=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!n)throw new Xi(Zi.MissingCart);const i=yield this._paymentIntegrationService.createBuyNowCart(n);yield this._paymentIntegrationService.loadCheckout(i.id);const r=this._paymentIntegrationService.getState(),{shouldExecuteSpamCheck:o}=r.getCheckoutOrThrow();o&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection())}catch(e){throw new yr}})}_handlePaymentMethodSelected(e){const t=this._paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getStoreConfigOrThrow(),r=t.getCheckoutOrThrow();if(!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xi(Zi.MissingPaymentMethod);const o=this._getBaseRequest(n,r,i,this._paymentMethod);delete o.total.type,e.completePaymentMethodSelection({newTotal:o.total,newLineItems:o.lineItems})}_handleShippingContactSelected(e,t,n){var i;return Xr(this,void 0,void 0,function*(){const r=this._transformContactToAddress(n.shippingContact);try{yield this._paymentIntegrationService.updateShippingAddress(r)}catch(t){throw e.abort(),new Error("Shipping address update failed")}let o=this._paymentIntegrationService.getState();const{currency:{decimalPlaces:a}}=o.getCartOrThrow();let s=o.getCheckoutOrThrow();const d=null===(i=s.consignments[0].selectedShippingOption)||void 0===i?void 0:i.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")}o=this._paymentIntegrationService.getState(),s=o.getCheckoutOrThrow(),e.completeShippingContactSelection({newShippingMethods:h,newTotal:{type:"final",label:t,amount:`${s.grandTotal.toFixed(a)}`},newLineItems:this._getUpdatedLineItems(s,a)})})}_handleShippingMethodSelected(e,t,n){return Xr(this,void 0,void 0,function*(){const{shippingMethod:{identifier:i}}=n;try{yield this._updateShippingOption(i)}catch(t){throw e.abort(),new Error("Shipping option selection update failed.")}const r=this._paymentIntegrationService.getState(),{currency:{decimalPlaces:o}}=r.getCartOrThrow(),a=r.getCheckoutOrThrow();e.completeShippingMethodSelection({newTotal:{type:"final",label:t,amount:`${a.grandTotal.toFixed(o)}`},newLineItems:this._getUpdatedLineItems(a,o)})})}_getUpdatedLineItems(e,t){const n=[{label:this._subTotalLabel,amount:`${e.subtotal.toFixed(t)}`}];return e.taxes.forEach(e=>n.push({label:e.name,amount:`${e.amount.toFixed(t)}`})),n.push({label:this._shippingLabel,amount:`${e.shippingCostTotal.toFixed(t)}`}),n}_updateShippingOption(e){return Xr(this,void 0,void 0,function*(){return this._paymentIntegrationService.selectShippingOption(e)})}_onValidateMerchant(e,t){return Xr(this,void 0,void 0,function*(){const n=[`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:n})})}_onPaymentAuthorized(e,t,n){var i;return Xr(this,void 0,void 0,function*(){const{token:r,billingContact:o,shippingContact:a}=e.payment,s=this._paymentIntegrationService.getState().getCartOrThrow().lineItems.physicalItems.length>0;let d;(null===(i=n.initializationData)||void 0===i?void 0:i.gateway)===Wr.BRAINTREE&&(d=yield this._getBraintreeDeviceData());const c={methodId:n.id,paymentData:{deviceSessionId:d,formattedPayload:{apple_pay_token:{payment_data:r.paymentData,payment_method:r.paymentMethod,transaction_id:r.transactionIdentifier}}}},u=this._transformContactToAddress(o),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 Xr(this,void 0,void 0,function*(){try{const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e}catch(e){}})}_initializeBraintreeSdk(){return Xr(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadPaymentMethod(Wr.BRAINTREE);const e=this._paymentIntegrationService.getState().getPaymentMethod(Wr.BRAINTREE);e&&e.clientToken&&e.initializationData&&this._braintreeSdk.initialize(e.clientToken)})}}function to(e){if(!function(e){return"ApplePaySession"in e}(e))throw new Error("Apple pay is not supported")}class no{create(e){return to(window),new ApplePaySession(1,e)}}class io{constructor(e){this.scriptLoader=e,this.sdkVersion="1.latest"}loadSdk(){return e=this,t=void 0,i=function*(){yield this.scriptLoader.loadScript(`https://applepay.cdn-apple.com/jsapi/${this.sdkVersion}/apple-pay-sdk.js`),to(window)},new((n=void 0)||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())});var e,t,n,i}}const ro=mr(t=>{const{getHost:n}=t.getState(),i=new Dr(t);return new eo(e({host:n()}),t,new no,new Vr(new Kr(le(),window,i)),new io(new ce))},[{id:"applepay"}]);var oo,ao,so,co,uo,lo,ho,po;!function(e){e.BuyNow="BUY_NOW"}(oo||(oo={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ao||(ao={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(so||(so={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(co||(co={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(uo||(uo={})),function(e){e.pill="pill",e.rect="rect"}(lo||(lo={})),function(e){e.OXXO="oxxo"}(ho||(ho={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(po||(po={}));var mo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class go{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=n,this.bigCommercePaymentsScriptLoader=i}loadPayPalSdk(e,t,n,i){return mo(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(a,o,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new hr;return this.paypalSdk}createBuyNowCartOrThrow(e){return mo(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new yr}})}createOrder(e,t){return mo(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return mo(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(){return mo(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getConsignmentsOrThrow()[0];try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:n.availableShippingOptions,cartId:t.id,selectedShippingOption:n.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return mo(this,void 0,void 0,function*(){try{const{status:n}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _e}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xi(Zi.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===oo.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return mo(this,void 0,void 0,function*(){const i={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:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}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,n;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===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:r}=e||{},o={color:t&&uo[t]?t:void 0,height:this.getValidHeight(n),label:i&&co[i]?i:void 0,shape:r&&lo[r]?r:void 0};return D(o,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 yo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class fo{constructor(e){this.requestSender=e}createOrder(e,t){return yo(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return yo(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:n,body:t})).body})}getOrderStatus(e="bigcommerce_payments",t){return yo(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}var vo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class So{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return vo(this,void 0,void 0,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e,t=!1){return vo(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.paypal)throw new hr;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new Xi(Zi.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}=o,v=h||n,S="bigcommerce_payments_creditcards"===i,C=S?["card"]:[],I=S?[]:["card"],_=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],b=n||!v,E=l?["venmo"]:[],P=l?[]:["venmo"],O=b?y:[],A=b?g.filter(e=>!y.includes(e)):g,T=f?["googlepay"]:[],k=n?["card-fields"]:[],D=this.filterFundingOptions([...I,...w,...P,...A]),R=this.filterFundingOptions([...C,..._,...E,...O]);return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":R.length>0?R:void 0,"disable-funding":D.length>0?D:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...T,...k],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":r}}}filterFundingOptions(e){const t=["klarna"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const Co=t=>{const{getHost:i}=t.getState();return new go(n(),t,new fo(e({host:i()})),new So(le()))};var Io=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class _o{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){var t;return Io(this,void 0,void 0,function*(){const{bigcommerce_payments:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(o&&!n.currencyCode)throw new gr('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new gr('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:c}=d.initializationData||{},u={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)},p=Object.assign(Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},u),i&&l),c&&h),m=s.Buttons(p);m.isEligible()?m.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Io(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Io(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Io(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 Io(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}})}}const wo=mr(e=>new _o(e,Co(e)),[{id:"bigcommerce_payments"}]);var bo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Eo{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return bo(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new hr}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return bo(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new hr;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return bo(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new hr}return this.window.paypalApms})}getPayPalMessages(e,t){return bo(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new hr;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return bo(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,attributionId:d}=r;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:o},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=r,h=u||n;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:o},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:o,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=n,l=this.filterFundingOptions(u),h=this.filterFundingOptions(c.filter(e=>!u.includes(e)));return{options:Object.assign({"client-id":r,"merchant-id":o,"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:i},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:o,isDeveloperModeApplicable:a,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":r,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":o}}}filterFundingOptions(e){const t=["klarna"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const Po=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 Oo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ao{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.payPalSdkHelper=n}initialize(e){return Oo(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o,messagingContainerId:a}=t||{},s=!!r;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(s&&!o)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new gr('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?o:d.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,c,!1),this.renderButton(n,i,t);const u=a&&document.getElementById(a);if(c&&u){const e=d.getPaymentMethodOrThrow(i),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},n=t&&t.find(({id:e})=>"cart"===e);if(!(null==n?void 0:n.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 r=yield this.payPalSdkHelper.getPayPalMessages(e,c);this.renderMessages(r,a,n)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)},p=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let m=!1;p.forEach(t=>{if(!m){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},u),i&&l),c&&h),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),m=!0):a&&"function"==typeof a&&a()}}),m||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Oo(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Oo(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Oo(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 Oo(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,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:Po(n)};e.Messages(i).render(`#${t}`)}}const To=mr(e=>new Ao(e,Co(e),new Eo(ue())),[{id:"bigcommerce_payments_paylater"}]);var ko=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Do{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return ko(this,void 0,void 0,function*(){const{bigcommerce_payments_apms:t,containerId:n,methodId:i}=e,{apm:r,buyNowInitializeOptions:o,currencyCode:a}=t||{},s=!!o;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');if(!r)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_apms.apm" argument is not provided.');if(s&&!a)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_apms.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new gr('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(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{apm:i,buyNowInitializeOptions:r,style:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(i))throw new gr('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(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:i,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o)},d),r&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return ko(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Ro=mr(e=>new Do(e,Co(e)),[{id:"bigcommerce_payments_apms"}]);var Mo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class No{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Mo(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(a&&!o)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new gr('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?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):o&&"function"==typeof o?o():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===uo.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return Mo(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Lo=mr(e=>new No(e,Co(e)),[{id:"bigcommerce_payments_venmo"}]);class zo extends Ce{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Uo,Fo,Bo;!function(e){e.SandboxMode="bolt_sandbox",e.StagingMode="bolt_staging",e.DevelopmentMode="bolt_development"}(Uo||(Uo={})),function(e){e.Small="small",e.Medium="medium",e.Large="large"}(Fo||(Fo={})),function(e){e.Pill="pill",e.Rect="rect"}(Bo||(Bo={}));class xo{constructor(e,t,n=window){this.paymentIntegrationService=e,this.boltScriptLoader=t,this.boltHostWindow=n}initialize(e){return t=this,n=void 0,r=function*(){const{bolt:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,style:o}=t||{};if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bolt" argument is not provided.');if(!Boolean(r))throw new zo("Only buy now flow is implemented for Bolt button");if(!(null==r?void 0:r.storefrontApiToken)||"string"!=typeof r.storefrontApiToken)throw new gr('Unable to initialize payment because "options.storefrontApiToken" argument is not provided.');const a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i),{initializationData:s,config:d}=a,{publishableKey:c,developerConfig:u}=s||{};yield this.boltScriptLoader.loadBoltClient(c,d.testMode,u,"BigCommerce",r.storefrontApiToken),this.renderButton(n,a,o)},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}deinitialize(){return Promise.resolve()}renderButton(e,t,n){var i;"function"==typeof(null===(i=this.boltHostWindow.BoltConnect)||void 0===i?void 0:i.setupProductPageCheckout)&&(this.addButtonContainer(e,t,n),this.boltHostWindow.BoltConnect.setupProductPageCheckout())}addButtonContainer(e,t,n){const i=document.getElementById(e);if(!i)return;const r=document.createElement("div"),o=document.createElement("object");r.setAttribute("id","product-page-checkout-wrapper"),r.setAttribute("class","bolt-button-wrapper"),r.setAttribute("style","display:none"),r.setAttribute("data-tid","product-page-checkout-wrapper"),o.setAttribute("data",this.getBoltObjectData(t,n)),o.setAttribute("class","bolt-product-checkout-button"),r.append(o),i.innerHTML="",i.append(r)}getBoltObjectData(e,t){const{initializationData:n,config:i}=e,{publishableKey:r,developerConfig:o}=n||{},a=this.boltScriptLoader.getDomainURL(!!i.testMode,o),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:r,variant:"ppc",height:s,border_radius:d}})}getButtonHeight(e){if(e)switch(e){case Fo.Small:return 25;case Fo.Large:return 45;case Fo.Medium:default:return 40}}getButtonBorderRadius(e,t){if(e)switch(e){case Bo.Pill:return t?Math.round(t/2):void 0;case Bo.Rect:default:return 4}}}var qo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class jo{constructor(e,t=window){this.scriptLoader=e,this.boltHostWindow=t}loadBoltClient(e,t,n,i,r){return qo(this,void 0,void 0,function*(){if(this.boltHostWindow.BoltCheckout)return this.boltHostWindow.BoltCheckout;if(!e)throw new gr('Unable to initialize payment because "publishableKey" argument is not provided.');if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,n)}/connect-bigcommerce.js`,this.getScriptOptions("bolt-connect",e,i,r)),yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,n)}/track.js`,this.getScriptOptions("bolt-track",e)),!this.boltHostWindow.BoltCheckout)throw new hr;return this.boltHostWindow.BoltCheckout})}loadBoltEmbedded(e,t,n){return qo(this,void 0,void 0,function*(){if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,n)}/embed.js`,{async:!0,attributes:{id:"bolt-embedded"}}),!this.boltHostWindow.Bolt)throw new hr;return this.boltHostWindow.Bolt(e)})}getDomainURL(e,t){if(!e)return"connect.bolt.com";if(t)switch(t.developerMode){case Uo.StagingMode:return"connect-staging.bolt.com";case Uo.DevelopmentMode:return`connect.${t.developerDomain}`}return"connect-sandbox.bolt.com"}getScriptOptions(e,t,n,i){return{async:!0,attributes:Object.assign(Object.assign({id:e,"data-publishable-key":t},n&&{"data-shopping-cart-id":n}),i&&{"data-storefront-api-token":i})}}}const Go=mr(e=>new xo(e,new jo(le())),[{id:"bolt"}]);class Ho extends gr{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 Vo 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 Yo{constructor(e){const t=new Promise((e,t)=>{this.cancel=t});this.promise=Promise.race([e,t])}}const Wo=["buttons","messages"];var $o,Ko,Qo,Zo,Jo,Xo;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}($o||($o={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Ko||(Ko={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(Qo||(Qo={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Zo||(Zo={})),function(e){e.PILL="pill",e.RECT="rect"}(Jo||(Jo={})),function(e){e.CART="cart",e.HOME="homepage",e.PAYMENT="payment",e.PRODUCT="product"}(Xo||(Xo={}));var ea=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ta{constructor(e,t,n){this.braintreeScriptLoader=e,this.braintreeHostWindow=t,this.overlay=n,this.dataCollectors={}}initialize(e,t){this.clientToken=e,this.threeDSecureOptions=t}getBraintreeFastlane(e,t,n){return ea(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(),i=yield this.getClient(),r=yield this.getSessionId(e),o=yield this.braintreeScriptLoader.loadFastlane(),a={root:{backgroundColorPrimary:"transparent"}};this.braintreeHostWindow.braintreeFastlane=yield o.create({authorization:t,client:i,deviceData:r,styles:n||a})}return this.braintreeHostWindow.braintreeFastlane})}getClient(){return ea(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,n=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["shouldSaveInstrument"]);const i=pe();return this.getPaypal().then(e=>{var r;return i&&(null===(r=this.overlay)||void 0===r||r.show({onClick:()=>e.focusWindow()})),e.tokenize(Object.assign({enableShippingAddress:!0,flow:t?"vault":"checkout",useraction:"commit"},n))}).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,n){return ea(this,void 0,void 0,function*(){const i=yield this.getClient(),r=yield this.braintreeScriptLoader.loadPaypalCheckout(),o={client:i};return this.paypalCheckout=yield r.create(o,(i,r)=>{var o;if(i)return n(i);const a=Object.assign(Object.assign({currency:e.currency},e.isCreditEnabled&&{"enable-funding":"paylater"}),{components:Wo.toString(),intent:e.intent,commit:null===(o=e.commit)||void 0===o||o});this.braintreeHostWindow.paypal?t(r):r.loadPayPalSDK(a,()=>t(r))}),this.paypalCheckout})}getDataCollector(e){return ea(this,void 0,void 0,function*(){const t=(null==e?void 0:e.paypal)?"paypal":"default";let n=this.dataCollectors[t];if(!n){try{const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadDataCollector(),r=Object.assign({client:t,kount:!0},e);n=yield i.create(r)}catch(e){if(!xr(e)||"DATA_COLLECTOR_KOUNT_NOT_ENABLED"!==e.code)throw e;n={deviceData:void 0,teardown:()=>Promise.resolve()}}this.dataCollectors[t]=n}return n})}getBraintreeEnv(e=!1){return e?qr.Sandbox:qr.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:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}mapToLegacyBillingAddress(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,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 ea(this,void 0,void 0,function*(){const{deviceData:t}=yield this.getDataCollector({riskCorrelationId:e});return t})}teardown(){return ea(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 ea(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 ea(this,void 0,void 0,function*(){if(!this.venmoCheckout){const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadVenmoCheckout(),i=Object.assign({client:t,allowDesktop:!0,paymentMethodUsage:"multi_use"},e||{});this.venmoCheckout=yield new Promise((e,t)=>{n.create(i,(n,i)=>n?t(n):i.isBrowserSupported()?void e(i):t(new Rr))})}return this.venmoCheckout})}verifyCard(e,t,n){return ea(this,void 0,void 0,function*(){const i=yield this.tokenizeCard(e,t);return this.challenge3DSVerification(i,n)})}tokenizeCard(e,t){return ea(this,void 0,void 0,function*(){const{paymentData:n}=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}(n))throw new Ho(["payment.paymentData"]);const i=this.getErrorsRequiredFields(n);if(!f(i))throw new Vo(i);const r=this.mapToCreditCard(n,t),o=yield this.getClient(),{creditCards:a}=yield o.request(r);return{nonce:a[0].nonce,bin:a[0].details.bin}})}challenge3DSVerification(e,t){return ea(this,void 0,void 0,function*(){const n=yield this.get3DS();return this.present3DSChallenge(n,t,e)})}teardownModule(e){return e?e.teardown():Promise.resolve()}getClientTokenOrThrow(){if(!this.clientToken)throw new nr(Ji.PaymentNotInitialized);return this.clientToken}getErrorsRequiredFields(e){const{ccNumber:t,ccExpiry:n}=e,i={};return t||(i.ccNumber=[{message:"Credit card number is required",type:"required"}]),n||(i.ccExpiry=[{message:"Expiration date is required",type:"required"}]),i}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,n){const{nonce:i,bin:r}=n;if(!this.threeDSecureOptions||!i)throw new nr(Ji.PaymentNotInitialized);const{addFrame:o,removeFrame:a,challengeRequested:s=!0,additionalInformation:d}=this.threeDSecureOptions,c=()=>ea(this,void 0,void 0,function*(){const t=yield e.cancelVerifyCard();return l.cancel(new Qr),t}),u=t.toFixed(2),l=new Yo(e.verifyCard({addFrame:(e,t)=>{o&&o(e,t,c)},amount:Number(u),bin:r,challengeRequested:s,nonce:i,removeFrame:a,onLookupComplete:(e,t)=>{t()},collectDeviceData:!0,additionalInformation:d}));return l.promise}}function na(e){const{color:t,fundingicons:n,height:i=40,layout:r,shape:o,size:a,tagline:s}=e||{},d={color:t,fundingicons:n,height:ia(i),layout:r,shape:o||"rect",size:a,tagline:s};return D(d,C)}function ia(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 oa=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class aa{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return oa(this,void 0,void 0,function*(){const{braintreepaypal:t,containerId:n,methodId:i}=e;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let r,o=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new gr('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');r=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow().currency.code;const a=o.getPaymentMethodOrThrow(i),{clientToken:s,config:d,initializationData:c}=a;if(!s||!c)throw new Xi(Zi.MissingPaymentMethod);const u={currency:r,intent:c.intent,isCreditEnabled:c.isCreditEnabled};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(u,e=>{this.renderPayPalButton(e,t,n,i,!!d.testMode)},e=>this.handleError(e,n,t.onError))})}deinitialize(){return oa(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,n,i,r){const{style:o,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:d}=t,{paypal:c}=this.braintreeHostWindow;if(c){const u=c.Buttons({env:r?"sandbox":"production",fundingSource:c.FUNDING.PAYPAL,style:na(o),createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});u.isEligible()?u.render(`#${n}`):d&&"function"==typeof d&&d()}else this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){var i;return oa(this,void 0,void 0,function*(){const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(n),u=r?r.cartAmount:s.getCartOrThrow().cartAmount,l=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(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===(i=c.initializationData)||void 0===i?void 0:i.intent})}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return oa(this,void 0,void 0,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}createBuyNowCart(e){return oa(this,void 0,void 0,function*(){if(!e)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new yr}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!xr(e))throw e;n(e)}}const sa=mr(e=>{const t=window,i=new Dr(e),r=new ta(new Kr(le(),t,i),t);return new aa(e,n(),r,t)},[{id:"braintreepaypal"}]);class da{constructor(e){this.paymentIntegrationService=e,this.braintreeHostWindow=window}render(e,t,n){const i=t&&document.getElementById(t);if(this.braintreeHostWindow.paypal&&i){const r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow(),a=r.getBillingAddressOrThrow(),s=r.getPaymentMethodOrThrow(e);if(!s.initializationData)return;const{paypalBNPLConfiguration:d=[]}=s.initializationData,c=n===Xo.PAYMENT?"checkout":n,u=d&&d.find(({id:e})=>e===c);if(!u||!u.status)return;n===Xo.CART&&(i.removeAttribute("data-pp-style-logo-type"),i.removeAttribute("data-pp-style-logo-position"),i.removeAttribute("data-pp-style-text-color"),i.removeAttribute("data-pp-style-text-size")),this.braintreeHostWindow.paypal.Messages({amount:o.cartAmount,buyerCountry:a.countryCode,placement:n,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 ca=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ua{constructor(e,t,n,i,r){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeMessages=i,this.braintreeHostWindow=r}initialize(e){var t,n;return ca(this,void 0,void 0,function*(){const{braintreepaypalcredit:i,containerId:r,methodId:o}=e;if(!o)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let a,s=this.paymentIntegrationService.getState();if(i.buyNowInitializeOptions){if(!i.currencyCode)throw new gr('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');a=i.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),s=this.paymentIntegrationService.getState(),a=s.getCartOrThrow().currency.code;const d=s.getPaymentMethodOrThrow(o),{clientToken:c,config:u,initializationData:l}=d;if(!c||!l)throw new Xi(Zi.MissingPaymentMethod);const h={currency:a,intent:l.intent,isCreditEnabled:l.isCreditEnabled},p=Or(null!==(n=null===(t=s.getStoreConfig())||void 0===t?void 0:t.checkoutSettings.features)&&void 0!==n?n:{},"PAYPAL-5663.hide_braintree_card_banner_implementation_in_checkout_sdk");this.braintreeIntegrationService.initialize(c),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{!p&&i.messagingContainerId&&this.renderPayPalMessages(o,i.messagingContainerId),this.renderPayPalButton(e,i,r,o,!!u.testMode)},e=>this.handleError(e,r,i.onError))})}deinitialize(){return ca(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalMessages(e,t){this.braintreeMessages.render(e,t,Xo.CART)}renderPayPalButton(e,t,n,i,r){const{style:o,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:Zo.CREDIT},na(o)):na(o);if(!u){const o=c.Buttons({env:r?"sandbox":"production",fundingSource:l,style:h,createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});o.isEligible()?(o.render(`#${n}`),u=!0):c.FUNDING.CREDIT&&d&&"function"==typeof d&&d()}}),c&&u||this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){var i;return ca(this,void 0,void 0,function*(){const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(n),u=r?r.cartAmount:s.getCartOrThrow().cartAmount,l=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(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===(i=c.initializationData)||void 0===i?void 0:i.intent})}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return ca(this,void 0,void 0,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}createBuyNowCart(e){return ca(this,void 0,void 0,function*(){if(!e)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new yr}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!xr(e))throw e;n(e)}}const la=mr(e=>{const t=window,i=new Dr(e),r=new ta(new Kr(le(),t,i),t),o=new da(e);return new ua(e,n(),r,o,t)},[{id:"braintreepaypalcredit"}]);var ha=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class pa{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n}initialize(e){return ha(this,void 0,void 0,function*(){const{containerId:t,methodId:n}=e;if(!n)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),{clientToken:r,initializationData:o,config:a}=i.getPaymentMethodOrThrow(n);if(!r||!o)throw new Xi(Zi.MissingPaymentMethod);this.braintreeSdk.initialize(r);const s=yield this.braintreeSdk.getBraintreeVisaCheckout(),{currency:{code:d},cartAmount:c}=i.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=>ha(this,void 0,void 0,function*(){yield this.paymentSuccess(s,e)}))})}deinitialize(){return Promise.resolve()}paymentSuccess(e,t){return ha(this,void 0,void 0,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.toVisaCheckoutAddress(i),billingAddress:a=this.toVisaCheckoutAddress(r)}=e;return this.postForm(Object.assign(Object.assign({},e),{shippingAddress:o,billingAddress:a}),t)})})}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{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:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}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 ma=mr(e=>{const t=window,i=new Dr(e),r=new Vr(new Kr(le(),t,i));return new pa(e,n(),r)},[{id:"braintreevisacheckout"}]);function ga(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,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 ya(e){const{email:t,phone:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}var fa=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};const va=e=>{const{color:t,height:n}=e;return{backgroundColor:(i=t||"",i===Qo.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("/app/assets/img/payment-providers/venmo-logo-${t===Qo.WHITE?Qo.BLUE:Qo.WHITE}.svg")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${n||40}px`,minWidth:"150px",height:"100%",width:"100%",border:t===Qo.WHITE?"1px solid black":"none"};var i};class Sa{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n,this.onError=T}initialize(e){return fa(this,void 0,void 0,function*(){const{braintreevenmo:t,containerId:n,methodId:i}=e;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i),{clientToken:o,initializationData:a}=r,{paymentButtonStyles:s}=a,{cartButtonStyles:d}=s||{},c=(null==t?void 0:t.style)||d;if(!o||!a)throw new Xi(Zi.MissingPaymentMethod);if(!n)throw new gr('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(o);try{const e=yield this.braintreeSdk.getVenmoCheckoutOrThrow();this.renderVenmoButton(e,n,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 Rr}(e))&&this.handleInitializationVenmoError(e,n)}})}deinitialize(){return fa(this,void 0,void 0,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}handleError(e){throw new Error(e.message)}createBuyNowCart(e){return fa(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 Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new yr}}})}handleInitializationVenmoError(e,t){return this.removeVenmoContainer(t),this.onError(e)}removeVenmoContainer(e){const t=document.getElementById(e);t&&t.remove()}renderVenmoButton(e,t,n,i){const r=document.getElementById(t),{color:o}=i||{};if(!r)throw new gr("Unable to create wallet button without valid container ID.");r.setAttribute("aria-label","Venmo"),Object.assign(r.style,va(i||{})),r.addEventListener("click",()=>fa(this,void 0,void 0,function*(){r.setAttribute("disabled","true");const t=yield this.createBuyNowCart(n);e.tokenize&&e.tokenize((e,n)=>fa(this,void 0,void 0,function*(){r.removeAttribute("disabled"),e&&this.onError(e),yield this.handlePostForm(n,null==t?void 0:t.id)}))})),o===Qo.BLUE&&(r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#0a7fc2"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor=va(i||{}).backgroundColor}))}handlePostForm(e,t){return fa(this,void 0,void 0,function*(){const{deviceData:n}=yield this.braintreeSdk.getDataCollectorOrThrow(),{nonce:i,details:r}=e;this.formPoster.postForm("/checkout.php",Object.assign({nonce:i,provider:"braintreevenmo",payment_type:"paypal",device_data:n,action:"set_external_checkout",billing_address:JSON.stringify(ga(r)),shipping_address:JSON.stringify(ya(r))},t&&{cart_id:t}))})}}const Ca=mr(e=>{const t=window,i=le(),r=new Dr(e),o=new Kr(i,t,r),a=new Vr(o);return new Sa(e,n(),a)},[{id:"braintreevenmo"}]);var Ia;!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"}(Ia||(Ia={}));const _a=function(e,t,n){return t&&n?wa(0,t,n):function(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(n=>{const i=Object.getOwnPropertyDescriptor(e.prototype,n);i&&"constructor"!==n&&Object.defineProperty(t.prototype,n,wa(e.prototype,n,i))}),t}(e)};function wa(e,t,n){if("function"!=typeof n.value)return n;let i=n.value;return{get(){const e=i.bind(this);return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e},set(e){i=e}}}class ba{constructor(e){if(!e)throw new Error("Currency settings missing");const{decimalPlaces:t,symbolLocation:n,symbol:i,thousandsSeparator:r,decimalSeparator:o}=e;if("string"!=typeof n||"string"!=typeof i||"string"!=typeof r||"string"!=typeof o||"string"!=typeof t)throw new gr("Invalid currency settings provided");this._decimalPlaces=parseInt(t,10),this._symbolLocation=n,this._symbol=i,this._thousandsSeparator=r,this._decimalSeparator=o}format(e){if("number"!=typeof e)throw new gr("Invalid amount provided");const t=this._formatNumber(e),n=this._formatCurrency(t);return e<0?`-${n}`:n}_formatNumber(e){const t=Math.abs(e),[n,i=""]=this._toFixed(t,this._decimalPlaces).split("."),r=n.replace(/\B(?=(\d{3})+(?!\d))/g,this._thousandsSeparator);return this._decimalPlaces<1?r:[r,i].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 Ea=class{constructor(e){this._storeConfig=e,this._customerFormatter=new ba(this._storeConfig.shopperCurrency),this._storeFormatter=new ba(this._storeConfig.currency)}toCustomerCurrency(e){const t=this._storeConfig.shopperCurrency.exchangeRate;return this._customerFormatter.format(e*t)}toStoreCurrency(e){return this._storeFormatter.format(e)}};Ea=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([_a],Ea);const Pa=Ea;var Oa,Aa,Ta,ka,Da,Ra,Ma,Na,La;function za(e){return e in Ra}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(Oa||(Oa={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Aa||(Aa={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(Ta||(Ta={})),function(e){e.pill="pill",e.rect="rect"}(ka||(ka={})),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"}(Ra||(Ra={})),function(e){e.OFFER="OFFER",e.PAYMENT_AUTHORIZATION="PAYMENT_AUTHORIZATION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.SHIPPING_OPTION="SHIPPING_OPTION"}(Ma||(Ma={})),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"}(Na||(Na={})),function(e){e.INITIALIZE="INITIALIZE",e.SHIPPING_OPTION="SHIPPING_OPTION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.OFFER="OFFER"}(La||(La={}));var Ua=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Fa{constructor(e,t){this._gatewayIdentifier=e,this._paymentIntegrationService=t,this._isBuyNowFlow=!1}mapToShippingAddressRequestBody({shippingAddress:e}){if(!e)return;const{company:t="",phone:n=""}=this._paymentIntegrationService.getState().getShippingAddress()||{};return this._mapToAddressRequestBody(e,t,n)}mapToBillingAddressRequestBody(e){const{billingAddress:t}=e.paymentMethodData.info;if(!t)return;const{company:n="",phone:i="",email:r,customFields:o=[]}=this._paymentIntegrationService.getState().getBillingAddress()||{};return Object.assign(Object.assign({},this._mapToAddressRequestBody(t,n,i,o)),{email:r||e.email})}mapToExternalCheckoutData(e){var t;const{paymentMethodData:{tokenizationData:{token:n},info:{cardNetwork:i,cardDetails:r}}}=e;if(!n)throw new Xi(Zi.MissingPaymentToken);return Promise.resolve(Object.assign({nonce:n,card_information:{type:i,number:r}},this._isBuyNowFlow&&{cart_id:null===(t=this._paymentIntegrationService.getState().getCart())||void 0===t?void 0:t.id}))}getRequiredData(){var e;return Ua(this,void 0,void 0,function*(){const t={emailRequired:!0};if(!this._isShippingAddressRequired())return t;const n=yield this._paymentIntegrationService.loadShippingCountries(),i=null===(e=n.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code);return Object.assign(Object.assign({},t),{shippingAddressRequired:!0,shippingAddressParameters:Object.assign({phoneNumberRequired:!0},i&&{allowedCountryCodes:i}),shippingOptionRequired:!0})})}getCallbackIntents(){return this._isShippingAddressRequired()?[Ma.OFFER,Ma.SHIPPING_ADDRESS,Ma.SHIPPING_OPTION]:[Ma.OFFER]}getCallbackTriggers(){const e=this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-2875.googlepay_coupons_handling"]||!1;return{availableTriggers:[La.INITIALIZE,La.SHIPPING_ADDRESS,La.SHIPPING_OPTION,...e?[La.OFFER]:[]],initializationTrigger:[La.INITIALIZE],addressChangeTriggers:[La.INITIALIZE,La.SHIPPING_ADDRESS],shippingOptionsChangeTriggers:[La.SHIPPING_OPTION],offerChangeTriggers:e?[La.OFFER]:[]}}getNonce(e){var t;const n=null===(t=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.nonce;if(!n)throw new Xi(Zi.MissingPaymentToken);return Promise.resolve(n)}extraPaymentData(){return Promise.resolve(void 0)}getMerchantInfo(){const{googleMerchantName:e,googleMerchantId:t,platformToken:n}=this.getGooglePayInitializationData();return{merchantName:e,merchantId:t,authJwt:n}}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 gr("Unable to proceed, gatewayMerchantId is missing.");return{gateway:this._gatewayIdentifier,gatewayMerchantId:e}}getCardParameters(){return{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:this.getPaymentMethod().supportedCards.filter(za).map(e=>Ra[e]),billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}initialize(e,t,n){return this._getPaymentMethodFn=e,this._isBuyNowFlow=Boolean(t),this._currencyCode=n,this._isBuyNowFlow&&this._getCurrencyCodeOrThrow(),Promise.resolve()}handleShippingAddressChange(e){var t,n,i,r;return Ua(this,void 0,void 0,function*(){e&&(e.name=e.name||"",e.address1=e.address1||"");const o=this.mapToShippingAddressRequestBody({shippingAddress:e});o&&(yield this._paymentIntegrationService.updateShippingAddress(o));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 Pa(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===(n=d.selectedShippingOption)||void 0===n?void 0:n.id)||(null==l?void 0:l.id)||(null===(i=u[0])||void 0===i?void 0:i.id);return!(null===(r=d.selectedShippingOption)||void 0===r?void 0:r.id)&&u[0]&&(yield this.handleShippingOptionChange((null==l?void 0:l.id)||u[0].id)),{defaultSelectedOptionId:e,shippingOptions:u}}})}handleShippingOptionChange(e){return Ua(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:n}=t().currency;return L(e().outstandingBalance,n).toFixed(n)}handleCoupons(e){return Ua(this,void 0,void 0,function*(){const{redemptionCodes:t=[]}=e,{offers:n}=this.getAppliedCoupons();let i;return yield t.reduce((e,t)=>Ua(this,void 0,void 0,function*(){if(yield e,n.some(({redemptionCode:e})=>e===t))return;const r=yield this.applyCoupon(t);r&&(i=r)}),Promise.resolve()),yield n.reduce((e,n)=>Ua(this,void 0,void 0,function*(){yield e,t.includes(n.redemptionCode)||(yield this._paymentIntegrationService.removeCoupon(n.redemptionCode))}),Promise.resolve()),{newOfferInfo:this.getAppliedCoupons(),error:i}})}getAppliedCoupons(){const e=this._paymentIntegrationService.getState(),{coupons:t}=e.getCheckout()||{};return{offers:(t||[]).map(e=>{const{displayName:t,code:n}=e;return{redemptionCode:n,description:t}})}}applyCoupon(e){return Ua(this,void 0,void 0,function*(){let t;try{yield this._paymentIntegrationService.applyCoupon(e)}catch(e){return e instanceof Error&&(t={reason:Na.OFFER_INVALID,message:e.message,intent:La.OFFER}),t}})}getGooglePayInitializationData(){return tr(this.getPaymentMethod().initializationData,()=>new gr("Missing initialization data."))}getPaymentMethod(){return tr(this._getPaymentMethodFn,()=>new nr(Ji.PaymentNotInitialized))()}getGatewayIdentifier(){return this._gatewayIdentifier}setGatewayIdentifier(e){this._gatewayIdentifier=e||this.getGatewayIdentifier()}_isShippingAddressRequired(){const{getCartOrThrow:e,getStoreConfig:t,getShippingAddress:n}=this._paymentIntegrationService.getState();return void 0===n()&&(i=e(),r=t(),!!i&&(!!i.lineItems.physicalItems.some(e=>e.isShippingRequired)||!(!r||!i.lineItems.customItems)&&i.lineItems.customItems.length>0));var i,r}_mapToAddressRequestBody(e,t,n,i){const{name:r,address1:o,address2:a,address3:s,locality:d,administrativeArea:c,countryCode:u,postalCode:l,phoneNumber:h}=e,[p,m]=this._getFirstAndLastName(r);return{firstName:p,lastName:m,company:t,address1:o,address2:`${a} ${s}`.trim(),city:d||c,stateOrProvince:c,stateOrProvinceCode:c,countryCode:u,postalCode:l,phone:h||n,customFields:i||[]}}_getFirstAndLastName(e){const t=e.split(" ");return 1===t.length?[e,""]:[t.slice(0,-1).join(" "),t[t.length-1]]}_getCurrencyCodeOrThrow(){return tr(this._currencyCode,()=>new gr('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}_getGooglePayShippingOption({id:e,cost:t,description:n,additionalDescription:i}){var r;const o=null===(r=this._currencyService)||void 0===r?void 0:r.toCustomerCurrency(t);return this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-3540.googlepay_new_shipping_options_description"]?{id:e,label:`${o||t} ${n}`,description:i}:{id:e,label:n,description:o||t}}}var Ba=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class xa extends Fa{constructor(e,t){super("braintree",e),this._braintreeSdk=t,this._methodId=Ia.BRAINTREE,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return Ba(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);let r=i.getPaymentMethod.call(this);if(r.clientToken||(r=(yield this._service.loadPaymentMethod(this._methodId)).getPaymentMethodOrThrow(this._methodId)),!r.clientToken||!r.initializationData)throw new Xi(Zi.MissingPaymentMethod);return this._braintreeSdk.initialize(r.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 n;return Ba(this,void 0,void 0,function*(){const i=yield t.getNonce.call(this,e),{clientToken:r,initializationData:o}=t.getPaymentMethod.call(this);if(!r||!o||!(null===(n=o.card_information)||void 0===n?void 0:n.bin))throw new Xi(Zi.MissingPaymentMethod);const{isThreeDSecureEnabled:a,card_information:{bin:s,isNetworkTokenized:d}}=o;if(a&&!d){const e=yield this._braintreeSdk.getBraintreeThreeDS(),{orderAmount:t}=this._service.getState().getOrderOrThrow();return(yield this._braintreePresent3DSChallenge(e,t,i,s)).nonce}return i})}extraPaymentData(){return Ba(this,void 0,void 0,function*(){return{deviceSessionId:yield this._getBraintreeDeviceData()}})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Ba(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new gr("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 Xi(Zi.MissingPaymentToken)}(i),n.nonce=i.androidPayCards[0].nonce,n.card_information.bin=i.androidPayCards[0].details.bin,n.card_information.isNetworkTokenized=i.androidPayCards[0].details.isNetworkTokenized,n})}getCardParameters(){return super.getCardParameters()}getPaymentGatewayParameters(){const e=Object.create(null,{getMerchantInfo:{get:()=>super.getMerchantInfo},getTransactionInfo:{get:()=>super.getTransactionInfo},getRequiredData:{get:()=>super.getRequiredData}});return Ba(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 Xi(Zi.MissingPaymentMethod);return this._braintreeGooglePayment}_getBraintreeDeviceData(){return Ba(this,void 0,void 0,function*(){const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e})}_braintreePresent3DSChallenge(e,t,n,i){return new Yo(e.verifyCard({amount:t,bin:i,nonce:n,onLookupComplete:(e,t)=>{t()}})).promise}}class qa 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 ja=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ga{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t,n;return ja(this,void 0,void 0,function*(){if(!e.methodId||(i=e.methodId,!Object.values(Ia).includes(i)))throw new gr('Unable to proceed because "methodId" is not a valid key.');var i;if(this._methodId=e.methodId,!e.containerId)throw new gr('Unable to proceed because "containerId" is not a valid key.');const r=e[this._getMethodOrThrow()];if(!r)throw new gr("Unable to proceed without valid options.");const{buyNowInitializeOptions:o,currencyCode:a,buttonColor:s,buttonType:d,onError:c}=r;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,o){if(!a)throw new gr('Unable to initialize payment because "options.currencyCode" argument is not provided.');this._currencyCode=a,this._buyNowInitializeOptions=o,yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions(),!!o,a)}else yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions());this._paymentButton=null!==(n=this._paymentButton)&&void 0!==n?n: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=>ja(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 n=t;if(function(e){return"object"==typeof e&&null!==e&&"statusCode"in e}(t)){if("CANCELED"===t.statusCode)throw new Qr;n=new qa(JSON.stringify(t))}throw null==e||e(new qa("An error occurred while requesting your Google Pay payment details.")),n}})}_interactWithPaymentSheet(){var e;return ja(this,void 0,void 0,function*(){const t=yield this._googlePayPaymentProcessor.showPaymentSheet(),n=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(t),i=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(t),r="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;n&&(yield this._paymentIntegrationService.updateBillingAddress(n)),i&&!(null===(e=this._buyNowCart)||void 0===e?void 0:e.lineItems.digitalItems.length)&&(yield this._paymentIntegrationService.updateShippingAddress(i)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodOrThrow(),t,r)})}_getGooglePayClientOptions(){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:e,shippingAddress:t,shippingOptionData:n,offerData:i})=>ja(this,void 0,void 0,function*(){const{availableTriggers:r,addressChangeTriggers:o,shippingOptionsChangeTriggers:a,offerChangeTriggers:s}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!r.includes(e))return;const d=o.includes(e)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(t):void 0;a.includes(e)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(n.id));const{newOfferInfo:c,error:u}=s.includes(e)?yield this._googlePayPaymentProcessor.handleCoupons(i):{},l=u;return this._buyNowInitializeOptions?this._getBuyNowTransactionInfo(d,c,l):this._getTransactionInfo(d,c,l)})}}}_createBuyNowCartOrThrow(e){return ja(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 yr(e);throw e}}})}_getBuyNowTransactionInfo(e,t,n){if(!this._buyNowCart)return;const{cartAmount:i}=this._buyNowCart,r=this._googlePayPaymentProcessor.getTotalPrice();return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:this._getCurrencyCodeOrThrow(),totalPrice:r||String(i),totalPriceStatus:Da.FINAL})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})}_getTransactionInfo(e,t,n){return ja(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadCheckout();const i=this._googlePayPaymentProcessor.getTotalPrice(),{code:r}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:r,totalPriceStatus:Da.FINAL,totalPrice:i})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})})}_getMethodOrThrow(){return tr(this._methodId,()=>new nr(Ji.PaymentNotInitialized))}_getCurrencyCodeOrThrow(){return tr(this._currencyCode,()=>new gr('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}}var Ha=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Va{constructor(e,t,n,i){this._scriptLoader=e,this._gateway=t,this._requestSender=n,this._formPoster=i,this._baseRequest={apiVersion:2,apiVersionMinor:0}}initialize(e,t,n,i){return Ha(this,void 0,void 0,function*(){this._paymentsClient=yield this._scriptLoader.getGooglePaymentsClient(e().config.testMode,t),yield this._gateway.initialize(e,n,i),this._buildButtonPayloads()})}initializeWidget(){return Ha(this,void 0,void 0,function*(){yield this._buildWidgetPayloads(),yield this._determineReadinessToPay(),this._prefetchGooglePaymentData()})}getNonce(e){return this._gateway.getNonce(e)}extraPaymentData(){return Ha(this,void 0,void 0,function*(){return this._gateway.extraPaymentData()})}addPaymentButton(e,t){const n=document.querySelector(`#${e}`);if(!n)return;const i=this._getPaymentsClient().createButton(Object.assign(Object.assign({},t),{allowedPaymentMethods:[this._getBaseCardPaymentMethod()]}));return n.appendChild(i)}showPaymentSheet(){return Ha(this,void 0,void 0,function*(){const e=this._getPaymentDataRequest();return this._getPaymentsClient().loadPaymentData(e)})}setExternalCheckoutXhr(e,t){return Ha(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t)})}setExternalCheckoutForm(e,t,n){return Ha(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t,!0,n)})}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 Ha(this,void 0,void 0,function*(){yield this._requestSender.get(`/remote-checkout/${e}/signout`)})}getCallbackTriggers(){return this._gateway.getCallbackTriggers()}handleShippingAddressChange(e){return Ha(this,void 0,void 0,function*(){return this._gateway.handleShippingAddressChange(e)})}handleShippingOptionChange(e){return Ha(this,void 0,void 0,function*(){yield this._gateway.handleShippingOptionChange(e)})}handleCoupons(e){return Ha(this,void 0,void 0,function*(){return this._gateway.handleCoupons(e)})}getTotalPrice(){return this._gateway.getTotalPrice()}_setExternalCheckout(e,t,n=!1,i){return Ha(this,void 0,void 0,function*(){const r="/checkout.php",o=Object.assign({action:"set_external_checkout",provider:e},yield this._gateway.mapToExternalCheckoutData(t));if(n)return new Promise(e=>{this._formPoster.postForm(i?`${i}/checkout`:r,Object.assign(Object.assign({},o),{card_information:JSON.stringify(o.card_information)}),e)});yield this._requestSender.post(r,{headers:Object.assign({Accept:"text/html","Content-Type":"application/x-www-form-urlencoded"},br),body:o})})}_prefetchGooglePaymentData(){const e=this._getPaymentDataRequest();e.transactionInfo=this._gateway.getTransactionInfo(),this._getPaymentsClient().prefetchPaymentData(e)}_determineReadinessToPay(){return Ha(this,void 0,void 0,function*(){try{const{result:e}=yield this._getPaymentsClient().isReadyToPay(this._getIsReadyToPayRequest());if(!1===e)throw new qa("Google Pay is not supported by the current device and browser, please try another payment method.")}catch(e){if(e instanceof qa)throw e;throw new qa}})}_buildButtonPayloads(){this._baseCardPaymentMethod={type:"CARD",parameters:this._gateway.getCardParameters()}}_buildWidgetPayloads(){return Ha(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 tr(e,()=>new nr(Ji.PaymentNotInitialized))}}class Ya{constructor(e){this._scriptLoader=e,this._window=window}getGooglePaymentsClient(e=!1,t){return n=this,i=void 0,o=function*(){if(yield this._scriptLoader.loadScript("https://pay.google.com/gp/p/js/pay.js"),!this._window.google)throw new hr;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((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}function Wa(){return new Ya(le())}const $a=mr(t=>{const i=e(),r=window,o=new Dr(t),a=new Vr(new Kr(le(),r,o));return new Ga(t,new Va(Wa(),new xa(t,a),i,n()))},[{id:"googlepaybraintree"}]);var Ka=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Qa{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new hr}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new hr;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new hr}return this.window.paypalApms})}getPayPalMessages(e,t){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new hr;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return Ka(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,attributionId:d}=r;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:o},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=r,h=u||n;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:o},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:o,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=n,l=u,h=c.filter(e=>!u.includes(e));return{options:Object.assign({"client-id":r,"merchant-id":o,"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:i},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:o,isDeveloperModeApplicable:a,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":r,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":o}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function Za(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 Xi(Zi.MissingPaymentMethod)}var Ja=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Xa extends Fa{constructor(e,t){super("paypalsb",e),this.payPalCommerceSdk=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var r,o,a,s,d;return Ja(this,void 0,void 0,function*(){const c=null!==(o=null===(r=this.service.getState().getStoreConfig())||void 0===r?void 0:r.currency.code)&&void 0!==o?o:n;if(!c)throw new Xi(Zi.MissingPaymentMethod);yield i.initialize.call(this,e,t,c);const u=i.getPaymentMethod.call(this);if(!u.initializationData)throw new Xi(Zi.MissingPaymentMethod);Za(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 Ja(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}const es=mr(t=>new Ga(t,new Va(Wa(),new Xa(t,new Qa(le())),e(),n())),[{id:"googlepaypaypalcommerce"}]);var ts=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ns extends Fa{constructor(e,t){super("googlepay_bigcommerce_payments",e),this.payPalSdkHelper=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var r,o,a,s,d;return ts(this,void 0,void 0,function*(){const c=null!==(o=null===(r=this.service.getState().getStoreConfig())||void 0===r?void 0:r.currency.code)&&void 0!==o?o:n;if(!c)throw new Xi(Zi.MissingPaymentMethod);yield i.initialize.call(this,e,t,c);const u=i.getPaymentMethod.call(this);if(!u.initializationData)throw new Xi(Zi.MissingPaymentMethod);Za(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 ts(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}const is=mr(t=>new Ga(t,new Va(Wa(),new ns(t,new Eo(le())),e(),n())),[{id:"googlepay_bigcommerce_payments"}]),rs=mr(t=>{const i=e();return new Ga(t,new Va(Wa(),new Fa("adyen",t),i,n()))},[{id:"googlepayadyenv2"}]),os=mr(t=>{const i=e();return new Ga(t,new Va(Wa(),new Fa("adyen",t),i,n()))},[{id:"googlepayadyenv3"}]);class as extends Fa{constructor(e){super("authorizenet",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return function(e){if(!function(e){return"paymentGatewayId"in e}(e))throw new Xi(Zi.MissingPaymentMethod)}(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.paymentGatewayId}}}const ss=mr(t=>new Ga(t,new Va(Wa(),new as(t),e(),n())),[{id:"googlepayauthorizenet"}]),ds=e=>"object"==typeof e&&null!==e&&"body"in e;function cs(e){if(!function(e){return"checkoutcomkey"in e}(e))throw new Xi(Zi.MissingPaymentMethod)}var us=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ls extends Fa{constructor(e,t){super("checkoutltd",e),this._requestSender=t}processAdditionalAction(e){return new Promise((t,n)=>{if(ds(e)&&function(e){var t;if("object"!=typeof e||null===e)return!1;const n=e;return"string"==typeof(null===(t=n.three_ds_result)||void 0===t?void 0:t.acs_url)&&"string"==typeof n.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);n(e)})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return us(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new gr("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 Xi(Zi.MissingPaymentToken)}(i),n.nonce=yield this._tokenize(i),n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return cs(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.checkoutcomkey}}_tokenize(e){return us(this,void 0,void 0,function*(){const t=this.getPaymentMethod().config.testMode?"https://api.sandbox.checkout.com/tokens":"https://api.checkout.com/tokens",n=this.getGooglePayInitializationData();cs(n);const{body:i}=yield this._requestSender.post(t,{credentials:!1,body:{type:"googlepay",token_data:e},headers:{Authorization:n.checkoutcomkey,"Content-Type":wr.Json,"X-XSRF-TOKEN":null}});return i.token})}}const hs=mr(t=>{const i=e();return new Ga(t,new Va(Wa(),new ls(t,i),i,n()))},[{id:"googlepaycheckoutcom"}]);class ps extends Fa{constructor(e){super("cybersource",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}const ms=mr(t=>new Ga(t,new Va(Wa(),new ps(t),e(),n())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]);class gs extends Fa{constructor(e){super("chase",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}const ys=mr(t=>new Ga(t,new Va(Wa(),new gs(t),e(),n())),[{id:"googlepayorbital"}]);function fs(e){if(!function(e){return"stripeConnectedAccount"in e&&"stripePublishableKey"in e&&"stripeVersion"in e}(e))throw new Xi(Zi.MissingPaymentMethod)}var vs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ss extends Fa{constructor(e,t){super("stripe",e),this.paymentIntegrationService=e,this.scriptLoader=t}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return vs(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new gr("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 Xi(Zi.MissingPaymentToken)}(i),n.nonce=i.id,n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();fs(e);const{stripeVersion:t,stripePublishableKey:n,stripeConnectedAccount:i}=e;return{gateway:this.getGatewayIdentifier(),"stripe:version":t,"stripe:publishableKey":`${n}/${i}`}}processAdditionalAction(e,t){var n,i;return vs(this,void 0,void 0,function*(){if(!t)throw new Ho(["payment"]);if(!ds(e)||("object"!=typeof(r=e.body)||null===r||!("three_ds_result"in r)||!("errors"in r)))throw e;var r;const o=this.paymentIntegrationService.getState(),a=null===(n=o.getStoreConfig())||void 0===n?void 0:n.checkoutSettings.features["STRIPE-476.enable_stripe_googlepay_3ds"];if(z(e.body.errors,{code:"three_d_secure_required"})&&a){const n=this.getGooglePayInitializationData();fs(n);const{stripePublishableKey:r,stripeConnectedAccount:o}=n;this.stripeUPEClient=yield this.loadStripeJs(r,o);const a=e.body.three_ds_result.token;let s,d=!1;try{s=yield this.stripeUPEClient.confirmCardPayment(a)}catch(e){try{s=yield this.stripeUPEClient.retrievePaymentIntent(a)}catch(e){d=!0}}if(null==s?void 0:s.error){if(this._throwDisplayableStripeError(s.error),this._isCancellationError(s.error))throw new Qr;throw new qa}if(!(null==s?void 0:s.paymentIntent)&&!d)throw new _e;return this.paymentIntegrationService.submitPayment({methodId:t,paymentData:{nonce:(null===(i=null==s?void 0:s.paymentIntent)||void 0===i?void 0:i.id)||a}})}throw e})}loadStripeJs(e,t){return vs(this,void 0,void 0,function*(){return this.stripeUPEClient?this.stripeUPEClient:this.scriptLoader.getStripeClient(e,t)})}_isCancellationError(e){var t,n;return e&&-1!==(null===(n=null===(t=e.payment_intent.last_payment_error)||void 0===t?void 0:t.message)||void 0===n?void 0:n.indexOf("canceled"))}_throwDisplayableStripeError(e){if(g(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}}var Cs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Is{constructor(e,t=window){this.scriptLoader=e,this.stripeWindow=t}getStripeClient(e,t,n){return Cs(this,void 0,void 0,function*(){let i=this.stripeWindow.bcStripeClient;return i||(i=(yield this.load())(e,{stripeAccount:t,locale:n,betas:["payment_element_beta_2","alipay_pm_beta_1","link_default_integration_beta_1","shipping_address_element_beta_1","address_element_beta_1"],apiVersion:"2020-03-02;alipay_beta=v1;link_beta=v1"}),Object.assign(this.stripeWindow,{bcStripeClient:i})),i})}load(){return Cs(this,void 0,void 0,function*(){if(this.stripeWindow.Stripe||(yield this.scriptLoader.loadScript("https://js.stripe.com/v3/")),!this.stripeWindow.Stripe)throw new hr;return this.stripeWindow.Stripe})}}const _s=mr(t=>new Ga(t,new Va(Wa(),new Ss(t,new Is(le())),e(),n())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]);class ws extends Fa{constructor(e){super("worldpay",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}const bs=mr(t=>new Ga(t,new Va(Wa(),new ws(t),e(),n())),[{id:"googlepayworldpayaccess"}]);function Es(){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 Ps=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Os extends Fa{constructor(e,t){super("worldlinena",e),this.formPoster=t}extraPaymentData(){return Ps(this,void 0,void 0,function*(){return Promise.resolve({browser_info:Es()})})}processAdditionalAction(e){return Ps(this,void 0,void 0,function*(){if(!function(e){return ds(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:n,payer_auth_request:i,merchant_data:r}=t||{};if(!n||!i||!r)throw new Ho(["formUrl","threeDSSessionData","creq"]);return new Promise(e=>{this.formPoster.postForm(n,{threeDSSessionData:i,creq:r},e,"_top")})})}}const As=mr(t=>new Ga(t,new Va(Wa(),new Os(t,n()),e(),n())),[{id:"googlepaytdonlinemart"}]);var Ts,ks,Ds,Rs,Ms,Ns,Ls;!function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(Ts||(Ts={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(ks||(ks={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Ds||(Ds={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(Rs||(Rs={})),function(e){e.pill="pill",e.rect="rect"}(Ms||(Ms={})),(Ns||(Ns={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Ls||(Ls={}));var zs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Us{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=i}loadPayPalSdk(e,t,n,i){return zs(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,o,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new hr;return this.paypalSdk}createBuyNowCartOrThrow(e){return zs(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new yr}})}createOrder(e,t){return zs(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return zs(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(){return zs(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:n.availableShippingOptions,cartId:t.id,selectedShippingOption:n.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return zs(this,void 0,void 0,function*(){try{const{status:n}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _e}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xi(Zi.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===oo.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return zs(this,void 0,void 0,function*(){const i={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:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}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,n;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===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:r}=e||{},o={color:t&&Rs[t]?t:void 0,height:this.getValidHeight(n),label:i&&Ds[i]?i:void 0,shape:r&&Ms[r]?r:void 0};return D(o,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 Fs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Bs{constructor(e){this.requestSender=e}createOrder(e,t){return Fs(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return Fs(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:n,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return Fs(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}var xs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class qs{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return xs(this,void 0,void 0,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e,t=!1){return xs(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.paypal)throw new hr;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new Xi(Zi.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}=o,v=h||n,S="paypalcommercecreditcards"===i,C=S?["card"]:[],I=p?["credit","paylater"]:[],_=n||!v,w=l?["venmo"]:[],b=_?y:[],E=f?["googlepay"]:[],P=n?["card-fields"]:[],O=[...S?[]:["card"],...p?[]:["credit","paylater"],...l?[]:["venmo"],..._?g.filter(e=>!y.includes(e)):g],A=[...C,...I,...w,...b];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":A.length>0?A:void 0,"disable-funding":O.length>0?O:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...E,...P],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":r}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const js=t=>{const{getHost:i}=t.getState();return new Us(n(),t,new Bs(e({host:i()})),new qs(le()))};var Gs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Hs{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){var t;return Gs(this,void 0,void 0,function*(){const{paypalcommerce:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(o&&!n.currencyCode)throw new gr('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new gr('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n,o)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){var r,o;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:c}=n,u=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:h,isAppSwitchEnabled:p}=l.initializationData||{},m=Object.assign(Object.assign({},!i&&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,n)=>this.onHostedCheckoutApprove(e,n,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===(r=v.hasReturned)||void 0===r?void 0:r.call(v))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(o=v.resume)||void 0===o||o.call(v):v.render(`#${e}`):c&&"function"==typeof c?c():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return Gs(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Gs(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalCommerceIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Gs(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 Gs(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 Vs=mr(e=>new Hs(e,js(e)),[{id:"paypalcommerce"}]),Ys=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 Ws=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class $s{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=n}initialize(e){var t;return Ws(this,void 0,void 0,function*(){const{paypalcommercecredit:n,containerId:i,methodId:r}=e,{buyNowInitializeOptions:o,currencyCode:a,messagingContainerId:s}=n||{},d=!!o;if(!r)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(d&&!a)throw new gr('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(d&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new gr('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(r,u,!1),this.renderButton(i,r,n);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(r),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},n=t&&t.find(({id:e})=>"cart"===e);if(!(null==n?void 0:n.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 i=yield this.paypalCommerceSdk.getPayPalMessages(e,u);this.renderMessages(i,s,n)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},p=Object.assign(Object.assign({},!u&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)}),m=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let g=!1;m.forEach(t=>{if(!g){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r)},l),i&&h),c&&p),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),g=!0):a&&"function"==typeof a&&a()}}),g||this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return Ws(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Ws(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalCommerceIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Ws(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 Ws(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,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:Ys(n)};e.Messages(i).render(`#${t}`)}}const Ks=mr(e=>new $s(e,js(e),new Qa(ue())),[{id:"paypalcommercecredit"}]);var Qs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Zs{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Qs(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(a&&!o)throw new gr('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new gr('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?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):o&&"function"==typeof o?o():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===Rs.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return Qs(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Js=mr(e=>new Zs(e,js(e)),[{id:"paypalcommercevenmo"}]);var Xs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ed{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Xs(this,void 0,void 0,function*(){const{paypalcommercealternativemethods:t,containerId:n,methodId:i}=e,{apm:r,buyNowInitializeOptions:o,currencyCode:a}=t||{},s=!!o;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');if(!r)throw new gr('Unable to initialize payment because "options.paypalcommercealternativemethods.apm" argument is not provided.');if(s&&!a)throw new gr('Unable to initialize payment because "options.paypalcommercealternativemethods.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new gr('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.paypalCommerceIntegrationService.loadPayPalSdk(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{apm:i,buyNowInitializeOptions:r,style:o,onEligibilityFailure:a}=n,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(i))throw new gr('Unable to initialize PayPal button because "options.paypalcommercealternativemethods.apm" argument is not valid funding source.');const d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethod"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:i,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o)},d),r&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return Xs(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const td=mr(e=>new ed(e,js(e)),[{id:"paypalcommercealternativemethods"}]);var nd,id,rd,od,ad,sd;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(nd||(nd={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(id||(id={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black"}(rd||(rd={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(od||(od={})),function(e){e.PILL="pill",e.RECT="rect"}(ad||(ad={})),function(e){e.ACKNOWLEDGE="ACKNOWLEDGE",e.FINALIZE="FINALIZE",e.INITIALIZE="INITIALIZE"}(sd||(sd={}));var dd=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class cd{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalExpressScriptLoader=t,this.formPoster=n}initialize(e){return dd(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!e.paypal)throw new gr;if(!t.config.merchantId)throw new Xi(Zi.MissingPaymentMethod);const n=yield this.paypalExpressScriptLoader.loadPaypalSDK(t.config.merchantId);this.renderButton(e,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t){const{containerId:n,methodId:i,paypal:r}=e,{allowCredit:o,clientId:a,onPaymentError:s,shouldProcessPayment:d,style:c}=r,u=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!u.config.merchantId)throw new Xi(Zi.MissingPaymentMethod);const l=u.config.merchantId,h=u.config.testMode?"sandbox":"production",p={[h]:a},m=t.FUNDING.CREDIT||"credit",g=o?[m]:[],y=o?[]:[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,i,t,d)},n)}getStyle(e){const{color:t,fundingicons:n,label:i,layout:r,shape:o,size:a,tagline:s}=e||{};return{color:t,fundingicons:n,label:i,layout:r,shape:o||ad.RECT,size:"small"===a?id.RESPONSIVE:a,tagline:s}}setupPayment(e,t,n){return dd(this,void 0,void 0,function*(){if(!t)throw new nr(Ji.CheckoutButtonNotInitialized);try{const n=yield this.paymentIntegrationService.loadDefaultCheckout(),{id:i}=n.getCartOrThrow(),r=n.getHost()||"";return(yield t.request.post(`${r}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:i},{headers:Object.assign({"X-API-INTERNAL":Ir},br)})).id}catch(e){throw n&&e instanceof Ce&&n(e),e}})}tokenizePayment(e,t,n,i){return dd(this,void 0,void 0,function*(){if(!n)throw new nr(Ji.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new Xi(Zi.MissingPayment);const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),o=yield n.payment.get(e.paymentID);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:r.id,action:i?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(o.payer.payer_info)})})}}class ud{constructor(e){this.scriptLoader=e,this.window=window}loadPaypalSDK(e=""){return t=this,n=void 0,r=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 hr;return this.window.paypal},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}}const ld=mr(e=>new cd(e,new ud(le()),n()),[{id:"paypalexpress"}]);function hd(e,t,n){const i=new WeakMap;function r(e){return(...n)=>{const r=n[n.length-1],{useCache:o}=(a=r)&&"boolean"==typeof a.useCache?r:{useCache:!1};var a;if(!o)return e.call(this,...n);const s=i.get(this)||{};var d;return i.get(this)||i.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(ie()):"function"==typeof t?ae(e=>W(t(e)).pipe(ie()),{isEqual:v}):t},{isEqual:v}))),s[t].call(this,...n)}}return{get(){if("function"!=typeof n.value)throw new Error("Decorator should be used in functions");const e=r.call(this,n.value);return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e}}}const pd=e=>!!e;class md{constructor(e){this._requestSender=e}loadPaymentMethodsById(e,t){return n=>new j(i=>{var r;const a=null===(r=n.getState().cart.getCart())||void 0===r?void 0:r.id,s=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);i.next(o(vn.LoadPaymentMethodsRequested)),Promise.all(e.map(e=>{return n=this,i=void 0,o=function*(){try{return(yield this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:s}))).body}catch(e){return}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o})).then(e=>{const t=e.filter(pd);i.next(o(vn.LoadPaymentMethodsSucceeded,t)),i.complete()}).catch(e=>{i.next(o(vn.LoadPaymentMethodsFailed,e)),i.complete()})})}loadPaymentMethods(e){return t=>j.create(n=>{const i=t.getState().cart.getCartOrThrow();n.next(o(vn.LoadPaymentMethodsRequested)),this._requestSender.loadPaymentMethods(Object.assign(Object.assign({},e),{params:Object.assign(Object.assign({},null==e?void 0:e.params),{cartId:i.id})})).then(e=>{const t={deviceSessionId:e.headers["x-device-session-id"],sessionHash:e.headers["x-session-hash"]},i=e.body;n.next(o(vn.LoadPaymentMethodsSucceeded,i,t)),n.complete()}).catch(e=>{n.error(s(vn.LoadPaymentMethodsFailed,e))})})}loadPaymentMethod(e,t){return n=>j.create(i=>{var r;const a=null===(r=n.getState().cart.getCart())||void 0===r?void 0:r.id,d=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);i.next(o(vn.LoadPaymentMethodRequested,void 0,{methodId:e})),this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:d})).then(t=>{i.next(o(vn.LoadPaymentMethodSucceeded,t.body,{methodId:e})),i.complete()}).catch(t=>{i.error(s(vn.LoadPaymentMethodFailed,t,{methodId:e}))})})}}var gd;(function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)})([hd],md.prototype,"loadPaymentMethod",null),function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(gd||(gd={}));const yd=gd,fd="This API endpoint is for internal use only and may change in the future",vd={"X-Checkout-SDK-Version":"1.817.0"};class Sd{constructor(e){this._requestSender=e}loadPaymentMethods({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/payments",{timeout:e,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd),params:t})}loadPaymentMethod(e,{timeout:t,params:n}={}){const i=`/api/storefront/payments/${e}`;return this._requestSender.get(i,{timeout:t,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd),params:n})}}function Cd(e,t,n){return(i=t)&&i.type&&i.error?H(Q(t),Z(s(e,t.payload,n))):Z(s(e,t,n));var i}class Id 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 _d{constructor(e,t){this._requestSender=e,this._subscriptionActionCreator=t}continueAsGuest(e,t){return n=>{const i=n.getState(),r=i.checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);const a=i.customer.getCustomer();if(a&&!a.isGuest)throw new Id;const s=i.billingAddress.getBillingAddress();let d;if(s){const{country:t}=s,n=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(s,["country"]);d=Object.assign(Object.assign({},n),e)}else d=e;const c=!f(s);return K(H(Q(o(Ue.ContinueAsGuestRequested)),V(()=>{return e=this,n=void 0,a=function*(){const{body:e}=yield this._createOrUpdateBillingAddress(r.id,d,c,t);return o(Ue.ContinueAsGuestSucceeded,e)},new((i=void 0)||(i=Promise))(function(t,r){function o(e){try{d(a.next(e))}catch(e){r(e)}}function s(e){try{d(a.throw(e))}catch(e){r(e)}}function d(e){var n;e.done?t(e.value):(n=e.value,n instanceof i?n:new i(function(e){e(n)})).then(o,s)}d((a=a.apply(e,n||[])).next())});var e,n,i,a})).pipe(J(e=>Cd(Ue.ContinueAsGuestFailed,e))),this._updateCustomerConsent(e,t))}}updateAddress(e,t){return n=>j.create(i=>{const r=n.getState(),a=r.checkout.getCheckout();if(!a)throw new qi(xi.MissingCheckout);i.next(o(Ue.UpdateBillingAddressRequested));const d=r.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})=>{i.next(o(Ue.UpdateBillingAddressSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Ue.UpdateBillingAddressFailed,e))})})}_updateCustomerConsent({email:e,acceptsAbandonedCartEmails:t,acceptsMarketingNewsletter:n},i){return null==t&&null==n?Y():this._subscriptionActionCreator.updateSubscriptions({email:e,acceptsMarketingNewsletter:n||!1,acceptsAbandonedCartEmails:t||!1},i)}_createOrUpdateBillingAddress(e,t,n,i){return n?this._requestSender.updateAddress(e,t,i):this._requestSender.createAddress(e,t,i)}}class wd 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 bd={include:["cart.lineItems.physicalItems.options","cart.lineItems.digitalItems.options","customer","promotions.banners"].join(",")};class Ed{constructor(e){this._requestSender=e}createAddress(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/billing-address`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(i,{body:t,params:bd,headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}updateAddress(e,t,{timeout:n}={}){const{id:i}=t,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["id"]),o=`/api/storefront/checkouts/${e}/billing-address/${i}`,a=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.put(o,{params:bd,body:r,headers:a,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}class Pd{constructor(e){this._requestSender=e}createBuyNowCart(e,{timeout:t}={}){const n=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post("/api/storefront/carts",{body:e,headers:n,timeout:t})}}class Od{constructor(e,t,n){this._checkoutRequestSender=e,this._configActionCreator=t,this._formFieldsActionCreator=n}loadCheckout(e,t){return()=>H(Q(o(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})=>o(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(e))))).pipe(J(e=>Cd(Me.LoadCheckoutFailed,e)))}loadDefaultCheckout(e){return t=>H(Q(o(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 n=this,i=void 0,a=function*(){const n=t.getState().config.getContextConfig();if(!n||!n.checkoutId)throw new qi(xi.MissingCheckoutConfig);const{body:i}=yield this._checkoutRequestSender.loadCheckout(n.checkoutId,e);return o(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(i))},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(e=>Cd(Me.LoadCheckoutFailed,e)))}updateCheckout(e,t){return n=>new j(i=>{const r=n.getState().checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);i.next(o(Me.UpdateCheckoutRequested)),this._checkoutRequestSender.updateCheckout(r.id,e,t).then(({body:e})=>{i.next(o(Me.UpdateCheckoutSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Me.UpdateCheckoutFailed,e))})})}loadCurrentCheckout(e){return t=>{const n=t.getState().checkout.getCheckout();if(!n)throw new qi(xi.MissingCheckout);return this.loadCheckout(n.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 Ad(e){return F(e).join(",")}function Td(e,t=[]){return Array.isArray(t)?Ad([...e,...t]):function(e,t){const n=b(M(t,e=>!e)),i=b(u(t));return Ad([...c(e,n),...i])}(e,t)}const kd=["cart.lineItems.physicalItems.options","cart.lineItems.digitalItems.options","customer","customer.customerGroup","payments","promotions.banners"];class Dd extends Pe{constructor(e){super(e,{message:e.body.title}),this.name="CheckoutNotAvailableError",this.type="checkout_not_available"}}class Rd{constructor(e){this._requestSender=e}loadCheckout(e,{params:{include:t}={},timeout:n}={}){const i=`/api/storefront/checkout/${e}`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.get(i,{params:{include:Td(kd,t)},headers:r,timeout:n}).catch(e=>{if(e.status>=400&&e.status<500)throw new Dd(e);throw e})}updateCheckout(e,t,{params:{include:n}={},timeout:i}={}){const r=`/api/storefront/checkout/${e}`,o=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.put(r,{params:{include:Td(kd,n)},body:t,headers:o,timeout:i})}}class Md{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 Nd 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 Ld{constructor(e){this._checkoutRequestSender=e}validate(e,t){if(!e)throw new qi(xi.MissingCheckout);return this._checkoutRequestSender.loadCheckout(e.id,t).then(t=>{const n=new Md;if(!(e.outstandingBalance===t.body.outstandingBalance&&this._compareCoupons(e.coupons,t.body.coupons)&&this._compareGiftCertificates(e.giftCertificates,t.body.giftCertificates)&&n.isEqual(e.cart,t.body.cart)))throw new Nd(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:n,giftCertificates:i,outstandingBalance:r}=e;return{cart:{cartAmount:t.cartAmount,currency:t.currency,lineItems:t.lineItems},coupons:n,giftCertificates:i,outstandingBalance:r}}}var zd;class Ud{constructor(e){this._configRequestSender=e}loadConfig(e){return j.create(t=>{t.next(o(mt.LoadConfigRequested)),this._configRequestSender.loadConfig(e).then(e=>{t.next(o(mt.LoadConfigSucceeded,e.body)),t.complete()}).catch(e=>{t.error(s(mt.LoadConfigFailed,e))})})}}!function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)}([hd],Ud.prototype,"loadConfig",null);class Fd{constructor(e){this._requestSender=e}loadConfig({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/checkout-settings",{timeout:e,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd),params:t}).catch(e=>{if(e.status>=400&&e.status<500)throw new Dd(e);throw e})}}class Bd{constructor(e){this._couponRequestSender=e}applyCoupon(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);i.next(o(Ze.ApplyCouponRequested)),this._couponRequestSender.applyCoupon(r.id,e,t).then(({body:e})=>{i.next(o(Ze.ApplyCouponSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Ze.ApplyCouponFailed,e))})})}removeCoupon(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);i.next(o(Ze.RemoveCouponRequested)),this._couponRequestSender.removeCoupon(r.id,e,t).then(({body:e})=>{i.next(o(Ze.RemoveCouponSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Ze.RemoveCouponFailed,e))})})}}!function(e){e.AvailableShippingOptions="consignments.availableShippingOptions",e.PhysicalItemsCategoryNames="cart.lineItems.physicalItems.categoryNames",e.DigitalItemsCategoryNames="cart.lineItems.digitalItems.categoryNames"}(zd||(zd={}));class xd{constructor(e){this._requestSender=e}applyCoupon(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/coupons`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(i,{headers:r,timeout:n,params:{include:Ad([...kd,zd.AvailableShippingOptions])},body:{couponCode:t}}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}removeCoupon(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/coupons/${t}`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.delete(i,{headers:r,timeout:n,params:{include:Ad([...kd,zd.AvailableShippingOptions])}}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}function qd(e){const t=e;return"object"==typeof t&&"object"==typeof t.payload&&"string"==typeof t.payload.token}class jd{constructor(e,t,n){this._customerRequestSender=e,this._checkoutActionCreator=t,this._spamProtectionActionCreator=n}createCustomer(e,t){return n=>{const i=n.getState().config.getStoreConfigOrThrow(),{isStorefrontSpamProtectionEnabled:r}=i.checkoutSettings,a=i=>W(this._customerRequestSender.createAccount(Object.assign(Object.assign({},e),{token:i}),t)).pipe(re(()=>H(this._checkoutActionCreator.loadCurrentCheckout(t)(n),Q(o(Dt.CreateCustomerSucceeded)))));return H(Q(o(Dt.CreateCustomerRequested)),r?W(this._spamProtectionActionCreator.execute()(n)).pipe(re(e=>{var t;return qd(e)?H(Q(e),a(null===(t=e.payload)||void 0===t?void 0:t.token)):Q(e)})):a()).pipe(J(e=>Cd(Dt.CreateCustomerFailed,e)))}}createAddress(e,t){return H(Q(o(Dt.CreateCustomerAddressRequested)),V(()=>{return n=this,i=void 0,a=function*(){const{body:n}=yield this._customerRequestSender.createAddress(e,t);return o(Dt.CreateCustomerAddressSucceeded,n)},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(e=>Cd(Dt.CreateCustomerAddressFailed,e)))}signInCustomer(e,t){return n=>{const i=n.getState().checkout.getCheckoutOrThrow(),r=i.cart.source===oo.BuyNow?i.id:void 0;return H(Q(o(Dt.SignInCustomerRequested)),W(this._customerRequestSender.signInCustomer(Object.assign(Object.assign({},e),{cartId:r}),t)).pipe(re(({body:e})=>e.data.persistentCartRetrievalInformation?H(this._checkoutActionCreator.loadCheckout(e.data.persistentCartRetrievalInformation.id,t)(n),Q(o(Dt.SignInCustomerSucceeded,e.data))):H(this._checkoutActionCreator.loadCurrentCheckout(t)(n),Q(o(Dt.SignInCustomerSucceeded,e.data)))))).pipe(J(e=>Cd(Dt.SignInCustomerFailed,e)))}}signOutCustomer(e){return t=>{const n=t.getState().checkout.getCheckoutOrThrow(),i=n.cart.source===oo.BuyNow?n.id:void 0;return H(Q(o(Dt.SignOutCustomerRequested)),W(this._customerRequestSender.signOutCustomer(e,i)).pipe(re(({body:n})=>H(this._checkoutActionCreator.loadCurrentCheckout(e)(t),Q(o(Dt.SignOutCustomerSucceeded,n.data)))))).pipe(J(e=>Cd(Dt.SignOutCustomerFailed,e)))}}}class Gd{constructor(e){this._requestSender=e}createAccount(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer",{timeout:t,headers:vd,body:e})}createAddress(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer-address",{timeout:t,headers:vd,body:e})}signInCustomer(e,{timeout:t}={}){return this._requestSender.post("/internalapi/v1/checkout/customer",{timeout:t,headers:vd,body:e})}signOutCustomer({timeout:e}={},t){return this._requestSender.delete("/internalapi/v1/checkout/customer",Object.assign({timeout:e,headers:vd},t&&{body:{cartId:t}}))}}class Hd{constructor(e){this._formFieldsRequestSender=e}loadFormFields(e){return H(Q(o(Kt.LoadFormFieldsRequested)),V(()=>{return t=this,n=void 0,r=function*(){const{body:t}=yield this._formFieldsRequestSender.loadFields(e);return o(Kt.LoadFormFieldsSucceeded,t)},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r})).pipe(J(e=>Cd(Kt.LoadFormFieldsFailed,e)))}}!function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)}([hd],Hd.prototype,"loadFormFields",null);class Vd{constructor(e){this._requestSender=e}loadFields({timeout:e}={}){return this._requestSender.get("/api/storefront/form-fields",{timeout:e,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd)})}}class Yd 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 Wd{constructor(e){this._mutationObserver=e}ensurePresence(e,t){return n=this,i=void 0,o=function*(){const n=new Yo(t),i=this._mutationObserver.create(t=>{t.forEach(t=>{0!==Array.from(t.removedNodes).filter(t=>e.some(e=>t===e||t.contains(e))).length&&n.cancel(new Yd)})});i.observe(document.body,{childList:!0,subtree:!0});try{const e=yield n.promise;return i.disconnect(),e}catch(e){throw i.disconnect(),e}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}class $d{constructor(e=window){this._window=e}create(e){return new this._window.MutationObserver(e)}}class Kd extends be{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}function Qd(e){if(!/^(https?:)?\/\//.test(e))throw new Kd("The provided URL must be absolute.");const t=document.createElement("a");t.href=e;const n=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}${n?`:${n}`:""}`,pathname:t.pathname,port:n,protocol:t.protocol,search:t.search}}function Zd(e,t){return e.type===t}class Jd{constructor(e,t,n){this._targetWindow=t,this._context=n,this._targetOrigin="*"===e?"*":Qd(e).origin}post(e,t){const n=this._targetWindow;if(window===n)return;if(!n)throw new Error("Unable to post message because target window is not set.");const i=t&&$(window,"message").pipe(ee(e=>e.origin===this._targetOrigin&&Zd(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}),oe(1)).toPromise();return n.postMessage(Object.assign(Object.assign({},e),{context:this._context}),this._targetOrigin),i}setTarget(e){this._targetWindow=e}setContext(e){this._context=e}}class Xd{constructor(e){var t;this._sourceOrigins=[Qd(e).origin,(t=Qd(e),Qd(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 n=this._listeners[e];n||(this._listeners[e]=n=[]),-1===n.indexOf(t)&&n.push(t)}removeListener(e,t){const n=this._listeners[e];if(!n)return;const i=n.indexOf(t);i>=0&&n.splice(i,1)}trigger(e,t){const n=this._listeners[e.type];n&&n.forEach(n=>t?n(e,t):n(e))}_handleMessage(e){if(-1===this._sourceOrigins.indexOf(e.origin)||!Zd(e.data,e.data.type))return;const t=e.data,{context:n}=t,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["context"]);this.trigger(i,n)}}!function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)}([_a],Xd.prototype,"_handleMessage",null);class ec 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 tc extends be{constructor(){super("Please complete our human verification challenge and try again."),this.name="CardingProtectionChallengeNotCompletedError",this.type="carding_protection_challenge_not_completed"}}class nc 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 ic,rc,oc,ac=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class sc{constructor(e){this._googleRecaptcha=e}handle(e,t){return ac(this,void 0,void 0,function*(){return"string"==typeof e?this.handleWithRecaptchaSitekey(e,t):this.handleWithPaymentHumanVerificationRequestError(e)})}handleWithPaymentHumanVerificationRequestError(e){return ac(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 ac(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(oe(1)).pipe(re(({error:e,token:t})=>ac(this,void 0,void 0,function*(){if(e instanceof ec)throw new tc;if(e||!t)throw new nc;return{type:"recaptcha_v2_verification",data:{human_verification_token:t}}}))).toPromise()}_initialize(e){const t="cardingProtectionContainer";let n=document.getElementById(t);return n&&n.parentNode&&n.parentNode.removeChild(n),n=document.createElement("div"),n.setAttribute("id",t),document.body.appendChild(n),this._googleRecaptcha.load(t,e)}_isPaymentHumanVerificationRequest(e){const{additional_action_required:t,status:n}=e.body||{};return"additional_action_required"===n&&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"}(ic||(ic={}));class dc extends be{constructor(e){super(function(e){switch(e){case ic.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case ic.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case ic.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case ic.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 cc 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 uc extends be{constructor(){super("Spam protection is not loaded. Please try again."),this.name="SpamProtectionNotLoadedError",this.type="spam_protection_failed"}}class lc{constructor(e,t){this.googleRecaptchaScriptLoader=e,this.mutationObserverFactory=t,this._memoized=ae((e,t,n)=>{const i=new G;if(!n)throw new Error;return this._widgetId=e.render(n.id,{sitekey:t,size:"invisible",callback:()=>{i.next({token:e.getResponse(this._widgetId)}),e.reset(this._widgetId)},"error-callback":()=>{i.next({error:new cc})}}),i},{isEqual:(e,t)=>e===t})}load(e,t){return this.googleRecaptchaScriptLoader.load().then(n=>{n&&(this._event$=this._memoized(n,t,document.getElementById(e)),this._recaptcha=n)}).catch(e=>{throw e})}reset(e){var t;const n=document.getElementById(e);null==n||n.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 dc(ic.SpamProtectionNotInitialized);return V(()=>{const e=document.querySelector('iframe[src*="bframe"]');return e?Q(e):Z(new uc)}).pipe(ne(e=>e.pipe(X(250),re((e,t)=>t<28?Q(e):Z(e)))),re(n=>(this._watchRecaptchaChallengeWindow(e,n),t.execute(this._widgetId),e)),J(e=>Q({error:e})))})}_watchRecaptchaChallengeWindow(e,t){const n=t.parentElement;if(!n)throw new uc;const i=n.parentElement;if(!i)throw new uc;this.mutationObserverFactory.create(()=>{"hidden"===i.style.visibility&&e.next({error:new ec})}).observe(i,{attributes:!0,attributeFilter:["style"]})}}class hc{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((n,i)=>{this._window[e]=()=>n(this._window.grecaptcha),this._scriptLoader.loadScript(`//www.google.com/recaptcha/api.js?${t}`).catch(e=>{this._loadPromise=void 0,i(e)})})}}function pc(e){return new lc(new hc(e),new $d)}class mc 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 gc 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 yc 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"}(rc||(rc={})),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"}(oc||(oc={}));var fc=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class vc{constructor(e,t,n,i,r,o,a,s,d,c){this._type=e,this._containerId=t,this._placeholder=n,this._accessibilityLabel=i,this._styles=r,this._eventPoster=o,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.817.0&checkoutId=${this._checkoutId}`:"/checkout/payment/hosted-field?version=1.817.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 fc(this,void 0,void 0,function*(){const e=document.getElementById(this._containerId);if(!e)throw new mc("Unable to proceed because the provided container ID is not valid.");e.appendChild(this._iframe),this._eventListener.listen();const t=$(this._iframe,"load").pipe(re(({target:e})=>fc(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:rc.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:oc.AttachSucceeded,errorType:oc.AttachFailed})})),oe(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 fc(this,void 0,void 0,function*(){try{const n=this._eventPoster.post({type:rc.SubmitRequested,payload:{fields:e,data:t}},{successType:oc.SubmitSucceeded,errorType:oc.SubmitFailed});return yield this._detachmentObserver.ensurePresence([this._iframe],n)}catch(e){if(this._isSubmitErrorEvent(e)){if("hosted_form_error"===e.payload.error.code)throw new gc(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 fc(this,void 0,void 0,function*(){const n=this._eventPoster.post({type:rc.StoredCardRequested,payload:{fields:e,data:t}},{successType:oc.StoredCardSucceeded,errorType:oc.StoredCardFailed});return this._detachmentObserver.ensurePresence([this._iframe],n)})}validateForm(){return fc(this,void 0,void 0,function*(){const e=this._eventPoster.post({type:rc.ValidateRequested},{successType:oc.Validated}),{payload:t}=yield this._detachmentObserver.ensurePresence([this._iframe],e);if(!t.isValid)throw new yc(t.errors)})}_getFontUrls(){const e="fonts.googleapis.com",t=document.querySelectorAll(`link[href*='${e}'][rel='stylesheet']`);return Array.prototype.slice.call(t).filter(t=>Qd(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===oc.SubmitFailed}}var Sc=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Cc{constructor(e,t,n,i,r){this._fields=e,this._eventListener=t,this._payloadTransformer=n,this._eventCallbacks=i,this._paymentHumanVerificationHandler=r,this._handleEnter=({payload:e})=>Sc(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:o=T,onCardTypeChange:a=T,onFocus:s=T,onValidate:d=T}=this._eventCallbacks;this._eventListener.addListener(oc.Blurred,({payload:e})=>o(e)),this._eventListener.addListener(oc.CardTypeChanged,({payload:e})=>a(e)),this._eventListener.addListener(oc.Focused,({payload:e})=>s(e)),this._eventListener.addListener(oc.Validated,({payload:e})=>d(e)),this._eventListener.addListener(oc.Entered,this._handleEnter),this._eventListener.addListener(oc.CardTypeChanged,({payload:e})=>this._cardType=e.cardType),this._eventListener.addListener(oc.BinChanged,({payload:e})=>this._bin=e.bin)}getBin(){return this._bin}getCardType(){return this._cardType}attach(){return Sc(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 Sc(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 n=yield this._paymentHumanVerificationHandler.handle(t);return yield this._getFirstField().submitForm(this._fields.map(e=>e.getType()),this._payloadTransformer.transform(e,n))}})}submitStoredCard(e){return Sc(this,void 0,void 0,function*(){return this._getFirstField().submitStoredCardForm(e.fields,e.data)})}validate(){return Sc(this,void 0,void 0,function*(){return this._getFirstField().validateForm()})}_getFirstField(){const e=this._fields[0];if(!e)throw new mc("Unable to proceed because the payment form has no field defined.");return e}}function Ic(e){return Boolean(e.instrumentId)}class _c{constructor(e){this._store=e}transform(e,t){const n=this._store.getState(),i=n.checkout.getCheckout(),r=n.config.getConfig(),o=n.instruments.getInstrumentsMeta(),a=n.order.getOrder(),s=n.order.getOrderMeta(),d=k(e.paymentData,"ccExpiry","ccName","ccNumber","ccCvv"),c=n.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),u=n.paymentMethods.getPaymentMethodsMeta(),l=o&&d&&Ic(d)?`${n.payment.getPaymentToken()}, ${o.vaultAccessToken}`:n.payment.getPaymentToken();if(!l)throw new qi(xi.MissingPaymentToken);return{additionalAction:t,authToken:l,checkout:i,config:r,order:a,orderMeta:s,payment:d,paymentMethod:c,paymentMethodMeta:u}}}class wc{constructor(e){this._store=e}create(e,t,n){const i=Object.keys(t.fields).reduce((i,r)=>{const o=t.fields[r];return o?[...i,new vc(r,o.containerId,o.placeholder||"",o.accessibilityLabel||"",t.styles||{},new Jd(e),new Xd(e),new Wd(new $d),n,"instrumentId"in o?this._getCardInstrument(o.instrumentId):void 0)]:i},[]);return new Cc(i,new Xd(e),new _c(this._store),R(t,"onBlur","onEnter","onFocus","onCardTypeChange","onValidate"),new sc(pc(ue())))}_getCardInstrument(e){const{instruments:{getCardInstrument:t}}=this._store.getState(),n=t(e);if(!n)throw new qi(xi.MissingPaymentInstrument);return n}}class bc extends be{constructor(){super("You haven't complete our spam check. Please try again."),this.name="SpamProtectionNotCompletedError",this.type="spam_protection_not_completed"}}class Ec{constructor(e,t){this._orderRequestSender=e,this._checkoutValidator=t}loadOrder(e,t){return new j(n=>{n.next(o(Ct.LoadOrderRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{n.next(o(Ct.LoadOrderSucceeded,e.body)),n.complete()}).catch(e=>{n.error(s(Ct.LoadOrderFailed,e))})})}loadOrderPayments(e,t){return new j(n=>{n.next(o(Ct.LoadOrderPaymentsRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{n.next(o(Ct.LoadOrderPaymentsSucceeded,e.body)),n.complete()}).catch(e=>{n.error(s(Ct.LoadOrderPaymentsFailed,e))})})}loadCurrentOrder(e){return t=>V(()=>{const n=this._getCurrentOrderId(t.getState());if(!n)throw new qi(xi.MissingOrderId);return this.loadOrder(n,e)})}submitOrder(e,t){return n=>H(Q(o(Ct.SubmitOrderRequested)),V(()=>{const i=n.getState(),r=i.config.getExternalSource(),a=i.config.getVariantIdentificationToken(),s=i.checkout.getCheckout();if(!s)throw new qi(xi.MissingCheckout);if(s.shouldExecuteSpamCheck)throw new bc;return W(this._checkoutValidator.validate(s,t).then(()=>this._orderRequestSender.submitOrder(this._mapToOrderRequestBody(null!=e?e:{},s.id,s.customerMessage,r),Object.assign(Object.assign({},t),{headers:{checkoutVariant:a}})))).pipe(re(e=>H(this.loadOrder(e.body.data.order.orderId,t),Q(o(Ct.SubmitOrderSucceeded,e.body.data,Object.assign(Object.assign({},e.body.meta),{token:e.headers.token}))))))}).pipe(J(e=>Cd(Ct.SubmitOrderFailed,e))))}finalizeOrder(e,t){return H(Q(o(Ct.FinalizeOrderRequested)),W(this._orderRequestSender.finalizeOrder(e,t)).pipe(re(n=>H(this.loadOrder(e,t),Q(o(Ct.FinalizeOrderSucceeded,n.body.data)))))).pipe(J(e=>Cd(Ct.FinalizeOrderFailed,e)))}_getCurrentOrderId(e){const t=e.order.getOrder(),n=e.checkout.getCheckout();return t&&t.orderId||n&&n.orderId}_mapToOrderRequestBody(e,t,n,i){const{payment:r}=e,o=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);return r?Object.assign(Object.assign({},o),{cartId:t,customerMessage:n,externalSource:i,payment:{paymentData:r.paymentData,name:r.methodId,gateway:r.gatewayId}}):Object.assign(Object.assign({},o),{cartId:t,customerMessage:n,externalSource:i})}}class Pc 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 Oc extends be{constructor(e){super(e||"The tax provider is unavailable."),this.name="OrderTaxProviderUnavailableError",this.type="tax_provider_unavailable"}}class Ac extends be{constructor(e){super(e),this.name="MissingShippingMethodError",this.type="missing_shipping_method"}}class Tc extends be{constructor(e){super(e),this.name="InvalidShippingAddressError",this.type="invalid_shipping_address"}}class kc{constructor(e){this._requestSender=e}loadOrder(e,{timeout:t}={}){const n=`/api/storefront/orders/${e}`,i=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.get(n,{params:{include:Ad(["payments","lineItems.physicalItems.socialMedia","lineItems.physicalItems.options","lineItems.physicalItems.categories","lineItems.digitalItems.socialMedia","lineItems.digitalItems.options","lineItems.digitalItems.categories"])},headers:i,timeout:t})}submitOrder(e,{headers:t,timeout:n}={}){return this._requestSender.post("/internalapi/v1/checkout/order",{body:e,headers:D(Object.assign({"X-Checkout-Variant":t&&t.checkoutVariant},vd),C),timeout:n}).catch(e=>{if("tax_provider_unavailable"===e.body.type)throw new Oc;if("cart_has_changed"===e.body.type)throw new Pc;if("missing_shipping_method"===e.body.type)throw new Ac(e.body.detail);if("invalid_shipping_address"===e.body.type)throw new Tc(e.body.detail);if("empty_cart"===e.body.type)throw new wd;throw e})}finalizeOrder(e,{timeout:t}={}){const n=`/internalapi/v1/checkout/order/${e}`;return this._requestSender.post(n,{timeout:t,headers:vd})}}class Dc{constructor(e,t,n,i){this._paymentRequestSender=e,this._orderActionCreator=t,this._paymentRequestTransformer=n,this._paymentHumanVerificationHandler=i,this.initializeOffsitePayment=({methodId:e,gatewayId:t,instrumentId:n,target:i,promise:r,shouldSaveInstrument:a,shouldSetAsDefaultInstrument:s})=>d=>{let c;n?c={formattedPayload:{bigpay_token:n}}: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(Q(o(fn.InitializeOffsitePaymentRequested)),Promise.race([this._paymentRequestSender.initializeOffsitePayment(u,i),r].filter(Boolean)).then(()=>o(fn.InitializeOffsitePaymentSucceeded))).pipe(J(e=>Cd(fn.InitializeOffsitePaymentFailed,e)))}}submitPayment(e){return t=>H(Q(o(fn.SubmitPaymentRequested)),V(()=>{return n=this,i=void 0,o=function*(){try{return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(e,t.getState()))}catch(n){const i=yield this._paymentHumanVerificationHandler.handle(n);return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(Object.assign(Object.assign({},e),{additionalAction:i}),t.getState()))}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}).pipe(re(({body:e})=>H(this._orderActionCreator.loadCurrentOrder()(t),Q(o(fn.SubmitPaymentSucceeded,e)))))).pipe(J(e=>Cd(fn.SubmitPaymentFailed,e)))}}class Rc{constructor(e){this._client=e}submitPayment(e){return new Promise((t,n)=>{this._client.submitPayment(e,(e,i)=>{e?n(this._transformResponse(e)):t(this._transformResponse(i))})})}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 Mc(e,t){let n;return function(e){return void 0!==e.id}(e)?n=e.id:t&&t.length&&(n=t[0].id),{id:n,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}}class Nc{constructor(e){this._decimalPlaces=e}toInteger(e){return Math.round(e*Math.pow(10,this._decimalPlaces))}}const Lc=["per_item_discount","percentage_discount","per_total_discount","shipping_discount","free_shipping"];function zc(e){return{code:e.code,discount:e.displayName,discountType:Lc.indexOf(e.couponType)}}function Uc(e){return{code:e.code,discountedAmount:e.used,remainingBalance:e.remaining,giftCertificate:{balance:e.balance,code:e.code,purchaseDate:e.purchaseDate}}}function Fc(e){const t=[];return(e||[]).forEach(e=>{(e.banners||[]).forEach(e=>{t.push({placeholders:[],discountType:null,message:"",messageHtml:e.text})})}),t}function Bc(e,t,n="id"){return Object.keys(e).reduce((i,r)=>[...i,...e[r].map(e=>"giftCertificates"===r?function(e,t){const n=new Nc(t);return{id:e.id,imageUrl:"",name:e.name,amount:e.amount,amountAfterDiscount:e.amount,discount:0,integerAmount:n.toInteger(e.amount),integerAmountAfterDiscount:n.toInteger(e.amount),integerUnitPrice:n.toInteger(e.amount),integerUnitPriceAfterDiscount:n.toInteger(e.amount),integerDiscount:0,quantity:1,sender:e.sender,recipient:e.recipient,type:"ItemGiftCertificateEntity",attributes:[],variantId:null}}(e,t):function(e,t,n,i="id"){const r=new Nc(n);return{id:e[i],imageUrl:e.imageUrl,amount:e.extendedListPrice,amountAfterDiscount:e.extendedSalePrice,discount:e.discountAmount,integerAmount:r.toInteger(e.extendedListPrice),integerAmountAfterDiscount:r.toInteger(e.extendedSalePrice),integerDiscount:r.toInteger(e.discountAmount),integerUnitPrice:r.toInteger(e.listPrice),integerUnitPriceAfterDiscount:r.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""}}(r),t,n))],[])}function xc(e){const t=e.cart.currency.decimalPlaces,n=new Nc(t);return{id:e.cart.id,items:Bc(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(zc)},discount:{amount:e.cart.discountAmount,integerAmount:n.toInteger(e.cart.discountAmount)},discountNotifications:Fc(e.promotions),giftCertificate:{totalDiscountedAmount:N(e.giftCertificates,(e,t)=>e+t.used,0),appliedGiftCertificates:w(e.giftCertificates.map(Uc),"code")},shipping:{amount:e.shippingCostTotal,integerAmount:n.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:n.toInteger(e.shippingCostBeforeDiscount),required:z(e.cart.lineItems.physicalItems,e=>e.isShippingRequired)},subtotal:{amount:e.subtotal,integerAmount:n.toInteger(e.subtotal)},storeCredit:{amount:e.customer?e.customer.storeCredit:0},taxSubtotal:{amount:e.taxTotal,integerAmount:n.toInteger(e.taxTotal)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:n.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:n.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.grandTotal,integerAmount:n.toInteger(e.grandTotal)}}}var qc;!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.MASTERPASS="masterpass",e.PAYPALEXPRESS="paypalexpress"}(qc||(qc={}));const jc=qc;function Gc(e,t){const n=e.firstName||t.firstName||"",i=e.lastName||t.lastName||"";return{addresses:(e.addresses||[]).map(e=>Mc(e)),customerId:e.id,isGuest:e.isGuest,storeCredit:e.storeCredit,email:e.email||t.email||"",firstName:n,lastName:i,name:e.fullName||[n,i].join(" "),customerGroupName:e.customerGroup&&e.customerGroup.name}}class Hc{format(e){const[t="",n=""]=e.split(new RegExp("\\s*/\\s*")),i=t.slice(0,2),r=4===n.length?n.slice(-2):n?n.slice(0,2):t.slice(2);return e.length<2?t:e.length>3&&!r?i:`${i} / ${r}`}toObject(e){const[t="",n=""]=e.split(new RegExp("\\s*/\\s*"));return/^\d+$/.test(t)&&/^\d+$/.test(n)?{month:1===t.length?`0${t}`:t.slice(0,2),year:2===n.length?`20${n}`:n.slice(0,4)}:{month:"",year:""}}}class Vc{format(e){const{card:t}=ye(e);if(!t)return e;const n=O(ge(e).map(e=>O(e.lengths))),i=this.unformat(e).slice(0,n);return t.gaps.filter(e=>i.length>e).reduce((e,t,n)=>[e.slice(0,t+n),e.slice(t+n)].join(" "),i)}unformat(e){const{card:t}=ye(e);return t?e.replace(new RegExp(" ","g"),""):e}}function Yc(e,t={}){const n=e.currency.decimalPlaces,i=new Nc(n);return{id:e.orderId,items:Bc(e.lineItems,e.currency.decimalPlaces,"productId"),orderId:e.orderId,currency:e.currency.code,customerCanBeCreated:e.customerCanBeCreated,payment:Kc(e.payments,t.payment),subtotal:{amount:e.baseAmount,integerAmount:i.toInteger(e.baseAmount)},coupon:{discountedAmount:N(e.coupons,(e,t)=>e+t.discountedAmount,0),coupons:e.coupons.map(zc)},discount:{amount:e.discountAmount,integerAmount:i.toInteger(e.discountAmount)},token:t.orderToken,callbackUrl:t.callbackUrl,discountNotifications:[],giftCertificate:$c(e.payments),socialData:Zc(e),status:e.status,hasDigitalItems:e.hasDigitalItems,isDownloadable:e.isDownloadable,isComplete:e.isComplete,shipping:{amount:e.shippingCostTotal,integerAmount:i.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:i.toInteger(e.shippingCostBeforeDiscount)},storeCredit:{amount:Wc(e.payments)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:i.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.orderAmount,integerAmount:e.orderAmountAsInteger}}}function Wc(e){const t=l(e,{providerId:"storecredit"});return t?t.amount:0}function $c(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 Kc(e,t={}){const n=l(e,Qc);return n?{id:n.providerId,status:(i=n.detail.step,`PAYMENT_STATUS_${i}`),helpText:n.detail.instructions,returnUrl:t.returnUrl}:{};var i}function Qc(e){return"giftcertificate"!==e.providerId&&"storecredit"!==e.providerId}function Zc(e){const t={};return[...e.lineItems.physicalItems,...e.lineItems.digitalItems].forEach(e=>{var n;t[e.id]=(n=e,["fb","tw","gp"].reduce((e,t)=>{const i=n.socialMedia&&l(n.socialMedia,e=>e.code===t);return i?(e[t]={name:n.name,description:n.name,image:n.imageUrl,url:i.link,shareText:i.text,sharingLink:i.link,channelName:i.channel,channelCode:i.code},e):e},{}))}),t}function Jc(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 Xc{constructor(){this._cardExpiryFormatter=new Hc,this._cardNumberFormatter=new Vc}transform(e,t){const n=t.billingAddress.getBillingAddress(),i=t.checkout.getCheckout(),r=t.customer.getCustomer(),o=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=r&&n&&Gc(r,n),y=h&&e.paymentData&&(Ic(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 qi(xi.MissingPaymentToken);return{additionalAction:e.additionalAction,authToken:y,customer:g,billingAddress:n&&Mc(n),shippingAddress:s&&Mc(s,d),shippingOption:c&&Jc(c,!0),cart:i&&xc(i),order:o&&Yc(o,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:R(u&&u.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}}transformWithHostedFormData(e,t,n){const{additionalAction:i,authToken:r,checkout:o,config:a,order:s,orderMeta:d,payment:c={},paymentMethod:u,paymentMethodMeta:l}=t,h=o&&o.consignments[0],p=h&&h.shippingAddress,m=h&&h.selectedShippingOption;return{additionalAction:i,authToken:r,paymentMethod:u&&this._transformPaymentMethod(u),customer:s&&s.billingAddress&&o&&Gc(o.customer,s.billingAddress),billingAddress:s&&s.billingAddress&&Mc(s.billingAddress),shippingAddress:p&&o&&Mc(p,o.consignments),shippingOption:m&&Jc(m,!0),cart:o&&xc(o),order:s&&Yc(s,d),orderMeta:d,payment:this._transformHostedInputValues(e,c,n),quoteMeta:{request:Object.assign(Object.assign({},l),{geoCountryCode:a&&a.context.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:a&&R(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===jc.BRAINTREE_VENMO?Object.assign(Object.assign({},e),{id:jc.BRAINTREE_PAYPAL}):e:Object.assign(Object.assign({},e),{gateway:e.id})}_transformHostedInputValues(e,t,n){return"instrumentId"in t?Object.assign(Object.assign({},t),{ccCvv:e.cardCodeVerification,ccNumber:e.cardNumberVerification&&this._cardNumberFormatter.unformat(e.cardNumberVerification),hostedFormNonce:n}):Object.assign(Object.assign({},t),{ccCvv:e.cardCode,ccExpiry:this._cardExpiryFormatter.toObject(e.cardExpiry||""),ccName:e.cardName||"",ccNumber:this._cardNumberFormatter.unformat(e.cardNumber||""),hostedFormNonce:n})}_mapShippingAddress(e,t){var n,i,r,o;if(t){const a=null===(i=null===(n=t.initializationData)||void 0===n?void 0:n.bopis)||void 0===i?void 0:i.enabled,s=null===(o=null===(r=t.initializationData)||void 0===r?void 0:r.bopis)||void 0===o?void 0:o.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 eu{updatePaymentProviderCustomer(e){return Q(o(Mn.UpdatePaymentProviderCustomer,e))}}class tu{widgetInteraction(e,t){const n={methodId:t&&t.methodId};return H(Q(o(On.WidgetInteractionStarted,void 0,n)),V(()=>e().then(()=>o(On.WidgetInteractionFinished,void 0,n)))).pipe(J(e=>Cd(On.WidgetInteractionFailed,e,n)))}}class nu{constructor(e,t){this._remoteCheckoutRequestSender=e,this._checkoutActionCreator=t}initializeBilling(e,t,n){return j.create(i=>{i.next(o(Hn.InitializeRemoteBillingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeBilling(e,t,n).then(({body:t={}})=>{i.next(o(Hn.InitializeRemoteBillingSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Hn.InitializeRemoteBillingFailed,t,{methodId:e}))})})}initializeShipping(e,t,n){return j.create(i=>{i.next(o(Hn.InitializeRemoteShippingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeShipping(e,t,n).then(({body:t={}})=>{i.next(o(Hn.InitializeRemoteShippingSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Hn.InitializeRemoteShippingFailed,t,{methodId:e}))})})}initializePayment(e,t,n){return j.create(i=>{i.next(o(Hn.InitializeRemotePaymentRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializePayment(e,t,n).then(({body:t={}})=>{i.next(o(Hn.InitializeRemotePaymentSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Hn.InitializeRemotePaymentFailed,t,{methodId:e}))})})}loadSettings(e,t){return j.create(n=>{n.next(o(Hn.LoadRemoteSettingsRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.loadSettings(e,t).then(({body:t})=>{n.next(o(Hn.LoadRemoteSettingsSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Hn.LoadRemoteSettingsFailed,t,{methodId:e}))})})}signOut(e,t){return j.create(n=>{n.next(o(Hn.SignOutRemoteCustomerRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.signOut(e,t).then(()=>{n.next(o(Hn.SignOutRemoteCustomerSucceeded,void 0,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Hn.SignOutRemoteCustomerFailed,t,{methodId:e}))})})}forgetCheckout(e,t){return H(Q(o(Hn.ForgetCheckoutRemoteCustomerRequested,void 0,{methodId:e})),V(()=>{return n=this,i=void 0,a=function*(){return yield this._remoteCheckoutRequestSender.forgetCheckout(t),yield this._checkoutActionCreator.loadCurrentCheckout(),o(Hn.ForgetCheckoutRemoteCustomerSucceeded,void 0,{methodId:e})},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(t=>Cd(Hn.ForgetCheckoutRemoteCustomerFailed,t,{methodId:e})))}updateCheckout(e,t){return o(Hn.UpdateRemoteCheckout,t,{methodId:e})}}class iu{constructor(e){this._requestSender=e}initializeBilling(e,t,{timeout:n}={}){const i=`/remote-checkout/${e}/billing`;return this._requestSender.get(i,{params:t,timeout:n,headers:vd})}initializeShipping(e,t,{timeout:n}={}){const i=`/remote-checkout/${e}/shipping`;return this._requestSender.get(i,{params:t,timeout:n,headers:vd})}initializePayment(e,t,{timeout:n}={}){const i=`/remote-checkout/${e}/payment`;return this._requestSender.get(i,{params:t,timeout:n,headers:vd})}loadSettings(e,{timeout:t}={}){const n=`/remote-checkout/${e}/settings`;return this._requestSender.get(n,{timeout:t,headers:vd})}signOut(e,{timeout:t}={}){const n=`/remote-checkout/${e}/signout`;return this._requestSender.get(n,{timeout:t,headers:vd})}generateToken({timeout:e}={}){return this._requestSender.get("/remote-checkout-token",{timeout:e,headers:vd})}trackAuthorizationEvent({timeout:e}={}){return this._requestSender.post("/remote-checkout/events/shopper-checkout-service-provider-authorization-requested",{timeout:e,headers:vd})}forgetCheckout({timeout:e}={}){return this._requestSender.post("/remote-checkout/forget-checkout",{timeout:e,headers:vd})}}class ru{constructor(e,t){this._consignmentRequestSender=e,this._checkoutRequestSender=t}unassignItemsByAddress(e,t){return n=>{const i=n.getState();if(!i.checkout.getCheckout())throw new qi(xi.MissingCheckout);const r=this._consignmentHasAddress(e)?e.address:e.shippingAddress,o=i.consignments.getConsignmentByAddress(r);if(!o)throw new Kd("No consignment found for the specified address");const a=this._removeLineItems(e.lineItems,o,i.cart.getCart());return a.length?this.updateConsignment({id:o.id,address:r,lineItems:a},t)(n):this.deleteConsignment(o.id,t)(n)}}assignItemsByAddress(e,t){return n=>{const i=n.getState(),r=this._consignmentHasAddress(e)?e.address:e.shippingAddress,o=i.consignments.getConsignmentByAddress(r);return this._createOrUpdateConsignment({id:o&&o.id,address:r,lineItems:this._addLineItems(e.lineItems,o,i.cart.getCart())},t)(n)}}selectShippingOption(e,t){return n=>j.create(i=>{const r=n.getState(),a=r.checkout.getCheckout(),d=r.consignments.getConsignments();if(!a)throw new qi(xi.MissingCheckout);if(!d||!d.length)throw new qi(xi.MissingConsignments);const c={id:d[0].id,shippingOptionId:e},u={id:d[0].id};i.next(o(Xe.UpdateShippingOptionRequested,void 0,u)),this._consignmentRequestSender.updateConsignment(a.id,c,t).then(({body:e})=>{i.next(o(Xe.UpdateShippingOptionSucceeded,e,u)),i.complete()}).catch(e=>{i.error(s(Xe.UpdateShippingOptionFailed,e,u))})})}loadShippingOptions(e){return t=>j.create(n=>{const i=t.getState().checkout.getCheckout();if(!i)throw new qi(xi.MissingCheckout);n.next(o(Xe.LoadShippingOptionsRequested)),this._checkoutRequestSender.loadCheckout(i.id,Object.assign(Object.assign({},e),{params:{include:[zd.AvailableShippingOptions]}})).then(({body:e})=>{n.next(o(Xe.LoadShippingOptionsSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Xe.LoadShippingOptionsFailed,e))})})}updateAddress(e,t){return n=>{const i=this._getUpdateAddressRequestBody(e,n),r=n.getState().consignments.getConsignments();return r&&r.length&&(i.id=r[0].id),this._createOrUpdateConsignment(i,t)(n)}}createConsignments(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r||!r.id)throw new qi(xi.MissingCheckout);i.next(o(Xe.CreateConsignmentsRequested)),this._consignmentRequestSender.createConsignments(r.id,e,t).then(({body:e})=>{i.next(o(Xe.CreateConsignmentsSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Xe.CreateConsignmentsFailed,e))})})}updateConsignment(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r||!r.id)throw new qi(xi.MissingCheckout);const a={id:e.id};i.next(o(Xe.UpdateConsignmentRequested,void 0,a)),this._consignmentRequestSender.updateConsignment(r.id,e,t).then(({body:e})=>{i.next(o(Xe.UpdateConsignmentSucceeded,e,a)),i.complete()}).catch(e=>{i.error(s(Xe.UpdateConsignmentFailed,e,a))})})}deleteConsignment(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout(),a={id:e};if(!r||!r.id)throw new qi(xi.MissingCheckout);i.next(o(Xe.DeleteConsignmentRequested,void 0,a)),this._consignmentRequestSender.deleteConsignment(r.id,e,t).then(({body:e})=>{i.next(o(Xe.DeleteConsignmentSucceeded,e,a)),i.complete()}).catch(e=>{i.error(s(Xe.DeleteConsignmentFailed,e,a))})})}updateShippingOption(e,t){return n=>j.create(i=>{var r;const a=n.getState().checkout.getCheckout(),d=n.getState().consignments.getConsignmentById(e.id);if((null===(r=null==d?void 0:d.selectedShippingOption)||void 0===r?void 0:r.id)===e.shippingOptionId)return void i.complete();if(!a||!a.id)throw new qi(xi.MissingCheckout);const c={id:e.id};i.next(o(Xe.UpdateShippingOptionRequested,void 0,c)),this._consignmentRequestSender.updateConsignment(a.id,e,t).then(({body:e})=>{i.next(o(Xe.UpdateShippingOptionSucceeded,e,c)),i.complete()}).catch(e=>{i.error(s(Xe.UpdateShippingOptionFailed,e,c))})})}_createOrUpdateConsignment(e,t){return n=>{const i=n.getState().checkout.getCheckout();if(!i||!i.id)throw new qi(xi.MissingCheckout);return this._isUpdateConsignmentRequest(e)?this.updateConsignment(e,t)(n):this.createConsignments([e],t)(n)}}_getUpdateAddressRequestBody(e,t){const n=t.getState().cart.getCart();if(!n)throw new qi(xi.MissingCart);const{physicalItems:i,customItems:r=[]}=n.lineItems;return{address:e,lineItems:[...i,...r].map(e=>({itemId:e.id,quantity:e.quantity}))}}_removeLineItems(e,t,n){if(!n)throw new qi(xi.MissingCart);return this._hydrateLineItems(t.lineItemIds,n).map(t=>{const n=l(e,e=>e.itemId===t.itemId);return Object.assign(Object.assign({},t),{quantity:n?t.quantity-n.quantity:t.quantity})}).filter(e=>e.quantity>0)}_addLineItems(e,t,n){if(!t)return e;if(!n)throw new qi(xi.MissingCart);return e.concat(this._hydrateLineItems(t.lineItemIds,n)).filter(e=>e.quantity>0)}_hydrateLineItems(e,t){return e.map(e=>{const n=l(t.lineItems.physicalItems,t=>t.id===e);return{itemId:e,quantity:n?n.quantity:0}})}_isUpdateConsignmentRequest(e){return!!e.id}_consignmentHasAddress(e){return"object"==typeof e&&"address"in e}}const ou=["consignments.availableShippingOptions","cart.lineItems.physicalItems.options","cart.lineItems.digitalItems.options","customer","promotions.banners"];class au{constructor(e){this._requestSender=e}createConsignments(e,t,{timeout:n,params:{include:i}={}}={}){const r=`/api/storefront/checkouts/${e}/consignments`,o=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(r,{body:t,params:{include:Td(ou,i)},headers:o,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}updateConsignment(e,t,{timeout:n,params:{include:i}={}}={}){const{id:r}=t,o=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["id"]),a=`/api/storefront/checkouts/${e}/consignments/${r}`,s=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.put(a,{body:o,params:{include:Td(ou,i)},headers:s,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}deleteConsignment(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/consignments/${t}`,r=Object.assign({Accept:yd.JsonV1},vd),o=Ad(ou);return this._requestSender.delete(i,{params:{include:o},headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}class su{constructor(e,t){this._shippingCountryRequestSender=e,this._store=t}loadCountries(e){const{checkout:t}=this._store.getState(),n=t.getCheckout(),i=n?n.channelId:null;return j.create(t=>{t.next(o(si.LoadShippingCountriesRequested)),this._shippingCountryRequestSender.loadCountries(i,e).then(e=>{t.next(o(si.LoadShippingCountriesSucceeded,e.body.data)),t.complete()}).catch(e=>{t.error(s(si.LoadShippingCountriesFailed,e))})})}}class du{constructor(e,t){this._requestSender=e,this._config=t}loadCountries(e,{timeout:t}={}){const n="/internalapi/v1/shipping/countries"+(e?`?channel_id=${e}`:""),i=Object.assign({"Accept-Language":this._config.locale},vd);return this._requestSender.get(n,{headers:i,timeout:t})}}var cu=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class uu{constructor(e,t){this._googleRecaptcha=e,this._requestSender=t}initialize(e){return t=>H(Q(o(Ni.InitializeRequested,void 0)),V(()=>cu(this,void 0,void 0,function*(){const n=e?e.containerId:"spamProtectionContainer";if(document.getElementById(n)&&this._googleRecaptcha.reset(n),!e&&!document.getElementById(n)){const e=document.createElement("div");e.setAttribute("id",n),document.body.appendChild(e)}const i=t.getState().config.getStoreConfigOrThrow().checkoutSettings.googleRecaptchaSitekey;return yield this._googleRecaptcha.load(n,i),o(Ni.InitializeSucceeded)}))).pipe(J(e=>Cd(Ni.InitializeFailed,e)))}verifyCheckoutSpamProtection(){return e=>V(()=>{const t=e.getState().checkout.getCheckout();if(!t)throw new qi(xi.MissingCheckout);return H(Q(o(Ni.VerifyCheckoutRequested)),W(this.execute()(e)).pipe(re(e=>qd(e)&&e.payload?W(this._requestSender.validate(t.id,e.payload.token)).pipe(re(({body:t})=>H(Q(e),Q(o(Ni.VerifyCheckoutSucceeded,t))))):Q(e)))).pipe(J(e=>Cd(Ni.VerifyCheckoutFailed,e)))})}execute(){return e=>H(Q(o(Ni.ExecuteRequested)),this.initialize()(e),this._googleRecaptcha.execute().pipe(oe(1)).pipe(re(({error:e,token:t})=>cu(this,void 0,void 0,function*(){if(e instanceof ec)throw e;if(e||!t)throw new cc;return o(Ni.ExecuteSucceeded,{token:t})})))).pipe(J(e=>Cd(Ni.ExecuteFailed,e)))}}class lu{constructor(e){this._requestSender=e}validate(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/spam-protection`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(i,{body:{token:t},headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}class hu{constructor(e){this._storeCreditRequestSender=e}applyStoreCredit(e,t){return n=>H(Q(o(Ei.ApplyStoreCreditRequested)),V(()=>{return i=this,r=void 0,s=function*(){const i=n.getState().checkout.getCheckout();if(!i)throw new qi(xi.MissingCheckout);const{body:r}=yield e?this._storeCreditRequestSender.applyStoreCredit(i.id,t):this._storeCreditRequestSender.removeStoreCredit(i.id,t);return o(Ei.ApplyStoreCreditSucceeded,r)},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{d(s.next(e))}catch(e){t(e)}}function o(e){try{d(s.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof a?i:new a(function(e){e(i)})).then(n,o)}d((s=s.apply(i,r||[])).next())});var i,r,a,s})).pipe(J(e=>Cd(Ei.ApplyStoreCreditFailed,e)))}}class pu{constructor(e){this._requestSender=e}applyStoreCredit(e,{timeout:t}={}){const n=`/api/storefront/checkouts/${e}/store-credit`,i=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(n,{headers:i,timeout:t,params:{include:Ad(kd)}})}removeStoreCredit(e,{timeout:t}={}){const n=`/api/storefront/checkouts/${e}/store-credit`,i=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.delete(n,{headers:i,timeout:t,params:{include:Ad(kd)}})}}class mu extends Pe{constructor(e){super(e),this.name="UpdateSubscriptionsError",this.type="update_subscriptions"}}class gu{constructor(e){this._subscriptionsRequestSender=e}updateSubscriptions(e,t){return H(Q(o(ze.UpdateSubscriptionsRequested)),V(()=>{return n=this,i=void 0,a=function*(){const{body:n}=yield this._subscriptionsRequestSender.updateSubscriptions(e,t);return o(ze.UpdateSubscriptionsSucceeded,n)},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(e=>Cd(ze.UpdateSubscriptionsFailed,new mu(e))))}}class yu{constructor(e){this._requestSender=e}updateSubscriptions(e,{timeout:t}={}){const n=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post("/api/storefront/subscriptions",{body:e,headers:n,timeout:t})}}const fu=A(e=>Array.isArray(e)?e.map(e=>vu(e)):$e(e)?Object.keys(e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:vu(e[n])}),{}):e);fu.cache=new WeakMap;const vu=e=>"object"==typeof e&&null!==e?fu(e):e;function Su(e){return(...t)=>vu(e(...t))}function Cu({billingAddress:{getBillingAddress:e,getBillingAddressOrThrow:t},cart:{getCart:n,getCartOrThrow:i},checkout:{getCheckout:r,getCheckoutOrThrow:o,getOutstandingBalance:a},config:{getContextConfig:s,getHost:d,getLocale:c,getStoreConfig:u,getStoreConfigOrThrow:l,getConfig:h},consignments:{getConsignments:p,getConsignmentsOrThrow:m},countries:{getCountries:g},customer:{getCustomer:y,getCustomerOrThrow:f},instruments:{getCardInstrument:v,getCardInstrumentOrThrow:S,getInstruments:C,getInstrumentsMeta:I},order:{getOrder:_,getOrderOrThrow:w,getOrderMeta:b},payment:{getPaymentToken:E,getPaymentTokenOrThrow:P,getPaymentId:O,getPaymentIdOrThrow:A,getPaymentStatus:T,getPaymentStatusOrThrow:k,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:R,isPaymentDataRequired:M},paymentMethods:{getPaymentMethod:N,getPaymentMethodOrThrow:L,getPaymentMethodsMeta:z},paymentProviderCustomer:{getPaymentProviderCustomer:U,getPaymentProviderCustomerOrThrow:F},paymentStrategies:{isInitialized:B},shippingAddress:{getShippingAddress:x,getShippingAddressOrThrow:q,getShippingAddresses:j,getShippingAddressesOrThrow:G},shippingCountries:{getShippingCountries:H}}){return{getHost:Su(d),getLocale:Su(c),getBillingAddress:Su(e),getBillingAddressOrThrow:Su(t),getCart:Su(n),getCartOrThrow:Su(i),getCheckout:Su(r),getCheckoutOrThrow:Su(o),getCountries:Su(g),getStoreConfig:Su(u),getStoreConfigOrThrow:Su(l),getConfig:Su(h),getConsignments:Su(p),getConsignmentsOrThrow:Su(m),getContextConfig:Su(s),getCustomer:Su(y),getCustomerOrThrow:Su(f),getCardInstrument:Su(v),getInstruments:Su(C),getCardInstrumentOrThrow:Su(S),getOrder:Su(_),getOrderOrThrow:Su(w),getOrderMeta:Su(b),getInstrumentsMeta:Su(I),getPaymentToken:E,getPaymentTokenOrThrow:P,getPaymentId:O,getPaymentIdOrThrow:A,getPaymentStatus:T,getPaymentStatusOrThrow:k,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:R,getPaymentMethod:Su(N),getPaymentMethodOrThrow:Su(L),getPaymentMethodsMeta:Su(z),getPaymentProviderCustomer:Su(U),getPaymentProviderCustomerOrThrow:Su(F),getShippingAddress:Su(x),getShippingAddressOrThrow:Su(q),getShippingAddresses:Su(j),getShippingAddressesOrThrow:Su(G),getShippingCountries:Su(H),getOutstandingBalance:Su(a),isPaymentDataRequired:M,isPaymentMethodInitialized:B}}var Iu,_u=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class wu{constructor(e,t,n,i,r,o,a,s,d,c,u,l,h,p,m,g,y,f,v,S){this._store=e,this._storeProjectionFactory=t,this._checkoutActionCreator=n,this._checkoutValidator=i,this._hostedFormFactory=r,this._orderActionCreator=o,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 n=this._storeProjection.getState().getCheckoutOrThrow().id;return this._hostedFormFactory.create(e,t,n)}subscribe(e,...t){return this._storeProjection.subscribe(e,...t)}getState(){return this._storeProjection.getState()}initializeOffsitePayment(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.initializeOffsitePayment(e)),this._storeProjection.getState()})}loadCheckout(e){return _u(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 _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()),this._storeProjection.getState()})}loadPaymentMethod(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethod(e,t)),this._storeProjection.getState()})}loadPaymentMethods(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethods(e)),this._storeProjection.getState()})}submitOrder(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.submitOrder(e,t)),this._storeProjection.getState()})}submitPayment(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.submitPayment(e)),this._storeProjection.getState()})}finalizeOrder(e){return _u(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 _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._billingAddressActionCreator.updateAddress(e)),this._storeProjection.getState()})}updateShippingAddress(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.updateAddress(e)),this._storeProjection.getState()})}selectShippingOption(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.selectShippingOption(e,t)),this._storeProjection.getState()})}signInCustomer(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signInCustomer(e,t)),this._storeProjection.getState()})}signOutCustomer(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signOutCustomer(e)),this._storeProjection.getState()})}createBuyNowCart(e,t){return _u(this,void 0,void 0,function*(){const{body:n}=yield this._cartRequestSender.createBuyNowCart(e,t);return n})}applyStoreCredit(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._storeCreditActionCreator.applyStoreCredit(e,t)),this._storeProjection.getState()})}applyCoupon(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.applyCoupon(e,t)),this._storeProjection.getState()})}removeCoupon(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.removeCoupon(e,t)),this._storeProjection.getState()})}verifyCheckoutSpamProtection(){return _u(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 _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.loadCurrentOrder(e)),this._storeProjection.getState()})}updatePaymentProviderCustomer(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentProviderCustomerActionCreator.updatePaymentProviderCustomer(e)),this._storeProjection.getState()})}loadShippingCountries(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._shippingCountryActionCreator.loadCountries(e)),this._storeProjection.getState()})}deleteConsignment(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.deleteConsignment(e,t)),this._storeProjection.getState()})}initializePayment(e,t,n){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.initializePayment(e,t,n)),this._storeProjection.getState()})}forgetCheckout(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.forgetCheckout(e,t)),this._storeProjection.getState()})}remoteCheckoutSignOut(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.signOut(e,t)),this._storeProjection.getState()})}validateCheckout(e,t){return _u(this,void 0,void 0,function*(){yield this._checkoutValidator.validate(e,t)})}handlePaymentHumanVerification(e,t){return _u(this,void 0,void 0,function*(){return"string"==typeof e?this._paymentHumanVerificationHandler.handle(e,null!=t?t:""):this._paymentHumanVerificationHandler.handle(e)})}widgetInteraction(e){return _u(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"}(Iu||(Iu={}));class bu{constructor(e){this._transformSelectors=e}create(e){return function(e,t){const n=a((e,t)=>t.type===Iu.Synchronize?t.payload:e,e.getState(),{stateTransformer:t});return e.subscribe(e=>{n.dispatch(o(Iu.Synchronize,e))},{initial:!1}),n}(e,this._transformSelectors)}}const Eu=e=>{const t=B(e);return document.getElementById(t)?Eu(e):t};function Pu(e){return Object.prototype.hasOwnProperty.call(e,"cacheKey")}class Ou{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:n,parentMap:i}=t;let{map:r}=t;return r&&r.cacheKey?r.usedCount++:r=this._generateMap(i,e.slice(n)),this._removeLeastUsedMap(r),r.cacheKey}getUsedCount(...e){const{map:t}=this._resolveMap(...e);return t?t.usedCount:0}_resolveMap(...e){let t=0,n=this._map;for(;n.maps.length;){let i=!1;for(let r=0;r<n.maps.length;r++){const o=n.maps[r];if(this._options.isEqual(o.value,e[t])){if(n.maps.unshift(...n.maps.splice(r,1)),(0===e.length||t===e.length-1)&&Pu(o))return{index:t,map:o,parentMap:n};i=!0,n=o,t++;break}}if(!i)break}return{index:t,parentMap:n}}_generateMap(e,t){let n,i=0,r=e;do{n={maps:[],parentMap:r,usedCount:1,value:t[i]},r.maps.unshift(n),r=n,i++}while(i<t.length);const o=n;return o.cacheKey=""+ ++this._lastId,o}_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 n=this._usedMaps.pop();n&&(this._removeMap(n),this._options.onExpire(n.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 Au(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(n=>{const i=Object.getOwnPropertyDescriptor(e.prototype,n);i&&"constructor"!==n&&Object.defineProperty(t.prototype,n,function(e,t,n){if("function"!=typeof n.value)return n;let i=new Ou,r=n.value,o=ae(r);return _a(e,t,{get(){const e=(...e)=>{const t=o.call(this,...e);if(1===i.getUsedCount(...e))return t;const n=r.call(this,...e);return xe(n,t,{keyFilter:e=>!function(e){return 0===`${e}`.indexOf("$$")||0===`${e}`.indexOf("_")}(e)})?t:(o.cache.set(i.getKey(...e),n),n)};return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e},set(e){i=new Ou,r=e,o=ae(r)}})}(e.prototype,n,i))}),t}let Tu=class{constructor(e){this._checkoutButton=e.checkoutButton}getInitializeButtonError(e){return this._checkoutButton.getInitializeError(e)}getDeinitializeButtonError(e){return this._checkoutButton.getDeinitializeError(e)}};Tu=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([Au],Tu);const ku=Tu;let Du=class{constructor(e){this._checkoutButton=e.checkoutButton}isInitializingButton(e){return this._checkoutButton.isInitializing(e)}isDeinitializingButton(e){return this._checkoutButton.isDeinitializing(e)}};Du=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([Au],Du);const Ru=Du;function Mu(e){return{errors:new ku(e),statuses:new Ru(e)}}let Nu=class{constructor(e,t){this._store=e,this._buttonStrategyActionCreator=t,this._state=Mu(this._store.getState()),this._store.subscribe(e=>{this._state=Mu(e)})}getState(){return this._state}subscribe(e,...t){return this._store.subscribe(()=>e(this.getState()),e=>e.checkoutButton.getState(),...t.map(e=>t=>e(Mu(t))))}initializeButton(e){const t=(n=e.containerId,/^\w[\w\-\:\.]*$/.test(n)?[e.containerId]:function(e,t){const n=document.querySelectorAll(e);if(!n.length)throw new Kd(`Unable to find any element with the specified selector: ${e}`);return Array.prototype.slice.call(n).map(e=>(e.id||(e.id=Eu(t)),e.id))}(e.containerId,`${e.methodId}-container`));var n;return Promise.all(t.map(t=>{const n=this._buttonStrategyActionCreator.initialize(Object.assign(Object.assign({},e),{containerId:t})),i=`checkoutButtonStrategy:${e.methodId}:${t}`;return this._store.dispatch(n,{queueId:i})})).then(()=>this.getState())}deinitializeButton(e){const t=this._buttonStrategyActionCreator.deinitialize(e),n=`checkoutButtonStrategy:${e.methodId}`;return this._store.dispatch(t,{queueId:n}).then(()=>this.getState())}};Nu=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([_a],Nu);const Lu=Nu;class zu{constructor(e,t,n){this._registry=e,this._registryV2=t,this._paymentMethodActionCreator=n}initialize(e){return t=>{const n={methodId:e.methodId,containerId:e.containerId};if(t.getState().checkoutButton.isInitialized(e.methodId,e.containerId))return Y();const i=e.currencyCode?{params:{currencyCode:e.currencyCode}}:{},r=Object.assign(Object.assign({},i),{timeout:e.timeout,useCache:!0});return H(Q(o(ot.InitializeButtonRequested,void 0,n)),this._paymentMethodActionCreator.loadPaymentMethod(e.methodId,r)(t),V(()=>this._getStrategy(e.methodId).initialize(e).then(()=>o(ot.InitializeButtonSucceeded,void 0,n)))).pipe(J(e=>Cd(ot.InitializeButtonFailed,e,n)))}}deinitialize(e){return t=>{const n={methodId:e.methodId};return t.getState().checkoutButton.isInitialized(e.methodId)?H(Q(o(ot.DeinitializeButtonRequested,void 0,n)),V(()=>this._getStrategy(e.methodId).deinitialize().then(()=>o(ot.DeinitializeButtonSucceeded,void 0,n)))).pipe(J(e=>Cd(ot.DeinitializeButtonFailed,e,n))):Y()}}_getStrategy(e){let t;try{t=this._registryV2.get({id:e})}catch(n){t=this._registry.get(e)}return t}}class Uu{constructor(e){var t,n,i;this._factories={},this._instances={},this._defaultToken=null!==(t=null==e?void 0:e.defaultToken)&&void 0!==t?t:"default",this._useFallback=null===(n=null==e?void 0:e.useFallback)||void 0===n||n,this._tokenResolver=null!==(i=null==e?void 0:e.tokenResolver)&&void 0!==i?i: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){const t=this._tokenResolver(e,Object.keys(this._factories));return t?this._factories[t]:void 0}register(e,t){if(this._hasFactory(e))throw new Kd(`'${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 n=this.getFactory(e);if(!n)throw new Kd(`'${e}' is not registered.`);this._instances[t]=n()}return this._instances[t]}}class Fu 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"}}class Bu{constructor(e,t=window){this._scriptLoader=e,this._window=t}load({useMasterpassSrc:e,language:t,testMode:n,checkoutId:i}){return r=this,o=void 0,s=function*(){if(e){const e=[`https://${n?"sandbox.":""}src.mastercard.com/srci/integration/merchant.js`,[`locale=${t}`,`checkoutid=${i}`].join("&")].join("?");if(yield this._scriptLoader.loadScript(e),!this._window.masterpass)throw new Fu;return this._window.masterpass}if(yield this._scriptLoader.loadScript(`//${n?"sandbox.":""}masterpass.com/integration/merchant.js`),!this._window.masterpass)throw new Fu;return this._window.masterpass},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{d(s.next(e))}catch(e){t(e)}}function i(e){try{d(s.throw(e))}catch(e){t(e)}}function d(t){var r;t.done?e(t.value):(r=t.value,r instanceof a?r:new a(function(e){e(r)})).then(n,i)}d((s=s.apply(r,o||[])).next())});var r,o,a,s}}class xu{constructor(e){this._scriptLoader=e,this._window=window}loadPaypal(e=""){return t=this,n=void 0,r=function*(){const t="//www.paypalobjects.com/api/checkout.min.js",n={async:!0,attributes:{"data-merchant-id":e}};if(e?yield this._scriptLoader.loadScript(t,n):yield this._scriptLoader.loadScript(t),!this._window.paypal)throw new Fu;return this._window.paypal},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}}const qu={es:["es_es","es_mx","es_pe","es_co","es_ar","es_cl"],en:["en_us","en_gb","en_ca","en_es","en_fr","en_ie","en_sg","en_au","en_nz","en_my","en_hk","en_th","en_ae","en_sa","en_qa","en_kw","en_za"],pt:["pt_br"],zu:["zu_za"],ar:["ar_sa","ar_ae","ar_qa","ar_kw"],zh:["zh_sg","zh_hk"],ms:["ms_my"],uk:["uk_ua"],sv:["sv_se"],hr:["hr_hr"],pl:["pl_pl"],nl:["nl_be"],it:["it_it"],de:["de_de"],fr:["fr_fr","fr_ca"]};function ju(e){const[t,n]=e.replace("-","_").toLowerCase().split("_"),i=`${t}_${n}`,r=qu[t];return r?r.indexOf(i)>-1?i:r[0]:"en_us"}var Gu,Hu,Vu,Yu,Wu;class $u{constructor(e,t,n,i){this._store=e,this._checkoutActionCreator=t,this._masterpassScriptLoader=n,this._locale=i}initialize(e){const{containerId:t,methodId:n}=e;if(!t||!n)throw new Kd('Unable to proceed because "containerId" argument is not provided.');return this._methodId=n,this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()).then(e=>{const t=e.paymentMethods.getPaymentMethod(n);if(!t||!t.initializationData.checkoutId)throw new qi(xi.MissingPaymentMethod);const i={useMasterpassSrc:t.initializationData.isMasterpassSrcEnabled,language:ju(this._locale),testMode:t.config.testMode,checkoutId:t.initializationData.checkoutId};return this._masterpassScriptLoader.load(i)}).then(e=>{this._masterpassClient=e,this._signInButton=this._createSignInButton(t)})}deinitialize(){return this._signInButton&&this._signInButton.parentNode&&(this._signInButton.removeEventListener("click",this._handleWalletButtonClick),this._signInButton.parentNode.removeChild(this._signInButton),this._signInButton=void 0),Promise.resolve()}_createSignInButton(e){const t=document.getElementById(e),n=this._store.getState(),i=this._methodId?n.paymentMethods.getPaymentMethod(this._methodId):null,r=n.config.getStoreConfig();if(!t)throw new Error("Need a container to place the button");if(!i)throw new qi(xi.MissingPaymentMethod);if(!r)throw new Kd("Unable to retrieve store configuration");const o=document.createElement("input");if(o.type="image",i.initializationData.isMasterpassSrcEnabled){const e=i.config.testMode?"sandbox.":"",{checkoutId:t}=i.initializationData,n=[`locale=${ju(this._locale)}`,"paymentmethod=master,visa,amex,discover",`checkoutid=${t}`];o.src=[`https://${e}src.mastercard.com/assets/img/btn/src_chk_btn_126x030px.svg`,n.join("&")].join("?")}else o.src="https://static.masterpass.com/dyn/img/btn/global/mp_chk_btn_160x037px.svg";return t.appendChild(o),o.addEventListener("click",this._handleWalletButtonClick),o}_createMasterpassPayload(){const e=this._store.getState(),t=e.checkout.getCheckout(),n=this._methodId?e.paymentMethods.getPaymentMethod(this._methodId):null;if(!t)throw new qi(xi.MissingCheckout);if(!n)throw new qi(xi.MissingPaymentMethod);return{checkoutId:n.initializationData.checkoutId,allowedCardTypes:n.initializationData.allowedCardTypes,amount:t.cart.cartAmount.toString(),currency:t.cart.currency.code,cartId:t.cart.id,callbackUrl:`${window.location.origin}/checkout.php?action=set_external_checkout&provider=masterpass&gateway=stripe&origin=cart`}}_handleWalletButtonClick(){if(!this._masterpassClient)throw new dc(ic.CheckoutButtonNotInitialized);this._masterpassClient.checkout(this._createMasterpassPayload())}}(function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)})([_a],$u.prototype,"_handleWalletButtonClick",null),function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(Gu||(Gu={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Hu||(Hu={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(Vu||(Vu={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Yu||(Yu={})),function(e){e.PILL="pill",e.RECT="rect"}(Wu||(Wu={}));class Ku{constructor(e,t,n,i,r=""){this._store=e,this._checkoutActionCreator=t,this._paypalScriptLoader=n,this._formPoster=i,this._host=r}initialize(e){const t=e.paypal,n=this._store.getState(),i=this._paymentMethod=n.paymentMethods.getPaymentMethod(e.methodId);if(!t)throw new Kd;if(!i)throw new qi(xi.MissingPaymentMethod);return this._paypalScriptLoader.loadPaypal(i.config.merchantId).then(n=>{var r,o;if(!i||!i.config.merchantId)throw new qi(xi.MissingPaymentMethod);const a=i.config.merchantId,s=i.config.testMode?"sandbox":"production",d={[s]:t.clientId},c=n.FUNDING.CREDIT||"credit",u=t.allowCredit?[c]:[],l=t.allowCredit?[]:[c];return n.Button.render({env:s,client:d,commit:t.shouldProcessPayment,funding:{allowed:u,disallowed:l},style:Object.assign(Object.assign({shape:Wu.RECT},R(t.style,"layout","color","label","shape","tagline","fundingicons")),{size:"paypalexpress"===i.id&&"small"===(null===(r=t.style)||void 0===r?void 0:r.size)?Hu.RESPONSIVE:null===(o=t.style)||void 0===o?void 0:o.size}),payment:(e,n)=>this._setupPayment(a,n,t.onPaymentError),onAuthorize:(e,n)=>this._tokenizePayment(e,n,t.shouldProcessPayment,t.onAuthorizeError)},e.containerId)})}deinitialize(){return this._paymentMethod=void 0,Promise.resolve()}_setupPayment(e,t,n){if(!t)throw new dc(ic.CheckoutButtonNotInitialized);return this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()).then(n=>{const i=n.cart.getCart(),r=i?i.id:"";return t.request.post(`${this._host}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:r},{headers:Object.assign({"X-API-INTERNAL":fd},vd)})}).then(e=>e.id).catch(e=>{throw n&&n(e),e})}_tokenizePayment(e,t,n,i){if(!this._paymentMethod)throw new dc(ic.CheckoutButtonNotInitialized);if(!t)throw new dc(ic.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new qi(xi.MissingPayment);const r=this._paymentMethod.id;return t.payment.get(e.paymentID).then(t=>{this._formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:r,action:n?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(t.payer.payer_info)})})}}function Qu(e){return e&&"resolveIds"in e}function Zu(){try{return"production"}catch(e){return"development"}}class Ju{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 Xu{log(){}info(){}warn(){}error(){}debug(){}}const el=function(e=!0){return e?new Ju(console):new Xu}("test"!==Zu());class tl{constructor(e=!1){this._useFallback=e,this._registry=new Uu({tokenResolver:this._resolveToken.bind(this),useFallback:this._useFallback})}get(e){return this._registry.get(this._encodeToken(e))}getFactory(e){try{return this._registry.getFactory(this._encodeToken(e))}catch(e){return}}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){var n;const i=this._decodeToken(e),r=[];t.forEach(e=>{const t=this._decodeToken(e),n={token:e,matches:0,default:!1};for(const[e,r]of Object.entries(t)){if(e in i&&i[e]!==r){n.matches=0;break}e in i&&i[e]===r&&n.matches++,"default"===e&&!0===r&&(n.default=!0)}r.push(n)});const o=r.sort((e,t)=>t.matches-e.matches).filter(e=>e.matches>0);o.length>1&&o[0].matches===o[1].matches&&"development"===Zu()&&el.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 a=o[0];if(a&&a.token)return a.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 nl(t){const{host:i,locale:r="en"}=null!=t?t:{},o=Qi({config:{meta:{host:null==t?void 0:t.host,locale:null==t?void 0:t.locale},errors:{},statuses:{}}}),a=e({host:i}),s=n({host:i}),d=function(e,t){const n=new tl;for(const[,i]of Object.entries(t))if(Qu(i))for(const t of i.resolveIds)n.register(t,()=>i(e));return n}(function(t){const{config:{getHost:n,getLocale:i}}=t.getState(),r=e({host:n()}),o=new bu(Cu),a=new Od(new Rd(r),new Ud(new Fd(r)),new Hd(new Vd(r))),s=new Ld(new Rd(r)),d=new wc(t),c=new Ec(new kc(r),new Ld(new Rd(r))),u=new _d(new Ed(r),new gu(new yu(r))),l=new ru(new au(r),new Rd(r)),h=new md(new Sd(r)),p=new Dc(new Rc(function(e){const t=me();return e.subscribe(e=>{const n=e.config.getStoreConfig();n&&t.setHost(n.paymentSettings.bigpayBaseUrl)},e=>e.config.getStoreConfig()),t}(t)),c,new Xc,new sc(pc(ue()))),m=new sc(pc(ue())),g=new jd(new Gd(r),a,new uu(pc(ue()),new lu(r))),y=new hu(new pu(r)),f=new Bd(new xd(r)),v=pc(ue()),S=new lu(r),C=new uu(v,S),I=new Pd(r),_=new eu,w=new su(new du(r,{locale:i()}),t),b=new nu(new iu(r),a),E=new tu;return new wu(t,o,a,s,d,c,u,l,h,p,m,g,I,y,f,C,_,w,b,E)}(o),Se);return new Lu(o,new zu(function(e,t,n,i,r){const o=new Uu,a=le(),s=new Rd(t),d=new Od(s,new Ud(new Fd(t)),new Hd(new Vd(t)));return o.register(jc.MASTERPASS,()=>new $u(e,d,new Bu(a),i)),o.register(jc.PAYPALEXPRESS,()=>new Ku(e,d,new xu(a),n,r)),o}(o,a,s,r,i),d,new md(new Sd(a))))}export{nl as createCheckoutButtonInitializer,t as createTimeout};
1
+ import{createRequestSender as e,createTimeout as t}from"@bigcommerce/request-sender";import{createFormPoster as n}from"@bigcommerce/form-poster";import{combineReducers as i,composeReducers as r,createAction as o,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 D,pick as R,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 Q,throwError as Z}from"rxjs";import{catchError as J,delay as X,filter as ee,map as te,retryWhen as ne,shareReplay as ie,switchMap as re,take as oe}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 n in t)ve.o(t,n)&&!ve.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},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:()=>Pr,createApplePayButtonStrategy:()=>ro,createBigCommercePaymentsAlternativeMethodsButtonStrategy:()=>Ro,createBigCommercePaymentsButtonStrategy:()=>wo,createBigCommercePaymentsPayLaterButtonStrategy:()=>To,createBigCommercePaymentsVenmoButtonStrategy:()=>Lo,createBoltButtonStrategy:()=>Go,createBraintreePaypalButtonStrategy:()=>sa,createBraintreePaypalCreditButtonStrategy:()=>la,createBraintreeVenmoButtonStrategy:()=>Ca,createBraintreeVisaCheckoutButtonStrategy:()=>ma,createGooglePayAdyenV2ButtonStrategy:()=>rs,createGooglePayAdyenV3ButtonStrategy:()=>os,createGooglePayAuthorizeDotNetButtonStrategy:()=>ss,createGooglePayBigCommercePaymentsButtonStrategy:()=>is,createGooglePayBraintreeButtonStrategy:()=>$a,createGooglePayCheckoutComButtonStrategy:()=>hs,createGooglePayCybersourceButtonStrategy:()=>ms,createGooglePayOrbitalButtonStrategy:()=>ys,createGooglePayPayPalCommerceButtonStrategy:()=>es,createGooglePayStripeButtonStrategy:()=>_s,createGooglePayTdOnlineMartButtonStrategy:()=>As,createGooglePayWorldpayAccessButtonStrategy:()=>bs,createPayPalCommerceAlternativeMethodsButtonStrategy:()=>td,createPayPalCommerceButtonStrategy:()=>Vs,createPayPalCommerceCreditButtonStrategy:()=>Ks,createPayPalCommerceVenmoButtonStrategy:()=>Js,createPaypalExpressButtonStrategy:()=>ld});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:n}={}){const{body:i,headers:r,status:o}=e||Ie;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}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:n}={}){const{body:i,headers:r,status:o}=e||Ee;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}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:n}=e,{errors:i=[]}=n;return new Pe(e,{message:ke(i)||t,errors:i})}function ke(e){if(Array.isArray(e))return e.reduce((e,t)=>t&&t.message?[...e,t.message]:e,[]).join(" ")}class De extends Pe{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}class Re{constructor(){this._factoryMethods={},this.register("default",(e,t)=>new Pe(e,{message:t})),this.register("internal",(e,t)=>function(e,t){const{body:n}=e,{errors:i=[]}=n;return new Pe(e,{message:Ae(i)||n.detail||n.title||t,errors:i.length?i.map(e=>({code:n.type,message:e})):[{code:n.type,message:n.detail||n.title}]})}(e,t)),this.register("storefront",(e,t)=>function(e,t){const{body:n}=e;return new Pe(e,{message:t||n.detail||n.title,errors:[{code:n.code||n.type,message:n.detail||n.title}]})}(e,t)),this.register("payment",(e,t)=>Te(e,t)),this.register("timeout",e=>new De(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(D(e,t),(e,n,i)=>{e[i]=Fe(n,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,n){return e===t||(e&&t&&"object"==typeof e&&"object"==typeof t?Array.isArray(e)&&Array.isArray(t)?function(e,t,n){if(e.length!==t.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!xe(e[i],t[i],n))return!1;return!0}(e,t,n):!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,n){const i=n&&n.keyFilter,r=i?Object.keys(e).filter(i):Object.keys(e),o=i?Object.keys(t).filter(i):Object.keys(t);if(r.length!==o.length)return!1;for(let i=0,o=r.length;i<o;i++){const o=r[i];if(!Object.prototype.hasOwnProperty.call(t,o))return!1;if(!xe(e[o],t[o],n))return!1}return!0}(e,t,n))):e===t)}function qe(e,t){return void 0===t||xe(e,t)?e:t}function je(e,t,n){return e&&Object.prototype.hasOwnProperty.call(e,t)&&xe(e[t],n)?e:Object.assign(Object.assign({},e),{[t]:n})}!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 i({data:Ve,errors:r(Ye,Be),statuses:We})(e,t)}function Ve(e,t){var n,i;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===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.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,n,i){const{matchObject:r=(e,t)=>void 0!==e.id&&e.id===t.id}=i||{};if(!t)return n;if(!n||t===n)return t;let o=0,a=0;const s=(e,t,n)=>(o+=e===t?1:0,a+=e===n?1:0,e),d=n.map((n,i)=>{const o=t&&t[i];return $e(o)&&$e(n)?r(o,n)?s(Qe(o,n),o,n):s(qe(o,n),o,n):y(o)&&y(n)?s(e(o,n),o,n):s(qe(o,n),o,n)});return o===n.length&&t&&t.length===n.length?t:a===n.length?n:d},Qe=function e(t,n){return t?n&&t!==n?Object.keys(n).reduce((t,i)=>{const r=t[i],o=n[i];return $e(r)&&$e(o)?je(t,i,e(r,o)):y(r)&&y(o)?je(t,i,Ke(r,o)):je(t,i,o)},t):t:n};var Ze,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"}(Ze||(Ze={})),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 i({data:nt,errors:r(rt,Be),statuses:it})(e,t)}function nt(e,t){var n,i;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 Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Qe(e,t.payload&&t.payload.cart);case Ne.HydrateInitialState:return Qe(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.cart);default:return e}}function it(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 rt(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 ot;!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"}(ot||(ot={}));const at={data:{},errors:{},statuses:{}},st={initializedContainers:{}},dt={},ct={};function ut(e=at,t){return t.meta&&t.meta.methodId?i({data:i({[t.meta.methodId]:lt}),errors:i({[t.meta.methodId]:ht}),statuses:i({[t.meta.methodId]:pt})})(e,t):e}function lt(e=st,t){switch(t.type){case ot.InitializeButtonSucceeded:return t.meta&&t.meta.containerId?Qe(e,{initializedContainers:{[t.meta.containerId]:!0}}):e;case ot.DeinitializeButtonSucceeded:return je(e,"initializedContainers",{})}return e}function ht(e=dt,t){switch(t.type){case ot.InitializeButtonRequested:case ot.InitializeButtonSucceeded:return je(e,"initializeError",void 0);case ot.InitializeButtonFailed:return je(e,"initializeError",t.payload);case ot.DeinitializeButtonRequested:case ot.DeinitializeButtonSucceeded:return je(e,"deinitializeError",void 0);case ot.DeinitializeButtonFailed:return je(e,"deinitializeError",t.payload);default:return e}}function pt(e=ct,t){switch(t.type){case ot.InitializeButtonRequested:return je(e,"isInitializing",!0);case ot.InitializeButtonFailed:case ot.InitializeButtonSucceeded:return je(e,"isInitializing",!1);case ot.DeinitializeButtonRequested:return je(e,"isDeinitializing",!0);case ot.DeinitializeButtonFailed:case ot.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 i({data:ft,errors:r(vt,Be),statuses:St})(e,t)}function ft(e,t){var n;switch(t.type){case mt.LoadConfigSucceeded:return Qe(e,t.payload);case Ne.HydrateInitialState:return Qe(e,null===(n=t.payload)||void 0===n?void 0:n.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 i({data:wt,errors:r(bt,Be),statuses:Et})(e,t)}function wt(e,t){var n,i;switch(t.type){case Me.LoadCheckoutSucceeded:case Ze.ApplyCouponSucceeded:case Xe.UpdateShippingOptionSucceeded:case Ze.RemoveCouponSucceeded:case Ct.LoadOrderSucceeded:return Ke(e,t.payload&&t.payload.coupons);case Ne.HydrateInitialState:return Ke(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.coupons);default:return e}}function bt(e={},t){switch(t.type){case Ze.ApplyCouponRequested:case Ze.ApplyCouponSucceeded:return je(e,"applyCouponError",void 0);case Ze.ApplyCouponFailed:return je(e,"applyCouponError",t.payload);case Ze.RemoveCouponRequested:case Ze.RemoveCouponSucceeded:return je(e,"removeCouponError",void 0);case Ze.RemoveCouponFailed:return je(e,"removeCouponError",t.payload);default:return e}}function Et(e={},t){switch(t.type){case Ze.ApplyCouponRequested:return je(e,"isApplyingCoupon",!0);case Ze.ApplyCouponSucceeded:case Ze.ApplyCouponFailed:return je(e,"isApplyingCoupon",!1);case Ze.RemoveCouponRequested:return je(e,"isRemovingCoupon",!0);case Ze.RemoveCouponSucceeded:case Ze.RemoveCouponFailed:return je(e,"isRemovingCoupon",!1);default:return e}}const Pt={errors:{},statuses:{}};function Ot(e=Pt,t){return i({data:At,errors:r(Tt,Be),statuses:kt})(e,t)}function At(e,t){var n,i;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:return Ke(e,t.payload&&t.payload.giftCertificates);case Ne.HydrateInitialState:return Ke(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.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 Dt;!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"}(Dt||(Dt={}));const Rt={errors:{},statuses:{}};function Mt(e=Rt,t){return i({data:Nt,errors:r(Lt,Be),statuses:zt})(e,t)}function Nt(e,t){var n,i;switch(t.type){case Ue.ContinueAsGuestSucceeded:case Me.LoadCheckoutSucceeded:return Qe(e,t.payload&&t.payload.customer);case Dt.CreateCustomerAddressSucceeded:return Qe(e,t.payload);case Ne.HydrateInitialState:return Qe(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.customer);default:return e}}function Lt(e=Rt.errors,t){switch(t.type){case Dt.CreateCustomerRequested:case Dt.CreateCustomerSucceeded:return je(e,"createError",void 0);case Dt.CreateCustomerFailed:return je(e,"createError",t.payload);case Dt.CreateCustomerAddressRequested:case Dt.CreateCustomerAddressSucceeded:return je(e,"createAddressError",void 0);case Dt.CreateCustomerAddressFailed:return je(e,"createAddressError",t.payload);default:return e}}function zt(e=Rt.statuses,t){switch(t.type){case Dt.CreateCustomerRequested:return je(e,"isCreating",!0);case Dt.CreateCustomerFailed:case Dt.CreateCustomerSucceeded:return je(e,"isCreating",!1);case Dt.CreateCustomerAddressRequested:return je(e,"isCreatingAddress",!0);case Dt.CreateCustomerAddressFailed:case Dt.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 i({data:xt,errors:r(qt,Be),statuses:jt})(e,t)}function xt(e=Ft.data,t){switch(t.type){case Ut.InitializeSucceeded:return Qe(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case Ut.DeinitializeSucceeded:return Qe(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 Qe(e,{initializeErrors:Object.assign({},e.initializeErrors),initializeMethodId:e.initializeMethodId?e.initializeMethodId:void 0});case Ut.InitializeFailed:return Qe(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 Qe(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case Ut.DeinitializeFailed:return Qe(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.SignInRequested:case Ut.SignInSucceeded:return Qe(e,{signInError:void 0,signInMethodId:void 0});case Ut.SignInFailed:return Qe(e,{signInError:t.payload,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignOutRequested:case Ut.SignOutSucceeded:return Qe(e,{signOutError:void 0,signOutMethodId:void 0});case Ut.SignOutFailed:return Qe(e,{signOutError:t.payload,signOutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutRequested:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Qe(e,{executePaymentMethodCheckoutError:void 0,executePaymentMethodCheckoutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutFailed:return Qe(e,{executePaymentMethodCheckoutError:t.payload,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.WidgetInteractionStarted:case Ut.WidgetInteractionFinished:return Qe(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case Ut.WidgetInteractionFailed:return Qe(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function jt(e=Ft.statuses,t){switch(t.type){case Ut.InitializeRequested:return Qe(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case Ut.InitializeFailed:case Ut.InitializeSucceeded:return Qe(e,{isInitializing:!1,initializeMethodId:void 0});case Ut.DeinitializeRequested:return Qe(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case Ut.DeinitializeFailed:case Ut.DeinitializeSucceeded:return Qe(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case Ut.SignInRequested:return Qe(e,{isSigningIn:!0,signInMethodId:t.meta&&t.meta.methodId});case Ut.SignInFailed:case Ut.SignInSucceeded:return Qe(e,{isSigningIn:!1,signInMethodId:void 0});case Ut.SignOutRequested:return Qe(e,{isSigningOut:!0,signOutMethodId:t.meta&&t.meta.methodId});case Ut.SignOutFailed:case Ut.SignOutSucceeded:return Qe(e,{isSigningOut:!1,signOutMethodId:void 0});case Ut.ExecutePaymentMethodCheckoutRequested:return Qe(e,{isExecutingPaymentMethodCheckout:!0,executePaymentMethodCheckoutMethodId:t.meta&&t.meta.methodId});case Ut.ExecutePaymentMethodCheckoutFailed:case Ut.ExecutePaymentMethodCheckoutSucceeded:return Qe(e,{isExecutingPaymentMethodCheckout:!1,executePaymentMethodCheckoutMethodId:void 0});case Ut.WidgetInteractionStarted:return Qe(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case Ut.WidgetInteractionFinished:case Ut.WidgetInteractionFailed:return Qe(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 i({data:Yt,errors:r(Wt,Be),statuses:$t})(e,t)}function Yt(e,t){var n;return t.type===Gt.LoadExtensionsSucceeded?Ke(e,t.payload):t.type===Ne.HydrateInitialState?Ke(e,null===(n=t.payload)||void 0===n?void 0:n.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 Qt={errors:{},statuses:{}};function Zt(e=Qt,t){return i({data:Jt,errors:r(Xt,Be),statuses:en})(e,t)}function Jt(e,t){var n;switch(t.type){case Kt.LoadFormFieldsSucceeded:return Qe(e,t.payload);case Ne.HydrateInitialState:return Qe(e,null===(n=t.payload)||void 0===n?void 0:n.formFields);default:return e}}function Xt(e=Qt.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 en(e=Qt.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 tn;!function(e){e.LoadCountriesRequested="LOAD_COUNTRIES_REQUESTED",e.LoadCountriesSucceeded="LOAD_COUNTRIES_SUCCEEDED",e.LoadCountriesFailed="LOAD_COUNTRIES_FAILED"}(tn||(tn={}));const nn={errors:{},statuses:{}};function rn(e=nn,t){return i({data:on,errors:r(an,Be),statuses:sn})(e,t)}function on(e,t){return t.type===tn.LoadCountriesSucceeded?Ke(e,t.payload):e}function an(e=nn.errors,t){switch(t.type){case tn.LoadCountriesRequested:case tn.LoadCountriesSucceeded:return je(e,"loadError",void 0);case tn.LoadCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function sn(e=nn.statuses,t){switch(t.type){case tn.LoadCountriesRequested:return je(e,"isLoading",!0);case tn.LoadCountriesSucceeded:case tn.LoadCountriesFailed:return je(e,"isLoading",!1);default:return e}}const dn={errors:{},meta:{},statuses:{}};function cn(e=dn,t){return i({data:un,errors:r(hn,Be),meta:ln,statuses:pn})(e,t)}function un(e,t){switch(t.type){case Ct.LoadOrderSucceeded:case Ct.LoadOrderPaymentsSucceeded:return Qe(e,k(t.payload,["billingAddress","coupons"]));default:return e}}function ln(e,t){switch(t.type){case Ct.FinalizeOrderSucceeded:case Ct.SubmitOrderSucceeded:return Qe(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 hn(e=dn.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 pn(e=dn.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 mn={};function gn(e=mn,t){return i({data:yn})(e,t)}function yn(e,t){switch(t.type){case Ct.LoadOrderPaymentsSucceeded:case Ct.LoadOrderSucceeded:return qe(e,t.payload&&t.payload.billingAddress);default:return e}}var fn,vn;function Sn(e={},t){return i({data:Cn})(e,t)}function Cn(e,t){return t.type===fn.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"}(fn||(fn={})),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"}(vn||(vn={}));const In={errors:{},statuses:{}};function _n(e=In,t){return i({data:wn,errors:r(En,Be),meta:bn,statuses:Pn})(e,t)}function wn(e,t){switch(t.type){case vn.LoadPaymentMethodSucceeded:return function(e,t,n){if(!t)return e;const i=R(t,"id"),r="object"==typeof n?M(n):n||i,o=h(e,r),a=[...e];if(-1===o)a.push(t);else{const n=e[o];a[o]=$e(n)&&$e(t)?Qe(n,t):t}return a}(e||[],t.payload,t.payload&&{id:t.payload.id,gateway:t.payload.gateway});case vn.LoadPaymentMethodsSucceeded:return Ke(e,t.payload,{matchObject:(e,t)=>e.id===t.id&&e.gateway===t.gateway});default:return e}}function bn(e,t){return t.type===vn.LoadPaymentMethodsSucceeded?Qe(e,t.meta):e}function En(e=In.errors,t){switch(t.type){case vn.LoadPaymentMethodsRequested:case vn.LoadPaymentMethodsSucceeded:return je(e,"loadError",void 0);case vn.LoadPaymentMethodsFailed:return je(e,"loadError",t.payload);case vn.LoadPaymentMethodRequested:case vn.LoadPaymentMethodSucceeded:return Qe(e,{loadMethodId:void 0,loadMethodError:void 0});case vn.LoadPaymentMethodFailed:return Qe(e,{loadMethodId:t.meta.methodId,loadMethodError:t.payload});default:return e}}function Pn(e=In.statuses,t){switch(t.type){case vn.LoadPaymentMethodsRequested:return je(e,"isLoading",!0);case vn.LoadPaymentMethodsSucceeded:case vn.LoadPaymentMethodsFailed:return je(e,"isLoading",!1);case vn.LoadPaymentMethodRequested:return Qe(e,{isLoadingMethod:!0,loadMethodId:t.meta.methodId});case vn.LoadPaymentMethodSucceeded:case vn.LoadPaymentMethodFailed:return Qe(e,{isLoadingMethod:!1,loadMethodId:void 0});default:return e}}var On;!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"}(On||(On={}));const An={data:{},errors:{},statuses:{}};function Tn(e=An,t){return i({data:kn,errors:r(Dn,Be),statuses:Rn})(e,t)}function kn(e=An.data,t){switch(t.type){case On.InitializeSucceeded:if(t.meta){const{methodId:n,gatewayId:i}=t.meta,r=i?`${n}.${i}`:n;return Qe(e,{[r]:{isInitialized:!0}})}break;case On.DeinitializeSucceeded:if(t.meta){const{methodId:n,gatewayId:i}=t.meta,r=i?`${n}.${i}`:n;return Qe(e,{[r]:{isInitialized:!1}})}}return e}function Dn(e=An.errors,t){switch(t.type){case On.InitializeRequested:case On.InitializeSucceeded:return Qe(e,{initializeError:void 0,initializeMethodId:void 0});case On.InitializeFailed:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{initializeError:t.payload,initializeMethodId:n})}case On.DeinitializeRequested:case On.DeinitializeSucceeded:return Qe(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case On.DeinitializeFailed:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{deinitializeError:t.payload,deinitializeMethodId:n})}case On.ExecuteRequested:case On.ExecuteSucceeded:return Qe(e,{executeError:void 0,executeMethodId:void 0});case On.ExecuteFailed:return Qe(e,{executeError:t.payload,executeMethodId:t.meta&&t.meta.methodId});case On.FinalizeRequested:case On.FinalizeSucceeded:return Qe(e,{finalizeError:void 0,finalizeMethodId:void 0});case On.FinalizeFailed:return Qe(e,{finalizeError:t.payload,finalizeMethodId:t.meta&&t.meta.methodId});case On.WidgetInteractionStarted:case On.WidgetInteractionFinished:return Qe(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case On.WidgetInteractionFailed:return Qe(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta.methodId});default:return e}}function Rn(e=An.statuses,t){switch(t.type){case On.InitializeRequested:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{isInitializing:!0,initializeMethodId:n})}case On.InitializeFailed:case On.InitializeSucceeded:return Qe(e,{isInitializing:!1,initializeMethodId:void 0});case On.DeinitializeRequested:{let n=t.meta&&t.meta.methodId;if(t.meta){const{methodId:e,gatewayId:i}=t.meta;n=i?`${e}.${i}`:e}return Qe(e,{isDeinitializing:!0,deinitializeMethodId:n})}case On.DeinitializeFailed:case On.DeinitializeSucceeded:return Qe(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case On.ExecuteRequested:return Qe(e,{isExecuting:!0,executeMethodId:t.meta&&t.meta.methodId});case On.ExecuteFailed:case On.ExecuteSucceeded:return Qe(e,{isExecuting:!1,executeMethodId:void 0});case On.FinalizeRequested:return Qe(e,{isFinalizing:!0,finalizeMethodId:t.meta&&t.meta.methodId});case On.FinalizeFailed:case On.FinalizeSucceeded:return Qe(e,{isFinalizing:!1,finalizeMethodId:void 0});case On.WidgetInteractionStarted:return Qe(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta.methodId});case On.WidgetInteractionFinished:case On.WidgetInteractionFailed:return Qe(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Mn;!function(e){e.UpdatePaymentProviderCustomer="UPDATE_PAYMENT_PROVIDER_CUSTOMER"}(Mn||(Mn={}));const Nn={data:{}};function Ln(e=Nn,t){return i({data:zn})(e,t)}function zn(e=Nn.data,t){return t.type===Mn.UpdatePaymentProviderCustomer?Qe(e,t.payload):e}var Un;!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"}(Un||(Un={}));const Fn={data:[],errors:{},statuses:{}};function Bn(e=Fn,t){return i({data:xn,errors:r(jn,Be),meta:qn,statuses:Gn})(e,t)}function xn(e=Fn.data,t){return t.type===Un.LoadInstrumentsSucceeded?Ke(e,t.payload&&t.payload.vaultedInstruments||[]):e}function qn(e,t){switch(t.type){case Un.LoadInstrumentsSucceeded:case Un.DeleteInstrumentSucceeded:return Qe(e,t.meta);default:return e}}function jn(e=Fn.errors,t){switch(t.type){case Un.LoadInstrumentsRequested:case Un.LoadInstrumentsSucceeded:return je(e,"loadError",void 0);case Un.DeleteInstrumentRequested:case Un.DeleteInstrumentSucceeded:return Qe(e,{deleteError:void 0,failedInstrument:void 0});case Un.LoadInstrumentsFailed:return je(e,"loadError",t.payload);case Un.DeleteInstrumentFailed:return Qe(e,{deleteError:t.payload,failedInstrument:t.meta.instrumentId});default:return e}}function Gn(e=Fn.statuses,t){switch(t.type){case Un.LoadInstrumentsRequested:return je(e,"isLoading",!0);case Un.DeleteInstrumentRequested:return Qe(e,{isDeleting:!0,deletingInstrument:t.meta.instrumentId});case Un.LoadInstrumentsSucceeded:case Un.LoadInstrumentsFailed:return je(e,"isLoading",!1);case Un.DeleteInstrumentSucceeded:case Un.DeleteInstrumentFailed:return Qe(e,{isDeleting:!1,deletingInstrument:void 0});default:return e}}var Hn;!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"}(Hn||(Hn={}));const Vn={data:{}};function Yn(e=Vn,t){return t.meta&&t.meta.methodId?i({data:i({[t.meta.methodId]:Wn})})(e,t):e}function Wn(e,t){switch(t.type){case Hn.InitializeRemoteBillingSucceeded:return je(e,"billing",t.payload&&t.payload.billing);case Hn.InitializeRemoteShippingSucceeded:return je(e,"shipping",t.payload&&t.payload.shipping);case Hn.LoadRemoteSettingsSucceeded:return je(e,"settings",t.payload);case Hn.UpdateRemoteCheckout:return Qe(e,t.payload);default:return e}}const $n={errors:{updateShippingOptionError:{},updateError:{},deleteError:{}},statuses:{isUpdating:{},isUpdatingShippingOption:{},isDeleting:{}}};function Kn(e=$n,t){return i({data:Qn,errors:r(Zn,Be),statuses:Jn})(e,t)}function Qn(e,t){var n,i;switch(t.type){case Me.LoadCheckoutSucceeded:case Xe.LoadShippingOptionsSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:return Ke(e,t.payload&&t.payload.consignments);case Dt.SignOutCustomerSucceeded:return Ke(e,[]);case Ne.HydrateInitialState:return Ke(e,null===(i=null===(n=t.payload)||void 0===n?void 0:n.checkout)||void 0===i?void 0:i.consignments);default:return e}}function Zn(e=$n.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?Qe(e,{updateError:{[t.meta.id]:void 0}}):e;case Xe.UpdateConsignmentFailed:return t.meta?Qe(e,{updateError:{[t.meta.id]:t.payload}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentRequested:return t.meta?Qe(e,{deleteError:{[t.meta.id]:void 0}}):e;case Xe.DeleteConsignmentFailed:return t.meta?Qe(e,{deleteError:{[t.meta.id]:t.payload}}):e;case Xe.UpdateShippingOptionRequested:case Xe.UpdateShippingOptionSucceeded:return t.meta?Qe(e,{updateShippingOptionError:{[t.meta.id]:void 0}}):e;case Xe.UpdateShippingOptionFailed:return t.meta?Qe(e,{updateShippingOptionError:{[t.meta.id]:t.payload}}):e;default:return e}}function Jn(e=$n.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?Qe(e,{isUpdating:{[t.meta.id]:!0}}):e;case Xe.UpdateConsignmentSucceeded:case Xe.UpdateConsignmentFailed:return t.meta?Qe(e,{isUpdating:{[t.meta.id]:!1}}):e;case Xe.DeleteConsignmentRequested:return t.meta?Qe(e,{isDeleting:{[t.meta.id]:!0}}):e;case Xe.DeleteConsignmentSucceeded:case Xe.DeleteConsignmentFailed:return t.meta?Qe(e,{isDeleting:{[t.meta.id]:!1}}):e;case Xe.UpdateShippingOptionRequested:return t.meta?Qe(e,{isUpdatingShippingOption:{[t.meta.id]:!0}}):e;case Xe.UpdateShippingOptionSucceeded:case Xe.UpdateShippingOptionFailed:return t.meta?Qe(e,{isUpdatingShippingOption:{[t.meta.id]:!1}}):e;default:return e}}function Xn(e,t){const n={};return Object.keys(e).forEach(i=>{const r=e[i],o=t?`${t}.${i}`:i;"object"==typeof r?Object.assign(n,Xn(r,o)):n[o]=r}),n}function ei(e){return Object.keys(e).sort().reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e[n]}),{})}var ti;!function(e){e.LoadPickupOptionsRequested="LOAD_PICKUP_OPTIONS_REQUESTED",e.LoadPickupOptionsSucceeded="LOAD_PICKUP_OPTIONS_SUCCEEDED",e.LoadPickupOptionsFailed="LOAD_PICKUP_OPTIONS_FAILED"}(ti||(ti={}));const ni={errors:{},statuses:{}};function ii(e=ni,t){return i({data:ri,errors:r(oi,Be),statuses:ai})(e,t)}function ri(e,t){if(t.type!==ti.LoadPickupOptionsSucceeded)return e;if(t.meta){const n=ei(Xn({consignmentId:t.meta.consignmentId,searchArea:t.meta.searchArea}));return je(e,btoa(`${JSON.stringify(n)}`),t.payload)}}function oi(e=ni.errors,t){switch(t.type){case ti.LoadPickupOptionsRequested:case ti.LoadPickupOptionsSucceeded:return je(e,"loadError",void 0);case ti.LoadPickupOptionsFailed:return je(e,"loadError",t.payload);default:return e}}function ai(e=ni.statuses,t){switch(t.type){case ti.LoadPickupOptionsRequested:return je(e,"isLoading",!0);case ti.LoadPickupOptionsSucceeded:case ti.LoadPickupOptionsFailed:return je(e,"isLoading",!1);default:return e}}var si;!function(e){e.LoadShippingCountriesRequested="LOAD_SHIPPING_COUNTRIES_REQUESTED",e.LoadShippingCountriesSucceeded="LOAD_SHIPPING_COUNTRIES_SUCCEEDED",e.LoadShippingCountriesFailed="LOAD_SHIPPING_COUNTRIES_FAILED"}(si||(si={}));const di={errors:{},statuses:{}};function ci(e=di,t){return i({data:ui,errors:r(li,Be),statuses:hi})(e,t)}function ui(e,t){return t.type===si.LoadShippingCountriesSucceeded?Ke(e,t.payload):e}function li(e=di.errors,t){switch(t.type){case si.LoadShippingCountriesRequested:case si.LoadShippingCountriesSucceeded:return je(e,"loadError",void 0);case si.LoadShippingCountriesFailed:return je(e,"loadError",t.payload);default:return e}}function hi(e=di.statuses,t){switch(t.type){case si.LoadShippingCountriesRequested:return je(e,"isLoading",!0);case si.LoadShippingCountriesSucceeded:case si.LoadShippingCountriesFailed:return je(e,"isLoading",!1);default:return e}}var pi;!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"}(pi||(pi={}));const mi={data:{},errors:{},statuses:{}};function gi(e=mi,t){return i({data:yi,errors:r(fi,Be),statuses:vi})(e,t)}function yi(e=mi.data,t){switch(t.type){case pi.InitializeSucceeded:return Qe(e,{[t.meta&&t.meta.methodId]:{isInitialized:!0}});case pi.DeinitializeSucceeded:return Qe(e,{[t.meta&&t.meta.methodId]:{isInitialized:!1}})}return e}function fi(e=mi.errors,t){switch(t.type){case pi.InitializeRequested:case pi.InitializeSucceeded:return Qe(e,{initializeError:void 0,initializeMethodId:void 0});case pi.InitializeFailed:return Qe(e,{initializeError:t.payload,initializeMethodId:t.meta&&t.meta.methodId});case pi.DeinitializeRequested:case pi.DeinitializeSucceeded:return Qe(e,{deinitializeError:void 0,deinitializeMethodId:void 0});case pi.DeinitializeFailed:return Qe(e,{deinitializeError:t.payload,deinitializeMethodId:t.meta&&t.meta.methodId});case pi.UpdateAddressRequested:case pi.UpdateAddressSucceeded:return Qe(e,{updateAddressError:void 0,updateAddressMethodId:void 0});case pi.UpdateAddressFailed:return Qe(e,{updateAddressError:t.payload,updateAddressMethodId:t.meta&&t.meta.methodId});case pi.SelectOptionRequested:case pi.SelectOptionSucceeded:return Qe(e,{selectOptionError:void 0,selectOptionMethodId:void 0});case pi.SelectOptionFailed:return Qe(e,{selectOptionError:t.payload,selectOptionMethodId:t.meta&&t.meta.methodId});case pi.WidgetInteractionStarted:case pi.WidgetInteractionFinished:return Qe(e,{widgetInteractionError:void 0,widgetInteractionMethodId:void 0});case pi.WidgetInteractionFailed:return Qe(e,{widgetInteractionError:t.payload,widgetInteractionMethodId:t.meta&&t.meta.methodId});default:return e}}function vi(e=mi.statuses,t){switch(t.type){case pi.InitializeRequested:return Qe(e,{isInitializing:!0,initializeMethodId:t.meta&&t.meta.methodId});case pi.InitializeFailed:case pi.InitializeSucceeded:return Qe(e,{isInitializing:!1,initializeMethodId:void 0});case pi.DeinitializeRequested:return Qe(e,{isDeinitializing:!0,deinitializeMethodId:t.meta&&t.meta.methodId});case pi.DeinitializeFailed:case pi.DeinitializeSucceeded:return Qe(e,{isDeinitializing:!1,deinitializeMethodId:void 0});case pi.UpdateAddressRequested:return Qe(e,{isUpdatingAddress:!0,updateAddressMethodId:t.meta&&t.meta.methodId});case pi.UpdateAddressFailed:case pi.UpdateAddressSucceeded:return Qe(e,{isUpdatingAddress:!1,updateAddressMethodId:void 0});case pi.SelectOptionRequested:return Qe(e,{isSelectingOption:!0,selectOptionMethodId:t.meta&&t.meta.methodId});case pi.SelectOptionFailed:case pi.SelectOptionSucceeded:return Qe(e,{isSelectingOption:!1,selectOptionMethodId:void 0});case pi.WidgetInteractionStarted:return Qe(e,{isWidgetInteracting:!0,widgetInteractionMethodId:t.meta&&t.meta.methodId});case pi.WidgetInteractionFinished:case pi.WidgetInteractionFailed:return Qe(e,{isWidgetInteracting:!1,widgetInteractionMethodId:void 0});default:return e}}var Si;!function(e){e.SendSignInEmailRequested="SEND_SIGNIN_EMAIL_REQUESTED",e.SendSignInEmailSucceeded="SEND_SIGNIN_EMAIL_SUCCEEDED",e.SendSignInEmailFailed="SEND_SIGNIN_EMAIL_FAILED"}(Si||(Si={}));const Ci={errors:{},statuses:{}};function Ii(e=Ci,t){return i({data:_i,errors:r(wi,Be),statuses:bi})(e,t)}function _i(e,t){return t.type===Si.SendSignInEmailSucceeded?Qe(e,t.payload):e}function wi(e=Ci.errors,t){switch(t.type){case Si.SendSignInEmailRequested:case Si.SendSignInEmailSucceeded:return je(e,"sendError",void 0);case Si.SendSignInEmailFailed:return je(e,"sendError",t.payload);default:return e}}function bi(e=Ci.statuses,t){switch(t.type){case Si.SendSignInEmailRequested:return je(e,"isSending",!0);case Si.SendSignInEmailFailed:case Si.SendSignInEmailSucceeded:return je(e,"isSending",!1);default:return e}}var Ei;!function(e){e.ApplyStoreCreditRequested="APPLY_STORE_CREDIT_REQUESTED",e.ApplyStoreCreditSucceeded="APPLY_STORE_CREDIT_SUCCEEDED",e.ApplyStoreCreditFailed="APPLY_STORE_CREDIT_FAILED"}(Ei||(Ei={}));const Pi={errors:{},statuses:{}};function Oi(e=Pi,t){return i({errors:r(Ai,Be),statuses:Ti})(e,t)}function Ai(e=Pi.errors,t){switch(t.type){case Ei.ApplyStoreCreditRequested:case Ei.ApplyStoreCreditSucceeded:return je(e,"applyError",void 0);case Ei.ApplyStoreCreditFailed:return je(e,"applyError",t.payload);default:return e}}function Ti(e=Pi.statuses,t){switch(t.type){case Ei.ApplyStoreCreditRequested:return je(e,"isApplying",!0);case Ei.ApplyStoreCreditSucceeded:case Ei.ApplyStoreCreditFailed:return je(e,"isApplying",!1);default:return e}}const ki={errors:{},statuses:{}};function Di(e=ki,t){return i({errors:r(Ri,Be),statuses:Mi})(e,t)}function Ri(e=ki.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 Mi(e=ki.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 Ni;!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"}(Ni||(Ni={}));const Li={errors:{},statuses:{}};function zi(e=Li,t){return i({data:Ui,errors:r(Fi,Be),statuses:Bi})(e,t)}function Ui(e,t){var n;switch(t.type){case Me.LoadCheckoutSucceeded:case Me.UpdateCheckoutSucceeded:case Ei.ApplyStoreCreditSucceeded:case Ue.UpdateBillingAddressSucceeded:case Ze.ApplyCouponSucceeded:case Ze.RemoveCouponSucceeded:case Xe.CreateConsignmentsSucceeded:case Xe.UpdateConsignmentSucceeded:case Xe.DeleteConsignmentSucceeded:case Xe.UpdateShippingOptionSucceeded:case Xe.LoadShippingOptionsSucceeded:case Je.ApplyGiftCertificateSucceeded:case Je.RemoveGiftCertificateSucceeded:case Ni.VerifyCheckoutSucceeded:return Qe(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 Qe(e,k(null===(n=t.payload)||void 0===n?void 0:n.checkout,["billingAddress","cart","consignments","customer","coupons","giftCertificates"]));default:return e}}function Fi(e=Li.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 Bi(e=Li.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 Ni.ExecuteRequested:return je(e,"isExecutingSpamCheck",!0);case Ni.ExecuteFailed:case Ni.ExecuteSucceeded:return je(e,"isExecutingSpamCheck",!1);default:return e}}var xi;!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"}(xi||(xi={}));class qi extends be{constructor(e){super(function(e){switch(e){case xi.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case xi.MissingCart:return"Unable to proceed because cart data is unavailable.";case xi.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case xi.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case xi.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case xi.MissingCheckoutConfig:case xi.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case xi.MissingOrder:return"Unable to proceed because order data is unavailable.";case xi.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case xi.MissingPayment:return"Unable to proceed because payment data is unavailable.";case xi.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case xi.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case xi.MissingPaymentProviderCustomer:return"Unable to proceed because payment provider customer is unavailable.";case xi.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 ji=(Gi=de,(...e)=>{const t=e.pop();return Gi(...e,(...e)=>{const n=t(...e);return"function"==typeof n?ae(n):n})});var Gi;function Hi(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}function Vi(e){return function(e){const t=Object.create(e);return function(e,t){let n=Object.getPrototypeOf(e);for(;n;)t(n),n=Object.getPrototypeOf(n)}(e,n=>{Object.getOwnPropertyNames(n).forEach(n=>{"constructor"!==n&&"function"==typeof t[n]&&"_"!==n.charAt(0)&&(t[n]=((e,t)=>(...n)=>d(e[t].call(e,...n)))(e,n))})}),t}(e)}const Yi={"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"},barclays:{provider:"barclays",method:"credit_card"},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 Wi(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 $i={errors:{},statuses:{}};function Ki(){const e=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingBillingAddress))),n=ji(e=>e.errors.updateError,e=>()=>e),i=ji(e=>e.errors.continueAsGuestError,e=>()=>e),r=ji(e=>e.errors.loadError,e=>()=>e),o=ji(e=>!!e.statuses.isUpdating,e=>()=>e),a=ji(e=>!!e.statuses.isContinuingAsGuest,e=>()=>e),s=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((d=Ge)=>({getBillingAddress:e(d),getBillingAddressOrThrow:t(d),getUpdateError:n(d),getContinueAsGuestError:i(d),getLoadError:r(d),isUpdating:o(d),isContinuingAsGuest:a(d),isLoading:s(d)}))}(),t=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingCart))),n=ji(e=>e.errors.loadError,e=>()=>e),i=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((r=et)=>({getCart:e(r),getCartOrThrow:t(r),getLoadError:n(r),isLoading:i(r)}))}(),n=function(){const e=ji(e=>e,e=>()=>e),t=ji(e=>e.statuses,e=>ae(t=>{if(t){const n=e[t];return!0===(n&&n.isInitializing)}return z(e,{isInitializing:!0})})),n=ji(e=>e.data,e=>ae((t,n)=>{const i=e[t];return!!i&&(n?!0===i.initializedContainers[n]:z(i.initializedContainers,e=>!0===e))})),i=ji(e=>e.statuses,e=>ae(t=>{if(t){const n=e[t];return!0===(n&&n.isDeinitializing)}return z(e,{isDeinitializing:!0})})),r=ji(e=>e.errors,e=>ae(t=>{const n=t?e[t]:l(x(e),e=>!(!e||!e.initializeError));return n&&n.initializeError})),o=ji(e=>e.errors,e=>ae(t=>{const n=t?e[t]:l(x(e),e=>!(!e||!e.deinitializeError));return n&&n.deinitializeError}));return se((a=at)=>({getState:e(a),isInitializing:t(a),isInitialized:n(a),isDeinitializing:i(a),getInitializeError:r(a),getDeinitializeError:o(a)}))}(),i=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.data,e=>t=>{if(!e)return;const{flashMessages:n}=e.context;return n?void 0!==t?n.filter(({type:e})=>t===e):n:void 0}),n=ji(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),i=ji(n,e=>()=>Hi(e(),()=>new qi(xi.MissingCheckoutConfig))),r=ji(e=>e.data&&e.data.context,e=>()=>e),o=ji(e=>e.meta&&e.meta.externalSource,e=>()=>e),a=ji(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.host},e=>()=>e),s=ji(e=>{var t;return null===(t=e.meta)||void 0===t?void 0:t.locale},e=>()=>e),d=ji(e=>e.meta&&e.meta.variantIdentificationToken,e=>()=>e),c=ji(e=>e.errors.loadError,e=>()=>e),u=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((l=gt,h)=>({getConfig:e(l),getFlashMessages:t(l),getStoreConfig:n(l,{formState:h}),getStoreConfigOrThrow:i(l,{formState:h}),getContextConfig:r(l),getExternalSource:o(l),getHost:a(l),getLocale:s(l),getVariantIdentificationToken:d(l),getLoadError:c(l),isLoading:u(l)}))}(),r=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.loadError,e=>()=>e),n=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((i=nn)=>({getCountries:e(i),getLoadError:t(i),isLoading:n(i)}))}(),o=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.removeCouponError,e=>()=>e),n=ji(e=>e.errors.applyCouponError,e=>()=>e),i=ji(e=>!!e.statuses.isApplyingCoupon,e=>()=>e),r=ji(e=>!!e.statuses.isRemovingCoupon,e=>()=>e);return se((o=It)=>({getCoupons:e(o),getRemoveError:t(o),getApplyError:n(o),isApplying:i(o),isRemoving:r(o)}))}(),a=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingCustomer))),n=ji(e=>e.errors.createError,e=>()=>e),i=ji(e=>!!e.statuses.isCreating,e=>()=>e),r=ji(e=>e.errors.createAddressError,e=>()=>e),o=ji(e=>!!e.statuses.isCreatingAddress,e=>()=>e);return se((a=Rt)=>({getCustomer:e(a),getCustomerOrThrow:t(a),getCreateAccountError:n(a),isCreatingCustomerAccount:i(a),getCreateAddressError:r(a),isCreatingCustomerAddress:o(a)}))}(),s=function(){const e=ji(e=>e.errors.signInMethodId,e=>e.errors.signInError,(e,t)=>n=>{if(!n||e===n)return t}),t=ji(e=>e.errors.signOutMethodId,e=>e.errors.signOutError,(e,t)=>n=>{if(!n||e===n)return t}),n=ji(e=>e.errors.executePaymentMethodCheckoutMethodId,e=>e.errors.executePaymentMethodCheckoutError,(e,t)=>n=>{if(!n||e===n)return t}),i=ji(e=>e.errors.initializeMethodId,e=>e.errors.initializeErrors,(e,t)=>n=>{if(e&&t)return n?t[n]:t[e]}),r=ji(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>n=>{if(!n||e===n)return t}),o=ji(e=>e.statuses.signInMethodId,e=>e.statuses.isSigningIn,(e,t)=>n=>!(n&&e!==n||!t)),a=ji(e=>e.statuses.signOutMethodId,e=>e.statuses.isSigningOut,(e,t)=>n=>!(n&&e!==n||!t)),s=ji(e=>e.statuses.executePaymentMethodCheckoutMethodId,e=>e.statuses.isExecutingPaymentMethodCheckout,(e,t)=>n=>!(n&&e!==n||!t)),d=ji(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>n=>!(n&&e!==n||!t)),c=ji(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),u=ji(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>n=>!(n&&e!==n||!t));return se((l=Ft)=>({getSignInError:e(l),getSignOutError:t(l),getExecutePaymentMethodCheckoutError:n(l),getInitializeError:i(l),getWidgetInteractionError:r(l),isSigningIn:o(l),isSigningOut:a(l),isExecutingPaymentMethodCheckout:s(l),isInitializing:d(l),isInitialized:c(l),isWidgetInteracting:u(l)}))}(),d=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.removeGiftCertificateError,e=>()=>e),n=ji(e=>e.errors.applyGiftCertificateError,e=>()=>e),i=ji(e=>!!e.statuses.isApplyingGiftCertificate,e=>()=>e),r=ji(e=>!!e.statuses.isRemovingGiftCertificate,e=>()=>e);return se((o=Pt)=>({getGiftCertificates:e(o),getRemoveError:t(o),getApplyError:n(o),isApplying:i(o),isRemoving:r(o)}))}(),c=function(){const e=ji(e=>e.data,e=>t=>{if(!e)return;const n=t.gateway?`${t.gateway}.${t.id}`:t.id,i=Yi[n];return i?u(e,i):[]}),t=ji(e=>e.data,(e=[])=>t=>{const n=x(Yi);return e.find(e=>e.bigpayToken===t&&"card"===e.type&&n.some(t=>S(e,t)))}),n=ji(t,e=>t=>Hi(e(t),()=>new qi(xi.MissingPaymentInstrument))),i=ji(e=>e.data,e=>()=>{if(e)return p(Yi,t=>u(e,e=>S(e,t)))}),r=ji(e=>e.meta,e=>()=>e),o=ji(e=>e.errors.loadError,e=>()=>e),a=ji(e=>e.errors.failedInstrument,e=>e.errors.deleteError,(e,t)=>n=>{if(!n||e===n)return t}),s=ji(e=>e.statuses.isLoading,e=>()=>!!e),d=ji(e=>e.statuses.deletingInstrument,e=>e.statuses.isDeleting,(e,t)=>n=>!(n&&e!==n||!t));return se((c=Fn)=>({getCardInstrument:t(c),getCardInstrumentOrThrow:n(c),getInstruments:i(c),getInstrumentsByPaymentMethod:e(c),getInstrumentsMeta:r(c),getLoadError:o(c),getDeleteError:a(c),isLoading:s(c),isDeleting:d(c)}))}(),h=function(){const e=ji(e=>e.data,e=>(t=[],n)=>{const i=l(t,{code:n});return(e?e.shippingAddress:[]).map(e=>o(e,t,i))}),t=ji(e=>e.data,e=>(t=[],n)=>{const i=l(t,{code:n});return(e?e.billingAddress:[]).map(e=>o(e,t,i))}),n=ji(e=>e.data,e=>()=>e?e.customerAccount:[]),i=ji(e=>e.errors.loadError,e=>()=>e),r=ji(e=>!!e.statuses.isLoading,e=>()=>e);function o(e,t,n){return"countryCode"===e.name?function(e,t=[],n){if(!t.length)return e;const{code:i=""}=n||{},r=t.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{options:{items:r},default:i,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,t,n):"stateOrProvince"===e.name?function(e,t){const{subdivisions:n=[],requiresState:i}=t||{};if(!n.length)return Object.assign(Object.assign({},e),{required:null!=i&&i});const r=n.map(({code:e,name:t})=>({value:e,label:t}));return Object.assign(Object.assign({},e),{name:"stateOrProvinceCode",options:{items:r},required:null==i||i,type:"array",fieldType:"dropdown",itemtype:"string"})}(e,n):"postalCode"===e.name?function(e,t){const{hasPostalCodes:n=[]}=t||{};return void 0===n?e:Object.assign(Object.assign({},e),{required:Boolean(n)})}(e,n):e}return se((o=Qt)=>({getShippingAddressFields:e(o),getBillingAddressFields:t(o),getCustomerAccountFields:n(o),getLoadError:i(o),isLoading:r(o)}))}(),m=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.meta,e=>()=>e),n=ji(e=>e.data,e=>(t,n)=>l(e,n?{id:t,gateway:n}:{id:t})),i=ji(n,e=>(t,n)=>Hi(e(t,n),()=>new qi(xi.MissingPaymentMethod))),r=ji(e=>e.errors.loadError,e=>()=>e),o=ji(e=>e.errors.loadMethodId,e=>e.errors.loadMethodError,(e,t)=>n=>{if(!n||e===n)return t}),a=ji(e=>e.statuses.isLoading,e=>()=>!!e),s=ji(e=>e.statuses.loadMethodId,e=>e.statuses.isLoadingMethod,(e,t)=>n=>!(n&&e!==n||!t));return se((d=In)=>({getPaymentMethods:e(d),getPaymentMethodsMeta:t(d),getPaymentMethod:n(d),getPaymentMethodOrThrow:i(d),getLoadError:r(d),getLoadMethodError:o(d),isLoading:a(d),isLoadingMethod:s(d)}))}(),g=function(){const e=ji(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>n=>{if(!n||e===n)return t}),t=ji(e=>e.errors.executeMethodId,e=>e.errors.executeError,(e,t)=>n=>{if(!n||e===n)return t}),n=ji(e=>e.errors.finalizeMethodId,e=>e.errors.finalizeError,(e,t)=>n=>{if(!n||e===n)return t}),i=ji(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>n=>{if(!n||e===n)return t}),r=ji(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>n=>!(n&&e!==n||!t)),o=ji(e=>e.data,e=>t=>{const n=t.gatewayId?`${t.methodId}.${t.gatewayId}`:t.methodId;return!(!e[n]||!e[n].isInitialized)}),a=ji(e=>e.statuses.executeMethodId,e=>e.statuses.isExecuting,(e,t)=>n=>!(n&&e!==n||!t)),s=ji(e=>e.statuses.finalizeMethodId,e=>e.statuses.isFinalizing,(e,t)=>n=>!(n&&e!==n||!t)),d=ji(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>n=>!(n&&e!==n||!t));return se((c=An)=>({getInitializeError:e(c),getExecuteError:t(c),getFinalizeError:n(c),getWidgetInteractingError:i(c),isInitializing:r(c),isInitialized:o(c),isExecuting:a(c),isFinalizing:s(c),isWidgetInteracting:d(c)}))}(),y=function(){const e=ji(e=>e.data,e=>(t,n)=>{if(!e)return;const i=ei(Xn({consignmentId:t,searchArea:n})),r=btoa(`${JSON.stringify(i)}`);return e[r]}),t=ji(e=>e.errors.loadError,e=>()=>e),n=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((i=ni)=>({getPickupOptions:e(i),getLoadError:t(i),isLoading:n(i)}))}(),f=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentProviderCustomer)));return se((n=Nn)=>({getPaymentProviderCustomer:e(n),getPaymentProviderCustomerOrThrow:t(n)}))}(),C=function(){const e=ji(e=>e.data,e=>t=>e[t]);return se((t=Vn)=>({getCheckout:e(t)}))}(),I=function(){const e=ji(e=>e.data,e=>()=>{const t=null==e?void 0:e.find(e=>!e.selectedPickupOption);return null==t?void 0:t.shippingAddress}),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingShippingAddress))),n=ji(e=>e.data,e=>()=>{const t=null==e?void 0:e.filter(e=>!e.selectedPickupOption);return t?t.map(e=>e.shippingAddress):[]}),i=ji(n,e=>()=>Hi(e(),()=>new qi(xi.MissingShippingAddress)));return se((r=$n)=>({getShippingAddress:e(r),getShippingAddressOrThrow:t(r),getShippingAddresses:n(r),getShippingAddressesOrThrow:i(r)}))}(),_=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.loadError,e=>()=>e),n=ji(e=>e.statuses.isLoading,e=>()=>!!e);return se((i=di)=>({getShippingCountries:e(i),getLoadError:t(i),isLoading:n(i)}))}(),w=function(){const e=ji(e=>e.errors.updateAddressMethodId,e=>e.errors.updateAddressError,(e,t)=>n=>{if(!n||e===n)return t}),t=ji(e=>e.errors.selectOptionMethodId,e=>e.errors.selectOptionError,(e,t)=>n=>{if(!n||e===n)return t}),n=ji(e=>e.errors.initializeMethodId,e=>e.errors.initializeError,(e,t)=>n=>{if(!n||e===n)return t}),i=ji(e=>e.errors.widgetInteractionMethodId,e=>e.errors.widgetInteractionError,(e,t)=>n=>{if(!n||e===n)return t}),r=ji(e=>e.statuses.updateAddressMethodId,e=>e.statuses.isUpdatingAddress,(e,t)=>n=>!(n&&e!==n||!t)),o=ji(e=>e.statuses.selectOptionMethodId,e=>e.statuses.isSelectingOption,(e,t)=>n=>!(n&&e!==n||!t)),a=ji(e=>e.statuses.initializeMethodId,e=>e.statuses.isInitializing,(e,t)=>n=>!(n&&e!==n||!t)),s=ji(e=>e.data,e=>t=>!(!e[t]||!e[t].isInitialized)),d=ji(e=>e.statuses.widgetInteractionMethodId,e=>e.statuses.isWidgetInteracting,(e,t)=>n=>!(n&&e!==n||!t));return se((c=mi)=>({getUpdateAddressError:e(c),getSelectOptionError:t(c),getInitializeError:n(c),getWidgetInteractionError:i(c),isUpdatingAddress:r(c),isSelectingOption:o(c),isInitializing:a(c),isInitialized:s(c),isWidgetInteracting:d(c)}))}(),b=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingConsignments))),n=ji(e=>e.data,e=>t=>{if(e&&e.length)return l(e,{id:t})}),i=ji(e=>e.data,e=>t=>{if(e&&e.length)return l(e,e=>{return n=e.shippingAddress,i=t,v(Wi(n),Wi(i));var n,i})}),r=ji(e=>e.data,e=>()=>{if(e&&e.length)return e[0].selectedShippingOption}),o=ji(e=>e.errors.loadError,e=>()=>e),a=ji(e=>e.errors.createError,e=>()=>e),s=ji(e=>e.errors.loadShippingOptionsError,e=>()=>e),d=ji(e,(e,{cart:t})=>t.getCart,(e,t)=>()=>{const n=t();if(!n)return[];const i=(e()||[]).reduce((e,t)=>e.concat(t.lineItemIds),[]);return(n.lineItems.physicalItems||[]).filter(e=>i.indexOf(e.id)<0)}),c=ji(e=>e.errors.updateError,e=>t=>t?e[t]:l(e)),u=ji(e=>e.errors.deleteError,e=>t=>t?e[t]:l(e)),h=ji(i,c,a,(e,t,n)=>i=>{const r=e(i);return r?t(r.id):n()}),p=ji(e=>e.errors.updateShippingOptionError,e=>t=>t?e[t]:l(e)),m=ji(e=>e.statuses.isLoading,e=>()=>!0===e),g=ji(e=>e.statuses.isLoadingShippingOptions,e=>()=>!0===e),y=ji(e=>e.statuses.isCreating,e=>()=>!0===e),f=ji(e=>e.statuses.isUpdating,e=>t=>t?!0===e[t]:!0===l(e)),S=ji(e=>e.statuses.isDeleting,e=>t=>t?!0===e[t]:!0===l(e)),C=ji(i,f,y,(e,t,n)=>i=>{const r=e(i);return r?t(r.id):n()}),I=ji(e=>e.statuses.isUpdatingShippingOption,e=>t=>t?!0===e[t]:!0===l(e));return se((l=$n,v)=>({getConsignments:e(l),getConsignmentsOrThrow:t(l),getConsignmentById:n(l),getConsignmentByAddress:i(l),getShippingOption:r(l),getLoadError:o(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=ji(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,n,i,r,o,a)=>()=>{const s=t(),d=n(),c=i(),u=r()||[],l=o()||[],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=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingCheckout))),n=ji(e,e=>t=>{const n=e();if(!n)return;const i=n.grandTotal||0,r=n.customer.storeCredit||0;return t?Math.max(i-r,0):n.outstandingBalance}),i=ji(e=>e.errors.loadError,e=>()=>e),r=ji(e=>e.errors.updateError,e=>()=>e),o=ji(e=>e.statuses.isExecutingSpamCheck,e=>()=>!0===e),a=ji(e=>e.statuses.isLoading,e=>()=>!0===e),s=ji(e=>e.statuses.isUpdating,e=>()=>!0===e);return se((d=Li,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:n(d,{billingAddress:c,cart:u,consignments:l,coupons:h,customer:p,giftCertificates:m}),getLoadError:i(d),getUpdateError:r(d),isExecutingSpamCheck:o(d),isLoading:a(d),isUpdating:s(d)}))}(),P=function(){const e=ji(e=>e.data,(e,{billingAddress:t})=>t.getOrderBillingAddress(),(e,{coupons:t})=>t.getCoupons(),(e,t,n=[])=>()=>{if(e&&t)return Object.assign(Object.assign({},e),{billingAddress:t,coupons:n})}),t=ji(e,e=>()=>Hi(e(),()=>new qi(xi.MissingOrder))),n=ji(e=>e.meta,e=>()=>e),i=ji(e=>e.errors.loadError,e=>()=>e),r=ji(e=>{var t;return null===(t=e.data)||void 0===t?void 0:t.payments},(e=[])=>t=>{const n=e.find(({providerId:e})=>e===t);return null==n?void 0:n.paymentId}),o=ji(e=>!!e.statuses.isLoading,e=>()=>e);return se((a=dn,s,d)=>({getOrder:e(a,{billingAddress:s,coupons:d}),getOrderOrThrow:t(a,{billingAddress:s,coupons:d}),getOrderMeta:n(a),getLoadError:i(a),getPaymentId:r(a),isLoading:o(a)}))}(),O=function(){const e=ji(e=>e.data,e=>()=>e);return se((t=mn)=>({getOrderBillingAddress:e(t)}))}(),A=function(){const e=ji(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.payment}),t=ji(({order:e})=>e.getOrder,e=>()=>{const t=e();return l(t&&t.payments,({providerId:e})=>"giftcertificate"!==e&&"storecredit"!==e)}),n=ji(({checkout:e})=>e.getCheckout,e=>()=>{const t=e();return l(t&&t.payments,({providerType:e})=>"PAYMENT_TYPE_HOSTED"===e)}),i=ji(e,n,t,(e,t,n)=>()=>{const i=e();if(i&&i.id)return{providerId:i.id,gatewayId:i.gateway};const r=t()||n();return r&&r.providerId?{providerId:r.providerId,gatewayId:r.gatewayId}:void 0}),r=ji(i,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentId))),o=ji(e,n,t,(e,t,n)=>()=>{const i=e();if(i&&i.status)return i.status.replace("PAYMENT_STATUS_","");const r=t()||n();return r?r.detail.step:void 0}),a=ji(o,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentStatus))),s=ji(({order:e})=>e.getOrderMeta,e=>()=>{const t=e();return t&&t.token}),d=ji(s,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentToken))),c=ji(e,e=>()=>{const t=e();return t&&t.redirectUrl}),u=ji(c,e=>()=>Hi(e(),()=>new qi(xi.MissingPaymentRedirectUrl))),h=ji(({checkout:e})=>e.getOutstandingBalance,e=>(t=!1)=>{const n=e(t);return!!n&&n>0}),p=ji(o,e=>t=>!(!t||!t.nonce)||"ACKNOWLEDGE"===e()||"FINALIZE"===e());return se((e,t)=>({getPaymentId:i({checkout:e,order:t}),getPaymentIdOrThrow:r({checkout:e,order:t}),getPaymentStatus:o({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=ji(e=>e.errors.applyError,e=>()=>e),t=ji(e=>!!e.statuses.isApplying,e=>()=>e);return se((n=$i)=>({getApplyError:e(n),isApplying:t(n)}))}(),k=function(){const e=ji(e=>e.errors.updateError,e=>()=>e),t=ji(e=>!!e.statuses.isUpdating,e=>()=>e);return se((n=ki)=>({getUpdateError:e(n),isUpdating:t(n)}))}(),D=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.errors.sendError,e=>()=>e),n=ji(e=>!!e.statuses.isSending,e=>()=>e);return se((i=Ci)=>({getEmail:e(i),getSendError:t(i),isSending:n(i)}))}(),R=function(){const e=ji(e=>e.data,e=>()=>e),t=ji(e=>e.data,e=>t=>null==e?void 0:e.find(e=>e.region===t)),n=ji(e=>e.errors.loadError,e=>()=>e),i=ji(e=>e.statuses.isLoading,e=>()=>!!e);return se((r=Ht)=>({getExtensions:e(r),getExtensionByRegion:t(r),getLoadError:n(r),isLoading:i(r)}))}();return(u,l={})=>{const p=e(u.billingAddress),v=t(u.cart),S=n(u.checkoutButton),M=r(u.countries),N=o(u.coupons),L=a(u.customer),z=s(u.customerStrategies),U=R(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),Q=k(u.subscriptions),Z=T(u.storeCredit),J=D(u.signInEmail),X=b(u.consignments,v),ee=E(u.checkout,p,v,X,N,L,B),te=P(u.order,q,N),ne=A(ee,te),ie={billingAddress:p,cart:v,checkout:ee,checkoutButton:S,config:i(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:ne,paymentMethods:j,paymentProviderCustomer:G,paymentStrategies:H,pickupOptions:V,remoteCheckout:Y,shippingAddress:W,shippingCountries:$,shippingStrategies:K,signInEmail:J,subscriptions:Q,storeCredit:Z};return l.shouldWarnMutation?function(e){return Object.keys(e).reduce((t,n)=>(t[n]=Vi(e[n]),t),{})}(ie):ie}}function Qi(e={},t){const n=(s=function(){const e=new Re;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}))),r=Ki(),o=i({billingAddress:He,cart:tt,checkout:zi,checkoutButton:ut,config:yt,consignments:Kn,countries:rn,coupons:_t,customer:Mt,customerStrategies:Bt,extensions:Vt,formFields:Zt,giftCertificates:Ot,instruments:Bn,orderBillingAddress:gn,order:cn,payment:Sn,paymentMethods:_n,paymentStrategies:Tn,pickupOptions:ii,paymentProviderCustomer:Ln,remoteCheckout:Yn,shippingCountries:ci,shippingStrategies:gi,signInEmail:Ii,subscriptions:Di,storeCredit:Oi});var s;return a(o,e,Object.assign({actionTransformer:n,stateTransformer:e=>r(e)},t))}var Zi,Ji;!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"}(Zi||(Zi={}));class Xi extends Ce{constructor(e){super(function(e){switch(e){case Zi.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case Zi.MissingCart:return"Unable to proceed because cart data is unavailable.";case Zi.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case Zi.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case Zi.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case Zi.MissingCheckoutConfig:case Zi.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case Zi.MissingOrder:return"Unable to proceed because order data is unavailable.";case Zi.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case Zi.MissingPayment:return"Unable to proceed because payment data is unavailable.";case Zi.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case Zi.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case Zi.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 er(e){return t=e.lineItems.physicalItems.filter(e=>!e.addedByPromotion),N(t,(e,t)=>e+t.quantity,0);var t}function tr(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"}(Ji||(Ji={}));class nr extends Ce{constructor(e){super(function(e){switch(e){case Ji.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Ji.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Ji.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Ji.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 ir={de:"eu",jp:"fe",uk:"eu",us:"na"};var rr,or,ar,sr,dr,cr;!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"}(rr||(rr={})),function(e){e.Home="Home",e.Product="Product",e.Cart="Cart",e.Checkout="Checkout",e.Other="Other"}(or||(or={})),function(e){e.USD="USD",e.EUR="EUR",e.GBP="GBP",e.JPY="JPY"}(ar||(ar={})),function(e){e.PayAndShip="PayAndShip",e.PayOnly="PayOnly"}(sr||(sr={})),function(e){e.Gold="Gold",e.LightGray="LightGray",e.DarkGray="DarkGray"}(dr||(dr={})),function(e){e.C0001="C0001"}(cr||(cr={}));var ur=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class lr{constructor(e){this.amazonPayV2ScriptLoader=e}initialize(e){return ur(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,n){this.getAmazonPayV2SDK().Pay.bindChangeAction(`#${e}`,{amazonCheckoutSessionId:t,changeAction:n})}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(()=>ur(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 ur(this,void 0,void 0,function*(){return this.amazonPayV2SDK&&this.amazonPayV2SDK.Pay.signout(),Promise.resolve()})}renderAmazonPayButton({buttonColor:e,checkoutState:t,containerId:n,decoupleCheckoutInitiation:i=!1,methodId:r,options:o,placement:a,isButtonMicroTextDisabled:s=!1}){const d=document.querySelector(`#${n}`);if(!d)return;const{id:c}=d.appendChild(this.getButtonParentContainer());o&&s&&(o.design=cr.C0001);const u=null!=o?o:this.getAmazonPayV2ButtonOptions(t,r,a,i,e);return this.createButton(c,u),this.getButtonParentContainer()}updateBuyNowFlowFlag(e){this.isBuyNowFlow=Boolean(e)}isPh4Enabled(e,t){const n=!!e["PROJECT-3483.amazon_pay_ph4"],i=!!e["INT-6885.amazon_pay_ph4_us_only"];return n&&i?"US"===t:n}prepareRequestConfig(e,t,n){const{publicKeyId:i}=e,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["publicKeyId"]);return Object.assign(Object.assign({createCheckoutSessionConfig:this.isEnvironmentSpecific(i)?r:e},t&&{estimatedOrderAmount:t}),n&&{productType:n})}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,n,i=!1,r=dr.Gold){var o;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 Xi(Zi.MissingPaymentMethod);const{checkoutLanguage:p,checkoutSessionMethod:m,createCheckoutSessionConfig:g,extractAmazonCheckoutSessionId:y,ledgerCurrency:f,publicKeyId:v="",isButtonMicroTextDisabled:S}=h;if(!u||!f)throw new Xi(Zi.MissingPaymentMethod);const C=Object.assign({merchantId:u,ledgerCurrency:f,checkoutLanguage:p,placement:n,buttonColor:r},S?{design:cr.C0001}:{});if(this.isBuyNowFlow)return Object.assign(Object.assign({},C),{sandbox:!!l});const I=a();C.productType=I&&0===er(I)?sr.PayOnly:sr.PayAndShip;const{checkoutSettings:{features:_},storeProfile:{shopPath:w,storeCountryCode:b}}=d();if(this.isPh4Enabled(_,b)){if(!g)throw new Xi(Zi.MissingPaymentMethod);const e=null===(o=s())||void 0===o?void 0:o.outstandingBalance.toString(),t=null==I?void 0:I.currency.code,n=Object.assign({},C);let r;return this.isEnvironmentSpecific(v)?(n.publicKeyId=v,r=g):(n.sandbox=!!l,r=Object.assign(Object.assign({},g),{publicKeyId:v})),i||(n.createCheckoutSessionConfig=r),e&&t&&(n.estimatedOrderAmount={amount:e,currencyCode:t}),n}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 tr(e,()=>new nr(Ji.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 hr 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 pr{constructor(e,t=window){this.scriptLoader=e,this.windowWithAmazonPay=t}load(e){return t=this,n=void 0,r=function*(){const{initializationData:t}=e,n=(null==t?void 0:t.region)||"us",i=ir[n];if(yield this.scriptLoader.loadScript(`https://static-${i}.payments-amazon.com/checkout.js`),!this.windowWithAmazonPay.amazon)throw new hr;return this.windowWithAmazonPay.amazon},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}}function mr(e,t){return Object.assign(e,{resolveIds:t})}class gr extends Ce{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class yr 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 fr 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 vr(e){return e instanceof Object&&"buyNowInitializeOptions"in e}var Sr=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Cr{constructor(e,t,n){this.paymentIntegrationService=e,this.amazonPayV2PaymentProcessor=t,this.amazonPayV2ConfigRequestSender=n}initialize(e){var t;return Sr(this,void 0,void 0,function*(){const{methodId:n,containerId:i,amazonpay:r}=e,{buttonColor:o}=r||{};if(!n||!i)throw new gr('Unable to proceed because "methodId" or "containerId" argument is not provided.');const{getPaymentMethodOrThrow:a}=this.paymentIntegrationService.getState(),s=a(n),{initializationData:d}=s;yield this.amazonPayV2PaymentProcessor.initialize(s),r||(yield this.paymentIntegrationService.loadDefaultCheckout());const c=vr(r)?void 0:r;vr(r)&&"function"==typeof(null===(t=r.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody)&&(this._buyNowInitializeOptions=r.buyNowInitializeOptions,this.amazonPayV2PaymentProcessor.updateBuyNowFlowFlag(!0)),this.amazonPayV2PaymentProcessor.renderAmazonPayButton({checkoutState:this.paymentIntegrationService.getState(),containerId:i,methodId:n,options:c,placement:or.Cart,buttonColor:o,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 Sr(this,void 0,void 0,function*(){const n=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!n)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(n)}catch(e){throw new yr}})}_createCheckoutConfig(e){return Sr(this,void 0,void 0,function*(){try{const t=(yield this.amazonPayV2ConfigRequestSender.createCheckoutConfig(e)).body,{payload:n,public_key:i}=t,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["payload","public_key"]);return Object.assign({payloadJSON:n,publicKeyId:i},r)}catch(e){throw new fr}})}_getCheckoutCreationRequestConfig(){return Sr(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===er(e)?sr.PayOnly:sr.PayAndShip}})}}const Ir="This API endpoint is for internal use only and may change in the future";var _r;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(_r||(_r={}));const wr=_r,br={"X-Checkout-SDK-Version":"1.818.0"};class Er{constructor(e){this._requestSender=e}createCheckoutConfig(e){const t={cartId:e},n=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return this._requestSender.post("/api/storefront/payment/amazonpay",{headers:n,body:t})}}const Pr=mr(t=>{const n=e(),i=new Er(n),r=new lr(new pr(le()));return new Cr(t,r,i)},[{id:"amazonpay"}]);function Or(e,t,n=!0){var i;return null!==(i=e[t])&&void 0!==i?i:n}const Ar="3.128.0",Tr="3.123.2",kr="3.106.0";class Dr{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()||(Or(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?Ar:Or(t,"PAYPAL-5636.update_braintree_sdk_version")?Tr:kr)}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 Rr extends Ce{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var Mr,Nr,Lr,zr,Ur,Fr,Br;function xr(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"}(Mr||(Mr={})),function(e){e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED"}(Nr||(Nr={})),function(e){e.TRUSTLY="trustly"}(Lr||(Lr={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="cancelled",e.UNRECOGNIZED="unrecognized"}(zr||(zr={})),function(e){e.Customer="CUSTOMER",e.Merchant="MERCHANT",e.Network="NETWORK",e.Internal="INTERNAL",e.Unknown="UNKNOWN"}(Ur||(Ur={})),function(e){e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED"}(Fr||(Fr={})),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"}(Br||(Br={}));var qr,jr,Gr,Hr=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Vr{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return Hr(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return Hr(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 Hr(this,void 0,void 0,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),i=Object.assign({client:t,kount:!0},e);this.dataCollector=yield n.create(i)}catch(e){if(xr(e)&&e.code===Fr.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return Hr(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 Hr(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 Hr(this,void 0,void 0,function*(){if(!this.braintreeLocalPayment){const[t,n]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((i,r)=>{n.create({client:t,merchantAccountId:e},(e,t)=>{e&&r(e),i(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return Hr(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 Hr(this,void 0,void 0,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return Hr(this,void 0,void 0,function*(){if(!this.braintreeVenmo){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadVenmoCheckout(),n={client:e,allowDesktop:!0,paymentMethodUsage:"multi_use"},i=yield t.create(n);if(!i.isBrowserSupported())throw new Rr;this.braintreeVenmo=i}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new nr(Ji.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}!function(e){e.Sandbox="sandbox",e.Production="production"}(qr||(qr={})),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"}(jr||(jr={})),function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(Gr||(Gr={}));const Yr={[kr]:{[jr.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[jr.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[jr.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[jr.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[jr.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[jr.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[jr.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[jr.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[jr.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[jr.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[jr.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[jr.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[Tr]:{[jr.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[jr.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[jr.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[jr.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[jr.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[jr.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[jr.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[jr.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[jr.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[jr.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[jr.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[jr.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[Ar]:{[jr.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[jr.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[jr.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[jr.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[jr.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[jr.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[jr.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[jr.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[jr.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[jr.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[jr.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[jr.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var Wr,$r=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Kr{constructor(e,t,n){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=n}loadClient(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.Client,"client.min.js")})}loadFastlane(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.Paypal,"paypal.min.js")})}loadLocalPayment(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.GooglePayment,"google-payment.min.js")})}load3DS(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(jr.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(jr.Venmo,"venmo.min.js")}loadHostedFields(){return $r(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(jr.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return $r(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 hr;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return $r(this,void 0,void 0,function*(){let n=this.getBraintreeModule(e);if(n)return n;const i=this.braintreeSDKVersionManager.getSDKVersion(),r=`//js.braintreegateway.com/web/${i}/js/${t}`,o=i in Yr?this.getIntegrityValuesByModuleName(e,i):void 0;if(yield this.scriptLoader.loadScript(r,o?{async:!0,attributes:{integrity:o,crossorigin:"anonymous"}}:void 0),n=this.getBraintreeModule(e),!n)throw new hr;return n})}getBraintreeModule(e){var t;return null===(t=this.braintreeHostWindow.braintree)||void 0===t?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const n=Yr[t][e];if(!n)throw new Error("Unexpected fileName value");return n}}class Qr 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"}(Wr||(Wr={}));var Zr,Jr,Xr=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};!function(e){e.Subtotal="Subtotal",e.Shipping="Shipping"}(Zr||(Zr={})),function(e){e.Black="black",e.White="white",e.WhiteBorder="white-border"}(Jr||(Jr={}));class eo{constructor(e,t,n,i,r){this._requestSender=e,this._paymentIntegrationService=t,this._sessionFactory=n,this._braintreeSdk=i,this._applePayScriptLoader=r,this._onAuthorizeCallback=T,this._subTotalLabel=Zr.Subtotal,this._shippingLabel=Zr.Shipping}initialize(e){var t,n;return Xr(this,void 0,void 0,function*(){const{methodId:i,containerId:r,applepay:o}=e;if(!i||!o)throw new Xi(Zi.MissingPaymentMethod);yield this._applePayScriptLoader.loadSdk();const{onPaymentAuthorize:a,buyNowInitializeOptions:s,requiresShipping:d}=o;this._requiresShipping=d,this._buyNowInitializeOptions=s,this._onAuthorizeCallback=a,s||(yield this._paymentIntegrationService.loadDefaultCheckout()),yield this._paymentIntegrationService.loadPaymentMethod(i);const c=this._paymentIntegrationService.getState();return this._paymentMethod=c.getPaymentMethodOrThrow(i),c.getCart()&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection()),(null===(t=this._paymentMethod.initializationData)||void 0===t?void 0:t.gateway)===Wr.BRAINTREE&&(yield this._initializeBraintreeSdk()),this._applePayButton=this._createButton(r,null===(n=this._paymentMethod.initializationData)||void 0===n?void 0:n.styleOption),this._applePayButton.addEventListener("click",this._handleWalletButtonClick.bind(this)),Promise.resolve()})}deinitialize(){return Promise.resolve()}_createButton(e,t){const n=document.getElementById(e);if(!n)throw new gr("Unable to create wallet button without valid container ID.");const i=this._createApplePayButtonElement(t);return n.appendChild(i),i}_createApplePayButtonElement(e){const t=document.createElement("apple-pay-button");return t.setAttribute("buttonstyle",(e=>{switch(e){case Jr.White:return"white";case Jr.WhiteBorder:return"white-outline";case Jr.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 Xr(this,void 0,void 0,function*(){if(e.preventDefault(),!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xi(Zi.MissingPaymentMethod);if(this._buyNowInitializeOptions&&"function"==typeof this._buyNowInitializeOptions.getBuyNowCartRequestBody){const{countryCode:e,currencyCode:n,merchantCapabilities:i,supportedNetworks:r,storeName:o}=this._paymentMethod.initializationData,a=this._getRequestWithEmptyTotal(e,n,r,i);this._requiresShipping&&(null===(t=a.requiredShippingContactFields)||void 0===t||t.push("postalAddress"));const s=this._sessionFactory.create(a);this._handleApplePayEvents(s,this._paymentMethod,o),s.begin()}else{const e=this._paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getStoreConfigOrThrow(),i=e.getCheckoutOrThrow(),r=this._getBaseRequest(t,i,n,this._paymentMethod),o=this._sessionFactory.create(r);this._handleApplePayEvents(o,this._paymentMethod,n.storeProfile.storeName),o.begin()}})}_getRequestWithEmptyTotal(e,t,n,i){return{countryCode:e,currencyCode:t,supportedNetworks:n,merchantCapabilities:i,total:{label:"",amount:"0",type:"pending"},requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"]}}_getBaseRequest(e,t,n,i){var r;const{storeProfile:{storeCountryCode:o,storeName:a}}=n,{currency:{code:s,decimalPlaces:d}}=e,{initializationData:{merchantCapabilities:c,supportedNetworks:u}}=i,l=e.lineItems.physicalItems.length>0,h={requiredBillingContactFields:["postalAddress"],requiredShippingContactFields:["email","phone"],countryCode:o,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===(r=h.requiredShippingContactFields)||void 0===r||r.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,n){e.onvalidatemerchant=n=>Xr(this,void 0,void 0,function*(){try{const{body:i}=yield this._onValidateMerchant(t,n);e.completeMerchantValidation(i)}catch(e){throw new Error("Merchant validation failed")}}),this._buyNowInitializeOptions&&!this._requiresShipping&&(e.onpaymentmethodselected=()=>Xr(this,void 0,void 0,function*(){yield this._createBuyNowCart(),this._handlePaymentMethodSelected(e)})),e.onshippingcontactselected=t=>Xr(this,void 0,void 0,function*(){this._buyNowInitializeOptions&&this._requiresShipping&&(yield this._createBuyNowCart()),yield this._handleShippingContactSelected(e,n,t)}),e.onshippingmethodselected=t=>Xr(this,void 0,void 0,function*(){yield this._handleShippingMethodSelected(e,n,t)}),e.oncancel=()=>Xr(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 Qr}}),e.onpaymentauthorized=n=>Xr(this,void 0,void 0,function*(){return this._onPaymentAuthorized(n,e,t)})}_createBuyNowCart(){var e,t;return Xr(this,void 0,void 0,function*(){try{const n=null===(t=null===(e=this._buyNowInitializeOptions)||void 0===e?void 0:e.getBuyNowCartRequestBody)||void 0===t?void 0:t.call(e);if(!n)throw new Xi(Zi.MissingCart);const i=yield this._paymentIntegrationService.createBuyNowCart(n);yield this._paymentIntegrationService.loadCheckout(i.id);const r=this._paymentIntegrationService.getState(),{shouldExecuteSpamCheck:o}=r.getCheckoutOrThrow();o&&(yield this._paymentIntegrationService.verifyCheckoutSpamProtection())}catch(e){throw new yr}})}_handlePaymentMethodSelected(e){const t=this._paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getStoreConfigOrThrow(),r=t.getCheckoutOrThrow();if(!this._paymentMethod||!this._paymentMethod.initializationData)throw new Xi(Zi.MissingPaymentMethod);const o=this._getBaseRequest(n,r,i,this._paymentMethod);delete o.total.type,e.completePaymentMethodSelection({newTotal:o.total,newLineItems:o.lineItems})}_handleShippingContactSelected(e,t,n){var i;return Xr(this,void 0,void 0,function*(){const r=this._transformContactToAddress(n.shippingContact);try{yield this._paymentIntegrationService.updateShippingAddress(r)}catch(t){throw e.abort(),new Error("Shipping address update failed")}let o=this._paymentIntegrationService.getState();const{currency:{decimalPlaces:a}}=o.getCartOrThrow();let s=o.getCheckoutOrThrow();const d=null===(i=s.consignments[0].selectedShippingOption)||void 0===i?void 0:i.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")}o=this._paymentIntegrationService.getState(),s=o.getCheckoutOrThrow(),e.completeShippingContactSelection({newShippingMethods:h,newTotal:{type:"final",label:t,amount:`${s.grandTotal.toFixed(a)}`},newLineItems:this._getUpdatedLineItems(s,a)})})}_handleShippingMethodSelected(e,t,n){return Xr(this,void 0,void 0,function*(){const{shippingMethod:{identifier:i}}=n;try{yield this._updateShippingOption(i)}catch(t){throw e.abort(),new Error("Shipping option selection update failed.")}const r=this._paymentIntegrationService.getState(),{currency:{decimalPlaces:o}}=r.getCartOrThrow(),a=r.getCheckoutOrThrow();e.completeShippingMethodSelection({newTotal:{type:"final",label:t,amount:`${a.grandTotal.toFixed(o)}`},newLineItems:this._getUpdatedLineItems(a,o)})})}_getUpdatedLineItems(e,t){const n=[{label:this._subTotalLabel,amount:`${e.subtotal.toFixed(t)}`}];return e.taxes.forEach(e=>n.push({label:e.name,amount:`${e.amount.toFixed(t)}`})),n.push({label:this._shippingLabel,amount:`${e.shippingCostTotal.toFixed(t)}`}),n}_updateShippingOption(e){return Xr(this,void 0,void 0,function*(){return this._paymentIntegrationService.selectShippingOption(e)})}_onValidateMerchant(e,t){return Xr(this,void 0,void 0,function*(){const n=[`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:n})})}_onPaymentAuthorized(e,t,n){var i;return Xr(this,void 0,void 0,function*(){const{token:r,billingContact:o,shippingContact:a}=e.payment,s=this._paymentIntegrationService.getState().getCartOrThrow().lineItems.physicalItems.length>0;let d;(null===(i=n.initializationData)||void 0===i?void 0:i.gateway)===Wr.BRAINTREE&&(d=yield this._getBraintreeDeviceData());const c={methodId:n.id,paymentData:{deviceSessionId:d,formattedPayload:{apple_pay_token:{payment_data:r.paymentData,payment_method:r.paymentMethod,transaction_id:r.transactionIdentifier}}}},u=this._transformContactToAddress(o),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 Xr(this,void 0,void 0,function*(){try{const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e}catch(e){}})}_initializeBraintreeSdk(){return Xr(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadPaymentMethod(Wr.BRAINTREE);const e=this._paymentIntegrationService.getState().getPaymentMethod(Wr.BRAINTREE);e&&e.clientToken&&e.initializationData&&this._braintreeSdk.initialize(e.clientToken)})}}function to(e){if(!function(e){return"ApplePaySession"in e}(e))throw new Error("Apple pay is not supported")}class no{create(e){return to(window),new ApplePaySession(1,e)}}class io{constructor(e){this.scriptLoader=e,this.sdkVersion="1.latest"}loadSdk(){return e=this,t=void 0,i=function*(){yield this.scriptLoader.loadScript(`https://applepay.cdn-apple.com/jsapi/${this.sdkVersion}/apple-pay-sdk.js`),to(window)},new((n=void 0)||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())});var e,t,n,i}}const ro=mr(t=>{const{getHost:n}=t.getState(),i=new Dr(t);return new eo(e({host:n()}),t,new no,new Vr(new Kr(le(),window,i)),new io(new ce))},[{id:"applepay"}]);var oo,ao,so,co,uo,lo,ho,po;!function(e){e.BuyNow="BUY_NOW"}(oo||(oo={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ao||(ao={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(so||(so={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(co||(co={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(uo||(uo={})),function(e){e.pill="pill",e.rect="rect"}(lo||(lo={})),function(e){e.OXXO="oxxo"}(ho||(ho={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(po||(po={}));var mo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class go{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=n,this.bigCommercePaymentsScriptLoader=i}loadPayPalSdk(e,t,n,i){return mo(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(a,o,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new hr;return this.paypalSdk}createBuyNowCartOrThrow(e){return mo(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new yr}})}createOrder(e,t){return mo(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return mo(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(){return mo(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getConsignmentsOrThrow()[0];try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:n.availableShippingOptions,cartId:t.id,selectedShippingOption:n.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return mo(this,void 0,void 0,function*(){try{const{status:n}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _e}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xi(Zi.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===oo.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return mo(this,void 0,void 0,function*(){const i={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:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}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,n;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===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:r}=e||{},o={color:t&&uo[t]?t:void 0,height:this.getValidHeight(n),label:i&&co[i]?i:void 0,shape:r&&lo[r]?r:void 0};return D(o,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 yo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class fo{constructor(e){this.requestSender=e}createOrder(e,t){return yo(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return yo(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:n,body:t})).body})}getOrderStatus(e="bigcommerce_payments",t){return yo(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}var vo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class So{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return vo(this,void 0,void 0,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e,t=!1){return vo(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.paypal)throw new hr;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new Xi(Zi.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}=o,v=h||n,S="bigcommerce_payments_creditcards"===i,C=S?["card"]:[],I=S?[]:["card"],_=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],b=n||!v,E=l?["venmo"]:[],P=l?[]:["venmo"],O=b?y:[],A=b?g.filter(e=>!y.includes(e)):g,T=f?["googlepay"]:[],k=n?["card-fields"]:[],D=this.filterFundingOptions([...I,...w,...P,...A]),R=this.filterFundingOptions([...C,..._,...E,...O]);return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":R.length>0?R:void 0,"disable-funding":D.length>0?D:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...T,...k],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":r}}}filterFundingOptions(e){const t=["klarna"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const Co=t=>{const{getHost:i}=t.getState();return new go(n(),t,new fo(e({host:i()})),new So(le()))};var Io=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class _o{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){var t;return Io(this,void 0,void 0,function*(){const{bigcommerce_payments:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(o&&!n.currencyCode)throw new gr('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new gr('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:c}=d.initializationData||{},u={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)},p=Object.assign(Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},u),i&&l),c&&h),m=s.Buttons(p);m.isEligible()?m.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Io(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Io(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Io(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 Io(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}})}}const wo=mr(e=>new _o(e,Co(e)),[{id:"bigcommerce_payments"}]);var bo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Eo{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return bo(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new hr}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return bo(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new hr;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return bo(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new hr}return this.window.paypalApms})}getPayPalMessages(e,t){return bo(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new hr;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return bo(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,attributionId:d}=r;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:o},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=r,h=u||n;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:o},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:o,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=n,l=this.filterFundingOptions(u),h=this.filterFundingOptions(c.filter(e=>!u.includes(e)));return{options:Object.assign({"client-id":r,"merchant-id":o,"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:i},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:o,isDeveloperModeApplicable:a,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":r,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":o}}}filterFundingOptions(e){const t=["klarna"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const Po=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 Oo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ao{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.payPalSdkHelper=n}initialize(e){return Oo(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o,messagingContainerId:a}=t||{},s=!!r;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(s&&!o)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new gr('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?o:d.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,c,!1),this.renderButton(n,i,t);const u=a&&document.getElementById(a);if(c&&u){const e=d.getPaymentMethodOrThrow(i),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},n=t&&t.find(({id:e})=>"cart"===e);if(!(null==n?void 0:n.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 r=yield this.payPalSdkHelper.getPayPalMessages(e,c);this.renderMessages(r,a,n)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)},p=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let m=!1;p.forEach(t=>{if(!m){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},u),i&&l),c&&h),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),m=!0):a&&"function"==typeof a&&a()}}),m||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return Oo(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Oo(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Oo(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 Oo(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,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:Po(n)};e.Messages(i).render(`#${t}`)}}const To=mr(e=>new Ao(e,Co(e),new Eo(ue())),[{id:"bigcommerce_payments_paylater"}]);var ko=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Do{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return ko(this,void 0,void 0,function*(){const{bigcommerce_payments_apms:t,containerId:n,methodId:i}=e,{apm:r,buyNowInitializeOptions:o,currencyCode:a}=t||{},s=!!o;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');if(!r)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_apms.apm" argument is not provided.');if(s&&!a)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_apms.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new gr('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(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{apm:i,buyNowInitializeOptions:r,style:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(i))throw new gr('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(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:i,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o)},d),r&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return ko(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Ro=mr(e=>new Do(e,Co(e)),[{id:"bigcommerce_payments_apms"}]);var Mo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class No{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Mo(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(a&&!o)throw new gr('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new gr('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?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):o&&"function"==typeof o?o():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===uo.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return Mo(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Lo=mr(e=>new No(e,Co(e)),[{id:"bigcommerce_payments_venmo"}]);class zo extends Ce{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Uo,Fo,Bo;!function(e){e.SandboxMode="bolt_sandbox",e.StagingMode="bolt_staging",e.DevelopmentMode="bolt_development"}(Uo||(Uo={})),function(e){e.Small="small",e.Medium="medium",e.Large="large"}(Fo||(Fo={})),function(e){e.Pill="pill",e.Rect="rect"}(Bo||(Bo={}));class xo{constructor(e,t,n=window){this.paymentIntegrationService=e,this.boltScriptLoader=t,this.boltHostWindow=n}initialize(e){return t=this,n=void 0,r=function*(){const{bolt:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,style:o}=t||{};if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.bolt" argument is not provided.');if(!Boolean(r))throw new zo("Only buy now flow is implemented for Bolt button");if(!(null==r?void 0:r.storefrontApiToken)||"string"!=typeof r.storefrontApiToken)throw new gr('Unable to initialize payment because "options.storefrontApiToken" argument is not provided.');const a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i),{initializationData:s,config:d}=a,{publishableKey:c,developerConfig:u}=s||{};yield this.boltScriptLoader.loadBoltClient(c,d.testMode,u,"BigCommerce",r.storefrontApiToken),this.renderButton(n,a,o)},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}deinitialize(){return Promise.resolve()}renderButton(e,t,n){var i;"function"==typeof(null===(i=this.boltHostWindow.BoltConnect)||void 0===i?void 0:i.setupProductPageCheckout)&&(this.addButtonContainer(e,t,n),this.boltHostWindow.BoltConnect.setupProductPageCheckout())}addButtonContainer(e,t,n){const i=document.getElementById(e);if(!i)return;const r=document.createElement("div"),o=document.createElement("object");r.setAttribute("id","product-page-checkout-wrapper"),r.setAttribute("class","bolt-button-wrapper"),r.setAttribute("style","display:none"),r.setAttribute("data-tid","product-page-checkout-wrapper"),o.setAttribute("data",this.getBoltObjectData(t,n)),o.setAttribute("class","bolt-product-checkout-button"),r.append(o),i.innerHTML="",i.append(r)}getBoltObjectData(e,t){const{initializationData:n,config:i}=e,{publishableKey:r,developerConfig:o}=n||{},a=this.boltScriptLoader.getDomainURL(!!i.testMode,o),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:r,variant:"ppc",height:s,border_radius:d}})}getButtonHeight(e){if(e)switch(e){case Fo.Small:return 25;case Fo.Large:return 45;case Fo.Medium:default:return 40}}getButtonBorderRadius(e,t){if(e)switch(e){case Bo.Pill:return t?Math.round(t/2):void 0;case Bo.Rect:default:return 4}}}var qo=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class jo{constructor(e,t=window){this.scriptLoader=e,this.boltHostWindow=t}loadBoltClient(e,t,n,i,r){return qo(this,void 0,void 0,function*(){if(this.boltHostWindow.BoltCheckout)return this.boltHostWindow.BoltCheckout;if(!e)throw new gr('Unable to initialize payment because "publishableKey" argument is not provided.');if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,n)}/connect-bigcommerce.js`,this.getScriptOptions("bolt-connect",e,i,r)),yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,n)}/track.js`,this.getScriptOptions("bolt-track",e)),!this.boltHostWindow.BoltCheckout)throw new hr;return this.boltHostWindow.BoltCheckout})}loadBoltEmbedded(e,t,n){return qo(this,void 0,void 0,function*(){if(yield this.scriptLoader.loadScript(`//${this.getDomainURL(!!t,n)}/embed.js`,{async:!0,attributes:{id:"bolt-embedded"}}),!this.boltHostWindow.Bolt)throw new hr;return this.boltHostWindow.Bolt(e)})}getDomainURL(e,t){if(!e)return"connect.bolt.com";if(t)switch(t.developerMode){case Uo.StagingMode:return"connect-staging.bolt.com";case Uo.DevelopmentMode:return`connect.${t.developerDomain}`}return"connect-sandbox.bolt.com"}getScriptOptions(e,t,n,i){return{async:!0,attributes:Object.assign(Object.assign({id:e,"data-publishable-key":t},n&&{"data-shopping-cart-id":n}),i&&{"data-storefront-api-token":i})}}}const Go=mr(e=>new xo(e,new jo(le())),[{id:"bolt"}]);class Ho extends gr{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 Vo 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 Yo{constructor(e){const t=new Promise((e,t)=>{this.cancel=t});this.promise=Promise.race([e,t])}}const Wo=["buttons","messages"];var $o,Ko,Qo,Zo,Jo,Xo;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}($o||($o={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Ko||(Ko={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(Qo||(Qo={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Zo||(Zo={})),function(e){e.PILL="pill",e.RECT="rect"}(Jo||(Jo={})),function(e){e.CART="cart",e.HOME="homepage",e.PAYMENT="payment",e.PRODUCT="product"}(Xo||(Xo={}));var ea=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ta{constructor(e,t,n){this.braintreeScriptLoader=e,this.braintreeHostWindow=t,this.overlay=n,this.dataCollectors={}}initialize(e,t){this.clientToken=e,this.threeDSecureOptions=t}getBraintreeFastlane(e,t,n){return ea(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(),i=yield this.getClient(),r=yield this.getSessionId(e),o=yield this.braintreeScriptLoader.loadFastlane(),a={root:{backgroundColorPrimary:"transparent"}};this.braintreeHostWindow.braintreeFastlane=yield o.create({authorization:t,client:i,deviceData:r,styles:n||a})}return this.braintreeHostWindow.braintreeFastlane})}getClient(){return ea(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,n=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["shouldSaveInstrument"]);const i=pe();return this.getPaypal().then(e=>{var r;return i&&(null===(r=this.overlay)||void 0===r||r.show({onClick:()=>e.focusWindow()})),e.tokenize(Object.assign({enableShippingAddress:!0,flow:t?"vault":"checkout",useraction:"commit"},n))}).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,n){return ea(this,void 0,void 0,function*(){const i=yield this.getClient(),r=yield this.braintreeScriptLoader.loadPaypalCheckout(),o={client:i};return this.paypalCheckout=yield r.create(o,(i,r)=>{var o;if(i)return n(i);const a=Object.assign(Object.assign({currency:e.currency},e.isCreditEnabled&&{"enable-funding":"paylater"}),{components:Wo.toString(),intent:e.intent,commit:null===(o=e.commit)||void 0===o||o});this.braintreeHostWindow.paypal?t(r):r.loadPayPalSDK(a,()=>t(r))}),this.paypalCheckout})}getDataCollector(e){return ea(this,void 0,void 0,function*(){const t=(null==e?void 0:e.paypal)?"paypal":"default";let n=this.dataCollectors[t];if(!n){try{const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadDataCollector(),r=Object.assign({client:t,kount:!0},e);n=yield i.create(r)}catch(e){if(!xr(e)||"DATA_COLLECTOR_KOUNT_NOT_ENABLED"!==e.code)throw e;n={deviceData:void 0,teardown:()=>Promise.resolve()}}this.dataCollectors[t]=n}return n})}getBraintreeEnv(e=!1){return e?qr.Sandbox:qr.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:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}mapToLegacyBillingAddress(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,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 ea(this,void 0,void 0,function*(){const{deviceData:t}=yield this.getDataCollector({riskCorrelationId:e});return t})}teardown(){return ea(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 ea(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 ea(this,void 0,void 0,function*(){if(!this.venmoCheckout){const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadVenmoCheckout(),i=Object.assign({client:t,allowDesktop:!0,paymentMethodUsage:"multi_use"},e||{});this.venmoCheckout=yield new Promise((e,t)=>{n.create(i,(n,i)=>n?t(n):i.isBrowserSupported()?void e(i):t(new Rr))})}return this.venmoCheckout})}verifyCard(e,t,n){return ea(this,void 0,void 0,function*(){const i=yield this.tokenizeCard(e,t);return this.challenge3DSVerification(i,n)})}tokenizeCard(e,t){return ea(this,void 0,void 0,function*(){const{paymentData:n}=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}(n))throw new Ho(["payment.paymentData"]);const i=this.getErrorsRequiredFields(n);if(!f(i))throw new Vo(i);const r=this.mapToCreditCard(n,t),o=yield this.getClient(),{creditCards:a}=yield o.request(r);return{nonce:a[0].nonce,bin:a[0].details.bin}})}challenge3DSVerification(e,t){return ea(this,void 0,void 0,function*(){const n=yield this.get3DS();return this.present3DSChallenge(n,t,e)})}teardownModule(e){return e?e.teardown():Promise.resolve()}getClientTokenOrThrow(){if(!this.clientToken)throw new nr(Ji.PaymentNotInitialized);return this.clientToken}getErrorsRequiredFields(e){const{ccNumber:t,ccExpiry:n}=e,i={};return t||(i.ccNumber=[{message:"Credit card number is required",type:"required"}]),n||(i.ccExpiry=[{message:"Expiration date is required",type:"required"}]),i}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,n){const{nonce:i,bin:r}=n;if(!this.threeDSecureOptions||!i)throw new nr(Ji.PaymentNotInitialized);const{addFrame:o,removeFrame:a,challengeRequested:s=!0,additionalInformation:d}=this.threeDSecureOptions,c=()=>ea(this,void 0,void 0,function*(){const t=yield e.cancelVerifyCard();return l.cancel(new Qr),t}),u=t.toFixed(2),l=new Yo(e.verifyCard({addFrame:(e,t)=>{o&&o(e,t,c)},amount:Number(u),bin:r,challengeRequested:s,nonce:i,removeFrame:a,onLookupComplete:(e,t)=>{t()},collectDeviceData:!0,additionalInformation:d}));return l.promise}}function na(e){const{color:t,fundingicons:n,height:i=40,layout:r,shape:o,size:a,tagline:s}=e||{},d={color:t,fundingicons:n,height:ia(i),layout:r,shape:o||"rect",size:a,tagline:s};return D(d,C)}function ia(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 oa=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class aa{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return oa(this,void 0,void 0,function*(){const{braintreepaypal:t,containerId:n,methodId:i}=e;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let r,o=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new gr('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');r=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow().currency.code;const a=o.getPaymentMethodOrThrow(i),{clientToken:s,config:d,initializationData:c}=a;if(!s||!c)throw new Xi(Zi.MissingPaymentMethod);const u={currency:r,intent:c.intent,isCreditEnabled:c.isCreditEnabled};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(u,e=>{this.renderPayPalButton(e,t,n,i,!!d.testMode)},e=>this.handleError(e,n,t.onError))})}deinitialize(){return oa(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,n,i,r){const{style:o,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:d}=t,{paypal:c}=this.braintreeHostWindow;if(c){const u=c.Buttons({env:r?"sandbox":"production",fundingSource:c.FUNDING.PAYPAL,style:na(o),createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});u.isEligible()?u.render(`#${n}`):d&&"function"==typeof d&&d()}else this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){var i;return oa(this,void 0,void 0,function*(){const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(n),u=r?r.cartAmount:s.getCartOrThrow().cartAmount,l=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(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===(i=c.initializationData)||void 0===i?void 0:i.intent})}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return oa(this,void 0,void 0,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}createBuyNowCart(e){return oa(this,void 0,void 0,function*(){if(!e)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new yr}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!xr(e))throw e;n(e)}}const sa=mr(e=>{const t=window,i=new Dr(e),r=new ta(new Kr(le(),t,i),t);return new aa(e,n(),r,t)},[{id:"braintreepaypal"}]);class da{constructor(e){this.paymentIntegrationService=e,this.braintreeHostWindow=window}render(e,t,n){const i=t&&document.getElementById(t);if(this.braintreeHostWindow.paypal&&i){const r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow(),a=r.getBillingAddressOrThrow(),s=r.getPaymentMethodOrThrow(e);if(!s.initializationData)return;const{paypalBNPLConfiguration:d=[]}=s.initializationData,c=n===Xo.PAYMENT?"checkout":n,u=d&&d.find(({id:e})=>e===c);if(!u||!u.status)return;n===Xo.CART&&(i.removeAttribute("data-pp-style-logo-type"),i.removeAttribute("data-pp-style-logo-position"),i.removeAttribute("data-pp-style-text-color"),i.removeAttribute("data-pp-style-text-size")),this.braintreeHostWindow.paypal.Messages({amount:o.cartAmount,buyerCountry:a.countryCode,placement:n,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 ca=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ua{constructor(e,t,n,i,r){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeMessages=i,this.braintreeHostWindow=r}initialize(e){var t,n;return ca(this,void 0,void 0,function*(){const{braintreepaypalcredit:i,containerId:r,methodId:o}=e;if(!o)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let a,s=this.paymentIntegrationService.getState();if(i.buyNowInitializeOptions){if(!i.currencyCode)throw new gr('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');a=i.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),s=this.paymentIntegrationService.getState(),a=s.getCartOrThrow().currency.code;const d=s.getPaymentMethodOrThrow(o),{clientToken:c,config:u,initializationData:l}=d;if(!c||!l)throw new Xi(Zi.MissingPaymentMethod);const h={currency:a,intent:l.intent,isCreditEnabled:l.isCreditEnabled},p=Or(null!==(n=null===(t=s.getStoreConfig())||void 0===t?void 0:t.checkoutSettings.features)&&void 0!==n?n:{},"PAYPAL-5663.hide_braintree_card_banner_implementation_in_checkout_sdk");this.braintreeIntegrationService.initialize(c),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{!p&&i.messagingContainerId&&this.renderPayPalMessages(o,i.messagingContainerId),this.renderPayPalButton(e,i,r,o,!!u.testMode)},e=>this.handleError(e,r,i.onError))})}deinitialize(){return ca(this,void 0,void 0,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalMessages(e,t){this.braintreeMessages.render(e,t,Xo.CART)}renderPayPalButton(e,t,n,i,r){const{style:o,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:Zo.CREDIT},na(o)):na(o);if(!u){const o=c.Buttons({env:r?"sandbox":"production",fundingSource:l,style:h,createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});o.isEligible()?(o.render(`#${n}`),u=!0):c.FUNDING.CREDIT&&d&&"function"==typeof d&&d()}}),c&&u||this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){var i;return ca(this,void 0,void 0,function*(){const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),d=s.getCustomer(),c=s.getPaymentMethodOrThrow(n),u=r?r.cartAmount:s.getCartOrThrow().cartAmount,l=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(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===(i=c.initializationData)||void 0===i?void 0:i.intent})}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return ca(this,void 0,void 0,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,d=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),c=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(d),shipping_address:JSON.stringify(c)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(xr(e)||e instanceof Ce)&&r(e),e}})}createBuyNowCart(e){return ca(this,void 0,void 0,function*(){if(!e)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new yr}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!xr(e))throw e;n(e)}}const la=mr(e=>{const t=window,i=new Dr(e),r=new ta(new Kr(le(),t,i),t),o=new da(e);return new ua(e,n(),r,o,t)},[{id:"braintreepaypalcredit"}]);var ha=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class pa{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n}initialize(e){return ha(this,void 0,void 0,function*(){const{containerId:t,methodId:n}=e;if(!n)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),{clientToken:r,initializationData:o,config:a}=i.getPaymentMethodOrThrow(n);if(!r||!o)throw new Xi(Zi.MissingPaymentMethod);this.braintreeSdk.initialize(r);const s=yield this.braintreeSdk.getBraintreeVisaCheckout(),{currency:{code:d},cartAmount:c}=i.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=>ha(this,void 0,void 0,function*(){yield this.paymentSuccess(s,e)}))})}deinitialize(){return Promise.resolve()}paymentSuccess(e,t){return ha(this,void 0,void 0,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.toVisaCheckoutAddress(i),billingAddress:a=this.toVisaCheckoutAddress(r)}=e;return this.postForm(Object.assign(Object.assign({},e),{shippingAddress:o,billingAddress:a}),t)})})}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{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:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}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 ma=mr(e=>{const t=window,i=new Dr(e),r=new Vr(new Kr(le(),t,i));return new pa(e,n(),r)},[{id:"braintreevisacheckout"}]);function ga(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,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 ya(e){const{email:t,phone:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}var fa=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};const va=e=>{const{color:t,height:n}=e;return{backgroundColor:(i=t||"",i===Qo.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("/app/assets/img/payment-providers/venmo-logo-${t===Qo.WHITE?Qo.BLUE:Qo.WHITE}.svg")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${n||40}px`,minWidth:"150px",height:"100%",width:"100%",border:t===Qo.WHITE?"1px solid black":"none"};var i};class Sa{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n,this.onError=T}initialize(e){return fa(this,void 0,void 0,function*(){const{braintreevenmo:t,containerId:n,methodId:i}=e;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i),{clientToken:o,initializationData:a}=r,{paymentButtonStyles:s}=a,{cartButtonStyles:d}=s||{},c=(null==t?void 0:t.style)||d;if(!o||!a)throw new Xi(Zi.MissingPaymentMethod);if(!n)throw new gr('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(o);try{const e=yield this.braintreeSdk.getVenmoCheckoutOrThrow();this.renderVenmoButton(e,n,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 Rr}(e))&&this.handleInitializationVenmoError(e,n)}})}deinitialize(){return fa(this,void 0,void 0,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}handleError(e){throw new Error(e.message)}createBuyNowCart(e){return fa(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 Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new yr}}})}handleInitializationVenmoError(e,t){return this.removeVenmoContainer(t),this.onError(e)}removeVenmoContainer(e){const t=document.getElementById(e);t&&t.remove()}renderVenmoButton(e,t,n,i){const r=document.getElementById(t),{color:o}=i||{};if(!r)throw new gr("Unable to create wallet button without valid container ID.");r.setAttribute("aria-label","Venmo"),Object.assign(r.style,va(i||{})),r.addEventListener("click",()=>fa(this,void 0,void 0,function*(){r.setAttribute("disabled","true");const t=yield this.createBuyNowCart(n);e.tokenize&&e.tokenize((e,n)=>fa(this,void 0,void 0,function*(){r.removeAttribute("disabled"),e&&this.onError(e),yield this.handlePostForm(n,null==t?void 0:t.id)}))})),o===Qo.BLUE&&(r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#0a7fc2"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor=va(i||{}).backgroundColor}))}handlePostForm(e,t){return fa(this,void 0,void 0,function*(){const{deviceData:n}=yield this.braintreeSdk.getDataCollectorOrThrow(),{nonce:i,details:r}=e;this.formPoster.postForm("/checkout.php",Object.assign({nonce:i,provider:"braintreevenmo",payment_type:"paypal",device_data:n,action:"set_external_checkout",billing_address:JSON.stringify(ga(r)),shipping_address:JSON.stringify(ya(r))},t&&{cart_id:t}))})}}const Ca=mr(e=>{const t=window,i=le(),r=new Dr(e),o=new Kr(i,t,r),a=new Vr(o);return new Sa(e,n(),a)},[{id:"braintreevenmo"}]);var Ia;!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"}(Ia||(Ia={}));const _a=function(e,t,n){return t&&n?wa(0,t,n):function(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(n=>{const i=Object.getOwnPropertyDescriptor(e.prototype,n);i&&"constructor"!==n&&Object.defineProperty(t.prototype,n,wa(e.prototype,n,i))}),t}(e)};function wa(e,t,n){if("function"!=typeof n.value)return n;let i=n.value;return{get(){const e=i.bind(this);return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e},set(e){i=e}}}class ba{constructor(e){if(!e)throw new Error("Currency settings missing");const{decimalPlaces:t,symbolLocation:n,symbol:i,thousandsSeparator:r,decimalSeparator:o}=e;if("string"!=typeof n||"string"!=typeof i||"string"!=typeof r||"string"!=typeof o||"string"!=typeof t)throw new gr("Invalid currency settings provided");this._decimalPlaces=parseInt(t,10),this._symbolLocation=n,this._symbol=i,this._thousandsSeparator=r,this._decimalSeparator=o}format(e){if("number"!=typeof e)throw new gr("Invalid amount provided");const t=this._formatNumber(e),n=this._formatCurrency(t);return e<0?`-${n}`:n}_formatNumber(e){const t=Math.abs(e),[n,i=""]=this._toFixed(t,this._decimalPlaces).split("."),r=n.replace(/\B(?=(\d{3})+(?!\d))/g,this._thousandsSeparator);return this._decimalPlaces<1?r:[r,i].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 Ea=class{constructor(e){this._storeConfig=e,this._customerFormatter=new ba(this._storeConfig.shopperCurrency),this._storeFormatter=new ba(this._storeConfig.currency)}toCustomerCurrency(e){const t=this._storeConfig.shopperCurrency.exchangeRate;return this._customerFormatter.format(e*t)}toStoreCurrency(e){return this._storeFormatter.format(e)}};Ea=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([_a],Ea);const Pa=Ea;var Oa,Aa,Ta,ka,Da,Ra,Ma,Na,La;function za(e){return e in Ra}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(Oa||(Oa={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Aa||(Aa={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(Ta||(Ta={})),function(e){e.pill="pill",e.rect="rect"}(ka||(ka={})),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"}(Ra||(Ra={})),function(e){e.OFFER="OFFER",e.PAYMENT_AUTHORIZATION="PAYMENT_AUTHORIZATION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.SHIPPING_OPTION="SHIPPING_OPTION"}(Ma||(Ma={})),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"}(Na||(Na={})),function(e){e.INITIALIZE="INITIALIZE",e.SHIPPING_OPTION="SHIPPING_OPTION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.OFFER="OFFER"}(La||(La={}));var Ua=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Fa{constructor(e,t){this._gatewayIdentifier=e,this._paymentIntegrationService=t,this._isBuyNowFlow=!1}mapToShippingAddressRequestBody({shippingAddress:e}){if(!e)return;const{company:t="",phone:n=""}=this._paymentIntegrationService.getState().getShippingAddress()||{};return this._mapToAddressRequestBody(e,t,n)}mapToBillingAddressRequestBody(e){const{billingAddress:t}=e.paymentMethodData.info;if(!t)return;const{company:n="",phone:i="",email:r,customFields:o=[]}=this._paymentIntegrationService.getState().getBillingAddress()||{};return Object.assign(Object.assign({},this._mapToAddressRequestBody(t,n,i,o)),{email:r||e.email})}mapToExternalCheckoutData(e){var t;const{paymentMethodData:{tokenizationData:{token:n},info:{cardNetwork:i,cardDetails:r}}}=e;if(!n)throw new Xi(Zi.MissingPaymentToken);return Promise.resolve(Object.assign({nonce:n,card_information:{type:i,number:r}},this._isBuyNowFlow&&{cart_id:null===(t=this._paymentIntegrationService.getState().getCart())||void 0===t?void 0:t.id}))}getRequiredData(){var e;return Ua(this,void 0,void 0,function*(){const t={emailRequired:!0};if(!this._isShippingAddressRequired())return t;const n=yield this._paymentIntegrationService.loadShippingCountries(),i=null===(e=n.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code);return Object.assign(Object.assign({},t),{shippingAddressRequired:!0,shippingAddressParameters:Object.assign({phoneNumberRequired:!0},i&&{allowedCountryCodes:i}),shippingOptionRequired:!0})})}getCallbackIntents(){return this._isShippingAddressRequired()?[Ma.OFFER,Ma.SHIPPING_ADDRESS,Ma.SHIPPING_OPTION]:[Ma.OFFER]}getCallbackTriggers(){const e=this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-2875.googlepay_coupons_handling"]||!1;return{availableTriggers:[La.INITIALIZE,La.SHIPPING_ADDRESS,La.SHIPPING_OPTION,...e?[La.OFFER]:[]],initializationTrigger:[La.INITIALIZE],addressChangeTriggers:[La.INITIALIZE,La.SHIPPING_ADDRESS],shippingOptionsChangeTriggers:[La.SHIPPING_OPTION],offerChangeTriggers:e?[La.OFFER]:[]}}getNonce(e){var t;const n=null===(t=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.nonce;if(!n)throw new Xi(Zi.MissingPaymentToken);return Promise.resolve(n)}extraPaymentData(){return Promise.resolve(void 0)}getMerchantInfo(){const{googleMerchantName:e,googleMerchantId:t,platformToken:n}=this.getGooglePayInitializationData();return{merchantName:e,merchantId:t,authJwt:n}}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 gr("Unable to proceed, gatewayMerchantId is missing.");return{gateway:this._gatewayIdentifier,gatewayMerchantId:e}}getCardParameters(){return{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:this.getPaymentMethod().supportedCards.filter(za).map(e=>Ra[e]),billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}initialize(e,t,n){return this._getPaymentMethodFn=e,this._isBuyNowFlow=Boolean(t),this._currencyCode=n,this._isBuyNowFlow&&this._getCurrencyCodeOrThrow(),Promise.resolve()}handleShippingAddressChange(e){var t,n,i,r;return Ua(this,void 0,void 0,function*(){e&&(e.name=e.name||"",e.address1=e.address1||"");const o=this.mapToShippingAddressRequestBody({shippingAddress:e});o&&(yield this._paymentIntegrationService.updateShippingAddress(o));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 Pa(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===(n=d.selectedShippingOption)||void 0===n?void 0:n.id)||(null==l?void 0:l.id)||(null===(i=u[0])||void 0===i?void 0:i.id);return!(null===(r=d.selectedShippingOption)||void 0===r?void 0:r.id)&&u[0]&&(yield this.handleShippingOptionChange((null==l?void 0:l.id)||u[0].id)),{defaultSelectedOptionId:e,shippingOptions:u}}})}handleShippingOptionChange(e){return Ua(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:n}=t().currency;return L(e().outstandingBalance,n).toFixed(n)}handleCoupons(e){return Ua(this,void 0,void 0,function*(){const{redemptionCodes:t=[]}=e,{offers:n}=this.getAppliedCoupons();let i;return yield t.reduce((e,t)=>Ua(this,void 0,void 0,function*(){if(yield e,n.some(({redemptionCode:e})=>e===t))return;const r=yield this.applyCoupon(t);r&&(i=r)}),Promise.resolve()),yield n.reduce((e,n)=>Ua(this,void 0,void 0,function*(){yield e,t.includes(n.redemptionCode)||(yield this._paymentIntegrationService.removeCoupon(n.redemptionCode))}),Promise.resolve()),{newOfferInfo:this.getAppliedCoupons(),error:i}})}getAppliedCoupons(){const e=this._paymentIntegrationService.getState(),{coupons:t}=e.getCheckout()||{};return{offers:(t||[]).map(e=>{const{displayName:t,code:n}=e;return{redemptionCode:n,description:t}})}}applyCoupon(e){return Ua(this,void 0,void 0,function*(){let t;try{yield this._paymentIntegrationService.applyCoupon(e)}catch(e){return e instanceof Error&&(t={reason:Na.OFFER_INVALID,message:e.message,intent:La.OFFER}),t}})}getGooglePayInitializationData(){return tr(this.getPaymentMethod().initializationData,()=>new gr("Missing initialization data."))}getPaymentMethod(){return tr(this._getPaymentMethodFn,()=>new nr(Ji.PaymentNotInitialized))()}getGatewayIdentifier(){return this._gatewayIdentifier}setGatewayIdentifier(e){this._gatewayIdentifier=e||this.getGatewayIdentifier()}_isShippingAddressRequired(){const{getCartOrThrow:e,getStoreConfig:t,getShippingAddress:n}=this._paymentIntegrationService.getState();return void 0===n()&&(i=e(),r=t(),!!i&&(!!i.lineItems.physicalItems.some(e=>e.isShippingRequired)||!(!r||!i.lineItems.customItems)&&i.lineItems.customItems.length>0));var i,r}_mapToAddressRequestBody(e,t,n,i){const{name:r,address1:o,address2:a,address3:s,locality:d,administrativeArea:c,countryCode:u,postalCode:l,phoneNumber:h}=e,[p,m]=this._getFirstAndLastName(r);return{firstName:p,lastName:m,company:t,address1:o,address2:`${a} ${s}`.trim(),city:d||c,stateOrProvince:c,stateOrProvinceCode:c,countryCode:u,postalCode:l,phone:h||n,customFields:i||[]}}_getFirstAndLastName(e){const t=e.split(" ");return 1===t.length?[e,""]:[t.slice(0,-1).join(" "),t[t.length-1]]}_getCurrencyCodeOrThrow(){return tr(this._currencyCode,()=>new gr('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}_getGooglePayShippingOption({id:e,cost:t,description:n,additionalDescription:i}){var r;const o=null===(r=this._currencyService)||void 0===r?void 0:r.toCustomerCurrency(t);return this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-3540.googlepay_new_shipping_options_description"]?{id:e,label:`${o||t} ${n}`,description:i}:{id:e,label:n,description:o||t}}}var Ba=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class xa extends Fa{constructor(e,t){super("braintree",e),this._braintreeSdk=t,this._methodId=Ia.BRAINTREE,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return Ba(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);let r=i.getPaymentMethod.call(this);if(r.clientToken||(r=(yield this._service.loadPaymentMethod(this._methodId)).getPaymentMethodOrThrow(this._methodId)),!r.clientToken||!r.initializationData)throw new Xi(Zi.MissingPaymentMethod);return this._braintreeSdk.initialize(r.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 n;return Ba(this,void 0,void 0,function*(){const i=yield t.getNonce.call(this,e),{clientToken:r,initializationData:o}=t.getPaymentMethod.call(this);if(!r||!o||!(null===(n=o.card_information)||void 0===n?void 0:n.bin))throw new Xi(Zi.MissingPaymentMethod);const{isThreeDSecureEnabled:a,card_information:{bin:s,isNetworkTokenized:d}}=o;if(a&&!d){const e=yield this._braintreeSdk.getBraintreeThreeDS(),{orderAmount:t}=this._service.getState().getOrderOrThrow();return(yield this._braintreePresent3DSChallenge(e,t,i,s)).nonce}return i})}extraPaymentData(){return Ba(this,void 0,void 0,function*(){return{deviceSessionId:yield this._getBraintreeDeviceData()}})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Ba(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new gr("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 Xi(Zi.MissingPaymentToken)}(i),n.nonce=i.androidPayCards[0].nonce,n.card_information.bin=i.androidPayCards[0].details.bin,n.card_information.isNetworkTokenized=i.androidPayCards[0].details.isNetworkTokenized,n})}getCardParameters(){return super.getCardParameters()}getPaymentGatewayParameters(){const e=Object.create(null,{getMerchantInfo:{get:()=>super.getMerchantInfo},getTransactionInfo:{get:()=>super.getTransactionInfo},getRequiredData:{get:()=>super.getRequiredData}});return Ba(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 Xi(Zi.MissingPaymentMethod);return this._braintreeGooglePayment}_getBraintreeDeviceData(){return Ba(this,void 0,void 0,function*(){const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e})}_braintreePresent3DSChallenge(e,t,n,i){return new Yo(e.verifyCard({amount:t,bin:i,nonce:n,onLookupComplete:(e,t)=>{t()}})).promise}}class qa 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 ja=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ga{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t,n;return ja(this,void 0,void 0,function*(){if(!e.methodId||(i=e.methodId,!Object.values(Ia).includes(i)))throw new gr('Unable to proceed because "methodId" is not a valid key.');var i;if(this._methodId=e.methodId,!e.containerId)throw new gr('Unable to proceed because "containerId" is not a valid key.');const r=e[this._getMethodOrThrow()];if(!r)throw new gr("Unable to proceed without valid options.");const{buyNowInitializeOptions:o,currencyCode:a,buttonColor:s,buttonType:d,onError:c}=r;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,o){if(!a)throw new gr('Unable to initialize payment because "options.currencyCode" argument is not provided.');this._currencyCode=a,this._buyNowInitializeOptions=o,yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions(),!!o,a)}else yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initialize(()=>u,this._getGooglePayClientOptions());this._paymentButton=null!==(n=this._paymentButton)&&void 0!==n?n: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=>ja(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 n=t;if(function(e){return"object"==typeof e&&null!==e&&"statusCode"in e}(t)){if("CANCELED"===t.statusCode)throw new Qr;n=new qa(JSON.stringify(t))}throw null==e||e(new qa("An error occurred while requesting your Google Pay payment details.")),n}})}_interactWithPaymentSheet(){var e;return ja(this,void 0,void 0,function*(){const t=yield this._googlePayPaymentProcessor.showPaymentSheet(),n=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(t),i=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(t),r="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;n&&(yield this._paymentIntegrationService.updateBillingAddress(n)),i&&!(null===(e=this._buyNowCart)||void 0===e?void 0:e.lineItems.digitalItems.length)&&(yield this._paymentIntegrationService.updateShippingAddress(i)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodOrThrow(),t,r)})}_getGooglePayClientOptions(){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:e,shippingAddress:t,shippingOptionData:n,offerData:i})=>ja(this,void 0,void 0,function*(){const{availableTriggers:r,addressChangeTriggers:o,shippingOptionsChangeTriggers:a,offerChangeTriggers:s}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!r.includes(e))return;const d=o.includes(e)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(t):void 0;a.includes(e)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(n.id));const{newOfferInfo:c,error:u}=s.includes(e)?yield this._googlePayPaymentProcessor.handleCoupons(i):{},l=u;return this._buyNowInitializeOptions?this._getBuyNowTransactionInfo(d,c,l):this._getTransactionInfo(d,c,l)})}}}_createBuyNowCartOrThrow(e){return ja(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 yr(e);throw e}}})}_getBuyNowTransactionInfo(e,t,n){if(!this._buyNowCart)return;const{cartAmount:i}=this._buyNowCart,r=this._googlePayPaymentProcessor.getTotalPrice();return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:this._getCurrencyCodeOrThrow(),totalPrice:r||String(i),totalPriceStatus:Da.FINAL})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})}_getTransactionInfo(e,t,n){return ja(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadCheckout();const i=this._googlePayPaymentProcessor.getTotalPrice(),{code:r}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:r,totalPriceStatus:Da.FINAL,totalPrice:i})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})})}_getMethodOrThrow(){return tr(this._methodId,()=>new nr(Ji.PaymentNotInitialized))}_getCurrencyCodeOrThrow(){return tr(this._currencyCode,()=>new gr('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}}var Ha=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Va{constructor(e,t,n,i){this._scriptLoader=e,this._gateway=t,this._requestSender=n,this._formPoster=i,this._baseRequest={apiVersion:2,apiVersionMinor:0}}initialize(e,t,n,i){return Ha(this,void 0,void 0,function*(){this._paymentsClient=yield this._scriptLoader.getGooglePaymentsClient(e().config.testMode,t),yield this._gateway.initialize(e,n,i),this._buildButtonPayloads()})}initializeWidget(){return Ha(this,void 0,void 0,function*(){yield this._buildWidgetPayloads(),yield this._determineReadinessToPay(),this._prefetchGooglePaymentData()})}getNonce(e){return this._gateway.getNonce(e)}extraPaymentData(){return Ha(this,void 0,void 0,function*(){return this._gateway.extraPaymentData()})}addPaymentButton(e,t){const n=document.querySelector(`#${e}`);if(!n)return;const i=this._getPaymentsClient().createButton(Object.assign(Object.assign({},t),{allowedPaymentMethods:[this._getBaseCardPaymentMethod()]}));return n.appendChild(i)}showPaymentSheet(){return Ha(this,void 0,void 0,function*(){const e=this._getPaymentDataRequest();return this._getPaymentsClient().loadPaymentData(e)})}setExternalCheckoutXhr(e,t){return Ha(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t)})}setExternalCheckoutForm(e,t,n){return Ha(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t,!0,n)})}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 Ha(this,void 0,void 0,function*(){yield this._requestSender.get(`/remote-checkout/${e}/signout`)})}getCallbackTriggers(){return this._gateway.getCallbackTriggers()}handleShippingAddressChange(e){return Ha(this,void 0,void 0,function*(){return this._gateway.handleShippingAddressChange(e)})}handleShippingOptionChange(e){return Ha(this,void 0,void 0,function*(){yield this._gateway.handleShippingOptionChange(e)})}handleCoupons(e){return Ha(this,void 0,void 0,function*(){return this._gateway.handleCoupons(e)})}getTotalPrice(){return this._gateway.getTotalPrice()}_setExternalCheckout(e,t,n=!1,i){return Ha(this,void 0,void 0,function*(){const r="/checkout.php",o=Object.assign({action:"set_external_checkout",provider:e},yield this._gateway.mapToExternalCheckoutData(t));if(n)return new Promise(e=>{this._formPoster.postForm(i?`${i}/checkout`:r,Object.assign(Object.assign({},o),{card_information:JSON.stringify(o.card_information)}),e)});yield this._requestSender.post(r,{headers:Object.assign({Accept:"text/html","Content-Type":"application/x-www-form-urlencoded"},br),body:o})})}_prefetchGooglePaymentData(){const e=this._getPaymentDataRequest();e.transactionInfo=this._gateway.getTransactionInfo(),this._getPaymentsClient().prefetchPaymentData(e)}_determineReadinessToPay(){return Ha(this,void 0,void 0,function*(){try{const{result:e}=yield this._getPaymentsClient().isReadyToPay(this._getIsReadyToPayRequest());if(!1===e)throw new qa("Google Pay is not supported by the current device and browser, please try another payment method.")}catch(e){if(e instanceof qa)throw e;throw new qa}})}_buildButtonPayloads(){this._baseCardPaymentMethod={type:"CARD",parameters:this._gateway.getCardParameters()}}_buildWidgetPayloads(){return Ha(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 tr(e,()=>new nr(Ji.PaymentNotInitialized))}}class Ya{constructor(e){this._scriptLoader=e,this._window=window}getGooglePaymentsClient(e=!1,t){return n=this,i=void 0,o=function*(){if(yield this._scriptLoader.loadScript("https://pay.google.com/gp/p/js/pay.js"),!this._window.google)throw new hr;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((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}function Wa(){return new Ya(le())}const $a=mr(t=>{const i=e(),r=window,o=new Dr(t),a=new Vr(new Kr(le(),r,o));return new Ga(t,new Va(Wa(),new xa(t,a),i,n()))},[{id:"googlepaybraintree"}]);var Ka=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Qa{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new hr}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new hr;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new hr}return this.window.paypalApms})}getPayPalMessages(e,t){return Ka(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new hr;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return Ka(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,attributionId:d}=r;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:o},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:u,isDeveloperModeApplicable:l}=r,h=u||n;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:o},l&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:o,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:u=[]}=n,l=u,h=c.filter(e=>!u.includes(e));return{options:Object.assign({"client-id":r,"merchant-id":o,"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:i},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new Xi(Zi.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:o,isDeveloperModeApplicable:a,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":r,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":o}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function Za(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 Xi(Zi.MissingPaymentMethod)}var Ja=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Xa extends Fa{constructor(e,t){super("paypalsb",e),this.payPalCommerceSdk=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var r,o,a,s,d;return Ja(this,void 0,void 0,function*(){const c=null!==(o=null===(r=this.service.getState().getStoreConfig())||void 0===r?void 0:r.currency.code)&&void 0!==o?o:n;if(!c)throw new Xi(Zi.MissingPaymentMethod);yield i.initialize.call(this,e,t,c);const u=i.getPaymentMethod.call(this);if(!u.initializationData)throw new Xi(Zi.MissingPaymentMethod);Za(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 Ja(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}const es=mr(t=>new Ga(t,new Va(Wa(),new Xa(t,new Qa(le())),e(),n())),[{id:"googlepaypaypalcommerce"}]);var ts=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ns extends Fa{constructor(e,t){super("googlepay_bigcommerce_payments",e),this.payPalSdkHelper=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var r,o,a,s,d;return ts(this,void 0,void 0,function*(){const c=null!==(o=null===(r=this.service.getState().getStoreConfig())||void 0===r?void 0:r.currency.code)&&void 0!==o?o:n;if(!c)throw new Xi(Zi.MissingPaymentMethod);yield i.initialize.call(this,e,t,c);const u=i.getPaymentMethod.call(this);if(!u.initializationData)throw new Xi(Zi.MissingPaymentMethod);Za(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 ts(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}const is=mr(t=>new Ga(t,new Va(Wa(),new ns(t,new Eo(le())),e(),n())),[{id:"googlepay_bigcommerce_payments"}]),rs=mr(t=>{const i=e();return new Ga(t,new Va(Wa(),new Fa("adyen",t),i,n()))},[{id:"googlepayadyenv2"}]),os=mr(t=>{const i=e();return new Ga(t,new Va(Wa(),new Fa("adyen",t),i,n()))},[{id:"googlepayadyenv3"}]);class as extends Fa{constructor(e){super("authorizenet",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return function(e){if(!function(e){return"paymentGatewayId"in e}(e))throw new Xi(Zi.MissingPaymentMethod)}(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.paymentGatewayId}}}const ss=mr(t=>new Ga(t,new Va(Wa(),new as(t),e(),n())),[{id:"googlepayauthorizenet"}]),ds=e=>"object"==typeof e&&null!==e&&"body"in e;function cs(e){if(!function(e){return"checkoutcomkey"in e}(e))throw new Xi(Zi.MissingPaymentMethod)}var us=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ls extends Fa{constructor(e,t){super("checkoutltd",e),this._requestSender=t}processAdditionalAction(e){return new Promise((t,n)=>{if(ds(e)&&function(e){var t;if("object"!=typeof e||null===e)return!1;const n=e;return"string"==typeof(null===(t=n.three_ds_result)||void 0===t?void 0:t.acs_url)&&"string"==typeof n.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);n(e)})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return us(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new gr("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 Xi(Zi.MissingPaymentToken)}(i),n.nonce=yield this._tokenize(i),n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return cs(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.checkoutcomkey}}_tokenize(e){return us(this,void 0,void 0,function*(){const t=this.getPaymentMethod().config.testMode?"https://api.sandbox.checkout.com/tokens":"https://api.checkout.com/tokens",n=this.getGooglePayInitializationData();cs(n);const{body:i}=yield this._requestSender.post(t,{credentials:!1,body:{type:"googlepay",token_data:e},headers:{Authorization:n.checkoutcomkey,"Content-Type":wr.Json,"X-XSRF-TOKEN":null}});return i.token})}}const hs=mr(t=>{const i=e();return new Ga(t,new Va(Wa(),new ls(t,i),i,n()))},[{id:"googlepaycheckoutcom"}]);class ps extends Fa{constructor(e){super("cybersource",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}const ms=mr(t=>new Ga(t,new Va(Wa(),new ps(t),e(),n())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]);class gs extends Fa{constructor(e){super("chase",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}const ys=mr(t=>new Ga(t,new Va(Wa(),new gs(t),e(),n())),[{id:"googlepayorbital"}]);function fs(e){if(!function(e){return"stripeConnectedAccount"in e&&"stripePublishableKey"in e&&"stripeVersion"in e}(e))throw new Xi(Zi.MissingPaymentMethod)}var vs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ss extends Fa{constructor(e,t){super("stripe",e),this.paymentIntegrationService=e,this.scriptLoader=t}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return vs(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new gr("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 Xi(Zi.MissingPaymentToken)}(i),n.nonce=i.id,n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();fs(e);const{stripeVersion:t,stripePublishableKey:n,stripeConnectedAccount:i}=e;return{gateway:this.getGatewayIdentifier(),"stripe:version":t,"stripe:publishableKey":`${n}/${i}`}}processAdditionalAction(e,t){var n,i;return vs(this,void 0,void 0,function*(){if(!t)throw new Ho(["payment"]);if(!ds(e)||("object"!=typeof(r=e.body)||null===r||!("three_ds_result"in r)||!("errors"in r)))throw e;var r;const o=this.paymentIntegrationService.getState(),a=null===(n=o.getStoreConfig())||void 0===n?void 0:n.checkoutSettings.features["STRIPE-476.enable_stripe_googlepay_3ds"];if(z(e.body.errors,{code:"three_d_secure_required"})&&a){const n=this.getGooglePayInitializationData();fs(n);const{stripePublishableKey:r,stripeConnectedAccount:o}=n;this.stripeUPEClient=yield this.loadStripeJs(r,o);const a=e.body.three_ds_result.token;let s,d=!1;try{s=yield this.stripeUPEClient.confirmCardPayment(a)}catch(e){try{s=yield this.stripeUPEClient.retrievePaymentIntent(a)}catch(e){d=!0}}if(null==s?void 0:s.error){if(this._throwDisplayableStripeError(s.error),this._isCancellationError(s.error))throw new Qr;throw new qa}if(!(null==s?void 0:s.paymentIntent)&&!d)throw new _e;return this.paymentIntegrationService.submitPayment({methodId:t,paymentData:{nonce:(null===(i=null==s?void 0:s.paymentIntent)||void 0===i?void 0:i.id)||a}})}throw e})}loadStripeJs(e,t){return vs(this,void 0,void 0,function*(){return this.stripeUPEClient?this.stripeUPEClient:this.scriptLoader.getStripeClient(e,t)})}_isCancellationError(e){var t,n;return e&&-1!==(null===(n=null===(t=e.payment_intent.last_payment_error)||void 0===t?void 0:t.message)||void 0===n?void 0:n.indexOf("canceled"))}_throwDisplayableStripeError(e){if(g(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}}var Cs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Is{constructor(e,t=window){this.scriptLoader=e,this.stripeWindow=t}getStripeClient(e,t,n){return Cs(this,void 0,void 0,function*(){let i=this.stripeWindow.bcStripeClient;return i||(i=(yield this.load())(e,{stripeAccount:t,locale:n,betas:["payment_element_beta_2","alipay_pm_beta_1","link_default_integration_beta_1","shipping_address_element_beta_1","address_element_beta_1"],apiVersion:"2020-03-02;alipay_beta=v1;link_beta=v1"}),Object.assign(this.stripeWindow,{bcStripeClient:i})),i})}load(){return Cs(this,void 0,void 0,function*(){if(this.stripeWindow.Stripe||(yield this.scriptLoader.loadScript("https://js.stripe.com/v3/")),!this.stripeWindow.Stripe)throw new hr;return this.stripeWindow.Stripe})}}const _s=mr(t=>new Ga(t,new Va(Wa(),new Ss(t,new Is(le())),e(),n())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]);class ws extends Fa{constructor(e){super("worldpay",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,o=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}const bs=mr(t=>new Ga(t,new Va(Wa(),new ws(t),e(),n())),[{id:"googlepayworldpayaccess"}]);function Es(){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 Ps=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Os extends Fa{constructor(e,t){super("worldlinena",e),this.formPoster=t}extraPaymentData(){return Ps(this,void 0,void 0,function*(){return Promise.resolve({browser_info:Es()})})}processAdditionalAction(e){return Ps(this,void 0,void 0,function*(){if(!function(e){return ds(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:n,payer_auth_request:i,merchant_data:r}=t||{};if(!n||!i||!r)throw new Ho(["formUrl","threeDSSessionData","creq"]);return new Promise(e=>{this.formPoster.postForm(n,{threeDSSessionData:i,creq:r},e,"_top")})})}}const As=mr(t=>new Ga(t,new Va(Wa(),new Os(t,n()),e(),n())),[{id:"googlepaytdonlinemart"}]);var Ts,ks,Ds,Rs,Ms,Ns,Ls;!function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(Ts||(Ts={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(ks||(ks={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(Ds||(Ds={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(Rs||(Rs={})),function(e){e.pill="pill",e.rect="rect"}(Ms||(Ms={})),(Ns||(Ns={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Ls||(Ls={}));var zs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Us{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=i}loadPayPalSdk(e,t,n,i){return zs(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,o,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new hr;return this.paypalSdk}createBuyNowCartOrThrow(e){return zs(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new Xi(Zi.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new yr}})}createOrder(e,t){return zs(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return zs(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(){return zs(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:n.availableShippingOptions,cartId:t.id,selectedShippingOption:n.selectedShippingOption})}catch(e){throw new _e}})}getOrderStatus(e,t){return zs(this,void 0,void 0,function*(){try{const{status:n}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _e}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new Xi(Zi.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===oo.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return zs(this,void 0,void 0,function*(){const i={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:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}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,n;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===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:r}=e||{},o={color:t&&Rs[t]?t:void 0,height:this.getValidHeight(n),label:i&&Ds[i]?i:void 0,shape:r&&Ms[r]?r:void 0};return D(o,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 Fs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Bs{constructor(e){this.requestSender=e}createOrder(e,t){return Fs(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return Fs(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:n,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return Fs(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":Ir,"Content-Type":wr.Json},br);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}var xs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class qs{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return xs(this,void 0,void 0,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e,t=!1){return xs(this,void 0,void 0,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.paypal)throw new hr;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new Xi(Zi.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}=o,v=h||n,S="paypalcommercecreditcards"===i,C=S?["card"]:[],I=p?["credit","paylater"]:[],_=n||!v,w=l?["venmo"]:[],b=_?y:[],E=f?["googlepay"]:[],P=n?["card-fields"]:[],O=[...S?[]:["card"],...p?[]:["credit","paylater"],...l?[]:["venmo"],..._?g.filter(e=>!y.includes(e)):g],A=[...C,...I,...w,...b];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":A.length>0?A:void 0,"disable-funding":O.length>0?O:void 0,commit:v,components:["buttons","hosted-fields","payment-fields","legal",...E,...P],currency:t,intent:a},m&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":u,"data-client-token":r}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const js=t=>{const{getHost:i}=t.getState();return new Us(n(),t,new Bs(e({host:i()})),new qs(le()))};var Gs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Hs{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){var t;return Gs(this,void 0,void 0,function*(){const{paypalcommerce:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(o&&!n.currencyCode)throw new gr('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new gr('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n,o)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){var r,o;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:c}=n,u=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:h,isAppSwitchEnabled:p}=l.initializationData||{},m=Object.assign(Object.assign({},!i&&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,n)=>this.onHostedCheckoutApprove(e,n,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===(r=v.hasReturned)||void 0===r?void 0:r.call(v))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(o=v.resume)||void 0===o||o.call(v):v.render(`#${e}`):c&&"function"==typeof c?c():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return Gs(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Gs(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalCommerceIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Gs(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 Gs(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 Vs=mr(e=>new Hs(e,js(e)),[{id:"paypalcommerce"}]),Ys=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 Ws=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class $s{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=n}initialize(e){var t;return Ws(this,void 0,void 0,function*(){const{paypalcommercecredit:n,containerId:i,methodId:r}=e,{buyNowInitializeOptions:o,currencyCode:a,messagingContainerId:s}=n||{},d=!!o;if(!r)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(d&&!a)throw new gr('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(d&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new gr('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(r,u,!1),this.renderButton(i,r,n);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(r),{paypalBNPLConfiguration:t=[]}=e.initializationData||{},n=t&&t.find(({id:e})=>"cart"===e);if(!(null==n?void 0:n.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 i=yield this.paypalCommerceSdk.getPayPalMessages(e,u);this.renderMessages(i,s,n)}})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},p=Object.assign(Object.assign({},!u&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)}),m=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let g=!1;m.forEach(t=>{if(!g){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r)},l),i&&h),c&&p),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),g=!0):a&&"function"==typeof a&&a()}}),g||this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return Ws(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return Ws(this,void 0,void 0,function*(){if(!e.orderID)throw new Xi(Zi.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalCommerceIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return Ws(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 Ws(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,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"cart",style:Ys(n)};e.Messages(i).render(`#${t}`)}}const Ks=mr(e=>new $s(e,js(e),new Qa(ue())),[{id:"paypalcommercecredit"}]);var Qs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Zs{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Qs(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(a&&!o)throw new gr('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new gr('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?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,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(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&c),l=a.Buttons(u);l.isEligible()?l.render(`#${e}`):o&&"function"==typeof o?o():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===Rs.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return Qs(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Js=mr(e=>new Zs(e,js(e)),[{id:"paypalcommercevenmo"}]);var Xs=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ed{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Xs(this,void 0,void 0,function*(){const{paypalcommercealternativemethods:t,containerId:n,methodId:i}=e,{apm:r,buyNowInitializeOptions:o,currencyCode:a}=t||{},s=!!o;if(!i)throw new gr('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new gr('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new gr('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');if(!r)throw new gr('Unable to initialize payment because "options.paypalcommercealternativemethods.apm" argument is not provided.');if(s&&!a)throw new gr('Unable to initialize payment because "options.paypalcommercealternativemethods.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==o?void 0:o.getBuyNowCartRequestBody))throw new gr('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.paypalCommerceIntegrationService.loadPayPalSdk(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{apm:i,buyNowInitializeOptions:r,style:o,onEligibilityFailure:a}=n,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(i))throw new gr('Unable to initialize PayPal button because "options.paypalcommercealternativemethods.apm" argument is not valid funding source.');const d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethod"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},c={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Object.assign(Object.assign({fundingSource:i,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o)},d),r&&c),l=s.Buttons(u);l.isEligible()?l.render(`#${e}`):a&&"function"==typeof a?a():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return Xs(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const td=mr(e=>new ed(e,js(e)),[{id:"paypalcommercealternativemethods"}]);var nd,id,rd,od,ad,sd;!function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(nd||(nd={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(id||(id={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black"}(rd||(rd={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(od||(od={})),function(e){e.PILL="pill",e.RECT="rect"}(ad||(ad={})),function(e){e.ACKNOWLEDGE="ACKNOWLEDGE",e.FINALIZE="FINALIZE",e.INITIALIZE="INITIALIZE"}(sd||(sd={}));var dd=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class cd{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalExpressScriptLoader=t,this.formPoster=n}initialize(e){return dd(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!e.paypal)throw new gr;if(!t.config.merchantId)throw new Xi(Zi.MissingPaymentMethod);const n=yield this.paypalExpressScriptLoader.loadPaypalSDK(t.config.merchantId);this.renderButton(e,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t){const{containerId:n,methodId:i,paypal:r}=e,{allowCredit:o,clientId:a,onPaymentError:s,shouldProcessPayment:d,style:c}=r,u=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e.methodId);if(!u.config.merchantId)throw new Xi(Zi.MissingPaymentMethod);const l=u.config.merchantId,h=u.config.testMode?"sandbox":"production",p={[h]:a},m=t.FUNDING.CREDIT||"credit",g=o?[m]:[],y=o?[]:[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,i,t,d)},n)}getStyle(e){const{color:t,fundingicons:n,label:i,layout:r,shape:o,size:a,tagline:s}=e||{};return{color:t,fundingicons:n,label:i,layout:r,shape:o||ad.RECT,size:"small"===a?id.RESPONSIVE:a,tagline:s}}setupPayment(e,t,n){return dd(this,void 0,void 0,function*(){if(!t)throw new nr(Ji.CheckoutButtonNotInitialized);try{const n=yield this.paymentIntegrationService.loadDefaultCheckout(),{id:i}=n.getCartOrThrow(),r=n.getHost()||"";return(yield t.request.post(`${r}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:i},{headers:Object.assign({"X-API-INTERNAL":Ir},br)})).id}catch(e){throw n&&e instanceof Ce&&n(e),e}})}tokenizePayment(e,t,n,i){return dd(this,void 0,void 0,function*(){if(!n)throw new nr(Ji.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new Xi(Zi.MissingPayment);const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),o=yield n.payment.get(e.paymentID);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:r.id,action:i?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(o.payer.payer_info)})})}}class ud{constructor(e){this.scriptLoader=e,this.window=window}loadPaypalSDK(e=""){return t=this,n=void 0,r=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 hr;return this.window.paypal},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}}const ld=mr(e=>new cd(e,new ud(le()),n()),[{id:"paypalexpress"}]);function hd(e,t,n){const i=new WeakMap;function r(e){return(...n)=>{const r=n[n.length-1],{useCache:o}=(a=r)&&"boolean"==typeof a.useCache?r:{useCache:!1};var a;if(!o)return e.call(this,...n);const s=i.get(this)||{};var d;return i.get(this)||i.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(ie()):"function"==typeof t?ae(e=>W(t(e)).pipe(ie()),{isEqual:v}):t},{isEqual:v}))),s[t].call(this,...n)}}return{get(){if("function"!=typeof n.value)throw new Error("Decorator should be used in functions");const e=r.call(this,n.value);return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e}}}const pd=e=>!!e;class md{constructor(e){this._requestSender=e}loadPaymentMethodsById(e,t){return n=>new j(i=>{var r;const a=null===(r=n.getState().cart.getCart())||void 0===r?void 0:r.id,s=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);i.next(o(vn.LoadPaymentMethodsRequested)),Promise.all(e.map(e=>{return n=this,i=void 0,o=function*(){try{return(yield this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:s}))).body}catch(e){return}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o})).then(e=>{const t=e.filter(pd);i.next(o(vn.LoadPaymentMethodsSucceeded,t)),i.complete()}).catch(e=>{i.next(o(vn.LoadPaymentMethodsFailed,e)),i.complete()})})}loadPaymentMethods(e){return t=>j.create(n=>{const i=t.getState().cart.getCartOrThrow();n.next(o(vn.LoadPaymentMethodsRequested)),this._requestSender.loadPaymentMethods(Object.assign(Object.assign({},e),{params:Object.assign(Object.assign({},null==e?void 0:e.params),{cartId:i.id})})).then(e=>{const t={deviceSessionId:e.headers["x-device-session-id"],sessionHash:e.headers["x-session-hash"]},i=e.body;n.next(o(vn.LoadPaymentMethodsSucceeded,i,t)),n.complete()}).catch(e=>{n.error(s(vn.LoadPaymentMethodsFailed,e))})})}loadPaymentMethod(e,t){return n=>j.create(i=>{var r;const a=null===(r=n.getState().cart.getCart())||void 0===r?void 0:r.id,d=a?Object.assign(Object.assign({},null==t?void 0:t.params),{cartId:a}):Object.assign({},null==t?void 0:t.params);i.next(o(vn.LoadPaymentMethodRequested,void 0,{methodId:e})),this._requestSender.loadPaymentMethod(e,Object.assign(Object.assign({},t),{params:d})).then(t=>{i.next(o(vn.LoadPaymentMethodSucceeded,t.body,{methodId:e})),i.complete()}).catch(t=>{i.error(s(vn.LoadPaymentMethodFailed,t,{methodId:e}))})})}}var gd;(function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)})([hd],md.prototype,"loadPaymentMethod",null),function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(gd||(gd={}));const yd=gd,fd="This API endpoint is for internal use only and may change in the future",vd={"X-Checkout-SDK-Version":"1.818.0"};class Sd{constructor(e){this._requestSender=e}loadPaymentMethods({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/payments",{timeout:e,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd),params:t})}loadPaymentMethod(e,{timeout:t,params:n}={}){const i=`/api/storefront/payments/${e}`;return this._requestSender.get(i,{timeout:t,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd),params:n})}}function Cd(e,t,n){return(i=t)&&i.type&&i.error?H(Q(t),Z(s(e,t.payload,n))):Z(s(e,t,n));var i}class Id 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 _d{constructor(e,t){this._requestSender=e,this._subscriptionActionCreator=t}continueAsGuest(e,t){return n=>{const i=n.getState(),r=i.checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);const a=i.customer.getCustomer();if(a&&!a.isGuest)throw new Id;const s=i.billingAddress.getBillingAddress();let d;if(s){const{country:t}=s,n=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(s,["country"]);d=Object.assign(Object.assign({},n),e)}else d=e;const c=!f(s);return K(H(Q(o(Ue.ContinueAsGuestRequested)),V(()=>{return e=this,n=void 0,a=function*(){const{body:e}=yield this._createOrUpdateBillingAddress(r.id,d,c,t);return o(Ue.ContinueAsGuestSucceeded,e)},new((i=void 0)||(i=Promise))(function(t,r){function o(e){try{d(a.next(e))}catch(e){r(e)}}function s(e){try{d(a.throw(e))}catch(e){r(e)}}function d(e){var n;e.done?t(e.value):(n=e.value,n instanceof i?n:new i(function(e){e(n)})).then(o,s)}d((a=a.apply(e,n||[])).next())});var e,n,i,a})).pipe(J(e=>Cd(Ue.ContinueAsGuestFailed,e))),this._updateCustomerConsent(e,t))}}updateAddress(e,t){return n=>j.create(i=>{const r=n.getState(),a=r.checkout.getCheckout();if(!a)throw new qi(xi.MissingCheckout);i.next(o(Ue.UpdateBillingAddressRequested));const d=r.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})=>{i.next(o(Ue.UpdateBillingAddressSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Ue.UpdateBillingAddressFailed,e))})})}_updateCustomerConsent({email:e,acceptsAbandonedCartEmails:t,acceptsMarketingNewsletter:n},i){return null==t&&null==n?Y():this._subscriptionActionCreator.updateSubscriptions({email:e,acceptsMarketingNewsletter:n||!1,acceptsAbandonedCartEmails:t||!1},i)}_createOrUpdateBillingAddress(e,t,n,i){return n?this._requestSender.updateAddress(e,t,i):this._requestSender.createAddress(e,t,i)}}class wd 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 bd={include:["cart.lineItems.physicalItems.options","cart.lineItems.digitalItems.options","customer","promotions.banners"].join(",")};class Ed{constructor(e){this._requestSender=e}createAddress(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/billing-address`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(i,{body:t,params:bd,headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}updateAddress(e,t,{timeout:n}={}){const{id:i}=t,r=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["id"]),o=`/api/storefront/checkouts/${e}/billing-address/${i}`,a=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.put(o,{params:bd,body:r,headers:a,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}class Pd{constructor(e){this._requestSender=e}createBuyNowCart(e,{timeout:t}={}){const n=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post("/api/storefront/carts",{body:e,headers:n,timeout:t})}}class Od{constructor(e,t,n){this._checkoutRequestSender=e,this._configActionCreator=t,this._formFieldsActionCreator=n}loadCheckout(e,t){return()=>H(Q(o(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})=>o(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(e))))).pipe(J(e=>Cd(Me.LoadCheckoutFailed,e)))}loadDefaultCheckout(e){return t=>H(Q(o(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 n=this,i=void 0,a=function*(){const n=t.getState().config.getContextConfig();if(!n||!n.checkoutId)throw new qi(xi.MissingCheckoutConfig);const{body:i}=yield this._checkoutRequestSender.loadCheckout(n.checkoutId,e);return o(Me.LoadCheckoutSucceeded,this._transformCustomerAddresses(i))},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(e=>Cd(Me.LoadCheckoutFailed,e)))}updateCheckout(e,t){return n=>new j(i=>{const r=n.getState().checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);i.next(o(Me.UpdateCheckoutRequested)),this._checkoutRequestSender.updateCheckout(r.id,e,t).then(({body:e})=>{i.next(o(Me.UpdateCheckoutSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Me.UpdateCheckoutFailed,e))})})}loadCurrentCheckout(e){return t=>{const n=t.getState().checkout.getCheckout();if(!n)throw new qi(xi.MissingCheckout);return this.loadCheckout(n.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 Ad(e){return F(e).join(",")}function Td(e,t=[]){return Array.isArray(t)?Ad([...e,...t]):function(e,t){const n=b(M(t,e=>!e)),i=b(u(t));return Ad([...c(e,n),...i])}(e,t)}const kd=["cart.lineItems.physicalItems.options","cart.lineItems.digitalItems.options","customer","customer.customerGroup","payments","promotions.banners"];class Dd extends Pe{constructor(e){super(e,{message:e.body.title}),this.name="CheckoutNotAvailableError",this.type="checkout_not_available"}}class Rd{constructor(e){this._requestSender=e}loadCheckout(e,{params:{include:t}={},timeout:n}={}){const i=`/api/storefront/checkout/${e}`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.get(i,{params:{include:Td(kd,t)},headers:r,timeout:n}).catch(e=>{if(e.status>=400&&e.status<500)throw new Dd(e);throw e})}updateCheckout(e,t,{params:{include:n}={},timeout:i}={}){const r=`/api/storefront/checkout/${e}`,o=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.put(r,{params:{include:Td(kd,n)},body:t,headers:o,timeout:i})}}class Md{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 Nd 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 Ld{constructor(e){this._checkoutRequestSender=e}validate(e,t){if(!e)throw new qi(xi.MissingCheckout);return this._checkoutRequestSender.loadCheckout(e.id,t).then(t=>{const n=new Md;if(!(e.outstandingBalance===t.body.outstandingBalance&&this._compareCoupons(e.coupons,t.body.coupons)&&this._compareGiftCertificates(e.giftCertificates,t.body.giftCertificates)&&n.isEqual(e.cart,t.body.cart)))throw new Nd(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:n,giftCertificates:i,outstandingBalance:r}=e;return{cart:{cartAmount:t.cartAmount,currency:t.currency,lineItems:t.lineItems},coupons:n,giftCertificates:i,outstandingBalance:r}}}var zd;class Ud{constructor(e){this._configRequestSender=e}loadConfig(e){return j.create(t=>{t.next(o(mt.LoadConfigRequested)),this._configRequestSender.loadConfig(e).then(e=>{t.next(o(mt.LoadConfigSucceeded,e.body)),t.complete()}).catch(e=>{t.error(s(mt.LoadConfigFailed,e))})})}}!function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)}([hd],Ud.prototype,"loadConfig",null);class Fd{constructor(e){this._requestSender=e}loadConfig({timeout:e,params:t}={}){return this._requestSender.get("/api/storefront/checkout-settings",{timeout:e,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd),params:t}).catch(e=>{if(e.status>=400&&e.status<500)throw new Dd(e);throw e})}}class Bd{constructor(e){this._couponRequestSender=e}applyCoupon(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);i.next(o(Ze.ApplyCouponRequested)),this._couponRequestSender.applyCoupon(r.id,e,t).then(({body:e})=>{i.next(o(Ze.ApplyCouponSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Ze.ApplyCouponFailed,e))})})}removeCoupon(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r)throw new qi(xi.MissingCheckout);i.next(o(Ze.RemoveCouponRequested)),this._couponRequestSender.removeCoupon(r.id,e,t).then(({body:e})=>{i.next(o(Ze.RemoveCouponSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Ze.RemoveCouponFailed,e))})})}}!function(e){e.AvailableShippingOptions="consignments.availableShippingOptions",e.PhysicalItemsCategoryNames="cart.lineItems.physicalItems.categoryNames",e.DigitalItemsCategoryNames="cart.lineItems.digitalItems.categoryNames"}(zd||(zd={}));class xd{constructor(e){this._requestSender=e}applyCoupon(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/coupons`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(i,{headers:r,timeout:n,params:{include:Ad([...kd,zd.AvailableShippingOptions])},body:{couponCode:t}}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}removeCoupon(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/coupons/${t}`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.delete(i,{headers:r,timeout:n,params:{include:Ad([...kd,zd.AvailableShippingOptions])}}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}function qd(e){const t=e;return"object"==typeof t&&"object"==typeof t.payload&&"string"==typeof t.payload.token}class jd{constructor(e,t,n){this._customerRequestSender=e,this._checkoutActionCreator=t,this._spamProtectionActionCreator=n}createCustomer(e,t){return n=>{const i=n.getState().config.getStoreConfigOrThrow(),{isStorefrontSpamProtectionEnabled:r}=i.checkoutSettings,a=i=>W(this._customerRequestSender.createAccount(Object.assign(Object.assign({},e),{token:i}),t)).pipe(re(()=>H(this._checkoutActionCreator.loadCurrentCheckout(t)(n),Q(o(Dt.CreateCustomerSucceeded)))));return H(Q(o(Dt.CreateCustomerRequested)),r?W(this._spamProtectionActionCreator.execute()(n)).pipe(re(e=>{var t;return qd(e)?H(Q(e),a(null===(t=e.payload)||void 0===t?void 0:t.token)):Q(e)})):a()).pipe(J(e=>Cd(Dt.CreateCustomerFailed,e)))}}createAddress(e,t){return H(Q(o(Dt.CreateCustomerAddressRequested)),V(()=>{return n=this,i=void 0,a=function*(){const{body:n}=yield this._customerRequestSender.createAddress(e,t);return o(Dt.CreateCustomerAddressSucceeded,n)},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(e=>Cd(Dt.CreateCustomerAddressFailed,e)))}signInCustomer(e,t){return n=>{const i=n.getState().checkout.getCheckoutOrThrow(),r=i.cart.source===oo.BuyNow?i.id:void 0;return H(Q(o(Dt.SignInCustomerRequested)),W(this._customerRequestSender.signInCustomer(Object.assign(Object.assign({},e),{cartId:r}),t)).pipe(re(({body:e})=>e.data.persistentCartRetrievalInformation?H(this._checkoutActionCreator.loadCheckout(e.data.persistentCartRetrievalInformation.id,t)(n),Q(o(Dt.SignInCustomerSucceeded,e.data))):H(this._checkoutActionCreator.loadCurrentCheckout(t)(n),Q(o(Dt.SignInCustomerSucceeded,e.data)))))).pipe(J(e=>Cd(Dt.SignInCustomerFailed,e)))}}signOutCustomer(e){return t=>{const n=t.getState().checkout.getCheckoutOrThrow(),i=n.cart.source===oo.BuyNow?n.id:void 0;return H(Q(o(Dt.SignOutCustomerRequested)),W(this._customerRequestSender.signOutCustomer(e,i)).pipe(re(({body:n})=>H(this._checkoutActionCreator.loadCurrentCheckout(e)(t),Q(o(Dt.SignOutCustomerSucceeded,n.data)))))).pipe(J(e=>Cd(Dt.SignOutCustomerFailed,e)))}}}class Gd{constructor(e){this._requestSender=e}createAccount(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer",{timeout:t,headers:vd,body:e})}createAddress(e,{timeout:t}={}){return this._requestSender.post("/api/storefront/customer-address",{timeout:t,headers:vd,body:e})}signInCustomer(e,{timeout:t}={}){return this._requestSender.post("/internalapi/v1/checkout/customer",{timeout:t,headers:vd,body:e})}signOutCustomer({timeout:e}={},t){return this._requestSender.delete("/internalapi/v1/checkout/customer",Object.assign({timeout:e,headers:vd},t&&{body:{cartId:t}}))}}class Hd{constructor(e){this._formFieldsRequestSender=e}loadFormFields(e){return H(Q(o(Kt.LoadFormFieldsRequested)),V(()=>{return t=this,n=void 0,r=function*(){const{body:t}=yield this._formFieldsRequestSender.loadFields(e);return o(Kt.LoadFormFieldsSucceeded,t)},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r})).pipe(J(e=>Cd(Kt.LoadFormFieldsFailed,e)))}}!function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)}([hd],Hd.prototype,"loadFormFields",null);class Vd{constructor(e){this._requestSender=e}loadFields({timeout:e}={}){return this._requestSender.get("/api/storefront/form-fields",{timeout:e,headers:Object.assign({Accept:yd.JsonV1,"X-API-INTERNAL":fd},vd)})}}class Yd 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 Wd{constructor(e){this._mutationObserver=e}ensurePresence(e,t){return n=this,i=void 0,o=function*(){const n=new Yo(t),i=this._mutationObserver.create(t=>{t.forEach(t=>{0!==Array.from(t.removedNodes).filter(t=>e.some(e=>t===e||t.contains(e))).length&&n.cancel(new Yd)})});i.observe(document.body,{childList:!0,subtree:!0});try{const e=yield n.promise;return i.disconnect(),e}catch(e){throw i.disconnect(),e}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}}class $d{constructor(e=window){this._window=e}create(e){return new this._window.MutationObserver(e)}}class Kd extends be{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}function Qd(e){if(!/^(https?:)?\/\//.test(e))throw new Kd("The provided URL must be absolute.");const t=document.createElement("a");t.href=e;const n=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}${n?`:${n}`:""}`,pathname:t.pathname,port:n,protocol:t.protocol,search:t.search}}function Zd(e,t){return e.type===t}class Jd{constructor(e,t,n){this._targetWindow=t,this._context=n,this._targetOrigin="*"===e?"*":Qd(e).origin}post(e,t){const n=this._targetWindow;if(window===n)return;if(!n)throw new Error("Unable to post message because target window is not set.");const i=t&&$(window,"message").pipe(ee(e=>e.origin===this._targetOrigin&&Zd(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}),oe(1)).toPromise();return n.postMessage(Object.assign(Object.assign({},e),{context:this._context}),this._targetOrigin),i}setTarget(e){this._targetWindow=e}setContext(e){this._context=e}}class Xd{constructor(e){var t;this._sourceOrigins=[Qd(e).origin,(t=Qd(e),Qd(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 n=this._listeners[e];n||(this._listeners[e]=n=[]),-1===n.indexOf(t)&&n.push(t)}removeListener(e,t){const n=this._listeners[e];if(!n)return;const i=n.indexOf(t);i>=0&&n.splice(i,1)}trigger(e,t){const n=this._listeners[e.type];n&&n.forEach(n=>t?n(e,t):n(e))}_handleMessage(e){if(-1===this._sourceOrigins.indexOf(e.origin)||!Zd(e.data,e.data.type))return;const t=e.data,{context:n}=t,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["context"]);this.trigger(i,n)}}!function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)}([_a],Xd.prototype,"_handleMessage",null);class ec 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 tc extends be{constructor(){super("Please complete our human verification challenge and try again."),this.name="CardingProtectionChallengeNotCompletedError",this.type="carding_protection_challenge_not_completed"}}class nc 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 ic,rc,oc,ac=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class sc{constructor(e){this._googleRecaptcha=e}handle(e,t){return ac(this,void 0,void 0,function*(){return"string"==typeof e?this.handleWithRecaptchaSitekey(e,t):this.handleWithPaymentHumanVerificationRequestError(e)})}handleWithPaymentHumanVerificationRequestError(e){return ac(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 ac(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(oe(1)).pipe(re(({error:e,token:t})=>ac(this,void 0,void 0,function*(){if(e instanceof ec)throw new tc;if(e||!t)throw new nc;return{type:"recaptcha_v2_verification",data:{human_verification_token:t}}}))).toPromise()}_initialize(e){const t="cardingProtectionContainer";let n=document.getElementById(t);return n&&n.parentNode&&n.parentNode.removeChild(n),n=document.createElement("div"),n.setAttribute("id",t),document.body.appendChild(n),this._googleRecaptcha.load(t,e)}_isPaymentHumanVerificationRequest(e){const{additional_action_required:t,status:n}=e.body||{};return"additional_action_required"===n&&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"}(ic||(ic={}));class dc extends be{constructor(e){super(function(e){switch(e){case ic.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case ic.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case ic.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case ic.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 cc 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 uc extends be{constructor(){super("Spam protection is not loaded. Please try again."),this.name="SpamProtectionNotLoadedError",this.type="spam_protection_failed"}}class lc{constructor(e,t){this.googleRecaptchaScriptLoader=e,this.mutationObserverFactory=t,this._memoized=ae((e,t,n)=>{const i=new G;if(!n)throw new Error;return this._widgetId=e.render(n.id,{sitekey:t,size:"invisible",callback:()=>{i.next({token:e.getResponse(this._widgetId)}),e.reset(this._widgetId)},"error-callback":()=>{i.next({error:new cc})}}),i},{isEqual:(e,t)=>e===t})}load(e,t){return this.googleRecaptchaScriptLoader.load().then(n=>{n&&(this._event$=this._memoized(n,t,document.getElementById(e)),this._recaptcha=n)}).catch(e=>{throw e})}reset(e){var t;const n=document.getElementById(e);null==n||n.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 dc(ic.SpamProtectionNotInitialized);return V(()=>{const e=document.querySelector('iframe[src*="bframe"]');return e?Q(e):Z(new uc)}).pipe(ne(e=>e.pipe(X(250),re((e,t)=>t<28?Q(e):Z(e)))),re(n=>(this._watchRecaptchaChallengeWindow(e,n),t.execute(this._widgetId),e)),J(e=>Q({error:e})))})}_watchRecaptchaChallengeWindow(e,t){const n=t.parentElement;if(!n)throw new uc;const i=n.parentElement;if(!i)throw new uc;this.mutationObserverFactory.create(()=>{"hidden"===i.style.visibility&&e.next({error:new ec})}).observe(i,{attributes:!0,attributeFilter:["style"]})}}class hc{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((n,i)=>{this._window[e]=()=>n(this._window.grecaptcha),this._scriptLoader.loadScript(`//www.google.com/recaptcha/api.js?${t}`).catch(e=>{this._loadPromise=void 0,i(e)})})}}function pc(e){return new lc(new hc(e),new $d)}class mc 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 gc 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 yc 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"}(rc||(rc={})),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"}(oc||(oc={}));var fc=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class vc{constructor(e,t,n,i,r,o,a,s,d,c){this._type=e,this._containerId=t,this._placeholder=n,this._accessibilityLabel=i,this._styles=r,this._eventPoster=o,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.818.0&checkoutId=${this._checkoutId}`:"/checkout/payment/hosted-field?version=1.818.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 fc(this,void 0,void 0,function*(){const e=document.getElementById(this._containerId);if(!e)throw new mc("Unable to proceed because the provided container ID is not valid.");e.appendChild(this._iframe),this._eventListener.listen();const t=$(this._iframe,"load").pipe(re(({target:e})=>fc(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:rc.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:oc.AttachSucceeded,errorType:oc.AttachFailed})})),oe(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 fc(this,void 0,void 0,function*(){try{const n=this._eventPoster.post({type:rc.SubmitRequested,payload:{fields:e,data:t}},{successType:oc.SubmitSucceeded,errorType:oc.SubmitFailed});return yield this._detachmentObserver.ensurePresence([this._iframe],n)}catch(e){if(this._isSubmitErrorEvent(e)){if("hosted_form_error"===e.payload.error.code)throw new gc(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 fc(this,void 0,void 0,function*(){const n=this._eventPoster.post({type:rc.StoredCardRequested,payload:{fields:e,data:t}},{successType:oc.StoredCardSucceeded,errorType:oc.StoredCardFailed});return this._detachmentObserver.ensurePresence([this._iframe],n)})}validateForm(){return fc(this,void 0,void 0,function*(){const e=this._eventPoster.post({type:rc.ValidateRequested},{successType:oc.Validated}),{payload:t}=yield this._detachmentObserver.ensurePresence([this._iframe],e);if(!t.isValid)throw new yc(t.errors)})}_getFontUrls(){const e="fonts.googleapis.com",t=document.querySelectorAll(`link[href*='${e}'][rel='stylesheet']`);return Array.prototype.slice.call(t).filter(t=>Qd(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===oc.SubmitFailed}}var Sc=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Cc{constructor(e,t,n,i,r){this._fields=e,this._eventListener=t,this._payloadTransformer=n,this._eventCallbacks=i,this._paymentHumanVerificationHandler=r,this._handleEnter=({payload:e})=>Sc(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:o=T,onCardTypeChange:a=T,onFocus:s=T,onValidate:d=T}=this._eventCallbacks;this._eventListener.addListener(oc.Blurred,({payload:e})=>o(e)),this._eventListener.addListener(oc.CardTypeChanged,({payload:e})=>a(e)),this._eventListener.addListener(oc.Focused,({payload:e})=>s(e)),this._eventListener.addListener(oc.Validated,({payload:e})=>d(e)),this._eventListener.addListener(oc.Entered,this._handleEnter),this._eventListener.addListener(oc.CardTypeChanged,({payload:e})=>this._cardType=e.cardType),this._eventListener.addListener(oc.BinChanged,({payload:e})=>this._bin=e.bin)}getBin(){return this._bin}getCardType(){return this._cardType}attach(){return Sc(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 Sc(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 n=yield this._paymentHumanVerificationHandler.handle(t);return yield this._getFirstField().submitForm(this._fields.map(e=>e.getType()),this._payloadTransformer.transform(e,n))}})}submitStoredCard(e){return Sc(this,void 0,void 0,function*(){return this._getFirstField().submitStoredCardForm(e.fields,e.data)})}validate(){return Sc(this,void 0,void 0,function*(){return this._getFirstField().validateForm()})}_getFirstField(){const e=this._fields[0];if(!e)throw new mc("Unable to proceed because the payment form has no field defined.");return e}}function Ic(e){return Boolean(e.instrumentId)}class _c{constructor(e){this._store=e}transform(e,t){const n=this._store.getState(),i=n.checkout.getCheckout(),r=n.config.getConfig(),o=n.instruments.getInstrumentsMeta(),a=n.order.getOrder(),s=n.order.getOrderMeta(),d=k(e.paymentData,"ccExpiry","ccName","ccNumber","ccCvv"),c=n.paymentMethods.getPaymentMethod(e.methodId,e.gatewayId),u=n.paymentMethods.getPaymentMethodsMeta(),l=o&&d&&Ic(d)?`${n.payment.getPaymentToken()}, ${o.vaultAccessToken}`:n.payment.getPaymentToken();if(!l)throw new qi(xi.MissingPaymentToken);return{additionalAction:t,authToken:l,checkout:i,config:r,order:a,orderMeta:s,payment:d,paymentMethod:c,paymentMethodMeta:u}}}class wc{constructor(e){this._store=e}create(e,t,n){const i=Object.keys(t.fields).reduce((i,r)=>{const o=t.fields[r];return o?[...i,new vc(r,o.containerId,o.placeholder||"",o.accessibilityLabel||"",t.styles||{},new Jd(e),new Xd(e),new Wd(new $d),n,"instrumentId"in o?this._getCardInstrument(o.instrumentId):void 0)]:i},[]);return new Cc(i,new Xd(e),new _c(this._store),R(t,"onBlur","onEnter","onFocus","onCardTypeChange","onValidate"),new sc(pc(ue())))}_getCardInstrument(e){const{instruments:{getCardInstrument:t}}=this._store.getState(),n=t(e);if(!n)throw new qi(xi.MissingPaymentInstrument);return n}}class bc extends be{constructor(){super("You haven't complete our spam check. Please try again."),this.name="SpamProtectionNotCompletedError",this.type="spam_protection_not_completed"}}class Ec{constructor(e,t){this._orderRequestSender=e,this._checkoutValidator=t}loadOrder(e,t){return new j(n=>{n.next(o(Ct.LoadOrderRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{n.next(o(Ct.LoadOrderSucceeded,e.body)),n.complete()}).catch(e=>{n.error(s(Ct.LoadOrderFailed,e))})})}loadOrderPayments(e,t){return new j(n=>{n.next(o(Ct.LoadOrderPaymentsRequested)),this._orderRequestSender.loadOrder(e,t).then(e=>{n.next(o(Ct.LoadOrderPaymentsSucceeded,e.body)),n.complete()}).catch(e=>{n.error(s(Ct.LoadOrderPaymentsFailed,e))})})}loadCurrentOrder(e){return t=>V(()=>{const n=this._getCurrentOrderId(t.getState());if(!n)throw new qi(xi.MissingOrderId);return this.loadOrder(n,e)})}submitOrder(e,t){return n=>H(Q(o(Ct.SubmitOrderRequested)),V(()=>{const i=n.getState(),r=i.config.getExternalSource(),a=i.config.getVariantIdentificationToken(),s=i.checkout.getCheckout();if(!s)throw new qi(xi.MissingCheckout);if(s.shouldExecuteSpamCheck)throw new bc;return W(this._checkoutValidator.validate(s,t).then(()=>this._orderRequestSender.submitOrder(this._mapToOrderRequestBody(null!=e?e:{},s.id,s.customerMessage,r),Object.assign(Object.assign({},t),{headers:{checkoutVariant:a}})))).pipe(re(e=>H(this.loadOrder(e.body.data.order.orderId,t),Q(o(Ct.SubmitOrderSucceeded,e.body.data,Object.assign(Object.assign({},e.body.meta),{token:e.headers.token}))))))}).pipe(J(e=>Cd(Ct.SubmitOrderFailed,e))))}finalizeOrder(e,t){return H(Q(o(Ct.FinalizeOrderRequested)),W(this._orderRequestSender.finalizeOrder(e,t)).pipe(re(n=>H(this.loadOrder(e,t),Q(o(Ct.FinalizeOrderSucceeded,n.body.data)))))).pipe(J(e=>Cd(Ct.FinalizeOrderFailed,e)))}_getCurrentOrderId(e){const t=e.order.getOrder(),n=e.checkout.getCheckout();return t&&t.orderId||n&&n.orderId}_mapToOrderRequestBody(e,t,n,i){const{payment:r}=e,o=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);return r?Object.assign(Object.assign({},o),{cartId:t,customerMessage:n,externalSource:i,payment:{paymentData:r.paymentData,name:r.methodId,gateway:r.gatewayId}}):Object.assign(Object.assign({},o),{cartId:t,customerMessage:n,externalSource:i})}}class Pc 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 Oc extends be{constructor(e){super(e||"The tax provider is unavailable."),this.name="OrderTaxProviderUnavailableError",this.type="tax_provider_unavailable"}}class Ac extends be{constructor(e){super(e),this.name="MissingShippingMethodError",this.type="missing_shipping_method"}}class Tc extends be{constructor(e){super(e),this.name="InvalidShippingAddressError",this.type="invalid_shipping_address"}}class kc{constructor(e){this._requestSender=e}loadOrder(e,{timeout:t}={}){const n=`/api/storefront/orders/${e}`,i=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.get(n,{params:{include:Ad(["payments","lineItems.physicalItems.socialMedia","lineItems.physicalItems.options","lineItems.physicalItems.categories","lineItems.digitalItems.socialMedia","lineItems.digitalItems.options","lineItems.digitalItems.categories"])},headers:i,timeout:t})}submitOrder(e,{headers:t,timeout:n}={}){return this._requestSender.post("/internalapi/v1/checkout/order",{body:e,headers:D(Object.assign({"X-Checkout-Variant":t&&t.checkoutVariant},vd),C),timeout:n}).catch(e=>{if("tax_provider_unavailable"===e.body.type)throw new Oc;if("cart_has_changed"===e.body.type)throw new Pc;if("missing_shipping_method"===e.body.type)throw new Ac(e.body.detail);if("invalid_shipping_address"===e.body.type)throw new Tc(e.body.detail);if("empty_cart"===e.body.type)throw new wd;throw e})}finalizeOrder(e,{timeout:t}={}){const n=`/internalapi/v1/checkout/order/${e}`;return this._requestSender.post(n,{timeout:t,headers:vd})}}class Dc{constructor(e,t,n,i){this._paymentRequestSender=e,this._orderActionCreator=t,this._paymentRequestTransformer=n,this._paymentHumanVerificationHandler=i,this.initializeOffsitePayment=({methodId:e,gatewayId:t,instrumentId:n,target:i,promise:r,shouldSaveInstrument:a,shouldSetAsDefaultInstrument:s})=>d=>{let c;n?c={formattedPayload:{bigpay_token:n}}: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(Q(o(fn.InitializeOffsitePaymentRequested)),Promise.race([this._paymentRequestSender.initializeOffsitePayment(u,i),r].filter(Boolean)).then(()=>o(fn.InitializeOffsitePaymentSucceeded))).pipe(J(e=>Cd(fn.InitializeOffsitePaymentFailed,e)))}}submitPayment(e){return t=>H(Q(o(fn.SubmitPaymentRequested)),V(()=>{return n=this,i=void 0,o=function*(){try{return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(e,t.getState()))}catch(n){const i=yield this._paymentHumanVerificationHandler.handle(n);return yield this._paymentRequestSender.submitPayment(this._paymentRequestTransformer.transform(Object.assign(Object.assign({},e),{additionalAction:i}),t.getState()))}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}).pipe(re(({body:e})=>H(this._orderActionCreator.loadCurrentOrder()(t),Q(o(fn.SubmitPaymentSucceeded,e)))))).pipe(J(e=>Cd(fn.SubmitPaymentFailed,e)))}}class Rc{constructor(e){this._client=e}submitPayment(e){return new Promise((t,n)=>{this._client.submitPayment(e,(e,i)=>{e?n(this._transformResponse(e)):t(this._transformResponse(i))})})}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 Mc(e,t){let n;return function(e){return void 0!==e.id}(e)?n=e.id:t&&t.length&&(n=t[0].id),{id:n,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}}class Nc{constructor(e){this._decimalPlaces=e}toInteger(e){return Math.round(e*Math.pow(10,this._decimalPlaces))}}const Lc=["per_item_discount","percentage_discount","per_total_discount","shipping_discount","free_shipping"];function zc(e){return{code:e.code,discount:e.displayName,discountType:Lc.indexOf(e.couponType)}}function Uc(e){return{code:e.code,discountedAmount:e.used,remainingBalance:e.remaining,giftCertificate:{balance:e.balance,code:e.code,purchaseDate:e.purchaseDate}}}function Fc(e){const t=[];return(e||[]).forEach(e=>{(e.banners||[]).forEach(e=>{t.push({placeholders:[],discountType:null,message:"",messageHtml:e.text})})}),t}function Bc(e,t,n="id"){return Object.keys(e).reduce((i,r)=>[...i,...e[r].map(e=>"giftCertificates"===r?function(e,t){const n=new Nc(t);return{id:e.id,imageUrl:"",name:e.name,amount:e.amount,amountAfterDiscount:e.amount,discount:0,integerAmount:n.toInteger(e.amount),integerAmountAfterDiscount:n.toInteger(e.amount),integerUnitPrice:n.toInteger(e.amount),integerUnitPriceAfterDiscount:n.toInteger(e.amount),integerDiscount:0,quantity:1,sender:e.sender,recipient:e.recipient,type:"ItemGiftCertificateEntity",attributes:[],variantId:null}}(e,t):function(e,t,n,i="id"){const r=new Nc(n);return{id:e[i],imageUrl:e.imageUrl,amount:e.extendedListPrice,amountAfterDiscount:e.extendedSalePrice,discount:e.discountAmount,integerAmount:r.toInteger(e.extendedListPrice),integerAmountAfterDiscount:r.toInteger(e.extendedSalePrice),integerDiscount:r.toInteger(e.discountAmount),integerUnitPrice:r.toInteger(e.listPrice),integerUnitPriceAfterDiscount:r.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""}}(r),t,n))],[])}function xc(e){const t=e.cart.currency.decimalPlaces,n=new Nc(t);return{id:e.cart.id,items:Bc(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(zc)},discount:{amount:e.cart.discountAmount,integerAmount:n.toInteger(e.cart.discountAmount)},discountNotifications:Fc(e.promotions),giftCertificate:{totalDiscountedAmount:N(e.giftCertificates,(e,t)=>e+t.used,0),appliedGiftCertificates:w(e.giftCertificates.map(Uc),"code")},shipping:{amount:e.shippingCostTotal,integerAmount:n.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:n.toInteger(e.shippingCostBeforeDiscount),required:z(e.cart.lineItems.physicalItems,e=>e.isShippingRequired)},subtotal:{amount:e.subtotal,integerAmount:n.toInteger(e.subtotal)},storeCredit:{amount:e.customer?e.customer.storeCredit:0},taxSubtotal:{amount:e.taxTotal,integerAmount:n.toInteger(e.taxTotal)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:n.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:n.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.grandTotal,integerAmount:n.toInteger(e.grandTotal)}}}var qc;!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.MASTERPASS="masterpass",e.PAYPALEXPRESS="paypalexpress"}(qc||(qc={}));const jc=qc;function Gc(e,t){const n=e.firstName||t.firstName||"",i=e.lastName||t.lastName||"";return{addresses:(e.addresses||[]).map(e=>Mc(e)),customerId:e.id,isGuest:e.isGuest,storeCredit:e.storeCredit,email:e.email||t.email||"",firstName:n,lastName:i,name:e.fullName||[n,i].join(" "),customerGroupName:e.customerGroup&&e.customerGroup.name}}class Hc{format(e){const[t="",n=""]=e.split(new RegExp("\\s*/\\s*")),i=t.slice(0,2),r=4===n.length?n.slice(-2):n?n.slice(0,2):t.slice(2);return e.length<2?t:e.length>3&&!r?i:`${i} / ${r}`}toObject(e){const[t="",n=""]=e.split(new RegExp("\\s*/\\s*"));return/^\d+$/.test(t)&&/^\d+$/.test(n)?{month:1===t.length?`0${t}`:t.slice(0,2),year:2===n.length?`20${n}`:n.slice(0,4)}:{month:"",year:""}}}class Vc{format(e){const{card:t}=ye(e);if(!t)return e;const n=O(ge(e).map(e=>O(e.lengths))),i=this.unformat(e).slice(0,n);return t.gaps.filter(e=>i.length>e).reduce((e,t,n)=>[e.slice(0,t+n),e.slice(t+n)].join(" "),i)}unformat(e){const{card:t}=ye(e);return t?e.replace(new RegExp(" ","g"),""):e}}function Yc(e,t={}){const n=e.currency.decimalPlaces,i=new Nc(n);return{id:e.orderId,items:Bc(e.lineItems,e.currency.decimalPlaces,"productId"),orderId:e.orderId,currency:e.currency.code,customerCanBeCreated:e.customerCanBeCreated,payment:Kc(e.payments,t.payment),subtotal:{amount:e.baseAmount,integerAmount:i.toInteger(e.baseAmount)},coupon:{discountedAmount:N(e.coupons,(e,t)=>e+t.discountedAmount,0),coupons:e.coupons.map(zc)},discount:{amount:e.discountAmount,integerAmount:i.toInteger(e.discountAmount)},token:t.orderToken,callbackUrl:t.callbackUrl,discountNotifications:[],giftCertificate:$c(e.payments),socialData:Zc(e),status:e.status,hasDigitalItems:e.hasDigitalItems,isDownloadable:e.isDownloadable,isComplete:e.isComplete,shipping:{amount:e.shippingCostTotal,integerAmount:i.toInteger(e.shippingCostTotal),amountBeforeDiscount:e.shippingCostBeforeDiscount,integerAmountBeforeDiscount:i.toInteger(e.shippingCostBeforeDiscount)},storeCredit:{amount:Wc(e.payments)},taxes:e.taxes,taxTotal:{amount:e.taxTotal,integerAmount:i.toInteger(e.taxTotal)},handling:{amount:e.handlingCostTotal,integerAmount:i.toInteger(e.handlingCostTotal)},grandTotal:{amount:e.orderAmount,integerAmount:e.orderAmountAsInteger}}}function Wc(e){const t=l(e,{providerId:"storecredit"});return t?t.amount:0}function $c(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 Kc(e,t={}){const n=l(e,Qc);return n?{id:n.providerId,status:(i=n.detail.step,`PAYMENT_STATUS_${i}`),helpText:n.detail.instructions,returnUrl:t.returnUrl}:{};var i}function Qc(e){return"giftcertificate"!==e.providerId&&"storecredit"!==e.providerId}function Zc(e){const t={};return[...e.lineItems.physicalItems,...e.lineItems.digitalItems].forEach(e=>{var n;t[e.id]=(n=e,["fb","tw","gp"].reduce((e,t)=>{const i=n.socialMedia&&l(n.socialMedia,e=>e.code===t);return i?(e[t]={name:n.name,description:n.name,image:n.imageUrl,url:i.link,shareText:i.text,sharingLink:i.link,channelName:i.channel,channelCode:i.code},e):e},{}))}),t}function Jc(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 Xc{constructor(){this._cardExpiryFormatter=new Hc,this._cardNumberFormatter=new Vc}transform(e,t){const n=t.billingAddress.getBillingAddress(),i=t.checkout.getCheckout(),r=t.customer.getCustomer(),o=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=r&&n&&Gc(r,n),y=h&&e.paymentData&&(Ic(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 qi(xi.MissingPaymentToken);return{additionalAction:e.additionalAction,authToken:y,customer:g,billingAddress:n&&Mc(n),shippingAddress:s&&Mc(s,d),shippingOption:c&&Jc(c,!0),cart:i&&xc(i),order:o&&Yc(o,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:R(u&&u.storeProfile,["storeHash","storeId","storeLanguage","storeName"])}}transformWithHostedFormData(e,t,n){const{additionalAction:i,authToken:r,checkout:o,config:a,order:s,orderMeta:d,payment:c={},paymentMethod:u,paymentMethodMeta:l}=t,h=o&&o.consignments[0],p=h&&h.shippingAddress,m=h&&h.selectedShippingOption;return{additionalAction:i,authToken:r,paymentMethod:u&&this._transformPaymentMethod(u),customer:s&&s.billingAddress&&o&&Gc(o.customer,s.billingAddress),billingAddress:s&&s.billingAddress&&Mc(s.billingAddress),shippingAddress:p&&o&&Mc(p,o.consignments),shippingOption:m&&Jc(m,!0),cart:o&&xc(o),order:s&&Yc(s,d),orderMeta:d,payment:this._transformHostedInputValues(e,c,n),quoteMeta:{request:Object.assign(Object.assign({},l),{geoCountryCode:a&&a.context.geoCountryCode})},source:"bigcommerce-checkout-js-sdk",store:a&&R(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===jc.BRAINTREE_VENMO?Object.assign(Object.assign({},e),{id:jc.BRAINTREE_PAYPAL}):e:Object.assign(Object.assign({},e),{gateway:e.id})}_transformHostedInputValues(e,t,n){return"instrumentId"in t?Object.assign(Object.assign({},t),{ccCvv:e.cardCodeVerification,ccNumber:e.cardNumberVerification&&this._cardNumberFormatter.unformat(e.cardNumberVerification),hostedFormNonce:n}):Object.assign(Object.assign({},t),{ccCvv:e.cardCode,ccExpiry:this._cardExpiryFormatter.toObject(e.cardExpiry||""),ccName:e.cardName||"",ccNumber:this._cardNumberFormatter.unformat(e.cardNumber||""),hostedFormNonce:n})}_mapShippingAddress(e,t){var n,i,r,o;if(t){const a=null===(i=null===(n=t.initializationData)||void 0===n?void 0:n.bopis)||void 0===i?void 0:i.enabled,s=null===(o=null===(r=t.initializationData)||void 0===r?void 0:r.bopis)||void 0===o?void 0:o.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 eu{updatePaymentProviderCustomer(e){return Q(o(Mn.UpdatePaymentProviderCustomer,e))}}class tu{widgetInteraction(e,t){const n={methodId:t&&t.methodId};return H(Q(o(On.WidgetInteractionStarted,void 0,n)),V(()=>e().then(()=>o(On.WidgetInteractionFinished,void 0,n)))).pipe(J(e=>Cd(On.WidgetInteractionFailed,e,n)))}}class nu{constructor(e,t){this._remoteCheckoutRequestSender=e,this._checkoutActionCreator=t}initializeBilling(e,t,n){return j.create(i=>{i.next(o(Hn.InitializeRemoteBillingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeBilling(e,t,n).then(({body:t={}})=>{i.next(o(Hn.InitializeRemoteBillingSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Hn.InitializeRemoteBillingFailed,t,{methodId:e}))})})}initializeShipping(e,t,n){return j.create(i=>{i.next(o(Hn.InitializeRemoteShippingRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializeShipping(e,t,n).then(({body:t={}})=>{i.next(o(Hn.InitializeRemoteShippingSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Hn.InitializeRemoteShippingFailed,t,{methodId:e}))})})}initializePayment(e,t,n){return j.create(i=>{i.next(o(Hn.InitializeRemotePaymentRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.initializePayment(e,t,n).then(({body:t={}})=>{i.next(o(Hn.InitializeRemotePaymentSucceeded,t,{methodId:e})),i.complete()}).catch(t=>{i.error(s(Hn.InitializeRemotePaymentFailed,t,{methodId:e}))})})}loadSettings(e,t){return j.create(n=>{n.next(o(Hn.LoadRemoteSettingsRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.loadSettings(e,t).then(({body:t})=>{n.next(o(Hn.LoadRemoteSettingsSucceeded,t,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Hn.LoadRemoteSettingsFailed,t,{methodId:e}))})})}signOut(e,t){return j.create(n=>{n.next(o(Hn.SignOutRemoteCustomerRequested,void 0,{methodId:e})),this._remoteCheckoutRequestSender.signOut(e,t).then(()=>{n.next(o(Hn.SignOutRemoteCustomerSucceeded,void 0,{methodId:e})),n.complete()}).catch(t=>{n.error(s(Hn.SignOutRemoteCustomerFailed,t,{methodId:e}))})})}forgetCheckout(e,t){return H(Q(o(Hn.ForgetCheckoutRemoteCustomerRequested,void 0,{methodId:e})),V(()=>{return n=this,i=void 0,a=function*(){return yield this._remoteCheckoutRequestSender.forgetCheckout(t),yield this._checkoutActionCreator.loadCurrentCheckout(),o(Hn.ForgetCheckoutRemoteCustomerSucceeded,void 0,{methodId:e})},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(t=>Cd(Hn.ForgetCheckoutRemoteCustomerFailed,t,{methodId:e})))}updateCheckout(e,t){return o(Hn.UpdateRemoteCheckout,t,{methodId:e})}}class iu{constructor(e){this._requestSender=e}initializeBilling(e,t,{timeout:n}={}){const i=`/remote-checkout/${e}/billing`;return this._requestSender.get(i,{params:t,timeout:n,headers:vd})}initializeShipping(e,t,{timeout:n}={}){const i=`/remote-checkout/${e}/shipping`;return this._requestSender.get(i,{params:t,timeout:n,headers:vd})}initializePayment(e,t,{timeout:n}={}){const i=`/remote-checkout/${e}/payment`;return this._requestSender.get(i,{params:t,timeout:n,headers:vd})}loadSettings(e,{timeout:t}={}){const n=`/remote-checkout/${e}/settings`;return this._requestSender.get(n,{timeout:t,headers:vd})}signOut(e,{timeout:t}={}){const n=`/remote-checkout/${e}/signout`;return this._requestSender.get(n,{timeout:t,headers:vd})}generateToken({timeout:e}={}){return this._requestSender.get("/remote-checkout-token",{timeout:e,headers:vd})}trackAuthorizationEvent({timeout:e}={}){return this._requestSender.post("/remote-checkout/events/shopper-checkout-service-provider-authorization-requested",{timeout:e,headers:vd})}forgetCheckout({timeout:e}={}){return this._requestSender.post("/remote-checkout/forget-checkout",{timeout:e,headers:vd})}}class ru{constructor(e,t){this._consignmentRequestSender=e,this._checkoutRequestSender=t}unassignItemsByAddress(e,t){return n=>{const i=n.getState();if(!i.checkout.getCheckout())throw new qi(xi.MissingCheckout);const r=this._consignmentHasAddress(e)?e.address:e.shippingAddress,o=i.consignments.getConsignmentByAddress(r);if(!o)throw new Kd("No consignment found for the specified address");const a=this._removeLineItems(e.lineItems,o,i.cart.getCart());return a.length?this.updateConsignment({id:o.id,address:r,lineItems:a},t)(n):this.deleteConsignment(o.id,t)(n)}}assignItemsByAddress(e,t){return n=>{const i=n.getState(),r=this._consignmentHasAddress(e)?e.address:e.shippingAddress,o=i.consignments.getConsignmentByAddress(r);return this._createOrUpdateConsignment({id:o&&o.id,address:r,lineItems:this._addLineItems(e.lineItems,o,i.cart.getCart())},t)(n)}}selectShippingOption(e,t){return n=>j.create(i=>{const r=n.getState(),a=r.checkout.getCheckout(),d=r.consignments.getConsignments();if(!a)throw new qi(xi.MissingCheckout);if(!d||!d.length)throw new qi(xi.MissingConsignments);const c={id:d[0].id,shippingOptionId:e},u={id:d[0].id};i.next(o(Xe.UpdateShippingOptionRequested,void 0,u)),this._consignmentRequestSender.updateConsignment(a.id,c,t).then(({body:e})=>{i.next(o(Xe.UpdateShippingOptionSucceeded,e,u)),i.complete()}).catch(e=>{i.error(s(Xe.UpdateShippingOptionFailed,e,u))})})}loadShippingOptions(e){return t=>j.create(n=>{const i=t.getState().checkout.getCheckout();if(!i)throw new qi(xi.MissingCheckout);n.next(o(Xe.LoadShippingOptionsRequested)),this._checkoutRequestSender.loadCheckout(i.id,Object.assign(Object.assign({},e),{params:{include:[zd.AvailableShippingOptions]}})).then(({body:e})=>{n.next(o(Xe.LoadShippingOptionsSucceeded,e)),n.complete()}).catch(e=>{n.error(s(Xe.LoadShippingOptionsFailed,e))})})}updateAddress(e,t){return n=>{const i=this._getUpdateAddressRequestBody(e,n),r=n.getState().consignments.getConsignments();return r&&r.length&&(i.id=r[0].id),this._createOrUpdateConsignment(i,t)(n)}}createConsignments(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r||!r.id)throw new qi(xi.MissingCheckout);i.next(o(Xe.CreateConsignmentsRequested)),this._consignmentRequestSender.createConsignments(r.id,e,t).then(({body:e})=>{i.next(o(Xe.CreateConsignmentsSucceeded,e)),i.complete()}).catch(e=>{i.error(s(Xe.CreateConsignmentsFailed,e))})})}updateConsignment(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout();if(!r||!r.id)throw new qi(xi.MissingCheckout);const a={id:e.id};i.next(o(Xe.UpdateConsignmentRequested,void 0,a)),this._consignmentRequestSender.updateConsignment(r.id,e,t).then(({body:e})=>{i.next(o(Xe.UpdateConsignmentSucceeded,e,a)),i.complete()}).catch(e=>{i.error(s(Xe.UpdateConsignmentFailed,e,a))})})}deleteConsignment(e,t){return n=>j.create(i=>{const r=n.getState().checkout.getCheckout(),a={id:e};if(!r||!r.id)throw new qi(xi.MissingCheckout);i.next(o(Xe.DeleteConsignmentRequested,void 0,a)),this._consignmentRequestSender.deleteConsignment(r.id,e,t).then(({body:e})=>{i.next(o(Xe.DeleteConsignmentSucceeded,e,a)),i.complete()}).catch(e=>{i.error(s(Xe.DeleteConsignmentFailed,e,a))})})}updateShippingOption(e,t){return n=>j.create(i=>{var r;const a=n.getState().checkout.getCheckout(),d=n.getState().consignments.getConsignmentById(e.id);if((null===(r=null==d?void 0:d.selectedShippingOption)||void 0===r?void 0:r.id)===e.shippingOptionId)return void i.complete();if(!a||!a.id)throw new qi(xi.MissingCheckout);const c={id:e.id};i.next(o(Xe.UpdateShippingOptionRequested,void 0,c)),this._consignmentRequestSender.updateConsignment(a.id,e,t).then(({body:e})=>{i.next(o(Xe.UpdateShippingOptionSucceeded,e,c)),i.complete()}).catch(e=>{i.error(s(Xe.UpdateShippingOptionFailed,e,c))})})}_createOrUpdateConsignment(e,t){return n=>{const i=n.getState().checkout.getCheckout();if(!i||!i.id)throw new qi(xi.MissingCheckout);return this._isUpdateConsignmentRequest(e)?this.updateConsignment(e,t)(n):this.createConsignments([e],t)(n)}}_getUpdateAddressRequestBody(e,t){const n=t.getState().cart.getCart();if(!n)throw new qi(xi.MissingCart);const{physicalItems:i,customItems:r=[]}=n.lineItems;return{address:e,lineItems:[...i,...r].map(e=>({itemId:e.id,quantity:e.quantity}))}}_removeLineItems(e,t,n){if(!n)throw new qi(xi.MissingCart);return this._hydrateLineItems(t.lineItemIds,n).map(t=>{const n=l(e,e=>e.itemId===t.itemId);return Object.assign(Object.assign({},t),{quantity:n?t.quantity-n.quantity:t.quantity})}).filter(e=>e.quantity>0)}_addLineItems(e,t,n){if(!t)return e;if(!n)throw new qi(xi.MissingCart);return e.concat(this._hydrateLineItems(t.lineItemIds,n)).filter(e=>e.quantity>0)}_hydrateLineItems(e,t){return e.map(e=>{const n=l(t.lineItems.physicalItems,t=>t.id===e);return{itemId:e,quantity:n?n.quantity:0}})}_isUpdateConsignmentRequest(e){return!!e.id}_consignmentHasAddress(e){return"object"==typeof e&&"address"in e}}const ou=["consignments.availableShippingOptions","cart.lineItems.physicalItems.options","cart.lineItems.digitalItems.options","customer","promotions.banners"];class au{constructor(e){this._requestSender=e}createConsignments(e,t,{timeout:n,params:{include:i}={}}={}){const r=`/api/storefront/checkouts/${e}/consignments`,o=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(r,{body:t,params:{include:Td(ou,i)},headers:o,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}updateConsignment(e,t,{timeout:n,params:{include:i}={}}={}){const{id:r}=t,o=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(t,["id"]),a=`/api/storefront/checkouts/${e}/consignments/${r}`,s=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.put(a,{body:o,params:{include:Td(ou,i)},headers:s,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}deleteConsignment(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/consignments/${t}`,r=Object.assign({Accept:yd.JsonV1},vd),o=Ad(ou);return this._requestSender.delete(i,{params:{include:o},headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}class su{constructor(e,t){this._shippingCountryRequestSender=e,this._store=t}loadCountries(e){const{checkout:t}=this._store.getState(),n=t.getCheckout(),i=n?n.channelId:null;return j.create(t=>{t.next(o(si.LoadShippingCountriesRequested)),this._shippingCountryRequestSender.loadCountries(i,e).then(e=>{t.next(o(si.LoadShippingCountriesSucceeded,e.body.data)),t.complete()}).catch(e=>{t.error(s(si.LoadShippingCountriesFailed,e))})})}}class du{constructor(e,t){this._requestSender=e,this._config=t}loadCountries(e,{timeout:t}={}){const n="/internalapi/v1/shipping/countries"+(e?`?channel_id=${e}`:""),i=Object.assign({"Accept-Language":this._config.locale},vd);return this._requestSender.get(n,{headers:i,timeout:t})}}var cu=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class uu{constructor(e,t){this._googleRecaptcha=e,this._requestSender=t}initialize(e){return t=>H(Q(o(Ni.InitializeRequested,void 0)),V(()=>cu(this,void 0,void 0,function*(){const n=e?e.containerId:"spamProtectionContainer";if(document.getElementById(n)&&this._googleRecaptcha.reset(n),!e&&!document.getElementById(n)){const e=document.createElement("div");e.setAttribute("id",n),document.body.appendChild(e)}const i=t.getState().config.getStoreConfigOrThrow().checkoutSettings.googleRecaptchaSitekey;return yield this._googleRecaptcha.load(n,i),o(Ni.InitializeSucceeded)}))).pipe(J(e=>Cd(Ni.InitializeFailed,e)))}verifyCheckoutSpamProtection(){return e=>V(()=>{const t=e.getState().checkout.getCheckout();if(!t)throw new qi(xi.MissingCheckout);return H(Q(o(Ni.VerifyCheckoutRequested)),W(this.execute()(e)).pipe(re(e=>qd(e)&&e.payload?W(this._requestSender.validate(t.id,e.payload.token)).pipe(re(({body:t})=>H(Q(e),Q(o(Ni.VerifyCheckoutSucceeded,t))))):Q(e)))).pipe(J(e=>Cd(Ni.VerifyCheckoutFailed,e)))})}execute(){return e=>H(Q(o(Ni.ExecuteRequested)),this.initialize()(e),this._googleRecaptcha.execute().pipe(oe(1)).pipe(re(({error:e,token:t})=>cu(this,void 0,void 0,function*(){if(e instanceof ec)throw e;if(e||!t)throw new cc;return o(Ni.ExecuteSucceeded,{token:t})})))).pipe(J(e=>Cd(Ni.ExecuteFailed,e)))}}class lu{constructor(e){this._requestSender=e}validate(e,t,{timeout:n}={}){const i=`/api/storefront/checkouts/${e}/spam-protection`,r=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(i,{body:{token:t},headers:r,timeout:n}).catch(e=>{if("empty_cart"===e.body.type)throw new wd;throw e})}}class hu{constructor(e){this._storeCreditRequestSender=e}applyStoreCredit(e,t){return n=>H(Q(o(Ei.ApplyStoreCreditRequested)),V(()=>{return i=this,r=void 0,s=function*(){const i=n.getState().checkout.getCheckout();if(!i)throw new qi(xi.MissingCheckout);const{body:r}=yield e?this._storeCreditRequestSender.applyStoreCredit(i.id,t):this._storeCreditRequestSender.removeStoreCredit(i.id,t);return o(Ei.ApplyStoreCreditSucceeded,r)},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{d(s.next(e))}catch(e){t(e)}}function o(e){try{d(s.throw(e))}catch(e){t(e)}}function d(t){var i;t.done?e(t.value):(i=t.value,i instanceof a?i:new a(function(e){e(i)})).then(n,o)}d((s=s.apply(i,r||[])).next())});var i,r,a,s})).pipe(J(e=>Cd(Ei.ApplyStoreCreditFailed,e)))}}class pu{constructor(e){this._requestSender=e}applyStoreCredit(e,{timeout:t}={}){const n=`/api/storefront/checkouts/${e}/store-credit`,i=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post(n,{headers:i,timeout:t,params:{include:Ad(kd)}})}removeStoreCredit(e,{timeout:t}={}){const n=`/api/storefront/checkouts/${e}/store-credit`,i=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.delete(n,{headers:i,timeout:t,params:{include:Ad(kd)}})}}class mu extends Pe{constructor(e){super(e),this.name="UpdateSubscriptionsError",this.type="update_subscriptions"}}class gu{constructor(e){this._subscriptionsRequestSender=e}updateSubscriptions(e,t){return H(Q(o(ze.UpdateSubscriptionsRequested)),V(()=>{return n=this,i=void 0,a=function*(){const{body:n}=yield this._subscriptionsRequestSender.updateSubscriptions(e,t);return o(ze.UpdateSubscriptionsSucceeded,n)},new((r=void 0)||(r=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(o,s)}d((a=a.apply(n,i||[])).next())});var n,i,r,a})).pipe(J(e=>Cd(ze.UpdateSubscriptionsFailed,new mu(e))))}}class yu{constructor(e){this._requestSender=e}updateSubscriptions(e,{timeout:t}={}){const n=Object.assign({Accept:yd.JsonV1},vd);return this._requestSender.post("/api/storefront/subscriptions",{body:e,headers:n,timeout:t})}}const fu=A(e=>Array.isArray(e)?e.map(e=>vu(e)):$e(e)?Object.keys(e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:vu(e[n])}),{}):e);fu.cache=new WeakMap;const vu=e=>"object"==typeof e&&null!==e?fu(e):e;function Su(e){return(...t)=>vu(e(...t))}function Cu({billingAddress:{getBillingAddress:e,getBillingAddressOrThrow:t},cart:{getCart:n,getCartOrThrow:i},checkout:{getCheckout:r,getCheckoutOrThrow:o,getOutstandingBalance:a},config:{getContextConfig:s,getHost:d,getLocale:c,getStoreConfig:u,getStoreConfigOrThrow:l,getConfig:h},consignments:{getConsignments:p,getConsignmentsOrThrow:m},countries:{getCountries:g},customer:{getCustomer:y,getCustomerOrThrow:f},instruments:{getCardInstrument:v,getCardInstrumentOrThrow:S,getInstruments:C,getInstrumentsMeta:I},order:{getOrder:_,getOrderOrThrow:w,getOrderMeta:b},payment:{getPaymentToken:E,getPaymentTokenOrThrow:P,getPaymentId:O,getPaymentIdOrThrow:A,getPaymentStatus:T,getPaymentStatusOrThrow:k,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:R,isPaymentDataRequired:M},paymentMethods:{getPaymentMethod:N,getPaymentMethodOrThrow:L,getPaymentMethodsMeta:z},paymentProviderCustomer:{getPaymentProviderCustomer:U,getPaymentProviderCustomerOrThrow:F},paymentStrategies:{isInitialized:B},shippingAddress:{getShippingAddress:x,getShippingAddressOrThrow:q,getShippingAddresses:j,getShippingAddressesOrThrow:G},shippingCountries:{getShippingCountries:H}}){return{getHost:Su(d),getLocale:Su(c),getBillingAddress:Su(e),getBillingAddressOrThrow:Su(t),getCart:Su(n),getCartOrThrow:Su(i),getCheckout:Su(r),getCheckoutOrThrow:Su(o),getCountries:Su(g),getStoreConfig:Su(u),getStoreConfigOrThrow:Su(l),getConfig:Su(h),getConsignments:Su(p),getConsignmentsOrThrow:Su(m),getContextConfig:Su(s),getCustomer:Su(y),getCustomerOrThrow:Su(f),getCardInstrument:Su(v),getInstruments:Su(C),getCardInstrumentOrThrow:Su(S),getOrder:Su(_),getOrderOrThrow:Su(w),getOrderMeta:Su(b),getInstrumentsMeta:Su(I),getPaymentToken:E,getPaymentTokenOrThrow:P,getPaymentId:O,getPaymentIdOrThrow:A,getPaymentStatus:T,getPaymentStatusOrThrow:k,getPaymentRedirectUrl:D,getPaymentRedirectUrlOrThrow:R,getPaymentMethod:Su(N),getPaymentMethodOrThrow:Su(L),getPaymentMethodsMeta:Su(z),getPaymentProviderCustomer:Su(U),getPaymentProviderCustomerOrThrow:Su(F),getShippingAddress:Su(x),getShippingAddressOrThrow:Su(q),getShippingAddresses:Su(j),getShippingAddressesOrThrow:Su(G),getShippingCountries:Su(H),getOutstandingBalance:Su(a),isPaymentDataRequired:M,isPaymentMethodInitialized:B}}var Iu,_u=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class wu{constructor(e,t,n,i,r,o,a,s,d,c,u,l,h,p,m,g,y,f,v,S){this._store=e,this._storeProjectionFactory=t,this._checkoutActionCreator=n,this._checkoutValidator=i,this._hostedFormFactory=r,this._orderActionCreator=o,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 n=this._storeProjection.getState().getCheckoutOrThrow().id;return this._hostedFormFactory.create(e,t,n)}subscribe(e,...t){return this._storeProjection.subscribe(e,...t)}getState(){return this._storeProjection.getState()}initializeOffsitePayment(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.initializeOffsitePayment(e)),this._storeProjection.getState()})}loadCheckout(e){return _u(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 _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()),this._storeProjection.getState()})}loadPaymentMethod(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethod(e,t)),this._storeProjection.getState()})}loadPaymentMethods(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentMethodActionCreator.loadPaymentMethods(e)),this._storeProjection.getState()})}submitOrder(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.submitOrder(e,t)),this._storeProjection.getState()})}submitPayment(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentActionCreator.submitPayment(e)),this._storeProjection.getState()})}finalizeOrder(e){return _u(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 _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._billingAddressActionCreator.updateAddress(e)),this._storeProjection.getState()})}updateShippingAddress(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.updateAddress(e)),this._storeProjection.getState()})}selectShippingOption(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.selectShippingOption(e,t)),this._storeProjection.getState()})}signInCustomer(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signInCustomer(e,t)),this._storeProjection.getState()})}signOutCustomer(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._customerActionCreator.signOutCustomer(e)),this._storeProjection.getState()})}createBuyNowCart(e,t){return _u(this,void 0,void 0,function*(){const{body:n}=yield this._cartRequestSender.createBuyNowCart(e,t);return n})}applyStoreCredit(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._storeCreditActionCreator.applyStoreCredit(e,t)),this._storeProjection.getState()})}applyCoupon(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.applyCoupon(e,t)),this._storeProjection.getState()})}removeCoupon(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._couponActionCreator.removeCoupon(e,t)),this._storeProjection.getState()})}verifyCheckoutSpamProtection(){return _u(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 _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._orderActionCreator.loadCurrentOrder(e)),this._storeProjection.getState()})}updatePaymentProviderCustomer(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._paymentProviderCustomerActionCreator.updatePaymentProviderCustomer(e)),this._storeProjection.getState()})}loadShippingCountries(e){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._shippingCountryActionCreator.loadCountries(e)),this._storeProjection.getState()})}deleteConsignment(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._consignmentActionCreator.deleteConsignment(e,t)),this._storeProjection.getState()})}initializePayment(e,t,n){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.initializePayment(e,t,n)),this._storeProjection.getState()})}forgetCheckout(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.forgetCheckout(e,t)),this._storeProjection.getState()})}remoteCheckoutSignOut(e,t){return _u(this,void 0,void 0,function*(){return yield this._store.dispatch(this._remoteCheckoutActionCreator.signOut(e,t)),this._storeProjection.getState()})}validateCheckout(e,t){return _u(this,void 0,void 0,function*(){yield this._checkoutValidator.validate(e,t)})}handlePaymentHumanVerification(e,t){return _u(this,void 0,void 0,function*(){return"string"==typeof e?this._paymentHumanVerificationHandler.handle(e,null!=t?t:""):this._paymentHumanVerificationHandler.handle(e)})}widgetInteraction(e){return _u(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"}(Iu||(Iu={}));class bu{constructor(e){this._transformSelectors=e}create(e){return function(e,t){const n=a((e,t)=>t.type===Iu.Synchronize?t.payload:e,e.getState(),{stateTransformer:t});return e.subscribe(e=>{n.dispatch(o(Iu.Synchronize,e))},{initial:!1}),n}(e,this._transformSelectors)}}const Eu=e=>{const t=B(e);return document.getElementById(t)?Eu(e):t};function Pu(e){return Object.prototype.hasOwnProperty.call(e,"cacheKey")}class Ou{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:n,parentMap:i}=t;let{map:r}=t;return r&&r.cacheKey?r.usedCount++:r=this._generateMap(i,e.slice(n)),this._removeLeastUsedMap(r),r.cacheKey}getUsedCount(...e){const{map:t}=this._resolveMap(...e);return t?t.usedCount:0}_resolveMap(...e){let t=0,n=this._map;for(;n.maps.length;){let i=!1;for(let r=0;r<n.maps.length;r++){const o=n.maps[r];if(this._options.isEqual(o.value,e[t])){if(n.maps.unshift(...n.maps.splice(r,1)),(0===e.length||t===e.length-1)&&Pu(o))return{index:t,map:o,parentMap:n};i=!0,n=o,t++;break}}if(!i)break}return{index:t,parentMap:n}}_generateMap(e,t){let n,i=0,r=e;do{n={maps:[],parentMap:r,usedCount:1,value:t[i]},r.maps.unshift(n),r=n,i++}while(i<t.length);const o=n;return o.cacheKey=""+ ++this._lastId,o}_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 n=this._usedMaps.pop();n&&(this._removeMap(n),this._options.onExpire(n.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 Au(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(n=>{const i=Object.getOwnPropertyDescriptor(e.prototype,n);i&&"constructor"!==n&&Object.defineProperty(t.prototype,n,function(e,t,n){if("function"!=typeof n.value)return n;let i=new Ou,r=n.value,o=ae(r);return _a(e,t,{get(){const e=(...e)=>{const t=o.call(this,...e);if(1===i.getUsedCount(...e))return t;const n=r.call(this,...e);return xe(n,t,{keyFilter:e=>!function(e){return 0===`${e}`.indexOf("$$")||0===`${e}`.indexOf("_")}(e)})?t:(o.cache.set(i.getKey(...e),n),n)};return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e},set(e){i=new Ou,r=e,o=ae(r)}})}(e.prototype,n,i))}),t}let Tu=class{constructor(e){this._checkoutButton=e.checkoutButton}getInitializeButtonError(e){return this._checkoutButton.getInitializeError(e)}getDeinitializeButtonError(e){return this._checkoutButton.getDeinitializeError(e)}};Tu=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([Au],Tu);const ku=Tu;let Du=class{constructor(e){this._checkoutButton=e.checkoutButton}isInitializingButton(e){return this._checkoutButton.isInitializing(e)}isDeinitializingButton(e){return this._checkoutButton.isDeinitializing(e)}};Du=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([Au],Du);const Ru=Du;function Mu(e){return{errors:new ku(e),statuses:new Ru(e)}}let Nu=class{constructor(e,t){this._store=e,this._buttonStrategyActionCreator=t,this._state=Mu(this._store.getState()),this._store.subscribe(e=>{this._state=Mu(e)})}getState(){return this._state}subscribe(e,...t){return this._store.subscribe(()=>e(this.getState()),e=>e.checkoutButton.getState(),...t.map(e=>t=>e(Mu(t))))}initializeButton(e){const t=(n=e.containerId,/^\w[\w\-\:\.]*$/.test(n)?[e.containerId]:function(e,t){const n=document.querySelectorAll(e);if(!n.length)throw new Kd(`Unable to find any element with the specified selector: ${e}`);return Array.prototype.slice.call(n).map(e=>(e.id||(e.id=Eu(t)),e.id))}(e.containerId,`${e.methodId}-container`));var n;return Promise.all(t.map(t=>{const n=this._buttonStrategyActionCreator.initialize(Object.assign(Object.assign({},e),{containerId:t})),i=`checkoutButtonStrategy:${e.methodId}:${t}`;return this._store.dispatch(n,{queueId:i})})).then(()=>this.getState())}deinitializeButton(e){const t=this._buttonStrategyActionCreator.deinitialize(e),n=`checkoutButtonStrategy:${e.methodId}`;return this._store.dispatch(t,{queueId:n}).then(()=>this.getState())}};Nu=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([_a],Nu);const Lu=Nu;class zu{constructor(e,t,n){this._registry=e,this._registryV2=t,this._paymentMethodActionCreator=n}initialize(e){return t=>{const n={methodId:e.methodId,containerId:e.containerId};if(t.getState().checkoutButton.isInitialized(e.methodId,e.containerId))return Y();const i=e.currencyCode?{params:{currencyCode:e.currencyCode}}:{},r=Object.assign(Object.assign({},i),{timeout:e.timeout,useCache:!0});return H(Q(o(ot.InitializeButtonRequested,void 0,n)),this._paymentMethodActionCreator.loadPaymentMethod(e.methodId,r)(t),V(()=>this._getStrategy(e.methodId).initialize(e).then(()=>o(ot.InitializeButtonSucceeded,void 0,n)))).pipe(J(e=>Cd(ot.InitializeButtonFailed,e,n)))}}deinitialize(e){return t=>{const n={methodId:e.methodId};return t.getState().checkoutButton.isInitialized(e.methodId)?H(Q(o(ot.DeinitializeButtonRequested,void 0,n)),V(()=>this._getStrategy(e.methodId).deinitialize().then(()=>o(ot.DeinitializeButtonSucceeded,void 0,n)))).pipe(J(e=>Cd(ot.DeinitializeButtonFailed,e,n))):Y()}}_getStrategy(e){let t;try{t=this._registryV2.get({id:e})}catch(n){t=this._registry.get(e)}return t}}class Uu{constructor(e){var t,n,i;this._factories={},this._instances={},this._defaultToken=null!==(t=null==e?void 0:e.defaultToken)&&void 0!==t?t:"default",this._useFallback=null===(n=null==e?void 0:e.useFallback)||void 0===n||n,this._tokenResolver=null!==(i=null==e?void 0:e.tokenResolver)&&void 0!==i?i: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){const t=this._tokenResolver(e,Object.keys(this._factories));return t?this._factories[t]:void 0}register(e,t){if(this._hasFactory(e))throw new Kd(`'${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 n=this.getFactory(e);if(!n)throw new Kd(`'${e}' is not registered.`);this._instances[t]=n()}return this._instances[t]}}class Fu 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"}}class Bu{constructor(e,t=window){this._scriptLoader=e,this._window=t}load({useMasterpassSrc:e,language:t,testMode:n,checkoutId:i}){return r=this,o=void 0,s=function*(){if(e){const e=[`https://${n?"sandbox.":""}src.mastercard.com/srci/integration/merchant.js`,[`locale=${t}`,`checkoutid=${i}`].join("&")].join("?");if(yield this._scriptLoader.loadScript(e),!this._window.masterpass)throw new Fu;return this._window.masterpass}if(yield this._scriptLoader.loadScript(`//${n?"sandbox.":""}masterpass.com/integration/merchant.js`),!this._window.masterpass)throw new Fu;return this._window.masterpass},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{d(s.next(e))}catch(e){t(e)}}function i(e){try{d(s.throw(e))}catch(e){t(e)}}function d(t){var r;t.done?e(t.value):(r=t.value,r instanceof a?r:new a(function(e){e(r)})).then(n,i)}d((s=s.apply(r,o||[])).next())});var r,o,a,s}}class xu{constructor(e){this._scriptLoader=e,this._window=window}loadPaypal(e=""){return t=this,n=void 0,r=function*(){const t="//www.paypalobjects.com/api/checkout.min.js",n={async:!0,attributes:{"data-merchant-id":e}};if(e?yield this._scriptLoader.loadScript(t,n):yield this._scriptLoader.loadScript(t),!this._window.paypal)throw new Fu;return this._window.paypal},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}}const qu={es:["es_es","es_mx","es_pe","es_co","es_ar","es_cl"],en:["en_us","en_gb","en_ca","en_es","en_fr","en_ie","en_sg","en_au","en_nz","en_my","en_hk","en_th","en_ae","en_sa","en_qa","en_kw","en_za"],pt:["pt_br"],zu:["zu_za"],ar:["ar_sa","ar_ae","ar_qa","ar_kw"],zh:["zh_sg","zh_hk"],ms:["ms_my"],uk:["uk_ua"],sv:["sv_se"],hr:["hr_hr"],pl:["pl_pl"],nl:["nl_be"],it:["it_it"],de:["de_de"],fr:["fr_fr","fr_ca"]};function ju(e){const[t,n]=e.replace("-","_").toLowerCase().split("_"),i=`${t}_${n}`,r=qu[t];return r?r.indexOf(i)>-1?i:r[0]:"en_us"}var Gu,Hu,Vu,Yu,Wu;class $u{constructor(e,t,n,i){this._store=e,this._checkoutActionCreator=t,this._masterpassScriptLoader=n,this._locale=i}initialize(e){const{containerId:t,methodId:n}=e;if(!t||!n)throw new Kd('Unable to proceed because "containerId" argument is not provided.');return this._methodId=n,this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()).then(e=>{const t=e.paymentMethods.getPaymentMethod(n);if(!t||!t.initializationData.checkoutId)throw new qi(xi.MissingPaymentMethod);const i={useMasterpassSrc:t.initializationData.isMasterpassSrcEnabled,language:ju(this._locale),testMode:t.config.testMode,checkoutId:t.initializationData.checkoutId};return this._masterpassScriptLoader.load(i)}).then(e=>{this._masterpassClient=e,this._signInButton=this._createSignInButton(t)})}deinitialize(){return this._signInButton&&this._signInButton.parentNode&&(this._signInButton.removeEventListener("click",this._handleWalletButtonClick),this._signInButton.parentNode.removeChild(this._signInButton),this._signInButton=void 0),Promise.resolve()}_createSignInButton(e){const t=document.getElementById(e),n=this._store.getState(),i=this._methodId?n.paymentMethods.getPaymentMethod(this._methodId):null,r=n.config.getStoreConfig();if(!t)throw new Error("Need a container to place the button");if(!i)throw new qi(xi.MissingPaymentMethod);if(!r)throw new Kd("Unable to retrieve store configuration");const o=document.createElement("input");if(o.type="image",i.initializationData.isMasterpassSrcEnabled){const e=i.config.testMode?"sandbox.":"",{checkoutId:t}=i.initializationData,n=[`locale=${ju(this._locale)}`,"paymentmethod=master,visa,amex,discover",`checkoutid=${t}`];o.src=[`https://${e}src.mastercard.com/assets/img/btn/src_chk_btn_126x030px.svg`,n.join("&")].join("?")}else o.src="https://static.masterpass.com/dyn/img/btn/global/mp_chk_btn_160x037px.svg";return t.appendChild(o),o.addEventListener("click",this._handleWalletButtonClick),o}_createMasterpassPayload(){const e=this._store.getState(),t=e.checkout.getCheckout(),n=this._methodId?e.paymentMethods.getPaymentMethod(this._methodId):null;if(!t)throw new qi(xi.MissingCheckout);if(!n)throw new qi(xi.MissingPaymentMethod);return{checkoutId:n.initializationData.checkoutId,allowedCardTypes:n.initializationData.allowedCardTypes,amount:t.cart.cartAmount.toString(),currency:t.cart.currency.code,cartId:t.cart.id,callbackUrl:`${window.location.origin}/checkout.php?action=set_external_checkout&provider=masterpass&gateway=stripe&origin=cart`}}_handleWalletButtonClick(){if(!this._masterpassClient)throw new dc(ic.CheckoutButtonNotInitialized);this._masterpassClient.checkout(this._createMasterpassPayload())}}(function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);o>3&&a&&Object.defineProperty(t,n,a)})([_a],$u.prototype,"_handleWalletButtonClick",null),function(e){e.HORIZONTAL="horizontal",e.VERTICAL="vertical"}(Gu||(Gu={})),function(e){e.SMALL="small",e.MEDIUM="medium",e.LARGE="large",e.RESPONSIVE="responsive"}(Hu||(Hu={})),function(e){e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white"}(Vu||(Vu={})),function(e){e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit"}(Yu||(Yu={})),function(e){e.PILL="pill",e.RECT="rect"}(Wu||(Wu={}));class Ku{constructor(e,t,n,i,r=""){this._store=e,this._checkoutActionCreator=t,this._paypalScriptLoader=n,this._formPoster=i,this._host=r}initialize(e){const t=e.paypal,n=this._store.getState(),i=this._paymentMethod=n.paymentMethods.getPaymentMethod(e.methodId);if(!t)throw new Kd;if(!i)throw new qi(xi.MissingPaymentMethod);return this._paypalScriptLoader.loadPaypal(i.config.merchantId).then(n=>{var r,o;if(!i||!i.config.merchantId)throw new qi(xi.MissingPaymentMethod);const a=i.config.merchantId,s=i.config.testMode?"sandbox":"production",d={[s]:t.clientId},c=n.FUNDING.CREDIT||"credit",u=t.allowCredit?[c]:[],l=t.allowCredit?[]:[c];return n.Button.render({env:s,client:d,commit:t.shouldProcessPayment,funding:{allowed:u,disallowed:l},style:Object.assign(Object.assign({shape:Wu.RECT},R(t.style,"layout","color","label","shape","tagline","fundingicons")),{size:"paypalexpress"===i.id&&"small"===(null===(r=t.style)||void 0===r?void 0:r.size)?Hu.RESPONSIVE:null===(o=t.style)||void 0===o?void 0:o.size}),payment:(e,n)=>this._setupPayment(a,n,t.onPaymentError),onAuthorize:(e,n)=>this._tokenizePayment(e,n,t.shouldProcessPayment,t.onAuthorizeError)},e.containerId)})}deinitialize(){return this._paymentMethod=void 0,Promise.resolve()}_setupPayment(e,t,n){if(!t)throw new dc(ic.CheckoutButtonNotInitialized);return this._store.dispatch(this._checkoutActionCreator.loadDefaultCheckout()).then(n=>{const i=n.cart.getCart(),r=i?i.id:"";return t.request.post(`${this._host}/api/storefront/payment/paypalexpress`,{merchantId:e,cartId:r},{headers:Object.assign({"X-API-INTERNAL":fd},vd)})}).then(e=>e.id).catch(e=>{throw n&&n(e),e})}_tokenizePayment(e,t,n,i){if(!this._paymentMethod)throw new dc(ic.CheckoutButtonNotInitialized);if(!t)throw new dc(ic.CheckoutButtonNotInitialized);if(!e.paymentID||!e.payerID)throw new qi(xi.MissingPayment);const r=this._paymentMethod.id;return t.payment.get(e.paymentID).then(t=>{this._formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:r,action:n?"process_payment":"set_external_checkout",paymentId:e.paymentID,payerId:e.payerID,payerInfo:JSON.stringify(t.payer.payer_info)})})}}function Qu(e){return e&&"resolveIds"in e}function Zu(){try{return"production"}catch(e){return"development"}}class Ju{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 Xu{log(){}info(){}warn(){}error(){}debug(){}}const el=function(e=!0){return e?new Ju(console):new Xu}("test"!==Zu());class tl{constructor(e=!1){this._useFallback=e,this._registry=new Uu({tokenResolver:this._resolveToken.bind(this),useFallback:this._useFallback})}get(e){return this._registry.get(this._encodeToken(e))}getFactory(e){try{return this._registry.getFactory(this._encodeToken(e))}catch(e){return}}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){var n;const i=this._decodeToken(e),r=[];t.forEach(e=>{const t=this._decodeToken(e),n={token:e,matches:0,default:!1};for(const[e,r]of Object.entries(t)){if(e in i&&i[e]!==r){n.matches=0;break}e in i&&i[e]===r&&n.matches++,"default"===e&&!0===r&&(n.default=!0)}r.push(n)});const o=r.sort((e,t)=>t.matches-e.matches).filter(e=>e.matches>0);o.length>1&&o[0].matches===o[1].matches&&"development"===Zu()&&el.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 a=o[0];if(a&&a.token)return a.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 nl(t){const{host:i,locale:r="en"}=null!=t?t:{},o=Qi({config:{meta:{host:null==t?void 0:t.host,locale:null==t?void 0:t.locale},errors:{},statuses:{}}}),a=e({host:i}),s=n({host:i}),d=function(e,t){const n=new tl;for(const[,i]of Object.entries(t))if(Qu(i))for(const t of i.resolveIds)n.register(t,()=>i(e));return n}(function(t){const{config:{getHost:n,getLocale:i}}=t.getState(),r=e({host:n()}),o=new bu(Cu),a=new Od(new Rd(r),new Ud(new Fd(r)),new Hd(new Vd(r))),s=new Ld(new Rd(r)),d=new wc(t),c=new Ec(new kc(r),new Ld(new Rd(r))),u=new _d(new Ed(r),new gu(new yu(r))),l=new ru(new au(r),new Rd(r)),h=new md(new Sd(r)),p=new Dc(new Rc(function(e){const t=me();return e.subscribe(e=>{const n=e.config.getStoreConfig();n&&t.setHost(n.paymentSettings.bigpayBaseUrl)},e=>e.config.getStoreConfig()),t}(t)),c,new Xc,new sc(pc(ue()))),m=new sc(pc(ue())),g=new jd(new Gd(r),a,new uu(pc(ue()),new lu(r))),y=new hu(new pu(r)),f=new Bd(new xd(r)),v=pc(ue()),S=new lu(r),C=new uu(v,S),I=new Pd(r),_=new eu,w=new su(new du(r,{locale:i()}),t),b=new nu(new iu(r),a),E=new tu;return new wu(t,o,a,s,d,c,u,l,h,p,m,g,I,y,f,C,_,w,b,E)}(o),Se);return new Lu(o,new zu(function(e,t,n,i,r){const o=new Uu,a=le(),s=new Rd(t),d=new Od(s,new Ud(new Fd(t)),new Hd(new Vd(t)));return o.register(jc.MASTERPASS,()=>new $u(e,d,new Bu(a),i)),o.register(jc.PAYPALEXPRESS,()=>new Ku(e,d,new xu(a),n,r)),o}(o,a,s,r,i),d,new md(new Sd(a))))}export{nl as createCheckoutButtonInitializer,t as createTimeout};
2
2
  //# sourceMappingURL=checkout-button.js.map