@bigcommerce/checkout-sdk 1.983.3 → 1.983.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{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 s}from"lodash";function l(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,_=Object.prototype.hasOwnProperty,I=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={}))_.call(t,n)&&w(e,n,t[n]);if(b)for(var n of b(t))I.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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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:s,clientId:l,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:m,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:f,isDeveloperModeApplicable:S,availableAlternativePaymentMethods:P=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:_}=o,I=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)),N=_?["googlepay"]:[],F=r?["card-fields"]:[],M=this.filterFundingOptions([...E,...k,...A,...B]),D=this.filterFundingOptions([...O,...z,...T,...b]),x=v(n);return{options:C(C({"client-id":l,"merchant-id":d,"enable-funding":D.length>0?D:void 0,"disable-funding":M.length>0?M:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...N,...F],currency:t,intent:s},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:s,merchantId:l,attributionId:d}=a,c=v(r);return{options:O(C({"client-id":s,"merchant-id":l,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:o}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":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:s,merchantId:l,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:m}=a,g=h||r,f=v(n);return{options:C(C({"client-id":s,"merchant-id":l,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:s,attributionId:l,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":s}),f&&{locale:f}),attributes:{"data-partner-attribution-id":l,"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:s,buyerCountry:l}=r,d=v(n);return{options:C(C({"client-id":i,"merchant-id":a,components:["messages"],currency:t},s&&{"buyer-country":l}),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 N=(e=>(e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE",e))(N||{}),F=(e=>(e.Always="SCA_ALWAYS",e))(F||{}),M=(e=>(e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored",e))(M||{}),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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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),s=i.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(o,a,s,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===N.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 s(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.983.3"};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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 se=e=>{const{getHost:r}=e.getState();return new q(t(),e,new oe(n({host:r()})),k())};var le=Object.defineProperty,de=Object.getOwnPropertySymbols,ce=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?le(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 _e(e){return Boolean(e.instrumentId)}const Ie=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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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:s}=r,{orderId:l,paypalBNPLConfiguration:d=[],isPayPalCreditAvailable:c}=a.initializationData||{};if(void 0!==s){if(!document.getElementById(s))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,s,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}l?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:s}=this.paypalcommerce||{};if(!a)throw new fe(["payment"]);const{methodId:l,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(l,this.orderId,d):this.preparePaymentPayload(l,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"),s)),t()})),this.handleError(e,s),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:s,onRenderButton:l,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,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(u),this.paypalButton.isEligible()&&(l&&"function"==typeof l&&l(),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&&_e(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&&_e(e)&&be(e)}renderMessages(e,t,n){const r={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:Ie(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=l(t=>new ke(t,se(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,Ne=Object.prototype.hasOwnProperty,Fe=Object.prototype.propertyIsEnumerable,Me=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 Me(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:s=[],orderId:l}=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=s&&s.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)}l?this.orderId=l:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,i))})}execute(e,t){return Me(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Ne.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&&Fe.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:s,onRenderButton:l,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,s)};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.`);l&&"function"==typeof l&&l(),this.paypalButton.render(o),u=!0}})}handleClick(e,t){return Me(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:Ie(n)};e.Messages(r).render(`#${t}`)}}const xe=l(e=>new De(e,se(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(r);(null==(t=s.initializationData)?void 0:t.orderId)?this.orderId=null==(n=s.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:s,onRenderButton:l,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,s)};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.");l&&"function"==typeof l&&l(),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=l(e=>new Re(e,se(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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(),s=o.getPaymentMethodOrThrow(n,t),{orderId:l,shouldRenderFields:d}=s.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),l?this.orderId=l:(this.paypalApms=yield this.paypalSdkScriptLoader.getPayPalApmsSdk(s,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:s,onRenderButton:l,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,s)},onClick:(e,t)=>tt(this,null,function*(){return n.onValidate(t.resolve,t.reject)})};this.paypalButton=r.Buttons(c),this.paypalButton.isEligible()&&(l&&"function"==typeof l&&l(),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:s,apmFieldsStyles:l}=t;if(!s)throw new ve('Unable to initialize payment because "options.paypalcommercealternativemethods" argument should contain "apmFieldsContainer".');const d=document.querySelector(s);d&&(d.innerHTML="");const c={fundingSource:e,style:l||{},fields:{name:{value:`${i} ${a}`},email:{value:o}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in Je}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const rt=l(e=>new nt(e,se(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,st=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,dt=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;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:s}=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}`),s&&(r+="; secure"),document.cookie=r}static remove(e,t){ct.set(e,"",((e,t)=>{for(var n in t||(t={}))st.call(t,n)&&dt(e,n,t[n]);if(ot)for(var n of ot(t))lt.call(t,n)&&dt(e,n,t[n]);return e})({expires:new Date(0)},t))}}var pt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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,s=null==(i=null==(r=null==(n=null==o?void 0:o.card)?void 0:n.paymentSource)?void 0:r.card)?void 0:i.billingAddress,l=null==o?void 0:o.shippingAddress,d=null==o?void 0:o.name,c=null==o?void 0:o.card,p=l?this.mapPayPalToBcAddress(l.address,l.name,l.phoneNumber):void 0,u=s&&d?this.mapPayPalToBcAddress(s,d,null==l?void 0:l.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([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,[s,l]=a.split("-");return[{bigpayToken:n,brand:i,defaultInstrument:!1,expiryMonth:l,expiryYear:s,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)||"",s=(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:s+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 _t 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 It=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?It(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Nt{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:s}=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==s||s(),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 s=this.preparePaymentPayload(a,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(s)})}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:{},l=t&&_e(t)?t.instrumentId:void 0,d=s({verification_nonce:r,token:l},i);return{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:o,instrumentId:l,formattedPayload:Tt(Tt({},r||l?{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(_e(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 _t(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=(s=a)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?a:{};var s;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 Ft=l(e=>new Nt(e,se(e),k(),ht()),[{id:"paypalcommercecreditcards"}]);var Mt=Object.getOwnPropertySymbols,Dt=Object.prototype.hasOwnProperty,xt=Object.prototype.propertyIsEnumerable,Ut=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:l}=s.initializationData||{};if(!l)throw new ve("Unable to initialize payment because merchantId argument is not provided.");this.paypalcommerceratepay=r,yield this.paypalCommerceService.loadPayPalSdk(n),this.createFraudNetScript(l,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&&Mt)for(var r of Mt(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:s}=a(),l={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:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:r.methodId,paymentData:l}),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 s=this.paypalCommerceService.getPayPalSdkOrThrow(),l=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new ve('Unable to initialize payment because "legalTextContainerElement" argument is not found.');l.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=l(e=>{return new Lt(e,se(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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,sn=Object.prototype.propertyIsEnumerable,ln=(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=s(e.root,dn),a=s(e.input,dn),o=s(e.toggle,dn),l=s(null==(t=e.text)?void 0:t.body,dn),d=s(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(l).length&&(r.text={},r.text.body=l),Object.keys(d).length&&(r.text=((e,t)=>{for(var n in t||(t={}))on.call(t,n)&&ln(e,n,t[n]);if(an)for(var n of an(t))sn.call(t,n)&&ln(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,s,l,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==(s=null==t?void 0:t.root)?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(l=null==t?void 0:t.input)?void 0:l.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null==(d=null==t?void 0:t.input)?void 0:d.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null==(c=null==t?void 0:t.input)?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null==(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==(I=null==(_=null==t?void 0:t.text)?void 0:_.caption)?void 0:I.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function pn(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var un=Object.defineProperty,hn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,mn=Object.getOwnPropertySymbols,gn=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable,fn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||(t={}))gn.call(t,n)&&fn(e,n,t[n]);if(mn)for(var n of mn(t))vn.call(t,n)&&fn(e,n,t[n]);return e},Pn=(e,t)=>hn(e,yn(t)),bn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class _n{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=r}initialize(e){return bn(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(),s=a.getPaymentMethodOrThrow(r),{isDeveloperModeApplicable:l,isFastlaneStylingEnabled:d}=s.initializationData||{};this.threeDSVerificationMethod=null==(t=s.initializationData)?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(s,o.currency.code,o.id,a.getLocale());const c=cn(d?null==(n=null==s?void 0:s.initializationData)?void 0:n.fastlaneStyles:{},null==i?void 0:i.styles);yield this.paypalFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!l,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(r)),yield this.initializePayPalPaymentComponent(),i.onInit(e=>this.renderPayPalPaymentComponent(e)),i.onChange(()=>this.handlePayPalStoredInstrumentChange(r))})}execute(e,t){return bn(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)gn.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&mn)for(var r of mn(e))t.indexOf(r)<0&&vn.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);const{paymentData:a,methodId:o}=r,s=a&&_e(a);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=s?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 bn(this,null,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),r=e.getPaymentProviderCustomer(),i=pn(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 bn(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),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),{authenticationState:l,addresses:d,instruments:c}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:l,addresses:d,instruments:c}),s.authenticationState===L.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return bn(this,null,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),r=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),i={fields:Sn({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 bn(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 bn(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:s}=yield o({name:{fullName:a},billingAddress:this.paypalFastlaneUtils.mapBcToPayPalAddress(r)}),l=i.config.is3dsEnabled?yield this.get3DSNonce(s):s;yield this.createOrder(l);const{shouldSaveInstrument:d=!1,shouldSetAsDefaultInstrument:c=!1}=be(t)?t:{};return{methodId:e,paymentData:Pn(Sn({},t),{shouldSaveInstrument:d,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:l}}})}})}createOrder(e){return bn(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 bn(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 s={amount:i.orderAmount.toFixed(2),currency:r.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===F.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},l=yield o.isEligible(s);if(this.threeDSVerificationMethod===F.Always&&!l)throw new Se;if(l){const{liabilityShift:e,authenticationState:t,nonce:n}=yield o.show();if(e===Ke.No||e===Ke.Unknown||t===M.Errored||t===M.Cancelled)throw new Se;if(t===M.Succeeded&&[Ke.Yes,Ke.Possible].includes(e))return n;throw new Se}return e})}handlePayPalStoredInstrumentChange(e){return bn(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=pn(t)?t:{},i=this.paypalFastlaneUtils.mapPayPalToBcInstrument(e,r)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Pn(Sn({},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 In=l(e=>{const{getHost:t}=e.getState();return new _n(e,new nn(n({host:t()})),k(),ht())},[{id:"paypalcommerceacceleratedcheckout"}]);var wn=Object.defineProperty,Cn=Object.defineProperties,On=Object.getOwnPropertyDescriptors,En=Object.getOwnPropertySymbols,zn=Object.prototype.hasOwnProperty,kn=Object.prototype.propertyIsEnumerable,Tn=(e,t,n)=>t in e?wn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,An=(e,t)=>{for(var n in t||(t={}))zn.call(t,n)&&Tn(e,n,t[n]);if(En)for(var n of En(t))kn.call(t,n)&&Tn(e,n,t[n]);return e},Bn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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:s,onClick:l,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=An({},!s&&{onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e)}),Cn(y,On({onApprove:(n,r)=>this.onHostedCheckoutApprove(n,r,t,e,c,s)})));var y;return u.Buttons(An(An(An({fundingSource:a,style:this.paypalIntegrationService.getValidButtonStyle(i),createOrder:()=>Bn(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)},l?{onClick:l}:{}),d?{onCancel:d}:{}),o&&h))}onHostedCheckoutApprove(e,t,n,r,i,a){return Bn(this,null,function*(){if(!e.orderID)throw new u(p.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const s=o.lineItems.physicalItems.length>0;if(!a){const e=yield t.order.get(),n=this.paypalIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),s){const t=this.paypalIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}s&&(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 Bn(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 Bn(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 Fn=Object.defineProperty,Mn=Object.defineProperties,Dn=Object.getOwnPropertyDescriptors,xn=Object.getOwnPropertySymbols,Un=Object.prototype.hasOwnProperty,Ln=Object.prototype.propertyIsEnumerable,jn=(e,t,n)=>t in e?Fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vn=(e,t)=>{for(var n in t||(t={}))Un.call(t,n)&&jn(e,n,t[n]);if(xn)for(var n of xn(t))Ln.call(t,n)&&jn(e,n,t[n]);return e},Rn=(e,t)=>Mn(e,Dn(t)),Gn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Hn{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Gn(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 Gn(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Gn(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(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:l,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=Rn(Vn(Vn({fundingSource:o.FUNDING.PAYPAL,isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:l,style:Rn(Vn({},p),{height:40})},r&&{onClick:()=>r()}),l&&i&&{onPaymentComplete:()=>i()}),{onError:a}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,u);h.isEligible()?h.render(`#${n}`):this.paypalIntegrationService.removeElement(n)}}const Wn=l(e=>{const t=se(e),n=new Nn(e,t);return new Hn(e,t,n)},[{id:"paypalcommerce"}]);var Kn=Object.defineProperty,$n=Object.defineProperties,qn=Object.getOwnPropertyDescriptors,Yn=Object.getOwnPropertySymbols,Jn=Object.prototype.hasOwnProperty,Zn=Object.prototype.propertyIsEnumerable,Xn=(e,t,n)=>t in e?Kn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qn=(e,t)=>{for(var n in t||(t={}))Jn.call(t,n)&&Xn(e,n,t[n]);if(Yn)for(var n of Yn(t))Zn.call(t,n)&&Xn(e,n,t[n]);return e},er=(e,t)=>$n(e,qn(t)),tr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class nr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return tr(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 tr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return tr(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(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:l,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let h=!1;u.forEach(t=>{if(!h){const o=er(Qn(Qn({fundingSource:t,style:this.paypalIntegrationService.getValidButtonStyle(er(Qn({},p),{height:40})),isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c},l&&r&&{onPaymentComplete:()=>r()}),i&&{onClick:()=>i()}),{onError:a}),s=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,o);s.isEligible()&&(s.render(`#${n}`),h=!0)}}),h||this.paypalIntegrationService.removeElement(n)}}const rr=l(e=>{const t=se(e),n=new Nn(e,t);return new nr(e,t,n)},[{id:"paypalcommercecredit"}]);var ir=Object.defineProperty,ar=Object.getOwnPropertySymbols,or=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable,lr=(e,t,n)=>t in e?ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dr=(e,t)=>{for(var n in t||(t={}))or.call(t,n)&&lr(e,n,t[n]);if(ar)for(var n of ar(t))sr.call(t,n)&&lr(e,n,t[n]);return e},cr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class pr{constructor(e,t,n,r){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=r}loadPayPalSdk(e,t,n,r){return cr(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 cr(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 cr(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r}=yield this.paypalCommerceRequestSender.createOrder(e,dr({cartId:n},t));return r})}createOrderCardFields(e,t){return cr(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r,setupToken:i}=yield this.paypalCommerceRequestSender.createOrder(e,dr({cartId:n},t));return dr({orderId:r},i?{setupToken:i}:{})})}updateOrder(e){return cr(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 cr(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",dr({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===N.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return cr(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(dr({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 s(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 ur=Object.defineProperty,hr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,mr=Object.getOwnPropertySymbols,gr=Object.prototype.hasOwnProperty,vr=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?ur(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sr=(e,t)=>{for(var n in t||(t={}))gr.call(t,n)&&fr(e,n,t[n]);if(mr)for(var n of mr(t))vr.call(t,n)&&fr(e,n,t[n]);return e},Pr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class br{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,r,i){return Pr(this,null,function*(){const a=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);return this.loadPayPalSDK(a,i)})}loadPayPalSDK(e,t=!1){return Pr(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:s,clientId:l,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:m,isPayPalCreditAvailable:g,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:P=[],isGooglePayEnabled:b}=o,_=m||r,I="paypalcommercecreditcards"===i,w=I?["card"]:[],C=g?["credit","paylater"]:[],O=y?["venmo"]:[],E=b?["googlepay"]:[],z=r?["card-fields"]:[],k=[...I?[]:["card"],...g?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!P.includes(e))],T=[...w,...C,...O,...P],A=v(n);return{options:Sr(Sr({"client-id":l,"merchant-id":d,"enable-funding":T.length>0?T:void 0,"disable-funding":k.length>0?k:void 0,commit:_,components:["buttons","hosted-fields","payment-fields","legal",...E,...z],currency:t,intent:s},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=Sr({},t),a={[n]:Array.isArray(r)?r.join(","):r},t=hr(i,yr(a)))}),t}}const _r=r=>{const{getHost:i}=r.getState();return new pr(t(),r,new nn(n({host:i()})),new br(e()))};var Ir=Object.defineProperty,wr=Object.defineProperties,Cr=Object.getOwnPropertyDescriptors,Or=Object.getOwnPropertySymbols,Er=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable,kr=(e,t,n)=>t in e?Ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tr=(e,t)=>{for(var n in t||(t={}))Er.call(t,n)&&kr(e,n,t[n]);if(Or)for(var n of Or(t))zr.call(t,n)&&kr(e,n,t[n]);return e},Ar=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Br{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Ar(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 Ar(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Ar(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:s}=o||{},l=Tr({fundingSource:i.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle((d=Tr({},s),c={height:40},wr(d,Cr(c)))),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()});var d,c;const p=i.Buttons(l);p.isEligible()?p.render(`#${n}`):this.paypalCommerceIntegrationService.removeElement(n)}}const Nr=l(e=>new Br(e,_r(e)),[{id:"paypalcommercevenmo"}]);var Fr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Mr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=n}initialize(e){return Fr(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),s=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(a,i.currency.code,i.id,e.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(s,o,this.getFastlaneStyles(n,r))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Fr(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Fr(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 Fr(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Fr(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 Fr(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),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),l=s.authenticationState===L.CANCELED;yield this.updateCustomerDataState(e,s),l?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Fr(this,null,function*(){var n;const r=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:i,addresses:a,billingAddress:o,shippingAddress:s,instruments:l}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:i,addresses:a,instruments:l}),o&&(yield this.paymentIntegrationService.updateBillingAddress(o)),s&&r.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),r=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:i}=r.initializationData||{},a=(null==(n=(t.getConsignments()||[])[0])?void 0:n.availableShippingOptions)||[],o=a[0],l=a.find(e=>e.isRecommended);if((l||o)&&i){const e=(null==l?void 0:l.id)||o.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles: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 Dr=l(e=>new Mr(e,k(),ht()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var xr=Object.defineProperty,Ur=Object.getOwnPropertySymbols,Lr=Object.prototype.hasOwnProperty,jr=Object.prototype.propertyIsEnumerable,Vr=(e,t,n)=>t in e?xr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rr=(e,t)=>{for(var n in t||(t={}))Lr.call(t,n)&&Vr(e,n,t[n]);if(Ur)for(var n of Ur(t))jr.call(t,n)&&Vr(e,n,t[n]);return e};class Gr{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,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},p={onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Rr(Rr({fundingSource:s.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 Hr=l(e=>{const t=se(e),n=new Nn(e,t);return new Gr(e,t,n)},[{id:"paypalcommerce"}]);var Wr=Object.defineProperty,Kr=Object.getOwnPropertySymbols,$r=Object.prototype.hasOwnProperty,qr=Object.prototype.propertyIsEnumerable,Yr=(e,t,n)=>t in e?Wr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Jr=(e,t)=>{for(var n in t||(t={}))$r.call(t,n)&&Yr(e,n,t[n]);if(Kr)for(var n of Kr(t))qr.call(t,n)&&Yr(e,n,t[n]);return e},Zr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Xr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Zr(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 s=this.paymentIntegrationService.getState(),l=o?a:s.getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(r,l,!1),this.renderButton(n,r,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onComplete:a,onEligibilityFailure:o}=n,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},p={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let h=!1;u.forEach(n=>{if(!h){const s=Jr(Jr({fundingSource:n,style:this.paypalIntegrationService.getValidButtonStyle(i),isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c,buyNowInitializeOptions:r},d&&a&&{onPaymentComplete:()=>a()}),r&&p),l=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,s);l.isEligible()?(l.render(`#${e}`),h=!0):o&&"function"==typeof o&&o()}}),h||this.paypalIntegrationService.removeElement(e)}handleClick(e){return Zr(this,null,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Qr=l(e=>{const t=se(e),n=new Nn(e,t);return new Xr(e,t,n)},[{id:"paypalcommercecredit"}]);var ei=Object.defineProperty,ti=Object.defineProperties,ni=Object.getOwnPropertyDescriptors,ri=Object.getOwnPropertySymbols,ii=Object.prototype.hasOwnProperty,ai=Object.prototype.propertyIsEnumerable,oi=(e,t,n)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,si=(e,t)=>{for(var n in t||(t={}))ii.call(t,n)&&oi(e,n,t[n]);if(ri)for(var n of ri(t))ai.call(t,n)&&oi(e,n,t[n]);return e},li=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class di{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return li(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 s=o?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(r,s,!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(),s=o.FUNDING.VENMO,l={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},d={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=si(si({fundingSource:s,style:this.getValidVenmoButtonStyles(i)},l),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=si({},t),ti(n,ni({color:void 0}))):t;var n}handleClick(e){return li(this,null,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ci=l(e=>new di(e,_r(e)),[{id:"paypalcommercevenmo"}]);var pi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class ui{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,r){return pi(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 pi(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 pi(this,null,function*(){const r={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(r,this.intentTypename,n)).body.orderId})}addBillingAddress(e,t,n){return pi(this,null,function*(){return this.walletButtonIntegrationService.addBillingAddress(e,t,n)})}mapOrderDetailsToBillingAddress({payer:e}){var t,n,r,i;return{firstName:e.name.given_name,lastName:e.name.surname,company:"",address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,email:e.email_address,stateOrProvince:null!=(t=e.address.admin_area_1)?t:"",stateOrProvinceCode:null!=(n=e.address.admin_area_1)?n:"",countryCode:e.address.country_code,postalCode:e.address.postal_code,phone:null!=(i=null==(r=e.phone)?void 0:r.phone_number.national_number)?i:"",shouldSaveAddress:!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 s(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 hi=Object.defineProperty,yi=Object.getOwnPropertySymbols,mi=Object.prototype.hasOwnProperty,gi=Object.prototype.propertyIsEnumerable,vi=(e,t,n)=>t in e?hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Si{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return fi(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 s=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,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>fi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommerce",e)})},o=((e,t)=>{for(var n in t||(t={}))mi.call(t,n)&&vi(e,n,t[n]);if(yi)for(var n of yi(t))gi.call(t,n)&&vi(e,n,t[n]);return e})({fundingSource:i.FUNDING.PAYPAL,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},a),s=i.Buttons(o);s.isEligible()?s.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const Pi=l(e=>new Si(new ui(e,k())),[{id:"paypalcommercepaypal"}]);var bi=Object.defineProperty,_i=Object.getOwnPropertySymbols,Ii=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,Ci=(e,t,n)=>t in e?bi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Oi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ei{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return Oi(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 s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;this.renderButton(i,"paypalcommerce.paypalcredit",r.cartId,s)})}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=>Oi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercecredit",e)})};let s=!1;a.forEach(t=>{if(!s){const n=((e,t)=>{for(var n in t||(t={}))Ii.call(t,n)&&Ci(e,n,t[n]);if(_i)for(var n of _i(t))wi.call(t,n)&&Ci(e,n,t[n]);return e})({fundingSource:t,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},o),a=i.Buttons(n);a.isEligible()&&(a.render(`#${e}`),s=!0)}}),s||this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const zi=l(e=>new Ei(new ui(e,k())),[{id:"paypalcommercepaypalcredit"}]);var ki=Object.defineProperty,Ti=Object.defineProperties,Ai=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertySymbols,Ni=Object.prototype.hasOwnProperty,Fi=Object.prototype.propertyIsEnumerable,Mi=(e,t,n)=>t in e?ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Di=(e,t)=>{for(var n in t||(t={}))Ni.call(t,n)&&Mi(e,n,t[n]);if(Bi)for(var n of Bi(t))Fi.call(t,n)&&Mi(e,n,t[n]);return e},xi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ui{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return xi(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 s=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,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>xi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercevenmo",e)})},o=Di({fundingSource:i.FUNDING.VENMO,style:this.getValidVenmoButtonStyles(r)},a),s=i.Buttons(o);s.isEligible()?s.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(e);return t.color===qe.gold?(n=Di({},t),Ti(n,Ai({color:void 0}))):t;var n}}const Li=l(e=>new Ui(new ui(e,k())),[{id:"paypalcommercevenmo"}]);export{rt as createPayPalCommerceAlternativeMethodsPaymentStrategy,Hr as createPayPalCommerceButtonStrategy,Qr as createPayPalCommerceCreditButtonStrategy,Ft as createPayPalCommerceCreditCardsPaymentStrategy,rr as createPayPalCommerceCreditCustomerStrategy,xe as createPayPalCommerceCreditPaymentStrategy,zi as createPayPalCommerceCreditWalletStrategy,Wn as createPayPalCommerceCustomerStrategy,Dr as createPayPalCommerceFastlaneCustomerStrategy,In as createPayPalCommerceFastlanePaymentStrategy,Te as createPayPalCommercePaymentStrategy,qt as createPayPalCommerceRatePayPaymentStrategy,ci as createPayPalCommerceVenmoButtonStrategy,Nr as createPayPalCommerceVenmoCustomerStrategy,Ge as createPayPalCommerceVenmoPaymentStrategy,Li as createPayPalCommerceVenmoWalletStrategy,Pi 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 s}from"lodash";function l(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,_=Object.prototype.hasOwnProperty,I=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={}))_.call(t,n)&&w(e,n,t[n]);if(b)for(var n of b(t))I.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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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:s,clientId:l,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:m,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:f,isDeveloperModeApplicable:S,availableAlternativePaymentMethods:P=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:_}=o,I=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)),N=_?["googlepay"]:[],F=r?["card-fields"]:[],M=this.filterFundingOptions([...E,...k,...A,...B]),D=this.filterFundingOptions([...O,...z,...T,...b]),x=v(n);return{options:C(C({"client-id":l,"merchant-id":d,"enable-funding":D.length>0?D:void 0,"disable-funding":M.length>0?M:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...N,...F],currency:t,intent:s},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:s,merchantId:l,attributionId:d}=a,c=v(r);return{options:O(C({"client-id":s,"merchant-id":l,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:o}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":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:s,merchantId:l,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:m}=a,g=h||r,f=v(n);return{options:C(C({"client-id":s,"merchant-id":l,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:s,attributionId:l,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":s}),f&&{locale:f}),attributes:{"data-partner-attribution-id":l,"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:s,buyerCountry:l}=r,d=v(n);return{options:C(C({"client-id":i,"merchant-id":a,components:["messages"],currency:t},s&&{"buyer-country":l}),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 N=(e=>(e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE",e))(N||{}),F=(e=>(e.Always="SCA_ALWAYS",e))(F||{}),M=(e=>(e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored",e))(M||{}),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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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),s=i.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(o,a,s,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===N.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 s(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.983.4"};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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 se=e=>{const{getHost:r}=e.getState();return new q(t(),e,new oe(n({host:r()})),k())};var le=Object.defineProperty,de=Object.getOwnPropertySymbols,ce=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable,ue=(e,t,n)=>t in e?le(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 _e(e){return Boolean(e.instrumentId)}const Ie=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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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:s}=r,{orderId:l,paypalBNPLConfiguration:d=[],isPayPalCreditAvailable:c}=a.initializationData||{};if(void 0!==s){if(!document.getElementById(s))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,s,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}l?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:s}=this.paypalcommerce||{};if(!a)throw new fe(["payment"]);const{methodId:l,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(l,this.orderId,d):this.preparePaymentPayload(l,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"),s)),t()})),this.handleError(e,s),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:s,onRenderButton:l,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,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(u),this.paypalButton.isEligible()&&(l&&"function"==typeof l&&l(),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&&_e(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&&_e(e)&&be(e)}renderMessages(e,t,n){const r={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:Ie(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=l(t=>new ke(t,se(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,Ne=Object.prototype.hasOwnProperty,Fe=Object.prototype.propertyIsEnumerable,Me=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 Me(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:s=[],orderId:l}=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=s&&s.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)}l?this.orderId=l:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,i))})}execute(e,t){return Me(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)Ne.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&&Fe.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:s,onRenderButton:l,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,s)};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.`);l&&"function"==typeof l&&l(),this.paypalButton.render(o),u=!0}})}handleClick(e,t){return Me(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:Ie(n)};e.Messages(r).render(`#${t}`)}}const xe=l(e=>new De(e,se(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(r);(null==(t=s.initializationData)?void 0:t.orderId)?this.orderId=null==(n=s.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:s,onRenderButton:l,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,s)};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.");l&&"function"==typeof l&&l(),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=l(e=>new Re(e,se(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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(),s=o.getPaymentMethodOrThrow(n,t),{orderId:l,shouldRenderFields:d}=s.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),l?this.orderId=l:(this.paypalApms=yield this.paypalSdkScriptLoader.getPayPalApmsSdk(s,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:s,onRenderButton:l,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,s)},onClick:(e,t)=>tt(this,null,function*(){return n.onValidate(t.resolve,t.reject)})};this.paypalButton=r.Buttons(c),this.paypalButton.isEligible()&&(l&&"function"==typeof l&&l(),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:s,apmFieldsStyles:l}=t;if(!s)throw new ve('Unable to initialize payment because "options.paypalcommercealternativemethods" argument should contain "apmFieldsContainer".');const d=document.querySelector(s);d&&(d.innerHTML="");const c={fundingSource:e,style:l||{},fields:{name:{value:`${i} ${a}`},email:{value:o}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in Je}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const rt=l(e=>new nt(e,se(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,st=Object.prototype.hasOwnProperty,lt=Object.prototype.propertyIsEnumerable,dt=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;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:s}=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}`),s&&(r+="; secure"),document.cookie=r}static remove(e,t){ct.set(e,"",((e,t)=>{for(var n in t||(t={}))st.call(t,n)&&dt(e,n,t[n]);if(ot)for(var n of ot(t))lt.call(t,n)&&dt(e,n,t[n]);return e})({expires:new Date(0)},t))}}var pt=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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,s=null==(i=null==(r=null==(n=null==o?void 0:o.card)?void 0:n.paymentSource)?void 0:r.card)?void 0:i.billingAddress,l=null==o?void 0:o.shippingAddress,d=null==o?void 0:o.name,c=null==o?void 0:o.card,p=l?this.mapPayPalToBcAddress(l.address,l.name,l.phoneNumber):void 0,u=s&&d?this.mapPayPalToBcAddress(s,d,null==l?void 0:l.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([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,[s,l]=a.split("-");return[{bigpayToken:n,brand:i,defaultInstrument:!1,expiryMonth:l,expiryYear:s,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)||"",s=(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:s+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 _t 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 It=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?It(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Nt{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:s}=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==s||s(),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 s=this.preparePaymentPayload(a,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(s)})}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:{},l=t&&_e(t)?t.instrumentId:void 0,d=s({verification_nonce:r,token:l},i);return{methodId:e,paymentData:{shouldSaveInstrument:a,shouldSetAsDefaultInstrument:o,instrumentId:l,formattedPayload:Tt(Tt({},r||l?{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(_e(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 _t(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=(s=a)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?a:{};var s;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 Ft=l(e=>new Nt(e,se(e),k(),ht()),[{id:"paypalcommercecreditcards"}]);var Mt=Object.getOwnPropertySymbols,Dt=Object.prototype.hasOwnProperty,xt=Object.prototype.propertyIsEnumerable,Ut=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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 s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:l}=s.initializationData||{};if(!l)throw new ve("Unable to initialize payment because merchantId argument is not provided.");this.paypalcommerceratepay=r,yield this.paypalCommerceService.loadPayPalSdk(n),this.createFraudNetScript(l,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&&Mt)for(var r of Mt(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:s}=a(),l={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:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:r.methodId,paymentData:l}),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 s=this.paypalCommerceService.getPayPalSdkOrThrow(),l=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new ve('Unable to initialize payment because "legalTextContainerElement" argument is not found.');l.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=l(e=>{return new Lt(e,se(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{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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,sn=Object.prototype.propertyIsEnumerable,ln=(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=s(e.root,dn),a=s(e.input,dn),o=s(e.toggle,dn),l=s(null==(t=e.text)?void 0:t.body,dn),d=s(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(l).length&&(r.text={},r.text.body=l),Object.keys(d).length&&(r.text=((e,t)=>{for(var n in t||(t={}))on.call(t,n)&&ln(e,n,t[n]);if(an)for(var n of an(t))sn.call(t,n)&&ln(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,s,l,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==(s=null==t?void 0:t.root)?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(l=null==t?void 0:t.input)?void 0:l.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null==(d=null==t?void 0:t.input)?void 0:d.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null==(c=null==t?void 0:t.input)?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null==(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==(I=null==(_=null==t?void 0:t.text)?void 0:_.caption)?void 0:I.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function pn(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var un=Object.defineProperty,hn=Object.defineProperties,yn=Object.getOwnPropertyDescriptors,mn=Object.getOwnPropertySymbols,gn=Object.prototype.hasOwnProperty,vn=Object.prototype.propertyIsEnumerable,fn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||(t={}))gn.call(t,n)&&fn(e,n,t[n]);if(mn)for(var n of mn(t))vn.call(t,n)&&fn(e,n,t[n]);return e},Pn=(e,t)=>hn(e,yn(t)),bn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class _n{constructor(e,t,n,r){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=r}initialize(e){return bn(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(),s=a.getPaymentMethodOrThrow(r),{isDeveloperModeApplicable:l,isFastlaneStylingEnabled:d}=s.initializationData||{};this.threeDSVerificationMethod=null==(t=s.initializationData)?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(s,o.currency.code,o.id,a.getLocale());const c=cn(d?null==(n=null==s?void 0:s.initializationData)?void 0:n.fastlaneStyles:{},null==i?void 0:i.styles);yield this.paypalFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!l,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(r)),yield this.initializePayPalPaymentComponent(),i.onInit(e=>this.renderPayPalPaymentComponent(e)),i.onChange(()=>this.handlePayPalStoredInstrumentChange(r))})}execute(e,t){return bn(this,null,function*(){const n=e,{payment:r}=n,i=((e,t)=>{var n={};for(var r in e)gn.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&mn)for(var r of mn(e))t.indexOf(r)<0&&vn.call(e,r)&&(n[r]=e[r]);return n})(n,["payment"]);if(!r)throw new fe(["payment"]);const{paymentData:a,methodId:o}=r,s=a&&_e(a);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=s?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 bn(this,null,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),r=e.getPaymentProviderCustomer(),i=pn(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 bn(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),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),{authenticationState:l,addresses:d,instruments:c}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:l,addresses:d,instruments:c}),s.authenticationState===L.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return bn(this,null,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),r=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),i={fields:Sn({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 bn(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 bn(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:s}=yield o({name:{fullName:a},billingAddress:this.paypalFastlaneUtils.mapBcToPayPalAddress(r)}),l=i.config.is3dsEnabled?yield this.get3DSNonce(s):s;yield this.createOrder(l);const{shouldSaveInstrument:d=!1,shouldSetAsDefaultInstrument:c=!1}=be(t)?t:{};return{methodId:e,paymentData:Pn(Sn({},t),{shouldSaveInstrument:d,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:l}}})}})}createOrder(e){return bn(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 bn(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 s={amount:i.orderAmount.toFixed(2),currency:r.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===F.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},l=yield o.isEligible(s);if(this.threeDSVerificationMethod===F.Always&&!l)throw new Se;if(l){const{liabilityShift:e,authenticationState:t,nonce:n}=yield o.show();if(e===Ke.No||e===Ke.Unknown||t===M.Errored||t===M.Cancelled)throw new Se;if(t===M.Succeeded&&[Ke.Yes,Ke.Possible].includes(e))return n;throw new Se}return e})}handlePayPalStoredInstrumentChange(e){return bn(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=pn(t)?t:{},i=this.paypalFastlaneUtils.mapPayPalToBcInstrument(e,r)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Pn(Sn({},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 In=l(e=>{const{getHost:t}=e.getState();return new _n(e,new nn(n({host:t()})),k(),ht())},[{id:"paypalcommerceacceleratedcheckout"}]);var wn=Object.defineProperty,Cn=Object.defineProperties,On=Object.getOwnPropertyDescriptors,En=Object.getOwnPropertySymbols,zn=Object.prototype.hasOwnProperty,kn=Object.prototype.propertyIsEnumerable,Tn=(e,t,n)=>t in e?wn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,An=(e,t)=>{for(var n in t||(t={}))zn.call(t,n)&&Tn(e,n,t[n]);if(En)for(var n of En(t))kn.call(t,n)&&Tn(e,n,t[n]);return e},Bn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((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:s,onClick:l,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=An({},!s&&{onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e)}),Cn(y,On({onApprove:(n,r)=>this.onHostedCheckoutApprove(n,r,t,e,c,s)})));var y;return u.Buttons(An(An(An({fundingSource:a,style:this.paypalIntegrationService.getValidButtonStyle(i),createOrder:()=>Bn(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)},l?{onClick:l}:{}),d?{onCancel:d}:{}),o&&h))}onHostedCheckoutApprove(e,t,n,r,i,a){return Bn(this,null,function*(){if(!e.orderID)throw new u(p.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const s=o.lineItems.physicalItems.length>0;if(!a){const e=yield t.order.get(),n=this.paypalIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),s){const t=this.paypalIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}s&&(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 Bn(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 Bn(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 Fn=Object.defineProperty,Mn=Object.defineProperties,Dn=Object.getOwnPropertyDescriptors,xn=Object.getOwnPropertySymbols,Un=Object.prototype.hasOwnProperty,Ln=Object.prototype.propertyIsEnumerable,jn=(e,t,n)=>t in e?Fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vn=(e,t)=>{for(var n in t||(t={}))Un.call(t,n)&&jn(e,n,t[n]);if(xn)for(var n of xn(t))Ln.call(t,n)&&jn(e,n,t[n]);return e},Rn=(e,t)=>Mn(e,Dn(t)),Gn=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Hn{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Gn(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 Gn(this,null,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Gn(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(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:l,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=Rn(Vn(Vn({fundingSource:o.FUNDING.PAYPAL,isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:l,style:Rn(Vn({},p),{height:40})},r&&{onClick:()=>r()}),l&&i&&{onPaymentComplete:()=>i()}),{onError:a}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,u);h.isEligible()?h.render(`#${n}`):this.paypalIntegrationService.removeElement(n)}}const Wn=l(e=>{const t=se(e),n=new Nn(e,t);return new Hn(e,t,n)},[{id:"paypalcommerce"}]);var Kn=Object.defineProperty,$n=Object.defineProperties,qn=Object.getOwnPropertyDescriptors,Yn=Object.getOwnPropertySymbols,Jn=Object.prototype.hasOwnProperty,Zn=Object.prototype.propertyIsEnumerable,Xn=(e,t,n)=>t in e?Kn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qn=(e,t)=>{for(var n in t||(t={}))Jn.call(t,n)&&Xn(e,n,t[n]);if(Yn)for(var n of Yn(t))Zn.call(t,n)&&Xn(e,n,t[n]);return e},er=(e,t)=>$n(e,qn(t)),tr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class nr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return tr(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 tr(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return tr(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(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:l,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},{checkoutTopButtonStyles:p}=d||{},u=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let h=!1;u.forEach(t=>{if(!h){const o=er(Qn(Qn({fundingSource:t,style:this.paypalIntegrationService.getValidButtonStyle(er(Qn({},p),{height:40})),isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c},l&&r&&{onPaymentComplete:()=>r()}),i&&{onClick:()=>i()}),{onError:a}),s=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,o);s.isEligible()&&(s.render(`#${n}`),h=!0)}}),h||this.paypalIntegrationService.removeElement(n)}}const rr=l(e=>{const t=se(e),n=new Nn(e,t);return new nr(e,t,n)},[{id:"paypalcommercecredit"}]);var ir=Object.defineProperty,ar=Object.getOwnPropertySymbols,or=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable,lr=(e,t,n)=>t in e?ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,dr=(e,t)=>{for(var n in t||(t={}))or.call(t,n)&&lr(e,n,t[n]);if(ar)for(var n of ar(t))sr.call(t,n)&&lr(e,n,t[n]);return e},cr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class pr{constructor(e,t,n,r){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=r}loadPayPalSdk(e,t,n,r){return cr(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 cr(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 cr(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r}=yield this.paypalCommerceRequestSender.createOrder(e,dr({cartId:n},t));return r})}createOrderCardFields(e,t){return cr(this,null,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:r,setupToken:i}=yield this.paypalCommerceRequestSender.createOrder(e,dr({cartId:n},t));return dr({orderId:r},i?{setupToken:i}:{})})}updateOrder(e){return cr(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 cr(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",dr({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===N.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return cr(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(dr({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 s(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 ur=Object.defineProperty,hr=Object.defineProperties,yr=Object.getOwnPropertyDescriptors,mr=Object.getOwnPropertySymbols,gr=Object.prototype.hasOwnProperty,vr=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?ur(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sr=(e,t)=>{for(var n in t||(t={}))gr.call(t,n)&&fr(e,n,t[n]);if(mr)for(var n of mr(t))vr.call(t,n)&&fr(e,n,t[n]);return e},Pr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class br{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,r,i){return Pr(this,null,function*(){const a=this.getPayPalSdkScriptConfigOrThrow(e,t,n,r);return this.loadPayPalSDK(a,i)})}loadPayPalSDK(e,t=!1){return Pr(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:s,clientId:l,merchantId:d,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:m,isPayPalCreditAvailable:g,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:P=[],isGooglePayEnabled:b}=o,_=m||r,I="paypalcommercecreditcards"===i,w=I?["card"]:[],C=g?["credit","paylater"]:[],O=y?["venmo"]:[],E=b?["googlepay"]:[],z=r?["card-fields"]:[],k=[...I?[]:["card"],...g?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!P.includes(e))],T=[...w,...C,...O,...P],A=v(n);return{options:Sr(Sr({"client-id":l,"merchant-id":d,"enable-funding":T.length>0?T:void 0,"disable-funding":k.length>0?k:void 0,commit:_,components:["buttons","hosted-fields","payment-fields","legal",...E,...z],currency:t,intent:s},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=Sr({},t),a={[n]:Array.isArray(r)?r.join(","):r},t=hr(i,yr(a)))}),t}}const _r=r=>{const{getHost:i}=r.getState();return new pr(t(),r,new nn(n({host:i()})),new br(e()))};var Ir=Object.defineProperty,wr=Object.defineProperties,Cr=Object.getOwnPropertyDescriptors,Or=Object.getOwnPropertySymbols,Er=Object.prototype.hasOwnProperty,zr=Object.prototype.propertyIsEnumerable,kr=(e,t,n)=>t in e?Ir(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tr=(e,t)=>{for(var n in t||(t={}))Er.call(t,n)&&kr(e,n,t[n]);if(Or)for(var n of Or(t))zr.call(t,n)&&kr(e,n,t[n]);return e},Ar=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Br{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Ar(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 Ar(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Ar(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:s}=o||{},l=Tr({fundingSource:i.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle((d=Tr({},s),c={height:40},wr(d,Cr(c)))),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()});var d,c;const p=i.Buttons(l);p.isEligible()?p.render(`#${n}`):this.paypalCommerceIntegrationService.removeElement(n)}}const Nr=l(e=>new Br(e,_r(e)),[{id:"paypalcommercevenmo"}]);var Fr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Mr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=n}initialize(e){return Fr(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),s=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(a,i.currency.code,i.id,e.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(s,o,this.getFastlaneStyles(n,r))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Fr(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Fr(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 Fr(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Fr(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 Fr(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),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(o),l=s.authenticationState===L.CANCELED;yield this.updateCustomerDataState(e,s),l?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Fr(this,null,function*(){var n;const r=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:i,addresses:a,billingAddress:o,shippingAddress:s,instruments:l}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:i,addresses:a,instruments:l}),o&&(yield this.paymentIntegrationService.updateBillingAddress(o)),s&&r.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),r=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:i}=r.initializationData||{},a=(null==(n=(t.getConsignments()||[])[0])?void 0:n.availableShippingOptions)||[],o=a[0],l=a.find(e=>e.isRecommended);if((l||o)&&i){const e=(null==l?void 0:l.id)||o.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles: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 Dr=l(e=>new Mr(e,k(),ht()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var xr=Object.defineProperty,Ur=Object.getOwnPropertySymbols,Lr=Object.prototype.hasOwnProperty,jr=Object.prototype.propertyIsEnumerable,Vr=(e,t,n)=>t in e?xr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rr=(e,t)=>{for(var n in t||(t={}))Lr.call(t,n)&&Vr(e,n,t[n]);if(Ur)for(var n of Ur(t))jr.call(t,n)&&Vr(e,n,t[n]);return e};class Gr{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,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},p={onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=Rr(Rr({fundingSource:s.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 Hr=l(e=>{const t=se(e),n=new Nn(e,t);return new Gr(e,t,n)},[{id:"paypalcommerce"}]);var Wr=Object.defineProperty,Kr=Object.getOwnPropertySymbols,$r=Object.prototype.hasOwnProperty,qr=Object.prototype.propertyIsEnumerable,Yr=(e,t,n)=>t in e?Wr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Jr=(e,t)=>{for(var n in t||(t={}))$r.call(t,n)&&Yr(e,n,t[n]);if(Kr)for(var n of Kr(t))qr.call(t,n)&&Yr(e,n,t[n]);return e},Zr=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Xr{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Zr(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 s=this.paymentIntegrationService.getState(),l=o?a:s.getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(r,l,!1),this.renderButton(n,r,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:r,style:i,onComplete:a,onEligibilityFailure:o}=n,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),l=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c}=l.initializationData||{},p={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let h=!1;u.forEach(n=>{if(!h){const s=Jr(Jr({fundingSource:n,style:this.paypalIntegrationService.getValidButtonStyle(i),isHostedCheckoutEnabled:d,isServerSideShippingCallbacksEnabled:c,buyNowInitializeOptions:r},d&&a&&{onPaymentComplete:()=>a()}),r&&p),l=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,s);l.isEligible()?(l.render(`#${e}`),h=!0):o&&"function"==typeof o&&o()}}),h||this.paypalIntegrationService.removeElement(e)}handleClick(e){return Zr(this,null,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const Qr=l(e=>{const t=se(e),n=new Nn(e,t);return new Xr(e,t,n)},[{id:"paypalcommercecredit"}]);var ei=Object.defineProperty,ti=Object.defineProperties,ni=Object.getOwnPropertyDescriptors,ri=Object.getOwnPropertySymbols,ii=Object.prototype.hasOwnProperty,ai=Object.prototype.propertyIsEnumerable,oi=(e,t,n)=>t in e?ei(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,si=(e,t)=>{for(var n in t||(t={}))ii.call(t,n)&&oi(e,n,t[n]);if(ri)for(var n of ri(t))ai.call(t,n)&&oi(e,n,t[n]);return e},li=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class di{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return li(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 s=o?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(r,s,!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(),s=o.FUNDING.VENMO,l={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},d={onClick:()=>this.handleClick(r),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=si(si({fundingSource:s,style:this.getValidVenmoButtonStyles(i)},l),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=si({},t),ti(n,ni({color:void 0}))):t;var n}handleClick(e){return li(this,null,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const ci=l(e=>new di(e,_r(e)),[{id:"paypalcommercevenmo"}]);var pi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class ui{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,r){return pi(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 pi(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 pi(this,null,function*(){const r={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(r,this.intentTypename,n)).body.orderId})}addBillingAddress(e,t,n){return pi(this,null,function*(){return this.walletButtonIntegrationService.addBillingAddress(e,t,n)})}mapOrderDetailsToBillingAddress({payer:e}){var t,n,r,i;return{firstName:e.name.given_name,lastName:e.name.surname,company:"",address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,email:e.email_address,stateOrProvince:null!=(t=e.address.admin_area_1)?t:"",stateOrProvinceCode:null!=(n=e.address.admin_area_1)?n:"",countryCode:e.address.country_code,postalCode:e.address.postal_code,phone:null!=(i=null==(r=e.phone)?void 0:r.phone_number.national_number)?i:"",shouldSaveAddress:!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 s(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 hi=Object.defineProperty,yi=Object.getOwnPropertySymbols,mi=Object.prototype.hasOwnProperty,gi=Object.prototype.propertyIsEnumerable,vi=(e,t,n)=>t in e?hi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Si{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return fi(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 s=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,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>fi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommerce",e)})},o=((e,t)=>{for(var n in t||(t={}))mi.call(t,n)&&vi(e,n,t[n]);if(yi)for(var n of yi(t))gi.call(t,n)&&vi(e,n,t[n]);return e})({fundingSource:i.FUNDING.PAYPAL,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},a),s=i.Buttons(o);s.isEligible()?s.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const Pi=l(e=>new Si(new ui(e,k())),[{id:"paypalcommercepaypal"}]);var bi=Object.defineProperty,_i=Object.getOwnPropertySymbols,Ii=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,Ci=(e,t,n)=>t in e?bi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Oi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ei{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return Oi(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 s=null==(n=null==(t=o.initializationData)?void 0:t.paymentButtonStyles)?void 0:n.cartButtonStyles;this.renderButton(i,"paypalcommerce.paypalcredit",r.cartId,s)})}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=>Oi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercecredit",e)})};let s=!1;a.forEach(t=>{if(!s){const n=((e,t)=>{for(var n in t||(t={}))Ii.call(t,n)&&Ci(e,n,t[n]);if(_i)for(var n of _i(t))wi.call(t,n)&&Ci(e,n,t[n]);return e})({fundingSource:t,style:this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(r)},o),a=i.Buttons(n);a.isEligible()&&(a.render(`#${e}`),s=!0)}}),s||this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}}const zi=l(e=>new Ei(new ui(e,k())),[{id:"paypalcommercepaypalcredit"}]);var ki=Object.defineProperty,Ti=Object.defineProperties,Ai=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertySymbols,Ni=Object.prototype.hasOwnProperty,Fi=Object.prototype.propertyIsEnumerable,Mi=(e,t,n)=>t in e?ki(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Di=(e,t)=>{for(var n in t||(t={}))Ni.call(t,n)&&Mi(e,n,t[n]);if(Bi)for(var n of Bi(t))Fi.call(t,n)&&Mi(e,n,t[n]);return e},xi=(e,t,n)=>new Promise((r,i)=>{var a=e=>{try{s(n.next(e))}catch(e){i(e)}},o=e=>{try{s(n.throw(e))}catch(e){i(e)}},s=e=>e.done?r(e.value):Promise.resolve(e.value).then(a,o);s((n=n.apply(e,t)).next())});class Ui{constructor(e){this.paypalCommerceHeadlessWalletButtonService=e}initialize(e){return xi(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 s=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,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,r){const i=this.paypalCommerceHeadlessWalletButtonService.getPayPalSdkOrThrow(),a={createOrder:()=>this.paypalCommerceHeadlessWalletButtonService.createPaymentOrderIntent(t,n),onApprove:e=>xi(this,[e],function*({orderID:e}){yield this.paypalCommerceHeadlessWalletButtonService.proxyTokenizationPayment(n,t,"paypalcommercevenmo",e)})},o=Di({fundingSource:i.FUNDING.VENMO,style:this.getValidVenmoButtonStyles(r)},a),s=i.Buttons(o);s.isEligible()?s.render(`#${e}`):this.paypalCommerceHeadlessWalletButtonService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceHeadlessWalletButtonService.getValidButtonStyle(e);return t.color===qe.gold?(n=Di({},t),Ti(n,Ai({color:void 0}))):t;var n}}const Li=l(e=>new Ui(new ui(e,k())),[{id:"paypalcommercevenmo"}]);export{rt as createPayPalCommerceAlternativeMethodsPaymentStrategy,Hr as createPayPalCommerceButtonStrategy,Qr as createPayPalCommerceCreditButtonStrategy,Ft as createPayPalCommerceCreditCardsPaymentStrategy,rr as createPayPalCommerceCreditCustomerStrategy,xe as createPayPalCommerceCreditPaymentStrategy,zi as createPayPalCommerceCreditWalletStrategy,Wn as createPayPalCommerceCustomerStrategy,Dr as createPayPalCommerceFastlaneCustomerStrategy,In as createPayPalCommerceFastlanePaymentStrategy,Te as createPayPalCommercePaymentStrategy,qt as createPayPalCommerceRatePayPaymentStrategy,ci as createPayPalCommerceVenmoButtonStrategy,Nr as createPayPalCommerceVenmoCustomerStrategy,Ge as createPayPalCommerceVenmoPaymentStrategy,Li as createPayPalCommerceVenmoWalletStrategy,Pi as createPayPalCommerceWalletStrategy};
2
2
  //# sourceMappingURL=paypal-commerce.js.map