@bigcommerce/checkout-sdk 1.898.4 → 1.898.5

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