@bigcommerce/checkout-sdk 1.960.0 → 1.960.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/checkout-button.js +1 -1
- package/dist/cjs/checkout-sdk-essential.js +1 -1
- package/dist/cjs/checkout-sdk.js +1 -1
- package/dist/cjs/hosted-form-v2-iframe-host.js +1 -1
- package/dist/cjs/integrations/amazon-pay.js +1 -1
- package/dist/cjs/integrations/bigcommerce-payments.js +1 -1
- package/dist/cjs/integrations/braintree.js +1 -1
- package/dist/cjs/integrations/google-pay.js +1 -1
- package/dist/cjs/integrations/klarna.js +1 -1
- package/dist/cjs/integrations/paypal-commerce.js +1 -1
- package/dist/cjs/integrations/paypal-express.js +1 -1
- package/dist/cjs/integrations/zip.js +1 -1
- package/dist/esm/checkout-button.js +1 -1
- package/dist/esm/checkout-sdk-essential.js +1 -1
- package/dist/esm/checkout-sdk.js +1 -1
- package/dist/esm/hosted-form-v2-iframe-host.js +1 -1
- package/dist/esm/integrations/amazon-pay.js +1 -1
- package/dist/esm/integrations/bigcommerce-payments.js +1 -1
- package/dist/esm/integrations/braintree.js +1 -1
- package/dist/esm/integrations/google-pay.js +1 -1
- package/dist/esm/integrations/klarna.js +1 -1
- package/dist/esm/integrations/paypal-commerce.js +1 -1
- package/dist/esm/integrations/paypal-express.js +1 -1
- package/dist/esm/integrations/zip.js +1 -1
- package/dist/types/checkout-sdk.d.ts +3 -1
- package/dist/types/internal-mappers.d.ts +3 -1
- package/docs/README.md +1 -0
- package/docs/interfaces/CustomerAddress.md +1 -1
- package/docs/type-aliases/CustomerAddressType.md +9 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createScriptLoader as e,getScriptLoader as t}from"@bigcommerce/script-loader";import{createFormPoster as n}from"@bigcommerce/form-poster";import{createRequestSender as i}from"@bigcommerce/request-sender";import{isEqual as r,isNil as o,noop as a,omit as s,omitBy as d}from"lodash";class l extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}class c extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var m;!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"}(m||(m={}));class u extends l{constructor(e){super(function(e){switch(e){case m.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case m.MissingCart:return"Unable to proceed because cart data is unavailable.";case m.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case m.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case m.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case m.MissingCheckoutConfig:case m.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case m.MissingOrder:return"Unable to proceed because order data is unavailable.";case m.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case m.MissingPayment:return"Unable to proceed because payment data is unavailable.";case m.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case m.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case m.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 h=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class y{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.bigCommercePaymentsFastlaneSdk)throw new c}return this.window.bigCommercePaymentsFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.bigCommercePaymentsGooglePay)throw new c;return this.window.bigCommercePaymentsGooglePay})}getPayPalApmsSdk(e,t){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.bigCommercePaymentsApms)throw new c}return this.window.bigCommercePaymentsApms})}getPayPalMessages(e,t){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.bigCommercePaymentsMessages)throw new c;return this.window.bigCommercePaymentsMessages})}loadPayPalSdk(e){return h(this,arguments,void 0,function*({options:e,attributes:t}){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,attributionId:d}=r;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:o},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"bigCommercePaymentsFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,buyerCountry:d,attributionId:l,isHostedCheckoutEnabled:c,isDeveloperModeApplicable:h}=r,y=c||n;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:y,components:["googlepay"],currency:t,intent:o},h&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":l,"data-client-token":i,"data-namespace":"bigCommercePaymentsGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:o,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:l=[],enabledAlternativePaymentMethods:c=[]}=n,h=this.filterFundingOptions(c),y=this.filterFundingOptions(l.filter(e=>!c.includes(e)));return{options:Object.assign({"client-id":r,"merchant-id":o,"enable-funding":h.length>0?h:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"bigCommercePaymentsApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:o,isDeveloperModeApplicable:a,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":r,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"bigCommercePaymentsMessages","data-partner-attribution-id":o}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function p(){return new y(e())}function g(e,t){return Object.assign(e,{resolveIds:t})}const v={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},f="embedded-checkout-loading-indicator-rotation";class b{constructor(e){this.styles=Object.assign(Object.assign({},v),e&&e.styles),this.containerStyles=Object.assign({},e&&e.containerStyles),this.defineAnimation(),this.container=this.buildContainer(),this.indicator=this.buildIndicator(),this.container.appendChild(this.indicator)}show(e){if(e){const t=document.getElementById(e);if(!t)throw new Error("Unable to attach the loading indicator because the parent ID is not valid.");t.appendChild(this.container)}this.container.style.visibility="visible",this.container.style.opacity="1"}hide(){const e=()=>{this.container.style.visibility="hidden",this.container.removeEventListener("transitionend",e)};this.container.addEventListener("transitionend",e),this.container.style.opacity="0"}buildContainer(){const e=document.createElement("div");return e.style.display="block",e.style.bottom="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.position="absolute",e.style.right="0",e.style.top="0",e.style.transition="all 250ms ease-out",e.style.opacity="0",this.setStyleAttribute(e,this.containerStyles),e}buildIndicator(){const e=document.createElement("div");return e.style.display="block",e.style.width=`${this.styles.size}px`,e.style.height=`${this.styles.size}px`,e.style.borderRadius=`${this.styles.size}px`,e.style.border="solid 1px",e.style.borderColor=`${this.styles.backgroundColor} ${this.styles.backgroundColor} ${this.styles.color} ${this.styles.color}`,e.style.margin="0 auto",e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top="50%",e.style.transform="translateY(-50%) rotate(0deg)",e.style.transformStyle="preserve-3d",e.style.animation=`${f} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(n=>{e.style.setProperty(n,t[n])})}defineAnimation(){var e;if(document.getElementById(f))return;const t=document.createElement("style");t.id=f,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${f} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}const P={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class _ extends l{constructor(e){super(e||"An unexpected error has occurred during buy now cart creation process. Please try again later."),this.name="BuyNowCartCreationError",this.type="buy_now_cart_creation_error"}}const S={body:{},headers:{},status:0};class I extends l{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:o}=e||S;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}var C,w,O,A,z,E,k,T;!function(e){e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE"}(C||(C={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(w||(w={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(O||(O={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(A||(A={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(z||(z={})),function(e){e.pill="pill",e.rect="rect"}(E||(E={})),function(e){e.OXXO="oxxo"}(k||(k={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(T||(T={}));var M=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class B{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=n,this.bigCommercePaymentsScriptLoader=i}loadPayPalSdk(e,t,n,i){return M(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(a,o,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return M(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(m.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new _}})}createOrder(e,t){return M(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return M(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(e){return M(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow();let i;e||(i=t.getConsignmentsOrThrow()[0]);try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:e?[]:null==i?void 0:i.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:null==i?void 0:i.selectedShippingOption})}catch(e){throw new I}})}getOrderStatus(e,t){return M(this,void 0,void 0,function*(){try{const{status:n}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return n}catch(e){throw new I}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(m.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===C.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return M(this,void 0,void 0,function*(){const i={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,n;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:r}=e||{},a={color:t&&z[t]?t:void 0,height:this.getValidHeight(n),label:i&&A[i]?i:void 0,shape:r&&E[r]?r:void 0};return d(a,o)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}const F="This API endpoint is for internal use only and may change in the future";var D;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(D||(D={}));const N=D,U={"X-Checkout-SDK-Version":"1.960.0"};var x=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class j{constructor(e){this.requestSender=e}createOrder(e,t){return x(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":N.Json},U);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return x(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":F,"Content-Type":N.Json},U);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:n,body:t})).body})}getOrderStatus(){return x(this,arguments,void 0,function*(e="bigcommerce_payments",t){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":F,"Content-Type":N.Json},U);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}var L=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class V{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return L(this,void 0,void 0,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e){return L(this,arguments,void 0,function*(e,t=!1){if(!this.window.bigCommercePaymentsPayPalSDK||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.bigCommercePaymentsPayPalSDK)throw new c;return this.window.bigCommercePaymentsPayPalSDK})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new u(m.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:l,attributionId:c,isVenmoEnabled:h,isHostedCheckoutEnabled:y,isPayPalCreditAvailable:p,isDeveloperModeApplicable:g,availableAlternativePaymentMethods:v=[],enabledAlternativePaymentMethods:f=[],isGooglePayEnabled:b}=o,P=y||n,_="bigcommerce_payments_creditcards"===i,S=_?["card"]:[],I=_?[]:["card"],C=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],O=h?["venmo"]:[],A=h?[]:["venmo"],z=v.filter(e=>!f.includes(e)),E=b?["googlepay"]:[],k=n?["card-fields"]:[],T=this.filterFundingOptions([...I,...w,...A,...z]),M=this.filterFundingOptions([...S,...C,...O,...f]);return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":M.length>0?M:void 0,"disable-funding":T.length>0?T:void 0,commit:P,components:["buttons","hosted-fields","payment-fields","legal",...E,...k],currency:t,intent:a},g&&{"buyer-country":l}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"bigCommercePaymentsPayPalSDK"}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const R=e=>{const{getHost:r}=e.getState();return new B(n(),e,new j(i({host:r()})),new V(t()))},G=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};class W extends l{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class H extends W{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 K 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 $ extends l{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function Y(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function q(e){return Boolean(e.instrumentId)}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 J=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Q{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.paypalSdkHelper=n,this.loadingIndicator=i}initialize(e){return J(this,void 0,void 0,function*(){const{methodId:t,bigcommerce_payments:n}=e||{};if(this.bigcommerce_payments=n,!t)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{container:o,bannerContainerId:a}=n,{orderId:s,paypalBNPLConfiguration:d=[],isPayPalCreditAvailable:l}=r.initializationData||{};if(void 0!==a){if(!document.getElementById(a))return void console.error("Unable to create banner without valid banner container ID.");const e=null==d?void 0:d.find(({id:e})=>"checkout"===e);if(l||!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return t&&"function"==typeof(null==t?void 0:t.Messages)?this.renderMessages(t,a,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}s?this.orderId=s:(this.loadingIndicatorContainer=null==o?void 0:o.split("#")[1],yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t),n.onInit&&"function"==typeof n.onInit&&n.onInit(()=>this.renderButton(t,n)),(void 0===n.shouldRenderPayPalButtonOnInitialization||n.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(t,n))})}execute(e,t){return J(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{onError:r}=this.bigcommerce_payments||{};if(!n)throw new H(["payment"]);const{methodId:o,paymentData:a}=n;if(this.isPayPalVaultedInstrumentPaymentData(a)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new K;const s=this.isPayPalVaultedInstrumentPaymentData(a)?this.prepareVaultedInstrumentPaymentPayload(o,this.orderId,a):this.preparePaymentPayload(o,this.orderId,a);try{yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(s)}catch(e){return this.isProviderError(e)&&(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n.methodId),yield new Promise((e,t)=>{var i;this.bigcommerce_payments&&(null===(i=this.paypalButton)||void 0===i||i.close(),this.renderButton(n.methodId,this.bigcommerce_payments),this.handleError(new Error("INSTRUMENT_DECLINED"),r)),t()})),this.handleError(e,r),Promise.reject()}})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:i,shouldSetAsDefaultInstrument:r}=n,o=!this.isTrustedVaultingFlow(n);return o?{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:i}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:i=!1,shouldSetAsDefaultInstrument:r=!1}=Y(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t;if(!a)throw new W('Unable to initialize payment because "container" argument is not provided.');const m={fundingSource:n.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onError:e=>this.handleError(e,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(m),this.paypalButton.isEligible()&&(d&&"function"==typeof d&&d(),this.paypalButton.render(a))}handleClick(e,t){return J(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;yield null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return J(this,void 0,void 0,function*(){const e=this.getFieldsValues();return this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_paymentscheckout",{shouldSaveInstrument:(null==e?void 0:e.shouldSaveInstrument)||!1})})}getFieldsValues(){const{getFieldsValues:e}=this.bigcommerce_payments||{};return"function"==typeof e?e():void 0}isTrustedVaultingFlow(e){if(e&&q(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>Z(t)&&t.bigpayToken===e.instrumentId);return!(Z(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&q(e)&&Y(e)}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:G(n)};e.Messages(i).render(`#${t}`)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null===(i=null===(n=((null===(t=null==e?void 0:e.errors)||void 0===t?void 0:t.filter(e=>e.provider_error))||[])[0])||void 0===n?void 0:n.provider_error)||void 0===i?void 0:i.code)}}const X=g(e=>new Q(e,R(e),p(),new b({containerStyles:P})),[{id:"bigcommerce_payments"}]);var ee,te,ne,ie,re,oe,ae,se,de;!function(e){e.CVV="cvv",e.PAN="pan"}(ee||(ee={}));class le{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:o,domain:a,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}o&&(i+=`; path=${o}`),a&&(i+=`; domain=${a}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){le.set(e,"",Object.assign({expires:new Date(0)},t))}}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(te||(te={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ne||(ne={})),function(e){e.Always="SCA_ALWAYS"}(ie||(ie={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(re||(re={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(oe||(oe={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ae||(ae={})),function(e){e.pill="pill",e.rect="rect"}(se||(se={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(de||(de={}));var ce=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class me{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return ce(this,void 0,void 0,function*(){if(t&&(window.localStorage.setItem("fastlaneEnv","sandbox"),window.localStorage.setItem("axoEnv","sandbox")),!this.window.bigCommercePaymentsFastlane){const t={root:{backgroundColorPrimary:"transparent"}};this.window.bigCommercePaymentsFastlane=yield e.Fastlane({styles:n||t})}return this.window.bigCommercePaymentsFastlane})}getPayPalFastlaneOrThrow(){if(!this.window.bigCommercePaymentsFastlane)throw new c;return this.window.bigCommercePaymentsFastlane}lookupCustomerOrThrow(e){return ce(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return ce(this,void 0,void 0,function*(){return e?this.getPayPalFastlaneOrThrow().identity.triggerAuthenticationFlow(e):{}})}updateStorageSessionId(e){const t=new Date;t.setDate(t.getDate()+14);const n={expires:t,secure:!0};le.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){le.remove("bc-fastlane-sessionId")}getStorageSessionId(){return le.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,i,r;const{authenticationState:o,profileData:a}=t,s=null===(r=null===(i=null===(n=null==a?void 0:a.card)||void 0===n?void 0:n.paymentSource)||void 0===i?void 0:i.card)||void 0===r?void 0:r.billingAddress,d=null==a?void 0:a.shippingAddress,l=null==a?void 0:a.name,c=null==a?void 0:a.card,m=d?this.mapPayPalToBcAddress(d.address,d.name,d.phoneNumber):void 0,u=s&&l?this.mapPayPalToBcAddress(s,l,null==d?void 0:d.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([m,u]);return{authenticationState:o||de.UNRECOGNIZED,addresses:y,billingAddress:u,shippingAddress:m,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:i}=t,{brand:r,expiry:o,lastDigits:a}=i.card,[s,d]=o.split("-");return[{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:d,expiryYear:s,iin:"",last4:a,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode: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,n,i){const[r,o]=t.fullName.split(" "),a=(null==n?void 0:n.nationalNumber)||"",s=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||r||"",lastName:t.lastName||o||"",company:e.company||"",address1:e.addressLine1,address2:e.addressLine2||"",city:e.adminArea2,stateOrProvince:e.adminArea1,stateOrProvinceCode:e.adminArea1,country:e.countryCode||"",countryCode:e.countryCode||"",postalCode:e.postalCode,phone:s+a,customFields:i||[]}}filterAddresses(e){return e.reduce((e,t)=>t?e.some(e=>this.isEqualAddresses(e,t))?e:[...e,t]:e,[])}isEqualAddresses(e,t){return r(this.normalizeAddress(e),this.normalizeAddress(t))}normalizeAddress(e){return s(e,["id","phone"])}}function ue(){return new me}function he(e){return"string"!=typeof e}function ye(e,t){if(t||e)return function(e){var t,n;const i={},r=d(e.root,he),o=d(e.input,he),a=d(e.toggle,he),s=d(null===(t=e.text)||void 0===t?void 0:t.body,he),l=d(null===(n=e.text)||void 0===n?void 0:n.caption,he),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(o).length&&(i.input=o),Object.keys(a).length&&(i.toggle=a),Object.keys(s).length&&(i.text={},i.text.body=s),Object.keys(l).length&&(i.text=Object.assign({},i.text),i.text.caption=l),c&&(i.branding=c),i}(function(e,t){var n,i,r,o,a,s,d,l,c,m,u,h,y,p,g,v,f,b,P,_,S,I;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null===(n=null==t?void 0:t.root)||void 0===n?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null===(i=null==t?void 0:t.root)||void 0===i?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null===(r=null==t?void 0:t.root)||void 0===r?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null===(o=null==t?void 0:t.root)||void 0===o?void 0:o.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null===(a=null==t?void 0:t.root)||void 0===a?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null===(s=null==t?void 0:t.root)||void 0===s?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null===(d=null==t?void 0:t.input)||void 0===d?void 0:d.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null===(l=null==t?void 0:t.input)||void 0===l?void 0:l.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null===(c=null==t?void 0:t.input)||void 0===c?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null===(m=null==t?void 0:t.input)||void 0===m?void 0:m.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null===(u=null==t?void 0:t.input)||void 0===u?void 0:u.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null===(h=null==t?void 0:t.input)||void 0===h?void 0:h.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null===(y=null==t?void 0:t.toggle)||void 0===y?void 0:y.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null===(p=null==t?void 0:t.toggle)||void 0===p?void 0:p.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===(b=null===(f=null==t?void 0:t.text)||void 0===f?void 0:f.body)||void 0===b?void 0:b.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null===(_=null===(P=null==t?void 0:t.text)||void 0===P?void 0:P.caption)||void 0===_?void 0:_.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null===(I=null===(S=null==t?void 0:t.text)||void 0===S?void 0:S.caption)||void 0===I?void 0:I.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function pe(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}function ge(e,t,n=!0){var i;return null!==(i=e[t])&&void 0!==i?i:n}var ve=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class fe{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsRequestSender=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return ve(this,void 0,void 0,function*(){var t,n;const{methodId:i,bigcommerce_payments_fastlane:r}=e;if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(this.methodId=i,!r)throw new W('Unable to initialize payment because "options.bigcommerce_payments_fastlane" argument is not provided.');if(this.bigcommerce_payments_fastlane=r,!r.onInit||"function"!=typeof r.onInit)throw new W('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onInit" argument is not provided or it is not a function.');if(!r.onChange||"function"!=typeof r.onChange)throw new W('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(i);const o=this.paymentIntegrationService.getState(),a=o.getCartOrThrow(),s=o.getPaymentMethodOrThrow(i),{isDeveloperModeApplicable:d,isFastlaneStylingEnabled:l}=s.initializationData||{};this.threeDSVerificationMethod=null===(t=s.initializationData)||void 0===t?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(s,a.currency.code,a.id);const c=ye(l?null===(n=null==s?void 0:s.initializationData)||void 0===n?void 0:n.fastlaneStyles:{},null==r?void 0:r.styles);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!d,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(i)),yield this.initializePayPalPaymentComponent(),r.onInit(e=>this.renderPayPalPaymentComponent(e)),r.onChange(()=>this.handlePayPalStoredInstrumentChange(i))})}execute(e,t){return ve(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);const{paymentData:r,methodId:o}=n,a=r&&q(r);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=a?yield this.prepareVaultedInstrumentPaymentPayload(o,r):yield this.preparePaymentPayload(o,r);yield this.paymentIntegrationService.submitPayment(e),this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()}catch(e){if(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"response"in e&&"name"in e.response}(e)&&"INVALID_REQUEST"===e.response.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 $)}deinitialize(){return ve(this,void 0,void 0,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=pe(i)?i:{},o=this.bigCommercePaymentsFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===de.CANCELED||(null==r?void 0:r.authenticationState)||o!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return ve(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(a),{authenticationState:d,addresses:l,instruments:c}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:d,addresses:l,instruments:c}),s.authenticationState===de.CANCELED?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return ve(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),i=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),r={fields:Object.assign({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield i.FastlaneCardComponent(r)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new W('Unable to render card component because "container" argument is not provided.');t.render(e)}getPayPalComponentMethodsOrThrow(){if(!this.paypalComponentMethods)throw new c;return this.paypalComponentMethods}prepareVaultedInstrumentPaymentPayload(e,t){return ve(this,void 0,void 0,function*(){const{instrumentId:n}=t,i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),r=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&i.config.is3dsEnabled?yield this.get3DSNonce(n):n;return yield this.createOrder(r),{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:r}}}}})}preparePaymentPayload(e,t){return ve(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getPaymentMethodOrThrow(e),o=`${i.firstName} ${i.lastName}`.trim(),{getPaymentToken:a}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield a({name:{fullName:o},billingAddress:this.bigCommercePaymentsFastlaneUtils.mapBcToPayPalAddress(i)}),d=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&r.config.is3dsEnabled,{shouldSaveInstrument:l=!1,shouldSetAsDefaultInstrument:c=!1}=Y(t)?t:{},m=d?yield this.get3DSNonce(s):s;return yield this.createOrder(m),{methodId:e,paymentData:Object.assign(Object.assign({},t),{shouldSaveInstrument:l,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:m}}})}})}createOrder(e){return ve(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState().getCartOrThrow().id;if(this.methodId){const{orderId:n}=yield this.bigCommercePaymentsRequestSender.createOrder(this.methodId,{cartId:t,fastlaneToken:e});this.orderId=n}})}get3DSNonce(e){return ve(this,void 0,void 0,function*(){var t;const n=this.paymentIntegrationService.getState(),i=n.getCartOrThrow(),r=n.getOrderOrThrow(),o=n.getStoreConfigOrThrow().links.checkoutLink,a=null===(t=this.paypalFastlaneSdk)||void 0===t?void 0:t.ThreeDomainSecureClient;if(!a)throw new c;const s={amount:r.orderAmount.toFixed(2),currency:i.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===ie.Always,transactionContext:{experience_context:{locale:"en-US",return_url:o,cancel_url:o}}},d=yield a.isEligible(s);if(this.threeDSVerificationMethod===ie.Always&&!d)throw new K;if(d){const{liabilityShift:e,authenticationState:t,nonce:n}=yield a.show();if(e===w.No||e===w.Unknown||t===re.Errored||t===re.Cancelled)throw new K;if(t===re.Succeeded&&[w.Yes,w.Possible].includes(e))return n}return e})}handlePayPalStoredInstrumentChange(e){return ve(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=pe(t)?t:{},r=this.bigCommercePaymentsFastlaneUtils.mapPayPalToBcInstrument(e,i)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Object.assign(Object.assign({},n),{instruments:[r]})),r}})}isBigcommercePaymentsFastlaneThreeDSAvailable(){return ge(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.bcp_fastlane_three_ds")}handleError(e){var t;(null===(t=this.bigcommerce_payments_fastlane)||void 0===t?void 0:t.onError)&&"function"==typeof this.bigcommerce_payments_fastlane.onError&&this.bigcommerce_payments_fastlane.onError(e)}handleErrorLog(e){var t;(null===(t=this.bigcommerce_payments_fastlane)||void 0===t?void 0:t.onErrorLog)&&"function"==typeof this.bigcommerce_payments_fastlane.onErrorLog&&this.bigcommerce_payments_fastlane.onErrorLog(e)}}const be=g(e=>{const{getHost:t}=e.getState();return new fe(e,new j(i({host:t()})),p(),ue())},[{id:"bigcommerce_payments_fastlane"}]);class Pe extends l{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var _e=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Se{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.paypalSdkHelper=i}initialize(e){return _e(this,void 0,void 0,function*(){const{methodId:t,bigcommerce_payments_paylater:n}=e||{};if(!t)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:o=[],orderId:a}=r.initializationData||{},{bannerContainerId:s,container:d}=n;if(void 0!==s){if(!document.getElementById(s))return void console.error("Unable to create banner without valid banner container ID.");const e=o&&o.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return this.renderMessages(t,s,e)}a?this.orderId=a:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==d?void 0:d.split("#")[1],this.renderButton(t,n))})}execute(e,t){return _e(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);if(!this.orderId)throw new K;yield this.paymentIntegrationService.submitOrder(i,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.bigCommercePaymentsButtons)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new W('Unable to initialize payment because "container" argument is not provided.');const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,m=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let u=!1;m.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),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.bigCommercePaymentsButtons=n.Buttons(t),this.bigCommercePaymentsButtons.isEligible()||e!==n.FUNDING.PAYLATER){if(!this.bigCommercePaymentsButtons.isEligible()&&e===n.FUNDING.CREDIT)throw new Pe(`BigCommercePayments ${e} is not available for your region. Please use BigCommercePayments Checkout instead.`);d&&"function"==typeof d&&d(),this.bigCommercePaymentsButtons.render(a),u=!0}})}handleClick(e,t){return _e(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;t&&"function"==typeof t&&(yield t(()=>(this.toggleLoadingIndicator(!0),n()),i))})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:G(n)};e.Messages(i).render(`#${t}`)}}const Ie=g(e=>new Se(e,R(e),new b({containerStyles:P}),p()),[{id:"bigcommerce_payments_paylater"}]);class Ce extends I{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var we=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Oe{constructor(e,t,n,i=3e3,r=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.pollingInterval=i,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=a}initialize(e){return we(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_ratepay:i}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_payments_ratepay" argument is not provided.');const{legalTextContainer:r,container:o,loadingContainerId:a}=i;if(!o)throw new W('Unable to initialize payment because "options.container" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!a)throw new W('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=a;const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:d}=s.initializationData||{};if(!d)throw new W("Unable to initialize payment because merchantId argument is not provided.");this.bigcommerce_payments_ratepay=i,yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n),this.createFraudNetScript(d,n,t),this.loadFraudnetConfig(),this.renderLegalText(r,o)})}execute(e,t){return we(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{getFieldsValues:r}=this.bigcommerce_payments_ratepay||{};if(!n)throw new H(["payment"]);if(!r||"function"!=typeof r)throw new W('Unable to initialize payment because "options.getFieldsValues" argument is not provided.');this.toggleLoadingIndicator(!0);try{const e=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apmscheckout",{metadataId:this.guid}),{ratepayBirthDate:o,ratepayPhoneNumber:a,ratepayPhoneCountryCode:s}=r(),d={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:n.methodId,rate_pay:{birth_date:this.normalizeDate(o),phone:{national_number:a,country_code:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:n.methodId,paymentData:d}),yield new Promise((e,t)=>{this.initializePollingMechanism(n.methodId,e,t,n.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new $)}deinitialize(){const{legalTextContainer:e}=this.bigcommerce_payments_ratepay||{},t=document.querySelectorAll('[data-id="fraudnetScript"]')[0],n=document.querySelectorAll('[data-id="fraudnetConfig"]')[0];if(this.deinitializePollingMechanism(),t.remove(),n.remove(),e){const t=document.getElementById(e);null==t||t.remove()}return Promise.resolve()}normalizeDate(e){const t=this.formatDate(e.getDate()),n=this.formatDate(e.getMonth()+1);return`${e.getFullYear()}-${n}-${t}`}formatDate(e){return`${e<10?0:""}${e}`}renderLegalText(e,t){const n=e,i=t.split("#")[1],r=document.getElementById(i),o=null==r?void 0:r.parentNode,a=document.createElement("div");a.style.marginBottom="20px",a.setAttribute("id",n),null==o||o.prepend(a);const s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new W('Unable to initialize payment because "legalTextContainerElement" argument is not found.');d.render(`#${n}`)}handleError(e){const{onError:t}=this.bigcommerce_payments_ratepay||{};this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createFraudNetScript(e,t,n){const i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:r}=i.config,o=document.createElement("script");o.setAttribute("type","application/json"),o.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),o.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const a={f:this.guid,s:`${e}_checkout-page`,sandbox:r};o.innerHTML=JSON.stringify(a),document.body.appendChild(o)}generateGUID(){let e="";for(let t=0;t<32;t+=1)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(62*Math.random())];return e}loadFraudnetConfig(){const e=document.createElement("script");e.setAttribute("data-id","fraudnetConfig"),e.src="https://c.paypal.com/da/r/fb.js",document.body.appendChild(e)}reinitializeStrategy(e){return we(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return we(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus("bigcommerce_payments_apms",{params:{useMetadata:!0}}),o=r===T.PollingStop,a=r===T.PollingError;if(o)return this.deinitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigcommerce_payments_ratepay:this.bigcommerce_payments_ratepay}),this.handleError(new Ce)}catch(e){this.handleError(e),n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const Ae=g(e=>new Oe(e,R(e),new b({containerStyles:Object.assign(Object.assign({},P),{position:"fixed"})})),[{gateway:"bigcommerce_payments_apms",id:"ratepay"}]);var ze;!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 Ee=ze;function ke(e){return Ee.CardNumber in e&&Ee.CardName in e&&Ee.CardExpiry in e}function Te(e){return Ee.CardNumberVerification in e&&Ee.CardCodeVerification in e&&Ee.CardExpiryVerification in e}class Me extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method has thrown an unexpected error."),this.name="PaymentMethodFailedError",this.type="payment_method_client_invalid"}}var Be;!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"}(Be||(Be={}));class Fe extends l{constructor(e){super(function(e){switch(e){case Be.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Be.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Be.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Be.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 De extends l{constructor(e,t){super(t||"Unable to proceed because the payment form contains invalid data."),this.details=e,this.name="PaymentInvalidFormError",this.type="payment_invalid_form"}}var Ne=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ue{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return Ne(this,void 0,void 0,function*(){const{methodId:t,bigcommerce_payments_creditcards:n}=e,i=n,{form:r,onCreditCardFieldsRenderingError:o,onLoadComplete:a}=i||{};if(!t)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to proceed because "options.bigcommerce_payments_creditcards.form" argument is not provided.');this.hostedFormOptions=r,this.isCreditCardForm=ke(r.fields),this.isCreditCardVaultedForm=Te(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,o)),null==a||a(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Ne(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{methodId:r,paymentData:o}=n||{};if(!n||!r)throw new H(["payment"]);if(this.executionPaymentData=o,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const a=this.preparePaymentPayload(r,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(a)})}finalize(){return Promise.reject(new $)}deinitialize(){return Ne(this,void 0,void 0,function*(){var e,t,n,i;return yield null===(e=this.cvvField)||void 0===e?void 0:e.close(),yield null===(t=this.expiryField)||void 0===t?void 0:t.close(),yield null===(n=this.numberField)||void 0===n?void 0:n.close(),yield null===(i=this.nameField)||void 0===i?void 0:i.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,i){const{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:a=!1}=Y(t)?t:{},s=t&&q(t)?t.instrumentId:void 0,l=d({verification_nonce:i,token:s},o);return{methodId:e,paymentData:{shouldSaveInstrument:r,shouldSetAsDefaultInstrument:a,instrumentId:s,formattedPayload:Object.assign(Object.assign({},i||s?{bigpay_token:l}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Ne(this,void 0,void 0,function*(){const{fields:n,styles:i}=e,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.getExecuteCallback(n),a=Object.assign({style:this.getInputStyles(i),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===w.No||n===w.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Me},inputEvents:{onChange:t=>this.onChangeHandler(e,t),onFocus:t=>this.onFocusHandler(e,t),onBlur:t=>this.onBlurHandler(e,t),onInputSubmitRequest:t=>this.onInputSubmitRequest(e,t)}},o);if(this.cardFields=yield r.CardFields(a),!this.cardFields.isEligible())throw new Fe(Be.PaymentNotInitialized);try{this.stylizeInputContainers(n),ke(n)&&(yield this.renderFields(n)),Te(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Te(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Ne(this,void 0,void 0,function*(){const{setupToken:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",Object.assign(Object.assign({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Ne(this,void 0,void 0,function*(){const{orderId:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams()))||{};return e})}}handleApprove({orderID:e,vaultSetupToken:t}){e&&(this.returnedOrderId=e),t&&(this.returnedVaultedToken=t)}renderFields(e){return Ne(this,void 0,void 0,function*(){var t,n,i,r;const o=this.getCardFieldsOrThrow();(null===(t=e.cardCode)||void 0===t?void 0:t.containerId)&&(this.cvvField=o.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null===(n=e.cardExpiry)||void 0===n?void 0:n.containerId)&&(this.expiryField=o.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null===(i=e.cardName)||void 0===i?void 0:i.containerId)&&(this.nameField=o.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null===(r=e.cardNumber)||void 0===r?void 0:r.containerId)&&(this.numberField=o.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return Ne(this,void 0,void 0,function*(){var t,n,i;const r=this.getCardFieldsOrThrow();(null===(t=e.cardCodeVerification)||void 0===t?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null===(n=e.cardExpiryVerification)||void 0===n?void 0:n.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null===(i=e.cardNumberVerification)||void 0===i?void 0:i.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(Y(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(q(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return Ne(this,void 0,void 0,function*(){const e=this.getCardFieldsOrThrow(),t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n={billingAddress:{company:t.company,addressLine1:t.address1,addressLine2:t.address2,adminArea1:t.stateOrProvinceCode,adminArea2:t.city,postalCode:t.postalCode,countryCode:t.countryCode}};try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){throw new Me("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Ne(this,void 0,void 0,function*(){var e,t;const n=this.getCardFieldsOrThrow(),i=yield n.getState().then(e=>e),r=this.getValidityData(i);if(!r.isValid)throw null===(t=null===(e=this.hostedFormOptions)||void 0===e?void 0:e.onValidate)||void 0===t||t.call(e,r),new De(this.mapValidationErrors(r.errors))})}getValidityData({fields:e}){const t=Object.assign({},e);delete t.cardNameField;const n=Object.keys(t);return{isValid:n.every(e=>{var n;return null===(n=t[e])||void 0===n?void 0:n.isValid}),errors:n.reduce((e,n)=>{var i;const r=this.mapFieldType(n);return Object.assign(Object.assign({},e),{[r]:(null===(i=t[n])||void 0===i?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case Ee.CardCode:case Ee.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case Ee.CardNumber:case Ee.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case Ee.CardExpiry:case Ee.CardExpiryVerification:return{fieldType:e,message:"Invalid card expiry",type:"invalid_card_expiry"};default:return{fieldType:e,message:"Invalid field",type:"invalid"}}}mapValidationErrors(e={}){const t={};return Object.keys(e).forEach(n=>{var i,r;t[n]=[{message:(null===(r=null===(i=e[n])||void 0===i?void 0:i[0])||void 0===r?void 0:r.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return Ee.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?Ee.CardNumber:Ee.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?Ee.CardExpiry:Ee.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?Ee.CardCode:Ee.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Fe(Be.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,i;const r={"font-size":(null===(t=null==e?void 0:e.default)||void 0===t?void 0:t.fontSize)||"1rem","font-family":(null===(n=null==e?void 0:e.default)||void 0===n?void 0:n.fontFamily)||"Montserrat, Arial, Helvetica, sans-serif","font-weight":(null===(i=null==e?void 0:e.default)||void 0===i?void 0:i.fontWeight)||"400",outline:"none",padding:"9px 13px"},o=Object.assign(Object.assign({},r),{color:"#333333"});return{input:o,".invalid":Object.assign(Object.assign({},r),{color:"red"}),".valid":o,":focus":o}}stylizeInputContainers(e){Object.values(e||{}).forEach(e=>{const t=document.getElementById(`${(null==e?void 0:e.containerId)||""}`);t&&(t.style.padding="0px",t.style.boxShadow="none",t.style.border="none",t.style.background="transparent",t.style.marginBottom="10px",t.style.marginLeft="-5px")})}hasUndefinedValues(){return!this.hostedFormOptions||Object.values(this.hostedFormOptions.fields).some(e=>void 0===e)}onChangeHandler(e,t){var n;null===(n=null==e?void 0:e.onValidate)||void 0===n||n.call(e,this.getValidityData(t))}onFocusHandler(e,t){var n;null===(n=null==e?void 0:e.onFocus)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onBlurHandler(e,t){var n;null===(n=null==e?void 0:e.onBlur)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onInputSubmitRequest(e,t){var n;null===(n=null==e?void 0:e.onEnter)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}shouldInitializePayPalFastlane(e){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(e),o=i.getPaymentProviderCustomer(),a=(s=o)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?o:{};var s;return(null===(t=null==r?void 0:r.initializationData)||void 0===t?void 0:t.isAcceleratedCheckoutEnabled)&&(null===(n=null==r?void 0:r.initializationData)||void 0===n?void 0:n.isBigCommercePaymentsAnalyticsV2Enabled)&&!(null==a?void 0:a.authenticationState)}initializePayPalFastlaneOrThrow(e){return Ne(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{initializationData:r}=i;if(!(null==r?void 0:r.connectClientToken))return;const o=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(i,n.currency.code,n.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(o,!!(null==r?void 0:r.isDeveloperModeApplicable))}catch(e){}})}}const xe=g(e=>new Ue(e,R(e),p(),ue()),[{id:"bigcommerce_payments_creditcards"}]);var je=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Le{constructor(e){this.paymentIntegrationService=e}initialize(){return je(this,void 0,void 0,function*(){return Promise.resolve()})}execute(e,t){return je(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{methodId:r}=n||{};if(!n||!r)throw new H(["payment"]);const o={methodId:r,paymentData:{formattedPayload:{}}};yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(o)})}finalize(){return Promise.reject(new $)}deinitialize(){return Promise.resolve()}}const Ve=g(e=>new Le(e),[{id:"bigcommerce_payments_invoices"}]);var Re=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ge{constructor(e,t,n,i,r=3e3,o=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdkHelper=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=o,this.pollingTimer=0,this.stopPolling=a,this.isPollingEnabled=!1}initialize(e){return Re(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(n,t),{orderId:a,shouldRenderFields:s}=o.initializationData||{},d=r.getStoreConfigOrThrow().checkoutSettings.features;this.isPollingEnabled=ge(d,"PAYPAL-5624.bcp_ideal_polling"),a?this.orderId=a:(this.paypalApms=yield this.bigCommercePaymentsSdkHelper.getPayPalApmsSdk(o,r.getCartOrThrow().currency.code),this.loadingIndicatorContainer=i.container.split("#")[1],this.renderButton(n,t,i),s&&this.renderFields(n,i))})}execute(e,t){return Re(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);const{methodId:r,gatewayId:o}=n;if(!this.orderId)throw new K;this.isPollingEnabled&&"ideal"===r&&(yield new Promise((e,t)=>{this.initializePollingMechanism(r,e,t,o)})),this.isNonInstantPaymentMethod(r)||(yield this.paymentIntegrationService.submitOrder(i,t)),yield this.bigCommercePaymentsIntegrationService.submitPayment(r,this.orderId,o)})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,this.isPollingEnabled&&this.resetPollingMechanism(),null===(e=this.bigCommercePaymentsButton)||void 0===e||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,i){return Re(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus(i),o=r===T.Approved,a=r===T.PollingError;if(o)return this.deInitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigCommercePaymentsAlternativeMethods:this.bigCommercePaymentsAlternativeMethods}),this.handleError(new Ce)}catch(e){n()}})}deInitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deInitializePollingMechanism()}reinitializeStrategy(e){return Re(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderButton(e,t,n){const i=this.getPaypalAmpsSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:o}=r.initializationData||{},{container:a,onError:s,onRenderButton:d,submitForm:l}=n,c={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),onInit:(e,t)=>n.onInitButton(t),createOrder:()=>this.onCreateOrder(e,t,n),onApprove:e=>this.handleApprove(e,l),onCancel:()=>{this.toggleLoadingIndicator(!1),this.deInitializePollingMechanism()},onError:e=>{this.deInitializePollingMechanism(),this.handleFailure(e,s)},onClick:(e,t)=>Re(this,void 0,void 0,function*(){return n.onValidate(t.resolve,t.reject)})};this.bigCommercePaymentsButton=i.Buttons(c),this.bigCommercePaymentsButton.isEligible()&&(d&&"function"==typeof d&&d(),this.bigCommercePaymentsButton.render(a))}onCreateOrder(e,t,n){return Re(this,void 0,void 0,function*(){const{onValidate:i}=n;yield i(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),a);const r=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms");if(this.isNonInstantPaymentMethod(e)){const n={useStoreCredit:!1},i={params:{methodId:e,gatewayId:t}};yield this.paymentIntegrationService.submitOrder(n,i),yield this.bigCommercePaymentsIntegrationService.submitPayment(e,r,t)}return r})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const n=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState(),{firstName:r,lastName:o,email:a}=i.getBillingAddressOrThrow(),{apmFieldsContainer:s,apmFieldsStyles:d}=t;if(!s)throw new W('Unable to initialize payment because "options.bigcommerce_payments_apms" argument should contain "apmFieldsContainer".');const l=document.querySelector(s);l&&(l.innerHTML="");const c={fundingSource:e,style:d||{},fields:{name:{value:`${r} ${o}`},email:{value:a}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in k}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const We=g(e=>new Ge(e,R(e),p(),new b({containerStyles:P})),[{gateway:"bigcommerce_payments_apms"}]);class He{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.gatewayId" argument is not provided.');return Promise.resolve()}execute(e,t){return n=this,i=void 0,o=function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);const{methodId:r,gatewayId:o}=n;try{const e={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:r,paypal_account:{order_id:yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms",{gatewayId:"bigcommerce_payments_apms",methodId:r})}}};yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:r,gatewayId:o,paymentData:e})}catch(e){if(function(e){var t,n;return(e=>"object"==typeof e&&null!==e&&"body"in e)(e)&&(null===(n=null===(t=e.body)||void 0===t?void 0:t.additional_action_required)||void 0===n?void 0:n.data.redirect_url)}(e)){const t=e.body.additional_action_required.data.redirect_url;return new Promise((e,n)=>{window.location.replace(t),n()})}return this.handleError(e),Promise.reject(e)}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}finalize(){return Promise.reject(new $)}deinitialize(){return Promise.resolve()}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};t&&"function"==typeof t&&t(e)}}const Ke=g(e=>new He(e,R(e)),[{gateway:"bigcommerce_payments_apms",id:"klarna"},{gateway:"bigcommerce_payments_apms",id:"afterpay"}]);var $e=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ye{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n}initialize(e){return $e(this,void 0,void 0,function*(){var t,n;const{methodId:i,bigcommerce_payments_venmo:r}=e||{};if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i);(null===(t=o.initializationData)||void 0===t?void 0:t.orderId)?this.orderId=null===(n=o.initializationData)||void 0===n?void 0:n.orderId:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i),this.loadingIndicatorContainer=r.container.split("#")[1],this.renderButton(i,r))})}execute(e,t){return $e(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);if(!this.orderId)throw new K;yield this.paymentIntegrationService.submitOrder(i,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,m={fundingSource:n.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmocheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=n.Buttons(m),!this.paypalButton.isEligible())throw new Pe("Venmo is not available for your region. Please another payment method instead.");d&&"function"==typeof d&&d(),this.paypalButton.render(a)}handleClick(e,t){return $e(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;yield t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t(),this.toggleLoadingIndicator(!1)}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const qe=g(e=>new Ye(e,R(e),new b({styles:{backgroundColor:"black"}})),[{id:"bigcommerce_payments_venmo"}]);var Ze=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Je{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=a}initialize(e){return Ze(this,void 0,void 0,function*(){const{bigcommerce_payments:t,methodId:n}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(!t.container)throw new W('Unable to initialize payment because "options.bigcommerce_payments.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new W('Unable to initialize payment because "options.bigcommerce_payments.onClick" argument is not a function.');this.onError=t.onError||a,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i,onComplete:r}=t,o=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:l}=a.initializationData||{},{checkoutTopButtonStyles:c}=d||{},m=Object.assign({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),u=Object.assign(Object.assign({},!l&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,r,l)}),h=Object.assign(Object.assign({fundingSource:o.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},c),{height:40}))},m),s&&u),y=o.Buttons(h);y.isEligible()?y.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i,r){return Ze(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}a&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return Ze(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}onShippingOptionsChange(e){return Ze(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const Qe=g(e=>new Je(e,R(e)),[{id:"bigcommerce_payments"}]);var Xe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class et{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsSdk=t,this.bigCommercePaymentsFastlaneUtils=n}initialize(e){return Xe(this,void 0,void 0,function*(){var t;const{methodId:n,bigcommerce_payments_fastlane:i}=e;if(this.options=e,!n)throw new W('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),r=e.getCartOrThrow(),o=e.getPaymentMethodOrThrow(n),a=!!(null===(t=o.initializationData)||void 0===t?void 0:t.isDeveloperModeApplicable),s=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(o,r.currency.code,r.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(s,a,this.getFastlaneStyles(n,i))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Xe(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return Xe(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.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()})}signOut(e){return Xe(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Xe(this,void 0,void 0,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:i}=e||{};if(!i)throw new W('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new W('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');if(this.paymentIntegrationService.getState().getCustomerOrThrow().isGuest){t&&"function"==typeof t&&t();try{yield this.runPayPalAuthenticationFlowOrThrow(i)}catch(e){this.handleErrorLog(e)}}n()})}runPayPalAuthenticationFlowOrThrow(e){return Xe(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(a),d=s.authenticationState===de.CANCELED;yield this.updateCustomerDataState(e,s),d?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Xe(this,void 0,void 0,function*(){var n;const i=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:r,addresses:o,billingAddress:a,shippingAddress:s,instruments:d}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:r,addresses:o,instruments:d}),a&&(yield this.paymentIntegrationService.updateBillingAddress(a)),s&&i.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),i=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:r}=i.initializationData||{},o=(null===(n=(t.getConsignments()||[])[0])||void 0===n?void 0:n.availableShippingOptions)||[],a=o[0],d=o.find(e=>e.isRecommended);if((d||a)&&r){const e=(null==d?void 0:d.id)||a.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:i,isFastlaneStylingEnabled:r}=n.initializationData||{};return ye(r?i:{},null==t?void 0:t.styles)}handleErrorLog(e){const{onErrorLog:t}=this.options||{};t&&"function"==typeof t&&t(e)}}const tt=g(e=>new et(e,p(),ue()),[{id:"bigcommerce_payments_fastlane"},{id:"bigcommerce_payments_creditcards"}]);var nt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class it{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=a}initialize(e){return nt(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,methodId:n}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(!t.container)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.onClick" argument is not a function.');this.onError=t.onError||a,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC BigCommercePayments PayLater]: button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return nt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return nt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onComplete:i,onClick:r}=t,o=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d}=a.initializationData||{},{checkoutTopButtonStyles:l}=d||{},c=Object.assign({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()}),m={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,i)},u=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let h=!1;u.forEach(e=>{if(!h){const t=Object.assign(Object.assign({fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},l),{height:40}))},c),s&&m),i=o.Buttons(t);i.isEligible()&&(i.render(`#${n}`),h=!0)}}),h||this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i){return nt(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return nt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}onShippingOptionsChange(e){return nt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const rt=g(e=>new it(e,R(e)),[{id:"bigcommerce_payments_paylater"}]);var ot=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class at{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return ot(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,methodId:n}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(!t.container)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC Payments Venmo]: 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:n,onClick:i}=t,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:a}=o.initializationData||{},{checkoutTopButtonStyles:s}=a||{},d=Object.assign({fundingSource:r.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},s),{height:40})),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),l=r.Buttons(d);l.isEligible()?l.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}}const st=g(e=>new at(e,R(e)),[{id:"bigcommerce_payments_venmo"}]);var dt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class lt{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return dt(this,void 0,void 0,function*(){var t;const{bigcommerce_payments:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(o&&!n.currencyCode)throw new W('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new W('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c}=d.initializationData||{},m={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},u={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h=Object.assign(Object.assign({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o,c)}),y=Object.assign(Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},m),i&&u),l&&h),p=s.Buttons(y);p.isEligible()?p.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return dt(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i,r){return dt(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}return a&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return dt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return dt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}}const ct=g(e=>new lt(e,R(e)),[{id:"bigcommerce_payments"}]);var mt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ut{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return mt(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(a&&!o)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=this.paymentIntegrationService.getState(),d=a?o:s.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l}=d.initializationData||{},c={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},m={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)},h=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let y=!1;h.forEach(t=>{if(!y){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},c),i&&m),l&&u),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),y=!0):a&&"function"==typeof a&&a()}}),y||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return mt(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return mt(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return mt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}}const ht=g(e=>new ut(e,R(e)),[{id:"bigcommerce_payments_paylater"}]);var yt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class pt{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return yt(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(a&&!o)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&l),m=a.Buttons(c);m.isEligible()?m.render(`#${e}`):o&&"function"==typeof o?o():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===z.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return yt(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const gt=g(e=>new pt(e,R(e)),[{id:"bigcommerce_payments_venmo"}]);var vt,ft,bt,Pt,_t,St,It,Ct,wt,Ot;!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(vt||(vt={})),(ft||(ft={})).Always="SCA_ALWAYS",function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(bt||(bt={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(Pt||(Pt={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(_t||(_t={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(St||(St={})),function(e){e.pill="pill",e.rect="rect"}(It||(It={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(Ct||(Ct={})),(wt||(wt={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Ot||(Ot={}));var At=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class zt{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,i){return At(this,void 0,void 0,function*(){return this.paypalSdk=yield this.scriptLoader.getPayPalSDK(e,t,void 0,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}proxyTokenizationPayment(e,t,n,i){return At(this,void 0,void 0,function*(){var r;if(!i)throw new u(m.MissingOrderId);const o={paymentWalletData:{providerId:t,providerOrderId:i},cartEntityId:e,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:n},{key:"order_id",value:i}]},a=yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(o);if(!(null===(r=a.body.redirectUrls)||void 0===r?void 0:r.externalCheckoutUrl))throw new Error("Failed to redirection to checkout page");window.location.assign(a.body.redirectUrls.externalCheckoutUrl)})}createPaymentOrderIntent(e,t,n){return At(this,void 0,void 0,function*(){const i={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(i,this.intentTypename,n)).body.orderId})}addBillingAddress(e,t,n){return At(this,void 0,void 0,function*(){return this.walletButtonIntegrationService.addBillingAddress(e,t,n)})}mapOrderDetailsToBillingAddress({payer:e}){var t,n,i,r;return{firstName:e.name.given_name,lastName:e.name.surname,company:"",address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,email:e.email_address,stateOrProvince:null!==(t=e.address.admin_area_1)&&void 0!==t?t:"",stateOrProvinceCode:null!==(n=e.address.admin_area_1)&&void 0!==n?n:"",countryCode:e.address.country_code,postalCode:e.address.postal_code,phone:null!==(r=null===(i=e.phone)||void 0===i?void 0:i.phone_number.national_number)&&void 0!==r?r:"",shouldSaveAddress:!1}}getValidButtonStyle(e={}){const{color:t,height:n,label:i,shape:r}=e,a={color:t&&St[t]?t:void 0,height:this.getValidHeight(n),label:i&&_t[i]?i:void 0,shape:r&&It[r]?r:void 0};return d(a,o)}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 Et=["ar_BH","ar_DZ","ar_EG","ar_JO","ar_KW","ar_MA","ar_OM","ar_QA","ar_SA","ar_TN","ar_YE","ar_AE","bg_BG","cs_CZ","da_DK","da_FO","da_GL","de_AT","de_CH","de_DE","de_LU","el_GR","en_AD","en_AE","en_AG","en_AI","en_AL","en_AM","en_AN","en_AO","en_AT","en_AU","en_AW","en_AZ","en_BB","en_BE","en_BH","en_BJ","en_BM","en_BN","en_BS","en_BT","en_BW","en_BY","en_BZ","en_C2","en_CA","en_CD","en_CG","en_CH","en_CI","en_CK","en_CL","en_CM","en_CN","en_CO","en_CR","en_CV","en_CY","en_CZ","en_DE","en_DJ","en_DK","en_DM","en_DO","en_DZ","en_EC","en_EE","en_EG","en_ER","en_ES","en_ET","en_FI","en_FJ","en_FK","en_FM","en_FO","en_FR","en_GA","en_GB","en_GD","en_GE","en_GF","en_GI","en_GL","en_GM","en_GN","en_GP","en_GR","en_GT","en_GW","en_GY","en_HK","en_HN","en_HR","en_HU","en_ID","en_IE","en_IL","en_IN","en_IS","en_IT","en_JM","en_JO","en_JP","en_KE","en_KG","en_KH","en_KI","en_KM","en_KN","en_KR","en_KW","en_KY","en_KZ","en_LA","en_LC","en_LI","en_LK","en_LS","en_LT","en_LU","en_LV","en_MA","en_MC","en_MD","en_ME","en_MG","en_MH","en_MK","en_ML","en_MN","en_MQ","en_MR","en_MS","en_MT","en_MU","en_MV","en_MW","en_MY","en_MZ","en_NA","en_NC","en_NE","en_NF","en_NG","en_NI","en_NL","en_NO","en_NP","en_NR","en_NU","en_NZ","en_OM","en_PA","en_PE","en_PF","en_PG","en_PH","en_PL","en_PM","en_PN","en_PT","en_PW","en_PY","en_QA","en_RE","en_RO","en_RS","en_RU","en_RW","en_SA","en_SB","en_SC","en_SE","en_SG","en_SH","en_SI","en_SJ","en_SK","en_SL","en_SM","en_SN","en_SO","en_SR","en_ST","en_SV","en_SZ","en_TC","en_TD","en_TG","en_TH","en_TJ","en_TM","en_TN","en_TO","en_TR","en_TT","en_TV","en_TW","en_TZ","en_UA","en_UG","en_US","en_UY","en_VA","en_VC","en_VE","en_VG","en_VN","en_VU","en_WF","en_WS","en_YE","en_YT","en_ZA","en_ZM","en_ZW","es_AD","es_AI","es_AO","es_AR","es_AW","es_BB","es_BJ","es_BM","es_BO","es_BS","es_BZ","es_CD","es_CG","es_CK","es_CL","es_CO","es_CR","es_CV","es_DJ","es_DM","es_DO","es_DZ","es_EC","es_EG","es_ER","es_ES","es_ET","es_FJ","es_FK","es_FO","es_GA","es_GD","es_GE","es_GI","es_GL","es_GM","es_GN","es_GT","es_GW","es_GY","es_HN","es_IE","es_JM","es_JO","es_KE","es_KG","es_KI","es_KM","es_KN","es_KW","es_KY","es_KZ","es_LC","es_LI","es_LS","es_LU","es_MA","es_MG","es_MH","es_ML","es_MR","es_MS","es_MU","es_MW","es_MX","es_MZ","es_NA","es_NC","es_NE","es_NF","es_NI","es_NR","es_NU","es_NZ","es_OM","es_PA","es_PE","es_PF","es_PG","es_PM","es_PN","es_PW","es_PY","es_QA","es_RS","es_RW","es_SA","es_SB","es_SC","es_SH","es_SJ","es_SL","es_SM","es_SN","es_SO","es_SR","es_ST","es_SV","es_SZ","es_TC","es_TD","es_TG","es_TJ","es_TM","es_TN","es_TT","es_TV","es_UA","es_UG","es_US","es_UY","es_VA","es_VC","es_VE","es_VG","es_VU","es_WF","es_YE","es_ZM","et_EE","fi_FI","fr_AD","fr_AE","fr_AI","fr_AM","fr_AO","fr_AW","fr_AZ","fr_BB","fr_BE","fr_BF","fr_BI","fr_BJ","fr_BM","fr_BS","fr_BZ","fr_CA","fr_CD","fr_CG","fr_CH","fr_CI","fr_CK","fr_CM","fr_CV","fr_DJ","fr_DM","fr_DO","fr_DZ","fr_EC","fr_ER","fr_ET","fr_FJ","fr_FK","fr_FO","fr_FR","fr_GA","fr_GD","fr_GE","fr_GF","fr_GI","fr_GL","fr_GM","fr_GN","fr_GP","fr_GT","fr_GW","fr_GY","fr_HN","fr_IE","fr_JM","fr_JO","fr_KE","fr_KG","fr_KI","fr_KM","fr_KN","fr_KW","fr_KY","fr_KZ","fr_LC","fr_LI","fr_LS","fr_LU","fr_MA","fr_MC","fr_MG","fr_MH","fr_ML","fr_MQ","fr_MR","fr_MS","fr_MU","fr_MW","fr_MZ","fr_NA","fr_NC","fr_NE","fr_NF","fr_NI","fr_NR","fr_NU","fr_NZ","fr_OM","fr_PA","fr_PE","fr_PF","fr_PG","fr_PM","fr_PN","fr_PW","fr_QA","fr_RE","fr_RS","fr_RW","fr_SA","fr_SB","fr_SC","fr_SH","fr_SJ","fr_SL","fr_SM","fr_SN","fr_SO","fr_SR","fr_ST","fr_SV","fr_SZ","fr_TC","fr_TD","fr_TG","fr_TJ","fr_TM","fr_TN","fr_TT","fr_TV","fr_UA","fr_UG","fr_US","fr_UY","fr_VA","fr_VC","fr_VE","fr_VG","fr_VU","fr_WF","fr_YE","fr_YT","fr_ZA","fr_ZM","he_IL","hu_HU","id_ID","it_IT","ja_JP","ko_KR","lv_LV","lt_LT","ms_BN","ms_MY","nl_BE","nl_NL","pl_PL","pt_BR","pt_PT","ro_RO","ru_EE","ru_LT","ru_LV","ru_RU","ru_UA","si_LK","sk_SK","sl_SI","sq_AL","sv_SE","tl_PH","th_TH","tr_TR","vi_VN","zh_C2","zh_CN","zh_HK","zh_TW","zh_AD","zh_AE","zh_AI","zh_AO","zh_AW","zh_BB","zh_BH","zh_BJ","zh_BM","zh_BS","zh_BZ","zh_CD","zh_CG","zh_CK","zh_CL","zh_CO","zh_CV","zh_DJ","zh_DM","zh_DO","zh_DZ","zh_EC","zh_EG","zh_ER","zh_ET","zh_FJ","zh_FK","zh_FO","zh_GA","zh_GD","zh_GE","zh_GI","zh_GL","zh_GM","zh_GN","zh_GT","zh_GW","zh_GY","zh_HN","zh_IE","zh_JM","zh_JO","zh_KE","zh_KG","zh_KI","zh_KM","zh_KN","zh_KW","zh_KY","zh_KZ","zh_LC","zh_LI","zh_LS","zh_LT","zh_LU","zh_MA","zh_MG","zh_MH","zh_ML","zh_MR","zh_MS","zh_MU","zh_MW","zh_MZ","zh_NA","zh_NC","zh_NE","zh_NF","zh_NI","zh_NR","zh_NU","zh_NZ","zh_OM","zh_PA","zh_PE","zh_PF","zh_PG","zh_PM","zh_PN","zh_PW","zh_QA","zh_RS","zh_RW","zh_SA","zh_SB","zh_SC","zh_SH","zh_SJ","zh_SL","zh_SM","zh_SN","zh_SO","zh_SR","zh_ST","zh_SV","zh_SZ","zh_TC","zh_TD","zh_TG","zh_TJ","zh_TM","zh_TN","zh_TT","zh_TV","zh_UA","zh_UG","zh_US","zh_UY","zh_VA","zh_VC","zh_VE","zh_VG","zh_VU","zh_WF","zh_YE","zh_ZA","zh_ZM"];function kt(e){if(!e)return;let t;if(e.includes("-")){const[n,i]=e.split("-");t=`${n}_${i.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return Et.includes(t)?t:void 0}var Tt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Mt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return Tt(this,void 0,void 0,function*(){if(!this.window.paypal||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypal)throw new c}return this.window.paypal})}getPayPalFastlaneSdk(e,t,n,i){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const r=this.getPayPalFastlaneSdkConfiguration(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i,r){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||r){const r=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}loadPayPalSdk(e){return Tt(this,arguments,void 0,function*({options:e,attributes:t}){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:o,initializationData:a}=e;if(!a||!a.clientId)throw new u(m.MissingPaymentMethod);const{intent:s,clientId:d,merchantId:l,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:p,isPayPalCreditAvailable:g,isDeveloperModeApplicable:v,availableAlternativePaymentMethods:f=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:P}=a,_=p||i,S="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,I=S?["card"]:[],C=S?[]:["card"],w=g?["credit","paylater"]:[],O=g?[]:["credit","paylater"],A=y?["venmo"]:[],z=y?[]:["venmo"],E=f.filter(e=>!b.includes(e)),k=P?["googlepay"]:[],T=i?["card-fields"]:[],M=this.filterFundingOptions([...C,...O,...z,...E]),B=this.filterFundingOptions([...I,...w,...A,...b]),F=kt(n);return{options:Object.assign(Object.assign({"client-id":d,"merchant-id":l,"enable-funding":B.length>0?B:void 0,"disable-funding":M.length>0?M:void 0,commit:_,components:["buttons","hosted-fields","payment-fields","legal",...k,...T],currency:t,intent:s},v&&{"buyer-country":c}),F&&{locale:F}),attributes:{"data-partner-attribution-id":h,"data-client-token":o}}}getPayPalFastlaneSdkConfiguration(e,t,n,i){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new u(m.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,attributionId:l}=o,c=kt(i);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:a}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":l,"data-sdk-client-token":r}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i=!0){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new u(m.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:l,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:y}=o,p=h||i,g=kt(n);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:p,components:["googlepay"],currency:t,intent:a},y&&{"buyer-country":l}),g&&{locale:g}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{intent:r,clientId:o,merchantId:a,buyerCountry:s,attributionId:d,isDeveloperModeApplicable:l,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=i,y=this.filterFundingOptions(h),p=this.filterFundingOptions(c.filter(e=>!h.includes(e))),g=kt(n);return{options:Object.assign(Object.assign({"client-id":o,"merchant-id":a,"enable-funding":y.length>0?y:void 0,"disable-funding":p.length>0?p:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:r},l&&{"buyer-country":s}),g&&{locale:g}),attributes:{"data-partner-attribution-id":d,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{clientId:r,merchantId:o,attributionId:a,isDeveloperModeApplicable:s,buyerCountry:d}=i,l=kt(n);return{options:Object.assign(Object.assign({"client-id":r,"merchant-id":o,components:["messages"],currency:t},s&&{"buyer-country":d}),l&&{locale:l}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function Bt(){return new Mt(t())}var Ft=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Dt{constructor(e){this.bigCommercePaymentsWalletService=e}initialize(e){return Ft(this,void 0,void 0,function*(){var t,n;const{bigcommerce_paymentspaypal:i,containerId:r,methodId:o}=e;if(!o)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_paymentspaypal" argument is not provided.');let a;try{a=JSON.parse(atob(i.initializationData))}catch(e){throw new W("Failed to parse payment method 'initializationData'.")}const s=null===(n=null===(t=a.initializationData)||void 0===t?void 0:t.paymentButtonStyles)||void 0===n?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsWalletService.loadPayPalSdk(a,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypal",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsWalletService.getPayPalSdkOrThrow(),o={createOrder:()=>this.bigCommercePaymentsWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>Ft(this,[e,i],void 0,function*({orderID:e},i){const r=yield i.order.get(),o=this.bigCommercePaymentsWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsWalletService.addBillingAddress(n,o),yield this.bigCommercePaymentsWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments",e)})},a=Object.assign({fundingSource:r.FUNDING.PAYPAL,style:this.bigCommercePaymentsWalletService.getValidButtonStyle(i)},o),s=r.Buttons(a);s.isEligible()?s.render(`#${e}`):this.bigCommercePaymentsWalletService.removeElement(e)}}const Nt=g(e=>new Dt(new zt(e,Bt(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypal"}]);var Ut=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class xt{constructor(e){this.bigCommercePaymentsPayLaterWalletService=e}initialize(e){return Ut(this,void 0,void 0,function*(){var t,n;const{bigcommerce_paymentspaypalcredit:i,containerId:r,methodId:o}=e;if(!o)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_paymentspaypalcredit" argument is not provided.');let a;try{a=JSON.parse(atob(i.initializationData))}catch(e){throw new W("Failed to parse payment method 'initializationData'.")}const s=null===(n=null===(t=a.initializationData)||void 0===t?void 0:t.paymentButtonStyles)||void 0===n?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsPayLaterWalletService.loadPayPalSdk(a,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypalcredit",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsPayLaterWalletService.getPayPalSdkOrThrow(),o=[r.FUNDING.PAYLATER,r.FUNDING.CREDIT],a={createOrder:()=>this.bigCommercePaymentsPayLaterWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>Ut(this,[e,i],void 0,function*({orderID:e},i){const r=yield i.order.get(),o=this.bigCommercePaymentsPayLaterWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsPayLaterWalletService.addBillingAddress(n,o),yield this.bigCommercePaymentsPayLaterWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_paylater",e)})};let s=!1;o.forEach(t=>{if(!s){const n=Object.assign({fundingSource:t,style:this.bigCommercePaymentsPayLaterWalletService.getValidButtonStyle(i)},a),o=r.Buttons(n);o.isEligible()&&(o.render(`#${e}`),s=!0)}}),s||this.bigCommercePaymentsPayLaterWalletService.removeElement(e)}}const jt=g(e=>new xt(new zt(e,Bt(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypalcredit"}]);export{We as createBigCommercePaymentsAlternativeMethodsPaymentStrategy,ct as createBigCommercePaymentsButtonStrategy,xe as createBigCommercePaymentsCreditCardsPaymentStrategy,Qe as createBigCommercePaymentsCustomerStrategy,tt as createBigCommercePaymentsFastlaneCustomerStrategy,be as createBigCommercePaymentsFastlanePaymentStrategy,Ve as createBigCommercePaymentsInvoicesPaymentStrategy,ht as createBigCommercePaymentsPayLaterButtonStrategy,rt as createBigCommercePaymentsPayLaterCustomerStrategy,Ie as createBigCommercePaymentsPayLaterPaymentStrategy,jt as createBigCommercePaymentsPayLaterWalletStrategy,X as createBigCommercePaymentsPaymentStrategy,Ae as createBigCommercePaymentsRatePayPayPaymentStrategy,Ke as createBigCommercePaymentsRedirectAlternativeMethodsPaymentStrategy,gt as createBigCommercePaymentsVenmoButtonStrategy,st as createBigCommercePaymentsVenmoCustomerStrategy,qe as createBigCommercePaymentsVenmoPaymentStrategy,Nt as createBigCommercePaymentsWalletStrategy};
|
|
1
|
+
import{createScriptLoader as e,getScriptLoader as t}from"@bigcommerce/script-loader";import{createFormPoster as n}from"@bigcommerce/form-poster";import{createRequestSender as i}from"@bigcommerce/request-sender";import{isEqual as r,isNil as o,noop as a,omit as s,omitBy as d}from"lodash";class l extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}class c extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var m;!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"}(m||(m={}));class u extends l{constructor(e){super(function(e){switch(e){case m.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case m.MissingCart:return"Unable to proceed because cart data is unavailable.";case m.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case m.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case m.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case m.MissingCheckoutConfig:case m.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case m.MissingOrder:return"Unable to proceed because order data is unavailable.";case m.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case m.MissingPayment:return"Unable to proceed because payment data is unavailable.";case m.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case m.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case m.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 h=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class y{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.bigCommercePaymentsFastlaneSdk)throw new c}return this.window.bigCommercePaymentsFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.bigCommercePaymentsGooglePay)throw new c;return this.window.bigCommercePaymentsGooglePay})}getPayPalApmsSdk(e,t){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.bigCommercePaymentsApms)throw new c}return this.window.bigCommercePaymentsApms})}getPayPalMessages(e,t){return h(this,void 0,void 0,function*(){if(!this.window.bigCommercePaymentsMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.bigCommercePaymentsMessages)throw new c;return this.window.bigCommercePaymentsMessages})}loadPayPalSdk(e){return h(this,arguments,void 0,function*({options:e,attributes:t}){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,attributionId:d}=r;return{options:{"client-id":a,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:o},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"bigCommercePaymentsFastlaneSdk","data-partner-attribution-id":d,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:r}=e;if(!r||!r.clientId)throw new u(m.MissingPaymentMethod);const{intent:o,clientId:a,merchantId:s,buyerCountry:d,attributionId:l,isHostedCheckoutEnabled:c,isDeveloperModeApplicable:h}=r,y=c||n;return{options:Object.assign({"client-id":a,"merchant-id":s,commit:y,components:["googlepay"],currency:t,intent:o},h&&{"buyer-country":d}),attributes:{"data-partner-attribution-id":l,"data-client-token":i,"data-namespace":"bigCommercePaymentsGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{intent:i,clientId:r,merchantId:o,buyerCountry:a,attributionId:s,isDeveloperModeApplicable:d,availableAlternativePaymentMethods:l=[],enabledAlternativePaymentMethods:c=[]}=n,h=this.filterFundingOptions(c),y=this.filterFundingOptions(l.filter(e=>!c.includes(e)));return{options:Object.assign({"client-id":r,"merchant-id":o,"enable-funding":h.length>0?h:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},d&&{"buyer-country":a}),attributes:{"data-partner-attribution-id":s,"data-namespace":"bigCommercePaymentsApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new u(m.MissingPaymentMethod);const{clientId:i,merchantId:r,attributionId:o,isDeveloperModeApplicable:a,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":r,components:["messages"],currency:t},a&&{"buyer-country":s}),attributes:{"data-namespace":"bigCommercePaymentsMessages","data-partner-attribution-id":o}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function p(){return new y(e())}function g(e,t){return Object.assign(e,{resolveIds:t})}const v={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},f="embedded-checkout-loading-indicator-rotation";class b{constructor(e){this.styles=Object.assign(Object.assign({},v),e&&e.styles),this.containerStyles=Object.assign({},e&&e.containerStyles),this.defineAnimation(),this.container=this.buildContainer(),this.indicator=this.buildIndicator(),this.container.appendChild(this.indicator)}show(e){if(e){const t=document.getElementById(e);if(!t)throw new Error("Unable to attach the loading indicator because the parent ID is not valid.");t.appendChild(this.container)}this.container.style.visibility="visible",this.container.style.opacity="1"}hide(){const e=()=>{this.container.style.visibility="hidden",this.container.removeEventListener("transitionend",e)};this.container.addEventListener("transitionend",e),this.container.style.opacity="0"}buildContainer(){const e=document.createElement("div");return e.style.display="block",e.style.bottom="0",e.style.left="0",e.style.height="100%",e.style.width="100%",e.style.position="absolute",e.style.right="0",e.style.top="0",e.style.transition="all 250ms ease-out",e.style.opacity="0",this.setStyleAttribute(e,this.containerStyles),e}buildIndicator(){const e=document.createElement("div");return e.style.display="block",e.style.width=`${this.styles.size}px`,e.style.height=`${this.styles.size}px`,e.style.borderRadius=`${this.styles.size}px`,e.style.border="solid 1px",e.style.borderColor=`${this.styles.backgroundColor} ${this.styles.backgroundColor} ${this.styles.color} ${this.styles.color}`,e.style.margin="0 auto",e.style.position="absolute",e.style.left="0",e.style.right="0",e.style.top="50%",e.style.transform="translateY(-50%) rotate(0deg)",e.style.transformStyle="preserve-3d",e.style.animation=`${f} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(n=>{e.style.setProperty(n,t[n])})}defineAnimation(){var e;if(document.getElementById(f))return;const t=document.createElement("style");t.id=f,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${f} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}const P={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};class _ extends l{constructor(e){super(e||"An unexpected error has occurred during buy now cart creation process. Please try again later."),this.name="BuyNowCartCreationError",this.type="buy_now_cart_creation_error"}}const S={body:{},headers:{},status:0};class I extends l{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:o}=e||S;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}var C,w,O,A,z,E,k,T;!function(e){e.BuyNow="BUY_NOW",e.INVOICE="B2B_INVOICE"}(C||(C={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(w||(w={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(O||(O={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(A||(A={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(z||(z={})),function(e){e.pill="pill",e.rect="rect"}(E||(E={})),function(e){e.OXXO="oxxo"}(k||(k={})),function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(T||(T={}));var M=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class B{constructor(e,t,n,i){this.formPoster=e,this.paymentIntegrationService=t,this.bigCommercePaymentsRequestSender=n,this.bigCommercePaymentsScriptLoader=i}loadPayPalSdk(e,t,n,i){return M(this,void 0,void 0,function*(){const r=this.paymentIntegrationService.getState(),o=t||r.getCartOrThrow().currency.code,a=r.getPaymentMethodOrThrow(e);return this.paypalSdk=yield this.bigCommercePaymentsScriptLoader.getPayPalSDK(a,o,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}createBuyNowCartOrThrow(e){return M(this,void 0,void 0,function*(){const t=e.getBuyNowCartRequestBody();if(!t)throw new u(m.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new _}})}createOrder(e,t){return M(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return i})}createOrderCardFields(e,t){return M(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState().getCartOrThrow().id,{orderId:i,setupToken:r}=yield this.bigCommercePaymentsRequestSender.createOrder(e,Object.assign({cartId:n},t));return Object.assign({orderId:i},r?{setupToken:r}:{})})}updateOrder(e){return M(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow();let i;e||(i=t.getConsignmentsOrThrow()[0]);try{yield this.bigCommercePaymentsRequestSender.updateOrder({availableShippingOptions:e?[]:null==i?void 0:i.availableShippingOptions,cartId:n.id,selectedShippingOption:e?null:null==i?void 0:i.selectedShippingOption})}catch(e){throw new I}})}getOrderStatus(e,t){return M(this,void 0,void 0,function*(){try{const{status:n}=yield this.bigCommercePaymentsRequestSender.getOrderStatus(e,t);return n}catch(e){throw new I}})}tokenizePayment(e,t){const n=this.paymentIntegrationService.getState().getCartOrThrow();if(!t)throw new u(m.MissingOrderId);return this.formPoster.postForm("/checkout.php",Object.assign({payment_type:"paypal",action:"set_external_checkout",provider:e,order_id:t},n.source===C.BuyNow&&{cart_id:n.id}))}submitPayment(e,t,n){return M(this,void 0,void 0,function*(){const i={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:e,paypal_account:{order_id:t}}};yield this.paymentIntegrationService.submitPayment(Object.assign({methodId:e,paymentData:i},n?{gatewayId:n}:{}))})}getShippingOptionOrThrow(e){const t=this.paymentIntegrationService.getState().getConsignmentsOrThrow()[0],n=t.availableShippingOptions||[],i=n.find(e=>e.isRecommended),r=(e?n.find(t=>t.id===e):n.find(e=>{var n;return e.id===(null===(n=t.selectedShippingOption)||void 0===n?void 0:n.id)}))||i||n[0];if(!r)throw new Error("Your order can't be shipped to this address");return r}getAddress(e){return{firstName:(null==e?void 0:e.firstName)||"",lastName:(null==e?void 0:e.lastName)||"",email:(null==e?void 0:e.email)||"",phone:(null==e?void 0:e.phone)||"",company:"",address1:(null==e?void 0:e.address1)||"",address2:(null==e?void 0:e.address2)||"",city:(null==e?void 0:e.city)||"",countryCode:(null==e?void 0:e.countryCode)||"",postalCode:(null==e?void 0:e.postalCode)||"",stateOrProvince:"",stateOrProvinceCode:(null==e?void 0:e.stateOrProvinceCode)||"",customFields:[]}}getBillingAddressFromOrderDetails({payer:e}){var t,n;return this.getAddress({firstName:e.name.given_name,lastName:e.name.surname,email:e.email_address,address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,countryCode:e.address.country_code,postalCode:e.address.postal_code,stateOrProvinceCode:e.address.admin_area_1,phone:null===(n=null===(t=e.phone)||void 0===t?void 0:t.phone_number)||void 0===n?void 0:n.national_number})}getShippingAddressFromOrderDetails(e){const{payer:t,purchase_units:n}=e,{address:i,name:{full_name:r}}=n[0].shipping,[o,...a]=r.split(" ");return this.getAddress({firstName:o,lastName:a.join(" "),email:t.email_address,address1:i.address_line_1,address2:i.address_line_2,city:i.admin_area_2,countryCode:i.country_code,postalCode:i.postal_code,stateOrProvinceCode:i.admin_area_1})}getValidButtonStyle(e){const{color:t,height:n,label:i,shape:r}=e||{},a={color:t&&z[t]?t:void 0,height:this.getValidHeight(n),label:i&&A[i]?i:void 0,shape:r&&E[r]?r:void 0};return d(a,o)}getValidHeight(e){return e&&"number"==typeof e?e>55?55:e<25?25:e:40}removeElement(e){const t=e&&document.getElementById(e);t&&(t.style.display="none")}}const F="This API endpoint is for internal use only and may change in the future";var D;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(D||(D={}));const N=D,U={"X-Checkout-SDK-Version":"1.960.1"};var x=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class j{constructor(e){this.requestSender=e}createOrder(e,t){return x(this,void 0,void 0,function*(){const n=`/api/storefront/payment/${e}`,i=t,r=Object.assign({"X-API-INTERNAL":F,"Content-Type":N.Json},U);return(yield this.requestSender.post(n,{headers:r,body:i})).body})}updateOrder(e){return x(this,void 0,void 0,function*(){const t=e,n=Object.assign({"X-API-INTERNAL":F,"Content-Type":N.Json},U);return(yield this.requestSender.put("/api/storefront/initialization/bigcommerce_payments",{headers:n,body:t})).body})}getOrderStatus(){return x(this,arguments,void 0,function*(e="bigcommerce_payments",t){const n=`/api/storefront/initialization/${e}`,i=Object.assign({"X-API-INTERNAL":F,"Content-Type":N.Json},U);return(yield this.requestSender.get(n,Object.assign({headers:i},t))).body})}}var L=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class V{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i){return L(this,void 0,void 0,function*(){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n);return this.loadPayPalSDK(r,i)})}loadPayPalSDK(e){return L(this,arguments,void 0,function*(e,t=!1){if(!this.window.bigCommercePaymentsPayPalSDK||t){const t=this.transformConfig(e.options),n=this.transformConfig(e.attributes),i=`https://www.paypal.com/sdk/js?${new URLSearchParams(t).toString()}`;yield this.scriptLoader.loadScript(i,{async:!0,attributes:n})}if(!this.window.bigCommercePaymentsPayPalSDK)throw new c;return this.window.bigCommercePaymentsPayPalSDK})}getPayPalSdkScriptConfigOrThrow(e,t,n=!0){const{id:i,clientToken:r,initializationData:o}=e;if(!(null==o?void 0:o.clientId))throw new u(m.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:l,attributionId:c,isVenmoEnabled:h,isHostedCheckoutEnabled:y,isPayPalCreditAvailable:p,isDeveloperModeApplicable:g,availableAlternativePaymentMethods:v=[],enabledAlternativePaymentMethods:f=[],isGooglePayEnabled:b}=o,P=y||n,_="bigcommerce_payments_creditcards"===i,S=_?["card"]:[],I=_?[]:["card"],C=p?["credit","paylater"]:[],w=p?[]:["credit","paylater"],O=h?["venmo"]:[],A=h?[]:["venmo"],z=v.filter(e=>!f.includes(e)),E=b?["googlepay"]:[],k=n?["card-fields"]:[],T=this.filterFundingOptions([...I,...w,...A,...z]),M=this.filterFundingOptions([...S,...C,...O,...f]);return{options:Object.assign({"client-id":s,"merchant-id":d,"enable-funding":M.length>0?M:void 0,"disable-funding":T.length>0?T:void 0,commit:P,components:["buttons","hosted-fields","payment-fields","legal",...E,...k],currency:t,intent:a},g&&{"buyer-country":l}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"bigCommercePaymentsPayPalSDK"}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}const R=e=>{const{getHost:r}=e.getState();return new B(n(),e,new j(i({host:r()})),new V(t()))},G=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};class W extends l{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class H extends W{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 K 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 $ extends l{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function Y(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}function q(e){return Boolean(e.instrumentId)}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 J=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Q{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.paypalSdkHelper=n,this.loadingIndicator=i}initialize(e){return J(this,void 0,void 0,function*(){const{methodId:t,bigcommerce_payments:n}=e||{};if(this.bigcommerce_payments=n,!t)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{container:o,bannerContainerId:a}=n,{orderId:s,paypalBNPLConfiguration:d=[],isPayPalCreditAvailable:l}=r.initializationData||{};if(void 0!==a){if(!document.getElementById(a))return void console.error("Unable to create banner without valid banner container ID.");const e=null==d?void 0:d.find(({id:e})=>"checkout"===e);if(l||!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return t&&"function"==typeof(null==t?void 0:t.Messages)?this.renderMessages(t,a,e):void console.error("[BC PayPalCommerce PayLater]: banner could not be rendered, due to issues with loading PayPal SDK")}s?this.orderId=s:(this.loadingIndicatorContainer=null==o?void 0:o.split("#")[1],yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t),n.onInit&&"function"==typeof n.onInit&&n.onInit(()=>this.renderButton(t,n)),(void 0===n.shouldRenderPayPalButtonOnInitialization||n.shouldRenderPayPalButtonOnInitialization)&&this.renderButton(t,n))})}execute(e,t){return J(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{onError:r}=this.bigcommerce_payments||{};if(!n)throw new H(["payment"]);const{methodId:o,paymentData:a}=n;if(this.isPayPalVaultedInstrumentPaymentData(a)&&!this.orderId&&(this.orderId=yield this.createOrder()),!this.orderId)throw new K;const s=this.isPayPalVaultedInstrumentPaymentData(a)?this.prepareVaultedInstrumentPaymentPayload(o,this.orderId,a):this.preparePaymentPayload(o,this.orderId,a);try{yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(s)}catch(e){return this.isProviderError(e)&&(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n.methodId),yield new Promise((e,t)=>{var i;this.bigcommerce_payments&&(null===(i=this.paypalButton)||void 0===i||i.close(),this.renderButton(n.methodId,this.bigcommerce_payments),this.handleError(new Error("INSTRUMENT_DECLINED"),r)),t()})),this.handleError(e,r),Promise.reject()}})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}prepareVaultedInstrumentPaymentPayload(e,t,n){const{instrumentId:i,shouldSetAsDefaultInstrument:r}=n,o=!this.isTrustedVaultingFlow(n);return o?{methodId:e,paymentData:{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}:{methodId:e,paymentData:{instrumentId:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t},bigpay_token:{token:i}}}}}preparePaymentPayload(e,t,n){const{shouldSaveInstrument:i=!1,shouldSetAsDefaultInstrument:r=!1}=Y(n)?n:{};return{methodId:e,paymentData:{shouldSaveInstrument:i,shouldSetAsDefaultInstrument:r,formattedPayload:{paypal_account:{order_id:t}}}}}renderButton(e,t){const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t;if(!a)throw new W('Unable to initialize payment because "container" argument is not provided.');const m={fundingSource:n.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),createOrder:()=>this.createOrder(),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onError:e=>this.handleError(e,s),onCancel:()=>this.toggleLoadingIndicator(!1)};this.paypalButton=n.Buttons(m),this.paypalButton.isEligible()&&(d&&"function"==typeof d&&d(),this.paypalButton.render(a))}handleClick(e,t){return J(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;yield null==t?void 0:t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,null==t||t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createOrder(){return J(this,void 0,void 0,function*(){const e=this.getFieldsValues();return this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_paymentscheckout",{shouldSaveInstrument:(null==e?void 0:e.shouldSaveInstrument)||!1})})}getFieldsValues(){const{getFieldsValues:e}=this.bigcommerce_payments||{};return"function"==typeof e?e():void 0}isTrustedVaultingFlow(e){if(e&&q(e)){const t=this.paymentIntegrationService.getState().getInstruments(),n=null==t?void 0:t.find(t=>Z(t)&&t.bigpayToken===e.instrumentId);return!(Z(n)&&!n.trustedShippingAddress)}return!1}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isPayPalVaultedInstrumentPaymentData(e){return!!e&&q(e)&&Y(e)}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:G(n)};e.Messages(i).render(`#${t}`)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"INSTRUMENT_DECLINED"===(null===(i=null===(n=((null===(t=null==e?void 0:e.errors)||void 0===t?void 0:t.filter(e=>e.provider_error))||[])[0])||void 0===n?void 0:n.provider_error)||void 0===i?void 0:i.code)}}const X=g(e=>new Q(e,R(e),p(),new b({containerStyles:P})),[{id:"bigcommerce_payments"}]);var ee,te,ne,ie,re,oe,ae,se,de;!function(e){e.CVV="cvv",e.PAN="pan"}(ee||(ee={}));class le{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:o,domain:a,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}o&&(i+=`; path=${o}`),a&&(i+=`; domain=${a}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){le.set(e,"",Object.assign({expires:new Date(0)},t))}}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(te||(te={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(ne||(ne={})),function(e){e.Always="SCA_ALWAYS"}(ie||(ie={})),function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(re||(re={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(oe||(oe={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(ae||(ae={})),function(e){e.pill="pill",e.rect="rect"}(se||(se={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(de||(de={}));var ce=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class me{constructor(){this.window=window}initializePayPalFastlane(e,t,n){return ce(this,void 0,void 0,function*(){if(t&&(window.localStorage.setItem("fastlaneEnv","sandbox"),window.localStorage.setItem("axoEnv","sandbox")),!this.window.bigCommercePaymentsFastlane){const t={root:{backgroundColorPrimary:"transparent"}};this.window.bigCommercePaymentsFastlane=yield e.Fastlane({styles:n||t})}return this.window.bigCommercePaymentsFastlane})}getPayPalFastlaneOrThrow(){if(!this.window.bigCommercePaymentsFastlane)throw new c;return this.window.bigCommercePaymentsFastlane}lookupCustomerOrThrow(e){return ce(this,void 0,void 0,function*(){return this.getPayPalFastlaneOrThrow().identity.lookupCustomerByEmail(e)})}triggerAuthenticationFlowOrThrow(e){return ce(this,void 0,void 0,function*(){return e?this.getPayPalFastlaneOrThrow().identity.triggerAuthenticationFlow(e):{}})}updateStorageSessionId(e){const t=new Date;t.setDate(t.getDate()+14);const n={expires:t,secure:!0};le.set("bc-fastlane-sessionId",e,n)}removeStorageSessionId(){le.remove("bc-fastlane-sessionId")}getStorageSessionId(){return le.get("bc-fastlane-sessionId")||""}mapPayPalFastlaneProfileToBcCustomerData(e,t){var n,i,r;const{authenticationState:o,profileData:a}=t,s=null===(r=null===(i=null===(n=null==a?void 0:a.card)||void 0===n?void 0:n.paymentSource)||void 0===i?void 0:i.card)||void 0===r?void 0:r.billingAddress,d=null==a?void 0:a.shippingAddress,l=null==a?void 0:a.name,c=null==a?void 0:a.card,m=d?this.mapPayPalToBcAddress(d.address,d.name,d.phoneNumber):void 0,u=s&&l?this.mapPayPalToBcAddress(s,l,null==d?void 0:d.phoneNumber):void 0,h=c?this.mapPayPalToBcInstrument(e,c):[],y=this.filterAddresses([m,u]);return{authenticationState:o||de.UNRECOGNIZED,addresses:y,billingAddress:u,shippingAddress:m,instruments:h}}mapPayPalToBcInstrument(e,t){const{id:n,paymentSource:i}=t,{brand:r,expiry:o,lastDigits:a}=i.card,[s,d]=o.split("-");return[{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:d,expiryYear:s,iin:"",last4:a,method:e,provider:e,trustedShippingAddress:!1,untrustedShippingCardVerificationMode: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,n,i){const[r,o]=t.fullName.split(" "),a=(null==n?void 0:n.nationalNumber)||"",s=(null==n?void 0:n.countryCode)||"";return{id:Date.now(),type:"paypal-address",firstName:t.firstName||r||"",lastName:t.lastName||o||"",company:e.company||"",address1:e.addressLine1,address2:e.addressLine2||"",city:e.adminArea2,stateOrProvince:e.adminArea1,stateOrProvinceCode:e.adminArea1,country:e.countryCode||"",countryCode:e.countryCode||"",postalCode:e.postalCode,phone:s+a,customFields:i||[]}}filterAddresses(e){return e.reduce((e,t)=>t?e.some(e=>this.isEqualAddresses(e,t))?e:[...e,t]:e,[])}isEqualAddresses(e,t){return r(this.normalizeAddress(e),this.normalizeAddress(t))}normalizeAddress(e){return s(e,["id","phone"])}}function ue(){return new me}function he(e){return"string"!=typeof e}function ye(e,t){if(t||e)return function(e){var t,n;const i={},r=d(e.root,he),o=d(e.input,he),a=d(e.toggle,he),s=d(null===(t=e.text)||void 0===t?void 0:t.body,he),l=d(null===(n=e.text)||void 0===n?void 0:n.caption,he),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(o).length&&(i.input=o),Object.keys(a).length&&(i.toggle=a),Object.keys(s).length&&(i.text={},i.text.body=s),Object.keys(l).length&&(i.text=Object.assign({},i.text),i.text.caption=l),c&&(i.branding=c),i}(function(e,t){var n,i,r,o,a,s,d,l,c,m,u,h,y,p,g,v,f,b,P,_,S,I;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null===(n=null==t?void 0:t.root)||void 0===n?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null===(i=null==t?void 0:t.root)||void 0===i?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null===(r=null==t?void 0:t.root)||void 0===r?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null===(o=null==t?void 0:t.root)||void 0===o?void 0:o.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null===(a=null==t?void 0:t.root)||void 0===a?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null===(s=null==t?void 0:t.root)||void 0===s?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null===(d=null==t?void 0:t.input)||void 0===d?void 0:d.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null===(l=null==t?void 0:t.input)||void 0===l?void 0:l.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null===(c=null==t?void 0:t.input)||void 0===c?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null===(m=null==t?void 0:t.input)||void 0===m?void 0:m.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null===(u=null==t?void 0:t.input)||void 0===u?void 0:u.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null===(h=null==t?void 0:t.input)||void 0===h?void 0:h.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null===(y=null==t?void 0:t.toggle)||void 0===y?void 0:y.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null===(p=null==t?void 0:t.toggle)||void 0===p?void 0:p.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===(b=null===(f=null==t?void 0:t.text)||void 0===f?void 0:f.body)||void 0===b?void 0:b.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null===(_=null===(P=null==t?void 0:t.text)||void 0===P?void 0:P.caption)||void 0===_?void 0:_.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null===(I=null===(S=null==t?void 0:t.text)||void 0===S?void 0:S.caption)||void 0===I?void 0:I.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function pe(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}function ge(e,t,n=!0){var i;return null!==(i=e[t])&&void 0!==i?i:n}var ve=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class fe{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsRequestSender=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return ve(this,void 0,void 0,function*(){var t,n;const{methodId:i,bigcommerce_payments_fastlane:r}=e;if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(this.methodId=i,!r)throw new W('Unable to initialize payment because "options.bigcommerce_payments_fastlane" argument is not provided.');if(this.bigcommerce_payments_fastlane=r,!r.onInit||"function"!=typeof r.onInit)throw new W('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onInit" argument is not provided or it is not a function.');if(!r.onChange||"function"!=typeof r.onChange)throw new W('Unable to initialize payment because "options.bigcommerce_payments_fastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(i);const o=this.paymentIntegrationService.getState(),a=o.getCartOrThrow(),s=o.getPaymentMethodOrThrow(i),{isDeveloperModeApplicable:d,isFastlaneStylingEnabled:l}=s.initializationData||{};this.threeDSVerificationMethod=null===(t=s.initializationData)||void 0===t?void 0:t.threeDSVerificationMethod,this.paypalFastlaneSdk=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(s,a.currency.code,a.id);const c=ye(l?null===(n=null==s?void 0:s.initializationData)||void 0===n?void 0:n.fastlaneStyles:{},null==r?void 0:r.styles);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(this.paypalFastlaneSdk,!!d,c),this.shouldRunAuthenticationFlow()&&(yield this.runPayPalAuthenticationFlowOrThrow(i)),yield this.initializePayPalPaymentComponent(),r.onInit(e=>this.renderPayPalPaymentComponent(e)),r.onChange(()=>this.handlePayPalStoredInstrumentChange(i))})}execute(e,t){return ve(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);const{paymentData:r,methodId:o}=n,a=r&&q(r);try{yield this.paymentIntegrationService.submitOrder(i,t);const e=a?yield this.prepareVaultedInstrumentPaymentPayload(o,r):yield this.preparePaymentPayload(o,r);yield this.paymentIntegrationService.submitPayment(e),this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()}catch(e){if(function(e){return"object"==typeof e&&null!==e&&"message"in e&&"response"in e&&"name"in e.response}(e)&&"INVALID_REQUEST"===e.response.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 $)}deinitialize(){return ve(this,void 0,void 0,function*(){return Promise.resolve()})}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=pe(i)?i:{},o=this.bigCommercePaymentsFastlaneUtils.getStorageSessionId();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===de.CANCELED||(null==r?void 0:r.authenticationState)||o!==t.id)}runPayPalAuthenticationFlowOrThrow(e){return ve(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(a),{authenticationState:d,addresses:l,instruments:c}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,s);yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:d,addresses:l,instruments:c}),s.authenticationState===de.CANCELED?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n.id)}catch(e){this.handleErrorLog(e)}})}initializePayPalPaymentComponent(){return ve(this,void 0,void 0,function*(){const e=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),t=e.phone,n=`${e.firstName} ${e.lastName}`.trim(),i=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),r={fields:Object.assign({cardholderName:{prefill:n,enabled:!0}},t&&{phoneNumber:{prefill:t}})};this.paypalComponentMethods=yield i.FastlaneCardComponent(r)})}renderPayPalPaymentComponent(e){const t=this.getPayPalComponentMethodsOrThrow();if(!e)throw new W('Unable to render card component because "container" argument is not provided.');t.render(e)}getPayPalComponentMethodsOrThrow(){if(!this.paypalComponentMethods)throw new c;return this.paypalComponentMethods}prepareVaultedInstrumentPaymentPayload(e,t){return ve(this,void 0,void 0,function*(){const{instrumentId:n}=t,i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),r=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&i.config.is3dsEnabled?yield this.get3DSNonce(n):n;return yield this.createOrder(r),{methodId:e,paymentData:{formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:r}}}}})}preparePaymentPayload(e,t){return ve(this,void 0,void 0,function*(){const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getPaymentMethodOrThrow(e),o=`${i.firstName} ${i.lastName}`.trim(),{getPaymentToken:a}=this.getPayPalComponentMethodsOrThrow(),{id:s}=yield a({name:{fullName:o},billingAddress:this.bigCommercePaymentsFastlaneUtils.mapBcToPayPalAddress(i)}),d=this.isBigcommercePaymentsFastlaneThreeDSAvailable()&&r.config.is3dsEnabled,{shouldSaveInstrument:l=!1,shouldSetAsDefaultInstrument:c=!1}=Y(t)?t:{},m=d?yield this.get3DSNonce(s):s;return yield this.createOrder(m),{methodId:e,paymentData:Object.assign(Object.assign({},t),{shouldSaveInstrument:l,shouldSetAsDefaultInstrument:c,formattedPayload:{paypal_fastlane_token:{order_id:this.orderId,token:m}}})}})}createOrder(e){return ve(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState().getCartOrThrow().id;if(this.methodId){const{orderId:n}=yield this.bigCommercePaymentsRequestSender.createOrder(this.methodId,{cartId:t,fastlaneToken:e});this.orderId=n}})}get3DSNonce(e){return ve(this,void 0,void 0,function*(){var t;const n=this.paymentIntegrationService.getState(),i=n.getCartOrThrow(),r=n.getOrderOrThrow(),o=n.getStoreConfigOrThrow().links.checkoutLink,a=null===(t=this.paypalFastlaneSdk)||void 0===t?void 0:t.ThreeDomainSecureClient;if(!a)throw new c;const s={amount:r.orderAmount.toFixed(2),currency:i.currency.code,nonce:e,threeDSRequested:this.threeDSVerificationMethod===ie.Always,transactionContext:{experience_context:{locale:"en-US",return_url:o,cancel_url:o}}},d=yield a.isEligible(s);if(this.threeDSVerificationMethod===ie.Always&&!d)throw new K;if(d){const{liabilityShift:e,authenticationState:t,nonce:n}=yield a.show();if(e===w.No||e===w.Unknown||t===re.Errored||t===re.Cancelled)throw new K;if(t===re.Succeeded&&[w.Yes,w.Possible].includes(e))return n}return e})}handlePayPalStoredInstrumentChange(e){return ve(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsFastlaneUtils.getPayPalFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=pe(t)?t:{},r=this.bigCommercePaymentsFastlaneUtils.mapPayPalToBcInstrument(e,i)[0];return yield this.paymentIntegrationService.updatePaymentProviderCustomer(Object.assign(Object.assign({},n),{instruments:[r]})),r}})}isBigcommercePaymentsFastlaneThreeDSAvailable(){return ge(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.bcp_fastlane_three_ds")}handleError(e){var t;(null===(t=this.bigcommerce_payments_fastlane)||void 0===t?void 0:t.onError)&&"function"==typeof this.bigcommerce_payments_fastlane.onError&&this.bigcommerce_payments_fastlane.onError(e)}handleErrorLog(e){var t;(null===(t=this.bigcommerce_payments_fastlane)||void 0===t?void 0:t.onErrorLog)&&"function"==typeof this.bigcommerce_payments_fastlane.onErrorLog&&this.bigcommerce_payments_fastlane.onErrorLog(e)}}const be=g(e=>{const{getHost:t}=e.getState();return new fe(e,new j(i({host:t()})),p(),ue())},[{id:"bigcommerce_payments_fastlane"}]);class Pe extends l{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var _e=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Se{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.paypalSdkHelper=i}initialize(e){return _e(this,void 0,void 0,function*(){const{methodId:t,bigcommerce_payments_paylater:n}=e||{};if(!t)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(t),{paypalBNPLConfiguration:o=[],orderId:a}=r.initializationData||{},{bannerContainerId:s,container:d}=n;if(void 0!==s){if(!document.getElementById(s))return void console.error("Unable to create banner without valid banner container ID.");const e=o&&o.find(({id:e})=>"checkout"===e);if(!(null==e?void 0:e.status))return;const t=yield this.paypalSdkHelper.getPayPalMessages(r,i.getCartOrThrow().currency.code);return this.renderMessages(t,s,e)}a?this.orderId=a:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t),this.loadingIndicatorContainer=null==d?void 0:d.split("#")[1],this.renderButton(t,n))})}execute(e,t){return _e(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);if(!this.orderId)throw new K;yield this.paymentIntegrationService.submitOrder(i,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.bigCommercePaymentsButtons)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){if(!(null==t?void 0:t.container))throw new W('Unable to initialize payment because "container" argument is not provided.');const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,m=[n.FUNDING.PAYLATER,n.FUNDING.CREDIT];let u=!1;m.forEach(e=>{if(u)return;const t={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),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.bigCommercePaymentsButtons=n.Buttons(t),this.bigCommercePaymentsButtons.isEligible()||e!==n.FUNDING.PAYLATER){if(!this.bigCommercePaymentsButtons.isEligible()&&e===n.FUNDING.CREDIT)throw new Pe(`BigCommercePayments ${e} is not available for your region. Please use BigCommercePayments Checkout instead.`);d&&"function"==typeof d&&d(),this.bigCommercePaymentsButtons.render(a),u=!0}})}handleClick(e,t){return _e(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;t&&"function"==typeof t&&(yield t(()=>(this.toggleLoadingIndicator(!0),n()),i))})}handleApprove({orderID:e},t){this.orderId=e,t&&"function"==typeof t&&t()}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}renderMessages(e,t,n){const i={amount:this.paymentIntegrationService.getState().getCheckoutOrThrow().outstandingBalance,placement:"payment",style:G(n)};e.Messages(i).render(`#${t}`)}}const Ie=g(e=>new Se(e,R(e),new b({containerStyles:P}),p()),[{id:"bigcommerce_payments_paylater"}]);class Ce extends I{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var we=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Oe{constructor(e,t,n,i=3e3,r=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n,this.pollingInterval=i,this.maxPollingIntervalTime=r,this.pollingTimer=0,this.stopPolling=a}initialize(e){return we(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_ratepay:i}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_payments_ratepay" argument is not provided.');const{legalTextContainer:r,container:o,loadingContainerId:a}=i;if(!o)throw new W('Unable to initialize payment because "options.container" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.legalTextContainer" argument is not provided.');if(!a)throw new W('Unable to initialize payment because "options.loadingContainerId" argument is not provided.');this.loadingIndicatorContainer=a;const s=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n,t),{merchantId:d}=s.initializationData||{};if(!d)throw new W("Unable to initialize payment because merchantId argument is not provided.");this.bigcommerce_payments_ratepay=i,yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n),this.createFraudNetScript(d,n,t),this.loadFraudnetConfig(),this.renderLegalText(r,o)})}execute(e,t){return we(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{getFieldsValues:r}=this.bigcommerce_payments_ratepay||{};if(!n)throw new H(["payment"]);if(!r||"function"!=typeof r)throw new W('Unable to initialize payment because "options.getFieldsValues" argument is not provided.');this.toggleLoadingIndicator(!0);try{const e=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apmscheckout",{metadataId:this.guid}),{ratepayBirthDate:o,ratepayPhoneNumber:a,ratepayPhoneCountryCode:s}=r(),d={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:n.methodId,rate_pay:{birth_date:this.normalizeDate(o),phone:{national_number:a,country_code:s.split("+")[1]}},paypal_account:{order_id:e}}};return yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:n.methodId,paymentData:d}),yield new Promise((e,t)=>{this.initializePollingMechanism(n.methodId,e,t,n.gatewayId)})}catch(e){return this.handleError(e),new Promise((e,t)=>t())}})}finalize(){return Promise.reject(new $)}deinitialize(){const{legalTextContainer:e}=this.bigcommerce_payments_ratepay||{},t=document.querySelectorAll('[data-id="fraudnetScript"]')[0],n=document.querySelectorAll('[data-id="fraudnetConfig"]')[0];if(this.deinitializePollingMechanism(),t.remove(),n.remove(),e){const t=document.getElementById(e);null==t||t.remove()}return Promise.resolve()}normalizeDate(e){const t=this.formatDate(e.getDate()),n=this.formatDate(e.getMonth()+1);return`${e.getFullYear()}-${n}-${t}`}formatDate(e){return`${e<10?0:""}${e}`}renderLegalText(e,t){const n=e,i=t.split("#")[1],r=document.getElementById(i),o=null==r?void 0:r.parentNode,a=document.createElement("div");a.style.marginBottom="20px",a.setAttribute("id",n),null==o||o.prepend(a);const s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=s.Legal({fundingSource:s.Legal.FUNDING.PAY_UPON_INVOICE});if(!document.getElementById(n))throw new W('Unable to initialize payment because "legalTextContainerElement" argument is not found.');d.render(`#${n}`)}handleError(e){const{onError:t}=this.bigcommerce_payments_ratepay||{};this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}createFraudNetScript(e,t,n){const i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t,n),{testMode:r}=i.config,o=document.createElement("script");o.setAttribute("type","application/json"),o.setAttribute("fncls","fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99"),o.setAttribute("data-id","fraudnetScript"),this.guid=this.generateGUID();const a={f:this.guid,s:`${e}_checkout-page`,sandbox:r};o.innerHTML=JSON.stringify(a),document.body.appendChild(o)}generateGUID(){let e="";for(let t=0;t<32;t+=1)e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[Math.floor(62*Math.random())];return e}loadFraudnetConfig(){const e=document.createElement("script");e.setAttribute("data-id","fraudnetConfig"),e.src="https://c.paypal.com/da/r/fb.js",document.body.appendChild(e)}reinitializeStrategy(e){return we(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}initializePollingMechanism(e,t,n,i){return we(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus("bigcommerce_payments_apms",{params:{useMetadata:!0}}),o=r===T.PollingStop,a=r===T.PollingError;if(o)return this.deinitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigcommerce_payments_ratepay:this.bigcommerce_payments_ratepay}),this.handleError(new Ce)}catch(e){this.handleError(e),n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const Ae=g(e=>new Oe(e,R(e),new b({containerStyles:Object.assign(Object.assign({},P),{position:"fixed"})})),[{gateway:"bigcommerce_payments_apms",id:"ratepay"}]);var ze;!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 Ee=ze;function ke(e){return Ee.CardNumber in e&&Ee.CardName in e&&Ee.CardExpiry in e}function Te(e){return Ee.CardNumberVerification in e&&Ee.CardCodeVerification in e&&Ee.CardExpiryVerification in e}class Me extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method has thrown an unexpected error."),this.name="PaymentMethodFailedError",this.type="payment_method_client_invalid"}}var Be;!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"}(Be||(Be={}));class Fe extends l{constructor(e){super(function(e){switch(e){case Be.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case Be.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case Be.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case Be.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 De extends l{constructor(e,t){super(t||"Unable to proceed because the payment form contains invalid data."),this.details=e,this.name="PaymentInvalidFormError",this.type="payment_invalid_form"}}var Ne=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ue{constructor(e,t,n,i){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdk=n,this.bigCommercePaymentsFastlaneUtils=i}initialize(e){return Ne(this,void 0,void 0,function*(){const{methodId:t,bigcommerce_payments_creditcards:n}=e,i=n,{form:r,onCreditCardFieldsRenderingError:o,onLoadComplete:a}=i||{};if(!t)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to proceed because "options.bigcommerce_payments_creditcards.form" argument is not provided.');this.hostedFormOptions=r,this.isCreditCardForm=ke(r.fields),this.isCreditCardVaultedForm=Te(r.fields)&&!this.hasUndefinedValues(),yield this.paymentIntegrationService.loadPaymentMethod(t),yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(t,void 0,!0,!0),(this.isCreditCardForm||this.isCreditCardVaultedForm)&&(yield this.initializeFields(r,o)),null==a||a(),this.shouldInitializePayPalFastlane(t)&&(yield this.initializePayPalFastlaneOrThrow(t))})}execute(e,t){return Ne(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{methodId:r,paymentData:o}=n||{};if(!n||!r)throw new H(["payment"]);if(this.executionPaymentData=o,this.isCreditCardForm||this.isCreditCardVaultedForm)yield this.validateHostedFormOrThrow(),yield this.submitHostedForm();else{const{orderId:e}=yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams());this.returnedOrderId=e}const a=this.preparePaymentPayload(r,o,this.returnedOrderId,this.returnedVaultedToken);yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(a)})}finalize(){return Promise.reject(new $)}deinitialize(){return Ne(this,void 0,void 0,function*(){var e,t,n,i;return yield null===(e=this.cvvField)||void 0===e?void 0:e.close(),yield null===(t=this.expiryField)||void 0===t?void 0:t.close(),yield null===(n=this.numberField)||void 0===n?void 0:n.close(),yield null===(i=this.nameField)||void 0===i?void 0:i.close(),Promise.resolve()})}preparePaymentPayload(e,t,n,i){const{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:a=!1}=Y(t)?t:{},s=t&&q(t)?t.instrumentId:void 0,l=d({verification_nonce:i,token:s},o);return{methodId:e,paymentData:{shouldSaveInstrument:r,shouldSetAsDefaultInstrument:a,instrumentId:s,formattedPayload:Object.assign(Object.assign({},i||s?{bigpay_token:l}:{}),n?{card_with_order:{order_id:n}}:{})}}}initializeFields(e,t){return Ne(this,void 0,void 0,function*(){const{fields:n,styles:i}=e,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.getExecuteCallback(n),a=Object.assign({style:this.getInputStyles(i),onApprove:({orderID:e,vaultSetupToken:t,liabilityShift:n})=>{if(n===w.No||n===w.Unknown)throw new Error;return this.handleApprove({orderID:e,vaultSetupToken:t})},onError:()=>{throw new Me},inputEvents:{onChange:t=>this.onChangeHandler(e,t),onFocus:t=>this.onFocusHandler(e,t),onBlur:t=>this.onBlurHandler(e,t),onInputSubmitRequest:t=>this.onInputSubmitRequest(e,t)}},o);if(this.cardFields=yield r.CardFields(a),!this.cardFields.isEligible())throw new Fe(Be.PaymentNotInitialized);try{this.stylizeInputContainers(n),ke(n)&&(yield this.renderFields(n)),Te(n)&&(yield this.renderVaultedFields(n))}catch(e){"function"==typeof t&&t(e)}})}getExecuteCallback(e){return Te(e)?this.createVaultSetupTokenCallback():this.createOrderCallback()}createVaultSetupTokenCallback(){return{createVaultSetupToken:()=>Ne(this,void 0,void 0,function*(){const{setupToken:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",Object.assign(Object.assign({},this.getInstrumentParams()),{setupToken:!0})))||{};return e})}}createOrderCallback(){return{createOrder:()=>Ne(this,void 0,void 0,function*(){const{orderId:e}=(yield this.bigCommercePaymentsIntegrationService.createOrderCardFields("bigcommerce_payments_creditcardscheckout",this.getInstrumentParams()))||{};return e})}}handleApprove({orderID:e,vaultSetupToken:t}){e&&(this.returnedOrderId=e),t&&(this.returnedVaultedToken=t)}renderFields(e){return Ne(this,void 0,void 0,function*(){var t,n,i,r;const o=this.getCardFieldsOrThrow();(null===(t=e.cardCode)||void 0===t?void 0:t.containerId)&&(this.cvvField=o.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCode.containerId}`)),(null===(n=e.cardExpiry)||void 0===n?void 0:n.containerId)&&(this.expiryField=o.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiry.containerId}`)),(null===(i=e.cardName)||void 0===i?void 0:i.containerId)&&(this.nameField=o.NameField({placeholder:""}),yield this.nameField.render(`#${e.cardName.containerId}`)),(null===(r=e.cardNumber)||void 0===r?void 0:r.containerId)&&(this.numberField=o.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumber.containerId}`))})}renderVaultedFields(e){return Ne(this,void 0,void 0,function*(){var t,n,i;const r=this.getCardFieldsOrThrow();(null===(t=e.cardCodeVerification)||void 0===t?void 0:t.containerId)&&(this.cvvField=r.CVVField({placeholder:""}),yield this.cvvField.render(`#${e.cardCodeVerification.containerId}`)),(null===(n=e.cardExpiryVerification)||void 0===n?void 0:n.containerId)&&(this.expiryField=r.ExpiryField(),yield this.expiryField.render(`#${e.cardExpiryVerification.containerId}`)),(null===(i=e.cardNumberVerification)||void 0===i?void 0:i.containerId)&&(this.numberField=r.NumberField({placeholder:""}),yield this.numberField.render(`#${e.cardNumberVerification.containerId}`))})}getInstrumentParams(){if(!this.executionPaymentData)return{};if(Y(this.executionPaymentData)){const{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}=this.executionPaymentData;return{shouldSaveInstrument:e,shouldSetAsDefaultInstrument:t}}if(q(this.executionPaymentData)){const{instrumentId:e}=this.executionPaymentData;return{instrumentId:e}}return{}}getFieldTypeByEmittedField({emittedBy:e}){return{fieldType:this.mapFieldType(e)}}submitHostedForm(){return Ne(this,void 0,void 0,function*(){const e=this.getCardFieldsOrThrow(),t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n={billingAddress:{company:t.company,addressLine1:t.address1,addressLine2:t.address2,adminArea1:t.stateOrProvinceCode,adminArea2:t.city,postalCode:t.postalCode,countryCode:t.countryCode}};try{this.isCreditCardVaultedForm?yield e.submit():yield e.submit(n)}catch(e){throw new Me("Failed authentication. Please try to authorize again.")}})}validateHostedFormOrThrow(){return Ne(this,void 0,void 0,function*(){var e,t;const n=this.getCardFieldsOrThrow(),i=yield n.getState().then(e=>e),r=this.getValidityData(i);if(!r.isValid)throw null===(t=null===(e=this.hostedFormOptions)||void 0===e?void 0:e.onValidate)||void 0===t||t.call(e,r),new De(this.mapValidationErrors(r.errors))})}getValidityData({fields:e}){const t=Object.assign({},e);delete t.cardNameField;const n=Object.keys(t);return{isValid:n.every(e=>{var n;return null===(n=t[e])||void 0===n?void 0:n.isValid}),errors:n.reduce((e,n)=>{var i;const r=this.mapFieldType(n);return Object.assign(Object.assign({},e),{[r]:(null===(i=t[n])||void 0===i?void 0:i.isValid)?void 0:[this.getInvalidErrorByFieldType(r)]})},{})}}getInvalidErrorByFieldType(e){switch(e){case Ee.CardCode:case Ee.CardCodeVerification:return{fieldType:e,message:"Invalid card code",type:"invalid_card_code"};case Ee.CardNumber:case Ee.CardNumberVerification:return{fieldType:e,message:"Invalid card number",type:"invalid_card_number"};case Ee.CardExpiry:case Ee.CardExpiryVerification:return{fieldType:e,message:"Invalid card expiry",type:"invalid_card_expiry"};default:return{fieldType:e,message:"Invalid field",type:"invalid"}}}mapValidationErrors(e={}){const t={};return Object.keys(e).forEach(n=>{var i,r;t[n]=[{message:(null===(r=null===(i=e[n])||void 0===i?void 0:i[0])||void 0===r?void 0:r.message)||"",type:n}]}),t}mapFieldType(e){switch(e){case"name":return Ee.CardName;case"cardNumberField":case"number":return this.isCreditCardForm?Ee.CardNumber:Ee.CardNumberVerification;case"cardExpiryField":case"expiry":return this.isCreditCardForm?Ee.CardExpiry:Ee.CardExpiryVerification;case"cardCvvField":case"cvv":return this.isCreditCardForm?Ee.CardCode:Ee.CardCodeVerification;default:throw new Error("Unexpected field type")}}getCardFieldsOrThrow(){if(!this.cardFields)throw new Fe(Be.PaymentNotInitialized);return this.cardFields}getInputStyles(e){var t,n,i;const r={"font-size":(null===(t=null==e?void 0:e.default)||void 0===t?void 0:t.fontSize)||"1rem","font-family":(null===(n=null==e?void 0:e.default)||void 0===n?void 0:n.fontFamily)||"Montserrat, Arial, Helvetica, sans-serif","font-weight":(null===(i=null==e?void 0:e.default)||void 0===i?void 0:i.fontWeight)||"400",outline:"none",padding:"9px 13px"},o=Object.assign(Object.assign({},r),{color:"#333333"});return{input:o,".invalid":Object.assign(Object.assign({},r),{color:"red"}),".valid":o,":focus":o}}stylizeInputContainers(e){Object.values(e||{}).forEach(e=>{const t=document.getElementById(`${(null==e?void 0:e.containerId)||""}`);t&&(t.style.padding="0px",t.style.boxShadow="none",t.style.border="none",t.style.background="transparent",t.style.marginBottom="10px",t.style.marginLeft="-5px")})}hasUndefinedValues(){return!this.hostedFormOptions||Object.values(this.hostedFormOptions.fields).some(e=>void 0===e)}onChangeHandler(e,t){var n;null===(n=null==e?void 0:e.onValidate)||void 0===n||n.call(e,this.getValidityData(t))}onFocusHandler(e,t){var n;null===(n=null==e?void 0:e.onFocus)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onBlurHandler(e,t){var n;null===(n=null==e?void 0:e.onBlur)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}onInputSubmitRequest(e,t){var n;null===(n=null==e?void 0:e.onEnter)||void 0===n||n.call(e,this.getFieldTypeByEmittedField(t))}shouldInitializePayPalFastlane(e){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getPaymentMethodOrThrow(e),o=i.getPaymentProviderCustomer(),a=(s=o)&&("authenticationState"in s||"addresses"in s||"instruments"in s)?o:{};var s;return(null===(t=null==r?void 0:r.initializationData)||void 0===t?void 0:t.isAcceleratedCheckoutEnabled)&&(null===(n=null==r?void 0:r.initializationData)||void 0===n?void 0:n.isBigCommercePaymentsAnalyticsV2Enabled)&&!(null==a?void 0:a.authenticationState)}initializePayPalFastlaneOrThrow(e){return Ne(this,void 0,void 0,function*(){try{const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{initializationData:r}=i;if(!(null==r?void 0:r.connectClientToken))return;const o=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(i,n.currency.code,n.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(o,!!(null==r?void 0:r.isDeveloperModeApplicable))}catch(e){}})}}const xe=g(e=>new Ue(e,R(e),p(),ue()),[{id:"bigcommerce_payments_creditcards"}]);var je=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Le{constructor(e){this.paymentIntegrationService=e}initialize(){return je(this,void 0,void 0,function*(){return Promise.resolve()})}execute(e,t){return je(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]),{methodId:r}=n||{};if(!n||!r)throw new H(["payment"]);const o={methodId:r,paymentData:{formattedPayload:{}}};yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment(o)})}finalize(){return Promise.reject(new $)}deinitialize(){return Promise.resolve()}}const Ve=g(e=>new Le(e),[{id:"bigcommerce_payments_invoices"}]);var Re=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ge{constructor(e,t,n,i,r=3e3,o=3e5){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.bigCommercePaymentsSdkHelper=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=o,this.pollingTimer=0,this.stopPolling=a,this.isPollingEnabled=!1}initialize(e){return Re(this,void 0,void 0,function*(){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_payments_apms" argument is not provided.');const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(n,t),{orderId:a,shouldRenderFields:s}=o.initializationData||{},d=r.getStoreConfigOrThrow().checkoutSettings.features;this.isPollingEnabled=ge(d,"PAYPAL-5624.bcp_ideal_polling"),a?this.orderId=a:(this.paypalApms=yield this.bigCommercePaymentsSdkHelper.getPayPalApmsSdk(o,r.getCartOrThrow().currency.code),this.loadingIndicatorContainer=i.container.split("#")[1],this.renderButton(n,t,i),s&&this.renderFields(n,i))})}execute(e,t){return Re(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);const{methodId:r,gatewayId:o}=n;if(!this.orderId)throw new K;this.isPollingEnabled&&"ideal"===r&&(yield new Promise((e,t)=>{this.initializePollingMechanism(r,e,t,o)})),this.isNonInstantPaymentMethod(r)||(yield this.paymentIntegrationService.submitOrder(i,t)),yield this.bigCommercePaymentsIntegrationService.submitPayment(r,this.orderId,o)})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,this.isPollingEnabled&&this.resetPollingMechanism(),null===(e=this.bigCommercePaymentsButton)||void 0===e||e.close(),Promise.resolve()}initializePollingMechanism(e,t,n,i){return Re(this,void 0,void 0,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.bigCommercePaymentsIntegrationService.getOrderStatus(i),o=r===T.Approved,a=r===T.PollingError;if(o)return this.deInitializePollingMechanism(),t();if(a)return n();if(!o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,bigCommercePaymentsAlternativeMethods:this.bigCommercePaymentsAlternativeMethods}),this.handleError(new Ce)}catch(e){n()}})}deInitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deInitializePollingMechanism()}reinitializeStrategy(e){return Re(this,void 0,void 0,function*(){yield this.deinitialize(),yield this.initialize(e)})}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderButton(e,t,n){const i=this.getPaypalAmpsSdkOrThrow(),r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t),{buttonStyle:o}=r.initializationData||{},{container:a,onError:s,onRenderButton:d,submitForm:l}=n,c={fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),onInit:(e,t)=>n.onInitButton(t),createOrder:()=>this.onCreateOrder(e,t,n),onApprove:e=>this.handleApprove(e,l),onCancel:()=>{this.toggleLoadingIndicator(!1),this.deInitializePollingMechanism()},onError:e=>{this.deInitializePollingMechanism(),this.handleFailure(e,s)},onClick:(e,t)=>Re(this,void 0,void 0,function*(){return n.onValidate(t.resolve,t.reject)})};this.bigCommercePaymentsButton=i.Buttons(c),this.bigCommercePaymentsButton.isEligible()&&(d&&"function"==typeof d&&d(),this.bigCommercePaymentsButton.render(a))}onCreateOrder(e,t,n){return Re(this,void 0,void 0,function*(){const{onValidate:i}=n;yield i(()=>(this.toggleLoadingIndicator(!0),()=>Promise.resolve()),a);const r=yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms");if(this.isNonInstantPaymentMethod(e)){const n={useStoreCredit:!1},i={params:{methodId:e,gatewayId:t}};yield this.paymentIntegrationService.submitOrder(n,i),yield this.bigCommercePaymentsIntegrationService.submitPayment(e,r,t)}return r})}handleApprove({orderID:e},t){this.orderId=e,t()}handleFailure(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}renderFields(e,t){const n=this.getPaypalAmpsSdkOrThrow(),i=this.paymentIntegrationService.getState(),{firstName:r,lastName:o,email:a}=i.getBillingAddressOrThrow(),{apmFieldsContainer:s,apmFieldsStyles:d}=t;if(!s)throw new W('Unable to initialize payment because "options.bigcommerce_payments_apms" argument should contain "apmFieldsContainer".');const l=document.querySelector(s);l&&(l.innerHTML="");const c={fundingSource:e,style:d||{},fields:{name:{value:`${r} ${o}`},email:{value:a}}};n.PaymentFields(c).render(s)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}isNonInstantPaymentMethod(e){return e.toUpperCase()in k}getPaypalAmpsSdkOrThrow(){if(!this.paypalApms)throw new c;return this.paypalApms}}const We=g(e=>new Ge(e,R(e),p(),new b({containerStyles:P})),[{gateway:"bigcommerce_payments_apms"}]);class He{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){const{gatewayId:t,methodId:n,bigcommerce_payments_apms:i}=e;if(this.bigCommercePaymentsAlternativeMethods=i,!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.gatewayId" argument is not provided.');return Promise.resolve()}execute(e,t){return n=this,i=void 0,o=function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);const{methodId:r,gatewayId:o}=n;try{const e={formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:null,method_id:r,paypal_account:{order_id:yield this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_apms",{gatewayId:"bigcommerce_payments_apms",methodId:r})}}};yield this.paymentIntegrationService.submitOrder(i,t),yield this.paymentIntegrationService.submitPayment({methodId:r,gatewayId:o,paymentData:e})}catch(e){if(function(e){var t,n;return(e=>"object"==typeof e&&null!==e&&"body"in e)(e)&&(null===(n=null===(t=e.body)||void 0===t?void 0:t.additional_action_required)||void 0===n?void 0:n.data.redirect_url)}(e)){const t=e.body.additional_action_required.data.redirect_url;return new Promise((e,n)=>{window.location.replace(t),n()})}return this.handleError(e),Promise.reject(e)}},new((r=void 0)||(r=Promise))(function(e,t){function a(e){try{d(o.next(e))}catch(e){t(e)}}function s(e){try{d(o.throw(e))}catch(e){t(e)}}function d(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r(function(e){e(n)})).then(a,s)}d((o=o.apply(n,i||[])).next())});var n,i,r,o}finalize(){return Promise.reject(new $)}deinitialize(){return Promise.resolve()}handleError(e){const{onError:t}=this.bigCommercePaymentsAlternativeMethods||{};t&&"function"==typeof t&&t(e)}}const Ke=g(e=>new He(e,R(e)),[{gateway:"bigcommerce_payments_apms",id:"klarna"},{gateway:"bigcommerce_payments_apms",id:"afterpay"}]);var $e=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Ye{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.loadingIndicator=n}initialize(e){return $e(this,void 0,void 0,function*(){var t,n;const{methodId:i,bigcommerce_payments_venmo:r}=e||{};if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(i);const o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i);(null===(t=o.initializationData)||void 0===t?void 0:t.orderId)?this.orderId=null===(n=o.initializationData)||void 0===n?void 0:n.orderId:(yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i),this.loadingIndicatorContainer=r.container.split("#")[1],this.renderButton(i,r))})}execute(e,t){return $e(this,void 0,void 0,function*(){const{payment:n}=e,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(e,["payment"]);if(!n)throw new H(["payment"]);if(!this.orderId)throw new K;yield this.paymentIntegrationService.submitOrder(i,t),yield this.bigCommercePaymentsIntegrationService.submitPayment(n.methodId,this.orderId)})}finalize(){return Promise.reject(new $)}deinitialize(){var e;return this.orderId=void 0,null===(e=this.paypalButton)||void 0===e||e.close(),Promise.resolve()}renderButton(e,t){const n=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:r}=i.initializationData||{},{checkoutPaymentButtonStyles:o}=r||{},{container:a,onError:s,onRenderButton:d,onValidate:l,submitForm:c}=t,m={fundingSource:n.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(o),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmocheckout"),onClick:(e,t)=>this.handleClick(t,l),onApprove:e=>this.handleApprove(e,c),onCancel:()=>this.toggleLoadingIndicator(!1),onError:e=>this.handleError(e,s)};if(this.paypalButton=n.Buttons(m),!this.paypalButton.isEligible())throw new Pe("Venmo is not available for your region. Please another payment method instead.");d&&"function"==typeof d&&d(),this.paypalButton.render(a)}handleClick(e,t){return $e(this,void 0,void 0,function*(){const{resolve:n,reject:i}=e;yield t(()=>(this.toggleLoadingIndicator(!0),n()),i)})}handleApprove({orderID:e},t){this.orderId=e,t(),this.toggleLoadingIndicator(!1)}handleError(e,t){this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}}const qe=g(e=>new Ye(e,R(e),new b({styles:{backgroundColor:"black"}})),[{id:"bigcommerce_payments_venmo"}]);var Ze=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Je{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=a}initialize(e){return Ze(this,void 0,void 0,function*(){const{bigcommerce_payments:t,methodId:n}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(!t.container)throw new W('Unable to initialize payment because "options.bigcommerce_payments.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new W('Unable to initialize payment because "options.bigcommerce_payments.onClick" argument is not a function.');this.onError=t.onError||a,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC PayPal]: PayPal Button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signInCustomer(e,t),Promise.resolve()})}signOut(e){return Ze(this,void 0,void 0,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onClick:i,onComplete:r}=t,o=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d,isServerSideShippingCallbacksEnabled:l}=a.initializationData||{},{checkoutTopButtonStyles:c}=d||{},m=Object.assign({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),u=Object.assign(Object.assign({},!l&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,r,l)}),h=Object.assign(Object.assign({fundingSource:o.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},c),{height:40}))},m),s&&u),y=o.Buttons(h);y.isEligible()?y.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i,r){return Ze(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}a&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return Ze(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}onShippingOptionsChange(e){return Ze(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const Qe=g(e=>new Je(e,R(e)),[{id:"bigcommerce_payments"}]);var Xe=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class et{constructor(e,t,n){this.paymentIntegrationService=e,this.bigCommercePaymentsSdk=t,this.bigCommercePaymentsFastlaneUtils=n}initialize(e){return Xe(this,void 0,void 0,function*(){var t;const{methodId:n,bigcommerce_payments_fastlane:i}=e;if(this.options=e,!n)throw new W('Unable to proceed because "methodId" argument is not provided.');try{yield this.paymentIntegrationService.loadPaymentMethod(n);const e=this.paymentIntegrationService.getState(),r=e.getCartOrThrow(),o=e.getPaymentMethodOrThrow(n),a=!!(null===(t=o.initializationData)||void 0===t?void 0:t.isDeveloperModeApplicable),s=yield this.bigCommercePaymentsSdk.getPayPalFastlaneSdk(o,r.currency.code,r.id);yield this.bigCommercePaymentsFastlaneUtils.initializePayPalFastlane(s,a,this.getFastlaneStyles(n,i))}catch(e){this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Xe(this,void 0,void 0,function*(){return Promise.resolve()})}signIn(e,t){return Xe(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.bigCommercePaymentsFastlaneUtils.removeStorageSessionId()})}signOut(e){return Xe(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Xe(this,void 0,void 0,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n,methodId:i}=e||{};if(!i)throw new W('Unable to proceed because "methodId" argument is not provided.');if("function"!=typeof n)throw new W('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');if(this.paymentIntegrationService.getState().getCustomerOrThrow().isGuest){t&&"function"==typeof t&&t();try{yield this.runPayPalAuthenticationFlowOrThrow(i)}catch(e){this.handleErrorLog(e)}}n()})}runPayPalAuthenticationFlowOrThrow(e){return Xe(this,void 0,void 0,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow().id,i=t.getCustomer(),r=t.getBillingAddress(),o=(null==i?void 0:i.email)||(null==r?void 0:r.email)||"",{customerContextId:a}=yield this.bigCommercePaymentsFastlaneUtils.lookupCustomerOrThrow(o),s=yield this.bigCommercePaymentsFastlaneUtils.triggerAuthenticationFlowOrThrow(a),d=s.authenticationState===de.CANCELED;yield this.updateCustomerDataState(e,s),d?this.bigCommercePaymentsFastlaneUtils.removeStorageSessionId():this.bigCommercePaymentsFastlaneUtils.updateStorageSessionId(n)})}updateCustomerDataState(e,t){return Xe(this,void 0,void 0,function*(){var n;const i=this.paymentIntegrationService.getState().getCartOrThrow(),{authenticationState:r,addresses:o,billingAddress:a,shippingAddress:s,instruments:d}=this.bigCommercePaymentsFastlaneUtils.mapPayPalFastlaneProfileToBcCustomerData(e,t);if(yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:r,addresses:o,instruments:d}),a&&(yield this.paymentIntegrationService.updateBillingAddress(a)),s&&i.lineItems.physicalItems.length>0){const t=yield this.paymentIntegrationService.updateShippingAddress(s),i=t.getPaymentMethodOrThrow(e),{isFastlaneShippingOptionAutoSelectEnabled:r}=i.initializationData||{},o=(null===(n=(t.getConsignments()||[])[0])||void 0===n?void 0:n.availableShippingOptions)||[],a=o[0],d=o.find(e=>e.isRecommended);if((d||a)&&r){const e=(null==d?void 0:d.id)||a.id;yield this.paymentIntegrationService.selectShippingOption(e)}}})}getFastlaneStyles(e,t){const n=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{fastlaneStyles:i,isFastlaneStylingEnabled:r}=n.initializationData||{};return ye(r?i:{},null==t?void 0:t.styles)}handleErrorLog(e){const{onErrorLog:t}=this.options||{};t&&"function"==typeof t&&t(e)}}const tt=g(e=>new et(e,p(),ue()),[{id:"bigcommerce_payments_fastlane"},{id:"bigcommerce_payments_creditcards"}]);var nt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class it{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t,this.onError=a}initialize(e){return nt(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,methodId:n}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(!t.container)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.onClick" argument is not a function.');this.onError=t.onError||a,this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC BigCommercePayments PayLater]: button could not be rendered, due to issues with loading PayPal SDK")})}deinitialize(){return Promise.resolve()}signIn(e,t){return nt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return nt(this,void 0,void 0,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}renderButton(e,t){const{container:n,onComplete:i,onClick:r}=t,o=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),a=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{isHostedCheckoutEnabled:s,paymentButtonStyles:d}=a.initializationData||{},{checkoutTopButtonStyles:l}=d||{},c=Object.assign({createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},r&&{onClick:()=>r()}),m={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(t,n)=>this.onHostedCheckoutApprove(t,n,e,i)},u=[o.FUNDING.PAYLATER,o.FUNDING.CREDIT];let h=!1;u.forEach(e=>{if(!h){const t=Object.assign(Object.assign({fundingSource:e,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},l),{height:40}))},c),s&&m),i=o.Buttons(t);i.isEligible()&&(i.render(`#${n}`),h=!0)}}),h||this.bigCommercePaymentsIntegrationService.removeElement(n)}onHostedCheckoutApprove(e,t,n,i){return nt(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i()}catch(e){this.handleError(e)}})}onShippingAddressChange(e){return nt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}onShippingOptionsChange(e){return nt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){this.handleError(e)}})}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const rt=g(e=>new it(e,R(e)),[{id:"bigcommerce_payments_paylater"}]);var ot=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class at{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return ot(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,methodId:n}=e;if(!n)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(!t.container)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.container" argument is not provided.');if(t.onClick&&"function"!=typeof t.onClick)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.onClick" argument is not a function.');this.paymentIntegrationService.getState().getPaymentMethod(n)||(yield this.paymentIntegrationService.loadPaymentMethod(n));const i=yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(n);i&&i.Buttons&&"function"==typeof i.Buttons?this.renderButton(n,t):console.error("[BC Payments Venmo]: 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:n,onClick:i}=t,r=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),o=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e),{paymentButtonStyles:a}=o.initializationData||{},{checkoutTopButtonStyles:s}=a||{},d=Object.assign({fundingSource:r.FUNDING.VENMO,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(Object.assign(Object.assign({},s),{height:40})),createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:t})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(e,t)},i&&{onClick:()=>i()}),l=r.Buttons(d);l.isEligible()?l.render(`#${n}`):this.bigCommercePaymentsIntegrationService.removeElement(n)}}const st=g(e=>new at(e,R(e)),[{id:"bigcommerce_payments_venmo"}]);var dt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class lt{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return dt(this,void 0,void 0,function*(){var t;const{bigcommerce_payments:n,containerId:i,methodId:r}=e,o=Boolean(null==n?void 0:n.buyNowInitializeOptions);if(!r)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.bigcommerce_payments" argument is not provided.');if(o&&!n.currencyCode)throw new W('Unable to initialize payment because "options.bigcommerce_payments.currencyCode" argument is not provided.');if(o&&"function"!=typeof(null===(t=n.buyNowInitializeOptions)||void 0===t?void 0:t.getBuyNowCartRequestBody))throw new W('Unable to initialize payment because "options.bigcommerce_payments.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');o||(yield this.paymentIntegrationService.loadDefaultCheckout());const a=o?n.currencyCode:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(r,a,!1),this.renderButton(i,r,n)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l,isServerSideShippingCallbacksEnabled:c}=d.initializationData||{},m={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},u={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},h=Object.assign(Object.assign({},!c&&{onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e)}),{onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o,c)}),y=Object.assign(Object.assign(Object.assign({fundingSource:s.FUNDING.PAYPAL,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},m),i&&u),l&&h),p=s.Buttons(y);p.isEligible()?p.render(`#${e}`):a&&"function"==typeof a?a():this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return dt(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i,r){return dt(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const o=this.paymentIntegrationService.getState().getCartOrThrow();try{const a=o.lineItems.physicalItems.length>0;if(!r){const e=yield t.order.get(),n=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(e);if(yield this.paymentIntegrationService.updateBillingAddress(n),a){const t=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(e);yield this.paymentIntegrationService.updateShippingAddress(t)}}return a&&(yield this.bigCommercePaymentsIntegrationService.updateOrder(r)),r&&(yield this.paymentIntegrationService.loadCheckout()),yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return dt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingOptionsChange(e){return dt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}}const ct=g(e=>new lt(e,R(e)),[{id:"bigcommerce_payments"}]);var mt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class ut{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return mt(this,void 0,void 0,function*(){const{bigcommerce_payments_paylater:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater" argument is not provided.');if(a&&!o)throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new W('Unable to initialize payment because "options.bigcommerce_payments_paylater.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=this.paymentIntegrationService.getState(),d=a?o:s.getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,d,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onComplete:o,onEligibilityFailure:a}=n,s=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),d=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{isHostedCheckoutEnabled:l}=d.initializationData||{},c={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_paylater"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},m={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},u={onShippingAddressChange:e=>this.onShippingAddressChange(e),onShippingOptionsChange:e=>this.onShippingOptionsChange(e),onApprove:(e,n)=>this.onHostedCheckoutApprove(e,n,t,o)},h=[s.FUNDING.PAYLATER,s.FUNDING.CREDIT];let y=!1;h.forEach(t=>{if(!y){const n=Object.assign(Object.assign(Object.assign({fundingSource:t,style:this.bigCommercePaymentsIntegrationService.getValidButtonStyle(r)},c),i&&m),l&&u),o=s.Buttons(n);o.isEligible()?(o.render(`#${e}`),y=!0):a&&"function"==typeof a&&a()}}),y||this.bigCommercePaymentsIntegrationService.removeElement(e)}handleClick(e){return mt(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}onHostedCheckoutApprove(e,t,n,i){return mt(this,void 0,void 0,function*(){if(!e.orderID)throw new u(m.MissingOrderId);const r=this.paymentIntegrationService.getState().getCartOrThrow(),o=yield t.order.get();try{const t=this.bigCommercePaymentsIntegrationService.getBillingAddressFromOrderDetails(o);if(yield this.paymentIntegrationService.updateBillingAddress(t),r.lineItems.physicalItems.length>0){const e=this.bigCommercePaymentsIntegrationService.getShippingAddressFromOrderDetails(o);yield this.paymentIntegrationService.updateShippingAddress(e),yield this.bigCommercePaymentsIntegrationService.updateOrder()}return yield this.paymentIntegrationService.submitOrder({},{params:{methodId:n}}),yield this.bigCommercePaymentsIntegrationService.submitPayment(n,e.orderID),i&&"function"==typeof i&&i(),!0}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}onShippingAddressChange(e){return mt(this,void 0,void 0,function*(){const t=this.bigCommercePaymentsIntegrationService.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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow();yield this.paymentIntegrationService.selectShippingOption(e.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}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.bigCommercePaymentsIntegrationService.getShippingOptionOrThrow(e.selectedShippingOption.id);try{yield this.paymentIntegrationService.selectShippingOption(t.id),yield this.bigCommercePaymentsIntegrationService.updateOrder()}catch(e){if("string"==typeof e)throw new Error(e);throw e}})}}const ht=g(e=>new ut(e,R(e)),[{id:"bigcommerce_payments_paylater"}]);var yt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class pt{constructor(e,t){this.paymentIntegrationService=e,this.bigCommercePaymentsIntegrationService=t}initialize(e){return yt(this,void 0,void 0,function*(){const{bigcommerce_payments_venmo:t,containerId:n,methodId:i}=e,{buyNowInitializeOptions:r,currencyCode:o}=t||{},a=!!r;if(!i)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo" argument is not provided.');if(a&&!o)throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.currencyCode" argument is not provided.');if(a&&"function"!=typeof(null==r?void 0:r.getBuyNowCartRequestBody))throw new W('Unable to initialize payment because "options.bigcommerce_payments_venmo.buyNowInitializeOptions.getBuyNowCartRequestBody" argument is not provided or it is not a function.');a||(yield this.paymentIntegrationService.loadDefaultCheckout());const s=a?o:this.paymentIntegrationService.getState().getCartOrThrow().currency.code;yield this.bigCommercePaymentsIntegrationService.loadPayPalSdk(i,s,!1),this.renderButton(n,i,t)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n){const{buyNowInitializeOptions:i,style:r,onEligibilityFailure:o}=n,a=this.bigCommercePaymentsIntegrationService.getPayPalSdkOrThrow(),s=a.FUNDING.VENMO,d={createOrder:()=>this.bigCommercePaymentsIntegrationService.createOrder("bigcommerce_payments_venmo"),onApprove:({orderID:e})=>this.bigCommercePaymentsIntegrationService.tokenizePayment(t,e)},l={onClick:()=>this.handleClick(i),onCancel:()=>this.paymentIntegrationService.loadDefaultCheckout()},c=Object.assign(Object.assign({fundingSource:s,style:this.getValidVenmoButtonStyles(r)},d),i&&l),m=a.Buttons(c);m.isEligible()?m.render(`#${e}`):o&&"function"==typeof o?o():this.bigCommercePaymentsIntegrationService.removeElement(e)}getValidVenmoButtonStyles(e){const t=this.bigCommercePaymentsIntegrationService.getValidButtonStyle(e);return t.color===z.gold?Object.assign(Object.assign({},t),{color:void 0}):t}handleClick(e){return yt(this,void 0,void 0,function*(){if(e){const t=yield this.bigCommercePaymentsIntegrationService.createBuyNowCartOrThrow(e);yield this.paymentIntegrationService.loadCheckout(t.id)}})}}const gt=g(e=>new pt(e,R(e)),[{id:"bigcommerce_payments_venmo"}]);var vt,ft,bt,Pt,_t,St,It,Ct,wt,Ot;!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(vt||(vt={})),(ft||(ft={})).Always="SCA_ALWAYS",function(e){e.Succeeded="succeeded",e.Cancelled="cancelled",e.Errored="errored"}(bt||(bt={})),function(e){e.Possible="POSSIBLE",e.No="NO",e.Unknown="UNKNOWN",e.Yes="YES"}(Pt||(Pt={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(_t||(_t={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(St||(St={})),function(e){e.pill="pill",e.rect="rect"}(It||(It={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized"}(Ct||(Ct={})),(wt||(wt={})).OXXO="oxxo",function(e){e.Approved="APPROVED",e.Created="CREATED",e.PayerActionRequired="PAYER_ACTION_REQUIRED",e.PollingStop="POLLING_STOP",e.PollingError="POLLING_ERROR"}(Ot||(Ot={}));var At=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class zt{constructor(e,t,n="PayPalCommercePaymentWalletIntentData"){this.walletButtonIntegrationService=e,this.scriptLoader=t,this.intentTypename=n}loadPayPalSdk(e,t,n,i){return At(this,void 0,void 0,function*(){return this.paypalSdk=yield this.scriptLoader.getPayPalSDK(e,t,void 0,n,i),this.paypalSdk})}getPayPalSdkOrThrow(){if(!this.paypalSdk)throw new c;return this.paypalSdk}proxyTokenizationPayment(e,t,n,i){return At(this,void 0,void 0,function*(){var r;if(!i)throw new u(m.MissingOrderId);const o={paymentWalletData:{providerId:t,providerOrderId:i},cartEntityId:e,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:n},{key:"order_id",value:i}]},a=yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(o);if(!(null===(r=a.body.redirectUrls)||void 0===r?void 0:r.externalCheckoutUrl))throw new Error("Failed to redirection to checkout page");window.location.assign(a.body.redirectUrls.externalCheckoutUrl)})}createPaymentOrderIntent(e,t,n){return At(this,void 0,void 0,function*(){const i={cartEntityId:t,paymentWalletEntityId:e};return(yield this.walletButtonIntegrationService.createPaymentOrderIntent(i,this.intentTypename,n)).body.orderId})}addBillingAddress(e,t,n){return At(this,void 0,void 0,function*(){return this.walletButtonIntegrationService.addBillingAddress(e,t,n)})}mapOrderDetailsToBillingAddress({payer:e}){var t,n,i,r;return{firstName:e.name.given_name,lastName:e.name.surname,company:"",address1:e.address.address_line_1,address2:e.address.address_line_2,city:e.address.admin_area_2,email:e.email_address,stateOrProvince:null!==(t=e.address.admin_area_1)&&void 0!==t?t:"",stateOrProvinceCode:null!==(n=e.address.admin_area_1)&&void 0!==n?n:"",countryCode:e.address.country_code,postalCode:e.address.postal_code,phone:null!==(r=null===(i=e.phone)||void 0===i?void 0:i.phone_number.national_number)&&void 0!==r?r:"",shouldSaveAddress:!1}}getValidButtonStyle(e={}){const{color:t,height:n,label:i,shape:r}=e,a={color:t&&St[t]?t:void 0,height:this.getValidHeight(n),label:i&&_t[i]?i:void 0,shape:r&&It[r]?r:void 0};return d(a,o)}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 Et=["ar_BH","ar_DZ","ar_EG","ar_JO","ar_KW","ar_MA","ar_OM","ar_QA","ar_SA","ar_TN","ar_YE","ar_AE","bg_BG","cs_CZ","da_DK","da_FO","da_GL","de_AT","de_CH","de_DE","de_LU","el_GR","en_AD","en_AE","en_AG","en_AI","en_AL","en_AM","en_AN","en_AO","en_AT","en_AU","en_AW","en_AZ","en_BB","en_BE","en_BH","en_BJ","en_BM","en_BN","en_BS","en_BT","en_BW","en_BY","en_BZ","en_C2","en_CA","en_CD","en_CG","en_CH","en_CI","en_CK","en_CL","en_CM","en_CN","en_CO","en_CR","en_CV","en_CY","en_CZ","en_DE","en_DJ","en_DK","en_DM","en_DO","en_DZ","en_EC","en_EE","en_EG","en_ER","en_ES","en_ET","en_FI","en_FJ","en_FK","en_FM","en_FO","en_FR","en_GA","en_GB","en_GD","en_GE","en_GF","en_GI","en_GL","en_GM","en_GN","en_GP","en_GR","en_GT","en_GW","en_GY","en_HK","en_HN","en_HR","en_HU","en_ID","en_IE","en_IL","en_IN","en_IS","en_IT","en_JM","en_JO","en_JP","en_KE","en_KG","en_KH","en_KI","en_KM","en_KN","en_KR","en_KW","en_KY","en_KZ","en_LA","en_LC","en_LI","en_LK","en_LS","en_LT","en_LU","en_LV","en_MA","en_MC","en_MD","en_ME","en_MG","en_MH","en_MK","en_ML","en_MN","en_MQ","en_MR","en_MS","en_MT","en_MU","en_MV","en_MW","en_MY","en_MZ","en_NA","en_NC","en_NE","en_NF","en_NG","en_NI","en_NL","en_NO","en_NP","en_NR","en_NU","en_NZ","en_OM","en_PA","en_PE","en_PF","en_PG","en_PH","en_PL","en_PM","en_PN","en_PT","en_PW","en_PY","en_QA","en_RE","en_RO","en_RS","en_RU","en_RW","en_SA","en_SB","en_SC","en_SE","en_SG","en_SH","en_SI","en_SJ","en_SK","en_SL","en_SM","en_SN","en_SO","en_SR","en_ST","en_SV","en_SZ","en_TC","en_TD","en_TG","en_TH","en_TJ","en_TM","en_TN","en_TO","en_TR","en_TT","en_TV","en_TW","en_TZ","en_UA","en_UG","en_US","en_UY","en_VA","en_VC","en_VE","en_VG","en_VN","en_VU","en_WF","en_WS","en_YE","en_YT","en_ZA","en_ZM","en_ZW","es_AD","es_AI","es_AO","es_AR","es_AW","es_BB","es_BJ","es_BM","es_BO","es_BS","es_BZ","es_CD","es_CG","es_CK","es_CL","es_CO","es_CR","es_CV","es_DJ","es_DM","es_DO","es_DZ","es_EC","es_EG","es_ER","es_ES","es_ET","es_FJ","es_FK","es_FO","es_GA","es_GD","es_GE","es_GI","es_GL","es_GM","es_GN","es_GT","es_GW","es_GY","es_HN","es_IE","es_JM","es_JO","es_KE","es_KG","es_KI","es_KM","es_KN","es_KW","es_KY","es_KZ","es_LC","es_LI","es_LS","es_LU","es_MA","es_MG","es_MH","es_ML","es_MR","es_MS","es_MU","es_MW","es_MX","es_MZ","es_NA","es_NC","es_NE","es_NF","es_NI","es_NR","es_NU","es_NZ","es_OM","es_PA","es_PE","es_PF","es_PG","es_PM","es_PN","es_PW","es_PY","es_QA","es_RS","es_RW","es_SA","es_SB","es_SC","es_SH","es_SJ","es_SL","es_SM","es_SN","es_SO","es_SR","es_ST","es_SV","es_SZ","es_TC","es_TD","es_TG","es_TJ","es_TM","es_TN","es_TT","es_TV","es_UA","es_UG","es_US","es_UY","es_VA","es_VC","es_VE","es_VG","es_VU","es_WF","es_YE","es_ZM","et_EE","fi_FI","fr_AD","fr_AE","fr_AI","fr_AM","fr_AO","fr_AW","fr_AZ","fr_BB","fr_BE","fr_BF","fr_BI","fr_BJ","fr_BM","fr_BS","fr_BZ","fr_CA","fr_CD","fr_CG","fr_CH","fr_CI","fr_CK","fr_CM","fr_CV","fr_DJ","fr_DM","fr_DO","fr_DZ","fr_EC","fr_ER","fr_ET","fr_FJ","fr_FK","fr_FO","fr_FR","fr_GA","fr_GD","fr_GE","fr_GF","fr_GI","fr_GL","fr_GM","fr_GN","fr_GP","fr_GT","fr_GW","fr_GY","fr_HN","fr_IE","fr_JM","fr_JO","fr_KE","fr_KG","fr_KI","fr_KM","fr_KN","fr_KW","fr_KY","fr_KZ","fr_LC","fr_LI","fr_LS","fr_LU","fr_MA","fr_MC","fr_MG","fr_MH","fr_ML","fr_MQ","fr_MR","fr_MS","fr_MU","fr_MW","fr_MZ","fr_NA","fr_NC","fr_NE","fr_NF","fr_NI","fr_NR","fr_NU","fr_NZ","fr_OM","fr_PA","fr_PE","fr_PF","fr_PG","fr_PM","fr_PN","fr_PW","fr_QA","fr_RE","fr_RS","fr_RW","fr_SA","fr_SB","fr_SC","fr_SH","fr_SJ","fr_SL","fr_SM","fr_SN","fr_SO","fr_SR","fr_ST","fr_SV","fr_SZ","fr_TC","fr_TD","fr_TG","fr_TJ","fr_TM","fr_TN","fr_TT","fr_TV","fr_UA","fr_UG","fr_US","fr_UY","fr_VA","fr_VC","fr_VE","fr_VG","fr_VU","fr_WF","fr_YE","fr_YT","fr_ZA","fr_ZM","he_IL","hu_HU","id_ID","it_IT","ja_JP","ko_KR","lv_LV","lt_LT","ms_BN","ms_MY","nl_BE","nl_NL","pl_PL","pt_BR","pt_PT","ro_RO","ru_EE","ru_LT","ru_LV","ru_RU","ru_UA","si_LK","sk_SK","sl_SI","sq_AL","sv_SE","tl_PH","th_TH","tr_TR","vi_VN","zh_C2","zh_CN","zh_HK","zh_TW","zh_AD","zh_AE","zh_AI","zh_AO","zh_AW","zh_BB","zh_BH","zh_BJ","zh_BM","zh_BS","zh_BZ","zh_CD","zh_CG","zh_CK","zh_CL","zh_CO","zh_CV","zh_DJ","zh_DM","zh_DO","zh_DZ","zh_EC","zh_EG","zh_ER","zh_ET","zh_FJ","zh_FK","zh_FO","zh_GA","zh_GD","zh_GE","zh_GI","zh_GL","zh_GM","zh_GN","zh_GT","zh_GW","zh_GY","zh_HN","zh_IE","zh_JM","zh_JO","zh_KE","zh_KG","zh_KI","zh_KM","zh_KN","zh_KW","zh_KY","zh_KZ","zh_LC","zh_LI","zh_LS","zh_LT","zh_LU","zh_MA","zh_MG","zh_MH","zh_ML","zh_MR","zh_MS","zh_MU","zh_MW","zh_MZ","zh_NA","zh_NC","zh_NE","zh_NF","zh_NI","zh_NR","zh_NU","zh_NZ","zh_OM","zh_PA","zh_PE","zh_PF","zh_PG","zh_PM","zh_PN","zh_PW","zh_QA","zh_RS","zh_RW","zh_SA","zh_SB","zh_SC","zh_SH","zh_SJ","zh_SL","zh_SM","zh_SN","zh_SO","zh_SR","zh_ST","zh_SV","zh_SZ","zh_TC","zh_TD","zh_TG","zh_TJ","zh_TM","zh_TN","zh_TT","zh_TV","zh_UA","zh_UG","zh_US","zh_UY","zh_VA","zh_VC","zh_VE","zh_VG","zh_VU","zh_WF","zh_YE","zh_ZA","zh_ZM"];function kt(e){if(!e)return;let t;if(e.includes("-")){const[n,i]=e.split("-");t=`${n}_${i.toUpperCase()}`}else t=`${e}_${e.toUpperCase()}`;return Et.includes(t)?t:void 0}var Tt=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Mt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalSDK(e,t,n,i,r){return Tt(this,void 0,void 0,function*(){if(!this.window.paypal||r){const r=this.getPayPalSdkScriptConfigOrThrow(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypal)throw new c}return this.window.paypal})}getPayPalFastlaneSdk(e,t,n,i){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const r=this.getPayPalFastlaneSdkConfiguration(e,t,n,i);if(yield this.loadPayPalSdk(r),!this.window.paypalFastlaneSdk)throw new c}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i,r){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||r){const r=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i);yield this.loadPayPalSdk(r)}if(!this.window.paypalGooglePay)throw new c;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t,n){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalApms){const i=this.getPayPalApmSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalApms)throw new c}return this.window.paypalApms})}getPayPalMessages(e,t,n){return Tt(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const i=this.getPayPalSdkMessagesConfiguration(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalMessages)throw new c;return this.window.paypalMessages})}loadPayPalSdk(e){return Tt(this,arguments,void 0,function*({options:e,attributes:t}){const n=this.transformConfig(e),i=this.transformConfig(t),r=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(r,{async:!0,attributes:i})})}getPayPalSdkScriptConfigOrThrow(e,t,n,i=!0){const{id:r,clientToken:o,initializationData:a}=e;if(!a||!a.clientId)throw new u(m.MissingPaymentMethod);const{intent:s,clientId:d,merchantId:l,buyerCountry:c,attributionId:h,isVenmoEnabled:y,isHostedCheckoutEnabled:p,isPayPalCreditAvailable:g,isDeveloperModeApplicable:v,availableAlternativePaymentMethods:f=[],enabledAlternativePaymentMethods:b=[],isGooglePayEnabled:P}=a,_=p||i,S="paypalcommercecreditcards"===r||"bigcommerce_payments_creditcards"===r,I=S?["card"]:[],C=S?[]:["card"],w=g?["credit","paylater"]:[],O=g?[]:["credit","paylater"],A=y?["venmo"]:[],z=y?[]:["venmo"],E=f.filter(e=>!b.includes(e)),k=P?["googlepay"]:[],T=i?["card-fields"]:[],M=this.filterFundingOptions([...C,...O,...z,...E]),B=this.filterFundingOptions([...I,...w,...A,...b]),F=kt(n);return{options:Object.assign(Object.assign({"client-id":d,"merchant-id":l,"enable-funding":B.length>0?B:void 0,"disable-funding":M.length>0?M:void 0,commit:_,components:["buttons","hosted-fields","payment-fields","legal",...k,...T],currency:t,intent:s},v&&{"buyer-country":c}),F&&{locale:F}),attributes:{"data-partner-attribution-id":h,"data-client-token":o}}}getPayPalFastlaneSdkConfiguration(e,t,n,i){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new u(m.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,attributionId:l}=o,c=kt(i);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t},c&&{locale:c}),{intent:a}),attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":l,"data-sdk-client-token":r}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n,i=!0){const{clientToken:r,initializationData:o}=e;if(!o||!o.clientId)throw new u(m.MissingPaymentMethod);const{intent:a,clientId:s,merchantId:d,buyerCountry:l,attributionId:c,isHostedCheckoutEnabled:h,isDeveloperModeApplicable:y}=o,p=h||i,g=kt(n);return{options:Object.assign(Object.assign({"client-id":s,"merchant-id":d,commit:p,components:["googlepay"],currency:t,intent:a},y&&{"buyer-country":l}),g&&{locale:g}),attributes:{"data-partner-attribution-id":c,"data-client-token":r,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{intent:r,clientId:o,merchantId:a,buyerCountry:s,attributionId:d,isDeveloperModeApplicable:l,availableAlternativePaymentMethods:c=[],enabledAlternativePaymentMethods:h=[]}=i,y=this.filterFundingOptions(h),p=this.filterFundingOptions(c.filter(e=>!h.includes(e))),g=kt(n);return{options:Object.assign(Object.assign({"client-id":o,"merchant-id":a,"enable-funding":y.length>0?y:void 0,"disable-funding":p.length>0?p:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:r},l&&{"buyer-country":s}),g&&{locale:g}),attributes:{"data-partner-attribution-id":d,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t,n){const{initializationData:i}=e;if(!i||!i.clientId)throw new u(m.MissingPaymentMethod);const{clientId:r,merchantId:o,attributionId:a,isDeveloperModeApplicable:s,buyerCountry:d}=i,l=kt(n);return{options:Object.assign(Object.assign({"client-id":r,"merchant-id":o,components:["messages"],currency:t},s&&{"buyer-country":d}),l&&{locale:l}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function Bt(){return new Mt(t())}var Ft=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class Dt{constructor(e){this.bigCommercePaymentsWalletService=e}initialize(e){return Ft(this,void 0,void 0,function*(){var t,n;const{bigcommerce_paymentspaypal:i,containerId:r,methodId:o}=e;if(!o)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_paymentspaypal" argument is not provided.');let a;try{a=JSON.parse(atob(i.initializationData))}catch(e){throw new W("Failed to parse payment method 'initializationData'.")}const s=null===(n=null===(t=a.initializationData)||void 0===t?void 0:t.paymentButtonStyles)||void 0===n?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsWalletService.loadPayPalSdk(a,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypal",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsWalletService.getPayPalSdkOrThrow(),o={createOrder:()=>this.bigCommercePaymentsWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>Ft(this,[e,i],void 0,function*({orderID:e},i){const r=yield i.order.get(),o=this.bigCommercePaymentsWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsWalletService.addBillingAddress(n,o),yield this.bigCommercePaymentsWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments",e)})},a=Object.assign({fundingSource:r.FUNDING.PAYPAL,style:this.bigCommercePaymentsWalletService.getValidButtonStyle(i)},o),s=r.Buttons(a);s.isEligible()?s.render(`#${e}`):this.bigCommercePaymentsWalletService.removeElement(e)}}const Nt=g(e=>new Dt(new zt(e,Bt(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypal"}]);var Ut=function(e,t,n,i){return new(n||(n=Promise))(function(r,o){function a(e){try{d(i.next(e))}catch(e){o(e)}}function s(e){try{d(i.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,s)}d((i=i.apply(e,t||[])).next())})};class xt{constructor(e){this.bigCommercePaymentsPayLaterWalletService=e}initialize(e){return Ut(this,void 0,void 0,function*(){var t,n;const{bigcommerce_paymentspaypalcredit:i,containerId:r,methodId:o}=e;if(!o)throw new W('Unable to initialize payment because "options.methodId" argument is not provided.');if(!r)throw new W('Unable to initialize payment because "options.containerId" argument is not provided.');if(!i)throw new W('Unable to initialize payment because "options.bigcommerce_paymentspaypalcredit" argument is not provided.');let a;try{a=JSON.parse(atob(i.initializationData))}catch(e){throw new W("Failed to parse payment method 'initializationData'.")}const s=null===(n=null===(t=a.initializationData)||void 0===t?void 0:t.paymentButtonStyles)||void 0===n?void 0:n.cartButtonStyles;yield this.bigCommercePaymentsPayLaterWalletService.loadPayPalSdk(a,i.currency.code,!1),this.renderButton(r,"bigcommerce_payments.paypalcredit",i.cartId,s)})}deinitialize(){return Promise.resolve()}renderButton(e,t,n,i){const r=this.bigCommercePaymentsPayLaterWalletService.getPayPalSdkOrThrow(),o=[r.FUNDING.PAYLATER,r.FUNDING.CREDIT],a={createOrder:()=>this.bigCommercePaymentsPayLaterWalletService.createPaymentOrderIntent(t,n),onApprove:(e,i)=>Ut(this,[e,i],void 0,function*({orderID:e},i){const r=yield i.order.get(),o=this.bigCommercePaymentsPayLaterWalletService.mapOrderDetailsToBillingAddress(r);yield this.bigCommercePaymentsPayLaterWalletService.addBillingAddress(n,o),yield this.bigCommercePaymentsPayLaterWalletService.proxyTokenizationPayment(n,t,"bigcommerce_payments_paylater",e)})};let s=!1;o.forEach(t=>{if(!s){const n=Object.assign({fundingSource:t,style:this.bigCommercePaymentsPayLaterWalletService.getValidButtonStyle(i)},a),o=r.Buttons(n);o.isEligible()&&(o.render(`#${e}`),s=!0)}}),s||this.bigCommercePaymentsPayLaterWalletService.removeElement(e)}}const jt=g(e=>new xt(new zt(e,Bt(),"BigcommercePaymentWalletIntentData")),[{id:"bigcommerce_paymentspaypalcredit"}]);export{We as createBigCommercePaymentsAlternativeMethodsPaymentStrategy,ct as createBigCommercePaymentsButtonStrategy,xe as createBigCommercePaymentsCreditCardsPaymentStrategy,Qe as createBigCommercePaymentsCustomerStrategy,tt as createBigCommercePaymentsFastlaneCustomerStrategy,be as createBigCommercePaymentsFastlanePaymentStrategy,Ve as createBigCommercePaymentsInvoicesPaymentStrategy,ht as createBigCommercePaymentsPayLaterButtonStrategy,rt as createBigCommercePaymentsPayLaterCustomerStrategy,Ie as createBigCommercePaymentsPayLaterPaymentStrategy,jt as createBigCommercePaymentsPayLaterWalletStrategy,X as createBigCommercePaymentsPaymentStrategy,Ae as createBigCommercePaymentsRatePayPayPaymentStrategy,Ke as createBigCommercePaymentsRedirectAlternativeMethodsPaymentStrategy,gt as createBigCommercePaymentsVenmoButtonStrategy,st as createBigCommercePaymentsVenmoCustomerStrategy,qe as createBigCommercePaymentsVenmoPaymentStrategy,Nt as createBigCommercePaymentsWalletStrategy};
|
|
2
2
|
//# sourceMappingURL=bigcommerce-payments.js.map
|