@bigcommerce/checkout-sdk 1.995.0 → 1.995.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/checkout-button.js +1 -1
- package/dist/cjs/checkout-sdk-essential.js +1 -1
- package/dist/cjs/checkout-sdk.js +1 -1
- package/dist/cjs/hosted-form-v2-iframe-host.js +1 -1
- package/dist/cjs/integrations/amazon-pay.js +1 -1
- package/dist/cjs/integrations/bigcommerce-payments.js +1 -1
- package/dist/cjs/integrations/braintree.js +1 -1
- package/dist/cjs/integrations/google-pay.js +1 -1
- package/dist/cjs/integrations/klarna.js +1 -1
- package/dist/cjs/integrations/paypal-commerce.js +1 -1
- package/dist/cjs/integrations/paypal-express.js +1 -1
- package/dist/cjs/integrations/zip.js +1 -1
- package/dist/esm/checkout-button.js +1 -1
- package/dist/esm/checkout-sdk-essential.js +1 -1
- package/dist/esm/checkout-sdk.js +1 -1
- package/dist/esm/hosted-form-v2-iframe-host.js +1 -1
- package/dist/esm/integrations/amazon-pay.js +1 -1
- package/dist/esm/integrations/bigcommerce-payments.js +1 -1
- package/dist/esm/integrations/braintree.js +1 -1
- package/dist/esm/integrations/google-pay.js +1 -1
- package/dist/esm/integrations/klarna.js +1 -1
- package/dist/esm/integrations/paypal-commerce.js +1 -1
- package/dist/esm/integrations/paypal-express.js +1 -1
- package/dist/esm/integrations/zip.js +1 -1
- package/package.json +1 -1
|
@@ -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,f=(e,t,n)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,P=(e,t)=>{for(var n in t||(t={}))v.call(t,n)&&f(e,n,t[n]);if(g)for(var n of g(t))b.call(t,n)&&f(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:P({"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:P({"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:P({"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=P({},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 z(e){return window[e]}function A(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,M=Object.getOwnPropertySymbols,B=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={}))B.call(t,n)&&D(e,n,t[n]);if(M)for(var n of M(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(!z(a)||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}const o=z(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:f=[],isGooglePayEnabled:P}=o,S=p||i,_="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,I=_?["card"]:[],C=_?[]:["card"],O=g?["credit","paylater"]:[],z=g?[]:["credit","paylater"],E=y?["venmo"]:[],k=y?[]:["venmo"],T=b.filter(e=>!f.includes(e)),M=P?["googlepay"]:[],B=i?["card-fields"]:[],F=this.filterFundingOptions([...C,...z,...k,...T]),D=this.filterFundingOptions([...I,...O,...E,...f]),x=A(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",...M,...B],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=A(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=A(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=A(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=A(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.995.0"};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,fe=(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 Pe={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Se="embedded-checkout-loading-indicator-rotation";class _e{constructor(e){this.styles=fe(fe({},Pe),e&&e.styles),this.containerStyles=fe({},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 ze 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 Ae 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 Me=Object.getOwnPropertySymbols,Be=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)Be.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Me)for(var i of Me(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 ze;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 Ae)}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,f,P,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==(f=null==(b=null==t?void 0:t.text)?void 0:b.body)?void 0:f.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(S=null==(P=null==t?void 0:t.text)?void 0:P.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||{}),ft=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(ft||{}),Pt=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?Pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zt=(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},At=(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 Ae)}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:zt({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:At(zt({},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 ze;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 ze;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(At(zt({},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 Mt=Object.defineProperty,Bt=Object.getOwnPropertySymbols,Ft=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable,Nt=(e,t,n)=>t in e?Mt(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(Bt)for(var n of Bt(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,arguments,function*(e,t,n,i,{withClientMetadataId:r=!1}={}){var a,o;const s=this.paymentIntegrationService.getState(),l=t||s.getCartOrThrow().currency.code,d=s.getPaymentMethodOrThrow(e),c=r&&ht((null==(a=s.getStoreConfig())?void 0:a.checkoutSettings.features)||{},"PAYPAL-7233.bcp_card_client_metadata_id",!1)?null==(o=s.getCart())?void 0:o.id.replace(/-/g,""):void 0;return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(d,l,n,i,c),this.clientMetadataId=c&&this.bigCommercePaymentsScriptLoader.getClientMetadataId(this.paypalSdk),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(xt({cartId:n},this.clientMetadataId&&{metadataId:this.clientMetadataId}),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&>[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())});const Yt=class e{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return qt(this,null,function*(){const a=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);return this.loadPayPalSDK(a,i)})}getClientMetadataId(t){return e.clientMetadataIds.get(t)}loadPayPalSDK(t,n=!1){return qt(this,null,function*(){if(!this.window.bigCommercePaymentsPayPalSDK||n){const n=this.transformConfig(t.options),i=this.transformConfig(t.attributes),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i});const a=this.window.bigCommercePaymentsPayPalSDK;a&&!e.clientMetadataIds.has(a)&&e.clientMetadataIds.set(a,i["data-client-metadata-id"])}if(!this.window.bigCommercePaymentsPayPalSDK)throw new c;return this.window.bigCommercePaymentsPayPalSDK})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0,i){const{id:r,clientToken:a,initializationData:o}=e;if(!(null==o?void 0: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:f=[],isGooglePayEnabled:P}=o,S=p||n,_="bigcommerce_payments_creditcards"===r,I=_?["card"]:[],C=_?[]:["card"],w=g?["credit","paylater"]:[],O=g?[]:["credit","paylater"],z=y?["venmo"]:[],A=y?[]:["venmo"],E=b.filter(e=>!f.includes(e)),k=P?["googlepay"]:[],T=n?["card-fields"]:[],M=this.filterFundingOptions([...C,...O,...A,...E]),B=this.filterFundingOptions([...I,...w,...z,...f]);return{options:$t({"client-id":l,"merchant-id":d,"enable-funding":B.length>0?B:void 0,"disable-funding":M.length>0?M:void 0,commit:S,components:["buttons","hosted-fields","payment-fields","legal",...k,...T],currency:t,intent:s},v&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":h,"data-client-token":a,"data-client-metadata-id":i,"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}};Yt.clientMetadataIds=new WeakMap;let Jt=Yt;const Zt=e=>{const{getHost:r}=e.getState();return new jt(n(),e,new rt(i({host:r()})),new Jt(t()))};class Xt extends d{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Qt=Object.getOwnPropertySymbols,en=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,nn=(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 rn{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.paypalSdkHelper=i}initialize(e){return nn(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 nn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)en.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Qt)for(var i of Qt(e))t.indexOf(i)<0&&tn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new ze;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new Ae)}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 Xt(`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 nn(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 an=C(e=>new rn(e,Zt(e),new _e({containerStyles:Ie}),I()),[{id:"bigcommerce_payments_paylater"}]);class on extends G{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var sn=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,dn=Object.prototype.propertyIsEnumerable,cn=(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 mn{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 cn(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 cn(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&&sn)for(var i of sn(e))t.indexOf(i)<0&&dn.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 Ae)}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 cn(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return cn(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===ft.PollingStop,o=r===ft.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 on)}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 un=Object.defineProperty,hn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,pn=Object.getOwnPropertySymbols,gn=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable,bn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fn=(e,t)=>{for(var n in t||(t={}))gn.call(t,n)&&bn(e,n,t[n]);if(pn)for(var n of pn(t))vn.call(t,n)&&bn(e,n,t[n]);return e};const Pn=C(e=>{return new mn(e,Zt(e),new _e({containerStyles:(t=fn({},Ie),n={position:"fixed"},hn(t,yn(n)))}));var t,n},[{gateway:"bigcommerce_payments_apms",id:"ratepay"}]);var Sn=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification",e))(Sn||{});const _n=Sn;function In(e){return _n.CardNumber in e&&_n.CardName in e&&_n.CardExpiry in e}function Cn(e){return _n.CardNumberVerification in e&&_n.CardCodeVerification in e&&_n.CardExpiryVerification in e}class wn 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 On=(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))(On||{});class zn 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 En=Object.defineProperty,kn=Object.defineProperties,Tn=Object.getOwnPropertyDescriptors,Mn=Object.getOwnPropertySymbols,Bn=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable,Dn=(e,t,n)=>t in e?En(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nn=(e,t)=>{for(var n in t||(t={}))Bn.call(t,n)&&Dn(e,n,t[n]);if(Mn)for(var n of Mn(t))Fn.call(t,n)&&Dn(e,n,t[n]);return e},xn=(e,t)=>kn(e,Tn(t)),Un=(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){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return Un(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=In(r.fields),this.isCreditCardVaultedForm=Cn(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t,void 0,!0,!0,{withClientMetadataId:!0}),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,a)),null==o||o(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Un(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&&Mn)for(var i of Mn(e))t.indexOf(i)<0&&Fn.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 Ae)}deinitialize(){return Un(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:Nn(Nn({},i||s?{bigpay_token:d}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Un(this,null,function*(){const{fields:n,styles:i}=e,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.getExecuteCallback(n),o=Nn({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 wn},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 zn(On.PaymentNotInitialized);try{this.stylizeInputContainers(n),In(n)&&(yield this.renderFields(n)),Cn(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Cn(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Un(this,null,function*(){const{setupToken:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",xn(Nn({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Un(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 Un(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 Un(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 Un(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 wn("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Un(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=Nn({},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 xn(Nn({},e),{[r]:(null==(i=t[n])?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case _n.CardCode:case _n.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case _n.CardNumber:case _n.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case _n.CardExpiry:case _n.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 _n.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?_n.CardNumber:_n.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?_n.CardExpiry:_n.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?_n.CardCode:_n.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new zn(On.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=xn(Nn({},r),{color:"#333333"});return{input:a,".invalid":xn(Nn({},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 Un(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 Vn=C(e=>new jn(e,Zt(e),I(),Je()),[{id:"bigcommerce_payments_creditcards"}]);var Ln=Object.getOwnPropertySymbols,Rn=Object.prototype.hasOwnProperty,Gn=Object.prototype.propertyIsEnumerable,Wn=(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 Kn{constructor(e){this.paymentIntegrationService=e}initialize(){return Wn(this,null,function*(){return Promise.resolve()})}execute(e,t){return Wn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Rn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Ln)for(var i of Ln(e))t.indexOf(i)<0&&Gn.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 Ae)}deinitialize(){return Promise.resolve()}}const Hn=C(e=>new Kn(e),[{id:"bigcommerce_payments_invoices"}]);var $n=Object.getOwnPropertySymbols,qn=Object.prototype.hasOwnProperty,Yn=Object.prototype.propertyIsEnumerable,Jn=(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 Zn{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 Jn(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 Jn(this,null,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&&$n)for(var i of $n(e))t.indexOf(i)<0&&Yn.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 ze;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 Ae)}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 Jn(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===ft.Approved,o=r===ft.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 on)}catch(e){n()}})}deInitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deInitializePollingMechanism()}reinitializeStrategy(e){return Jn(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)=>Jn(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 Jn(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 Xn=C(e=>new Zn(e,Zt(e),I(),new _e({containerStyles:Ie})),[{gateway:"bigcommerce_payments_apms"}]);var Qn=Object.getOwnPropertySymbols,ei=Object.prototype.hasOwnProperty,ti=Object.prototype.propertyIsEnumerable;class ni{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)ei.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Qn)for(var i of Qn(e))t.indexOf(i)<0&&ti.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 Ae)}deinitialize(){return Promise.resolve()}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};t&&"function"==typeof t&&t(e)}}const ii=C(e=>new ni(e,Zt(e)),[{gateway:"bigcommerce_payments_apms",id:"klarna"},{gateway:"bigcommerce_payments_apms",id:"afterpay"}]);var ri=Object.getOwnPropertySymbols,ai=Object.prototype.hasOwnProperty,oi=Object.prototype.propertyIsEnumerable,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 li{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n}initialize(e){return si(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 si(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)ai.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&ri)for(var i of ri(e))t.indexOf(i)<0&&oi.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new ze;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new Ae)}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 Xt("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 si(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 di=C(e=>new li(e,Zt(e),new _e({styles:{backgroundColor:"black"}})),[{id:"bigcommerce_payments_venmo"}]);var ci=Object.defineProperty,mi=Object.defineProperties,ui=Object.getOwnPropertyDescriptors,hi=Object.getOwnPropertySymbols,yi=Object.prototype.hasOwnProperty,pi=Object.prototype.propertyIsEnumerable,gi=(e,t,n)=>t in e?ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vi=(e,t)=>{for(var n in t||(t={}))yi.call(t,n)&&gi(e,n,t[n]);if(hi)for(var n of hi(t))pi.call(t,n)&&gi(e,n,t[n]);return e},bi=(e,t)=>mi(e,ui(t)),fi=(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 fi(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 fi(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return fi(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=vi({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),u=bi(vi({},!d&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,r,d)}),h=vi(vi({fundingSource:a.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(bi(vi({},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 fi(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 fi(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 fi(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 Si=C(e=>new Pi(e,Zt(e)),[{id:"bigcommerce_payments"}]);var _i=(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 Ii{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsSdk=t,this.bigCommercePaymentsFastlaneUtils=n}initialize(e){return _i(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 _i(this,null,function*(){return Promise.resolve()})}signIn(e,t){return _i(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 _i(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return _i(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 _i(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 _i(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 Ci=C(e=>new Ii(e,I(),Je()),[{id:"bigcommerce_payments_fastlane"},{id:"bigcommerce_payments_creditcards"}]);var wi=Object.defineProperty,Oi=Object.defineProperties,zi=Object.getOwnPropertyDescriptors,Ai=Object.getOwnPropertySymbols,Ei=Object.prototype.hasOwnProperty,ki=Object.prototype.propertyIsEnumerable,Ti=(e,t,n)=>t in e?wi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mi=(e,t)=>{for(var n in t||(t={}))Ei.call(t,n)&&Ti(e,n,t[n]);if(Ai)for(var n of Ai(t))ki.call(t,n)&&Ti(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 Fi{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=Mi({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=Mi(Mi({fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((t=Mi({},d),i={height:40},Oi(t,zi(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 Di=C(e=>new Fi(e,Zt(e)),[{id:"bigcommerce_payments_paylater"}]);var Ni=Object.defineProperty,xi=Object.defineProperties,Ui=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,Vi=Object.prototype.hasOwnProperty,Li=Object.prototype.propertyIsEnumerable,Ri=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gi=(e,t)=>{for(var n in t||(t={}))Vi.call(t,n)&&Ri(e,n,t[n]);if(ji)for(var n of ji(t))Li.call(t,n)&&Ri(e,n,t[n]);return e},Wi=(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 Ki{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Wi(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 Wi(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Wi(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=Gi({fundingSource:r.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((d=Gi({},s),c={height:40},xi(d,Ui(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 Hi=C(e=>new Ki(e,Zt(e)),[{id:"bigcommerce_payments_venmo"}]);var $i=Object.defineProperty,qi=Object.defineProperties,Yi=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,Zi=Object.prototype.hasOwnProperty,Xi=Object.prototype.propertyIsEnumerable,Qi=(e,t,n)=>t in e?$i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,er=(e,t)=>{for(var n in t||(t={}))Zi.call(t,n)&&Qi(e,n,t[n]);if(Ji)for(var n of Ji(t))Xi.call(t,n)&&Qi(e,n,t[n]);return e},tr=(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 nr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return tr(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=er({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),qi(y,Yi({onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,a,c)})));var y;const p=er(er(er({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 tr(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 tr(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 tr(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 tr(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 ir=C(e=>new nr(e,Zt(e)),[{id:"bigcommerce_payments"}]);var rr=Object.defineProperty,ar=Object.getOwnPropertySymbols,or=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable,lr=(e,t,n)=>t in e?rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dr=(e,t)=>{for(var n in t||(t={}))or.call(t,n)&&lr(e,n,t[n]);if(ar)for(var n of ar(t))sr.call(t,n)&&lr(e,n,t[n]);return e},cr=(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 mr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return cr(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=dr(dr(dr({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 cr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return cr(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 cr(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 cr(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 ur=C(e=>new mr(e,Zt(e)),[{id:"bigcommerce_payments_paylater"}]);var hr=Object.defineProperty,yr=Object.defineProperties,pr=Object.getOwnPropertyDescriptors,gr=Object.getOwnPropertySymbols,vr=Object.prototype.hasOwnProperty,br=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pr=(e,t)=>{for(var n in t||(t={}))vr.call(t,n)&&fr(e,n,t[n]);if(gr)for(var n of gr(t))br.call(t,n)&&fr(e,n,t[n]);return e},Sr=(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 _r{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Sr(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),yr(n,pr({color:void 0}))):t;var n}handleClick(e){return Sr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Ir=C(e=>new _r(e,Zt(e)),[{id:"bigcommerce_payments_venmo"}]);var Cr=(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 wr{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,i){return Cr(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 Cr(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 Cr(this,null,function*(){const i={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(i,this.intentTypename,n)).body.orderId})}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 Or=Object.defineProperty,zr=Object.getOwnPropertySymbols,Ar=Object.prototype.hasOwnProperty,Er=Object.prototype.propertyIsEnumerable,kr=(e,t,n)=>t in e?Or(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tr=(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 Mr{constructor(e){this.bigCommercePaymentsWalletService=e}initialize(e){return Tr(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=>Tr(this,[e],function*({orderID:e}){yield this.bigCommercePaymentsWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments",e)})},o=((e,t)=>{for(var n in t||(t={}))Ar.call(t,n)&&kr(e,n,t[n]);if(zr)for(var n of zr(t))Er.call(t,n)&&kr(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 Mr(new wr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypal"}]);var Fr=Object.defineProperty,Dr=Object.getOwnPropertySymbols,Nr=Object.prototype.hasOwnProperty,xr=Object.prototype.propertyIsEnumerable,Ur=(e,t,n)=>t in e?Fr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jr=(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 Vr{constructor(e){this.bigCommercePaymentsPayLaterWalletService=e}initialize(e){return jr(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=>jr(this,[e],function*({orderID:e}){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={}))Nr.call(t,n)&&Ur(e,n,t[n]);if(Dr)for(var n of Dr(t))xr.call(t,n)&&Ur(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 Lr=C(e=>new Vr(new wr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypalcredit"}]);var Rr=Object.defineProperty,Gr=Object.defineProperties,Wr=Object.getOwnPropertyDescriptors,Kr=Object.getOwnPropertySymbols,Hr=Object.prototype.hasOwnProperty,$r=Object.prototype.propertyIsEnumerable,qr=(e,t,n)=>t in e?Rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yr=(e,t)=>{for(var n in t||(t={}))Hr.call(t,n)&&qr(e,n,t[n]);if(Kr)for(var n of Kr(t))$r.call(t,n)&&qr(e,n,t[n]);return e},Jr=(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 Zr{constructor(e){this.bigCommercePaymentsVenmoWalletService=e}initialize(e){return Jr(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=>Jr(this,[e],function*({orderID:e}){yield this.bigCommercePaymentsVenmoWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_venmo",e)})},o=Yr({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=Yr({},t),Gr(n,Wr({color:void 0}))):t;var n}}const Xr=C(e=>new Zr(new wr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentsvenmo"}]);export{Xn as createBigCommercePaymentsAlternativeMethodsPaymentStrategy,ir as createBigCommercePaymentsButtonStrategy,Vn as createBigCommercePaymentsCreditCardsPaymentStrategy,Si as createBigCommercePaymentsCustomerStrategy,Ci as createBigCommercePaymentsFastlaneCustomerStrategy,Tt as createBigCommercePaymentsFastlanePaymentStrategy,Hn as createBigCommercePaymentsInvoicesPaymentStrategy,ur as createBigCommercePaymentsPayLaterButtonStrategy,Di as createBigCommercePaymentsPayLaterCustomerStrategy,an as createBigCommercePaymentsPayLaterPaymentStrategy,Lr as createBigCommercePaymentsPayLaterWalletStrategy,xe as createBigCommercePaymentsPaymentStrategy,Pn as createBigCommercePaymentsRatePayPayPaymentStrategy,ii as createBigCommercePaymentsRedirectAlternativeMethodsPaymentStrategy,Ir as createBigCommercePaymentsVenmoButtonStrategy,Hi as createBigCommercePaymentsVenmoCustomerStrategy,di as createBigCommercePaymentsVenmoPaymentStrategy,Xr 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,f=(e,t,n)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,P=(e,t)=>{for(var n in t||(t={}))v.call(t,n)&&f(e,n,t[n]);if(g)for(var n of g(t))b.call(t,n)&&f(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:P({"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:P({"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:P({"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=P({},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 z(e){return window[e]}function A(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,M=Object.getOwnPropertySymbols,B=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={}))B.call(t,n)&&D(e,n,t[n]);if(M)for(var n of M(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(!z(a)||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}const o=z(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:f=[],isGooglePayEnabled:P}=o,S=p||i,_="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,I=_?["card"]:[],C=_?[]:["card"],O=g?["credit","paylater"]:[],z=g?[]:["credit","paylater"],E=y?["venmo"]:[],k=y?[]:["venmo"],T=b.filter(e=>!f.includes(e)),M=P?["googlepay"]:[],B=i?["card-fields"]:[],F=this.filterFundingOptions([...C,...z,...k,...T]),D=this.filterFundingOptions([...I,...O,...E,...f]),x=A(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",...M,...B],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=A(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=A(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=A(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=A(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.995.1"};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,fe=(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 Pe={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Se="embedded-checkout-loading-indicator-rotation";class _e{constructor(e){this.styles=fe(fe({},Pe),e&&e.styles),this.containerStyles=fe({},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 ze 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 Ae 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 Me=Object.getOwnPropertySymbols,Be=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)Be.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Me)for(var i of Me(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 ze;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 Ae)}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,f,P,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==(f=null==(b=null==t?void 0:t.text)?void 0:b.body)?void 0:f.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(S=null==(P=null==t?void 0:t.text)?void 0:P.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||{}),ft=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(ft||{}),Pt=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?Pt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zt=(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},At=(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 Ae)}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:zt({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:At(zt({},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 ze;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 ze;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(At(zt({},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 Mt=Object.defineProperty,Bt=Object.getOwnPropertySymbols,Ft=Object.prototype.hasOwnProperty,Dt=Object.prototype.propertyIsEnumerable,Nt=(e,t,n)=>t in e?Mt(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(Bt)for(var n of Bt(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,arguments,function*(e,t,n,i,{withClientMetadataId:r=!1}={}){var a,o;const s=this.paymentIntegrationService.getState(),l=t||s.getCartOrThrow().currency.code,d=s.getPaymentMethodOrThrow(e),c=r&&ht((null==(a=s.getStoreConfig())?void 0:a.checkoutSettings.features)||{},"PAYPAL-7233.bcp_card_client_metadata_id",!1)?null==(o=s.getCart())?void 0:o.id.replace(/-/g,""):void 0;return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(d,l,n,i,c),this.clientMetadataId=c&&this.bigCommercePaymentsScriptLoader.getClientMetadataId(this.paypalSdk),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(xt({cartId:n},this.clientMetadataId&&{metadataId:this.clientMetadataId}),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&>[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())});const Yt=class e{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return qt(this,null,function*(){const a=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);return this.loadPayPalSDK(a,i)})}getClientMetadataId(t){return e.clientMetadataIds.get(t)}loadPayPalSDK(t,n=!1){return qt(this,null,function*(){if(!this.window.bigCommercePaymentsPayPalSDK||n){const n=this.transformConfig(t.options),i=this.transformConfig(t.attributes),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i});const a=this.window.bigCommercePaymentsPayPalSDK;a&&!e.clientMetadataIds.has(a)&&e.clientMetadataIds.set(a,i["data-client-metadata-id"])}if(!this.window.bigCommercePaymentsPayPalSDK)throw new c;return this.window.bigCommercePaymentsPayPalSDK})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0,i){const{id:r,clientToken:a,initializationData:o}=e;if(!(null==o?void 0: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:f=[],isGooglePayEnabled:P}=o,S=p||n,_="bigcommerce_payments_creditcards"===r,I=_?["card"]:[],C=_?[]:["card"],w=g?["credit","paylater"]:[],O=g?[]:["credit","paylater"],z=y?["venmo"]:[],A=y?[]:["venmo"],E=b.filter(e=>!f.includes(e)),k=P?["googlepay"]:[],T=n?["card-fields"]:[],M=this.filterFundingOptions([...C,...O,...A,...E]),B=this.filterFundingOptions([...I,...w,...z,...f]);return{options:$t({"client-id":l,"merchant-id":d,"enable-funding":B.length>0?B:void 0,"disable-funding":M.length>0?M:void 0,commit:S,components:["buttons","hosted-fields","payment-fields","legal",...k,...T],currency:t,intent:s},v&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":h,"data-client-token":a,"data-client-metadata-id":i,"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}};Yt.clientMetadataIds=new WeakMap;let Jt=Yt;const Zt=e=>{const{getHost:r}=e.getState();return new jt(n(),e,new rt(i({host:r()})),new Jt(t()))};class Xt extends d{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Qt=Object.getOwnPropertySymbols,en=Object.prototype.hasOwnProperty,tn=Object.prototype.propertyIsEnumerable,nn=(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 rn{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.paypalSdkHelper=i}initialize(e){return nn(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 nn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)en.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Qt)for(var i of Qt(e))t.indexOf(i)<0&&tn.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new ze;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new Ae)}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 Xt(`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 nn(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 an=C(e=>new rn(e,Zt(e),new _e({containerStyles:Ie}),I()),[{id:"bigcommerce_payments_paylater"}]);class on extends G{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var sn=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,dn=Object.prototype.propertyIsEnumerable,cn=(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 mn{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 cn(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 cn(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&&sn)for(var i of sn(e))t.indexOf(i)<0&&dn.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 Ae)}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 cn(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return cn(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===ft.PollingStop,o=r===ft.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 on)}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 un=Object.defineProperty,hn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,pn=Object.getOwnPropertySymbols,gn=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable,bn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fn=(e,t)=>{for(var n in t||(t={}))gn.call(t,n)&&bn(e,n,t[n]);if(pn)for(var n of pn(t))vn.call(t,n)&&bn(e,n,t[n]);return e};const Pn=C(e=>{return new mn(e,Zt(e),new _e({containerStyles:(t=fn({},Ie),n={position:"fixed"},hn(t,yn(n)))}));var t,n},[{gateway:"bigcommerce_payments_apms",id:"ratepay"}]);var Sn=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification",e))(Sn||{});const _n=Sn;function In(e){return _n.CardNumber in e&&_n.CardName in e&&_n.CardExpiry in e}function Cn(e){return _n.CardNumberVerification in e&&_n.CardCodeVerification in e&&_n.CardExpiryVerification in e}class wn 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 On=(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))(On||{});class zn 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 En=Object.defineProperty,kn=Object.defineProperties,Tn=Object.getOwnPropertyDescriptors,Mn=Object.getOwnPropertySymbols,Bn=Object.prototype.hasOwnProperty,Fn=Object.prototype.propertyIsEnumerable,Dn=(e,t,n)=>t in e?En(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nn=(e,t)=>{for(var n in t||(t={}))Bn.call(t,n)&&Dn(e,n,t[n]);if(Mn)for(var n of Mn(t))Fn.call(t,n)&&Dn(e,n,t[n]);return e},xn=(e,t)=>kn(e,Tn(t)),Un=(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){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return Un(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=In(r.fields),this.isCreditCardVaultedForm=Cn(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t,void 0,!0,!0,{withClientMetadataId:!0}),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,a)),null==o||o(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Un(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&&Mn)for(var i of Mn(e))t.indexOf(i)<0&&Fn.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 Ae)}deinitialize(){return Un(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:Nn(Nn({},i||s?{bigpay_token:d}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Un(this,null,function*(){const{fields:n,styles:i}=e,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.getExecuteCallback(n),o=Nn({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 wn},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 zn(On.PaymentNotInitialized);try{this.stylizeInputContainers(n),In(n)&&(yield this.renderFields(n)),Cn(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Cn(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Un(this,null,function*(){const{setupToken:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",xn(Nn({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Un(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 Un(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 Un(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 Un(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 wn("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Un(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=Nn({},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 xn(Nn({},e),{[r]:(null==(i=t[n])?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case _n.CardCode:case _n.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case _n.CardNumber:case _n.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case _n.CardExpiry:case _n.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 _n.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?_n.CardNumber:_n.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?_n.CardExpiry:_n.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?_n.CardCode:_n.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new zn(On.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=xn(Nn({},r),{color:"#333333"});return{input:a,".invalid":xn(Nn({},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 Un(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 Vn=C(e=>new jn(e,Zt(e),I(),Je()),[{id:"bigcommerce_payments_creditcards"}]);var Ln=Object.getOwnPropertySymbols,Rn=Object.prototype.hasOwnProperty,Gn=Object.prototype.propertyIsEnumerable,Wn=(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 Kn{constructor(e){this.paymentIntegrationService=e}initialize(){return Wn(this,null,function*(){return Promise.resolve()})}execute(e,t){return Wn(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)Rn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Ln)for(var i of Ln(e))t.indexOf(i)<0&&Gn.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 Ae)}deinitialize(){return Promise.resolve()}}const Hn=C(e=>new Kn(e),[{id:"bigcommerce_payments_invoices"}]);var $n=Object.getOwnPropertySymbols,qn=Object.prototype.hasOwnProperty,Yn=Object.prototype.propertyIsEnumerable,Jn=(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 Zn{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 Jn(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 Jn(this,null,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&&$n)for(var i of $n(e))t.indexOf(i)<0&&Yn.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 ze;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 Ae)}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 Jn(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===ft.Approved,o=r===ft.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 on)}catch(e){n()}})}deInitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deInitializePollingMechanism()}reinitializeStrategy(e){return Jn(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)=>Jn(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 Jn(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 Xn=C(e=>new Zn(e,Zt(e),I(),new _e({containerStyles:Ie})),[{gateway:"bigcommerce_payments_apms"}]);var Qn=Object.getOwnPropertySymbols,ei=Object.prototype.hasOwnProperty,ti=Object.prototype.propertyIsEnumerable;class ni{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)ei.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Qn)for(var i of Qn(e))t.indexOf(i)<0&&ti.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 Ae)}deinitialize(){return Promise.resolve()}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};t&&"function"==typeof t&&t(e)}}const ii=C(e=>new ni(e,Zt(e)),[{gateway:"bigcommerce_payments_apms",id:"klarna"},{gateway:"bigcommerce_payments_apms",id:"afterpay"}]);var ri=Object.getOwnPropertySymbols,ai=Object.prototype.hasOwnProperty,oi=Object.prototype.propertyIsEnumerable,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 li{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n}initialize(e){return si(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 si(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)ai.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&ri)for(var i of ri(e))t.indexOf(i)<0&&oi.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new Oe(["payment"]);if(!this.orderId)throw new ze;yield this.paymentIntegrationService.submitOrder(r,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new Ae)}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 Xt("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 si(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 di=C(e=>new li(e,Zt(e),new _e({styles:{backgroundColor:"black"}})),[{id:"bigcommerce_payments_venmo"}]);var ci=Object.defineProperty,mi=Object.defineProperties,ui=Object.getOwnPropertyDescriptors,hi=Object.getOwnPropertySymbols,yi=Object.prototype.hasOwnProperty,pi=Object.prototype.propertyIsEnumerable,gi=(e,t,n)=>t in e?ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,vi=(e,t)=>{for(var n in t||(t={}))yi.call(t,n)&&gi(e,n,t[n]);if(hi)for(var n of hi(t))pi.call(t,n)&&gi(e,n,t[n]);return e},bi=(e,t)=>mi(e,ui(t)),fi=(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 fi(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 fi(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return fi(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=vi({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),u=bi(vi({},!d&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,r,d)}),h=vi(vi({fundingSource:a.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(bi(vi({},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 fi(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 fi(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 fi(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 Si=C(e=>new Pi(e,Zt(e)),[{id:"bigcommerce_payments"}]);var _i=(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 Ii{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsSdk=t,this.bigCommercePaymentsFastlaneUtils=n}initialize(e){return _i(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 _i(this,null,function*(){return Promise.resolve()})}signIn(e,t){return _i(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 _i(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return _i(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 _i(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 _i(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 Ci=C(e=>new Ii(e,I(),Je()),[{id:"bigcommerce_payments_fastlane"},{id:"bigcommerce_payments_creditcards"}]);var wi=Object.defineProperty,Oi=Object.defineProperties,zi=Object.getOwnPropertyDescriptors,Ai=Object.getOwnPropertySymbols,Ei=Object.prototype.hasOwnProperty,ki=Object.prototype.propertyIsEnumerable,Ti=(e,t,n)=>t in e?wi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Mi=(e,t)=>{for(var n in t||(t={}))Ei.call(t,n)&&Ti(e,n,t[n]);if(Ai)for(var n of Ai(t))ki.call(t,n)&&Ti(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 Fi{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=Mi({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=Mi(Mi({fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((t=Mi({},d),i={height:40},Oi(t,zi(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 Di=C(e=>new Fi(e,Zt(e)),[{id:"bigcommerce_payments_paylater"}]);var Ni=Object.defineProperty,xi=Object.defineProperties,Ui=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,Vi=Object.prototype.hasOwnProperty,Li=Object.prototype.propertyIsEnumerable,Ri=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gi=(e,t)=>{for(var n in t||(t={}))Vi.call(t,n)&&Ri(e,n,t[n]);if(ji)for(var n of ji(t))Li.call(t,n)&&Ri(e,n,t[n]);return e},Wi=(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 Ki{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Wi(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 Wi(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Wi(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=Gi({fundingSource:r.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle((d=Gi({},s),c={height:40},xi(d,Ui(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 Hi=C(e=>new Ki(e,Zt(e)),[{id:"bigcommerce_payments_venmo"}]);var $i=Object.defineProperty,qi=Object.defineProperties,Yi=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,Zi=Object.prototype.hasOwnProperty,Xi=Object.prototype.propertyIsEnumerable,Qi=(e,t,n)=>t in e?$i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,er=(e,t)=>{for(var n in t||(t={}))Zi.call(t,n)&&Qi(e,n,t[n]);if(Ji)for(var n of Ji(t))Xi.call(t,n)&&Qi(e,n,t[n]);return e},tr=(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 nr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return tr(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=er({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),qi(y,Yi({onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,a,c)})));var y;const p=er(er(er({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 tr(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 tr(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 tr(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 tr(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 ir=C(e=>new nr(e,Zt(e)),[{id:"bigcommerce_payments"}]);var rr=Object.defineProperty,ar=Object.getOwnPropertySymbols,or=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable,lr=(e,t,n)=>t in e?rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dr=(e,t)=>{for(var n in t||(t={}))or.call(t,n)&&lr(e,n,t[n]);if(ar)for(var n of ar(t))sr.call(t,n)&&lr(e,n,t[n]);return e},cr=(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 mr{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return cr(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=dr(dr(dr({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 cr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return cr(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 cr(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 cr(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 ur=C(e=>new mr(e,Zt(e)),[{id:"bigcommerce_payments_paylater"}]);var hr=Object.defineProperty,yr=Object.defineProperties,pr=Object.getOwnPropertyDescriptors,gr=Object.getOwnPropertySymbols,vr=Object.prototype.hasOwnProperty,br=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pr=(e,t)=>{for(var n in t||(t={}))vr.call(t,n)&&fr(e,n,t[n]);if(gr)for(var n of gr(t))br.call(t,n)&&fr(e,n,t[n]);return e},Sr=(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 _r{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return Sr(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),yr(n,pr({color:void 0}))):t;var n}handleClick(e){return Sr(this,null,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Ir=C(e=>new _r(e,Zt(e)),[{id:"bigcommerce_payments_venmo"}]);var Cr=(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 wr{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,i){return Cr(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 Cr(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 Cr(this,null,function*(){const i={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(i,this.intentTypename,n)).body.orderId})}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 Or=Object.defineProperty,zr=Object.getOwnPropertySymbols,Ar=Object.prototype.hasOwnProperty,Er=Object.prototype.propertyIsEnumerable,kr=(e,t,n)=>t in e?Or(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tr=(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 Mr{constructor(e){this.bigCommercePaymentsWalletService=e}initialize(e){return Tr(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=>Tr(this,[e],function*({orderID:e}){yield this.bigCommercePaymentsWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments",e)})},o=((e,t)=>{for(var n in t||(t={}))Ar.call(t,n)&&kr(e,n,t[n]);if(zr)for(var n of zr(t))Er.call(t,n)&&kr(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 Mr(new wr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypal"}]);var Fr=Object.defineProperty,Dr=Object.getOwnPropertySymbols,Nr=Object.prototype.hasOwnProperty,xr=Object.prototype.propertyIsEnumerable,Ur=(e,t,n)=>t in e?Fr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jr=(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 Vr{constructor(e){this.bigCommercePaymentsPayLaterWalletService=e}initialize(e){return jr(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=>jr(this,[e],function*({orderID:e}){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={}))Nr.call(t,n)&&Ur(e,n,t[n]);if(Dr)for(var n of Dr(t))xr.call(t,n)&&Ur(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 Lr=C(e=>new Vr(new wr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypalcredit"}]);var Rr=Object.defineProperty,Gr=Object.defineProperties,Wr=Object.getOwnPropertyDescriptors,Kr=Object.getOwnPropertySymbols,Hr=Object.prototype.hasOwnProperty,$r=Object.prototype.propertyIsEnumerable,qr=(e,t,n)=>t in e?Rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Yr=(e,t)=>{for(var n in t||(t={}))Hr.call(t,n)&&qr(e,n,t[n]);if(Kr)for(var n of Kr(t))$r.call(t,n)&&qr(e,n,t[n]);return e},Jr=(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 Zr{constructor(e){this.bigCommercePaymentsVenmoWalletService=e}initialize(e){return Jr(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=>Jr(this,[e],function*({orderID:e}){yield this.bigCommercePaymentsVenmoWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_venmo",e)})},o=Yr({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=Yr({},t),Gr(n,Wr({color:void 0}))):t;var n}}const Xr=C(e=>new Zr(new wr(e,V(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentsvenmo"}]);export{Xn as createBigCommercePaymentsAlternativeMethodsPaymentStrategy,ir as createBigCommercePaymentsButtonStrategy,Vn as createBigCommercePaymentsCreditCardsPaymentStrategy,Si as createBigCommercePaymentsCustomerStrategy,Ci as createBigCommercePaymentsFastlaneCustomerStrategy,Tt as createBigCommercePaymentsFastlanePaymentStrategy,Hn as createBigCommercePaymentsInvoicesPaymentStrategy,ur as createBigCommercePaymentsPayLaterButtonStrategy,Di as createBigCommercePaymentsPayLaterCustomerStrategy,an as createBigCommercePaymentsPayLaterPaymentStrategy,Lr as createBigCommercePaymentsPayLaterWalletStrategy,xe as createBigCommercePaymentsPaymentStrategy,Pn as createBigCommercePaymentsRatePayPayPaymentStrategy,ii as createBigCommercePaymentsRedirectAlternativeMethodsPaymentStrategy,Ir as createBigCommercePaymentsVenmoButtonStrategy,Hi as createBigCommercePaymentsVenmoCustomerStrategy,di as createBigCommercePaymentsVenmoPaymentStrategy,Xr as createBigCommercePaymentsVenmoWalletStrategy,Br as createBigCommercePaymentsWalletStrategy};
|
|
2
2
|
//# sourceMappingURL=bigcommerce-payments.js.map
|