@bigcommerce/checkout-sdk 1.983.3 → 1.983.4

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{createScriptLoader as e,getScriptLoader as t}from"@bigcommerce/script-loader";import{createFormPoster as n}from"@bigcommerce/form-poster";import{createRequestSender as i}from"@bigcommerce/request-sender";import{isEqual as r,isNil as a,noop as o,omit as s,omitBy as l}from"lodash";class d 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}}class c extends d{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var m=(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",e))(m||{});class u extends d{constructor(e){super(function(e){switch(e){case 0:return"Unable to proceed because billing address data is unavailable.";case 1:return"Unable to proceed because cart data is unavailable.";case 3:return"Unable to proceed because consignments data is unavailable.";case 2:return"Unable to proceed because checkout data is unavailable.";case 4:return"Unable to proceed because customer data is unavailable.";case 5:case 7:return"Unable to proceed because configuration data is unavailable.";case 6:return"Unable to proceed because order data is unavailable.";case 8:return"Unable to proceed because order ID is unavailable or not generated yet.";case 9:return"Unable to proceed because payment data is unavailable.";case 15:return"Unable to proceed because the token required to submit a payment is missing.";case 12:return"Unable to proceed because payment method data is unavailable or not properly configured.";case 16: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"}}var h=Object.defineProperty,y=Object.defineProperties,p=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,P=(e,t,n)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))v.call(t,n)&&P(e,n,t[n]);if(g)for(var n of g(t))b.call(t,n)&&P(e,n,t[n]);return e},S=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class _{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return S(this,null,function*(){if(!this.window.bigCommercePaymentsFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.bigCommercePaymentsFastlaneSdk)throw new c}return this.window.bigCommercePaymentsFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return S(this,null,function*(){if(!this.window.bigCommercePaymentsGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.bigCommercePaymentsGooglePay)throw new c;return this.window.bigCommercePaymentsGooglePay})}getPayPalApmsSdk(e,t){return S(this,null,function*(){if(!this.window.bigCommercePaymentsApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.bigCommercePaymentsApms)throw new c}return this.window.bigCommercePaymentsApms})}getPayPalMessages(e,t){return S(this,null,function*(){if(!this.window.bigCommercePaymentsMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.bigCommercePaymentsMessages)throw new c;return this.window.bigCommercePaymentsMessages})}loadPayPalSdk(e){return S(this,arguments,function*({options:e,attributes:t}){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 u(m.MissingPaymentMethod);const{intent:a,clientId:o,merchantId:s,attributionId:l}=r;return{options:{"client-id":o,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:a},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"bigCommercePaymentsFastlaneSdk","data-partner-attribution-id":l,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new u(m.MissingPaymentMethod);const{intent:a,clientId:o,merchantId:s,buyerCountry:l,attributionId:d,isHostedCheckoutEnabled:c,isDeveloperModeApplicable:h}=r;return{options:f({"client-id":o,"merchant-id":s,commit:c||n,components:["googlepay"],currency:t,intent:a},h&&{"buyer-country":l}),attributes:{"data-partner-attribution-id":d,"data-client-token":i,"data-namespace":"bigCommercePaymentsGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:a,buyerCountry:o,attributionId:s,isDeveloperModeApplicable:l,availableAlternativePaymentMethods:d=[],enabledAlternativePaymentMethods:c=[]}=n,h=this.filterFundingOptions(c),y=this.filterFundingOptions(d.filter(e=>!c.includes(e)));return{options:f({"client-id":r,"merchant-id":a,"enable-funding":h.length>0?h:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},l&&{"buyer-country":o}),attributes:{"data-partner-attribution-id":s,"data-namespace":"bigCommercePaymentsApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:a,isDeveloperModeApplicable:o,buyerCountry:s}=n;return{options:f({"client-id":i,"merchant-id":r,components:["messages"],currency:t},o&&{"buyer-country":s}),attributes:{"data-namespace":"bigCommercePaymentsMessages","data-partner-attribution-id":a}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];var r,a;null==i||""===i||Array.isArray(i)&&0===i.length||(r=f({},t),a={[n]:Array.isArray(i)?i.join(","):i},t=y(r,p(a)))}),t}}function I(){return new _(e())}function C(e,t){return Object.assign(e,{resolveIds:t})}var w=(e=>(e.PayPal="paypal",e.BigCommercePaymentsPayPalSDK="bigCommercePaymentsPayPalSDK",e.PayPalFastlaneSdk="paypalFastlaneSdk",e.PayPalFastlane="paypalFastlane",e.PayPalGooglePay="paypalGooglePay",e.PayPalApms="paypalApms",e.PayPalMessages="paypalMessages",e))(w||{});const O=["ar_BH","ar_DZ","ar_EG","ar_JO","ar_KW","ar_MA","ar_OM","ar_QA","ar_SA","ar_TN","ar_YE","ar_AE","bg_BG","cs_CZ","da_DK","da_FO","da_GL","de_AT","de_CH","de_DE","de_LU","el_GR","en_AD","en_AE","en_AG","en_AI","en_AL","en_AM","en_AN","en_AO","en_AT","en_AU","en_AW","en_AZ","en_BB","en_BE","en_BH","en_BJ","en_BM","en_BN","en_BS","en_BT","en_BW","en_BY","en_BZ","en_C2","en_CA","en_CD","en_CG","en_CH","en_CI","en_CK","en_CL","en_CM","en_CN","en_CO","en_CR","en_CV","en_CY","en_CZ","en_DE","en_DJ","en_DK","en_DM","en_DO","en_DZ","en_EC","en_EE","en_EG","en_ER","en_ES","en_ET","en_FI","en_FJ","en_FK","en_FM","en_FO","en_FR","en_GA","en_GB","en_GD","en_GE","en_GF","en_GI","en_GL","en_GM","en_GN","en_GP","en_GR","en_GT","en_GW","en_GY","en_HK","en_HN","en_HR","en_HU","en_ID","en_IE","en_IL","en_IN","en_IS","en_IT","en_JM","en_JO","en_JP","en_KE","en_KG","en_KH","en_KI","en_KM","en_KN","en_KR","en_KW","en_KY","en_KZ","en_LA","en_LC","en_LI","en_LK","en_LS","en_LT","en_LU","en_LV","en_MA","en_MC","en_MD","en_ME","en_MG","en_MH","en_MK","en_ML","en_MN","en_MQ","en_MR","en_MS","en_MT","en_MU","en_MV","en_MW","en_MY","en_MZ","en_NA","en_NC","en_NE","en_NF","en_NG","en_NI","en_NL","en_NO","en_NP","en_NR","en_NU","en_NZ","en_OM","en_PA","en_PE","en_PF","en_PG","en_PH","en_PL","en_PM","en_PN","en_PT","en_PW","en_PY","en_QA","en_RE","en_RO","en_RS","en_RU","en_RW","en_SA","en_SB","en_SC","en_SE","en_SG","en_SH","en_SI","en_SJ","en_SK","en_SL","en_SM","en_SN","en_SO","en_SR","en_ST","en_SV","en_SZ","en_TC","en_TD","en_TG","en_TH","en_TJ","en_TM","en_TN","en_TO","en_TR","en_TT","en_TV","en_TW","en_TZ","en_UA","en_UG","en_US","en_UY","en_VA","en_VC","en_VE","en_VG","en_VN","en_VU","en_WF","en_WS","en_YE","en_YT","en_ZA","en_ZM","en_ZW","es_AD","es_AI","es_AO","es_AR","es_AW","es_BB","es_BJ","es_BM","es_BO","es_BS","es_BZ","es_CD","es_CG","es_CK","es_CL","es_CO","es_CR","es_CV","es_DJ","es_DM","es_DO","es_DZ","es_EC","es_EG","es_ER","es_ES","es_ET","es_FJ","es_FK","es_FO","es_GA","es_GD","es_GE","es_GI","es_GL","es_GM","es_GN","es_GT","es_GW","es_GY","es_HN","es_IE","es_JM","es_JO","es_KE","es_KG","es_KI","es_KM","es_KN","es_KW","es_KY","es_KZ","es_LC","es_LI","es_LS","es_LU","es_MA","es_MG","es_MH","es_ML","es_MR","es_MS","es_MU","es_MW","es_MX","es_MZ","es_NA","es_NC","es_NE","es_NF","es_NI","es_NR","es_NU","es_NZ","es_OM","es_PA","es_PE","es_PF","es_PG","es_PM","es_PN","es_PW","es_PY","es_QA","es_RS","es_RW","es_SA","es_SB","es_SC","es_SH","es_SJ","es_SL","es_SM","es_SN","es_SO","es_SR","es_ST","es_SV","es_SZ","es_TC","es_TD","es_TG","es_TJ","es_TM","es_TN","es_TT","es_TV","es_UA","es_UG","es_US","es_UY","es_VA","es_VC","es_VE","es_VG","es_VU","es_WF","es_YE","es_ZM","et_EE","fi_FI","fr_AD","fr_AE","fr_AI","fr_AM","fr_AO","fr_AW","fr_AZ","fr_BB","fr_BE","fr_BF","fr_BI","fr_BJ","fr_BM","fr_BS","fr_BZ","fr_CA","fr_CD","fr_CG","fr_CH","fr_CI","fr_CK","fr_CM","fr_CV","fr_DJ","fr_DM","fr_DO","fr_DZ","fr_EC","fr_ER","fr_ET","fr_FJ","fr_FK","fr_FO","fr_FR","fr_GA","fr_GD","fr_GE","fr_GF","fr_GI","fr_GL","fr_GM","fr_GN","fr_GP","fr_GT","fr_GW","fr_GY","fr_HN","fr_IE","fr_JM","fr_JO","fr_KE","fr_KG","fr_KI","fr_KM","fr_KN","fr_KW","fr_KY","fr_KZ","fr_LC","fr_LI","fr_LS","fr_LU","fr_MA","fr_MC","fr_MG","fr_MH","fr_ML","fr_MQ","fr_MR","fr_MS","fr_MU","fr_MW","fr_MZ","fr_NA","fr_NC","fr_NE","fr_NF","fr_NI","fr_NR","fr_NU","fr_NZ","fr_OM","fr_PA","fr_PE","fr_PF","fr_PG","fr_PM","fr_PN","fr_PW","fr_QA","fr_RE","fr_RS","fr_RW","fr_SA","fr_SB","fr_SC","fr_SH","fr_SJ","fr_SL","fr_SM","fr_SN","fr_SO","fr_SR","fr_ST","fr_SV","fr_SZ","fr_TC","fr_TD","fr_TG","fr_TJ","fr_TM","fr_TN","fr_TT","fr_TV","fr_UA","fr_UG","fr_US","fr_UY","fr_VA","fr_VC","fr_VE","fr_VG","fr_VU","fr_WF","fr_YE","fr_YT","fr_ZA","fr_ZM","he_IL","hu_HU","id_ID","it_IT","ja_JP","ko_KR","lv_LV","lt_LT","ms_BN","ms_MY","nl_BE","nl_NL","pl_PL","pt_BR","pt_PT","ro_RO","ru_EE","ru_LT","ru_LV","ru_RU","ru_UA","si_LK","sk_SK","sl_SI","sq_AL","sv_SE","tl_PH","th_TH","tr_TR","vi_VN","zh_C2","zh_CN","zh_HK","zh_TW","zh_AD","zh_AE","zh_AI","zh_AO","zh_AW","zh_BB","zh_BH","zh_BJ","zh_BM","zh_BS","zh_BZ","zh_CD","zh_CG","zh_CK","zh_CL","zh_CO","zh_CV","zh_DJ","zh_DM","zh_DO","zh_DZ","zh_EC","zh_EG","zh_ER","zh_ET","zh_FJ","zh_FK","zh_FO","zh_GA","zh_GD","zh_GE","zh_GI","zh_GL","zh_GM","zh_GN","zh_GT","zh_GW","zh_GY","zh_HN","zh_IE","zh_JM","zh_JO","zh_KE","zh_KG","zh_KI","zh_KM","zh_KN","zh_KW","zh_KY","zh_KZ","zh_LC","zh_LI","zh_LS","zh_LT","zh_LU","zh_MA","zh_MG","zh_MH","zh_ML","zh_MR","zh_MS","zh_MU","zh_MW","zh_MZ","zh_NA","zh_NC","zh_NE","zh_NF","zh_NI","zh_NR","zh_NU","zh_NZ","zh_OM","zh_PA","zh_PE","zh_PF","zh_PG","zh_PM","zh_PN","zh_PW","zh_QA","zh_RS","zh_RW","zh_SA","zh_SB","zh_SC","zh_SH","zh_SJ","zh_SL","zh_SM","zh_SN","zh_SO","zh_SR","zh_ST","zh_SV","zh_SZ","zh_TC","zh_TD","zh_TG","zh_TJ","zh_TM","zh_TN","zh_TT","zh_TV","zh_UA","zh_UG","zh_US","zh_UY","zh_VA","zh_VC","zh_VE","zh_VG","zh_VU","zh_WF","zh_YE","zh_ZA","zh_ZM"];function A(e){return window[e]}function z(e){if(!e)return;let t;if(e.includes("-")){const[n,i]=e.split("-");t=`${n}_${i.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return O.includes(t)?t:void 0}var E=Object.defineProperty,k=Object.defineProperties,T=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,D=(e,t,n)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,N=(e,t)=>{for(var n in t||(t={}))M.call(t,n)&&D(e,n,t[n]);if(B)for(var n of B(t))F.call(t,n)&&D(e,n,t[n]);return e},x=(e,t)=>k(e,T(t)),U=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class j{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return U(this,null,function*(){const a=this.isBigCommercePaymentsMethod(e.id)?w.BigCommercePaymentsPayPalSDK:w.PayPal;if(!A(a)||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}const o=A(a);if(!o)throw new c;return o})}getPayPalFastlaneSdk(e,t,n,i){return U(this,null,function*(){if(!this.window.paypalFastlaneSdk){const r=this.getPayPalFastlaneSdkConfiguration(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i,r){return U(this,null,function*(){if(!this.window.paypalGooglePay||r){const r=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return U(this,null,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return U(this,null,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}isBigCommercePaymentsMethod(e){return e.startsWith("bigcommerce_payments")}loadPayPalSdk(e){return U(this,arguments,function*({options:e,attributes:t}){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})})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:a,initializationData:o}=e;if(!o||!o.clientId)throw new u(m.MissingPaymentMethod);const{intent:s,clientId:l,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:p,isPayPalCreditAvailable:g,isDeveloperModeApplicable:v,availableAlternativePaymentMethods:b=[],enabledAlternativePaymentMethods:P=[],isGooglePayEnabled:f}=o,S=p||i,_="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,I=_?["card"]:[],C=_?[]:["card"],O=g?["credit","paylater"]:[],A=g?[]:["credit","paylater"],E=y?["venmo"]:[],k=y?[]:["venmo"],T=b.filter(e=>!P.includes(e)),B=f?["googlepay"]:[],M=i?["card-fields"]:[],F=this.filterFundingOptions([...C,...A,...k,...T]),D=this.filterFundingOptions([...I,...O,...E,...P]),x=z(n);return{options:N(N({"client-id":l,"merchant-id":d,"enable-funding":D.length>0?D:void 0,"disable-funding":F.length>0?F:void 0,commit:S,components:["buttons","hosted-fields","payment-fields","legal",...B,...M],currency:t,intent:s},v&&{"buyer-country":c}),x&&{locale:x}),attributes:N({"data-partner-attribution-id":h,"data-client-token":a},this.isBigCommercePaymentsMethod(r)&&{"data-namespace":w.BigCommercePaymentsPayPalSDK})}}getPayPalFastlaneSdkConfiguration(e,t,n,i){const{clientToken:r,initializationData:a}=e;if(!a||!a.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:s,merchantId:l,attributionId:d}=a,c=z(i);return{options:x(N({"client-id":s,"merchant-id":l,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:o}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":w.PayPalFastlaneSdk,"data-partner-attribution-id":d,"data-sdk-client-token":r}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i=!0){const{clientToken:r,initializationData:a}=e;if(!a||!a.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:s,merchantId:l,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:y}=a,p=h||i,g=z(n);return{options:N(N({"client-id":s,"merchant-id":l,commit:p,components:["googlepay"],currency:t,intent:o},y&&{"buyer-country":d}),g&&{locale:g}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":w.PayPalGooglePay}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:o,buyerCountry:s,attributionId:l,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=i,y=this.filterFundingOptions(h),p=this.filterFundingOptions(c.filter(e=>!h.includes(e))),g=z(n);return{options:N(N({"client-id":a,"merchant-id":o,"enable-funding":y.length>0?y:void 0,"disable-funding":p.length>0?p:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:r},d&&{"buyer-country":s}),g&&{locale:g}),attributes:{"data-partner-attribution-id":l,"data-namespace":w.PayPalApms}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{clientId:r,merchantId:a,attributionId:o,isDeveloperModeApplicable:s,buyerCountry:l}=i,d=z(n);return{options:N(N({"client-id":r,"merchant-id":a,components:["messages"],currency:t},s&&{"buyer-country":l}),d&&{locale:d}),attributes:{"data-namespace":w.PayPalMessages,"data-partner-attribution-id":o}}}filterFundingOptions(e){const t=["klarna","afterpay"];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=x(N({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function V(){return new j(t())}class L extends d{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"}}const R={body:{},headers:{},status:0};class G extends d{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:a}=e||R;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=a,this.errors=n||[]}}var W=(e=>(e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE",e))(W||{}),K=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))(K||{}),H=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(H||{}),$=(e=>(e.pill="pill",e.rect="rect",e))($||{}),q=Object.defineProperty,Y=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,X=(e,t,n)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Q=(e,t)=>{for(var n in t||(t={}))J.call(t,n)&&X(e,n,t[n]);if(Y)for(var n of Y(t))Z.call(t,n)&&X(e,n,t[n]);return e},ee=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class te{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=n,this.paypalSdkLoader=i}loadPayPalSdk(e,t,n,i){return ee(this,null,function*(){const r=this.paymentIntegrationService.getState(),a=t||r.getCartOrThrow().currency.code,o=r.getPaymentMethodOrThrow(e),s=r.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(o,a,s,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return ee(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(m.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new L}})}createOrder(e,t){return ee(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalRequestSender.createOrder(e,Q({cartId:n},t));return i})}createOrderCardFields(e,t){return ee(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalRequestSender.createOrder(e,Q({cartId:n},t));return Q({orderId:i},r?{setupToken:r}:{})})}updateOrder(e,t,n,i){return ee(this,null,function*(){const r=this.paymentIntegrationService.getState(),a=r.getCartOrThrow();let o;i||(o=r.getConsignmentsOrThrow()[0]);try{yield this.paypalRequestSender.updateOrder(e,Q(Q({availableShippingOptions:i?[]:null==o?void 0:o.availableShippingOptions,cartId:a.id,selectedShippingOption:i?null:null==o?void 0:o.selectedShippingOption},t?{methodId:t}:{}),n?{orderId:n}:{}))}catch(e){throw new G}})}getOrderStatus(e,t){return ee(this,null,function*(){try{const{status:n}=yield this.paypalRequestSender.getOrderStatus(e,t);return n}catch(e){throw new G}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(m.MissingOrderId);return this.formPoster.postForm("/checkout.php",Q({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===W.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return ee(this,null,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(Q({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=>{if(t.selectedShippingOption){const n=t.selectedShippingOption.id;return e.id===n}return!1}))||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.phone_number)?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[a,...o]=r.split(" ");return this.getAddress({firstName:a,lastName:o.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&&H[t]?t:void 0,height:this.getValidHeight(n),label:i&&K[i]?i:void 0,shape:r&&$[r]?r:void 0};return l(o,a)}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")}}const ne="This API endpoint is for internal use only and may change in the future";var ie=(e=>(e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json",e))(ie||{});const re=ie,ae={"X-Checkout-SDK-Version":"1.983.3"};var oe=Object.defineProperty,se=Object.getOwnPropertySymbols,le=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable,ce=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t)=>{for(var n in t||(t={}))le.call(t,n)&&ce(e,n,t[n]);if(se)for(var n of se(t))de.call(t,n)&&ce(e,n,t[n]);return e},ue=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class he{constructor(e){this.requestSender=e}createOrder(e,t){return ue(this,null,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=me({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e,t){return ue(this,null,function*(){const n=`/api/storefront/initialization/${e}`,i=t,r=me({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.put(n,{headers:r,body:i})).body})}getOrderStatus(e,t){return ue(this,null,function*(){const n=`/api/storefront/initialization/${e}`,i=me({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.get(n,me({headers:i},t))).body})}}var ye=Object.defineProperty,pe=Object.getOwnPropertySymbols,ge=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,be=(e,t,n)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pe=(e,t)=>{for(var n in t||(t={}))ge.call(t,n)&&be(e,n,t[n]);if(pe)for(var n of pe(t))ve.call(t,n)&&be(e,n,t[n]);return e};const fe={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Se="embedded-checkout-loading-indicator-rotation";class _e{constructor(e){this.styles=Pe(Pe({},fe),e&&e.styles),this.containerStyles=Pe({},e&&e.containerStyles),this.defineAnimation(),this.container=this.buildContainer(),this.indicator=this.buildIndicator(),this.container.appendChild(this.indicator)}show(e){if(e){const t=document.getElementById(e);if(!t)throw new Error("Unable to attach the loading indicator because the parent ID is not valid.");t.appendChild(this.container)}this.container.style.visibility="visible",this.container.style.opacity="1"}hide(){const e=()=>{this.container.style.visibility="hidden",this.container.removeEventListener("transitionend",e)};this.container.addEventListener("transitionend",e),this.container.style.opacity="0"}buildContainer(){const e=document.createElement("div");return e.style.display="block",e.style.bottom="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.position="absolute",e.style.right="0",e.style.top="0",e.style.transition="all 250ms ease-out",e.style.opacity="0",this.setStyleAttribute(e,this.containerStyles),e}buildIndicator(){const e=document.createElement("div");return e.style.display="block",e.style.width=`${this.styles.size}px`,e.style.height=`${this.styles.size}px`,e.style.borderRadius=`${this.styles.size}px`,e.style.border="solid 1px",e.style.borderColor=`${this.styles.backgroundColor} ${this.styles.backgroundColor} ${this.styles.color} ${this.styles.color}`,e.style.margin="0 auto",e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top="50%",e.style.transform="translateY(-50%) rotate(0deg)",e.style.transformStyle="preserve-3d",e.style.animation=`${Se} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(n=>{e.style.setProperty(n,t[n])})}defineAnimation(){var e;if(document.getElementById(Se))return;const t=document.createElement("style");t.id=Se,null==(e=document.head)||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${Se} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}const Ie={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},Ce=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};class we extends d{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class Oe extends we{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 Ae extends G{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 ze extends d{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function Ee(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function ke(e){return Boolean(e.instrumentId)}function Te(e){return"object"==typeof e&&null!==e&&"bigpayToken"in e&&"defaultInstrument"in e&&"provider"in e&&"trustedShippingAddress"in e&&"method"in e&&"type"in e}var Be=Object.getOwnPropertySymbols,Me=Object.prototype.hasOwnProperty,Fe=Object.prototype.propertyIsEnumerable,De=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ne{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkHelper=n,this.loadingIndicator=i}initialize(e){return De(this,null,function*(){const{methodId:t,bigcommerce_payments:n}=e||{};if(this.bigcommerce_payments=n,!t)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{container:a,bannerContainerId:o}=n,{orderId:s,paypalBNPLConfiguration:l=[],isPayPalCreditAvailable:d}=r.initializationData||{};if(void 0!==o){if(!document.getElementById(o))return void console.error("Unable to create banner without valid banner container ID.");const e=null==l?void 0:l.find(({id:e})=>"checkout"===e);if(d||!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return t&&"function"==typeof(null==t?void 0:t.Messages)?this.renderMessages(t,o,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}s?this.orderId=s:(this.loadingIndicatorContainer=null==a?void 0:a.split("#")[1],yield this.paypalIntegrationService.loadPayPalSdk(t),n.onInit&&"function"==typeof n.onInit&&n.onInit(()=>this.renderButton(t,n)),(void 0===n.shouldRenderPayPalButtonOnInitialization||n.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(t,n))})}execute(e,t){return De(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Me.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Be)for(var i of Be(e))t.indexOf(i)<0&&Fe.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{onError:a}=this.bigcommerce_payments||{};if(!i)throw new Oe(["payment"]);const{methodId:o,paymentData:s}=i;if(this.isPayPalVaultedInstrumentPaymentData(s)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new Ae;const l=this.isPayPalVaultedInstrumentPaymentData(s)?this.prepareVaultedInstrumentPaymentPayload(o,this.orderId,s):this.preparePaymentPayload(o,this.orderId,s);try{yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(l)}catch(e){return this.isProviderError(e)&&(yield this.paypalIntegrationService.loadPayPalSdk(i.methodId),yield new Promise((e,t)=>{var n;this.bigcommerce_payments&&(null==(n=this.paypalButton)||n.close(),this.renderButton(i.methodId,this.bigcommerce_payments),this.handleError(new Error("INSTRUMENT_DECLINED"),a)),t()})),this.handleError(e,a),Promise.reject()}})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:i,shouldSetAsDefaultInstrument:r}=n,a=!this.isTrustedVaultingFlow(n);return a?{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:i}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:i=!1,shouldSetAsDefaultInstrument:r=!1}=Ee(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:a}=r||{},{container:o,onError:s,onRenderButton:l,onValidate:d,submitForm:c}=t;if(!o)throw new we('Unable to initialize payment because "container" argument is not provided.');const m={fundingSource:n.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onError:e=>this.handleError(e,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(m),this.paypalButton.isEligible()&&(l&&"function"==typeof l&&l(),this.paypalButton.render(o))}handleClick(e,t){return De(this,null,function*(){const{resolve:n,reject:i}=e;yield null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return De(this,null,function*(){const e=this.getFieldsValues();return this.paypalIntegrationService.createOrder("bigcommerce_paymentscheckout",{shouldSaveInstrument:(null==e?void 0:e.shouldSaveInstrument)||!1})})}getFieldsValues(){const{getFieldsValues:e}=this.bigcommerce_payments||{};return"function"==typeof e?e():void 0}isTrustedVaultingFlow(e){if(e&&ke(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>Te(t)&&t.bigpayToken===e.instrumentId);return!(Te(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&ke(e)&&Ee(e)}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:Ce(n)};e.Messages(i).render(`#${t}`)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null==(i=null==(n=((null==(t=null==e?void 0:e.errors)?void 0:t.filter(e=>e.provider_error))||[])[0])?void 0:n.provider_error)?void 0:i.code)}}const xe=C(e=>new Ne(e,(e=>{const{getHost:t}=e.getState();return new te(n(),e,new he(i({host:t()})),V())})(e),I(),new _e({containerStyles:Ie})),[{id:"bigcommerce_payments"}]);var Ue=(e=>(e.CVV="cvv",e.PAN="pan",e))(Ue||{}),je=Object.defineProperty,Ve=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,Ge=(e,t,n)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;class We{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:a,domain:o,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}a&&(i+=`; path=${a}`),o&&(i+=`; domain=${o}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){We.set(e,"",((e,t)=>{for(var n in t||(t={}))Le.call(t,n)&&Ge(e,n,t[n]);if(Ve)for(var n of Ve(t))Re.call(t,n)&&Ge(e,n,t[n]);return e})({expires:new Date(0)},t))}}var Ke=(e=>(e.Always="SCA_ALWAYS",e))(Ke||{}),He=(e=>(e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored",e))(He||{}),$e=(e=>(e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized",e))($e||{}),qe=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ye{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return qe(this,null,function*(){if(t&&(window.localStorage.setItem("fastlaneEnv","sandbox"),window.localStorage.setItem("axoEnv","sandbox")),!this.window.bigCommercePaymentsFastlane){const t={root:{backgroundColorPrimary:"transparent"}};this.window.bigCommercePaymentsFastlane=yield e.Fastlane({styles:n||t})}return this.window.bigCommercePaymentsFastlane})}getPayPalFastlaneOrThrow(){if(!this.window.bigCommercePaymentsFastlane)throw new c;return this.window.bigCommercePaymentsFastlane}lookupCustomerOrThrow(e){return qe(this,null,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return qe(this,null,function*(){return e?this.getPayPalFastlaneOrThrow().identity.triggerAuthenticationFlow(e):{}})}updateStorageSessionId(e){const t=new Date;t.setDate(t.getDate()+14);const n={expires:t,secure:!0};We.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){We.remove("bc-fastlane-sessionId")}getStorageSessionId(){return We.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,i,r;const{authenticationState:a,profileData:o}=t,s=null==(r=null==(i=null==(n=null==o?void 0:o.card)?void 0:n.paymentSource)?void 0:i.card)?void 0:r.billingAddress,l=null==o?void 0:o.shippingAddress,d=null==o?void 0:o.name,c=null==o?void 0:o.card,m=l?this.mapPayPalToBcAddress(l.address,l.name,l.phoneNumber):void 0,u=s&&d?this.mapPayPalToBcAddress(s,d,null==l?void 0:l.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([m,u]);return{authenticationState:a||$e.UNRECOGNIZED,addresses:y,billingAddress:u,shippingAddress:m,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:i}=t,{brand:r,expiry:a,lastDigits:o}=i.card,[s,l]=a.split("-");return[{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:l,expiryYear:s,iin:"",last4:o,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:Ue.PAN,type:"card"}]}mapBcToPayPalAddress(e){return{company:(null==e?void 0:e.company)||"",addressLine1:(null==e?void 0:e.address1)||"",addressLine2:(null==e?void 0:e.address2)||"",adminArea1:(null==e?void 0:e.stateOrProvinceCode)||(null==e?void 0:e.stateOrProvince)||"",adminArea2:(null==e?void 0:e.city)||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCode:(null==e?void 0:e.countryCode)||""}}mapPayPalToBcAddress(e,t,n,i){const[r,a]=t.fullName.split(" "),o=(null==n?void 0:n.nationalNumber)||"",s=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||r||"",lastName:t.lastName||a||"",company:e.company||"",address1:e.addressLine1,address2:e.addressLine2||"",city:e.adminArea2,stateOrProvince:e.adminArea1,stateOrProvinceCode:e.adminArea1,country:e.countryCode||"",countryCode:e.countryCode||"",postalCode:e.postalCode,phone:s+o,customFields:i||[]}}filterAddresses(e){return e.reduce((e,t)=>t?e.some(e=>this.isEqualAddresses(e,t))?e:[...e,t]:e,[])}isEqualAddresses(e,t){return r(this.normalizeAddress(e),this.normalizeAddress(t))}normalizeAddress(e){return s(e,["id","phone"])}}function Je(){return new Ye}var Ze=Object.defineProperty,Xe=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,tt=(e,t,n)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nt=(e,t)=>{for(var n in t||(t={}))Qe.call(t,n)&&tt(e,n,t[n]);if(Xe)for(var n of Xe(t))et.call(t,n)&&tt(e,n,t[n]);return e},it=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class rt{constructor(e){this.requestSender=e}createOrder(e,t){return it(this,null,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=nt({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return it(this,null,function*(){const t=e,n=nt({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:n,body:t})).body})}getOrderStatus(e="bigcommerce_payments",t){return it(this,null,function*(){const n=`/api/storefront/initialization/${e}`,i=nt({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.get(n,nt({headers:i},t))).body})}}var at=Object.defineProperty,ot=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,dt=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function ct(e){return"string"!=typeof e}function mt(e,t){if(t||e)return function(e){var t,n;const i={},r=l(e.root,ct),a=l(e.input,ct),o=l(e.toggle,ct),s=l(null==(t=e.text)?void 0:t.body,ct),d=l(null==(n=e.text)?void 0:n.caption,ct),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(a).length&&(i.input=a),Object.keys(o).length&&(i.toggle=o),Object.keys(s).length&&(i.text={},i.text.body=s),Object.keys(d).length&&(i.text=((e,t)=>{for(var n in t||(t={}))st.call(t,n)&&dt(e,n,t[n]);if(ot)for(var n of ot(t))lt.call(t,n)&&dt(e,n,t[n]);return e})({},i.text),i.text.caption=d),c&&(i.branding=c),i}(function(e,t){var n,i,r,a,o,s,l,d,c,m,u,h,y,p,g,v,b,P,f,S,_,I;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null==(n=null==t?void 0:t.root)?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null==(i=null==t?void 0:t.root)?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null==(r=null==t?void 0:t.root)?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null==(a=null==t?void 0:t.root)?void 0:a.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null==(o=null==t?void 0:t.root)?void 0:o.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null==(s=null==t?void 0:t.root)?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(l=null==t?void 0:t.input)?void 0:l.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null==(d=null==t?void 0:t.input)?void 0:d.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null==(c=null==t?void 0:t.input)?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null==(m=null==t?void 0:t.input)?void 0:m.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null==(u=null==t?void 0:t.input)?void 0:u.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null==(h=null==t?void 0:t.input)?void 0:h.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null==(y=null==t?void 0:t.toggle)?void 0:y.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null==(p=null==t?void 0:t.toggle)?void 0:p.colorSecondary)},text:{body:{color:(null==e?void 0:e.fastlaneTextBodySettingsColor)||(null==(v=null==(g=null==t?void 0:t.text)?void 0:g.body)?void 0:v.color),fontSize:(null==e?void 0:e.fastlaneTextBodySettingsFontSize)||(null==(P=null==(b=null==t?void 0:t.text)?void 0:b.body)?void 0:P.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(S=null==(f=null==t?void 0:t.text)?void 0:f.caption)?void 0:S.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null==(I=null==(_=null==t?void 0:t.text)?void 0:_.caption)?void 0:I.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function ut(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}function ht(e,t,n=!0){var i;return null!=(i=e[t])?i:n}var yt=(e=>(e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES",e))(yt||{}),pt=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))(pt||{}),gt=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(gt||{}),vt=(e=>(e.pill="pill",e.rect="rect",e))(vt||{}),bt=(e=>(e.OXXO="oxxo",e))(bt||{}),Pt=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(Pt||{}),ft=Object.defineProperty,St=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,Ct=Object.prototype.hasOwnProperty,wt=Object.prototype.propertyIsEnumerable,Ot=(e,t,n)=>t in e?ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,At=(e,t)=>{for(var n in t||(t={}))Ct.call(t,n)&&Ot(e,n,t[n]);if(It)for(var n of It(t))wt.call(t,n)&&Ot(e,n,t[n]);return e},zt=(e,t)=>St(e,_t(t)),Et=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class kt{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsRequestSender=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return Et(this,null,function*(){var t,n;const{methodId:i,bigcommerce_payments_fastlane:r}=e;if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(this.methodId=i,!r)throw new we('Unable to initialize payment because "options.bigcommerce_payments_fastlane" argument is not provided.');if(this.bigcommerce_payments_fastlane=r,!r.onInit||"function"!=typeof r.onInit)throw new we('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onInit" argument is not provided or it is not a function.');if(!r.onChange||"function"!=typeof r.onChange)throw new we('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(i);const a=this.paymentIntegrationService.getState(),o=a.getCartOrThrow(),s=a.getPaymentMethodOrThrow(i),{isDeveloperModeApplicable:l,isFastlaneStylingEnabled:d}=s.initializationData||{};this.threeDSVerificationMethod=null==(t=s.initializationData)?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(s,o.currency.code,o.id);const c=mt(d?null==(n=null==s?void 0:s.initializationData)?void 0:n.fastlaneStyles:{},null==r?void 0:r.styles);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!l,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(i)),yield this.initializePayPalPaymentComponent(),r.onInit(e=>this.renderPayPalPaymentComponent(e)),r.onChange(()=>this.handlePayPalStoredInstrumentChange(i))})}execute(e,t){return Et(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Ct.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&It)for(var i of It(e))t.indexOf(i)<0&&wt.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);const{paymentData:a,methodId:o}=i,s=a&&ke(a);try{yield this.paymentIntegrationService.submitOrder(r,t);const e=s?yield this.prepareVaultedInstrumentPaymentPayload(o,a):yield this.preparePaymentPayload(o,a);yield this.paymentIntegrationService.submitPayment(e),this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()}catch(e){if(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"response"in e&&"name"in e.response}(e)&&"INVALID_REQUEST"===e.response.name){const e={translationKey:"payment.errors.invalid_request_error"};return this.handleError(e),Promise.reject()}if(e instanceof Error&&"FastlaneError"!==e.name)throw e;return Promise.reject()}})}finalize(){return Promise.reject(new ze)}deinitialize(){return Et(this,null,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=ut(i)?i:{},a=this.bigCommercePaymentsFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===$e.CANCELED||(null==r?void 0:r.authenticationState)||a!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return Et(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getCustomer(),r=t.getBillingAddress(),a=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:o}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(a),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(o),{authenticationState:l,addresses:d,instruments:c}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:l,addresses:d,instruments:c}),s.authenticationState===$e.CANCELED?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return Et(this,null,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),i=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),r={fields:At({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield i.FastlaneCardComponent(r)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new we('Unable to render card component because "container" argument is not provided.');t.render(e)}getPayPalComponentMethodsOrThrow(){if(!this.paypalComponentMethods)throw new c;return this.paypalComponentMethods}prepareVaultedInstrumentPaymentPayload(e,t){return Et(this,null,function*(){const{instrumentId:n}=t,i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),r=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&i.config.is3dsEnabled?yield this.get3DSNonce(n):n;return yield this.createOrder(r),{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:r}}}}})}preparePaymentPayload(e,t){return Et(this,null,function*(){const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getPaymentMethodOrThrow(e),a=`${i.firstName} ${i.lastName}`.trim(),{getPaymentToken:o}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield o({name:{fullName:a},billingAddress:this.bigCommercePaymentsFastlaneUtils.mapBcToPayPalAddress(i)}),l=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&r.config.is3dsEnabled,{shouldSaveInstrument:d=!1,shouldSetAsDefaultInstrument:c=!1}=Ee(t)?t:{},m=l?yield this.get3DSNonce(s):s;return yield this.createOrder(m),{methodId:e,paymentData:zt(At({},t),{shouldSaveInstrument:d,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:m}}})}})}createOrder(e){return Et(this,null,function*(){const t=this.paymentIntegrationService.getState().getCartOrThrow().id;if(this.methodId){const{orderId:n}=yield this.bigCommercePaymentsRequestSender.createOrder(this.methodId,{cartId:t,fastlaneToken:e});this.orderId=n}})}get3DSNonce(e){return Et(this,null,function*(){var t;const n=this.paymentIntegrationService.getState(),i=n.getCartOrThrow(),r=n.getOrderOrThrow(),a=n.getStoreConfigOrThrow().links.checkoutLink,o=null==(t=this.paypalFastlaneSdk)?void 0:t.ThreeDomainSecureClient;if(!o)throw new c;const s={amount:r.orderAmount.toFixed(2),currency:i.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===Ke.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},l=yield o.isEligible(s);if(this.threeDSVerificationMethod===Ke.Always&&!l)throw new Ae;if(l){const{liabilityShift:e,authenticationState:t,nonce:n}=yield o.show();if(e===yt.No||e===yt.Unknown||t===He.Errored||t===He.Cancelled)throw new Ae;if(t===He.Succeeded&&[yt.Yes,yt.Possible].includes(e))return n}return e})}handlePayPalStoredInstrumentChange(e){return Et(this,null,function*(){const t=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=ut(t)?t:{},r=this.bigCommercePaymentsFastlaneUtils.mapPayPalToBcInstrument(e,i)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(zt(At({},n),{instruments:[r]})),r}})}isBigcommercePaymentsFastlaneThreeDSAvailable(){return ht(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.bcp_fastlane_three_ds")}handleError(e){var t;(null==(t=this.bigcommerce_payments_fastlane)?void 0:t.onError)&&"function"==typeof this.bigcommerce_payments_fastlane.onError&&this.bigcommerce_payments_fastlane.onError(e)}handleErrorLog(e){var t;(null==(t=this.bigcommerce_payments_fastlane)?void 0:t.onErrorLog)&&"function"==typeof this.bigcommerce_payments_fastlane.onErrorLog&&this.bigcommerce_payments_fastlane.onErrorLog(e)}}const Tt=C(e=>{const{getHost:t}=e.getState();return new kt(e,new rt(i({host:t()})),I(),Je())},[{id:"bigcommerce_payments_fastlane"}]);var Bt=Object.defineProperty,Mt=Object.getOwnPropertySymbols,Ft=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable,Nt=(e,t,n)=>t in e?Bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xt=(e,t)=>{for(var n in t||(t={}))Ft.call(t,n)&&Nt(e,n,t[n]);if(Mt)for(var n of Mt(t))Dt.call(t,n)&&Nt(e,n,t[n]);return e},Ut=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class jt{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=n,this.bigCommercePaymentsScriptLoader=i}loadPayPalSdk(e,t,n,i){return Ut(this,null,function*(){const r=this.paymentIntegrationService.getState(),a=t||r.getCartOrThrow().currency.code,o=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(o,a,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return Ut(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(m.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new L}})}createOrder(e,t){return Ut(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.bigCommercePaymentsRequestSender.createOrder(e,xt({cartId:n},t));return i})}createOrderCardFields(e,t){return Ut(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.bigCommercePaymentsRequestSender.createOrder(e,xt({cartId:n},t));return xt({orderId:i},r?{setupToken:r}:{})})}updateOrder(e){return Ut(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow();let i;e||(i=t.getConsignmentsOrThrow()[0]);try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:e?[]:null==i?void 0:i.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:null==i?void 0:i.selectedShippingOption})}catch(e){throw new G}})}getOrderStatus(e,t){return Ut(this,null,function*(){try{const{status:n}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return n}catch(e){throw new G}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(m.MissingOrderId);return this.formPoster.postForm("/checkout.php",xt({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===W.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return Ut(this,null,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(xt({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.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.phone_number)?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[a,...o]=r.split(" ");return this.getAddress({firstName:a,lastName:o.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&&gt[t]?t:void 0,height:this.getValidHeight(n),label:i&&pt[i]?i:void 0,shape:r&&vt[r]?r:void 0};return l(o,a)}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 Vt=Object.defineProperty,Lt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,Wt=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable,Ht=(e,t,n)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$t=(e,t)=>{for(var n in t||(t={}))Wt.call(t,n)&&Ht(e,n,t[n]);if(Gt)for(var n of Gt(t))Kt.call(t,n)&&Ht(e,n,t[n]);return e},qt=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Yt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return qt(this,null,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e,t=!1){return qt(this,null,function*(){if(!this.window.bigCommercePaymentsPayPalSDK||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.bigCommercePaymentsPayPalSDK)throw new c;return this.window.bigCommercePaymentsPayPalSDK})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:a}=e;if(!(null==a?void 0:a.clientId))throw new u(m.MissingPaymentMethod);const{intent:o,clientId:s,merchantId:l,buyerCountry:d,attributionId:c,isVenmoEnabled:h,isHostedCheckoutEnabled:y,isPayPalCreditAvailable:p,isDeveloperModeApplicable:g,availableAlternativePaymentMethods:v=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:P}=a,f=y||n,S="bigcommerce_payments_creditcards"===i,_=S?["card"]:[],I=S?[]:["card"],C=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],O=h?["venmo"]:[],A=h?[]:["venmo"],z=v.filter(e=>!b.includes(e)),E=P?["googlepay"]:[],k=n?["card-fields"]:[],T=this.filterFundingOptions([...I,...w,...A,...z]),B=this.filterFundingOptions([..._,...C,...O,...b]);return{options:$t({"client-id":s,"merchant-id":l,"enable-funding":B.length>0?B:void 0,"disable-funding":T.length>0?T:void 0,commit:f,components:["buttons","hosted-fields","payment-fields","legal",...E,...k],currency:t,intent:o},g&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"bigCommercePaymentsPayPalSDK"}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];var r,a;null==i||""===i||Array.isArray(i)&&0===i.length||(r=$t({},t),a={[n]:Array.isArray(i)?i.join(","):i},t=Lt(r,Rt(a)))}),t}}const Jt=e=>{const{getHost:r}=e.getState();return new jt(n(),e,new rt(i({host:r()})),new Yt(t()))};class Zt extends d{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Xt=Object.getOwnPropertySymbols,Qt=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,tn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class nn{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.paypalSdkHelper=i}initialize(e){return tn(this,null,function*(){const{methodId:t,bigcommerce_payments_paylater:n}=e||{};if(!t)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:a=[],orderId:o}=r.initializationData||{},{bannerContainerId:s,container:l}=n;if(void 0!==s){if(!document.getElementById(s))return void console.error("Unable to create banner without valid banner container ID.");const e=a&&a.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return this.renderMessages(t,s,e)}o?this.orderId=o:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==l?void 0:l.split("#")[1],this.renderButton(t,n))})}execute(e,t){return tn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Qt.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Xt)for(var i of Xt(e))t.indexOf(i)<0&&en.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new Ae;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.bigCommercePaymentsButtons)||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new we('Unable to initialize payment because "container" argument is not provided.');const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:a}=r||{},{container:o,onError:s,onRenderButton:l,onValidate:d,submitForm:c}=t,m=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let u=!1;m.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(a),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.bigCommercePaymentsButtons=n.Buttons(t),this.bigCommercePaymentsButtons.isEligible()||e!==n.FUNDING.PAYLATER){if(!this.bigCommercePaymentsButtons.isEligible()&&e===n.FUNDING.CREDIT)throw new Zt(`BigCommercePayments ${e} is not available for your region. Please use BigCommercePayments Checkout instead.`);l&&"function"==typeof l&&l(),this.bigCommercePaymentsButtons.render(o),u=!0}})}handleClick(e,t){return tn(this,null,function*(){const{resolve:n,reject:i}=e;t&&"function"==typeof t&&(yield t(()=>(this.toggleLoadingIndicator(!0),n()),i))})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:Ce(n)};e.Messages(i).render(`#${t}`)}}const rn=C(e=>new nn(e,Jt(e),new _e({containerStyles:Ie}),I()),[{id:"bigcommerce_payments_paylater"}]);class an extends G{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var on=Object.getOwnPropertySymbols,sn=Object.prototype.hasOwnProperty,ln=Object.prototype.propertyIsEnumerable,dn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class cn{constructor(e,t,n,i=3e3,r=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.pollingInterval=i,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=o}initialize(e){return dn(this,null,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_ratepay:i}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_payments_ratepay" argument is not provided.');const{legalTextContainer:r,container:a,loadingContainerId:o}=i;if(!a)throw new we('Unable to initialize payment because "options.container" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!o)throw new we('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=o;const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:l}=s.initializationData||{};if(!l)throw new we("Unable to initialize payment because merchantId argument is not provided.");this.bigcommerce_payments_ratepay=i,yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n),this.createFraudNetScript(l,n,t),this.loadFraudnetConfig(),this.renderLegalText(r,a)})}execute(e,t){return dn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)sn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&on)for(var i of on(e))t.indexOf(i)<0&&ln.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{getFieldsValues:a}=this.bigcommerce_payments_ratepay||{};if(!i)throw new Oe(["payment"]);if(!a||"function"!=typeof a)throw new we('Unable to initialize payment because "options.getFieldsValues" argument is not provided.');this.toggleLoadingIndicator(!0);try{const e=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apmscheckout",{metadataId:this.guid}),{ratepayBirthDate:n,ratepayPhoneNumber:o,ratepayPhoneCountryCode:s}=a(),l={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:i.methodId,rate_pay:{birth_date:this.normalizeDate(n),phone:{national_number:o,country_code:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment({methodId:i.methodId,paymentData:l}),yield new Promise((e,t)=>{this.initializePollingMechanism(i.methodId,e,t,i.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new ze)}deinitialize(){const{legalTextContainer:e}=this.bigcommerce_payments_ratepay||{},t=document.querySelectorAll('[data-id="fraudnetScript"]')[0],n=document.querySelectorAll('[data-id="fraudnetConfig"]')[0];if(this.deinitializePollingMechanism(),t.remove(),n.remove(),e){const t=document.getElementById(e);null==t||t.remove()}return Promise.resolve()}normalizeDate(e){const t=this.formatDate(e.getDate()),n=this.formatDate(e.getMonth()+1);return`${e.getFullYear()}-${n}-${t}`}formatDate(e){return`${e<10?0:""}${e}`}renderLegalText(e,t){const n=e,i=t.split("#")[1],r=document.getElementById(i),a=null==r?void 0:r.parentNode,o=document.createElement("div");o.style.marginBottom="20px",o.setAttribute("id",n),null==a||a.prepend(o);const s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new we('Unable to initialize payment because "legalTextContainerElement" argument is not found.');l.render(`#${n}`)}handleError(e){const{onError:t}=this.bigcommerce_payments_ratepay||{};this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createFraudNetScript(e,t,n){const i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:r}=i.config,a=document.createElement("script");a.setAttribute("type","application/json"),a.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),a.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const o={f:this.guid,s:`${e}_checkout-page`,sandbox:r};a.innerHTML=JSON.stringify(o),document.body.appendChild(a)}generateGUID(){let e="";for(let t=0;t<32;t+=1)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(62*Math.random())];return e}loadFraudnetConfig(){const e=document.createElement("script");e.setAttribute("data-id","fraudnetConfig"),e.src="https://c.paypal.com/da/r/fb.js",document.body.appendChild(e)}reinitializeStrategy(e){return dn(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return dn(this,null,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus("bigcommerce_payments_apms",{params:{useMetadata:!0}}),a=r===Pt.PollingStop,o=r===Pt.PollingError;if(a)return this.deinitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigcommerce_payments_ratepay:this.bigcommerce_payments_ratepay}),this.handleError(new an)}catch(e){this.handleError(e),n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}var mn=Object.defineProperty,un=Object.defineProperties,hn=Object.getOwnPropertyDescriptors,yn=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,gn=Object.prototype.propertyIsEnumerable,vn=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))pn.call(t,n)&&vn(e,n,t[n]);if(yn)for(var n of yn(t))gn.call(t,n)&&vn(e,n,t[n]);return e};const Pn=C(e=>{return new cn(e,Jt(e),new _e({containerStyles:(t=bn({},Ie),n={position:"fixed"},un(t,hn(n)))}));var t,n},[{gateway:"bigcommerce_payments_apms",id:"ratepay"}]);var fn=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification",e))(fn||{});const Sn=fn;function _n(e){return Sn.CardNumber in e&&Sn.CardName in e&&Sn.CardExpiry in e}function In(e){return Sn.CardNumberVerification in e&&Sn.CardCodeVerification in e&&Sn.CardExpiryVerification in e}class Cn extends d{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 wn=(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",e))(wn||{});class On extends d{constructor(e){super(function(e){switch(e){case 1:return"Unable to proceed because the customer step of checkout has not been initialized.";case 2:return"Unable to proceed because the payment step of checkout has not been initialized.";case 3:return"Unable to proceed because the shipping step of checkout has not been initialized.";case 4: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 An extends d{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"}}var zn=Object.defineProperty,En=Object.defineProperties,kn=Object.getOwnPropertyDescriptors,Tn=Object.getOwnPropertySymbols,Bn=Object.prototype.hasOwnProperty,Mn=Object.prototype.propertyIsEnumerable,Fn=(e,t,n)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dn=(e,t)=>{for(var n in t||(t={}))Bn.call(t,n)&&Fn(e,n,t[n]);if(Tn)for(var n of Tn(t))Mn.call(t,n)&&Fn(e,n,t[n]);return e},Nn=(e,t)=>En(e,kn(t)),xn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Un{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return xn(this,null,function*(){const{methodId:t,bigcommerce_payments_creditcards:n}=e,i=n,{form:r,onCreditCardFieldsRenderingError:a,onLoadComplete:o}=i||{};if(!t)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to proceed because "options.bigcommerce_payments_creditcards.form" argument is not provided.');this.hostedFormOptions=r,this.isCreditCardForm=_n(r.fields),this.isCreditCardVaultedForm=In(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,a)),null==o||o(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return xn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Bn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Tn)for(var i of Tn(e))t.indexOf(i)<0&&Mn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{methodId:a,paymentData:o}=i||{};if(!i||!a)throw new Oe(["payment"]);if(this.executionPaymentData=o,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const s=this.preparePaymentPayload(a,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(s)})}finalize(){return Promise.reject(new ze)}deinitialize(){return xn(this,null,function*(){var e,t,n,i;return yield null==(e=this.cvvField)?void 0:e.close(),yield null==(t=this.expiryField)?void 0:t.close(),yield null==(n=this.numberField)?void 0:n.close(),yield null==(i=this.nameField)?void 0:i.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,i){const{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:o=!1}=Ee(t)?t:{},s=t&&ke(t)?t.instrumentId:void 0,d=l({verification_nonce:i,token:s},a);return{methodId:e,paymentData:{shouldSaveInstrument:r,shouldSetAsDefaultInstrument:o,instrumentId:s,formattedPayload:Dn(Dn({},i||s?{bigpay_token:d}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return xn(this,null,function*(){const{fields:n,styles:i}=e,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.getExecuteCallback(n),o=Dn({style:this.getInputStyles(i),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===yt.No||n===yt.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Cn},inputEvents:{onChange:t=>this.onChangeHandler(e,t),onFocus:t=>this.onFocusHandler(e,t),onBlur:t=>this.onBlurHandler(e,t),onInputSubmitRequest:t=>this.onInputSubmitRequest(e,t)}},a);if(this.cardFields=yield r.CardFields(o),!this.cardFields.isEligible())throw new On(wn.PaymentNotInitialized);try{this.stylizeInputContainers(n),_n(n)&&(yield this.renderFields(n)),In(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return In(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>xn(this,null,function*(){const{setupToken:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",Nn(Dn({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>xn(this,null,function*(){const{orderId:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams()))||{};return e})}}handleApprove({orderID:e,vaultSetupToken:t}){e&&(this.returnedOrderId=e),t&&(this.returnedVaultedToken=t)}renderFields(e){return xn(this,null,function*(){var t,n,i,r;const a=this.getCardFieldsOrThrow();(null==(t=e.cardCode)?void 0:t.containerId)&&(this.cvvField=a.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null==(n=e.cardExpiry)?void 0:n.containerId)&&(this.expiryField=a.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null==(i=e.cardName)?void 0:i.containerId)&&(this.nameField=a.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null==(r=e.cardNumber)?void 0:r.containerId)&&(this.numberField=a.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return xn(this,null,function*(){var t,n,i;const r=this.getCardFieldsOrThrow();(null==(t=e.cardCodeVerification)?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null==(n=e.cardExpiryVerification)?void 0:n.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null==(i=e.cardNumberVerification)?void 0:i.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(Ee(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(ke(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return xn(this,null,function*(){const e=this.getCardFieldsOrThrow(),t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n={billingAddress:{company:t.company,addressLine1:t.address1,addressLine2:t.address2,adminArea1:t.stateOrProvinceCode,adminArea2:t.city,postalCode:t.postalCode,countryCode:t.countryCode}};try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){throw new Cn("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return xn(this,null,function*(){var e,t;const n=this.getCardFieldsOrThrow(),i=yield n.getState().then(e=>e),r=this.getValidityData(i);if(!r.isValid)throw null==(t=null==(e=this.hostedFormOptions)?void 0:e.onValidate)||t.call(e,r),new An(this.mapValidationErrors(r.errors))})}getValidityData({fields:e}){const t=Dn({},e);delete t.cardNameField;const n=Object.keys(t);return{isValid:n.every(e=>{var n;return null==(n=t[e])?void 0:n.isValid}),errors:n.reduce((e,n)=>{var i;const r=this.mapFieldType(n);return Nn(Dn({},e),{[r]:(null==(i=t[n])?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case Sn.CardCode:case Sn.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case Sn.CardNumber:case Sn.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case Sn.CardExpiry:case Sn.CardExpiryVerification:return{fieldType:e,message:"Invalid card expiry",type:"invalid_card_expiry"};default:return{fieldType:e,message:"Invalid field",type:"invalid"}}}mapValidationErrors(e={}){const t={};return Object.keys(e).forEach(n=>{var i,r;t[n]=[{message:(null==(r=null==(i=e[n])?void 0:i[0])?void 0:r.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return Sn.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?Sn.CardNumber:Sn.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?Sn.CardExpiry:Sn.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?Sn.CardCode:Sn.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new On(wn.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,i;const r={"font-size":(null==(t=null==e?void 0:e.default)?void 0:t.fontSize)||"1rem","font-family":(null==(n=null==e?void 0:e.default)?void 0:n.fontFamily)||"Montserrat, Arial, Helvetica, sans-serif","font-weight":(null==(i=null==e?void 0:e.default)?void 0:i.fontWeight)||"400",outline:"none",padding:"9px 13px"},a=Nn(Dn({},r),{color:"#333333"});return{input:a,".invalid":Nn(Dn({},r),{color:"red"}),".valid":a,":focus":a}}stylizeInputContainers(e){Object.values(e||{}).forEach(e=>{const t=document.getElementById(`${(null==e?void 0:e.containerId)||""}`);t&&(t.style.padding="0px",t.style.boxShadow="none",t.style.border="none",t.style.background="transparent",t.style.marginBottom="10px",t.style.marginLeft="-5px")})}hasUndefinedValues(){return!this.hostedFormOptions||Object.values(this.hostedFormOptions.fields).some(e=>void 0===e)}onChangeHandler(e,t){var n;null==(n=null==e?void 0:e.onValidate)||n.call(e,this.getValidityData(t))}onFocusHandler(e,t){var n;null==(n=null==e?void 0:e.onFocus)||n.call(e,this.getFieldTypeByEmittedField(t))}onBlurHandler(e,t){var n;null==(n=null==e?void 0:e.onBlur)||n.call(e,this.getFieldTypeByEmittedField(t))}onInputSubmitRequest(e,t){var n;null==(n=null==e?void 0:e.onEnter)||n.call(e,this.getFieldTypeByEmittedField(t))}shouldInitializePayPalFastlane(e){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(e),a=i.getPaymentProviderCustomer(),o=(s=a)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?a:{};var s;return(null==(t=null==r?void 0:r.initializationData)?void 0:t.isAcceleratedCheckoutEnabled)&&(null==(n=null==r?void 0:r.initializationData)?void 0:n.isBigCommercePaymentsAnalyticsV2Enabled)&&!(null==o?void 0:o.authenticationState)}initializePayPalFastlaneOrThrow(e){return xn(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{initializationData:r}=i;if(!(null==r?void 0:r.connectClientToken))return;const a=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(i,n.currency.code,n.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(a,!!(null==r?void 0:r.isDeveloperModeApplicable))}catch(e){}})}}const jn=C(e=>new Un(e,Jt(e),I(),Je()),[{id:"bigcommerce_payments_creditcards"}]);var Vn=Object.getOwnPropertySymbols,Ln=Object.prototype.hasOwnProperty,Rn=Object.prototype.propertyIsEnumerable,Gn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Wn{constructor(e){this.paymentIntegrationService=e}initialize(){return Gn(this,null,function*(){return Promise.resolve()})}execute(e,t){return Gn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Ln.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Vn)for(var i of Vn(e))t.indexOf(i)<0&&Rn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{methodId:a}=i||{};if(!i||!a)throw new Oe(["payment"]);const o={methodId:a,paymentData:{formattedPayload:{}}};yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(o)})}finalize(){return Promise.reject(new ze)}deinitialize(){return Promise.resolve()}}const Kn=C(e=>new Wn(e),[{id:"bigcommerce_payments_invoices"}]);var Hn=Object.getOwnPropertySymbols,$n=Object.prototype.hasOwnProperty,qn=Object.prototype.propertyIsEnumerable,Yn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Jn{constructor(e,t,n,i,r=3e3,a=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdkHelper=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=a,this.pollingTimer=0,this.stopPolling=o,this.isPollingEnabled=!1}initialize(e){return Yn(this,null,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');const r=this.paymentIntegrationService.getState(),a=r.getPaymentMethodOrThrow(n,t),{orderId:o,shouldRenderFields:s}=a.initializationData||{},l=r.getStoreConfigOrThrow().checkoutSettings.features;this.isPollingEnabled=ht(l,"PAYPAL-5624.bcp_ideal_polling"),o?this.orderId=o:(this.paypalApms=yield this.bigCommercePaymentsSdkHelper.getPayPalApmsSdk(a,r.getCartOrThrow().currency.code),this.loadingIndicatorContainer=i.container.split("#")[1],this.renderButton(n,t,i),s&&this.renderFields(n,i))})}execute(e,t){return Yn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)$n.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Hn)for(var i of Hn(e))t.indexOf(i)<0&&qn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);const{methodId:a,gatewayId:o}=i;if(!this.orderId)throw new Ae;this.isPollingEnabled&&"ideal"===a&&(yield new Promise((e,t)=>{this.initializePollingMechanism(a,e,t,o)})),this.isNonInstantPaymentMethod(a)||(yield this.paymentIntegrationService.submitOrder(r,t)),yield this.bigCommercePaymentsIntegrationService.submitPayment(a,this.orderId,o)})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,this.isPollingEnabled&&this.resetPollingMechanism(),null==(e=this.bigCommercePaymentsButton)||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,i){return Yn(this,null,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus(i),a=r===Pt.Approved,o=r===Pt.PollingError;if(a)return this.deInitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigCommercePaymentsAlternativeMethods:this.bigCommercePaymentsAlternativeMethods}),this.handleError(new an)}catch(e){n()}})}deInitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deInitializePollingMechanism()}reinitializeStrategy(e){return Yn(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderButton(e,t,n){const i=this.getPaypalAmpsSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:a}=r.initializationData||{},{container:o,onError:s,onRenderButton:l,submitForm:d}=n,c={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(a),onInit:(e,t)=>n.onInitButton(t),createOrder:()=>this.onCreateOrder(e,t,n),onApprove:e=>this.handleApprove(e,d),onCancel:()=>{this.toggleLoadingIndicator(!1),this.deInitializePollingMechanism()},onError:e=>{this.deInitializePollingMechanism(),this.handleFailure(e,s)},onClick:(e,t)=>Yn(this,null,function*(){return n.onValidate(t.resolve,t.reject)})};this.bigCommercePaymentsButton=i.Buttons(c),this.bigCommercePaymentsButton.isEligible()&&(l&&"function"==typeof l&&l(),this.bigCommercePaymentsButton.render(o))}onCreateOrder(e,t,n){return Yn(this,null,function*(){const{onValidate:i}=n;yield i(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),o);const r=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms");if(this.isNonInstantPaymentMethod(e)){const n={useStoreCredit:!1},i={params:{methodId:e,gatewayId:t}};yield this.paymentIntegrationService.submitOrder(n,i),yield this.bigCommercePaymentsIntegrationService.submitPayment(e,r,t)}return r})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const n=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState(),{firstName:r,lastName:a,email:o}=i.getBillingAddressOrThrow(),{apmFieldsContainer:s,apmFieldsStyles:l}=t;if(!s)throw new we('Unable to initialize payment because "options.bigcommerce_payments_apms" argument should contain "apmFieldsContainer".');const d=document.querySelector(s);d&&(d.innerHTML="");const c={fundingSource:e,style:l||{},fields:{name:{value:`${r} ${a}`},email:{value:o}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in bt}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const Zn=C(e=>new Jn(e,Jt(e),I(),new _e({containerStyles:Ie})),[{gateway:"bigcommerce_payments_apms"}]);var Xn=Object.getOwnPropertySymbols,Qn=Object.prototype.hasOwnProperty,ei=Object.prototype.propertyIsEnumerable;class ti{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.gatewayId" argument is not provided.');return Promise.resolve()}execute(e,t){return n=this,i=function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Qn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Xn)for(var i of Xn(e))t.indexOf(i)<0&&ei.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);const{methodId:a,gatewayId:o}=i;try{const e={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:a,paypal_account:{order_id:yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms",{gatewayId:"bigcommerce_payments_apms",methodId:a})}}};yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment({methodId:a,gatewayId:o,paymentData:e})}catch(e){if(function(e){var t,n;return(e=>"object"==typeof e&&null!==e&&"body"in e)(e)&&(null==(n=null==(t=e.body)?void 0:t.additional_action_required)?void 0:n.data.redirect_url)}(e)){const t=e.body.additional_action_required.data.redirect_url;return new Promise((e,n)=>{window.location.replace(t),n()})}return this.handleError(e),Promise.reject(e)}},new Promise((e,t)=>{var r=e=>{try{o(i.next(e))}catch(e){t(e)}},a=e=>{try{o(i.throw(e))}catch(e){t(e)}},o=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,a);o((i=i.apply(n,null)).next())});var n,i}finalize(){return Promise.reject(new ze)}deinitialize(){return Promise.resolve()}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};t&&"function"==typeof t&&t(e)}}const ni=C(e=>new ti(e,Jt(e)),[{gateway:"bigcommerce_payments_apms",id:"klarna"},{gateway:"bigcommerce_payments_apms",id:"afterpay"}]);var ii=Object.getOwnPropertySymbols,ri=Object.prototype.hasOwnProperty,ai=Object.prototype.propertyIsEnumerable,oi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class si{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n}initialize(e){return oi(this,null,function*(){var t,n;const{methodId:i,bigcommerce_payments_venmo:r}=e||{};if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i);(null==(t=a.initializationData)?void 0:t.orderId)?this.orderId=null==(n=a.initializationData)?void 0:n.orderId:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i),this.loadingIndicatorContainer=r.container.split("#")[1],this.renderButton(i,r))})}execute(e,t){return oi(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)ri.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&ii)for(var i of ii(e))t.indexOf(i)<0&&ai.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new Ae;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}renderButton(e,t){const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:a}=r||{},{container:o,onError:s,onRenderButton:l,onValidate:d,submitForm:c}=t,m={fundingSource:n.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(a),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmocheckout"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=n.Buttons(m),!this.paypalButton.isEligible())throw new Zt("Venmo is not available for your region. Please another payment method instead.");l&&"function"==typeof l&&l(),this.paypalButton.render(o)}handleClick(e,t){return oi(this,null,function*(){const{resolve:n,reject:i}=e;yield t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t(),this.toggleLoadingIndicator(!1)}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const li=C(e=>new si(e,Jt(e),new _e({styles:{backgroundColor:"black"}})),[{id:"bigcommerce_payments_venmo"}]);var di=Object.defineProperty,ci=Object.defineProperties,mi=Object.getOwnPropertyDescriptors,ui=Object.getOwnPropertySymbols,hi=Object.prototype.hasOwnProperty,yi=Object.prototype.propertyIsEnumerable,pi=(e,t,n)=>t in e?di(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gi=(e,t)=>{for(var n in t||(t={}))hi.call(t,n)&&pi(e,n,t[n]);if(ui)for(var n of ui(t))yi.call(t,n)&&pi(e,n,t[n]);return e},vi=(e,t)=>ci(e,mi(t)),bi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Pi{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=o}initialize(e){return bi(this,null,function*(){const{bigcommerce_payments:t,methodId:n}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(!t.container)throw new we('Unable to initialize payment because "options.bigcommerce_payments.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new we('Unable to initialize payment because "options.bigcommerce_payments.onClick" argument is not a function.');this.onError=t.onError||o,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return bi(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return bi(this,null,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i,onComplete:r}=t,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:l,isServerSideShippingCallbacksEnabled:d}=o.initializationData||{},{checkoutTopButtonStyles:c}=l||{},m=gi({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),u=vi(gi({},!d&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,r,d)}),h=gi(gi({fundingSource:a.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(vi(gi({},c),{height:40}))},m),s&&u),y=a.Buttons(h);y.isEligible()?y.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i,r){return bi(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow();try{const o=a.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),o){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}o&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return bi(this,null,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){this.handleError(e)}})}onShippingOptionsChange(e){return bi(this,null,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const fi=C(e=>new Pi(e,Jt(e)),[{id:"bigcommerce_payments"}]);var Si=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class _i{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsSdk=t,this.bigCommercePaymentsFastlaneUtils=n}initialize(e){return Si(this,null,function*(){var t;const{methodId:n,bigcommerce_payments_fastlane:i}=e;if(this.options=e,!n)throw new we('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),r=e.getCartOrThrow(),a=e.getPaymentMethodOrThrow(n),o=!!(null==(t=a.initializationData)?void 0:t.isDeveloperModeApplicable),s=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(a,r.currency.code,r.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(s,o,this.getFastlaneStyles(n,i))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Si(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Si(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t),yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:void 0,addresses:void 0,instruments:void 0}),this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()})}signOut(e){return Si(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Si(this,null,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:i}=e||{};if(!i)throw new we('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new we('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');if(this.paymentIntegrationService.getState().getCustomerOrThrow().isGuest){t&&"function"==typeof t&&t();try{yield this.runPayPalAuthenticationFlowOrThrow(i)}catch(e){this.handleErrorLog(e)}}n()})}runPayPalAuthenticationFlowOrThrow(e){return Si(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,i=t.getCustomer(),r=t.getBillingAddress(),a=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:o}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(a),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(o),l=s.authenticationState===$e.CANCELED;yield this.updateCustomerDataState(e,s),l?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Si(this,null,function*(){var n;const i=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:r,addresses:a,billingAddress:o,shippingAddress:s,instruments:l}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:r,addresses:a,instruments:l}),o&&(yield this.paymentIntegrationService.updateBillingAddress(o)),s&&i.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),i=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:r}=i.initializationData||{},a=(null==(n=(t.getConsignments()||[])[0])?void 0:n.availableShippingOptions)||[],o=a[0],l=a.find(e=>e.isRecommended);if((l||o)&&r){const e=(null==l?void 0:l.id)||o.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:i,isFastlaneStylingEnabled:r}=n.initializationData||{};return mt(r?i:{},null==t?void 0:t.styles)}handleErrorLog(e){const{onErrorLog:t}=this.options||{};t&&"function"==typeof t&&t(e)}}const Ii=C(e=>new _i(e,I(),Je()),[{id:"bigcommerce_payments_fastlane"},{id:"bigcommerce_payments_creditcards"}]);var Ci=Object.defineProperty,wi=Object.defineProperties,Oi=Object.getOwnPropertyDescriptors,Ai=Object.getOwnPropertySymbols,zi=Object.prototype.hasOwnProperty,Ei=Object.prototype.propertyIsEnumerable,ki=(e,t,n)=>t in e?Ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ti=(e,t)=>{for(var n in t||(t={}))zi.call(t,n)&&ki(e,n,t[n]);if(Ai)for(var n of Ai(t))Ei.call(t,n)&&ki(e,n,t[n]);return e},Bi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Mi{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=o}initialize(e){return Bi(this,null,function*(){const{bigcommerce_payments_paylater:t,methodId:n}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(!t.container)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.onClick" argument is not a function.');this.onError=t.onError||o,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC BigCommercePayments PayLater]: button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Bi(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Bi(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onComplete:i,onClick:r}=t,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:l}=o.initializationData||{},{checkoutTopButtonStyles:d}=l||{},c=Ti({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()}),m={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,i)},u=[a.FUNDING.PAYLATER,a.FUNDING.CREDIT];let h=!1;u.forEach(e=>{if(!h){const r=Ti(Ti({fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((t=Ti({},d),i={height:40},wi(t,Oi(i))))},c),s&&m),o=a.Buttons(r);o.isEligible()&&(o.render(`#${n}`),h=!0)}var t,i}),h||this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i){return Bi(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),a=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(a);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(a);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return Bi(this,null,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){this.handleError(e)}})}onShippingOptionsChange(e){return Bi(this,null,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const Fi=C(e=>new Mi(e,Jt(e)),[{id:"bigcommerce_payments_paylater"}]);var Di=Object.defineProperty,Ni=Object.defineProperties,xi=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,ji=Object.prototype.hasOwnProperty,Vi=Object.prototype.propertyIsEnumerable,Li=(e,t,n)=>t in e?Di(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ri=(e,t)=>{for(var n in t||(t={}))ji.call(t,n)&&Li(e,n,t[n]);if(Ui)for(var n of Ui(t))Vi.call(t,n)&&Li(e,n,t[n]);return e},Gi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Wi{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Gi(this,null,function*(){const{bigcommerce_payments_venmo:t,methodId:n}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(!t.container)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC Payments Venmo]: Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Gi(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Gi(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i}=t,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:o}=a.initializationData||{},{checkoutTopButtonStyles:s}=o||{},l=Ri({fundingSource:r.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((d=Ri({},s),c={height:40},Ni(d,xi(c)))),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()});var d,c;const m=r.Buttons(l);m.isEligible()?m.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}}const Ki=C(e=>new Wi(e,Jt(e)),[{id:"bigcommerce_payments_venmo"}]);var Hi=Object.defineProperty,$i=Object.defineProperties,qi=Object.getOwnPropertyDescriptors,Yi=Object.getOwnPropertySymbols,Ji=Object.prototype.hasOwnProperty,Zi=Object.prototype.propertyIsEnumerable,Xi=(e,t,n)=>t in e?Hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qi=(e,t)=>{for(var n in t||(t={}))Ji.call(t,n)&&Xi(e,n,t[n]);if(Yi)for(var n of Yi(t))Zi.call(t,n)&&Xi(e,n,t[n]);return e},er=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class tr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return er(this,null,function*(){var t;const{bigcommerce_payments:n,containerId:i,methodId:r}=e,a=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(a&&!n.currencyCode)throw new we('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==(t=n.buyNowInitializeOptions)?void 0:t.getBuyNowCartRequestBody))throw new we('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const o=a?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(r,o,!1),this.renderButton(i,r,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:a,onEligibilityFailure:o}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},m={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},u={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h=(y=Qi({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),$i(y,qi({onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,a,c)})));var y;const p=Qi(Qi(Qi({fundingSource:s.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},m),i&&u),d&&h),g=s.Buttons(p);g.isEligible()?g.render(`#${e}`):o&&"function"==typeof o?o():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return er(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i,r){return er(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow();try{const o=a.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),o){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}return o&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),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 er(this,null,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 er(this,null,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 nr=C(e=>new tr(e,Jt(e)),[{id:"bigcommerce_payments"}]);var ir=Object.defineProperty,rr=Object.getOwnPropertySymbols,ar=Object.prototype.hasOwnProperty,or=Object.prototype.propertyIsEnumerable,sr=(e,t,n)=>t in e?ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lr=(e,t)=>{for(var n in t||(t={}))ar.call(t,n)&&sr(e,n,t[n]);if(rr)for(var n of rr(t))or.call(t,n)&&sr(e,n,t[n]);return e},dr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class cr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return dr(this,null,function*(){const{bigcommerce_payments_paylater:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:a}=t||{},o=!!r;if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(o&&!a)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=this.paymentIntegrationService.getState(),l=o?a:s.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,l,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:a,onEligibilityFailure:o}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d}=l.initializationData||{},c={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},m={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,a)},h=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let y=!1;h.forEach(t=>{if(!y){const n=lr(lr(lr({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},c),i&&m),d&&u),a=s.Buttons(n);a.isEligible()?(a.render(`#${e}`),y=!0):o&&"function"==typeof o&&o()}}),y||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return dr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return dr(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),a=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(a);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(a);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 dr(this,null,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 dr(this,null,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 mr=C(e=>new cr(e,Jt(e)),[{id:"bigcommerce_payments_paylater"}]);var ur=Object.defineProperty,hr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,pr=Object.getOwnPropertySymbols,gr=Object.prototype.hasOwnProperty,vr=Object.prototype.propertyIsEnumerable,br=(e,t,n)=>t in e?ur(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pr=(e,t)=>{for(var n in t||(t={}))gr.call(t,n)&&br(e,n,t[n]);if(pr)for(var n of pr(t))vr.call(t,n)&&br(e,n,t[n]);return e},fr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Sr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return fr(this,null,function*(){const{bigcommerce_payments_venmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:a}=t||{},o=!!r;if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(o&&!a)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=o?a: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:a}=n,o=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),s=o.FUNDING.VENMO,l={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},d={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Pr(Pr({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},l),i&&d),m=o.Buttons(c);m.isEligible()?m.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===gt.gold?(n=Pr({},t),hr(n,yr({color:void 0}))):t;var n}handleClick(e){return fr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const _r=C(e=>new Sr(e,Jt(e)),[{id:"bigcommerce_payments_venmo"}]);var Ir=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Cr{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,i){return Ir(this,null,function*(){return this.paypalSdk=yield this.scriptLoader.getPayPalSDK(e,t,void 0,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}proxyTokenizationPayment(e,t,n,i){return Ir(this,null,function*(){var r;if(!i)throw new u(m.MissingOrderId);const a={paymentWalletData:{providerId:t,providerOrderId:i},cartEntityId:e,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:n},{key:"order_id",value:i}]},o=yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(a);if(!(null==(r=o.body.redirectUrls)?void 0:r.externalCheckoutUrl))throw new Error("Failed to redirection to checkout page");window.location.assign(o.body.redirectUrls.externalCheckoutUrl)})}createPaymentOrderIntent(e,t,n){return Ir(this,null,function*(){const i={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(i,this.intentTypename,n)).body.orderId})}addBillingAddress(e,t,n){return Ir(this,null,function*(){return this.walletButtonIntegrationService.addBillingAddress(e,t,n)})}mapOrderDetailsToBillingAddress({payer:e}){var t,n,i,r;return{firstName:e.name.given_name,lastName:e.name.surname,company:"",address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,email:e.email_address,stateOrProvince:null!=(t=e.address.admin_area_1)?t:"",stateOrProvinceCode:null!=(n=e.address.admin_area_1)?n:"",countryCode:e.address.country_code,postalCode:e.address.postal_code,phone:null!=(r=null==(i=e.phone)?void 0:i.phone_number.national_number)?r:"",shouldSaveAddress:!1}}getValidButtonStyle(e={}){const{color:t,height:n,label:i,shape:r}=e,o={color:t&&H[t]?t:void 0,height:this.getValidHeight(n),label:i&&K[i]?i:void 0,shape:r&&$[r]?r:void 0};return l(o,a)}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 wr=Object.defineProperty,Or=Object.getOwnPropertySymbols,Ar=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable,Er=(e,t,n)=>t in e?wr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Tr{constructor(e){this.bigCommercePaymentsWalletService=e}initialize(e){return kr(this,null,function*(){var t,n;const{bigcommerce_paymentspaypal:i,containerId:r,methodId:a}=e;if(!a)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_paymentspaypal" argument is not provided.');let o;try{o=JSON.parse(atob(i.initializationData))}catch(e){throw new we("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsWalletService.loadPayPalSdk(o,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypal",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsWalletService.getPayPalSdkOrThrow(),a={createOrder:()=>this.bigCommercePaymentsWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>kr(this,[e,i],function*({orderID:e},i){const r=yield i.order.get(),a=this.bigCommercePaymentsWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsWalletService.addBillingAddress(n,a),yield this.bigCommercePaymentsWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments",e)})},o=((e,t)=>{for(var n in t||(t={}))Ar.call(t,n)&&Er(e,n,t[n]);if(Or)for(var n of Or(t))zr.call(t,n)&&Er(e,n,t[n]);return e})({fundingSource:r.FUNDING.PAYPAL,style:this.bigCommercePaymentsWalletService.getValidButtonStyle(i)},a),s=r.Buttons(o);s.isEligible()?s.render(`#${e}`):this.bigCommercePaymentsWalletService.removeElement(e)}}const Br=C(e=>new Tr(new Cr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypal"}]);var Mr=Object.defineProperty,Fr=Object.getOwnPropertySymbols,Dr=Object.prototype.hasOwnProperty,Nr=Object.prototype.propertyIsEnumerable,xr=(e,t,n)=>t in e?Mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ur=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class jr{constructor(e){this.bigCommercePaymentsPayLaterWalletService=e}initialize(e){return Ur(this,null,function*(){var t,n;const{bigcommerce_paymentspaypalcredit:i,containerId:r,methodId:a}=e;if(!a)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_paymentspaypalcredit" argument is not provided.');let o;try{o=JSON.parse(atob(i.initializationData))}catch(e){throw new we("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsPayLaterWalletService.loadPayPalSdk(o,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypalcredit",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsPayLaterWalletService.getPayPalSdkOrThrow(),a=[r.FUNDING.PAYLATER,r.FUNDING.CREDIT],o={createOrder:()=>this.bigCommercePaymentsPayLaterWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>Ur(this,[e,i],function*({orderID:e},i){const r=yield i.order.get(),a=this.bigCommercePaymentsPayLaterWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsPayLaterWalletService.addBillingAddress(n,a),yield this.bigCommercePaymentsPayLaterWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_paylater",e)})};let s=!1;a.forEach(t=>{if(!s){const n=((e,t)=>{for(var n in t||(t={}))Dr.call(t,n)&&xr(e,n,t[n]);if(Fr)for(var n of Fr(t))Nr.call(t,n)&&xr(e,n,t[n]);return e})({fundingSource:t,style:this.bigCommercePaymentsPayLaterWalletService.getValidButtonStyle(i)},o),a=r.Buttons(n);a.isEligible()&&(a.render(`#${e}`),s=!0)}}),s||this.bigCommercePaymentsPayLaterWalletService.removeElement(e)}}const Vr=C(e=>new jr(new Cr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypalcredit"}]);var Lr=Object.defineProperty,Rr=Object.defineProperties,Gr=Object.getOwnPropertyDescriptors,Wr=Object.getOwnPropertySymbols,Kr=Object.prototype.hasOwnProperty,Hr=Object.prototype.propertyIsEnumerable,$r=(e,t,n)=>t in e?Lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qr=(e,t)=>{for(var n in t||(t={}))Kr.call(t,n)&&$r(e,n,t[n]);if(Wr)for(var n of Wr(t))Hr.call(t,n)&&$r(e,n,t[n]);return e},Yr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Jr{constructor(e){this.bigCommercePaymentsVenmoWalletService=e}initialize(e){return Yr(this,null,function*(){var t,n;const{bigcommerce_paymentsvenmo:i,containerId:r,methodId:a}=e;if(!a)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_paymentsvenmo" argument is not provided.');let o;try{o=JSON.parse(atob(i.initializationData))}catch(e){throw new we("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsVenmoWalletService.loadPayPalSdk(o,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.venmo",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsVenmoWalletService.getPayPalSdkOrThrow(),a={createOrder:()=>this.bigCommercePaymentsVenmoWalletService.createPaymentOrderIntent(t,n),onApprove:e=>Yr(this,[e],function*({orderID:e}){yield this.bigCommercePaymentsVenmoWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_venmo",e)})},o=qr({fundingSource:r.FUNDING.VENMO,style:this.getValidVenmoButtonStyles(i)},a),s=r.Buttons(o);s.isEligible()?s.render(`#${e}`):this.bigCommercePaymentsVenmoWalletService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsVenmoWalletService.getValidButtonStyle(e);return t.color===gt.gold?(n=qr({},t),Rr(n,Gr({color:void 0}))):t;var n}}const Zr=C(e=>new Jr(new Cr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentsvenmo"}]);export{Zn as createBigCommercePaymentsAlternativeMethodsPaymentStrategy,nr as createBigCommercePaymentsButtonStrategy,jn as createBigCommercePaymentsCreditCardsPaymentStrategy,fi as createBigCommercePaymentsCustomerStrategy,Ii as createBigCommercePaymentsFastlaneCustomerStrategy,Tt as createBigCommercePaymentsFastlanePaymentStrategy,Kn as createBigCommercePaymentsInvoicesPaymentStrategy,mr as createBigCommercePaymentsPayLaterButtonStrategy,Fi as createBigCommercePaymentsPayLaterCustomerStrategy,rn as createBigCommercePaymentsPayLaterPaymentStrategy,Vr as createBigCommercePaymentsPayLaterWalletStrategy,xe as createBigCommercePaymentsPaymentStrategy,Pn as createBigCommercePaymentsRatePayPayPaymentStrategy,ni as createBigCommercePaymentsRedirectAlternativeMethodsPaymentStrategy,_r as createBigCommercePaymentsVenmoButtonStrategy,Ki as createBigCommercePaymentsVenmoCustomerStrategy,li as createBigCommercePaymentsVenmoPaymentStrategy,Zr as createBigCommercePaymentsVenmoWalletStrategy,Br as createBigCommercePaymentsWalletStrategy};
1
+ import{createScriptLoader as e,getScriptLoader as t}from"@bigcommerce/script-loader";import{createFormPoster as n}from"@bigcommerce/form-poster";import{createRequestSender as i}from"@bigcommerce/request-sender";import{isEqual as r,isNil as a,noop as o,omit as s,omitBy as l}from"lodash";class d 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}}class c extends d{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var m=(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",e))(m||{});class u extends d{constructor(e){super(function(e){switch(e){case 0:return"Unable to proceed because billing address data is unavailable.";case 1:return"Unable to proceed because cart data is unavailable.";case 3:return"Unable to proceed because consignments data is unavailable.";case 2:return"Unable to proceed because checkout data is unavailable.";case 4:return"Unable to proceed because customer data is unavailable.";case 5:case 7:return"Unable to proceed because configuration data is unavailable.";case 6:return"Unable to proceed because order data is unavailable.";case 8:return"Unable to proceed because order ID is unavailable or not generated yet.";case 9:return"Unable to proceed because payment data is unavailable.";case 15:return"Unable to proceed because the token required to submit a payment is missing.";case 12:return"Unable to proceed because payment method data is unavailable or not properly configured.";case 16: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"}}var h=Object.defineProperty,y=Object.defineProperties,p=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,P=(e,t,n)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,f=(e,t)=>{for(var n in t||(t={}))v.call(t,n)&&P(e,n,t[n]);if(g)for(var n of g(t))b.call(t,n)&&P(e,n,t[n]);return e},S=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class _{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return S(this,null,function*(){if(!this.window.bigCommercePaymentsFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.bigCommercePaymentsFastlaneSdk)throw new c}return this.window.bigCommercePaymentsFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return S(this,null,function*(){if(!this.window.bigCommercePaymentsGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.bigCommercePaymentsGooglePay)throw new c;return this.window.bigCommercePaymentsGooglePay})}getPayPalApmsSdk(e,t){return S(this,null,function*(){if(!this.window.bigCommercePaymentsApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.bigCommercePaymentsApms)throw new c}return this.window.bigCommercePaymentsApms})}getPayPalMessages(e,t){return S(this,null,function*(){if(!this.window.bigCommercePaymentsMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.bigCommercePaymentsMessages)throw new c;return this.window.bigCommercePaymentsMessages})}loadPayPalSdk(e){return S(this,arguments,function*({options:e,attributes:t}){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 u(m.MissingPaymentMethod);const{intent:a,clientId:o,merchantId:s,attributionId:l}=r;return{options:{"client-id":o,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:a},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"bigCommercePaymentsFastlaneSdk","data-partner-attribution-id":l,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new u(m.MissingPaymentMethod);const{intent:a,clientId:o,merchantId:s,buyerCountry:l,attributionId:d,isHostedCheckoutEnabled:c,isDeveloperModeApplicable:h}=r;return{options:f({"client-id":o,"merchant-id":s,commit:c||n,components:["googlepay"],currency:t,intent:a},h&&{"buyer-country":l}),attributes:{"data-partner-attribution-id":d,"data-client-token":i,"data-namespace":"bigCommercePaymentsGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:a,buyerCountry:o,attributionId:s,isDeveloperModeApplicable:l,availableAlternativePaymentMethods:d=[],enabledAlternativePaymentMethods:c=[]}=n,h=this.filterFundingOptions(c),y=this.filterFundingOptions(d.filter(e=>!c.includes(e)));return{options:f({"client-id":r,"merchant-id":a,"enable-funding":h.length>0?h:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},l&&{"buyer-country":o}),attributes:{"data-partner-attribution-id":s,"data-namespace":"bigCommercePaymentsApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:a,isDeveloperModeApplicable:o,buyerCountry:s}=n;return{options:f({"client-id":i,"merchant-id":r,components:["messages"],currency:t},o&&{"buyer-country":s}),attributes:{"data-namespace":"bigCommercePaymentsMessages","data-partner-attribution-id":a}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];var r,a;null==i||""===i||Array.isArray(i)&&0===i.length||(r=f({},t),a={[n]:Array.isArray(i)?i.join(","):i},t=y(r,p(a)))}),t}}function I(){return new _(e())}function C(e,t){return Object.assign(e,{resolveIds:t})}var w=(e=>(e.PayPal="paypal",e.BigCommercePaymentsPayPalSDK="bigCommercePaymentsPayPalSDK",e.PayPalFastlaneSdk="paypalFastlaneSdk",e.PayPalFastlane="paypalFastlane",e.PayPalGooglePay="paypalGooglePay",e.PayPalApms="paypalApms",e.PayPalMessages="paypalMessages",e))(w||{});const O=["ar_BH","ar_DZ","ar_EG","ar_JO","ar_KW","ar_MA","ar_OM","ar_QA","ar_SA","ar_TN","ar_YE","ar_AE","bg_BG","cs_CZ","da_DK","da_FO","da_GL","de_AT","de_CH","de_DE","de_LU","el_GR","en_AD","en_AE","en_AG","en_AI","en_AL","en_AM","en_AN","en_AO","en_AT","en_AU","en_AW","en_AZ","en_BB","en_BE","en_BH","en_BJ","en_BM","en_BN","en_BS","en_BT","en_BW","en_BY","en_BZ","en_C2","en_CA","en_CD","en_CG","en_CH","en_CI","en_CK","en_CL","en_CM","en_CN","en_CO","en_CR","en_CV","en_CY","en_CZ","en_DE","en_DJ","en_DK","en_DM","en_DO","en_DZ","en_EC","en_EE","en_EG","en_ER","en_ES","en_ET","en_FI","en_FJ","en_FK","en_FM","en_FO","en_FR","en_GA","en_GB","en_GD","en_GE","en_GF","en_GI","en_GL","en_GM","en_GN","en_GP","en_GR","en_GT","en_GW","en_GY","en_HK","en_HN","en_HR","en_HU","en_ID","en_IE","en_IL","en_IN","en_IS","en_IT","en_JM","en_JO","en_JP","en_KE","en_KG","en_KH","en_KI","en_KM","en_KN","en_KR","en_KW","en_KY","en_KZ","en_LA","en_LC","en_LI","en_LK","en_LS","en_LT","en_LU","en_LV","en_MA","en_MC","en_MD","en_ME","en_MG","en_MH","en_MK","en_ML","en_MN","en_MQ","en_MR","en_MS","en_MT","en_MU","en_MV","en_MW","en_MY","en_MZ","en_NA","en_NC","en_NE","en_NF","en_NG","en_NI","en_NL","en_NO","en_NP","en_NR","en_NU","en_NZ","en_OM","en_PA","en_PE","en_PF","en_PG","en_PH","en_PL","en_PM","en_PN","en_PT","en_PW","en_PY","en_QA","en_RE","en_RO","en_RS","en_RU","en_RW","en_SA","en_SB","en_SC","en_SE","en_SG","en_SH","en_SI","en_SJ","en_SK","en_SL","en_SM","en_SN","en_SO","en_SR","en_ST","en_SV","en_SZ","en_TC","en_TD","en_TG","en_TH","en_TJ","en_TM","en_TN","en_TO","en_TR","en_TT","en_TV","en_TW","en_TZ","en_UA","en_UG","en_US","en_UY","en_VA","en_VC","en_VE","en_VG","en_VN","en_VU","en_WF","en_WS","en_YE","en_YT","en_ZA","en_ZM","en_ZW","es_AD","es_AI","es_AO","es_AR","es_AW","es_BB","es_BJ","es_BM","es_BO","es_BS","es_BZ","es_CD","es_CG","es_CK","es_CL","es_CO","es_CR","es_CV","es_DJ","es_DM","es_DO","es_DZ","es_EC","es_EG","es_ER","es_ES","es_ET","es_FJ","es_FK","es_FO","es_GA","es_GD","es_GE","es_GI","es_GL","es_GM","es_GN","es_GT","es_GW","es_GY","es_HN","es_IE","es_JM","es_JO","es_KE","es_KG","es_KI","es_KM","es_KN","es_KW","es_KY","es_KZ","es_LC","es_LI","es_LS","es_LU","es_MA","es_MG","es_MH","es_ML","es_MR","es_MS","es_MU","es_MW","es_MX","es_MZ","es_NA","es_NC","es_NE","es_NF","es_NI","es_NR","es_NU","es_NZ","es_OM","es_PA","es_PE","es_PF","es_PG","es_PM","es_PN","es_PW","es_PY","es_QA","es_RS","es_RW","es_SA","es_SB","es_SC","es_SH","es_SJ","es_SL","es_SM","es_SN","es_SO","es_SR","es_ST","es_SV","es_SZ","es_TC","es_TD","es_TG","es_TJ","es_TM","es_TN","es_TT","es_TV","es_UA","es_UG","es_US","es_UY","es_VA","es_VC","es_VE","es_VG","es_VU","es_WF","es_YE","es_ZM","et_EE","fi_FI","fr_AD","fr_AE","fr_AI","fr_AM","fr_AO","fr_AW","fr_AZ","fr_BB","fr_BE","fr_BF","fr_BI","fr_BJ","fr_BM","fr_BS","fr_BZ","fr_CA","fr_CD","fr_CG","fr_CH","fr_CI","fr_CK","fr_CM","fr_CV","fr_DJ","fr_DM","fr_DO","fr_DZ","fr_EC","fr_ER","fr_ET","fr_FJ","fr_FK","fr_FO","fr_FR","fr_GA","fr_GD","fr_GE","fr_GF","fr_GI","fr_GL","fr_GM","fr_GN","fr_GP","fr_GT","fr_GW","fr_GY","fr_HN","fr_IE","fr_JM","fr_JO","fr_KE","fr_KG","fr_KI","fr_KM","fr_KN","fr_KW","fr_KY","fr_KZ","fr_LC","fr_LI","fr_LS","fr_LU","fr_MA","fr_MC","fr_MG","fr_MH","fr_ML","fr_MQ","fr_MR","fr_MS","fr_MU","fr_MW","fr_MZ","fr_NA","fr_NC","fr_NE","fr_NF","fr_NI","fr_NR","fr_NU","fr_NZ","fr_OM","fr_PA","fr_PE","fr_PF","fr_PG","fr_PM","fr_PN","fr_PW","fr_QA","fr_RE","fr_RS","fr_RW","fr_SA","fr_SB","fr_SC","fr_SH","fr_SJ","fr_SL","fr_SM","fr_SN","fr_SO","fr_SR","fr_ST","fr_SV","fr_SZ","fr_TC","fr_TD","fr_TG","fr_TJ","fr_TM","fr_TN","fr_TT","fr_TV","fr_UA","fr_UG","fr_US","fr_UY","fr_VA","fr_VC","fr_VE","fr_VG","fr_VU","fr_WF","fr_YE","fr_YT","fr_ZA","fr_ZM","he_IL","hu_HU","id_ID","it_IT","ja_JP","ko_KR","lv_LV","lt_LT","ms_BN","ms_MY","nl_BE","nl_NL","pl_PL","pt_BR","pt_PT","ro_RO","ru_EE","ru_LT","ru_LV","ru_RU","ru_UA","si_LK","sk_SK","sl_SI","sq_AL","sv_SE","tl_PH","th_TH","tr_TR","vi_VN","zh_C2","zh_CN","zh_HK","zh_TW","zh_AD","zh_AE","zh_AI","zh_AO","zh_AW","zh_BB","zh_BH","zh_BJ","zh_BM","zh_BS","zh_BZ","zh_CD","zh_CG","zh_CK","zh_CL","zh_CO","zh_CV","zh_DJ","zh_DM","zh_DO","zh_DZ","zh_EC","zh_EG","zh_ER","zh_ET","zh_FJ","zh_FK","zh_FO","zh_GA","zh_GD","zh_GE","zh_GI","zh_GL","zh_GM","zh_GN","zh_GT","zh_GW","zh_GY","zh_HN","zh_IE","zh_JM","zh_JO","zh_KE","zh_KG","zh_KI","zh_KM","zh_KN","zh_KW","zh_KY","zh_KZ","zh_LC","zh_LI","zh_LS","zh_LT","zh_LU","zh_MA","zh_MG","zh_MH","zh_ML","zh_MR","zh_MS","zh_MU","zh_MW","zh_MZ","zh_NA","zh_NC","zh_NE","zh_NF","zh_NI","zh_NR","zh_NU","zh_NZ","zh_OM","zh_PA","zh_PE","zh_PF","zh_PG","zh_PM","zh_PN","zh_PW","zh_QA","zh_RS","zh_RW","zh_SA","zh_SB","zh_SC","zh_SH","zh_SJ","zh_SL","zh_SM","zh_SN","zh_SO","zh_SR","zh_ST","zh_SV","zh_SZ","zh_TC","zh_TD","zh_TG","zh_TJ","zh_TM","zh_TN","zh_TT","zh_TV","zh_UA","zh_UG","zh_US","zh_UY","zh_VA","zh_VC","zh_VE","zh_VG","zh_VU","zh_WF","zh_YE","zh_ZA","zh_ZM"];function A(e){return window[e]}function z(e){if(!e)return;let t;if(e.includes("-")){const[n,i]=e.split("-");t=`${n}_${i.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return O.includes(t)?t:void 0}var E=Object.defineProperty,k=Object.defineProperties,T=Object.getOwnPropertyDescriptors,B=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable,D=(e,t,n)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,N=(e,t)=>{for(var n in t||(t={}))M.call(t,n)&&D(e,n,t[n]);if(B)for(var n of B(t))F.call(t,n)&&D(e,n,t[n]);return e},x=(e,t)=>k(e,T(t)),U=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class j{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return U(this,null,function*(){const a=this.isBigCommercePaymentsMethod(e.id)?w.BigCommercePaymentsPayPalSDK:w.PayPal;if(!A(a)||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}const o=A(a);if(!o)throw new c;return o})}getPayPalFastlaneSdk(e,t,n,i){return U(this,null,function*(){if(!this.window.paypalFastlaneSdk){const r=this.getPayPalFastlaneSdkConfiguration(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i,r){return U(this,null,function*(){if(!this.window.paypalGooglePay||r){const r=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return U(this,null,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return U(this,null,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}isBigCommercePaymentsMethod(e){return e.startsWith("bigcommerce_payments")}loadPayPalSdk(e){return U(this,arguments,function*({options:e,attributes:t}){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})})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:a,initializationData:o}=e;if(!o||!o.clientId)throw new u(m.MissingPaymentMethod);const{intent:s,clientId:l,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:p,isPayPalCreditAvailable:g,isDeveloperModeApplicable:v,availableAlternativePaymentMethods:b=[],enabledAlternativePaymentMethods:P=[],isGooglePayEnabled:f}=o,S=p||i,_="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,I=_?["card"]:[],C=_?[]:["card"],O=g?["credit","paylater"]:[],A=g?[]:["credit","paylater"],E=y?["venmo"]:[],k=y?[]:["venmo"],T=b.filter(e=>!P.includes(e)),B=f?["googlepay"]:[],M=i?["card-fields"]:[],F=this.filterFundingOptions([...C,...A,...k,...T]),D=this.filterFundingOptions([...I,...O,...E,...P]),x=z(n);return{options:N(N({"client-id":l,"merchant-id":d,"enable-funding":D.length>0?D:void 0,"disable-funding":F.length>0?F:void 0,commit:S,components:["buttons","hosted-fields","payment-fields","legal",...B,...M],currency:t,intent:s},v&&{"buyer-country":c}),x&&{locale:x}),attributes:N({"data-partner-attribution-id":h,"data-client-token":a},this.isBigCommercePaymentsMethod(r)&&{"data-namespace":w.BigCommercePaymentsPayPalSDK})}}getPayPalFastlaneSdkConfiguration(e,t,n,i){const{clientToken:r,initializationData:a}=e;if(!a||!a.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:s,merchantId:l,attributionId:d}=a,c=z(i);return{options:x(N({"client-id":s,"merchant-id":l,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:o}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":w.PayPalFastlaneSdk,"data-partner-attribution-id":d,"data-sdk-client-token":r}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i=!0){const{clientToken:r,initializationData:a}=e;if(!a||!a.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:s,merchantId:l,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:y}=a,p=h||i,g=z(n);return{options:N(N({"client-id":s,"merchant-id":l,commit:p,components:["googlepay"],currency:t,intent:o},y&&{"buyer-country":d}),g&&{locale:g}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":w.PayPalGooglePay}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:o,buyerCountry:s,attributionId:l,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=i,y=this.filterFundingOptions(h),p=this.filterFundingOptions(c.filter(e=>!h.includes(e))),g=z(n);return{options:N(N({"client-id":a,"merchant-id":o,"enable-funding":y.length>0?y:void 0,"disable-funding":p.length>0?p:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:r},d&&{"buyer-country":s}),g&&{locale:g}),attributes:{"data-partner-attribution-id":l,"data-namespace":w.PayPalApms}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{clientId:r,merchantId:a,attributionId:o,isDeveloperModeApplicable:s,buyerCountry:l}=i,d=z(n);return{options:N(N({"client-id":r,"merchant-id":a,components:["messages"],currency:t},s&&{"buyer-country":l}),d&&{locale:d}),attributes:{"data-namespace":w.PayPalMessages,"data-partner-attribution-id":o}}}filterFundingOptions(e){const t=["klarna","afterpay"];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=x(N({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function V(){return new j(t())}class L extends d{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"}}const R={body:{},headers:{},status:0};class G extends d{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:a}=e||R;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=a,this.errors=n||[]}}var W=(e=>(e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE",e))(W||{}),K=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))(K||{}),H=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(H||{}),$=(e=>(e.pill="pill",e.rect="rect",e))($||{}),q=Object.defineProperty,Y=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,X=(e,t,n)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Q=(e,t)=>{for(var n in t||(t={}))J.call(t,n)&&X(e,n,t[n]);if(Y)for(var n of Y(t))Z.call(t,n)&&X(e,n,t[n]);return e},ee=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class te{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=n,this.paypalSdkLoader=i}loadPayPalSdk(e,t,n,i){return ee(this,null,function*(){const r=this.paymentIntegrationService.getState(),a=t||r.getCartOrThrow().currency.code,o=r.getPaymentMethodOrThrow(e),s=r.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(o,a,s,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return ee(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(m.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new L}})}createOrder(e,t){return ee(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalRequestSender.createOrder(e,Q({cartId:n},t));return i})}createOrderCardFields(e,t){return ee(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalRequestSender.createOrder(e,Q({cartId:n},t));return Q({orderId:i},r?{setupToken:r}:{})})}updateOrder(e,t,n,i){return ee(this,null,function*(){const r=this.paymentIntegrationService.getState(),a=r.getCartOrThrow();let o;i||(o=r.getConsignmentsOrThrow()[0]);try{yield this.paypalRequestSender.updateOrder(e,Q(Q({availableShippingOptions:i?[]:null==o?void 0:o.availableShippingOptions,cartId:a.id,selectedShippingOption:i?null:null==o?void 0:o.selectedShippingOption},t?{methodId:t}:{}),n?{orderId:n}:{}))}catch(e){throw new G}})}getOrderStatus(e,t){return ee(this,null,function*(){try{const{status:n}=yield this.paypalRequestSender.getOrderStatus(e,t);return n}catch(e){throw new G}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(m.MissingOrderId);return this.formPoster.postForm("/checkout.php",Q({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===W.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return ee(this,null,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(Q({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=>{if(t.selectedShippingOption){const n=t.selectedShippingOption.id;return e.id===n}return!1}))||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.phone_number)?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[a,...o]=r.split(" ");return this.getAddress({firstName:a,lastName:o.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&&H[t]?t:void 0,height:this.getValidHeight(n),label:i&&K[i]?i:void 0,shape:r&&$[r]?r:void 0};return l(o,a)}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")}}const ne="This API endpoint is for internal use only and may change in the future";var ie=(e=>(e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json",e))(ie||{});const re=ie,ae={"X-Checkout-SDK-Version":"1.983.4"};var oe=Object.defineProperty,se=Object.getOwnPropertySymbols,le=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable,ce=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,me=(e,t)=>{for(var n in t||(t={}))le.call(t,n)&&ce(e,n,t[n]);if(se)for(var n of se(t))de.call(t,n)&&ce(e,n,t[n]);return e},ue=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class he{constructor(e){this.requestSender=e}createOrder(e,t){return ue(this,null,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=me({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e,t){return ue(this,null,function*(){const n=`/api/storefront/initialization/${e}`,i=t,r=me({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.put(n,{headers:r,body:i})).body})}getOrderStatus(e,t){return ue(this,null,function*(){const n=`/api/storefront/initialization/${e}`,i=me({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.get(n,me({headers:i},t))).body})}}var ye=Object.defineProperty,pe=Object.getOwnPropertySymbols,ge=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,be=(e,t,n)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pe=(e,t)=>{for(var n in t||(t={}))ge.call(t,n)&&be(e,n,t[n]);if(pe)for(var n of pe(t))ve.call(t,n)&&be(e,n,t[n]);return e};const fe={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Se="embedded-checkout-loading-indicator-rotation";class _e{constructor(e){this.styles=Pe(Pe({},fe),e&&e.styles),this.containerStyles=Pe({},e&&e.containerStyles),this.defineAnimation(),this.container=this.buildContainer(),this.indicator=this.buildIndicator(),this.container.appendChild(this.indicator)}show(e){if(e){const t=document.getElementById(e);if(!t)throw new Error("Unable to attach the loading indicator because the parent ID is not valid.");t.appendChild(this.container)}this.container.style.visibility="visible",this.container.style.opacity="1"}hide(){const e=()=>{this.container.style.visibility="hidden",this.container.removeEventListener("transitionend",e)};this.container.addEventListener("transitionend",e),this.container.style.opacity="0"}buildContainer(){const e=document.createElement("div");return e.style.display="block",e.style.bottom="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.position="absolute",e.style.right="0",e.style.top="0",e.style.transition="all 250ms ease-out",e.style.opacity="0",this.setStyleAttribute(e,this.containerStyles),e}buildIndicator(){const e=document.createElement("div");return e.style.display="block",e.style.width=`${this.styles.size}px`,e.style.height=`${this.styles.size}px`,e.style.borderRadius=`${this.styles.size}px`,e.style.border="solid 1px",e.style.borderColor=`${this.styles.backgroundColor} ${this.styles.backgroundColor} ${this.styles.color} ${this.styles.color}`,e.style.margin="0 auto",e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top="50%",e.style.transform="translateY(-50%) rotate(0deg)",e.style.transformStyle="preserve-3d",e.style.animation=`${Se} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(n=>{e.style.setProperty(n,t[n])})}defineAnimation(){var e;if(document.getElementById(Se))return;const t=document.createElement("style");t.id=Se,null==(e=document.head)||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${Se} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}const Ie={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},Ce=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};class we extends d{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class Oe extends we{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 Ae extends G{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 ze extends d{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function Ee(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function ke(e){return Boolean(e.instrumentId)}function Te(e){return"object"==typeof e&&null!==e&&"bigpayToken"in e&&"defaultInstrument"in e&&"provider"in e&&"trustedShippingAddress"in e&&"method"in e&&"type"in e}var Be=Object.getOwnPropertySymbols,Me=Object.prototype.hasOwnProperty,Fe=Object.prototype.propertyIsEnumerable,De=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ne{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkHelper=n,this.loadingIndicator=i}initialize(e){return De(this,null,function*(){const{methodId:t,bigcommerce_payments:n}=e||{};if(this.bigcommerce_payments=n,!t)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{container:a,bannerContainerId:o}=n,{orderId:s,paypalBNPLConfiguration:l=[],isPayPalCreditAvailable:d}=r.initializationData||{};if(void 0!==o){if(!document.getElementById(o))return void console.error("Unable to create banner without valid banner container ID.");const e=null==l?void 0:l.find(({id:e})=>"checkout"===e);if(d||!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return t&&"function"==typeof(null==t?void 0:t.Messages)?this.renderMessages(t,o,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}s?this.orderId=s:(this.loadingIndicatorContainer=null==a?void 0:a.split("#")[1],yield this.paypalIntegrationService.loadPayPalSdk(t),n.onInit&&"function"==typeof n.onInit&&n.onInit(()=>this.renderButton(t,n)),(void 0===n.shouldRenderPayPalButtonOnInitialization||n.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(t,n))})}execute(e,t){return De(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Me.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Be)for(var i of Be(e))t.indexOf(i)<0&&Fe.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{onError:a}=this.bigcommerce_payments||{};if(!i)throw new Oe(["payment"]);const{methodId:o,paymentData:s}=i;if(this.isPayPalVaultedInstrumentPaymentData(s)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new Ae;const l=this.isPayPalVaultedInstrumentPaymentData(s)?this.prepareVaultedInstrumentPaymentPayload(o,this.orderId,s):this.preparePaymentPayload(o,this.orderId,s);try{yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(l)}catch(e){return this.isProviderError(e)&&(yield this.paypalIntegrationService.loadPayPalSdk(i.methodId),yield new Promise((e,t)=>{var n;this.bigcommerce_payments&&(null==(n=this.paypalButton)||n.close(),this.renderButton(i.methodId,this.bigcommerce_payments),this.handleError(new Error("INSTRUMENT_DECLINED"),a)),t()})),this.handleError(e,a),Promise.reject()}})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:i,shouldSetAsDefaultInstrument:r}=n,a=!this.isTrustedVaultingFlow(n);return a?{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:i}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:i=!1,shouldSetAsDefaultInstrument:r=!1}=Ee(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:a}=r||{},{container:o,onError:s,onRenderButton:l,onValidate:d,submitForm:c}=t;if(!o)throw new we('Unable to initialize payment because "container" argument is not provided.');const m={fundingSource:n.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onError:e=>this.handleError(e,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(m),this.paypalButton.isEligible()&&(l&&"function"==typeof l&&l(),this.paypalButton.render(o))}handleClick(e,t){return De(this,null,function*(){const{resolve:n,reject:i}=e;yield null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return De(this,null,function*(){const e=this.getFieldsValues();return this.paypalIntegrationService.createOrder("bigcommerce_paymentscheckout",{shouldSaveInstrument:(null==e?void 0:e.shouldSaveInstrument)||!1})})}getFieldsValues(){const{getFieldsValues:e}=this.bigcommerce_payments||{};return"function"==typeof e?e():void 0}isTrustedVaultingFlow(e){if(e&&ke(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>Te(t)&&t.bigpayToken===e.instrumentId);return!(Te(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&ke(e)&&Ee(e)}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:Ce(n)};e.Messages(i).render(`#${t}`)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null==(i=null==(n=((null==(t=null==e?void 0:e.errors)?void 0:t.filter(e=>e.provider_error))||[])[0])?void 0:n.provider_error)?void 0:i.code)}}const xe=C(e=>new Ne(e,(e=>{const{getHost:t}=e.getState();return new te(n(),e,new he(i({host:t()})),V())})(e),I(),new _e({containerStyles:Ie})),[{id:"bigcommerce_payments"}]);var Ue=(e=>(e.CVV="cvv",e.PAN="pan",e))(Ue||{}),je=Object.defineProperty,Ve=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,Ge=(e,t,n)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;class We{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:a,domain:o,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}a&&(i+=`; path=${a}`),o&&(i+=`; domain=${o}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){We.set(e,"",((e,t)=>{for(var n in t||(t={}))Le.call(t,n)&&Ge(e,n,t[n]);if(Ve)for(var n of Ve(t))Re.call(t,n)&&Ge(e,n,t[n]);return e})({expires:new Date(0)},t))}}var Ke=(e=>(e.Always="SCA_ALWAYS",e))(Ke||{}),He=(e=>(e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored",e))(He||{}),$e=(e=>(e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized",e))($e||{}),qe=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ye{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return qe(this,null,function*(){if(t&&(window.localStorage.setItem("fastlaneEnv","sandbox"),window.localStorage.setItem("axoEnv","sandbox")),!this.window.bigCommercePaymentsFastlane){const t={root:{backgroundColorPrimary:"transparent"}};this.window.bigCommercePaymentsFastlane=yield e.Fastlane({styles:n||t})}return this.window.bigCommercePaymentsFastlane})}getPayPalFastlaneOrThrow(){if(!this.window.bigCommercePaymentsFastlane)throw new c;return this.window.bigCommercePaymentsFastlane}lookupCustomerOrThrow(e){return qe(this,null,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return qe(this,null,function*(){return e?this.getPayPalFastlaneOrThrow().identity.triggerAuthenticationFlow(e):{}})}updateStorageSessionId(e){const t=new Date;t.setDate(t.getDate()+14);const n={expires:t,secure:!0};We.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){We.remove("bc-fastlane-sessionId")}getStorageSessionId(){return We.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,i,r;const{authenticationState:a,profileData:o}=t,s=null==(r=null==(i=null==(n=null==o?void 0:o.card)?void 0:n.paymentSource)?void 0:i.card)?void 0:r.billingAddress,l=null==o?void 0:o.shippingAddress,d=null==o?void 0:o.name,c=null==o?void 0:o.card,m=l?this.mapPayPalToBcAddress(l.address,l.name,l.phoneNumber):void 0,u=s&&d?this.mapPayPalToBcAddress(s,d,null==l?void 0:l.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([m,u]);return{authenticationState:a||$e.UNRECOGNIZED,addresses:y,billingAddress:u,shippingAddress:m,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:i}=t,{brand:r,expiry:a,lastDigits:o}=i.card,[s,l]=a.split("-");return[{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:l,expiryYear:s,iin:"",last4:o,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:Ue.PAN,type:"card"}]}mapBcToPayPalAddress(e){return{company:(null==e?void 0:e.company)||"",addressLine1:(null==e?void 0:e.address1)||"",addressLine2:(null==e?void 0:e.address2)||"",adminArea1:(null==e?void 0:e.stateOrProvinceCode)||(null==e?void 0:e.stateOrProvince)||"",adminArea2:(null==e?void 0:e.city)||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCode:(null==e?void 0:e.countryCode)||""}}mapPayPalToBcAddress(e,t,n,i){const[r,a]=t.fullName.split(" "),o=(null==n?void 0:n.nationalNumber)||"",s=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||r||"",lastName:t.lastName||a||"",company:e.company||"",address1:e.addressLine1,address2:e.addressLine2||"",city:e.adminArea2,stateOrProvince:e.adminArea1,stateOrProvinceCode:e.adminArea1,country:e.countryCode||"",countryCode:e.countryCode||"",postalCode:e.postalCode,phone:s+o,customFields:i||[]}}filterAddresses(e){return e.reduce((e,t)=>t?e.some(e=>this.isEqualAddresses(e,t))?e:[...e,t]:e,[])}isEqualAddresses(e,t){return r(this.normalizeAddress(e),this.normalizeAddress(t))}normalizeAddress(e){return s(e,["id","phone"])}}function Je(){return new Ye}var Ze=Object.defineProperty,Xe=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,tt=(e,t,n)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nt=(e,t)=>{for(var n in t||(t={}))Qe.call(t,n)&&tt(e,n,t[n]);if(Xe)for(var n of Xe(t))et.call(t,n)&&tt(e,n,t[n]);return e},it=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class rt{constructor(e){this.requestSender=e}createOrder(e,t){return it(this,null,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=nt({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return it(this,null,function*(){const t=e,n=nt({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:n,body:t})).body})}getOrderStatus(e="bigcommerce_payments",t){return it(this,null,function*(){const n=`/api/storefront/initialization/${e}`,i=nt({"X-API-INTERNAL":ne,"Content-Type":re.Json},ae);return(yield this.requestSender.get(n,nt({headers:i},t))).body})}}var at=Object.defineProperty,ot=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,dt=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function ct(e){return"string"!=typeof e}function mt(e,t){if(t||e)return function(e){var t,n;const i={},r=l(e.root,ct),a=l(e.input,ct),o=l(e.toggle,ct),s=l(null==(t=e.text)?void 0:t.body,ct),d=l(null==(n=e.text)?void 0:n.caption,ct),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(a).length&&(i.input=a),Object.keys(o).length&&(i.toggle=o),Object.keys(s).length&&(i.text={},i.text.body=s),Object.keys(d).length&&(i.text=((e,t)=>{for(var n in t||(t={}))st.call(t,n)&&dt(e,n,t[n]);if(ot)for(var n of ot(t))lt.call(t,n)&&dt(e,n,t[n]);return e})({},i.text),i.text.caption=d),c&&(i.branding=c),i}(function(e,t){var n,i,r,a,o,s,l,d,c,m,u,h,y,p,g,v,b,P,f,S,_,I;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null==(n=null==t?void 0:t.root)?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null==(i=null==t?void 0:t.root)?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null==(r=null==t?void 0:t.root)?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null==(a=null==t?void 0:t.root)?void 0:a.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null==(o=null==t?void 0:t.root)?void 0:o.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null==(s=null==t?void 0:t.root)?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(l=null==t?void 0:t.input)?void 0:l.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null==(d=null==t?void 0:t.input)?void 0:d.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null==(c=null==t?void 0:t.input)?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null==(m=null==t?void 0:t.input)?void 0:m.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null==(u=null==t?void 0:t.input)?void 0:u.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null==(h=null==t?void 0:t.input)?void 0:h.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null==(y=null==t?void 0:t.toggle)?void 0:y.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null==(p=null==t?void 0:t.toggle)?void 0:p.colorSecondary)},text:{body:{color:(null==e?void 0:e.fastlaneTextBodySettingsColor)||(null==(v=null==(g=null==t?void 0:t.text)?void 0:g.body)?void 0:v.color),fontSize:(null==e?void 0:e.fastlaneTextBodySettingsFontSize)||(null==(P=null==(b=null==t?void 0:t.text)?void 0:b.body)?void 0:P.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(S=null==(f=null==t?void 0:t.text)?void 0:f.caption)?void 0:S.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null==(I=null==(_=null==t?void 0:t.text)?void 0:_.caption)?void 0:I.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function ut(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}function ht(e,t,n=!0){var i;return null!=(i=e[t])?i:n}var yt=(e=>(e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES",e))(yt||{}),pt=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))(pt||{}),gt=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(gt||{}),vt=(e=>(e.pill="pill",e.rect="rect",e))(vt||{}),bt=(e=>(e.OXXO="oxxo",e))(bt||{}),Pt=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(Pt||{}),ft=Object.defineProperty,St=Object.defineProperties,_t=Object.getOwnPropertyDescriptors,It=Object.getOwnPropertySymbols,Ct=Object.prototype.hasOwnProperty,wt=Object.prototype.propertyIsEnumerable,Ot=(e,t,n)=>t in e?ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,At=(e,t)=>{for(var n in t||(t={}))Ct.call(t,n)&&Ot(e,n,t[n]);if(It)for(var n of It(t))wt.call(t,n)&&Ot(e,n,t[n]);return e},zt=(e,t)=>St(e,_t(t)),Et=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class kt{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsRequestSender=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return Et(this,null,function*(){var t,n;const{methodId:i,bigcommerce_payments_fastlane:r}=e;if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(this.methodId=i,!r)throw new we('Unable to initialize payment because "options.bigcommerce_payments_fastlane" argument is not provided.');if(this.bigcommerce_payments_fastlane=r,!r.onInit||"function"!=typeof r.onInit)throw new we('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onInit" argument is not provided or it is not a function.');if(!r.onChange||"function"!=typeof r.onChange)throw new we('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(i);const a=this.paymentIntegrationService.getState(),o=a.getCartOrThrow(),s=a.getPaymentMethodOrThrow(i),{isDeveloperModeApplicable:l,isFastlaneStylingEnabled:d}=s.initializationData||{};this.threeDSVerificationMethod=null==(t=s.initializationData)?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(s,o.currency.code,o.id);const c=mt(d?null==(n=null==s?void 0:s.initializationData)?void 0:n.fastlaneStyles:{},null==r?void 0:r.styles);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!l,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(i)),yield this.initializePayPalPaymentComponent(),r.onInit(e=>this.renderPayPalPaymentComponent(e)),r.onChange(()=>this.handlePayPalStoredInstrumentChange(i))})}execute(e,t){return Et(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Ct.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&It)for(var i of It(e))t.indexOf(i)<0&&wt.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);const{paymentData:a,methodId:o}=i,s=a&&ke(a);try{yield this.paymentIntegrationService.submitOrder(r,t);const e=s?yield this.prepareVaultedInstrumentPaymentPayload(o,a):yield this.preparePaymentPayload(o,a);yield this.paymentIntegrationService.submitPayment(e),this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()}catch(e){if(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"response"in e&&"name"in e.response}(e)&&"INVALID_REQUEST"===e.response.name){const e={translationKey:"payment.errors.invalid_request_error"};return this.handleError(e),Promise.reject()}if(e instanceof Error&&"FastlaneError"!==e.name)throw e;return Promise.reject()}})}finalize(){return Promise.reject(new ze)}deinitialize(){return Et(this,null,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=ut(i)?i:{},a=this.bigCommercePaymentsFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===$e.CANCELED||(null==r?void 0:r.authenticationState)||a!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return Et(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getCustomer(),r=t.getBillingAddress(),a=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:o}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(a),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(o),{authenticationState:l,addresses:d,instruments:c}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:l,addresses:d,instruments:c}),s.authenticationState===$e.CANCELED?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return Et(this,null,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),i=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),r={fields:At({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield i.FastlaneCardComponent(r)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new we('Unable to render card component because "container" argument is not provided.');t.render(e)}getPayPalComponentMethodsOrThrow(){if(!this.paypalComponentMethods)throw new c;return this.paypalComponentMethods}prepareVaultedInstrumentPaymentPayload(e,t){return Et(this,null,function*(){const{instrumentId:n}=t,i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),r=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&i.config.is3dsEnabled?yield this.get3DSNonce(n):n;return yield this.createOrder(r),{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:r}}}}})}preparePaymentPayload(e,t){return Et(this,null,function*(){const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getPaymentMethodOrThrow(e),a=`${i.firstName} ${i.lastName}`.trim(),{getPaymentToken:o}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield o({name:{fullName:a},billingAddress:this.bigCommercePaymentsFastlaneUtils.mapBcToPayPalAddress(i)}),l=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&r.config.is3dsEnabled,{shouldSaveInstrument:d=!1,shouldSetAsDefaultInstrument:c=!1}=Ee(t)?t:{},m=l?yield this.get3DSNonce(s):s;return yield this.createOrder(m),{methodId:e,paymentData:zt(At({},t),{shouldSaveInstrument:d,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:m}}})}})}createOrder(e){return Et(this,null,function*(){const t=this.paymentIntegrationService.getState().getCartOrThrow().id;if(this.methodId){const{orderId:n}=yield this.bigCommercePaymentsRequestSender.createOrder(this.methodId,{cartId:t,fastlaneToken:e});this.orderId=n}})}get3DSNonce(e){return Et(this,null,function*(){var t;const n=this.paymentIntegrationService.getState(),i=n.getCartOrThrow(),r=n.getOrderOrThrow(),a=n.getStoreConfigOrThrow().links.checkoutLink,o=null==(t=this.paypalFastlaneSdk)?void 0:t.ThreeDomainSecureClient;if(!o)throw new c;const s={amount:r.orderAmount.toFixed(2),currency:i.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===Ke.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},l=yield o.isEligible(s);if(this.threeDSVerificationMethod===Ke.Always&&!l)throw new Ae;if(l){const{liabilityShift:e,authenticationState:t,nonce:n}=yield o.show();if(e===yt.No||e===yt.Unknown||t===He.Errored||t===He.Cancelled)throw new Ae;if(t===He.Succeeded&&[yt.Yes,yt.Possible].includes(e))return n}return e})}handlePayPalStoredInstrumentChange(e){return Et(this,null,function*(){const t=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=ut(t)?t:{},r=this.bigCommercePaymentsFastlaneUtils.mapPayPalToBcInstrument(e,i)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(zt(At({},n),{instruments:[r]})),r}})}isBigcommercePaymentsFastlaneThreeDSAvailable(){return ht(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.bcp_fastlane_three_ds")}handleError(e){var t;(null==(t=this.bigcommerce_payments_fastlane)?void 0:t.onError)&&"function"==typeof this.bigcommerce_payments_fastlane.onError&&this.bigcommerce_payments_fastlane.onError(e)}handleErrorLog(e){var t;(null==(t=this.bigcommerce_payments_fastlane)?void 0:t.onErrorLog)&&"function"==typeof this.bigcommerce_payments_fastlane.onErrorLog&&this.bigcommerce_payments_fastlane.onErrorLog(e)}}const Tt=C(e=>{const{getHost:t}=e.getState();return new kt(e,new rt(i({host:t()})),I(),Je())},[{id:"bigcommerce_payments_fastlane"}]);var Bt=Object.defineProperty,Mt=Object.getOwnPropertySymbols,Ft=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable,Nt=(e,t,n)=>t in e?Bt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xt=(e,t)=>{for(var n in t||(t={}))Ft.call(t,n)&&Nt(e,n,t[n]);if(Mt)for(var n of Mt(t))Dt.call(t,n)&&Nt(e,n,t[n]);return e},Ut=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class jt{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=n,this.bigCommercePaymentsScriptLoader=i}loadPayPalSdk(e,t,n,i){return Ut(this,null,function*(){const r=this.paymentIntegrationService.getState(),a=t||r.getCartOrThrow().currency.code,o=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(o,a,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return Ut(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(m.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new L}})}createOrder(e,t){return Ut(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.bigCommercePaymentsRequestSender.createOrder(e,xt({cartId:n},t));return i})}createOrderCardFields(e,t){return Ut(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.bigCommercePaymentsRequestSender.createOrder(e,xt({cartId:n},t));return xt({orderId:i},r?{setupToken:r}:{})})}updateOrder(e){return Ut(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow();let i;e||(i=t.getConsignmentsOrThrow()[0]);try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:e?[]:null==i?void 0:i.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:null==i?void 0:i.selectedShippingOption})}catch(e){throw new G}})}getOrderStatus(e,t){return Ut(this,null,function*(){try{const{status:n}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return n}catch(e){throw new G}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(m.MissingOrderId);return this.formPoster.postForm("/checkout.php",xt({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===W.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return Ut(this,null,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(xt({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.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.phone_number)?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[a,...o]=r.split(" ");return this.getAddress({firstName:a,lastName:o.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&&gt[t]?t:void 0,height:this.getValidHeight(n),label:i&&pt[i]?i:void 0,shape:r&&vt[r]?r:void 0};return l(o,a)}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 Vt=Object.defineProperty,Lt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,Wt=Object.prototype.hasOwnProperty,Kt=Object.prototype.propertyIsEnumerable,Ht=(e,t,n)=>t in e?Vt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$t=(e,t)=>{for(var n in t||(t={}))Wt.call(t,n)&&Ht(e,n,t[n]);if(Gt)for(var n of Gt(t))Kt.call(t,n)&&Ht(e,n,t[n]);return e},qt=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Yt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return qt(this,null,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e,t=!1){return qt(this,null,function*(){if(!this.window.bigCommercePaymentsPayPalSDK||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.bigCommercePaymentsPayPalSDK)throw new c;return this.window.bigCommercePaymentsPayPalSDK})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:a}=e;if(!(null==a?void 0:a.clientId))throw new u(m.MissingPaymentMethod);const{intent:o,clientId:s,merchantId:l,buyerCountry:d,attributionId:c,isVenmoEnabled:h,isHostedCheckoutEnabled:y,isPayPalCreditAvailable:p,isDeveloperModeApplicable:g,availableAlternativePaymentMethods:v=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:P}=a,f=y||n,S="bigcommerce_payments_creditcards"===i,_=S?["card"]:[],I=S?[]:["card"],C=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],O=h?["venmo"]:[],A=h?[]:["venmo"],z=v.filter(e=>!b.includes(e)),E=P?["googlepay"]:[],k=n?["card-fields"]:[],T=this.filterFundingOptions([...I,...w,...A,...z]),B=this.filterFundingOptions([..._,...C,...O,...b]);return{options:$t({"client-id":s,"merchant-id":l,"enable-funding":B.length>0?B:void 0,"disable-funding":T.length>0?T:void 0,commit:f,components:["buttons","hosted-fields","payment-fields","legal",...E,...k],currency:t,intent:o},g&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"bigCommercePaymentsPayPalSDK"}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];var r,a;null==i||""===i||Array.isArray(i)&&0===i.length||(r=$t({},t),a={[n]:Array.isArray(i)?i.join(","):i},t=Lt(r,Rt(a)))}),t}}const Jt=e=>{const{getHost:r}=e.getState();return new jt(n(),e,new rt(i({host:r()})),new Yt(t()))};class Zt extends d{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Xt=Object.getOwnPropertySymbols,Qt=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,tn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class nn{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.paypalSdkHelper=i}initialize(e){return tn(this,null,function*(){const{methodId:t,bigcommerce_payments_paylater:n}=e||{};if(!t)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:a=[],orderId:o}=r.initializationData||{},{bannerContainerId:s,container:l}=n;if(void 0!==s){if(!document.getElementById(s))return void console.error("Unable to create banner without valid banner container ID.");const e=a&&a.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return this.renderMessages(t,s,e)}o?this.orderId=o:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==l?void 0:l.split("#")[1],this.renderButton(t,n))})}execute(e,t){return tn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Qt.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Xt)for(var i of Xt(e))t.indexOf(i)<0&&en.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new Ae;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.bigCommercePaymentsButtons)||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new we('Unable to initialize payment because "container" argument is not provided.');const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:a}=r||{},{container:o,onError:s,onRenderButton:l,onValidate:d,submitForm:c}=t,m=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let u=!1;m.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(a),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.bigCommercePaymentsButtons=n.Buttons(t),this.bigCommercePaymentsButtons.isEligible()||e!==n.FUNDING.PAYLATER){if(!this.bigCommercePaymentsButtons.isEligible()&&e===n.FUNDING.CREDIT)throw new Zt(`BigCommercePayments ${e} is not available for your region. Please use BigCommercePayments Checkout instead.`);l&&"function"==typeof l&&l(),this.bigCommercePaymentsButtons.render(o),u=!0}})}handleClick(e,t){return tn(this,null,function*(){const{resolve:n,reject:i}=e;t&&"function"==typeof t&&(yield t(()=>(this.toggleLoadingIndicator(!0),n()),i))})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:Ce(n)};e.Messages(i).render(`#${t}`)}}const rn=C(e=>new nn(e,Jt(e),new _e({containerStyles:Ie}),I()),[{id:"bigcommerce_payments_paylater"}]);class an extends G{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var on=Object.getOwnPropertySymbols,sn=Object.prototype.hasOwnProperty,ln=Object.prototype.propertyIsEnumerable,dn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class cn{constructor(e,t,n,i=3e3,r=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.pollingInterval=i,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=o}initialize(e){return dn(this,null,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_ratepay:i}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_payments_ratepay" argument is not provided.');const{legalTextContainer:r,container:a,loadingContainerId:o}=i;if(!a)throw new we('Unable to initialize payment because "options.container" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!o)throw new we('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=o;const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:l}=s.initializationData||{};if(!l)throw new we("Unable to initialize payment because merchantId argument is not provided.");this.bigcommerce_payments_ratepay=i,yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n),this.createFraudNetScript(l,n,t),this.loadFraudnetConfig(),this.renderLegalText(r,a)})}execute(e,t){return dn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)sn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&on)for(var i of on(e))t.indexOf(i)<0&&ln.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{getFieldsValues:a}=this.bigcommerce_payments_ratepay||{};if(!i)throw new Oe(["payment"]);if(!a||"function"!=typeof a)throw new we('Unable to initialize payment because "options.getFieldsValues" argument is not provided.');this.toggleLoadingIndicator(!0);try{const e=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apmscheckout",{metadataId:this.guid}),{ratepayBirthDate:n,ratepayPhoneNumber:o,ratepayPhoneCountryCode:s}=a(),l={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:i.methodId,rate_pay:{birth_date:this.normalizeDate(n),phone:{national_number:o,country_code:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment({methodId:i.methodId,paymentData:l}),yield new Promise((e,t)=>{this.initializePollingMechanism(i.methodId,e,t,i.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new ze)}deinitialize(){const{legalTextContainer:e}=this.bigcommerce_payments_ratepay||{},t=document.querySelectorAll('[data-id="fraudnetScript"]')[0],n=document.querySelectorAll('[data-id="fraudnetConfig"]')[0];if(this.deinitializePollingMechanism(),t.remove(),n.remove(),e){const t=document.getElementById(e);null==t||t.remove()}return Promise.resolve()}normalizeDate(e){const t=this.formatDate(e.getDate()),n=this.formatDate(e.getMonth()+1);return`${e.getFullYear()}-${n}-${t}`}formatDate(e){return`${e<10?0:""}${e}`}renderLegalText(e,t){const n=e,i=t.split("#")[1],r=document.getElementById(i),a=null==r?void 0:r.parentNode,o=document.createElement("div");o.style.marginBottom="20px",o.setAttribute("id",n),null==a||a.prepend(o);const s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new we('Unable to initialize payment because "legalTextContainerElement" argument is not found.');l.render(`#${n}`)}handleError(e){const{onError:t}=this.bigcommerce_payments_ratepay||{};this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createFraudNetScript(e,t,n){const i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:r}=i.config,a=document.createElement("script");a.setAttribute("type","application/json"),a.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),a.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const o={f:this.guid,s:`${e}_checkout-page`,sandbox:r};a.innerHTML=JSON.stringify(o),document.body.appendChild(a)}generateGUID(){let e="";for(let t=0;t<32;t+=1)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(62*Math.random())];return e}loadFraudnetConfig(){const e=document.createElement("script");e.setAttribute("data-id","fraudnetConfig"),e.src="https://c.paypal.com/da/r/fb.js",document.body.appendChild(e)}reinitializeStrategy(e){return dn(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return dn(this,null,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus("bigcommerce_payments_apms",{params:{useMetadata:!0}}),a=r===Pt.PollingStop,o=r===Pt.PollingError;if(a)return this.deinitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigcommerce_payments_ratepay:this.bigcommerce_payments_ratepay}),this.handleError(new an)}catch(e){this.handleError(e),n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}var mn=Object.defineProperty,un=Object.defineProperties,hn=Object.getOwnPropertyDescriptors,yn=Object.getOwnPropertySymbols,pn=Object.prototype.hasOwnProperty,gn=Object.prototype.propertyIsEnumerable,vn=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))pn.call(t,n)&&vn(e,n,t[n]);if(yn)for(var n of yn(t))gn.call(t,n)&&vn(e,n,t[n]);return e};const Pn=C(e=>{return new cn(e,Jt(e),new _e({containerStyles:(t=bn({},Ie),n={position:"fixed"},un(t,hn(n)))}));var t,n},[{gateway:"bigcommerce_payments_apms",id:"ratepay"}]);var fn=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification",e))(fn||{});const Sn=fn;function _n(e){return Sn.CardNumber in e&&Sn.CardName in e&&Sn.CardExpiry in e}function In(e){return Sn.CardNumberVerification in e&&Sn.CardCodeVerification in e&&Sn.CardExpiryVerification in e}class Cn extends d{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 wn=(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",e))(wn||{});class On extends d{constructor(e){super(function(e){switch(e){case 1:return"Unable to proceed because the customer step of checkout has not been initialized.";case 2:return"Unable to proceed because the payment step of checkout has not been initialized.";case 3:return"Unable to proceed because the shipping step of checkout has not been initialized.";case 4: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 An extends d{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"}}var zn=Object.defineProperty,En=Object.defineProperties,kn=Object.getOwnPropertyDescriptors,Tn=Object.getOwnPropertySymbols,Bn=Object.prototype.hasOwnProperty,Mn=Object.prototype.propertyIsEnumerable,Fn=(e,t,n)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dn=(e,t)=>{for(var n in t||(t={}))Bn.call(t,n)&&Fn(e,n,t[n]);if(Tn)for(var n of Tn(t))Mn.call(t,n)&&Fn(e,n,t[n]);return e},Nn=(e,t)=>En(e,kn(t)),xn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Un{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return xn(this,null,function*(){const{methodId:t,bigcommerce_payments_creditcards:n}=e,i=n,{form:r,onCreditCardFieldsRenderingError:a,onLoadComplete:o}=i||{};if(!t)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to proceed because "options.bigcommerce_payments_creditcards.form" argument is not provided.');this.hostedFormOptions=r,this.isCreditCardForm=_n(r.fields),this.isCreditCardVaultedForm=In(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,a)),null==o||o(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return xn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Bn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Tn)for(var i of Tn(e))t.indexOf(i)<0&&Mn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{methodId:a,paymentData:o}=i||{};if(!i||!a)throw new Oe(["payment"]);if(this.executionPaymentData=o,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const s=this.preparePaymentPayload(a,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(s)})}finalize(){return Promise.reject(new ze)}deinitialize(){return xn(this,null,function*(){var e,t,n,i;return yield null==(e=this.cvvField)?void 0:e.close(),yield null==(t=this.expiryField)?void 0:t.close(),yield null==(n=this.numberField)?void 0:n.close(),yield null==(i=this.nameField)?void 0:i.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,i){const{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:o=!1}=Ee(t)?t:{},s=t&&ke(t)?t.instrumentId:void 0,d=l({verification_nonce:i,token:s},a);return{methodId:e,paymentData:{shouldSaveInstrument:r,shouldSetAsDefaultInstrument:o,instrumentId:s,formattedPayload:Dn(Dn({},i||s?{bigpay_token:d}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return xn(this,null,function*(){const{fields:n,styles:i}=e,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.getExecuteCallback(n),o=Dn({style:this.getInputStyles(i),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===yt.No||n===yt.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Cn},inputEvents:{onChange:t=>this.onChangeHandler(e,t),onFocus:t=>this.onFocusHandler(e,t),onBlur:t=>this.onBlurHandler(e,t),onInputSubmitRequest:t=>this.onInputSubmitRequest(e,t)}},a);if(this.cardFields=yield r.CardFields(o),!this.cardFields.isEligible())throw new On(wn.PaymentNotInitialized);try{this.stylizeInputContainers(n),_n(n)&&(yield this.renderFields(n)),In(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return In(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>xn(this,null,function*(){const{setupToken:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",Nn(Dn({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>xn(this,null,function*(){const{orderId:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams()))||{};return e})}}handleApprove({orderID:e,vaultSetupToken:t}){e&&(this.returnedOrderId=e),t&&(this.returnedVaultedToken=t)}renderFields(e){return xn(this,null,function*(){var t,n,i,r;const a=this.getCardFieldsOrThrow();(null==(t=e.cardCode)?void 0:t.containerId)&&(this.cvvField=a.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null==(n=e.cardExpiry)?void 0:n.containerId)&&(this.expiryField=a.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null==(i=e.cardName)?void 0:i.containerId)&&(this.nameField=a.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null==(r=e.cardNumber)?void 0:r.containerId)&&(this.numberField=a.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return xn(this,null,function*(){var t,n,i;const r=this.getCardFieldsOrThrow();(null==(t=e.cardCodeVerification)?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null==(n=e.cardExpiryVerification)?void 0:n.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null==(i=e.cardNumberVerification)?void 0:i.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(Ee(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(ke(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return xn(this,null,function*(){const e=this.getCardFieldsOrThrow(),t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n={billingAddress:{company:t.company,addressLine1:t.address1,addressLine2:t.address2,adminArea1:t.stateOrProvinceCode,adminArea2:t.city,postalCode:t.postalCode,countryCode:t.countryCode}};try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){throw new Cn("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return xn(this,null,function*(){var e,t;const n=this.getCardFieldsOrThrow(),i=yield n.getState().then(e=>e),r=this.getValidityData(i);if(!r.isValid)throw null==(t=null==(e=this.hostedFormOptions)?void 0:e.onValidate)||t.call(e,r),new An(this.mapValidationErrors(r.errors))})}getValidityData({fields:e}){const t=Dn({},e);delete t.cardNameField;const n=Object.keys(t);return{isValid:n.every(e=>{var n;return null==(n=t[e])?void 0:n.isValid}),errors:n.reduce((e,n)=>{var i;const r=this.mapFieldType(n);return Nn(Dn({},e),{[r]:(null==(i=t[n])?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case Sn.CardCode:case Sn.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case Sn.CardNumber:case Sn.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case Sn.CardExpiry:case Sn.CardExpiryVerification:return{fieldType:e,message:"Invalid card expiry",type:"invalid_card_expiry"};default:return{fieldType:e,message:"Invalid field",type:"invalid"}}}mapValidationErrors(e={}){const t={};return Object.keys(e).forEach(n=>{var i,r;t[n]=[{message:(null==(r=null==(i=e[n])?void 0:i[0])?void 0:r.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return Sn.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?Sn.CardNumber:Sn.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?Sn.CardExpiry:Sn.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?Sn.CardCode:Sn.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new On(wn.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,i;const r={"font-size":(null==(t=null==e?void 0:e.default)?void 0:t.fontSize)||"1rem","font-family":(null==(n=null==e?void 0:e.default)?void 0:n.fontFamily)||"Montserrat, Arial, Helvetica, sans-serif","font-weight":(null==(i=null==e?void 0:e.default)?void 0:i.fontWeight)||"400",outline:"none",padding:"9px 13px"},a=Nn(Dn({},r),{color:"#333333"});return{input:a,".invalid":Nn(Dn({},r),{color:"red"}),".valid":a,":focus":a}}stylizeInputContainers(e){Object.values(e||{}).forEach(e=>{const t=document.getElementById(`${(null==e?void 0:e.containerId)||""}`);t&&(t.style.padding="0px",t.style.boxShadow="none",t.style.border="none",t.style.background="transparent",t.style.marginBottom="10px",t.style.marginLeft="-5px")})}hasUndefinedValues(){return!this.hostedFormOptions||Object.values(this.hostedFormOptions.fields).some(e=>void 0===e)}onChangeHandler(e,t){var n;null==(n=null==e?void 0:e.onValidate)||n.call(e,this.getValidityData(t))}onFocusHandler(e,t){var n;null==(n=null==e?void 0:e.onFocus)||n.call(e,this.getFieldTypeByEmittedField(t))}onBlurHandler(e,t){var n;null==(n=null==e?void 0:e.onBlur)||n.call(e,this.getFieldTypeByEmittedField(t))}onInputSubmitRequest(e,t){var n;null==(n=null==e?void 0:e.onEnter)||n.call(e,this.getFieldTypeByEmittedField(t))}shouldInitializePayPalFastlane(e){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(e),a=i.getPaymentProviderCustomer(),o=(s=a)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?a:{};var s;return(null==(t=null==r?void 0:r.initializationData)?void 0:t.isAcceleratedCheckoutEnabled)&&(null==(n=null==r?void 0:r.initializationData)?void 0:n.isBigCommercePaymentsAnalyticsV2Enabled)&&!(null==o?void 0:o.authenticationState)}initializePayPalFastlaneOrThrow(e){return xn(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{initializationData:r}=i;if(!(null==r?void 0:r.connectClientToken))return;const a=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(i,n.currency.code,n.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(a,!!(null==r?void 0:r.isDeveloperModeApplicable))}catch(e){}})}}const jn=C(e=>new Un(e,Jt(e),I(),Je()),[{id:"bigcommerce_payments_creditcards"}]);var Vn=Object.getOwnPropertySymbols,Ln=Object.prototype.hasOwnProperty,Rn=Object.prototype.propertyIsEnumerable,Gn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Wn{constructor(e){this.paymentIntegrationService=e}initialize(){return Gn(this,null,function*(){return Promise.resolve()})}execute(e,t){return Gn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Ln.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Vn)for(var i of Vn(e))t.indexOf(i)<0&&Rn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]),{methodId:a}=i||{};if(!i||!a)throw new Oe(["payment"]);const o={methodId:a,paymentData:{formattedPayload:{}}};yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(o)})}finalize(){return Promise.reject(new ze)}deinitialize(){return Promise.resolve()}}const Kn=C(e=>new Wn(e),[{id:"bigcommerce_payments_invoices"}]);var Hn=Object.getOwnPropertySymbols,$n=Object.prototype.hasOwnProperty,qn=Object.prototype.propertyIsEnumerable,Yn=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Jn{constructor(e,t,n,i,r=3e3,a=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdkHelper=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=a,this.pollingTimer=0,this.stopPolling=o,this.isPollingEnabled=!1}initialize(e){return Yn(this,null,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');const r=this.paymentIntegrationService.getState(),a=r.getPaymentMethodOrThrow(n,t),{orderId:o,shouldRenderFields:s}=a.initializationData||{},l=r.getStoreConfigOrThrow().checkoutSettings.features;this.isPollingEnabled=ht(l,"PAYPAL-5624.bcp_ideal_polling"),o?this.orderId=o:(this.paypalApms=yield this.bigCommercePaymentsSdkHelper.getPayPalApmsSdk(a,r.getCartOrThrow().currency.code),this.loadingIndicatorContainer=i.container.split("#")[1],this.renderButton(n,t,i),s&&this.renderFields(n,i))})}execute(e,t){return Yn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)$n.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Hn)for(var i of Hn(e))t.indexOf(i)<0&&qn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);const{methodId:a,gatewayId:o}=i;if(!this.orderId)throw new Ae;this.isPollingEnabled&&"ideal"===a&&(yield new Promise((e,t)=>{this.initializePollingMechanism(a,e,t,o)})),this.isNonInstantPaymentMethod(a)||(yield this.paymentIntegrationService.submitOrder(r,t)),yield this.bigCommercePaymentsIntegrationService.submitPayment(a,this.orderId,o)})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,this.isPollingEnabled&&this.resetPollingMechanism(),null==(e=this.bigCommercePaymentsButton)||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,i){return Yn(this,null,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus(i),a=r===Pt.Approved,o=r===Pt.PollingError;if(a)return this.deInitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigCommercePaymentsAlternativeMethods:this.bigCommercePaymentsAlternativeMethods}),this.handleError(new an)}catch(e){n()}})}deInitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deInitializePollingMechanism()}reinitializeStrategy(e){return Yn(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderButton(e,t,n){const i=this.getPaypalAmpsSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:a}=r.initializationData||{},{container:o,onError:s,onRenderButton:l,submitForm:d}=n,c={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(a),onInit:(e,t)=>n.onInitButton(t),createOrder:()=>this.onCreateOrder(e,t,n),onApprove:e=>this.handleApprove(e,d),onCancel:()=>{this.toggleLoadingIndicator(!1),this.deInitializePollingMechanism()},onError:e=>{this.deInitializePollingMechanism(),this.handleFailure(e,s)},onClick:(e,t)=>Yn(this,null,function*(){return n.onValidate(t.resolve,t.reject)})};this.bigCommercePaymentsButton=i.Buttons(c),this.bigCommercePaymentsButton.isEligible()&&(l&&"function"==typeof l&&l(),this.bigCommercePaymentsButton.render(o))}onCreateOrder(e,t,n){return Yn(this,null,function*(){const{onValidate:i}=n;yield i(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),o);const r=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms");if(this.isNonInstantPaymentMethod(e)){const n={useStoreCredit:!1},i={params:{methodId:e,gatewayId:t}};yield this.paymentIntegrationService.submitOrder(n,i),yield this.bigCommercePaymentsIntegrationService.submitPayment(e,r,t)}return r})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const n=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState(),{firstName:r,lastName:a,email:o}=i.getBillingAddressOrThrow(),{apmFieldsContainer:s,apmFieldsStyles:l}=t;if(!s)throw new we('Unable to initialize payment because "options.bigcommerce_payments_apms" argument should contain "apmFieldsContainer".');const d=document.querySelector(s);d&&(d.innerHTML="");const c={fundingSource:e,style:l||{},fields:{name:{value:`${r} ${a}`},email:{value:o}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in bt}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const Zn=C(e=>new Jn(e,Jt(e),I(),new _e({containerStyles:Ie})),[{gateway:"bigcommerce_payments_apms"}]);var Xn=Object.getOwnPropertySymbols,Qn=Object.prototype.hasOwnProperty,ei=Object.prototype.propertyIsEnumerable;class ti{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.gatewayId" argument is not provided.');return Promise.resolve()}execute(e,t){return n=this,i=function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Qn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Xn)for(var i of Xn(e))t.indexOf(i)<0&&ei.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);const{methodId:a,gatewayId:o}=i;try{const e={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:a,paypal_account:{order_id:yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms",{gatewayId:"bigcommerce_payments_apms",methodId:a})}}};yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment({methodId:a,gatewayId:o,paymentData:e})}catch(e){if(function(e){var t,n;return(e=>"object"==typeof e&&null!==e&&"body"in e)(e)&&(null==(n=null==(t=e.body)?void 0:t.additional_action_required)?void 0:n.data.redirect_url)}(e)){const t=e.body.additional_action_required.data.redirect_url;return new Promise((e,n)=>{window.location.replace(t),n()})}return this.handleError(e),Promise.reject(e)}},new Promise((e,t)=>{var r=e=>{try{o(i.next(e))}catch(e){t(e)}},a=e=>{try{o(i.throw(e))}catch(e){t(e)}},o=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,a);o((i=i.apply(n,null)).next())});var n,i}finalize(){return Promise.reject(new ze)}deinitialize(){return Promise.resolve()}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};t&&"function"==typeof t&&t(e)}}const ni=C(e=>new ti(e,Jt(e)),[{gateway:"bigcommerce_payments_apms",id:"klarna"},{gateway:"bigcommerce_payments_apms",id:"afterpay"}]);var ii=Object.getOwnPropertySymbols,ri=Object.prototype.hasOwnProperty,ai=Object.prototype.propertyIsEnumerable,oi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class si{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n}initialize(e){return oi(this,null,function*(){var t,n;const{methodId:i,bigcommerce_payments_venmo:r}=e||{};if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i);(null==(t=a.initializationData)?void 0:t.orderId)?this.orderId=null==(n=a.initializationData)?void 0:n.orderId:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i),this.loadingIndicatorContainer=r.container.split("#")[1],this.renderButton(i,r))})}execute(e,t){return oi(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)ri.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&ii)for(var i of ii(e))t.indexOf(i)<0&&ai.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new Ae;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new ze)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}renderButton(e,t){const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:a}=r||{},{container:o,onError:s,onRenderButton:l,onValidate:d,submitForm:c}=t,m={fundingSource:n.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(a),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmocheckout"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=n.Buttons(m),!this.paypalButton.isEligible())throw new Zt("Venmo is not available for your region. Please another payment method instead.");l&&"function"==typeof l&&l(),this.paypalButton.render(o)}handleClick(e,t){return oi(this,null,function*(){const{resolve:n,reject:i}=e;yield t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t(),this.toggleLoadingIndicator(!1)}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const li=C(e=>new si(e,Jt(e),new _e({styles:{backgroundColor:"black"}})),[{id:"bigcommerce_payments_venmo"}]);var di=Object.defineProperty,ci=Object.defineProperties,mi=Object.getOwnPropertyDescriptors,ui=Object.getOwnPropertySymbols,hi=Object.prototype.hasOwnProperty,yi=Object.prototype.propertyIsEnumerable,pi=(e,t,n)=>t in e?di(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,gi=(e,t)=>{for(var n in t||(t={}))hi.call(t,n)&&pi(e,n,t[n]);if(ui)for(var n of ui(t))yi.call(t,n)&&pi(e,n,t[n]);return e},vi=(e,t)=>ci(e,mi(t)),bi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Pi{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=o}initialize(e){return bi(this,null,function*(){const{bigcommerce_payments:t,methodId:n}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(!t.container)throw new we('Unable to initialize payment because "options.bigcommerce_payments.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new we('Unable to initialize payment because "options.bigcommerce_payments.onClick" argument is not a function.');this.onError=t.onError||o,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return bi(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return bi(this,null,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i,onComplete:r}=t,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:l,isServerSideShippingCallbacksEnabled:d}=o.initializationData||{},{checkoutTopButtonStyles:c}=l||{},m=gi({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),u=vi(gi({},!d&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,r,d)}),h=gi(gi({fundingSource:a.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(vi(gi({},c),{height:40}))},m),s&&u),y=a.Buttons(h);y.isEligible()?y.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i,r){return bi(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow();try{const o=a.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),o){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}o&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return bi(this,null,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){this.handleError(e)}})}onShippingOptionsChange(e){return bi(this,null,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const fi=C(e=>new Pi(e,Jt(e)),[{id:"bigcommerce_payments"}]);var Si=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class _i{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsSdk=t,this.bigCommercePaymentsFastlaneUtils=n}initialize(e){return Si(this,null,function*(){var t;const{methodId:n,bigcommerce_payments_fastlane:i}=e;if(this.options=e,!n)throw new we('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),r=e.getCartOrThrow(),a=e.getPaymentMethodOrThrow(n),o=!!(null==(t=a.initializationData)?void 0:t.isDeveloperModeApplicable),s=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(a,r.currency.code,r.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(s,o,this.getFastlaneStyles(n,i))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Si(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Si(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t),yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:void 0,addresses:void 0,instruments:void 0}),this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()})}signOut(e){return Si(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Si(this,null,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:i}=e||{};if(!i)throw new we('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new we('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');if(this.paymentIntegrationService.getState().getCustomerOrThrow().isGuest){t&&"function"==typeof t&&t();try{yield this.runPayPalAuthenticationFlowOrThrow(i)}catch(e){this.handleErrorLog(e)}}n()})}runPayPalAuthenticationFlowOrThrow(e){return Si(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,i=t.getCustomer(),r=t.getBillingAddress(),a=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:o}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(a),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(o),l=s.authenticationState===$e.CANCELED;yield this.updateCustomerDataState(e,s),l?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Si(this,null,function*(){var n;const i=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:r,addresses:a,billingAddress:o,shippingAddress:s,instruments:l}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:r,addresses:a,instruments:l}),o&&(yield this.paymentIntegrationService.updateBillingAddress(o)),s&&i.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),i=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:r}=i.initializationData||{},a=(null==(n=(t.getConsignments()||[])[0])?void 0:n.availableShippingOptions)||[],o=a[0],l=a.find(e=>e.isRecommended);if((l||o)&&r){const e=(null==l?void 0:l.id)||o.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:i,isFastlaneStylingEnabled:r}=n.initializationData||{};return mt(r?i:{},null==t?void 0:t.styles)}handleErrorLog(e){const{onErrorLog:t}=this.options||{};t&&"function"==typeof t&&t(e)}}const Ii=C(e=>new _i(e,I(),Je()),[{id:"bigcommerce_payments_fastlane"},{id:"bigcommerce_payments_creditcards"}]);var Ci=Object.defineProperty,wi=Object.defineProperties,Oi=Object.getOwnPropertyDescriptors,Ai=Object.getOwnPropertySymbols,zi=Object.prototype.hasOwnProperty,Ei=Object.prototype.propertyIsEnumerable,ki=(e,t,n)=>t in e?Ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ti=(e,t)=>{for(var n in t||(t={}))zi.call(t,n)&&ki(e,n,t[n]);if(Ai)for(var n of Ai(t))Ei.call(t,n)&&ki(e,n,t[n]);return e},Bi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Mi{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=o}initialize(e){return Bi(this,null,function*(){const{bigcommerce_payments_paylater:t,methodId:n}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(!t.container)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.onClick" argument is not a function.');this.onError=t.onError||o,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC BigCommercePayments PayLater]: button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Bi(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Bi(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onComplete:i,onClick:r}=t,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:l}=o.initializationData||{},{checkoutTopButtonStyles:d}=l||{},c=Ti({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()}),m={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,i)},u=[a.FUNDING.PAYLATER,a.FUNDING.CREDIT];let h=!1;u.forEach(e=>{if(!h){const r=Ti(Ti({fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((t=Ti({},d),i={height:40},wi(t,Oi(i))))},c),s&&m),o=a.Buttons(r);o.isEligible()&&(o.render(`#${n}`),h=!0)}var t,i}),h||this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i){return Bi(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),a=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(a);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(a);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return Bi(this,null,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){this.handleError(e)}})}onShippingOptionsChange(e){return Bi(this,null,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const Fi=C(e=>new Mi(e,Jt(e)),[{id:"bigcommerce_payments_paylater"}]);var Di=Object.defineProperty,Ni=Object.defineProperties,xi=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,ji=Object.prototype.hasOwnProperty,Vi=Object.prototype.propertyIsEnumerable,Li=(e,t,n)=>t in e?Di(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ri=(e,t)=>{for(var n in t||(t={}))ji.call(t,n)&&Li(e,n,t[n]);if(Ui)for(var n of Ui(t))Vi.call(t,n)&&Li(e,n,t[n]);return e},Gi=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Wi{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Gi(this,null,function*(){const{bigcommerce_payments_venmo:t,methodId:n}=e;if(!n)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(!t.container)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC Payments Venmo]: Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Gi(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Gi(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i}=t,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:o}=a.initializationData||{},{checkoutTopButtonStyles:s}=o||{},l=Ri({fundingSource:r.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((d=Ri({},s),c={height:40},Ni(d,xi(c)))),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()});var d,c;const m=r.Buttons(l);m.isEligible()?m.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}}const Ki=C(e=>new Wi(e,Jt(e)),[{id:"bigcommerce_payments_venmo"}]);var Hi=Object.defineProperty,$i=Object.defineProperties,qi=Object.getOwnPropertyDescriptors,Yi=Object.getOwnPropertySymbols,Ji=Object.prototype.hasOwnProperty,Zi=Object.prototype.propertyIsEnumerable,Xi=(e,t,n)=>t in e?Hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qi=(e,t)=>{for(var n in t||(t={}))Ji.call(t,n)&&Xi(e,n,t[n]);if(Yi)for(var n of Yi(t))Zi.call(t,n)&&Xi(e,n,t[n]);return e},er=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class tr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return er(this,null,function*(){var t;const{bigcommerce_payments:n,containerId:i,methodId:r}=e,a=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(a&&!n.currencyCode)throw new we('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==(t=n.buyNowInitializeOptions)?void 0:t.getBuyNowCartRequestBody))throw new we('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const o=a?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(r,o,!1),this.renderButton(i,r,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:a,onEligibilityFailure:o}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},m={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},u={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h=(y=Qi({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),$i(y,qi({onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,a,c)})));var y;const p=Qi(Qi(Qi({fundingSource:s.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},m),i&&u),d&&h),g=s.Buttons(p);g.isEligible()?g.render(`#${e}`):o&&"function"==typeof o?o():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return er(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i,r){return er(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow();try{const o=a.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),o){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}return o&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),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 er(this,null,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 er(this,null,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 nr=C(e=>new tr(e,Jt(e)),[{id:"bigcommerce_payments"}]);var ir=Object.defineProperty,rr=Object.getOwnPropertySymbols,ar=Object.prototype.hasOwnProperty,or=Object.prototype.propertyIsEnumerable,sr=(e,t,n)=>t in e?ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lr=(e,t)=>{for(var n in t||(t={}))ar.call(t,n)&&sr(e,n,t[n]);if(rr)for(var n of rr(t))or.call(t,n)&&sr(e,n,t[n]);return e},dr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class cr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return dr(this,null,function*(){const{bigcommerce_payments_paylater:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:a}=t||{},o=!!r;if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(o&&!a)throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new we('Unable to initialize payment because "options.bigcommerce_payments_paylater.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=this.paymentIntegrationService.getState(),l=o?a:s.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,l,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:a,onEligibilityFailure:o}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d}=l.initializationData||{},c={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},m={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,a)},h=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let y=!1;h.forEach(t=>{if(!y){const n=lr(lr(lr({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},c),i&&m),d&&u),a=s.Buttons(n);a.isEligible()?(a.render(`#${e}`),y=!0):o&&"function"==typeof o&&o()}}),y||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return dr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return dr(this,null,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),a=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(a);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(a);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 dr(this,null,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 dr(this,null,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 mr=C(e=>new cr(e,Jt(e)),[{id:"bigcommerce_payments_paylater"}]);var ur=Object.defineProperty,hr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,pr=Object.getOwnPropertySymbols,gr=Object.prototype.hasOwnProperty,vr=Object.prototype.propertyIsEnumerable,br=(e,t,n)=>t in e?ur(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pr=(e,t)=>{for(var n in t||(t={}))gr.call(t,n)&&br(e,n,t[n]);if(pr)for(var n of pr(t))vr.call(t,n)&&br(e,n,t[n]);return e},fr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Sr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return fr(this,null,function*(){const{bigcommerce_payments_venmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:a}=t||{},o=!!r;if(!i)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(o&&!a)throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new we('Unable to initialize payment because "options.bigcommerce_payments_venmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=o?a: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:a}=n,o=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),s=o.FUNDING.VENMO,l={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},d={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Pr(Pr({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},l),i&&d),m=o.Buttons(c);m.isEligible()?m.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===gt.gold?(n=Pr({},t),hr(n,yr({color:void 0}))):t;var n}handleClick(e){return fr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const _r=C(e=>new Sr(e,Jt(e)),[{id:"bigcommerce_payments_venmo"}]);var Ir=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Cr{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,i){return Ir(this,null,function*(){return this.paypalSdk=yield this.scriptLoader.getPayPalSDK(e,t,void 0,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}proxyTokenizationPayment(e,t,n,i){return Ir(this,null,function*(){var r;if(!i)throw new u(m.MissingOrderId);const a={paymentWalletData:{providerId:t,providerOrderId:i},cartEntityId:e,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:n},{key:"order_id",value:i}]},o=yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(a);if(!(null==(r=o.body.redirectUrls)?void 0:r.externalCheckoutUrl))throw new Error("Failed to redirection to checkout page");window.location.assign(o.body.redirectUrls.externalCheckoutUrl)})}createPaymentOrderIntent(e,t,n){return Ir(this,null,function*(){const i={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(i,this.intentTypename,n)).body.orderId})}addBillingAddress(e,t,n){return Ir(this,null,function*(){return this.walletButtonIntegrationService.addBillingAddress(e,t,n)})}mapOrderDetailsToBillingAddress({payer:e}){var t,n,i,r;return{firstName:e.name.given_name,lastName:e.name.surname,company:"",address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,email:e.email_address,stateOrProvince:null!=(t=e.address.admin_area_1)?t:"",stateOrProvinceCode:null!=(n=e.address.admin_area_1)?n:"",countryCode:e.address.country_code,postalCode:e.address.postal_code,phone:null!=(r=null==(i=e.phone)?void 0:i.phone_number.national_number)?r:"",shouldSaveAddress:!1}}getValidButtonStyle(e={}){const{color:t,height:n,label:i,shape:r}=e,o={color:t&&H[t]?t:void 0,height:this.getValidHeight(n),label:i&&K[i]?i:void 0,shape:r&&$[r]?r:void 0};return l(o,a)}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 wr=Object.defineProperty,Or=Object.getOwnPropertySymbols,Ar=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable,Er=(e,t,n)=>t in e?wr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Tr{constructor(e){this.bigCommercePaymentsWalletService=e}initialize(e){return kr(this,null,function*(){var t,n;const{bigcommerce_paymentspaypal:i,containerId:r,methodId:a}=e;if(!a)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_paymentspaypal" argument is not provided.');let o;try{o=JSON.parse(atob(i.initializationData))}catch(e){throw new we("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsWalletService.loadPayPalSdk(o,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypal",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsWalletService.getPayPalSdkOrThrow(),a={createOrder:()=>this.bigCommercePaymentsWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>kr(this,[e,i],function*({orderID:e},i){const r=yield i.order.get(),a=this.bigCommercePaymentsWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsWalletService.addBillingAddress(n,a),yield this.bigCommercePaymentsWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments",e)})},o=((e,t)=>{for(var n in t||(t={}))Ar.call(t,n)&&Er(e,n,t[n]);if(Or)for(var n of Or(t))zr.call(t,n)&&Er(e,n,t[n]);return e})({fundingSource:r.FUNDING.PAYPAL,style:this.bigCommercePaymentsWalletService.getValidButtonStyle(i)},a),s=r.Buttons(o);s.isEligible()?s.render(`#${e}`):this.bigCommercePaymentsWalletService.removeElement(e)}}const Br=C(e=>new Tr(new Cr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypal"}]);var Mr=Object.defineProperty,Fr=Object.getOwnPropertySymbols,Dr=Object.prototype.hasOwnProperty,Nr=Object.prototype.propertyIsEnumerable,xr=(e,t,n)=>t in e?Mr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ur=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class jr{constructor(e){this.bigCommercePaymentsPayLaterWalletService=e}initialize(e){return Ur(this,null,function*(){var t,n;const{bigcommerce_paymentspaypalcredit:i,containerId:r,methodId:a}=e;if(!a)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_paymentspaypalcredit" argument is not provided.');let o;try{o=JSON.parse(atob(i.initializationData))}catch(e){throw new we("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsPayLaterWalletService.loadPayPalSdk(o,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypalcredit",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsPayLaterWalletService.getPayPalSdkOrThrow(),a=[r.FUNDING.PAYLATER,r.FUNDING.CREDIT],o={createOrder:()=>this.bigCommercePaymentsPayLaterWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>Ur(this,[e,i],function*({orderID:e},i){const r=yield i.order.get(),a=this.bigCommercePaymentsPayLaterWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsPayLaterWalletService.addBillingAddress(n,a),yield this.bigCommercePaymentsPayLaterWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_paylater",e)})};let s=!1;a.forEach(t=>{if(!s){const n=((e,t)=>{for(var n in t||(t={}))Dr.call(t,n)&&xr(e,n,t[n]);if(Fr)for(var n of Fr(t))Nr.call(t,n)&&xr(e,n,t[n]);return e})({fundingSource:t,style:this.bigCommercePaymentsPayLaterWalletService.getValidButtonStyle(i)},o),a=r.Buttons(n);a.isEligible()&&(a.render(`#${e}`),s=!0)}}),s||this.bigCommercePaymentsPayLaterWalletService.removeElement(e)}}const Vr=C(e=>new jr(new Cr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypalcredit"}]);var Lr=Object.defineProperty,Rr=Object.defineProperties,Gr=Object.getOwnPropertyDescriptors,Wr=Object.getOwnPropertySymbols,Kr=Object.prototype.hasOwnProperty,Hr=Object.prototype.propertyIsEnumerable,$r=(e,t,n)=>t in e?Lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,qr=(e,t)=>{for(var n in t||(t={}))Kr.call(t,n)&&$r(e,n,t[n]);if(Wr)for(var n of Wr(t))Hr.call(t,n)&&$r(e,n,t[n]);return e},Yr=(e,t,n)=>new Promise((i,r)=>{var a=e=>{try{s(n.next(e))}catch(e){r(e)}},o=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Jr{constructor(e){this.bigCommercePaymentsVenmoWalletService=e}initialize(e){return Yr(this,null,function*(){var t,n;const{bigcommerce_paymentsvenmo:i,containerId:r,methodId:a}=e;if(!a)throw new we('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new we('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new we('Unable to initialize payment because "options.bigcommerce_paymentsvenmo" argument is not provided.');let o;try{o=JSON.parse(atob(i.initializationData))}catch(e){throw new we("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsVenmoWalletService.loadPayPalSdk(o,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.venmo",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsVenmoWalletService.getPayPalSdkOrThrow(),a={createOrder:()=>this.bigCommercePaymentsVenmoWalletService.createPaymentOrderIntent(t,n),onApprove:e=>Yr(this,[e],function*({orderID:e}){yield this.bigCommercePaymentsVenmoWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_venmo",e)})},o=qr({fundingSource:r.FUNDING.VENMO,style:this.getValidVenmoButtonStyles(i)},a),s=r.Buttons(o);s.isEligible()?s.render(`#${e}`):this.bigCommercePaymentsVenmoWalletService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsVenmoWalletService.getValidButtonStyle(e);return t.color===gt.gold?(n=qr({},t),Rr(n,Gr({color:void 0}))):t;var n}}const Zr=C(e=>new Jr(new Cr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentsvenmo"}]);export{Zn as createBigCommercePaymentsAlternativeMethodsPaymentStrategy,nr as createBigCommercePaymentsButtonStrategy,jn as createBigCommercePaymentsCreditCardsPaymentStrategy,fi as createBigCommercePaymentsCustomerStrategy,Ii as createBigCommercePaymentsFastlaneCustomerStrategy,Tt as createBigCommercePaymentsFastlanePaymentStrategy,Kn as createBigCommercePaymentsInvoicesPaymentStrategy,mr as createBigCommercePaymentsPayLaterButtonStrategy,Fi as createBigCommercePaymentsPayLaterCustomerStrategy,rn as createBigCommercePaymentsPayLaterPaymentStrategy,Vr as createBigCommercePaymentsPayLaterWalletStrategy,xe as createBigCommercePaymentsPaymentStrategy,Pn as createBigCommercePaymentsRatePayPayPaymentStrategy,ni as createBigCommercePaymentsRedirectAlternativeMethodsPaymentStrategy,_r as createBigCommercePaymentsVenmoButtonStrategy,Ki as createBigCommercePaymentsVenmoCustomerStrategy,li as createBigCommercePaymentsVenmoPaymentStrategy,Zr as createBigCommercePaymentsVenmoWalletStrategy,Br as createBigCommercePaymentsWalletStrategy};
2
2
  //# sourceMappingURL=bigcommerce-payments.js.map