@bigcommerce/checkout-sdk 1.992.0 → 1.993.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/dist/types/checkout-sdk.d.ts +1 -0
- package/docs/interfaces/CheckoutSettings.md +6 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getScriptLoader as e}from"@bigcommerce/script-loader";import{createFormPoster as t}from"@bigcommerce/form-poster";import{createRequestSender as n}from"@bigcommerce/request-sender";import{isEqual as r,isNil as i,noop as a,omit as o,omitBy as l}from"lodash";function s(e,t){return Object.assign(e,{resolveIds:t})}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 p=(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))(p||{});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"}}const h={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};var y=(e=>(e.PayPal="paypal",e.BigCommercePaymentsPayPalSDK="bigCommercePaymentsPayPalSDK",e.PayPalFastlaneSdk="paypalFastlaneSdk",e.PayPalFastlane="paypalFastlane",e.PayPalGooglePay="paypalGooglePay",e.PayPalApms="paypalApms",e.PayPalMessages="paypalMessages",e))(y||{});const m=["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 g(e){return window[e]}function v(e){if(!e)return;let t;if(e.includes("-")){const[n,r]=e.split("-");t=`${n}_${r.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return m.includes(t)?t:void 0}var f=Object.defineProperty,S=Object.defineProperties,P=Object.getOwnPropertyDescriptors,b=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,w=(e,t,n)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))I.call(t,n)&&w(e,n,t[n]);if(b)for(var n of b(t))_.call(t,n)&&w(e,n,t[n]);return e},O=(e,t)=>S(e,P(t)),E=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class z{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,r,i){return E(this,null,function*(){const a=this.isBigCommercePaymentsMethod(e.id)?y.BigCommercePaymentsPayPalSDK:y.PayPal;if(!g(a)||i){const i=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);yield this.loadPayPalSdk(i)}const o=g(a);if(!o)throw new c;return o})}getPayPalFastlaneSdk(e,t,n,r){return E(this,null,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n,r);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,r,i){return E(this,null,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,r);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return E(this,null,function*(){if(!this.window.paypalApms){const r=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(r),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return E(this,null,function*(){if(!this.window.paypalMessages){const r=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(r)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}isBigCommercePaymentsMethod(e){return e.startsWith("bigcommerce_payments")}loadPayPalSdk(e){return E(this,arguments,function*({options:e,attributes:t}){const n=this.transformConfig(e),r=this.transformConfig(t),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:r})})}getPayPalSdkScriptConfigOrThrow(e,t,n,r=!0){const{id:i,clientToken:a,initializationData:o}=e;if(!o||!o.clientId)throw new u(p.MissingPaymentMethod);const{intent:l,clientId:s,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:m,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:f,isDeveloperModeApplicable:S,availableAlternativePaymentMethods:P=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:I}=o,_=g||r,w="paypalcommercecreditcards"===i||"bigcommerce_payments_creditcards"===i,O=w?["card"]:[],E=w?[]:["card"],z=f?["credit","paylater"]:[],k=f?[]:["credit","paylater"],T=m?["venmo"]:[],A=m?[]:["venmo"],B=P.filter(e=>!b.includes(e)),F=I?["googlepay"]:[],M=r?["card-fields"]:[],N=this.filterFundingOptions([...E,...k,...A,...B]),D=this.filterFundingOptions([...O,...z,...T,...b]),x=v(n);return{options:C(C({"client-id":s,"merchant-id":d,"enable-funding":D.length>0?D:void 0,"disable-funding":N.length>0?N:void 0,commit:_,components:["buttons","hosted-fields","payment-fields","legal",...F,...M],currency:t,intent:l},S&&{"buyer-country":c}),x&&{locale:x}),attributes:C({"data-partner-attribution-id":h,"data-client-token":a},this.isBigCommercePaymentsMethod(i)&&{"data-namespace":y.BigCommercePaymentsPayPalSDK})}}getPayPalFastlaneSdkConfiguration(e,t,n,r){const{clientToken:i,initializationData:a}=e;if(!a||!a.clientId)throw new u(p.MissingPaymentMethod);const{intent:o,clientId:l,merchantId:s,attributionId:d}=a,c=v(r);return{options:O(C({"client-id":l,"merchant-id":s,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":y.PayPalFastlaneSdk,"data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,r=!0){const{clientToken:i,initializationData:a}=e;if(!a||!a.clientId)throw new u(p.MissingPaymentMethod);const{intent:o,clientId:l,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:m}=a,g=h||r,f=v(n);return{options:C(C({"client-id":l,"merchant-id":s,commit:g,components:["googlepay"],currency:t,intent:o},m&&{"buyer-country":d}),f&&{locale:f}),attributes:{"data-partner-attribution-id":c,"data-client-token":i,"data-namespace":y.PayPalGooglePay}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:r}=e;if(!r||!r.clientId)throw new u(p.MissingPaymentMethod);const{intent:i,clientId:a,merchantId:o,buyerCountry:l,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=r,m=this.filterFundingOptions(h),g=this.filterFundingOptions(c.filter(e=>!h.includes(e))),f=v(n);return{options:C(C({"client-id":a,"merchant-id":o,"enable-funding":m.length>0?m:void 0,"disable-funding":g.length>0?g:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},d&&{"buyer-country":l}),f&&{locale:f}),attributes:{"data-partner-attribution-id":s,"data-namespace":y.PayPalApms}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:r}=e;if(!r||!r.clientId)throw new u(p.MissingPaymentMethod);const{clientId:i,merchantId:a,attributionId:o,isDeveloperModeApplicable:l,buyerCountry:s}=r,d=v(n);return{options:C(C({"client-id":i,"merchant-id":a,components:["messages"],currency:t},l&&{"buyer-country":s}),d&&{locale:d}),attributes:{"data-namespace":y.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 r=e[n];null==r||""===r||Array.isArray(r)&&0===r.length||(t=O(C({},t),{[n]:Array.isArray(r)?r.join(","):r}))}),t}}function k(){return new z(e())}class T 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 A={body:{},headers:{},status:0};class B extends d{constructor(e,{message:t,errors:n}={}){const{body:r,headers:i,status:a}=e||A;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=r,this.headers=i,this.status=a,this.errors=n||[]}}var F=(e=>(e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE",e))(F||{}),M=(e=>(e.Always="SCA_ALWAYS",e))(M||{}),N=(e=>(e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored",e))(N||{}),D=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))(D||{}),x=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(x||{}),U=(e=>(e.pill="pill",e.rect="rect",e))(U||{}),L=(e=>(e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized",e))(L||{}),j=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(j||{}),V=Object.defineProperty,R=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,W=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,K=(e,t)=>{for(var n in t||(t={}))G.call(t,n)&&W(e,n,t[n]);if(R)for(var n of R(t))H.call(t,n)&&W(e,n,t[n]);return e},$=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class q{constructor(e,t,n,r){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=n,this.paypalSdkLoader=r}loadPayPalSdk(e,t,n,r){return $(this,null,function*(){const i=this.paymentIntegrationService.getState(),a=t||i.getCartOrThrow().currency.code,o=i.getPaymentMethodOrThrow(e),l=i.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(o,a,l,n,r),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return $(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(p.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new T}})}createOrder(e,t){return $(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r}=yield this.paypalRequestSender.createOrder(e,K({cartId:n},t));return r})}createOrderCardFields(e,t){return $(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r,setupToken:i}=yield this.paypalRequestSender.createOrder(e,K({cartId:n},t));return K({orderId:r},i?{setupToken:i}:{})})}updateOrder(e,t,n,r){return $(this,null,function*(){const i=this.paymentIntegrationService.getState(),a=i.getCartOrThrow();let o;r||(o=i.getConsignmentsOrThrow()[0]);try{yield this.paypalRequestSender.updateOrder(e,K(K({availableShippingOptions:r?[]:null==o?void 0:o.availableShippingOptions,cartId:a.id,selectedShippingOption:r?null:null==o?void 0:o.selectedShippingOption},t?{methodId:t}:{}),n?{orderId:n}:{}))}catch(e){throw new B}})}getOrderStatus(e,t){return $(this,null,function*(){try{const{status:n}=yield this.paypalRequestSender.getOrderStatus(e,t);return n}catch(e){throw new B}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(p.MissingOrderId);return this.formPoster.postForm("/checkout.php",K({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===F.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return $(this,null,function*(){const r={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(K({methodId:e,paymentData:r},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],r=n.find(e=>e.isRecommended),i=(e?n.find(t=>t.id===e):n.find(e=>{if(t.selectedShippingOption){const n=t.selectedShippingOption.id;return e.id===n}return!1}))||r||n[0];if(!i)throw new Error("Your order can't be shipped to this address");return i}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:r,name:{full_name:i}}=n[0].shipping,[a,...o]=i.split(" ");return this.getAddress({firstName:a,lastName:o.join(" "),email:t.email_address,address1:r.address_line_1,address2:r.address_line_2,city:r.admin_area_2,countryCode:r.country_code,postalCode:r.postal_code,stateOrProvinceCode:r.admin_area_1})}getValidButtonStyle(e={}){const{color:t,height:n,label:r,shape:a}=e,o={color:t&&x[t]?t:void 0,height:this.getValidHeight(n),label:r&&D[r]?r:void 0,shape:a&&U[a]?a:void 0};return l(o,i)}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 Y="This API endpoint is for internal use only and may change in the future";var J=(e=>(e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json",e))(J||{});const Z=J,X={"X-Checkout-SDK-Version":"1.992.0"};var Q=Object.defineProperty,ee=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,re=(e,t,n)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))te.call(t,n)&&re(e,n,t[n]);if(ee)for(var n of ee(t))ne.call(t,n)&&re(e,n,t[n]);return e},ae=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class oe{constructor(e){this.requestSender=e}createOrder(e,t){return ae(this,null,function*(){const n=`/api/storefront/payment/${e}`,r=t,i=ie({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.post(n,{headers:i,body:r})).body})}updateOrder(e,t){return ae(this,null,function*(){const n=`/api/storefront/initialization/${e}`,r=t,i=ie({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.put(n,{headers:i,body:r})).body})}getOrderStatus(e,t){return ae(this,null,function*(){const n=`/api/storefront/initialization/${e}`,r=ie({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.get(n,ie({headers:r},t))).body})}}const le=e=>{const{getHost:r}=e.getState();return new q(t(),e,new oe(n({host:r()})),k())};var se=Object.defineProperty,de=Object.getOwnPropertySymbols,ce=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,he=(e,t)=>{for(var n in t||(t={}))ce.call(t,n)&&ue(e,n,t[n]);if(de)for(var n of de(t))pe.call(t,n)&&ue(e,n,t[n]);return e};const ye={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},me="embedded-checkout-loading-indicator-rotation";class ge{constructor(e){this.styles=he(he({},ye),e&&e.styles),this.containerStyles=he({},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=`${me} 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(me))return;const t=document.createElement("style");t.id=me,null==(e=document.head)||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${me} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}class ve extends d{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class fe extends ve{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 Se extends B{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 Pe 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 be(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function Ie(e){return Boolean(e.instrumentId)}const _e=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};function we(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 Ce=Object.getOwnPropertySymbols,Oe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable,ze=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ke{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.payPalSdkScriptLoader=n,this.loadingIndicator=r}initialize(e){return ze(this,null,function*(){var t;const{methodId:n,paypalcommerce:r}=e||{};if(this.paypalcommerce=r,!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),a=i.getPaymentMethodOrThrow(n),{container:o,bannerContainerId:l}=r,{orderId:s,paypalBNPLConfiguration:d=[],isPayPalCreditAvailable:c}=a.initializationData||{};if(void 0!==l){if(!document.getElementById(l))return void console.error("Unable to create banner without valid banner container ID.");const e=null==d?void 0:d.find(({id:e})=>"checkout"===e);if(c||!(null==e?void 0:e.status))return;const t=yield this.payPalSdkScriptLoader.getPayPalMessages(a,i.getCartOrThrow().currency.code,i.getLocale());return t&&"function"==typeof(null==t?void 0:t.Messages)?this.renderMessages(t,l,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}s?this.orderId=null==(t=a.initializationData)?void 0:t.orderId:(this.loadingIndicatorContainer=null==o?void 0:o.split("#")[1],yield this.paypalIntegrationService.loadPayPalSdk(n),r.onInit&&"function"==typeof r.onInit&&r.onInit(()=>this.renderButton(n,r)),(void 0===r.shouldRenderPayPalButtonOnInitialization||r.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(n,r))})}execute(e,t){return ze(this,null,function*(){var n,r;const i=e,{payment:a}=i,o=((e,t)=>{var n={};for(var r in e)Oe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Ce)for(var r of Ce(e))t.indexOf(r)<0&&Ee.call(e,r)&&(n[r]=e[r]);return n})(i,["payment"]),{onError:l}=this.paypalcommerce||{};if(!a)throw new fe(["payment"]);const{methodId:s,paymentData:d}=a;if(this.isPayPalVaultedInstrumentPaymentData(d)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new Se;const c=this.isPayPalVaultedInstrumentPaymentData(d)?this.prepareVaultedInstrumentPaymentPayload(s,this.orderId,d):this.preparePaymentPayload(s,this.orderId,d);try{yield this.paymentIntegrationService.submitOrder(o,t),yield this.paymentIntegrationService.submitPayment(c)}catch(e){if(function(e){var t;return(e=>"object"==typeof e&&null!==e&&"body"in e)(e)&&"offsite_redirect"===(null==(t=e.body.additional_action_required)?void 0:t.type)}(e)){const t=null==(r=null==(n=e.body.additional_action_required)?void 0:n.data)?void 0:r.redirect_url;return new Promise(()=>window.location.replace(t))}return this.isProviderError(e)&&(yield this.paypalIntegrationService.loadPayPalSdk(a.methodId),yield new Promise((e,t)=>{var n;this.paypalcommerce&&(null==(n=this.paypalButton)||n.close(),this.renderButton(a.methodId,this.paypalcommerce),this.handleError(new Error("INSTRUMENT_DECLINED"),l)),t()})),this.handleError(e,l),Promise.reject()}})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:r,shouldSetAsDefaultInstrument:i}=n,a=!this.isTrustedVaultingFlow(n);return a?{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:i,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:r,shouldSetAsDefaultInstrument:i,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:r}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:i=!1}=be(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:r,shouldSetAsDefaultInstrument:i,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:i}=r.initializationData||{},{checkoutPaymentButtonStyles:a}=i||{},{container:o,onError:l,onRenderButton:s,onValidate:d,submitForm:c}=t;if(!o)throw new ve('Unable to initialize payment because "container" argument is not provided.');const p=this.getSmartButtonContainerId(o);if(!document.getElementById(p))throw new ve(`Unable to initialize payment because element with id ${p} does not exist.`);const u={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,l),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(u),this.paypalButton.isEligible()&&(s&&"function"==typeof s&&s(),this.paypalButton.render(o))}handleClick(e,t){return ze(this,null,function*(){const{resolve:n,reject:r}=e;return null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),r)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return ze(this,null,function*(){const e=this.getFieldsValues();return this.paypalIntegrationService.createOrder("paypalcommercecheckout",{shouldSaveInstrument:(null==e?void 0:e.shouldSaveInstrument)||!1})})}getFieldsValues(){const{getFieldsValues:e}=this.paypalcommerce||{};return"function"==typeof e?e():void 0}isTrustedVaultingFlow(e){if(e&&Ie(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>we(t)&&t.bigpayToken===e.instrumentId);return!(we(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&Ie(e)&&be(e)}renderMessages(e,t,n){const r={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:_e(n)};e.Messages(r).render(`#${t}`)}isProviderError(e){var t,n,r;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null==(r=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:r.code)}getSmartButtonContainerId(e){var t;return null!=(t=e.split("#")[1])?t:e}}const Te=s(t=>new ke(t,le(t),new z(e()),new ge({containerStyles:h})),[{id:"paypalcommerce"}]);class Ae extends d{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Be=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,Ne=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class De{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n,this.payPalSdkScriptLoader=r}initialize(e){return Ne(this,null,function*(){const{methodId:t,paypalcommerce:n,paypalcommercecredit:r}=e||{},i=r||n;if(!t)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const a=this.paymentIntegrationService.getState(),o=a.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:l=[],orderId:s}=o.initializationData||{},{bannerContainerId:d,container:c}=i;if(void 0!==d){if(!document.getElementById(d))return void console.error("Unable to create banner without valid banner container ID.");const e=l&&l.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.payPalSdkScriptLoader.getPayPalMessages(o,a.getCartOrThrow().currency.code,a.getLocale());return this.renderMessages(t,d,e)}s?this.orderId=s:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,i))})}execute(e,t){return Ne(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Fe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Be)for(var r of Be(e))t.indexOf(r)<0&&Me.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);if(!this.orderId)throw new Se;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(r.methodId,this.orderId)})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new ve('Unable to initialize payment because "container" argument is not provided.');const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:i}=r.initializationData||{},{checkoutPaymentButtonStyles:a}=i||{},{container:o,onError:l,onRenderButton:s,onValidate:d,submitForm:c}=t,p=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let u=!1;p.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,l)};if(this.paypalButton=n.Buttons(t),this.paypalButton.isEligible()||e!==n.FUNDING.PAYLATER){if(!this.paypalButton.isEligible()&&e===n.FUNDING.CREDIT)throw new Ae(`PayPal ${e} is not available for your region. Please use PayPal Checkout instead.`);s&&"function"==typeof s&&s(),this.paypalButton.render(o),u=!0}})}handleClick(e,t){return Ne(this,null,function*(){const{resolve:n,reject:r}=e;if(t&&"function"==typeof t)return t(()=>(this.toggleLoadingIndicator(!0),n()),r)})}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 r={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:_e(n)};e.Messages(r).render(`#${t}`)}}const xe=s(e=>new De(e,le(e),new ge({containerStyles:h}),k()),[{id:"paypalcommercecredit"}]);var Ue=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Re{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n}initialize(e){return Ve(this,null,function*(){var t,n;const{methodId:r,paypalcommerce:i,paypalcommercevenmo:a}=e||{},o=a||i;if(!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!o)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(r);const l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(r);(null==(t=l.initializationData)?void 0:t.orderId)?this.orderId=null==(n=l.initializationData)?void 0:n.orderId:(yield this.paypalIntegrationService.loadPayPalSdk(r),this.loadingIndicatorContainer=o.container.split("#")[1],this.renderButton(r,o))})}execute(e,t){return Ve(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Le.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Ue)for(var r of Ue(e))t.indexOf(r)<0&&je.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);if(!this.orderId)throw new Se;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(r.methodId,this.orderId)})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:i}=r.initializationData||{},{checkoutPaymentButtonStyles:a}=i||{},{container:o,onError:l,onRenderButton:s,onValidate:d,submitForm:c}=t,p={fundingSource:n.FUNDING.VENMO,style:this.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercevenmocheckout"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,l)};if(this.paypalButton=n.Buttons(p),!this.paypalButton.isEligible())throw new Ae("PayPal Venmo is not available for your region. Please use PayPal Checkout instead.");s&&"function"==typeof s&&s(),this.paypalButton.render(o)}handleClick(e,t){return Ve(this,null,function*(){const{resolve:n,reject:r}=e;return t(()=>(this.toggleLoadingIndicator(!0),n()),r)})}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 Ge=s(e=>new Re(e,le(e),new ge({containerStyles:h,styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]),He={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class We extends B{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var Ke=(e=>(e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES",e))(Ke||{}),$e=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))($e||{}),qe=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(qe||{}),Ye=(e=>(e.pill="pill",e.rect="rect",e))(Ye||{}),Je=(e=>(e.OXXO="oxxo",e.IDEAL="ideal",e))(Je||{}),Ze=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(Ze||{}),Xe=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,tt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class nt{constructor(e,t,n,r,i=3e3,o=3e5){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalSdkScriptLoader=n,this.loadingIndicator=r,this.pollingInterval=i,this.maxPollingIntervalTime=o,this.pollingTimer=0,this.stopPolling=a,this.isOrderApprovedProcessing=!1}initialize(e){return tt(this,null,function*(){const{gatewayId:t,methodId:n,paypalcommerce:r,paypalcommercealternativemethods:i}=e,a=i||r;if(this.paypalcommercealternativemethods=i,!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!a)throw new ve('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');const o=this.paymentIntegrationService.getState(),l=o.getPaymentMethodOrThrow(n,t),{orderId:s,shouldRenderFields:d}=l.initializationData||{},c=o.getStoreConfigOrThrow().checkoutSettings.features;this.isOrderApprovedProcessing=function(e,t,n=!0){var r;return null!=(r=e["PAYPAL-5431.order_approved_processing"])?r:n}(c,0,!1),s?this.orderId=s:(this.paypalApms=yield this.paypalSdkScriptLoader.getPayPalApmsSdk(l,o.getCartOrThrow().currency.code,o.getLocale()),this.loadingIndicatorContainer=a.container.split("#")[1],this.renderButton(n,t,a),d&&this.renderFields(n,a))})}execute(e,t){return tt(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Qe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Xe)for(var r of Xe(e))t.indexOf(r)<0&&et.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);const{methodId:a,gatewayId:o}=r;if(!this.orderId)throw new Se;this.isOrderApprovedProcessing||"ideal"!==a||(yield new Promise((e,t)=>{this.initializePollingMechanism(a,e,t,o)})),this.isNonInstantPaymentMethod(a)&&(a!==Je.IDEAL||this.isOrderApprovedProcessing)||(yield this.paymentIntegrationService.submitOrder(i,t)),yield this.paypalCommerceIntegrationService.submitPayment(a,this.orderId,o)})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,this.isOrderApprovedProcessing||this.resetPollingMechanism(),null==(e=this.paypalButton)||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,r){return tt(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 i=yield this.paypalCommerceIntegrationService.getOrderStatus(null!=r?r:"paypalcommerce"),a=i===Ze.Approved,o=i===Ze.PollingError;if(a)return this.deinitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,r);yield this.reinitializeStrategy({methodId:e,gatewayId:r,paypalcommercealternativemethods:this.paypalcommercealternativemethods}),this.handleError(new We)}catch(e){n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return tt(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.paypalcommercealternativemethods||{};this.isOrderApprovedProcessing||this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderButton(e,t,n){const r=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:a}=i.initializationData||{},{container:o,onError:l,onRenderButton:s,submitForm:d}=n,c={fundingSource:e,style:this.paypalCommerceIntegrationService.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,l)},onClick:(e,t)=>tt(this,null,function*(){return n.onValidate(t.resolve,t.reject)})};this.paypalButton=r.Buttons(c),this.paypalButton.isEligible()&&(s&&"function"==typeof s&&s(),this.paypalButton.render(o))}onCreateOrder(e,t,n){return tt(this,null,function*(){var r;const{onValidate:i}=n;yield i(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),a);const o=yield this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethodscheckout");if(this.isNonInstantPaymentMethod(e)&&(e===Je.IDEAL&&this.isOrderApprovedProcessing||e===Je.OXXO)){const n={useStoreCredit:!1},i={params:{methodId:e,gatewayId:t}};if(yield this.paymentIntegrationService.submitOrder(n,i),e===Je.IDEAL){const t=null==(r=this.paymentIntegrationService.getState().getOrder())?void 0:r.orderId;yield this.paypalCommerceIntegrationService.updateOrder("paypalcommercealternativemethods",e,t)}yield this.paypalCommerceIntegrationService.submitPayment(e,o,t)}return o})}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(),r=this.paymentIntegrationService.getState(),{firstName:i,lastName:a,email:o}=r.getBillingAddressOrThrow(),{apmFieldsContainer:l,apmFieldsStyles:s}=t;if(!l)throw new ve('Unable to initialize payment because "options.paypalcommercealternativemethods" argument should contain "apmFieldsContainer".');const d=document.querySelector(l);d&&(d.innerHTML="");const c={fundingSource:e,style:s||{},fields:{name:{value:`${i} ${a}`},email:{value:o}}};n.PaymentFields(c).render(l)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in Je}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const rt=s(e=>new nt(e,le(e),k(),new ge({containerStyles:He})),[{gateway:"paypalcommercealternativemethods"}]);var it=(e=>(e.CVV="cvv",e.PAN="pan",e))(it||{}),at=Object.defineProperty,ot=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,dt=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;class ct{static get(e){const t=`${encodeURIComponent(e)}=`,n=document.cookie;let r=null;const i=n.indexOf(t);if(i>-1){let e=n.indexOf(";",i);-1===e&&(e=n.length),r=decodeURIComponent(n.substring(i+t.length,e))}return r}static set(e,t,n={secure:!0}){let r=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:i,path:a,domain:o,secure:l}=n;if(i)r+=`; expires=${i.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),r+=`; expires=${e.toUTCString()}`}a&&(r+=`; path=${a}`),o&&(r+=`; domain=${o}`),l&&(r+="; secure"),document.cookie=r}static remove(e,t){ct.set(e,"",((e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&dt(e,n,t[n]);if(ot)for(var n of ot(t))st.call(t,n)&&dt(e,n,t[n]);return e})({expires:new Date(0)},t))}}var pt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ut{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return pt(this,null,function*(){if(t&&(window.localStorage.setItem("fastlaneEnv","sandbox"),window.localStorage.setItem("axoEnv","sandbox")),!this.window.paypalFastlane){const t={root:{backgroundColorPrimary:"transparent"}};this.window.paypalFastlane=yield e.Fastlane({styles:n||t})}return this.window.paypalFastlane})}getPayPalFastlaneOrThrow(){if(!this.window.paypalFastlane)throw new c;return this.window.paypalFastlane}lookupCustomerOrThrow(e){return pt(this,null,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return pt(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};ct.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){ct.remove("bc-fastlane-sessionId")}getStorageSessionId(){return ct.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,r,i;const{authenticationState:a,profileData:o}=t,l=null==(i=null==(r=null==(n=null==o?void 0:o.card)?void 0:n.paymentSource)?void 0:r.card)?void 0:i.billingAddress,s=null==o?void 0:o.shippingAddress,d=null==o?void 0:o.name,c=null==o?void 0:o.card,p=s?this.mapPayPalToBcAddress(s.address,s.name,s.phoneNumber):void 0,u=l&&d?this.mapPayPalToBcAddress(l,d,null==s?void 0:s.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([p,u]);return{authenticationState:a||L.UNRECOGNIZED,addresses:y,billingAddress:u,shippingAddress:p,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:r}=t,{brand:i,expiry:a,lastDigits:o}=r.card,[l,s]=a.split("-");return[{bigpayToken:n,brand:i,defaultInstrument:!1,expiryMonth:s,expiryYear:l,iin:"",last4:o,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:it.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,r){const[i,a]=t.fullName.split(" "),o=(null==n?void 0:n.nationalNumber)||"",l=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||i||"",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:l+o,customFields:r||[]}}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 o(e,["id","phone"])}}function ht(){return new ut}var yt=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification",e))(yt||{});const mt=yt;function gt(e){return mt.CardNumber in e&&mt.CardName in e&&mt.CardExpiry in e}function vt(e){return mt.CardNumberVerification in e&&mt.CardCodeVerification in e&&mt.CardExpiryVerification in e}class ft extends d{constructor(){super("Your bank declined authentication, please use a different card."),this.name="PaymentMethodBankDeclinedAuthenticationError",this.type="bank_declined_authentication"}}class St 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 Pt=(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))(Pt||{});class bt 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 It 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 _t=Object.defineProperty,wt=Object.defineProperties,Ct=Object.getOwnPropertyDescriptors,Ot=Object.getOwnPropertySymbols,Et=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,kt=(e,t,n)=>t in e?_t(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tt=(e,t)=>{for(var n in t||(t={}))Et.call(t,n)&&kt(e,n,t[n]);if(Ot)for(var n of Ot(t))zt.call(t,n)&&kt(e,n,t[n]);return e},At=(e,t)=>wt(e,Ct(t)),Bt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Ft{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=r,this.isBankDeclinedAuthentication=!1}initialize(e){return Bt(this,null,function*(){const{methodId:t,paypalcommercecreditcards:n,paypalcommerce:r}=e,i=n||r,{form:a,onCreditCardFieldsRenderingError:o,onLoadComplete:l}=i||{};if(!t)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!a)throw new ve('Unable to proceed because "options.paypalcommercecreditcards.form" argument is not provided.');this.hostedFormOptions=a,this.isCreditCardForm=gt(a.fields),this.isCreditCardVaultedForm=vt(a.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.paypalIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(a,o)),null==l||l(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Bt(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Et.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Ot)for(var r of Ot(e))t.indexOf(r)<0&&zt.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]),{methodId:a,paymentData:o}=r||{};if(!r||!a)throw new fe(["payment"]);if(this.executionPaymentData=o,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const l=this.preparePaymentPayload(a,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(l)})}finalize(){return Promise.reject(new Pe)}deinitialize(){return Bt(this,null,function*(){var e,t,n,r;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==(r=this.nameField)?void 0:r.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,r){const{shouldSaveInstrument:a=!1,shouldSetAsDefaultInstrument:o=!1}=be(t)?t:{},s=t&&Ie(t)?t.instrumentId:void 0,d=l({verification_nonce:r,token:s},i);return{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:o,instrumentId:s,formattedPayload:Tt(Tt({},r||s?{bigpay_token:d}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Bt(this,null,function*(){const{fields:n,styles:r}=e,i=this.paypalIntegrationService.getPayPalSdkOrThrow(),a=this.getExecuteCallback(n),o=Tt({style:this.getInputStyles(r),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===Ke.No||n===Ke.Unknown)throw this.isBankDeclinedAuthentication=!0,new ft;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new St},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 i.CardFields(o),!this.cardFields.isEligible())throw new bt(Pt.PaymentNotInitialized);try{this.stylizeInputContainers(n),gt(n)&&(yield this.renderFields(n)),vt(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return vt(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Bt(this,null,function*(){const{setupToken:e}=(yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",At(Tt({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Bt(this,null,function*(){const{orderId:e}=(yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",this.getInstrumentParams()))||{};return e})}}handleApprove({orderID:e,vaultSetupToken:t}){e&&(this.returnedOrderId=e),t&&(this.returnedVaultedToken=t)}renderFields(e){return Bt(this,null,function*(){var t,n,r,i;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==(r=e.cardName)?void 0:r.containerId)&&(this.nameField=a.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null==(i=e.cardNumber)?void 0:i.containerId)&&(this.numberField=a.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return Bt(this,null,function*(){var t,n,r;const i=this.getCardFieldsOrThrow();(null==(t=e.cardCodeVerification)?void 0:t.containerId)&&(this.cvvField=i.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null==(n=e.cardExpiryVerification)?void 0:n.containerId)&&(this.expiryField=i.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null==(r=e.cardNumberVerification)?void 0:r.containerId)&&(this.numberField=i.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(be(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(Ie(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return Bt(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}};this.isBankDeclinedAuthentication=!1;try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){if(this.isBankDeclinedAuthentication)throw new ft;throw new St("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Bt(this,null,function*(){var e,t;const n=this.getCardFieldsOrThrow(),r=yield n.getState().then(e=>e),i=this.getValidityData(r);if(!i.isValid)throw null==(t=null==(e=this.hostedFormOptions)?void 0:e.onValidate)||t.call(e,i),new It(this.mapValidationErrors(i.errors))})}getValidityData({fields:e}){const t=Tt({},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 r;const i=this.mapFieldType(n);return At(Tt({},e),{[i]:(null==(r=t[n])?void 0:r.isValid)?void 0:[this.getInvalidErrorByFieldType(i)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case mt.CardCode:case mt.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case mt.CardNumber:case mt.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case mt.CardExpiry:case mt.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 r,i;t[n]=[{message:(null==(i=null==(r=e[n])?void 0:r[0])?void 0:i.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return mt.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?mt.CardNumber:mt.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?mt.CardExpiry:mt.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?mt.CardCode:mt.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new bt(Pt.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,r;const i={"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==(r=null==e?void 0:e.default)?void 0:r.fontWeight)||"400",outline:"none",padding:"9px 13px"},a=At(Tt({},i),{color:"#333333"});return{input:a,".invalid":At(Tt({},i),{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 r=this.paymentIntegrationService.getState(),i=r.getPaymentMethodOrThrow(e),a=r.getPaymentProviderCustomer(),o=(l=a)&&("authenticationState"in l||"addresses"in l||"instruments"in l)?a:{};var l;return(null==(t=null==i?void 0:i.initializationData)?void 0:t.isAcceleratedCheckoutEnabled)&&(null==(n=null==i?void 0:i.initializationData)?void 0:n.isPayPalCommerceAnalyticsV2Enabled)&&!(null==o?void 0:o.authenticationState)}initializePayPalFastlaneOrThrow(e){return Bt(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),r=t.getPaymentMethodOrThrow(e),{initializationData:i}=r;if(!(null==i?void 0:i.connectClientToken))return;const a=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(r,n.currency.code,n.id,t.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(a,!!(null==i?void 0:i.isDeveloperModeApplicable))}catch(e){}})}}const Mt=s(e=>new Ft(e,le(e),k(),ht()),[{id:"paypalcommercecreditcards"}]);var Nt=Object.getOwnPropertySymbols,Dt=Object.prototype.hasOwnProperty,xt=Object.prototype.propertyIsEnumerable,Ut=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Lt{constructor(e,t,n,r=3e3,i=3e5){this.paymentIntegrationService=e,this.paypalCommerceService=t,this.loadingIndicator=n,this.pollingInterval=r,this.maxPollingIntervalTime=i,this.pollingTimer=0,this.stopPolling=a}initialize(e){return Ut(this,null,function*(){const{gatewayId:t,methodId:n,paypalcommerceratepay:r}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommerceratepay" argument is not provided.');const{legalTextContainer:i,container:a,loadingContainerId:o}=r;if(!a)throw new ve('Unable to initialize payment because "options.container" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!o)throw new ve('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=o;const l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:s}=l.initializationData||{};if(!s)throw new ve("Unable to initialize payment because merchantId argument is not provided.");this.paypalcommerceratepay=r,yield this.paypalCommerceService.loadPayPalSdk(n),this.createFraudNetScript(s,n,t),this.loadFraudnetConfig(),this.renderLegalText(i,a)})}execute(e,t){return Ut(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Dt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Nt)for(var r of Nt(e))t.indexOf(r)<0&&xt.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]),{getFieldsValues:a}=this.paypalcommerceratepay||{};if(!r)throw new fe(["payment"]);if(!a||"function"!=typeof a)throw new ve('Unable to initialize payment because "options.getFieldsValues" argument is not provided.');this.toggleLoadingIndicator(!0);try{const e=yield this.paypalCommerceService.createOrder("paypalcommercealternativemethodscheckout",{metadataId:this.guid}),{ratepayBirthDate:n,ratepayPhoneNumber:o,ratepayPhoneCountryCode:l}=a(),s={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:r.methodId,rate_pay:{birth_date:this.normalizeDate(n),phone:{national_number:o,country_code:l.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:r.methodId,paymentData:s}),yield new Promise((e,t)=>{this.initializePollingMechanism(r.methodId,e,t,r.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new Pe)}deinitialize(){const{legalTextContainer:e}=this.paypalcommerceratepay||{},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,r=t.split("#")[1],i=document.getElementById(r),a=null==i?void 0:i.parentNode,o=document.createElement("div");o.style.marginBottom="20px",o.setAttribute("id",n),null==a||a.prepend(o);const l=this.paypalCommerceService.getPayPalSdkOrThrow(),s=l.Legal({fundingSource:l.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new ve('Unable to initialize payment because "legalTextContainerElement" argument is not found.');s.render(`#${n}`)}handleError(e){const{onError:t}=this.paypalcommerceratepay||{};this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createFraudNetScript(e,t,n){const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:i}=r.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:i};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 Ut(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,r){return Ut(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 i=yield this.paypalCommerceService.getOrderStatus("paypalcommercealternativemethods",{params:{useMetadata:!0}}),a=i===j.PollingStop,o=i===j.PollingError;if(a)return this.deinitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,r);yield this.reinitializeStrategy({methodId:e,gatewayId:r,paypalcommerceratepay:this.paypalcommerceratepay}),this.handleError(new We)}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 jt=Object.defineProperty,Vt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,Ht=Object.prototype.hasOwnProperty,Wt=Object.prototype.propertyIsEnumerable,Kt=(e,t,n)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$t=(e,t)=>{for(var n in t||(t={}))Ht.call(t,n)&&Kt(e,n,t[n]);if(Gt)for(var n of Gt(t))Wt.call(t,n)&&Kt(e,n,t[n]);return e};const qt=s(e=>{return new Lt(e,le(e),new ge({containerStyles:(t=$t({},h),n={position:"fixed"},Vt(t,Rt(n)))}));var t,n},[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);var Yt=Object.defineProperty,Jt=Object.getOwnPropertySymbols,Zt=Object.prototype.hasOwnProperty,Xt=Object.prototype.propertyIsEnumerable,Qt=(e,t,n)=>t in e?Yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,en=(e,t)=>{for(var n in t||(t={}))Zt.call(t,n)&&Qt(e,n,t[n]);if(Jt)for(var n of Jt(t))Xt.call(t,n)&&Qt(e,n,t[n]);return e},tn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class nn{constructor(e){this.requestSender=e}createOrder(e,t){return tn(this,null,function*(){const n=`/api/storefront/payment/${e}`,r=t,i=en({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.post(n,{headers:i,body:r})).body})}updateOrder(e){return tn(this,null,function*(){const t=e,n=en({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:n,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return tn(this,null,function*(){const n=`/api/storefront/initialization/${e}`,r=en({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.get(n,en({headers:r},t))).body})}}var rn=Object.defineProperty,an=Object.getOwnPropertySymbols,on=Object.prototype.hasOwnProperty,ln=Object.prototype.propertyIsEnumerable,sn=(e,t,n)=>t in e?rn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function dn(e){return"string"!=typeof e}function cn(e,t){if(t||e)return function(e){var t,n;const r={},i=l(e.root,dn),a=l(e.input,dn),o=l(e.toggle,dn),s=l(null==(t=e.text)?void 0:t.body,dn),d=l(null==(n=e.text)?void 0:n.caption,dn),c=e.branding;return Object.keys(i).length&&(r.root=i),Object.keys(a).length&&(r.input=a),Object.keys(o).length&&(r.toggle=o),Object.keys(s).length&&(r.text={},r.text.body=s),Object.keys(d).length&&(r.text=((e,t)=>{for(var n in t||(t={}))on.call(t,n)&&sn(e,n,t[n]);if(an)for(var n of an(t))ln.call(t,n)&&sn(e,n,t[n]);return e})({},r.text),r.text.caption=d),c&&(r.branding=c),r}(function(e,t){var n,r,i,a,o,l,s,d,c,p,u,h,y,m,g,v,f,S,P,b,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==(r=null==t?void 0:t.root)?void 0:r.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null==(i=null==t?void 0:t.root)?void 0:i.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==(l=null==t?void 0:t.root)?void 0:l.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(s=null==t?void 0:t.input)?void 0:s.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==(p=null==t?void 0:t.input)?void 0:p.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==(m=null==t?void 0:t.toggle)?void 0:m.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==(S=null==(f=null==t?void 0:t.text)?void 0:f.body)?void 0:S.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(b=null==(P=null==t?void 0:t.text)?void 0:P.caption)?void 0:b.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null==(_=null==(I=null==t?void 0:t.text)?void 0:I.caption)?void 0:_.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}const pn=["en","es","fr","zh"];function un(e){const t=null==e?void 0:e.split(/[-_]/)[0].toLowerCase();return t&&pn.includes(t)?`${t}_us`:"en_us"}function hn(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var yn=Object.defineProperty,mn=Object.defineProperties,gn=Object.getOwnPropertyDescriptors,vn=Object.getOwnPropertySymbols,fn=Object.prototype.hasOwnProperty,Sn=Object.prototype.propertyIsEnumerable,Pn=(e,t,n)=>t in e?yn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))fn.call(t,n)&&Pn(e,n,t[n]);if(vn)for(var n of vn(t))Sn.call(t,n)&&Pn(e,n,t[n]);return e},In=(e,t)=>mn(e,gn(t)),_n=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class wn{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=r}initialize(e){return _n(this,null,function*(){var t,n;const{methodId:r,paypalcommercefastlane:i}=e;if(this.methodId=r,this.paypalcommercefastlane=i,!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.paypalcommercefastlane" argument is not provided.');if(!i.onInit||"function"!=typeof i.onInit)throw new ve('Unable to initialize payment because "options.paypalcommercefastlane.onInit" argument is not provided or it is not a function.');if(!i.onChange||"function"!=typeof i.onChange)throw new ve('Unable to initialize payment because "options.paypalcommercefastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(r);const a=this.paymentIntegrationService.getState(),o=a.getCartOrThrow(),l=a.getPaymentMethodOrThrow(r),{isDeveloperModeApplicable:s,isFastlaneStylingEnabled:d}=l.initializationData||{};this.threeDSVerificationMethod=null==(t=l.initializationData)?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(l,o.currency.code,o.id,a.getLocale());const c=cn(d?null==(n=null==l?void 0:l.initializationData)?void 0:n.fastlaneStyles:{},null==i?void 0:i.styles);(yield this.paypalFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!s,c)).setLocale(un(a.getLocale())),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(r)),yield this.initializePayPalPaymentComponent(),i.onInit(e=>this.renderPayPalPaymentComponent(e)),i.onChange(()=>this.handlePayPalStoredInstrumentChange(r))})}execute(e,t){return _n(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)fn.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&vn)for(var r of vn(e))t.indexOf(r)<0&&Sn.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);const{paymentData:a,methodId:o}=r,l=a&&Ie(a);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=l?yield this.prepareVaultedInstrumentPaymentPayload(o,a):yield this.preparePaymentPayload(o,a);yield this.paymentIntegrationService.submitPayment(e),this.paypalFastlaneUtils.removeStorageSessionId()}catch(e){if(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"response"in e&&"body"in e.response&&"name"in e.response.body}(e)&&"INVALID_REQUEST"===e.response.body.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 Pe)}deinitialize(){return _n(this,null,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),r=e.getPaymentProviderCustomer(),i=hn(r)?r:{},a=this.paypalFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==i?void 0:i.authenticationState)===L.CANCELED||(null==i?void 0:i.authenticationState)||a!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return _n(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),r=t.getCustomer(),i=t.getBillingAddress(),a=(null==r?void 0:r.email)||(null==i?void 0:i.email)||"",{customerContextId:o}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(a),l=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),{authenticationState:s,addresses:d,instruments:c}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,l);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:s,addresses:d,instruments:c}),l.authenticationState===L.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return _n(this,null,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),r=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),i={fields:bn({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield r.FastlaneCardComponent(i)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new ve('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 _n(this,null,function*(){const{instrumentId:n}=t,r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).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 _n(this,null,function*(){const n=this.paymentIntegrationService.getState(),r=n.getBillingAddressOrThrow(),i=n.getPaymentMethodOrThrow(e),a=`${r.firstName} ${r.lastName}`.trim(),{getPaymentToken:o}=this.getPayPalComponentMethodsOrThrow(),{id:l}=yield o({name:{fullName:a},billingAddress:this.paypalFastlaneUtils.mapBcToPayPalAddress(r)}),s=i.config.is3dsEnabled?yield this.get3DSNonce(l):l;yield this.createOrder(s);const{shouldSaveInstrument:d=!1,shouldSetAsDefaultInstrument:c=!1}=be(t)?t:{};return{methodId:e,paymentData:In(bn({},t),{shouldSaveInstrument:d,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:s}}})}})}createOrder(e){return _n(this,null,function*(){const t=this.paymentIntegrationService.getState().getCartOrThrow().id;if(this.methodId){const{orderId:n}=yield this.paypalCommerceRequestSender.createOrder(this.methodId,{cartId:t,fastlaneToken:e});this.orderId=n}})}get3DSNonce(e){return _n(this,null,function*(){var t;const n=this.paymentIntegrationService.getState(),r=n.getCartOrThrow(),i=n.getOrderOrThrow(),a=n.getStoreConfigOrThrow().links.checkoutLink,o=null==(t=this.paypalFastlaneSdk)?void 0:t.ThreeDomainSecureClient;if(!o)throw new c;const l={amount:i.orderAmount.toFixed(2),currency:r.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===M.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},s=yield o.isEligible(l);if(this.threeDSVerificationMethod===M.Always&&!s)throw new Se;if(s){const{liabilityShift:e,authenticationState:t,nonce:n}=yield o.show();if(e===Ke.No||e===Ke.Unknown||t===N.Errored||t===N.Cancelled)throw new Se;if(t===N.Succeeded&&[Ke.Yes,Ke.Possible].includes(e))return n;throw new Se}return e})}handlePayPalStoredInstrumentChange(e){return _n(this,null,function*(){const t=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:r}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=hn(t)?t:{},i=this.paypalFastlaneUtils.mapPayPalToBcInstrument(e,r)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(In(bn({},n),{instruments:[i]})),i}})}handleError(e){var t;(null==(t=this.paypalcommercefastlane)?void 0:t.onError)&&"function"==typeof this.paypalcommercefastlane.onError&&this.paypalcommercefastlane.onError(e)}handleErrorLog(e){var t;(null==(t=this.paypalcommercefastlane)?void 0:t.onErrorLog)&&"function"==typeof this.paypalcommercefastlane.onErrorLog&&this.paypalcommercefastlane.onErrorLog(e)}}const Cn=s(e=>{const{getHost:t}=e.getState();return new wn(e,new nn(n({host:t()})),k(),ht())},[{id:"paypalcommerceacceleratedcheckout"}]);var On=Object.defineProperty,En=Object.defineProperties,zn=Object.getOwnPropertyDescriptors,kn=Object.getOwnPropertySymbols,Tn=Object.prototype.hasOwnProperty,An=Object.prototype.propertyIsEnumerable,Bn=(e,t,n)=>t in e?On(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fn=(e,t)=>{for(var n in t||(t={}))Tn.call(t,n)&&Bn(e,n,t[n]);if(kn)for(var n of kn(t))An.call(t,n)&&Bn(e,n,t[n]);return e},Mn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});const Nn=class{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}createPayPalButton(e,t,n,r){const{style:i,fundingSource:a,isHostedCheckoutEnabled:o,isServerSideShippingCallbacksEnabled:l,onClick:s,onCancel:d,onPaymentComplete:c,onError:p}=n;this.onError=p;const u=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(u.FUNDING).includes(a))throw new ve('Unable to initialize PayPal button because "fundingSource" argument is not valid funding source.');const h=(y=Fn({},!l&&{onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e)}),En(y,zn({onApprove:(n,r)=>this.onHostedCheckoutApprove(n,r,t,e,c,l)})));var y;return u.Buttons(Fn(Fn(Fn({fundingSource:a,style:this.paypalIntegrationService.getValidButtonStyle(i),createOrder:()=>Mn(this,null,function*(){if(r){const e=yield this.paypalIntegrationService.createBuyNowCartOrThrow(r);yield this.paymentIntegrationService.loadCheckout(e.id)}return this.paypalIntegrationService.createOrder(t)}),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},s?{onClick:s}:{}),d?{onCancel:d}:{}),o&&h))}onHostedCheckoutApprove(e,t,n,r,i,a){return Mn(this,null,function*(){if(!e.orderID)throw new u(p.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const l=o.lineItems.physicalItems.length>0;if(!a){const e=yield t.order.get(),n=this.paypalIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),l){const t=this.paypalIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}l&&(yield this.paypalIntegrationService.updateOrder(r,void 0,void 0,a)),a&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e,t){return Mn(this,null,function*(){const n=this.paypalIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(n),yield this.paymentIntegrationService.updateShippingAddress(n);const e=this.paypalIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){this.handleError(e)}})}onShippingOptionsChange(e,t){return Mn(this,null,function*(){const n=this.paypalIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(n.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}};var Dn=Object.defineProperty,xn=Object.defineProperties,Un=Object.getOwnPropertyDescriptors,Ln=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Vn=Object.prototype.propertyIsEnumerable,Rn=(e,t,n)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gn=(e,t)=>{for(var n in t||(t={}))jn.call(t,n)&&Rn(e,n,t[n]);if(Ln)for(var n of Ln(t))Vn.call(t,n)&&Rn(e,n,t[n]);return e},Hn=(e,t)=>xn(e,Un(t)),Wn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Kn{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Wn(this,null,function*(){const{paypalcommerce:t,methodId:n}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(!t.container)throw new ve('Unable to initialize payment because "options.paypalcommerce.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new ve('Unable to initialize payment because "options.paypalcommerce.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const r=yield this.paypalIntegrationService.loadPayPalSdk(n);r&&r.Buttons&&"function"==typeof r.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 Wn(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Wn(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:r,onComplete:i,onError:a}=t,o=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=Hn(Gn(Gn({fundingSource:o.FUNDING.PAYPAL,isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:s,style:Hn(Gn({},p),{height:40})},r&&{onClick:()=>r()}),s&&i&&{onPaymentComplete:()=>i()}),{onError:a}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,u);h.isEligible()?h.render(`#${n}`):this.paypalIntegrationService.removeElement(n)}}const $n=s(e=>{const t=le(e),n=new Nn(e,t);return new Kn(e,t,n)},[{id:"paypalcommerce"}]);var qn=Object.defineProperty,Yn=Object.defineProperties,Jn=Object.getOwnPropertyDescriptors,Zn=Object.getOwnPropertySymbols,Xn=Object.prototype.hasOwnProperty,Qn=Object.prototype.propertyIsEnumerable,er=(e,t,n)=>t in e?qn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,tr=(e,t)=>{for(var n in t||(t={}))Xn.call(t,n)&&er(e,n,t[n]);if(Zn)for(var n of Zn(t))Qn.call(t,n)&&er(e,n,t[n]);return e},nr=(e,t)=>Yn(e,Jn(t)),rr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ir{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return rr(this,null,function*(){const{paypalcommercecredit:t,methodId:n}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(!t.container)throw new ve('Unable to initialize payment because "options.paypalcommercecredit.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new ve('Unable to initialize payment because "options.paypalcommercecredit.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const r=yield this.paypalIntegrationService.loadPayPalSdk(n);r&&r.Buttons&&"function"==typeof r.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 rr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return rr(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:r,onClick:i,onError:a}=t,o=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let h=!1;u.forEach(t=>{if(!h){const o=nr(tr(tr({fundingSource:t,style:this.paypalIntegrationService.getValidButtonStyle(nr(tr({},p),{height:40})),isHostedCheckoutEnabled:s,isServerSideShippingCallbacksEnabled:c},s&&r&&{onPaymentComplete:()=>r()}),i&&{onClick:()=>i()}),{onError:a}),l=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,o);l.isEligible()&&(l.render(`#${n}`),h=!0)}}),h||this.paypalIntegrationService.removeElement(n)}}const ar=s(e=>{const t=le(e),n=new Nn(e,t);return new ir(e,t,n)},[{id:"paypalcommercecredit"}]);var or=Object.defineProperty,lr=Object.getOwnPropertySymbols,sr=Object.prototype.hasOwnProperty,dr=Object.prototype.propertyIsEnumerable,cr=(e,t,n)=>t in e?or(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pr=(e,t)=>{for(var n in t||(t={}))sr.call(t,n)&&cr(e,n,t[n]);if(lr)for(var n of lr(t))dr.call(t,n)&&cr(e,n,t[n]);return e},ur=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class hr{constructor(e,t,n,r){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=r}loadPayPalSdk(e,t,n,r){return ur(this,null,function*(){const i=this.paymentIntegrationService.getState(),a=t||i.getCartOrThrow().currency.code,o=i.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(o,a,i.getLocale(),n,r),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return ur(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(p.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new T}})}createOrder(e,t){return ur(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r}=yield this.paypalCommerceRequestSender.createOrder(e,pr({cartId:n},t));return r})}createOrderCardFields(e,t){return ur(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r,setupToken:i}=yield this.paypalCommerceRequestSender.createOrder(e,pr({cartId:n},t));return pr({orderId:r},i?{setupToken:i}:{})})}updateOrder(e){return ur(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),r=t.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:e?[]:r.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:r.selectedShippingOption})}catch(e){throw new B}})}getOrderStatus(e,t){return ur(this,null,function*(){try{const{status:n}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return n}catch(e){throw new B}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(p.MissingOrderId);return this.formPoster.postForm("/checkout.php",pr({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===F.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return ur(this,null,function*(){const r={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(pr({methodId:e,paymentData:r},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],r=n.find(e=>e.isRecommended),i=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null==(n=t.selectedShippingOption)?void 0:n.id)}))||r||n[0];if(!i)throw new Error("Your order can't be shipped to this address");return i}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:r,name:{full_name:i}}=n[0].shipping,[a,...o]=i.split(" ");return this.getAddress({firstName:a,lastName:o.join(" "),email:t.email_address,address1:r.address_line_1,address2:r.address_line_2,city:r.admin_area_2,countryCode:r.country_code,postalCode:r.postal_code,stateOrProvinceCode:r.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:r,shape:a}=e||{},o={color:t&&qe[t]?t:void 0,height:this.getValidHeight(n),label:r&&$e[r]?r:void 0,shape:a&&Ye[a]?a:void 0};return l(o,i)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var yr=Object.defineProperty,mr=Object.defineProperties,gr=Object.getOwnPropertyDescriptors,vr=Object.getOwnPropertySymbols,fr=Object.prototype.hasOwnProperty,Sr=Object.prototype.propertyIsEnumerable,Pr=(e,t,n)=>t in e?yr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t)=>{for(var n in t||(t={}))fr.call(t,n)&&Pr(e,n,t[n]);if(vr)for(var n of vr(t))Sr.call(t,n)&&Pr(e,n,t[n]);return e},Ir=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class _r{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,r,i){return Ir(this,null,function*(){const a=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);return this.loadPayPalSDK(a,i)})}loadPayPalSDK(e,t=!1){return Ir(this,null,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:n})}if(!this.window.paypal)throw new c;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n,r=!0){const{id:i,clientToken:a,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new u(p.MissingPaymentMethod);const{intent:l,clientId:s,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:m,isPayPalCreditAvailable:g,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:P=[],isGooglePayEnabled:b}=o,I=m||r,_="paypalcommercecreditcards"===i,w=_?["card"]:[],C=g?["credit","paylater"]:[],O=y?["venmo"]:[],E=b?["googlepay"]:[],z=r?["card-fields"]:[],k=[..._?[]:["card"],...g?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!P.includes(e))],T=[...w,...C,...O,...P],A=v(n);return{options:br(br({"client-id":s,"merchant-id":d,"enable-funding":T.length>0?T:void 0,"disable-funding":k.length>0?k:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...E,...z],currency:t,intent:l},f&&{"buyer-country":c}),A&&{locale:A}),attributes:{"data-partner-attribution-id":h,"data-client-token":a}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const r=e[n];var i,a;null==r||""===r||Array.isArray(r)&&0===r.length||(i=br({},t),a={[n]:Array.isArray(r)?r.join(","):r},t=mr(i,gr(a)))}),t}}const wr=r=>{const{getHost:i}=r.getState();return new hr(t(),r,new nn(n({host:i()})),new _r(e()))};var Cr=Object.defineProperty,Or=Object.defineProperties,Er=Object.getOwnPropertyDescriptors,zr=Object.getOwnPropertySymbols,kr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable,Ar=(e,t,n)=>t in e?Cr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Br=(e,t)=>{for(var n in t||(t={}))kr.call(t,n)&&Ar(e,n,t[n]);if(zr)for(var n of zr(t))Tr.call(t,n)&&Ar(e,n,t[n]);return e},Fr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Mr{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Fr(this,null,function*(){const{paypalcommercevenmo:t,methodId:n}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(!t.container)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const r=yield this.paypalCommerceIntegrationService.loadPayPalSdk(n);r&&r.Buttons&&"function"==typeof r.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 Fr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Fr(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:r}=t,i=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:o}=a.initializationData||{},{checkoutTopButtonStyles:l}=o||{},s=Br({fundingSource:i.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle((d=Br({},l),c={height:40},Or(d,Er(c)))),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()});var d,c;const p=i.Buttons(s);p.isEligible()?p.render(`#${n}`):this.paypalCommerceIntegrationService.removeElement(n)}}const Nr=s(e=>new Mr(e,wr(e)),[{id:"paypalcommercevenmo"}]);var Dr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class xr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=n}initialize(e){return Dr(this,null,function*(){var t;const{methodId:n,paypalcommercefastlane:r}=e;if(this.options=e,!n)throw new ve('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),i=e.getCartOrThrow(),a=e.getPaymentMethodOrThrow(n),o=!!(null==(t=a.initializationData)?void 0:t.isDeveloperModeApplicable),l=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(a,i.currency.code,i.id,e.getLocale());(yield this.paypalFastlaneUtils.initializePayPalFastlane(l,o,this.getFastlaneStyles(n,r))).setLocale(un(e.getLocale()))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Dr(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Dr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t),yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:void 0,addresses:void 0,instruments:void 0}),this.paypalFastlaneUtils.removeStorageSessionId()})}signOut(e){return Dr(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Dr(this,null,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:r}=e||{};if(!r)throw new ve('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new ve('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(r)}catch(e){this.handleErrorLog(e)}}n()})}runPayPalAuthenticationFlowOrThrow(e){return Dr(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,r=t.getCustomer(),i=t.getBillingAddress(),a=(null==r?void 0:r.email)||(null==i?void 0:i.email)||"",{customerContextId:o}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(a),l=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),s=l.authenticationState===L.CANCELED;yield this.updateCustomerDataState(e,l),s?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Dr(this,null,function*(){var n;const r=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:i,addresses:a,billingAddress:o,shippingAddress:l,instruments:s}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:i,addresses:a,instruments:s}),o&&(yield this.paymentIntegrationService.updateBillingAddress(o)),l&&r.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(l),r=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:i}=r.initializationData||{},a=(null==(n=(t.getConsignments()||[])[0])?void 0:n.availableShippingOptions)||[],o=a[0],s=a.find(e=>e.isRecommended);if((s||o)&&i){const e=(null==s?void 0:s.id)||o.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:r,isFastlaneStylingEnabled:i}=n.initializationData||{};return cn(i?r:{},null==t?void 0:t.styles)}handleErrorLog(e){const{onErrorLog:t}=this.options||{};t&&"function"==typeof t&&t(e)}}const Ur=s(e=>new xr(e,k(),ht()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var Lr=Object.defineProperty,jr=Object.getOwnPropertySymbols,Vr=Object.prototype.hasOwnProperty,Rr=Object.prototype.propertyIsEnumerable,Gr=(e,t,n)=>t in e?Lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hr=(e,t)=>{for(var n in t||(t={}))Vr.call(t,n)&&Gr(e,n,t[n]);if(jr)for(var n of jr(t))Rr.call(t,n)&&Gr(e,n,t[n]);return e};class Wr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return t=this,n=function*(){var t;const{paypalcommerce:n,containerId:r,methodId:i}=e,a=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!i)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(a&&!n.currencyCode)throw new ve('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==(t=n.buyNowInitializeOptions)?void 0:t.getBuyNowCartRequestBody))throw new ve('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout(),this.paymentIntegrationService.getState().getCheckoutOrThrow().shouldExecuteSpamCheck&&(yield this.paymentIntegrationService.verifyCheckoutSpamProtection()));const o=a?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(i,o,!1),this.renderButton(r,i,n)},new Promise((e,r)=>{var i=e=>{try{o(n.next(e))}catch(e){r(e)}},a=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=t=>t.done?e(t.value):Promise.resolve(t.value).then(i,a);o((n=n.apply(t,null)).next())});var t,n}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onComplete:a,onEligibilityFailure:o}=n,l=this.paypalIntegrationService.getPayPalSdkOrThrow(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},p={onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Hr(Hr({fundingSource:l.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(i),isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:d},r&&p),d&&a&&{onPaymentComplete:()=>a()}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,u,r);h.isEligible()?h.render(`#${e}`):o&&"function"==typeof o?o():this.paypalIntegrationService.removeElement(e)}}const Kr=s(e=>{const t=le(e),n=new Nn(e,t);return new Wr(e,t,n)},[{id:"paypalcommerce"}]);var $r=Object.defineProperty,qr=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,Zr=(e,t,n)=>t in e?$r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xr=(e,t)=>{for(var n in t||(t={}))Yr.call(t,n)&&Zr(e,n,t[n]);if(qr)for(var n of qr(t))Jr.call(t,n)&&Zr(e,n,t[n]);return e},Qr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ei{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Qr(this,null,function*(){const{paypalcommercecredit:t,containerId:n,methodId:r}=e,{buyNowInitializeOptions:i,currencyCode:a}=t||{},o=!!i;if(!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(o&&!a)throw new ve('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==i?void 0:i.getBuyNowCartRequestBody))throw new ve('Unable to initialize payment because "options.paypalcommercecredit.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const l=this.paymentIntegrationService.getState(),s=o?a:l.getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(r,s,!1),this.renderButton(n,r,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onComplete:a,onEligibilityFailure:o}=n,l=this.paypalIntegrationService.getPayPalSdkOrThrow(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},p={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=[l.FUNDING.PAYLATER,l.FUNDING.CREDIT];let h=!1;u.forEach(n=>{if(!h){const l=Xr(Xr({fundingSource:n,style:this.paypalIntegrationService.getValidButtonStyle(i),isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c,buyNowInitializeOptions:r},d&&a&&{onPaymentComplete:()=>a()}),r&&p),s=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,l);s.isEligible()?(s.render(`#${e}`),h=!0):o&&"function"==typeof o&&o()}}),h||this.paypalIntegrationService.removeElement(e)}handleClick(e){return Qr(this,null,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ti=s(e=>{const t=le(e),n=new Nn(e,t);return new ei(e,t,n)},[{id:"paypalcommercecredit"}]);var ni=Object.defineProperty,ri=Object.defineProperties,ii=Object.getOwnPropertyDescriptors,ai=Object.getOwnPropertySymbols,oi=Object.prototype.hasOwnProperty,li=Object.prototype.propertyIsEnumerable,si=(e,t,n)=>t in e?ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,di=(e,t)=>{for(var n in t||(t={}))oi.call(t,n)&&si(e,n,t[n]);if(ai)for(var n of ai(t))li.call(t,n)&&si(e,n,t[n]);return e},ci=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class pi{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return ci(this,null,function*(){const{paypalcommercevenmo:t,containerId:n,methodId:r}=e,{buyNowInitializeOptions:i,currencyCode:a}=t||{},o=!!i;if(!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(o&&!a)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==i?void 0:i.getBuyNowCartRequestBody))throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const l=o?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(r,l,!1),this.renderButton(n,r,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onEligibilityFailure:a}=n,o=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),l=o.FUNDING.VENMO,s={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},d={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=di(di({fundingSource:l,style:this.getValidVenmoButtonStyles(i)},s),r&&d),p=o.Buttons(c);p.isEligible()?p.render(`#${e}`):a&&"function"==typeof a?a():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===qe.gold?(n=di({},t),ri(n,ii({color:void 0}))):t;var n}handleClick(e){return ci(this,null,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ui=s(e=>new pi(e,wr(e)),[{id:"paypalcommercevenmo"}]);var hi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class yi{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,r){return hi(this,null,function*(){return this.paypalSdk=yield this.scriptLoader.getPayPalSDK(e,t,void 0,n,r),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}proxyTokenizationPayment(e,t,n,r){return hi(this,null,function*(){var i;if(!r)throw new u(p.MissingOrderId);const a={paymentWalletData:{providerId:t,providerOrderId:r},cartEntityId:e,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:n},{key:"order_id",value:r}]},o=yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(a);if(!(null==(i=o.body.redirectUrls)?void 0:i.externalCheckoutUrl))throw new Error("Failed to redirection to checkout page");window.location.assign(o.body.redirectUrls.externalCheckoutUrl)})}createPaymentOrderIntent(e,t,n){return hi(this,null,function*(){const r={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(r,this.intentTypename,n)).body.orderId})}getValidButtonStyle(e={}){const{color:t,height:n,label:r,shape:a}=e,o={color:t&&x[t]?t:void 0,height:this.getValidHeight(n),label:r&&D[r]?r:void 0,shape:a&&U[a]?a:void 0};return l(o,i)}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 mi=Object.defineProperty,gi=Object.getOwnPropertySymbols,vi=Object.prototype.hasOwnProperty,fi=Object.prototype.propertyIsEnumerable,Si=(e,t,n)=>t in e?mi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class bi{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return Pi(this,null,function*(){var t,n;const{paypalcommercepaypal:r,containerId:i,methodId:a}=e;if(!a)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommercepaypal" argument is not provided.');let o;try{o=JSON.parse(atob(r.initializationData))}catch(e){throw new ve("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const l=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.paypalCommerceHeadlessWalletButtonService.loadPayPalSdk(o,r.currency.code,!1),this.renderButton(i,"paypalcommerce.paypal",r.cartId,l)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>Pi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommerce",e)})},o=((e,t)=>{for(var n in t||(t={}))vi.call(t,n)&&Si(e,n,t[n]);if(gi)for(var n of gi(t))fi.call(t,n)&&Si(e,n,t[n]);return e})({fundingSource:i.FUNDING.PAYPAL,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},a),l=i.Buttons(o);l.isEligible()?l.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const Ii=s(e=>new bi(new yi(e,k())),[{id:"paypalcommercepaypal"}]);var _i=Object.defineProperty,wi=Object.getOwnPropertySymbols,Ci=Object.prototype.hasOwnProperty,Oi=Object.prototype.propertyIsEnumerable,Ei=(e,t,n)=>t in e?_i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ki{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return zi(this,null,function*(){var t,n;const{paypalcommercepaypalcredit:r,containerId:i,methodId:a}=e;if(!a)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommercepaypalcredit" argument is not provided.');let o;try{o=JSON.parse(atob(r.initializationData))}catch(e){throw new ve("Failed to parse payment method 'initializationData'.")}o.id=o.id||a,yield this.paypalCommerceHeadlessWalletButtonService.loadPayPalSdk(o,r.currency.code,!1);const l=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;this.renderButton(i,"paypalcommerce.paypalcredit",r.cartId,l)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a=[i.FUNDING.PAYLATER,i.FUNDING.CREDIT],o={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>zi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercecredit",e)})};let l=!1;a.forEach(t=>{if(!l){const n=((e,t)=>{for(var n in t||(t={}))Ci.call(t,n)&&Ei(e,n,t[n]);if(wi)for(var n of wi(t))Oi.call(t,n)&&Ei(e,n,t[n]);return e})({fundingSource:t,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},o),a=i.Buttons(n);a.isEligible()&&(a.render(`#${e}`),l=!0)}}),l||this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const Ti=s(e=>new ki(new yi(e,k())),[{id:"paypalcommercepaypalcredit"}]);var Ai=Object.defineProperty,Bi=Object.defineProperties,Fi=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,Ni=Object.prototype.hasOwnProperty,Di=Object.prototype.propertyIsEnumerable,xi=(e,t,n)=>t in e?Ai(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ui=(e,t)=>{for(var n in t||(t={}))Ni.call(t,n)&&xi(e,n,t[n]);if(Mi)for(var n of Mi(t))Di.call(t,n)&&xi(e,n,t[n]);return e},Li=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ji{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return Li(this,null,function*(){var t,n;const{paypalcommercevenmo:r,containerId:i,methodId:a}=e;if(!a)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');let o;try{o=JSON.parse(atob(r.initializationData))}catch(e){throw new ve("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const l=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.paypalCommerceHeadlessWalletButtonService.loadPayPalSdk(o,r.currency.code,!1),this.renderButton(i,"paypalcommerce.venmo",r.cartId,l)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>Li(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercevenmo",e)})},o=Ui({fundingSource:i.FUNDING.VENMO,style:this.getValidVenmoButtonStyles(r)},a),l=i.Buttons(o);l.isEligible()?l.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(e);return t.color===qe.gold?(n=Ui({},t),Bi(n,Fi({color:void 0}))):t;var n}}const Vi=s(e=>new ji(new yi(e,k())),[{id:"paypalcommercevenmo"}]);export{rt as createPayPalCommerceAlternativeMethodsPaymentStrategy,Kr as createPayPalCommerceButtonStrategy,ti as createPayPalCommerceCreditButtonStrategy,Mt as createPayPalCommerceCreditCardsPaymentStrategy,ar as createPayPalCommerceCreditCustomerStrategy,xe as createPayPalCommerceCreditPaymentStrategy,Ti as createPayPalCommerceCreditWalletStrategy,$n as createPayPalCommerceCustomerStrategy,Ur as createPayPalCommerceFastlaneCustomerStrategy,Cn as createPayPalCommerceFastlanePaymentStrategy,Te as createPayPalCommercePaymentStrategy,qt as createPayPalCommerceRatePayPaymentStrategy,ui as createPayPalCommerceVenmoButtonStrategy,Nr as createPayPalCommerceVenmoCustomerStrategy,Ge as createPayPalCommerceVenmoPaymentStrategy,Vi as createPayPalCommerceVenmoWalletStrategy,Ii as createPayPalCommerceWalletStrategy};
|
|
1
|
+
import{getScriptLoader as e}from"@bigcommerce/script-loader";import{createFormPoster as t}from"@bigcommerce/form-poster";import{createRequestSender as n}from"@bigcommerce/request-sender";import{isEqual as r,isNil as i,noop as a,omit as o,omitBy as l}from"lodash";function s(e,t){return Object.assign(e,{resolveIds:t})}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 p=(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))(p||{});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"}}const h={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};var y=(e=>(e.PayPal="paypal",e.BigCommercePaymentsPayPalSDK="bigCommercePaymentsPayPalSDK",e.PayPalFastlaneSdk="paypalFastlaneSdk",e.PayPalFastlane="paypalFastlane",e.PayPalGooglePay="paypalGooglePay",e.PayPalApms="paypalApms",e.PayPalMessages="paypalMessages",e))(y||{});const m=["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 g(e){return window[e]}function v(e){if(!e)return;let t;if(e.includes("-")){const[n,r]=e.split("-");t=`${n}_${r.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return m.includes(t)?t:void 0}var f=Object.defineProperty,S=Object.defineProperties,P=Object.getOwnPropertyDescriptors,b=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,w=(e,t,n)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,C=(e,t)=>{for(var n in t||(t={}))I.call(t,n)&&w(e,n,t[n]);if(b)for(var n of b(t))_.call(t,n)&&w(e,n,t[n]);return e},O=(e,t)=>S(e,P(t)),E=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class z{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,r,i){return E(this,null,function*(){const a=this.isBigCommercePaymentsMethod(e.id)?y.BigCommercePaymentsPayPalSDK:y.PayPal;if(!g(a)||i){const i=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);yield this.loadPayPalSdk(i)}const o=g(a);if(!o)throw new c;return o})}getPayPalFastlaneSdk(e,t,n,r){return E(this,null,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n,r);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,r,i){return E(this,null,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,r);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return E(this,null,function*(){if(!this.window.paypalApms){const r=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(r),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return E(this,null,function*(){if(!this.window.paypalMessages){const r=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(r)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}isBigCommercePaymentsMethod(e){return e.startsWith("bigcommerce_payments")}loadPayPalSdk(e){return E(this,arguments,function*({options:e,attributes:t}){const n=this.transformConfig(e),r=this.transformConfig(t),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:r})})}getPayPalSdkScriptConfigOrThrow(e,t,n,r=!0){const{id:i,clientToken:a,initializationData:o}=e;if(!o||!o.clientId)throw new u(p.MissingPaymentMethod);const{intent:l,clientId:s,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:m,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:f,isDeveloperModeApplicable:S,availableAlternativePaymentMethods:P=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:I}=o,_=g||r,w="paypalcommercecreditcards"===i||"bigcommerce_payments_creditcards"===i,O=w?["card"]:[],E=w?[]:["card"],z=f?["credit","paylater"]:[],k=f?[]:["credit","paylater"],T=m?["venmo"]:[],A=m?[]:["venmo"],B=P.filter(e=>!b.includes(e)),F=I?["googlepay"]:[],M=r?["card-fields"]:[],N=this.filterFundingOptions([...E,...k,...A,...B]),D=this.filterFundingOptions([...O,...z,...T,...b]),x=v(n);return{options:C(C({"client-id":s,"merchant-id":d,"enable-funding":D.length>0?D:void 0,"disable-funding":N.length>0?N:void 0,commit:_,components:["buttons","hosted-fields","payment-fields","legal",...F,...M],currency:t,intent:l},S&&{"buyer-country":c}),x&&{locale:x}),attributes:C({"data-partner-attribution-id":h,"data-client-token":a},this.isBigCommercePaymentsMethod(i)&&{"data-namespace":y.BigCommercePaymentsPayPalSDK})}}getPayPalFastlaneSdkConfiguration(e,t,n,r){const{clientToken:i,initializationData:a}=e;if(!a||!a.clientId)throw new u(p.MissingPaymentMethod);const{intent:o,clientId:l,merchantId:s,attributionId:d}=a,c=v(r);return{options:O(C({"client-id":l,"merchant-id":s,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":y.PayPalFastlaneSdk,"data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,r=!0){const{clientToken:i,initializationData:a}=e;if(!a||!a.clientId)throw new u(p.MissingPaymentMethod);const{intent:o,clientId:l,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:m}=a,g=h||r,f=v(n);return{options:C(C({"client-id":l,"merchant-id":s,commit:g,components:["googlepay"],currency:t,intent:o},m&&{"buyer-country":d}),f&&{locale:f}),attributes:{"data-partner-attribution-id":c,"data-client-token":i,"data-namespace":y.PayPalGooglePay}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:r}=e;if(!r||!r.clientId)throw new u(p.MissingPaymentMethod);const{intent:i,clientId:a,merchantId:o,buyerCountry:l,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=r,m=this.filterFundingOptions(h),g=this.filterFundingOptions(c.filter(e=>!h.includes(e))),f=v(n);return{options:C(C({"client-id":a,"merchant-id":o,"enable-funding":m.length>0?m:void 0,"disable-funding":g.length>0?g:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},d&&{"buyer-country":l}),f&&{locale:f}),attributes:{"data-partner-attribution-id":s,"data-namespace":y.PayPalApms}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:r}=e;if(!r||!r.clientId)throw new u(p.MissingPaymentMethod);const{clientId:i,merchantId:a,attributionId:o,isDeveloperModeApplicable:l,buyerCountry:s}=r,d=v(n);return{options:C(C({"client-id":i,"merchant-id":a,components:["messages"],currency:t},l&&{"buyer-country":s}),d&&{locale:d}),attributes:{"data-namespace":y.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 r=e[n];null==r||""===r||Array.isArray(r)&&0===r.length||(t=O(C({},t),{[n]:Array.isArray(r)?r.join(","):r}))}),t}}function k(){return new z(e())}class T 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 A={body:{},headers:{},status:0};class B extends d{constructor(e,{message:t,errors:n}={}){const{body:r,headers:i,status:a}=e||A;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=r,this.headers=i,this.status=a,this.errors=n||[]}}var F=(e=>(e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE",e))(F||{}),M=(e=>(e.Always="SCA_ALWAYS",e))(M||{}),N=(e=>(e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored",e))(N||{}),D=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))(D||{}),x=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(x||{}),U=(e=>(e.pill="pill",e.rect="rect",e))(U||{}),L=(e=>(e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized",e))(L||{}),j=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(j||{}),V=Object.defineProperty,R=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable,W=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,K=(e,t)=>{for(var n in t||(t={}))G.call(t,n)&&W(e,n,t[n]);if(R)for(var n of R(t))H.call(t,n)&&W(e,n,t[n]);return e},$=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class q{constructor(e,t,n,r){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=n,this.paypalSdkLoader=r}loadPayPalSdk(e,t,n,r){return $(this,null,function*(){const i=this.paymentIntegrationService.getState(),a=t||i.getCartOrThrow().currency.code,o=i.getPaymentMethodOrThrow(e),l=i.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(o,a,l,n,r),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return $(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(p.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new T}})}createOrder(e,t){return $(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r}=yield this.paypalRequestSender.createOrder(e,K({cartId:n},t));return r})}createOrderCardFields(e,t){return $(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r,setupToken:i}=yield this.paypalRequestSender.createOrder(e,K({cartId:n},t));return K({orderId:r},i?{setupToken:i}:{})})}updateOrder(e,t,n,r){return $(this,null,function*(){const i=this.paymentIntegrationService.getState(),a=i.getCartOrThrow();let o;r||(o=i.getConsignmentsOrThrow()[0]);try{yield this.paypalRequestSender.updateOrder(e,K(K({availableShippingOptions:r?[]:null==o?void 0:o.availableShippingOptions,cartId:a.id,selectedShippingOption:r?null:null==o?void 0:o.selectedShippingOption},t?{methodId:t}:{}),n?{orderId:n}:{}))}catch(e){throw new B}})}getOrderStatus(e,t){return $(this,null,function*(){try{const{status:n}=yield this.paypalRequestSender.getOrderStatus(e,t);return n}catch(e){throw new B}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(p.MissingOrderId);return this.formPoster.postForm("/checkout.php",K({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===F.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return $(this,null,function*(){const r={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(K({methodId:e,paymentData:r},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],r=n.find(e=>e.isRecommended),i=(e?n.find(t=>t.id===e):n.find(e=>{if(t.selectedShippingOption){const n=t.selectedShippingOption.id;return e.id===n}return!1}))||r||n[0];if(!i)throw new Error("Your order can't be shipped to this address");return i}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:r,name:{full_name:i}}=n[0].shipping,[a,...o]=i.split(" ");return this.getAddress({firstName:a,lastName:o.join(" "),email:t.email_address,address1:r.address_line_1,address2:r.address_line_2,city:r.admin_area_2,countryCode:r.country_code,postalCode:r.postal_code,stateOrProvinceCode:r.admin_area_1})}getValidButtonStyle(e={}){const{color:t,height:n,label:r,shape:a}=e,o={color:t&&x[t]?t:void 0,height:this.getValidHeight(n),label:r&&D[r]?r:void 0,shape:a&&U[a]?a:void 0};return l(o,i)}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 Y="This API endpoint is for internal use only and may change in the future";var J=(e=>(e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json",e))(J||{});const Z=J,X={"X-Checkout-SDK-Version":"1.993.0"};var Q=Object.defineProperty,ee=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,re=(e,t,n)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ie=(e,t)=>{for(var n in t||(t={}))te.call(t,n)&&re(e,n,t[n]);if(ee)for(var n of ee(t))ne.call(t,n)&&re(e,n,t[n]);return e},ae=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class oe{constructor(e){this.requestSender=e}createOrder(e,t){return ae(this,null,function*(){const n=`/api/storefront/payment/${e}`,r=t,i=ie({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.post(n,{headers:i,body:r})).body})}updateOrder(e,t){return ae(this,null,function*(){const n=`/api/storefront/initialization/${e}`,r=t,i=ie({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.put(n,{headers:i,body:r})).body})}getOrderStatus(e,t){return ae(this,null,function*(){const n=`/api/storefront/initialization/${e}`,r=ie({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.get(n,ie({headers:r},t))).body})}}const le=e=>{const{getHost:r}=e.getState();return new q(t(),e,new oe(n({host:r()})),k())};var se=Object.defineProperty,de=Object.getOwnPropertySymbols,ce=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,he=(e,t)=>{for(var n in t||(t={}))ce.call(t,n)&&ue(e,n,t[n]);if(de)for(var n of de(t))pe.call(t,n)&&ue(e,n,t[n]);return e};const ye={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},me="embedded-checkout-loading-indicator-rotation";class ge{constructor(e){this.styles=he(he({},ye),e&&e.styles),this.containerStyles=he({},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=`${me} 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(me))return;const t=document.createElement("style");t.id=me,null==(e=document.head)||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${me} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}class ve extends d{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class fe extends ve{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 Se extends B{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 Pe 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 be(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function Ie(e){return Boolean(e.instrumentId)}const _e=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};function we(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 Ce=Object.getOwnPropertySymbols,Oe=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable,ze=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ke{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.payPalSdkScriptLoader=n,this.loadingIndicator=r}initialize(e){return ze(this,null,function*(){var t;const{methodId:n,paypalcommerce:r}=e||{};if(this.paypalcommerce=r,!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),a=i.getPaymentMethodOrThrow(n),{container:o,bannerContainerId:l}=r,{orderId:s,paypalBNPLConfiguration:d=[],isPayPalCreditAvailable:c}=a.initializationData||{};if(void 0!==l){if(!document.getElementById(l))return void console.error("Unable to create banner without valid banner container ID.");const e=null==d?void 0:d.find(({id:e})=>"checkout"===e);if(c||!(null==e?void 0:e.status))return;const t=yield this.payPalSdkScriptLoader.getPayPalMessages(a,i.getCartOrThrow().currency.code,i.getLocale());return t&&"function"==typeof(null==t?void 0:t.Messages)?this.renderMessages(t,l,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}s?this.orderId=null==(t=a.initializationData)?void 0:t.orderId:(this.loadingIndicatorContainer=null==o?void 0:o.split("#")[1],yield this.paypalIntegrationService.loadPayPalSdk(n),r.onInit&&"function"==typeof r.onInit&&r.onInit(()=>this.renderButton(n,r)),(void 0===r.shouldRenderPayPalButtonOnInitialization||r.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(n,r))})}execute(e,t){return ze(this,null,function*(){var n,r;const i=e,{payment:a}=i,o=((e,t)=>{var n={};for(var r in e)Oe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Ce)for(var r of Ce(e))t.indexOf(r)<0&&Ee.call(e,r)&&(n[r]=e[r]);return n})(i,["payment"]),{onError:l}=this.paypalcommerce||{};if(!a)throw new fe(["payment"]);const{methodId:s,paymentData:d}=a;if(this.isPayPalVaultedInstrumentPaymentData(d)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new Se;const c=this.isPayPalVaultedInstrumentPaymentData(d)?this.prepareVaultedInstrumentPaymentPayload(s,this.orderId,d):this.preparePaymentPayload(s,this.orderId,d);try{yield this.paymentIntegrationService.submitOrder(o,t),yield this.paymentIntegrationService.submitPayment(c)}catch(e){if(function(e){var t;return(e=>"object"==typeof e&&null!==e&&"body"in e)(e)&&"offsite_redirect"===(null==(t=e.body.additional_action_required)?void 0:t.type)}(e)){const t=null==(r=null==(n=e.body.additional_action_required)?void 0:n.data)?void 0:r.redirect_url;return new Promise(()=>window.location.replace(t))}return this.isProviderError(e)&&(yield this.paypalIntegrationService.loadPayPalSdk(a.methodId),yield new Promise((e,t)=>{var n;this.paypalcommerce&&(null==(n=this.paypalButton)||n.close(),this.renderButton(a.methodId,this.paypalcommerce),this.handleError(new Error("INSTRUMENT_DECLINED"),l)),t()})),this.handleError(e,l),Promise.reject()}})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:r,shouldSetAsDefaultInstrument:i}=n,a=!this.isTrustedVaultingFlow(n);return a?{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:i,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:r,shouldSetAsDefaultInstrument:i,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:r}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:i=!1}=be(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:r,shouldSetAsDefaultInstrument:i,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:i}=r.initializationData||{},{checkoutPaymentButtonStyles:a}=i||{},{container:o,onError:l,onRenderButton:s,onValidate:d,submitForm:c}=t;if(!o)throw new ve('Unable to initialize payment because "container" argument is not provided.');const p=this.getSmartButtonContainerId(o);if(!document.getElementById(p))throw new ve(`Unable to initialize payment because element with id ${p} does not exist.`);const u={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,l),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(u),this.paypalButton.isEligible()&&(s&&"function"==typeof s&&s(),this.paypalButton.render(o))}handleClick(e,t){return ze(this,null,function*(){const{resolve:n,reject:r}=e;return null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),r)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return ze(this,null,function*(){const e=this.getFieldsValues();return this.paypalIntegrationService.createOrder("paypalcommercecheckout",{shouldSaveInstrument:(null==e?void 0:e.shouldSaveInstrument)||!1})})}getFieldsValues(){const{getFieldsValues:e}=this.paypalcommerce||{};return"function"==typeof e?e():void 0}isTrustedVaultingFlow(e){if(e&&Ie(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>we(t)&&t.bigpayToken===e.instrumentId);return!(we(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&Ie(e)&&be(e)}renderMessages(e,t,n){const r={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:_e(n)};e.Messages(r).render(`#${t}`)}isProviderError(e){var t,n,r;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null==(r=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:r.code)}getSmartButtonContainerId(e){var t;return null!=(t=e.split("#")[1])?t:e}}const Te=s(t=>new ke(t,le(t),new z(e()),new ge({containerStyles:h})),[{id:"paypalcommerce"}]);class Ae extends d{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Be=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,Ne=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class De{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n,this.payPalSdkScriptLoader=r}initialize(e){return Ne(this,null,function*(){const{methodId:t,paypalcommerce:n,paypalcommercecredit:r}=e||{},i=r||n;if(!t)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const a=this.paymentIntegrationService.getState(),o=a.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:l=[],orderId:s}=o.initializationData||{},{bannerContainerId:d,container:c}=i;if(void 0!==d){if(!document.getElementById(d))return void console.error("Unable to create banner without valid banner container ID.");const e=l&&l.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.payPalSdkScriptLoader.getPayPalMessages(o,a.getCartOrThrow().currency.code,a.getLocale());return this.renderMessages(t,d,e)}s?this.orderId=s:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,i))})}execute(e,t){return Ne(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Fe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Be)for(var r of Be(e))t.indexOf(r)<0&&Me.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);if(!this.orderId)throw new Se;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(r.methodId,this.orderId)})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new ve('Unable to initialize payment because "container" argument is not provided.');const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:i}=r.initializationData||{},{checkoutPaymentButtonStyles:a}=i||{},{container:o,onError:l,onRenderButton:s,onValidate:d,submitForm:c}=t,p=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let u=!1;p.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,l)};if(this.paypalButton=n.Buttons(t),this.paypalButton.isEligible()||e!==n.FUNDING.PAYLATER){if(!this.paypalButton.isEligible()&&e===n.FUNDING.CREDIT)throw new Ae(`PayPal ${e} is not available for your region. Please use PayPal Checkout instead.`);s&&"function"==typeof s&&s(),this.paypalButton.render(o),u=!0}})}handleClick(e,t){return Ne(this,null,function*(){const{resolve:n,reject:r}=e;if(t&&"function"==typeof t)return t(()=>(this.toggleLoadingIndicator(!0),n()),r)})}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 r={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:_e(n)};e.Messages(r).render(`#${t}`)}}const xe=s(e=>new De(e,le(e),new ge({containerStyles:h}),k()),[{id:"paypalcommercecredit"}]);var Ue=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Ve=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Re{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n}initialize(e){return Ve(this,null,function*(){var t,n;const{methodId:r,paypalcommerce:i,paypalcommercevenmo:a}=e||{},o=a||i;if(!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!o)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(r);const l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(r);(null==(t=l.initializationData)?void 0:t.orderId)?this.orderId=null==(n=l.initializationData)?void 0:n.orderId:(yield this.paypalIntegrationService.loadPayPalSdk(r),this.loadingIndicatorContainer=o.container.split("#")[1],this.renderButton(r,o))})}execute(e,t){return Ve(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Le.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Ue)for(var r of Ue(e))t.indexOf(r)<0&&je.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);if(!this.orderId)throw new Se;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(r.methodId,this.orderId)})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,null==(e=this.paypalButton)||e.close(),Promise.resolve()}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:i}=r.initializationData||{},{checkoutPaymentButtonStyles:a}=i||{},{container:o,onError:l,onRenderButton:s,onValidate:d,submitForm:c}=t,p={fundingSource:n.FUNDING.VENMO,style:this.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercevenmocheckout"),onClick:(e,t)=>this.handleClick(t,d),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,l)};if(this.paypalButton=n.Buttons(p),!this.paypalButton.isEligible())throw new Ae("PayPal Venmo is not available for your region. Please use PayPal Checkout instead.");s&&"function"==typeof s&&s(),this.paypalButton.render(o)}handleClick(e,t){return Ve(this,null,function*(){const{resolve:n,reject:r}=e;return t(()=>(this.toggleLoadingIndicator(!0),n()),r)})}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 Ge=s(e=>new Re(e,le(e),new ge({containerStyles:h,styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]),He={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class We extends B{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var Ke=(e=>(e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES",e))(Ke||{}),$e=(e=>(e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment",e))($e||{}),qe=(e=>(e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white",e))(qe||{}),Ye=(e=>(e.pill="pill",e.rect="rect",e))(Ye||{}),Je=(e=>(e.OXXO="oxxo",e.IDEAL="ideal",e))(Je||{}),Ze=(e=>(e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR",e))(Ze||{}),Xe=Object.getOwnPropertySymbols,Qe=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,tt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class nt{constructor(e,t,n,r,i=3e3,o=3e5){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalSdkScriptLoader=n,this.loadingIndicator=r,this.pollingInterval=i,this.maxPollingIntervalTime=o,this.pollingTimer=0,this.stopPolling=a,this.isOrderApprovedProcessing=!1}initialize(e){return tt(this,null,function*(){const{gatewayId:t,methodId:n,paypalcommerce:r,paypalcommercealternativemethods:i}=e,a=i||r;if(this.paypalcommercealternativemethods=i,!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!a)throw new ve('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');const o=this.paymentIntegrationService.getState(),l=o.getPaymentMethodOrThrow(n,t),{orderId:s,shouldRenderFields:d}=l.initializationData||{},c=o.getStoreConfigOrThrow().checkoutSettings.features;this.isOrderApprovedProcessing=function(e,t,n=!0){var r;return null!=(r=e["PAYPAL-5431.order_approved_processing"])?r:n}(c,0,!1),s?this.orderId=s:(this.paypalApms=yield this.paypalSdkScriptLoader.getPayPalApmsSdk(l,o.getCartOrThrow().currency.code,o.getLocale()),this.loadingIndicatorContainer=a.container.split("#")[1],this.renderButton(n,t,a),d&&this.renderFields(n,a))})}execute(e,t){return tt(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Qe.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Xe)for(var r of Xe(e))t.indexOf(r)<0&&et.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);const{methodId:a,gatewayId:o}=r;if(!this.orderId)throw new Se;this.isOrderApprovedProcessing||"ideal"!==a||(yield new Promise((e,t)=>{this.initializePollingMechanism(a,e,t,o)})),this.isNonInstantPaymentMethod(a)&&(a!==Je.IDEAL||this.isOrderApprovedProcessing)||(yield this.paymentIntegrationService.submitOrder(i,t)),yield this.paypalCommerceIntegrationService.submitPayment(a,this.orderId,o)})}finalize(){return Promise.reject(new Pe)}deinitialize(){var e;return this.orderId=void 0,this.isOrderApprovedProcessing||this.resetPollingMechanism(),null==(e=this.paypalButton)||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,r){return tt(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 i=yield this.paypalCommerceIntegrationService.getOrderStatus(null!=r?r:"paypalcommerce"),a=i===Ze.Approved,o=i===Ze.PollingError;if(a)return this.deinitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,r);yield this.reinitializeStrategy({methodId:e,gatewayId:r,paypalcommercealternativemethods:this.paypalcommercealternativemethods}),this.handleError(new We)}catch(e){n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return tt(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.paypalcommercealternativemethods||{};this.isOrderApprovedProcessing||this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderButton(e,t,n){const r=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:a}=i.initializationData||{},{container:o,onError:l,onRenderButton:s,submitForm:d}=n,c={fundingSource:e,style:this.paypalCommerceIntegrationService.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,l)},onClick:(e,t)=>tt(this,null,function*(){return n.onValidate(t.resolve,t.reject)})};this.paypalButton=r.Buttons(c),this.paypalButton.isEligible()&&(s&&"function"==typeof s&&s(),this.paypalButton.render(o))}onCreateOrder(e,t,n){return tt(this,null,function*(){var r;const{onValidate:i}=n;yield i(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),a);const o=yield this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethodscheckout");if(this.isNonInstantPaymentMethod(e)&&(e===Je.IDEAL&&this.isOrderApprovedProcessing||e===Je.OXXO)){const n={useStoreCredit:!1},i={params:{methodId:e,gatewayId:t}};if(yield this.paymentIntegrationService.submitOrder(n,i),e===Je.IDEAL){const t=null==(r=this.paymentIntegrationService.getState().getOrder())?void 0:r.orderId;yield this.paypalCommerceIntegrationService.updateOrder("paypalcommercealternativemethods",e,t)}yield this.paypalCommerceIntegrationService.submitPayment(e,o,t)}return o})}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(),r=this.paymentIntegrationService.getState(),{firstName:i,lastName:a,email:o}=r.getBillingAddressOrThrow(),{apmFieldsContainer:l,apmFieldsStyles:s}=t;if(!l)throw new ve('Unable to initialize payment because "options.paypalcommercealternativemethods" argument should contain "apmFieldsContainer".');const d=document.querySelector(l);d&&(d.innerHTML="");const c={fundingSource:e,style:s||{},fields:{name:{value:`${i} ${a}`},email:{value:o}}};n.PaymentFields(c).render(l)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in Je}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const rt=s(e=>new nt(e,le(e),k(),new ge({containerStyles:He})),[{gateway:"paypalcommercealternativemethods"}]);var it=(e=>(e.CVV="cvv",e.PAN="pan",e))(it||{}),at=Object.defineProperty,ot=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,dt=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;class ct{static get(e){const t=`${encodeURIComponent(e)}=`,n=document.cookie;let r=null;const i=n.indexOf(t);if(i>-1){let e=n.indexOf(";",i);-1===e&&(e=n.length),r=decodeURIComponent(n.substring(i+t.length,e))}return r}static set(e,t,n={secure:!0}){let r=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:i,path:a,domain:o,secure:l}=n;if(i)r+=`; expires=${i.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),r+=`; expires=${e.toUTCString()}`}a&&(r+=`; path=${a}`),o&&(r+=`; domain=${o}`),l&&(r+="; secure"),document.cookie=r}static remove(e,t){ct.set(e,"",((e,t)=>{for(var n in t||(t={}))lt.call(t,n)&&dt(e,n,t[n]);if(ot)for(var n of ot(t))st.call(t,n)&&dt(e,n,t[n]);return e})({expires:new Date(0)},t))}}var pt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ut{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return pt(this,null,function*(){if(t&&(window.localStorage.setItem("fastlaneEnv","sandbox"),window.localStorage.setItem("axoEnv","sandbox")),!this.window.paypalFastlane){const t={root:{backgroundColorPrimary:"transparent"}};this.window.paypalFastlane=yield e.Fastlane({styles:n||t})}return this.window.paypalFastlane})}getPayPalFastlaneOrThrow(){if(!this.window.paypalFastlane)throw new c;return this.window.paypalFastlane}lookupCustomerOrThrow(e){return pt(this,null,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return pt(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};ct.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){ct.remove("bc-fastlane-sessionId")}getStorageSessionId(){return ct.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,r,i;const{authenticationState:a,profileData:o}=t,l=null==(i=null==(r=null==(n=null==o?void 0:o.card)?void 0:n.paymentSource)?void 0:r.card)?void 0:i.billingAddress,s=null==o?void 0:o.shippingAddress,d=null==o?void 0:o.name,c=null==o?void 0:o.card,p=s?this.mapPayPalToBcAddress(s.address,s.name,s.phoneNumber):void 0,u=l&&d?this.mapPayPalToBcAddress(l,d,null==s?void 0:s.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([p,u]);return{authenticationState:a||L.UNRECOGNIZED,addresses:y,billingAddress:u,shippingAddress:p,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:r}=t,{brand:i,expiry:a,lastDigits:o}=r.card,[l,s]=a.split("-");return[{bigpayToken:n,brand:i,defaultInstrument:!1,expiryMonth:s,expiryYear:l,iin:"",last4:o,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:it.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,r){const[i,a]=t.fullName.split(" "),o=(null==n?void 0:n.nationalNumber)||"",l=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||i||"",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:l+o,customFields:r||[]}}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 o(e,["id","phone"])}}function ht(){return new ut}var yt=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification",e))(yt||{});const mt=yt;function gt(e){return mt.CardNumber in e&&mt.CardName in e&&mt.CardExpiry in e}function vt(e){return mt.CardNumberVerification in e&&mt.CardCodeVerification in e&&mt.CardExpiryVerification in e}class ft extends d{constructor(){super("Your bank declined authentication, please use a different card."),this.name="PaymentMethodBankDeclinedAuthenticationError",this.type="bank_declined_authentication"}}class St 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 Pt=(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))(Pt||{});class bt 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 It 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 _t=Object.defineProperty,wt=Object.defineProperties,Ct=Object.getOwnPropertyDescriptors,Ot=Object.getOwnPropertySymbols,Et=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable,kt=(e,t,n)=>t in e?_t(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tt=(e,t)=>{for(var n in t||(t={}))Et.call(t,n)&&kt(e,n,t[n]);if(Ot)for(var n of Ot(t))zt.call(t,n)&&kt(e,n,t[n]);return e},At=(e,t)=>wt(e,Ct(t)),Bt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Ft{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=r,this.isBankDeclinedAuthentication=!1}initialize(e){return Bt(this,null,function*(){const{methodId:t,paypalcommercecreditcards:n,paypalcommerce:r}=e,i=n||r,{form:a,onCreditCardFieldsRenderingError:o,onLoadComplete:l}=i||{};if(!t)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!a)throw new ve('Unable to proceed because "options.paypalcommercecreditcards.form" argument is not provided.');this.hostedFormOptions=a,this.isCreditCardForm=gt(a.fields),this.isCreditCardVaultedForm=vt(a.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.paypalIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(a,o)),null==l||l(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Bt(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Et.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Ot)for(var r of Ot(e))t.indexOf(r)<0&&zt.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]),{methodId:a,paymentData:o}=r||{};if(!r||!a)throw new fe(["payment"]);if(this.executionPaymentData=o,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const l=this.preparePaymentPayload(a,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(l)})}finalize(){return Promise.reject(new Pe)}deinitialize(){return Bt(this,null,function*(){var e,t,n,r;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==(r=this.nameField)?void 0:r.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,r){const{shouldSaveInstrument:a=!1,shouldSetAsDefaultInstrument:o=!1}=be(t)?t:{},s=t&&Ie(t)?t.instrumentId:void 0,d=l({verification_nonce:r,token:s},i);return{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:o,instrumentId:s,formattedPayload:Tt(Tt({},r||s?{bigpay_token:d}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Bt(this,null,function*(){const{fields:n,styles:r}=e,i=this.paypalIntegrationService.getPayPalSdkOrThrow(),a=this.getExecuteCallback(n),o=Tt({style:this.getInputStyles(r),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===Ke.No||n===Ke.Unknown)throw this.isBankDeclinedAuthentication=!0,new ft;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new St},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 i.CardFields(o),!this.cardFields.isEligible())throw new bt(Pt.PaymentNotInitialized);try{this.stylizeInputContainers(n),gt(n)&&(yield this.renderFields(n)),vt(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return vt(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Bt(this,null,function*(){const{setupToken:e}=(yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",At(Tt({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Bt(this,null,function*(){const{orderId:e}=(yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",this.getInstrumentParams()))||{};return e})}}handleApprove({orderID:e,vaultSetupToken:t}){e&&(this.returnedOrderId=e),t&&(this.returnedVaultedToken=t)}renderFields(e){return Bt(this,null,function*(){var t,n,r,i;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==(r=e.cardName)?void 0:r.containerId)&&(this.nameField=a.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null==(i=e.cardNumber)?void 0:i.containerId)&&(this.numberField=a.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return Bt(this,null,function*(){var t,n,r;const i=this.getCardFieldsOrThrow();(null==(t=e.cardCodeVerification)?void 0:t.containerId)&&(this.cvvField=i.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null==(n=e.cardExpiryVerification)?void 0:n.containerId)&&(this.expiryField=i.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null==(r=e.cardNumberVerification)?void 0:r.containerId)&&(this.numberField=i.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(be(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(Ie(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return Bt(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}};this.isBankDeclinedAuthentication=!1;try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){if(this.isBankDeclinedAuthentication)throw new ft;throw new St("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Bt(this,null,function*(){var e,t;const n=this.getCardFieldsOrThrow(),r=yield n.getState().then(e=>e),i=this.getValidityData(r);if(!i.isValid)throw null==(t=null==(e=this.hostedFormOptions)?void 0:e.onValidate)||t.call(e,i),new It(this.mapValidationErrors(i.errors))})}getValidityData({fields:e}){const t=Tt({},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 r;const i=this.mapFieldType(n);return At(Tt({},e),{[i]:(null==(r=t[n])?void 0:r.isValid)?void 0:[this.getInvalidErrorByFieldType(i)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case mt.CardCode:case mt.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case mt.CardNumber:case mt.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case mt.CardExpiry:case mt.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 r,i;t[n]=[{message:(null==(i=null==(r=e[n])?void 0:r[0])?void 0:i.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return mt.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?mt.CardNumber:mt.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?mt.CardExpiry:mt.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?mt.CardCode:mt.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new bt(Pt.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,r;const i={"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==(r=null==e?void 0:e.default)?void 0:r.fontWeight)||"400",outline:"none",padding:"9px 13px"},a=At(Tt({},i),{color:"#333333"});return{input:a,".invalid":At(Tt({},i),{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 r=this.paymentIntegrationService.getState(),i=r.getPaymentMethodOrThrow(e),a=r.getPaymentProviderCustomer(),o=(l=a)&&("authenticationState"in l||"addresses"in l||"instruments"in l)?a:{};var l;return(null==(t=null==i?void 0:i.initializationData)?void 0:t.isAcceleratedCheckoutEnabled)&&(null==(n=null==i?void 0:i.initializationData)?void 0:n.isPayPalCommerceAnalyticsV2Enabled)&&!(null==o?void 0:o.authenticationState)}initializePayPalFastlaneOrThrow(e){return Bt(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),r=t.getPaymentMethodOrThrow(e),{initializationData:i}=r;if(!(null==i?void 0:i.connectClientToken))return;const a=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(r,n.currency.code,n.id,t.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(a,!!(null==i?void 0:i.isDeveloperModeApplicable))}catch(e){}})}}const Mt=s(e=>new Ft(e,le(e),k(),ht()),[{id:"paypalcommercecreditcards"}]);var Nt=Object.getOwnPropertySymbols,Dt=Object.prototype.hasOwnProperty,xt=Object.prototype.propertyIsEnumerable,Ut=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Lt{constructor(e,t,n,r=3e3,i=3e5){this.paymentIntegrationService=e,this.paypalCommerceService=t,this.loadingIndicator=n,this.pollingInterval=r,this.maxPollingIntervalTime=i,this.pollingTimer=0,this.stopPolling=a}initialize(e){return Ut(this,null,function*(){const{gatewayId:t,methodId:n,paypalcommerceratepay:r}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommerceratepay" argument is not provided.');const{legalTextContainer:i,container:a,loadingContainerId:o}=r;if(!a)throw new ve('Unable to initialize payment because "options.container" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!o)throw new ve('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=o;const l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:s}=l.initializationData||{};if(!s)throw new ve("Unable to initialize payment because merchantId argument is not provided.");this.paypalcommerceratepay=r,yield this.paypalCommerceService.loadPayPalSdk(n),this.createFraudNetScript(s,n,t),this.loadFraudnetConfig(),this.renderLegalText(i,a)})}execute(e,t){return Ut(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Dt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&Nt)for(var r of Nt(e))t.indexOf(r)<0&&xt.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]),{getFieldsValues:a}=this.paypalcommerceratepay||{};if(!r)throw new fe(["payment"]);if(!a||"function"!=typeof a)throw new ve('Unable to initialize payment because "options.getFieldsValues" argument is not provided.');this.toggleLoadingIndicator(!0);try{const e=yield this.paypalCommerceService.createOrder("paypalcommercealternativemethodscheckout",{metadataId:this.guid}),{ratepayBirthDate:n,ratepayPhoneNumber:o,ratepayPhoneCountryCode:l}=a(),s={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:r.methodId,rate_pay:{birth_date:this.normalizeDate(n),phone:{national_number:o,country_code:l.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:r.methodId,paymentData:s}),yield new Promise((e,t)=>{this.initializePollingMechanism(r.methodId,e,t,r.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new Pe)}deinitialize(){const{legalTextContainer:e}=this.paypalcommerceratepay||{},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,r=t.split("#")[1],i=document.getElementById(r),a=null==i?void 0:i.parentNode,o=document.createElement("div");o.style.marginBottom="20px",o.setAttribute("id",n),null==a||a.prepend(o);const l=this.paypalCommerceService.getPayPalSdkOrThrow(),s=l.Legal({fundingSource:l.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new ve('Unable to initialize payment because "legalTextContainerElement" argument is not found.');s.render(`#${n}`)}handleError(e){const{onError:t}=this.paypalcommerceratepay||{};this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createFraudNetScript(e,t,n){const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:i}=r.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:i};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 Ut(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,r){return Ut(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 i=yield this.paypalCommerceService.getOrderStatus("paypalcommercealternativemethods",{params:{useMetadata:!0}}),a=i===j.PollingStop,o=i===j.PollingError;if(a)return this.deinitializePollingMechanism(),t();if(o)return n();if(!a&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,r);yield this.reinitializeStrategy({methodId:e,gatewayId:r,paypalcommerceratepay:this.paypalcommerceratepay}),this.handleError(new We)}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 jt=Object.defineProperty,Vt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptors,Gt=Object.getOwnPropertySymbols,Ht=Object.prototype.hasOwnProperty,Wt=Object.prototype.propertyIsEnumerable,Kt=(e,t,n)=>t in e?jt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$t=(e,t)=>{for(var n in t||(t={}))Ht.call(t,n)&&Kt(e,n,t[n]);if(Gt)for(var n of Gt(t))Wt.call(t,n)&&Kt(e,n,t[n]);return e};const qt=s(e=>{return new Lt(e,le(e),new ge({containerStyles:(t=$t({},h),n={position:"fixed"},Vt(t,Rt(n)))}));var t,n},[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);var Yt=Object.defineProperty,Jt=Object.getOwnPropertySymbols,Zt=Object.prototype.hasOwnProperty,Xt=Object.prototype.propertyIsEnumerable,Qt=(e,t,n)=>t in e?Yt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,en=(e,t)=>{for(var n in t||(t={}))Zt.call(t,n)&&Qt(e,n,t[n]);if(Jt)for(var n of Jt(t))Xt.call(t,n)&&Qt(e,n,t[n]);return e},tn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class nn{constructor(e){this.requestSender=e}createOrder(e,t){return tn(this,null,function*(){const n=`/api/storefront/payment/${e}`,r=t,i=en({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.post(n,{headers:i,body:r})).body})}updateOrder(e){return tn(this,null,function*(){const t=e,n=en({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:n,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return tn(this,null,function*(){const n=`/api/storefront/initialization/${e}`,r=en({"X-API-INTERNAL":Y,"Content-Type":Z.Json},X);return(yield this.requestSender.get(n,en({headers:r},t))).body})}}var rn=Object.defineProperty,an=Object.getOwnPropertySymbols,on=Object.prototype.hasOwnProperty,ln=Object.prototype.propertyIsEnumerable,sn=(e,t,n)=>t in e?rn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function dn(e){return"string"!=typeof e}function cn(e,t){if(t||e)return function(e){var t,n;const r={},i=l(e.root,dn),a=l(e.input,dn),o=l(e.toggle,dn),s=l(null==(t=e.text)?void 0:t.body,dn),d=l(null==(n=e.text)?void 0:n.caption,dn),c=e.branding;return Object.keys(i).length&&(r.root=i),Object.keys(a).length&&(r.input=a),Object.keys(o).length&&(r.toggle=o),Object.keys(s).length&&(r.text={},r.text.body=s),Object.keys(d).length&&(r.text=((e,t)=>{for(var n in t||(t={}))on.call(t,n)&&sn(e,n,t[n]);if(an)for(var n of an(t))ln.call(t,n)&&sn(e,n,t[n]);return e})({},r.text),r.text.caption=d),c&&(r.branding=c),r}(function(e,t){var n,r,i,a,o,l,s,d,c,p,u,h,y,m,g,v,f,S,P,b,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==(r=null==t?void 0:t.root)?void 0:r.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null==(i=null==t?void 0:t.root)?void 0:i.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==(l=null==t?void 0:t.root)?void 0:l.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(s=null==t?void 0:t.input)?void 0:s.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==(p=null==t?void 0:t.input)?void 0:p.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==(m=null==t?void 0:t.toggle)?void 0:m.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==(S=null==(f=null==t?void 0:t.text)?void 0:f.body)?void 0:S.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(b=null==(P=null==t?void 0:t.text)?void 0:P.caption)?void 0:b.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null==(_=null==(I=null==t?void 0:t.text)?void 0:I.caption)?void 0:_.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}const pn=["en","es","fr","zh"];function un(e){const t=null==e?void 0:e.split(/[-_]/)[0].toLowerCase();return t&&pn.includes(t)?`${t}_us`:"en_us"}function hn(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var yn=Object.defineProperty,mn=Object.defineProperties,gn=Object.getOwnPropertyDescriptors,vn=Object.getOwnPropertySymbols,fn=Object.prototype.hasOwnProperty,Sn=Object.prototype.propertyIsEnumerable,Pn=(e,t,n)=>t in e?yn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bn=(e,t)=>{for(var n in t||(t={}))fn.call(t,n)&&Pn(e,n,t[n]);if(vn)for(var n of vn(t))Sn.call(t,n)&&Pn(e,n,t[n]);return e},In=(e,t)=>mn(e,gn(t)),_n=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class wn{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=r}initialize(e){return _n(this,null,function*(){var t,n;const{methodId:r,paypalcommercefastlane:i}=e;if(this.methodId=r,this.paypalcommercefastlane=i,!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.paypalcommercefastlane" argument is not provided.');if(!i.onInit||"function"!=typeof i.onInit)throw new ve('Unable to initialize payment because "options.paypalcommercefastlane.onInit" argument is not provided or it is not a function.');if(!i.onChange||"function"!=typeof i.onChange)throw new ve('Unable to initialize payment because "options.paypalcommercefastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(r);const a=this.paymentIntegrationService.getState(),o=a.getCartOrThrow(),l=a.getPaymentMethodOrThrow(r),{isDeveloperModeApplicable:s,isFastlaneStylingEnabled:d}=l.initializationData||{};this.threeDSVerificationMethod=null==(t=l.initializationData)?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(l,o.currency.code,o.id,a.getLocale());const c=cn(d?null==(n=null==l?void 0:l.initializationData)?void 0:n.fastlaneStyles:{},null==i?void 0:i.styles);(yield this.paypalFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!s,c)).setLocale(un(a.getLocale())),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(r)),yield this.initializePayPalPaymentComponent(),i.onInit(e=>this.renderPayPalPaymentComponent(e)),i.onChange(()=>this.handlePayPalStoredInstrumentChange(r))})}execute(e,t){return _n(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)fn.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&vn)for(var r of vn(e))t.indexOf(r)<0&&Sn.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);const{paymentData:a,methodId:o}=r,l=a&&Ie(a);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=l?yield this.prepareVaultedInstrumentPaymentPayload(o,a):yield this.preparePaymentPayload(o,a);yield this.paymentIntegrationService.submitPayment(e),this.paypalFastlaneUtils.removeStorageSessionId()}catch(e){if(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"response"in e&&"body"in e.response&&"name"in e.response.body}(e)&&"INVALID_REQUEST"===e.response.body.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 Pe)}deinitialize(){return _n(this,null,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),r=e.getPaymentProviderCustomer(),i=hn(r)?r:{},a=this.paypalFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==i?void 0:i.authenticationState)===L.CANCELED||(null==i?void 0:i.authenticationState)||a!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return _n(this,null,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),r=t.getCustomer(),i=t.getBillingAddress(),a=(null==r?void 0:r.email)||(null==i?void 0:i.email)||"",{customerContextId:o}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(a),l=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),{authenticationState:s,addresses:d,instruments:c}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,l);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:s,addresses:d,instruments:c}),l.authenticationState===L.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return _n(this,null,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),r=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),i={fields:bn({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield r.FastlaneCardComponent(i)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new ve('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 _n(this,null,function*(){const{instrumentId:n}=t,r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).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 _n(this,null,function*(){const n=this.paymentIntegrationService.getState(),r=n.getBillingAddressOrThrow(),i=n.getPaymentMethodOrThrow(e),a=`${r.firstName} ${r.lastName}`.trim(),{getPaymentToken:o}=this.getPayPalComponentMethodsOrThrow(),{id:l}=yield o({name:{fullName:a},billingAddress:this.paypalFastlaneUtils.mapBcToPayPalAddress(r)}),s=i.config.is3dsEnabled?yield this.get3DSNonce(l):l;yield this.createOrder(s);const{shouldSaveInstrument:d=!1,shouldSetAsDefaultInstrument:c=!1}=be(t)?t:{};return{methodId:e,paymentData:In(bn({},t),{shouldSaveInstrument:d,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:s}}})}})}createOrder(e){return _n(this,null,function*(){const t=this.paymentIntegrationService.getState().getCartOrThrow().id;if(this.methodId){const{orderId:n}=yield this.paypalCommerceRequestSender.createOrder(this.methodId,{cartId:t,fastlaneToken:e});this.orderId=n}})}get3DSNonce(e){return _n(this,null,function*(){var t;const n=this.paymentIntegrationService.getState(),r=n.getCartOrThrow(),i=n.getOrderOrThrow(),a=n.getStoreConfigOrThrow().links.checkoutLink,o=null==(t=this.paypalFastlaneSdk)?void 0:t.ThreeDomainSecureClient;if(!o)throw new c;const l={amount:i.orderAmount.toFixed(2),currency:r.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===M.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},s=yield o.isEligible(l);if(this.threeDSVerificationMethod===M.Always&&!s)throw new Se;if(s){const{liabilityShift:e,authenticationState:t,nonce:n}=yield o.show();if(e===Ke.No||e===Ke.Unknown||t===N.Errored||t===N.Cancelled)throw new Se;if(t===N.Succeeded&&[Ke.Yes,Ke.Possible].includes(e))return n;throw new Se}return e})}handlePayPalStoredInstrumentChange(e){return _n(this,null,function*(){const t=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:r}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=hn(t)?t:{},i=this.paypalFastlaneUtils.mapPayPalToBcInstrument(e,r)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(In(bn({},n),{instruments:[i]})),i}})}handleError(e){var t;(null==(t=this.paypalcommercefastlane)?void 0:t.onError)&&"function"==typeof this.paypalcommercefastlane.onError&&this.paypalcommercefastlane.onError(e)}handleErrorLog(e){var t;(null==(t=this.paypalcommercefastlane)?void 0:t.onErrorLog)&&"function"==typeof this.paypalcommercefastlane.onErrorLog&&this.paypalcommercefastlane.onErrorLog(e)}}const Cn=s(e=>{const{getHost:t}=e.getState();return new wn(e,new nn(n({host:t()})),k(),ht())},[{id:"paypalcommerceacceleratedcheckout"}]);var On=Object.defineProperty,En=Object.defineProperties,zn=Object.getOwnPropertyDescriptors,kn=Object.getOwnPropertySymbols,Tn=Object.prototype.hasOwnProperty,An=Object.prototype.propertyIsEnumerable,Bn=(e,t,n)=>t in e?On(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fn=(e,t)=>{for(var n in t||(t={}))Tn.call(t,n)&&Bn(e,n,t[n]);if(kn)for(var n of kn(t))An.call(t,n)&&Bn(e,n,t[n]);return e},Mn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});const Nn=class{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}createPayPalButton(e,t,n,r){const{style:i,fundingSource:a,isHostedCheckoutEnabled:o,isServerSideShippingCallbacksEnabled:l,onClick:s,onCancel:d,onPaymentComplete:c,onError:p}=n;this.onError=p;const u=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(u.FUNDING).includes(a))throw new ve('Unable to initialize PayPal button because "fundingSource" argument is not valid funding source.');const h=(y=Fn({},!l&&{onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e)}),En(y,zn({onApprove:(n,r)=>this.onHostedCheckoutApprove(n,r,t,e,c,l)})));var y;return u.Buttons(Fn(Fn(Fn({fundingSource:a,style:this.paypalIntegrationService.getValidButtonStyle(i),createOrder:()=>Mn(this,null,function*(){if(r){const e=yield this.paypalIntegrationService.createBuyNowCartOrThrow(r);yield this.paymentIntegrationService.loadCheckout(e.id)}return this.paypalIntegrationService.createOrder(t)}),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},s?{onClick:s}:{}),d?{onCancel:d}:{}),o&&h))}onHostedCheckoutApprove(e,t,n,r,i,a){return Mn(this,null,function*(){if(!e.orderID)throw new u(p.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const l=o.lineItems.physicalItems.length>0;if(!a){const e=yield t.order.get(),n=this.paypalIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),l){const t=this.paypalIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}l&&(yield this.paypalIntegrationService.updateOrder(r,void 0,void 0,a)),a&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e,t){return Mn(this,null,function*(){const n=this.paypalIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(n),yield this.paymentIntegrationService.updateShippingAddress(n);const e=this.paypalIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){this.handleError(e)}})}onShippingOptionsChange(e,t){return Mn(this,null,function*(){const n=this.paypalIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(n.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}};var Dn=Object.defineProperty,xn=Object.defineProperties,Un=Object.getOwnPropertyDescriptors,Ln=Object.getOwnPropertySymbols,jn=Object.prototype.hasOwnProperty,Vn=Object.prototype.propertyIsEnumerable,Rn=(e,t,n)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gn=(e,t)=>{for(var n in t||(t={}))jn.call(t,n)&&Rn(e,n,t[n]);if(Ln)for(var n of Ln(t))Vn.call(t,n)&&Rn(e,n,t[n]);return e},Hn=(e,t)=>xn(e,Un(t)),Wn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Kn{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Wn(this,null,function*(){const{paypalcommerce:t,methodId:n}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(!t.container)throw new ve('Unable to initialize payment because "options.paypalcommerce.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new ve('Unable to initialize payment because "options.paypalcommerce.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const r=yield this.paypalIntegrationService.loadPayPalSdk(n);r&&r.Buttons&&"function"==typeof r.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 Wn(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Wn(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:r,onComplete:i,onError:a}=t,o=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=Hn(Gn(Gn({fundingSource:o.FUNDING.PAYPAL,isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:s,style:Hn(Gn({},p),{height:40})},r&&{onClick:()=>r()}),s&&i&&{onPaymentComplete:()=>i()}),{onError:a}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,u);h.isEligible()?h.render(`#${n}`):this.paypalIntegrationService.removeElement(n)}}const $n=s(e=>{const t=le(e),n=new Nn(e,t);return new Kn(e,t,n)},[{id:"paypalcommerce"}]);var qn=Object.defineProperty,Yn=Object.defineProperties,Jn=Object.getOwnPropertyDescriptors,Zn=Object.getOwnPropertySymbols,Xn=Object.prototype.hasOwnProperty,Qn=Object.prototype.propertyIsEnumerable,er=(e,t,n)=>t in e?qn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,tr=(e,t)=>{for(var n in t||(t={}))Xn.call(t,n)&&er(e,n,t[n]);if(Zn)for(var n of Zn(t))Qn.call(t,n)&&er(e,n,t[n]);return e},nr=(e,t)=>Yn(e,Jn(t)),rr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ir{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return rr(this,null,function*(){const{paypalcommercecredit:t,methodId:n}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(!t.container)throw new ve('Unable to initialize payment because "options.paypalcommercecredit.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new ve('Unable to initialize payment because "options.paypalcommercecredit.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const r=yield this.paypalIntegrationService.loadPayPalSdk(n);r&&r.Buttons&&"function"==typeof r.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 rr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return rr(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:r,onClick:i,onError:a}=t,o=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let h=!1;u.forEach(t=>{if(!h){const o=nr(tr(tr({fundingSource:t,style:this.paypalIntegrationService.getValidButtonStyle(nr(tr({},p),{height:40})),isHostedCheckoutEnabled:s,isServerSideShippingCallbacksEnabled:c},s&&r&&{onPaymentComplete:()=>r()}),i&&{onClick:()=>i()}),{onError:a}),l=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,o);l.isEligible()&&(l.render(`#${n}`),h=!0)}}),h||this.paypalIntegrationService.removeElement(n)}}const ar=s(e=>{const t=le(e),n=new Nn(e,t);return new ir(e,t,n)},[{id:"paypalcommercecredit"}]);var or=Object.defineProperty,lr=Object.getOwnPropertySymbols,sr=Object.prototype.hasOwnProperty,dr=Object.prototype.propertyIsEnumerable,cr=(e,t,n)=>t in e?or(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pr=(e,t)=>{for(var n in t||(t={}))sr.call(t,n)&&cr(e,n,t[n]);if(lr)for(var n of lr(t))dr.call(t,n)&&cr(e,n,t[n]);return e},ur=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class hr{constructor(e,t,n,r){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=r}loadPayPalSdk(e,t,n,r){return ur(this,null,function*(){const i=this.paymentIntegrationService.getState(),a=t||i.getCartOrThrow().currency.code,o=i.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(o,a,i.getLocale(),n,r),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return ur(this,null,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(p.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new T}})}createOrder(e,t){return ur(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r}=yield this.paypalCommerceRequestSender.createOrder(e,pr({cartId:n},t));return r})}createOrderCardFields(e,t){return ur(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r,setupToken:i}=yield this.paypalCommerceRequestSender.createOrder(e,pr({cartId:n},t));return pr({orderId:r},i?{setupToken:i}:{})})}updateOrder(e){return ur(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),r=t.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:e?[]:r.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:r.selectedShippingOption})}catch(e){throw new B}})}getOrderStatus(e,t){return ur(this,null,function*(){try{const{status:n}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return n}catch(e){throw new B}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(p.MissingOrderId);return this.formPoster.postForm("/checkout.php",pr({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===F.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return ur(this,null,function*(){const r={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(pr({methodId:e,paymentData:r},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],r=n.find(e=>e.isRecommended),i=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null==(n=t.selectedShippingOption)?void 0:n.id)}))||r||n[0];if(!i)throw new Error("Your order can't be shipped to this address");return i}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:r,name:{full_name:i}}=n[0].shipping,[a,...o]=i.split(" ");return this.getAddress({firstName:a,lastName:o.join(" "),email:t.email_address,address1:r.address_line_1,address2:r.address_line_2,city:r.admin_area_2,countryCode:r.country_code,postalCode:r.postal_code,stateOrProvinceCode:r.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:r,shape:a}=e||{},o={color:t&&qe[t]?t:void 0,height:this.getValidHeight(n),label:r&&$e[r]?r:void 0,shape:a&&Ye[a]?a:void 0};return l(o,i)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}var yr=Object.defineProperty,mr=Object.defineProperties,gr=Object.getOwnPropertyDescriptors,vr=Object.getOwnPropertySymbols,fr=Object.prototype.hasOwnProperty,Sr=Object.prototype.propertyIsEnumerable,Pr=(e,t,n)=>t in e?yr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t)=>{for(var n in t||(t={}))fr.call(t,n)&&Pr(e,n,t[n]);if(vr)for(var n of vr(t))Sr.call(t,n)&&Pr(e,n,t[n]);return e},Ir=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class _r{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,r,i){return Ir(this,null,function*(){const a=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);return this.loadPayPalSDK(a,i)})}loadPayPalSDK(e,t=!1){return Ir(this,null,function*(){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:n})}if(!this.window.paypal)throw new c;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n,r=!0){const{id:i,clientToken:a,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new u(p.MissingPaymentMethod);const{intent:l,clientId:s,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:m,isPayPalCreditAvailable:g,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:P=[],isGooglePayEnabled:b}=o,I=m||r,_="paypalcommercecreditcards"===i,w=_?["card"]:[],C=g?["credit","paylater"]:[],O=y?["venmo"]:[],E=b?["googlepay"]:[],z=r?["card-fields"]:[],k=[..._?[]:["card"],...g?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!P.includes(e))],T=[...w,...C,...O,...P],A=v(n);return{options:br(br({"client-id":s,"merchant-id":d,"enable-funding":T.length>0?T:void 0,"disable-funding":k.length>0?k:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...E,...z],currency:t,intent:l},f&&{"buyer-country":c}),A&&{locale:A}),attributes:{"data-partner-attribution-id":h,"data-client-token":a}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const r=e[n];var i,a;null==r||""===r||Array.isArray(r)&&0===r.length||(i=br({},t),a={[n]:Array.isArray(r)?r.join(","):r},t=mr(i,gr(a)))}),t}}const wr=r=>{const{getHost:i}=r.getState();return new hr(t(),r,new nn(n({host:i()})),new _r(e()))};var Cr=Object.defineProperty,Or=Object.defineProperties,Er=Object.getOwnPropertyDescriptors,zr=Object.getOwnPropertySymbols,kr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable,Ar=(e,t,n)=>t in e?Cr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Br=(e,t)=>{for(var n in t||(t={}))kr.call(t,n)&&Ar(e,n,t[n]);if(zr)for(var n of zr(t))Tr.call(t,n)&&Ar(e,n,t[n]);return e},Fr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class Mr{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Fr(this,null,function*(){const{paypalcommercevenmo:t,methodId:n}=e;if(!n)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(!t.container)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const r=yield this.paypalCommerceIntegrationService.loadPayPalSdk(n);r&&r.Buttons&&"function"==typeof r.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 Fr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Fr(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:r}=t,i=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:o}=a.initializationData||{},{checkoutTopButtonStyles:l}=o||{},s=Br({fundingSource:i.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle((d=Br({},l),c={height:40},Or(d,Er(c)))),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()});var d,c;const p=i.Buttons(s);p.isEligible()?p.render(`#${n}`):this.paypalCommerceIntegrationService.removeElement(n)}}const Nr=s(e=>new Mr(e,wr(e)),[{id:"paypalcommercevenmo"}]);var Dr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class xr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=n}initialize(e){return Dr(this,null,function*(){var t;const{methodId:n,paypalcommercefastlane:r}=e;if(this.options=e,!n)throw new ve('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),i=e.getCartOrThrow(),a=e.getPaymentMethodOrThrow(n),o=!!(null==(t=a.initializationData)?void 0:t.isDeveloperModeApplicable),l=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(a,i.currency.code,i.id,e.getLocale());(yield this.paypalFastlaneUtils.initializePayPalFastlane(l,o,this.getFastlaneStyles(n,r))).setLocale(un(e.getLocale()))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Dr(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Dr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t),yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:void 0,addresses:void 0,instruments:void 0}),this.paypalFastlaneUtils.removeStorageSessionId()})}signOut(e){return Dr(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Dr(this,null,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:r}=e||{};if(!r)throw new ve('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new ve('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(r)}catch(e){this.handleErrorLog(e)}}n()})}runPayPalAuthenticationFlowOrThrow(e){return Dr(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,r=t.getCustomer(),i=t.getBillingAddress(),a=(null==r?void 0:r.email)||(null==i?void 0:i.email)||"",{customerContextId:o}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(a),l=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),s=l.authenticationState===L.CANCELED;yield this.updateCustomerDataState(e,l),s?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Dr(this,null,function*(){var n;const r=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:i,addresses:a,billingAddress:o,shippingAddress:l,instruments:s}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:i,addresses:a,instruments:s}),o&&(yield this.paymentIntegrationService.updateBillingAddress(o)),l&&r.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(l),r=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:i}=r.initializationData||{},a=(null==(n=(t.getConsignments()||[])[0])?void 0:n.availableShippingOptions)||[],o=a[0],s=a.find(e=>e.isRecommended);if((s||o)&&i){const e=(null==s?void 0:s.id)||o.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:r,isFastlaneStylingEnabled:i}=n.initializationData||{};return cn(i?r:{},null==t?void 0:t.styles)}handleErrorLog(e){const{onErrorLog:t}=this.options||{};t&&"function"==typeof t&&t(e)}}const Ur=s(e=>new xr(e,k(),ht()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var Lr=Object.defineProperty,jr=Object.getOwnPropertySymbols,Vr=Object.prototype.hasOwnProperty,Rr=Object.prototype.propertyIsEnumerable,Gr=(e,t,n)=>t in e?Lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hr=(e,t)=>{for(var n in t||(t={}))Vr.call(t,n)&&Gr(e,n,t[n]);if(jr)for(var n of jr(t))Rr.call(t,n)&&Gr(e,n,t[n]);return e};class Wr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return t=this,n=function*(){var t;const{paypalcommerce:n,containerId:r,methodId:i}=e,a=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!i)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new ve('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(a&&!n.currencyCode)throw new ve('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==(t=n.buyNowInitializeOptions)?void 0:t.getBuyNowCartRequestBody))throw new ve('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout(),this.paymentIntegrationService.getState().getCheckoutOrThrow().shouldExecuteSpamCheck&&(yield this.paymentIntegrationService.verifyCheckoutSpamProtection()));const o=a?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(i,o,!1),this.renderButton(r,i,n)},new Promise((e,r)=>{var i=e=>{try{o(n.next(e))}catch(e){r(e)}},a=e=>{try{o(n.throw(e))}catch(e){r(e)}},o=t=>t.done?e(t.value):Promise.resolve(t.value).then(i,a);o((n=n.apply(t,null)).next())});var t,n}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onComplete:a,onEligibilityFailure:o}=n,l=this.paypalIntegrationService.getPayPalSdkOrThrow(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},p={onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Hr(Hr({fundingSource:l.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(i),isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:d},r&&p),d&&a&&{onPaymentComplete:()=>a()}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,u,r);h.isEligible()?h.render(`#${e}`):o&&"function"==typeof o?o():this.paypalIntegrationService.removeElement(e)}}const Kr=s(e=>{const t=le(e),n=new Nn(e,t);return new Wr(e,t,n)},[{id:"paypalcommerce"}]);var $r=Object.defineProperty,qr=Object.getOwnPropertySymbols,Yr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,Zr=(e,t,n)=>t in e?$r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xr=(e,t)=>{for(var n in t||(t={}))Yr.call(t,n)&&Zr(e,n,t[n]);if(qr)for(var n of qr(t))Jr.call(t,n)&&Zr(e,n,t[n]);return e},Qr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ei{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Qr(this,null,function*(){const{paypalcommercecredit:t,containerId:n,methodId:r}=e,{buyNowInitializeOptions:i,currencyCode:a}=t||{},o=!!i;if(!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(o&&!a)throw new ve('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==i?void 0:i.getBuyNowCartRequestBody))throw new ve('Unable to initialize payment because "options.paypalcommercecredit.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const l=this.paymentIntegrationService.getState(),s=o?a:l.getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(r,s,!1),this.renderButton(n,r,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onComplete:a,onEligibilityFailure:o}=n,l=this.paypalIntegrationService.getPayPalSdkOrThrow(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},p={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=[l.FUNDING.PAYLATER,l.FUNDING.CREDIT];let h=!1;u.forEach(n=>{if(!h){const l=Xr(Xr({fundingSource:n,style:this.paypalIntegrationService.getValidButtonStyle(i),isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c,buyNowInitializeOptions:r},d&&a&&{onPaymentComplete:()=>a()}),r&&p),s=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,l);s.isEligible()?(s.render(`#${e}`),h=!0):o&&"function"==typeof o&&o()}}),h||this.paypalIntegrationService.removeElement(e)}handleClick(e){return Qr(this,null,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ti=s(e=>{const t=le(e),n=new Nn(e,t);return new ei(e,t,n)},[{id:"paypalcommercecredit"}]);var ni=Object.defineProperty,ri=Object.defineProperties,ii=Object.getOwnPropertyDescriptors,ai=Object.getOwnPropertySymbols,oi=Object.prototype.hasOwnProperty,li=Object.prototype.propertyIsEnumerable,si=(e,t,n)=>t in e?ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,di=(e,t)=>{for(var n in t||(t={}))oi.call(t,n)&&si(e,n,t[n]);if(ai)for(var n of ai(t))li.call(t,n)&&si(e,n,t[n]);return e},ci=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class pi{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return ci(this,null,function*(){const{paypalcommercevenmo:t,containerId:n,methodId:r}=e,{buyNowInitializeOptions:i,currencyCode:a}=t||{},o=!!i;if(!r)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(o&&!a)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null==i?void 0:i.getBuyNowCartRequestBody))throw new ve('Unable to initialize payment because "options.paypalcommercevenmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const l=o?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(r,l,!1),this.renderButton(n,r,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onEligibilityFailure:a}=n,o=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),l=o.FUNDING.VENMO,s={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},d={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=di(di({fundingSource:l,style:this.getValidVenmoButtonStyles(i)},s),r&&d),p=o.Buttons(c);p.isEligible()?p.render(`#${e}`):a&&"function"==typeof a?a():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===qe.gold?(n=di({},t),ri(n,ii({color:void 0}))):t;var n}handleClick(e){return ci(this,null,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ui=s(e=>new pi(e,wr(e)),[{id:"paypalcommercevenmo"}]);var hi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class yi{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,r){return hi(this,null,function*(){return this.paypalSdk=yield this.scriptLoader.getPayPalSDK(e,t,void 0,n,r),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}proxyTokenizationPayment(e,t,n,r){return hi(this,null,function*(){var i;if(!r)throw new u(p.MissingOrderId);const a={paymentWalletData:{providerId:t,providerOrderId:r},cartEntityId:e,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:n},{key:"order_id",value:r}]},o=yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(a);if(!(null==(i=o.body.redirectUrls)?void 0:i.externalCheckoutUrl))throw new Error("Failed to redirection to checkout page");window.location.assign(o.body.redirectUrls.externalCheckoutUrl)})}createPaymentOrderIntent(e,t,n){return hi(this,null,function*(){const r={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(r,this.intentTypename,n)).body.orderId})}getValidButtonStyle(e={}){const{color:t,height:n,label:r,shape:a}=e,o={color:t&&x[t]?t:void 0,height:this.getValidHeight(n),label:r&&D[r]?r:void 0,shape:a&&U[a]?a:void 0};return l(o,i)}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 mi=Object.defineProperty,gi=Object.getOwnPropertySymbols,vi=Object.prototype.hasOwnProperty,fi=Object.prototype.propertyIsEnumerable,Si=(e,t,n)=>t in e?mi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class bi{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return Pi(this,null,function*(){var t,n;const{paypalcommercepaypal:r,containerId:i,methodId:a}=e;if(!a)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommercepaypal" argument is not provided.');let o;try{o=JSON.parse(atob(r.initializationData))}catch(e){throw new ve("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const l=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.paypalCommerceHeadlessWalletButtonService.loadPayPalSdk(o,r.currency.code,!1),this.renderButton(i,"paypalcommerce.paypal",r.cartId,l)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>Pi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommerce",e)})},o=((e,t)=>{for(var n in t||(t={}))vi.call(t,n)&&Si(e,n,t[n]);if(gi)for(var n of gi(t))fi.call(t,n)&&Si(e,n,t[n]);return e})({fundingSource:i.FUNDING.PAYPAL,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},a),l=i.Buttons(o);l.isEligible()?l.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const Ii=s(e=>new bi(new yi(e,k())),[{id:"paypalcommercepaypal"}]);var _i=Object.defineProperty,wi=Object.getOwnPropertySymbols,Ci=Object.prototype.hasOwnProperty,Oi=Object.prototype.propertyIsEnumerable,Ei=(e,t,n)=>t in e?_i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ki{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return zi(this,null,function*(){var t,n;const{paypalcommercepaypalcredit:r,containerId:i,methodId:a}=e;if(!a)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommercepaypalcredit" argument is not provided.');let o;try{o=JSON.parse(atob(r.initializationData))}catch(e){throw new ve("Failed to parse payment method 'initializationData'.")}o.id=o.id||a,yield this.paypalCommerceHeadlessWalletButtonService.loadPayPalSdk(o,r.currency.code,!1);const l=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;this.renderButton(i,"paypalcommerce.paypalcredit",r.cartId,l)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a=[i.FUNDING.PAYLATER,i.FUNDING.CREDIT],o={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>zi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercecredit",e)})};let l=!1;a.forEach(t=>{if(!l){const n=((e,t)=>{for(var n in t||(t={}))Ci.call(t,n)&&Ei(e,n,t[n]);if(wi)for(var n of wi(t))Oi.call(t,n)&&Ei(e,n,t[n]);return e})({fundingSource:t,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},o),a=i.Buttons(n);a.isEligible()&&(a.render(`#${e}`),l=!0)}}),l||this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const Ti=s(e=>new ki(new yi(e,k())),[{id:"paypalcommercepaypalcredit"}]);var Ai=Object.defineProperty,Bi=Object.defineProperties,Fi=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,Ni=Object.prototype.hasOwnProperty,Di=Object.prototype.propertyIsEnumerable,xi=(e,t,n)=>t in e?Ai(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ui=(e,t)=>{for(var n in t||(t={}))Ni.call(t,n)&&xi(e,n,t[n]);if(Mi)for(var n of Mi(t))Di.call(t,n)&&xi(e,n,t[n]);return e},Li=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{l(n.next(e))}catch(e){i(e)}},o=e=>{try{l(n.throw(e))}catch(e){i(e)}},l=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);l((n=n.apply(e,t)).next())});class ji{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return Li(this,null,function*(){var t,n;const{paypalcommercevenmo:r,containerId:i,methodId:a}=e;if(!a)throw new ve('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new ve('Unable to initialize payment because "options.containerId" argument is not provided.');if(!r)throw new ve('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');let o;try{o=JSON.parse(atob(r.initializationData))}catch(e){throw new ve("Failed to parse payment method 'initializationData'.")}o.id=o.id||a;const l=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;yield this.paypalCommerceHeadlessWalletButtonService.loadPayPalSdk(o,r.currency.code,!1),this.renderButton(i,"paypalcommerce.venmo",r.cartId,l)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>Li(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercevenmo",e)})},o=Ui({fundingSource:i.FUNDING.VENMO,style:this.getValidVenmoButtonStyles(r)},a),l=i.Buttons(o);l.isEligible()?l.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(e);return t.color===qe.gold?(n=Ui({},t),Bi(n,Fi({color:void 0}))):t;var n}}const Vi=s(e=>new ji(new yi(e,k())),[{id:"paypalcommercevenmo"}]);export{rt as createPayPalCommerceAlternativeMethodsPaymentStrategy,Kr as createPayPalCommerceButtonStrategy,ti as createPayPalCommerceCreditButtonStrategy,Mt as createPayPalCommerceCreditCardsPaymentStrategy,ar as createPayPalCommerceCreditCustomerStrategy,xe as createPayPalCommerceCreditPaymentStrategy,Ti as createPayPalCommerceCreditWalletStrategy,$n as createPayPalCommerceCustomerStrategy,Ur as createPayPalCommerceFastlaneCustomerStrategy,Cn as createPayPalCommerceFastlanePaymentStrategy,Te as createPayPalCommercePaymentStrategy,qt as createPayPalCommerceRatePayPaymentStrategy,ui as createPayPalCommerceVenmoButtonStrategy,Nr as createPayPalCommerceVenmoCustomerStrategy,Ge as createPayPalCommerceVenmoPaymentStrategy,Vi as createPayPalCommerceVenmoWalletStrategy,Ii as createPayPalCommerceWalletStrategy};
|
|
2
2
|
//# sourceMappingURL=paypal-commerce.js.map
|