@bigcommerce/checkout-sdk 1.889.0 → 1.889.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,A,k,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"}(A||(A={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(k||(k={})),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&&k[t]?t:void 0,height:this.getValidHeight(i),label:n&&A[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.889.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"]:[],A=i?["card-fields"]:[],k=[...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":k.length>0?k:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...O,...A],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"}]);var ee,te,ie,ne,oe,ae,re,se,de,le,ce=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.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return ce(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 ce(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 ce(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 ce(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 ce(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 ce(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"]:[],A=i?["card-fields"]:[],k=[...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":k.length>0?k:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...O,...A],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 ue(){return new pe(e())}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(ee||(ee={})),function(e){e.Always="SCA_ALWAYS"}(te||(te={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(ie||(ie={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ne||(ne={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(oe||(oe={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ae||(ae={})),function(e){e.pill="pill",e.rect="rect"}(re||(re={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(se||(se={})),(de||(de={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(le||(le={}));var he=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 ye{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=i,this.paypalSdkLoader=n}loadPayPalSdk(e,t,i,n){return he(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 he(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 he(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 he(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 he(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 he(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 he(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&&ae[t]?t:void 0,height:this.getValidHeight(i),label:n&&oe[n]?n:void 0,shape:o&&re[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 me=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 ge{constructor(e){this.requestSender=e}createOrder(e,t){return me(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 me(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 me(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 ve=e=>{const{getHost:t}=e.getState();return new ye(i(),e,new ge(n({host:t()})),ue())},fe={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class Se extends u{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}const Ie=function({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t};var we=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 be{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=i,this.payPalSdkScriptLoader=n}initialize(e){return we(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.payPalSdkScriptLoader.getPayPalMessages(r,a.getCartOrThrow().currency.code);return this.renderMessages(t,l,e)}d?this.orderId=d:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,o))})}execute(e,t){return we(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.paypalIntegrationService.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.paypalIntegrationService.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.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=i.Buttons(t),this.paypalButton.isEligible()||e!==i.FUNDING.PAYLATER){if(!this.paypalButton.isEligible()&&e===i.FUNDING.CREDIT)throw new Se(`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 we(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:Ie(i)};e.Messages(n).render(`#${t}`)}}const Pe=p(e=>new be(e,ve(e),new S({containerStyles:fe}),ue()),[{id:"paypalcommercecredit"}]);var Ce=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 Oe{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.loadingIndicator=i}initialize(e){var t,i;return Ce(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 Ce(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 Se("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 Ce(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 Ae=p(e=>new Oe(e,R(e),new S({styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]);class ke extends b{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var Ee=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 Te{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 Ee(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 Ee(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 Ee(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 ke)}catch(e){i()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return Ee(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)=>Ee(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 Ee(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 ze=p(e=>new Te(e,ve(e),ue(),new S({containerStyles:L})),[{gateway:"paypalcommercealternativemethods"}]);var Fe;!function(e){e.CVV="cvv",e.PAN="pan"}(Fe||(Fe={}));class Be{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){Be.set(e,"",Object.assign({expires:new Date(0)},t))}}var Me,De=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 xe{constructor(){this.window=window}initializePayPalFastlane(e,t,i){return De(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 De(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return De(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};Be.set("bc-fastlane-sessionId",e,i)}removeStorageSessionId(){Be.remove("bc-fastlane-sessionId")}getStorageSessionId(){return Be.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||se.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:Fe.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 Ne(){return new xe}!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification"}(Me||(Me={}));const _e=Me;function je(e){return _e.CardNumber in e&&_e.CardName in e&&_e.CardExpiry in e}function Ue(e){return _e.CardNumberVerification in e&&_e.CardCodeVerification in e&&_e.CardExpiryVerification in e}class Ve 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 Re;!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"}(Re||(Re={}));class Le extends u{constructor(e){super(function(e){switch(e){case Re.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Re.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Re.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Re.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 $e 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 qe=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 Ge{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkScriptLoader=i,this.paypalFastlaneUtils=n}initialize(e){return qe(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=je(a.fields),this.isCreditCardVaultedForm=Ue(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 qe(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 qe(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 qe(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 Ve},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 Le(Re.PaymentNotInitialized);try{this.stylizeInputContainers(i),je(i)&&(yield this.renderFields(i)),Ue(i)&&(yield this.renderVaultedFields(i))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Ue(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>qe(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:()=>qe(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 qe(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 qe(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 qe(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 Ve("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){var e,t;return qe(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 $e(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 _e.CardCode:case _e.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case _e.CardNumber:case _e.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case _e.CardExpiry:case _e.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 _e.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?_e.CardNumber:_e.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?_e.CardExpiry:_e.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?_e.CardCode:_e.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Le(Re.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 qe(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 He=p(e=>new Ge(e,ve(e),ue(),Ne()),[{id:"paypalcommercecreditcards"}]);var Ye=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=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 Ye(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 Ye(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 Ye(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,i,n){return Ye(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 ke)}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 Ke=p(e=>new We(e,R(e),new S({containerStyles:Object.assign(Object.assign({},L),{position:"fixed"})})),[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);function Xe(e){return"string"!=typeof e}function Je(e,t){if(t||e)return function(e){var t,i;const n={},o=d(e.root,Xe),a=d(e.input,Xe),r=d(e.toggle,Xe),s=d(null===(t=e.text)||void 0===t?void 0:t.body,Xe),l=d(null===(i=e.text)||void 0===i?void 0:i.caption,Xe),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 Ze(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var Qe=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 et{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=i,this.paypalFastlaneUtils=n}initialize(e){var t,i;return Qe(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=Je(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 Qe(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 Qe(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=Ze(n)?n:{},a=this.paypalFastlaneUtils.getStorageSessionId();return!(!i.isGuest||(null==o?void 0:o.authenticationState)===se.CANCELED||(null==o?void 0:o.authenticationState)||a!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return Qe(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===se.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(i.id)}catch(e){}})}initializePayPalPaymentComponent(){return Qe(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 Qe(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 Qe(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 Qe(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 Qe(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===te.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},d=yield r.isEligible(s);if(this.threeDSVerificationMethod===te.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===ie.Errored||t===ie.Cancelled)throw new G;if(t===ie.Succeeded&&[C.Yes,C.Possible].includes(e))return i}return e})}handlePayPalStoredInstrumentChange(e){return Qe(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=Ze(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 tt=p(e=>{const{getHost:t}=e.getState();return new et(e,new j(n({host:t()})),ue(),Ne())},[{id:"paypalcommerceacceleratedcheckout"}]);var it=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 nt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=r}initialize(e){return it(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 it(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return it(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 it(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 it(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 it(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 ot=p(e=>new nt(e,R(e)),[{id:"paypalcommerce"}]);var at=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 rt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=r}initialize(e){return at(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 at(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return at(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 at(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 at(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 at(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 st=p(e=>new rt(e,R(e)),[{id:"paypalcommercecredit"}]);var dt=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 lt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return dt(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 dt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return dt(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 ct=p(e=>new lt(e,R(e)),[{id:"paypalcommercevenmo"}]);var pt=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 ut{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=i}initialize(e){var t;return pt(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 pt(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return pt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return pt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return pt(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 pt(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===se.CANCELED;yield this.updateCustomerDataState(e,s),d?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(i)})}updateCustomerDataState(e,t){var i;return pt(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 Je(o?n:{},null==t?void 0:t.styles)}}const ht=p(e=>new ut(e,ue(),Ne()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var yt=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 mt{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}initialize(e){var t;return yt(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.paypalIntegrationService.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.paypalIntegrationService.getPayPalSdkOrThrow(),c=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:p,isAppSwitchEnabled:u}=c.initializationData||{},h=Object.assign(Object.assign({},this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>yt(this,void 0,void 0,function*(){if(a){const e=yield this.paypalIntegrationService.createBuyNowCartOrThrow(a);yield this.paymentIntegrationService.loadCheckout(e.id)}return this.paypalIntegrationService.createOrder("paypalcommerce")}),onApprove:({orderID:e})=>this.paypalIntegrationService.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.paypalIntegrationService.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.paypalIntegrationService.removeElement(e)}onHostedCheckoutApprove(e,t,i,n){return yt(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 yt(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 yt(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}})}isPaypalCommerceAppSwitchEnabled(e){var t;return(null===(t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.isAppSwitchEnabled)||!1}}const gt=p(e=>new mt(e,ve(e)),[{id:"paypalcommerce"}]);var vt=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 ft{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalCommerceSdk=i}initialize(e){var t;return vt(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 vt(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 vt(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 vt(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 vt(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:Ie(i)};e.Messages(n).render(`#${t}`)}}const St=p(e=>new ft(e,ve(e),ue()),[{id:"paypalcommercecredit"}]);var It=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 wt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return It(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===k.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return It(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const bt=p(e=>new wt(e,R(e)),[{id:"paypalcommercevenmo"}]);var Pt=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())})};const Ct=class{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}createPayPalButton(e,t,i,n=!1){const{style:o,fundingSource:a,onClick:r,onCancel:s,onPaymentComplete:d}=i,l=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(l.FUNDING).includes(a))throw new $('Unable to initialize PayPal button because "fundingSource" argument is not valid funding source.');const c={onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e),onApprove:(i,n)=>this.onHostedCheckoutApprove(i,n,t,e,d)};return l.Buttons(Object.assign(Object.assign(Object.assign({fundingSource:a,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.paypalIntegrationService.createOrder(e),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},r?{onClick:r}:{}),s?{onCancel:s}:{}),n&&c))}onHostedCheckoutApprove(e,t,i,n,o){return Pt(this,void 0,void 0,function*(){if(!e.orderID)throw new y(l.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),a.lineItems.physicalItems.length>0){const e=this.paypalIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalIntegrationService.updateOrder(n)}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalIntegrationService.submitPayment(i,e.orderID),o&&"function"==typeof o&&o(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e,t){return Pt(this,void 0,void 0,function*(){const i=this.paypalIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(i),yield this.paymentIntegrationService.updateShippingAddress(i);const e=this.paypalIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e,t){return Pt(this,void 0,void 0,function*(){const i=this.paypalIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(i.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}};var Ot=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 At{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=i}initialize(e){return Ot(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=Object.assign({fundingSource:n,style:a},o&&{onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()}),d=this.paypalButtonCreationService.createPayPalButton("paypalcommercealternativemethod",t,s);d.isEligible()?d.render(`#${e}`):r&&"function"==typeof r?r():this.paypalIntegrationService.removeElement(e)}handleClick(e){return Ot(this,void 0,void 0,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const kt=p(e=>{const t=ve(e),i=new Ct(e,t);return new At(e,t,i)},[{id:"paypalcommercealternativemethods"}]);export{kt as createPayPalCommerceAlternativeMethodsButtonStrategy,ze as createPayPalCommerceAlternativeMethodsPaymentStrategy,gt as createPayPalCommerceButtonStrategy,St as createPayPalCommerceCreditButtonStrategy,He as createPayPalCommerceCreditCardsPaymentStrategy,st as createPayPalCommerceCreditCustomerStrategy,Pe as createPayPalCommerceCreditPaymentStrategy,ot as createPayPalCommerceCustomerStrategy,ht as createPayPalCommerceFastlaneCustomerStrategy,tt as createPayPalCommerceFastlanePaymentStrategy,Q as createPayPalCommercePaymentStrategy,Ke as createPayPalCommerceRatePayPaymentStrategy,bt as createPayPalCommerceVenmoButtonStrategy,ct as createPayPalCommerceVenmoCustomerStrategy,Ae 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,A,k,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"}(A||(A={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(k||(k={})),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&&k[t]?t:void 0,height:this.getValidHeight(i),label:n&&A[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.889.1"};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"]:[],A=i?["card-fields"]:[],k=[...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":k.length>0?k:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...O,...A],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"}]);var ee,te,ie,ne,oe,ae,re,se,de,le,ce=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.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return ce(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 ce(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 ce(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 ce(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 ce(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 ce(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"]:[],A=i?["card-fields"]:[],k=[...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":k.length>0?k:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...O,...A],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 ue(){return new pe(e())}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(ee||(ee={})),function(e){e.Always="SCA_ALWAYS"}(te||(te={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(ie||(ie={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ne||(ne={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(oe||(oe={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ae||(ae={})),function(e){e.pill="pill",e.rect="rect"}(re||(re={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(se||(se={})),(de||(de={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(le||(le={}));var he=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 ye{constructor(e,t,i,n){this.formPoster=e,this.paymentIntegrationService=t,this.paypalRequestSender=i,this.paypalSdkLoader=n}loadPayPalSdk(e,t,i,n){return he(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 he(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 he(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 he(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 he(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 he(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 he(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&&ae[t]?t:void 0,height:this.getValidHeight(i),label:n&&oe[n]?n:void 0,shape:o&&re[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 me=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 ge{constructor(e){this.requestSender=e}createOrder(e,t){return me(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 me(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 me(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 ve=e=>{const{getHost:t}=e.getState();return new ye(i(),e,new ge(n({host:t()})),ue())},fe={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class Se extends u{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}const Ie=function({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t};var we=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 be{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.loadingIndicator=i,this.payPalSdkScriptLoader=n}initialize(e){return we(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.payPalSdkScriptLoader.getPayPalMessages(r,a.getCartOrThrow().currency.code);return this.renderMessages(t,l,e)}d?this.orderId=d:(yield this.paypalIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,o))})}execute(e,t){return we(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.paypalIntegrationService.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.paypalIntegrationService.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.paypalIntegrationService.getValidButtonStyle(a),createOrder:()=>this.paypalIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=i.Buttons(t),this.paypalButton.isEligible()||e!==i.FUNDING.PAYLATER){if(!this.paypalButton.isEligible()&&e===i.FUNDING.CREDIT)throw new Se(`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 we(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:Ie(i)};e.Messages(n).render(`#${t}`)}}const Pe=p(e=>new be(e,ve(e),new S({containerStyles:fe}),ue()),[{id:"paypalcommercecredit"}]);var Ce=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 Oe{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.loadingIndicator=i}initialize(e){var t,i;return Ce(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 Ce(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 Se("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 Ce(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 Ae=p(e=>new Oe(e,R(e),new S({styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]);class ke extends b{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var Ee=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 Te{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 Ee(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 Ee(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 Ee(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 ke)}catch(e){i()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return Ee(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)=>Ee(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 Ee(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 ze=p(e=>new Te(e,ve(e),ue(),new S({containerStyles:L})),[{gateway:"paypalcommercealternativemethods"}]);var Fe;!function(e){e.CVV="cvv",e.PAN="pan"}(Fe||(Fe={}));class Be{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){Be.set(e,"",Object.assign({expires:new Date(0)},t))}}var Me,De=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 xe{constructor(){this.window=window}initializePayPalFastlane(e,t,i){return De(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 De(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return De(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};Be.set("bc-fastlane-sessionId",e,i)}removeStorageSessionId(){Be.remove("bc-fastlane-sessionId")}getStorageSessionId(){return Be.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||se.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:Fe.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 Ne(){return new xe}!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification"}(Me||(Me={}));const _e=Me;function je(e){return _e.CardNumber in e&&_e.CardName in e&&_e.CardExpiry in e}function Ue(e){return _e.CardNumberVerification in e&&_e.CardCodeVerification in e&&_e.CardExpiryVerification in e}class Ve 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 Re;!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"}(Re||(Re={}));class Le extends u{constructor(e){super(function(e){switch(e){case Re.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Re.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Re.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Re.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 $e 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 qe=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 Ge{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalSdkScriptLoader=i,this.paypalFastlaneUtils=n}initialize(e){return qe(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=je(a.fields),this.isCreditCardVaultedForm=Ue(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 qe(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 qe(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 qe(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 Ve},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 Le(Re.PaymentNotInitialized);try{this.stylizeInputContainers(i),je(i)&&(yield this.renderFields(i)),Ue(i)&&(yield this.renderVaultedFields(i))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Ue(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>qe(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:()=>qe(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 qe(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 qe(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 qe(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 Ve("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){var e,t;return qe(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 $e(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 _e.CardCode:case _e.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case _e.CardNumber:case _e.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case _e.CardExpiry:case _e.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 _e.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?_e.CardNumber:_e.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?_e.CardExpiry:_e.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?_e.CardCode:_e.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Le(Re.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 qe(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 He=p(e=>new Ge(e,ve(e),ue(),Ne()),[{id:"paypalcommercecreditcards"}]);var Ye=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=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 Ye(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 Ye(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 Ye(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,i,n){return Ye(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 ke)}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 Ke=p(e=>new We(e,R(e),new S({containerStyles:Object.assign(Object.assign({},L),{position:"fixed"})})),[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);function Xe(e){return"string"!=typeof e}function Je(e,t){if(t||e)return function(e){var t,i;const n={},o=d(e.root,Xe),a=d(e.input,Xe),r=d(e.toggle,Xe),s=d(null===(t=e.text)||void 0===t?void 0:t.body,Xe),l=d(null===(i=e.text)||void 0===i?void 0:i.caption,Xe),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 Ze(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var Qe=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 et{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalSdkScriptLoader=i,this.paypalFastlaneUtils=n}initialize(e){var t,i;return Qe(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=Je(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 Qe(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 Qe(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=Ze(n)?n:{},a=this.paypalFastlaneUtils.getStorageSessionId();return!(!i.isGuest||(null==o?void 0:o.authenticationState)===se.CANCELED||(null==o?void 0:o.authenticationState)||a!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return Qe(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===se.CANCELED?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(i.id)}catch(e){}})}initializePayPalPaymentComponent(){return Qe(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 Qe(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 Qe(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 Qe(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 Qe(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===te.Always,transactionContext:{experience_context:{locale:"en-US",return_url:a,cancel_url:a}}},d=yield r.isEligible(s);if(this.threeDSVerificationMethod===te.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===ie.Errored||t===ie.Cancelled)throw new G;if(t===ie.Succeeded&&[C.Yes,C.Possible].includes(e))return i}return e})}handlePayPalStoredInstrumentChange(e){return Qe(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=Ze(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 tt=p(e=>{const{getHost:t}=e.getState();return new et(e,new j(n({host:t()})),ue(),Ne())},[{id:"paypalcommerceacceleratedcheckout"}]);var it=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 nt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=r}initialize(e){return it(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 it(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return it(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 it(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 it(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 it(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 ot=p(e=>new nt(e,R(e)),[{id:"paypalcommerce"}]);var at=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 rt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=r}initialize(e){return at(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 at(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return at(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 at(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 at(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 at(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 st=p(e=>new rt(e,R(e)),[{id:"paypalcommercecredit"}]);var dt=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 lt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return dt(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 dt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return dt(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 ct=p(e=>new lt(e,R(e)),[{id:"paypalcommercevenmo"}]);var pt=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 ut{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalSdkScriptLoader=t,this.paypalFastlaneUtils=i}initialize(e){var t;return pt(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 pt(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return pt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return pt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return pt(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 pt(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===se.CANCELED;yield this.updateCustomerDataState(e,s),d?this.paypalFastlaneUtils.removeStorageSessionId():this.paypalFastlaneUtils.updateStorageSessionId(i)})}updateCustomerDataState(e,t){var i;return pt(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 Je(o?n:{},null==t?void 0:t.styles)}}const ht=p(e=>new ut(e,ue(),Ne()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var yt=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 mt{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}initialize(e){var t;return yt(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.paypalIntegrationService.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.paypalIntegrationService.getPayPalSdkOrThrow(),c=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:p,isAppSwitchEnabled:u}=c.initializationData||{},h=Object.assign(Object.assign({},this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>yt(this,void 0,void 0,function*(){if(a){const e=yield this.paypalIntegrationService.createBuyNowCartOrThrow(a);yield this.paymentIntegrationService.loadCheckout(e.id)}return this.paypalIntegrationService.createOrder("paypalcommerce")}),onApprove:({orderID:e})=>this.paypalIntegrationService.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.paypalIntegrationService.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.paypalIntegrationService.removeElement(e)}onHostedCheckoutApprove(e,t,i,n){return yt(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 yt(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 yt(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}})}isPaypalCommerceAppSwitchEnabled(e){var t;return(null===(t=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.isAppSwitchEnabled)||!1}}const gt=p(e=>new mt(e,ve(e)),[{id:"paypalcommerce"}]);var vt=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 ft{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalCommerceSdk=i}initialize(e){var t;return vt(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 vt(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 vt(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 vt(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 vt(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:Ie(i)};e.Messages(n).render(`#${t}`)}}const St=p(e=>new ft(e,ve(e),ue()),[{id:"paypalcommercecredit"}]);var It=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 wt{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return It(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===k.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return It(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const bt=p(e=>new wt(e,R(e)),[{id:"paypalcommercevenmo"}]);var Pt=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())})};const Ct=class{constructor(e,t){this.paymentIntegrationService=e,this.paypalIntegrationService=t}createPayPalButton(e,t,i,n=!1){const{style:o,fundingSource:a,onClick:r,onCancel:s,onPaymentComplete:d}=i,l=this.paypalIntegrationService.getPayPalSdkOrThrow();if(!Object.values(l.FUNDING).includes(a))throw new $('Unable to initialize PayPal button because "fundingSource" argument is not valid funding source.');const c={onShippingAddressChange:t=>this.onShippingAddressChange(t,e),onShippingOptionsChange:t=>this.onShippingOptionsChange(t,e),onApprove:(i,n)=>this.onHostedCheckoutApprove(i,n,t,e,d)};return l.Buttons(Object.assign(Object.assign(Object.assign({fundingSource:a,style:this.paypalIntegrationService.getValidButtonStyle(o),createOrder:()=>this.paypalIntegrationService.createOrder(e),onApprove:({orderID:e})=>this.paypalIntegrationService.tokenizePayment(t,e)},r?{onClick:r}:{}),s?{onCancel:s}:{}),n&&c))}onHostedCheckoutApprove(e,t,i,n,o){return Pt(this,void 0,void 0,function*(){if(!e.orderID)throw new y(l.MissingOrderId);const a=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),a.lineItems.physicalItems.length>0){const e=this.paypalIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalIntegrationService.updateOrder(n)}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalIntegrationService.submitPayment(i,e.orderID),o&&"function"==typeof o&&o(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e,t){return Pt(this,void 0,void 0,function*(){const i=this.paypalIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(i),yield this.paymentIntegrationService.updateShippingAddress(i);const e=this.paypalIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e,t){return Pt(this,void 0,void 0,function*(){const i=this.paypalIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(i.id),yield this.paypalIntegrationService.updateOrder(t)}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}};var Ot=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 At{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalIntegrationService=t,this.paypalButtonCreationService=i}initialize(e){return Ot(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=Object.assign({fundingSource:n,style:a},o&&{onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()}),d=this.paypalButtonCreationService.createPayPalButton("paypalcommercealternativemethod",t,s);d.isEligible()?d.render(`#${e}`):r&&"function"==typeof r?r():this.paypalIntegrationService.removeElement(e)}handleClick(e){return Ot(this,void 0,void 0,function*(){if(e){const t=yield this.paypalIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const kt=p(e=>{const t=ve(e),i=new Ct(e,t);return new At(e,t,i)},[{id:"paypalcommercealternativemethods"}]);export{kt as createPayPalCommerceAlternativeMethodsButtonStrategy,ze as createPayPalCommerceAlternativeMethodsPaymentStrategy,gt as createPayPalCommerceButtonStrategy,St as createPayPalCommerceCreditButtonStrategy,He as createPayPalCommerceCreditCardsPaymentStrategy,st as createPayPalCommerceCreditCustomerStrategy,Pe as createPayPalCommerceCreditPaymentStrategy,ot as createPayPalCommerceCustomerStrategy,ht as createPayPalCommerceFastlaneCustomerStrategy,tt as createPayPalCommerceFastlanePaymentStrategy,Q as createPayPalCommercePaymentStrategy,Ke as createPayPalCommerceRatePayPaymentStrategy,bt as createPayPalCommerceVenmoButtonStrategy,ct as createPayPalCommerceVenmoCustomerStrategy,Ae as createPayPalCommerceVenmoPaymentStrategy};
2
2
  //# sourceMappingURL=paypal-commerce.js.map