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