@bigcommerce/checkout-sdk 1.818.0 → 1.819.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{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 r,noop as a,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 m 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 y=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class g{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,i){return y(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 y(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 y(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 y(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 y(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 m(l.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:r},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 m(l.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:p,isDeveloperModeApplicable:u}=o,h=p||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},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 m(l.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,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":r,"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":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new m(l.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}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 C={body:{},headers:{},status:0};class b extends u{constructor(e,{message:t,errors:i}={}){const{body:n,headers:o,status:r}=e||C;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=n,this.headers=o,this.status=r,this.errors=i||[]}}var w,P,O,k,A,E,T,z;!function(e){e.BuyNow="BUY_NOW"}(w||(w={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(P||(P={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(O||(O={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(k||(k={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(A||(A={})),function(e){e.pill="pill",e.rect="rect"}(E||(E={})),function(e){e.OXXO="oxxo"}(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,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,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(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,r,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 m(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 m(l.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===w.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,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.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||{},a={color:t&&A[t]?t:void 0,height:this.getValidHeight(i),label:n&&k[n]?n:void 0,shape:o&&E[o]?o:void 0};return d(a,r)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}const D="This API endpoint is for internal use only and may change in the future";var M;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(M||(M={}));const x=M,N={"X-Checkout-SDK-Version":"1.818.0"};var U=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class j{constructor(e){this.requestSender=e}createOrder(e,t){return U(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":D,"Content-Type":x.Json},N);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e){return U(this,void 0,void 0,function*(){const t=e,i=Object.assign({"X-API-INTERNAL":D,"Content-Type":x.Json},N);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:i,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return U(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":D,"Content-Type":x.Json},N);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var _=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class V{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return _(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,i);return this.loadPayPalSDK(o,n)})}loadPayPalSDK(e,t=!1){return _(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:r}=e;if(!(null==r?void 0:r.clientId))throw new m(l.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:p,isVenmoEnabled:u,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:y,isDeveloperModeApplicable:g,availableAlternativePaymentMethods:v=[],enabledAlternativePaymentMethods:f=[],isGooglePayEnabled:S}=r,I=h||i,C="paypalcommercecreditcards"===n,b=C?["card"]:[],w=y?["credit","paylater"]:[],P=i||!I,O=u?["venmo"]:[],k=P?f:[],A=S?["googlepay"]:[],E=i?["card-fields"]:[],T=[...C?[]:["card"],...y?[]:["credit","paylater"],...u?[]:["venmo"],...P?v.filter(e=>!f.includes(e)):v],z=[...b,...w,...O,...k];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":z.length>0?z:void 0,"disable-funding":T.length>0?T:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...A,...E],currency:t,intent:a},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 H 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 G 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 J(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 X=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,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 X(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(),r=o.getPaymentMethodOrThrow(i),{container:a,bannerContainerId:s}=n,{orderId:d,paypalBNPLConfiguration:l=[],isPayPalCreditAvailable:c}=r.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(r,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=r.initializationData)||void 0===t?void 0:t.orderId:(this.loadingIndicatorContainer=null==a?void 0:a.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 X(this,void 0,void 0,function*(){const{payment:o}=e,r=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:a}=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 H;const l=this.isPayPalVaultedInstrumentPaymentData(d)?this.prepareVaultedInstrumentPaymentPayload(s,this.orderId,d):this.preparePaymentPayload(s,this.orderId,d);try{yield this.paymentIntegrationService.submitOrder(r,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"),a)),t()})),this.handleError(e,a),Promise.reject()}})}finalize(){return Promise.reject(new G)}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,r=!this.isTrustedVaultingFlow(i);return r?{methodId:e,paymentData:{shouldSaveInstrument:r,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,r;const a=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:m}=t;if(!c)throw new $('Unable to initialize payment because "container" argument is not provided.');const y=Object.assign(Object.assign({},this.isPaypalCommerceAppSwitchEnabled(e)&&{appSwitchWhenAvailable:!0}),{fundingSource:a.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(l),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,h),onApprove:e=>this.handleApprove(e,m),onError:e=>this.handleError(e,p),onCancel:()=>this.toggleLoadingIndicator(!1)});this.paypalButton=a.Buttons(y),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===(r=(o=this.paypalButton).resume)||void 0===r||r.call(o):this.paypalButton.render(c))}handleClick(e,t){return X(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 X(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=>J(t)&&t.bigpayToken===e.instrumentId);return!(J(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}}const Q=p(e=>new Z(e,R(e),new g(t()),new S({containerStyles:L})),[{id:"paypalcommerce"}]);function ee(){return new g(e())}class te extends u{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var ie=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ne{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.loadingIndicator=i,this.paypalCommerceSdk=n}initialize(e){return ie(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 r=this.paymentIntegrationService.getState(),a=r.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:s=[],orderId:d}=a.initializationData||{},{bannerContainerId:l,container:c}=o;if(void 0!==l){if(!document.getElementById(l))return void console.error("Unable to create banner without valid banner container ID.");const e=s&&s.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.paypalCommerceSdk.getPayPalMessages(a,r.getCartOrThrow().currency.code);return this.renderMessages(t,l,e)}d?this.orderId=d:(yield this.paypalCommerceIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,o))})}execute(e,t){return ie(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 H;yield this.paymentIntegrationService.submitOrder(n,t),yield this.paypalCommerceIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new G)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new $('Unable to initialize payment because "container" argument is not provided.');const i=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:o}=n.initializationData||{},{checkoutPaymentButtonStyles:r}=o||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,p=[i.FUNDING.PAYLATER,i.FUNDING.CREDIT];let u=!1;p.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=i.Buttons(t),this.paypalButton.isEligible()||e!==i.FUNDING.PAYLATER){if(!this.paypalButton.isEligible()&&e===i.FUNDING.CREDIT)throw new te(`PayPal ${e} is not available for your region. Please use PayPal Checkout instead.`);d&&"function"==typeof d&&d(),this.paypalButton.render(a),u=!0}})}handleClick(e,t){return ie(this,void 0,void 0,function*(){const{resolve:i,reject:n}=e;if(t&&"function"==typeof t)return t(()=>(this.toggleLoadingIndicator(!0),i()),n)})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,i){const n={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:K(i)};e.Messages(n).render(`#${t}`)}}const oe=p(e=>new ne(e,R(e),new S({containerStyles:L}),ee()),[{id:"paypalcommercecredit"}]);var re=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ae{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.loadingIndicator=i}initialize(e){var t,i;return re(this,void 0,void 0,function*(){const{methodId:n,paypalcommerce:o,paypalcommercevenmo:r}=e||{},a=r||o;if(!n)throw new $('Unable to initialize payment because "options.methodId" argument is not provided.');if(!a)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=a.container.split("#")[1],this.renderButton(n,a))})}execute(e,t){return re(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 H;yield this.paymentIntegrationService.submitOrder(n,t),yield this.paypalCommerceIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new G)}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:r}=o||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,p={fundingSource:i.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r),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 te("PayPal Venmo is not available for your region. Please use PayPal Checkout instead.");d&&"function"==typeof d&&d(),this.paypalButton.render(a)}handleClick(e,t){return re(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 se=p(e=>new ae(e,R(e),new S({styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]);class de extends b{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}function le(e,t,i=!0){var n;return null!==(n=e[t])&&void 0!==n?n:i}var ce=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class pe{constructor(e,t,i,n,o=3e3,r=3e5){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i,this.loadingIndicator=n,this.pollingInterval=o,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=a,this.isPollingEnabled=!1}initialize(e){return ce(this,void 0,void 0,function*(){const{gatewayId:t,methodId:i,paypalcommerce:n,paypalcommercealternativemethods:o}=e,r=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(!r)throw new $('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');const a=this.paymentIntegrationService.getState(),s=a.getPaymentMethodOrThrow(i,t),{orderId:d,shouldRenderFields:l}=s.initializationData||{},c=a.getStoreConfigOrThrow().checkoutSettings.features;this.isPollingEnabled=le(c,"PAYPAL-5192.paypal_commerce_ideal_polling"),d?this.orderId=d:(this.paypalApms=yield this.paypalCommerceSdk.getPayPalApmsSdk(s,a.getCartOrThrow().currency.code),this.loadingIndicatorContainer=r.container.split("#")[1],this.renderButton(i,t,r),l&&this.renderFields(i,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"]);const{methodId:o,gatewayId:r}=i;if(!this.orderId)throw new H;this.isPollingEnabled&&"ideal"===o&&(yield new Promise((e,t)=>{this.initializePollingMechanism(o,e,t,r)})),this.isNonInstantPaymentMethod(o)||(yield this.paymentIntegrationService.submitOrder(n,t)),yield this.paypalCommerceIntegrationService.submitPayment(o,this.orderId,r)})}finalize(){return Promise.reject(new G)}deinitialize(){var e;return this.orderId=void 0,this.isPollingEnabled&&this.resetPollingMechanism(),null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}initializePollingMechanism(e,t,i,n){return ce(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(n),r=o===z.Approved,a=o===z.PollingError;if(r)return this.deinitializePollingMechanism(),t();if(a)return i();if(!r&&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 de)}catch(e){i()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return ce(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.paypalcommercealternativemethods||{};this.isPollingEnabled&&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:r}=o.initializationData||{},{container:a,onError:s,onRenderButton:d,submitForm:l}=i,c={fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r),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)=>ce(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(a))}onCreateOrder(e,t,i){return ce(this,void 0,void 0,function*(){const{onValidate:n}=i;yield n(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),a);const o=yield this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethodscheckout");if(this.isNonInstantPaymentMethod(e)){const i={useStoreCredit:!1},n={params:{methodId:e,gatewayId:t}};yield this.paymentIntegrationService.submitOrder(i,n),yield this.paypalCommerceIntegrationService.submitPayment(e,o,t)}return o})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const i=this.getPaypalAmpsSdkOrThrow(),n=this.paymentIntegrationService.getState(),{firstName:o,lastName:r,email:a}=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} ${r}`},email:{value:a}}};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 ue=p(e=>new pe(e,R(e),ee(),new S({containerStyles:L})),[{gateway:"paypalcommercealternativemethods"}]);var he,me,ye,ge,ve,fe,Se,Ie;!function(e){e.CVV="cvv",e.PAN="pan"}(he||(he={}));class Ce{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:r,domain:a,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()}`}r&&(n+=`; path=${r}`),a&&(n+=`; domain=${a}`),s&&(n+="; secure"),document.cookie=n}static remove(e,t){Ce.set(e,"",Object.assign({expires:new Date(0)},t))}}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(me||(me={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(ye||(ye={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ge||(ge={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(ve||(ve={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(fe||(fe={})),function(e){e.pill="pill",e.rect="rect"}(Se||(Se={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(Ie||(Ie={}));var be,we=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Pe{constructor(){this.window=window}initializePayPalFastlane(e,t,i){return we(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 we(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return we(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};Ce.set("bc-fastlane-sessionId",e,i)}removeStorageSessionId(){Ce.remove("bc-fastlane-sessionId")}getStorageSessionId(){return Ce.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var i,n,o;const{authenticationState:r,profileData:a}=t,s=null===(o=null===(n=null===(i=null==a?void 0:a.card)||void 0===i?void 0:i.paymentSource)||void 0===n?void 0:n.card)||void 0===o?void 0:o.billingAddress,d=null==a?void 0:a.shippingAddress,l=null==a?void 0:a.name,c=null==a?void 0:a.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):[],m=this.filterAddresses([p,u]);return{authenticationState:r||Ie.UNRECOGNIZED,addresses:m,billingAddress:u,shippingAddress:p,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:i,paymentSource:n}=t,{brand:o,expiry:r,lastDigits:a}=n.card,[s,d]=r.split("-");return[{bigpayToken:i,brand:o,defaultInstrument:!1,expiryMonth:d,expiryYear:s,iin:"",last4:a,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:he.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,r]=t.fullName.split(" "),a=(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||r||"",company:e.company||"",address1:e.addressLine1,address2:e.addressLine2||"",city:e.adminArea2,stateOrProvince:e.adminArea1,stateOrProvinceCode:e.adminArea1,country:e.countryCode||"",countryCode:e.countryCode||"",postalCode:e.postalCode,phone:s+a,customFields: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 Oe(){return new Pe}!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification"}(be||(be={}));const ke=be;function Ae(e){return ke.CardNumber in e&&ke.CardName in e&&ke.CardExpiry in e}function Ee(e){return ke.CardNumberVerification in e&&ke.CardCodeVerification in e&&ke.CardExpiryVerification in e}class Te 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 ze;!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"}(ze||(ze={}));class Fe extends u{constructor(e){super(function(e){switch(e){case ze.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case ze.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case ze.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case ze.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 Be 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 De=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Me{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i,this.paypalCommerceFastlaneUtils=n}initialize(e){return De(this,void 0,void 0,function*(){const{methodId:t,paypalcommercecreditcards:i,paypalcommerce:n}=e,o=i||n,{form:r,onCreditCardFieldsRenderingError:a,onLoadComplete:s}=o||{};if(!t)throw new $('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new $('Unable to proceed because "options.paypalcommercecreditcards.form" argument is not provided.');this.hostedFormOptions=r,this.isCreditCardForm=Ae(r.fields),this.isCreditCardVaultedForm=Ee(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.paypalCommerceIntegrationService.loadPayPalSdk(t,void 0,!0,!0),null==s||s(),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,a)),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return De(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:r}=i||{};if(!i||!o)throw new q(["payment"]);if(this.executionPaymentData=r,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.paypalCommerceIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const a=this.preparePaymentPayload(o,r,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(n,t),yield this.paymentIntegrationService.submitPayment(a)})}finalize(){return Promise.reject(new G)}deinitialize(){var e,t,i,n;return De(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:a=!1}=Y(t)?t:{},s=t&&W(t)?t.instrumentId:void 0,l=d({verification_nonce:n,token:s},r);return{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,instrumentId:s,formattedPayload:Object.assign(Object.assign({},n||s?{bigpay_token:l}:{}),i?{card_with_order:{order_id:i}}:{})}}}initializeFields(e,t){return De(this,void 0,void 0,function*(){const{fields:i,styles:n}=e,o=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),r=this.getExecuteCallback(i),a=Object.assign({style:this.getInputStyles(n),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:i})=>{if(i===P.No||i===P.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Te},inputEvents:{onChange:t=>this.onChangeHandler(e,t),onFocus:t=>this.onFocusHandler(e,t),onBlur:t=>this.onBlurHandler(e,t),onInputSubmitRequest:t=>this.onInputSubmitRequest(e,t)}},r);if(this.cardFields=yield o.CardFields(a),!this.cardFields.isEligible())throw new Fe(ze.PaymentNotInitialized);try{this.stylizeInputContainers(i),Ae(i)&&(yield this.renderFields(i)),Ee(i)&&(yield this.renderVaultedFields(i))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Ee(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>De(this,void 0,void 0,function*(){const{setupToken:e}=(yield this.paypalCommerceIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",Object.assign(Object.assign({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>De(this,void 0,void 0,function*(){const{orderId:e}=(yield this.paypalCommerceIntegrationService.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 De(this,void 0,void 0,function*(){const r=this.getCardFieldsOrThrow();(null===(t=e.cardCode)||void 0===t?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null===(i=e.cardExpiry)||void 0===i?void 0:i.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null===(n=e.cardName)||void 0===n?void 0:n.containerId)&&(this.nameField=r.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null===(o=e.cardNumber)||void 0===o?void 0:o.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){var t,i,n;return De(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 De(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 Te("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){var e,t;return De(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 Be(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 ke.CardCode:case ke.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case ke.CardNumber:case ke.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case ke.CardExpiry:case ke.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 ke.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?ke.CardNumber:ke.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?ke.CardExpiry:ke.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?ke.CardCode:ke.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Fe(ze.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"},r=Object.assign(Object.assign({},o),{color:"#333333"});return{input:r,".invalid":Object.assign(Object.assign({},o),{color:"red"}),".valid":r,":focus":r}}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),r=n.getPaymentProviderCustomer(),a=(s=r)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?r:{};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==a?void 0:a.authenticationState)}initializePayPalFastlaneOrThrow(e){return De(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 r=yield this.paypalCommerceSdk.getPayPalFastlaneSdk(n,i.currency.code,i.id);yield this.paypalCommerceFastlaneUtils.initializePayPalFastlane(r,!!(null==o?void 0:o.isDeveloperModeApplicable))}catch(e){}})}}const xe=p(e=>new Me(e,R(e),ee(),Oe()),[{id:"paypalcommercecreditcards"}]);var Ne=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ue{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=a}initialize(e){return Ne(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:r,loadingContainerId:a}=n;if(!r)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(!a)throw new $('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=a;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,r)})}execute(e,t){return Ne(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:r,ratepayPhoneNumber:a,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(r),phone:{national_number:a,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 G)}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),r=null==o?void 0:o.parentNode,a=document.createElement("div");a.style.marginBottom="20px",a.setAttribute("id",i),null==r||r.prepend(a);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,r=document.createElement("script");r.setAttribute("type","application/json"),r.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),r.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const a={f:this.guid,s:`${e}_checkout-page`,sandbox:o};r.innerHTML=JSON.stringify(a),document.body.appendChild(r)}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 Ne(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,i,n){return Ne(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}}),r=o===z.PollingStop,a=o===z.PollingError;if(r)return this.deinitializePollingMechanism(),t();if(a)return i();if(!r&&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 de)}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 je=p(e=>new Ue(e,R(e),new S({containerStyles:Object.assign(Object.assign({},L),{position:"fixed"})})),[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);function _e(e){return"string"!=typeof e}function Ve(e,t){if(t||e)return function(e){var t,i;const n={},o=d(e.root,_e),r=d(e.input,_e),a=d(e.toggle,_e),s=d(null===(t=e.text)||void 0===t?void 0:t.body,_e),l=d(null===(i=e.text)||void 0===i?void 0:i.caption,_e),c=e.branding;return Object.keys(o).length&&(n.root=o),Object.keys(r).length&&(n.input=r),Object.keys(a).length&&(n.toggle=a),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,r,a,s,d,l,c,p,u,h,m,y,g,v,f,S,I,C,b,w;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===(r=null==t?void 0:t.root)||void 0===r?void 0:r.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null===(a=null==t?void 0:t.root)||void 0===a?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null===(s=null==t?void 0:t.root)||void 0===s?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null===(d=null==t?void 0:t.input)||void 0===d?void 0:d.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null===(l=null==t?void 0:t.input)||void 0===l?void 0:l.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null===(c=null==t?void 0:t.input)||void 0===c?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null===(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===(m=null==t?void 0:t.toggle)||void 0===m?void 0:m.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null===(y=null==t?void 0:t.toggle)||void 0===y?void 0:y.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===(C=null===(I=null==t?void 0:t.text)||void 0===I?void 0:I.caption)||void 0===C?void 0:C.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null===(w=null===(b=null==t?void 0:t.text)||void 0===b?void 0:b.caption)||void 0===w?void 0:w.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function Re(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var Le=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class $e{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalCommerceSdk=i,this.paypalCommerceFastlaneUtils=n}initialize(e){var t,i;return Le(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 r=this.paymentIntegrationService.getState(),a=r.getCartOrThrow(),s=r.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.paypalCommerceSdk.getPayPalFastlaneSdk(s,a.currency.code,a.id);const c=Ve(l?null===(i=null==s?void 0:s.initializationData)||void 0===i?void 0:i.fastlaneStyles:{},null==o?void 0:o.styles);yield this.paypalCommerceFastlaneUtils.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 Le(this,void 0,void 0,function*(){const{payment:i}=e,n=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["payment"]);if(!i)throw new q(["payment"]);const{paymentData:o,methodId:r}=i,a=o&&W(o);try{yield this.paymentIntegrationService.submitOrder(n,t);const e=a?yield this.prepareVaultedInstrumentPaymentPayload(r,o):yield this.preparePaymentPayload(r,o);yield this.paymentIntegrationService.submitPayment(e),this.paypalCommerceFastlaneUtils.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 G)}deinitialize(){return Le(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=Re(n)?n:{},r=this.paypalCommerceFastlaneUtils.getStorageSessionId();return!(!i.isGuest||(null==o?void 0:o.authenticationState)===Ie.CANCELED||(null==o?void 0:o.authenticationState)||r!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return Le(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),i=t.getCartOrThrow(),n=t.getCustomer(),o=t.getBillingAddress(),r=(null==n?void 0:n.email)||(null==o?void 0:o.email)||"",{customerContextId:a}=yield this.paypalCommerceFastlaneUtils.lookupCustomerOrThrow(r),s=yield this.paypalCommerceFastlaneUtils.triggerAuthenticationFlowOrThrow(a),{authenticationState:d,addresses:l,instruments:c}=this.paypalCommerceFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:d,addresses:l,instruments:c}),s.authenticationState===Ie.CANCELED?this.paypalCommerceFastlaneUtils.removeStorageSessionId():this.paypalCommerceFastlaneUtils.updateStorageSessionId(i.id)}catch(e){}})}initializePayPalPaymentComponent(){return Le(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,i=`${e.firstName} ${e.lastName}`.trim(),n=this.paypalCommerceFastlaneUtils.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 Le(this,void 0,void 0,function*(){const{instrumentId:i}=t,n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),o=this.isPaypalCommerceFastlaneThreeDSAvailable()&&n.config.is3dsEnabled;o||(yield this.createOrder(i));const r=o?yield this.get3DSNonce(i):i;return{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:r}}}}})}preparePaymentPayload(e,t){return Le(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState(),n=i.getBillingAddressOrThrow(),o=i.getPaymentMethodOrThrow(e),r=`${n.firstName} ${n.lastName}`.trim(),{getPaymentToken:a}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield a({name:{fullName:r},billingAddress:this.paypalCommerceFastlaneUtils.mapBcToPayPalAddress(n)}),d=this.isPaypalCommerceFastlaneThreeDSAvailable()&&o.config.is3dsEnabled;d||(yield this.createOrder(s));const l=d?yield this.get3DSNonce(s):s,{shouldSaveInstrument:c=!1,shouldSetAsDefaultInstrument:p=!1}=Y(t)?t:{};return{methodId:e,paymentData:Object.assign(Object.assign({},t),{shouldSaveInstrument:c,shouldSetAsDefaultInstrument:p,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:l}}})}})}createOrder(e){return Le(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 Le(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState(),n=i.getCartOrThrow(),o=i.getOrderOrThrow(),r=i.getStoreConfigOrThrow().links.checkoutLink,a=null===(t=this.paypalFastlaneSdk)||void 0===t?void 0:t.ThreeDomainSecureClient;if(!a)throw new h;const s={amount:o.orderAmount.toFixed(2),currency:n.currency.code,nonce:e,threeDSRequested:"SCA_ALWAYS"===this.threeDSVerificationMethod,transactionContext:{experience_context:{locale:"en-US",return_url:r,cancel_url:r}}};if(yield a.isEligible(s)){const{liabilityShift:e,authenticationState:t,nonce:i}=yield a.show();if(e===P.No||e===P.Unknown||t===ye.Errored||t===ye.Cancelled)throw new H;if(t===ye.Succeeded)return yield this.createOrder(i),i}return e})}handlePayPalStoredInstrumentChange(e){return Le(this,void 0,void 0,function*(){const t=this.paypalCommerceFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:i,selectedCard:n}=yield t.profile.showCardSelector();if(i){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),i=Re(t)?t:{},o=this.paypalCommerceFastlaneUtils.mapPayPalToBcInstrument(e,n)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Object.assign(Object.assign({},i),{instruments:[o]})),o}})}isPaypalCommerceFastlaneThreeDSAvailable(){return le(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.paypalcommerce_fastlane_three_ds")}handleError(e){var t;(null===(t=this.paypalcommercefastlane)||void 0===t?void 0:t.onError)&&"function"==typeof this.paypalcommercefastlane.onError&&this.paypalcommercefastlane.onError(e)}}const qe=p(e=>{const{getHost:t}=e.getState();return new $e(e,new j(n({host:t()})),ee(),Oe())},[{id:"paypalcommerceacceleratedcheckout"}]);var He=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ge{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=a}initialize(e){return He(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||a,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 He(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return He(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:r,onComplete:a}=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)}),r&&{onClick:()=>r()}),m=Object.assign(Object.assign({},!p&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,i)=>this.onHostedCheckoutApprove(t,i,e,a)}),y=Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},u),{height:36}))},h),l&&m),g=s.Buttons(y);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 He(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);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 He(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 He(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 Ye=p(e=>new Ge(e,R(e)),[{id:"paypalcommerce"}]);var We=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ke{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=a}initialize(e){return We(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||a,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 We(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return We(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,r=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isAppSwitchEnabled:l}=a.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=[r.FUNDING.PAYLATER,r.FUNDING.CREDIT];let m=!1;h.forEach(e=>{if(!m){const t=Object.assign(Object.assign({fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},c),{height:36}))},p),s&&u),n=r.Buttons(t);n.isEligible()&&(n.render(`#${i}`),m=!0)}}),m||this.paypalCommerceIntegrationService.removeElement(i)}onHostedCheckoutApprove(e,t,i,n){return We(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);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 We(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 We(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 Je=p(e=>new Ke(e,R(e)),[{id:"paypalcommercecredit"}]);var Xe=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ze{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Xe(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 Xe(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Xe(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(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:a}=r.initializationData||{},{checkoutTopButtonStyles:s}=a||{},d=Object.assign({fundingSource:o.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},s),{height:36})),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 Qe=p(e=>new Ze(e,R(e)),[{id:"paypalcommercevenmo"}]);var et=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class tt{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceSdk=t,this.paypalCommerceFastlaneUtils=i}initialize(e){var t;return et(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(),r=e.getPaymentMethodOrThrow(i),a=!!(null===(t=r.initializationData)||void 0===t?void 0:t.isDeveloperModeApplicable),s=yield this.paypalCommerceSdk.getPayPalFastlaneSdk(r,o.currency.code,o.id);yield this.paypalCommerceFastlaneUtils.initializePayPalFastlane(s,a,this.getFastlaneStyles(i,n))}catch(e){}return Promise.resolve()})}deinitialize(){return et(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return et(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return et(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return et(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 et(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),i=t.getCartOrThrow().id,n=t.getCustomer(),o=t.getBillingAddress(),r=(null==n?void 0:n.email)||(null==o?void 0:o.email)||"",{customerContextId:a}=yield this.paypalCommerceFastlaneUtils.lookupCustomerOrThrow(r),s=yield this.paypalCommerceFastlaneUtils.triggerAuthenticationFlowOrThrow(a),d=s.authenticationState===Ie.CANCELED;yield this.updateCustomerDataState(e,s),d?this.paypalCommerceFastlaneUtils.removeStorageSessionId():this.paypalCommerceFastlaneUtils.updateStorageSessionId(i)})}updateCustomerDataState(e,t){var i;return et(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:o,addresses:r,billingAddress:a,shippingAddress:s,instruments:d}=this.paypalCommerceFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:o,addresses:r,instruments:d}),a&&(yield this.paymentIntegrationService.updateBillingAddress(a)),s&&n.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),n=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:o}=n.initializationData||{},r=t.getConsignments()||[],a=(null===(i=r[0])||void 0===i?void 0:i.availableShippingOptions)||[],d=a[0],l=a.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 Ve(o?n:{},null==t?void 0:t.styles)}}const it=p(e=>new tt(e,ee(),Oe()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var nt=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ot{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){var t;return nt(this,void 0,void 0,function*(){const{paypalcommerce:i,containerId:n,methodId:o}=e,r=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(r&&!i.currencyCode)throw new $('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(r&&"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.');r||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=r?i.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(o,a,!1),this.renderButton(n,o,i,r)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i,n){var o,r;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:l}=i,c=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),p=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:u,isAppSwitchEnabled:h}=p.initializationData||{},m=Object.assign(Object.assign({},!n&&this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommerce"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)}),y={onClick:()=>this.handleClick(a),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},g=Object.assign(Object.assign({},!h&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,d)}),v=Object.assign(Object.assign(Object.assign({fundingSource:c.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(s)},m),a&&y),u&&g),f=c.Buttons(v);f.isEligible()?(null===(o=f.hasReturned)||void 0===o?void 0:o.call(f))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(r=f.resume)||void 0===r||r.call(f):f.render(`#${e}`):l&&"function"==typeof l?l():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return nt(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return nt(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return nt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return nt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){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 rt=p(e=>new ot(e,R(e)),[{id:"paypalcommerce"}]);var at=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class st{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i}initialize(e){var t;return at(this,void 0,void 0,function*(){const{paypalcommercecredit:i,containerId:n,methodId:o}=e,{buyNowInitializeOptions:r,currencyCode:a,messagingContainerId:s}=i||{},d=!!r;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&&!a)throw new $('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(d&&"function"!=typeof(null==r?void 0:r.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?a:l.getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.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:r,onEligibilityFailure:a}=i,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isAppSwitchEnabled:c}=d.initializationData||{},p={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.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,r)}),m=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let y=!1;m.forEach(t=>{if(!y){const i=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o)},p),n&&u),l&&h),r=s.Buttons(i);r.isEligible()?(r.render(`#${e}`),y=!0):a&&"function"==typeof a&&a()}}),y||this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return at(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return at(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return 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){if("string"==typeof e)throw new Error(e);throw 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){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:K(i)};e.Messages(n).render(`#${t}`)}}const dt=p(e=>new st(e,R(e),ee()),[{id:"paypalcommercecredit"}]);var lt=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ct{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return lt(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r}=t||{},a=!!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(a&&!r)throw new $('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"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.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?r: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:r}=i,a=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(o)},d),n&&l),p=a.Buttons(c);p.isEligible()?p.render(`#${e}`):r&&"function"==typeof r?r():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===A.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return lt(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const pt=p(e=>new ct(e,R(e)),[{id:"paypalcommercevenmo"}]);var ut=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ht{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return ut(this,void 0,void 0,function*(){const{paypalcommercealternativemethods:t,containerId:i,methodId:n}=e,{apm:o,buyNowInitializeOptions:r,currencyCode:a}=t||{},s=!!r;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&&!a)throw new $('Unable to initialize payment because "options.paypalcommercealternativemethods.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.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?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(n,d,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{apm:n,buyNowInitializeOptions:o,style:r,onEligibilityFailure:a}=i,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(n))throw new $('Unable to initialize PayPal button because "options.paypalcommercealternativemethods.apm" argument is not valid funding source.');const d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethod"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:n,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r)},d),o&&l),p=s.Buttons(c);p.isEligible()?p.render(`#${e}`):a&&"function"==typeof a?a():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return ut(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const mt=p(e=>new ht(e,R(e)),[{id:"paypalcommercealternativemethods"}]);export{mt as createPayPalCommerceAlternativeMethodsButtonStrategy,ue as createPayPalCommerceAlternativeMethodsPaymentStrategy,rt as createPayPalCommerceButtonStrategy,dt as createPayPalCommerceCreditButtonStrategy,xe as createPayPalCommerceCreditCardsPaymentStrategy,Je as createPayPalCommerceCreditCustomerStrategy,oe as createPayPalCommerceCreditPaymentStrategy,Ye as createPayPalCommerceCustomerStrategy,it as createPayPalCommerceFastlaneCustomerStrategy,qe as createPayPalCommerceFastlanePaymentStrategy,Q as createPayPalCommercePaymentStrategy,je as createPayPalCommerceRatePayPaymentStrategy,pt as createPayPalCommerceVenmoButtonStrategy,Qe as createPayPalCommerceVenmoCustomerStrategy,se 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 r,noop as a,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 m 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 y=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class g{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,i){return y(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 y(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 y(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 y(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 y(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 m(l.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,attributionId:d}=o;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:r},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 m(l.MissingPaymentMethod);const{intent:r,clientId:a,merchantId:s,buyerCountry:d,attributionId:c,isHostedCheckoutEnabled:p,isDeveloperModeApplicable:u}=o,h=p||i;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:h,components:["googlepay"],currency:t,intent:r},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 m(l.MissingPaymentMethod);const{intent:n,clientId:o,merchantId:r,buyerCountry:a,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":r,"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":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:i}=e;if(!i||!i.clientId)throw new m(l.MissingPaymentMethod);const{clientId:n,merchantId:o,attributionId:r,isDeveloperModeApplicable:a,buyerCountry:s}=i;return{options:Object.assign({"client-id":n,"merchant-id":o,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":r}}}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 C={body:{},headers:{},status:0};class b extends u{constructor(e,{message:t,errors:i}={}){const{body:n,headers:o,status:r}=e||C;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=n,this.headers=o,this.status=r,this.errors=i||[]}}var w,P,O,k,A,E,T,z;!function(e){e.BuyNow="BUY_NOW"}(w||(w={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(P||(P={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(O||(O={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(k||(k={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(A||(A={})),function(e){e.pill="pill",e.rect="rect"}(E||(E={})),function(e){e.OXXO="oxxo"}(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,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,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(),r=t||o.getCartOrThrow().currency.code,a=o.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.paypalCommerceScriptLoader.getPayPalSDK(a,r,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 m(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 m(l.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},i.source===w.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,[r,...a]=o.split(" ");return this.getAddress({firstName:r,lastName:a.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||{},a={color:t&&A[t]?t:void 0,height:this.getValidHeight(i),label:n&&k[n]?n:void 0,shape:o&&E[o]?o:void 0};return d(a,r)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}const D="This API endpoint is for internal use only and may change in the future";var M;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(M||(M={}));const x=M,N={"X-Checkout-SDK-Version":"1.819.0"};var U=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class j{constructor(e){this.requestSender=e}createOrder(e,t){return U(this,void 0,void 0,function*(){const i=`/api/storefront/payment/${e}`,n=t,o=Object.assign({"X-API-INTERNAL":D,"Content-Type":x.Json},N);return(yield this.requestSender.post(i,{headers:o,body:n})).body})}updateOrder(e){return U(this,void 0,void 0,function*(){const t=e,i=Object.assign({"X-API-INTERNAL":D,"Content-Type":x.Json},N);return(yield this.requestSender.put("/api/storefront/initialization/paypalcommerce",{headers:i,body:t})).body})}getOrderStatus(e="paypalcommerce",t){return U(this,void 0,void 0,function*(){const i=`/api/storefront/initialization/${e}`,n=Object.assign({"X-API-INTERNAL":D,"Content-Type":x.Json},N);return(yield this.requestSender.get(i,Object.assign({headers:n},t))).body})}}var _=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class V{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,i,n){return _(this,void 0,void 0,function*(){const o=this.getPayPalSdkScriptConfigOrThrow(e,t,i);return this.loadPayPalSDK(o,n)})}loadPayPalSDK(e,t=!1){return _(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:r}=e;if(!(null==r?void 0:r.clientId))throw new m(l.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:c,attributionId:p,isVenmoEnabled:u,isHostedCheckoutEnabled:h,isPayPalCreditAvailable:y,isDeveloperModeApplicable:g,availableAlternativePaymentMethods:v=[],enabledAlternativePaymentMethods:f=[],isGooglePayEnabled:S}=r,I=h||i,C="paypalcommercecreditcards"===n,b=C?["card"]:[],w=y?["credit","paylater"]:[],P=i||!I,O=u?["venmo"]:[],k=P?f:[],A=S?["googlepay"]:[],E=i?["card-fields"]:[],T=[...C?[]:["card"],...y?[]:["credit","paylater"],...u?[]:["venmo"],...P?v.filter(e=>!f.includes(e)):v],z=[...b,...w,...O,...k];return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":z.length>0?z:void 0,"disable-funding":T.length>0?T:void 0,commit:I,components:["buttons","hosted-fields","payment-fields","legal",...A,...E],currency:t,intent:a},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 H 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 G 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 J(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 X=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,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 X(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(),r=o.getPaymentMethodOrThrow(i),{container:a,bannerContainerId:s}=n,{orderId:d,paypalBNPLConfiguration:l=[],isPayPalCreditAvailable:c}=r.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(r,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=r.initializationData)||void 0===t?void 0:t.orderId:(this.loadingIndicatorContainer=null==a?void 0:a.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 X(this,void 0,void 0,function*(){const{payment:o}=e,r=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:a}=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 H;const l=this.isPayPalVaultedInstrumentPaymentData(d)?this.prepareVaultedInstrumentPaymentPayload(s,this.orderId,d):this.preparePaymentPayload(s,this.orderId,d);try{yield this.paymentIntegrationService.submitOrder(r,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"),a)),t()})),this.handleError(e,a),Promise.reject()}})}finalize(){return Promise.reject(new G)}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,r=!this.isTrustedVaultingFlow(i);return r?{methodId:e,paymentData:{shouldSaveInstrument:r,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,r;const a=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:m}=t;if(!c)throw new $('Unable to initialize payment because "container" argument is not provided.');const y=Object.assign(Object.assign({},this.isPaypalCommerceAppSwitchEnabled(e)&&{appSwitchWhenAvailable:!0}),{fundingSource:a.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(l),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,h),onApprove:e=>this.handleApprove(e,m),onError:e=>this.handleError(e,p),onCancel:()=>this.toggleLoadingIndicator(!1)});this.paypalButton=a.Buttons(y),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===(r=(o=this.paypalButton).resume)||void 0===r||r.call(o):this.paypalButton.render(c))}handleClick(e,t){return X(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 X(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=>J(t)&&t.bigpayToken===e.instrumentId);return!(J(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}}const Q=p(e=>new Z(e,R(e),new g(t()),new S({containerStyles:L})),[{id:"paypalcommerce"}]);function ee(){return new g(e())}class te extends u{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var ie=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ne{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.loadingIndicator=i,this.paypalCommerceSdk=n}initialize(e){return ie(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 r=this.paymentIntegrationService.getState(),a=r.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:s=[],orderId:d}=a.initializationData||{},{bannerContainerId:l,container:c}=o;if(void 0!==l){if(!document.getElementById(l))return void console.error("Unable to create banner without valid banner container ID.");const e=s&&s.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.paypalCommerceSdk.getPayPalMessages(a,r.getCartOrThrow().currency.code);return this.renderMessages(t,l,e)}d?this.orderId=d:(yield this.paypalCommerceIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==c?void 0:c.split("#")[1],this.renderButton(t,o))})}execute(e,t){return ie(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 H;yield this.paymentIntegrationService.submitOrder(n,t),yield this.paypalCommerceIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new G)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new $('Unable to initialize payment because "container" argument is not provided.');const i=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:o}=n.initializationData||{},{checkoutPaymentButtonStyles:r}=o||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,p=[i.FUNDING.PAYLATER,i.FUNDING.CREDIT];let u=!1;p.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r),createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecreditcheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=i.Buttons(t),this.paypalButton.isEligible()||e!==i.FUNDING.PAYLATER){if(!this.paypalButton.isEligible()&&e===i.FUNDING.CREDIT)throw new te(`PayPal ${e} is not available for your region. Please use PayPal Checkout instead.`);d&&"function"==typeof d&&d(),this.paypalButton.render(a),u=!0}})}handleClick(e,t){return ie(this,void 0,void 0,function*(){const{resolve:i,reject:n}=e;if(t&&"function"==typeof t)return t(()=>(this.toggleLoadingIndicator(!0),i()),n)})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,i){const n={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:K(i)};e.Messages(n).render(`#${t}`)}}const oe=p(e=>new ne(e,R(e),new S({containerStyles:L}),ee()),[{id:"paypalcommercecredit"}]);var re=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ae{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.loadingIndicator=i}initialize(e){var t,i;return re(this,void 0,void 0,function*(){const{methodId:n,paypalcommerce:o,paypalcommercevenmo:r}=e||{},a=r||o;if(!n)throw new $('Unable to initialize payment because "options.methodId" argument is not provided.');if(!a)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=a.container.split("#")[1],this.renderButton(n,a))})}execute(e,t){return re(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 H;yield this.paymentIntegrationService.submitOrder(n,t),yield this.paypalCommerceIntegrationService.submitPayment(i.methodId,this.orderId)})}finalize(){return Promise.reject(new G)}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:r}=o||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,p={fundingSource:i.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r),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 te("PayPal Venmo is not available for your region. Please use PayPal Checkout instead.");d&&"function"==typeof d&&d(),this.paypalButton.render(a)}handleClick(e,t){return re(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 se=p(e=>new ae(e,R(e),new S({styles:{backgroundColor:"black"}})),[{id:"paypalcommercevenmo"}]);class de extends b{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}function le(e,t,i=!0){var n;return null!==(n=e[t])&&void 0!==n?n:i}var ce=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class pe{constructor(e,t,i,n,o=3e3,r=3e5){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i,this.loadingIndicator=n,this.pollingInterval=o,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=a,this.isPollingEnabled=!1}initialize(e){return ce(this,void 0,void 0,function*(){const{gatewayId:t,methodId:i,paypalcommerce:n,paypalcommercealternativemethods:o}=e,r=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(!r)throw new $('Unable to initialize payment because "options.paypalcommercealternativemethods" argument is not provided.');const a=this.paymentIntegrationService.getState(),s=a.getPaymentMethodOrThrow(i,t),{orderId:d,shouldRenderFields:l}=s.initializationData||{},c=a.getStoreConfigOrThrow().checkoutSettings.features;this.isPollingEnabled=le(c,"PAYPAL-5192.paypal_commerce_ideal_polling"),d?this.orderId=d:(this.paypalApms=yield this.paypalCommerceSdk.getPayPalApmsSdk(s,a.getCartOrThrow().currency.code),this.loadingIndicatorContainer=r.container.split("#")[1],this.renderButton(i,t,r),l&&this.renderFields(i,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"]);const{methodId:o,gatewayId:r}=i;if(!this.orderId)throw new H;this.isPollingEnabled&&"ideal"===o&&(yield new Promise((e,t)=>{this.initializePollingMechanism(o,e,t,r)})),this.isNonInstantPaymentMethod(o)||(yield this.paymentIntegrationService.submitOrder(n,t)),yield this.paypalCommerceIntegrationService.submitPayment(o,this.orderId,r)})}finalize(){return Promise.reject(new G)}deinitialize(){var e;return this.orderId=void 0,this.isPollingEnabled&&this.resetPollingMechanism(),null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}initializePollingMechanism(e,t,i,n){return ce(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(n),r=o===z.Approved,a=o===z.PollingError;if(r)return this.deinitializePollingMechanism(),t();if(a)return i();if(!r&&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 de)}catch(e){i()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return ce(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.paypalcommercealternativemethods||{};this.isPollingEnabled&&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:r}=o.initializationData||{},{container:a,onError:s,onRenderButton:d,submitForm:l}=i,c={fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r),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)=>ce(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(a))}onCreateOrder(e,t,i){return ce(this,void 0,void 0,function*(){const{onValidate:n}=i;yield n(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),a);const o=yield this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethodscheckout");if(this.isNonInstantPaymentMethod(e)){const i={useStoreCredit:!1},n={params:{methodId:e,gatewayId:t}};yield this.paymentIntegrationService.submitOrder(i,n),yield this.paypalCommerceIntegrationService.submitPayment(e,o,t)}return o})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const i=this.getPaypalAmpsSdkOrThrow(),n=this.paymentIntegrationService.getState(),{firstName:o,lastName:r,email:a}=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} ${r}`},email:{value:a}}};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 ue=p(e=>new pe(e,R(e),ee(),new S({containerStyles:L})),[{gateway:"paypalcommercealternativemethods"}]);var he,me,ye,ge,ve,fe,Se,Ie;!function(e){e.CVV="cvv",e.PAN="pan"}(he||(he={}));class Ce{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:r,domain:a,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()}`}r&&(n+=`; path=${r}`),a&&(n+=`; domain=${a}`),s&&(n+="; secure"),document.cookie=n}static remove(e,t){Ce.set(e,"",Object.assign({expires:new Date(0)},t))}}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(me||(me={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(ye||(ye={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ge||(ge={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(ve||(ve={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(fe||(fe={})),function(e){e.pill="pill",e.rect="rect"}(Se||(Se={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(Ie||(Ie={}));var be,we=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Pe{constructor(){this.window=window}initializePayPalFastlane(e,t,i){return we(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 we(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return we(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};Ce.set("bc-fastlane-sessionId",e,i)}removeStorageSessionId(){Ce.remove("bc-fastlane-sessionId")}getStorageSessionId(){return Ce.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var i,n,o;const{authenticationState:r,profileData:a}=t,s=null===(o=null===(n=null===(i=null==a?void 0:a.card)||void 0===i?void 0:i.paymentSource)||void 0===n?void 0:n.card)||void 0===o?void 0:o.billingAddress,d=null==a?void 0:a.shippingAddress,l=null==a?void 0:a.name,c=null==a?void 0:a.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):[],m=this.filterAddresses([p,u]);return{authenticationState:r||Ie.UNRECOGNIZED,addresses:m,billingAddress:u,shippingAddress:p,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:i,paymentSource:n}=t,{brand:o,expiry:r,lastDigits:a}=n.card,[s,d]=r.split("-");return[{bigpayToken:i,brand:o,defaultInstrument:!1,expiryMonth:d,expiryYear:s,iin:"",last4:a,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode:he.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,r]=t.fullName.split(" "),a=(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||r||"",company:e.company||"",address1:e.addressLine1,address2:e.addressLine2||"",city:e.adminArea2,stateOrProvince:e.adminArea1,stateOrProvinceCode:e.adminArea1,country:e.countryCode||"",countryCode:e.countryCode||"",postalCode:e.postalCode,phone:s+a,customFields: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 Oe(){return new Pe}!function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e.CardExpiryVerification="cardExpiryVerification"}(be||(be={}));const ke=be;function Ae(e){return ke.CardNumber in e&&ke.CardName in e&&ke.CardExpiry in e}function Ee(e){return ke.CardNumberVerification in e&&ke.CardCodeVerification in e&&ke.CardExpiryVerification in e}class Te 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 ze;!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"}(ze||(ze={}));class Fe extends u{constructor(e){super(function(e){switch(e){case ze.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case ze.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case ze.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case ze.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 Be 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 De=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Me{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i,this.paypalCommerceFastlaneUtils=n}initialize(e){return De(this,void 0,void 0,function*(){const{methodId:t,paypalcommercecreditcards:i,paypalcommerce:n}=e,o=i||n,{form:r,onCreditCardFieldsRenderingError:a,onLoadComplete:s}=o||{};if(!t)throw new $('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new $('Unable to proceed because "options.paypalcommercecreditcards.form" argument is not provided.');this.hostedFormOptions=r,this.isCreditCardForm=Ae(r.fields),this.isCreditCardVaultedForm=Ee(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.paypalCommerceIntegrationService.loadPayPalSdk(t,void 0,!0,!0),null==s||s(),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,a)),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return De(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:r}=i||{};if(!i||!o)throw new q(["payment"]);if(this.executionPaymentData=r,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.paypalCommerceIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const a=this.preparePaymentPayload(o,r,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(n,t),yield this.paymentIntegrationService.submitPayment(a)})}finalize(){return Promise.reject(new G)}deinitialize(){var e,t,i,n;return De(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:a=!1}=Y(t)?t:{},s=t&&W(t)?t.instrumentId:void 0,l=d({verification_nonce:n,token:s},r);return{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,instrumentId:s,formattedPayload:Object.assign(Object.assign({},n||s?{bigpay_token:l}:{}),i?{card_with_order:{order_id:i}}:{})}}}initializeFields(e,t){return De(this,void 0,void 0,function*(){const{fields:i,styles:n}=e,o=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),r=this.getExecuteCallback(i),a=Object.assign({style:this.getInputStyles(n),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:i})=>{if(i===P.No||i===P.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Te},inputEvents:{onChange:t=>this.onChangeHandler(e,t),onFocus:t=>this.onFocusHandler(e,t),onBlur:t=>this.onBlurHandler(e,t),onInputSubmitRequest:t=>this.onInputSubmitRequest(e,t)}},r);if(this.cardFields=yield o.CardFields(a),!this.cardFields.isEligible())throw new Fe(ze.PaymentNotInitialized);try{this.stylizeInputContainers(i),Ae(i)&&(yield this.renderFields(i)),Ee(i)&&(yield this.renderVaultedFields(i))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Ee(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>De(this,void 0,void 0,function*(){const{setupToken:e}=(yield this.paypalCommerceIntegrationService.createOrderCardFields("paypalcommercecreditcardscheckout",Object.assign(Object.assign({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>De(this,void 0,void 0,function*(){const{orderId:e}=(yield this.paypalCommerceIntegrationService.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 De(this,void 0,void 0,function*(){const r=this.getCardFieldsOrThrow();(null===(t=e.cardCode)||void 0===t?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null===(i=e.cardExpiry)||void 0===i?void 0:i.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null===(n=e.cardName)||void 0===n?void 0:n.containerId)&&(this.nameField=r.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null===(o=e.cardNumber)||void 0===o?void 0:o.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){var t,i,n;return De(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 De(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 Te("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){var e,t;return De(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 Be(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 ke.CardCode:case ke.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case ke.CardNumber:case ke.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case ke.CardExpiry:case ke.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 ke.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?ke.CardNumber:ke.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?ke.CardExpiry:ke.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?ke.CardCode:ke.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Fe(ze.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"},r=Object.assign(Object.assign({},o),{color:"#333333"});return{input:r,".invalid":Object.assign(Object.assign({},o),{color:"red"}),".valid":r,":focus":r}}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),r=n.getPaymentProviderCustomer(),a=(s=r)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?r:{};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==a?void 0:a.authenticationState)}initializePayPalFastlaneOrThrow(e){return De(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 r=yield this.paypalCommerceSdk.getPayPalFastlaneSdk(n,i.currency.code,i.id);yield this.paypalCommerceFastlaneUtils.initializePayPalFastlane(r,!!(null==o?void 0:o.isDeveloperModeApplicable))}catch(e){}})}}const xe=p(e=>new Me(e,R(e),ee(),Oe()),[{id:"paypalcommercecreditcards"}]);var Ne=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ue{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=a}initialize(e){return Ne(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:r,loadingContainerId:a}=n;if(!r)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(!a)throw new $('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=a;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,r)})}execute(e,t){return Ne(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:r,ratepayPhoneNumber:a,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(r),phone:{national_number:a,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 G)}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),r=null==o?void 0:o.parentNode,a=document.createElement("div");a.style.marginBottom="20px",a.setAttribute("id",i),null==r||r.prepend(a);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,r=document.createElement("script");r.setAttribute("type","application/json"),r.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),r.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const a={f:this.guid,s:`${e}_checkout-page`,sandbox:o};r.innerHTML=JSON.stringify(a),document.body.appendChild(r)}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 Ne(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,i,n){return Ne(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}}),r=o===z.PollingStop,a=o===z.PollingError;if(r)return this.deinitializePollingMechanism(),t();if(a)return i();if(!r&&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 de)}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 je=p(e=>new Ue(e,R(e),new S({containerStyles:Object.assign(Object.assign({},L),{position:"fixed"})})),[{gateway:"paypalcommercealternativemethods",id:"ratepay"}]);function _e(e){return"string"!=typeof e}function Ve(e,t){if(t||e)return function(e){var t,i;const n={},o=d(e.root,_e),r=d(e.input,_e),a=d(e.toggle,_e),s=d(null===(t=e.text)||void 0===t?void 0:t.body,_e),l=d(null===(i=e.text)||void 0===i?void 0:i.caption,_e),c=e.branding;return Object.keys(o).length&&(n.root=o),Object.keys(r).length&&(n.input=r),Object.keys(a).length&&(n.toggle=a),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,r,a,s,d,l,c,p,u,h,m,y,g,v,f,S,I,C,b,w;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===(r=null==t?void 0:t.root)||void 0===r?void 0:r.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null===(a=null==t?void 0:t.root)||void 0===a?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null===(s=null==t?void 0:t.root)||void 0===s?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null===(d=null==t?void 0:t.input)||void 0===d?void 0:d.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null===(l=null==t?void 0:t.input)||void 0===l?void 0:l.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null===(c=null==t?void 0:t.input)||void 0===c?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null===(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===(m=null==t?void 0:t.toggle)||void 0===m?void 0:m.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null===(y=null==t?void 0:t.toggle)||void 0===y?void 0:y.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===(C=null===(I=null==t?void 0:t.text)||void 0===I?void 0:I.caption)||void 0===C?void 0:C.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null===(w=null===(b=null==t?void 0:t.text)||void 0===b?void 0:b.caption)||void 0===w?void 0:w.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function Re(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var Le=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class $e{constructor(e,t,i,n){this.paymentIntegrationService=e,this.paypalCommerceRequestSender=t,this.paypalCommerceSdk=i,this.paypalCommerceFastlaneUtils=n}initialize(e){var t,i;return Le(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 r=this.paymentIntegrationService.getState(),a=r.getCartOrThrow(),s=r.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.paypalCommerceSdk.getPayPalFastlaneSdk(s,a.currency.code,a.id);const c=Ve(l?null===(i=null==s?void 0:s.initializationData)||void 0===i?void 0:i.fastlaneStyles:{},null==o?void 0:o.styles);yield this.paypalCommerceFastlaneUtils.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 Le(this,void 0,void 0,function*(){const{payment:i}=e,n=function(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(i[n[o]]=e[n[o]])}return i}(e,["payment"]);if(!i)throw new q(["payment"]);const{paymentData:o,methodId:r}=i,a=o&&W(o);try{yield this.paymentIntegrationService.submitOrder(n,t);const e=a?yield this.prepareVaultedInstrumentPaymentPayload(r,o):yield this.preparePaymentPayload(r,o);yield this.paymentIntegrationService.submitPayment(e),this.paypalCommerceFastlaneUtils.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 G)}deinitialize(){return Le(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=Re(n)?n:{},r=this.paypalCommerceFastlaneUtils.getStorageSessionId();return!(!i.isGuest||(null==o?void 0:o.authenticationState)===Ie.CANCELED||(null==o?void 0:o.authenticationState)||r!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return Le(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),i=t.getCartOrThrow(),n=t.getCustomer(),o=t.getBillingAddress(),r=(null==n?void 0:n.email)||(null==o?void 0:o.email)||"",{customerContextId:a}=yield this.paypalCommerceFastlaneUtils.lookupCustomerOrThrow(r),s=yield this.paypalCommerceFastlaneUtils.triggerAuthenticationFlowOrThrow(a),{authenticationState:d,addresses:l,instruments:c}=this.paypalCommerceFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:d,addresses:l,instruments:c}),s.authenticationState===Ie.CANCELED?this.paypalCommerceFastlaneUtils.removeStorageSessionId():this.paypalCommerceFastlaneUtils.updateStorageSessionId(i.id)}catch(e){}})}initializePayPalPaymentComponent(){return Le(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,i=`${e.firstName} ${e.lastName}`.trim(),n=this.paypalCommerceFastlaneUtils.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 Le(this,void 0,void 0,function*(){const{instrumentId:i}=t,n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),o=this.isPaypalCommerceFastlaneThreeDSAvailable()&&n.config.is3dsEnabled;o||(yield this.createOrder(i));const r=o?yield this.get3DSNonce(i):i;return{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:r}}}}})}preparePaymentPayload(e,t){return Le(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState(),n=i.getBillingAddressOrThrow(),o=i.getPaymentMethodOrThrow(e),r=`${n.firstName} ${n.lastName}`.trim(),{getPaymentToken:a}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield a({name:{fullName:r},billingAddress:this.paypalCommerceFastlaneUtils.mapBcToPayPalAddress(n)}),d=this.isPaypalCommerceFastlaneThreeDSAvailable()&&o.config.is3dsEnabled;d||(yield this.createOrder(s));const l=d?yield this.get3DSNonce(s):s,{shouldSaveInstrument:c=!1,shouldSetAsDefaultInstrument:p=!1}=Y(t)?t:{};return{methodId:e,paymentData:Object.assign(Object.assign({},t),{shouldSaveInstrument:c,shouldSetAsDefaultInstrument:p,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:l}}})}})}createOrder(e){return Le(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 Le(this,void 0,void 0,function*(){const i=this.paymentIntegrationService.getState(),n=i.getCartOrThrow(),o=i.getOrderOrThrow(),r=i.getStoreConfigOrThrow().links.checkoutLink,a=null===(t=this.paypalFastlaneSdk)||void 0===t?void 0:t.ThreeDomainSecureClient;if(!a)throw new h;const s={amount:o.orderAmount.toFixed(2),currency:n.currency.code,nonce:e,threeDSRequested:"SCA_ALWAYS"===this.threeDSVerificationMethod,transactionContext:{experience_context:{locale:"en-US",return_url:r,cancel_url:r}}};if(yield a.isEligible(s)){const{liabilityShift:e,authenticationState:t,nonce:i}=yield a.show();if(e===P.No||e===P.Unknown||t===ye.Errored||t===ye.Cancelled)throw new H;if(t===ye.Succeeded)return yield this.createOrder(i),i}return e})}handlePayPalStoredInstrumentChange(e){return Le(this,void 0,void 0,function*(){const t=this.paypalCommerceFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:i,selectedCard:n}=yield t.profile.showCardSelector();if(i){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),i=Re(t)?t:{},o=this.paypalCommerceFastlaneUtils.mapPayPalToBcInstrument(e,n)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Object.assign(Object.assign({},i),{instruments:[o]})),o}})}isPaypalCommerceFastlaneThreeDSAvailable(){return le(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.paypalcommerce_fastlane_three_ds")}handleError(e){var t;(null===(t=this.paypalcommercefastlane)||void 0===t?void 0:t.onError)&&"function"==typeof this.paypalcommercefastlane.onError&&this.paypalcommercefastlane.onError(e)}}const qe=p(e=>{const{getHost:t}=e.getState();return new $e(e,new j(n({host:t()})),ee(),Oe())},[{id:"paypalcommerceacceleratedcheckout"}]);var He=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ge{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=a}initialize(e){return He(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||a,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 He(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return He(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:r,onComplete:a}=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)}),r&&{onClick:()=>r()}),m=Object.assign(Object.assign({},!p&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,i)=>this.onHostedCheckoutApprove(t,i,e,a)}),y=Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},u),{height:36}))},h),l&&m),g=s.Buttons(y);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 He(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);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 He(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 He(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 Ye=p(e=>new Ge(e,R(e)),[{id:"paypalcommerce"}]);var We=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ke{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.onError=a}initialize(e){return We(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||a,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 We(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return We(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,r=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isAppSwitchEnabled:l}=a.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=[r.FUNDING.PAYLATER,r.FUNDING.CREDIT];let m=!1;h.forEach(e=>{if(!m){const t=Object.assign(Object.assign({fundingSource:e,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},c),{height:36}))},p),s&&u),n=r.Buttons(t);n.isEligible()&&(n.render(`#${i}`),m=!0)}}),m||this.paypalCommerceIntegrationService.removeElement(i)}onHostedCheckoutApprove(e,t,i,n){return We(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);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 We(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 We(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 Je=p(e=>new Ke(e,R(e)),[{id:"paypalcommercecredit"}]);var Xe=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class Ze{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return Xe(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 Xe(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Xe(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(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:a}=r.initializationData||{},{checkoutTopButtonStyles:s}=a||{},d=Object.assign({fundingSource:o.FUNDING.VENMO,style:this.paypalCommerceIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},s),{height:36})),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 Qe=p(e=>new Ze(e,R(e)),[{id:"paypalcommercevenmo"}]);var et=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class tt{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceSdk=t,this.paypalCommerceFastlaneUtils=i}initialize(e){var t;return et(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(),r=e.getPaymentMethodOrThrow(i),a=!!(null===(t=r.initializationData)||void 0===t?void 0:t.isDeveloperModeApplicable),s=yield this.paypalCommerceSdk.getPayPalFastlaneSdk(r,o.currency.code,o.id);yield this.paypalCommerceFastlaneUtils.initializePayPalFastlane(s,a,this.getFastlaneStyles(i,n))}catch(e){}return Promise.resolve()})}deinitialize(){return et(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return et(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return et(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return et(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 et(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),i=t.getCartOrThrow().id,n=t.getCustomer(),o=t.getBillingAddress(),r=(null==n?void 0:n.email)||(null==o?void 0:o.email)||"",{customerContextId:a}=yield this.paypalCommerceFastlaneUtils.lookupCustomerOrThrow(r),s=yield this.paypalCommerceFastlaneUtils.triggerAuthenticationFlowOrThrow(a),d=s.authenticationState===Ie.CANCELED;yield this.updateCustomerDataState(e,s),d?this.paypalCommerceFastlaneUtils.removeStorageSessionId():this.paypalCommerceFastlaneUtils.updateStorageSessionId(i)})}updateCustomerDataState(e,t){var i;return et(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:o,addresses:r,billingAddress:a,shippingAddress:s,instruments:d}=this.paypalCommerceFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:o,addresses:r,instruments:d}),a&&(yield this.paymentIntegrationService.updateBillingAddress(a)),s&&n.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),n=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:o}=n.initializationData||{},r=t.getConsignments()||[],a=(null===(i=r[0])||void 0===i?void 0:i.availableShippingOptions)||[],d=a[0],l=a.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 Ve(o?n:{},null==t?void 0:t.styles)}}const it=p(e=>new tt(e,ee(),Oe()),[{id:"paypalcommerceacceleratedcheckout"},{id:"paypalcommercecreditcards"}]);var nt=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ot{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){var t;return nt(this,void 0,void 0,function*(){const{paypalcommerce:i,containerId:n,methodId:o}=e,r=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(r&&!i.currencyCode)throw new $('Unable to initialize payment because "options.paypalcommerce.currencyCode" argument is not provided.');if(r&&"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.');r||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=r?i.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(o,a,!1),this.renderButton(n,o,i,r)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i,n){var o,r;const{buyNowInitializeOptions:a,style:s,onComplete:d,onEligibilityFailure:l}=i,c=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),p=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:u,isAppSwitchEnabled:h}=p.initializationData||{},m=Object.assign(Object.assign({},!n&&this.isPaypalCommerceAppSwitchEnabled(t)&&{appSwitchWhenAvailable:!0}),{createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommerce"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)}),y={onClick:()=>this.handleClick(a),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},g=Object.assign(Object.assign({},!h&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,i)=>this.onHostedCheckoutApprove(e,i,t,d)}),v=Object.assign(Object.assign(Object.assign({fundingSource:c.FUNDING.PAYPAL,style:this.paypalCommerceIntegrationService.getValidButtonStyle(s)},m),a&&y),u&&g),f=c.Buttons(v);f.isEligible()?(null===(o=f.hasReturned)||void 0===o?void 0:o.call(f))&&this.isPaypalCommerceAppSwitchEnabled(t)?null===(r=f.resume)||void 0===r||r.call(f):f.render(`#${e}`):l&&"function"==typeof l?l():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return nt(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return nt(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return nt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getAddress({city:e.shippingAddress.city,countryCode:e.shippingAddress.countryCode,postalCode:e.shippingAddress.postalCode,stateOrProvinceCode:e.shippingAddress.state});try{yield this.paymentIntegrationService.updateBillingAddress(t),yield this.paymentIntegrationService.updateShippingAddress(t);const e=this.paypalCommerceIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return nt(this,void 0,void 0,function*(){const t=this.paypalCommerceIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.paypalCommerceIntegrationService.updateOrder()}catch(e){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 rt=p(e=>new ot(e,R(e)),[{id:"paypalcommerce"}]);var at=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class st{constructor(e,t,i){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t,this.paypalCommerceSdk=i}initialize(e){var t;return at(this,void 0,void 0,function*(){const{paypalcommercecredit:i,containerId:n,methodId:o}=e,{buyNowInitializeOptions:r,currencyCode:a,messagingContainerId:s}=i||{},d=!!r;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&&!a)throw new $('Unable to initialize payment because "options.paypalcommercecredit.currencyCode" argument is not provided.');if(d&&"function"!=typeof(null==r?void 0:r.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?a:l.getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.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:r,onEligibilityFailure:a}=i,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isAppSwitchEnabled:c}=d.initializationData||{},p={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercecredit"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.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,r)}),m=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let y=!1;m.forEach(t=>{if(!y){const i=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.paypalCommerceIntegrationService.getValidButtonStyle(o)},p),n&&u),l&&h),r=s.Buttons(i);r.isEligible()?(r.render(`#${e}`),y=!0):a&&"function"==typeof a&&a()}}),y||this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return at(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,i,n){return at(this,void 0,void 0,function*(){if(!e.orderID)throw new m(l.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow(),r=yield t.order.get();try{const t=this.paypalCommerceIntegrationService.getBillingAddressFromOrderDetails(r);if(yield this.paymentIntegrationService.updateBillingAddress(t),o.lineItems.physicalItems.length>0){const e=this.paypalCommerceIntegrationService.getShippingAddressFromOrderDetails(r);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.paypalCommerceIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:i}}),yield this.paypalCommerceIntegrationService.submitPayment(i,e.orderID),n&&"function"==typeof n&&n(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return 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){if("string"==typeof e)throw new Error(e);throw 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){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:K(i)};e.Messages(n).render(`#${t}`)}}const dt=p(e=>new st(e,R(e),ee()),[{id:"paypalcommercecredit"}]);var lt=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ct{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return lt(this,void 0,void 0,function*(){const{paypalcommercevenmo:t,containerId:i,methodId:n}=e,{buyNowInitializeOptions:o,currencyCode:r}=t||{},a=!!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(a&&!r)throw new $('Unable to initialize payment because "options.paypalcommercevenmo.currencyCode" argument is not provided.');if(a&&"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.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?r: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:r}=i,a=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercevenmo"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(n),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(o)},d),n&&l),p=a.Buttons(c);p.isEligible()?p.render(`#${e}`):r&&"function"==typeof r?r():this.paypalCommerceIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.paypalCommerceIntegrationService.getValidButtonStyle(e);return t.color===A.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return lt(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const pt=p(e=>new ct(e,R(e)),[{id:"paypalcommercevenmo"}]);var ut=function(e,t,i,n){return new(i||(i=Promise))(function(o,r){function a(e){try{d(n.next(e))}catch(e){r(e)}}function s(e){try{d(n.throw(e))}catch(e){r(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(a,s)}d((n=n.apply(e,t||[])).next())})};class ht{constructor(e,t){this.paymentIntegrationService=e,this.paypalCommerceIntegrationService=t}initialize(e){return ut(this,void 0,void 0,function*(){const{paypalcommercealternativemethods:t,containerId:i,methodId:n}=e,{apm:o,buyNowInitializeOptions:r,currencyCode:a}=t||{},s=!!r;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&&!a)throw new $('Unable to initialize payment because "options.paypalcommercealternativemethods.currencyCode" argument is not provided.');if(s&&"function"!=typeof(null==r?void 0:r.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?a:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.paypalCommerceIntegrationService.loadPayPalSdk(n,d,!1),this.renderButton(i,n,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,i){const{apm:n,buyNowInitializeOptions:o,style:r,onEligibilityFailure:a}=i,s=this.paypalCommerceIntegrationService.getPayPalSdkOrThrow();if(!Object.values(s.FUNDING).includes(n))throw new $('Unable to initialize PayPal button because "options.paypalcommercealternativemethods.apm" argument is not valid funding source.');const d={createOrder:()=>this.paypalCommerceIntegrationService.createOrder("paypalcommercealternativemethod"),onApprove:({orderID:e})=>this.paypalCommerceIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(o),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:n,style:this.paypalCommerceIntegrationService.getValidButtonStyle(r)},d),o&&l),p=s.Buttons(c);p.isEligible()?p.render(`#${e}`):a&&"function"==typeof a?a():this.paypalCommerceIntegrationService.removeElement(e)}handleClick(e){return ut(this,void 0,void 0,function*(){if(e){const t=yield this.paypalCommerceIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const mt=p(e=>new ht(e,R(e)),[{id:"paypalcommercealternativemethods"}]);export{mt as createPayPalCommerceAlternativeMethodsButtonStrategy,ue as createPayPalCommerceAlternativeMethodsPaymentStrategy,rt as createPayPalCommerceButtonStrategy,dt as createPayPalCommerceCreditButtonStrategy,xe as createPayPalCommerceCreditCardsPaymentStrategy,Je as createPayPalCommerceCreditCustomerStrategy,oe as createPayPalCommerceCreditPaymentStrategy,Ye as createPayPalCommerceCustomerStrategy,it as createPayPalCommerceFastlaneCustomerStrategy,qe as createPayPalCommerceFastlanePaymentStrategy,Q as createPayPalCommercePaymentStrategy,je as createPayPalCommerceRatePayPaymentStrategy,pt as createPayPalCommerceVenmoButtonStrategy,Qe as createPayPalCommerceVenmoCustomerStrategy,se as createPayPalCommerceVenmoPaymentStrategy};
2
2
  //# sourceMappingURL=paypal-commerce.js.map