@bigcommerce/checkout-sdk 1.927.2 → 1.928.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{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 i,isNil as r,noop as o,omit as a,omitBy as s}from"lodash";function d(e,t){return Object.assign(e,{resolveIds:t})}class l 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 l{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 u;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentRedirectUrl=13]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=14]="MissingPaymentStatus",e[e.MissingPaymentToken=15]="MissingPaymentToken",e[e.MissingShippingAddress=16]="MissingShippingAddress"}(u||(u={}));class p extends l{constructor(e){super(function(e){switch(e){case u.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case u.MissingCart:return"Unable to proceed because cart data is unavailable.";case u.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case u.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case u.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case u.MissingCheckoutConfig:case u.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case u.MissingOrder:return"Unable to proceed because order data is unavailable.";case u.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case u.MissingPayment:return"Unable to proceed because payment data is unavailable.";case u.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case u.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case u.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(e)),this.subtype=e,this.name="MissingDataError",this.type="missing_data"}}const h={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},y=["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 m(e){if(!e)return;let t;if(e.includes("-")){const[n,i]=e.split("-");t=`${n}_${i.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return y.includes(t)?t:void 0}var g=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class v{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return g(this,void 0,void 0,function*(){if(!this.window.paypal||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypal)throw new c}return this.window.paypal})}getPayPalFastlaneSdk(e,t,n,i){return g(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const r=this.getPayPalFastlaneSdkConfiguration(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i,r){return g(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||r){const r=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return g(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return g(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}loadPayPalSdk(e){return g(this,arguments,void 0,function*({options:e,attributes:t}){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:o,initializationData:a}=e;if(!a||!a.clientId)throw new p(u.MissingPaymentMethod);const{intent:s,clientId:d,merchantId:l,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:v,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:I=[],isGooglePayEnabled:_}=a,P=g||i,b="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,C=b?["card"]:[],w=v?["credit","paylater"]:[],O=y?["venmo"]:[],z=_?["googlepay"]:[],A=i?["card-fields"]:[],E=[...b?[]:["card"],...v?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!I.includes(e))],T=[...C,...w,...O,...I],k=m(n);return{options:Object.assign(Object.assign({"client-id":d,"merchant-id":l,"enable-funding":T.length>0?T:void 0,"disable-funding":E.length>0?E:void 0,commit:P,components:["buttons","hosted-fields","payment-fields","legal",...z,...A],currency:t,intent:s},f&&{"buyer-country":c}),k&&{locale:k}),attributes:{"data-partner-attribution-id":h,"data-client-token":o}}}getPayPalFastlaneSdkConfiguration(e,t,n,i){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new p(u.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,attributionId:l}=o,c=m(i);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:a}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":l,"data-sdk-client-token":r}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i=!0){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new p(u.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:l,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:y}=o,g=h||i,v=m(n);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:g,components:["googlepay"],currency:t,intent:a},y&&{"buyer-country":l}),v&&{locale:v}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new p(u.MissingPaymentMethod);const{intent:r,clientId:o,merchantId:a,buyerCountry:s,attributionId:d,isDeveloperModeApplicable:l,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=i,y=h,g=c.filter(e=>!h.includes(e)),v=m(n);return{options:Object.assign(Object.assign({"client-id":o,"merchant-id":a,"enable-funding":y.length>0?y:void 0,"disable-funding":g.length>0?g:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:r},l&&{"buyer-country":s}),v&&{locale:v}),attributes:{"data-partner-attribution-id":d,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new p(u.MissingPaymentMethod);const{clientId:r,merchantId:o,attributionId:a,isDeveloperModeApplicable:s,buyerCountry:d}=i,l=m(n);return{options:Object.assign(Object.assign({"client-id":r,"merchant-id":o,components:["messages"],currency:t},s&&{"buyer-country":d}),l&&{locale:l}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function f(){return new v(e())}class S extends l{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 I={body:{},headers:{},status:0};class _ extends l{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:o}=e||I;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}var P,b,C,w,O,z,A,E,T,k,M;!function(e){e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE"}(P||(P={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(b||(b={})),function(e){e.Always="SCA_ALWAYS"}(C||(C={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(w||(w={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(O||(O={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(z||(z={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(A||(A={})),function(e){e.pill="pill",e.rect="rect"}(E||(E={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(T||(T={})),function(e){e.OXXO="oxxo"}(k||(k={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(M||(M={}));var N=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class B{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=n,this.paypalSdkLoader=i}loadPayPalSdk(e,t,n,i){return N(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e),s=r.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(a,o,s,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return N(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new p(u.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new S}})}createOrder(e,t){return N(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return N(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(e,t,n,i){return N(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow();let a;i||(a=r.getConsignmentsOrThrow()[0]);try{yield this.paypalRequestSender.updateOrder(e,Object.assign(Object.assign({availableShippingOptions:i?[]:null==a?void 0:a.availableShippingOptions,cartId:o.id,selectedShippingOption:i?null:null==a?void 0:a.selectedShippingOption},t?{methodId:t}:{}),n?{orderId:n}:{}))}catch(e){throw new _}})}getOrderStatus(e,t){return N(this,void 0,void 0,function*(){try{const{status:n}=yield this.paypalRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new p(u.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===P.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return N(this,void 0,void 0,function*(){const i={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{if(t.selectedShippingOption){const n=t.selectedShippingOption.id;return e.id===n}return!1}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,n;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e={}){const{color:t,height:n,label:i,shape:o}=e,a={color:t&&A[t]?t:void 0,height:this.getValidHeight(n),label:i&&z[i]?i:void 0,shape:o&&E[o]?o:void 0};return s(a,r)}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 F="This API endpoint is for internal use only and may change in the future";var D;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(D||(D={}));const x=D,U={"X-Checkout-SDK-Version":"1.927.2"};var j=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class L{constructor(e){this.requestSender=e}createOrder(e,t){return j(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e,t){return j(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.put(n,{headers:r,body:i})).body})}getOrderStatus(e,t){return j(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}const V=e=>{const{getHost:i}=e.getState();return new B(t(),e,new L(n({host:i()})),f())},R={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},G="embedded-checkout-loading-indicator-rotation";class K{constructor(e){this.styles=Object.assign(Object.assign({},R),e&&e.styles),this.containerStyles=Object.assign({},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=`${G} 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(G))return;const t=document.createElement("style");t.id=G,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${G} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}class H extends l{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class $ extends H{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 q extends _{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 Y extends l{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function W(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function Z(e){return Boolean(e.instrumentId)}const J=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 X(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 Q=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ee{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.payPalSdkScriptLoader=n,this.loadingIndicator=i}initialize(e){return Q(this,void 0,void 0,function*(){var t;const{methodId:n,paypalcommerce:i}=e||{};if(this.paypalcommerce=i,!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(n),{container:a,bannerContainerId:s}=i,{orderId:d,paypalBNPLConfiguration:l=[],isPayPalCreditAvailable:c}=o.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==l?void 0:l.find(({id:e})=>"checkout"===e);if(c||!(null==e?void 0:e.status))return;const t=yield this.payPalSdkScriptLoader.getPayPalMessages(o,r.getCartOrThrow().currency.code,r.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")}d?this.orderId=null===(t=o.initializationData)||void 0===t?void 0:t.orderId:(this.loadingIndicatorContainer=null==a?void 0:a.split("#")[1],yield this.paypalIntegrationService.loadPayPalSdk(n),i.onInit&&"function"==typeof i.onInit&&i.onInit(()=>this.renderButton(n,i)),(void 0===i.shouldRenderPayPalButtonOnInitialization||i.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(n,i))})}execute(e,t){return Q(this,void 0,void 0,function*(){var n,i;const{payment:r}=e,o=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{onError:a}=this.paypalcommerce||{};if(!r)throw new $(["payment"]);const{methodId:s,paymentData:d}=r;if(this.isPayPalVaultedInstrumentPaymentData(d)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new q;const l=this.isPayPalVaultedInstrumentPaymentData(d)?this.prepareVaultedInstrumentPaymentPayload(s,this.orderId,d):this.preparePaymentPayload(s,this.orderId,d);try{yield this.paymentIntegrationService.submitOrder(o,t),yield this.paymentIntegrationService.submitPayment(l)}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?void 0:t.type)}(e)){const t=null===(i=null===(n=e.body.additional_action_required)||void 0===n?void 0:n.data)||void 0===i?void 0:i.redirect_url;return new Promise(()=>window.location.replace(t))}return this.isProviderError(e)&&(yield this.paypalIntegrationService.loadPayPalSdk(r.methodId),yield new Promise((e,t)=>{var n;this.paypalcommerce&&(null===(n=this.paypalButton)||void 0===n||n.close(),this.renderButton(r.methodId,this.paypalcommerce),this.handleError(new Error("INSTRUMENT_DECLINED"),a)),t()})),this.handleError(e,a),Promise.reject()}})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:i,shouldSetAsDefaultInstrument:r}=n,o=!this.isTrustedVaultingFlow(n);return o?{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:i}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:i=!1,shouldSetAsDefaultInstrument:r=!1}=W(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t;if(!a)throw new H('Unable to initialize payment because "container" argument is not provided.');const u=this.getSmartButtonContainerId(a);if(!document.getElementById(u))throw new H(`Unable to initialize payment because element with id ${u} does not exist.`);const p={fundingSource:n.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onError:e=>this.handleError(e,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(p),this.paypalButton.isEligible()&&(d&&"function"==typeof d&&d(),this.paypalButton.render(a))}handleClick(e,t){return Q(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;return null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return Q(this,void 0,void 0,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&&Z(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>X(t)&&t.bigpayToken===e.instrumentId);return!(X(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&Z(e)&&W(e)}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:J(n)};e.Messages(i).render(`#${t}`)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null===(i=null===(n=((null===(t=null==e?void 0:e.errors)||void 0===t?void 0:t.filter(e=>e.provider_error))||[])[0])||void 0===n?void 0:n.provider_error)||void 0===i?void 0:i.code)}getSmartButtonContainerId(e){var t;return null!==(t=e.split("#")[1])&&void 0!==t?t:e}}const te=d(t=>new ee(t,V(t),new v(e()),new K({containerStyles:h})),[{id:"paypalcommerce"}]);class ne extends l{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var ie=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class re{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n,this.payPalSdkScriptLoader=i}initialize(e){return ie(this,void 0,void 0,function*(){const{methodId:t,paypalcommerce:n,paypalcommercecredit:i}=e||{},r=i||n;if(!t)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const o=this.paymentIntegrationService.getState(),a=o.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:s=[],orderId:d}=a.initializationData||{},{bannerContainerId:l,container:c}=r;if(void 0!==l){if(!document.getElementById(l))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(a,o.getCartOrThrow().currency.code,o.getLocale());return this.renderMessages(t,l,e)}d?this.orderId=d:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,r))})}execute(e,t){return ie(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);if(!this.orderId)throw new q;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new H('Unable to initialize payment because "container" argument is not provided.');const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,u=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let p=!1;u.forEach(e=>{if(p)return;const t={fundingSource:e,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,l),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 ne(`PayPal ${e} is not available for your region. Please use PayPal Checkout instead.`);d&&"function"==typeof d&&d(),this.paypalButton.render(a),p=!0}})}handleClick(e,t){return ie(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;if(t&&"function"==typeof t)return t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:J(n)};e.Messages(i).render(`#${t}`)}}const oe=d(e=>new re(e,V(e),new K({containerStyles:h}),f()),[{id:"paypalcommercecredit"}]);var ae=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class se{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n}initialize(e){return ae(this,void 0,void 0,function*(){var t,n;const{methodId:i,paypalcommerce:r,paypalcommercevenmo:o}=e||{},a=o||r;if(!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!a)throw new H('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i);(null===(t=s.initializationData)||void 0===t?void 0:t.orderId)?this.orderId=null===(n=s.initializationData)||void 0===n?void 0:n.orderId:(yield this.paypalIntegrationService.loadPayPalSdk(i),this.loadingIndicatorContainer=a.container.split("#")[1],this.renderButton(i,a))})}execute(e,t){return ae(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);if(!this.orderId)throw new q;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,u={fundingSource:n.FUNDING.VENMO,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercevenmocheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=n.Buttons(u),!this.paypalButton.isEligible())throw new ne("PayPal Venmo is not available for your region. Please use PayPal Checkout instead.");d&&"function"==typeof d&&d(),this.paypalButton.render(a)}handleClick(e,t){return ae(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;return t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t(),this.toggleLoadingIndicator(!1)}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const de=d(e=>new se(e,V(e),new K({containerStyles:h,styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]),le={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class ce extends _{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var ue,pe,he,ye,me,ge,ve;!function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ue||(ue={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(pe||(pe={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(he||(he={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ye||(ye={})),function(e){e.pill="pill",e.rect="rect"}(me||(me={})),function(e){e.OXXO="oxxo",e.IDEAL="ideal"}(ge||(ge={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(ve||(ve={}));var fe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Se{constructor(e,t,n,i,r=3e3,a=3e5){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalSdkScriptLoader=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=a,this.pollingTimer=0,this.stopPolling=o,this.isOrderApprovedProcessing=!1}initialize(e){return fe(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,paypalcommerce:i,paypalcommercealternativemethods:r}=e,o=r||i;if(this.paypalcommercealternativemethods=r,!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!o)throw new H('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');const a=this.paymentIntegrationService.getState(),s=a.getPaymentMethodOrThrow(n,t),{orderId:d,shouldRenderFields:l}=s.initializationData||{},c=a.getStoreConfigOrThrow().checkoutSettings.features;this.isOrderApprovedProcessing=function(e,t,n=!0){var i;return null!==(i=e["PAYPAL-5431.order_approved_processing"])&&void 0!==i?i:n}(c,0,!1),d?this.orderId=d:(this.paypalApms=yield this.paypalSdkScriptLoader.getPayPalApmsSdk(s,a.getCartOrThrow().currency.code,a.getLocale()),this.loadingIndicatorContainer=o.container.split("#")[1],this.renderButton(n,t,o),l&&this.renderFields(n,o))})}execute(e,t){return fe(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);const{methodId:r,gatewayId:o}=n;if(!this.orderId)throw new q;this.isOrderApprovedProcessing||"ideal"!==r||(yield new Promise((e,t)=>{this.initializePollingMechanism(r,e,t,o)})),this.isNonInstantPaymentMethod(r)&&(r!==ge.IDEAL||this.isOrderApprovedProcessing)||(yield this.paymentIntegrationService.submitOrder(i,t)),yield this.paypalCommerceIntegrationService.submitPayment(r,this.orderId,o)})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,this.isOrderApprovedProcessing||this.resetPollingMechanism(),null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,i){return fe(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.paypalCommerceIntegrationService.getOrderStatus(null!=i?i:"paypalcommerce"),o=r===ve.Approved,a=r===ve.PollingError;if(o)return this.deinitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,paypalcommercealternativemethods:this.paypalcommercealternativemethods}),this.handleError(new ce)}catch(e){n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return fe(this,void 0,void 0,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 i=this.getPaypalAmpsSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:o}=r.initializationData||{},{container:a,onError:s,onRenderButton:d,submitForm:l}=n,c={fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o),onInit:(e,t)=>n.onInitButton(t),createOrder:()=>this.onCreateOrder(e,t,n),onApprove:e=>this.handleApprove(e,l),onCancel:()=>{this.toggleLoadingIndicator(!1),this.deinitializePollingMechanism()},onError:e=>{this.deinitializePollingMechanism(),this.handleFailure(e,s)},onClick:(e,t)=>fe(this,void 0,void 0,function*(){return n.onValidate(t.resolve,t.reject)})};this.paypalButton=i.Buttons(c),this.paypalButton.isEligible()&&(d&&"function"==typeof d&&d(),this.paypalButton.render(a))}onCreateOrder(e,t,n){return fe(this,void 0,void 0,function*(){var i;const{onValidate:r}=n;yield r(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),o);const a=yield this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethodscheckout");if(this.isNonInstantPaymentMethod(e)&&(e===ge.IDEAL&&this.isOrderApprovedProcessing||e===ge.OXXO)){const n={useStoreCredit:!1},r={params:{methodId:e,gatewayId:t}};if(yield this.paymentIntegrationService.submitOrder(n,r),e===ge.IDEAL){const t=null===(i=this.paymentIntegrationService.getState().getOrder())||void 0===i?void 0:i.orderId;yield this.paypalCommerceIntegrationService.updateOrder("paypalcommercealternativemethods",e,t)}yield this.paypalCommerceIntegrationService.submitPayment(e,a,t)}return a})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const n=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState(),{firstName:r,lastName:o,email:a}=i.getBillingAddressOrThrow(),{apmFieldsContainer:s,apmFieldsStyles:d}=t;if(!s)throw new H('Unable to initialize payment because "options.paypalcommercealternativemethods" argument should contain "apmFieldsContainer".');const l=document.querySelector(s);l&&(l.innerHTML="");const c={fundingSource:e,style:d||{},fields:{name:{value:`${r} ${o}`},email:{value:a}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in ge}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const Ie=d(e=>new Se(e,V(e),f(),new K({containerStyles:le})),[{gateway:"paypalcommercealternativemethods"}]);var _e;!function(e){e.CVV="cvv",e.PAN="pan"}(_e||(_e={}));class Pe{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:o,domain:a,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}o&&(i+=`; path=${o}`),a&&(i+=`; domain=${a}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){Pe.set(e,"",Object.assign({expires:new Date(0)},t))}}var be,Ce=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class we{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return Ce(this,void 0,void 0,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 Ce(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return Ce(this,void 0,void 0,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};Pe.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){Pe.remove("bc-fastlane-sessionId")}getStorageSessionId(){return Pe.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,i,r;const{authenticationState:o,profileData:a}=t,s=null===(r=null===(i=null===(n=null==a?void 0:a.card)||void 0===n?void 0:n.paymentSource)||void 0===i?void 0:i.card)||void 0===r?void 0:r.billingAddress,d=null==a?void 0:a.shippingAddress,l=null==a?void 0:a.name,c=null==a?void 0:a.card,u=d?this.mapPayPalToBcAddress(d.address,d.name,d.phoneNumber):void 0,p=s&&l?this.mapPayPalToBcAddress(s,l,null==d?void 0:d.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([u,p]);return{authenticationState:o||T.UNRECOGNIZED,addresses:y,billingAddress:p,shippingAddress:u,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:i}=t,{brand:r,expiry:o,lastDigits:a}=i.card,[s,d]=o.split("-");return[{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:d,expiryYear:s,iin:"",last4:a,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:_e.PAN,type:"card"}]}mapBcToPayPalAddress(e){return{company:(null==e?void 0:e.company)||"",addressLine1:(null==e?void 0:e.address1)||"",addressLine2:(null==e?void 0:e.address2)||"",adminArea1:(null==e?void 0:e.stateOrProvinceCode)||(null==e?void 0:e.stateOrProvince)||"",adminArea2:(null==e?void 0:e.city)||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCode:(null==e?void 0:e.countryCode)||""}}mapPayPalToBcAddress(e,t,n,i){const[r,o]=t.fullName.split(" "),a=(null==n?void 0:n.nationalNumber)||"",s=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||r||"",lastName:t.lastName||o||"",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+a,customFields:i||[]}}filterAddresses(e){return e.reduce((e,t)=>t?e.some(e=>this.isEqualAddresses(e,t))?e:[...e,t]:e,[])}isEqualAddresses(e,t){return i(this.normalizeAddress(e),this.normalizeAddress(t))}normalizeAddress(e){return a(e,["id","phone"])}}function Oe(){return new we}!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification"}(be||(be={}));const ze=be;function Ae(e){return ze.CardNumber in e&&ze.CardName in e&&ze.CardExpiry in e}function Ee(e){return ze.CardNumberVerification in e&&ze.CardCodeVerification in e&&ze.CardExpiryVerification in e}class Te extends l{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 ke;!function(e){e[e.CheckoutButtonNotInitialized=0]="CheckoutButtonNotInitialized",e[e.CustomerNotInitialized=1]="CustomerNotInitialized",e[e.PaymentNotInitialized=2]="PaymentNotInitialized",e[e.ShippingNotInitialized=3]="ShippingNotInitialized",e[e.SpamProtectionNotInitialized=4]="SpamProtectionNotInitialized"}(ke||(ke={}));class Me extends l{constructor(e){super(function(e){switch(e){case ke.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case ke.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case ke.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case ke.SpamProtectionNotInitialized:return"Unable to proceed because the checkout spam protection has not been initialized.";default:return"Unable to proceed because the required component has not been initialized."}}(e)),this.subtype=e,this.name="NotInitializedError",this.type="not_initialized"}}class Ne extends l{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 Be=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Fe{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=i}initialize(e){return Be(this,void 0,void 0,function*(){const{methodId:t,paypalcommercecreditcards:n,paypalcommerce:i}=e,r=n||i,{form:o,onCreditCardFieldsRenderingError:a,onLoadComplete:s}=r||{};if(!t)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!o)throw new H('Unable to proceed because "options.paypalcommercecreditcards.form" argument is not provided.');this.hostedFormOptions=o,this.isCreditCardForm=Ae(o.fields),this.isCreditCardVaultedForm=Ee(o.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.paypalIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(o,a)),null==s||s(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Be(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{methodId:r,paymentData:o}=n||{};if(!n||!r)throw new $(["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 a=this.preparePaymentPayload(r,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(a)})}finalize(){return Promise.reject(new Y)}deinitialize(){return Be(this,void 0,void 0,function*(){var e,t,n,i;return yield null===(e=this.cvvField)||void 0===e?void 0:e.close(),yield null===(t=this.expiryField)||void 0===t?void 0:t.close(),yield null===(n=this.numberField)||void 0===n?void 0:n.close(),yield null===(i=this.nameField)||void 0===i?void 0:i.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,i){const{shouldSaveInstrument:o=!1,shouldSetAsDefaultInstrument:a=!1}=W(t)?t:{},d=t&&Z(t)?t.instrumentId:void 0,l=s({verification_nonce:i,token:d},r);return{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,instrumentId:d,formattedPayload:Object.assign(Object.assign({},i||d?{bigpay_token:l}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Be(this,void 0,void 0,function*(){const{fields:n,styles:i}=e,r=this.paypalIntegrationService.getPayPalSdkOrThrow(),o=this.getExecuteCallback(n),a=Object.assign({style:this.getInputStyles(i),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===ue.No||n===ue.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Te},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)}},o);if(this.cardFields=yield r.CardFields(a),!this.cardFields.isEligible())throw new Me(ke.PaymentNotInitialized);try{this.stylizeInputContainers(n),Ae(n)&&(yield this.renderFields(n)),Ee(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Ee(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Be(this,void 0,void 0,function*(){const{setupToken:e}=(yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",Object.assign(Object.assign({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Be(this,void 0,void 0,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 Be(this,void 0,void 0,function*(){var t,n,i,r;const o=this.getCardFieldsOrThrow();(null===(t=e.cardCode)||void 0===t?void 0:t.containerId)&&(this.cvvField=o.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null===(n=e.cardExpiry)||void 0===n?void 0:n.containerId)&&(this.expiryField=o.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null===(i=e.cardName)||void 0===i?void 0:i.containerId)&&(this.nameField=o.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null===(r=e.cardNumber)||void 0===r?void 0:r.containerId)&&(this.numberField=o.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return Be(this,void 0,void 0,function*(){var t,n,i;const r=this.getCardFieldsOrThrow();(null===(t=e.cardCodeVerification)||void 0===t?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null===(n=e.cardExpiryVerification)||void 0===n?void 0:n.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null===(i=e.cardNumberVerification)||void 0===i?void 0:i.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(W(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(Z(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return Be(this,void 0,void 0,function*(){const e=this.getCardFieldsOrThrow(),t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n={billingAddress:{company:t.company,addressLine1:t.address1,addressLine2:t.address2,adminArea1:t.stateOrProvinceCode,adminArea2:t.city,postalCode:t.postalCode,countryCode:t.countryCode}};try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){throw new Te("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Be(this,void 0,void 0,function*(){var e,t;const n=this.getCardFieldsOrThrow(),i=yield n.getState().then(e=>e),r=this.getValidityData(i);if(!r.isValid)throw null===(t=null===(e=this.hostedFormOptions)||void 0===e?void 0:e.onValidate)||void 0===t||t.call(e,r),new Ne(this.mapValidationErrors(r.errors))})}getValidityData({fields:e}){const t=Object.assign({},e);delete t.cardNameField;const n=Object.keys(t);return{isValid:n.every(e=>{var n;return null===(n=t[e])||void 0===n?void 0:n.isValid}),errors:n.reduce((e,n)=>{var i;const r=this.mapFieldType(n);return Object.assign(Object.assign({},e),{[r]:(null===(i=t[n])||void 0===i?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case ze.CardCode:case ze.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case ze.CardNumber:case ze.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case ze.CardExpiry:case ze.CardExpiryVerification:return{fieldType:e,message:"Invalid card expiry",type:"invalid_card_expiry"};default:return{fieldType:e,message:"Invalid field",type:"invalid"}}}mapValidationErrors(e={}){const t={};return Object.keys(e).forEach(n=>{var i,r;t[n]=[{message:(null===(r=null===(i=e[n])||void 0===i?void 0:i[0])||void 0===r?void 0:r.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return ze.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?ze.CardNumber:ze.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?ze.CardExpiry:ze.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?ze.CardCode:ze.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Me(ke.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,i;const r={"font-size":(null===(t=null==e?void 0:e.default)||void 0===t?void 0:t.fontSize)||"1rem","font-family":(null===(n=null==e?void 0:e.default)||void 0===n?void 0:n.fontFamily)||"Montserrat, Arial, Helvetica, sans-serif","font-weight":(null===(i=null==e?void 0:e.default)||void 0===i?void 0:i.fontWeight)||"400",outline:"none",padding:"9px 13px"},o=Object.assign(Object.assign({},r),{color:"#333333"});return{input:o,".invalid":Object.assign(Object.assign({},r),{color:"red"}),".valid":o,":focus":o}}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)||void 0===n||n.call(e,this.getValidityData(t))}onFocusHandler(e,t){var n;null===(n=null==e?void 0:e.onFocus)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onBlurHandler(e,t){var n;null===(n=null==e?void 0:e.onBlur)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onInputSubmitRequest(e,t){var n;null===(n=null==e?void 0:e.onEnter)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}shouldInitializePayPalFastlane(e){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(e),o=i.getPaymentProviderCustomer(),a=(s=o)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?o:{};var s;return(null===(t=null==r?void 0:r.initializationData)||void 0===t?void 0:t.isAcceleratedCheckoutEnabled)&&(null===(n=null==r?void 0:r.initializationData)||void 0===n?void 0:n.isPayPalCommerceAnalyticsV2Enabled)&&!(null==a?void 0:a.authenticationState)}initializePayPalFastlaneOrThrow(e){return Be(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{initializationData:r}=i;if(!(null==r?void 0:r.connectClientToken))return;const o=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(i,n.currency.code,n.id,t.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(o,!!(null==r?void 0:r.isDeveloperModeApplicable))}catch(e){}})}}const De=d(e=>new Fe(e,V(e),f(),Oe()),[{id:"paypalcommercecreditcards"}]);var xe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ue{constructor(e,t,n,i=3e3,r=3e5){this.paymentIntegrationService=e,this.paypalCommerceService=t,this.loadingIndicator=n,this.pollingInterval=i,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=o}initialize(e){return xe(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,paypalcommerceratepay:i}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new H('Unable to initialize payment because "options.paypalcommerceratepay" argument is not provided.');const{legalTextContainer:r,container:o,loadingContainerId:a}=i;if(!o)throw new H('Unable to initialize payment because "options.container" argument is not provided.');if(!r)throw new H('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!a)throw new H('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=a;const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:d}=s.initializationData||{};if(!d)throw new H("Unable to initialize payment because merchantId argument is not provided.");this.paypalcommerceratepay=i,yield this.paypalCommerceService.loadPayPalSdk(n),this.createFraudNetScript(d,n,t),this.loadFraudnetConfig(),this.renderLegalText(r,o)})}execute(e,t){return xe(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{getFieldsValues:r}=this.paypalcommerceratepay||{};if(!n)throw new $(["payment"]);if(!r||"function"!=typeof r)throw new H('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:o,ratepayPhoneNumber:a,ratepayPhoneCountryCode:s}=r(),d={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:n.methodId,rate_pay:{birth_date:this.normalizeDate(o),phone:{national_number:a,country_code:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:n.methodId,paymentData:d}),yield new Promise((e,t)=>{this.initializePollingMechanism(n.methodId,e,t,n.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new Y)}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,i=t.split("#")[1],r=document.getElementById(i),o=null==r?void 0:r.parentNode,a=document.createElement("div");a.style.marginBottom="20px",a.setAttribute("id",n),null==o||o.prepend(a);const s=this.paypalCommerceService.getPayPalSdkOrThrow(),d=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new H('Unable to initialize payment because "legalTextContainerElement" argument is not found.');d.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 i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:r}=i.config,o=document.createElement("script");o.setAttribute("type","application/json"),o.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),o.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const a={f:this.guid,s:`${e}_checkout-page`,sandbox:r};o.innerHTML=JSON.stringify(a),document.body.appendChild(o)}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 xe(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return xe(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.paypalCommerceService.getOrderStatus("paypalcommercealternativemethods",{params:{useMetadata:!0}}),o=r===M.PollingStop,a=r===M.PollingError;if(o)return this.deinitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,paypalcommerceratepay:this.paypalcommerceratepay}),this.handleError(new ce)}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()}}const je=d(e=>new Ue(e,V(e),new K({containerStyles:Object.assign(Object.assign({},h),{position:"fixed"})})),[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);var Le=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ve{constructor(e){this.requestSender=e}createOrder(e,t){return Le(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return Le(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:n,body:t})).body})}getOrderStatus(){return Le(this,arguments,void 0,function*(e="paypalcommerce",t){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}function Re(e){return"string"!=typeof e}function Ge(e,t){if(t||e)return function(e){var t,n;const i={},r=s(e.root,Re),o=s(e.input,Re),a=s(e.toggle,Re),d=s(null===(t=e.text)||void 0===t?void 0:t.body,Re),l=s(null===(n=e.text)||void 0===n?void 0:n.caption,Re),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(o).length&&(i.input=o),Object.keys(a).length&&(i.toggle=a),Object.keys(d).length&&(i.text={},i.text.body=d),Object.keys(l).length&&(i.text=Object.assign({},i.text),i.text.caption=l),c&&(i.branding=c),i}(function(e,t){var n,i,r,o,a,s,d,l,c,u,p,h,y,m,g,v,f,S,I,_,P,b;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null===(n=null==t?void 0:t.root)||void 0===n?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null===(i=null==t?void 0:t.root)||void 0===i?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null===(r=null==t?void 0:t.root)||void 0===r?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null===(o=null==t?void 0:t.root)||void 0===o?void 0:o.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null===(a=null==t?void 0:t.root)||void 0===a?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null===(s=null==t?void 0:t.root)||void 0===s?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null===(d=null==t?void 0:t.input)||void 0===d?void 0:d.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null===(l=null==t?void 0:t.input)||void 0===l?void 0:l.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null===(c=null==t?void 0:t.input)||void 0===c?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null===(u=null==t?void 0:t.input)||void 0===u?void 0:u.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null===(p=null==t?void 0:t.input)||void 0===p?void 0:p.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null===(h=null==t?void 0:t.input)||void 0===h?void 0:h.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null===(y=null==t?void 0:t.toggle)||void 0===y?void 0:y.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null===(m=null==t?void 0:t.toggle)||void 0===m?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?void 0:g.body)||void 0===v?void 0:v.color),fontSize:(null==e?void 0:e.fastlaneTextBodySettingsFontSize)||(null===(S=null===(f=null==t?void 0:t.text)||void 0===f?void 0:f.body)||void 0===S?void 0:S.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null===(_=null===(I=null==t?void 0:t.text)||void 0===I?void 0:I.caption)||void 0===_?void 0:_.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null===(b=null===(P=null==t?void 0:t.text)||void 0===P?void 0:P.caption)||void 0===b?void 0:b.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function Ke(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var He=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class $e{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=i}initialize(e){return He(this,void 0,void 0,function*(){var t,n;const{methodId:i,paypalcommercefastlane:r}=e;if(this.methodId=i,this.paypalcommercefastlane=r,!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new H('Unable to initialize payment because "options.paypalcommercefastlane" argument is not provided.');if(!r.onInit||"function"!=typeof r.onInit)throw new H('Unable to initialize payment because "options.paypalcommercefastlane.onInit" argument is not provided or it is not a function.');if(!r.onChange||"function"!=typeof r.onChange)throw new H('Unable to initialize payment because "options.paypalcommercefastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(i);const o=this.paymentIntegrationService.getState(),a=o.getCartOrThrow(),s=o.getPaymentMethodOrThrow(i),{isDeveloperModeApplicable:d,isFastlaneStylingEnabled:l}=s.initializationData||{};this.threeDSVerificationMethod=null===(t=s.initializationData)||void 0===t?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(s,a.currency.code,a.id,o.getLocale());const c=Ge(l?null===(n=null==s?void 0:s.initializationData)||void 0===n?void 0:n.fastlaneStyles:{},null==r?void 0:r.styles);yield this.paypalFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!d,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(i)),yield this.initializePayPalPaymentComponent(),r.onInit(e=>this.renderPayPalPaymentComponent(e)),r.onChange(()=>this.handlePayPalStoredInstrumentChange(i))})}execute(e,t){return He(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);const{paymentData:r,methodId:o}=n,a=r&&Z(r);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=a?yield this.prepareVaultedInstrumentPaymentPayload(o,r):yield this.preparePaymentPayload(o,r);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 Y)}deinitialize(){return He(this,void 0,void 0,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=Ke(i)?i:{},o=this.paypalFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===T.CANCELED||(null==r?void 0:r.authenticationState)||o!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return He(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(a),{authenticationState:d,addresses:l,instruments:c}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:d,addresses:l,instruments:c}),s.authenticationState===T.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n.id)}catch(e){}})}initializePayPalPaymentComponent(){return He(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),i=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),r={fields:Object.assign({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield i.FastlaneCardComponent(r)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new H('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 He(this,void 0,void 0,function*(){const{instrumentId:n}=t,i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).config.is3dsEnabled?yield this.get3DSNonce(n):n;return yield this.createOrder(i),{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:i}}}}})}preparePaymentPayload(e,t){return He(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getPaymentMethodOrThrow(e),o=`${i.firstName} ${i.lastName}`.trim(),{getPaymentToken:a}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield a({name:{fullName:o},billingAddress:this.paypalFastlaneUtils.mapBcToPayPalAddress(i)}),d=r.config.is3dsEnabled?yield this.get3DSNonce(s):s;yield this.createOrder(d);const{shouldSaveInstrument:l=!1,shouldSetAsDefaultInstrument:c=!1}=W(t)?t:{};return{methodId:e,paymentData:Object.assign(Object.assign({},t),{shouldSaveInstrument:l,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:d}}})}})}createOrder(e){return He(this,void 0,void 0,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 He(this,void 0,void 0,function*(){var t;const n=this.paymentIntegrationService.getState(),i=n.getCartOrThrow(),r=n.getOrderOrThrow(),o=n.getStoreConfigOrThrow().links.checkoutLink,a=null===(t=this.paypalFastlaneSdk)||void 0===t?void 0:t.ThreeDomainSecureClient;if(!a)throw new c;const s={amount:r.orderAmount.toFixed(2),currency:i.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===C.Always,transactionContext:{experience_context:{locale:"en-US",return_url:o,cancel_url:o}}},d=yield a.isEligible(s);if(this.threeDSVerificationMethod===C.Always&&!d)throw new q;if(d){const{liabilityShift:e,authenticationState:t,nonce:n}=yield a.show();if(e===ue.No||e===ue.Unknown||t===w.Errored||t===w.Cancelled)throw new q;if(t===w.Succeeded&&[ue.Yes,ue.Possible].includes(e))return n;throw new q}return e})}handlePayPalStoredInstrumentChange(e){return He(this,void 0,void 0,function*(){const t=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=Ke(t)?t:{},r=this.paypalFastlaneUtils.mapPayPalToBcInstrument(e,i)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Object.assign(Object.assign({},n),{instruments:[r]})),r}})}handleError(e){var t;(null===(t=this.paypalcommercefastlane)||void 0===t?void 0:t.onError)&&"function"==typeof this.paypalcommercefastlane.onError&&this.paypalcommercefastlane.onError(e)}}const qe=d(e=>{const{getHost:t}=e.getState();return new $e(e,new Ve(n({host:t()})),f(),Oe())},[{id:"paypalcommerceacceleratedcheckout"}]);var Ye=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};const We=class{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}createPayPalButton(e,t,n,i){const{style:r,fundingSource:o,isHostedCheckoutEnabled:a,isServerSideShippingCallbacksEnabled:s,onClick:d,onCancel:l,onPaymentComplete:c,onError:u}=n;this.onError=u;const p=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(p.FUNDING).includes(o))throw new H('Unable to initialize PayPal button because "fundingSource" argument is not valid funding source.');const h=Object.assign(Object.assign({},!s&&{onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e)}),{onApprove:(n,i)=>this.onHostedCheckoutApprove(n,i,t,e,c,s)});return p.Buttons(Object.assign(Object.assign(Object.assign({fundingSource:o,style:this.paypalIntegrationService.getValidButtonStyle(r),createOrder:()=>Ye(this,void 0,void 0,function*(){if(i){const e=yield this.paypalIntegrationService.createBuyNowCartOrThrow(i);yield this.paymentIntegrationService.loadCheckout(e.id)}return this.paypalIntegrationService.createOrder(e)}),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},d?{onClick:d}:{}),l?{onCancel:l}:{}),a&&h))}onHostedCheckoutApprove(e,t,n,i,r,o){return Ye(this,void 0,void 0,function*(){if(!e.orderID)throw new p(u.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow();try{const s=a.lineItems.physicalItems.length>0;if(!o){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(i,void 0,void 0,o)),o&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalIntegrationService.submitPayment(n,e.orderID),r&&"function"==typeof r&&r()}catch(e){this.handleError(e)}})}onShippingAddressChange(e,t){return Ye(this,void 0,void 0,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 Ye(this,void 0,void 0,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 Ze=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Je{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Ze(this,void 0,void 0,function*(){const{paypalcommerce:t,methodId:n}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(!t.container)throw new H('Unable to initialize payment because "options.paypalcommerce.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new H('Unable to initialize payment because "options.paypalcommerce.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.paypalIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i,onComplete:r,onError:o}=t,a=this.paypalIntegrationService.getPayPalSdkOrThrow(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:d,paymentButtonStyles:l,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},{checkoutTopButtonStyles:u}=l||{},p=Object.assign(Object.assign(Object.assign({fundingSource:a.FUNDING.PAYPAL,isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:d,style:Object.assign(Object.assign({},u),{height:40})},i&&{onClick:()=>i()}),d&&r&&{onPaymentComplete:()=>r()}),{onError:o}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,p);h.isEligible()?h.render(`#${n}`):this.paypalIntegrationService.removeElement(n)}}const Xe=d(e=>{const t=V(e),n=new We(e,t);return new Je(e,t,n)},[{id:"paypalcommerce"}]);var Qe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class et{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=i}loadPayPalSdk(e,t,n,i){return Qe(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,o,r.getLocale(),n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return Qe(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new p(u.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new S}})}createOrder(e,t){return Qe(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return Qe(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(e){return Qe(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:e?[]:i.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:i.selectedShippingOption})}catch(e){throw new _}})}getOrderStatus(e,t){return Qe(this,void 0,void 0,function*(){try{const{status:n}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new p(u.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===P.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return Qe(this,void 0,void 0,function*(){const i={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,n;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:o}=e||{},a={color:t&&ye[t]?t:void 0,height:this.getValidHeight(n),label:i&&he[i]?i:void 0,shape:o&&me[o]?o:void 0};return s(a,r)}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 tt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class nt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return tt(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);return this.loadPayPalSDK(o,r)})}loadPayPalSDK(e){return tt(this,arguments,void 0,function*(e,t=!1){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.paypal)throw new c;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:o,initializationData:a}=e;if(!(null==a?void 0:a.clientId))throw new p(u.MissingPaymentMethod);const{intent:s,clientId:d,merchantId:l,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:v,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:I=[],isGooglePayEnabled:_}=a,P=g||i,b="paypalcommercecreditcards"===r,C=b?["card"]:[],w=v?["credit","paylater"]:[],O=y?["venmo"]:[],z=_?["googlepay"]:[],A=i?["card-fields"]:[],E=[...b?[]:["card"],...v?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!I.includes(e))],T=[...C,...w,...O,...I],k=m(n);return{options:Object.assign(Object.assign({"client-id":d,"merchant-id":l,"enable-funding":T.length>0?T:void 0,"disable-funding":E.length>0?E:void 0,commit:P,components:["buttons","hosted-fields","payment-fields","legal",...z,...A],currency:t,intent:s},f&&{"buyer-country":c}),k&&{locale:k}),attributes:{"data-partner-attribution-id":h,"data-client-token":o}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const it=i=>{const{getHost:r}=i.getState();return new et(t(),i,new Ve(n({host:r()})),new nt(e()))};var rt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ot{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=o}initialize(e){return rt(this,void 0,void 0,function*(){const{paypalcommercecredit:t,methodId:n}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(!t.container)throw new H('Unable to initialize payment because "options.paypalcommercecredit.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new H('Unable to initialize payment because "options.paypalcommercecredit.onClick" argument is not a function.');this.onError=t.onError||o,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.paypalCommerceIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return rt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return rt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onComplete:i,onClick:r}=t,o=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:l}=a.initializationData||{},{checkoutTopButtonStyles:c}=d||{},u=Object.assign({createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()}),p=Object.assign(Object.assign({},!l&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,i,l)}),h=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let y=!1;h.forEach(e=>{if(!y){const t=Object.assign(Object.assign({fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},c),{height:40}))},u),s&&p),i=o.Buttons(t);i.isEligible()&&(i.render(`#${n}`),y=!0)}}),y||this.paypalCommerceIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i,r){return rt(this,void 0,void 0,function*(){if(!e.orderID)throw new p(u.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}a&&(yield this.paypalCommerceIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalCommerceIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return rt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}onShippingOptionsChange(e){return rt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const at=d(e=>new ot(e,it(e)),[{id:"paypalcommercecredit"}]);var st=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class dt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return st(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,methodId:n}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(!t.container)throw new H('Unable to initialize payment because "options.paypalcommercevenmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new H('Unable to initialize payment because "options.paypalcommercevenmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.paypalCommerceIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return st(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return st(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i}=t,r=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:a}=o.initializationData||{},{checkoutTopButtonStyles:s}=a||{},d=Object.assign({fundingSource:r.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},s),{height:40})),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),l=r.Buttons(d);l.isEligible()?l.render(`#${n}`):this.paypalCommerceIntegrationService.removeElement(n)}}const lt=d(e=>new dt(e,it(e)),[{id:"paypalcommercevenmo"}]);var ct=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ut{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=n}initialize(e){return ct(this,void 0,void 0,function*(){var t;const{methodId:n,paypalcommercefastlane:i}=e;if(!n)throw new H('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),r=e.getCartOrThrow(),o=e.getPaymentMethodOrThrow(n),a=!!(null===(t=o.initializationData)||void 0===t?void 0:t.isDeveloperModeApplicable),s=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(o,r.currency.code,r.id,e.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(s,a,this.getFastlaneStyles(n,i))}catch(e){}return Promise.resolve()})}deinitialize(){return ct(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return ct(this,void 0,void 0,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 ct(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return ct(this,void 0,void 0,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:i}=e||{};if(!i)throw new H('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new H('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');if(this.paymentIntegrationService.getState().getCustomerOrThrow().isGuest){t&&"function"==typeof t&&t();try{yield this.runPayPalAuthenticationFlowOrThrow(i)}catch(e){}}n()})}runPayPalAuthenticationFlowOrThrow(e){return ct(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(a),d=s.authenticationState===T.CANCELED;yield this.updateCustomerDataState(e,s),d?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return ct(this,void 0,void 0,function*(){var n;const i=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:r,addresses:o,billingAddress:a,shippingAddress:s,instruments:d}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:r,addresses:o,instruments:d}),a&&(yield this.paymentIntegrationService.updateBillingAddress(a)),s&&i.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),i=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:r}=i.initializationData||{},o=(null===(n=(t.getConsignments()||[])[0])||void 0===n?void 0:n.availableShippingOptions)||[],a=o[0],d=o.find(e=>e.isRecommended);if((d||a)&&r){const e=(null==d?void 0:d.id)||a.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:i,isFastlaneStylingEnabled:r}=n.initializationData||{};return Ge(r?i:{},null==t?void 0:t.styles)}}const pt=d(e=>new ut(e,f(),Oe()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);class ht{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return t=this,n=void 0,r=function*(){var t;const{paypalcommerce:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new H('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(o&&!n.currencyCode)throw new H('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new H('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n)},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c}=d.initializationData||{},u={onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},p=Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(r),isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:l},i&&u),l&&o&&{onPaymentComplete:()=>o()}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,p,i);h.isEligible()?h.render(`#${e}`):a&&"function"==typeof a?a():this.paypalIntegrationService.removeElement(e)}}const yt=d(e=>{const t=V(e),n=new We(e,t);return new ht(e,t,n)},[{id:"paypalcommerce"}]);var mt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class gt{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}initialize(e){return mt(this,void 0,void 0,function*(){const{paypalcommercecredit:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new H('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(a&&!o)throw new H('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new H('Unable to initialize payment because "options.paypalcommercecredit.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=this.paymentIntegrationService.getState(),d=a?o:s.getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c}=d.initializationData||{},u={createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},p={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h=Object.assign(Object.assign({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o,c)}),y=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let m=!1;y.forEach(t=>{if(!m){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalIntegrationService.getValidButtonStyle(r)},u),i&&p),l&&h),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),m=!0):a&&"function"==typeof a&&a()}}),m||this.paypalIntegrationService.removeElement(e)}handleClick(e){return mt(this,void 0,void 0,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i,r){return mt(this,void 0,void 0,function*(){if(!e.orderID)throw new p(u.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.paypalIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.paypalIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}return a&&(yield this.paypalIntegrationService.updateOrder("paypalcommerce",void 0,void 0,r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return mt(this,void 0,void 0,function*(){const t=this.paypalIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalIntegrationService.updateOrder("paypalcommerce")}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return mt(this,void 0,void 0,function*(){const t=this.paypalIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalIntegrationService.updateOrder("paypalcommerce")}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}}const vt=d(e=>new gt(e,V(e)),[{id:"paypalcommercecredit"}]);var ft=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class St{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return ft(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new H('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(a&&!o)throw new H('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new H('Unable to initialize payment because "options.paypalcommercevenmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,a=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&l),u=a.Buttons(c);u.isEligible()?u.render(`#${e}`):o&&"function"==typeof o?o():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===ye.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return ft(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const It=d(e=>new St(e,it(e)),[{id:"paypalcommercevenmo"}]);class _t{constructor(e){this.walletButtonIntegrationService=e}getWalletButtonIntegrationService(){return this.walletButtonIntegrationService}initialize(e){return t=this,n=void 0,r=function*(){return Promise.resolve()},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}deinitialize(){return Promise.resolve()}}const Pt=d(e=>new _t(e),[{id:"paypalcommercepaypal"}]);export{Ie as createPayPalCommerceAlternativeMethodsPaymentStrategy,yt as createPayPalCommerceButtonStrategy,vt as createPayPalCommerceCreditButtonStrategy,De as createPayPalCommerceCreditCardsPaymentStrategy,at as createPayPalCommerceCreditCustomerStrategy,oe as createPayPalCommerceCreditPaymentStrategy,Xe as createPayPalCommerceCustomerStrategy,pt as createPayPalCommerceFastlaneCustomerStrategy,qe as createPayPalCommerceFastlanePaymentStrategy,te as createPayPalCommercePaymentStrategy,je as createPayPalCommerceRatePayPaymentStrategy,It as createPayPalCommerceVenmoButtonStrategy,lt as createPayPalCommerceVenmoCustomerStrategy,de as createPayPalCommerceVenmoPaymentStrategy,Pt 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 i,isNil as r,noop as o,omit as a,omitBy as s}from"lodash";function d(e,t){return Object.assign(e,{resolveIds:t})}class l 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 l{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 u;!function(e){e[e.MissingBillingAddress=0]="MissingBillingAddress",e[e.MissingCart=1]="MissingCart",e[e.MissingCheckout=2]="MissingCheckout",e[e.MissingConsignments=3]="MissingConsignments",e[e.MissingCustomer=4]="MissingCustomer",e[e.MissingCheckoutConfig=5]="MissingCheckoutConfig",e[e.MissingOrder=6]="MissingOrder",e[e.MissingOrderConfig=7]="MissingOrderConfig",e[e.MissingOrderId=8]="MissingOrderId",e[e.MissingPayment=9]="MissingPayment",e[e.MissingPaymentId=10]="MissingPaymentId",e[e.MissingPaymentInstrument=11]="MissingPaymentInstrument",e[e.MissingPaymentMethod=12]="MissingPaymentMethod",e[e.MissingPaymentRedirectUrl=13]="MissingPaymentRedirectUrl",e[e.MissingPaymentStatus=14]="MissingPaymentStatus",e[e.MissingPaymentToken=15]="MissingPaymentToken",e[e.MissingShippingAddress=16]="MissingShippingAddress"}(u||(u={}));class p extends l{constructor(e){super(function(e){switch(e){case u.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case u.MissingCart:return"Unable to proceed because cart data is unavailable.";case u.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case u.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case u.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case u.MissingCheckoutConfig:case u.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case u.MissingOrder:return"Unable to proceed because order data is unavailable.";case u.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case u.MissingPayment:return"Unable to proceed because payment data is unavailable.";case u.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case u.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case u.MissingShippingAddress:return"Unable to proceed because shipping address data is unavailable.";default:return"Unable to proceed because the required data is unavailable."}}(e)),this.subtype=e,this.name="MissingDataError",this.type="missing_data"}}const h={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},y=["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 m(e){if(!e)return;let t;if(e.includes("-")){const[n,i]=e.split("-");t=`${n}_${i.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return y.includes(t)?t:void 0}var g=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class v{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return g(this,void 0,void 0,function*(){if(!this.window.paypal||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypal)throw new c}return this.window.paypal})}getPayPalFastlaneSdk(e,t,n,i){return g(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const r=this.getPayPalFastlaneSdkConfiguration(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i,r){return g(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||r){const r=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return g(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return g(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}loadPayPalSdk(e){return g(this,arguments,void 0,function*({options:e,attributes:t}){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:o,initializationData:a}=e;if(!a||!a.clientId)throw new p(u.MissingPaymentMethod);const{intent:s,clientId:d,merchantId:l,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:v,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:I=[],isGooglePayEnabled:_}=a,P=g||i,b="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,C=b?["card"]:[],w=v?["credit","paylater"]:[],O=y?["venmo"]:[],z=_?["googlepay"]:[],A=i?["card-fields"]:[],E=[...b?[]:["card"],...v?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!I.includes(e))],T=[...C,...w,...O,...I],k=m(n);return{options:Object.assign(Object.assign({"client-id":d,"merchant-id":l,"enable-funding":T.length>0?T:void 0,"disable-funding":E.length>0?E:void 0,commit:P,components:["buttons","hosted-fields","payment-fields","legal",...z,...A],currency:t,intent:s},f&&{"buyer-country":c}),k&&{locale:k}),attributes:{"data-partner-attribution-id":h,"data-client-token":o}}}getPayPalFastlaneSdkConfiguration(e,t,n,i){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new p(u.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,attributionId:l}=o,c=m(i);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:a}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":l,"data-sdk-client-token":r}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i=!0){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new p(u.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:l,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:y}=o,g=h||i,v=m(n);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:g,components:["googlepay"],currency:t,intent:a},y&&{"buyer-country":l}),v&&{locale:v}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new p(u.MissingPaymentMethod);const{intent:r,clientId:o,merchantId:a,buyerCountry:s,attributionId:d,isDeveloperModeApplicable:l,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=i,y=h,g=c.filter(e=>!h.includes(e)),v=m(n);return{options:Object.assign(Object.assign({"client-id":o,"merchant-id":a,"enable-funding":y.length>0?y:void 0,"disable-funding":g.length>0?g:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:r},l&&{"buyer-country":s}),v&&{locale:v}),attributes:{"data-partner-attribution-id":d,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new p(u.MissingPaymentMethod);const{clientId:r,merchantId:o,attributionId:a,isDeveloperModeApplicable:s,buyerCountry:d}=i,l=m(n);return{options:Object.assign(Object.assign({"client-id":r,"merchant-id":o,components:["messages"],currency:t},s&&{"buyer-country":d}),l&&{locale:l}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function f(){return new v(e())}class S extends l{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 I={body:{},headers:{},status:0};class _ extends l{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:o}=e||I;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}var P,b,C,w,O,z,A,E,T,k,M;!function(e){e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE"}(P||(P={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(b||(b={})),function(e){e.Always="SCA_ALWAYS"}(C||(C={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(w||(w={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(O||(O={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(z||(z={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(A||(A={})),function(e){e.pill="pill",e.rect="rect"}(E||(E={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(T||(T={})),function(e){e.OXXO="oxxo"}(k||(k={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(M||(M={}));var N=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class B{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=n,this.paypalSdkLoader=i}loadPayPalSdk(e,t,n,i){return N(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e),s=r.getLocale();return this.paypalSdk=yield this.paypalSdkLoader.getPayPalSDK(a,o,s,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return N(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new p(u.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new S}})}createOrder(e,t){return N(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return N(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(e,t,n,i){return N(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow();let a;i||(a=r.getConsignmentsOrThrow()[0]);try{yield this.paypalRequestSender.updateOrder(e,Object.assign(Object.assign({availableShippingOptions:i?[]:null==a?void 0:a.availableShippingOptions,cartId:o.id,selectedShippingOption:i?null:null==a?void 0:a.selectedShippingOption},t?{methodId:t}:{}),n?{orderId:n}:{}))}catch(e){throw new _}})}getOrderStatus(e,t){return N(this,void 0,void 0,function*(){try{const{status:n}=yield this.paypalRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new p(u.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===P.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return N(this,void 0,void 0,function*(){const i={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{if(t.selectedShippingOption){const n=t.selectedShippingOption.id;return e.id===n}return!1}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,n;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e={}){const{color:t,height:n,label:i,shape:o}=e,a={color:t&&A[t]?t:void 0,height:this.getValidHeight(n),label:i&&z[i]?i:void 0,shape:o&&E[o]?o:void 0};return s(a,r)}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 F="This API endpoint is for internal use only and may change in the future";var D;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(D||(D={}));const x=D,U={"X-Checkout-SDK-Version":"1.928.0"};var j=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class L{constructor(e){this.requestSender=e}createOrder(e,t){return j(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e,t){return j(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.put(n,{headers:r,body:i})).body})}getOrderStatus(e,t){return j(this,void 0,void 0,function*(){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}const V=e=>{const{getHost:i}=e.getState();return new B(t(),e,new L(n({host:i()})),f())},R={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},G="embedded-checkout-loading-indicator-rotation";class K{constructor(e){this.styles=Object.assign(Object.assign({},R),e&&e.styles),this.containerStyles=Object.assign({},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=`${G} 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(G))return;const t=document.createElement("style");t.id=G,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${G} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}class H extends l{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class $ extends H{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 q extends _{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 Y extends l{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function W(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function Z(e){return Boolean(e.instrumentId)}const J=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 X(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 Q=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ee{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.payPalSdkScriptLoader=n,this.loadingIndicator=i}initialize(e){return Q(this,void 0,void 0,function*(){var t;const{methodId:n,paypalcommerce:i}=e||{};if(this.paypalcommerce=i,!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(n),{container:a,bannerContainerId:s}=i,{orderId:d,paypalBNPLConfiguration:l=[],isPayPalCreditAvailable:c}=o.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==l?void 0:l.find(({id:e})=>"checkout"===e);if(c||!(null==e?void 0:e.status))return;const t=yield this.payPalSdkScriptLoader.getPayPalMessages(o,r.getCartOrThrow().currency.code,r.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")}d?this.orderId=null===(t=o.initializationData)||void 0===t?void 0:t.orderId:(this.loadingIndicatorContainer=null==a?void 0:a.split("#")[1],yield this.paypalIntegrationService.loadPayPalSdk(n),i.onInit&&"function"==typeof i.onInit&&i.onInit(()=>this.renderButton(n,i)),(void 0===i.shouldRenderPayPalButtonOnInitialization||i.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(n,i))})}execute(e,t){return Q(this,void 0,void 0,function*(){var n,i;const{payment:r}=e,o=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{onError:a}=this.paypalcommerce||{};if(!r)throw new $(["payment"]);const{methodId:s,paymentData:d}=r;if(this.isPayPalVaultedInstrumentPaymentData(d)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new q;const l=this.isPayPalVaultedInstrumentPaymentData(d)?this.prepareVaultedInstrumentPaymentPayload(s,this.orderId,d):this.preparePaymentPayload(s,this.orderId,d);try{yield this.paymentIntegrationService.submitOrder(o,t),yield this.paymentIntegrationService.submitPayment(l)}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?void 0:t.type)}(e)){const t=null===(i=null===(n=e.body.additional_action_required)||void 0===n?void 0:n.data)||void 0===i?void 0:i.redirect_url;return new Promise(()=>window.location.replace(t))}return this.isProviderError(e)&&(yield this.paypalIntegrationService.loadPayPalSdk(r.methodId),yield new Promise((e,t)=>{var n;this.paypalcommerce&&(null===(n=this.paypalButton)||void 0===n||n.close(),this.renderButton(r.methodId,this.paypalcommerce),this.handleError(new Error("INSTRUMENT_DECLINED"),a)),t()})),this.handleError(e,a),Promise.reject()}})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:i,shouldSetAsDefaultInstrument:r}=n,o=!this.isTrustedVaultingFlow(n);return o?{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:i}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:i=!1,shouldSetAsDefaultInstrument:r=!1}=W(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t;if(!a)throw new H('Unable to initialize payment because "container" argument is not provided.');const u=this.getSmartButtonContainerId(a);if(!document.getElementById(u))throw new H(`Unable to initialize payment because element with id ${u} does not exist.`);const p={fundingSource:n.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onError:e=>this.handleError(e,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(p),this.paypalButton.isEligible()&&(d&&"function"==typeof d&&d(),this.paypalButton.render(a))}handleClick(e,t){return Q(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;return null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return Q(this,void 0,void 0,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&&Z(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>X(t)&&t.bigpayToken===e.instrumentId);return!(X(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&Z(e)&&W(e)}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:J(n)};e.Messages(i).render(`#${t}`)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null===(i=null===(n=((null===(t=null==e?void 0:e.errors)||void 0===t?void 0:t.filter(e=>e.provider_error))||[])[0])||void 0===n?void 0:n.provider_error)||void 0===i?void 0:i.code)}getSmartButtonContainerId(e){var t;return null!==(t=e.split("#")[1])&&void 0!==t?t:e}}const te=d(t=>new ee(t,V(t),new v(e()),new K({containerStyles:h})),[{id:"paypalcommerce"}]);class ne extends l{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var ie=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class re{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n,this.payPalSdkScriptLoader=i}initialize(e){return ie(this,void 0,void 0,function*(){const{methodId:t,paypalcommerce:n,paypalcommercecredit:i}=e||{},r=i||n;if(!t)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const o=this.paymentIntegrationService.getState(),a=o.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:s=[],orderId:d}=a.initializationData||{},{bannerContainerId:l,container:c}=r;if(void 0!==l){if(!document.getElementById(l))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(a,o.getCartOrThrow().currency.code,o.getLocale());return this.renderMessages(t,l,e)}d?this.orderId=d:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,r))})}execute(e,t){return ie(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);if(!this.orderId)throw new q;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new H('Unable to initialize payment because "container" argument is not provided.');const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,u=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let p=!1;u.forEach(e=>{if(p)return;const t={fundingSource:e,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,l),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 ne(`PayPal ${e} is not available for your region. Please use PayPal Checkout instead.`);d&&"function"==typeof d&&d(),this.paypalButton.render(a),p=!0}})}handleClick(e,t){return ie(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;if(t&&"function"==typeof t)return t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:J(n)};e.Messages(i).render(`#${t}`)}}const oe=d(e=>new re(e,V(e),new K({containerStyles:h}),f()),[{id:"paypalcommercecredit"}]);var ae=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class se{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=n}initialize(e){return ae(this,void 0,void 0,function*(){var t,n;const{methodId:i,paypalcommerce:r,paypalcommercevenmo:o}=e||{},a=o||r;if(!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!a)throw new H('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i);(null===(t=s.initializationData)||void 0===t?void 0:t.orderId)?this.orderId=null===(n=s.initializationData)||void 0===n?void 0:n.orderId:(yield this.paypalIntegrationService.loadPayPalSdk(i),this.loadingIndicatorContainer=a.container.split("#")[1],this.renderButton(i,a))})}execute(e,t){return ae(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);if(!this.orderId)throw new q;yield this.paymentIntegrationService.submitOrder(i,t),yield this.paypalIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){const n=this.paypalIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,u={fundingSource:n.FUNDING.VENMO,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercevenmocheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=n.Buttons(u),!this.paypalButton.isEligible())throw new ne("PayPal Venmo is not available for your region. Please use PayPal Checkout instead.");d&&"function"==typeof d&&d(),this.paypalButton.render(a)}handleClick(e,t){return ae(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;return t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t(),this.toggleLoadingIndicator(!1)}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const de=d(e=>new se(e,V(e),new K({containerStyles:h,styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]),le={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class ce extends _{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var ue,pe,he,ye,me,ge,ve;!function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ue||(ue={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(pe||(pe={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(he||(he={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ye||(ye={})),function(e){e.pill="pill",e.rect="rect"}(me||(me={})),function(e){e.OXXO="oxxo",e.IDEAL="ideal"}(ge||(ge={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(ve||(ve={}));var fe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Se{constructor(e,t,n,i,r=3e3,a=3e5){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalSdkScriptLoader=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=a,this.pollingTimer=0,this.stopPolling=o,this.isOrderApprovedProcessing=!1}initialize(e){return fe(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,paypalcommerce:i,paypalcommercealternativemethods:r}=e,o=r||i;if(this.paypalcommercealternativemethods=r,!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!o)throw new H('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');const a=this.paymentIntegrationService.getState(),s=a.getPaymentMethodOrThrow(n,t),{orderId:d,shouldRenderFields:l}=s.initializationData||{},c=a.getStoreConfigOrThrow().checkoutSettings.features;this.isOrderApprovedProcessing=function(e,t,n=!0){var i;return null!==(i=e["PAYPAL-5431.order_approved_processing"])&&void 0!==i?i:n}(c,0,!1),d?this.orderId=d:(this.paypalApms=yield this.paypalSdkScriptLoader.getPayPalApmsSdk(s,a.getCartOrThrow().currency.code,a.getLocale()),this.loadingIndicatorContainer=o.container.split("#")[1],this.renderButton(n,t,o),l&&this.renderFields(n,o))})}execute(e,t){return fe(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);const{methodId:r,gatewayId:o}=n;if(!this.orderId)throw new q;this.isOrderApprovedProcessing||"ideal"!==r||(yield new Promise((e,t)=>{this.initializePollingMechanism(r,e,t,o)})),this.isNonInstantPaymentMethod(r)&&(r!==ge.IDEAL||this.isOrderApprovedProcessing)||(yield this.paymentIntegrationService.submitOrder(i,t)),yield this.paypalCommerceIntegrationService.submitPayment(r,this.orderId,o)})}finalize(){return Promise.reject(new Y)}deinitialize(){var e;return this.orderId=void 0,this.isOrderApprovedProcessing||this.resetPollingMechanism(),null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,i){return fe(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.paypalCommerceIntegrationService.getOrderStatus(null!=i?i:"paypalcommerce"),o=r===ve.Approved,a=r===ve.PollingError;if(o)return this.deinitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,paypalcommercealternativemethods:this.paypalcommercealternativemethods}),this.handleError(new ce)}catch(e){n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return fe(this,void 0,void 0,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 i=this.getPaypalAmpsSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:o}=r.initializationData||{},{container:a,onError:s,onRenderButton:d,submitForm:l}=n,c={fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o),onInit:(e,t)=>n.onInitButton(t),createOrder:()=>this.onCreateOrder(e,t,n),onApprove:e=>this.handleApprove(e,l),onCancel:()=>{this.toggleLoadingIndicator(!1),this.deinitializePollingMechanism()},onError:e=>{this.deinitializePollingMechanism(),this.handleFailure(e,s)},onClick:(e,t)=>fe(this,void 0,void 0,function*(){return n.onValidate(t.resolve,t.reject)})};this.paypalButton=i.Buttons(c),this.paypalButton.isEligible()&&(d&&"function"==typeof d&&d(),this.paypalButton.render(a))}onCreateOrder(e,t,n){return fe(this,void 0,void 0,function*(){var i;const{onValidate:r}=n;yield r(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),o);const a=yield this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethodscheckout");if(this.isNonInstantPaymentMethod(e)&&(e===ge.IDEAL&&this.isOrderApprovedProcessing||e===ge.OXXO)){const n={useStoreCredit:!1},r={params:{methodId:e,gatewayId:t}};if(yield this.paymentIntegrationService.submitOrder(n,r),e===ge.IDEAL){const t=null===(i=this.paymentIntegrationService.getState().getOrder())||void 0===i?void 0:i.orderId;yield this.paypalCommerceIntegrationService.updateOrder("paypalcommercealternativemethods",e,t)}yield this.paypalCommerceIntegrationService.submitPayment(e,a,t)}return a})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const n=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState(),{firstName:r,lastName:o,email:a}=i.getBillingAddressOrThrow(),{apmFieldsContainer:s,apmFieldsStyles:d}=t;if(!s)throw new H('Unable to initialize payment because "options.paypalcommercealternativemethods" argument should contain "apmFieldsContainer".');const l=document.querySelector(s);l&&(l.innerHTML="");const c={fundingSource:e,style:d||{},fields:{name:{value:`${r} ${o}`},email:{value:a}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in ge}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const Ie=d(e=>new Se(e,V(e),f(),new K({containerStyles:le})),[{gateway:"paypalcommercealternativemethods"}]);var _e;!function(e){e.CVV="cvv",e.PAN="pan"}(_e||(_e={}));class Pe{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:o,domain:a,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}o&&(i+=`; path=${o}`),a&&(i+=`; domain=${a}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){Pe.set(e,"",Object.assign({expires:new Date(0)},t))}}var be,Ce=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class we{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return Ce(this,void 0,void 0,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 Ce(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return Ce(this,void 0,void 0,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};Pe.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){Pe.remove("bc-fastlane-sessionId")}getStorageSessionId(){return Pe.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,i,r;const{authenticationState:o,profileData:a}=t,s=null===(r=null===(i=null===(n=null==a?void 0:a.card)||void 0===n?void 0:n.paymentSource)||void 0===i?void 0:i.card)||void 0===r?void 0:r.billingAddress,d=null==a?void 0:a.shippingAddress,l=null==a?void 0:a.name,c=null==a?void 0:a.card,u=d?this.mapPayPalToBcAddress(d.address,d.name,d.phoneNumber):void 0,p=s&&l?this.mapPayPalToBcAddress(s,l,null==d?void 0:d.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([u,p]);return{authenticationState:o||T.UNRECOGNIZED,addresses:y,billingAddress:p,shippingAddress:u,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:i}=t,{brand:r,expiry:o,lastDigits:a}=i.card,[s,d]=o.split("-");return[{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:d,expiryYear:s,iin:"",last4:a,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:_e.PAN,type:"card"}]}mapBcToPayPalAddress(e){return{company:(null==e?void 0:e.company)||"",addressLine1:(null==e?void 0:e.address1)||"",addressLine2:(null==e?void 0:e.address2)||"",adminArea1:(null==e?void 0:e.stateOrProvinceCode)||(null==e?void 0:e.stateOrProvince)||"",adminArea2:(null==e?void 0:e.city)||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCode:(null==e?void 0:e.countryCode)||""}}mapPayPalToBcAddress(e,t,n,i){const[r,o]=t.fullName.split(" "),a=(null==n?void 0:n.nationalNumber)||"",s=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||r||"",lastName:t.lastName||o||"",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+a,customFields:i||[]}}filterAddresses(e){return e.reduce((e,t)=>t?e.some(e=>this.isEqualAddresses(e,t))?e:[...e,t]:e,[])}isEqualAddresses(e,t){return i(this.normalizeAddress(e),this.normalizeAddress(t))}normalizeAddress(e){return a(e,["id","phone"])}}function Oe(){return new we}!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification"}(be||(be={}));const ze=be;function Ae(e){return ze.CardNumber in e&&ze.CardName in e&&ze.CardExpiry in e}function Ee(e){return ze.CardNumberVerification in e&&ze.CardCodeVerification in e&&ze.CardExpiryVerification in e}class Te extends l{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 ke;!function(e){e[e.CheckoutButtonNotInitialized=0]="CheckoutButtonNotInitialized",e[e.CustomerNotInitialized=1]="CustomerNotInitialized",e[e.PaymentNotInitialized=2]="PaymentNotInitialized",e[e.ShippingNotInitialized=3]="ShippingNotInitialized",e[e.SpamProtectionNotInitialized=4]="SpamProtectionNotInitialized"}(ke||(ke={}));class Me extends l{constructor(e){super(function(e){switch(e){case ke.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case ke.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case ke.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case ke.SpamProtectionNotInitialized:return"Unable to proceed because the checkout spam protection has not been initialized.";default:return"Unable to proceed because the required component has not been initialized."}}(e)),this.subtype=e,this.name="NotInitializedError",this.type="not_initialized"}}class Ne extends l{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 Be=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Fe{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=i}initialize(e){return Be(this,void 0,void 0,function*(){const{methodId:t,paypalcommercecreditcards:n,paypalcommerce:i}=e,r=n||i,{form:o,onCreditCardFieldsRenderingError:a,onLoadComplete:s}=r||{};if(!t)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!o)throw new H('Unable to proceed because "options.paypalcommercecreditcards.form" argument is not provided.');this.hostedFormOptions=o,this.isCreditCardForm=Ae(o.fields),this.isCreditCardVaultedForm=Ee(o.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.paypalIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(o,a)),null==s||s(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Be(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{methodId:r,paymentData:o}=n||{};if(!n||!r)throw new $(["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 a=this.preparePaymentPayload(r,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(a)})}finalize(){return Promise.reject(new Y)}deinitialize(){return Be(this,void 0,void 0,function*(){var e,t,n,i;return yield null===(e=this.cvvField)||void 0===e?void 0:e.close(),yield null===(t=this.expiryField)||void 0===t?void 0:t.close(),yield null===(n=this.numberField)||void 0===n?void 0:n.close(),yield null===(i=this.nameField)||void 0===i?void 0:i.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,i){const{shouldSaveInstrument:o=!1,shouldSetAsDefaultInstrument:a=!1}=W(t)?t:{},d=t&&Z(t)?t.instrumentId:void 0,l=s({verification_nonce:i,token:d},r);return{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,instrumentId:d,formattedPayload:Object.assign(Object.assign({},i||d?{bigpay_token:l}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Be(this,void 0,void 0,function*(){const{fields:n,styles:i}=e,r=this.paypalIntegrationService.getPayPalSdkOrThrow(),o=this.getExecuteCallback(n),a=Object.assign({style:this.getInputStyles(i),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===ue.No||n===ue.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Te},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)}},o);if(this.cardFields=yield r.CardFields(a),!this.cardFields.isEligible())throw new Me(ke.PaymentNotInitialized);try{this.stylizeInputContainers(n),Ae(n)&&(yield this.renderFields(n)),Ee(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Ee(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Be(this,void 0,void 0,function*(){const{setupToken:e}=(yield this.paypalIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",Object.assign(Object.assign({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Be(this,void 0,void 0,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 Be(this,void 0,void 0,function*(){var t,n,i,r;const o=this.getCardFieldsOrThrow();(null===(t=e.cardCode)||void 0===t?void 0:t.containerId)&&(this.cvvField=o.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null===(n=e.cardExpiry)||void 0===n?void 0:n.containerId)&&(this.expiryField=o.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null===(i=e.cardName)||void 0===i?void 0:i.containerId)&&(this.nameField=o.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null===(r=e.cardNumber)||void 0===r?void 0:r.containerId)&&(this.numberField=o.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return Be(this,void 0,void 0,function*(){var t,n,i;const r=this.getCardFieldsOrThrow();(null===(t=e.cardCodeVerification)||void 0===t?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null===(n=e.cardExpiryVerification)||void 0===n?void 0:n.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null===(i=e.cardNumberVerification)||void 0===i?void 0:i.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(W(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(Z(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return Be(this,void 0,void 0,function*(){const e=this.getCardFieldsOrThrow(),t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n={billingAddress:{company:t.company,addressLine1:t.address1,addressLine2:t.address2,adminArea1:t.stateOrProvinceCode,adminArea2:t.city,postalCode:t.postalCode,countryCode:t.countryCode}};try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){throw new Te("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Be(this,void 0,void 0,function*(){var e,t;const n=this.getCardFieldsOrThrow(),i=yield n.getState().then(e=>e),r=this.getValidityData(i);if(!r.isValid)throw null===(t=null===(e=this.hostedFormOptions)||void 0===e?void 0:e.onValidate)||void 0===t||t.call(e,r),new Ne(this.mapValidationErrors(r.errors))})}getValidityData({fields:e}){const t=Object.assign({},e);delete t.cardNameField;const n=Object.keys(t);return{isValid:n.every(e=>{var n;return null===(n=t[e])||void 0===n?void 0:n.isValid}),errors:n.reduce((e,n)=>{var i;const r=this.mapFieldType(n);return Object.assign(Object.assign({},e),{[r]:(null===(i=t[n])||void 0===i?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case ze.CardCode:case ze.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case ze.CardNumber:case ze.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case ze.CardExpiry:case ze.CardExpiryVerification:return{fieldType:e,message:"Invalid card expiry",type:"invalid_card_expiry"};default:return{fieldType:e,message:"Invalid field",type:"invalid"}}}mapValidationErrors(e={}){const t={};return Object.keys(e).forEach(n=>{var i,r;t[n]=[{message:(null===(r=null===(i=e[n])||void 0===i?void 0:i[0])||void 0===r?void 0:r.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return ze.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?ze.CardNumber:ze.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?ze.CardExpiry:ze.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?ze.CardCode:ze.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Me(ke.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,i;const r={"font-size":(null===(t=null==e?void 0:e.default)||void 0===t?void 0:t.fontSize)||"1rem","font-family":(null===(n=null==e?void 0:e.default)||void 0===n?void 0:n.fontFamily)||"Montserrat, Arial, Helvetica, sans-serif","font-weight":(null===(i=null==e?void 0:e.default)||void 0===i?void 0:i.fontWeight)||"400",outline:"none",padding:"9px 13px"},o=Object.assign(Object.assign({},r),{color:"#333333"});return{input:o,".invalid":Object.assign(Object.assign({},r),{color:"red"}),".valid":o,":focus":o}}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)||void 0===n||n.call(e,this.getValidityData(t))}onFocusHandler(e,t){var n;null===(n=null==e?void 0:e.onFocus)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onBlurHandler(e,t){var n;null===(n=null==e?void 0:e.onBlur)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onInputSubmitRequest(e,t){var n;null===(n=null==e?void 0:e.onEnter)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}shouldInitializePayPalFastlane(e){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(e),o=i.getPaymentProviderCustomer(),a=(s=o)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?o:{};var s;return(null===(t=null==r?void 0:r.initializationData)||void 0===t?void 0:t.isAcceleratedCheckoutEnabled)&&(null===(n=null==r?void 0:r.initializationData)||void 0===n?void 0:n.isPayPalCommerceAnalyticsV2Enabled)&&!(null==a?void 0:a.authenticationState)}initializePayPalFastlaneOrThrow(e){return Be(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{initializationData:r}=i;if(!(null==r?void 0:r.connectClientToken))return;const o=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(i,n.currency.code,n.id,t.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(o,!!(null==r?void 0:r.isDeveloperModeApplicable))}catch(e){}})}}const De=d(e=>new Fe(e,V(e),f(),Oe()),[{id:"paypalcommercecreditcards"}]);var xe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ue{constructor(e,t,n,i=3e3,r=3e5){this.paymentIntegrationService=e,this.paypalCommerceService=t,this.loadingIndicator=n,this.pollingInterval=i,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=o}initialize(e){return xe(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,paypalcommerceratepay:i}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new H('Unable to initialize payment because "options.paypalcommerceratepay" argument is not provided.');const{legalTextContainer:r,container:o,loadingContainerId:a}=i;if(!o)throw new H('Unable to initialize payment because "options.container" argument is not provided.');if(!r)throw new H('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!a)throw new H('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=a;const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:d}=s.initializationData||{};if(!d)throw new H("Unable to initialize payment because merchantId argument is not provided.");this.paypalcommerceratepay=i,yield this.paypalCommerceService.loadPayPalSdk(n),this.createFraudNetScript(d,n,t),this.loadFraudnetConfig(),this.renderLegalText(r,o)})}execute(e,t){return xe(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{getFieldsValues:r}=this.paypalcommerceratepay||{};if(!n)throw new $(["payment"]);if(!r||"function"!=typeof r)throw new H('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:o,ratepayPhoneNumber:a,ratepayPhoneCountryCode:s}=r(),d={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:n.methodId,rate_pay:{birth_date:this.normalizeDate(o),phone:{national_number:a,country_code:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:n.methodId,paymentData:d}),yield new Promise((e,t)=>{this.initializePollingMechanism(n.methodId,e,t,n.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new Y)}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,i=t.split("#")[1],r=document.getElementById(i),o=null==r?void 0:r.parentNode,a=document.createElement("div");a.style.marginBottom="20px",a.setAttribute("id",n),null==o||o.prepend(a);const s=this.paypalCommerceService.getPayPalSdkOrThrow(),d=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new H('Unable to initialize payment because "legalTextContainerElement" argument is not found.');d.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 i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:r}=i.config,o=document.createElement("script");o.setAttribute("type","application/json"),o.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),o.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const a={f:this.guid,s:`${e}_checkout-page`,sandbox:r};o.innerHTML=JSON.stringify(a),document.body.appendChild(o)}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 xe(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return xe(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.paypalCommerceService.getOrderStatus("paypalcommercealternativemethods",{params:{useMetadata:!0}}),o=r===M.PollingStop,a=r===M.PollingError;if(o)return this.deinitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,paypalcommerceratepay:this.paypalcommerceratepay}),this.handleError(new ce)}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()}}const je=d(e=>new Ue(e,V(e),new K({containerStyles:Object.assign(Object.assign({},h),{position:"fixed"})})),[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);var Le=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ve{constructor(e){this.requestSender=e}createOrder(e,t){return Le(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return Le(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:n,body:t})).body})}getOrderStatus(){return Le(this,arguments,void 0,function*(e="paypalcommerce",t){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":F,"Content-Type":x.Json},U);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}function Re(e){return"string"!=typeof e}function Ge(e,t){if(t||e)return function(e){var t,n;const i={},r=s(e.root,Re),o=s(e.input,Re),a=s(e.toggle,Re),d=s(null===(t=e.text)||void 0===t?void 0:t.body,Re),l=s(null===(n=e.text)||void 0===n?void 0:n.caption,Re),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(o).length&&(i.input=o),Object.keys(a).length&&(i.toggle=a),Object.keys(d).length&&(i.text={},i.text.body=d),Object.keys(l).length&&(i.text=Object.assign({},i.text),i.text.caption=l),c&&(i.branding=c),i}(function(e,t){var n,i,r,o,a,s,d,l,c,u,p,h,y,m,g,v,f,S,I,_,P,b;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null===(n=null==t?void 0:t.root)||void 0===n?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null===(i=null==t?void 0:t.root)||void 0===i?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null===(r=null==t?void 0:t.root)||void 0===r?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null===(o=null==t?void 0:t.root)||void 0===o?void 0:o.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null===(a=null==t?void 0:t.root)||void 0===a?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null===(s=null==t?void 0:t.root)||void 0===s?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null===(d=null==t?void 0:t.input)||void 0===d?void 0:d.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null===(l=null==t?void 0:t.input)||void 0===l?void 0:l.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null===(c=null==t?void 0:t.input)||void 0===c?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null===(u=null==t?void 0:t.input)||void 0===u?void 0:u.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null===(p=null==t?void 0:t.input)||void 0===p?void 0:p.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null===(h=null==t?void 0:t.input)||void 0===h?void 0:h.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null===(y=null==t?void 0:t.toggle)||void 0===y?void 0:y.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null===(m=null==t?void 0:t.toggle)||void 0===m?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?void 0:g.body)||void 0===v?void 0:v.color),fontSize:(null==e?void 0:e.fastlaneTextBodySettingsFontSize)||(null===(S=null===(f=null==t?void 0:t.text)||void 0===f?void 0:f.body)||void 0===S?void 0:S.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null===(_=null===(I=null==t?void 0:t.text)||void 0===I?void 0:I.caption)||void 0===_?void 0:_.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null===(b=null===(P=null==t?void 0:t.text)||void 0===P?void 0:P.caption)||void 0===b?void 0:b.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function Ke(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var He=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class $e{constructor(e,t,n,i){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=n,this.paypalFastlaneUtils=i}initialize(e){return He(this,void 0,void 0,function*(){var t,n;const{methodId:i,paypalcommercefastlane:r}=e;if(this.methodId=i,this.paypalcommercefastlane=r,!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new H('Unable to initialize payment because "options.paypalcommercefastlane" argument is not provided.');if(!r.onInit||"function"!=typeof r.onInit)throw new H('Unable to initialize payment because "options.paypalcommercefastlane.onInit" argument is not provided or it is not a function.');if(!r.onChange||"function"!=typeof r.onChange)throw new H('Unable to initialize payment because "options.paypalcommercefastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(i);const o=this.paymentIntegrationService.getState(),a=o.getCartOrThrow(),s=o.getPaymentMethodOrThrow(i),{isDeveloperModeApplicable:d,isFastlaneStylingEnabled:l}=s.initializationData||{};this.threeDSVerificationMethod=null===(t=s.initializationData)||void 0===t?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(s,a.currency.code,a.id,o.getLocale());const c=Ge(l?null===(n=null==s?void 0:s.initializationData)||void 0===n?void 0:n.fastlaneStyles:{},null==r?void 0:r.styles);yield this.paypalFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!d,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(i)),yield this.initializePayPalPaymentComponent(),r.onInit(e=>this.renderPayPalPaymentComponent(e)),r.onChange(()=>this.handlePayPalStoredInstrumentChange(i))})}execute(e,t){return He(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new $(["payment"]);const{paymentData:r,methodId:o}=n,a=r&&Z(r);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=a?yield this.prepareVaultedInstrumentPaymentPayload(o,r):yield this.preparePaymentPayload(o,r);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 Y)}deinitialize(){return He(this,void 0,void 0,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=Ke(i)?i:{},o=this.paypalFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===T.CANCELED||(null==r?void 0:r.authenticationState)||o!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return He(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(a),{authenticationState:d,addresses:l,instruments:c}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:d,addresses:l,instruments:c}),s.authenticationState===T.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n.id)}catch(e){}})}initializePayPalPaymentComponent(){return He(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),i=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),r={fields:Object.assign({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield i.FastlaneCardComponent(r)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new H('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 He(this,void 0,void 0,function*(){const{instrumentId:n}=t,i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).config.is3dsEnabled?yield this.get3DSNonce(n):n;return yield this.createOrder(i),{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:i}}}}})}preparePaymentPayload(e,t){return He(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getPaymentMethodOrThrow(e),o=`${i.firstName} ${i.lastName}`.trim(),{getPaymentToken:a}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield a({name:{fullName:o},billingAddress:this.paypalFastlaneUtils.mapBcToPayPalAddress(i)}),d=r.config.is3dsEnabled?yield this.get3DSNonce(s):s;yield this.createOrder(d);const{shouldSaveInstrument:l=!1,shouldSetAsDefaultInstrument:c=!1}=W(t)?t:{};return{methodId:e,paymentData:Object.assign(Object.assign({},t),{shouldSaveInstrument:l,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:d}}})}})}createOrder(e){return He(this,void 0,void 0,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 He(this,void 0,void 0,function*(){var t;const n=this.paymentIntegrationService.getState(),i=n.getCartOrThrow(),r=n.getOrderOrThrow(),o=n.getStoreConfigOrThrow().links.checkoutLink,a=null===(t=this.paypalFastlaneSdk)||void 0===t?void 0:t.ThreeDomainSecureClient;if(!a)throw new c;const s={amount:r.orderAmount.toFixed(2),currency:i.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===C.Always,transactionContext:{experience_context:{locale:"en-US",return_url:o,cancel_url:o}}},d=yield a.isEligible(s);if(this.threeDSVerificationMethod===C.Always&&!d)throw new q;if(d){const{liabilityShift:e,authenticationState:t,nonce:n}=yield a.show();if(e===ue.No||e===ue.Unknown||t===w.Errored||t===w.Cancelled)throw new q;if(t===w.Succeeded&&[ue.Yes,ue.Possible].includes(e))return n;throw new q}return e})}handlePayPalStoredInstrumentChange(e){return He(this,void 0,void 0,function*(){const t=this.paypalFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=Ke(t)?t:{},r=this.paypalFastlaneUtils.mapPayPalToBcInstrument(e,i)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Object.assign(Object.assign({},n),{instruments:[r]})),r}})}handleError(e){var t;(null===(t=this.paypalcommercefastlane)||void 0===t?void 0:t.onError)&&"function"==typeof this.paypalcommercefastlane.onError&&this.paypalcommercefastlane.onError(e)}}const qe=d(e=>{const{getHost:t}=e.getState();return new $e(e,new Ve(n({host:t()})),f(),Oe())},[{id:"paypalcommerceacceleratedcheckout"}]);var Ye=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};const We=class{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}createPayPalButton(e,t,n,i){const{style:r,fundingSource:o,isHostedCheckoutEnabled:a,isServerSideShippingCallbacksEnabled:s,onClick:d,onCancel:l,onPaymentComplete:c,onError:u}=n;this.onError=u;const p=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(p.FUNDING).includes(o))throw new H('Unable to initialize PayPal button because "fundingSource" argument is not valid funding source.');const h=Object.assign(Object.assign({},!s&&{onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e)}),{onApprove:(n,i)=>this.onHostedCheckoutApprove(n,i,t,e,c,s)});return p.Buttons(Object.assign(Object.assign(Object.assign({fundingSource:o,style:this.paypalIntegrationService.getValidButtonStyle(r),createOrder:()=>Ye(this,void 0,void 0,function*(){if(i){const e=yield this.paypalIntegrationService.createBuyNowCartOrThrow(i);yield this.paymentIntegrationService.loadCheckout(e.id)}return this.paypalIntegrationService.createOrder(e)}),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},d?{onClick:d}:{}),l?{onCancel:l}:{}),a&&h))}onHostedCheckoutApprove(e,t,n,i,r,o){return Ye(this,void 0,void 0,function*(){if(!e.orderID)throw new p(u.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow();try{const s=a.lineItems.physicalItems.length>0;if(!o){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(i,void 0,void 0,o)),o&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalIntegrationService.submitPayment(n,e.orderID),r&&"function"==typeof r&&r()}catch(e){this.handleError(e)}})}onShippingAddressChange(e,t){return Ye(this,void 0,void 0,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 Ye(this,void 0,void 0,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 Ze=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Je{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return Ze(this,void 0,void 0,function*(){const{paypalcommerce:t,methodId:n}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(!t.container)throw new H('Unable to initialize payment because "options.paypalcommerce.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new H('Unable to initialize payment because "options.paypalcommerce.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.paypalIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i,onComplete:r,onError:o}=t,a=this.paypalIntegrationService.getPayPalSdkOrThrow(),s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:d,paymentButtonStyles:l,isServerSideShippingCallbacksEnabled:c}=s.initializationData||{},{checkoutTopButtonStyles:u}=l||{},p=Object.assign(Object.assign(Object.assign({fundingSource:a.FUNDING.PAYPAL,isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:d,style:Object.assign(Object.assign({},u),{height:40})},i&&{onClick:()=>i()}),d&&r&&{onPaymentComplete:()=>r()}),{onError:o}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",e,p);h.isEligible()?h.render(`#${n}`):this.paypalIntegrationService.removeElement(n)}}const Xe=d(e=>{const t=V(e),n=new We(e,t);return new Je(e,t,n)},[{id:"paypalcommerce"}]);var Qe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class et{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.paypalCommerceRequestSender=n,this.paypalCommerceScriptLoader=i}loadPayPalSdk(e,t,n,i){return Qe(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,o,r.getLocale(),n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return Qe(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new p(u.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new S}})}createOrder(e,t){return Qe(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return Qe(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.paypalCommerceRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(e){return Qe(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getConsignmentsOrThrow()[0];try{yield this.paypalCommerceRequestSender.updateOrder({availableShippingOptions:e?[]:i.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:i.selectedShippingOption})}catch(e){throw new _}})}getOrderStatus(e,t){return Qe(this,void 0,void 0,function*(){try{const{status:n}=yield this.paypalCommerceRequestSender.getOrderStatus(e,t);return n}catch(e){throw new _}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new p(u.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===P.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return Qe(this,void 0,void 0,function*(){const i={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,n;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:o}=e||{},a={color:t&&ye[t]?t:void 0,height:this.getValidHeight(n),label:i&&he[i]?i:void 0,shape:o&&me[o]?o:void 0};return s(a,r)}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 tt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class nt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return tt(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);return this.loadPayPalSDK(o,r)})}loadPayPalSDK(e){return tt(this,arguments,void 0,function*(e,t=!1){if(!this.window.paypal||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.paypal)throw new c;return this.window.paypal})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:o,initializationData:a}=e;if(!(null==a?void 0:a.clientId))throw new p(u.MissingPaymentMethod);const{intent:s,clientId:d,merchantId:l,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:g,isPayPalCreditAvailable:v,isDeveloperModeApplicable:f,availableAlternativePaymentMethods:S=[],enabledAlternativePaymentMethods:I=[],isGooglePayEnabled:_}=a,P=g||i,b="paypalcommercecreditcards"===r,C=b?["card"]:[],w=v?["credit","paylater"]:[],O=y?["venmo"]:[],z=_?["googlepay"]:[],A=i?["card-fields"]:[],E=[...b?[]:["card"],...v?[]:["credit","paylater"],...y?[]:["venmo"],...S.filter(e=>!I.includes(e))],T=[...C,...w,...O,...I],k=m(n);return{options:Object.assign(Object.assign({"client-id":d,"merchant-id":l,"enable-funding":T.length>0?T:void 0,"disable-funding":E.length>0?E:void 0,commit:P,components:["buttons","hosted-fields","payment-fields","legal",...z,...A],currency:t,intent:s},f&&{"buyer-country":c}),k&&{locale:k}),attributes:{"data-partner-attribution-id":h,"data-client-token":o}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const it=i=>{const{getHost:r}=i.getState();return new et(t(),i,new Ve(n({host:r()})),new nt(e()))};var rt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ot{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=o}initialize(e){return rt(this,void 0,void 0,function*(){const{paypalcommercecredit:t,methodId:n}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(!t.container)throw new H('Unable to initialize payment because "options.paypalcommercecredit.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new H('Unable to initialize payment because "options.paypalcommercecredit.onClick" argument is not a function.');this.onError=t.onError||o,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.paypalCommerceIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return rt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return rt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onComplete:i,onClick:r}=t,o=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:l}=a.initializationData||{},{checkoutTopButtonStyles:c}=d||{},u=Object.assign({createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()}),p=Object.assign(Object.assign({},!l&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,i,l)}),h=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let y=!1;h.forEach(e=>{if(!y){const t=Object.assign(Object.assign({fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},c),{height:40}))},u),s&&p),i=o.Buttons(t);i.isEligible()&&(i.render(`#${n}`),y=!0)}}),y||this.paypalCommerceIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i,r){return rt(this,void 0,void 0,function*(){if(!e.orderID)throw new p(u.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}a&&(yield this.paypalCommerceIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalCommerceIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return rt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}onShippingOptionsChange(e){return rt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const at=d(e=>new ot(e,it(e)),[{id:"paypalcommercecredit"}]);var st=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class dt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return st(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,methodId:n}=e;if(!n)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(!t.container)throw new H('Unable to initialize payment because "options.paypalcommercevenmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new H('Unable to initialize payment because "options.paypalcommercevenmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.paypalCommerceIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return st(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return st(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i}=t,r=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:a}=o.initializationData||{},{checkoutTopButtonStyles:s}=a||{},d=Object.assign({fundingSource:r.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},s),{height:40})),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:t})=>this.paypalCommerceIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),l=r.Buttons(d);l.isEligible()?l.render(`#${n}`):this.paypalCommerceIntegrationService.removeElement(n)}}const lt=d(e=>new dt(e,it(e)),[{id:"paypalcommercevenmo"}]);var ct=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ut{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=n}initialize(e){return ct(this,void 0,void 0,function*(){var t;const{methodId:n,paypalcommercefastlane:i}=e;if(!n)throw new H('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),r=e.getCartOrThrow(),o=e.getPaymentMethodOrThrow(n),a=!!(null===(t=o.initializationData)||void 0===t?void 0:t.isDeveloperModeApplicable),s=yield this.paypalSdkScriptLoader.getPayPalFastlaneSdk(o,r.currency.code,r.id,e.getLocale());yield this.paypalFastlaneUtils.initializePayPalFastlane(s,a,this.getFastlaneStyles(n,i))}catch(e){}return Promise.resolve()})}deinitialize(){return ct(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return ct(this,void 0,void 0,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 ct(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return ct(this,void 0,void 0,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:i}=e||{};if(!i)throw new H('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new H('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');if(this.paymentIntegrationService.getState().getCustomerOrThrow().isGuest){t&&"function"==typeof t&&t();try{yield this.runPayPalAuthenticationFlowOrThrow(i)}catch(e){}}n()})}runPayPalAuthenticationFlowOrThrow(e){return ct(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.paypalFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.paypalFastlaneUtils.triggerAuthenticationFlowOrThrow(a),d=s.authenticationState===T.CANCELED;yield this.updateCustomerDataState(e,s),d?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return ct(this,void 0,void 0,function*(){var n;const i=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:r,addresses:o,billingAddress:a,shippingAddress:s,instruments:d}=this.paypalFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:r,addresses:o,instruments:d}),a&&(yield this.paymentIntegrationService.updateBillingAddress(a)),s&&i.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),i=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:r}=i.initializationData||{},o=(null===(n=(t.getConsignments()||[])[0])||void 0===n?void 0:n.availableShippingOptions)||[],a=o[0],d=o.find(e=>e.isRecommended);if((d||a)&&r){const e=(null==d?void 0:d.id)||a.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:i,isFastlaneStylingEnabled:r}=n.initializationData||{};return Ge(r?i:{},null==t?void 0:t.styles)}}const pt=d(e=>new ut(e,f(),Oe()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);class ht{constructor(e,t,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=n}initialize(e){return t=this,n=void 0,r=function*(){var t;const{paypalcommerce:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new H('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new H('Unable to initialize payment because "options.paypalcommerce" argument is not provided.');if(o&&!n.currencyCode)throw new H('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new H('Unable to initialize payment because "options.paypalcommerce.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n)},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c}=d.initializationData||{},u={onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},p=Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.paypalIntegrationService.getValidButtonStyle(r),isServerSideShippingCallbacksEnabled:c,isHostedCheckoutEnabled:l},i&&u),l&&o&&{onPaymentComplete:()=>o()}),h=this.paypalButtonCreationService.createPayPalButton("paypalcommerce",t,p,i);h.isEligible()?h.render(`#${e}`):a&&"function"==typeof a?a():this.paypalIntegrationService.removeElement(e)}}const yt=d(e=>{const t=V(e),n=new We(e,t);return new ht(e,t,n)},[{id:"paypalcommerce"}]);var mt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class gt{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}initialize(e){return mt(this,void 0,void 0,function*(){const{paypalcommercecredit:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new H('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercecredit" argument is not provided.');if(a&&!o)throw new H('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new H('Unable to initialize payment because "options.paypalcommercecredit.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=this.paymentIntegrationService.getState(),d=a?o:s.getCartOrThrow().currency.code;yield this.paypalIntegrationService.loadPayPalSdk(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.paypalIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c}=d.initializationData||{},u={createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},p={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h=Object.assign(Object.assign({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o,c)}),y=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let m=!1;y.forEach(t=>{if(!m){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalIntegrationService.getValidButtonStyle(r)},u),i&&p),l&&h),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),m=!0):a&&"function"==typeof a&&a()}}),m||this.paypalIntegrationService.removeElement(e)}handleClick(e){return mt(this,void 0,void 0,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i,r){return mt(this,void 0,void 0,function*(){if(!e.orderID)throw new p(u.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.paypalIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.paypalIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}return a&&(yield this.paypalIntegrationService.updateOrder("paypalcommerce",void 0,void 0,r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.paypalIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return mt(this,void 0,void 0,function*(){const t=this.paypalIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalIntegrationService.updateOrder("paypalcommerce")}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return mt(this,void 0,void 0,function*(){const t=this.paypalIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalIntegrationService.updateOrder("paypalcommerce")}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}}const vt=d(e=>new gt(e,V(e)),[{id:"paypalcommercecredit"}]);var ft=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class St{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return ft(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new H('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new H('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new H('Unable to initialize payment because "options.paypalcommercevenmo" argument is not provided.');if(a&&!o)throw new H('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new H('Unable to initialize payment because "options.paypalcommercevenmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,a=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&l),u=a.Buttons(c);u.isEligible()?u.render(`#${e}`):o&&"function"==typeof o?o():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===ye.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return ft(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const It=d(e=>new St(e,it(e)),[{id:"paypalcommercevenmo"}]);class _t{constructor(e){this.walletButtonIntegrationService=e}getWalletButtonIntegrationService(){return this.walletButtonIntegrationService}initialize(e){return t=this,n=void 0,r=function*(){return Promise.resolve()},new((i=void 0)||(i=Promise))(function(e,o){function a(e){try{d(r.next(e))}catch(e){o(e)}}function s(e){try{d(r.throw(e))}catch(e){o(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof i?n:new i(function(e){e(n)})).then(a,s)}d((r=r.apply(t,n||[])).next())});var t,n,i,r}deinitialize(){return Promise.resolve()}}const Pt=d(e=>new _t(e),[{id:"paypalcommercepaypal"}]);export{Ie as createPayPalCommerceAlternativeMethodsPaymentStrategy,yt as createPayPalCommerceButtonStrategy,vt as createPayPalCommerceCreditButtonStrategy,De as createPayPalCommerceCreditCardsPaymentStrategy,at as createPayPalCommerceCreditCustomerStrategy,oe as createPayPalCommerceCreditPaymentStrategy,Xe as createPayPalCommerceCustomerStrategy,pt as createPayPalCommerceFastlaneCustomerStrategy,qe as createPayPalCommerceFastlanePaymentStrategy,te as createPayPalCommercePaymentStrategy,je as createPayPalCommerceRatePayPaymentStrategy,It as createPayPalCommerceVenmoButtonStrategy,lt as createPayPalCommerceVenmoCustomerStrategy,de as createPayPalCommerceVenmoPaymentStrategy,Pt as createPayPalCommerceWalletStrategy};
2
2
  //# sourceMappingURL=paypal-commerce.js.map