@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{createFormPoster as e}from"@bigcommerce/form-poster";import{createRequestSender as t}from"@bigcommerce/request-sender";import{getScriptLoader as n,getStylesheetLoader as i}from"@bigcommerce/script-loader";import{find as o,includes as a,isArray as r,isObject as s,round as c,some as d}from"lodash";class l extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}class u extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var h;class y{constructor(e,t,n=window){this._scriptLoader=e,this._stylesheetLoader=t,this._window=n}load(e){var t,n,i,o,a,r;return i=this,o=void 0,r=function*(){if(yield Promise.all([this._stylesheetLoader.loadStylesheet(`https://checkoutshopper-${null!==(t=e.environment)&&void 0!==t?t:""}.adyen.com/checkoutshopper/sdk/3.10.1/adyen.css`,{prepend:!1,attributes:{integrity:"sha384-8ofgICZZ/k5cC5N7xegqFZOA73H9RQ7H13439JfAZW8Gj3qjuKL2isaTD3GMIhDE",crossorigin:"anonymous"}}),this._scriptLoader.loadScript(`https://checkoutshopper-${null!==(n=e.environment)&&void 0!==n?n:""}.adyen.com/checkoutshopper/sdk/3.10.1/adyen.js`,{async:!0,attributes:{integrity:"sha384-wG2z9zSQo61EIvyXmiFCo+zB3y0ZB4hsrXVcANmpP8HLthjoQJQPBh7tZKJSV8jA",crossorigin:"anonymous"}})]),!this._window.AdyenCheckout)throw new u;return new this._window.AdyenCheckout(e)},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var i;t.done?e(t.value):(i=t.value,i instanceof a?i:new a(function(e){e(i)})).then(n,s)}c((r=r.apply(i,o||[])).next())})}}function g(e,t){return Object.assign(e,{resolveIds:t})}function p(e){return"object"==typeof e&&null!==e&&"errors"in e&&Array.isArray(e.errors)&&"code"in e.errors[0]&&"string"==typeof e.errors[0].code&&"provider_data"in e&&"object"==typeof e.provider_data}!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"}(h||(h={}));class m extends l{constructor(e){super(function(e){switch(e){case h.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case h.MissingCart:return"Unable to proceed because cart data is unavailable.";case h.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case h.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case h.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case h.MissingCheckoutConfig:case h.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case h.MissingOrder:return"Unable to proceed because order data is unavailable.";case h.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case h.MissingPayment:return"Unable to proceed because payment data is unavailable.";case h.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case h.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case h.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"}}function f(){const{navigator:e}=window;let t;return t=e.language?e.language:e.userLanguage,{color_depth:window.screen.colorDepth||24,java_enabled:"function"==typeof e.javaEnabled&&e.javaEnabled(),language:t,screen_height:window.screen.height,screen_width:window.screen.width,time_zone_offset:(new Date).getTimezoneOffset().toString()}}const w=e=>"object"==typeof e&&null!==e&&"body"in e;class P extends l{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}var v;!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"}(v||(v={}));class _ extends l{constructor(e){super(function(e){switch(e){case v.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case v.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case v.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case v.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 C extends l{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}function b(e,t,n){if("function"!=typeof n.value)return n;let i=n.value;return{get(){const e=i.bind(this);return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e},set(e){i=e}}}class S{constructor(e){if(!e)throw new Error("Currency settings missing");const{decimalPlaces:t,symbolLocation:n,symbol:i,thousandsSeparator:o,decimalSeparator:a}=e;if("string"!=typeof n||"string"!=typeof i||"string"!=typeof o||"string"!=typeof a||"string"!=typeof t)throw new C("Invalid currency settings provided");this._decimalPlaces=parseInt(t,10),this._symbolLocation=n,this._symbol=i,this._thousandsSeparator=o,this._decimalSeparator=a}format(e){if("number"!=typeof e)throw new C("Invalid amount provided");const t=this._formatNumber(e),n=this._formatCurrency(t);return e<0?`-${n}`:n}_formatNumber(e){const t=Math.abs(e),[n,i=""]=this._toFixed(t,this._decimalPlaces).split("."),o=n.replace(/\B(?=(\d{3})+(?!\d))/g,this._thousandsSeparator);return this._decimalPlaces<1?o:[o,i].join(this._decimalSeparator)}_formatCurrency(e){return"left"===this._symbolLocation.toLowerCase()?`${this._symbol}${e}`:`${e}${this._symbol}`}_toFixed(e,t){return(+`${Math.round(+`${e}e${t}`)}e${-t}`).toFixed(t)}}let I=class{constructor(e){this._storeConfig=e,this._customerFormatter=new S(this._storeConfig.shopperCurrency),this._storeFormatter=new S(this._storeConfig.currency)}toCustomerCurrency(e){const t=this._storeConfig.shopperCurrency.exchangeRate;return this._customerFormatter.format(e*t)}toStoreCurrency(e){return this._storeFormatter.format(e)}};I=function(e,t,n,i){var o,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(r=(a<3?o(r):a>3?o(t,n,r):o(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([function(e,t,n){return t&&n?b(0,t,n):function(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(n=>{const i=Object.getOwnPropertyDescriptor(e.prototype,n);i&&"constructor"!==n&&Object.defineProperty(t.prototype,n,b(e.prototype,n,i))}),t}(e)}],I);const O=I;function k(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}function A(e,t,n=!0){var i;return null!==(i=e[t])&&void 0!==i?i:n}var T,M,E,D,N,R,z,G,x;function B(e){return e in R}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(T||(T={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(M||(M={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(E||(E={})),function(e){e.pill="pill",e.rect="rect"}(D||(D={})),function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(N||(N={})),function(e){e.AMEX="AMEX",e.DISCOVER="DISCOVER",e.INTERAC="INTERAC",e.JCB="JCB",e.MC="MASTERCARD",e.VISA="VISA"}(R||(R={})),function(e){e.OFFER="OFFER",e.PAYMENT_AUTHORIZATION="PAYMENT_AUTHORIZATION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.SHIPPING_OPTION="SHIPPING_OPTION"}(z||(z={})),function(e){e.OFFER_INVALID="OFFER_INVALID",e.PAYMENT_DATA_INVALID="PAYMENT_DATA_INVALID",e.SHIPPING_ADDRESS_INVALID="SHIPPING_ADDRESS_INVALID",e.SHIPPING_ADDRESS_UNSERVICEABLE="SHIPPING_ADDRESS_UNSERVICEABLE",e.SHIPPING_OPTION_INVALID="SHIPPING_OPTION_INVALID",e.OTHER_ERROR="OTHER_ERROR"}(G||(G={})),function(e){e.INITIALIZE="INITIALIZE",e.SHIPPING_OPTION="SHIPPING_OPTION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.OFFER="OFFER"}(x||(x={}));var L=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class j{constructor(e,t){this._gatewayIdentifier=e,this._paymentIntegrationService=t,this._isBuyNowFlow=!1,this._shouldRequestShipping=!0}mapToShippingAddressRequestBody({shippingAddress:e}){if(!e)return;const{company:t="",phone:n=""}=this._paymentIntegrationService.getState().getShippingAddress()||{};return this._mapToAddressRequestBody(e,t,n)}mapToBillingAddressRequestBody(e){const{billingAddress:t}=e.paymentMethodData.info;if(!t)return;const{company:n="",phone:i="",email:o,customFields:a=[]}=this._paymentIntegrationService.getState().getBillingAddress()||{};return Object.assign(Object.assign({},this._mapToAddressRequestBody(t,n,i,a)),{email:o||e.email})}mapToExternalCheckoutData(e){var t;const{paymentMethodData:{tokenizationData:{token:n},info:{cardNetwork:i,cardDetails:o}}}=e;if(!n)throw new m(h.MissingPaymentToken);return Promise.resolve(Object.assign({nonce:n,card_information:{type:i,number:o}},this._isBuyNowFlow&&{cart_id:null===(t=this._paymentIntegrationService.getState().getCart())||void 0===t?void 0:t.id}))}getRequiredData(){var e;return L(this,void 0,void 0,function*(){const t={emailRequired:!0};if(!this._isShippingAddressRequired())return t;const n=yield this._paymentIntegrationService.loadShippingCountries(),i=null===(e=n.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code);return Object.assign(Object.assign({},t),{shippingAddressRequired:!0,shippingAddressParameters:Object.assign({phoneNumberRequired:!0},i&&{allowedCountryCodes:i}),shippingOptionRequired:!0})})}getCallbackIntents(){return this._isShippingAddressRequired()?[z.OFFER,z.SHIPPING_ADDRESS,z.SHIPPING_OPTION]:[z.OFFER]}getCallbackTriggers(){return{availableTriggers:[x.INITIALIZE,x.SHIPPING_ADDRESS,x.SHIPPING_OPTION,x.OFFER],initializationTrigger:[x.INITIALIZE],addressChangeTriggers:[x.INITIALIZE,x.SHIPPING_ADDRESS],shippingOptionsChangeTriggers:[x.SHIPPING_OPTION],offerChangeTriggers:[x.OFFER]}}getNonce(e){var t;const n=null===(t=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.nonce;if(!n)throw new m(h.MissingPaymentToken);return Promise.resolve(n)}extraPaymentData(){return Promise.resolve(void 0)}getMerchantInfo(){const{googleMerchantName:e,googleMerchantId:t,platformToken:n}=this.getGooglePayInitializationData();return{merchantName:e,merchantId:t,authJwt:n}}getTransactionInfo(){let e;if(this._isBuyNowFlow)e=this._getCurrencyCodeOrThrow();else{const{getCartOrThrow:t}=this._paymentIntegrationService.getState();e=t().currency.code}const t=this.getGooglePayInitializationData().storeCountry;return Object.assign(Object.assign({},t&&{countryCode:t}),{currencyCode:e,totalPriceStatus:N.ESTIMATED,totalPrice:"0"})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData().gatewayMerchantId;if(!e)throw new C("Unable to proceed, gatewayMerchantId is missing.");return{gateway:this._gatewayIdentifier,gatewayMerchantId:e}}getCardParameters(){return{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:this.getPaymentMethod().supportedCards.filter(B).map(e=>R[e]),billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}initialize(e,t,n){return this._getPaymentMethodFn=e,this._isBuyNowFlow=Boolean(t),this._currencyCode=n,this._isBuyNowFlow&&this._getCurrencyCodeOrThrow(),Promise.resolve()}handleShippingAddressChange(e){var t,n,i,o;return L(this,void 0,void 0,function*(){e&&(e.name=e.name||"",e.address1=e.address1||"");const a=this.mapToShippingAddressRequestBody({shippingAddress:e});a&&(yield this._paymentIntegrationService.updateShippingAddress(a));const r=this._paymentIntegrationService.getState(),s=r.getConsignments();if(!(null==s?void 0:s[0]))return;const c=s[0],d=r.getStoreConfigOrThrow();this._currencyService||(this._currencyService=new O(d));const l=(c.availableShippingOptions||[]).map(this._getGooglePayShippingOption.bind(this)),u=null===(t=c.availableShippingOptions)||void 0===t?void 0:t.find(e=>e.isRecommended);if(l.length){const e=(null===(n=c.selectedShippingOption)||void 0===n?void 0:n.id)||(null==u?void 0:u.id)||(null===(i=l[0])||void 0===i?void 0:i.id);return!(null===(o=c.selectedShippingOption)||void 0===o?void 0:o.id)&&l[0]&&(yield this.handleShippingOptionChange((null==u?void 0:u.id)||l[0].id)),{defaultSelectedOptionId:e,shippingOptions:l}}})}handleShippingOptionChange(e){return L(this,void 0,void 0,function*(){if("shipping_option_unselected"!==e)return this._paymentIntegrationService.selectShippingOption(e)})}getTotalPrice(){const{getCheckoutOrThrow:e,getCartOrThrow:t}=this._paymentIntegrationService.getState(),{decimalPlaces:n}=t().currency;return c(e().outstandingBalance,n).toFixed(n)}handleCoupons(e){return L(this,void 0,void 0,function*(){const{redemptionCodes:t=[]}=e,{offers:n}=this.getAppliedCoupons();let i;return yield t.reduce((e,t)=>L(this,void 0,void 0,function*(){if(yield e,n.some(({redemptionCode:e})=>e===t))return;const o=yield this.applyCoupon(t);o&&(i=o)}),Promise.resolve()),yield n.reduce((e,n)=>L(this,void 0,void 0,function*(){yield e,t.includes(n.redemptionCode)||(yield this._paymentIntegrationService.removeCoupon(n.redemptionCode))}),Promise.resolve()),{newOfferInfo:this.getAppliedCoupons(),error:i}})}getAppliedCoupons(){const e=this._paymentIntegrationService.getState(),{coupons:t}=e.getCheckout()||{};return{offers:(t||[]).map(e=>{const{displayName:t,code:n}=e;return{redemptionCode:n,description:t}})}}applyCoupon(e){return L(this,void 0,void 0,function*(){let t;try{yield this._paymentIntegrationService.applyCoupon(e)}catch(e){return e instanceof Error&&(t={reason:G.OFFER_INVALID,message:e.message,intent:x.OFFER}),t}})}setShouldRequestShipping(e){this._shouldRequestShipping=e}getGooglePayInitializationData(){return k(this.getPaymentMethod().initializationData,()=>new C("Missing initialization data."))}getPaymentMethod(){return k(this._getPaymentMethodFn,()=>new _(v.PaymentNotInitialized))()}getGatewayIdentifier(){return this._gatewayIdentifier}setGatewayIdentifier(e){this._gatewayIdentifier=e||this.getGatewayIdentifier()}_isShippingAddressRequired(){const{getCartOrThrow:e,getStoreConfigOrThrow:t,getShippingAddress:n}=this._paymentIntegrationService.getState(),i=t();let o;return o=A(i.checkoutSettings.features,"PI-4290.google_pay_require_shipping_address")?this._shouldRequestShipping:void 0===n(),o&&(a=e(),r=i,!!a&&(!!a.lineItems.physicalItems.some(e=>e.isShippingRequired)||!(!r||!a.lineItems.customItems)&&a.lineItems.customItems.length>0));var a,r}_mapToAddressRequestBody(e,t,n,i){const{name:o,address1:a,address2:r,address3:s,locality:c,administrativeArea:d,countryCode:l,postalCode:u,phoneNumber:h}=e,[y,g]=this._getFirstAndLastName(o);return{firstName:y,lastName:g,company:t,address1:a,address2:`${r} ${s}`.trim(),city:c||d,stateOrProvince:d,stateOrProvinceCode:d,countryCode:l,postalCode:u,phone:h||n,customFields:i||[]}}_getFirstAndLastName(e){const t=e.split(" ");return 1===t.length?[e,""]:[t.slice(0,-1).join(" "),t[t.length-1]]}_getCurrencyCodeOrThrow(){return k(this._currencyCode,()=>new C('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}_getGooglePayShippingOption({id:e,cost:t,description:n,additionalDescription:i}){var o;const a=null===(o=this._currencyService)||void 0===o?void 0:o.toCustomerCurrency(t);return this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-3540.googlepay_new_shipping_options_description"]?{id:e,label:`${a||t} ${n}`,description:i}:{id:e,label:n,description:a||t}}}var F=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class U extends j{constructor(e,t){super("adyen",e),this._scriptLoader=t,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return F(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);const o=i.getPaymentMethod.call(this),a=this._service.getState().getStoreConfig();if(!a)throw new m(h.MissingCheckoutConfig);return this._adyenClient=yield this._scriptLoader.load({environment:o.config.testMode?"test":"live",locale:a.storeProfile.storeLanguage}),Promise.resolve()})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});return F(this,void 0,void 0,function*(){const n=yield t.getNonce.call(this,e),i=t.getPaymentMethod.call(this);return JSON.stringify({type:i.method,googlePayToken:n,browser_info:f()})})}processAdditionalAction(e){return F(this,void 0,void 0,function*(){if(!w(e)||!p(e.body))throw e;const t=yield this._handleAction(e.body.provider_data);try{return yield this._service.submitPayment(t)}catch(e){return this.processAdditionalAction(e)}})}_handleAction(e){return new Promise((t,n)=>{const i=JSON.parse(e.action);this._getAdyenClient().createFromAction(i,{onAdditionalDetails:e=>{const n={methodId:i.paymentMethodType,paymentData:{nonce:JSON.stringify(e.data)}};t(n)},size:"05",onError:e=>n(e)}).mount("body"),n(new P)})}_getAdyenClient(){if(!this._adyenClient)throw new _(v.PaymentNotInitialized);return this._adyenClient}}const V={"X-Checkout-SDK-Version":"1.857.0"};class q extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method has thrown an unexpected error."),this.name="PaymentMethodFailedError",this.type="payment_method_client_invalid"}}var H=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class W{constructor(e,t,n,i){this._scriptLoader=e,this._gateway=t,this._requestSender=n,this._formPoster=i,this._baseRequest={apiVersion:2,apiVersionMinor:0}}initialize(e,t,n,i){return H(this,void 0,void 0,function*(){this._paymentsClient=yield this._scriptLoader.getGooglePaymentsClient(e().config.testMode,t),yield this._gateway.initialize(e,n,i),this._buildButtonPayloads()})}initializeWidget(){return H(this,void 0,void 0,function*(){yield this._buildWidgetPayloads(),yield this._determineReadinessToPay(),this._prefetchGooglePaymentData()})}getNonce(e){return this._gateway.getNonce(e)}extraPaymentData(){return H(this,void 0,void 0,function*(){return this._gateway.extraPaymentData()})}addPaymentButton(e,t){const n=document.querySelector(`#${e}`);if(!n)return;const i=this._getPaymentsClient().createButton(Object.assign(Object.assign({},t),{allowedPaymentMethods:[this._getBaseCardPaymentMethod()]}));return n.appendChild(i)}showPaymentSheet(){return H(this,void 0,void 0,function*(){const e=this._getPaymentDataRequest();return this._getPaymentsClient().loadPaymentData(e)})}setExternalCheckoutXhr(e,t){return H(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t)})}setExternalCheckoutForm(e,t,n){return H(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t,!0,n)})}mapToBillingAddressRequestBody(e){return this._gateway.mapToBillingAddressRequestBody(e)}mapToShippingAddressRequestBody(e){return this._gateway.mapToShippingAddressRequestBody(e)}processAdditionalAction(e,t){return"processAdditionalAction"in this._gateway?this._gateway.processAdditionalAction(e,t):Promise.reject(e)}signOut(e){return H(this,void 0,void 0,function*(){yield this._requestSender.get(`/remote-checkout/${e}/signout`)})}getCallbackTriggers(){return this._gateway.getCallbackTriggers()}setShouldRequestShipping(e){return this._gateway.setShouldRequestShipping(e)}handleShippingAddressChange(e){return H(this,void 0,void 0,function*(){return this._gateway.handleShippingAddressChange(e)})}handleShippingOptionChange(e){return H(this,void 0,void 0,function*(){yield this._gateway.handleShippingOptionChange(e)})}handleCoupons(e){return H(this,void 0,void 0,function*(){return this._gateway.handleCoupons(e)})}getTotalPrice(){return this._gateway.getTotalPrice()}_setExternalCheckout(e,t,n=!1,i){return H(this,void 0,void 0,function*(){const o="/checkout.php",a=Object.assign({action:"set_external_checkout",provider:e},yield this._gateway.mapToExternalCheckoutData(t));if(n)return new Promise(e=>{this._formPoster.postForm(i?`${i}/checkout`:o,Object.assign(Object.assign({},a),{card_information:JSON.stringify(a.card_information)}),e)});yield this._requestSender.post(o,{headers:Object.assign({Accept:"text/html","Content-Type":"application/x-www-form-urlencoded"},V),body:a})})}_prefetchGooglePaymentData(){const e=this._getPaymentDataRequest();e.transactionInfo=this._gateway.getTransactionInfo(),this._getPaymentsClient().prefetchPaymentData(e)}_determineReadinessToPay(){return H(this,void 0,void 0,function*(){try{const{result:e}=yield this._getPaymentsClient().isReadyToPay(this._getIsReadyToPayRequest());if(!1===e)throw new q("Google Pay is not supported by the current device and browser, please try another payment method.")}catch(e){if(e instanceof q)throw e;throw new q}})}_buildButtonPayloads(){this._baseCardPaymentMethod={type:"CARD",parameters:this._gateway.getCardParameters()}}_buildWidgetPayloads(){return H(this,void 0,void 0,function*(){const e=this._getBaseCardPaymentMethod();this._cardPaymentMethod=Object.assign(Object.assign({},e),{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:yield this._gateway.getPaymentGatewayParameters()}}),this._paymentDataRequest=Object.assign(Object.assign(Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[this._cardPaymentMethod],transactionInfo:this._gateway.getTransactionInfo(),merchantInfo:this._gateway.getMerchantInfo()}),yield this._gateway.getRequiredData()),{callbackIntents:this._gateway.getCallbackIntents(),offerInfo:this._gateway.getAppliedCoupons()}),this._isReadyToPayRequest=Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[e]})})}_getBaseCardPaymentMethod(){return this._getOrThrow(this._baseCardPaymentMethod)}_getPaymentDataRequest(){return this._getOrThrow(this._paymentDataRequest)}_getIsReadyToPayRequest(){return this._getOrThrow(this._isReadyToPayRequest)}_getPaymentsClient(){return this._getOrThrow(this._paymentsClient)}_getOrThrow(e){return k(e,()=>new _(v.PaymentNotInitialized))}}class Y extends C{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 J extends l{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}const K={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Z={position:"fixed","background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},X="embedded-checkout-loading-indicator-rotation";class Q{constructor(e){this.styles=Object.assign(Object.assign({},K),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=`${X} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(n=>{e.style.setProperty(n,t[n])})}defineAnimation(){var e;if(document.getElementById(X))return;const t=document.createElement("style");t.id=X,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${X} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}function $(e){return"object"==typeof e&&null!==e&&"statusCode"in e}var ee;function te(e){return Object.values(ee).includes(e)}!function(e){e.ADYEN_V2="googlepayadyenv2",e.ADYEN_V3="googlepayadyenv3",e.AUTHORIZE_NET="googlepayauthorizenet",e.BNZ="googlepaybnz",e.BRAINTREE="googlepaybraintree",e.PAYPAL_COMMERCE="googlepaypaypalcommerce",e.BIGCOMMERCE_PAYMENTS="googlepay_bigcommerce_payments",e.CHECKOUT_COM="googlepaycheckoutcom",e.CYBERSOURCE_V2="googlepaycybersourcev2",e.ORBITAL="googlepayorbital",e.STRIPE="googlepaystripe",e.STRIPE_UPE="googlepaystripeupe",e.STRIPE_OCS="googlepaystripeocs",e.WORLDPAY_ACCESS="googlepayworldpayaccess",e.TD_ONLINE_MART="googlepaytdonlinemart"}(ee||(ee={}));var ne=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ie{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t,this._isDeinitializationBlocked=!1,this._loadingIndicator=new Q({containerStyles:Z})}initialize(e){var t;return ne(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId)||!te(e.methodId))throw new C('Unable to proceed because "methodId" is not a valid key.');this._methodId=e.methodId;const n=e[this._getMethodId()];if(!(null==n?void 0:n.walletButton))throw new C("Unable to proceed without valid options.");const{walletButton:i,loadingContainerId:o}=n,a=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}return n}(n,["walletButton","loadingContainerId"]);this._loadingIndicatorContainer=o,yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodId());const r=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(this._getMethodId());yield this._googlePayPaymentProcessor.initialize(()=>r,this._getGooglePayClientOptions(null===(t=r.initializationData)||void 0===t?void 0:t.storeCountry)),this._addPaymentButton(i,a)})}execute({payment:e}){return ne(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId))throw new Y(["payment"]);yield this._paymentIntegrationService.submitOrder();const t=yield this._googlePayPaymentProcessor.getNonce(e.methodId),n=yield this._googlePayPaymentProcessor.extraPaymentData();try{yield this._paymentIntegrationService.submitPayment(Object.assign(Object.assign({},e),{paymentData:Object.assign({nonce:t},n)}))}catch(t){yield this._googlePayPaymentProcessor.processAdditionalAction(t,e.methodId)}})}finalize(){return Promise.reject(new J)}deinitialize(){var e;return this._isDeinitializationBlocked||(this._clickListener&&(null===(e=this._paymentButton)||void 0===e||e.removeEventListener("click",this._clickListener)),this._paymentButton=void 0,this._clickListener=void 0,this._methodId=void 0),Promise.resolve()}_addPaymentButton(e,t){if(this._paymentButton)return;const n=document.getElementById(e);if(!n)throw new C("Unable to proceed without a walletButton.");this._paymentButton=n,this._clickListener=this._handleClick(t),this._paymentButton.addEventListener("click",this._clickListener)}_handleClick({onPaymentSelect:e,onError:t}){return n=>ne(this,void 0,void 0,function*(){n.preventDefault();try{this._googlePayPaymentProcessor.setShouldRequestShipping(!1),yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(e){let n=e;if(this._toggleLoadingIndicator(!1),$(e)){if("CANCELED"===e.statusCode)throw new P;n=new q(JSON.stringify(e))}throw null==t||t(new q("An error occurred while requesting your Google Pay payment details.")),n}finally{this._toggleBlockDeinitialization(!1)}null==e||e()})}_interactWithPaymentSheet(){return ne(this,void 0,void 0,function*(){const e=yield this._googlePayPaymentProcessor.showPaymentSheet();this._toggleBlockDeinitialization(!0),this._toggleLoadingIndicator(!0);const t=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(e);t&&(yield this._paymentIntegrationService.updateBillingAddress(t)),yield this._googlePayPaymentProcessor.setExternalCheckoutXhr(this._getMethodId(),e),yield this._paymentIntegrationService.loadCheckout(),yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodId()),this._toggleLoadingIndicator(!1),this._toggleBlockDeinitialization(!1)})}_getMethodId(){return k(this._methodId,()=>new _(v.PaymentNotInitialized))}_getIsSignedInOrThrow(){return ne(this,void 0,void 0,function*(){try{return!!(yield this._googlePayPaymentProcessor.getNonce(this._getMethodId()))}catch(e){if(e instanceof m&&e.subtype===h.MissingPaymentToken)return!1;throw e}})}_handleOfferTrigger(e){return ne(this,void 0,void 0,function*(){let t=!1,n="Sign in to Google Pay first to apply or remove promo codes.";try{t=yield this._getIsSignedInOrThrow()}catch(e){e instanceof m&&(n=e.message)}if(t){const{newOfferInfo:t,error:n}=yield this._googlePayPaymentProcessor.handleCoupons(e);return{newOfferInfo:t,error:n}}return{error:{reason:G.OFFER_INVALID,message:n,intent:x.OFFER}}})}_getGooglePayClientOptions(e){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:t,offerData:n})=>ne(this,void 0,void 0,function*(){if(t!==x.INITIALIZE&&t!==x.OFFER)return;const{offerChangeTriggers:i}=this._googlePayPaymentProcessor.getCallbackTriggers(),{newOfferInfo:o,error:a}=i.includes(t)?yield this._handleOfferTrigger(n):{},r=a;yield this._paymentIntegrationService.loadCheckout();const{getCheckoutOrThrow:s,getCartOrThrow:d}=this._paymentIntegrationService.getState(),{code:l,decimalPlaces:u}=d().currency,h=c(s().outstandingBalance,u).toFixed(u);return Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},e&&{countryCode:e}),{currencyCode:l,totalPriceStatus:N.FINAL,totalPrice:h})},o&&{newOfferInfo:o}),r&&{error:r})})}}}_toggleBlockDeinitialization(e){this._isDeinitializationBlocked=e}_toggleLoadingIndicator(e){e&&this._loadingIndicatorContainer?this._loadingIndicator.show(this._loadingIndicatorContainer):this._loadingIndicator.hide()}}class oe{constructor(e){this._scriptLoader=e,this._window=window}getGooglePaymentsClient(e=!1,t){return n=this,i=void 0,a=function*(){if(yield this._scriptLoader.loadScript("https://pay.google.com/gp/p/js/pay.js"),!this._window.google)throw new u;return void 0===this._paymentsClient&&(this._paymentsClient=new this._window.google.payments.api.PaymentsClient(Object.assign({environment:e?"TEST":"PRODUCTION"},null!=t?t:{}))),this._paymentsClient},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}function ae(){return new oe(n())}const re=g(o=>new ie(o,new W(ae(),new U(o,new y(n(),i())),t(),e())),[{id:"googlepayadyenv2"}]);class se{constructor(e,t,n=window){this._scriptLoader=e,this._stylesheetLoader=t,this._window=n}load(e){var t,n,i,o,a,r;return i=this,o=void 0,r=function*(){if(yield Promise.all([this._stylesheetLoader.loadStylesheet(`https://checkoutshopper-${null!==(t=e.environment)&&void 0!==t?t:""}.adyen.com/checkoutshopper/sdk/5.71.1/adyen.css`,{prepend:!1,attributes:{integrity:"sha384-5MvB4RnzvviA3VBT4KYABZ4HXNZG5LRqREEgd41xt/pf/QvKmsj2O9GuNuywRXx9",crossorigin:"anonymous"}}),this._scriptLoader.loadScript(`https://checkoutshopper-${null!==(n=e.environment)&&void 0!==n?n:""}.adyen.com/checkoutshopper/sdk/5.71.1/adyen.js`,{async:!0,attributes:{integrity:"sha384-yvY2yFNR4WqIjPqP9MzjI+gJimmaJnAvj4rLHKvgJbgFD5fMuf8zIJrFJOW8Lhhf",crossorigin:"anonymous"}})]),!this._window.AdyenCheckout)throw new u;return yield this._window.AdyenCheckout(e)},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var i;t.done?e(t.value):(i=t.value,i instanceof a?i:new a(function(e){e(i)})).then(n,s)}c((r=r.apply(i,o||[])).next())})}}var ce=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class de extends j{constructor(e,t){super("adyen",e),this._scriptLoader=t,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return ce(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);const o=i.getPaymentMethod.call(this),a=this._service.getState().getStoreConfig();if(!a)throw new m(h.MissingCheckoutConfig);return this._adyenClient=yield this._scriptLoader.load({environment:o.config.testMode?"test":"live",locale:a.storeProfile.storeLanguage}),Promise.resolve()})}processAdditionalAction(e){return ce(this,void 0,void 0,function*(){if(!w(e)||!p(e.body))throw e;const t=yield this._handleAction(e.body.provider_data);try{return yield this._service.submitPayment(t)}catch(e){return this.processAdditionalAction(e)}})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});return ce(this,void 0,void 0,function*(){const n=yield t.getNonce.call(this,e),i=t.getPaymentMethod.call(this);return JSON.stringify({type:i.method,googlePayToken:n,browser_info:f()})})}_handleAction(e){return new Promise((t,n)=>{const i=JSON.parse(e.action);this._getAdyenClient().createFromAction(i,{onAdditionalDetails:e=>{const n={methodId:i.paymentMethodType,paymentData:{nonce:JSON.stringify(e.data)}};t(n)},size:"05",onError:e=>n(e)}).mount("body"),n(new P)})}_getAdyenClient(){if(!this._adyenClient)throw new _(v.PaymentNotInitialized);return this._adyenClient}}const le=g(o=>new ie(o,new W(ae(),new de(o,new se(n(),i())),t(),e())),[{id:"googlepayadyenv3"}]);class ue extends j{constructor(e){super("authorizenet",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return function(e){if(!function(e){return"paymentGatewayId"in e}(e))throw new m(h.MissingPaymentMethod)}(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.paymentGatewayId}}}const he=g(n=>new ie(n,new W(ae(),new ue(n),t(),e())),[{id:"googlepayauthorizenet"}]);var ye;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(ye||(ye={}));const ge=ye;function pe(e){if(!function(e){return"checkoutcomkey"in e}(e))throw new m(h.MissingPaymentMethod)}var me=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class fe extends j{constructor(e,t){super("checkoutltd",e),this._requestSender=t}processAdditionalAction(e){return new Promise((t,n)=>{if(w(e)&&function(e){var t;if("object"!=typeof e||null===e)return!1;const n=e;return"string"==typeof(null===(t=n.three_ds_result)||void 0===t?void 0:t.acs_url)&&"string"==typeof n.three_ds_result.code}(e.body)&&"three_d_secure_required"===e.body.three_ds_result.code)return window.location.assign(e.body.three_ds_result.acs_url);n(e)})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return me(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new C("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"protocolVersion"in e&&"signature"in e&&"signedMessage"in e}(e))throw new m(h.MissingPaymentToken)}(i),n.nonce=yield this._tokenize(i),n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return pe(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.checkoutcomkey}}_tokenize(e){return me(this,void 0,void 0,function*(){const t=this.getPaymentMethod().config.testMode?"https://api.sandbox.checkout.com/tokens":"https://api.checkout.com/tokens",n=this.getGooglePayInitializationData();pe(n);const{body:i}=yield this._requestSender.post(t,{credentials:!1,body:{type:"googlepay",token_data:e},headers:{Authorization:n.checkoutcomkey,"Content-Type":ge.Json,"X-XSRF-TOKEN":null}});return i.token})}}const we=g(n=>{const i=t();return new ie(n,new W(ae(),new fe(n,i),i,e()))},[{id:"googlepaycheckoutcom"}]);class Pe extends j{constructor(e){super("cybersource",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}const ve=g(n=>new ie(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]);class _e extends j{constructor(e){super("chase",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}const Ce=g(n=>new ie(n,new W(ae(),new _e(n),t(),e())),[{id:"googlepayorbital"}]);var be,Se,Ie,Oe,ke,Ae,Te,Me,Ee;!function(e){e.SHIPPING="shipping",e.BILLING="billing"}(be||(be={})),function(e){e.SPLIT="split",e.FULL="full",e.ORGANIZATION="organization"}(Se||(Se={})),function(e){e.CreditCard="card",e.Link="link",e.EPS="eps",e.GRABPAY="grabpay",e.BANCONTACT="bancontact",e.IDEAL="ideal",e.ALIPAY="alipay",e.KLARNA="klarna",e.OCS="optimized_checkout"}(Ie||(Ie={})),function(e){e.NEVER="never",e.AUTO="auto",e.ALWAYS="always",e.PAYMENT="payment",e.IF_REQUIRED="if_required"}(Oe||(Oe={})),function(e){e.V3="v3",e.ACACIA="acacia",e.BASIL="basil",e.CLOVER="clover"}(ke||(ke={})),function(e){e.PAYMENT="payment",e.AUTHENTICATION="linkAuthentication",e.SHIPPING="address",e.EXPRESS_CHECKOUT="expressCheckout"}(Ae||(Ae={})),function(e){e.REQUIRES_PAYMENT_METHOD="requires_payment_method",e.REQUIRES_CONFIRMATION="requires_confirmation",e.REQUIRES_ACTION="requires_action",e.PROCESSING="processing",e.SUCCEEDED="succeeded",e.CANCELED="canceled"}(Te||(Te={})),function(e){e.CLICK="click",e.CHANGE="change",e.READY="ready",e.SHIPPING_ADDRESS_CHANGE="shippingaddresschange",e.SHIPPING_RATE_CHANGE="shippingratechange",e.CONFIRM="confirm",e.CANCEL="cancel",e.LOADER_START="loaderstart"}(Me||(Me={})),function(e){e.ON_SESSION="on_session",e.OFF_SESSION="off_session"}(Ee||(Ee={}));var De=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Ne{constructor(e,t=window){this.scriptLoader=e,this.stripeWindow=t}getStripeClient(e,t,n,i,o){return De(this,void 0,void 0,function*(){if(this.stripeWindow.bcStripeClient)return this.stripeWindow.bcStripeClient;const a=yield this.load(n),{stripePublishableKey:r,stripeConnectedAccount:s}=e,c=a(r,Object.assign(Object.assign(Object.assign(Object.assign({},s?{stripeAccount:s}:{}),t?{locale:t}:{}),i?{betas:i}:{}),o?{apiVersion:o}:{}));return Object.assign(this.stripeWindow,{bcStripeClient:c}),c})}getElements(e,t){return De(this,void 0,void 0,function*(){let n=this.stripeWindow.bcStripeElements;return n?yield this.updateStripeElements(t):(n=e.elements(t),Object.assign(this.stripeWindow,{bcStripeElements:n})),n})}updateStripeElements(e){return De(this,void 0,void 0,function*(){const t=this.stripeWindow.bcStripeElements;t&&(t.update(e),yield t.fetchUpdates())})}load(e){return De(this,void 0,void 0,function*(){if(!this.stripeWindow.Stripe&&(yield this.scriptLoader.loadScript(this.getScriptUrl(e)),!this.stripeWindow.Stripe))throw new u;return this.stripeWindow.Stripe})}getScriptUrl(e){return e&&e!==ke.V3?`https://js.stripe.com/${e}/stripe.js`:"https://js.stripe.com/v3/"}}const Re={body:{},headers:{},status:0};class ze extends l{constructor(e,{message:t,errors:n}={}){const{body:i,headers:o,status:a}=e||Re;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=o,this.status=a,this.errors=n||[]}}const Ge=["payment_element_beta_2","alipay_pm_beta_1","link_default_integration_beta_1","shipping_address_element_beta_1","address_element_beta_1"];function xe(e){if(!function(e){return"stripeConnectedAccount"in e&&"stripePublishableKey"in e&&"stripeVersion"in e}(e))throw new m(h.MissingPaymentMethod)}var Be=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Le extends j{constructor(e,t){super("stripe",e),this.paymentIntegrationService=e,this.scriptLoader=t}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Be(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new C("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"id"in e}(e))throw new m(h.MissingPaymentToken)}(i),n.nonce=i.id,n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();xe(e);const{stripeVersion:t,stripePublishableKey:n,stripeConnectedAccount:i}=e;return{gateway:this.getGatewayIdentifier(),"stripe:version":t,"stripe:publishableKey":`${n}/${i}`}}processAdditionalAction(e,t){var n;return Be(this,void 0,void 0,function*(){if(!t)throw new Y(["payment"]);if(!w(e)||("object"!=typeof(i=e.body)||null===i||!("three_ds_result"in i)||!("errors"in i)))throw e;var i;if(d(e.body.errors,{code:"three_d_secure_required"})){const i=this.getGooglePayInitializationData();xe(i),this.stripeUPEClient=yield this.loadStripeJs(i,t);const o=e.body.three_ds_result.token;let a,r=!1;try{a=yield this.stripeUPEClient.confirmCardPayment(o)}catch(e){try{a=yield this.stripeUPEClient.retrievePaymentIntent(o)}catch(e){r=!0}}if(null==a?void 0:a.error){if(this._throwDisplayableStripeError(a.error),this._isCancellationError(a.error))throw new P;throw new q}if(!(null==a?void 0:a.paymentIntent)&&!r)throw new ze;return this.paymentIntegrationService.submitPayment({methodId:t,paymentData:{nonce:(null===(n=null==a?void 0:a.paymentIntent)||void 0===n?void 0:n.id)||o}})}throw e})}loadStripeJs(e,t){return Be(this,void 0,void 0,function*(){if(this.stripeUPEClient)return this.stripeUPEClient;const n=this.paymentIntegrationService.getState().getCartLocale();return"googlepaystripeocs"===t&&e.useNewStripeJsVersion?this.scriptLoader.getStripeClient(e,n,ke.CLOVER):this.scriptLoader.getStripeClient(e,n,ke.V3,Ge,"2020-03-02;alipay_beta=v1;link_beta=v1")})}_isCancellationError(e){var t,n;return e&&-1!==(null===(n=null===(t=e.payment_intent.last_payment_error)||void 0===t?void 0:t.message)||void 0===n?void 0:n.indexOf("canceled"))}_throwDisplayableStripeError(e){if(a(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}}const je=g(i=>new ie(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]);class Fe extends j{constructor(e){super("worldpay",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}const Ue=g(n=>new ie(n,new W(ae(),new Fe(n),t(),e())),[{id:"googlepayworldpayaccess"}]),Ve="3.128.0",qe="3.123.2",He="3.106.0";class We{constructor(e){this.paymentIntegrationService=e,this.braintreeWindow=window}getSDKVersion(){const e=this.paymentIntegrationService.getState().getStoreConfig(),t=(null==e?void 0:e.checkoutSettings.features)||{};return this.getPreloadedSDKVersion()||(A(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?Ve:A(t,"PAYPAL-5636.update_braintree_sdk_version")?qe:He)}getPreloadedSDKVersion(){const e=this.braintreeWindow.braintree;if(e){const t=o(Object.values(e),e=>!!e.VERSION);return null==t?void 0:t.VERSION}}}class Ye extends l{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var Je,Ke,Ze,Xe,Qe,$e,et;!function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(Je||(Je={})),function(e){e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED"}(Ke||(Ke={})),function(e){e.TRUSTLY="trustly"}(Ze||(Ze={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="cancelled",e.UNRECOGNIZED="unrecognized"}(Xe||(Xe={})),function(e){e.Customer="CUSTOMER",e.Merchant="MERCHANT",e.Network="NETWORK",e.Internal="INTERNAL",e.Unknown="UNKNOWN"}(Qe||(Qe={})),function(e){e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED"}($e||($e={})),function(e){e.Visa="visa",e.Mastercard="mastercard",e.AmericanExpress="american-express",e.DinersClub="diners-club",e.Discover="discover",e.Jcb="jcb",e.UnionPay="union-pay",e.Maestro="maestro",e.Elo="elo",e.Mir="mir",e.Hiper="hiper",e.Hipercard="hipercard"}(et||(et={}));var tt,nt,it,ot=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class at{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return ot(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return ot(this,void 0,void 0,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=yield t.create({authorization:e})}return this.client})}getDataCollectorOrThrow(e){return ot(this,void 0,void 0,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),i=Object.assign({client:t,kount:!0},e);this.dataCollector=yield n.create(i)}catch(e){if(function(e){return Boolean("object"==typeof e&&null!==e&&("type"in e||"message"in e||"code"in e))}(e)&&e.code===$e.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return ot(this,void 0,void 0,function*(){if(!this.googlePayment){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadGooglePayment()]);this.googlePayment=yield t.create({client:e})}return this.googlePayment})}getBraintreeThreeDS(){return ot(this,void 0,void 0,function*(){if(!this.threeDS){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]);this.threeDS=yield t.create({client:e,version:2})}return this.threeDS})}getBraintreeLocalPayment(e){return ot(this,void 0,void 0,function*(){if(!this.braintreeLocalPayment){const[t,n]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((i,o)=>{n.create({client:t,merchantAccountId:e},(e,t)=>{e&&o(e),i(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return ot(this,void 0,void 0,function*(){if(!this.usBankAccount){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadUsBankAccount();this.usBankAccount=yield t.create({client:e})}return this.usBankAccount})}getBraintreeVisaCheckout(){return this.visaCheckout||(this.visaCheckout=Promise.all([this.getClient(),this.braintreeScriptLoader.loadVisaCheckout()]).then(([e,t])=>t.create({client:e}))),this.visaCheckout}getVisaCheckoutSdk(e){return ot(this,void 0,void 0,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return ot(this,void 0,void 0,function*(){if(!this.braintreeVenmo){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadVenmoCheckout(),n={client:e,allowDesktop:!0,paymentMethodUsage:"multi_use"},i=yield t.create(n);if(!i.isBrowserSupported())throw new Ye;this.braintreeVenmo=i}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new _(v.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}!function(e){e.Sandbox="sandbox",e.Production="production"}(tt||(tt={})),function(e){e.Client="client",e.DataCollector="dataCollector",e.Fastlane="fastlane",e.GooglePayment="googlePayment",e.HostedFields="hostedFields",e.LocalPayment="localPayment",e.Paypal="paypal",e.PaypalCheckout="paypalCheckout",e.ThreeDSecure="threeDSecure",e.UsBankAccount="usBankAccount",e.Venmo="venmo",e.VisaCheckout="visaCheckout"}(nt||(nt={})),function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(it||(it={}));const rt={[He]:{[nt.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[nt.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[nt.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[nt.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[nt.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[nt.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[nt.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[nt.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[nt.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[nt.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[nt.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[nt.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[qe]:{[nt.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[nt.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[nt.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[nt.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[nt.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[nt.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[nt.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[nt.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[nt.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[nt.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[nt.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[nt.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[Ve]:{[nt.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[nt.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[nt.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[nt.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[nt.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[nt.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[nt.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[nt.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[nt.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[nt.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[nt.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[nt.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var st=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ct{constructor(e,t,n){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=n}loadClient(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.Client,"client.min.js")})}loadFastlane(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.Paypal,"paypal.min.js")})}loadLocalPayment(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.GooglePayment,"google-payment.min.js")})}load3DS(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(nt.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(nt.Venmo,"venmo.min.js")}loadHostedFields(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return st(this,void 0,void 0,function*(){if(this.braintreeHostWindow.V)return this.braintreeHostWindow.V;const t=e?"sha384-0eu1s1GtqzXlL9DtLgmwzC5WWlEH/ADRM0n38cVQkvtT+W/gey96rcb1LwuUOPDm":"sha384-1f1csvP3ZFxg4dILH1GaY4LHlZ0oX7Rk83rxmLlwbnIi4TM0NYzXoev1VoEiVDS6";return this.scriptLoader.loadScript(`//${e?"sandbox-":""}assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js`,{async:!0,attributes:{integrity:t,crossorigin:"anonymous"}}).then(()=>{if(!this.braintreeHostWindow.V)throw new u;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return st(this,void 0,void 0,function*(){let n=this.getBraintreeModule(e);if(n)return n;const i=this.braintreeSDKVersionManager.getSDKVersion(),o=`//js.braintreegateway.com/web/${i}/js/${t}`,a=i in rt?this.getIntegrityValuesByModuleName(e,i):void 0;if(yield this.scriptLoader.loadScript(o,a?{async:!0,attributes:{integrity:a,crossorigin:"anonymous"}}:void 0),n=this.getBraintreeModule(e),!n)throw new u;return n})}getBraintreeModule(e){var t;return null===(t=this.braintreeHostWindow.braintree)||void 0===t?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const n=rt[t][e];if(!n)throw new Error("Unexpected fileName value");return n}}class dt{constructor(e){const t=new Promise((e,t)=>{this.cancel=t});this.promise=Promise.race([e,t])}}var lt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ut extends j{constructor(e,t){super("braintree",e),this._braintreeSdk=t,this._methodId=ee.BRAINTREE,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return lt(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);let o=i.getPaymentMethod.call(this);if(o.clientToken||(o=(yield this._service.loadPaymentMethod(this._methodId)).getPaymentMethodOrThrow(this._methodId)),!o.clientToken||!o.initializationData)throw new m(h.MissingPaymentMethod);return this._braintreeSdk.initialize(o.clientToken),this._braintreeGooglePayment=yield this._braintreeSdk.getBraintreeGooglePayment(),Promise.resolve()})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});var n;return lt(this,void 0,void 0,function*(){const i=yield t.getNonce.call(this,e),{clientToken:o,initializationData:a}=t.getPaymentMethod.call(this);if(!o||!a||!(null===(n=a.card_information)||void 0===n?void 0:n.bin))throw new m(h.MissingPaymentMethod);const{isThreeDSecureEnabled:r,card_information:{bin:s,isNetworkTokenized:c}}=a;if(r&&!c){const e=yield this._braintreeSdk.getBraintreeThreeDS(),{orderAmount:t}=this._service.getState().getOrderOrThrow();return(yield this._braintreePresent3DSChallenge(e,t,i,s)).nonce}return i})}extraPaymentData(){return lt(this,void 0,void 0,function*(){return{deviceSessionId:yield this._getBraintreeDeviceData()}})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return lt(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new C("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"androidPayCards"in e}(e))throw new m(h.MissingPaymentToken)}(i),n.nonce=i.androidPayCards[0].nonce,n.card_information.bin=i.androidPayCards[0].details.bin,n.card_information.isNetworkTokenized=i.androidPayCards[0].details.isNetworkTokenized,n})}getCardParameters(){return super.getCardParameters()}getPaymentGatewayParameters(){const e=Object.create(null,{getMerchantInfo:{get:()=>super.getMerchantInfo},getTransactionInfo:{get:()=>super.getTransactionInfo},getRequiredData:{get:()=>super.getRequiredData}});return lt(this,void 0,void 0,function*(){return this.getBraintreeGooglePayment().createPaymentDataRequest(Object.assign({merchantInfo:e.getMerchantInfo.call(this),transactionInfo:e.getTransactionInfo.call(this),cardRequirements:{billingAddressRequired:!0,billingAddressFormat:"FULL"}},yield e.getRequiredData.call(this))).paymentMethodTokenizationParameters.parameters})}getBraintreeGooglePayment(){if(!this._braintreeGooglePayment)throw new m(h.MissingPaymentMethod);return this._braintreeGooglePayment}_getBraintreeDeviceData(){return lt(this,void 0,void 0,function*(){const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e})}_braintreePresent3DSChallenge(e,t,n,i){return new dt(e.verifyCard({amount:t,bin:i,nonce:n,onLookupComplete:(e,t)=>{t()}})).promise}}const ht=g(i=>{const o=t(),a=window,r=new We(i),s=new at(new ct(n(),a,r));return new ie(i,new W(ae(),new ut(i,s),o,e()))},[{id:"googlepaybraintree"}]);var yt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class gt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return yt(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new u}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return yt(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new u;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return yt(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new u}return this.window.paypalApms})}getPayPalMessages(e,t){return yt(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new u;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return yt(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,attributionId:c}=o;return{options:{"client-id":r,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:a},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":c,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,buyerCountry:c,attributionId:d,isHostedCheckoutEnabled:l,isDeveloperModeApplicable:u}=o,y=l||n;return{options:Object.assign({"client-id":r,"merchant-id":s,commit:y,components:["googlepay"],currency:t,intent:a},u&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":d,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{intent:i,clientId:o,merchantId:a,buyerCountry:r,attributionId:s,isDeveloperModeApplicable:c,availableAlternativePaymentMethods:d=[],enabledAlternativePaymentMethods:l=[]}=n,u=l,y=d.filter(e=>!l.includes(e));return{options:Object.assign({"client-id":o,"merchant-id":a,"enable-funding":u.length>0?u:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},c&&{"buyer-country":r}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{clientId:i,merchantId:o,attributionId:a,isDeveloperModeApplicable:r,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":o,components:["messages"],currency:t},r&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function pt(e){if(!function(e){return!!e.initializationData&&"attributionId"in e.initializationData&&"isVenmoEnabled"in e.initializationData&&"isGooglePayEnabled"in e.initializationData&&"isPayPalCreditAvailable"in e.initializationData}(e))throw new m(h.MissingPaymentMethod)}var mt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ft extends j{constructor(e,t){super("paypalsb",e),this.payPalCommerceSdk=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,a,r,s,c;return mt(this,void 0,void 0,function*(){const d=null!==(a=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==a?a:n;if(!d)throw new m(h.MissingPaymentMethod);yield i.initialize.call(this,e,t,d);const l=i.getPaymentMethod.call(this);if(!l.initializationData)throw new m(h.MissingPaymentMethod);pt(l);const u=yield this.payPalCommerceSdk.getPayPalGooglePaySdk(l,d);this.googlepayConfig=yield u.Googlepay().config();const{allowedPaymentMethods:y}=this.googlepayConfig;this.setGatewayIdentifier(null===(c=null===(s=null===(r=y[0])||void 0===r?void 0:r.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===c?void 0:c.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return mt(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}const wt="This API endpoint is for internal use only and may change in the future";var Pt,vt;!function(e){e.Approved="APPROVED",e.PayerActionRequired="PAYER_ACTION_REQUIRED"}(Pt||(Pt={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(vt||(vt={}));var _t=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Ct extends ie{constructor(e,t,n,i){super(e,t),this._payPalCommerceSdk=n,this._requestSender=i}execute({payment:e}){return _t(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId))throw new Y(["payment"]);const t=this._paymentIntegrationService.getState(),n=t.getCartOrThrow().id,{initializationData:i}=t.getPaymentMethodOrThrow(this._getMethodId()),{orderId:o}=yield this.getOrderId(n),{card_information:a}=i||{},r=yield this._googlePayPaymentProcessor.getNonce(e.methodId),s={tokenizationData:{type:"PAYMENT_GATEWAY",token:atob(r)},info:{cardNetwork:(null==a?void 0:a.type)||"",cardDetails:(null==a?void 0:a.number)||""},type:"CARD"};yield this.confirmOrder(o,s),yield this._paymentIntegrationService.submitOrder();try{const t={formattedPayload:{method_id:e.methodId,paypal_account:{order_id:o}}};yield this._paymentIntegrationService.submitPayment({methodId:e.methodId,paymentData:t})}catch(e){yield this._googlePayPaymentProcessor.processAdditionalAction(e)}})}confirmOrder(e,t){return _t(this,void 0,void 0,function*(){const n=this._paymentIntegrationService.getState(),i=n.getPaymentMethodOrThrow(this._getMethodId());if(!i.initializationData)throw new m(h.MissingPaymentMethod);const o=n.getCartOrThrow().currency.code,a=yield this._payPalCommerceSdk.getPayPalGooglePaySdk(i,o,!0),{status:r}=yield a.Googlepay().confirmOrder({orderId:e,paymentMethodData:t});if(r===Pt.PayerActionRequired)return yield a.Googlepay().initiatePayerAction({orderId:e}),Promise.resolve();if(r!==Pt.Approved)throw new C("Payment is not approved.");return Promise.resolve()})}getOrderId(e){return _t(this,void 0,void 0,function*(){const t={cartId:e,shouldSaveInstrument:!1},{body:n}=yield this._requestSender.post("/api/storefront/payments/googlepaypaypalcommercecheckout",{headers:Object.assign({"X-API-INTERNAL":wt,"Content-Type":ge.Json},V),body:t});return n})}}const bt=g(i=>{const o=new gt(n());return new Ct(i,new W(ae(),new ft(i,o),t(),e()),o,t())},[{id:"googlepaypaypalcommerce"}]);var St=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class It{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return St(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new u}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return St(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new u;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return St(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new u}return this.window.paypalApms})}getPayPalMessages(e,t){return St(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new u;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return St(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,attributionId:c}=o;return{options:{"client-id":r,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:a},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":c,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,buyerCountry:c,attributionId:d,isHostedCheckoutEnabled:l,isDeveloperModeApplicable:u}=o,y=l||n;return{options:Object.assign({"client-id":r,"merchant-id":s,commit:y,components:["googlepay"],currency:t,intent:a},u&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":d,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{intent:i,clientId:o,merchantId:a,buyerCountry:r,attributionId:s,isDeveloperModeApplicable:c,availableAlternativePaymentMethods:d=[],enabledAlternativePaymentMethods:l=[]}=n,u=this.filterFundingOptions(l),y=this.filterFundingOptions(d.filter(e=>!l.includes(e)));return{options:Object.assign({"client-id":o,"merchant-id":a,"enable-funding":u.length>0?u:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},c&&{"buyer-country":r}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{clientId:i,merchantId:o,attributionId:a,isDeveloperModeApplicable:r,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":o,components:["messages"],currency:t},r&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}var Ot,kt,At=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Tt extends j{constructor(e,t){super("googlepay_bigcommerce_payments",e),this.payPalSdkHelper=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,a,r,s,c;return At(this,void 0,void 0,function*(){const d=null!==(a=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==a?a:n;if(!d)throw new m(h.MissingPaymentMethod);yield i.initialize.call(this,e,t,d);const l=i.getPaymentMethod.call(this);if(!l.initializationData)throw new m(h.MissingPaymentMethod);pt(l);const u=yield this.payPalSdkHelper.getPayPalGooglePaySdk(l,d);this.googlepayConfig=yield u.Googlepay().config();const{allowedPaymentMethods:y}=this.googlepayConfig;this.setGatewayIdentifier(null===(c=null===(s=null===(r=y[0])||void 0===r?void 0:r.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===c?void 0:c.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return At(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}!function(e){e.Approved="APPROVED",e.PayerActionRequired="PAYER_ACTION_REQUIRED"}(Ot||(Ot={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(kt||(kt={}));var Mt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Et extends ie{constructor(e,t,n,i){super(e,t),this._payPalSdkHelper=n,this._requestSender=i}execute({payment:e}){return Mt(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId))throw new Y(["payment"]);const t=this._paymentIntegrationService.getState(),n=t.getCartOrThrow().id,{initializationData:i}=t.getPaymentMethodOrThrow(this._getMethodId()),{orderId:o}=yield this.getOrderId(n),{card_information:a}=i||{},r=yield this._googlePayPaymentProcessor.getNonce(e.methodId),s={tokenizationData:{type:"PAYMENT_GATEWAY",token:atob(r)},info:{cardNetwork:(null==a?void 0:a.type)||"",cardDetails:(null==a?void 0:a.number)||""},type:"CARD"};yield this.confirmOrder(o,s),yield this._paymentIntegrationService.submitOrder();try{const t={formattedPayload:{method_id:e.methodId,paypal_account:{order_id:o}}};yield this._paymentIntegrationService.submitPayment({methodId:e.methodId,paymentData:t})}catch(e){yield this._googlePayPaymentProcessor.processAdditionalAction(e)}})}confirmOrder(e,t){return Mt(this,void 0,void 0,function*(){const n=this._paymentIntegrationService.getState(),i=n.getPaymentMethodOrThrow(this._getMethodId());if(!i.initializationData)throw new m(h.MissingPaymentMethod);const o=n.getCartOrThrow().currency.code,a=yield this._payPalSdkHelper.getPayPalGooglePaySdk(i,o,!0),{status:r}=yield a.Googlepay().confirmOrder({orderId:e,paymentMethodData:t});if(r===Ot.PayerActionRequired)return yield a.Googlepay().initiatePayerAction({orderId:e}),Promise.resolve();if(r!==Ot.Approved)throw new C("Payment is not approved.");return Promise.resolve()})}getOrderId(e){return Mt(this,void 0,void 0,function*(){const t={cartId:e,shouldSaveInstrument:!1},{body:n}=yield this._requestSender.post("/api/storefront/payments/googlepay_bigcommerce_paymentscheckout",{headers:Object.assign({"X-API-INTERNAL":wt,"Content-Type":ge.Json},V),body:t});return n})}}const Dt=g(i=>{const o=new It(n());return new Et(i,new W(ae(),new Tt(i,o),t(),e()),o,t())},[{id:"googlepay_bigcommerce_payments"}]);var Nt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Rt extends j{constructor(e,t){super("worldlinena",e),this.formPoster=t}extraPaymentData(){return Nt(this,void 0,void 0,function*(){return Promise.resolve({browser_info:f()})})}processAdditionalAction(e){return Nt(this,void 0,void 0,function*(){if(!function(e){return w(e)&&(t=e.body,s(t)&&"object"==typeof t&&"errors"in t&&"three_ds_result"in t&&r(t.errors)&&d(t.errors,{code:"three_d_secure_required"}));var t}(e))throw e;const{three_ds_result:t}=e.body,{acs_url:n,payer_auth_request:i,merchant_data:o}=t||{};if(!n||!i||!o)throw new Y(["formUrl","threeDSSessionData","creq"]);return new Promise(e=>{this.formPoster.postForm(n,{threeDSSessionData:i,creq:o},e,"_top")})})}}const zt=g(n=>new ie(n,new W(ae(),new Rt(n,e()),t(),e())),[{id:"googlepaytdonlinemart"}]);class Gt extends l{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var xt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Bt{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t;return xt(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId)||!te(e.methodId))throw new C('Unable to proceed because "methodId" is not a valid key.');this._methodId=e.methodId;const n=e[this._getMethodId()];if(!n)throw new C("Unable to proceed without valid options.");let i,o=this._paymentIntegrationService.getState();try{i=o.getPaymentMethodOrThrow(this._getMethodId())}catch(e){o=yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodId()),i=o.getPaymentMethodOrThrow(this._getMethodId())}try{yield this._googlePayPaymentProcessor.initialize(()=>i,this._getGooglePayClientOptions(null===(t=i.initializationData)||void 0===t?void 0:t.storeCountry))}catch(e){return}this._addPaymentButton(n)})}signIn(){return Promise.reject(new Gt('In order to sign in via Google Pay, the shopper must click on "Google Pay" button.'))}signOut(){var e;return xt(this,void 0,void 0,function*(){const t=null===(e=this._paymentIntegrationService.getState().getPaymentId())||void 0===e?void 0:e.providerId;t&&(yield this._googlePayPaymentProcessor.signOut(t))})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}deinitialize(){var e;return null===(e=this._paymentButton)||void 0===e||e.remove(),this._paymentButton=void 0,this._methodId=void 0,Promise.resolve()}_getGooglePayClientOptions(e){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:t,shippingAddress:n,shippingOptionData:i,offerData:o})=>xt(this,void 0,void 0,function*(){const{availableTriggers:a,addressChangeTriggers:r,shippingOptionsChangeTriggers:s,offerChangeTriggers:c}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!a.includes(t))return;const d=r.includes(t)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(n):void 0;s.includes(t)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(i.id));const{newOfferInfo:l,error:u}=c.includes(t)?yield this._googlePayPaymentProcessor.handleCoupons(o):{},h=u;yield this._paymentIntegrationService.loadCheckout();const y=this._googlePayPaymentProcessor.getTotalPrice(),{code:g}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},e&&{countryCode:e}),{currencyCode:g,totalPriceStatus:N.FINAL,totalPrice:y})},d&&{newShippingOptionParameters:d}),l&&{newOfferInfo:l}),h&&{error:h})})}}}_addPaymentButton({container:e,buttonColor:t,buttonType:n,onClick:i,onError:o}){var a;this._paymentButton=null!==(a=this._paymentButton)&&void 0!==a?a:this._googlePayPaymentProcessor.addPaymentButton(e,{buttonColor:null!=t?t:"default",buttonType:null!=n?n:"plain",onClick:this._handleClick(o,i)})}_handleClick(e,t){return n=>xt(this,void 0,void 0,function*(){n.preventDefault(),t&&"function"==typeof t&&t();try{yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(t){let n=t;if($(t)){if("CANCELED"===t.statusCode)throw new P;n=new q(JSON.stringify(t))}throw null==e||e(new q("An error occurred while requesting your Google Pay payment details.")),n}})}_interactWithPaymentSheet(){return xt(this,void 0,void 0,function*(){const e=yield this._googlePayPaymentProcessor.showPaymentSheet(),t=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(e),n=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(e),i="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;t&&(yield this._paymentIntegrationService.updateBillingAddress(t)),n&&(yield this._paymentIntegrationService.updateShippingAddress(n)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodId(),e,i)})}_getMethodId(){return k(this._methodId,()=>new _(v.PaymentNotInitialized))}}const Lt=g(n=>{const i=t();return new Bt(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv2"}]),jt=g(n=>{const i=t();return new Bt(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv3"}]),Ft=g(n=>new Bt(n,new W(ae(),new ue(n),t(),e())),[{id:"googlepayauthorizenet"}]),Ut=g(n=>{const i=t();return new Bt(n,new W(ae(),new fe(n,i),i,e()))},[{id:"googlepaycheckoutcom"}]),Vt=g(n=>new Bt(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaycybersourcev2"}]),qt=g(n=>new Bt(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaybnz"}]),Ht=g(n=>new Bt(n,new W(ae(),new _e(n),t(),e())),[{id:"googlepayorbital"}]),Wt=g(i=>new Bt(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripe"},{id:"googlepaystripeocs"}]),Yt=g(i=>new Bt(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripeupe"}]),Jt=g(n=>new Bt(n,new W(ae(),new Fe(n),t(),e())),[{id:"googlepayworldpayaccess"}]),Kt=g(i=>{const o=t(),a=window,r=new We(i),s=new at(new ct(n(),a,r));return new Bt(i,new W(ae(),new ut(i,s),o,e()))},[{id:"googlepaybraintree"}]),Zt=g(i=>new Bt(i,new W(ae(),new ft(i,new gt(n())),t(),e())),[{id:"googlepaypaypalcommerce"}]),Xt=g(i=>new Bt(i,new W(ae(),new Tt(i,new It(n())),t(),e())),[{id:"googlepay_bigcommerce_payments"}]),Qt=g(n=>new Bt(n,new W(ae(),new Rt(n,e()),t(),e())),[{id:"googlepaytdonlinemart"}]);class $t extends l{constructor(e){super(e||"An unexpected error has occurred during buy now cart creation process. Please try again later."),this.name="BuyNowCartCreationError",this.type="buy_now_cart_creation_error"}}var en=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class tn{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t,n;return en(this,void 0,void 0,function*(){if(!e.methodId||!te(e.methodId))throw new C('Unable to proceed because "methodId" is not a valid key.');if(this._methodId=e.methodId,!e.containerId)throw new C('Unable to proceed because "containerId" is not a valid key.');const i=e[this._getMethodOrThrow()];if(!i)throw new C("Unable to proceed without valid options.");const{buyNowInitializeOptions:o,currencyCode:a,buttonColor:r,buttonType:s,onError:c}=i;let d,l=this._paymentIntegrationService.getState();try{d=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}catch(e){l=yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodOrThrow()),d=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}if(this._countryCode=null===(t=d.initializationData)||void 0===t?void 0:t.storeCountry,o){if(!a)throw new C('Unable to initialize payment because "options.currencyCode" argument is not provided.');this._currencyCode=a,this._buyNowInitializeOptions=o,yield this._googlePayPaymentProcessor.initialize(()=>d,this._getGooglePayClientOptions(),!!o,a)}else yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initialize(()=>d,this._getGooglePayClientOptions());this._paymentButton=null!==(n=this._paymentButton)&&void 0!==n?n:this._googlePayPaymentProcessor.addPaymentButton(e.containerId,{buttonColor:null!=r?r:"default",buttonType:null!=s?s:"plain",onClick:this._handleClick(c)})})}deinitialize(){var e;return null===(e=this._paymentButton)||void 0===e||e.remove(),this._paymentButton=void 0,this._methodId=void 0,Promise.resolve()}_handleClick(e){return t=>en(this,void 0,void 0,function*(){t.preventDefault();try{this._buyNowInitializeOptions?yield this._createBuyNowCartOrThrow(this._buyNowInitializeOptions):yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(t){let n=t;if($(t)){if("CANCELED"===t.statusCode)throw new P;n=new q(JSON.stringify(t))}throw null==e||e(new q("An error occurred while requesting your Google Pay payment details.")),n}})}_interactWithPaymentSheet(){var e;return en(this,void 0,void 0,function*(){const t=yield this._googlePayPaymentProcessor.showPaymentSheet(),n=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(t),i=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(t),o="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;n&&(yield this._paymentIntegrationService.updateBillingAddress(n)),i&&!(null===(e=this._buyNowCart)||void 0===e?void 0:e.lineItems.digitalItems.length)&&(yield this._paymentIntegrationService.updateShippingAddress(i)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodOrThrow(),t,o)})}_getGooglePayClientOptions(){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:e,shippingAddress:t,shippingOptionData:n,offerData:i})=>en(this,void 0,void 0,function*(){const{availableTriggers:o,addressChangeTriggers:a,shippingOptionsChangeTriggers:r,offerChangeTriggers:s}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!o.includes(e))return;const c=a.includes(e)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(t):void 0;r.includes(e)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(n.id));const{newOfferInfo:d,error:l}=s.includes(e)?yield this._googlePayPaymentProcessor.handleCoupons(i):{},u=l;return this._buyNowInitializeOptions?this._getBuyNowTransactionInfo(c,d,u):this._getTransactionInfo(c,d,u)})}}}_createBuyNowCartOrThrow(e){return en(this,void 0,void 0,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=e.getBuyNowCartRequestBody();try{this._buyNowCart=yield this._paymentIntegrationService.createBuyNowCart(t),yield this._paymentIntegrationService.loadCheckout(this._buyNowCart.id)}catch(e){if("string"==typeof e)throw new $t(e);throw e}}})}_getBuyNowTransactionInfo(e,t,n){if(!this._buyNowCart)return;const{cartAmount:i}=this._buyNowCart,o=this._googlePayPaymentProcessor.getTotalPrice();return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:this._getCurrencyCodeOrThrow(),totalPrice:o||String(i),totalPriceStatus:N.FINAL})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})}_getTransactionInfo(e,t,n){return en(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadCheckout();const i=this._googlePayPaymentProcessor.getTotalPrice(),{code:o}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:o,totalPriceStatus:N.FINAL,totalPrice:i})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})})}_getMethodOrThrow(){return k(this._methodId,()=>new _(v.PaymentNotInitialized))}_getCurrencyCodeOrThrow(){return k(this._currencyCode,()=>new C('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}}const nn=g(i=>{const o=t(),a=window,r=new We(i),s=new at(new ct(n(),a,r));return new tn(i,new W(ae(),new ut(i,s),o,e()))},[{id:"googlepaybraintree"}]),on=g(i=>new tn(i,new W(ae(),new ft(i,new gt(n())),t(),e())),[{id:"googlepaypaypalcommerce"}]),an=g(i=>new tn(i,new W(ae(),new Tt(i,new It(n())),t(),e())),[{id:"googlepay_bigcommerce_payments"}]),rn=g(n=>{const i=t();return new tn(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv2"}]),sn=g(n=>{const i=t();return new tn(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv3"}]),cn=g(n=>new tn(n,new W(ae(),new ue(n),t(),e())),[{id:"googlepayauthorizenet"}]),dn=g(n=>{const i=t();return new tn(n,new W(ae(),new fe(n,i),i,e()))},[{id:"googlepaycheckoutcom"}]),ln=g(n=>new tn(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]),un=g(n=>new tn(n,new W(ae(),new _e(n),t(),e())),[{id:"googlepayorbital"}]),hn=g(i=>new tn(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]),yn=g(n=>new tn(n,new W(ae(),new Fe(n),t(),e())),[{id:"googlepayworldpayaccess"}]),gn=g(n=>new tn(n,new W(ae(),new Rt(n,e()),t(),e())),[{id:"googlepaytdonlinemart"}]);export{rn as createGooglePayAdyenV2ButtonStrategy,Lt as createGooglePayAdyenV2CustomerStrategy,re as createGooglePayAdyenV2PaymentStrategy,sn as createGooglePayAdyenV3ButtonStrategy,jt as createGooglePayAdyenV3CustomerStrategy,le as createGooglePayAdyenV3PaymentStrategy,cn as createGooglePayAuthorizeDotNetButtonStrategy,Ft as createGooglePayAuthorizeDotNetCustomerStrategy,he as createGooglePayAuthorizeNetPaymentStrategy,an as createGooglePayBigCommercePaymentsButtonStrategy,Xt as createGooglePayBigCommercePaymentsCustomerStrategy,Dt as createGooglePayBigCommercePaymentsPaymentStrategy,qt as createGooglePayBnzCustomerStrategy,nn as createGooglePayBraintreeButtonStrategy,Kt as createGooglePayBraintreeCustomerStrategy,ht as createGooglePayBraintreePaymentStrategy,dn as createGooglePayCheckoutComButtonStrategy,Ut as createGooglePayCheckoutComCustomerStrategy,we as createGooglePayCheckoutComPaymentStrategy,ln as createGooglePayCybersourceButtonStrategy,Vt as createGooglePayCybersourceCustomerStrategy,ve as createGooglePayCybersourcePaymentStrategy,un as createGooglePayOrbitalButtonStrategy,Ht as createGooglePayOrbitalCustomerStrategy,Ce as createGooglePayOrbitalPaymentStrategy,bt as createGooglePayPPCPPaymentStrategy,on as createGooglePayPayPalCommerceButtonStrategy,Zt as createGooglePayPayPalCommerceCustomerStrategy,hn as createGooglePayStripeButtonStrategy,Wt as createGooglePayStripeCustomerStrategy,je as createGooglePayStripePaymentStrategy,Yt as createGooglePayStripeUpeCustomerStrategy,gn as createGooglePayTdOnlineMartButtonStrategy,Qt as createGooglePayTdOnlineMartCustomerStrategy,zt as createGooglePayTdOnlineMartPaymentStrategy,yn as createGooglePayWorldpayAccessButtonStrategy,Jt as createGooglePayWorldpayAccessCustomerStrategy,Ue as createGooglePayWorldpayAccessPaymentStrategy};
|
|
1
|
+
import{createFormPoster as e}from"@bigcommerce/form-poster";import{createRequestSender as t}from"@bigcommerce/request-sender";import{getScriptLoader as n,getStylesheetLoader as i}from"@bigcommerce/script-loader";import{find as o,includes as a,isArray as r,isObject as s,round as c,some as d}from"lodash";class l extends Error{constructor(e){var t;super(e||"An unexpected error has occurred."),this.name="StandardError",this.type="standard",t=new.target.prototype,Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(this,new.target):this.stack=new Error(this.message).stack}}class u extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method is not loaded or ready to be used."),this.name="PaymentMethodClientUnavailableError",this.type="payment_method_client_unavailable"}}var h;class y{constructor(e,t,n=window){this._scriptLoader=e,this._stylesheetLoader=t,this._window=n}load(e){var t,n,i,o,a,r;return i=this,o=void 0,r=function*(){if(yield Promise.all([this._stylesheetLoader.loadStylesheet(`https://checkoutshopper-${null!==(t=e.environment)&&void 0!==t?t:""}.adyen.com/checkoutshopper/sdk/3.10.1/adyen.css`,{prepend:!1,attributes:{integrity:"sha384-8ofgICZZ/k5cC5N7xegqFZOA73H9RQ7H13439JfAZW8Gj3qjuKL2isaTD3GMIhDE",crossorigin:"anonymous"}}),this._scriptLoader.loadScript(`https://checkoutshopper-${null!==(n=e.environment)&&void 0!==n?n:""}.adyen.com/checkoutshopper/sdk/3.10.1/adyen.js`,{async:!0,attributes:{integrity:"sha384-wG2z9zSQo61EIvyXmiFCo+zB3y0ZB4hsrXVcANmpP8HLthjoQJQPBh7tZKJSV8jA",crossorigin:"anonymous"}})]),!this._window.AdyenCheckout)throw new u;return new this._window.AdyenCheckout(e)},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var i;t.done?e(t.value):(i=t.value,i instanceof a?i:new a(function(e){e(i)})).then(n,s)}c((r=r.apply(i,o||[])).next())})}}function g(e,t){return Object.assign(e,{resolveIds:t})}function p(e){return"object"==typeof e&&null!==e&&"errors"in e&&Array.isArray(e.errors)&&"code"in e.errors[0]&&"string"==typeof e.errors[0].code&&"provider_data"in e&&"object"==typeof e.provider_data}!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"}(h||(h={}));class m extends l{constructor(e){super(function(e){switch(e){case h.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case h.MissingCart:return"Unable to proceed because cart data is unavailable.";case h.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case h.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case h.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case h.MissingCheckoutConfig:case h.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case h.MissingOrder:return"Unable to proceed because order data is unavailable.";case h.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case h.MissingPayment:return"Unable to proceed because payment data is unavailable.";case h.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case h.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case h.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"}}function f(){const{navigator:e}=window;let t;return t=e.language?e.language:e.userLanguage,{color_depth:window.screen.colorDepth||24,java_enabled:"function"==typeof e.javaEnabled&&e.javaEnabled(),language:t,screen_height:window.screen.height,screen_width:window.screen.width,time_zone_offset:(new Date).getTimezoneOffset().toString()}}const w=e=>"object"==typeof e&&null!==e&&"body"in e;class P extends l{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}var v;!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"}(v||(v={}));class _ extends l{constructor(e){super(function(e){switch(e){case v.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case v.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case v.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case v.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 C extends l{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}function b(e,t,n){if("function"!=typeof n.value)return n;let i=n.value;return{get(){const e=i.bind(this);return Object.defineProperty(this,t,Object.assign(Object.assign({},n),{value:e})),e},set(e){i=e}}}class S{constructor(e){if(!e)throw new Error("Currency settings missing");const{decimalPlaces:t,symbolLocation:n,symbol:i,thousandsSeparator:o,decimalSeparator:a}=e;if("string"!=typeof n||"string"!=typeof i||"string"!=typeof o||"string"!=typeof a||"string"!=typeof t)throw new C("Invalid currency settings provided");this._decimalPlaces=parseInt(t,10),this._symbolLocation=n,this._symbol=i,this._thousandsSeparator=o,this._decimalSeparator=a}format(e){if("number"!=typeof e)throw new C("Invalid amount provided");const t=this._formatNumber(e),n=this._formatCurrency(t);return e<0?`-${n}`:n}_formatNumber(e){const t=Math.abs(e),[n,i=""]=this._toFixed(t,this._decimalPlaces).split("."),o=n.replace(/\B(?=(\d{3})+(?!\d))/g,this._thousandsSeparator);return this._decimalPlaces<1?o:[o,i].join(this._decimalSeparator)}_formatCurrency(e){return"left"===this._symbolLocation.toLowerCase()?`${this._symbol}${e}`:`${e}${this._symbol}`}_toFixed(e,t){return(+`${Math.round(+`${e}e${t}`)}e${-t}`).toFixed(t)}}let I=class{constructor(e){this._storeConfig=e,this._customerFormatter=new S(this._storeConfig.shopperCurrency),this._storeFormatter=new S(this._storeConfig.currency)}toCustomerCurrency(e){const t=this._storeConfig.shopperCurrency.exchangeRate;return this._customerFormatter.format(e*t)}toStoreCurrency(e){return this._storeFormatter.format(e)}};I=function(e,t,n,i){var o,a=arguments.length,r=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(r=(a<3?o(r):a>3?o(t,n,r):o(t,n))||r);return a>3&&r&&Object.defineProperty(t,n,r),r}([function(e,t,n){return t&&n?b(0,t,n):function(e){const t=class extends e{};return Object.getOwnPropertyNames(e.prototype).forEach(n=>{const i=Object.getOwnPropertyDescriptor(e.prototype,n);i&&"constructor"!==n&&Object.defineProperty(t.prototype,n,b(e.prototype,n,i))}),t}(e)}],I);const O=I;function k(e,t){if(null==e)throw t?t():new Error("An unexpected error has occurred.");return e}function A(e,t,n=!0){var i;return null!==(i=e[t])&&void 0!==i?i:n}var T,M,E,D,N,R,z,G,x;function B(e){return e in R}!function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(T||(T={})),function(e){e.paypal="paypal",e.checkout="checkout",e.buynow="buynow",e.pay="pay",e.installment="installment"}(M||(M={})),function(e){e.gold="gold",e.blue="blue",e.silver="silver",e.black="black",e.white="white"}(E||(E={})),function(e){e.pill="pill",e.rect="rect"}(D||(D={})),function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(N||(N={})),function(e){e.AMEX="AMEX",e.DISCOVER="DISCOVER",e.INTERAC="INTERAC",e.JCB="JCB",e.MC="MASTERCARD",e.VISA="VISA"}(R||(R={})),function(e){e.OFFER="OFFER",e.PAYMENT_AUTHORIZATION="PAYMENT_AUTHORIZATION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.SHIPPING_OPTION="SHIPPING_OPTION"}(z||(z={})),function(e){e.OFFER_INVALID="OFFER_INVALID",e.PAYMENT_DATA_INVALID="PAYMENT_DATA_INVALID",e.SHIPPING_ADDRESS_INVALID="SHIPPING_ADDRESS_INVALID",e.SHIPPING_ADDRESS_UNSERVICEABLE="SHIPPING_ADDRESS_UNSERVICEABLE",e.SHIPPING_OPTION_INVALID="SHIPPING_OPTION_INVALID",e.OTHER_ERROR="OTHER_ERROR"}(G||(G={})),function(e){e.INITIALIZE="INITIALIZE",e.SHIPPING_OPTION="SHIPPING_OPTION",e.SHIPPING_ADDRESS="SHIPPING_ADDRESS",e.OFFER="OFFER"}(x||(x={}));var L=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class j{constructor(e,t){this._gatewayIdentifier=e,this._paymentIntegrationService=t,this._isBuyNowFlow=!1,this._shouldRequestShipping=!0}mapToShippingAddressRequestBody({shippingAddress:e}){if(!e)return;const{company:t="",phone:n=""}=this._paymentIntegrationService.getState().getShippingAddress()||{};return this._mapToAddressRequestBody(e,t,n)}mapToBillingAddressRequestBody(e){const{billingAddress:t}=e.paymentMethodData.info;if(!t)return;const{company:n="",phone:i="",email:o,customFields:a=[]}=this._paymentIntegrationService.getState().getBillingAddress()||{};return Object.assign(Object.assign({},this._mapToAddressRequestBody(t,n,i,a)),{email:o||e.email})}mapToExternalCheckoutData(e){var t;const{paymentMethodData:{tokenizationData:{token:n},info:{cardNetwork:i,cardDetails:o}}}=e;if(!n)throw new m(h.MissingPaymentToken);return Promise.resolve(Object.assign({nonce:n,card_information:{type:i,number:o}},this._isBuyNowFlow&&{cart_id:null===(t=this._paymentIntegrationService.getState().getCart())||void 0===t?void 0:t.id}))}getRequiredData(){var e;return L(this,void 0,void 0,function*(){const t={emailRequired:!0};if(!this._isShippingAddressRequired())return t;const n=yield this._paymentIntegrationService.loadShippingCountries(),i=null===(e=n.getShippingCountries())||void 0===e?void 0:e.map(e=>e.code);return Object.assign(Object.assign({},t),{shippingAddressRequired:!0,shippingAddressParameters:Object.assign({phoneNumberRequired:!0},i&&{allowedCountryCodes:i}),shippingOptionRequired:!0})})}getCallbackIntents(){return this._isShippingAddressRequired()?[z.OFFER,z.SHIPPING_ADDRESS,z.SHIPPING_OPTION]:[z.OFFER]}getCallbackTriggers(){return{availableTriggers:[x.INITIALIZE,x.SHIPPING_ADDRESS,x.SHIPPING_OPTION,x.OFFER],initializationTrigger:[x.INITIALIZE],addressChangeTriggers:[x.INITIALIZE,x.SHIPPING_ADDRESS],shippingOptionsChangeTriggers:[x.SHIPPING_OPTION],offerChangeTriggers:[x.OFFER]}}getNonce(e){var t;const n=null===(t=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(e).initializationData)||void 0===t?void 0:t.nonce;if(!n)throw new m(h.MissingPaymentToken);return Promise.resolve(n)}extraPaymentData(){return Promise.resolve(void 0)}getMerchantInfo(){const{googleMerchantName:e,googleMerchantId:t,platformToken:n}=this.getGooglePayInitializationData();return{merchantName:e,merchantId:t,authJwt:n}}getTransactionInfo(){let e;if(this._isBuyNowFlow)e=this._getCurrencyCodeOrThrow();else{const{getCartOrThrow:t}=this._paymentIntegrationService.getState();e=t().currency.code}const t=this.getGooglePayInitializationData().storeCountry;return Object.assign(Object.assign({},t&&{countryCode:t}),{currencyCode:e,totalPriceStatus:N.ESTIMATED,totalPrice:"0"})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData().gatewayMerchantId;if(!e)throw new C("Unable to proceed, gatewayMerchantId is missing.");return{gateway:this._gatewayIdentifier,gatewayMerchantId:e}}getCardParameters(){return{allowedAuthMethods:["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:this.getPaymentMethod().supportedCards.filter(B).map(e=>R[e]),billingAddressRequired:!0,billingAddressParameters:{format:"FULL",phoneNumberRequired:!0}}}initialize(e,t,n){return this._getPaymentMethodFn=e,this._isBuyNowFlow=Boolean(t),this._currencyCode=n,this._isBuyNowFlow&&this._getCurrencyCodeOrThrow(),Promise.resolve()}handleShippingAddressChange(e){var t,n,i,o;return L(this,void 0,void 0,function*(){e&&(e.name=e.name||"",e.address1=e.address1||"");const a=this.mapToShippingAddressRequestBody({shippingAddress:e});a&&(yield this._paymentIntegrationService.updateShippingAddress(a));const r=this._paymentIntegrationService.getState(),s=r.getConsignments();if(!(null==s?void 0:s[0]))return;const c=s[0],d=r.getStoreConfigOrThrow();this._currencyService||(this._currencyService=new O(d));const l=(c.availableShippingOptions||[]).map(this._getGooglePayShippingOption.bind(this)),u=null===(t=c.availableShippingOptions)||void 0===t?void 0:t.find(e=>e.isRecommended);if(l.length){const e=(null===(n=c.selectedShippingOption)||void 0===n?void 0:n.id)||(null==u?void 0:u.id)||(null===(i=l[0])||void 0===i?void 0:i.id);return!(null===(o=c.selectedShippingOption)||void 0===o?void 0:o.id)&&l[0]&&(yield this.handleShippingOptionChange((null==u?void 0:u.id)||l[0].id)),{defaultSelectedOptionId:e,shippingOptions:l}}})}handleShippingOptionChange(e){return L(this,void 0,void 0,function*(){if("shipping_option_unselected"!==e)return this._paymentIntegrationService.selectShippingOption(e)})}getTotalPrice(){const{getCheckoutOrThrow:e,getCartOrThrow:t}=this._paymentIntegrationService.getState(),{decimalPlaces:n}=t().currency;return c(e().outstandingBalance,n).toFixed(n)}handleCoupons(e){return L(this,void 0,void 0,function*(){const{redemptionCodes:t=[]}=e,{offers:n}=this.getAppliedCoupons();let i;return yield t.reduce((e,t)=>L(this,void 0,void 0,function*(){if(yield e,n.some(({redemptionCode:e})=>e===t))return;const o=yield this.applyCoupon(t);o&&(i=o)}),Promise.resolve()),yield n.reduce((e,n)=>L(this,void 0,void 0,function*(){yield e,t.includes(n.redemptionCode)||(yield this._paymentIntegrationService.removeCoupon(n.redemptionCode))}),Promise.resolve()),{newOfferInfo:this.getAppliedCoupons(),error:i}})}getAppliedCoupons(){const e=this._paymentIntegrationService.getState(),{coupons:t}=e.getCheckout()||{};return{offers:(t||[]).map(e=>{const{displayName:t,code:n}=e;return{redemptionCode:n,description:t}})}}applyCoupon(e){return L(this,void 0,void 0,function*(){let t;try{yield this._paymentIntegrationService.applyCoupon(e)}catch(e){return e instanceof Error&&(t={reason:G.OFFER_INVALID,message:e.message,intent:x.OFFER}),t}})}setShouldRequestShipping(e){this._shouldRequestShipping=e}getGooglePayInitializationData(){return k(this.getPaymentMethod().initializationData,()=>new C("Missing initialization data."))}getPaymentMethod(){return k(this._getPaymentMethodFn,()=>new _(v.PaymentNotInitialized))()}getGatewayIdentifier(){return this._gatewayIdentifier}setGatewayIdentifier(e){this._gatewayIdentifier=e||this.getGatewayIdentifier()}_isShippingAddressRequired(){const{getCartOrThrow:e,getStoreConfigOrThrow:t,getShippingAddress:n}=this._paymentIntegrationService.getState(),i=t();let o;return o=A(i.checkoutSettings.features,"PI-4290.google_pay_require_shipping_address")?this._shouldRequestShipping:void 0===n(),o&&(a=e(),r=i,!!a&&(!!a.lineItems.physicalItems.some(e=>e.isShippingRequired)||!(!r||!a.lineItems.customItems)&&a.lineItems.customItems.length>0));var a,r}_mapToAddressRequestBody(e,t,n,i){const{name:o,address1:a,address2:r,address3:s,locality:c,administrativeArea:d,countryCode:l,postalCode:u,phoneNumber:h}=e,[y,g]=this._getFirstAndLastName(o);return{firstName:y,lastName:g,company:t,address1:a,address2:`${r} ${s}`.trim(),city:c||d,stateOrProvince:d,stateOrProvinceCode:d,countryCode:l,postalCode:u,phone:h||n,customFields:i||[]}}_getFirstAndLastName(e){const t=e.split(" ");return 1===t.length?[e,""]:[t.slice(0,-1).join(" "),t[t.length-1]]}_getCurrencyCodeOrThrow(){return k(this._currencyCode,()=>new C('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}_getGooglePayShippingOption({id:e,cost:t,description:n,additionalDescription:i}){var o;const a=null===(o=this._currencyService)||void 0===o?void 0:o.toCustomerCurrency(t);return this._paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features["PI-3540.googlepay_new_shipping_options_description"]?{id:e,label:`${a||t} ${n}`,description:i}:{id:e,label:n,description:a||t}}}var F=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class U extends j{constructor(e,t){super("adyen",e),this._scriptLoader=t,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return F(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);const o=i.getPaymentMethod.call(this),a=this._service.getState().getStoreConfig();if(!a)throw new m(h.MissingCheckoutConfig);return this._adyenClient=yield this._scriptLoader.load({environment:o.config.testMode?"test":"live",locale:a.storeProfile.storeLanguage}),Promise.resolve()})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});return F(this,void 0,void 0,function*(){const n=yield t.getNonce.call(this,e),i=t.getPaymentMethod.call(this);return JSON.stringify({type:i.method,googlePayToken:n,browser_info:f()})})}processAdditionalAction(e){return F(this,void 0,void 0,function*(){if(!w(e)||!p(e.body))throw e;const t=yield this._handleAction(e.body.provider_data);try{return yield this._service.submitPayment(t)}catch(e){return this.processAdditionalAction(e)}})}_handleAction(e){return new Promise((t,n)=>{const i=JSON.parse(e.action);this._getAdyenClient().createFromAction(i,{onAdditionalDetails:e=>{const n={methodId:i.paymentMethodType,paymentData:{nonce:JSON.stringify(e.data)}};t(n)},size:"05",onError:e=>n(e)}).mount("body"),n(new P)})}_getAdyenClient(){if(!this._adyenClient)throw new _(v.PaymentNotInitialized);return this._adyenClient}}const V={"X-Checkout-SDK-Version":"1.858.0"};class q extends l{constructor(e){super(e||"Unable to proceed because the client library of a payment method has thrown an unexpected error."),this.name="PaymentMethodFailedError",this.type="payment_method_client_invalid"}}var H=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class W{constructor(e,t,n,i){this._scriptLoader=e,this._gateway=t,this._requestSender=n,this._formPoster=i,this._baseRequest={apiVersion:2,apiVersionMinor:0}}initialize(e,t,n,i){return H(this,void 0,void 0,function*(){this._paymentsClient=yield this._scriptLoader.getGooglePaymentsClient(e().config.testMode,t),yield this._gateway.initialize(e,n,i),this._buildButtonPayloads()})}initializeWidget(){return H(this,void 0,void 0,function*(){yield this._buildWidgetPayloads(),yield this._determineReadinessToPay(),this._prefetchGooglePaymentData()})}getNonce(e){return this._gateway.getNonce(e)}extraPaymentData(){return H(this,void 0,void 0,function*(){return this._gateway.extraPaymentData()})}addPaymentButton(e,t){const n=document.querySelector(`#${e}`);if(!n)return;const i=this._getPaymentsClient().createButton(Object.assign(Object.assign({},t),{allowedPaymentMethods:[this._getBaseCardPaymentMethod()]}));return n.appendChild(i)}showPaymentSheet(){return H(this,void 0,void 0,function*(){const e=this._getPaymentDataRequest();return this._getPaymentsClient().loadPaymentData(e)})}setExternalCheckoutXhr(e,t){return H(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t)})}setExternalCheckoutForm(e,t,n){return H(this,void 0,void 0,function*(){return this._setExternalCheckout(e,t,!0,n)})}mapToBillingAddressRequestBody(e){return this._gateway.mapToBillingAddressRequestBody(e)}mapToShippingAddressRequestBody(e){return this._gateway.mapToShippingAddressRequestBody(e)}processAdditionalAction(e,t){return"processAdditionalAction"in this._gateway?this._gateway.processAdditionalAction(e,t):Promise.reject(e)}signOut(e){return H(this,void 0,void 0,function*(){yield this._requestSender.get(`/remote-checkout/${e}/signout`)})}getCallbackTriggers(){return this._gateway.getCallbackTriggers()}setShouldRequestShipping(e){return this._gateway.setShouldRequestShipping(e)}handleShippingAddressChange(e){return H(this,void 0,void 0,function*(){return this._gateway.handleShippingAddressChange(e)})}handleShippingOptionChange(e){return H(this,void 0,void 0,function*(){yield this._gateway.handleShippingOptionChange(e)})}handleCoupons(e){return H(this,void 0,void 0,function*(){return this._gateway.handleCoupons(e)})}getTotalPrice(){return this._gateway.getTotalPrice()}_setExternalCheckout(e,t,n=!1,i){return H(this,void 0,void 0,function*(){const o="/checkout.php",a=Object.assign({action:"set_external_checkout",provider:e},yield this._gateway.mapToExternalCheckoutData(t));if(n)return new Promise(e=>{this._formPoster.postForm(i?`${i}/checkout`:o,Object.assign(Object.assign({},a),{card_information:JSON.stringify(a.card_information)}),e)});yield this._requestSender.post(o,{headers:Object.assign({Accept:"text/html","Content-Type":"application/x-www-form-urlencoded"},V),body:a})})}_prefetchGooglePaymentData(){const e=this._getPaymentDataRequest();e.transactionInfo=this._gateway.getTransactionInfo(),this._getPaymentsClient().prefetchPaymentData(e)}_determineReadinessToPay(){return H(this,void 0,void 0,function*(){try{const{result:e}=yield this._getPaymentsClient().isReadyToPay(this._getIsReadyToPayRequest());if(!1===e)throw new q("Google Pay is not supported by the current device and browser, please try another payment method.")}catch(e){if(e instanceof q)throw e;throw new q}})}_buildButtonPayloads(){this._baseCardPaymentMethod={type:"CARD",parameters:this._gateway.getCardParameters()}}_buildWidgetPayloads(){return H(this,void 0,void 0,function*(){const e=this._getBaseCardPaymentMethod();this._cardPaymentMethod=Object.assign(Object.assign({},e),{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:yield this._gateway.getPaymentGatewayParameters()}}),this._paymentDataRequest=Object.assign(Object.assign(Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[this._cardPaymentMethod],transactionInfo:this._gateway.getTransactionInfo(),merchantInfo:this._gateway.getMerchantInfo()}),yield this._gateway.getRequiredData()),{callbackIntents:this._gateway.getCallbackIntents(),offerInfo:this._gateway.getAppliedCoupons()}),this._isReadyToPayRequest=Object.assign(Object.assign({},this._baseRequest),{allowedPaymentMethods:[e]})})}_getBaseCardPaymentMethod(){return this._getOrThrow(this._baseCardPaymentMethod)}_getPaymentDataRequest(){return this._getOrThrow(this._paymentDataRequest)}_getIsReadyToPayRequest(){return this._getOrThrow(this._isReadyToPayRequest)}_getPaymentsClient(){return this._getOrThrow(this._paymentsClient)}_getOrThrow(e){return k(e,()=>new _(v.PaymentNotInitialized))}}class Y extends C{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 J extends l{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}const K={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Z={position:"fixed","background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"},X="embedded-checkout-loading-indicator-rotation";class Q{constructor(e){this.styles=Object.assign(Object.assign({},K),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=`${X} 500ms infinite cubic-bezier(0.69, 0.31, 0.56, 0.83)`,e}setStyleAttribute(e,t){Object.keys(t).forEach(n=>{e.style.setProperty(n,t[n])})}defineAnimation(){var e;if(document.getElementById(X))return;const t=document.createElement("style");t.id=X,null===(e=document.head)||void 0===e||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${X} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}function $(e){return"object"==typeof e&&null!==e&&"statusCode"in e}var ee;function te(e){return Object.values(ee).includes(e)}!function(e){e.ADYEN_V2="googlepayadyenv2",e.ADYEN_V3="googlepayadyenv3",e.AUTHORIZE_NET="googlepayauthorizenet",e.BNZ="googlepaybnz",e.BRAINTREE="googlepaybraintree",e.PAYPAL_COMMERCE="googlepaypaypalcommerce",e.BIGCOMMERCE_PAYMENTS="googlepay_bigcommerce_payments",e.CHECKOUT_COM="googlepaycheckoutcom",e.CYBERSOURCE_V2="googlepaycybersourcev2",e.ORBITAL="googlepayorbital",e.STRIPE="googlepaystripe",e.STRIPE_UPE="googlepaystripeupe",e.STRIPE_OCS="googlepaystripeocs",e.WORLDPAY_ACCESS="googlepayworldpayaccess",e.TD_ONLINE_MART="googlepaytdonlinemart"}(ee||(ee={}));var ne=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ie{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t,this._isDeinitializationBlocked=!1,this._loadingIndicator=new Q({containerStyles:Z})}initialize(e){var t;return ne(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId)||!te(e.methodId))throw new C('Unable to proceed because "methodId" is not a valid key.');this._methodId=e.methodId;const n=e[this._getMethodId()];if(!(null==n?void 0:n.walletButton))throw new C("Unable to proceed without valid options.");const{walletButton:i,loadingContainerId:o}=n,a=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}return n}(n,["walletButton","loadingContainerId"]);this._loadingIndicatorContainer=o,yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodId());const r=this._paymentIntegrationService.getState().getPaymentMethodOrThrow(this._getMethodId());yield this._googlePayPaymentProcessor.initialize(()=>r,this._getGooglePayClientOptions(null===(t=r.initializationData)||void 0===t?void 0:t.storeCountry)),this._addPaymentButton(i,a)})}execute({payment:e}){return ne(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId))throw new Y(["payment"]);yield this._paymentIntegrationService.submitOrder();const t=yield this._googlePayPaymentProcessor.getNonce(e.methodId),n=yield this._googlePayPaymentProcessor.extraPaymentData();try{yield this._paymentIntegrationService.submitPayment(Object.assign(Object.assign({},e),{paymentData:Object.assign({nonce:t},n)}))}catch(t){yield this._googlePayPaymentProcessor.processAdditionalAction(t,e.methodId)}})}finalize(){return Promise.reject(new J)}deinitialize(){var e;return this._isDeinitializationBlocked||(this._clickListener&&(null===(e=this._paymentButton)||void 0===e||e.removeEventListener("click",this._clickListener)),this._paymentButton=void 0,this._clickListener=void 0,this._methodId=void 0),Promise.resolve()}_addPaymentButton(e,t){if(this._paymentButton)return;const n=document.getElementById(e);if(!n)throw new C("Unable to proceed without a walletButton.");this._paymentButton=n,this._clickListener=this._handleClick(t),this._paymentButton.addEventListener("click",this._clickListener)}_handleClick({onPaymentSelect:e,onError:t}){return n=>ne(this,void 0,void 0,function*(){n.preventDefault();try{this._googlePayPaymentProcessor.setShouldRequestShipping(!1),yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(e){let n=e;if(this._toggleLoadingIndicator(!1),$(e)){if("CANCELED"===e.statusCode)throw new P;n=new q(JSON.stringify(e))}throw null==t||t(new q("An error occurred while requesting your Google Pay payment details.")),n}finally{this._toggleBlockDeinitialization(!1)}null==e||e()})}_interactWithPaymentSheet(){return ne(this,void 0,void 0,function*(){const e=yield this._googlePayPaymentProcessor.showPaymentSheet();this._toggleBlockDeinitialization(!0),this._toggleLoadingIndicator(!0);const t=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(e);t&&(yield this._paymentIntegrationService.updateBillingAddress(t)),yield this._googlePayPaymentProcessor.setExternalCheckoutXhr(this._getMethodId(),e),yield this._paymentIntegrationService.loadCheckout(),yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodId()),this._toggleLoadingIndicator(!1),this._toggleBlockDeinitialization(!1)})}_getMethodId(){return k(this._methodId,()=>new _(v.PaymentNotInitialized))}_getIsSignedInOrThrow(){return ne(this,void 0,void 0,function*(){try{return!!(yield this._googlePayPaymentProcessor.getNonce(this._getMethodId()))}catch(e){if(e instanceof m&&e.subtype===h.MissingPaymentToken)return!1;throw e}})}_handleOfferTrigger(e){return ne(this,void 0,void 0,function*(){let t=!1,n="Sign in to Google Pay first to apply or remove promo codes.";try{t=yield this._getIsSignedInOrThrow()}catch(e){e instanceof m&&(n=e.message)}if(t){const{newOfferInfo:t,error:n}=yield this._googlePayPaymentProcessor.handleCoupons(e);return{newOfferInfo:t,error:n}}return{error:{reason:G.OFFER_INVALID,message:n,intent:x.OFFER}}})}_getGooglePayClientOptions(e){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:t,offerData:n})=>ne(this,void 0,void 0,function*(){if(t!==x.INITIALIZE&&t!==x.OFFER)return;const{offerChangeTriggers:i}=this._googlePayPaymentProcessor.getCallbackTriggers(),{newOfferInfo:o,error:a}=i.includes(t)?yield this._handleOfferTrigger(n):{},r=a;yield this._paymentIntegrationService.loadCheckout();const{getCheckoutOrThrow:s,getCartOrThrow:d}=this._paymentIntegrationService.getState(),{code:l,decimalPlaces:u}=d().currency,h=c(s().outstandingBalance,u).toFixed(u);return Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},e&&{countryCode:e}),{currencyCode:l,totalPriceStatus:N.FINAL,totalPrice:h})},o&&{newOfferInfo:o}),r&&{error:r})})}}}_toggleBlockDeinitialization(e){this._isDeinitializationBlocked=e}_toggleLoadingIndicator(e){e&&this._loadingIndicatorContainer?this._loadingIndicator.show(this._loadingIndicatorContainer):this._loadingIndicator.hide()}}class oe{constructor(e){this._scriptLoader=e,this._window=window}getGooglePaymentsClient(e=!1,t){return n=this,i=void 0,a=function*(){if(yield this._scriptLoader.loadScript("https://pay.google.com/gp/p/js/pay.js"),!this._window.google)throw new u;return void 0===this._paymentsClient&&(this._paymentsClient=new this._window.google.payments.api.PaymentsClient(Object.assign({environment:e?"TEST":"PRODUCTION"},null!=t?t:{}))),this._paymentsClient},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}function ae(){return new oe(n())}const re=g(o=>new ie(o,new W(ae(),new U(o,new y(n(),i())),t(),e())),[{id:"googlepayadyenv2"}]);class se{constructor(e,t,n=window){this._scriptLoader=e,this._stylesheetLoader=t,this._window=n}load(e){var t,n,i,o,a,r;return i=this,o=void 0,r=function*(){if(yield Promise.all([this._stylesheetLoader.loadStylesheet(`https://checkoutshopper-${null!==(t=e.environment)&&void 0!==t?t:""}.adyen.com/checkoutshopper/sdk/5.71.1/adyen.css`,{prepend:!1,attributes:{integrity:"sha384-5MvB4RnzvviA3VBT4KYABZ4HXNZG5LRqREEgd41xt/pf/QvKmsj2O9GuNuywRXx9",crossorigin:"anonymous"}}),this._scriptLoader.loadScript(`https://checkoutshopper-${null!==(n=e.environment)&&void 0!==n?n:""}.adyen.com/checkoutshopper/sdk/5.71.1/adyen.js`,{async:!0,attributes:{integrity:"sha384-yvY2yFNR4WqIjPqP9MzjI+gJimmaJnAvj4rLHKvgJbgFD5fMuf8zIJrFJOW8Lhhf",crossorigin:"anonymous"}})]),!this._window.AdyenCheckout)throw new u;return yield this._window.AdyenCheckout(e)},new((a=void 0)||(a=Promise))(function(e,t){function n(e){try{c(r.next(e))}catch(e){t(e)}}function s(e){try{c(r.throw(e))}catch(e){t(e)}}function c(t){var i;t.done?e(t.value):(i=t.value,i instanceof a?i:new a(function(e){e(i)})).then(n,s)}c((r=r.apply(i,o||[])).next())})}}var ce=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class de extends j{constructor(e,t){super("adyen",e),this._scriptLoader=t,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return ce(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);const o=i.getPaymentMethod.call(this),a=this._service.getState().getStoreConfig();if(!a)throw new m(h.MissingCheckoutConfig);return this._adyenClient=yield this._scriptLoader.load({environment:o.config.testMode?"test":"live",locale:a.storeProfile.storeLanguage}),Promise.resolve()})}processAdditionalAction(e){return ce(this,void 0,void 0,function*(){if(!w(e)||!p(e.body))throw e;const t=yield this._handleAction(e.body.provider_data);try{return yield this._service.submitPayment(t)}catch(e){return this.processAdditionalAction(e)}})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});return ce(this,void 0,void 0,function*(){const n=yield t.getNonce.call(this,e),i=t.getPaymentMethod.call(this);return JSON.stringify({type:i.method,googlePayToken:n,browser_info:f()})})}_handleAction(e){return new Promise((t,n)=>{const i=JSON.parse(e.action);this._getAdyenClient().createFromAction(i,{onAdditionalDetails:e=>{const n={methodId:i.paymentMethodType,paymentData:{nonce:JSON.stringify(e.data)}};t(n)},size:"05",onError:e=>n(e)}).mount("body"),n(new P)})}_getAdyenClient(){if(!this._adyenClient)throw new _(v.PaymentNotInitialized);return this._adyenClient}}const le=g(o=>new ie(o,new W(ae(),new de(o,new se(n(),i())),t(),e())),[{id:"googlepayadyenv3"}]);class ue extends j{constructor(e){super("authorizenet",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return function(e){if(!function(e){return"paymentGatewayId"in e}(e))throw new m(h.MissingPaymentMethod)}(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.paymentGatewayId}}}const he=g(n=>new ie(n,new W(ae(),new ue(n),t(),e())),[{id:"googlepayauthorizenet"}]);var ye;!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(ye||(ye={}));const ge=ye;function pe(e){if(!function(e){return"checkoutcomkey"in e}(e))throw new m(h.MissingPaymentMethod)}var me=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class fe extends j{constructor(e,t){super("checkoutltd",e),this._requestSender=t}processAdditionalAction(e){return new Promise((t,n)=>{if(w(e)&&function(e){var t;if("object"!=typeof e||null===e)return!1;const n=e;return"string"==typeof(null===(t=n.three_ds_result)||void 0===t?void 0:t.acs_url)&&"string"==typeof n.three_ds_result.code}(e.body)&&"three_d_secure_required"===e.body.three_ds_result.code)return window.location.assign(e.body.three_ds_result.acs_url);n(e)})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return me(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new C("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"protocolVersion"in e&&"signature"in e&&"signedMessage"in e}(e))throw new m(h.MissingPaymentToken)}(i),n.nonce=yield this._tokenize(i),n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();return pe(e),{gateway:this.getGatewayIdentifier(),gatewayMerchantId:e.checkoutcomkey}}_tokenize(e){return me(this,void 0,void 0,function*(){const t=this.getPaymentMethod().config.testMode?"https://api.sandbox.checkout.com/tokens":"https://api.checkout.com/tokens",n=this.getGooglePayInitializationData();pe(n);const{body:i}=yield this._requestSender.post(t,{credentials:!1,body:{type:"googlepay",token_data:e},headers:{Authorization:n.checkoutcomkey,"Content-Type":ge.Json,"X-XSRF-TOKEN":null}});return i.token})}}const we=g(n=>{const i=t();return new ie(n,new W(ae(),new fe(n,i),i,e()))},[{id:"googlepaycheckoutcom"}]);class Pe extends j{constructor(e){super("cybersource",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}const ve=g(n=>new ie(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]);class _e extends j{constructor(e){super("chase",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}const Ce=g(n=>new ie(n,new W(ae(),new _e(n),t(),e())),[{id:"googlepayorbital"}]);var be,Se,Ie,Oe,ke,Ae,Te,Me,Ee;!function(e){e.SHIPPING="shipping",e.BILLING="billing"}(be||(be={})),function(e){e.SPLIT="split",e.FULL="full",e.ORGANIZATION="organization"}(Se||(Se={})),function(e){e.CreditCard="card",e.Link="link",e.EPS="eps",e.GRABPAY="grabpay",e.BANCONTACT="bancontact",e.IDEAL="ideal",e.ALIPAY="alipay",e.KLARNA="klarna",e.OCS="optimized_checkout"}(Ie||(Ie={})),function(e){e.NEVER="never",e.AUTO="auto",e.ALWAYS="always",e.PAYMENT="payment",e.IF_REQUIRED="if_required"}(Oe||(Oe={})),function(e){e.V3="v3",e.ACACIA="acacia",e.BASIL="basil",e.CLOVER="clover"}(ke||(ke={})),function(e){e.PAYMENT="payment",e.AUTHENTICATION="linkAuthentication",e.SHIPPING="address",e.EXPRESS_CHECKOUT="expressCheckout"}(Ae||(Ae={})),function(e){e.REQUIRES_PAYMENT_METHOD="requires_payment_method",e.REQUIRES_CONFIRMATION="requires_confirmation",e.REQUIRES_ACTION="requires_action",e.PROCESSING="processing",e.SUCCEEDED="succeeded",e.CANCELED="canceled"}(Te||(Te={})),function(e){e.CLICK="click",e.CHANGE="change",e.READY="ready",e.SHIPPING_ADDRESS_CHANGE="shippingaddresschange",e.SHIPPING_RATE_CHANGE="shippingratechange",e.CONFIRM="confirm",e.CANCEL="cancel",e.LOADER_START="loaderstart"}(Me||(Me={})),function(e){e.ON_SESSION="on_session",e.OFF_SESSION="off_session"}(Ee||(Ee={}));var De=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Ne{constructor(e,t=window){this.scriptLoader=e,this.stripeWindow=t}getStripeClient(e,t,n,i,o){return De(this,void 0,void 0,function*(){if(this.stripeWindow.bcStripeClient)return this.stripeWindow.bcStripeClient;const a=yield this.load(n),{stripePublishableKey:r,stripeConnectedAccount:s}=e,c=a(r,Object.assign(Object.assign(Object.assign(Object.assign({},s?{stripeAccount:s}:{}),t?{locale:t}:{}),i?{betas:i}:{}),o?{apiVersion:o}:{}));return Object.assign(this.stripeWindow,{bcStripeClient:c}),c})}getElements(e,t){return De(this,void 0,void 0,function*(){let n=this.stripeWindow.bcStripeElements;return n?yield this.updateStripeElements(t):(n=e.elements(t),Object.assign(this.stripeWindow,{bcStripeElements:n})),n})}updateStripeElements(e){return De(this,void 0,void 0,function*(){const t=this.stripeWindow.bcStripeElements;t&&(t.update(e),yield t.fetchUpdates())})}load(e){return De(this,void 0,void 0,function*(){if(!this.stripeWindow.Stripe&&(yield this.scriptLoader.loadScript(this.getScriptUrl(e)),!this.stripeWindow.Stripe))throw new u;return this.stripeWindow.Stripe})}getScriptUrl(e){return e&&e!==ke.V3?`https://js.stripe.com/${e}/stripe.js`:"https://js.stripe.com/v3/"}}const Re={body:{},headers:{},status:0};class ze extends l{constructor(e,{message:t,errors:n}={}){const{body:i,headers:o,status:a}=e||Re;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=o,this.status=a,this.errors=n||[]}}const Ge=["payment_element_beta_2","alipay_pm_beta_1","link_default_integration_beta_1","shipping_address_element_beta_1","address_element_beta_1"];function xe(e){if(!function(e){return"stripeConnectedAccount"in e&&"stripePublishableKey"in e&&"stripeVersion"in e}(e))throw new m(h.MissingPaymentMethod)}var Be=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Le extends j{constructor(e,t){super("stripe",e),this.paymentIntegrationService=e,this.scriptLoader=t}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return Be(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new C("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"id"in e}(e))throw new m(h.MissingPaymentToken)}(i),n.nonce=i.id,n})}getPaymentGatewayParameters(){const e=this.getGooglePayInitializationData();xe(e);const{stripeVersion:t,stripePublishableKey:n,stripeConnectedAccount:i}=e;return{gateway:this.getGatewayIdentifier(),"stripe:version":t,"stripe:publishableKey":`${n}/${i}`}}processAdditionalAction(e,t){var n;return Be(this,void 0,void 0,function*(){if(!t)throw new Y(["payment"]);if(!w(e)||("object"!=typeof(i=e.body)||null===i||!("three_ds_result"in i)||!("errors"in i)))throw e;var i;if(d(e.body.errors,{code:"three_d_secure_required"})){const i=this.getGooglePayInitializationData();xe(i),this.stripeUPEClient=yield this.loadStripeJs(i,t);const o=e.body.three_ds_result.token;let a,r=!1;try{a=yield this.stripeUPEClient.confirmCardPayment(o)}catch(e){try{a=yield this.stripeUPEClient.retrievePaymentIntent(o)}catch(e){r=!0}}if(null==a?void 0:a.error){if(this._throwDisplayableStripeError(a.error),this._isCancellationError(a.error))throw new P;throw new q}if(!(null==a?void 0:a.paymentIntent)&&!r)throw new ze;return this.paymentIntegrationService.submitPayment({methodId:t,paymentData:{nonce:(null===(n=null==a?void 0:a.paymentIntent)||void 0===n?void 0:n.id)||o}})}throw e})}loadStripeJs(e,t){return Be(this,void 0,void 0,function*(){if(this.stripeUPEClient)return this.stripeUPEClient;const n=this.paymentIntegrationService.getState().getCartLocale();return"googlepaystripeocs"===t&&e.useNewStripeJsVersion?this.scriptLoader.getStripeClient(e,n,ke.CLOVER):this.scriptLoader.getStripeClient(e,n,ke.V3,Ge,"2020-03-02;alipay_beta=v1;link_beta=v1")})}_isCancellationError(e){var t,n;return e&&-1!==(null===(n=null===(t=e.payment_intent.last_payment_error)||void 0===t?void 0:t.message)||void 0===n?void 0:n.indexOf("canceled"))}_throwDisplayableStripeError(e){if(a(["card_error","invalid_request_error","validation_error"],e.type))throw new Error(e.message)}}const je=g(i=>new ie(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]);class Fe extends j{constructor(e){super("worldpay",e)}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return n=this,i=void 0,a=function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n},new((o=void 0)||(o=Promise))(function(e,t){function r(e){try{c(a.next(e))}catch(e){t(e)}}function s(e){try{c(a.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o(function(e){e(n)})).then(r,s)}c((a=a.apply(n,i||[])).next())});var n,i,o,a}}const Ue=g(n=>new ie(n,new W(ae(),new Fe(n),t(),e())),[{id:"googlepayworldpayaccess"}]),Ve="3.128.0",qe="3.123.2",He="3.106.0";class We{constructor(e){this.paymentIntegrationService=e,this.braintreeWindow=window}getSDKVersion(){const e=this.paymentIntegrationService.getState().getStoreConfig(),t=(null==e?void 0:e.checkoutSettings.features)||{};return this.getPreloadedSDKVersion()||(A(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?Ve:A(t,"PAYPAL-5636.update_braintree_sdk_version")?qe:He)}getPreloadedSDKVersion(){const e=this.braintreeWindow.braintree;if(e){const t=o(Object.values(e),e=>!!e.VERSION);return null==t?void 0:t.VERSION}}}class Ye extends l{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var Je,Ke,Ze,Xe,Qe,$e,et;!function(e){e.ESTIMATED="ESTIMATED",e.FINAL="FINAL",e.NOT_CURRENTLY_KNOWN="NOT_CURRENTLY_KNOWN"}(Je||(Je={})),function(e){e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED"}(Ke||(Ke={})),function(e){e.TRUSTLY="trustly"}(Ze||(Ze={})),function(e){e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="cancelled",e.UNRECOGNIZED="unrecognized"}(Xe||(Xe={})),function(e){e.Customer="CUSTOMER",e.Merchant="MERCHANT",e.Network="NETWORK",e.Internal="INTERNAL",e.Unknown="UNKNOWN"}(Qe||(Qe={})),function(e){e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED"}($e||($e={})),function(e){e.Visa="visa",e.Mastercard="mastercard",e.AmericanExpress="american-express",e.DinersClub="diners-club",e.Discover="discover",e.Jcb="jcb",e.UnionPay="union-pay",e.Maestro="maestro",e.Elo="elo",e.Mir="mir",e.Hiper="hiper",e.Hipercard="hipercard"}(et||(et={}));var tt,nt,it,ot=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class at{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return ot(this,void 0,void 0,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return ot(this,void 0,void 0,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=yield t.create({authorization:e})}return this.client})}getDataCollectorOrThrow(e){return ot(this,void 0,void 0,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),i=Object.assign({client:t,kount:!0},e);this.dataCollector=yield n.create(i)}catch(e){if(function(e){return Boolean("object"==typeof e&&null!==e&&("type"in e||"message"in e||"code"in e))}(e)&&e.code===$e.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return ot(this,void 0,void 0,function*(){if(!this.googlePayment){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadGooglePayment()]);this.googlePayment=yield t.create({client:e})}return this.googlePayment})}getBraintreeThreeDS(){return ot(this,void 0,void 0,function*(){if(!this.threeDS){const[e,t]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]);this.threeDS=yield t.create({client:e,version:2})}return this.threeDS})}getBraintreeLocalPayment(e){return ot(this,void 0,void 0,function*(){if(!this.braintreeLocalPayment){const[t,n]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((i,o)=>{n.create({client:t,merchantAccountId:e},(e,t)=>{e&&o(e),i(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return ot(this,void 0,void 0,function*(){if(!this.usBankAccount){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadUsBankAccount();this.usBankAccount=yield t.create({client:e})}return this.usBankAccount})}getBraintreeVisaCheckout(){return this.visaCheckout||(this.visaCheckout=Promise.all([this.getClient(),this.braintreeScriptLoader.loadVisaCheckout()]).then(([e,t])=>t.create({client:e}))),this.visaCheckout}getVisaCheckoutSdk(e){return ot(this,void 0,void 0,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return ot(this,void 0,void 0,function*(){if(!this.braintreeVenmo){const e=yield this.getClient(),t=yield this.braintreeScriptLoader.loadVenmoCheckout(),n={client:e,allowDesktop:!0,paymentMethodUsage:"multi_use"},i=yield t.create(n);if(!i.isBrowserSupported())throw new Ye;this.braintreeVenmo=i}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new _(v.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}!function(e){e.Sandbox="sandbox",e.Production="production"}(tt||(tt={})),function(e){e.Client="client",e.DataCollector="dataCollector",e.Fastlane="fastlane",e.GooglePayment="googlePayment",e.HostedFields="hostedFields",e.LocalPayment="localPayment",e.Paypal="paypal",e.PaypalCheckout="paypalCheckout",e.ThreeDSecure="threeDSecure",e.UsBankAccount="usBankAccount",e.Venmo="venmo",e.VisaCheckout="visaCheckout"}(nt||(nt={})),function(e){e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification"}(it||(it={}));const rt={[He]:{[nt.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[nt.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[nt.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[nt.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[nt.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[nt.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[nt.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[nt.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[nt.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[nt.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[nt.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[nt.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[qe]:{[nt.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[nt.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[nt.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[nt.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[nt.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[nt.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[nt.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[nt.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[nt.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[nt.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[nt.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[nt.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[Ve]:{[nt.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[nt.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[nt.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[nt.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[nt.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[nt.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[nt.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[nt.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[nt.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[nt.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[nt.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[nt.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var st=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ct{constructor(e,t,n){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=n}loadClient(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.Client,"client.min.js")})}loadFastlane(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.Paypal,"paypal.min.js")})}loadLocalPayment(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.GooglePayment,"google-payment.min.js")})}load3DS(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(nt.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(nt.Venmo,"venmo.min.js")}loadHostedFields(){return st(this,void 0,void 0,function*(){return this.loadBraintreeModuleOrThrow(nt.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return st(this,void 0,void 0,function*(){if(this.braintreeHostWindow.V)return this.braintreeHostWindow.V;const t=e?"sha384-0eu1s1GtqzXlL9DtLgmwzC5WWlEH/ADRM0n38cVQkvtT+W/gey96rcb1LwuUOPDm":"sha384-1f1csvP3ZFxg4dILH1GaY4LHlZ0oX7Rk83rxmLlwbnIi4TM0NYzXoev1VoEiVDS6";return this.scriptLoader.loadScript(`//${e?"sandbox-":""}assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js`,{async:!0,attributes:{integrity:t,crossorigin:"anonymous"}}).then(()=>{if(!this.braintreeHostWindow.V)throw new u;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return st(this,void 0,void 0,function*(){let n=this.getBraintreeModule(e);if(n)return n;const i=this.braintreeSDKVersionManager.getSDKVersion(),o=`//js.braintreegateway.com/web/${i}/js/${t}`,a=i in rt?this.getIntegrityValuesByModuleName(e,i):void 0;if(yield this.scriptLoader.loadScript(o,a?{async:!0,attributes:{integrity:a,crossorigin:"anonymous"}}:void 0),n=this.getBraintreeModule(e),!n)throw new u;return n})}getBraintreeModule(e){var t;return null===(t=this.braintreeHostWindow.braintree)||void 0===t?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const n=rt[t][e];if(!n)throw new Error("Unexpected fileName value");return n}}class dt{constructor(e){const t=new Promise((e,t)=>{this.cancel=t});this.promise=Promise.race([e,t])}}var lt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ut extends j{constructor(e,t){super("braintree",e),this._braintreeSdk=t,this._methodId=ee.BRAINTREE,this._service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});return lt(this,void 0,void 0,function*(){yield i.initialize.call(this,e,t,n);let o=i.getPaymentMethod.call(this);if(o.clientToken||(o=(yield this._service.loadPaymentMethod(this._methodId)).getPaymentMethodOrThrow(this._methodId)),!o.clientToken||!o.initializationData)throw new m(h.MissingPaymentMethod);return this._braintreeSdk.initialize(o.clientToken),this._braintreeGooglePayment=yield this._braintreeSdk.getBraintreeGooglePayment(),Promise.resolve()})}getNonce(e){const t=Object.create(null,{getNonce:{get:()=>super.getNonce},getPaymentMethod:{get:()=>super.getPaymentMethod}});var n;return lt(this,void 0,void 0,function*(){const i=yield t.getNonce.call(this,e),{clientToken:o,initializationData:a}=t.getPaymentMethod.call(this);if(!o||!a||!(null===(n=a.card_information)||void 0===n?void 0:n.bin))throw new m(h.MissingPaymentMethod);const{isThreeDSecureEnabled:r,card_information:{bin:s,isNetworkTokenized:c}}=a;if(r&&!c){const e=yield this._braintreeSdk.getBraintreeThreeDS(),{orderAmount:t}=this._service.getState().getOrderOrThrow();return(yield this._braintreePresent3DSChallenge(e,t,i,s)).nonce}return i})}extraPaymentData(){return lt(this,void 0,void 0,function*(){return{deviceSessionId:yield this._getBraintreeDeviceData()}})}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return lt(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);let i;try{i=JSON.parse(n.nonce)}catch(e){throw new C("Unable to parse response from Google Pay.")}return function(e){if(!function(e){return"object"==typeof e&&null!==e&&"androidPayCards"in e}(e))throw new m(h.MissingPaymentToken)}(i),n.nonce=i.androidPayCards[0].nonce,n.card_information.bin=i.androidPayCards[0].details.bin,n.card_information.isNetworkTokenized=i.androidPayCards[0].details.isNetworkTokenized,n})}getCardParameters(){return super.getCardParameters()}getPaymentGatewayParameters(){const e=Object.create(null,{getMerchantInfo:{get:()=>super.getMerchantInfo},getTransactionInfo:{get:()=>super.getTransactionInfo},getRequiredData:{get:()=>super.getRequiredData}});return lt(this,void 0,void 0,function*(){return this.getBraintreeGooglePayment().createPaymentDataRequest(Object.assign({merchantInfo:e.getMerchantInfo.call(this),transactionInfo:e.getTransactionInfo.call(this),cardRequirements:{billingAddressRequired:!0,billingAddressFormat:"FULL"}},yield e.getRequiredData.call(this))).paymentMethodTokenizationParameters.parameters})}getBraintreeGooglePayment(){if(!this._braintreeGooglePayment)throw new m(h.MissingPaymentMethod);return this._braintreeGooglePayment}_getBraintreeDeviceData(){return lt(this,void 0,void 0,function*(){const{deviceData:e}=yield this._braintreeSdk.getDataCollectorOrThrow();return e})}_braintreePresent3DSChallenge(e,t,n,i){return new dt(e.verifyCard({amount:t,bin:i,nonce:n,onLookupComplete:(e,t)=>{t()}})).promise}}const ht=g(i=>{const o=t(),a=window,r=new We(i),s=new at(new ct(n(),a,r));return new ie(i,new W(ae(),new ut(i,s),o,e()))},[{id:"googlepaybraintree"}]);var yt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class gt{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return yt(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new u}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return yt(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new u;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return yt(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new u}return this.window.paypalApms})}getPayPalMessages(e,t){return yt(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new u;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return yt(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,attributionId:c}=o;return{options:{"client-id":r,"merchant-id":s,commit:!0,components:["fastlane","buttons","payment-fields","hosted-fields","three-domain-secure"],currency:t,intent:a},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":c,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,buyerCountry:c,attributionId:d,isHostedCheckoutEnabled:l,isDeveloperModeApplicable:u}=o,y=l||n;return{options:Object.assign({"client-id":r,"merchant-id":s,commit:y,components:["googlepay"],currency:t,intent:a},u&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":d,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{intent:i,clientId:o,merchantId:a,buyerCountry:r,attributionId:s,isDeveloperModeApplicable:c,availableAlternativePaymentMethods:d=[],enabledAlternativePaymentMethods:l=[]}=n,u=l,y=d.filter(e=>!l.includes(e));return{options:Object.assign({"client-id":o,"merchant-id":a,"enable-funding":u.length>0?u:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},c&&{"buyer-country":r}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{clientId:i,merchantId:o,attributionId:a,isDeveloperModeApplicable:r,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":o,components:["messages"],currency:t},r&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}function pt(e){if(!function(e){return!!e.initializationData&&"attributionId"in e.initializationData&&"isVenmoEnabled"in e.initializationData&&"isGooglePayEnabled"in e.initializationData&&"isPayPalCreditAvailable"in e.initializationData}(e))throw new m(h.MissingPaymentMethod)}var mt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class ft extends j{constructor(e,t){super("paypalsb",e),this.payPalCommerceSdk=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,a,r,s,c;return mt(this,void 0,void 0,function*(){const d=null!==(a=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==a?a:n;if(!d)throw new m(h.MissingPaymentMethod);yield i.initialize.call(this,e,t,d);const l=i.getPaymentMethod.call(this);if(!l.initializationData)throw new m(h.MissingPaymentMethod);pt(l);const u=yield this.payPalCommerceSdk.getPayPalGooglePaySdk(l,d);this.googlepayConfig=yield u.Googlepay().config();const{allowedPaymentMethods:y}=this.googlepayConfig;this.setGatewayIdentifier(null===(c=null===(s=null===(r=y[0])||void 0===r?void 0:r.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===c?void 0:c.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return mt(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}const wt="This API endpoint is for internal use only and may change in the future";var Pt,vt;!function(e){e.Approved="APPROVED",e.PayerActionRequired="PAYER_ACTION_REQUIRED"}(Pt||(Pt={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(vt||(vt={}));var _t=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Ct extends ie{constructor(e,t,n,i){super(e,t),this._payPalCommerceSdk=n,this._requestSender=i}execute({payment:e}){return _t(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId))throw new Y(["payment"]);const t=this._paymentIntegrationService.getState(),n=t.getCartOrThrow().id,{initializationData:i}=t.getPaymentMethodOrThrow(this._getMethodId()),{orderId:o}=yield this.getOrderId(n),{card_information:a}=i||{},r=yield this._googlePayPaymentProcessor.getNonce(e.methodId),s={tokenizationData:{type:"PAYMENT_GATEWAY",token:atob(r)},info:{cardNetwork:(null==a?void 0:a.type)||"",cardDetails:(null==a?void 0:a.number)||""},type:"CARD"};yield this.confirmOrder(o,s),yield this._paymentIntegrationService.submitOrder();try{const t={formattedPayload:{method_id:e.methodId,paypal_account:{order_id:o}}};yield this._paymentIntegrationService.submitPayment({methodId:e.methodId,paymentData:t})}catch(e){yield this._googlePayPaymentProcessor.processAdditionalAction(e)}})}confirmOrder(e,t){return _t(this,void 0,void 0,function*(){const n=this._paymentIntegrationService.getState(),i=n.getPaymentMethodOrThrow(this._getMethodId());if(!i.initializationData)throw new m(h.MissingPaymentMethod);const o=n.getCartOrThrow().currency.code,a=yield this._payPalCommerceSdk.getPayPalGooglePaySdk(i,o,!0),{status:r}=yield a.Googlepay().confirmOrder({orderId:e,paymentMethodData:t});if(r===Pt.PayerActionRequired)return yield a.Googlepay().initiatePayerAction({orderId:e}),Promise.resolve();if(r!==Pt.Approved)throw new C("Payment is not approved.");return Promise.resolve()})}getOrderId(e){return _t(this,void 0,void 0,function*(){const t={cartId:e,shouldSaveInstrument:!1},{body:n}=yield this._requestSender.post("/api/storefront/payments/googlepaypaypalcommercecheckout",{headers:Object.assign({"X-API-INTERNAL":wt,"Content-Type":ge.Json},V),body:t});return n})}}const bt=g(i=>{const o=new gt(n());return new Ct(i,new W(ae(),new ft(i,o),t(),e()),o,t())},[{id:"googlepaypaypalcommerce"}]);var St=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class It{constructor(e){this.scriptLoader=e,this.window=window}getPayPalFastlaneSdk(e,t,n){return St(this,void 0,void 0,function*(){if(!this.window.paypalFastlaneSdk){const i=this.getPayPalFastlaneSdkConfiguration(e,t,n);if(yield this.loadPayPalSdk(i),!this.window.paypalFastlaneSdk)throw new u}return this.window.paypalFastlaneSdk})}getPayPalGooglePaySdk(e,t,n,i){return St(this,void 0,void 0,function*(){if(!this.window.paypalGooglePay||i){const i=this.getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n);yield this.loadPayPalSdk(i)}if(!this.window.paypalGooglePay)throw new u;return this.window.paypalGooglePay})}getPayPalApmsSdk(e,t){return St(this,void 0,void 0,function*(){if(!this.window.paypalApms){const n=this.getPayPalApmSdkConfiguration(e,t);if(yield this.loadPayPalSdk(n),!this.window.paypalApms)throw new u}return this.window.paypalApms})}getPayPalMessages(e,t){return St(this,void 0,void 0,function*(){if(!this.window.paypalMessages){const n=this.getPayPalSdkMessagesConfiguration(e,t);yield this.loadPayPalSdk(n)}if(!this.window.paypalMessages)throw new u;return this.window.paypalMessages})}loadPayPalSdk({options:e,attributes:t}){return St(this,void 0,void 0,function*(){const n=this.transformConfig(e),i=this.transformConfig(t),o=`https://www.paypal.com/sdk/js?${new URLSearchParams(n).toString()}`;yield this.scriptLoader.loadScript(o,{async:!0,attributes:i})})}getPayPalFastlaneSdkConfiguration(e,t,n){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,attributionId:c}=o;return{options:{"client-id":r,"merchant-id":s,commit:!0,components:["fastlane","three-domain-secure"],currency:t,intent:a},attributes:{"data-client-metadata-id":n.replace(/-/g,""),"data-namespace":"paypalFastlaneSdk","data-partner-attribution-id":c,"data-sdk-client-token":i}}}getPayPalGooglePaySdkScriptConfigOrThrow(e,t,n=!0){const{clientToken:i,initializationData:o}=e;if(!o||!o.clientId)throw new m(h.MissingPaymentMethod);const{intent:a,clientId:r,merchantId:s,buyerCountry:c,attributionId:d,isHostedCheckoutEnabled:l,isDeveloperModeApplicable:u}=o,y=l||n;return{options:Object.assign({"client-id":r,"merchant-id":s,commit:y,components:["googlepay"],currency:t,intent:a},u&&{"buyer-country":c}),attributes:{"data-partner-attribution-id":d,"data-client-token":i,"data-namespace":"paypalGooglePay"}}}getPayPalApmSdkConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{intent:i,clientId:o,merchantId:a,buyerCountry:r,attributionId:s,isDeveloperModeApplicable:c,availableAlternativePaymentMethods:d=[],enabledAlternativePaymentMethods:l=[]}=n,u=this.filterFundingOptions(l),y=this.filterFundingOptions(d.filter(e=>!l.includes(e)));return{options:Object.assign({"client-id":o,"merchant-id":a,"enable-funding":u.length>0?u:void 0,"disable-funding":y.length>0?y:void 0,commit:!0,components:["buttons","payment-fields"],currency:t,intent:i},c&&{"buyer-country":r}),attributes:{"data-partner-attribution-id":s,"data-namespace":"paypalApms"}}}getPayPalSdkMessagesConfiguration(e,t){const{initializationData:n}=e;if(!n||!n.clientId)throw new m(h.MissingPaymentMethod);const{clientId:i,merchantId:o,attributionId:a,isDeveloperModeApplicable:r,buyerCountry:s}=n;return{options:Object.assign({"client-id":i,"merchant-id":o,components:["messages"],currency:t},r&&{"buyer-country":s}),attributes:{"data-namespace":"paypalMessages","data-partner-attribution-id":a}}}filterFundingOptions(e){const t=["klarna","afterpay"];return e?e.filter(e=>!t.includes(e)):[]}transformConfig(e){let t={};return Object.keys(e).forEach(n=>{const i=e[n];null==i||""===i||Array.isArray(i)&&0===i.length||(t=Object.assign(Object.assign({},t),{[n]:Array.isArray(i)?i.join(","):i}))}),t}}var Ot,kt,At=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Tt extends j{constructor(e,t){super("googlepay_bigcommerce_payments",e),this.payPalSdkHelper=t,this.service=e}initialize(e,t,n){const i=Object.create(null,{initialize:{get:()=>super.initialize},getPaymentMethod:{get:()=>super.getPaymentMethod}});var o,a,r,s,c;return At(this,void 0,void 0,function*(){const d=null!==(a=null===(o=this.service.getState().getStoreConfig())||void 0===o?void 0:o.currency.code)&&void 0!==a?a:n;if(!d)throw new m(h.MissingPaymentMethod);yield i.initialize.call(this,e,t,d);const l=i.getPaymentMethod.call(this);if(!l.initializationData)throw new m(h.MissingPaymentMethod);pt(l);const u=yield this.payPalSdkHelper.getPayPalGooglePaySdk(l,d);this.googlepayConfig=yield u.Googlepay().config();const{allowedPaymentMethods:y}=this.googlepayConfig;this.setGatewayIdentifier(null===(c=null===(s=null===(r=y[0])||void 0===r?void 0:r.tokenizationSpecification)||void 0===s?void 0:s.parameters)||void 0===c?void 0:c.gateway)})}getPaymentGatewayParameters(){if(this.googlepayConfig){const{allowedPaymentMethods:e}=this.googlepayConfig,{gatewayMerchantId:t}=e[0].tokenizationSpecification.parameters;return{gateway:this.getGatewayIdentifier(),gatewayMerchantId:t}}return{gateway:this.getGatewayIdentifier()}}mapToExternalCheckoutData(e){const t=Object.create(null,{mapToExternalCheckoutData:{get:()=>super.mapToExternalCheckoutData}});return At(this,void 0,void 0,function*(){const n=yield t.mapToExternalCheckoutData.call(this,e);return n.nonce=btoa(n.nonce),n})}}!function(e){e.Approved="APPROVED",e.PayerActionRequired="PAYER_ACTION_REQUIRED"}(Ot||(Ot={})),function(e){e.AUTHORIZE="authorize",e.CAPTURE="capture"}(kt||(kt={}));var Mt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Et extends ie{constructor(e,t,n,i){super(e,t),this._payPalSdkHelper=n,this._requestSender=i}execute({payment:e}){return Mt(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId))throw new Y(["payment"]);const t=this._paymentIntegrationService.getState(),n=t.getCartOrThrow().id,{initializationData:i}=t.getPaymentMethodOrThrow(this._getMethodId()),{orderId:o}=yield this.getOrderId(n),{card_information:a}=i||{},r=yield this._googlePayPaymentProcessor.getNonce(e.methodId),s={tokenizationData:{type:"PAYMENT_GATEWAY",token:atob(r)},info:{cardNetwork:(null==a?void 0:a.type)||"",cardDetails:(null==a?void 0:a.number)||""},type:"CARD"};yield this.confirmOrder(o,s),yield this._paymentIntegrationService.submitOrder();try{const t={formattedPayload:{method_id:e.methodId,paypal_account:{order_id:o}}};yield this._paymentIntegrationService.submitPayment({methodId:e.methodId,paymentData:t})}catch(e){yield this._googlePayPaymentProcessor.processAdditionalAction(e)}})}confirmOrder(e,t){return Mt(this,void 0,void 0,function*(){const n=this._paymentIntegrationService.getState(),i=n.getPaymentMethodOrThrow(this._getMethodId());if(!i.initializationData)throw new m(h.MissingPaymentMethod);const o=n.getCartOrThrow().currency.code,a=yield this._payPalSdkHelper.getPayPalGooglePaySdk(i,o,!0),{status:r}=yield a.Googlepay().confirmOrder({orderId:e,paymentMethodData:t});if(r===Ot.PayerActionRequired)return yield a.Googlepay().initiatePayerAction({orderId:e}),Promise.resolve();if(r!==Ot.Approved)throw new C("Payment is not approved.");return Promise.resolve()})}getOrderId(e){return Mt(this,void 0,void 0,function*(){const t={cartId:e,shouldSaveInstrument:!1},{body:n}=yield this._requestSender.post("/api/storefront/payments/googlepay_bigcommerce_paymentscheckout",{headers:Object.assign({"X-API-INTERNAL":wt,"Content-Type":ge.Json},V),body:t});return n})}}const Dt=g(i=>{const o=new It(n());return new Et(i,new W(ae(),new Tt(i,o),t(),e()),o,t())},[{id:"googlepay_bigcommerce_payments"}]);var Nt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Rt extends j{constructor(e,t){super("worldlinena",e),this.formPoster=t}extraPaymentData(){return Nt(this,void 0,void 0,function*(){return Promise.resolve({browser_info:f()})})}processAdditionalAction(e){return Nt(this,void 0,void 0,function*(){if(!function(e){return w(e)&&(t=e.body,s(t)&&"object"==typeof t&&"errors"in t&&"three_ds_result"in t&&r(t.errors)&&d(t.errors,{code:"three_d_secure_required"}));var t}(e))throw e;const{three_ds_result:t}=e.body,{acs_url:n,payer_auth_request:i,merchant_data:o}=t||{};if(!n||!i||!o)throw new Y(["formUrl","threeDSSessionData","creq"]);return new Promise(e=>{this.formPoster.postForm(n,{threeDSSessionData:i,creq:o},e,"_top")})})}}const zt=g(n=>new ie(n,new W(ae(),new Rt(n,e()),t(),e())),[{id:"googlepaytdonlinemart"}]);class Gt extends l{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var xt=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class Bt{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t;return xt(this,void 0,void 0,function*(){if(!(null==e?void 0:e.methodId)||!te(e.methodId))throw new C('Unable to proceed because "methodId" is not a valid key.');this._methodId=e.methodId;const n=e[this._getMethodId()];if(!n)throw new C("Unable to proceed without valid options.");let i,o=this._paymentIntegrationService.getState();try{i=o.getPaymentMethodOrThrow(this._getMethodId())}catch(e){o=yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodId()),i=o.getPaymentMethodOrThrow(this._getMethodId())}try{yield this._googlePayPaymentProcessor.initialize(()=>i,this._getGooglePayClientOptions(null===(t=i.initializationData)||void 0===t?void 0:t.storeCountry))}catch(e){return}this._addPaymentButton(n)})}signIn(){return Promise.reject(new Gt('In order to sign in via Google Pay, the shopper must click on "Google Pay" button.'))}signOut(){var e;return xt(this,void 0,void 0,function*(){const t=null===(e=this._paymentIntegrationService.getState().getPaymentId())||void 0===e?void 0:e.providerId;t&&(yield this._googlePayPaymentProcessor.signOut(t))})}executePaymentMethodCheckout(e){var t;return null===(t=null==e?void 0:e.continueWithCheckoutCallback)||void 0===t||t.call(e),Promise.resolve()}deinitialize(){var e;return null===(e=this._paymentButton)||void 0===e||e.remove(),this._paymentButton=void 0,this._methodId=void 0,Promise.resolve()}_getGooglePayClientOptions(e){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:t,shippingAddress:n,shippingOptionData:i,offerData:o})=>xt(this,void 0,void 0,function*(){const{availableTriggers:a,addressChangeTriggers:r,shippingOptionsChangeTriggers:s,offerChangeTriggers:c}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!a.includes(t))return;const d=r.includes(t)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(n):void 0;s.includes(t)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(i.id));const{newOfferInfo:l,error:u}=c.includes(t)?yield this._googlePayPaymentProcessor.handleCoupons(o):{},h=u;yield this._paymentIntegrationService.loadCheckout();const y=this._googlePayPaymentProcessor.getTotalPrice(),{code:g}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},e&&{countryCode:e}),{currencyCode:g,totalPriceStatus:N.FINAL,totalPrice:y})},d&&{newShippingOptionParameters:d}),l&&{newOfferInfo:l}),h&&{error:h})})}}}_addPaymentButton({container:e,buttonColor:t,buttonType:n,onClick:i,onError:o}){var a;this._paymentButton=null!==(a=this._paymentButton)&&void 0!==a?a:this._googlePayPaymentProcessor.addPaymentButton(e,{buttonColor:null!=t?t:"default",buttonType:null!=n?n:"plain",onClick:this._handleClick(o,i)})}_handleClick(e,t){return n=>xt(this,void 0,void 0,function*(){n.preventDefault(),t&&"function"==typeof t&&t();try{yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(t){let n=t;if($(t)){if("CANCELED"===t.statusCode)throw new P;n=new q(JSON.stringify(t))}throw null==e||e(new q("An error occurred while requesting your Google Pay payment details.")),n}})}_interactWithPaymentSheet(){return xt(this,void 0,void 0,function*(){const e=yield this._googlePayPaymentProcessor.showPaymentSheet(),t=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(e),n=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(e),i="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;t&&(yield this._paymentIntegrationService.updateBillingAddress(t)),n&&(yield this._paymentIntegrationService.updateShippingAddress(n)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodId(),e,i)})}_getMethodId(){return k(this._methodId,()=>new _(v.PaymentNotInitialized))}}const Lt=g(n=>{const i=t();return new Bt(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv2"}]),jt=g(n=>{const i=t();return new Bt(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv3"}]),Ft=g(n=>new Bt(n,new W(ae(),new ue(n),t(),e())),[{id:"googlepayauthorizenet"}]),Ut=g(n=>{const i=t();return new Bt(n,new W(ae(),new fe(n,i),i,e()))},[{id:"googlepaycheckoutcom"}]),Vt=g(n=>new Bt(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaycybersourcev2"}]),qt=g(n=>new Bt(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaybnz"}]),Ht=g(n=>new Bt(n,new W(ae(),new _e(n),t(),e())),[{id:"googlepayorbital"}]),Wt=g(i=>new Bt(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripe"},{id:"googlepaystripeocs"}]),Yt=g(i=>new Bt(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripeupe"}]),Jt=g(n=>new Bt(n,new W(ae(),new Fe(n),t(),e())),[{id:"googlepayworldpayaccess"}]),Kt=g(i=>{const o=t(),a=window,r=new We(i),s=new at(new ct(n(),a,r));return new Bt(i,new W(ae(),new ut(i,s),o,e()))},[{id:"googlepaybraintree"}]),Zt=g(i=>new Bt(i,new W(ae(),new ft(i,new gt(n())),t(),e())),[{id:"googlepaypaypalcommerce"}]),Xt=g(i=>new Bt(i,new W(ae(),new Tt(i,new It(n())),t(),e())),[{id:"googlepay_bigcommerce_payments"}]),Qt=g(n=>new Bt(n,new W(ae(),new Rt(n,e()),t(),e())),[{id:"googlepaytdonlinemart"}]);class $t extends l{constructor(e){super(e||"An unexpected error has occurred during buy now cart creation process. Please try again later."),this.name="BuyNowCartCreationError",this.type="buy_now_cart_creation_error"}}var en=function(e,t,n,i){return new(n||(n=Promise))(function(o,a){function r(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,s)}c((i=i.apply(e,t||[])).next())})};class tn{constructor(e,t){this._paymentIntegrationService=e,this._googlePayPaymentProcessor=t}initialize(e){var t,n;return en(this,void 0,void 0,function*(){if(!e.methodId||!te(e.methodId))throw new C('Unable to proceed because "methodId" is not a valid key.');if(this._methodId=e.methodId,!e.containerId)throw new C('Unable to proceed because "containerId" is not a valid key.');const i=e[this._getMethodOrThrow()];if(!i)throw new C("Unable to proceed without valid options.");const{buyNowInitializeOptions:o,currencyCode:a,buttonColor:r,buttonType:s,onError:c}=i;let d,l=this._paymentIntegrationService.getState();try{d=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}catch(e){l=yield this._paymentIntegrationService.loadPaymentMethod(this._getMethodOrThrow()),d=l.getPaymentMethodOrThrow(this._getMethodOrThrow())}if(this._countryCode=null===(t=d.initializationData)||void 0===t?void 0:t.storeCountry,o){if(!a)throw new C('Unable to initialize payment because "options.currencyCode" argument is not provided.');this._currencyCode=a,this._buyNowInitializeOptions=o,yield this._googlePayPaymentProcessor.initialize(()=>d,this._getGooglePayClientOptions(),!!o,a)}else yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initialize(()=>d,this._getGooglePayClientOptions());this._paymentButton=null!==(n=this._paymentButton)&&void 0!==n?n:this._googlePayPaymentProcessor.addPaymentButton(e.containerId,{buttonColor:null!=r?r:"default",buttonType:null!=s?s:"plain",onClick:this._handleClick(c)})})}deinitialize(){var e;return null===(e=this._paymentButton)||void 0===e||e.remove(),this._paymentButton=void 0,this._methodId=void 0,Promise.resolve()}_handleClick(e){return t=>en(this,void 0,void 0,function*(){t.preventDefault();try{this._buyNowInitializeOptions?yield this._createBuyNowCartOrThrow(this._buyNowInitializeOptions):yield this._paymentIntegrationService.loadDefaultCheckout(),yield this._googlePayPaymentProcessor.initializeWidget(),yield this._interactWithPaymentSheet()}catch(t){let n=t;if($(t)){if("CANCELED"===t.statusCode)throw new P;n=new q(JSON.stringify(t))}throw null==e||e(new q("An error occurred while requesting your Google Pay payment details.")),n}})}_interactWithPaymentSheet(){var e;return en(this,void 0,void 0,function*(){const t=yield this._googlePayPaymentProcessor.showPaymentSheet(),n=this._googlePayPaymentProcessor.mapToBillingAddressRequestBody(t),i=this._googlePayPaymentProcessor.mapToShippingAddressRequestBody(t),o="/embedded-checkout"===window.location.pathname?this._paymentIntegrationService.getState().getStoreConfigOrThrow().links.siteLink:void 0;n&&(yield this._paymentIntegrationService.updateBillingAddress(n)),i&&!(null===(e=this._buyNowCart)||void 0===e?void 0:e.lineItems.digitalItems.length)&&(yield this._paymentIntegrationService.updateShippingAddress(i)),yield this._googlePayPaymentProcessor.setExternalCheckoutForm(this._getMethodOrThrow(),t,o)})}_getGooglePayClientOptions(){return{paymentDataCallbacks:{onPaymentDataChanged:({callbackTrigger:e,shippingAddress:t,shippingOptionData:n,offerData:i})=>en(this,void 0,void 0,function*(){const{availableTriggers:o,addressChangeTriggers:a,shippingOptionsChangeTriggers:r,offerChangeTriggers:s}=this._googlePayPaymentProcessor.getCallbackTriggers();if(!o.includes(e))return;const c=a.includes(e)?yield this._googlePayPaymentProcessor.handleShippingAddressChange(t):void 0;r.includes(e)&&(yield this._googlePayPaymentProcessor.handleShippingOptionChange(n.id));const{newOfferInfo:d,error:l}=s.includes(e)?yield this._googlePayPaymentProcessor.handleCoupons(i):{},u=l;return this._buyNowInitializeOptions?this._getBuyNowTransactionInfo(c,d,u):this._getTransactionInfo(c,d,u)})}}}_createBuyNowCartOrThrow(e){return en(this,void 0,void 0,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=e.getBuyNowCartRequestBody();try{this._buyNowCart=yield this._paymentIntegrationService.createBuyNowCart(t),yield this._paymentIntegrationService.loadCheckout(this._buyNowCart.id)}catch(e){if("string"==typeof e)throw new $t(e);throw e}}})}_getBuyNowTransactionInfo(e,t,n){if(!this._buyNowCart)return;const{cartAmount:i}=this._buyNowCart,o=this._googlePayPaymentProcessor.getTotalPrice();return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:this._getCurrencyCodeOrThrow(),totalPrice:o||String(i),totalPriceStatus:N.FINAL})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})}_getTransactionInfo(e,t,n){return en(this,void 0,void 0,function*(){yield this._paymentIntegrationService.loadCheckout();const i=this._googlePayPaymentProcessor.getTotalPrice(),{code:o}=this._paymentIntegrationService.getState().getCartOrThrow().currency;return Object.assign(Object.assign(Object.assign({newTransactionInfo:Object.assign(Object.assign({},this._countryCode&&{countryCode:this._countryCode}),{currencyCode:o,totalPriceStatus:N.FINAL,totalPrice:i})},e&&{newShippingOptionParameters:e}),t&&{newOfferInfo:t}),n&&{error:n})})}_getMethodOrThrow(){return k(this._methodId,()=>new _(v.PaymentNotInitialized))}_getCurrencyCodeOrThrow(){return k(this._currencyCode,()=>new C('Unable to initialize payment because "options.currencyCode" argument is not provided.'))}}const nn=g(i=>{const o=t(),a=window,r=new We(i),s=new at(new ct(n(),a,r));return new tn(i,new W(ae(),new ut(i,s),o,e()))},[{id:"googlepaybraintree"}]),on=g(i=>new tn(i,new W(ae(),new ft(i,new gt(n())),t(),e())),[{id:"googlepaypaypalcommerce"}]),an=g(i=>new tn(i,new W(ae(),new Tt(i,new It(n())),t(),e())),[{id:"googlepay_bigcommerce_payments"}]),rn=g(n=>{const i=t();return new tn(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv2"}]),sn=g(n=>{const i=t();return new tn(n,new W(ae(),new j("adyen",n),i,e()))},[{id:"googlepayadyenv3"}]),cn=g(n=>new tn(n,new W(ae(),new ue(n),t(),e())),[{id:"googlepayauthorizenet"}]),dn=g(n=>{const i=t();return new tn(n,new W(ae(),new fe(n,i),i,e()))},[{id:"googlepaycheckoutcom"}]),ln=g(n=>new tn(n,new W(ae(),new Pe(n),t(),e())),[{id:"googlepaycybersourcev2"},{id:"googlepaybnz"}]),un=g(n=>new tn(n,new W(ae(),new _e(n),t(),e())),[{id:"googlepayorbital"}]),hn=g(i=>new tn(i,new W(ae(),new Le(i,new Ne(n())),t(),e())),[{id:"googlepaystripe"},{id:"googlepaystripeupe"},{id:"googlepaystripeocs"}]),yn=g(n=>new tn(n,new W(ae(),new Fe(n),t(),e())),[{id:"googlepayworldpayaccess"}]),gn=g(n=>new tn(n,new W(ae(),new Rt(n,e()),t(),e())),[{id:"googlepaytdonlinemart"}]);export{rn as createGooglePayAdyenV2ButtonStrategy,Lt as createGooglePayAdyenV2CustomerStrategy,re as createGooglePayAdyenV2PaymentStrategy,sn as createGooglePayAdyenV3ButtonStrategy,jt as createGooglePayAdyenV3CustomerStrategy,le as createGooglePayAdyenV3PaymentStrategy,cn as createGooglePayAuthorizeDotNetButtonStrategy,Ft as createGooglePayAuthorizeDotNetCustomerStrategy,he as createGooglePayAuthorizeNetPaymentStrategy,an as createGooglePayBigCommercePaymentsButtonStrategy,Xt as createGooglePayBigCommercePaymentsCustomerStrategy,Dt as createGooglePayBigCommercePaymentsPaymentStrategy,qt as createGooglePayBnzCustomerStrategy,nn as createGooglePayBraintreeButtonStrategy,Kt as createGooglePayBraintreeCustomerStrategy,ht as createGooglePayBraintreePaymentStrategy,dn as createGooglePayCheckoutComButtonStrategy,Ut as createGooglePayCheckoutComCustomerStrategy,we as createGooglePayCheckoutComPaymentStrategy,ln as createGooglePayCybersourceButtonStrategy,Vt as createGooglePayCybersourceCustomerStrategy,ve as createGooglePayCybersourcePaymentStrategy,un as createGooglePayOrbitalButtonStrategy,Ht as createGooglePayOrbitalCustomerStrategy,Ce as createGooglePayOrbitalPaymentStrategy,bt as createGooglePayPPCPPaymentStrategy,on as createGooglePayPayPalCommerceButtonStrategy,Zt as createGooglePayPayPalCommerceCustomerStrategy,hn as createGooglePayStripeButtonStrategy,Wt as createGooglePayStripeCustomerStrategy,je as createGooglePayStripePaymentStrategy,Yt as createGooglePayStripeUpeCustomerStrategy,gn as createGooglePayTdOnlineMartButtonStrategy,Qt as createGooglePayTdOnlineMartCustomerStrategy,zt as createGooglePayTdOnlineMartPaymentStrategy,yn as createGooglePayWorldpayAccessButtonStrategy,Jt as createGooglePayWorldpayAccessCustomerStrategy,Ue as createGooglePayWorldpayAccessPaymentStrategy};
|
|
2
2
|
//# sourceMappingURL=google-pay.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getScriptLoader as e}from"@bigcommerce/script-loader";import{includes as t}from"lodash";import{createRequestSender as n}from"@bigcommerce/request-sender";var i,a,r={};function o(e,t){return Object.assign(e,{resolveIds:t})}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);class s 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 d extends s{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class c extends s{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}!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"}(i||(i={}));class l extends s{constructor(e){super(function(e){switch(e){case i.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case i.MissingCart:return"Unable to proceed because cart data is unavailable.";case i.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case i.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case i.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case i.MissingCheckoutConfig:case i.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case i.MissingOrder:return"Unable to proceed because order data is unavailable.";case i.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case i.MissingPayment:return"Unable to proceed because payment data is unavailable.";case i.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case i.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case i.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"}}!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"}(a||(a={}));class u extends s{constructor(e){super(function(e){switch(e){case a.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case a.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case a.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case a.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 h extends s{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}const p={body:{},headers:{},status:0};class m extends s{constructor(e,{message:t,errors:n}={}){const{body:i,headers:a,status:r}=e||p;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=a,this.status=r,this.errors=n||[]}}class y extends m{constructor(e){super(e,{message:"There is a problem processing your payment. Please try again later."}),this.name="PaymentMethodInvalidError",this.type="payment_method_invalid"}}const g=["AT","BE","CA","CH","CZ","DE","DK","ES","FI","FR","GB","GR","IE","IT","NL","NO","NZ","PL","PT","SE"],b=["AU"];var v=function(e,t,n,i){return new(n||(n=Promise))(function(a,r){function o(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}d((i=i.apply(e,t||[])).next())})};class f{constructor(e,t){this.paymentIntegrationService=e,this.klarnaScriptLoader=t}initialize(e){return v(this,void 0,void 0,function*(){this.klarnaCredit=yield this.klarnaScriptLoader.load(),this.unsubscribe=this.paymentIntegrationService.subscribe(t=>{t.isPaymentMethodInitialized({methodId:e.methodId,gatewayId:e.gatewayId})&&this.loadWidget(e)},e=>{const t=e.getCheckout();return t&&t.outstandingBalance},e=>{const t=e.getCheckout();return t&&t.coupons}),yield this.loadWidget(e)})}deinitialize(){return this.unsubscribe&&this.unsubscribe(),Promise.resolve()}execute(e,t){return v(this,void 0,void 0,function*(){if(!e.payment)throw new d('Unable to proceed because "payload.payment" argument is not provided.');const n=e.payment,{paymentData:i}=n,a=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(e);a<i.length;a++)t.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(e,i[a])&&(n[i[a]]=e[i[a]])}return n}(n,["paymentData"]),{authorization_token:r}=yield this.authorize();yield this.paymentIntegrationService.initializePayment(a.methodId,{authorizationToken:r}),yield this.paymentIntegrationService.submitOrder(Object.assign(Object.assign({},e),{payment:a,useStoreCredit:e.useStoreCredit}),t)})}finalize(){return Promise.reject(new c)}loadWidget(e){return v(this,void 0,void 0,function*(){if(!e.klarna)throw new d('Unable to load widget because "options.klarna" argument is not provided.');const{methodId:t,klarna:{container:n,onLoad:r}}=e;return yield this.paymentIntegrationService.loadPaymentMethod(t),new Promise(e=>{const o=this.paymentIntegrationService.getState().getPaymentMethod(t);if(!o)throw new l(i.MissingPaymentMethod);if(!this.klarnaCredit||!o.clientToken)throw new u(a.PaymentNotInitialized);this.klarnaCredit.init({client_token:o.clientToken}),this.klarnaCredit.load({container:n},t=>{r&&r(t),e(t)})})})}getUpdateSessionData(e,n){if(!t([...g,...b],e.countryCode))return{};const i={billing_address:this.mapToKlarnaAddress(e,e.email)};return n&&(i.shipping_address=this.mapToKlarnaAddress(n,e.email)),i}needsStateCode(e){return t(b,e)}mapToKlarnaAddress(e,t){const n={street_address:e.address1,city:e.city,country:e.countryCode,given_name:e.firstName,family_name:e.lastName,postal_code:e.postalCode,region:this.needsStateCode(e.countryCode)?e.stateOrProvinceCode:e.stateOrProvince,email:t};return e.address2&&(n.street_address2=e.address2),e.phone&&(n.phone=e.phone),n}authorize(){return new Promise((e,t)=>{const n=this.paymentIntegrationService.getState(),r=n.getBillingAddress(),o=n.getShippingAddress();if(!r)throw new l(i.MissingBillingAddress);if(!this.klarnaCredit)throw new u(a.PaymentNotInitialized);const s=this.getUpdateSessionData(r,o);this.klarnaCredit.authorize(s,n=>n.approved?e(n):n.show_form?t(new h):void t(new y))})}}class w extends s{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"}}class P{constructor(e,t=window){this.scriptLoader=e,this.klarnaWindow=t}load(){var e,t,n,i,a,r;return n=this,i=void 0,r=function*(){if((null===(e=this.klarnaWindow.Klarna)||void 0===e?void 0:e.Credit)||(yield this.scriptLoader.loadScript("//credit.klarnacdn.net/lib/v1/api.js")),!(null===(t=this.klarnaWindow.Klarna)||void 0===t?void 0:t.Credit))throw new w;return this.klarnaWindow.Klarna.Credit},new((a=void 0)||(a=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(o,s)}d((r=r.apply(n,i||[])).next())})}}const k=o(t=>new f(t,new P(e())),[{id:"klarna"}]);var I=function(e,t,n,i){return new(n||(n=Promise))(function(a,r){function o(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}d((i=i.apply(e,t||[])).next())})};class M{constructor(e,t,n){this.paymentIntegrationService=e,this.klarnav2ScriptLoader=t,this.klarnav2TokenUpdater=n}initialize(e){return I(this,void 0,void 0,function*(){this.klarnaPayments=yield this.klarnav2ScriptLoader.load(),this.unsubscribe=this.paymentIntegrationService.subscribe(t=>{t.isPaymentMethodInitialized({methodId:e.methodId,gatewayId:e.gatewayId})&&this.loadPaymentsWidget(e)},e=>{const t=e.getCheckout();return t&&t.outstandingBalance},e=>{const t=e.getCheckout();return t&&t.coupons}),yield this.loadPaymentsWidget(e)})}deinitialize(){return this.unsubscribe&&this.unsubscribe(),Promise.resolve()}execute(e,t){return I(this,void 0,void 0,function*(){if(!e.payment)throw new d('Unable to proceed because "payload.payment" argument is not provided.');const n=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(e);a<i.length;a++)t.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(e,i[a])&&(n[i[a]]=e[i[a]])}return n}(e.payment,[]),{gatewayId:i,methodId:a}=n;if(!i)throw new d('Unable to proceed because "payload.payment.gatewayId" argument is not provided.');const r=this.paymentIntegrationService.getState(),{id:o}=r.getCartOrThrow(),{clientToken:s,initializationData:c}=r.getPaymentMethodOrThrow(a),{klarnaMultipleRadioButton:l}=c||{};yield this.klarnav2TokenUpdater.klarnaOrderInitialization(o,s);const u=this.isKlarnaMultipleRadioButtonEnabled(l,i,a),{authorization_token:h}=yield this.authorizeOrThrow(u,a);yield this.paymentIntegrationService.initializePayment(i,{authorizationToken:h}),yield this.paymentIntegrationService.submitOrder(Object.assign(Object.assign({},e),{payment:n,useStoreCredit:e.useStoreCredit}),t)})}finalize(){return Promise.reject(new c)}loadPaymentsWidget(e){return I(this,void 0,void 0,function*(){if(!e.klarnav2)throw new d('Unable to load widget because "options.klarnav2" argument is not provided.');const{methodId:t,gatewayId:n,klarnav2:{container:r,onLoad:o}}=e;if(!n)throw new d('Unable to proceed because "payload.payment.gatewayId" argument is not provided.');const s=this.paymentIntegrationService.getState(),c={params:s.getCartOrThrow().id};return yield this.klarnav2TokenUpdater.updateClientToken(n,{params:c}).catch(()=>{throw new l(i.MissingPaymentMethod)}),new Promise(e=>{const i=s.getPaymentMethodOrThrow(t),{klarnaMultipleRadioButton:d}=i.initializationData||{};if(!this.klarnaPayments||!i.clientToken)throw new u(a.PaymentNotInitialized);this.klarnaPayments.init({client_token:i.clientToken}),this.klarnaPayments.load({container:r,payment_method_category:this.isKlarnaMultipleRadioButtonEnabled(d,n,t)},t=>{o&&o(t),e(t)})})})}getUpdateSessionData(e,n,i){if(!t([...g,...b],n.countryCode))return{};const a={billing_address:this.mapToKlarnaAddress(e,n,n.email)};return i&&(a.shipping_address=this.mapToKlarnaAddress(e,i,n.email)),a}needsStateCode(e){return t(b,e)}isKlarnaMultipleRadioButtonEnabled(e,t,n){return e?n:t}mapToKlarnaAddress(e,t,n){const i=this.paymentIntegrationService.getState(),{checkoutSettings:a}=i.getStoreConfigOrThrow(),r=i.getPaymentMethodOrThrow(e),{enableBillie:o}=r.initializationData||{},s={street_address:t.address1,city:t.city,country:t.countryCode,given_name:t.firstName,family_name:t.lastName,postal_code:t.postalCode,region:this.needsStateCode(t.countryCode)?t.stateOrProvinceCode:t.stateOrProvince,email:n};return t.address2&&(s.street_address2=t.address2),t.phone&&(s.phone=t.phone),t.company&&o&&function(e,t,n=!0){var i;return null!==(i=e["PI-3915.b2b_payment_session_for_klarna"])&&void 0!==i?i:n}(a.features)&&(s.organization_name=t.company),s}authorizeOrThrow(e,t){return I(this,void 0,void 0,function*(){yield this.paymentIntegrationService.loadCheckout();const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getShippingAddress(),o=this.getUpdateSessionData(t,i,r);return new Promise((t,n)=>{if(!this.klarnaPayments)return n(new u(a.PaymentNotInitialized));this.klarnaPayments.authorize({payment_method_category:e},o,e=>e.approved?t(e):e.show_form?n(new h):void n(new y))})})}}var S;class C{constructor(e,t=window){this.scriptLoader=e,this.klarnaWindow=t}load(){var e,t,n,i,a,r;return n=this,i=void 0,r=function*(){if((null===(e=this.klarnaWindow.Klarna)||void 0===e?void 0:e.Payments)||(yield this.scriptLoader.loadScript("https://x.klarnacdn.net/kp/lib/v1/api.js")),!(null===(t=this.klarnaWindow.Klarna)||void 0===t?void 0:t.Payments))throw new w;return this.klarnaWindow.Klarna.Payments},new((a=void 0)||(a=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(o,s)}d((r=r.apply(n,i||[])).next())})}}!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(S||(S={}));const O=S,z="This API endpoint is for internal use only and may change in the future",_={"X-Checkout-SDK-Version":"1.857.0"};class T{constructor(e){this.requestSender=e}updateClientToken(e,{timeout:t,params:n}={}){const i=`/api/storefront/payments/${e}`;return this.requestSender.get(i,{timeout:t,headers:Object.assign({Accept:O.JsonV1,"X-API-INTERNAL":z},_),params:n})}klarnaOrderInitialization(e,t){return n=this,i=void 0,r=function*(){const n={headers:Object.assign({Accept:O.JsonV1,"X-API-INTERNAL":z},_),body:{cartId:e,clientToken:t}};yield this.requestSender.put("/api/storefront/initialization/klarna",n)},new((a=void 0)||(a=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(o,s)}d((r=r.apply(n,i||[])).next())});var n,i,a,r}}const U=o(t=>{const{getHost:i}=t.getState(),a=n({host:i()});return new M(t,new C(e()),new T(a))},[{gateway:"klarna"}]);export{k as createKlarnaPaymentStrategy,U as createKlarnaV2PaymentStrategy};
|
|
1
|
+
import{getScriptLoader as e}from"@bigcommerce/script-loader";import{includes as t}from"lodash";import{createRequestSender as n}from"@bigcommerce/request-sender";var i,a,r={};function o(e,t){return Object.assign(e,{resolveIds:t})}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);class s 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 d extends s{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}class c extends s{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}!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"}(i||(i={}));class l extends s{constructor(e){super(function(e){switch(e){case i.MissingBillingAddress:return"Unable to proceed because billing address data is unavailable.";case i.MissingCart:return"Unable to proceed because cart data is unavailable.";case i.MissingConsignments:return"Unable to proceed because consignments data is unavailable.";case i.MissingCheckout:return"Unable to proceed because checkout data is unavailable.";case i.MissingCustomer:return"Unable to proceed because customer data is unavailable.";case i.MissingCheckoutConfig:case i.MissingOrderConfig:return"Unable to proceed because configuration data is unavailable.";case i.MissingOrder:return"Unable to proceed because order data is unavailable.";case i.MissingOrderId:return"Unable to proceed because order ID is unavailable or not generated yet.";case i.MissingPayment:return"Unable to proceed because payment data is unavailable.";case i.MissingPaymentToken:return"Unable to proceed because the token required to submit a payment is missing.";case i.MissingPaymentMethod:return"Unable to proceed because payment method data is unavailable or not properly configured.";case i.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"}}!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"}(a||(a={}));class u extends s{constructor(e){super(function(e){switch(e){case a.CustomerNotInitialized:return"Unable to proceed because the customer step of checkout has not been initialized.";case a.PaymentNotInitialized:return"Unable to proceed because the payment step of checkout has not been initialized.";case a.ShippingNotInitialized:return"Unable to proceed because the shipping step of checkout has not been initialized.";case a.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 h extends s{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}const p={body:{},headers:{},status:0};class m extends s{constructor(e,{message:t,errors:n}={}){const{body:i,headers:a,status:r}=e||p;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=a,this.status=r,this.errors=n||[]}}class y extends m{constructor(e){super(e,{message:"There is a problem processing your payment. Please try again later."}),this.name="PaymentMethodInvalidError",this.type="payment_method_invalid"}}const g=["AT","BE","CA","CH","CZ","DE","DK","ES","FI","FR","GB","GR","IE","IT","NL","NO","NZ","PL","PT","SE"],b=["AU"];var v=function(e,t,n,i){return new(n||(n=Promise))(function(a,r){function o(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}d((i=i.apply(e,t||[])).next())})};class f{constructor(e,t){this.paymentIntegrationService=e,this.klarnaScriptLoader=t}initialize(e){return v(this,void 0,void 0,function*(){this.klarnaCredit=yield this.klarnaScriptLoader.load(),this.unsubscribe=this.paymentIntegrationService.subscribe(t=>{t.isPaymentMethodInitialized({methodId:e.methodId,gatewayId:e.gatewayId})&&this.loadWidget(e)},e=>{const t=e.getCheckout();return t&&t.outstandingBalance},e=>{const t=e.getCheckout();return t&&t.coupons}),yield this.loadWidget(e)})}deinitialize(){return this.unsubscribe&&this.unsubscribe(),Promise.resolve()}execute(e,t){return v(this,void 0,void 0,function*(){if(!e.payment)throw new d('Unable to proceed because "payload.payment" argument is not provided.');const n=e.payment,{paymentData:i}=n,a=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(e);a<i.length;a++)t.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(e,i[a])&&(n[i[a]]=e[i[a]])}return n}(n,["paymentData"]),{authorization_token:r}=yield this.authorize();yield this.paymentIntegrationService.initializePayment(a.methodId,{authorizationToken:r}),yield this.paymentIntegrationService.submitOrder(Object.assign(Object.assign({},e),{payment:a,useStoreCredit:e.useStoreCredit}),t)})}finalize(){return Promise.reject(new c)}loadWidget(e){return v(this,void 0,void 0,function*(){if(!e.klarna)throw new d('Unable to load widget because "options.klarna" argument is not provided.');const{methodId:t,klarna:{container:n,onLoad:r}}=e;return yield this.paymentIntegrationService.loadPaymentMethod(t),new Promise(e=>{const o=this.paymentIntegrationService.getState().getPaymentMethod(t);if(!o)throw new l(i.MissingPaymentMethod);if(!this.klarnaCredit||!o.clientToken)throw new u(a.PaymentNotInitialized);this.klarnaCredit.init({client_token:o.clientToken}),this.klarnaCredit.load({container:n},t=>{r&&r(t),e(t)})})})}getUpdateSessionData(e,n){if(!t([...g,...b],e.countryCode))return{};const i={billing_address:this.mapToKlarnaAddress(e,e.email)};return n&&(i.shipping_address=this.mapToKlarnaAddress(n,e.email)),i}needsStateCode(e){return t(b,e)}mapToKlarnaAddress(e,t){const n={street_address:e.address1,city:e.city,country:e.countryCode,given_name:e.firstName,family_name:e.lastName,postal_code:e.postalCode,region:this.needsStateCode(e.countryCode)?e.stateOrProvinceCode:e.stateOrProvince,email:t};return e.address2&&(n.street_address2=e.address2),e.phone&&(n.phone=e.phone),n}authorize(){return new Promise((e,t)=>{const n=this.paymentIntegrationService.getState(),r=n.getBillingAddress(),o=n.getShippingAddress();if(!r)throw new l(i.MissingBillingAddress);if(!this.klarnaCredit)throw new u(a.PaymentNotInitialized);const s=this.getUpdateSessionData(r,o);this.klarnaCredit.authorize(s,n=>n.approved?e(n):n.show_form?t(new h):void t(new y))})}}class w extends s{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"}}class P{constructor(e,t=window){this.scriptLoader=e,this.klarnaWindow=t}load(){var e,t,n,i,a,r;return n=this,i=void 0,r=function*(){if((null===(e=this.klarnaWindow.Klarna)||void 0===e?void 0:e.Credit)||(yield this.scriptLoader.loadScript("//credit.klarnacdn.net/lib/v1/api.js")),!(null===(t=this.klarnaWindow.Klarna)||void 0===t?void 0:t.Credit))throw new w;return this.klarnaWindow.Klarna.Credit},new((a=void 0)||(a=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(o,s)}d((r=r.apply(n,i||[])).next())})}}const k=o(t=>new f(t,new P(e())),[{id:"klarna"}]);var I=function(e,t,n,i){return new(n||(n=Promise))(function(a,r){function o(e){try{d(i.next(e))}catch(e){r(e)}}function s(e){try{d(i.throw(e))}catch(e){r(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(o,s)}d((i=i.apply(e,t||[])).next())})};class M{constructor(e,t,n){this.paymentIntegrationService=e,this.klarnav2ScriptLoader=t,this.klarnav2TokenUpdater=n}initialize(e){return I(this,void 0,void 0,function*(){this.klarnaPayments=yield this.klarnav2ScriptLoader.load(),this.unsubscribe=this.paymentIntegrationService.subscribe(t=>{t.isPaymentMethodInitialized({methodId:e.methodId,gatewayId:e.gatewayId})&&this.loadPaymentsWidget(e)},e=>{const t=e.getCheckout();return t&&t.outstandingBalance},e=>{const t=e.getCheckout();return t&&t.coupons}),yield this.loadPaymentsWidget(e)})}deinitialize(){return this.unsubscribe&&this.unsubscribe(),Promise.resolve()}execute(e,t){return I(this,void 0,void 0,function*(){if(!e.payment)throw new d('Unable to proceed because "payload.payment" argument is not provided.');const n=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(i=Object.getOwnPropertySymbols(e);a<i.length;a++)t.indexOf(i[a])<0&&Object.prototype.propertyIsEnumerable.call(e,i[a])&&(n[i[a]]=e[i[a]])}return n}(e.payment,[]),{gatewayId:i,methodId:a}=n;if(!i)throw new d('Unable to proceed because "payload.payment.gatewayId" argument is not provided.');const r=this.paymentIntegrationService.getState(),{id:o}=r.getCartOrThrow(),{clientToken:s,initializationData:c}=r.getPaymentMethodOrThrow(a),{klarnaMultipleRadioButton:l}=c||{};yield this.klarnav2TokenUpdater.klarnaOrderInitialization(o,s);const u=this.isKlarnaMultipleRadioButtonEnabled(l,i,a),{authorization_token:h}=yield this.authorizeOrThrow(u,a);yield this.paymentIntegrationService.initializePayment(i,{authorizationToken:h}),yield this.paymentIntegrationService.submitOrder(Object.assign(Object.assign({},e),{payment:n,useStoreCredit:e.useStoreCredit}),t)})}finalize(){return Promise.reject(new c)}loadPaymentsWidget(e){return I(this,void 0,void 0,function*(){if(!e.klarnav2)throw new d('Unable to load widget because "options.klarnav2" argument is not provided.');const{methodId:t,gatewayId:n,klarnav2:{container:r,onLoad:o}}=e;if(!n)throw new d('Unable to proceed because "payload.payment.gatewayId" argument is not provided.');const s=this.paymentIntegrationService.getState(),c={params:s.getCartOrThrow().id};return yield this.klarnav2TokenUpdater.updateClientToken(n,{params:c}).catch(()=>{throw new l(i.MissingPaymentMethod)}),new Promise(e=>{const i=s.getPaymentMethodOrThrow(t),{klarnaMultipleRadioButton:d}=i.initializationData||{};if(!this.klarnaPayments||!i.clientToken)throw new u(a.PaymentNotInitialized);this.klarnaPayments.init({client_token:i.clientToken}),this.klarnaPayments.load({container:r,payment_method_category:this.isKlarnaMultipleRadioButtonEnabled(d,n,t)},t=>{o&&o(t),e(t)})})})}getUpdateSessionData(e,n,i){if(!t([...g,...b],n.countryCode))return{};const a={billing_address:this.mapToKlarnaAddress(e,n,n.email)};return i&&(a.shipping_address=this.mapToKlarnaAddress(e,i,n.email)),a}needsStateCode(e){return t(b,e)}isKlarnaMultipleRadioButtonEnabled(e,t,n){return e?n:t}mapToKlarnaAddress(e,t,n){const i=this.paymentIntegrationService.getState(),{checkoutSettings:a}=i.getStoreConfigOrThrow(),r=i.getPaymentMethodOrThrow(e),{enableBillie:o}=r.initializationData||{},s={street_address:t.address1,city:t.city,country:t.countryCode,given_name:t.firstName,family_name:t.lastName,postal_code:t.postalCode,region:this.needsStateCode(t.countryCode)?t.stateOrProvinceCode:t.stateOrProvince,email:n};return t.address2&&(s.street_address2=t.address2),t.phone&&(s.phone=t.phone),t.company&&o&&function(e,t,n=!0){var i;return null!==(i=e["PI-3915.b2b_payment_session_for_klarna"])&&void 0!==i?i:n}(a.features)&&(s.organization_name=t.company),s}authorizeOrThrow(e,t){return I(this,void 0,void 0,function*(){yield this.paymentIntegrationService.loadCheckout();const n=this.paymentIntegrationService.getState(),i=n.getBillingAddressOrThrow(),r=n.getShippingAddress(),o=this.getUpdateSessionData(t,i,r);return new Promise((t,n)=>{if(!this.klarnaPayments)return n(new u(a.PaymentNotInitialized));this.klarnaPayments.authorize({payment_method_category:e},o,e=>e.approved?t(e):e.show_form?n(new h):void n(new y))})})}}var S;class C{constructor(e,t=window){this.scriptLoader=e,this.klarnaWindow=t}load(){var e,t,n,i,a,r;return n=this,i=void 0,r=function*(){if((null===(e=this.klarnaWindow.Klarna)||void 0===e?void 0:e.Payments)||(yield this.scriptLoader.loadScript("https://x.klarnacdn.net/kp/lib/v1/api.js")),!(null===(t=this.klarnaWindow.Klarna)||void 0===t?void 0:t.Payments))throw new w;return this.klarnaWindow.Klarna.Payments},new((a=void 0)||(a=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(o,s)}d((r=r.apply(n,i||[])).next())})}}!function(e){e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json"}(S||(S={}));const O=S,z="This API endpoint is for internal use only and may change in the future",_={"X-Checkout-SDK-Version":"1.858.0"};class T{constructor(e){this.requestSender=e}updateClientToken(e,{timeout:t,params:n}={}){const i=`/api/storefront/payments/${e}`;return this.requestSender.get(i,{timeout:t,headers:Object.assign({Accept:O.JsonV1,"X-API-INTERNAL":z},_),params:n})}klarnaOrderInitialization(e,t){return n=this,i=void 0,r=function*(){const n={headers:Object.assign({Accept:O.JsonV1,"X-API-INTERNAL":z},_),body:{cartId:e,clientToken:t}};yield this.requestSender.put("/api/storefront/initialization/klarna",n)},new((a=void 0)||(a=Promise))(function(e,t){function o(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 n;t.done?e(t.value):(n=t.value,n instanceof a?n:new a(function(e){e(n)})).then(o,s)}d((r=r.apply(n,i||[])).next())});var n,i,a,r}}const U=o(t=>{const{getHost:i}=t.getState(),a=n({host:i()});return new M(t,new C(e()),new T(a))},[{gateway:"klarna"}]);export{k as createKlarnaPaymentStrategy,U as createKlarnaV2PaymentStrategy};
|
|
2
2
|
//# sourceMappingURL=klarna.js.map
|