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