@bigcommerce/checkout-sdk 1.983.3 → 1.983.4
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/package.json +9 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getScriptLoader as e}from"@bigcommerce/script-loader";import{find as t,isEmpty as n,isEqual as i,isNil as r,noop as o,omit as a,omitBy as s,some as l}from"lodash";import{supportsPopups as d}from"@braintree/browser-detection";import{createRequestSender as c}from"@bigcommerce/request-sender";import{createFormPoster as u}from"@bigcommerce/form-poster";class h 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 y extends h{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 p=(e=>(e.Sandbox="sandbox",e.Production="production",e))(p||{}),m=(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",e))(m||{}),g=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e))(g||{});const b="3.128.0",v="3.123.2",w="3.106.0",f={[w]:{[m.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[m.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[m.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[m.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[m.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[m.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[m.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[m.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[m.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[m.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[m.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[m.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[v]:{[m.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[m.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[m.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[m.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[m.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[m.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[m.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[m.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[m.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[m.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[m.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[m.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[b]:{[m.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[m.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[m.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[m.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[m.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[m.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[m.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[m.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[m.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[m.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[m.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[m.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var C=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class I{constructor(e,t,n){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=n}loadClient(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.Client,"client.min.js")})}loadFastlane(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.Paypal,"paypal.min.js")})}loadLocalPayment(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.GooglePayment,"google-payment.min.js")})}load3DS(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(m.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(m.Venmo,"venmo.min.js")}loadHostedFields(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return C(this,null,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 y;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return C(this,null,function*(){let n=this.getBraintreeModule(e);if(n)return n;const i=this.braintreeSDKVersionManager.getSDKVersion(),r=`//js.braintreegateway.com/web/${i}/js/${t}`,o=i in f?this.getIntegrityValuesByModuleName(e,i):void 0;if(yield this.scriptLoader.loadScript(r,o?{async:!0,attributes:{integrity:o,crossorigin:"anonymous"}}:void 0),n=this.getBraintreeModule(e),!n)throw new y;return n})}getBraintreeModule(e){var t;return null==(t=this.braintreeHostWindow.braintree)?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const n=f[t][e];if(!n)throw new Error("Unexpected fileName value");return n}}class M extends h{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var S=(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",e))(S||{});class P extends h{constructor(e){super(function(e){switch(e){case 1:return"Unable to proceed because the customer step of checkout has not been initialized.";case 2:return"Unable to proceed because the payment step of checkout has not been initialized.";case 3:return"Unable to proceed because the shipping step of checkout has not been initialized.";case 4: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"}}var O=(e=>(e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED",e))(O||{}),T=(e=>(e.TRUSTLY="trustly",e))(T||{}),N=(e=>(e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized",e))(N||{}),D=(e=>(e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED",e))(D||{}),z=(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",e))(z||{});function E(e){return Boolean("object"==typeof e&&null!==e&&("type"in e||"message"in e||"code"in e))}var k=Object.defineProperty,A=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,x=(e,t,n)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,B=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class _{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return B(this,null,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return B(this,null,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 B(this,null,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),i=((e,t)=>{for(var n in t||(t={}))L.call(t,n)&&x(e,n,t[n]);if(A)for(var n of A(t))j.call(t,n)&&x(e,n,t[n]);return e})({client:t,kount:!0},e);this.dataCollector=yield n.create(i)}catch(e){if(E(e)&&e.code===D.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return B(this,null,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 B(this,null,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 B(this,null,function*(){if(!this.braintreeLocalPayment){const[t,n]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((i,r)=>{n.create({client:t,merchantAccountId:e},(e,t)=>{e&&r(e),i(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return B(this,null,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 B(this,null,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return B(this,null,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 M;this.braintreeVenmo=i}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new P(S.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}function U(e,t,n=!0){var i;return null!=(i=e[t])?i:n}class F{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()||(U(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?b:U(t,"PAYPAL-5636.update_braintree_sdk_version")?v:w)}getPreloadedSDKVersion(){const e=this.braintreeWindow.braintree;if(e){const n=t(Object.values(e),e=>!!e.VERSION);return null==n?void 0:n.VERSION}}}function V(e,t){return Object.assign(e,{resolveIds:t})}class Y extends h{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}var W=(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",e))(W||{});class R extends h{constructor(e){super(function(e){switch(e){case 0:return"Unable to proceed because billing address data is unavailable.";case 1:return"Unable to proceed because cart data is unavailable.";case 3:return"Unable to proceed because consignments data is unavailable.";case 2:return"Unable to proceed because checkout data is unavailable.";case 4:return"Unable to proceed because customer data is unavailable.";case 5:case 7:return"Unable to proceed because configuration data is unavailable.";case 6:return"Unable to proceed because order data is unavailable.";case 8:return"Unable to proceed because order ID is unavailable or not generated yet.";case 9:return"Unable to proceed because payment data is unavailable.";case 15:return"Unable to proceed because the token required to submit a payment is missing.";case 12:return"Unable to proceed because payment method data is unavailable or not properly configured.";case 16: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"}}class H extends Y{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"}}function G(e){return Boolean(e.instrumentId)}class Q extends h{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function Z(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}class q extends h{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"}}function J(e){return!!e&&"accountNumber"in e&&"routingNumber"in e&&"ownershipType"in e&&"accountType"in e}var $=Object.defineProperty,X=Object.defineProperties,K=Object.getOwnPropertyDescriptors,ee=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,ie=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,re=(e,t)=>{for(var n in t||(t={}))te.call(t,n)&&ie(e,n,t[n]);if(ee)for(var n of ee(t))ne.call(t,n)&&ie(e,n,t[n]);return e},oe=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class ae{constructor(e,t){this.paymentIntegrationService=e,this.braintreeSdk=t}initialize(e){return oe(this,null,function*(){const{methodId:t,braintreeach:n}=e||{};if(!t)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');this.getMandateText=null==n?void 0:n.getMandateText,yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{clientToken:r,initializationData:o}=i;if(!r||!o)throw new R(W.MissingPaymentMethod);this.braintreeSdk.initialize(r);try{this.usBankAccount=yield this.braintreeSdk.getUsBankAccount()}catch(e){this.handleBraintreeError(e)}})}execute(e,t){return oe(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)te.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&ee)for(var i of ee(e))t.indexOf(i)<0&&ne.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new H(["payment"]);const o=G(i.paymentData||{}),a=o?yield this.tokenizePaymentForVaultedInstrument(i):yield this.tokenizePayment(i),s=o?yield this.preparePaymentDataForVaultedInstrument(a,i):yield this.preparePaymentData(a,i);yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(s)})}finalize(){return Promise.reject(new Q)}deinitialize(){return oe(this,null,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}tokenizePayment(e){return oe(this,arguments,function*({paymentData:e}){const t=this.getUsBankAccountOrThrow();if(!J(e))throw new H(["payment.paymentData"]);const n=G(e)?"The data are used for stored instrument verification":"function"==typeof this.getMandateText&&this.getMandateText();if(!n)throw new Y("Unable to proceed because getMandateText is not provided or returned undefined value.");try{const{nonce:i}=yield t.tokenize({bankDetails:this.getBankDetails(e),mandateText:n});return i}catch(e){this.handleBraintreeError(e)}})}tokenizePaymentForVaultedInstrument(e){return oe(this,null,function*(){const{methodId:t,paymentData:n={}}=e,i=this.paymentIntegrationService.getState(),{config:r}=i.getPaymentMethodOrThrow(t);if(!r.isVaultingEnabled)throw new Y("Vaulting is disabled but a vaulted instrument was being used for this transaction");return J(n)?this.tokenizePayment(e):null})}preparePaymentData(e,t){return oe(this,null,function*(){const{methodId:n,paymentData:i={}}=t;if(!J(i))throw new H(["payment.paymentData"]);const{deviceData:r}=yield this.braintreeSdk.getDataCollectorOrThrow(),{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,routingNumber:s,accountNumber:l}=i;return{methodId:n,paymentData:{deviceSessionId:r,shouldSetAsDefaultInstrument:a,shouldSaveInstrument:o,formattedPayload:{tokenized_bank_account:{issuer:s,masked_account_number:l.substr(-4),token:e}}}}})}preparePaymentDataForVaultedInstrument(e,t){return oe(this,null,function*(){const{methodId:n,paymentData:i={}}=t;if(!G(i)||!Z(i))throw new H(["payment.paymentData"]);const{deviceData:r}=yield this.braintreeSdk.getDataCollectorOrThrow(),{instrumentId:o,shouldSetAsDefaultInstrument:a}=i;return{methodId:n,paymentData:re({deviceSessionId:r,instrumentId:o,shouldSetAsDefaultInstrument:a},e&&{nonce:e})}})}getBankDetails(e){const t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n=e.ownershipType.toLowerCase(),i=e.accountType.toLowerCase();return r=re({accountNumber:e.accountNumber,routingNumber:e.routingNumber,ownershipType:n},"personal"===n?{firstName:e.firstName,lastName:e.lastName}:{businessName:e.businessName}),o={accountType:i,billingAddress:{streetAddress:t.address1,extendedAddress:t.address2,locality:t.city,region:t.stateOrProvinceCode,postalCode:t.postalCode}},X(r,K(o));var r,o}getUsBankAccountOrThrow(){if(!this.usBankAccount)throw new P(S.PaymentNotInitialized);return this.usBankAccount}handleBraintreeError(e){if(!E(e))throw e;throw new q(e.message)}}const se=V(t=>new ae(t,(t=>{const n=new F(t),i=new I(e(),window,n);return new _(i)})(t)),[{id:"braintreeach"}]);class le extends h{constructor(e,t){super(t||"Unable to proceed because the payment form contains invalid data."),this.details=e,this.name="PaymentInvalidFormError",this.type="payment_invalid_form"}}let de=null;const ce=["buttons","messages"];var ue=(e=>(e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white",e))(ue||{}),he=(e=>(e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit",e))(he||{}),ye=(e=>(e.CART="cart",e.HOME="homepage",e.PAYMENT="payment",e.PRODUCT="product",e))(ye||{}),pe=Object.defineProperty,me=Object.defineProperties,ge=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertySymbols,ve=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable,fe=(e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ce=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&fe(e,n,t[n]);if(be)for(var n of be(t))we.call(t,n)&&fe(e,n,t[n]);return e},Ie=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Me{constructor(e,t,n){this.braintreeScriptLoader=e,this.braintreeHostWindow=t,this.overlay=n,this.dataCollectors={}}initialize(e,t){this.clientToken=e,this.threeDSecureOptions=t}getBraintreeFastlane(e,t,n){return Ie(this,null,function*(){if(t&&(window.localStorage.setItem("axoEnv","sandbox"),window.localStorage.setItem("fastlaneEnv","sandbox")),!this.braintreeHostWindow.braintreeFastlane){const t=this.getClientTokenOrThrow(),i=yield this.getClient(),r=yield this.getSessionId(e),o=yield this.braintreeScriptLoader.loadFastlane(),a={root:{backgroundColorPrimary:"transparent"}};this.braintreeHostWindow.braintreeFastlane=yield o.create({authorization:t,client:i,deviceData:r,styles:n||a})}return this.braintreeHostWindow.braintreeFastlane})}getClient(){return Ie(this,null,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=t.create({authorization:e})}return this.client})}getPaypal(){return this.braintreePaypal||(this.braintreePaypal=Promise.all([this.getClient(),this.braintreeScriptLoader.loadPaypal()]).then(([e,t])=>t.create({client:e}))),this.braintreePaypal}paypal(e){var t=e,{shouldSaveInstrument:n}=t,i=((e,t)=>{var n={};for(var i in e)ve.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&be)for(var i of be(e))t.indexOf(i)<0&&we.call(e,i)&&(n[i]=e[i]);return n})(t,["shouldSaveInstrument"]);const r=d();return this.getPaypal().then(e=>{var t;return r&&(null==(t=this.overlay)||t.show({onClick:()=>e.focusWindow()})),e.tokenize(Ce({enableShippingAddress:!0,flow:n?"vault":"checkout",useraction:"commit"},i))}).then(e=>{var t;return null==(t=this.overlay)||t.remove(),e}).catch(e=>{var t;throw null==(t=this.overlay)||t.remove(),e})}getPaypalCheckout(e,t,n){return Ie(this,null,function*(){const i=yield this.getClient(),r=yield this.braintreeScriptLoader.loadPaypalCheckout(),o={client:i};return this.paypalCheckout=yield r.create(o,(i,r)=>{var o;if(i)return n(i);const a=(s=Ce({currency:e.currency},e.isCreditEnabled&&{"enable-funding":"paylater"}),l={components:ce.toString(),intent:e.intent,commit:null==(o=e.commit)||o},me(s,ge(l)));var s,l;this.braintreeHostWindow.paypal?t(r):function(e,t){return de||(de=new Promise((n,i)=>{e.loadPayPalSDK(t,t=>{t?(de=null,i(t)):n(e)})})),de}(r,a).then(()=>t(r))}),this.paypalCheckout})}getDataCollector(e){return Ie(this,null,function*(){const t=(null==e?void 0:e.paypal)?"paypal":"default";let n=this.dataCollectors[t];if(!n){try{const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadDataCollector(),r=Ce({client:t,kount:!0},e);n=yield i.create(r)}catch(e){if(!E(e)||"DATA_COLLECTOR_KOUNT_NOT_ENABLED"!==e.code)throw e;n={deviceData:void 0,teardown:()=>Promise.resolve()}}this.dataCollectors[t]=n}return n})}getBraintreeEnv(e=!1){return e?p.Sandbox:p.Production}mapToBraintreeShippingAddressOverride(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}mapToLegacyShippingAddress(e){const{email:t,phone:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}mapToLegacyBillingAddress(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}removeElement(e){const t=e&&document.getElementById(e);t&&t.remove()}getSessionId(e){return Ie(this,null,function*(){const{deviceData:t}=yield this.getDataCollector({riskCorrelationId:e});return t})}teardown(){return Ie(this,null,function*(){yield this.teardownModule(this.dataCollectors.default),yield this.teardownModule(this.dataCollectors.paypal),this.dataCollectors={},yield this.teardownModule(this.paypalCheckout),this.paypalCheckout=void 0})}get3DS(){return Ie(this,null,function*(){return this.threeDS||(this.threeDS=Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]).then(([e,t])=>t.create({client:e,version:2}))),this.threeDS})}getVenmoCheckout(e){return Ie(this,null,function*(){if(!this.venmoCheckout){const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadVenmoCheckout(),i=Ce({client:t,allowDesktop:!0,paymentMethodUsage:"multi_use"},e||{});this.venmoCheckout=yield new Promise((e,t)=>{n.create(i,(n,i)=>n?t(n):i.isBrowserSupported()?void e(i):t(new M))})}return this.venmoCheckout})}verifyCard(e,t,n){return Ie(this,null,function*(){const i=yield this.tokenizeCard(e,t);return this.challenge3DSVerification(i,n)})}tokenizeCard(e,t){return Ie(this,null,function*(){const{paymentData:i}=e;if(!function(e){if("object"!=typeof e||null===e)return!1;const t=e;return"object"==typeof t.ccExpiry&&null!==t.ccExpiry&&"string"==typeof t.ccNumber&&"string"==typeof t.ccName}(i))throw new H(["payment.paymentData"]);const r=this.getErrorsRequiredFields(i);if(!n(r))throw new le(r);const o=this.mapToCreditCard(i,t),a=yield this.getClient(),{creditCards:s}=yield a.request(o);return{nonce:s[0].nonce,bin:s[0].details.bin}})}challenge3DSVerification(e,t){return Ie(this,null,function*(){const n=yield this.get3DS();return this.present3DSChallenge(n,t,e)})}teardownModule(e){return e?e.teardown():Promise.resolve()}getClientTokenOrThrow(){if(!this.clientToken)throw new P(S.PaymentNotInitialized);return this.clientToken}getErrorsRequiredFields(e){const{ccNumber:t,ccExpiry:n}=e,i={};return t||(i.ccNumber=[{message:"Credit card number is required",type:"required"}]),n||(i.ccExpiry=[{message:"Expiration date is required",type:"required"}]),i}mapToCreditCard(e,t){return{data:{creditCard:{cardholderName:e.ccName,number:e.ccNumber,cvv:e.ccCvv,expirationDate:`${e.ccExpiry.month}/${e.ccExpiry.year}`,options:{validate:!1},billingAddress:t&&{countryCodeAlpha2:t.countryCode,locality:t.city,countryName:t.country,postalCode:t.postalCode,streetAddress:t.address2?`${t.address1} ${t.address2}`:t.address1}}},endpoint:"payment_methods/credit_cards",method:"post"}}present3DSChallenge(e,t,n){const{nonce:i,bin:r}=n;if(!i)throw new P(S.PaymentNotInitialized);const{challengeRequested:o=!0,additionalInformation:a}=this.threeDSecureOptions||{},s=t.toFixed(2);return e.verifyCard({amount:Number(s),bin:r,challengeRequested:o,nonce:i,onLookupComplete:(e,t)=>{t()},collectDeviceData:!0,additionalInformation:a})}}class Se{constructor(e){this.paymentIntegrationService=e,this.braintreeHostWindow=window}render(e,t,n){const i=t&&document.getElementById(t);if(this.braintreeHostWindow.paypal&&i){const r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow(),a=r.getBillingAddressOrThrow(),s=r.getPaymentMethodOrThrow(e);if(!s.initializationData)return;const{paypalBNPLConfiguration:l=[]}=s.initializationData,d=n===ye.PAYMENT?"checkout":n,c=l&&l.find(({id:e})=>e===d);if(!c||!c.status)return;n===ye.CART&&(i.removeAttribute("data-pp-style-logo-type"),i.removeAttribute("data-pp-style-logo-position"),i.removeAttribute("data-pp-style-text-color"),i.removeAttribute("data-pp-style-text-size")),this.braintreeHostWindow.paypal.Messages({amount:o.cartAmount,buyerCountry:a.countryCode,placement:n,style:this.getPaypalMessagesStylesFromBNPLConfig(c)}).render(`#${t}`)}}getPaypalMessagesStylesFromBNPLConfig({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t}}class Pe{constructor(e){const{element:t,closeElement:n,mainElement:i}=this._createElements(e);this._element=t,this._closeElement=n,this._mainElement=i}show(e){this._mainElement.parentElement||(this._registerClick(e),document.body.appendChild(this._mainElement),setTimeout(()=>this._element.style.opacity="1"))}remove(){this._mainElement.parentElement&&(this._unregisterClick&&this._unregisterClick(),this._removeAfterTransition(),setTimeout(()=>this._element.style.opacity="0"))}_createElements(e){const t=document.createElement("div"),{background:n="rgba(0, 0, 0, 0.8)",id:i="checkoutOverlay",transitionDuration:r=400,hasCloseButton:o=!1,innerHtml:a=null}=e||{};let s,l,d,c,u=t;if(i&&(t.id=i),a){const e=document.createElement("div");c=`${i}--overlayText`,e.className=c,e.appendChild(a),t.appendChild(e)}return o&&(d=`${i}--close`,s=document.createElement("div"),s.className=d,l=`${i}--layout`,u=document.createElement("div"),u.className=l,u.appendChild(t),u.appendChild(s)),u.appendChild(function(e){const{id:t,background:n,transitionDuration:i,classLayout:r,classOverlayText:o,classClose:a}=e,s=document.createElement("style"),l=r?`, .${r}`:"";return s.id=`${t}--styles`,s.type="text/css",s.innerText=`\n #${t}${l} {\n display: block;\n height: 100%;\n width: 100%;\n left: 0;\n top: 0;\n position: fixed;\n z-index: 2147483647;\n }\n #${t} {\n transition: opacity ${i}ms ease-out;\n background: ${n};\n opacity: 0;\n }\n `,o&&(s.innerText+=`\n #${t} {\n display: flex;\n align-items: center;\n justify-content: center;\n }\n #${t} .${o} {\n color: white;\n max-width: 330px;\n font-size: 1.2em;\n text-align: center;\n }\n `),a&&(s.innerText+=`\n #${t} {\n opacity: 1;\n }\n .${r} .${a} {\n position: fixed;\n right: 16px;\n top: 16px;\n width: 16px;\n height: 16px;\n opacity: 0.6;\n cursor: pointer;\n z-index: 3147483647;\n }\n .${r} .${a}::after, .${r} .${a}::before {\n position: absolute;\n left: 8px;\n content: '';\n height: 16px;\n width: 2px;\n background-color: #fff;\n }\n .${r} .${a}::after {\n transform: rotate(-45deg);\n }\n .${r} .${a}::before {\n transform: rotate(45deg);\n }\n `),s}({id:i,background:n,transitionDuration:r,classLayout:l,classOverlayText:c,classClose:d})),{element:t,closeElement:s,mainElement:u}}_addEventListener(e,t){e&&t&&e.addEventListener("click",t)}_removeEventListener(e,t){e&&t&&e.removeEventListener("click",t)}_registerClick(e){if(this._unregisterClick&&this._unregisterClick(),e){const{onClick:t,onClickClose:n}=e;this._addEventListener(this._element,t),this._addEventListener(this._closeElement,n),this._unregisterClick=()=>{this._removeEventListener(this._element,t),this._removeEventListener(this._closeElement,n),this._unregisterClick=void 0}}}_removeAfterTransition(){const e=t=>{"opacity"===t.propertyName&&(this._mainElement.parentElement&&this._mainElement.remove(),this._element.removeEventListener("transitionend",e))};this._element.addEventListener("transitionend",e)}}var Oe=Object.defineProperty,Te=Object.getOwnPropertySymbols,Ne=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable,ze=(e,t,n)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))Ne.call(t,n)&&ze(e,n,t[n]);if(Te)for(var n of Te(t))De.call(t,n)&&ze(e,n,t[n]);return e};const ke={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Ae="embedded-checkout-loading-indicator-rotation";class Le{constructor(e){this.styles=Ee(Ee({},ke),e&&e.styles),this.containerStyles=Ee({},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=`${Ae} 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(Ae))return;const t=document.createElement("style");t.id=Ae,null==(e=document.head)||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${Ae} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}const je={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};function xe(e){const{physicalItems:t=[],digitalItems:n=[],customItems:i=[]}=e.lineItems;return 0===(null==t?void 0:t.length)&&0===(null==i?void 0:i.length)&&(null==n?void 0:n.length)>0}class Be extends h{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}function _e(e){return"object"==typeof e&&null!==e&&"name"in e&&"BraintreeError"===e.name}function Ue(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}var Fe=Object.defineProperty,Ve=Object.defineProperties,Ye=Object.getOwnPropertyDescriptors,We=Object.getOwnPropertySymbols,Re=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,Ge=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qe=(e,t)=>{for(var n in t||(t={}))Re.call(t,n)&&Ge(e,n,t[n]);if(We)for(var n of We(t))He.call(t,n)&&Ge(e,n,t[n]);return e},Ze=(e,t)=>Ve(e,Ye(t)),qe=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Je{constructor(e,t,n,i){this.paymentIntegrationService=e,this.braintreeIntegrationService=t,this.braintreeMessages=n,this.loadingIndicator=i,this.braintreeHostWindow=window}initialize(e){return qe(this,null,function*(){const{braintree:t,methodId:n}=e;if((null==t?void 0:t.containerId)&&(this.braintreeButtonOptions=t),this.paymentMethod&&this.paymentMethod.nonce||(this.paymentMethod=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n)),this.paymentMethod.clientToken&&(null==t?void 0:t.bannerContainerId))return yield this.loadPaypal(),this.loadPaypalCheckoutInstance(t);if(this.paymentMethod.clientToken)return this.loadPaypal();const i=yield this.paymentIntegrationService.loadPaymentMethod(n);if(this.paymentMethod=i.getPaymentMethodOrThrow(n),null==t?void 0:t.bannerContainerId)return this.loadPaypalCheckoutInstance(t);if(!this.paymentMethod.clientToken)throw new R(W.MissingPaymentMethod);return this.loadPaypal()})}execute(e,t){return qe(this,null,function*(){var n;const i=e,{payment:r}=i,o=((e,t)=>{var n={};for(var i in e)Re.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&We)for(var i of We(e))t.indexOf(i)<0&&He.call(e,i)&&(n[i]=e[i]);return n})(i,["payment"]);if(!r)throw new H(["payment"]);const{onError:a}=this.braintreeButtonOptions||{};try{const e=yield this.preparePaymentData(r,o.useStoreCredit);yield this.paymentIntegrationService.submitOrder(o,t),yield this.paymentIntegrationService.submitPayment(e)}catch(e){this.isProviderError(e)&&(yield this.loadPaypal(),null==(n=this.paypalButtonRender)||n.close(),yield this.loadPaypalCheckoutInstance(this.braintreeButtonOptions),yield new Promise((e,t)=>{a&&"function"==typeof a&&a(new Error("INSTRUMENT_DECLINED")),t()})),this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){var e;return this.braintreeTokenizePayload=void 0,null==(e=this.paypalButtonRender)||e.close(),this.braintreeIntegrationService.teardown()}preparePaymentData(e,t){return qe(this,null,function*(){var n;const i=this.paymentIntegrationService.getState(),r=i.getOutstandingBalance(t),o=i.getStoreConfig();if(!r)throw new R(W.MissingCheckout);if(!o)throw new R(W.MissingCheckoutConfig);if(!this.paymentMethod)throw new P(S.PaymentNotInitialized);const{currency:a,storeProfile:{storeLanguage:s}}=o,{nonce:l,config:{isVaultingEnabled:d}}=this.paymentMethod,{methodId:c,paymentData:u={}}=e,h=(null==(n=this.braintreeTokenizePayload)?void 0:n.nonce)||l;if(h){const t=yield this.paymentIntegrationService.loadPaymentMethod(c);return this.paymentMethod=t.getPaymentMethod(c),Ze(Qe({},e),{paymentData:this.formattedPayload(h)})}if(G(u)||(y=u,Boolean(y.instrumentId)&&!Object.prototype.hasOwnProperty.call(y,"ccNumber")&&!Object.prototype.hasOwnProperty.call(y,"ccCvv"))){if(!d)throw new Y("Vaulting is disabled but a vaulted instrument was being used for this transaction");return Promise.resolve(e)}var y;if(!Z(u))throw new R(W.MissingPayment);const{shouldSaveInstrument:p,shouldSetAsDefaultInstrument:m}=u;if(p&&!d)throw new Y("Vaulting is disabled but shouldSaveInstrument is set to true");const g=i.getShippingAddress(),b=g?Ue(g):void 0,v=xe(i.getCartOrThrow());return Promise.all([this.braintreeIntegrationService.paypal({amount:r,locale:s,currency:a.code,offerCredit:"braintreepaypalcredit"===this.paymentMethod.id,shippingAddressOverride:v?void 0:b,enableShippingAddress:!v,shouldSaveInstrument:p||!1,shippingAddressEditable:!1}),this.braintreeIntegrationService.getSessionId()]).then(([{nonce:t,details:n}={},i])=>Ze(Qe({},e),{paymentData:this.formattedPayload(t,n&&n.email,i,p,m)}))})}formattedPayload(e,t,n,i,r){return{formattedPayload:{vault_payment_instrument:i||null,set_as_default_stored_instrument:r||null,device_info:n||null,paypal_account:{token:e,email:t||null}}}}loadPaypalCheckoutInstance(e){return qe(this,null,function*(){const{clientToken:t,initializationData:n,id:i}=this.paymentMethod||{};if(!t)throw new R(W.MissingPaymentMethod);try{this.braintreeIntegrationService.initialize(t);const r={currency:this.paymentIntegrationService.getState().getCartOrThrow().currency.code,intent:null==n?void 0:n.intent,isCreditEnabled:null==n?void 0:n.isCreditEnabled},o="braintreepaypalcredit"===i||!(null==n?void 0:n.isCreditEnabled);yield this.braintreeIntegrationService.getPaypalCheckout(r,t=>{o&&i&&(null==e?void 0:e.bannerContainerId)&&this.renderPayPalMessages(i,e.bannerContainerId),this.renderPayPalButton(t,e)},this.handleError)}catch(e){this.handleError(e)}})}renderPayPalMessages(e,t){this.braintreeMessages.render(e,t,ye.PAYMENT)}renderPayPalButton(e,t){const{onPaymentError:n,submitForm:i,onRenderButton:r,containerId:o,onError:a}=t||{};if(!o)return;const s=this.getSmartButtonContainerId(o);if(!document.getElementById(s))throw new Y(`Unable to initialize payment because element with id ${o} does not exist.`);if(!this.paymentMethod)throw new P(S.PaymentNotInitialized);this.loadingIndicatorContainer=o.split("#")[1];const{id:l,config:{testMode:d}}=this.paymentMethod,{paypal:c}=this.braintreeHostWindow,u=null==c?void 0:c.FUNDING.PAYPAL;c&&u?(this.paypalButtonRender=c.Buttons({env:d?"sandbox":"production",commit:!1,fundingSource:u,onInit:(e,n)=>{var i;null==(i=null==t?void 0:t.onInitButton)||i.call(t,n)},onClick:(e,n)=>{const{resolve:i,reject:r}=n,o=()=>(this.toggleLoadingIndicator(!0),i());return void 0!==(null==t?void 0:t.onValidate)?t.onValidate(o,r):o()},createOrder:()=>this.setupPayment(e,l,n),onApprove:t=>qe(this,null,function*(){this.braintreeTokenizePayload=yield this.tokenizePaymentOrThrow(t,e),i&&"function"==typeof i&&i()}),onCancel:()=>{this.toggleLoadingIndicator(!1)},onError:e=>{this.toggleLoadingIndicator(!1),null==a||a(e)}}),r&&"function"==typeof r&&r(),this.paypalButtonRender.isEligible()&&this.paypalButtonRender.render(`${o}`)):this.removeElement(o.split("#")[1])}setupPayment(e,t,n){return qe(this,null,function*(){const i=this.paymentIntegrationService.getState();try{const n=i.getCustomer(),r=i.getPaymentMethodOrThrow(t),o=i.getCheckoutOrThrow().outstandingBalance,a=i.getStoreConfigOrThrow().currency.code,s=i.getShippingAddress()||(null==n?void 0:n.addresses[0]),l=s?Ue(s):void 0,d=xe(i.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!d,shippingAddressEditable:!1,shippingAddressOverride:d?void 0:l,amount:o,currency:a,offerCredit:!1,intent:r.initializationData.intent})}catch(e){throw n&&(_e(e)||e instanceof h)&&n(e),e}})}tokenizePaymentOrThrow(e,t,n){return qe(this,null,function*(){try{return yield t.tokenizePayment(e)}catch(e){throw n&&(_e(e)||e instanceof h)&&n(e),e}})}loadPaypal(){return qe(this,null,function*(){const{clientToken:e,initializationData:t}=this.paymentMethod||{};if(!e||!t)throw new R(W.MissingPaymentMethod);try{this.braintreeIntegrationService.initialize(e),yield this.braintreeIntegrationService.getPaypal()}catch(e){this.handleError(e)}return Promise.resolve()})}handleError(e){if(!_e(e))throw e;if("PAYPAL_POPUP_CLOSED"===e.code)throw new Be(e.message);throw new q(e.message)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"2046"===(null==(i=null==(n=((null==(t=null==e?void 0:e.errors)?void 0:t.filter(e=>e.provider_error))||[])[0])?void 0:n.provider_error)?void 0:i.code)}removeElement(e){const t=e&&document.getElementById(e);t&&t.remove()}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}getSmartButtonContainerId(e){var t;return null!=(t=e.split("#")[1])?t:e}}const $e=V(t=>{const n=window,i=new Pe,r=new F(t),o=new Me(new I(e(),n,r),n,i),a=new Se(t);return new Je(t,o,a,new Le({containerStyles:je}))},[{id:"braintreepaypal"},{id:"braintreepaypalcredit"}]);var Xe=(e=>(e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json",e))(Xe||{});const Ke=Xe,et={"X-Checkout-SDK-Version":"1.983.3"};var tt=Object.defineProperty,nt=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,ot=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,at=(e,t)=>{for(var n in t||(t={}))it.call(t,n)&&ot(e,n,t[n]);if(nt)for(var n of nt(t))rt.call(t,n)&&ot(e,n,t[n]);return e};class st{constructor(e){this.requestSender=e}getOrderStatus(e="braintreelocalmethods",t){return n=this,i=function*(){const n=`/api/storefront/initialization/${e}`,i=at({"X-API-INTERNAL":"This API endpoint is for internal use only and may change in the future","Content-Type":Ke.Json},et);return(yield this.requestSender.get(n,at({headers:i},t))).body},new Promise((e,t)=>{var r=e=>{try{a(i.next(e))}catch(e){t(e)}},o=e=>{try{a(i.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,o);a((i=i.apply(n,null)).next())});var n,i}}const lt={body:{},headers:{},status:0};class dt extends h{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:o}=e||lt;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}class ct extends dt{constructor(e){super(e,{message:"There is a problem processing your payment. Please try again later."}),this.name="PaymentMethodInvalidError",this.type="payment_method_invalid"}}class ut extends dt{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var ht=Object.defineProperty,yt=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,mt=Object.getOwnPropertySymbols,gt=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable,vt=(e,t,n)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wt=(e,t)=>{for(var n in t||(t={}))gt.call(t,n)&&vt(e,n,t[n]);if(mt)for(var n of mt(t))bt.call(t,n)&&vt(e,n,t[n]);return e},ft=(e,t)=>yt(e,pt(t)),Ct=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class It{constructor(e,t,n,i,r=3e3,a=3e5){this.paymentIntegrationService=e,this.braintreeSdk=t,this.braintreeRequestSender=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=a,this.isLPMsUpdateExperimentEnabled=!1,this.pollingTimer=0,this.stopPolling=o,this.isPollingEnabled=!1}initialize(e){return Ct(this,null,function*(){const{gatewayId:t,methodId:n,braintreelocalmethods:i}=e;if(this.gatewayId=t,!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreelocalmethods" argument is not provided.');this.braintreelocalmethods=i,this.loadingIndicatorContainer=i.container.split("#")[1],yield this.paymentIntegrationService.loadPaymentMethod(t);const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(t),{clientToken:a,config:s,initializationData:l}=o,d=r.getStoreConfigOrThrow().checkoutSettings.features;if(this.isPollingEnabled=U(d,"PAYPAL-5258.braintree_local_methods_polling"),this.isLPMsUpdateExperimentEnabled=U(d,"PAYPAL-4853.add_new_payment_flow_for_braintree_lpms"),!a||!l||!s.merchantId)throw new R(W.MissingPaymentMethod);try{this.braintreeSdk.initialize(a),this.isNonInstantPaymentMethod(n)||(this.braintreeLocalPayment=yield this.braintreeSdk.getBraintreeLocalPayment(s.merchantId))}catch(e){this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return Ct(this,null,function*(){return this.toggleLoadingIndicator(!1),Promise.resolve()})}execute(e,t){return Ct(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)gt.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&mt)for(var i of mt(e))t.indexOf(i)<0&&bt.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new H(["payment"]);const{methodId:o}=i;this.toggleLoadingIndicator(!0),this.isNonInstantPaymentMethod(o)?yield this.executeWithNotInstantLPM(o):yield this.executeWithInstantLPM(o,r,t)})}executeWithNotInstantLPM(e){return Ct(this,null,function*(){try{const t=yield this.getLPMsBasicPaymentData();yield this.paymentIntegrationService.submitOrder(),yield this.paymentIntegrationService.submitPayment({methodId:e,paymentData:ft(wt({},t),{formattedPayload:{method:e}})})}catch(e){if(this.isBraintreeRedirectError(e)){const t=e.body.additional_action_required.data.redirect_url;return new Promise((e,n)=>{window.location.replace(t),this.toggleLoadingIndicator(!1),n()})}return this.handleError(e),Promise.reject(e)}})}executeWithInstantLPM(e,t,n){return Ct(this,null,function*(){if(!this.braintreeLocalPayment)throw new ct;yield new Promise((i,r)=>{var o;null==(o=this.braintreeLocalPayment)||o.startPayment(this.getInstantLPMConfig(e,t,n),this.getInstantLPMCallback(i,r,e,t,n))})})}getLPMsBasicPaymentData(){return Ct(this,null,function*(){const{deviceData:e}=yield this.braintreeSdk.getDataCollectorOrThrow();return{deviceSessionId:e}})}getInstantLPMConfig(e,t,n){const i=this.paymentIntegrationService.getState(),r=i.getCartOrThrow(),o=i.getBillingAddressOrThrow(),{firstName:a,lastName:s,countryCode:l}=o,{currency:d,email:c,lineItems:u}=r,h=u.physicalItems.length>0,y=i.getCheckoutOrThrow().outstandingBalance,p=i.getStoreConfigOrThrow().links.checkoutLink;return{paymentType:e,amount:y,fallback:{url:p,buttonText:"Complete Payment"},currencyCode:d.code,shippingAddressRequired:h,email:c,givenName:a,surname:s,address:{countryCode:l},onPaymentStart:(i,r)=>Ct(this,null,function*(){if(!this.isLPMsUpdateExperimentEnabled)return this.orderId=i.paymentId,void r();const o=yield this.getLPMsBasicPaymentData(),a=ft(wt({},o),{formattedPayload:{method:e,[`${e}_account`]:{order_id:i.paymentId}}});try{yield this.paymentIntegrationService.submitOrder(t,n),yield this.paymentIntegrationService.submitPayment({methodId:e,paymentData:a})}catch(t){if(this.isBraintreeOrderSavedResponse(t)&&t.body.additional_action_required.data.order_id_saved_successfully)return r(),this.isPollingEnabled?new Promise((t,n)=>{this.initializePollingMechanism(e,t,n,this.gatewayId)}):void 0;throw t}})}}getInstantLPMCallback(e,t,n,i,r){const o=this.paymentIntegrationService.getState().getCartOrThrow();return(a,s)=>Ct(this,null,function*(){if(a)return"LOCAL_PAYMENT_WINDOW_CLOSED"===a.code?(this.toggleLoadingIndicator(!1),this.resetPollingMechanism(),t()):(this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t(new ct));const l=yield this.getLPMsBasicPaymentData(),d=ft(wt({},l),{formattedPayload:{method:n,[`${n}_account`]:wt({email:o.email,token:s.nonce},this.isLPMsUpdateExperimentEnabled?{}:{order_id:this.orderId})}});try{return this.isLPMsUpdateExperimentEnabled||(yield this.paymentIntegrationService.submitOrder(i,r)),yield this.paymentIntegrationService.submitPayment({methodId:n,paymentData:d}),e(void 0)}catch(e){return this.handleError(e),t(e)}})}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}handleError(e){const{onError:t}=this.braintreelocalmethods||{};this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}isNonInstantPaymentMethod(e){return e.toUpperCase()in T}isBraintreeRedirectError(e){var t;if("object"!=typeof e||null===e)return!1;const{body:n}=e;return!!n&&!!(null==(t=n.additional_action_required)?void 0:t.data.redirect_url)}isBraintreeOrderSavedResponse(e){var t;if("object"!=typeof e||null===e)return!1;const{body:n}=e;return!!n&&(null==(t=n.additional_action_required)?void 0:t.data.hasOwnProperty("order_id_saved_successfully"))}initializePollingMechanism(e,t,n,i){return Ct(this,null,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.braintreeRequestSender.getOrderStatus(i,{params:{useMetadata:!1}}),o=r.status===O.Pending,a=r.status===O.Completed,s=r.status===O.Failed;if(a)return this.deinitializePollingMechanism(),t();if(s)return n();if(!a&&o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,braintreelocalmethods:this.braintreelocalmethods}),this.handleError(new ut)}catch(e){n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return Ct(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}}const Mt=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i)),o=c(),a=new st(o);return new It(t,r,a,new Le({styles:{backgroundColor:"black"}}))},[{gateway:"braintreelocalmethods"}]);var St=Object.defineProperty,Pt=Object.getOwnPropertySymbols,Ot=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable,Nt=(e,t,n)=>t in e?St(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function Dt(e){return"string"!=typeof e}function zt(e,t){if(t||e)return function(e){var t,n;const i={},r=s(e.root,Dt),o=s(e.input,Dt),a=s(e.toggle,Dt),l=s(null==(t=e.text)?void 0:t.body,Dt),d=s(null==(n=e.text)?void 0:n.caption,Dt),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(o).length&&(i.input=o),Object.keys(a).length&&(i.toggle=a),Object.keys(l).length&&(i.text={},i.text.body=l),Object.keys(d).length&&(i.text=((e,t)=>{for(var n in t||(t={}))Ot.call(t,n)&&Nt(e,n,t[n]);if(Pt)for(var n of Pt(t))Tt.call(t,n)&&Nt(e,n,t[n]);return e})({},i.text),i.text.caption=d),c&&(i.branding=c),i}(function(e,t){var n,i,r,o,a,s,l,d,c,u,h,y,p,m,g,b,v,w,f,C,I,M;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null==(n=null==t?void 0:t.root)?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null==(i=null==t?void 0:t.root)?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null==(r=null==t?void 0:t.root)?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null==(o=null==t?void 0:t.root)?void 0:o.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null==(a=null==t?void 0:t.root)?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null==(s=null==t?void 0:t.root)?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(l=null==t?void 0:t.input)?void 0:l.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null==(d=null==t?void 0:t.input)?void 0:d.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null==(c=null==t?void 0:t.input)?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null==(u=null==t?void 0:t.input)?void 0:u.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null==(h=null==t?void 0:t.input)?void 0:h.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null==(y=null==t?void 0:t.input)?void 0:y.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null==(p=null==t?void 0:t.toggle)?void 0:p.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null==(m=null==t?void 0:t.toggle)?void 0:m.colorSecondary)},text:{body:{color:(null==e?void 0:e.fastlaneTextBodySettingsColor)||(null==(b=null==(g=null==t?void 0:t.text)?void 0:g.body)?void 0:b.color),fontSize:(null==e?void 0:e.fastlaneTextBodySettingsFontSize)||(null==(w=null==(v=null==t?void 0:t.text)?void 0:v.body)?void 0:w.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(C=null==(f=null==t?void 0:t.text)?void 0:f.caption)?void 0:C.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null==(M=null==(I=null==t?void 0:t.text)?void 0:I.caption)?void 0:M.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function Et(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var kt=Object.defineProperty,At=Object.defineProperties,Lt=Object.getOwnPropertyDescriptors,jt=Object.getOwnPropertySymbols,xt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,_t=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ut=(e,t)=>{for(var n in t||(t={}))xt.call(t,n)&&_t(e,n,t[n]);if(jt)for(var n of jt(t))Bt.call(t,n)&&_t(e,n,t[n]);return e},Ft=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Vt{constructor(e,t,n){this.paymentIntegrationService=e,this.braintreeFastlaneUtils=t,this.braintreeSdk=n}initialize(e){return Ft(this,null,function*(){var t;const{methodId:n,braintreefastlane:i}=e;if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreefastlane" argument is not provided.');if(!i.onInit||"function"!=typeof i.onInit)throw new Y('Unable to initialize payment because "options.braintreefastlane.onInit" argument is not provided or it is not a function.');if(!i.onChange||"function"!=typeof i.onChange)throw new Y('Unable to initialize payment because "options.braintreefastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(n);const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(n),{initializationData:a,clientToken:s}=o||{},{isFastlaneStylingEnabled:l}=a||{},d=U(r.getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.braintree_fastlane_three_ds");this.is3DSEnabled=o.config.is3dsEnabled,s&&d&&this.braintreeSdk.initialize(s);const c=zt(l?null==(t=o.initializationData)?void 0:t.fastlaneStyles:void 0,i.styles);yield this.braintreeFastlaneUtils.initializeBraintreeFastlaneOrThrow(n,c),this.shouldRunAuthenticationFlow()&&(yield this.braintreeFastlaneUtils.runPayPalAuthenticationFlowOrThrow(void 0,void 0,i)),yield this.initializeCardComponent(),this.onError=i.onError,i.onInit(e=>this.renderBraintreeCardComponent(e)),i.onChange(()=>this.handleBraintreeStoredInstrumentChange(n))})}execute(e,t){return Ft(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)xt.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&jt)for(var i of jt(e))t.indexOf(i)<0&&Bt.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new H(["payment"]);yield this.paymentIntegrationService.submitOrder(r,t);const o=yield this.preparePaymentPayload(i.methodId);yield this.paymentIntegrationService.submitPayment(o),this.braintreeFastlaneUtils.removeSessionIdFromCookies()})}finalize(){return Promise.reject(new Q)}deinitialize(){return Ft(this,null,function*(){return this.braintreeCardComponent=void 0,Promise.resolve()})}initializeCardComponent(){return Ft(this,null,function*(){const e=this.paymentIntegrationService.getState(),{phone:t,firstName:n,lastName:i}=e.getBillingAddressOrThrow(),r={styles:{},fields:Ut({cardholderName:{prefill:`${n} ${i}`,enabled:!0}},t&&{phoneNumber:{prefill:t}})},o=this.braintreeFastlaneUtils.getBraintreeFastlaneComponentOrThrow();this.braintreeCardComponent=yield o(r)})}renderBraintreeCardComponent(e){const t=this.getBraintreeCardComponentOrThrow();if(!e)throw new Y('Unable to initialize payment because "container" argument is not provided.');t.render(e)}preparePaymentPayload(e){return Ft(this,null,function*(){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getBillingAddressOrThrow(),o=`${r.firstName} ${r.lastName}`,a=this.getPayPalInstruments()[0],s=yield this.braintreeFastlaneUtils.getDeviceSessionId(),l=U(i.getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.braintree_fastlane_three_ds");if(a){const t=this.is3DSEnabled&&l?yield this.get3DS(a.bigpayToken,(null==a?void 0:a.iin)||""):void 0;return{methodId:e,paymentData:{deviceSessionId:s,formattedPayload:{paypal_fastlane_token:{token:t||a.bigpayToken}}}}}const{getPaymentToken:d}=this.getBraintreeCardComponentOrThrow(),c=yield d({name:{fullName:o},billingAddress:this.mapToPayPalAddress(r)}),u=(null==(n=null==(t=c.paymentSource.card)?void 0:t.binDetails)?void 0:n.bin)||"",h=this.is3DSEnabled&&l?yield this.get3DS(c.id,u):void 0;return{methodId:e,paymentData:{deviceSessionId:s,nonce:h||c.id}}})}get3DS(e,t){return Ft(this,null,function*(){const n=this.paymentIntegrationService.getState(),i=yield this.braintreeSdk.getBraintreeThreeDS(),r=n.getOrderOrThrow();return new Promise((n,o)=>{i.verifyCard({amount:null==r?void 0:r.orderAmount,nonce:e,bin:t,onLookupComplete:(e,t)=>{i.on("customer-canceled",()=>{"function"==typeof this.onError&&this.onError(new Be),o(new Be)}),t()}},(e,t)=>(e&&"THREEDS_VERIFY_CARD_CANCELED_BY_MERCHANT"===e.code&&("function"==typeof this.onError&&this.onError(new Be),o(new Be)),n(t.nonce)))})})}mapToPayPalAddress(e){return{streetAddress:(null==e?void 0:e.address1)||"",locality:(null==e?void 0:e.city)||"",region:(null==e?void 0:e.stateOrProvinceCode)||(null==e?void 0:e.stateOrProvince)||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCodeAlpha2:(null==e?void 0:e.countryCode)||""}}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=Et(i)?i:{},o=this.braintreeFastlaneUtils.getSessionIdFromCookies();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===N.CANCELED||(null==r?void 0:r.authenticationState)||o!==t.id)}getBraintreeCardComponentOrThrow(){if(!this.braintreeCardComponent)throw new y;return this.braintreeCardComponent}getPayPalInstruments(){const e=this.paymentIntegrationService.getState().getPaymentProviderCustomerOrThrow();return(Et(e)?e:{}).instruments||[]}handleBraintreeStoredInstrumentChange(e){return Ft(this,null,function*(){const t=this.braintreeFastlaneUtils.getBraintreeFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=Et(t)?t:{},a=this.braintreeFastlaneUtils.mapPayPalToBcInstrument(e,[i]);if(a&&a.length>0)return yield this.paymentIntegrationService.updatePaymentProviderCustomer((r=Ut({},n),o={instruments:[...a]},At(r,Lt(o)))),a[0]}var r,o})}}var Yt=(e=>(e.CVV="cvv",e.PAN="pan",e))(Yt||{}),Wt=Object.defineProperty,Rt=Object.getOwnPropertySymbols,Ht=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable,Qt=(e,t,n)=>t in e?Wt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;class Zt{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:o,domain:a,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}o&&(i+=`; path=${o}`),a&&(i+=`; domain=${a}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){Zt.set(e,"",((e,t)=>{for(var n in t||(t={}))Ht.call(t,n)&&Qt(e,n,t[n]);if(Rt)for(var n of Rt(t))Gt.call(t,n)&&Qt(e,n,t[n]);return e})({expires:new Date(0)},t))}}var qt=Object.defineProperty,Jt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,Xt=Object.getOwnPropertySymbols,Kt=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,tn=(e,t,n)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nn=(e,t)=>{for(var n in t||(t={}))Kt.call(t,n)&&tn(e,n,t[n]);if(Xt)for(var n of Xt(t))en.call(t,n)&&tn(e,n,t[n]);return e},rn=(e,t)=>Jt(e,$t(t)),on=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class an{constructor(e,t){this.paymentIntegrationService=e,this.braintreeIntegrationService=t}getDeviceSessionId(){return on(this,null,function*(){const e=this.paymentIntegrationService.getState().getCart();return this.braintreeIntegrationService.getSessionId(null==e?void 0:e.id)})}initializeBraintreeFastlaneOrThrow(e,t){return on(this,null,function*(){const n=this.paymentIntegrationService.getState(),i=n.getCart(),{clientToken:r,config:o}=n.getPaymentMethodOrThrow(e);if(!r)throw new R(W.MissingPaymentMethod);this.methodId=e,this.braintreeIntegrationService.initialize(r),this.braintreeFastlane=yield this.braintreeIntegrationService.getBraintreeFastlane(null==i?void 0:i.id,o.testMode,t)})}getBraintreeFastlaneOrThrow(){if(!this.braintreeFastlane)throw new y;return this.braintreeFastlane}getBraintreeFastlaneComponentOrThrow(){return this.getBraintreeFastlaneOrThrow().FastlaneCardComponent}runPayPalAuthenticationFlowOrThrow(e,t,n){return on(this,null,function*(){var i;try{const n=this.getMethodIdOrThrow(),r=this.getBraintreeFastlaneOrThrow(),{lookupCustomerByEmail:o,triggerAuthenticationFlow:a}=r.identity,s=this.paymentIntegrationService.getState(),l=s.getCartOrThrow(),d=s.getCustomer(),c=s.getBillingAddress(),{isFastlaneShippingOptionAutoSelectEnabled:u}=s.getPaymentMethodOrThrow(n).initializationData||{},h=e||(null==d?void 0:d.email)||(null==c?void 0:c.email)||"",{customerContextId:y}=yield o(h);if(!y)return yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:N.UNRECOGNIZED,addresses:[],instruments:[]}),void this.saveSessionIdToCookies(l.id);const{authenticationState:p,profileData:m}=yield a(y),g=(null==(i=null==m?void 0:m.shippingAddress)?void 0:i.phoneNumber)||"";if(p===N.CANCELED||!m)return yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:p,addresses:[],instruments:[]}),void this.removeSessionIdFromCookies();const b=this.mapPayPalToBcAddress([m.shippingAddress],[g])||[],v=this.getPayPalBillingAddresses(m),w=v?this.mapPayPalToBcAddress([v],[g]):[],f=m.card?this.mapPayPalToBcInstrument(n,[m.card]):[],C=this.mergeShippingAndBillingAddresses(b,w);if(this.saveSessionIdToCookies(l.id),yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:p,addresses:C,instruments:f}),w.length>0&&l.lineItems.physicalItems.length>0&&(yield this.paymentIntegrationService.updateBillingAddress(w[0])),w.length>0&&l.lineItems.digitalItems.length>0&&0===l.lineItems.physicalItems.length){const{firstName:e,lastName:t}=C[0],n=rn(nn({},w[0]),{firstName:e,lastName:t});yield this.paymentIntegrationService.updateBillingAddress(n)}b.length>0&&l.lineItems.physicalItems.length>0&&(yield this.paymentIntegrationService.updateShippingAddress(b[0]),t&&u&&(yield this.setShippingOption()))}catch(e){this.handleErrorLog(e,n)}})}getSessionIdFromCookies(){return Zt.get("bc-fastlane-sessionId")||""}saveSessionIdToCookies(e){const t=new Date;t.setDate(t.getDate()+14),Zt.set("bc-fastlane-sessionId",e,{expires:t,secure:!0})}removeSessionIdFromCookies(){Zt.remove("bc-fastlane-sessionId")}mapPayPalToBcInstrument(e,t){if(t)return t.map(t=>{const{id:n,paymentSource:i}=t,{brand:r,expiry:o,lastDigits:a,binDetails:s}=i.card,[l,d]=o.split("-");return{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:d,expiryYear:l,iin:(null==s?void 0:s.bin)||"",last4:a,method:e,provider:e,trustedShippingAddress:!1,type:"card",untrustedShippingCardVerificationMode:Yt.PAN}})}mapPayPalToBcAddress(e,t){if(!e)return[];const n=this.paymentIntegrationService.getState().getCountries()||[],i=e=>{const t=n.find(t=>t.code===e);return(null==t?void 0:t.name)||""};return e.map(e=>({id:Date.now(),type:"paypal-address",firstName:e.firstName||"",lastName:e.lastName||"",company:e.company||"",address1:e.streetAddress,address2:e.extendedAddress||"",city:e.locality,stateOrProvince:e.region,stateOrProvinceCode:e.region,country:i(e.countryCodeAlpha2),countryCode:e.countryCodeAlpha2,postalCode:e.postalCode,phone:t&&t[0]||"",customFields:[]}))}getPayPalBillingAddresses(e){const{card:t,name:n}=e||{};if(!t)return;const{firstName:r,lastName:o}=t.paymentSource.card.billingAddress,{firstName:a,lastName:s}=n||{},{shippingAddress:l}=e||{},d=rn(nn({},t.paymentSource.card.billingAddress),{firstName:r||a,lastName:o||s});return l&&i(this.normalizeAddress(d),this.normalizeAddress(l))?l:d}normalizeAddress(e){return a(e,["id"])}mergeShippingAndBillingAddresses(e,t){const n=t.filter(t=>!e.some(e=>i(this.normalizeAddress(e),this.normalizeAddress(t))));return[...e,...n]}getMethodIdOrThrow(){if(!this.methodId)throw new Y('Unable to proceed because "methodId" argument is not provided.');return this.methodId}setShippingOption(){return on(this,null,function*(){var e;const t=(null==(e=(this.paymentIntegrationService.getState().getConsignments()||[])[0])?void 0:e.availableShippingOptions)||[],n=t.find(e=>e.isRecommended);if(n||t.length){const e=n||t[0];yield this.paymentIntegrationService.selectShippingOption(e.id)}})}handleErrorLog(e,t){(null==t?void 0:t.onErrorLog)&&"function"==typeof t.onErrorLog&&t.onErrorLog(e)}}const sn=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n),o=new an(t,r),a=new I(e(),n,i),s=new _(a);return new Vt(t,o,s)},[{id:"braintreeacceleratedcheckout"}]);var ln=Object.defineProperty,dn=Object.defineProperties,cn=Object.getOwnPropertyDescriptors,un=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,pn=(e,t,n)=>t in e?ln(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mn=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&pn(e,n,t[n]);if(un)for(var n of un(t))yn.call(t,n)&&pn(e,n,t[n]);return e},gn=(e,t)=>dn(e,cn(t)),bn=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class vn{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n}initialize(e){return bn(this,null,function*(){const{braintreevisacheckout:t,methodId:n}=e;if(!t)throw new Y('Unable to initialize payment because "options.braintreevisacheckout" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState();this.paymentMethod=i.getPaymentMethodOrThrow(n);const r=i.getCheckoutOrThrow(),a=i.getStoreConfigOrThrow(),{clientToken:s,config:l}=this.paymentMethod||{};if(!s)throw new R(W.MissingPaymentMethod);const{onError:d=o,onPaymentSelect:c=o}=t;this.braintreeSdk.initialize(s);const u=yield this.braintreeSdk.getBraintreeVisaCheckout(),h=yield this.braintreeSdk.getVisaCheckoutSdk(null==l?void 0:l.testMode),y=u.createInitOptions({settings:{locale:a.storeProfile.storeLanguage,shipping:{collectShipping:!1}},paymentRequest:{currencyCode:a.currency.code,subtotal:String(r.subtotal)}});yield h.init(y),h.on("payment.success",e=>this.tokenizePayment(u,e).then(()=>Promise.all([this.paymentIntegrationService.loadCheckout(),this.paymentIntegrationService.loadPaymentMethod(n)])).then(()=>c()).catch(e=>d(e))),h.on("payment.error",(e,t)=>d(t))})}execute(e,t){return bn(this,null,function*(){var n,i;const r=e,{payment:o}=r,a=((e,t)=>{var n={};for(var i in e)hn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&un)for(var i of un(e))t.indexOf(i)<0&&yn.call(e,i)&&(n[i]=e[i]);return n})(r,["payment"]);if(!o)throw new Y('Unable to submit payment because "payload.payment" argument is not provided.');if(!(null==(i=null==(n=this.paymentMethod)?void 0:n.initializationData)?void 0:i.nonce))throw new R(W.MissingPaymentMethod);const{nonce:s}=this.paymentMethod.initializationData;try{yield this.paymentIntegrationService.submitOrder(a,t),yield this.paymentIntegrationService.submitPayment(gn(mn({},o),{paymentData:{nonce:s}}))}catch(e){this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return bn(this,null,function*(){yield this.braintreeSdk.deinitialize()})}tokenizePayment(e,t){return bn(this,null,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.mapToVisaCheckoutAddress(i),billingAddress:a=this.mapToVisaCheckoutAddress(r)}=e;return this.postForm(gn(mn({},e),{shippingAddress:o,billingAddress:a}),t)})})}mapToVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}handleError(e){if(e instanceof Error&&"BraintreeError"===e.name)throw new q(e.message);throw e}}const wn=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i));return new vn(t,u(),r)},[{id:"braintreevisacheckout"}]);var fn=Object.defineProperty,Cn=Object.defineProperties,In=Object.getOwnPropertyDescriptors,Mn=Object.getOwnPropertySymbols,Sn=Object.prototype.hasOwnProperty,Pn=Object.prototype.propertyIsEnumerable,On=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tn=(e,t)=>{for(var n in t||(t={}))Sn.call(t,n)&&On(e,n,t[n]);if(Mn)for(var n of Mn(t))Pn.call(t,n)&&On(e,n,t[n]);return e},Nn=(e,t)=>Cn(e,In(t)),Dn=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class zn{constructor(e,t){this.paymentIntegrationService=e,this.braintreeIntegrationService=t}initialize(e){return Dn(this,null,function*(){const{methodId:t}=e;yield this.paymentIntegrationService.loadPaymentMethod(t);const n=this.paymentIntegrationService.getState();this.venmoOptions=e.braintreevenmo;const i=n.getPaymentMethodOrThrow(t);yield this.initializeBraintreeVenmo(i)})}execute(e){return Dn(this,null,function*(){const t=e,{payment:n}=t,i=((e,t)=>{var n={};for(var i in e)Sn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Mn)for(var i of Mn(e))t.indexOf(i)<0&&Pn.call(e,i)&&(n[i]=e[i]);return n})(t,["payment"]);if(!n)throw new H(["payment"]);try{const e=yield this.preparePaymentData(n);yield this.paymentIntegrationService.submitOrder(i),yield this.paymentIntegrationService.submitPayment(e)}catch(e){this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return Dn(this,null,function*(){return yield this.braintreeIntegrationService.teardown(),Promise.resolve()})}handleError(e){if(!E(e))throw e;if("PAYPAL_POPUP_CLOSED"===e.code)throw new Be(e.message);throw new q(e.message)}initializeBraintreeVenmo(e){return Dn(this,null,function*(){var t;const{clientToken:n}=e;if(!n)throw new R(W.MissingPaymentMethod);const i=U(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PAYPAL-5406.braintree_venmo_web_fallback_support");try{this.braintreeIntegrationService.initialize(n),this.braintreeVenmoCheckout=yield this.braintreeIntegrationService.getVenmoCheckout(Tn(Tn({},void 0!==(null==(t=this.venmoOptions)?void 0:t.allowDesktop)?{allowDesktop:this.venmoOptions.allowDesktop}:{}),i?{mobileWebFallBack:i}:{}))}catch(e){this.handleError(e)}})}preparePaymentData(e){return Dn(this,null,function*(){const t=this.paymentIntegrationService.getState(),{nonce:n}=t.getPaymentMethodOrThrow(e.methodId);if(n)return Nn(Tn({},e),{paymentData:this.formattedPayload(n)});const i=yield this.braintreeVenmoTokenize(),r=yield this.braintreeIntegrationService.getSessionId();return Nn(Tn({},e),{paymentData:this.formattedPayload(i.nonce,i.details.email,r)})})}formattedPayload(e,t,n){return{formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:n||null,paypal_account:{token:e,email:t||null}}}}braintreeVenmoTokenize(){return new Promise((e,t)=>{var n;null==(n=this.braintreeVenmoCheckout)||n.tokenize((n,i)=>{if(n)return t(n);e(i)})})}}const En=V(t=>{const n=window,i=e(),r=new F(t),o=new I(i,n,r),a=new Me(o,n);return new zn(t,a)},[{id:"braintreevenmo"}]);function kn(e){return"cardNumber"in e}function An(e){if(!E(e))return!1;const{details:t}=e;return void 0===t||"object"==typeof t&&null!==t&&void 0===t.invalidFieldKeys||(n=t,Array.isArray(n)&&n.every(e=>"string"==typeof e));var n}var Ln=Object.defineProperty,jn=Object.defineProperties,xn=Object.getOwnPropertyDescriptors,Bn=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Un=Object.prototype.propertyIsEnumerable,Fn=(e,t,n)=>t in e?Ln(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vn=(e,t)=>{for(var n in t||(t={}))_n.call(t,n)&&Fn(e,n,t[n]);if(Bn)for(var n of Bn(t))Un.call(t,n)&&Fn(e,n,t[n]);return e},Yn=(e,t)=>jn(e,xn(t)),Wn=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Rn{constructor(e,t){this.braintreeScriptLoader=e,this.braintreeSDKVersionManager=t,this.isInitializedHostedForm=!1,this.handleBlur=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onBlur)||n.call(t,{fieldType:this.mapFieldType(e.emittedBy),errors:this.mapErrors(e.fields)})},this.handleFocus=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onFocus)||n.call(t,{fieldType:this.mapFieldType(e.emittedBy)})},this.handleCardTypeChange=e=>{var t,n;const i=1===e.cards.length?e.cards[0].type.replace(/^master-card$/,"mastercard"):void 0;null==(n=null==(t=this.formOptions)?void 0:t.onCardTypeChange)||n.call(t,{cardType:i})},this.handleInputSubmitRequest=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onEnter)||n.call(t,{fieldType:this.mapFieldType(e.emittedBy)})},this.handleValidityChange=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onValidate)||n.call(t,{isValid:this.isValidForm(e),errors:this.mapValidationErrors(e.fields)})}}initialize(e,t,i){return Wn(this,null,function*(){var r,o,a,s,l;this.clientToken=i,this.formOptions=e,this.type=kn(e.fields)?0:1;const d=this.mapFieldOptions(e.fields,t);n(d)?this.isInitializedHostedForm=!1:(this.cardFields=yield this.createHostedFields({fields:d,styles:e.styles&&this.mapStyleOptions(e.styles)}),null==(r=this.cardFields)||r.on("blur",this.handleBlur),null==(o=this.cardFields)||o.on("focus",this.handleFocus),null==(a=this.cardFields)||a.on("cardTypeChange",this.handleCardTypeChange),null==(s=this.cardFields)||s.on("validityChange",this.handleValidityChange),null==(l=this.cardFields)||l.on("inputSubmitRequest",this.handleInputSubmitRequest),this.isInitializedHostedForm=!0)})}isInitialized(){return!!this.isInitializedHostedForm}deinitialize(){return Wn(this,null,function*(){var e;this.isInitializedHostedForm&&(this.isInitializedHostedForm=!1,yield null==(e=this.cardFields)?void 0:e.teardown())})}validate(){if(!this.cardFields)throw new P(S.PaymentNotInitialized);const e=this.cardFields.getState();if(!this.isValidForm(e)){this.handleValidityChange(e);const t=this.mapValidationErrors(e.fields);throw new le(t)}}tokenize(e){return Wn(this,null,function*(){var t,n,i,o,a;if(!this.cardFields)throw new P(S.PaymentNotInitialized);try{const o=yield this.cardFields.tokenize(s({billingAddress:e&&this.mapBillingAddress(e)},r));return null==(n=null==(t=this.formOptions)?void 0:t.onValidate)||n.call(t,{isValid:!0,errors:{}}),{nonce:o.nonce,bin:null==(i=o.details)?void 0:i.bin}}catch(e){if(An(e)){const t=this.mapTokenizeError(e);if(t)throw null==(a=null==(o=this.formOptions)?void 0:o.onValidate)||a.call(o,{isValid:!1,errors:t}),new le(t)}throw e}})}tokenizeForStoredCardVerification(){return Wn(this,null,function*(){var e,t,n,i,r;if(!this.cardFields)throw new P(S.PaymentNotInitialized);try{const i=yield this.cardFields.tokenize();return null==(t=null==(e=this.formOptions)?void 0:e.onValidate)||t.call(e,{isValid:!0,errors:{}}),{nonce:i.nonce,bin:null==(n=i.details)?void 0:n.bin}}catch(e){if(An(e)){const t=this.mapTokenizeError(e,!0);if(t)throw null==(r=null==(i=this.formOptions)?void 0:i.onValidate)||r.call(i,{isValid:!1,errors:t}),new le(t)}throw e}})}createHostedFields(e){return Wn(this,null,function*(){const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadHostedFields(),i=this.braintreeSDKVersionManager.getSDKVersion()===b?Yn(Vn({},e),{preventCursorJumps:!0}):e;return n.create(Yn(Vn({},i),{client:t}))})}getClient(){return Wn(this,null,function*(){if(!this.clientToken)throw new P(S.PaymentNotInitialized);if(!this.client){const e=yield this.braintreeScriptLoader.loadClient();this.client=e.create({authorization:this.clientToken})}return this.client})}mapBillingAddress(e){return{countryName:e.country,postalCode:e.postalCode,streetAddress:e.address2?`${e.address1} ${e.address2}`:e.address1}}mapFieldOptions(e,t){if(kn(e)){const n={};return null==t||t.forEach(e=>{(e=>Object.values(z).includes(e))(e)&&(n[e]=!1)}),s({number:Vn({container:`#${e.cardNumber.containerId}`,placeholder:e.cardNumber.placeholder,internalLabel:e.cardNumber.accessibilityLabel},Object.keys(n).length>0?{supportedCardBrands:n}:{}),expirationDate:{container:`#${e.cardExpiry.containerId}`,placeholder:e.cardExpiry.placeholder,internalLabel:e.cardExpiry.accessibilityLabel},cvv:e.cardCode&&{container:`#${e.cardCode.containerId}`,placeholder:e.cardCode.placeholder,internalLabel:e.cardCode.accessibilityLabel},cardholderName:{container:`#${e.cardName.containerId}`,placeholder:e.cardName.placeholder,internalLabel:e.cardName.accessibilityLabel}},r)}return s({number:e.cardNumberVerification&&{container:`#${e.cardNumberVerification.containerId}`,placeholder:e.cardNumberVerification.placeholder},cvv:e.cardCodeVerification&&{container:`#${e.cardCodeVerification.containerId}`,placeholder:e.cardCodeVerification.placeholder}},r)}mapStyleOptions(e){const t=(e={})=>s({color:e.color,"font-family":e.fontFamily,"font-size":e.fontSize,"font-weight":e.fontWeight},r);return{input:t(e.default),".invalid":t(e.error),":focus":t(e.focus)}}mapFieldType(e){switch(e){case"number":return 1===this.type?g.CardNumberVerification:g.CardNumber;case"expirationDate":return g.CardExpiry;case"cvv":return 1===this.type?g.CardCodeVerification:g.CardCode;case"cardholderName":return g.CardName;default:throw new Error("Unexpected field type")}}mapErrors(e){const t={};if(e)for(const[n,i]of Object.entries(e))if(i&&this.isValidParam(n)){const{isValid:e,isEmpty:r,isPotentiallyValid:o}=i;t[n]={isValid:e,isEmpty:r,isPotentiallyValid:o}}return t}mapValidationErrors(e){return Object.keys(e).reduce((t,n)=>{var i;return Yn(Vn({},t),{[this.mapFieldType(n)]:(null==(i=e[n])?void 0:i.isValid)?void 0:[this.createInvalidError(this.mapFieldType(n))]})},{})}mapTokenizeError(e,t=!1){var n,i;if("HOSTED_FIELDS_FIELDS_EMPTY"===e.code){const e=[this.createRequiredError(this.mapFieldType("cvv"))];return t?{[this.mapFieldType("cvv")]:e}:{[this.mapFieldType("cvv")]:e,[this.mapFieldType("expirationDate")]:[this.createRequiredError(this.mapFieldType("expirationDate"))],[this.mapFieldType("number")]:[this.createRequiredError(this.mapFieldType("number"))],[this.mapFieldType("cardholderName")]:[this.createRequiredError(this.mapFieldType("cardholderName"))]}}return null==(i=null==(n=e.details)?void 0:n.invalidFieldKeys)?void 0:i.reduce((e,t)=>{const n=this.mapFieldType(t);return Yn(Vn({},e),{[n]:[this.createInvalidError(n)]})},{})}createRequiredError(e){var t;return{fieldType:e,message:null!=(t={[g.CardCode]:"CVV is required",[g.CardCodeVerification]:"CVV is required",[g.CardNumber]:"Credit card number is required",[g.CardNumberVerification]:"Credit card number is required",[g.CardExpiry]:"Expiration date is required",[g.CardName]:"Full name is required"}[e])?t:"Field is required",type:"required"}}createInvalidError(e){var t,n,i,r;const o={[g.CardCode]:{message:"Invalid card code",type:"invalid_card_code"},[g.CardCodeVerification]:{message:"Invalid card code",type:"invalid_card_code"},[g.CardNumber]:{message:"Invalid card number",type:"invalid_card_number"},[g.CardNumberVerification]:{message:"Invalid card number",type:"invalid_card_number"},[g.CardExpiry]:{message:"Invalid card expiry",type:"invalid_card_expiry"},[g.CardName]:{message:"Invalid card name",type:"invalid_card_name"}};return{fieldType:e,message:null!=(n=null==(t=o[e])?void 0:t.message)?n:"Invalid field",type:null!=(r=null==(i=o[e])?void 0:i.type)?r:"invalid"}}isValidForm(e){return Object.keys(e.fields).every(t=>{var n;return null==(n=e.fields[t])?void 0:n.isValid})}isValidParam(e){return["number","cvv","expirationDate","postalCode","cardholderName","cardType"].includes(e)}}var Hn=Object.defineProperty,Gn=Object.defineProperties,Qn=Object.getOwnPropertyDescriptors,Zn=Object.getOwnPropertySymbols,qn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,$n=(e,t,n)=>t in e?Hn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xn=(e,t)=>{for(var n in t||(t={}))qn.call(t,n)&&$n(e,n,t[n]);if(Zn)for(var n of Zn(t))Jn.call(t,n)&&$n(e,n,t[n]);return e},Kn=(e,t)=>Gn(e,Qn(t)),ei=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class ti{constructor(e,t,n){this.paymentIntegrationService=e,this.braintreeIntegrationService=t,this.braintreeHostedForm=n}initialize(e){return ei(this,null,function*(){const{methodId:t,gatewayId:n,braintree:i}=e;yield this.paymentIntegrationService.loadPaymentMethod(t);const r=this.paymentIntegrationService.getState();this.paymentMethod=r.getPaymentMethodOrThrow(t);const{clientToken:o}=this.paymentMethod;if(!o)throw new R(W.MissingPaymentMethod);this.threeDSecure=null==i?void 0:i.threeDSecure,this.onPaymentError=null==i?void 0:i.onPaymentError;try{this.braintreeIntegrationService.initialize(o,this.threeDSecure),this.isHostedPaymentFormEnabled(t,n)&&(null==i?void 0:i.form)&&(yield this.braintreeHostedForm.initialize(i.form,i.unsupportedCardBrands,o),this.isHostedFormInitialized=this.braintreeHostedForm.isInitialized()),this.is3dsEnabled=this.paymentMethod.config.is3dsEnabled,this.deviceSessionId=yield this.braintreeIntegrationService.getSessionId(),this.shouldInitializeBraintreeFastlane()&&(yield this.initializeBraintreeFastlaneOrThrow(t))}catch(e){return this.handleError(e,t)}})}execute(e){return ei(this,null,function*(){const t=e,{payment:n}=t,i=((e,t)=>{var n={};for(var i in e)qn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Zn)for(var i of Zn(e))t.indexOf(i)<0&&Jn.call(e,i)&&(n[i]=e[i]);return n})(t,["payment"]);if(!n)throw new H(["payment"]);this.isHostedFormInitialized&&this.braintreeHostedForm.validate(),yield this.paymentIntegrationService.submitOrder(i);const r=this.paymentIntegrationService.getState(),o=r.getBillingAddressOrThrow(),a=r.getOrderOrThrow().orderAmount;try{const e=this.isHostedFormInitialized?yield this.prepareHostedPaymentData(n,o,a):yield this.preparePaymentData(n,o,a);yield this.paymentIntegrationService.submitPayment(Kn(Xn({},n),{paymentData:e}))}catch(e){return this.processAdditionalAction(e,n,a)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return ei(this,null,function*(){return this.isHostedFormInitialized=!1,yield Promise.all([this.braintreeIntegrationService.teardown(),this.braintreeHostedForm.deinitialize()]),Promise.resolve()})}handleError(e,t){var n;if(_e(e)){if(!(t&&this.paymentIntegrationService.getState().isPaymentMethodInitialized({methodId:t})||"HOSTED_FIELDS_INVALID_FIELD_SELECTOR"!==e.code))return;if(e.code.startsWith("THREEDS_"))return null==(n=this.onPaymentError)||n.call(this,new q("THREEDS_VERIFICATION_FAILED")),Promise.reject();throw new q(e.message)}throw e}preparePaymentData(e,t,n){return ei(this,null,function*(){const{paymentData:i}=e,r={deviceSessionId:this.deviceSessionId};if(this.isSubmittingWithStoredCard(e))return Xn(Xn({},r),i);const{shouldSaveInstrument:o=!1,shouldSetAsDefaultInstrument:a=!1}=Z(i)?i:{},{nonce:s}=this.shouldPerform3DSVerification(e)?yield this.braintreeIntegrationService.verifyCard(e,t,n):yield this.braintreeIntegrationService.tokenizeCard(e,t);return Kn(Xn({},r),{nonce:s,shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a})})}prepareHostedPaymentData(e,t,n){return ei(this,null,function*(){const{paymentData:i}=e,r={deviceSessionId:this.deviceSessionId};if(this.isSubmittingWithStoredCard(e)){const{nonce:e}=yield this.braintreeHostedForm.tokenizeForStoredCardVerification();return Kn(Xn(Xn({},r),i),{nonce:e})}const{shouldSaveInstrument:o=!1,shouldSetAsDefaultInstrument:a=!1}=Z(i)?i:{},{nonce:s}=this.shouldPerform3DSVerification(e)?yield this.verifyCardWithHostedForm(t,n):yield this.braintreeHostedForm.tokenize(t);return Kn(Xn({},r),{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,nonce:s})})}prepareAdditionalActionPaymentData(e,t){const{paymentData:n}=e,i={deviceSessionId:this.deviceSessionId,nonce:t},{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:o=!1}=Z(n)?n:{};return this.isSubmittingWithStoredCard(e)&&(r||o)?Xn(Xn({},n),i):Xn({},i)}verifyCardWithHostedForm(e,t){return ei(this,null,function*(){const n=yield this.braintreeHostedForm.tokenize(e);return this.braintreeIntegrationService.challenge3DSVerification(n,t)})}processAdditionalAction(e,t,n){return ei(this,null,function*(){if(!(e=>"object"==typeof e&&null!==e&&"body"in e)(e)||!l(e.body.errors,{code:"three_d_secure_required"}))return this.handleError(e);try{const{payer_auth_request:i}=function(e){return"object"==typeof e&&null!==e&&"name"in e&&"body"in e&&"status"in e.body&&"three_ds_result"in e.body&&"payer_auth_request"in e.body.three_ds_result&&"errors"in e.body}(e)&&e.body.three_ds_result||{},{paymentData:r}=t,o=this.paymentIntegrationService.getState();if(!r||!G(r))throw new H(["instrumentId"]);const a=o.getCardInstrumentOrThrow(r.instrumentId),{nonce:s}=yield this.braintreeIntegrationService.challenge3DSVerification({nonce:i||"",bin:a.iin},n),l=this.prepareAdditionalActionPaymentData(t,s);yield this.paymentIntegrationService.submitPayment(Kn(Xn({},t),{paymentData:l}))}catch(e){return this.handleError(e)}})}isHostedPaymentFormEnabled(e,t){return!!e&&!0===this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t).config.isHostedFormEnabled}isSubmittingWithStoredCard(e){return!(!e.paymentData||!G(e.paymentData))}shouldPerform3DSVerification(e){return!(!this.is3dsEnabled||this.isSubmittingWithStoredCard(e))}shouldInitializeBraintreeFastlane(){var e;const t=this.paymentIntegrationService.getState().getPaymentProviderCustomerOrThrow(),n=Et(t)?t:{};return(null==(e=this.paymentMethod)?void 0:e.initializationData.isAcceleratedCheckoutEnabled)&&!(null==n?void 0:n.authenticationState)}initializeBraintreeFastlaneOrThrow(e){return ei(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{clientToken:r,config:o}=i;if(!r)throw new R(W.MissingPaymentMethod);this.braintreeIntegrationService.initialize(r,this.threeDSecure),yield this.braintreeIntegrationService.getBraintreeFastlane(n.id,o.testMode)})}}const ni=V(t=>{const n=window,i=new F(t),r=new I(e(),n,i),o=new Me(r,n),a=new Rn(r,i);return new ti(t,o,a)},[{id:"braintree"}]);var ii=Object.defineProperty,ri=Object.defineProperties,oi=Object.getOwnPropertyDescriptors,ai=Object.getOwnPropertySymbols,si=Object.prototype.hasOwnProperty,li=Object.prototype.propertyIsEnumerable,di=(e,t,n)=>t in e?ii(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ci=(e,t)=>{for(var n in t||(t={}))si.call(t,n)&&di(e,n,t[n]);if(ai)for(var n of ai(t))li.call(t,n)&&di(e,n,t[n]);return e},ui=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class hi{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return ui(this,null,function*(){const{braintreepaypal:t,methodId:n}=e,{container:i,onError:r}=t||{};if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreepaypal.container" argument is not provided.');let o,a=this.paymentIntegrationService.getState();try{if(o=a.getPaymentMethodOrThrow(n),!o.clientToken)throw new R(W.MissingPaymentToken)}catch(e){a=yield this.paymentIntegrationService.loadPaymentMethod(n),o=a.getPaymentMethodOrThrow(n)}const{clientToken:s,config:l,initializationData:d}=o,{paymentButtonStyles:c}=d||{},{checkoutTopButtonStyles:u}=c||{};if(!s||!d)throw new R(W.MissingPaymentMethod);const h={currency:a.getCartOrThrow().currency.code,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{this.renderPayPalButton(e,t,n,Boolean(l.testMode),u)},e=>this.handleError(e,i,r))})}deinitialize(){return ui(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}signIn(e,t){return ui(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return ui(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderPayPalButton(e,t,n,i,r){const{container:a,onClick:s=o}=t,{paypal:l}=this.braintreeHostWindow,d=null==l?void 0:l.FUNDING.PAYPAL;if(l&&d){const o=l.Buttons({env:this.braintreeIntegrationService.getBraintreeEnv(i),fundingSource:d,style:(c=ci({},r),u={height:40},ri(c,oi(u))),createOrder:()=>this.setupPayment(e,t,n),onApprove:i=>this.tokenizePayment(i,e,n,t),onClick:s});o.isEligible()&&o.render(`#${a}`)}else this.braintreeIntegrationService.removeElement(a);var c,u}setupPayment(e,t,n){return ui(this,null,function*(){var i;try{yield this.paymentIntegrationService.loadDefaultCheckout();const t=this.paymentIntegrationService.getState(),r=t.getCheckoutOrThrow().outstandingBalance,o=t.getCartOrThrow().currency.code,a=t.getCustomer(),s=t.getPaymentMethodOrThrow(n),l=null==a?void 0:a.addresses[0],d=l?this.braintreeIntegrationService.mapToBraintreeShippingAddressOverride(l):void 0,c=xe(t.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!c,shippingAddressEditable:!1,shippingAddressOverride:c?void 0:d,amount:r,currency:o,offerCredit:!1,intent:null==(i=s.initializationData)?void 0:i.intent})}catch(e){const{container:n,onError:i}=t;this.handleError(e,n,i)}})}tokenizePayment(e,t,n,i){return ui(this,null,function*(){try{const{deviceData:i}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:o,nonce:a}=r,s=this.braintreeIntegrationService.mapToLegacyBillingAddress(o),l=this.braintreeIntegrationService.mapToLegacyShippingAddress(o);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:n,action:"set_external_checkout",nonce:a,device_data:i,billing_address:JSON.stringify(s),shipping_address:JSON.stringify(l)}),r}catch(e){const{container:t,onError:n}=i;this.handleError(e,t,n)}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const yi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new hi(t,u(),r,n)},[{id:"braintreepaypal"}]);var pi=Object.defineProperty,mi=Object.defineProperties,gi=Object.getOwnPropertyDescriptors,bi=Object.getOwnPropertySymbols,vi=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,fi=(e,t,n)=>t in e?pi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ci=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Ii{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return Ci(this,null,function*(){const{braintreepaypalcredit:t,methodId:n}=e,{container:i,onError:r}=t||{};if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit.container" argument is not provided.');let o,a=this.paymentIntegrationService.getState();try{if(o=a.getPaymentMethodOrThrow(n),!o.clientToken)throw new R(W.MissingPaymentToken)}catch(e){a=yield this.paymentIntegrationService.loadPaymentMethod(n),o=a.getPaymentMethodOrThrow(n)}const{clientToken:s,config:l,initializationData:d}=o,{paymentButtonStyles:c}=d||{},{checkoutTopButtonStyles:u}=c||{};if(!s||!d)throw new R(W.MissingPaymentMethod);const h={currency:a.getCartOrThrow().currency.code,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{var i;this.renderPayPalButton(e,t,n,Boolean(l.testMode),(i=((e,t)=>{for(var n in t||(t={}))vi.call(t,n)&&fi(e,n,t[n]);if(bi)for(var n of bi(t))wi.call(t,n)&&fi(e,n,t[n]);return e})({},u),mi(i,gi({height:40}))))},e=>this.handleError(e,i,r))})}deinitialize(){return Ci(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}signIn(e,t){return Ci(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Ci(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderPayPalButton(e,t,n,i,r){const{container:a,onClick:s=o}=t,{paypal:l}=this.braintreeHostWindow;let d=!1;l&&[l.FUNDING.PAYLATER,l.FUNDING.CREDIT].forEach(o=>{if(!d){const c=l.Buttons({env:i?"sandbox":"production",fundingSource:o,style:r,createOrder:()=>this.setupPayment(e,t,n),onApprove:i=>this.tokenizePayment(i,e,n,t),onClick:s});c.isEligible()&&(c.render(`#${a}`),d=!0)}}),l&&d||this.braintreeIntegrationService.removeElement(a)}setupPayment(e,t,n){return Ci(this,null,function*(){var i;try{yield this.paymentIntegrationService.loadDefaultCheckout();const t=this.paymentIntegrationService.getState(),r=t.getCheckoutOrThrow().outstandingBalance,o=t.getCartOrThrow().currency.code,a=t.getCustomer(),s=t.getPaymentMethodOrThrow(n),l=null==a?void 0:a.addresses[0],d=l?this.braintreeIntegrationService.mapToBraintreeShippingAddressOverride(l):void 0,c=xe(t.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!c,shippingAddressEditable:!1,shippingAddressOverride:c?void 0:d,amount:r,currency:o,offerCredit:!0,intent:null==(i=s.initializationData)?void 0:i.intent})}catch(e){const{container:n,onError:i}=t;this.handleError(e,n,i)}})}tokenizePayment(e,t,n,i){return Ci(this,null,function*(){try{const{deviceData:i}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:o,nonce:a}=r,s=this.braintreeIntegrationService.mapToLegacyBillingAddress(o),l=this.braintreeIntegrationService.mapToLegacyShippingAddress(o);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:n,action:"set_external_checkout",nonce:a,device_data:i,billing_address:JSON.stringify(s),shipping_address:JSON.stringify(l)}),r}catch(e){const{container:t,onError:n}=i;this.handleError(e,t,n)}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const Mi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new Ii(t,u(),r,n)},[{id:"braintreepaypalcredit"}]);var Si=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Pi{constructor(e,t){this.paymentIntegrationService=e,this.braintreeFastlaneUtils=t,this.isAcceleratedCheckoutEnabled=!1}initialize(e){return Si(this,arguments,function*({methodId:e,braintreefastlane:t,onErrorLog:n}){var i;if(!e)throw new Y('Unable to proceed because "methodId" argument is not provided.');const r=yield this.getValidPaymentMethodOrThrow(e),{isAcceleratedCheckoutEnabled:o,isFastlaneStylingEnabled:a}=r.initializationData||{},s=a?null==(i=r.initializationData)?void 0:i.fastlaneStyles:void 0;this.isAcceleratedCheckoutEnabled=!!o,this.onErrorLog=n;try{if(this.isAcceleratedCheckoutEnabled){const e=zt(s,null==t?void 0:t.styles);yield this.braintreeFastlaneUtils.initializeBraintreeFastlaneOrThrow(r.id,e)}}catch(e){e instanceof R&&e.subtype===W.MissingPaymentMethod||this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Si(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Si(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Si(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Si(this,null,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n}=e||{};if("function"!=typeof n)throw new Y('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');const i=this.paymentIntegrationService.getState().getCustomerOrThrow();if(this.isAcceleratedCheckoutEnabled&&i.isGuest){const e=yield this.shouldRunAuthenticationFlow();t&&"function"==typeof t&&t(),e&&(yield this.braintreeFastlaneUtils.runPayPalAuthenticationFlowOrThrow(void 0,!0,{onErrorLog:this.onErrorLog}))}n()})}shouldRunAuthenticationFlow(){return Si(this,null,function*(){var e;const t="braintreeacceleratedcheckout";try{yield this.paymentIntegrationService.loadPaymentMethod(t);return(null==(e=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t).initializationData)?void 0:e.shouldRunAcceleratedCheckout)||!1}catch(e){return!1}})}getValidPaymentMethodOrThrow(e){return Si(this,null,function*(){let t=e;try{yield this.paymentIntegrationService.loadPaymentMethod(t)}catch(n){t="braintree"===e?"braintreeacceleratedcheckout":"braintree",yield this.paymentIntegrationService.loadPaymentMethod(t)}return this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t)})}handleErrorLog(e){this.onErrorLog&&"function"==typeof this.onErrorLog&&this.onErrorLog(e)}}const Oi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n),o=new an(t,r);return new Pi(t,o)},[{id:"braintreeacceleratedcheckout"},{id:"braintree"}]);class Ti extends h{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Ni=Object.defineProperty,Di=Object.defineProperties,zi=Object.getOwnPropertyDescriptors,Ei=Object.getOwnPropertySymbols,ki=Object.prototype.hasOwnProperty,Ai=Object.prototype.propertyIsEnumerable,Li=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ji=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class xi{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n,this.buttonClassName="visa-checkout-wrapper",this.onError=o}initialize(e){return ji(this,null,function*(){const{braintreevisacheckout:t,methodId:n}=e;if(!n)throw new Y('Unable to proceed because "methodId" argument is not provided.');if(!t)throw new Y('Unable to proceed because "options.braintreevisacheckout" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),r=i.getCheckoutOrThrow(),{clientToken:a,config:s}=i.getPaymentMethodOrThrow(n),l=i.getStoreConfigOrThrow();if(!a)throw new R(W.MissingPaymentMethod);this.braintreeSdk.initialize(a);const d=yield this.braintreeSdk.getBraintreeVisaCheckout(),c=yield this.braintreeSdk.getVisaCheckoutSdk(s.testMode),{container:u,onError:h}=t;this.onError=h||o;const y=d.createInitOptions({paymentRequest:{currencyCode:l.currency.code,subtotal:String(r.subtotal)},settings:{locale:l.storeProfile.storeLanguage,shipping:{collectShipping:!0}}}),p=this.createSignInButton(u,this.buttonClassName);yield c.init(y),c.on("payment.success",e=>this.tokenizePayment(d,e).then(()=>this.paymentIntegrationService.loadCheckout()).catch(e=>this.handleError(e))),c.on("payment.error",(e,t)=>this.handleError(t)),p.style.visibility="visible"})}deinitialize(){return ji(this,null,function*(){yield this.braintreeSdk.deinitialize()})}signIn(){throw new Ti('In order to sign in via VisaCheckout, the shopper must click on "Visa Checkout" button.')}signOut(e){return ji(this,null,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}tokenizePayment(e,t){return ji(this,null,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.mapToVisaCheckoutAddress(i),billingAddress:a=this.mapToVisaCheckoutAddress(r)}=e;return this.postForm((s=((e,t)=>{for(var n in t||(t={}))ki.call(t,n)&&Li(e,n,t[n]);if(Ei)for(var n of Ei(t))Ai.call(t,n)&&Li(e,n,t[n]);return e})({},e),Di(s,zi({shippingAddress:o,billingAddress:a}))),t);var s})})}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}mapToVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}createSignInButton(e,t){const n=document.querySelector(`#${e}`);if(!n)throw new Error("Unable to proceed because the provided container ID is not valid.");return this.insertVisaCheckoutButton(n,t)}insertVisaCheckoutButton(e,t){const n=document.createElement("div");return n.style.display="flex",n.style.flexDirection="column",n.style.visibility="hidden",n.style.width="max-content",n.className=t,n.innerHTML='\n <img\n alt="Visa Checkout"\n class="v-button"\n role="button"\n src="https://secure.checkout.visa.com/wallet-services-web/xo/button.png?acceptCanadianVisaDebit=false&cobrand=true&height=34&width=178"\n />\n <a class="v-learn v-learn-default" style="text-align: right; display: block; font-size: 10px; color: #003366;" href="#" data-locale="en_US">Tell Me More</a>',e.appendChild(n),n}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const Bi=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i));return new xi(t,u(),r)},[{id:"braintreevisacheckout"}]);class _i extends h{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"}}function Ui(e){const{color:t,fundingicons:n,height:i=40,layout:o,shape:a,size:l,tagline:d}=e||{},c={color:t,fundingicons:n,height:Fi(i),layout:o,shape:a||"rect",size:l,tagline:d};return s(c,r)}function Fi(e){const t=Number(e);return!t||Number.isNaN(t)?40:t>55?55:t<25?25:t}var Vi=Object.defineProperty,Yi=Object.getOwnPropertySymbols,Wi=Object.prototype.hasOwnProperty,Ri=Object.prototype.propertyIsEnumerable,Hi=(e,t,n)=>t in e?Vi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gi=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Qi{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return Gi(this,null,function*(){const{braintreepaypal:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let r,o=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');r=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow().currency.code;const a=o.getPaymentMethodOrThrow(i),{clientToken:s,config:l,initializationData:d}=a;if(!s||!d)throw new R(W.MissingPaymentMethod);const c={currency:r,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(c,e=>{this.renderPayPalButton(e,t,n,i,!!l.testMode)},e=>this.handleError(e,n,t.onError))})}deinitialize(){return Gi(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,n,i,r){const{style:o,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:l}=t,{paypal:d}=this.braintreeHostWindow;if(d){const c=d.Buttons({env:r?"sandbox":"production",fundingSource:d.FUNDING.PAYPAL,style:Ui(o),createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});c.isEligible()?c.render(`#${n}`):l&&"function"==typeof l&&l()}else this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){return Gi(this,null,function*(){var i;const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),l=s.getCustomer(),d=s.getPaymentMethodOrThrow(n),c=r?r.cartAmount:s.getCartOrThrow().cartAmount,u=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(null==l?void 0:l.addresses[0]),y=h?Ue(h):void 0,p=xe(null!=r?r:s.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!p,shippingAddressEditable:!1,shippingAddressOverride:p?void 0:y,amount:c,currency:u,offerCredit:!1,intent:null==(i=d.initializationData)?void 0:i.intent})}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return Gi(this,null,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,l=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),d=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",((e,t)=>{for(var n in t||(t={}))Wi.call(t,n)&&Hi(e,n,t[n]);if(Yi)for(var n of Yi(t))Ri.call(t,n)&&Hi(e,n,t[n]);return e})({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(l),shipping_address:JSON.stringify(d)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}createBuyNowCart(e){return Gi(this,null,function*(){if(!e)throw new R(W.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new _i}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const Zi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new Qi(t,u(),r,n)},[{id:"braintreepaypal"}]);var qi=Object.defineProperty,Ji=Object.getOwnPropertySymbols,$i=Object.prototype.hasOwnProperty,Xi=Object.prototype.propertyIsEnumerable,Ki=(e,t,n)=>t in e?qi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,er=(e,t)=>{for(var n in t||(t={}))$i.call(t,n)&&Ki(e,n,t[n]);if(Ji)for(var n of Ji(t))Xi.call(t,n)&&Ki(e,n,t[n]);return e},tr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class nr{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return tr(this,null,function*(){const{braintreepaypalcredit:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let r,o=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');r=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow().currency.code;const a=o.getPaymentMethodOrThrow(i),{clientToken:s,config:l,initializationData:d}=a;if(!s||!d)throw new R(W.MissingPaymentMethod);const c={currency:r,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(c,e=>{this.renderPayPalButton(e,t,n,i,!!l.testMode)},e=>this.handleError(e,n,t.onError))})}deinitialize(){return tr(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,n,i,r){const{style:o,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:l}=t,{paypal:d}=this.braintreeHostWindow;let c=!1;d&&[d.FUNDING.PAYLATER,d.FUNDING.CREDIT].forEach(u=>{const h=u===d.FUNDING.CREDIT?er({label:he.CREDIT},Ui(o)):Ui(o);if(!c){const o=d.Buttons({env:r?"sandbox":"production",fundingSource:u,style:h,createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});o.isEligible()?(o.render(`#${n}`),c=!0):d.FUNDING.CREDIT&&l&&"function"==typeof l&&l()}}),d&&c||this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){return tr(this,null,function*(){var i;const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),l=s.getCustomer(),d=s.getPaymentMethodOrThrow(n),c=r?r.cartAmount:s.getCartOrThrow().cartAmount,u=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(null==l?void 0:l.addresses[0]),y=h?Ue(h):void 0,p=xe(null!=r?r:s.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!p,shippingAddressEditable:!1,shippingAddressOverride:p?void 0:y,amount:c,currency:u,offerCredit:!0,intent:null==(i=d.initializationData)?void 0:i.intent})}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return tr(this,null,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,l=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),d=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",er({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(l),shipping_address:JSON.stringify(d)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}createBuyNowCart(e){return tr(this,null,function*(){if(!e)throw new R(W.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new _i}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const ir=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new nr(t,u(),r,n)},[{id:"braintreepaypalcredit"}]);var rr=Object.defineProperty,or=Object.defineProperties,ar=Object.getOwnPropertyDescriptors,sr=Object.getOwnPropertySymbols,lr=Object.prototype.hasOwnProperty,dr=Object.prototype.propertyIsEnumerable,cr=(e,t,n)=>t in e?rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ur=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class hr{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n}initialize(e){return ur(this,null,function*(){const{containerId:t,methodId:n}=e;if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),{clientToken:r,initializationData:o,config:a}=i.getPaymentMethodOrThrow(n);if(!r||!o)throw new R(W.MissingPaymentMethod);this.braintreeSdk.initialize(r);const s=yield this.braintreeSdk.getBraintreeVisaCheckout(),{currency:{code:l},cartAmount:d}=i.getCartOrThrow(),c=yield this.braintreeSdk.getVisaCheckoutSdk(a.testMode),u=s.createInitOptions({paymentRequest:{currencyCode:l,subtotal:String(d)},settings:{shipping:{collectShipping:!0}}});this.createSignInButton(t),yield c.init(u),c.on("payment.success",e=>ur(this,null,function*(){yield this.paymentSuccess(s,e)}))})}deinitialize(){return Promise.resolve()}paymentSuccess(e,t){return ur(this,null,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.toVisaCheckoutAddress(i),billingAddress:a=this.toVisaCheckoutAddress(r)}=e;return this.postForm((s=((e,t)=>{for(var n in t||(t={}))lr.call(t,n)&&cr(e,n,t[n]);if(sr)for(var n of sr(t))dr.call(t,n)&&cr(e,n,t[n]);return e})({},e),or(s,ar({shippingAddress:o,billingAddress:a}))),t);var s})})}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}toVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}createSignInButton(e){const t=document.querySelector(`#${e}`);if(!t)throw new Error("Need a container to place the button");return this.insertVisaCheckoutButton(t)}insertVisaCheckoutButton(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-end",t.innerHTML='\n <img\n alt="Visa Checkout"\n class="v-button"\n role="button"\n src="https://secure.checkout.visa.com/wallet-services-web/xo/button.png?acceptCanadianVisaDebit=false&cobrand=true&height=34&width=178"\n />\n <a class="v-learn v-learn-default" style="text-align: right; display: block; font-size: 10px; color: #003366;" href="#" data-locale="en_US">Tell Me More</a>',e.appendChild(t),t}}const yr=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i));return new hr(t,u(),r)},[{id:"braintreevisacheckout"}]);function pr(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}function mr(e){const{email:t,phone:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}var gr=Object.defineProperty,br=Object.getOwnPropertySymbols,vr=Object.prototype.hasOwnProperty,wr=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Cr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});const Ir=e=>{const{color:t,height:n}=e;return{backgroundColor:(i=t||"",i===ue.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("/app/assets/img/payment-providers/venmo-logo-${t===ue.WHITE?ue.BLUE:ue.WHITE}.svg")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${n||40}px`,minWidth:"150px",height:"100%",width:"100%",border:t===ue.WHITE?"1px solid black":"none"};var i};class Mr{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n,this.onError=o}initialize(e){return Cr(this,null,function*(){const{braintreevenmo:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i),{clientToken:o,initializationData:a}=r,{paymentButtonStyles:s}=a,{cartButtonStyles:l}=s||{},d=(null==t?void 0:t.style)||l;if(!o||!a)throw new R(W.MissingPaymentMethod);if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadDefaultCheckout(),this.onError=(null==t?void 0:t.onError)||this.handleError,this.braintreeSdk.initialize(o);try{const e=yield this.braintreeSdk.getVenmoCheckoutOrThrow();this.renderVenmoButton(e,n,null==t?void 0:t.buyNowInitializeOptions,d)}catch(e){(_e(e)||function(e){return e instanceof M}(e))&&this.handleInitializationVenmoError(e,n)}})}deinitialize(){return Cr(this,null,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}handleError(e){throw new Error(e.message)}createBuyNowCart(e){return Cr(this,null,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=null==e?void 0:e.getBuyNowCartRequestBody();if(!t)throw new R(W.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new _i}}})}handleInitializationVenmoError(e,t){return this.removeVenmoContainer(t),this.onError(e)}removeVenmoContainer(e){const t=document.getElementById(e);t&&t.remove()}renderVenmoButton(e,t,n,i){const r=document.getElementById(t),{color:o}=i||{};if(!r)throw new Y("Unable to create wallet button without valid container ID.");r.setAttribute("aria-label","Venmo"),Object.assign(r.style,Ir(i||{})),r.addEventListener("click",()=>Cr(this,null,function*(){r.setAttribute("disabled","true");const t=yield this.createBuyNowCart(n);e.tokenize&&e.tokenize((e,n)=>Cr(this,null,function*(){r.removeAttribute("disabled"),e&&this.onError(e),yield this.handlePostForm(n,null==t?void 0:t.id)}))})),o===ue.BLUE&&(r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#0a7fc2"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor=Ir(i||{}).backgroundColor}))}handlePostForm(e,t){return Cr(this,null,function*(){const{deviceData:n}=yield this.braintreeSdk.getDataCollectorOrThrow(),{nonce:i,details:r}=e;this.formPoster.postForm("/checkout.php",((e,t)=>{for(var n in t||(t={}))vr.call(t,n)&&fr(e,n,t[n]);if(br)for(var n of br(t))wr.call(t,n)&&fr(e,n,t[n]);return e})({nonce:i,provider:"braintreevenmo",payment_type:"paypal",device_data:n,action:"set_external_checkout",billing_address:JSON.stringify(pr(r)),shipping_address:JSON.stringify(mr(r))},t&&{cart_id:t}))})}}const Sr=V(t=>{const n=window,i=e(),r=new F(t),o=new I(i,n,r),a=new _(o);return new Mr(t,u(),a)},[{id:"braintreevenmo"}]);class Pr{getSDKVersion(){return v}}class Or extends h{constructor(e){super(e||"Failed to redirect to checkout page"),this.name="BraintreePaypalWalletError",this.type="braintree_paypal_wallet"}}var Tr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Nr{constructor(e,t){this.walletButtonIntegrationService=e,this.braintreeIntegrationService=t}initialize(e){this.braintreeIntegrationService.initialize(e)}loadPaypalCheckout(e,t,n){return Tr(this,null,function*(){return this.braintreePaypalCheckout=yield new Promise((i,r)=>{this.braintreeIntegrationService.getPaypalCheckout(e,i,e=>{this.removeElement(t),n&&E(e)&&n(e),r(e)})}),this.braintreePaypalCheckout})}loadVenmoCheckout(e){return Tr(this,null,function*(){try{this.braintreeVenmoCheckout=yield this.braintreeIntegrationService.getVenmoCheckout()}catch(t){throw this.removeElement(e),t}return this.braintreeVenmoCheckout})}getBraintreePaypalCheckoutOrThrow(){if(!this.braintreePaypalCheckout)throw new y;return this.braintreePaypalCheckout}getBraintreeVenmoCheckoutOrThrow(){if(!this.braintreeVenmoCheckout)throw new y;return this.braintreeVenmoCheckout}teardown(){return Tr(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}proxyTokenizationPayment(e,t,n){return Tr(this,null,function*(){const i=this.getBraintreePaypalCheckoutOrThrow(),r=yield i.tokenizePayment(e);return this.redirectToExternalCheckout(r,t,n)})}proxyVenmoTokenizationPayment(e,t){return Tr(this,null,function*(){const n=yield this.tokenizeVenmo();return this.redirectToExternalCheckout(n,e,t)})}removeElement(e){this.braintreeIntegrationService.removeElement(e)}redirectToExternalCheckout(e,t,n){return Tr(this,null,function*(){var i;const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),{details:o,nonce:a}=e,s=this.braintreeIntegrationService.mapToLegacyShippingAddress(o);yield this.walletButtonIntegrationService.addBillingAddress(n,this.mapToBillingAddress(o));const l={paymentWalletData:{providerId:t,providerOrderId:a},cartEntityId:n,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:t},{key:"nonce",value:a},{key:"shipping_address",value:encodeURIComponent(JSON.stringify(s))},...r?[{key:"device_data",value:r}]:[]]},d=null==(i=(yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(l)).body.redirectUrls)?void 0:i.externalCheckoutUrl;if(!d)throw new Or;return window.location.assign(d),e})}mapToBillingAddress(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{firstName:i||"",lastName:r||"",company:"",address1:(null==s?void 0:s.line1)||"",address2:(null==s?void 0:s.line2)||"",city:(null==s?void 0:s.city)||"",email:n||"",stateOrProvince:(null==s?void 0:s.state)||"",stateOrProvinceCode:(null==s?void 0:s.state)||"",countryCode:(null==s?void 0:s.countryCode)||"",postalCode:(null==s?void 0:s.postalCode)||"",phone:o||"",shouldSaveAddress:!1}}tokenizeVenmo(){const e=this.getBraintreeVenmoCheckoutOrThrow();return new Promise((t,n)=>{e.tokenize((e,i)=>{if(e)return n(e);t(i)})})}}var Dr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class zr{constructor(e,t){this.braintreePaypalWalletService=e,this.braintreeHostWindow=t}initialize(e){return Dr(this,null,function*(){const{braintreepaypal:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let r;try{r=JSON.parse(atob(t.initializationData))}catch(e){throw new Y("Failed to parse payment method 'initializationData'.")}const{initializationData:o,config:a}=r;if(!t.clientToken||!o||!a)throw new R(W.MissingPaymentMethod);const s={currency:t.currency.code,intent:o.intent,isCreditEnabled:o.isCreditEnabled,commit:!1};this.braintreePaypalWalletService.initialize(t.clientToken),yield this.braintreePaypalWalletService.loadPaypalCheckout(s,n,t.onError),this.renderButton(t,n,i,!!a.testMode,o.intent)})}deinitialize(){return Dr(this,null,function*(){yield this.braintreePaypalWalletService.teardown()})}renderButton(e,t,n,i,r){const{style:o,onEligibilityFailure:a}=e,{paypal:s}=this.braintreeHostWindow;if(!s)return void this.braintreePaypalWalletService.removeElement(t);const l=s.Buttons({env:i?"sandbox":"production",fundingSource:s.FUNDING.PAYPAL,style:Ui(o),createOrder:()=>this.setupPayment(e,r),onApprove:t=>this.tokenizePayment(t,n,e.cartId,e.onAuthorizeError)});l.isEligible()?l.render(`#${t}`):a&&"function"==typeof a&&a()}setupPayment(e,t){return Dr(this,null,function*(){const{onPaymentError:n,amount:i,currency:r}=e,o=this.braintreePaypalWalletService.getBraintreePaypalCheckoutOrThrow();try{return yield o.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,amount:i,currency:r.code,offerCredit:!1,intent:t})}catch(e){throw(E(e)||e instanceof h)&&(null==n||n(e)),e}})}tokenizePayment(e,t,n,i){return Dr(this,null,function*(){try{yield this.braintreePaypalWalletService.proxyTokenizationPayment(e,t,n)}catch(e){throw(E(e)||e instanceof h)&&(null==i||i(e)),e}})}}const Er=V(t=>{const n=window,i=new Me(new I(e(),n,new Pr),n);return new zr(new Nr(t,i),n)},[{id:"braintreepaypal"}]);var kr=Object.defineProperty,Ar=Object.defineProperties,Lr=Object.getOwnPropertyDescriptors,jr=Object.getOwnPropertySymbols,xr=Object.prototype.hasOwnProperty,Br=Object.prototype.propertyIsEnumerable,_r=(e,t,n)=>t in e?kr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ur=(e,t)=>{for(var n in t||(t={}))xr.call(t,n)&&_r(e,n,t[n]);if(jr)for(var n of jr(t))Br.call(t,n)&&_r(e,n,t[n]);return e},Fr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Vr{constructor(e,t){this.braintreePaypalWalletService=e,this.braintreeHostWindow=t}initialize(e){return Fr(this,null,function*(){const{braintreepaypalcredit:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let r;try{r=JSON.parse(atob(t.initializationData))}catch(e){throw new Y("Failed to parse payment method 'initializationData'.")}const{initializationData:o,config:a}=r;if(!t.clientToken||!o||!a)throw new R(W.MissingPaymentMethod);const s={currency:t.currency.code,intent:o.intent,isCreditEnabled:o.isCreditEnabled,commit:!1};this.braintreePaypalWalletService.initialize(t.clientToken),yield this.braintreePaypalWalletService.loadPaypalCheckout(s,n,t.onError),this.renderButton(t,n,i,!!a.testMode,o.intent)})}deinitialize(){return Fr(this,null,function*(){yield this.braintreePaypalWalletService.teardown()})}renderButton(e,t,n,i,r){const{style:o,onEligibilityFailure:a}=e,{paypal:s}=this.braintreeHostWindow;if(!s)return void this.braintreePaypalWalletService.removeElement(t);const l=s.Buttons({env:i?"sandbox":"production",fundingSource:s.FUNDING.PAYLATER,style:(d=Ur({},Ui(o)),c={color:ue.GOLD},Ar(d,Lr(c))),createOrder:()=>this.setupPayment(e,r),onApprove:t=>this.tokenizePayment(t,n,e.cartId,e.onAuthorizeError)});var d,c;l.isEligible()?l.render(`#${t}`):a&&"function"==typeof a&&a()}setupPayment(e,t){return Fr(this,null,function*(){const{onPaymentError:n,amount:i,currency:r}=e,o=this.braintreePaypalWalletService.getBraintreePaypalCheckoutOrThrow();try{return yield o.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,amount:i,currency:r.code,offerCredit:!0,intent:t})}catch(e){throw(E(e)||e instanceof h)&&(null==n||n(e)),e}})}tokenizePayment(e,t,n,i){return Fr(this,null,function*(){try{yield this.braintreePaypalWalletService.proxyTokenizationPayment(e,t,n)}catch(e){throw(E(e)||e instanceof h)&&(null==i||i(e)),e}})}}const Yr=V(t=>{const n=window,i=new Me(new I(e(),n,new Pr),n);return new Vr(new Nr(t,i),n)},[{id:"braintreepaypalcredit"}]),Wr={[ue.WHITE]:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTE4IiBoZWlnaHQ9IjI5IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPgogICAgPGRlZnM+CiAgICAgICAgPGNsaXBQYXRoIGlkPSJjbGlwMCI+CiAgICAgICAgICAgIDxyZWN0IHdpZHRoPSIxOTgiIGhlaWdodD0iMzgiIGZpbGw9IndoaXRlIiBpZD0ic3ZnXzEiLz4KICAgICAgICA8L2NsaXBQYXRoPgogICAgPC9kZWZzPgogICAgPGc+CiAgICAgICAgPHRpdGxlPkxheWVyIDE8L3RpdGxlPgogICAgICAgIDxnIHN0cm9rZT0ibnVsbCIgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwKSIgaWQ9InN2Z18yIj4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtMjAuMDM2ODgsNGMwLjc1NDU4LDEuMjY3NTEgMS4wOTQ4NSwyLjU3Mjk0IDEuMDk0ODUsNC4yMjIwOGMwLDUuMjU5ODUgLTQuNDE0OTYsMTIuMDkyNzEgLTcuOTk4MjMsMTYuODkwNzVsLTguMTg0NDMsMGwtMy4yODI0LC0xOS45NjExN2w3LjE2NjM0LC0wLjY5MmwxLjczNTQ1LDE0LjIwMzY1YzEuNjIxNTQsLTIuNjg2NjQgMy42MjI1OSwtNi45MDg3MSAzLjYyMjU5LC05Ljc4NzMzYzAsLTEuNTc1NjMgLTAuMjY1NCwtMi42NDg4IC0wLjY4MDE3LC0zLjUzMjQzbDYuNTI2LC0xLjM0MzU0eiIgZmlsbD0id2hpdGUiIGlkPSJzdmdfMyIvPgogICAgICAgICAgICA8cGF0aCBzdHJva2U9Im51bGwiIGQ9Im0yOS4zMjQ3NCwxMi43ODk3NGMxLjMxODgsMCA0LjYzODc0LC0wLjYxMzUzIDQuNjM4NzQsLTIuNTMyNThjMCwtMC45MjE0NiAtMC42NDA2MiwtMS4zODEyIC0xLjM5NTY1LC0xLjM4MTJjLTEuMzIwODgsMCAtMy4wNTQxOCwxLjYxMDk0IC0zLjI0MzA5LDMuOTEzNzhsLTAuMDAwMDEsMHptLTAuMTUxMDgsMy44MDA2M2MwLDIuMzQzMyAxLjI4MTE0LDMuMjYyNTkgMi45Nzk1OCwzLjI2MjU5YzEuODQ5NjEsMCAzLjYyMDQ3LC0wLjQ1OTY1IDUuOTIyMjMsLTEuNjQ5MzFsLTAuODY3MDEsNS45ODcyNWMtMS42MjE2OCwwLjgwNTg4IC00LjE0OTExLDEuMzQzNTQgLTYuNjAyMzEsMS4zNDM1NGMtNi4yMjI5NCwwIC04LjQ1MDAyLC0zLjgzODEgLTguNDUwMDIsLTguNjM2MzJjMCwtNi4yMTg5NyAzLjYyMjczLC0xMi44MjIyOCAxMS4wOTE2OSwtMTIuODIyMjhjNC4xMTIxOCwwIDYuNDExNTksMi4zNDMwMyA2LjQxMTU5LDUuNjA1NjJjMC4wMDAzNiw1LjI1OTU4IC02LjYzNzI2LDYuODcwODggLTEwLjQ4NTc1LDYuOTA4OWwwLjAwMDAxLDB6IiBmaWxsPSJ3aGl0ZSIgaWQ9InN2Z180Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTYwLjM0MDQ5LDguNjg0MDdjMCwwLjc2NzY3IC0wLjExNDUsMS44ODEwMyAtMC4yMjgzOCwyLjYwODdsLTIuMTUwNDEsMTMuODIwMDRsLTYuOTc4MDcsMGwxLjk2MTQ5LC0xMi42Njg2N2MwLjAzNzIxLC0wLjM0MzYxIDAuMTUxNTMsLTEuMDM1MzQgMC4xNTE1MywtMS40MTkxM2MwLC0wLjkyMTU1IC0wLjU2NjEyLC0xLjE1MTQ3IC0xLjI0NjY0LC0xLjE1MTQ3Yy0wLjkwMzk1LDAgLTEuODEwMDUsMC40MjE4MSAtMi40MTM1NiwwLjcyOTg0bC0yLjIyNDgyLDE0LjUwOTQzbC03LjAxNzM1LDBsMy4yMDU4OSwtMjAuNjkwODNsNi4wNzM0OSwwbDAuMDc2OTQsMS42NTE0OGMxLjQzMjg1LC0wLjk1OTQ4IDMuMzE5NTgsLTEuOTk3MjYgNS45OTY1NSwtMS45OTcyNmMzLjU0NjcsLTAuMDAwMzYgNC43OTMzNCwxLjg0Mjg0IDQuNzkzMzQsNC42MDc4NmwwLjAwMDAxLDB6IiBmaWxsPSJ3aGl0ZSIgaWQ9InN2Z181Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTgxLjA1NjI0LDYuMzQwODZjMS45OTg1MiwtMS40NTcyMyAzLjg4NTcsLTIuMjY1MDEgNi40ODc3MiwtMi4yNjUwMWMzLjU4MzA5LDAgNC44Mjg5MiwxLjg0MzIgNC44Mjg5Miw0LjYwODIyYzAsMC43Njc2NyAtMC4xMTM3OCwxLjg4MTAzIC0wLjIyNzU3LDIuNjA4N2wtMi4xNDc5NywxMy44MTk4N2wtNi45Nzk5NiwwbDEuOTk4OTcsLTEyLjkzNjI0YzAuMDM2NzYsLTAuMzQ1NzcgMC4xMTQwNSwtMC43Njc1OCAwLjExNDA1LC0xLjAzNTE2YzAsLTEuMDM3NTkgLTAuNTY2MywtMS4yNjc2OSAtMS4yNDY2NCwtMS4yNjc2OWMtMC44NjY3NCwwIC0xLjczMzEyLDAuMzgzNzkgLTIuMzc2MzUsMC43Mjk3NWwtMi4yMjQzNywxNC41MDk2OWwtNi45NzgyNSwwbDEuOTk4ODgsLTEyLjkzNjQyYzAuMDM2ODQsLTAuMzQ1NzcgMC4xMTE3OSwtMC43Njc1OCAwLjExMTc5LC0xLjAzNTE2YzAsLTEuMDM3NSAtMC41NjY0OCwtMS4yNjc2OSAtMS4yNDQ0OCwtMS4yNjc2OWMtMC45MDU5MywwIC0xLjgxMDA1LDAuNDIxODEgLTIuNDEzNTYsMC43Mjk4NGwtMi4yMjY1NCwxNC41MDk0M2wtNy4wMTUwOSwwbDMuMjA1NTIsLTIwLjY5MDgzbDUuOTk5MjYsMGwwLjE4ODU1LDEuNzI3MzRjMS4zOTU2NSwtMS4wMzUxNiAzLjI4MDg0LC0yLjA3Mjg0IDUuODA4MDksLTIuMDcyODRjMi4xODgxNiwtMC4wMDA4MSAzLjYyMDgzLDAuOTU4ODUgNC4zMzkwMiwyLjI2NDE5bDAuMDAwMDEsMC4wMDAwMXoiIGZpbGw9IndoaXRlIiBpZD0ic3ZnXzYiLz4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtMTA2LjI2MDc1LDEyLjM2ODNjMCwtMS42ODkxNCAtMC40MTU0LC0yLjg0MDY5IC0xLjY1ODg4LC0yLjg0MDY5Yy0yLjc1NDI3LDAgLTMuMzE5NTgsNC45NTE0NyAtMy4zMTk1OCw3LjQ4NDRjMCwxLjkyMTY3IDAuNTI4MjgsMy4xMTA4OCAxLjc3MTc2LDMuMTEwODhjMi42MDM0NywwIDMuMjA2NywtNS4yMjE4NCAzLjIwNjcsLTcuNzU0NTl6bS0xMi4wNzAwNCw0LjMzNzk0YzAsLTYuNTI0OTIgMy4zOTQ1MywtMTIuNjMwMzggMTEuMjAzMTMsLTEyLjYzMDM4YzUuODg1MTIsMCA4LjAzNjE2LDMuNTMyNTEgOC4wMzYxNiw4LjQwODMxYzAsNi40NDkzNCAtMy4zNTc1MSwxMy4xMjgxMyAtMTEuMzU1NzMsMTMuMTI4MTNjLTUuOTIyMTQsMCAtNy44ODM1NSwtMy45NTQzMyAtNy44ODM1NSwtOC45MDYwNmwtMC4wMDAwMSwweiIgZmlsbD0id2hpdGUiIGlkPSJzdmdfNyIvPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+Cg==",[ue.BLUE]:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTE4IiBoZWlnaHQ9IjI5IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPgogICAgPGRlZnM+CiAgICAgICAgPGNsaXBQYXRoIGlkPSJjbGlwMCI+CiAgICAgICAgICAgIDxyZWN0IHdpZHRoPSIxOTgiIGhlaWdodD0iMzgiIGZpbGw9IiMwMDhDRkYiIGlkPSJzdmdfMSIvPgogICAgICAgIDwvY2xpcFBhdGg+CiAgICA8L2RlZnM+CiAgICA8Zz4KICAgICAgICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgICAgICAgPGcgc3Ryb2tlPSJudWxsIiBjbGlwLXBhdGg9InVybCgjY2xpcDApIiBpZD0ic3ZnXzIiPgogICAgICAgICAgICA8cGF0aCBzdHJva2U9Im51bGwiIGQ9Im0yMC4wMzY4OCw0YzAuNzU0NTgsMS4yNjc1MSAxLjA5NDg1LDIuNTcyOTQgMS4wOTQ4NSw0LjIyMjA4YzAsNS4yNTk4NSAtNC40MTQ5NiwxMi4wOTI3MSAtNy45OTgyMywxNi44OTA3NWwtOC4xODQ0MywwbC0zLjI4MjQsLTE5Ljk2MTE3bDcuMTY2MzQsLTAuNjkybDEuNzM1NDUsMTQuMjAzNjVjMS42MjE1NCwtMi42ODY2NCAzLjYyMjU5LC02LjkwODcxIDMuNjIyNTksLTkuNzg3MzNjMCwtMS41NzU2MyAtMC4yNjU0LC0yLjY0ODggLTAuNjgwMTcsLTMuNTMyNDNsNi41MjYsLTEuMzQzNTR6IiBmaWxsPSIjMDA4Q0ZGIiBpZD0ic3ZnXzMiLz4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtMjkuMzI0NzQsMTIuNzg5NzRjMS4zMTg4LDAgNC42Mzg3NCwtMC42MTM1MyA0LjYzODc0LC0yLjUzMjU4YzAsLTAuOTIxNDYgLTAuNjQwNjIsLTEuMzgxMiAtMS4zOTU2NSwtMS4zODEyYy0xLjMyMDg4LDAgLTMuMDU0MTgsMS42MTA5NCAtMy4yNDMwOSwzLjkxMzc4bC0wLjAwMDAxLDB6bS0wLjE1MTA4LDMuODAwNjNjMCwyLjM0MzMgMS4yODExNCwzLjI2MjU5IDIuOTc5NTgsMy4yNjI1OWMxLjg0OTYxLDAgMy42MjA0NywtMC40NTk2NSA1LjkyMjIzLC0xLjY0OTMxbC0wLjg2NzAxLDUuOTg3MjVjLTEuNjIxNjgsMC44MDU4OCAtNC4xNDkxMSwxLjM0MzU0IC02LjYwMjMxLDEuMzQzNTRjLTYuMjIyOTQsMCAtOC40NTAwMiwtMy44MzgxIC04LjQ1MDAyLC04LjYzNjMyYzAsLTYuMjE4OTcgMy42MjI3MywtMTIuODIyMjggMTEuMDkxNjksLTEyLjgyMjI4YzQuMTEyMTgsMCA2LjQxMTU5LDIuMzQzMDMgNi40MTE1OSw1LjYwNTYyYzAuMDAwMzYsNS4yNTk1OCAtNi42MzcyNiw2Ljg3MDg4IC0xMC40ODU3NSw2LjkwODlsMC4wMDAwMSwweiIgZmlsbD0iIzAwOENGRiIgaWQ9InN2Z180Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTYwLjM0MDQ5LDguNjg0MDdjMCwwLjc2NzY3IC0wLjExNDUsMS44ODEwMyAtMC4yMjgzOCwyLjYwODdsLTIuMTUwNDEsMTMuODIwMDRsLTYuOTc4MDcsMGwxLjk2MTQ5LC0xMi42Njg2N2MwLjAzNzIxLC0wLjM0MzYxIDAuMTUxNTMsLTEuMDM1MzQgMC4xNTE1MywtMS40MTkxM2MwLC0wLjkyMTU1IC0wLjU2NjEyLC0xLjE1MTQ3IC0xLjI0NjY0LC0xLjE1MTQ3Yy0wLjkwMzk1LDAgLTEuODEwMDUsMC40MjE4MSAtMi40MTM1NiwwLjcyOTg0bC0yLjIyNDgyLDE0LjUwOTQzbC03LjAxNzM1LDBsMy4yMDU4OSwtMjAuNjkwODNsNi4wNzM0OSwwbDAuMDc2OTQsMS42NTE0OGMxLjQzMjg1LC0wLjk1OTQ4IDMuMzE5NTgsLTEuOTk3MjYgNS45OTY1NSwtMS45OTcyNmMzLjU0NjcsLTAuMDAwMzYgNC43OTMzNCwxLjg0Mjg0IDQuNzkzMzQsNC42MDc4NmwwLjAwMDAxLDB6IiBmaWxsPSIjMDA4Q0ZGIiBpZD0ic3ZnXzUiLz4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtODEuMDU2MjQsNi4zNDA4NmMxLjk5ODUyLC0xLjQ1NzIzIDMuODg1NywtMi4yNjUwMSA2LjQ4NzcyLC0yLjI2NTAxYzMuNTgzMDksMCA0LjgyODkyLDEuODQzMiA0LjgyODkyLDQuNjA4MjJjMCwwLjc2NzY3IC0wLjExMzc4LDEuODgxMDMgLTAuMjI3NTcsMi42MDg3bC0yLjE0Nzk3LDEzLjgxOTg3bC02Ljk3OTk2LDBsMS45OTg5NywtMTIuOTM2MjRjMC4wMzY3NiwtMC4zNDU3NyAwLjExNDA1LC0wLjc2NzU4IDAuMTE0MDUsLTEuMDM1MTZjMCwtMS4wMzc1OSAtMC41NjYzLC0xLjI2NzY5IC0xLjI0NjY0LC0xLjI2NzY5Yy0wLjg2Njc0LDAgLTEuNzMzMTIsMC4zODM3OSAtMi4zNzYzNSwwLjcyOTc1bC0yLjIyNDM3LDE0LjUwOTY5bC02Ljk3ODI1LDBsMS45OTg4OCwtMTIuOTM2NDJjMC4wMzY4NCwtMC4zNDU3NyAwLjExMTc5LC0wLjc2NzU4IDAuMTExNzksLTEuMDM1MTZjMCwtMS4wMzc1IC0wLjU2NjQ4LC0xLjI2NzY5IC0xLjI0NDQ4LC0xLjI2NzY5Yy0wLjkwNTkzLDAgLTEuODEwMDUsMC40MjE4MSAtMi40MTM1NiwwLjcyOTg0bC0yLjIyNjU0LDE0LjUwOTQzbC03LjAxNTA5LDBsMy4yMDU1MiwtMjAuNjkwODNsNS45OTkyNiwwbDAuMTg4NTUsMS43MjczNGMxLjM5NTY1LC0xLjAzNTE2IDMuMjgwODQsLTIuMDcyODQgNS44MDgwOSwtMi4wNzI4NGMyLjE4ODE2LC0wLjAwMDgxIDMuNjIwODMsMC45NTg4NSA0LjMzOTAyLDIuMjY0MTlsMC4wMDAwMSwwLjAwMDAxeiIgZmlsbD0iIzAwOENGRiIgaWQ9InN2Z182Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTEwNi4yNjA3NSwxMi4zNjgzYzAsLTEuNjg5MTQgLTAuNDE1NCwtMi44NDA2OSAtMS42NTg4OCwtMi44NDA2OWMtMi43NTQyNywwIC0zLjMxOTU4LDQuOTUxNDcgLTMuMzE5NTgsNy40ODQ0YzAsMS45MjE2NyAwLjUyODI4LDMuMTEwODggMS43NzE3NiwzLjExMDg4YzIuNjAzNDcsMCAzLjIwNjcsLTUuMjIxODQgMy4yMDY3LC03Ljc1NDU5em0tMTIuMDcwMDQsNC4zMzc5NGMwLC02LjUyNDkyIDMuMzk0NTMsLTEyLjYzMDM4IDExLjIwMzEzLC0xMi42MzAzOGM1Ljg4NTEyLDAgOC4wMzYxNiwzLjUzMjUxIDguMDM2MTYsOC40MDgzMWMwLDYuNDQ5MzQgLTMuMzU3NTEsMTMuMTI4MTMgLTExLjM1NTczLDEzLjEyODEzYy01LjkyMjE0LDAgLTcuODgzNTUsLTMuOTU0MzMgLTcuODgzNTUsLTguOTA2MDZsLTAuMDAwMDEsMHoiIGZpbGw9IiMwMDhDRkYiIGlkPSJzdmdfNyIvPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+Cg=="},Rr=e=>{const{color:t,height:n}=e;return{backgroundColor:(i=t||"",i===ue.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("${Wr[t===ue.WHITE?ue.BLUE:ue.WHITE]}")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${n||40}px`,minWidth:"150px",height:"100%",border:t===ue.WHITE?"1px solid black":"none"};var i};var Hr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Gr{constructor(e){this.braintreePaypalWalletService=e}initialize(e){return Hr(this,null,function*(){const{braintreevenmo:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreevenmo" argument is not provided.');let r;try{r=JSON.parse(atob(t.initializationData))}catch(e){throw new Y("Failed to parse payment method 'initializationData'.")}const{initializationData:o,config:a}=r;if(!t.clientToken||!o||!a)throw new R(W.MissingPaymentMethod);this.braintreePaypalWalletService.initialize(t.clientToken);try{yield this.braintreePaypalWalletService.loadVenmoCheckout(n)}catch(e){return void this.handleInitializationError(e,t)}this.renderButton(t,n,i,o)})}deinitialize(){return Hr(this,null,function*(){yield this.braintreePaypalWalletService.teardown()})}handleInitializationError(e,t){const{onError:n,onEligibilityFailure:i}=t;e instanceof M?null==i||i():(E(e)||e instanceof h)&&(null==n||n(e))}renderButton(e,t,n,i){const{style:r,onEligibilityFailure:o}=e,{cartButtonStyles:a}=i.paymentButtonStyles||{},s=r||a||{},{color:l}=s,d=document.getElementById(t);if(!d)return this.braintreePaypalWalletService.removeElement(t),void(null==o||o());d.setAttribute("aria-label","Venmo"),Object.assign(d.style,Rr(s)),d.addEventListener("click",()=>Hr(this,null,function*(){var t;d.setAttribute("disabled","true");try{yield this.braintreePaypalWalletService.proxyVenmoTokenizationPayment(n,e.cartId)}catch(n){(E(n)||n instanceof h)&&(null==(t=e.onAuthorizeError)||t.call(e,n))}finally{d.removeAttribute("disabled")}})),l===ue.BLUE&&(d.addEventListener("mouseenter",()=>{d.style.backgroundColor="#0a7fc2"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor=Rr(s).backgroundColor}))}}const Qr=V(t=>{const n=window,i=new Me(new I(e(),n,new Pr),n);return new Gr(new Nr(t,i))},[{id:"braintreevenmo"}]);export{se as createBraintreeAchPaymentStrategy,ni as createBraintreeCreditCardPaymentStrategy,Oi as createBraintreeFastlaneCustomerStrategy,sn as createBraintreeFastlanePaymentStrategy,Mt as createBraintreeLocalMethodsPaymentStrategy,Zi as createBraintreePaypalButtonStrategy,ir as createBraintreePaypalCreditButtonStrategy,Mi as createBraintreePaypalCreditCustomerStrategy,Yr as createBraintreePaypalCreditWalletStrategy,yi as createBraintreePaypalCustomerStrategy,$e as createBraintreePaypalPaymentStrategy,Er as createBraintreePaypalWalletStrategy,Sr as createBraintreeVenmoButtonStrategy,En as createBraintreeVenmoPaymentStrategy,Qr as createBraintreeVenmoWalletStrategy,yr as createBraintreeVisaCheckoutButtonStrategy,Bi as createBraintreeVisaCheckoutCustomerStrategy,wn as createBraintreeVisaCheckoutPaymentStrategy};
|
|
1
|
+
import{getScriptLoader as e}from"@bigcommerce/script-loader";import{find as t,isEmpty as n,isEqual as i,isNil as r,noop as o,omit as a,omitBy as s,some as l}from"lodash";import{supportsPopups as d}from"@braintree/browser-detection";import{createRequestSender as c}from"@bigcommerce/request-sender";import{createFormPoster as u}from"@bigcommerce/form-poster";class h 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 y extends h{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 p=(e=>(e.Sandbox="sandbox",e.Production="production",e))(p||{}),m=(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",e))(m||{}),g=(e=>(e.CardCode="cardCode",e.CardCodeVerification="cardCodeVerification",e.CardExpiry="cardExpiry",e.CardName="cardName",e.CardNumber="cardNumber",e.CardNumberVerification="cardNumberVerification",e))(g||{});const b="3.128.0",v="3.123.2",w="3.106.0",f={[w]:{[m.Client]:"sha384-26BXDNnJI23JYRyFBj4xe4sVNrUSSiSSu11kxVXNM/vEPONm4LuL00w6ZaTgQewt",[m.PaypalCheckout]:"sha384-B+vzbZwnQtzWBthpkT4TXKUibO65tyeK7eCxSvpblgprTep2+IAXB2Cxxjrn710O",[m.Paypal]:"sha384-uyAGL1/3+XJAHnGoNy4eCoXdzJ4f7Ilzp+6w9PNnEjs6DCCz9WMyJjMN1gzc78U+",[m.LocalPayment]:"sha384-LIvOEMkIVEwVuYBdVOQc1AC5YbGGlwyfUheS0ACK218D2STuVYQlZ4FyEPowAEfT",[m.DataCollector]:"sha384-1bo9JDz+Kscthc085cCKWur8CLwUoBpoNyxsDi7932mCl0zFq3A5mv+FQLw9GHpV",[m.UsBankAccount]:"sha384-xmHBVaU+w74V+OebD3AaPONFxHUGMf+QRs8G/JxVPXNNP7MDa2jL0ICWHIe2tTfJ",[m.GooglePayment]:"sha384-WKDJl8mqoP82qZpMGH6AbZxnvXnSW8ILV4M64CyMLiugGMwu7LyP89wjCkHqsiBe",[m.ThreeDSecure]:"sha384-VQUlpGHzsGvs5XeiGFip7EXRsvoHWEXDVmgCacfbyieZI9mdBOqq3NSoyo28OCOB",[m.VisaCheckout]:"sha384-yx7mADfzTN0T43Q6rlH49LIg1EJ0iUZgBp/EczX9LXsUGkySgxrD+nWHQRBkyfoT",[m.Venmo]:"sha384-QX4rPjoj1ZDhuG0aSyKs56lEKDqTMTcjYxUHY1SzO5VZDsqIE2NTkqot7KNSCyov",[m.HostedFields]:"sha384-VvYBACfSu0Cr/J32uKmxG7AXcNOJE1AzIIL3kbikyS7YKp5fz5Is+NzNP/lyauNy",[m.Fastlane]:"sha384-9oGsZMRZwpGtDEDYa/dFt76dECqj1xAni9gIKgc3KfMIiRnR73nEeeUDLiBzxhFa"},[v]:{[m.Client]:"sha384-o+nbQGcwNNxIBeXeu3+XmbSq+Cg8R3EN3N0l5hXCgMMU2RGY0t1z0LroSEIAbfAO",[m.PaypalCheckout]:"sha384-WrfbWPBS4mH86GAoycPSgiH8hQ8KH7A67C93Hjhunv/xhNk2YpBn3wbFA4Fhg9U/",[m.Paypal]:"sha384-VF389nvvrRUgDsTXMxTYORDtVegB9IQa3Cxr//DyJnLYnz8/X8VCzEvck2c+Megt",[m.LocalPayment]:"sha384-tZKx2rEQbfmZpoPSY5VPmJEhaq4X75dLvwHMs3VE9U+C8lPyw+hWTIL1+GPvWCIH",[m.DataCollector]:"sha384-E6k3wOpP7syCDDwaRDLF06942Y00NkbwJvWi2OQXwwKzGwG5fd3E7RFUvCCecfvO",[m.UsBankAccount]:"sha384-258FON8LZGG0W9Qaz4Jij83pZHu30YnKjJA7gNulLBh6CclkucgF+tHDQuYFRYfW",[m.GooglePayment]:"sha384-taJ2p/0+n0VH328POAoBiuEbL3tnHUTE9S42hK1V+Txs3X+QYjZOyKW35JgHRFfO",[m.ThreeDSecure]:"sha384-+NSZH4Zj3sO5bdWvPKhU5N16QDxeueTVTnUVeleeESkhLSaz4Ob1hh/5myecc9Ym",[m.VisaCheckout]:"sha384-66DiBjghxk1OmBj8aksN8gbQ+CwoQcx1vPfiXUN08g1iQVM+BwewF0p7toM3i7SS",[m.Venmo]:"sha384-B5UwY42kE4RoLoWbQ7YpqosUlUad2/DlGWiw0HhoZbSPk30CQAaSA10ohyLDTkDU",[m.HostedFields]:"sha384-Aw9EesSaUeWxe36PqEHiOyOyOq8M6CIb1gw7/yHNVPRzGtFXXcd2OQ8qXrIlOj2P",[m.Fastlane]:"sha384-rhBL1hpZ71JqG+2TsT0Dih47mbjx8cjJCpeZjk9tw3df1gFMKfCTmMyZunhr7H4Y"},[b]:{[m.Client]:"sha384-0WNxksIpRP+fYZiIdr12g6DBUQfLDzYCQJZtR/C8KkcwSGhPHfcFp3tTaGcMyFTq",[m.PaypalCheckout]:"sha384-lWM1jk4BOxoDNV6Kop7tVNvQgINlmEVz0c/OwM+HNHK3QC8xqwd54Ovrt2QRDTjh",[m.Paypal]:"sha384-fXUmVxC2EMZBDXZ7eTHSTL/LFBrHej/MSXT/vTBXvra4lzgLNGvREAp+x0GYObuH",[m.LocalPayment]:"sha384-pha1xGuGSkmZH5x9aqHvRaO4xLea7rmQ/79PFj9zxNzxuFcOWZg7gOP7FibygOEC",[m.DataCollector]:"sha384-Q6PI2F9eekWbAxhroybl+aEcvqhdowN/EQlGwBUyJOzPFn9982u9xl6SU6XfGKzc",[m.UsBankAccount]:"sha384-W3RLQSKJL1tQ3+Y7mP6tmkamtZ8bV4Yw/XxL9Jj5JtXHraD8loMF8hAIG5m2zK7F",[m.GooglePayment]:"sha384-TITQMsFWA3elDNGP2mWz2oKBo4qjt+TlqzovcaPoeBiAh/wPBi6nae50ADdgU1/i",[m.ThreeDSecure]:"sha384-YiycYN89ZlL/Evcaq4y1ajW1mhd7JYfZBDuOwHtIn4/Jnm20GL+/XCM+zYAwWD8D",[m.VisaCheckout]:"sha384-/OdaTv9qrkKzjObtUe6yzfDhHozFW/+uXlrSl736sOZRJpjGQETvpYXqMFFg69xv",[m.Venmo]:"sha384-dA+ojdW9vbJS4JavcXyOs9d5uZHJg5dNtYupoPSH2zsXIiYDVS5amLb/u8qmQ6oz",[m.HostedFields]:"sha384-31ZkS58+iaWsW06ftW52zzVZFp43WPd7pNYRiddYynSNg6Oh7WGbSFGorAUH6T1z",[m.Fastlane]:"sha384-jlbrwNvL3HvLAUCtLSmrnQ2GH1udCUrRS/bVmReAS5fuIVvcW8Pko/Gkg82tlgtr"}};var C=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class I{constructor(e,t,n){this.scriptLoader=e,this.braintreeHostWindow=t,this.braintreeSDKVersionManager=n}loadClient(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.Client,"client.min.js")})}loadFastlane(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.Fastlane,"fastlane.min.js")})}loadPaypalCheckout(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.PaypalCheckout,"paypal-checkout.min.js")})}loadPaypal(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.Paypal,"paypal.min.js")})}loadLocalPayment(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.LocalPayment,"local-payment.min.js")})}loadDataCollector(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.DataCollector,"data-collector.min.js")})}loadUsBankAccount(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.UsBankAccount,"us-bank-account.min.js")})}loadGooglePayment(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.GooglePayment,"google-payment.min.js")})}load3DS(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.ThreeDSecure,"three-d-secure.min.js")})}loadVisaCheckout(){return this.loadBraintreeModuleOrThrow(m.VisaCheckout,"visa-checkout.min.js")}loadVenmoCheckout(){return this.loadBraintreeModuleOrThrow(m.Venmo,"venmo.min.js")}loadHostedFields(){return C(this,null,function*(){return this.loadBraintreeModuleOrThrow(m.HostedFields,"hosted-fields.min.js")})}loadVisaCheckoutSdk(e){return C(this,null,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 y;return this.braintreeHostWindow.V})})}loadBraintreeModuleOrThrow(e,t){return C(this,null,function*(){let n=this.getBraintreeModule(e);if(n)return n;const i=this.braintreeSDKVersionManager.getSDKVersion(),r=`//js.braintreegateway.com/web/${i}/js/${t}`,o=i in f?this.getIntegrityValuesByModuleName(e,i):void 0;if(yield this.scriptLoader.loadScript(r,o?{async:!0,attributes:{integrity:o,crossorigin:"anonymous"}}:void 0),n=this.getBraintreeModule(e),!n)throw new y;return n})}getBraintreeModule(e){var t;return null==(t=this.braintreeHostWindow.braintree)?void 0:t[e]}getIntegrityValuesByModuleName(e,t){const n=f[t][e];if(!n)throw new Error("Unexpected fileName value");return n}}class M extends h{constructor(e){super(e||"Unsupported browser error"),this.name="UnsupportedBrowserError",this.type="unsupported_browser"}}var S=(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",e))(S||{});class P extends h{constructor(e){super(function(e){switch(e){case 1:return"Unable to proceed because the customer step of checkout has not been initialized.";case 2:return"Unable to proceed because the payment step of checkout has not been initialized.";case 3:return"Unable to proceed because the shipping step of checkout has not been initialized.";case 4: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"}}var O=(e=>(e.Completed="COMPLETED",e.Pending="PENDING",e.Failed="FAILED",e))(O||{}),T=(e=>(e.TRUSTLY="trustly",e))(T||{}),N=(e=>(e.SUCCEEDED="succeeded",e.FAILED="failed",e.CANCELED="canceled",e.UNRECOGNIZED="unrecognized",e))(N||{}),D=(e=>(e.KountNotEnabled="DATA_COLLECTOR_KOUNT_NOT_ENABLED",e))(D||{}),z=(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",e))(z||{});function E(e){return Boolean("object"==typeof e&&null!==e&&("type"in e||"message"in e||"code"in e))}var k=Object.defineProperty,A=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,x=(e,t,n)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,B=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class _{constructor(e){this.braintreeScriptLoader=e}initialize(e){this.setClientToken(e)}deinitialize(){return B(this,null,function*(){yield this.teardownModule(this.dataCollector),this.dataCollector=void 0})}getClient(){return B(this,null,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 B(this,null,function*(){const t={deviceData:void 0,teardown:()=>Promise.resolve()};if(!this.dataCollector)try{const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadDataCollector(),i=((e,t)=>{for(var n in t||(t={}))L.call(t,n)&&x(e,n,t[n]);if(A)for(var n of A(t))j.call(t,n)&&x(e,n,t[n]);return e})({client:t,kount:!0},e);this.dataCollector=yield n.create(i)}catch(e){if(E(e)&&e.code===D.KountNotEnabled)return t;throw e}return this.dataCollector})}getBraintreeGooglePayment(){return B(this,null,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 B(this,null,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 B(this,null,function*(){if(!this.braintreeLocalPayment){const[t,n]=yield Promise.all([this.getClient(),this.braintreeScriptLoader.loadLocalPayment()]);this.braintreeLocalPayment=yield new Promise((i,r)=>{n.create({client:t,merchantAccountId:e},(e,t)=>{e&&r(e),i(t)})})}return this.braintreeLocalPayment})}getUsBankAccount(){return B(this,null,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 B(this,null,function*(){return this.visaCheckoutSDK||(this.visaCheckoutSDK=yield this.braintreeScriptLoader.loadVisaCheckoutSdk(e)),this.visaCheckoutSDK})}getVenmoCheckoutOrThrow(){return B(this,null,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 M;this.braintreeVenmo=i}return this.braintreeVenmo})}setClientToken(e){this.clientToken=e}getClientTokenOrThrow(){if(!this.clientToken)throw new P(S.PaymentNotInitialized);return this.clientToken}teardownModule(e){return e?e.teardown():Promise.resolve()}}function U(e,t,n=!0){var i;return null!=(i=e[t])?i:n}class F{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()||(U(t,"PAYPAL-5809.braintree_hosted_fields_fix_version")?b:U(t,"PAYPAL-5636.update_braintree_sdk_version")?v:w)}getPreloadedSDKVersion(){const e=this.braintreeWindow.braintree;if(e){const n=t(Object.values(e),e=>!!e.VERSION);return null==n?void 0:n.VERSION}}}function V(e,t){return Object.assign(e,{resolveIds:t})}class Y extends h{constructor(e){super(e||"Invalid arguments have been provided."),this.name="InvalidArgumentError",this.type="invalid_argument"}}var W=(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",e))(W||{});class R extends h{constructor(e){super(function(e){switch(e){case 0:return"Unable to proceed because billing address data is unavailable.";case 1:return"Unable to proceed because cart data is unavailable.";case 3:return"Unable to proceed because consignments data is unavailable.";case 2:return"Unable to proceed because checkout data is unavailable.";case 4:return"Unable to proceed because customer data is unavailable.";case 5:case 7:return"Unable to proceed because configuration data is unavailable.";case 6:return"Unable to proceed because order data is unavailable.";case 8:return"Unable to proceed because order ID is unavailable or not generated yet.";case 9:return"Unable to proceed because payment data is unavailable.";case 15:return"Unable to proceed because the token required to submit a payment is missing.";case 12:return"Unable to proceed because payment method data is unavailable or not properly configured.";case 16: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"}}class H extends Y{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"}}function G(e){return Boolean(e.instrumentId)}class Q extends h{constructor(){super("The current order does not need to be finalized at this stage."),this.name="OrderFinalizationNotRequiredError",this.type="order_finalization_not_required"}}function Z(e){return!("object"!=typeof e||null===e||void 0!==e.shouldSaveInstrument&&"boolean"!=typeof e.shouldSaveInstrument||void 0!==e.shouldSetAsDefaultInstrument&&"boolean"!=typeof e.shouldSetAsDefaultInstrument)}class q extends h{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"}}function J(e){return!!e&&"accountNumber"in e&&"routingNumber"in e&&"ownershipType"in e&&"accountType"in e}var $=Object.defineProperty,X=Object.defineProperties,K=Object.getOwnPropertyDescriptors,ee=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ne=Object.prototype.propertyIsEnumerable,ie=(e,t,n)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,re=(e,t)=>{for(var n in t||(t={}))te.call(t,n)&&ie(e,n,t[n]);if(ee)for(var n of ee(t))ne.call(t,n)&&ie(e,n,t[n]);return e},oe=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class ae{constructor(e,t){this.paymentIntegrationService=e,this.braintreeSdk=t}initialize(e){return oe(this,null,function*(){const{methodId:t,braintreeach:n}=e||{};if(!t)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');this.getMandateText=null==n?void 0:n.getMandateText,yield this.paymentIntegrationService.loadPaymentMethod(t);const i=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t),{clientToken:r,initializationData:o}=i;if(!r||!o)throw new R(W.MissingPaymentMethod);this.braintreeSdk.initialize(r);try{this.usBankAccount=yield this.braintreeSdk.getUsBankAccount()}catch(e){this.handleBraintreeError(e)}})}execute(e,t){return oe(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)te.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&ee)for(var i of ee(e))t.indexOf(i)<0&&ne.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new H(["payment"]);const o=G(i.paymentData||{}),a=o?yield this.tokenizePaymentForVaultedInstrument(i):yield this.tokenizePayment(i),s=o?yield this.preparePaymentDataForVaultedInstrument(a,i):yield this.preparePaymentData(a,i);yield this.paymentIntegrationService.submitOrder(r,t),yield this.paymentIntegrationService.submitPayment(s)})}finalize(){return Promise.reject(new Q)}deinitialize(){return oe(this,null,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}tokenizePayment(e){return oe(this,arguments,function*({paymentData:e}){const t=this.getUsBankAccountOrThrow();if(!J(e))throw new H(["payment.paymentData"]);const n=G(e)?"The data are used for stored instrument verification":"function"==typeof this.getMandateText&&this.getMandateText();if(!n)throw new Y("Unable to proceed because getMandateText is not provided or returned undefined value.");try{const{nonce:i}=yield t.tokenize({bankDetails:this.getBankDetails(e),mandateText:n});return i}catch(e){this.handleBraintreeError(e)}})}tokenizePaymentForVaultedInstrument(e){return oe(this,null,function*(){const{methodId:t,paymentData:n={}}=e,i=this.paymentIntegrationService.getState(),{config:r}=i.getPaymentMethodOrThrow(t);if(!r.isVaultingEnabled)throw new Y("Vaulting is disabled but a vaulted instrument was being used for this transaction");return J(n)?this.tokenizePayment(e):null})}preparePaymentData(e,t){return oe(this,null,function*(){const{methodId:n,paymentData:i={}}=t;if(!J(i))throw new H(["payment.paymentData"]);const{deviceData:r}=yield this.braintreeSdk.getDataCollectorOrThrow(),{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,routingNumber:s,accountNumber:l}=i;return{methodId:n,paymentData:{deviceSessionId:r,shouldSetAsDefaultInstrument:a,shouldSaveInstrument:o,formattedPayload:{tokenized_bank_account:{issuer:s,masked_account_number:l.substr(-4),token:e}}}}})}preparePaymentDataForVaultedInstrument(e,t){return oe(this,null,function*(){const{methodId:n,paymentData:i={}}=t;if(!G(i)||!Z(i))throw new H(["payment.paymentData"]);const{deviceData:r}=yield this.braintreeSdk.getDataCollectorOrThrow(),{instrumentId:o,shouldSetAsDefaultInstrument:a}=i;return{methodId:n,paymentData:re({deviceSessionId:r,instrumentId:o,shouldSetAsDefaultInstrument:a},e&&{nonce:e})}})}getBankDetails(e){const t=this.paymentIntegrationService.getState().getBillingAddressOrThrow(),n=e.ownershipType.toLowerCase(),i=e.accountType.toLowerCase();return r=re({accountNumber:e.accountNumber,routingNumber:e.routingNumber,ownershipType:n},"personal"===n?{firstName:e.firstName,lastName:e.lastName}:{businessName:e.businessName}),o={accountType:i,billingAddress:{streetAddress:t.address1,extendedAddress:t.address2,locality:t.city,region:t.stateOrProvinceCode,postalCode:t.postalCode}},X(r,K(o));var r,o}getUsBankAccountOrThrow(){if(!this.usBankAccount)throw new P(S.PaymentNotInitialized);return this.usBankAccount}handleBraintreeError(e){if(!E(e))throw e;throw new q(e.message)}}const se=V(t=>new ae(t,(t=>{const n=new F(t),i=new I(e(),window,n);return new _(i)})(t)),[{id:"braintreeach"}]);class le extends h{constructor(e,t){super(t||"Unable to proceed because the payment form contains invalid data."),this.details=e,this.name="PaymentInvalidFormError",this.type="payment_invalid_form"}}let de=null;const ce=["buttons","messages"];var ue=(e=>(e.GOLD="gold",e.BLUE="blue",e.SIlVER="silver",e.BLACK="black",e.WHITE="white",e))(ue||{}),he=(e=>(e.CHECKOUT="checkout",e.PAY="pay",e.BUYNOW="buynow",e.PAYPAL="paypal",e.CREDIT="credit",e))(he||{}),ye=(e=>(e.CART="cart",e.HOME="homepage",e.PAYMENT="payment",e.PRODUCT="product",e))(ye||{}),pe=Object.defineProperty,me=Object.defineProperties,ge=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertySymbols,ve=Object.prototype.hasOwnProperty,we=Object.prototype.propertyIsEnumerable,fe=(e,t,n)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ce=(e,t)=>{for(var n in t||(t={}))ve.call(t,n)&&fe(e,n,t[n]);if(be)for(var n of be(t))we.call(t,n)&&fe(e,n,t[n]);return e},Ie=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Me{constructor(e,t,n){this.braintreeScriptLoader=e,this.braintreeHostWindow=t,this.overlay=n,this.dataCollectors={}}initialize(e,t){this.clientToken=e,this.threeDSecureOptions=t}getBraintreeFastlane(e,t,n){return Ie(this,null,function*(){if(t&&(window.localStorage.setItem("axoEnv","sandbox"),window.localStorage.setItem("fastlaneEnv","sandbox")),!this.braintreeHostWindow.braintreeFastlane){const t=this.getClientTokenOrThrow(),i=yield this.getClient(),r=yield this.getSessionId(e),o=yield this.braintreeScriptLoader.loadFastlane(),a={root:{backgroundColorPrimary:"transparent"}};this.braintreeHostWindow.braintreeFastlane=yield o.create({authorization:t,client:i,deviceData:r,styles:n||a})}return this.braintreeHostWindow.braintreeFastlane})}getClient(){return Ie(this,null,function*(){if(!this.client){const e=this.getClientTokenOrThrow(),t=yield this.braintreeScriptLoader.loadClient();this.client=t.create({authorization:e})}return this.client})}getPaypal(){return this.braintreePaypal||(this.braintreePaypal=Promise.all([this.getClient(),this.braintreeScriptLoader.loadPaypal()]).then(([e,t])=>t.create({client:e}))),this.braintreePaypal}paypal(e){var t=e,{shouldSaveInstrument:n}=t,i=((e,t)=>{var n={};for(var i in e)ve.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&be)for(var i of be(e))t.indexOf(i)<0&&we.call(e,i)&&(n[i]=e[i]);return n})(t,["shouldSaveInstrument"]);const r=d();return this.getPaypal().then(e=>{var t;return r&&(null==(t=this.overlay)||t.show({onClick:()=>e.focusWindow()})),e.tokenize(Ce({enableShippingAddress:!0,flow:n?"vault":"checkout",useraction:"commit"},i))}).then(e=>{var t;return null==(t=this.overlay)||t.remove(),e}).catch(e=>{var t;throw null==(t=this.overlay)||t.remove(),e})}getPaypalCheckout(e,t,n){return Ie(this,null,function*(){const i=yield this.getClient(),r=yield this.braintreeScriptLoader.loadPaypalCheckout(),o={client:i};return this.paypalCheckout=yield r.create(o,(i,r)=>{var o;if(i)return n(i);const a=(s=Ce({currency:e.currency},e.isCreditEnabled&&{"enable-funding":"paylater"}),l={components:ce.toString(),intent:e.intent,commit:null==(o=e.commit)||o},me(s,ge(l)));var s,l;this.braintreeHostWindow.paypal?t(r):function(e,t){return de||(de=new Promise((n,i)=>{e.loadPayPalSDK(t,t=>{t?(de=null,i(t)):n(e)})})),de}(r,a).then(()=>t(r))}),this.paypalCheckout})}getDataCollector(e){return Ie(this,null,function*(){const t=(null==e?void 0:e.paypal)?"paypal":"default";let n=this.dataCollectors[t];if(!n){try{const t=yield this.getClient(),i=yield this.braintreeScriptLoader.loadDataCollector(),r=Ce({client:t,kount:!0},e);n=yield i.create(r)}catch(e){if(!E(e)||"DATA_COLLECTOR_KOUNT_NOT_ENABLED"!==e.code)throw e;n={deviceData:void 0,teardown:()=>Promise.resolve()}}this.dataCollectors[t]=n}return n})}getBraintreeEnv(e=!1){return e?p.Sandbox:p.Production}mapToBraintreeShippingAddressOverride(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}mapToLegacyShippingAddress(e){const{email:t,phone:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}mapToLegacyBillingAddress(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}removeElement(e){const t=e&&document.getElementById(e);t&&t.remove()}getSessionId(e){return Ie(this,null,function*(){const{deviceData:t}=yield this.getDataCollector({riskCorrelationId:e});return t})}teardown(){return Ie(this,null,function*(){yield this.teardownModule(this.dataCollectors.default),yield this.teardownModule(this.dataCollectors.paypal),this.dataCollectors={},yield this.teardownModule(this.paypalCheckout),this.paypalCheckout=void 0})}get3DS(){return Ie(this,null,function*(){return this.threeDS||(this.threeDS=Promise.all([this.getClient(),this.braintreeScriptLoader.load3DS()]).then(([e,t])=>t.create({client:e,version:2}))),this.threeDS})}getVenmoCheckout(e){return Ie(this,null,function*(){if(!this.venmoCheckout){const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadVenmoCheckout(),i=Ce({client:t,allowDesktop:!0,paymentMethodUsage:"multi_use"},e||{});this.venmoCheckout=yield new Promise((e,t)=>{n.create(i,(n,i)=>n?t(n):i.isBrowserSupported()?void e(i):t(new M))})}return this.venmoCheckout})}verifyCard(e,t,n){return Ie(this,null,function*(){const i=yield this.tokenizeCard(e,t);return this.challenge3DSVerification(i,n)})}tokenizeCard(e,t){return Ie(this,null,function*(){const{paymentData:i}=e;if(!function(e){if("object"!=typeof e||null===e)return!1;const t=e;return"object"==typeof t.ccExpiry&&null!==t.ccExpiry&&"string"==typeof t.ccNumber&&"string"==typeof t.ccName}(i))throw new H(["payment.paymentData"]);const r=this.getErrorsRequiredFields(i);if(!n(r))throw new le(r);const o=this.mapToCreditCard(i,t),a=yield this.getClient(),{creditCards:s}=yield a.request(o);return{nonce:s[0].nonce,bin:s[0].details.bin}})}challenge3DSVerification(e,t){return Ie(this,null,function*(){const n=yield this.get3DS();return this.present3DSChallenge(n,t,e)})}teardownModule(e){return e?e.teardown():Promise.resolve()}getClientTokenOrThrow(){if(!this.clientToken)throw new P(S.PaymentNotInitialized);return this.clientToken}getErrorsRequiredFields(e){const{ccNumber:t,ccExpiry:n}=e,i={};return t||(i.ccNumber=[{message:"Credit card number is required",type:"required"}]),n||(i.ccExpiry=[{message:"Expiration date is required",type:"required"}]),i}mapToCreditCard(e,t){return{data:{creditCard:{cardholderName:e.ccName,number:e.ccNumber,cvv:e.ccCvv,expirationDate:`${e.ccExpiry.month}/${e.ccExpiry.year}`,options:{validate:!1},billingAddress:t&&{countryCodeAlpha2:t.countryCode,locality:t.city,countryName:t.country,postalCode:t.postalCode,streetAddress:t.address2?`${t.address1} ${t.address2}`:t.address1}}},endpoint:"payment_methods/credit_cards",method:"post"}}present3DSChallenge(e,t,n){const{nonce:i,bin:r}=n;if(!i)throw new P(S.PaymentNotInitialized);const{challengeRequested:o=!0,additionalInformation:a}=this.threeDSecureOptions||{},s=t.toFixed(2);return e.verifyCard({amount:Number(s),bin:r,challengeRequested:o,nonce:i,onLookupComplete:(e,t)=>{t()},collectDeviceData:!0,additionalInformation:a})}}class Se{constructor(e){this.paymentIntegrationService=e,this.braintreeHostWindow=window}render(e,t,n){const i=t&&document.getElementById(t);if(this.braintreeHostWindow.paypal&&i){const r=this.paymentIntegrationService.getState(),o=r.getCartOrThrow(),a=r.getBillingAddressOrThrow(),s=r.getPaymentMethodOrThrow(e);if(!s.initializationData)return;const{paypalBNPLConfiguration:l=[]}=s.initializationData,d=n===ye.PAYMENT?"checkout":n,c=l&&l.find(({id:e})=>e===d);if(!c||!c.status)return;n===ye.CART&&(i.removeAttribute("data-pp-style-logo-type"),i.removeAttribute("data-pp-style-logo-position"),i.removeAttribute("data-pp-style-text-color"),i.removeAttribute("data-pp-style-text-size")),this.braintreeHostWindow.paypal.Messages({amount:o.cartAmount,buyerCountry:a.countryCode,placement:n,style:this.getPaypalMessagesStylesFromBNPLConfig(c)}).render(`#${t}`)}}getPaypalMessagesStylesFromBNPLConfig({styles:e}){const t={};return e.color&&(t.color=e.color),e.layout&&(t.layout=e.layout),(e["logo-type"]||e["logo-position"])&&(t.logo={},e["logo-type"]&&(t.logo.type=e["logo-type"]),e["logo-position"]&&(t.logo.position=e["logo-position"])),e.ratio&&(t.ratio=e.ratio),(e["text-color"]||e["text-size"])&&(t.text={},e["text-color"]&&(t.text.color=e["text-color"]),e["text-size"]&&(t.text.size=+e["text-size"])),t}}class Pe{constructor(e){const{element:t,closeElement:n,mainElement:i}=this._createElements(e);this._element=t,this._closeElement=n,this._mainElement=i}show(e){this._mainElement.parentElement||(this._registerClick(e),document.body.appendChild(this._mainElement),setTimeout(()=>this._element.style.opacity="1"))}remove(){this._mainElement.parentElement&&(this._unregisterClick&&this._unregisterClick(),this._removeAfterTransition(),setTimeout(()=>this._element.style.opacity="0"))}_createElements(e){const t=document.createElement("div"),{background:n="rgba(0, 0, 0, 0.8)",id:i="checkoutOverlay",transitionDuration:r=400,hasCloseButton:o=!1,innerHtml:a=null}=e||{};let s,l,d,c,u=t;if(i&&(t.id=i),a){const e=document.createElement("div");c=`${i}--overlayText`,e.className=c,e.appendChild(a),t.appendChild(e)}return o&&(d=`${i}--close`,s=document.createElement("div"),s.className=d,l=`${i}--layout`,u=document.createElement("div"),u.className=l,u.appendChild(t),u.appendChild(s)),u.appendChild(function(e){const{id:t,background:n,transitionDuration:i,classLayout:r,classOverlayText:o,classClose:a}=e,s=document.createElement("style"),l=r?`, .${r}`:"";return s.id=`${t}--styles`,s.type="text/css",s.innerText=`\n #${t}${l} {\n display: block;\n height: 100%;\n width: 100%;\n left: 0;\n top: 0;\n position: fixed;\n z-index: 2147483647;\n }\n #${t} {\n transition: opacity ${i}ms ease-out;\n background: ${n};\n opacity: 0;\n }\n `,o&&(s.innerText+=`\n #${t} {\n display: flex;\n align-items: center;\n justify-content: center;\n }\n #${t} .${o} {\n color: white;\n max-width: 330px;\n font-size: 1.2em;\n text-align: center;\n }\n `),a&&(s.innerText+=`\n #${t} {\n opacity: 1;\n }\n .${r} .${a} {\n position: fixed;\n right: 16px;\n top: 16px;\n width: 16px;\n height: 16px;\n opacity: 0.6;\n cursor: pointer;\n z-index: 3147483647;\n }\n .${r} .${a}::after, .${r} .${a}::before {\n position: absolute;\n left: 8px;\n content: '';\n height: 16px;\n width: 2px;\n background-color: #fff;\n }\n .${r} .${a}::after {\n transform: rotate(-45deg);\n }\n .${r} .${a}::before {\n transform: rotate(45deg);\n }\n `),s}({id:i,background:n,transitionDuration:r,classLayout:l,classOverlayText:c,classClose:d})),{element:t,closeElement:s,mainElement:u}}_addEventListener(e,t){e&&t&&e.addEventListener("click",t)}_removeEventListener(e,t){e&&t&&e.removeEventListener("click",t)}_registerClick(e){if(this._unregisterClick&&this._unregisterClick(),e){const{onClick:t,onClickClose:n}=e;this._addEventListener(this._element,t),this._addEventListener(this._closeElement,n),this._unregisterClick=()=>{this._removeEventListener(this._element,t),this._removeEventListener(this._closeElement,n),this._unregisterClick=void 0}}}_removeAfterTransition(){const e=t=>{"opacity"===t.propertyName&&(this._mainElement.parentElement&&this._mainElement.remove(),this._element.removeEventListener("transitionend",e))};this._element.addEventListener("transitionend",e)}}var Oe=Object.defineProperty,Te=Object.getOwnPropertySymbols,Ne=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable,ze=(e,t,n)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ee=(e,t)=>{for(var n in t||(t={}))Ne.call(t,n)&&ze(e,n,t[n]);if(Te)for(var n of Te(t))De.call(t,n)&&ze(e,n,t[n]);return e};const ke={size:70,color:"#d9d9d9",backgroundColor:"#ffffff"},Ae="embedded-checkout-loading-indicator-rotation";class Le{constructor(e){this.styles=Ee(Ee({},ke),e&&e.styles),this.containerStyles=Ee({},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=`${Ae} 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(Ae))return;const t=document.createElement("style");t.id=Ae,null==(e=document.head)||e.appendChild(t),t.sheet instanceof CSSStyleSheet&&t.sheet.insertRule(`\n @keyframes ${Ae} {\n 0% { transform: translateY(-50%) rotate(0deg); }\n 100% { transform: translateY(-50%) rotate(360deg); }\n }\n `,0)}}const je={"background-color":"rgba(0, 0, 0, 0.4)","z-index":"1000"};function xe(e){const{physicalItems:t=[],digitalItems:n=[],customItems:i=[]}=e.lineItems;return 0===(null==t?void 0:t.length)&&0===(null==i?void 0:i.length)&&(null==n?void 0:n.length)>0}class Be extends h{constructor(e){super(e||"Payment process was cancelled."),this.name="PaymentMethodCancelledError",this.type="payment_cancelled"}}function _e(e){return"object"==typeof e&&null!==e&&"name"in e&&"BraintreeError"===e.name}function Ue(e){return{recipientName:`${e.firstName} ${e.lastName}`,line1:e.address1,line2:e.address2,city:e.city,state:e.stateOrProvinceCode,postalCode:e.postalCode,countryCode:e.countryCode,phone:e.phone}}var Fe=Object.defineProperty,Ve=Object.defineProperties,Ye=Object.getOwnPropertyDescriptors,We=Object.getOwnPropertySymbols,Re=Object.prototype.hasOwnProperty,He=Object.prototype.propertyIsEnumerable,Ge=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qe=(e,t)=>{for(var n in t||(t={}))Re.call(t,n)&&Ge(e,n,t[n]);if(We)for(var n of We(t))He.call(t,n)&&Ge(e,n,t[n]);return e},Ze=(e,t)=>Ve(e,Ye(t)),qe=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Je{constructor(e,t,n,i){this.paymentIntegrationService=e,this.braintreeIntegrationService=t,this.braintreeMessages=n,this.loadingIndicator=i,this.braintreeHostWindow=window}initialize(e){return qe(this,null,function*(){const{braintree:t,methodId:n}=e;if((null==t?void 0:t.containerId)&&(this.braintreeButtonOptions=t),this.paymentMethod&&this.paymentMethod.nonce||(this.paymentMethod=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(n)),this.paymentMethod.clientToken&&(null==t?void 0:t.bannerContainerId))return yield this.loadPaypal(),this.loadPaypalCheckoutInstance(t);if(this.paymentMethod.clientToken)return this.loadPaypal();const i=yield this.paymentIntegrationService.loadPaymentMethod(n);if(this.paymentMethod=i.getPaymentMethodOrThrow(n),null==t?void 0:t.bannerContainerId)return this.loadPaypalCheckoutInstance(t);if(!this.paymentMethod.clientToken)throw new R(W.MissingPaymentMethod);return this.loadPaypal()})}execute(e,t){return qe(this,null,function*(){var n;const i=e,{payment:r}=i,o=((e,t)=>{var n={};for(var i in e)Re.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&We)for(var i of We(e))t.indexOf(i)<0&&He.call(e,i)&&(n[i]=e[i]);return n})(i,["payment"]);if(!r)throw new H(["payment"]);const{onError:a}=this.braintreeButtonOptions||{};try{const e=yield this.preparePaymentData(r,o.useStoreCredit);yield this.paymentIntegrationService.submitOrder(o,t),yield this.paymentIntegrationService.submitPayment(e)}catch(e){this.isProviderError(e)&&(yield this.loadPaypal(),null==(n=this.paypalButtonRender)||n.close(),yield this.loadPaypalCheckoutInstance(this.braintreeButtonOptions),yield new Promise((e,t)=>{a&&"function"==typeof a&&a(new Error("INSTRUMENT_DECLINED")),t()})),this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){var e;return this.braintreeTokenizePayload=void 0,null==(e=this.paypalButtonRender)||e.close(),this.braintreeIntegrationService.teardown()}preparePaymentData(e,t){return qe(this,null,function*(){var n;const i=this.paymentIntegrationService.getState(),r=i.getOutstandingBalance(t),o=i.getStoreConfig();if(!r)throw new R(W.MissingCheckout);if(!o)throw new R(W.MissingCheckoutConfig);if(!this.paymentMethod)throw new P(S.PaymentNotInitialized);const{currency:a,storeProfile:{storeLanguage:s}}=o,{nonce:l,config:{isVaultingEnabled:d}}=this.paymentMethod,{methodId:c,paymentData:u={}}=e,h=(null==(n=this.braintreeTokenizePayload)?void 0:n.nonce)||l;if(h){const t=yield this.paymentIntegrationService.loadPaymentMethod(c);return this.paymentMethod=t.getPaymentMethod(c),Ze(Qe({},e),{paymentData:this.formattedPayload(h)})}if(G(u)||(y=u,Boolean(y.instrumentId)&&!Object.prototype.hasOwnProperty.call(y,"ccNumber")&&!Object.prototype.hasOwnProperty.call(y,"ccCvv"))){if(!d)throw new Y("Vaulting is disabled but a vaulted instrument was being used for this transaction");return Promise.resolve(e)}var y;if(!Z(u))throw new R(W.MissingPayment);const{shouldSaveInstrument:p,shouldSetAsDefaultInstrument:m}=u;if(p&&!d)throw new Y("Vaulting is disabled but shouldSaveInstrument is set to true");const g=i.getShippingAddress(),b=g?Ue(g):void 0,v=xe(i.getCartOrThrow());return Promise.all([this.braintreeIntegrationService.paypal({amount:r,locale:s,currency:a.code,offerCredit:"braintreepaypalcredit"===this.paymentMethod.id,shippingAddressOverride:v?void 0:b,enableShippingAddress:!v,shouldSaveInstrument:p||!1,shippingAddressEditable:!1}),this.braintreeIntegrationService.getSessionId()]).then(([{nonce:t,details:n}={},i])=>Ze(Qe({},e),{paymentData:this.formattedPayload(t,n&&n.email,i,p,m)}))})}formattedPayload(e,t,n,i,r){return{formattedPayload:{vault_payment_instrument:i||null,set_as_default_stored_instrument:r||null,device_info:n||null,paypal_account:{token:e,email:t||null}}}}loadPaypalCheckoutInstance(e){return qe(this,null,function*(){const{clientToken:t,initializationData:n,id:i}=this.paymentMethod||{};if(!t)throw new R(W.MissingPaymentMethod);try{this.braintreeIntegrationService.initialize(t);const r={currency:this.paymentIntegrationService.getState().getCartOrThrow().currency.code,intent:null==n?void 0:n.intent,isCreditEnabled:null==n?void 0:n.isCreditEnabled},o="braintreepaypalcredit"===i||!(null==n?void 0:n.isCreditEnabled);yield this.braintreeIntegrationService.getPaypalCheckout(r,t=>{o&&i&&(null==e?void 0:e.bannerContainerId)&&this.renderPayPalMessages(i,e.bannerContainerId),this.renderPayPalButton(t,e)},this.handleError)}catch(e){this.handleError(e)}})}renderPayPalMessages(e,t){this.braintreeMessages.render(e,t,ye.PAYMENT)}renderPayPalButton(e,t){const{onPaymentError:n,submitForm:i,onRenderButton:r,containerId:o,onError:a}=t||{};if(!o)return;const s=this.getSmartButtonContainerId(o);if(!document.getElementById(s))throw new Y(`Unable to initialize payment because element with id ${o} does not exist.`);if(!this.paymentMethod)throw new P(S.PaymentNotInitialized);this.loadingIndicatorContainer=o.split("#")[1];const{id:l,config:{testMode:d}}=this.paymentMethod,{paypal:c}=this.braintreeHostWindow,u=null==c?void 0:c.FUNDING.PAYPAL;c&&u?(this.paypalButtonRender=c.Buttons({env:d?"sandbox":"production",commit:!1,fundingSource:u,onInit:(e,n)=>{var i;null==(i=null==t?void 0:t.onInitButton)||i.call(t,n)},onClick:(e,n)=>{const{resolve:i,reject:r}=n,o=()=>(this.toggleLoadingIndicator(!0),i());return void 0!==(null==t?void 0:t.onValidate)?t.onValidate(o,r):o()},createOrder:()=>this.setupPayment(e,l,n),onApprove:t=>qe(this,null,function*(){this.braintreeTokenizePayload=yield this.tokenizePaymentOrThrow(t,e),i&&"function"==typeof i&&i()}),onCancel:()=>{this.toggleLoadingIndicator(!1)},onError:e=>{this.toggleLoadingIndicator(!1),null==a||a(e)}}),r&&"function"==typeof r&&r(),this.paypalButtonRender.isEligible()&&this.paypalButtonRender.render(`${o}`)):this.removeElement(o.split("#")[1])}setupPayment(e,t,n){return qe(this,null,function*(){const i=this.paymentIntegrationService.getState();try{const n=i.getCustomer(),r=i.getPaymentMethodOrThrow(t),o=i.getCheckoutOrThrow().outstandingBalance,a=i.getStoreConfigOrThrow().currency.code,s=i.getShippingAddress()||(null==n?void 0:n.addresses[0]),l=s?Ue(s):void 0,d=xe(i.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!d,shippingAddressEditable:!1,shippingAddressOverride:d?void 0:l,amount:o,currency:a,offerCredit:!1,intent:r.initializationData.intent})}catch(e){throw n&&(_e(e)||e instanceof h)&&n(e),e}})}tokenizePaymentOrThrow(e,t,n){return qe(this,null,function*(){try{return yield t.tokenizePayment(e)}catch(e){throw n&&(_e(e)||e instanceof h)&&n(e),e}})}loadPaypal(){return qe(this,null,function*(){const{clientToken:e,initializationData:t}=this.paymentMethod||{};if(!e||!t)throw new R(W.MissingPaymentMethod);try{this.braintreeIntegrationService.initialize(e),yield this.braintreeIntegrationService.getPaypal()}catch(e){this.handleError(e)}return Promise.resolve()})}handleError(e){if(!_e(e))throw e;if("PAYPAL_POPUP_CLOSED"===e.code)throw new Be(e.message);throw new q(e.message)}isProviderError(e){var t,n,i;return!!function(e){return"object"==typeof e&&null!==e&&"errors"in e}(e)&&"2046"===(null==(i=null==(n=((null==(t=null==e?void 0:e.errors)?void 0:t.filter(e=>e.provider_error))||[])[0])?void 0:n.provider_error)?void 0:i.code)}removeElement(e){const t=e&&document.getElementById(e);t&&t.remove()}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}getSmartButtonContainerId(e){var t;return null!=(t=e.split("#")[1])?t:e}}const $e=V(t=>{const n=window,i=new Pe,r=new F(t),o=new Me(new I(e(),n,r),n,i),a=new Se(t);return new Je(t,o,a,new Le({containerStyles:je}))},[{id:"braintreepaypal"},{id:"braintreepaypalcredit"}]);var Xe=(e=>(e.Json="application/json",e.JsonV1="application/vnd.bc.v1+json",e))(Xe||{});const Ke=Xe,et={"X-Checkout-SDK-Version":"1.983.4"};var tt=Object.defineProperty,nt=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,ot=(e,t,n)=>t in e?tt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,at=(e,t)=>{for(var n in t||(t={}))it.call(t,n)&&ot(e,n,t[n]);if(nt)for(var n of nt(t))rt.call(t,n)&&ot(e,n,t[n]);return e};class st{constructor(e){this.requestSender=e}getOrderStatus(e="braintreelocalmethods",t){return n=this,i=function*(){const n=`/api/storefront/initialization/${e}`,i=at({"X-API-INTERNAL":"This API endpoint is for internal use only and may change in the future","Content-Type":Ke.Json},et);return(yield this.requestSender.get(n,at({headers:i},t))).body},new Promise((e,t)=>{var r=e=>{try{a(i.next(e))}catch(e){t(e)}},o=e=>{try{a(i.throw(e))}catch(e){t(e)}},a=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,o);a((i=i.apply(n,null)).next())});var n,i}}const lt={body:{},headers:{},status:0};class dt extends h{constructor(e,{message:t,errors:n}={}){const{body:i,headers:r,status:o}=e||lt;super(t||"An unexpected error has occurred."),this.name="RequestError",this.type="request",this.body=i,this.headers=r,this.status=o,this.errors=n||[]}}class ct extends dt{constructor(e){super(e,{message:"There is a problem processing your payment. Please try again later."}),this.name="PaymentMethodInvalidError",this.type="payment_method_invalid"}}class ut extends dt{constructor(e){super(e,{message:"The request has timed out or aborted."}),this.name="TimeoutError",this.type="timeout"}}var ht=Object.defineProperty,yt=Object.defineProperties,pt=Object.getOwnPropertyDescriptors,mt=Object.getOwnPropertySymbols,gt=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable,vt=(e,t,n)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wt=(e,t)=>{for(var n in t||(t={}))gt.call(t,n)&&vt(e,n,t[n]);if(mt)for(var n of mt(t))bt.call(t,n)&&vt(e,n,t[n]);return e},ft=(e,t)=>yt(e,pt(t)),Ct=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class It{constructor(e,t,n,i,r=3e3,a=3e5){this.paymentIntegrationService=e,this.braintreeSdk=t,this.braintreeRequestSender=n,this.loadingIndicator=i,this.pollingInterval=r,this.maxPollingIntervalTime=a,this.isLPMsUpdateExperimentEnabled=!1,this.pollingTimer=0,this.stopPolling=o,this.isPollingEnabled=!1}initialize(e){return Ct(this,null,function*(){const{gatewayId:t,methodId:n,braintreelocalmethods:i}=e;if(this.gatewayId=t,!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.gatewayId" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreelocalmethods" argument is not provided.');this.braintreelocalmethods=i,this.loadingIndicatorContainer=i.container.split("#")[1],yield this.paymentIntegrationService.loadPaymentMethod(t);const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(t),{clientToken:a,config:s,initializationData:l}=o,d=r.getStoreConfigOrThrow().checkoutSettings.features;if(this.isPollingEnabled=U(d,"PAYPAL-5258.braintree_local_methods_polling"),this.isLPMsUpdateExperimentEnabled=U(d,"PAYPAL-4853.add_new_payment_flow_for_braintree_lpms"),!a||!l||!s.merchantId)throw new R(W.MissingPaymentMethod);try{this.braintreeSdk.initialize(a),this.isNonInstantPaymentMethod(n)||(this.braintreeLocalPayment=yield this.braintreeSdk.getBraintreeLocalPayment(s.merchantId))}catch(e){this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return Ct(this,null,function*(){return this.toggleLoadingIndicator(!1),Promise.resolve()})}execute(e,t){return Ct(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)gt.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&mt)for(var i of mt(e))t.indexOf(i)<0&&bt.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new H(["payment"]);const{methodId:o}=i;this.toggleLoadingIndicator(!0),this.isNonInstantPaymentMethod(o)?yield this.executeWithNotInstantLPM(o):yield this.executeWithInstantLPM(o,r,t)})}executeWithNotInstantLPM(e){return Ct(this,null,function*(){try{const t=yield this.getLPMsBasicPaymentData();yield this.paymentIntegrationService.submitOrder(),yield this.paymentIntegrationService.submitPayment({methodId:e,paymentData:ft(wt({},t),{formattedPayload:{method:e}})})}catch(e){if(this.isBraintreeRedirectError(e)){const t=e.body.additional_action_required.data.redirect_url;return new Promise((e,n)=>{window.location.replace(t),this.toggleLoadingIndicator(!1),n()})}return this.handleError(e),Promise.reject(e)}})}executeWithInstantLPM(e,t,n){return Ct(this,null,function*(){if(!this.braintreeLocalPayment)throw new ct;yield new Promise((i,r)=>{var o;null==(o=this.braintreeLocalPayment)||o.startPayment(this.getInstantLPMConfig(e,t,n),this.getInstantLPMCallback(i,r,e,t,n))})})}getLPMsBasicPaymentData(){return Ct(this,null,function*(){const{deviceData:e}=yield this.braintreeSdk.getDataCollectorOrThrow();return{deviceSessionId:e}})}getInstantLPMConfig(e,t,n){const i=this.paymentIntegrationService.getState(),r=i.getCartOrThrow(),o=i.getBillingAddressOrThrow(),{firstName:a,lastName:s,countryCode:l}=o,{currency:d,email:c,lineItems:u}=r,h=u.physicalItems.length>0,y=i.getCheckoutOrThrow().outstandingBalance,p=i.getStoreConfigOrThrow().links.checkoutLink;return{paymentType:e,amount:y,fallback:{url:p,buttonText:"Complete Payment"},currencyCode:d.code,shippingAddressRequired:h,email:c,givenName:a,surname:s,address:{countryCode:l},onPaymentStart:(i,r)=>Ct(this,null,function*(){if(!this.isLPMsUpdateExperimentEnabled)return this.orderId=i.paymentId,void r();const o=yield this.getLPMsBasicPaymentData(),a=ft(wt({},o),{formattedPayload:{method:e,[`${e}_account`]:{order_id:i.paymentId}}});try{yield this.paymentIntegrationService.submitOrder(t,n),yield this.paymentIntegrationService.submitPayment({methodId:e,paymentData:a})}catch(t){if(this.isBraintreeOrderSavedResponse(t)&&t.body.additional_action_required.data.order_id_saved_successfully)return r(),this.isPollingEnabled?new Promise((t,n)=>{this.initializePollingMechanism(e,t,n,this.gatewayId)}):void 0;throw t}})}}getInstantLPMCallback(e,t,n,i,r){const o=this.paymentIntegrationService.getState().getCartOrThrow();return(a,s)=>Ct(this,null,function*(){if(a)return"LOCAL_PAYMENT_WINDOW_CLOSED"===a.code?(this.toggleLoadingIndicator(!1),this.resetPollingMechanism(),t()):(this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t(new ct));const l=yield this.getLPMsBasicPaymentData(),d=ft(wt({},l),{formattedPayload:{method:n,[`${n}_account`]:wt({email:o.email,token:s.nonce},this.isLPMsUpdateExperimentEnabled?{}:{order_id:this.orderId})}});try{return this.isLPMsUpdateExperimentEnabled||(yield this.paymentIntegrationService.submitOrder(i,r)),yield this.paymentIntegrationService.submitPayment({methodId:n,paymentData:d}),e(void 0)}catch(e){return this.handleError(e),t(e)}})}toggleLoadingIndicator(e){e&&this.loadingIndicatorContainer?this.loadingIndicator.show(this.loadingIndicatorContainer):this.loadingIndicator.hide()}handleError(e){const{onError:t}=this.braintreelocalmethods||{};this.isPollingEnabled&&this.resetPollingMechanism(),this.toggleLoadingIndicator(!1),t&&"function"==typeof t&&t(e)}isNonInstantPaymentMethod(e){return e.toUpperCase()in T}isBraintreeRedirectError(e){var t;if("object"!=typeof e||null===e)return!1;const{body:n}=e;return!!n&&!!(null==(t=n.additional_action_required)?void 0:t.data.redirect_url)}isBraintreeOrderSavedResponse(e){var t;if("object"!=typeof e||null===e)return!1;const{body:n}=e;return!!n&&(null==(t=n.additional_action_required)?void 0:t.data.hasOwnProperty("order_id_saved_successfully"))}initializePollingMechanism(e,t,n,i){return Ct(this,null,function*(){yield new Promise((e,t)=>{const n=setTimeout(e,this.pollingInterval);this.stopPolling=()=>(clearTimeout(n),this.toggleLoadingIndicator(!1),t())});try{this.pollingTimer+=this.pollingInterval;const r=yield this.braintreeRequestSender.getOrderStatus(i,{params:{useMetadata:!1}}),o=r.status===O.Pending,a=r.status===O.Completed,s=r.status===O.Failed;if(a)return this.deinitializePollingMechanism(),t();if(s)return n();if(!a&&o&&this.pollingTimer<this.maxPollingIntervalTime)return yield this.initializePollingMechanism(e,t,n,i);yield this.reinitializeStrategy({methodId:e,gatewayId:i,braintreelocalmethods:this.braintreelocalmethods}),this.handleError(new ut)}catch(e){n()}})}deinitializePollingMechanism(){this.stopPolling(),this.pollingTimer=0}resetPollingMechanism(){this.deinitializePollingMechanism()}reinitializeStrategy(e){return Ct(this,null,function*(){yield this.deinitialize(),yield this.initialize(e)})}}const Mt=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i)),o=c(),a=new st(o);return new It(t,r,a,new Le({styles:{backgroundColor:"black"}}))},[{gateway:"braintreelocalmethods"}]);var St=Object.defineProperty,Pt=Object.getOwnPropertySymbols,Ot=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable,Nt=(e,t,n)=>t in e?St(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function Dt(e){return"string"!=typeof e}function zt(e,t){if(t||e)return function(e){var t,n;const i={},r=s(e.root,Dt),o=s(e.input,Dt),a=s(e.toggle,Dt),l=s(null==(t=e.text)?void 0:t.body,Dt),d=s(null==(n=e.text)?void 0:n.caption,Dt),c=e.branding;return Object.keys(r).length&&(i.root=r),Object.keys(o).length&&(i.input=o),Object.keys(a).length&&(i.toggle=a),Object.keys(l).length&&(i.text={},i.text.body=l),Object.keys(d).length&&(i.text=((e,t)=>{for(var n in t||(t={}))Ot.call(t,n)&&Nt(e,n,t[n]);if(Pt)for(var n of Pt(t))Tt.call(t,n)&&Nt(e,n,t[n]);return e})({},i.text),i.text.caption=d),c&&(i.branding=c),i}(function(e,t){var n,i,r,o,a,s,l,d,c,u,h,y,p,m,g,b,v,w,f,C,I,M;return{root:{backgroundColorPrimary:(null==e?void 0:e.fastlaneRootSettingsBackgroundColor)||(null==(n=null==t?void 0:t.root)?void 0:n.backgroundColorPrimary),errorColor:(null==e?void 0:e.fastlaneRootSettingsErrorColor)||(null==(i=null==t?void 0:t.root)?void 0:i.errorColor),fontFamily:(null==e?void 0:e.fastlaneRootSettingsFontFamily)||(null==(r=null==t?void 0:t.root)?void 0:r.fontFamily),fontSizeBase:(null==e?void 0:e.fastlaneRootSettingsFontSize)||(null==(o=null==t?void 0:t.root)?void 0:o.fontSizeBase),padding:(null==e?void 0:e.fastlaneRootSettingsPadding)||(null==(a=null==t?void 0:t.root)?void 0:a.padding),primaryColor:(null==e?void 0:e.fastlaneRootSettingsPrimaryColor)||(null==(s=null==t?void 0:t.root)?void 0:s.primaryColor)},input:{borderRadius:(null==e?void 0:e.fastlaneInputSettingsBorderRadius)||(null==(l=null==t?void 0:t.input)?void 0:l.borderRadius),borderColor:(null==e?void 0:e.fastlaneInputSettingsBorderColor)||(null==(d=null==t?void 0:t.input)?void 0:d.borderColor),focusBorderColor:(null==e?void 0:e.fastlaneInputSettingsFocusBorderBase)||(null==(c=null==t?void 0:t.input)?void 0:c.focusBorderColor),backgroundColor:(null==e?void 0:e.fastlaneInputSettingsBackgroundColor)||(null==(u=null==t?void 0:t.input)?void 0:u.backgroundColor),borderWidth:(null==e?void 0:e.fastlaneInputSettingsBorderWidth)||(null==(h=null==t?void 0:t.input)?void 0:h.borderWidth),textColorBase:(null==e?void 0:e.fastlaneInputSettingsTextColorBase)||(null==(y=null==t?void 0:t.input)?void 0:y.textColorBase)},toggle:{colorPrimary:(null==e?void 0:e.fastlaneToggleSettingsColorPrimary)||(null==(p=null==t?void 0:t.toggle)?void 0:p.colorPrimary),colorSecondary:(null==e?void 0:e.fastlaneToggleSettingsColorSecondary)||(null==(m=null==t?void 0:t.toggle)?void 0:m.colorSecondary)},text:{body:{color:(null==e?void 0:e.fastlaneTextBodySettingsColor)||(null==(b=null==(g=null==t?void 0:t.text)?void 0:g.body)?void 0:b.color),fontSize:(null==e?void 0:e.fastlaneTextBodySettingsFontSize)||(null==(w=null==(v=null==t?void 0:t.text)?void 0:v.body)?void 0:w.fontSize)},caption:{color:(null==e?void 0:e.fastlaneTextCaptionSettingsColor)||(null==(C=null==(f=null==t?void 0:t.text)?void 0:f.caption)?void 0:C.color),fontSize:(null==e?void 0:e.fastlaneTextCaptionSettingsFontSize)||(null==(M=null==(I=null==t?void 0:t.text)?void 0:I.caption)?void 0:M.fontSize)}},branding:(null==e?void 0:e.fastlaneBrandingSettings)||(null==t?void 0:t.branding)}}(e,t))}function Et(e){return!!e&&("authenticationState"in e||"addresses"in e||"instruments"in e)}var kt=Object.defineProperty,At=Object.defineProperties,Lt=Object.getOwnPropertyDescriptors,jt=Object.getOwnPropertySymbols,xt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable,_t=(e,t,n)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ut=(e,t)=>{for(var n in t||(t={}))xt.call(t,n)&&_t(e,n,t[n]);if(jt)for(var n of jt(t))Bt.call(t,n)&&_t(e,n,t[n]);return e},Ft=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Vt{constructor(e,t,n){this.paymentIntegrationService=e,this.braintreeFastlaneUtils=t,this.braintreeSdk=n}initialize(e){return Ft(this,null,function*(){var t;const{methodId:n,braintreefastlane:i}=e;if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreefastlane" argument is not provided.');if(!i.onInit||"function"!=typeof i.onInit)throw new Y('Unable to initialize payment because "options.braintreefastlane.onInit" argument is not provided or it is not a function.');if(!i.onChange||"function"!=typeof i.onChange)throw new Y('Unable to initialize payment because "options.braintreefastlane.onChange" argument is not provided or it is not a function.');yield this.paymentIntegrationService.loadPaymentMethod(n);const r=this.paymentIntegrationService.getState(),o=r.getPaymentMethodOrThrow(n),{initializationData:a,clientToken:s}=o||{},{isFastlaneStylingEnabled:l}=a||{},d=U(r.getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.braintree_fastlane_three_ds");this.is3DSEnabled=o.config.is3dsEnabled,s&&d&&this.braintreeSdk.initialize(s);const c=zt(l?null==(t=o.initializationData)?void 0:t.fastlaneStyles:void 0,i.styles);yield this.braintreeFastlaneUtils.initializeBraintreeFastlaneOrThrow(n,c),this.shouldRunAuthenticationFlow()&&(yield this.braintreeFastlaneUtils.runPayPalAuthenticationFlowOrThrow(void 0,void 0,i)),yield this.initializeCardComponent(),this.onError=i.onError,i.onInit(e=>this.renderBraintreeCardComponent(e)),i.onChange(()=>this.handleBraintreeStoredInstrumentChange(n))})}execute(e,t){return Ft(this,null,function*(){const n=e,{payment:i}=n,r=((e,t)=>{var n={};for(var i in e)xt.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&jt)for(var i of jt(e))t.indexOf(i)<0&&Bt.call(e,i)&&(n[i]=e[i]);return n})(n,["payment"]);if(!i)throw new H(["payment"]);yield this.paymentIntegrationService.submitOrder(r,t);const o=yield this.preparePaymentPayload(i.methodId);yield this.paymentIntegrationService.submitPayment(o),this.braintreeFastlaneUtils.removeSessionIdFromCookies()})}finalize(){return Promise.reject(new Q)}deinitialize(){return Ft(this,null,function*(){return this.braintreeCardComponent=void 0,Promise.resolve()})}initializeCardComponent(){return Ft(this,null,function*(){const e=this.paymentIntegrationService.getState(),{phone:t,firstName:n,lastName:i}=e.getBillingAddressOrThrow(),r={styles:{},fields:Ut({cardholderName:{prefill:`${n} ${i}`,enabled:!0}},t&&{phoneNumber:{prefill:t}})},o=this.braintreeFastlaneUtils.getBraintreeFastlaneComponentOrThrow();this.braintreeCardComponent=yield o(r)})}renderBraintreeCardComponent(e){const t=this.getBraintreeCardComponentOrThrow();if(!e)throw new Y('Unable to initialize payment because "container" argument is not provided.');t.render(e)}preparePaymentPayload(e){return Ft(this,null,function*(){var t,n;const i=this.paymentIntegrationService.getState(),r=i.getBillingAddressOrThrow(),o=`${r.firstName} ${r.lastName}`,a=this.getPayPalInstruments()[0],s=yield this.braintreeFastlaneUtils.getDeviceSessionId(),l=U(i.getStoreConfigOrThrow().checkoutSettings.features,"PROJECT-7080.braintree_fastlane_three_ds");if(a){const t=this.is3DSEnabled&&l?yield this.get3DS(a.bigpayToken,(null==a?void 0:a.iin)||""):void 0;return{methodId:e,paymentData:{deviceSessionId:s,formattedPayload:{paypal_fastlane_token:{token:t||a.bigpayToken}}}}}const{getPaymentToken:d}=this.getBraintreeCardComponentOrThrow(),c=yield d({name:{fullName:o},billingAddress:this.mapToPayPalAddress(r)}),u=(null==(n=null==(t=c.paymentSource.card)?void 0:t.binDetails)?void 0:n.bin)||"",h=this.is3DSEnabled&&l?yield this.get3DS(c.id,u):void 0;return{methodId:e,paymentData:{deviceSessionId:s,nonce:h||c.id}}})}get3DS(e,t){return Ft(this,null,function*(){const n=this.paymentIntegrationService.getState(),i=yield this.braintreeSdk.getBraintreeThreeDS(),r=n.getOrderOrThrow();return new Promise((n,o)=>{i.verifyCard({amount:null==r?void 0:r.orderAmount,nonce:e,bin:t,onLookupComplete:(e,t)=>{i.on("customer-canceled",()=>{"function"==typeof this.onError&&this.onError(new Be),o(new Be)}),t()}},(e,t)=>(e&&"THREEDS_VERIFY_CARD_CANCELED_BY_MERCHANT"===e.code&&("function"==typeof this.onError&&this.onError(new Be),o(new Be)),n(t.nonce)))})})}mapToPayPalAddress(e){return{streetAddress:(null==e?void 0:e.address1)||"",locality:(null==e?void 0:e.city)||"",region:(null==e?void 0:e.stateOrProvinceCode)||(null==e?void 0:e.stateOrProvince)||"",postalCode:(null==e?void 0:e.postalCode)||"",countryCodeAlpha2:(null==e?void 0:e.countryCode)||""}}shouldRunAuthenticationFlow(){const e=this.paymentIntegrationService.getState(),t=e.getCartOrThrow(),n=e.getCustomerOrThrow(),i=e.getPaymentProviderCustomer(),r=Et(i)?i:{},o=this.braintreeFastlaneUtils.getSessionIdFromCookies();return!(!n.isGuest||(null==r?void 0:r.authenticationState)===N.CANCELED||(null==r?void 0:r.authenticationState)||o!==t.id)}getBraintreeCardComponentOrThrow(){if(!this.braintreeCardComponent)throw new y;return this.braintreeCardComponent}getPayPalInstruments(){const e=this.paymentIntegrationService.getState().getPaymentProviderCustomerOrThrow();return(Et(e)?e:{}).instruments||[]}handleBraintreeStoredInstrumentChange(e){return Ft(this,null,function*(){const t=this.braintreeFastlaneUtils.getBraintreeFastlaneOrThrow(),{selectionChanged:n,selectedCard:i}=yield t.profile.showCardSelector();if(n){const t=this.paymentIntegrationService.getState().getPaymentProviderCustomer(),n=Et(t)?t:{},a=this.braintreeFastlaneUtils.mapPayPalToBcInstrument(e,[i]);if(a&&a.length>0)return yield this.paymentIntegrationService.updatePaymentProviderCustomer((r=Ut({},n),o={instruments:[...a]},At(r,Lt(o)))),a[0]}var r,o})}}var Yt=(e=>(e.CVV="cvv",e.PAN="pan",e))(Yt||{}),Wt=Object.defineProperty,Rt=Object.getOwnPropertySymbols,Ht=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable,Qt=(e,t,n)=>t in e?Wt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;class Zt{static get(e){const t=`${encodeURIComponent(`${e}`)}=`,n=document.cookie;let i=null;const r=n.indexOf(t);if(r>-1){let e=n.indexOf(";",r);-1===e&&(e=n.length),i=decodeURIComponent(n.substring(r+t.length,e))}return i}static set(e,t,n={secure:!0}){let i=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;const{expires:r,path:o,domain:a,secure:s}=n;if(r)i+=`; expires=${r.toUTCString()}`;else{const e=new Date,t=60;e.setTime(e.getTime()+60*t*1e3),i+=`; expires=${e.toUTCString()}`}o&&(i+=`; path=${o}`),a&&(i+=`; domain=${a}`),s&&(i+="; secure"),document.cookie=i}static remove(e,t){Zt.set(e,"",((e,t)=>{for(var n in t||(t={}))Ht.call(t,n)&&Qt(e,n,t[n]);if(Rt)for(var n of Rt(t))Gt.call(t,n)&&Qt(e,n,t[n]);return e})({expires:new Date(0)},t))}}var qt=Object.defineProperty,Jt=Object.defineProperties,$t=Object.getOwnPropertyDescriptors,Xt=Object.getOwnPropertySymbols,Kt=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,tn=(e,t,n)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nn=(e,t)=>{for(var n in t||(t={}))Kt.call(t,n)&&tn(e,n,t[n]);if(Xt)for(var n of Xt(t))en.call(t,n)&&tn(e,n,t[n]);return e},rn=(e,t)=>Jt(e,$t(t)),on=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class an{constructor(e,t){this.paymentIntegrationService=e,this.braintreeIntegrationService=t}getDeviceSessionId(){return on(this,null,function*(){const e=this.paymentIntegrationService.getState().getCart();return this.braintreeIntegrationService.getSessionId(null==e?void 0:e.id)})}initializeBraintreeFastlaneOrThrow(e,t){return on(this,null,function*(){const n=this.paymentIntegrationService.getState(),i=n.getCart(),{clientToken:r,config:o}=n.getPaymentMethodOrThrow(e);if(!r)throw new R(W.MissingPaymentMethod);this.methodId=e,this.braintreeIntegrationService.initialize(r),this.braintreeFastlane=yield this.braintreeIntegrationService.getBraintreeFastlane(null==i?void 0:i.id,o.testMode,t)})}getBraintreeFastlaneOrThrow(){if(!this.braintreeFastlane)throw new y;return this.braintreeFastlane}getBraintreeFastlaneComponentOrThrow(){return this.getBraintreeFastlaneOrThrow().FastlaneCardComponent}runPayPalAuthenticationFlowOrThrow(e,t,n){return on(this,null,function*(){var i;try{const n=this.getMethodIdOrThrow(),r=this.getBraintreeFastlaneOrThrow(),{lookupCustomerByEmail:o,triggerAuthenticationFlow:a}=r.identity,s=this.paymentIntegrationService.getState(),l=s.getCartOrThrow(),d=s.getCustomer(),c=s.getBillingAddress(),{isFastlaneShippingOptionAutoSelectEnabled:u}=s.getPaymentMethodOrThrow(n).initializationData||{},h=e||(null==d?void 0:d.email)||(null==c?void 0:c.email)||"",{customerContextId:y}=yield o(h);if(!y)return yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:N.UNRECOGNIZED,addresses:[],instruments:[]}),void this.saveSessionIdToCookies(l.id);const{authenticationState:p,profileData:m}=yield a(y),g=(null==(i=null==m?void 0:m.shippingAddress)?void 0:i.phoneNumber)||"";if(p===N.CANCELED||!m)return yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:p,addresses:[],instruments:[]}),void this.removeSessionIdFromCookies();const b=this.mapPayPalToBcAddress([m.shippingAddress],[g])||[],v=this.getPayPalBillingAddresses(m),w=v?this.mapPayPalToBcAddress([v],[g]):[],f=m.card?this.mapPayPalToBcInstrument(n,[m.card]):[],C=this.mergeShippingAndBillingAddresses(b,w);if(this.saveSessionIdToCookies(l.id),yield this.paymentIntegrationService.updatePaymentProviderCustomer({authenticationState:p,addresses:C,instruments:f}),w.length>0&&l.lineItems.physicalItems.length>0&&(yield this.paymentIntegrationService.updateBillingAddress(w[0])),w.length>0&&l.lineItems.digitalItems.length>0&&0===l.lineItems.physicalItems.length){const{firstName:e,lastName:t}=C[0],n=rn(nn({},w[0]),{firstName:e,lastName:t});yield this.paymentIntegrationService.updateBillingAddress(n)}b.length>0&&l.lineItems.physicalItems.length>0&&(yield this.paymentIntegrationService.updateShippingAddress(b[0]),t&&u&&(yield this.setShippingOption()))}catch(e){this.handleErrorLog(e,n)}})}getSessionIdFromCookies(){return Zt.get("bc-fastlane-sessionId")||""}saveSessionIdToCookies(e){const t=new Date;t.setDate(t.getDate()+14),Zt.set("bc-fastlane-sessionId",e,{expires:t,secure:!0})}removeSessionIdFromCookies(){Zt.remove("bc-fastlane-sessionId")}mapPayPalToBcInstrument(e,t){if(t)return t.map(t=>{const{id:n,paymentSource:i}=t,{brand:r,expiry:o,lastDigits:a,binDetails:s}=i.card,[l,d]=o.split("-");return{bigpayToken:n,brand:r,defaultInstrument:!1,expiryMonth:d,expiryYear:l,iin:(null==s?void 0:s.bin)||"",last4:a,method:e,provider:e,trustedShippingAddress:!1,type:"card",untrustedShippingCardVerificationMode:Yt.PAN}})}mapPayPalToBcAddress(e,t){if(!e)return[];const n=this.paymentIntegrationService.getState().getCountries()||[],i=e=>{const t=n.find(t=>t.code===e);return(null==t?void 0:t.name)||""};return e.map(e=>({id:Date.now(),type:"paypal-address",firstName:e.firstName||"",lastName:e.lastName||"",company:e.company||"",address1:e.streetAddress,address2:e.extendedAddress||"",city:e.locality,stateOrProvince:e.region,stateOrProvinceCode:e.region,country:i(e.countryCodeAlpha2),countryCode:e.countryCodeAlpha2,postalCode:e.postalCode,phone:t&&t[0]||"",customFields:[]}))}getPayPalBillingAddresses(e){const{card:t,name:n}=e||{};if(!t)return;const{firstName:r,lastName:o}=t.paymentSource.card.billingAddress,{firstName:a,lastName:s}=n||{},{shippingAddress:l}=e||{},d=rn(nn({},t.paymentSource.card.billingAddress),{firstName:r||a,lastName:o||s});return l&&i(this.normalizeAddress(d),this.normalizeAddress(l))?l:d}normalizeAddress(e){return a(e,["id"])}mergeShippingAndBillingAddresses(e,t){const n=t.filter(t=>!e.some(e=>i(this.normalizeAddress(e),this.normalizeAddress(t))));return[...e,...n]}getMethodIdOrThrow(){if(!this.methodId)throw new Y('Unable to proceed because "methodId" argument is not provided.');return this.methodId}setShippingOption(){return on(this,null,function*(){var e;const t=(null==(e=(this.paymentIntegrationService.getState().getConsignments()||[])[0])?void 0:e.availableShippingOptions)||[],n=t.find(e=>e.isRecommended);if(n||t.length){const e=n||t[0];yield this.paymentIntegrationService.selectShippingOption(e.id)}})}handleErrorLog(e,t){(null==t?void 0:t.onErrorLog)&&"function"==typeof t.onErrorLog&&t.onErrorLog(e)}}const sn=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n),o=new an(t,r),a=new I(e(),n,i),s=new _(a);return new Vt(t,o,s)},[{id:"braintreeacceleratedcheckout"}]);var ln=Object.defineProperty,dn=Object.defineProperties,cn=Object.getOwnPropertyDescriptors,un=Object.getOwnPropertySymbols,hn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,pn=(e,t,n)=>t in e?ln(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mn=(e,t)=>{for(var n in t||(t={}))hn.call(t,n)&&pn(e,n,t[n]);if(un)for(var n of un(t))yn.call(t,n)&&pn(e,n,t[n]);return e},gn=(e,t)=>dn(e,cn(t)),bn=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class vn{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n}initialize(e){return bn(this,null,function*(){const{braintreevisacheckout:t,methodId:n}=e;if(!t)throw new Y('Unable to initialize payment because "options.braintreevisacheckout" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState();this.paymentMethod=i.getPaymentMethodOrThrow(n);const r=i.getCheckoutOrThrow(),a=i.getStoreConfigOrThrow(),{clientToken:s,config:l}=this.paymentMethod||{};if(!s)throw new R(W.MissingPaymentMethod);const{onError:d=o,onPaymentSelect:c=o}=t;this.braintreeSdk.initialize(s);const u=yield this.braintreeSdk.getBraintreeVisaCheckout(),h=yield this.braintreeSdk.getVisaCheckoutSdk(null==l?void 0:l.testMode),y=u.createInitOptions({settings:{locale:a.storeProfile.storeLanguage,shipping:{collectShipping:!1}},paymentRequest:{currencyCode:a.currency.code,subtotal:String(r.subtotal)}});yield h.init(y),h.on("payment.success",e=>this.tokenizePayment(u,e).then(()=>Promise.all([this.paymentIntegrationService.loadCheckout(),this.paymentIntegrationService.loadPaymentMethod(n)])).then(()=>c()).catch(e=>d(e))),h.on("payment.error",(e,t)=>d(t))})}execute(e,t){return bn(this,null,function*(){var n,i;const r=e,{payment:o}=r,a=((e,t)=>{var n={};for(var i in e)hn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&un)for(var i of un(e))t.indexOf(i)<0&&yn.call(e,i)&&(n[i]=e[i]);return n})(r,["payment"]);if(!o)throw new Y('Unable to submit payment because "payload.payment" argument is not provided.');if(!(null==(i=null==(n=this.paymentMethod)?void 0:n.initializationData)?void 0:i.nonce))throw new R(W.MissingPaymentMethod);const{nonce:s}=this.paymentMethod.initializationData;try{yield this.paymentIntegrationService.submitOrder(a,t),yield this.paymentIntegrationService.submitPayment(gn(mn({},o),{paymentData:{nonce:s}}))}catch(e){this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return bn(this,null,function*(){yield this.braintreeSdk.deinitialize()})}tokenizePayment(e,t){return bn(this,null,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.mapToVisaCheckoutAddress(i),billingAddress:a=this.mapToVisaCheckoutAddress(r)}=e;return this.postForm(gn(mn({},e),{shippingAddress:o,billingAddress:a}),t)})})}mapToVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}handleError(e){if(e instanceof Error&&"BraintreeError"===e.name)throw new q(e.message);throw e}}const wn=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i));return new vn(t,u(),r)},[{id:"braintreevisacheckout"}]);var fn=Object.defineProperty,Cn=Object.defineProperties,In=Object.getOwnPropertyDescriptors,Mn=Object.getOwnPropertySymbols,Sn=Object.prototype.hasOwnProperty,Pn=Object.prototype.propertyIsEnumerable,On=(e,t,n)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Tn=(e,t)=>{for(var n in t||(t={}))Sn.call(t,n)&&On(e,n,t[n]);if(Mn)for(var n of Mn(t))Pn.call(t,n)&&On(e,n,t[n]);return e},Nn=(e,t)=>Cn(e,In(t)),Dn=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class zn{constructor(e,t){this.paymentIntegrationService=e,this.braintreeIntegrationService=t}initialize(e){return Dn(this,null,function*(){const{methodId:t}=e;yield this.paymentIntegrationService.loadPaymentMethod(t);const n=this.paymentIntegrationService.getState();this.venmoOptions=e.braintreevenmo;const i=n.getPaymentMethodOrThrow(t);yield this.initializeBraintreeVenmo(i)})}execute(e){return Dn(this,null,function*(){const t=e,{payment:n}=t,i=((e,t)=>{var n={};for(var i in e)Sn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Mn)for(var i of Mn(e))t.indexOf(i)<0&&Pn.call(e,i)&&(n[i]=e[i]);return n})(t,["payment"]);if(!n)throw new H(["payment"]);try{const e=yield this.preparePaymentData(n);yield this.paymentIntegrationService.submitOrder(i),yield this.paymentIntegrationService.submitPayment(e)}catch(e){this.handleError(e)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return Dn(this,null,function*(){return yield this.braintreeIntegrationService.teardown(),Promise.resolve()})}handleError(e){if(!E(e))throw e;if("PAYPAL_POPUP_CLOSED"===e.code)throw new Be(e.message);throw new q(e.message)}initializeBraintreeVenmo(e){return Dn(this,null,function*(){var t;const{clientToken:n}=e;if(!n)throw new R(W.MissingPaymentMethod);const i=U(this.paymentIntegrationService.getState().getStoreConfigOrThrow().checkoutSettings.features,"PAYPAL-5406.braintree_venmo_web_fallback_support");try{this.braintreeIntegrationService.initialize(n),this.braintreeVenmoCheckout=yield this.braintreeIntegrationService.getVenmoCheckout(Tn(Tn({},void 0!==(null==(t=this.venmoOptions)?void 0:t.allowDesktop)?{allowDesktop:this.venmoOptions.allowDesktop}:{}),i?{mobileWebFallBack:i}:{}))}catch(e){this.handleError(e)}})}preparePaymentData(e){return Dn(this,null,function*(){const t=this.paymentIntegrationService.getState(),{nonce:n}=t.getPaymentMethodOrThrow(e.methodId);if(n)return Nn(Tn({},e),{paymentData:this.formattedPayload(n)});const i=yield this.braintreeVenmoTokenize(),r=yield this.braintreeIntegrationService.getSessionId();return Nn(Tn({},e),{paymentData:this.formattedPayload(i.nonce,i.details.email,r)})})}formattedPayload(e,t,n){return{formattedPayload:{vault_payment_instrument:null,set_as_default_stored_instrument:null,device_info:n||null,paypal_account:{token:e,email:t||null}}}}braintreeVenmoTokenize(){return new Promise((e,t)=>{var n;null==(n=this.braintreeVenmoCheckout)||n.tokenize((n,i)=>{if(n)return t(n);e(i)})})}}const En=V(t=>{const n=window,i=e(),r=new F(t),o=new I(i,n,r),a=new Me(o,n);return new zn(t,a)},[{id:"braintreevenmo"}]);function kn(e){return"cardNumber"in e}function An(e){if(!E(e))return!1;const{details:t}=e;return void 0===t||"object"==typeof t&&null!==t&&void 0===t.invalidFieldKeys||(n=t,Array.isArray(n)&&n.every(e=>"string"==typeof e));var n}var Ln=Object.defineProperty,jn=Object.defineProperties,xn=Object.getOwnPropertyDescriptors,Bn=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Un=Object.prototype.propertyIsEnumerable,Fn=(e,t,n)=>t in e?Ln(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vn=(e,t)=>{for(var n in t||(t={}))_n.call(t,n)&&Fn(e,n,t[n]);if(Bn)for(var n of Bn(t))Un.call(t,n)&&Fn(e,n,t[n]);return e},Yn=(e,t)=>jn(e,xn(t)),Wn=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Rn{constructor(e,t){this.braintreeScriptLoader=e,this.braintreeSDKVersionManager=t,this.isInitializedHostedForm=!1,this.handleBlur=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onBlur)||n.call(t,{fieldType:this.mapFieldType(e.emittedBy),errors:this.mapErrors(e.fields)})},this.handleFocus=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onFocus)||n.call(t,{fieldType:this.mapFieldType(e.emittedBy)})},this.handleCardTypeChange=e=>{var t,n;const i=1===e.cards.length?e.cards[0].type.replace(/^master-card$/,"mastercard"):void 0;null==(n=null==(t=this.formOptions)?void 0:t.onCardTypeChange)||n.call(t,{cardType:i})},this.handleInputSubmitRequest=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onEnter)||n.call(t,{fieldType:this.mapFieldType(e.emittedBy)})},this.handleValidityChange=e=>{var t,n;null==(n=null==(t=this.formOptions)?void 0:t.onValidate)||n.call(t,{isValid:this.isValidForm(e),errors:this.mapValidationErrors(e.fields)})}}initialize(e,t,i){return Wn(this,null,function*(){var r,o,a,s,l;this.clientToken=i,this.formOptions=e,this.type=kn(e.fields)?0:1;const d=this.mapFieldOptions(e.fields,t);n(d)?this.isInitializedHostedForm=!1:(this.cardFields=yield this.createHostedFields({fields:d,styles:e.styles&&this.mapStyleOptions(e.styles)}),null==(r=this.cardFields)||r.on("blur",this.handleBlur),null==(o=this.cardFields)||o.on("focus",this.handleFocus),null==(a=this.cardFields)||a.on("cardTypeChange",this.handleCardTypeChange),null==(s=this.cardFields)||s.on("validityChange",this.handleValidityChange),null==(l=this.cardFields)||l.on("inputSubmitRequest",this.handleInputSubmitRequest),this.isInitializedHostedForm=!0)})}isInitialized(){return!!this.isInitializedHostedForm}deinitialize(){return Wn(this,null,function*(){var e;this.isInitializedHostedForm&&(this.isInitializedHostedForm=!1,yield null==(e=this.cardFields)?void 0:e.teardown())})}validate(){if(!this.cardFields)throw new P(S.PaymentNotInitialized);const e=this.cardFields.getState();if(!this.isValidForm(e)){this.handleValidityChange(e);const t=this.mapValidationErrors(e.fields);throw new le(t)}}tokenize(e){return Wn(this,null,function*(){var t,n,i,o,a;if(!this.cardFields)throw new P(S.PaymentNotInitialized);try{const o=yield this.cardFields.tokenize(s({billingAddress:e&&this.mapBillingAddress(e)},r));return null==(n=null==(t=this.formOptions)?void 0:t.onValidate)||n.call(t,{isValid:!0,errors:{}}),{nonce:o.nonce,bin:null==(i=o.details)?void 0:i.bin}}catch(e){if(An(e)){const t=this.mapTokenizeError(e);if(t)throw null==(a=null==(o=this.formOptions)?void 0:o.onValidate)||a.call(o,{isValid:!1,errors:t}),new le(t)}throw e}})}tokenizeForStoredCardVerification(){return Wn(this,null,function*(){var e,t,n,i,r;if(!this.cardFields)throw new P(S.PaymentNotInitialized);try{const i=yield this.cardFields.tokenize();return null==(t=null==(e=this.formOptions)?void 0:e.onValidate)||t.call(e,{isValid:!0,errors:{}}),{nonce:i.nonce,bin:null==(n=i.details)?void 0:n.bin}}catch(e){if(An(e)){const t=this.mapTokenizeError(e,!0);if(t)throw null==(r=null==(i=this.formOptions)?void 0:i.onValidate)||r.call(i,{isValid:!1,errors:t}),new le(t)}throw e}})}createHostedFields(e){return Wn(this,null,function*(){const t=yield this.getClient(),n=yield this.braintreeScriptLoader.loadHostedFields(),i=this.braintreeSDKVersionManager.getSDKVersion()===b?Yn(Vn({},e),{preventCursorJumps:!0}):e;return n.create(Yn(Vn({},i),{client:t}))})}getClient(){return Wn(this,null,function*(){if(!this.clientToken)throw new P(S.PaymentNotInitialized);if(!this.client){const e=yield this.braintreeScriptLoader.loadClient();this.client=e.create({authorization:this.clientToken})}return this.client})}mapBillingAddress(e){return{countryName:e.country,postalCode:e.postalCode,streetAddress:e.address2?`${e.address1} ${e.address2}`:e.address1}}mapFieldOptions(e,t){if(kn(e)){const n={};return null==t||t.forEach(e=>{(e=>Object.values(z).includes(e))(e)&&(n[e]=!1)}),s({number:Vn({container:`#${e.cardNumber.containerId}`,placeholder:e.cardNumber.placeholder,internalLabel:e.cardNumber.accessibilityLabel},Object.keys(n).length>0?{supportedCardBrands:n}:{}),expirationDate:{container:`#${e.cardExpiry.containerId}`,placeholder:e.cardExpiry.placeholder,internalLabel:e.cardExpiry.accessibilityLabel},cvv:e.cardCode&&{container:`#${e.cardCode.containerId}`,placeholder:e.cardCode.placeholder,internalLabel:e.cardCode.accessibilityLabel},cardholderName:{container:`#${e.cardName.containerId}`,placeholder:e.cardName.placeholder,internalLabel:e.cardName.accessibilityLabel}},r)}return s({number:e.cardNumberVerification&&{container:`#${e.cardNumberVerification.containerId}`,placeholder:e.cardNumberVerification.placeholder},cvv:e.cardCodeVerification&&{container:`#${e.cardCodeVerification.containerId}`,placeholder:e.cardCodeVerification.placeholder}},r)}mapStyleOptions(e){const t=(e={})=>s({color:e.color,"font-family":e.fontFamily,"font-size":e.fontSize,"font-weight":e.fontWeight},r);return{input:t(e.default),".invalid":t(e.error),":focus":t(e.focus)}}mapFieldType(e){switch(e){case"number":return 1===this.type?g.CardNumberVerification:g.CardNumber;case"expirationDate":return g.CardExpiry;case"cvv":return 1===this.type?g.CardCodeVerification:g.CardCode;case"cardholderName":return g.CardName;default:throw new Error("Unexpected field type")}}mapErrors(e){const t={};if(e)for(const[n,i]of Object.entries(e))if(i&&this.isValidParam(n)){const{isValid:e,isEmpty:r,isPotentiallyValid:o}=i;t[n]={isValid:e,isEmpty:r,isPotentiallyValid:o}}return t}mapValidationErrors(e){return Object.keys(e).reduce((t,n)=>{var i;return Yn(Vn({},t),{[this.mapFieldType(n)]:(null==(i=e[n])?void 0:i.isValid)?void 0:[this.createInvalidError(this.mapFieldType(n))]})},{})}mapTokenizeError(e,t=!1){var n,i;if("HOSTED_FIELDS_FIELDS_EMPTY"===e.code){const e=[this.createRequiredError(this.mapFieldType("cvv"))];return t?{[this.mapFieldType("cvv")]:e}:{[this.mapFieldType("cvv")]:e,[this.mapFieldType("expirationDate")]:[this.createRequiredError(this.mapFieldType("expirationDate"))],[this.mapFieldType("number")]:[this.createRequiredError(this.mapFieldType("number"))],[this.mapFieldType("cardholderName")]:[this.createRequiredError(this.mapFieldType("cardholderName"))]}}return null==(i=null==(n=e.details)?void 0:n.invalidFieldKeys)?void 0:i.reduce((e,t)=>{const n=this.mapFieldType(t);return Yn(Vn({},e),{[n]:[this.createInvalidError(n)]})},{})}createRequiredError(e){var t;return{fieldType:e,message:null!=(t={[g.CardCode]:"CVV is required",[g.CardCodeVerification]:"CVV is required",[g.CardNumber]:"Credit card number is required",[g.CardNumberVerification]:"Credit card number is required",[g.CardExpiry]:"Expiration date is required",[g.CardName]:"Full name is required"}[e])?t:"Field is required",type:"required"}}createInvalidError(e){var t,n,i,r;const o={[g.CardCode]:{message:"Invalid card code",type:"invalid_card_code"},[g.CardCodeVerification]:{message:"Invalid card code",type:"invalid_card_code"},[g.CardNumber]:{message:"Invalid card number",type:"invalid_card_number"},[g.CardNumberVerification]:{message:"Invalid card number",type:"invalid_card_number"},[g.CardExpiry]:{message:"Invalid card expiry",type:"invalid_card_expiry"},[g.CardName]:{message:"Invalid card name",type:"invalid_card_name"}};return{fieldType:e,message:null!=(n=null==(t=o[e])?void 0:t.message)?n:"Invalid field",type:null!=(r=null==(i=o[e])?void 0:i.type)?r:"invalid"}}isValidForm(e){return Object.keys(e.fields).every(t=>{var n;return null==(n=e.fields[t])?void 0:n.isValid})}isValidParam(e){return["number","cvv","expirationDate","postalCode","cardholderName","cardType"].includes(e)}}var Hn=Object.defineProperty,Gn=Object.defineProperties,Qn=Object.getOwnPropertyDescriptors,Zn=Object.getOwnPropertySymbols,qn=Object.prototype.hasOwnProperty,Jn=Object.prototype.propertyIsEnumerable,$n=(e,t,n)=>t in e?Hn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Xn=(e,t)=>{for(var n in t||(t={}))qn.call(t,n)&&$n(e,n,t[n]);if(Zn)for(var n of Zn(t))Jn.call(t,n)&&$n(e,n,t[n]);return e},Kn=(e,t)=>Gn(e,Qn(t)),ei=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class ti{constructor(e,t,n){this.paymentIntegrationService=e,this.braintreeIntegrationService=t,this.braintreeHostedForm=n}initialize(e){return ei(this,null,function*(){const{methodId:t,gatewayId:n,braintree:i}=e;yield this.paymentIntegrationService.loadPaymentMethod(t);const r=this.paymentIntegrationService.getState();this.paymentMethod=r.getPaymentMethodOrThrow(t);const{clientToken:o}=this.paymentMethod;if(!o)throw new R(W.MissingPaymentMethod);this.threeDSecure=null==i?void 0:i.threeDSecure,this.onPaymentError=null==i?void 0:i.onPaymentError;try{this.braintreeIntegrationService.initialize(o,this.threeDSecure),this.isHostedPaymentFormEnabled(t,n)&&(null==i?void 0:i.form)&&(yield this.braintreeHostedForm.initialize(i.form,i.unsupportedCardBrands,o),this.isHostedFormInitialized=this.braintreeHostedForm.isInitialized()),this.is3dsEnabled=this.paymentMethod.config.is3dsEnabled,this.deviceSessionId=yield this.braintreeIntegrationService.getSessionId(),this.shouldInitializeBraintreeFastlane()&&(yield this.initializeBraintreeFastlaneOrThrow(t))}catch(e){return this.handleError(e,t)}})}execute(e){return ei(this,null,function*(){const t=e,{payment:n}=t,i=((e,t)=>{var n={};for(var i in e)qn.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&Zn)for(var i of Zn(e))t.indexOf(i)<0&&Jn.call(e,i)&&(n[i]=e[i]);return n})(t,["payment"]);if(!n)throw new H(["payment"]);this.isHostedFormInitialized&&this.braintreeHostedForm.validate(),yield this.paymentIntegrationService.submitOrder(i);const r=this.paymentIntegrationService.getState(),o=r.getBillingAddressOrThrow(),a=r.getOrderOrThrow().orderAmount;try{const e=this.isHostedFormInitialized?yield this.prepareHostedPaymentData(n,o,a):yield this.preparePaymentData(n,o,a);yield this.paymentIntegrationService.submitPayment(Kn(Xn({},n),{paymentData:e}))}catch(e){return this.processAdditionalAction(e,n,a)}})}finalize(){return Promise.reject(new Q)}deinitialize(){return ei(this,null,function*(){return this.isHostedFormInitialized=!1,yield Promise.all([this.braintreeIntegrationService.teardown(),this.braintreeHostedForm.deinitialize()]),Promise.resolve()})}handleError(e,t){var n;if(_e(e)){if(!(t&&this.paymentIntegrationService.getState().isPaymentMethodInitialized({methodId:t})||"HOSTED_FIELDS_INVALID_FIELD_SELECTOR"!==e.code))return;if(e.code.startsWith("THREEDS_"))return null==(n=this.onPaymentError)||n.call(this,new q("THREEDS_VERIFICATION_FAILED")),Promise.reject();throw new q(e.message)}throw e}preparePaymentData(e,t,n){return ei(this,null,function*(){const{paymentData:i}=e,r={deviceSessionId:this.deviceSessionId};if(this.isSubmittingWithStoredCard(e))return Xn(Xn({},r),i);const{shouldSaveInstrument:o=!1,shouldSetAsDefaultInstrument:a=!1}=Z(i)?i:{},{nonce:s}=this.shouldPerform3DSVerification(e)?yield this.braintreeIntegrationService.verifyCard(e,t,n):yield this.braintreeIntegrationService.tokenizeCard(e,t);return Kn(Xn({},r),{nonce:s,shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a})})}prepareHostedPaymentData(e,t,n){return ei(this,null,function*(){const{paymentData:i}=e,r={deviceSessionId:this.deviceSessionId};if(this.isSubmittingWithStoredCard(e)){const{nonce:e}=yield this.braintreeHostedForm.tokenizeForStoredCardVerification();return Kn(Xn(Xn({},r),i),{nonce:e})}const{shouldSaveInstrument:o=!1,shouldSetAsDefaultInstrument:a=!1}=Z(i)?i:{},{nonce:s}=this.shouldPerform3DSVerification(e)?yield this.verifyCardWithHostedForm(t,n):yield this.braintreeHostedForm.tokenize(t);return Kn(Xn({},r),{shouldSaveInstrument:o,shouldSetAsDefaultInstrument:a,nonce:s})})}prepareAdditionalActionPaymentData(e,t){const{paymentData:n}=e,i={deviceSessionId:this.deviceSessionId,nonce:t},{shouldSaveInstrument:r=!1,shouldSetAsDefaultInstrument:o=!1}=Z(n)?n:{};return this.isSubmittingWithStoredCard(e)&&(r||o)?Xn(Xn({},n),i):Xn({},i)}verifyCardWithHostedForm(e,t){return ei(this,null,function*(){const n=yield this.braintreeHostedForm.tokenize(e);return this.braintreeIntegrationService.challenge3DSVerification(n,t)})}processAdditionalAction(e,t,n){return ei(this,null,function*(){if(!(e=>"object"==typeof e&&null!==e&&"body"in e)(e)||!l(e.body.errors,{code:"three_d_secure_required"}))return this.handleError(e);try{const{payer_auth_request:i}=function(e){return"object"==typeof e&&null!==e&&"name"in e&&"body"in e&&"status"in e.body&&"three_ds_result"in e.body&&"payer_auth_request"in e.body.three_ds_result&&"errors"in e.body}(e)&&e.body.three_ds_result||{},{paymentData:r}=t,o=this.paymentIntegrationService.getState();if(!r||!G(r))throw new H(["instrumentId"]);const a=o.getCardInstrumentOrThrow(r.instrumentId),{nonce:s}=yield this.braintreeIntegrationService.challenge3DSVerification({nonce:i||"",bin:a.iin},n),l=this.prepareAdditionalActionPaymentData(t,s);yield this.paymentIntegrationService.submitPayment(Kn(Xn({},t),{paymentData:l}))}catch(e){return this.handleError(e)}})}isHostedPaymentFormEnabled(e,t){return!!e&&!0===this.paymentIntegrationService.getState().getPaymentMethodOrThrow(e,t).config.isHostedFormEnabled}isSubmittingWithStoredCard(e){return!(!e.paymentData||!G(e.paymentData))}shouldPerform3DSVerification(e){return!(!this.is3dsEnabled||this.isSubmittingWithStoredCard(e))}shouldInitializeBraintreeFastlane(){var e;const t=this.paymentIntegrationService.getState().getPaymentProviderCustomerOrThrow(),n=Et(t)?t:{};return(null==(e=this.paymentMethod)?void 0:e.initializationData.isAcceleratedCheckoutEnabled)&&!(null==n?void 0:n.authenticationState)}initializeBraintreeFastlaneOrThrow(e){return ei(this,null,function*(){const t=this.paymentIntegrationService.getState(),n=t.getCartOrThrow(),i=t.getPaymentMethodOrThrow(e),{clientToken:r,config:o}=i;if(!r)throw new R(W.MissingPaymentMethod);this.braintreeIntegrationService.initialize(r,this.threeDSecure),yield this.braintreeIntegrationService.getBraintreeFastlane(n.id,o.testMode)})}}const ni=V(t=>{const n=window,i=new F(t),r=new I(e(),n,i),o=new Me(r,n),a=new Rn(r,i);return new ti(t,o,a)},[{id:"braintree"}]);var ii=Object.defineProperty,ri=Object.defineProperties,oi=Object.getOwnPropertyDescriptors,ai=Object.getOwnPropertySymbols,si=Object.prototype.hasOwnProperty,li=Object.prototype.propertyIsEnumerable,di=(e,t,n)=>t in e?ii(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ci=(e,t)=>{for(var n in t||(t={}))si.call(t,n)&&di(e,n,t[n]);if(ai)for(var n of ai(t))li.call(t,n)&&di(e,n,t[n]);return e},ui=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class hi{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return ui(this,null,function*(){const{braintreepaypal:t,methodId:n}=e,{container:i,onError:r}=t||{};if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreepaypal.container" argument is not provided.');let o,a=this.paymentIntegrationService.getState();try{if(o=a.getPaymentMethodOrThrow(n),!o.clientToken)throw new R(W.MissingPaymentToken)}catch(e){a=yield this.paymentIntegrationService.loadPaymentMethod(n),o=a.getPaymentMethodOrThrow(n)}const{clientToken:s,config:l,initializationData:d}=o,{paymentButtonStyles:c}=d||{},{checkoutTopButtonStyles:u}=c||{};if(!s||!d)throw new R(W.MissingPaymentMethod);const h={currency:a.getCartOrThrow().currency.code,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{this.renderPayPalButton(e,t,n,Boolean(l.testMode),u)},e=>this.handleError(e,i,r))})}deinitialize(){return ui(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}signIn(e,t){return ui(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return ui(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderPayPalButton(e,t,n,i,r){const{container:a,onClick:s=o}=t,{paypal:l}=this.braintreeHostWindow,d=null==l?void 0:l.FUNDING.PAYPAL;if(l&&d){const o=l.Buttons({env:this.braintreeIntegrationService.getBraintreeEnv(i),fundingSource:d,style:(c=ci({},r),u={height:40},ri(c,oi(u))),createOrder:()=>this.setupPayment(e,t,n),onApprove:i=>this.tokenizePayment(i,e,n,t),onClick:s});o.isEligible()&&o.render(`#${a}`)}else this.braintreeIntegrationService.removeElement(a);var c,u}setupPayment(e,t,n){return ui(this,null,function*(){var i;try{yield this.paymentIntegrationService.loadDefaultCheckout();const t=this.paymentIntegrationService.getState(),r=t.getCheckoutOrThrow().outstandingBalance,o=t.getCartOrThrow().currency.code,a=t.getCustomer(),s=t.getPaymentMethodOrThrow(n),l=null==a?void 0:a.addresses[0],d=l?this.braintreeIntegrationService.mapToBraintreeShippingAddressOverride(l):void 0,c=xe(t.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!c,shippingAddressEditable:!1,shippingAddressOverride:c?void 0:d,amount:r,currency:o,offerCredit:!1,intent:null==(i=s.initializationData)?void 0:i.intent})}catch(e){const{container:n,onError:i}=t;this.handleError(e,n,i)}})}tokenizePayment(e,t,n,i){return ui(this,null,function*(){try{const{deviceData:i}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:o,nonce:a}=r,s=this.braintreeIntegrationService.mapToLegacyBillingAddress(o),l=this.braintreeIntegrationService.mapToLegacyShippingAddress(o);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:n,action:"set_external_checkout",nonce:a,device_data:i,billing_address:JSON.stringify(s),shipping_address:JSON.stringify(l)}),r}catch(e){const{container:t,onError:n}=i;this.handleError(e,t,n)}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const yi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new hi(t,u(),r,n)},[{id:"braintreepaypal"}]);var pi=Object.defineProperty,mi=Object.defineProperties,gi=Object.getOwnPropertyDescriptors,bi=Object.getOwnPropertySymbols,vi=Object.prototype.hasOwnProperty,wi=Object.prototype.propertyIsEnumerable,fi=(e,t,n)=>t in e?pi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ci=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Ii{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return Ci(this,null,function*(){const{braintreepaypalcredit:t,methodId:n}=e,{container:i,onError:r}=t||{};if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');if(!i)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit.container" argument is not provided.');let o,a=this.paymentIntegrationService.getState();try{if(o=a.getPaymentMethodOrThrow(n),!o.clientToken)throw new R(W.MissingPaymentToken)}catch(e){a=yield this.paymentIntegrationService.loadPaymentMethod(n),o=a.getPaymentMethodOrThrow(n)}const{clientToken:s,config:l,initializationData:d}=o,{paymentButtonStyles:c}=d||{},{checkoutTopButtonStyles:u}=c||{};if(!s||!d)throw new R(W.MissingPaymentMethod);const h={currency:a.getCartOrThrow().currency.code,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(h,e=>{var i;this.renderPayPalButton(e,t,n,Boolean(l.testMode),(i=((e,t)=>{for(var n in t||(t={}))vi.call(t,n)&&fi(e,n,t[n]);if(bi)for(var n of bi(t))wi.call(t,n)&&fi(e,n,t[n]);return e})({},u),mi(i,gi({height:40}))))},e=>this.handleError(e,i,r))})}deinitialize(){return Ci(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}signIn(e,t){return Ci(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Ci(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}renderPayPalButton(e,t,n,i,r){const{container:a,onClick:s=o}=t,{paypal:l}=this.braintreeHostWindow;let d=!1;l&&[l.FUNDING.PAYLATER,l.FUNDING.CREDIT].forEach(o=>{if(!d){const c=l.Buttons({env:i?"sandbox":"production",fundingSource:o,style:r,createOrder:()=>this.setupPayment(e,t,n),onApprove:i=>this.tokenizePayment(i,e,n,t),onClick:s});c.isEligible()&&(c.render(`#${a}`),d=!0)}}),l&&d||this.braintreeIntegrationService.removeElement(a)}setupPayment(e,t,n){return Ci(this,null,function*(){var i;try{yield this.paymentIntegrationService.loadDefaultCheckout();const t=this.paymentIntegrationService.getState(),r=t.getCheckoutOrThrow().outstandingBalance,o=t.getCartOrThrow().currency.code,a=t.getCustomer(),s=t.getPaymentMethodOrThrow(n),l=null==a?void 0:a.addresses[0],d=l?this.braintreeIntegrationService.mapToBraintreeShippingAddressOverride(l):void 0,c=xe(t.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!c,shippingAddressEditable:!1,shippingAddressOverride:c?void 0:d,amount:r,currency:o,offerCredit:!0,intent:null==(i=s.initializationData)?void 0:i.intent})}catch(e){const{container:n,onError:i}=t;this.handleError(e,n,i)}})}tokenizePayment(e,t,n,i){return Ci(this,null,function*(){try{const{deviceData:i}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),r=yield t.tokenizePayment(e),{details:o,nonce:a}=r,s=this.braintreeIntegrationService.mapToLegacyBillingAddress(o),l=this.braintreeIntegrationService.mapToLegacyShippingAddress(o);return this.formPoster.postForm("/checkout.php",{payment_type:"paypal",provider:n,action:"set_external_checkout",nonce:a,device_data:i,billing_address:JSON.stringify(s),shipping_address:JSON.stringify(l)}),r}catch(e){const{container:t,onError:n}=i;this.handleError(e,t,n)}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const Mi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new Ii(t,u(),r,n)},[{id:"braintreepaypalcredit"}]);var Si=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Pi{constructor(e,t){this.paymentIntegrationService=e,this.braintreeFastlaneUtils=t,this.isAcceleratedCheckoutEnabled=!1}initialize(e){return Si(this,arguments,function*({methodId:e,braintreefastlane:t,onErrorLog:n}){var i;if(!e)throw new Y('Unable to proceed because "methodId" argument is not provided.');const r=yield this.getValidPaymentMethodOrThrow(e),{isAcceleratedCheckoutEnabled:o,isFastlaneStylingEnabled:a}=r.initializationData||{},s=a?null==(i=r.initializationData)?void 0:i.fastlaneStyles:void 0;this.isAcceleratedCheckoutEnabled=!!o,this.onErrorLog=n;try{if(this.isAcceleratedCheckoutEnabled){const e=zt(s,null==t?void 0:t.styles);yield this.braintreeFastlaneUtils.initializeBraintreeFastlaneOrThrow(r.id,e)}}catch(e){e instanceof R&&e.subtype===W.MissingPaymentMethod||this.handleErrorLog(e)}return Promise.resolve()})}deinitialize(){return Si(this,null,function*(){return Promise.resolve()})}signIn(e,t){return Si(this,null,function*(){yield this.paymentIntegrationService.signInCustomer(e,t)})}signOut(e){return Si(this,null,function*(){yield this.paymentIntegrationService.signOutCustomer(e)})}executePaymentMethodCheckout(e){return Si(this,null,function*(){const{checkoutPaymentMethodExecuted:t,continueWithCheckoutCallback:n}=e||{};if("function"!=typeof n)throw new Y('Unable to proceed because "continueWithCheckoutCallback" argument is not provided and it must be a function.');const i=this.paymentIntegrationService.getState().getCustomerOrThrow();if(this.isAcceleratedCheckoutEnabled&&i.isGuest){const e=yield this.shouldRunAuthenticationFlow();t&&"function"==typeof t&&t(),e&&(yield this.braintreeFastlaneUtils.runPayPalAuthenticationFlowOrThrow(void 0,!0,{onErrorLog:this.onErrorLog}))}n()})}shouldRunAuthenticationFlow(){return Si(this,null,function*(){var e;const t="braintreeacceleratedcheckout";try{yield this.paymentIntegrationService.loadPaymentMethod(t);return(null==(e=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t).initializationData)?void 0:e.shouldRunAcceleratedCheckout)||!1}catch(e){return!1}})}getValidPaymentMethodOrThrow(e){return Si(this,null,function*(){let t=e;try{yield this.paymentIntegrationService.loadPaymentMethod(t)}catch(n){t="braintree"===e?"braintreeacceleratedcheckout":"braintree",yield this.paymentIntegrationService.loadPaymentMethod(t)}return this.paymentIntegrationService.getState().getPaymentMethodOrThrow(t)})}handleErrorLog(e){this.onErrorLog&&"function"==typeof this.onErrorLog&&this.onErrorLog(e)}}const Oi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n),o=new an(t,r);return new Pi(t,o)},[{id:"braintreeacceleratedcheckout"},{id:"braintree"}]);class Ti extends h{constructor(e){super(e||"Not implemented."),this.name="NotImplementedError",this.type="not_implemented"}}var Ni=Object.defineProperty,Di=Object.defineProperties,zi=Object.getOwnPropertyDescriptors,Ei=Object.getOwnPropertySymbols,ki=Object.prototype.hasOwnProperty,Ai=Object.prototype.propertyIsEnumerable,Li=(e,t,n)=>t in e?Ni(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ji=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class xi{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n,this.buttonClassName="visa-checkout-wrapper",this.onError=o}initialize(e){return ji(this,null,function*(){const{braintreevisacheckout:t,methodId:n}=e;if(!n)throw new Y('Unable to proceed because "methodId" argument is not provided.');if(!t)throw new Y('Unable to proceed because "options.braintreevisacheckout" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),r=i.getCheckoutOrThrow(),{clientToken:a,config:s}=i.getPaymentMethodOrThrow(n),l=i.getStoreConfigOrThrow();if(!a)throw new R(W.MissingPaymentMethod);this.braintreeSdk.initialize(a);const d=yield this.braintreeSdk.getBraintreeVisaCheckout(),c=yield this.braintreeSdk.getVisaCheckoutSdk(s.testMode),{container:u,onError:h}=t;this.onError=h||o;const y=d.createInitOptions({paymentRequest:{currencyCode:l.currency.code,subtotal:String(r.subtotal)},settings:{locale:l.storeProfile.storeLanguage,shipping:{collectShipping:!0}}}),p=this.createSignInButton(u,this.buttonClassName);yield c.init(y),c.on("payment.success",e=>this.tokenizePayment(d,e).then(()=>this.paymentIntegrationService.loadCheckout()).catch(e=>this.handleError(e))),c.on("payment.error",(e,t)=>this.handleError(t)),p.style.visibility="visible"})}deinitialize(){return ji(this,null,function*(){yield this.braintreeSdk.deinitialize()})}signIn(){throw new Ti('In order to sign in via VisaCheckout, the shopper must click on "Visa Checkout" button.')}signOut(e){return ji(this,null,function*(){return yield this.paymentIntegrationService.signOutCustomer(e),Promise.resolve()})}executePaymentMethodCheckout(e){var t;return null==(t=null==e?void 0:e.continueWithCheckoutCallback)||t.call(e),Promise.resolve()}tokenizePayment(e,t){return ji(this,null,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.mapToVisaCheckoutAddress(i),billingAddress:a=this.mapToVisaCheckoutAddress(r)}=e;return this.postForm((s=((e,t)=>{for(var n in t||(t={}))ki.call(t,n)&&Li(e,n,t[n]);if(Ei)for(var n of Ei(t))Ai.call(t,n)&&Li(e,n,t[n]);return e})({},e),Di(s,zi({shippingAddress:o,billingAddress:a}))),t);var s})})}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}mapToVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}createSignInButton(e,t){const n=document.querySelector(`#${e}`);if(!n)throw new Error("Unable to proceed because the provided container ID is not valid.");return this.insertVisaCheckoutButton(n,t)}insertVisaCheckoutButton(e,t){const n=document.createElement("div");return n.style.display="flex",n.style.flexDirection="column",n.style.visibility="hidden",n.style.width="max-content",n.className=t,n.innerHTML='\n <img\n alt="Visa Checkout"\n class="v-button"\n role="button"\n src="https://secure.checkout.visa.com/wallet-services-web/xo/button.png?acceptCanadianVisaDebit=false&cobrand=true&height=34&width=178"\n />\n <a class="v-learn v-learn-default" style="text-align: right; display: block; font-size: 10px; color: #003366;" href="#" data-locale="en_US">Tell Me More</a>',e.appendChild(n),n}handleError(e){if("function"!=typeof this.onError)throw e;this.onError(e)}}const Bi=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i));return new xi(t,u(),r)},[{id:"braintreevisacheckout"}]);class _i extends h{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"}}function Ui(e){const{color:t,fundingicons:n,height:i=40,layout:o,shape:a,size:l,tagline:d}=e||{},c={color:t,fundingicons:n,height:Fi(i),layout:o,shape:a||"rect",size:l,tagline:d};return s(c,r)}function Fi(e){const t=Number(e);return!t||Number.isNaN(t)?40:t>55?55:t<25?25:t}var Vi=Object.defineProperty,Yi=Object.getOwnPropertySymbols,Wi=Object.prototype.hasOwnProperty,Ri=Object.prototype.propertyIsEnumerable,Hi=(e,t,n)=>t in e?Vi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gi=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Qi{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return Gi(this,null,function*(){const{braintreepaypal:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let r,o=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');r=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow().currency.code;const a=o.getPaymentMethodOrThrow(i),{clientToken:s,config:l,initializationData:d}=a;if(!s||!d)throw new R(W.MissingPaymentMethod);const c={currency:r,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(c,e=>{this.renderPayPalButton(e,t,n,i,!!l.testMode)},e=>this.handleError(e,n,t.onError))})}deinitialize(){return Gi(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,n,i,r){const{style:o,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:l}=t,{paypal:d}=this.braintreeHostWindow;if(d){const c=d.Buttons({env:r?"sandbox":"production",fundingSource:d.FUNDING.PAYPAL,style:Ui(o),createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});c.isEligible()?c.render(`#${n}`):l&&"function"==typeof l&&l()}else this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){return Gi(this,null,function*(){var i;const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),l=s.getCustomer(),d=s.getPaymentMethodOrThrow(n),c=r?r.cartAmount:s.getCartOrThrow().cartAmount,u=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(null==l?void 0:l.addresses[0]),y=h?Ue(h):void 0,p=xe(null!=r?r:s.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!p,shippingAddressEditable:!1,shippingAddressOverride:p?void 0:y,amount:c,currency:u,offerCredit:!1,intent:null==(i=d.initializationData)?void 0:i.intent})}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return Gi(this,null,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,l=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),d=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",((e,t)=>{for(var n in t||(t={}))Wi.call(t,n)&&Hi(e,n,t[n]);if(Yi)for(var n of Yi(t))Ri.call(t,n)&&Hi(e,n,t[n]);return e})({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(l),shipping_address:JSON.stringify(d)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}createBuyNowCart(e){return Gi(this,null,function*(){if(!e)throw new R(W.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new _i}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const Zi=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new Qi(t,u(),r,n)},[{id:"braintreepaypal"}]);var qi=Object.defineProperty,Ji=Object.getOwnPropertySymbols,$i=Object.prototype.hasOwnProperty,Xi=Object.prototype.propertyIsEnumerable,Ki=(e,t,n)=>t in e?qi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,er=(e,t)=>{for(var n in t||(t={}))$i.call(t,n)&&Ki(e,n,t[n]);if(Ji)for(var n of Ji(t))Xi.call(t,n)&&Ki(e,n,t[n]);return e},tr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class nr{constructor(e,t,n,i){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeIntegrationService=n,this.braintreeHostWindow=i}initialize(e){return tr(this,null,function*(){const{braintreepaypalcredit:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let r,o=this.paymentIntegrationService.getState();if(t.buyNowInitializeOptions){if(!t.currencyCode)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit.currencyCode" argument is not provided.');r=t.currencyCode}else yield this.paymentIntegrationService.loadDefaultCheckout(),o=this.paymentIntegrationService.getState(),r=o.getCartOrThrow().currency.code;const a=o.getPaymentMethodOrThrow(i),{clientToken:s,config:l,initializationData:d}=a;if(!s||!d)throw new R(W.MissingPaymentMethod);const c={currency:r,intent:d.intent,isCreditEnabled:d.isCreditEnabled,commit:!1};this.braintreeIntegrationService.initialize(s),yield this.braintreeIntegrationService.getPaypalCheckout(c,e=>{this.renderPayPalButton(e,t,n,i,!!l.testMode)},e=>this.handleError(e,n,t.onError))})}deinitialize(){return tr(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}renderPayPalButton(e,t,n,i,r){const{style:o,shouldProcessPayment:a,onAuthorizeError:s,onEligibilityFailure:l}=t,{paypal:d}=this.braintreeHostWindow;let c=!1;d&&[d.FUNDING.PAYLATER,d.FUNDING.CREDIT].forEach(u=>{const h=u===d.FUNDING.CREDIT?er({label:he.CREDIT},Ui(o)):Ui(o);if(!c){const o=d.Buttons({env:r?"sandbox":"production",fundingSource:u,style:h,createOrder:()=>this.setupPayment(e,t,i),onApprove:t=>this.tokenizePayment(t,e,i,a,s)});o.isEligible()?(o.render(`#${n}`),c=!0):d.FUNDING.CREDIT&&l&&"function"==typeof l&&l()}}),d&&c||this.braintreeIntegrationService.removeElement(n)}setupPayment(e,t,n){return tr(this,null,function*(){var i;const{onPaymentError:r,shippingAddress:o,buyNowInitializeOptions:a}=t;try{const r="function"==typeof(null==a?void 0:a.getBuyNowCartRequestBody)?yield this.createBuyNowCart(a.getBuyNowCartRequestBody()):void 0;this.buyNowCartId=null==r?void 0:r.id;const s=this.paymentIntegrationService.getState(),l=s.getCustomer(),d=s.getPaymentMethodOrThrow(n),c=r?r.cartAmount:s.getCartOrThrow().cartAmount,u=r?t.currencyCode:s.getCartOrThrow().currency.code,h=o||(null==l?void 0:l.addresses[0]),y=h?Ue(h):void 0,p=xe(null!=r?r:s.getCartOrThrow());return yield e.createPayment({flow:"checkout",enableShippingAddress:!p,shippingAddressEditable:!1,shippingAddressOverride:p?void 0:y,amount:c,currency:u,offerCredit:!0,intent:null==(i=d.initializationData)?void 0:i.intent})}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}tokenizePayment(e,t,n,i,r){return tr(this,null,function*(){try{const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),o=yield t.tokenizePayment(e),{details:a,nonce:s}=o,l=this.braintreeIntegrationService.mapToLegacyBillingAddress(a),d=this.braintreeIntegrationService.mapToLegacyShippingAddress(a);return this.formPoster.postForm("/checkout.php",er({payment_type:"paypal",provider:n,action:i?"process_payment":"set_external_checkout",nonce:s,device_data:r,billing_address:JSON.stringify(l),shipping_address:JSON.stringify(d)},this.buyNowCartId&&{cart_id:this.buyNowCartId})),o}catch(e){throw r&&(E(e)||e instanceof h)&&r(e),e}})}createBuyNowCart(e){return tr(this,null,function*(){if(!e)throw new R(W.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(e)}catch(e){throw new _i}})}handleError(e,t,n){if(this.braintreeIntegrationService.removeElement(t),!n||!E(e))throw e;n(e)}}const ir=V(t=>{const n=window,i=new F(t),r=new Me(new I(e(),n,i),n);return new nr(t,u(),r,n)},[{id:"braintreepaypalcredit"}]);var rr=Object.defineProperty,or=Object.defineProperties,ar=Object.getOwnPropertyDescriptors,sr=Object.getOwnPropertySymbols,lr=Object.prototype.hasOwnProperty,dr=Object.prototype.propertyIsEnumerable,cr=(e,t,n)=>t in e?rr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ur=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class hr{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n}initialize(e){return ur(this,null,function*(){const{containerId:t,methodId:n}=e;if(!n)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadPaymentMethod(n);const i=this.paymentIntegrationService.getState(),{clientToken:r,initializationData:o,config:a}=i.getPaymentMethodOrThrow(n);if(!r||!o)throw new R(W.MissingPaymentMethod);this.braintreeSdk.initialize(r);const s=yield this.braintreeSdk.getBraintreeVisaCheckout(),{currency:{code:l},cartAmount:d}=i.getCartOrThrow(),c=yield this.braintreeSdk.getVisaCheckoutSdk(a.testMode),u=s.createInitOptions({paymentRequest:{currencyCode:l,subtotal:String(d)},settings:{shipping:{collectShipping:!0}}});this.createSignInButton(t),yield c.init(u),c.on("payment.success",e=>ur(this,null,function*(){yield this.paymentSuccess(s,e)}))})}deinitialize(){return Promise.resolve()}paymentSuccess(e,t){return ur(this,null,function*(){return Promise.all([e.tokenize(t),this.braintreeSdk.getDataCollectorOrThrow()]).then(([e,t])=>{const n=this.paymentIntegrationService.getState(),i=n.getShippingAddress(),r=n.getBillingAddress(),{shippingAddress:o=this.toVisaCheckoutAddress(i),billingAddress:a=this.toVisaCheckoutAddress(r)}=e;return this.postForm((s=((e,t)=>{for(var n in t||(t={}))lr.call(t,n)&&cr(e,n,t[n]);if(sr)for(var n of sr(t))dr.call(t,n)&&cr(e,n,t[n]);return e})({},e),or(s,ar({shippingAddress:o,billingAddress:a}))),t);var s})})}postForm(e,t){const{userData:n,billingAddress:i,shippingAddress:r,details:o}=e,{userEmail:a}=n,{deviceData:s}=t;return this.formPoster.postForm("/checkout.php",{payment_type:e.type,nonce:e.nonce,provider:"braintreevisacheckout",action:"set_external_checkout",device_data:s,card_information:JSON.stringify({type:o.cardType,number:o.lastTwo}),billing_address:JSON.stringify(this.getAddress(a,i)),shipping_address:JSON.stringify(this.getAddress(a,r))})}toVisaCheckoutAddress(e){return e?{firstName:e.firstName,lastName:e.lastName,phoneNumber:e.phone,streetAddress:e.address1,extendedAddress:e.address2,locality:e.city,region:e.stateOrProvinceCode,countryCode:e.countryCode,postalCode:e.postalCode}:{}}getAddress(e,t={}){return{email:e,first_name:t.firstName,last_name:t.lastName,phone_number:t.phoneNumber,address_line_1:t.streetAddress,address_line_2:t.extendedAddress,city:t.locality,state:t.region,country_code:t.countryCode,postal_code:t.postalCode}}createSignInButton(e){const t=document.querySelector(`#${e}`);if(!t)throw new Error("Need a container to place the button");return this.insertVisaCheckoutButton(t)}insertVisaCheckoutButton(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.alignItems="flex-end",t.innerHTML='\n <img\n alt="Visa Checkout"\n class="v-button"\n role="button"\n src="https://secure.checkout.visa.com/wallet-services-web/xo/button.png?acceptCanadianVisaDebit=false&cobrand=true&height=34&width=178"\n />\n <a class="v-learn v-learn-default" style="text-align: right; display: block; font-size: 10px; color: #003366;" href="#" data-locale="en_US">Tell Me More</a>',e.appendChild(t),t}}const yr=V(t=>{const n=window,i=new F(t),r=new _(new I(e(),n,i));return new hr(t,u(),r)},[{id:"braintreevisacheckout"}]);function pr(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{email:n,first_name:i,last_name:r,phone_number:o,address_line_1:null==s?void 0:s.line1,address_line_2:null==s?void 0:s.line2,city:null==s?void 0:s.city,state:null==s?void 0:s.state,country_code:null==s?void 0:s.countryCode,postal_code:null==s?void 0:s.postalCode}}function mr(e){const{email:t,phone:n,shippingAddress:i}=e,r=(null==i?void 0:i.recipientName)||"",[o,a]=r.split(" ");return{email:t,first_name:o||"",last_name:a||"",phone_number:n,address_line_1:null==i?void 0:i.line1,address_line_2:null==i?void 0:i.line2,city:null==i?void 0:i.city,state:null==i?void 0:i.state,country_code:null==i?void 0:i.countryCode,postal_code:null==i?void 0:i.postalCode}}var gr=Object.defineProperty,br=Object.getOwnPropertySymbols,vr=Object.prototype.hasOwnProperty,wr=Object.prototype.propertyIsEnumerable,fr=(e,t,n)=>t in e?gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Cr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});const Ir=e=>{const{color:t,height:n}=e;return{backgroundColor:(i=t||"",i===ue.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("/app/assets/img/payment-providers/venmo-logo-${t===ue.WHITE?ue.BLUE:ue.WHITE}.svg")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${n||40}px`,minWidth:"150px",height:"100%",width:"100%",border:t===ue.WHITE?"1px solid black":"none"};var i};class Mr{constructor(e,t,n){this.paymentIntegrationService=e,this.formPoster=t,this.braintreeSdk=n,this.onError=o}initialize(e){return Cr(this,null,function*(){const{braintreevenmo:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');const r=this.paymentIntegrationService.getState().getPaymentMethodOrThrow(i),{clientToken:o,initializationData:a}=r,{paymentButtonStyles:s}=a,{cartButtonStyles:l}=s||{},d=(null==t?void 0:t.style)||l;if(!o||!a)throw new R(W.MissingPaymentMethod);if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');yield this.paymentIntegrationService.loadDefaultCheckout(),this.onError=(null==t?void 0:t.onError)||this.handleError,this.braintreeSdk.initialize(o);try{const e=yield this.braintreeSdk.getVenmoCheckoutOrThrow();this.renderVenmoButton(e,n,null==t?void 0:t.buyNowInitializeOptions,d)}catch(e){(_e(e)||function(e){return e instanceof M}(e))&&this.handleInitializationVenmoError(e,n)}})}deinitialize(){return Cr(this,null,function*(){return yield this.braintreeSdk.deinitialize(),Promise.resolve()})}handleError(e){throw new Error(e.message)}createBuyNowCart(e){return Cr(this,null,function*(){if("function"==typeof(null==e?void 0:e.getBuyNowCartRequestBody)){const t=null==e?void 0:e.getBuyNowCartRequestBody();if(!t)throw new R(W.MissingCart);try{return yield this.paymentIntegrationService.createBuyNowCart(t)}catch(e){throw new _i}}})}handleInitializationVenmoError(e,t){return this.removeVenmoContainer(t),this.onError(e)}removeVenmoContainer(e){const t=document.getElementById(e);t&&t.remove()}renderVenmoButton(e,t,n,i){const r=document.getElementById(t),{color:o}=i||{};if(!r)throw new Y("Unable to create wallet button without valid container ID.");r.setAttribute("aria-label","Venmo"),Object.assign(r.style,Ir(i||{})),r.addEventListener("click",()=>Cr(this,null,function*(){r.setAttribute("disabled","true");const t=yield this.createBuyNowCart(n);e.tokenize&&e.tokenize((e,n)=>Cr(this,null,function*(){r.removeAttribute("disabled"),e&&this.onError(e),yield this.handlePostForm(n,null==t?void 0:t.id)}))})),o===ue.BLUE&&(r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#0a7fc2"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor=Ir(i||{}).backgroundColor}))}handlePostForm(e,t){return Cr(this,null,function*(){const{deviceData:n}=yield this.braintreeSdk.getDataCollectorOrThrow(),{nonce:i,details:r}=e;this.formPoster.postForm("/checkout.php",((e,t)=>{for(var n in t||(t={}))vr.call(t,n)&&fr(e,n,t[n]);if(br)for(var n of br(t))wr.call(t,n)&&fr(e,n,t[n]);return e})({nonce:i,provider:"braintreevenmo",payment_type:"paypal",device_data:n,action:"set_external_checkout",billing_address:JSON.stringify(pr(r)),shipping_address:JSON.stringify(mr(r))},t&&{cart_id:t}))})}}const Sr=V(t=>{const n=window,i=e(),r=new F(t),o=new I(i,n,r),a=new _(o);return new Mr(t,u(),a)},[{id:"braintreevenmo"}]);class Pr{getSDKVersion(){return v}}class Or extends h{constructor(e){super(e||"Failed to redirect to checkout page"),this.name="BraintreePaypalWalletError",this.type="braintree_paypal_wallet"}}var Tr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Nr{constructor(e,t){this.walletButtonIntegrationService=e,this.braintreeIntegrationService=t}initialize(e){this.braintreeIntegrationService.initialize(e)}loadPaypalCheckout(e,t,n){return Tr(this,null,function*(){return this.braintreePaypalCheckout=yield new Promise((i,r)=>{this.braintreeIntegrationService.getPaypalCheckout(e,i,e=>{this.removeElement(t),n&&E(e)&&n(e),r(e)})}),this.braintreePaypalCheckout})}loadVenmoCheckout(e){return Tr(this,null,function*(){try{this.braintreeVenmoCheckout=yield this.braintreeIntegrationService.getVenmoCheckout()}catch(t){throw this.removeElement(e),t}return this.braintreeVenmoCheckout})}getBraintreePaypalCheckoutOrThrow(){if(!this.braintreePaypalCheckout)throw new y;return this.braintreePaypalCheckout}getBraintreeVenmoCheckoutOrThrow(){if(!this.braintreeVenmoCheckout)throw new y;return this.braintreeVenmoCheckout}teardown(){return Tr(this,null,function*(){yield this.braintreeIntegrationService.teardown()})}proxyTokenizationPayment(e,t,n){return Tr(this,null,function*(){const i=this.getBraintreePaypalCheckoutOrThrow(),r=yield i.tokenizePayment(e);return this.redirectToExternalCheckout(r,t,n)})}proxyVenmoTokenizationPayment(e,t){return Tr(this,null,function*(){const n=yield this.tokenizeVenmo();return this.redirectToExternalCheckout(n,e,t)})}removeElement(e){this.braintreeIntegrationService.removeElement(e)}redirectToExternalCheckout(e,t,n){return Tr(this,null,function*(){var i;const{deviceData:r}=yield this.braintreeIntegrationService.getDataCollector({paypal:!0}),{details:o,nonce:a}=e,s=this.braintreeIntegrationService.mapToLegacyShippingAddress(o);yield this.walletButtonIntegrationService.addBillingAddress(n,this.mapToBillingAddress(o));const l={paymentWalletData:{providerId:t,providerOrderId:a},cartEntityId:n,queryParams:[{key:"payment_type",value:"paypal"},{key:"action",value:"set_external_checkout"},{key:"provider",value:t},{key:"nonce",value:a},{key:"shipping_address",value:encodeURIComponent(JSON.stringify(s))},...r?[{key:"device_data",value:r}]:[]]},d=null==(i=(yield this.walletButtonIntegrationService.getRedirectToCheckoutUrl(l)).body.redirectUrls)?void 0:i.externalCheckoutUrl;if(!d)throw new Or;return window.location.assign(d),e})}mapToBillingAddress(e){const{billingAddress:t,email:n,firstName:i,lastName:r,phone:o,shippingAddress:a}=e,s=t||a;return{firstName:i||"",lastName:r||"",company:"",address1:(null==s?void 0:s.line1)||"",address2:(null==s?void 0:s.line2)||"",city:(null==s?void 0:s.city)||"",email:n||"",stateOrProvince:(null==s?void 0:s.state)||"",stateOrProvinceCode:(null==s?void 0:s.state)||"",countryCode:(null==s?void 0:s.countryCode)||"",postalCode:(null==s?void 0:s.postalCode)||"",phone:o||"",shouldSaveAddress:!1}}tokenizeVenmo(){const e=this.getBraintreeVenmoCheckoutOrThrow();return new Promise((t,n)=>{e.tokenize((e,i)=>{if(e)return n(e);t(i)})})}}var Dr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class zr{constructor(e,t){this.braintreePaypalWalletService=e,this.braintreeHostWindow=t}initialize(e){return Dr(this,null,function*(){const{braintreepaypal:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypal" argument is not provided.');let r;try{r=JSON.parse(atob(t.initializationData))}catch(e){throw new Y("Failed to parse payment method 'initializationData'.")}const{initializationData:o,config:a}=r;if(!t.clientToken||!o||!a)throw new R(W.MissingPaymentMethod);const s={currency:t.currency.code,intent:o.intent,isCreditEnabled:o.isCreditEnabled,commit:!1};this.braintreePaypalWalletService.initialize(t.clientToken),yield this.braintreePaypalWalletService.loadPaypalCheckout(s,n,t.onError),this.renderButton(t,n,i,!!a.testMode,o.intent)})}deinitialize(){return Dr(this,null,function*(){yield this.braintreePaypalWalletService.teardown()})}renderButton(e,t,n,i,r){const{style:o,onEligibilityFailure:a}=e,{paypal:s}=this.braintreeHostWindow;if(!s)return void this.braintreePaypalWalletService.removeElement(t);const l=s.Buttons({env:i?"sandbox":"production",fundingSource:s.FUNDING.PAYPAL,style:Ui(o),createOrder:()=>this.setupPayment(e,r),onApprove:t=>this.tokenizePayment(t,n,e.cartId,e.onAuthorizeError)});l.isEligible()?l.render(`#${t}`):a&&"function"==typeof a&&a()}setupPayment(e,t){return Dr(this,null,function*(){const{onPaymentError:n,amount:i,currency:r}=e,o=this.braintreePaypalWalletService.getBraintreePaypalCheckoutOrThrow();try{return yield o.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,amount:i,currency:r.code,offerCredit:!1,intent:t})}catch(e){throw(E(e)||e instanceof h)&&(null==n||n(e)),e}})}tokenizePayment(e,t,n,i){return Dr(this,null,function*(){try{yield this.braintreePaypalWalletService.proxyTokenizationPayment(e,t,n)}catch(e){throw(E(e)||e instanceof h)&&(null==i||i(e)),e}})}}const Er=V(t=>{const n=window,i=new Me(new I(e(),n,new Pr),n);return new zr(new Nr(t,i),n)},[{id:"braintreepaypal"}]);var kr=Object.defineProperty,Ar=Object.defineProperties,Lr=Object.getOwnPropertyDescriptors,jr=Object.getOwnPropertySymbols,xr=Object.prototype.hasOwnProperty,Br=Object.prototype.propertyIsEnumerable,_r=(e,t,n)=>t in e?kr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ur=(e,t)=>{for(var n in t||(t={}))xr.call(t,n)&&_r(e,n,t[n]);if(jr)for(var n of jr(t))Br.call(t,n)&&_r(e,n,t[n]);return e},Fr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Vr{constructor(e,t){this.braintreePaypalWalletService=e,this.braintreeHostWindow=t}initialize(e){return Fr(this,null,function*(){const{braintreepaypalcredit:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreepaypalcredit" argument is not provided.');let r;try{r=JSON.parse(atob(t.initializationData))}catch(e){throw new Y("Failed to parse payment method 'initializationData'.")}const{initializationData:o,config:a}=r;if(!t.clientToken||!o||!a)throw new R(W.MissingPaymentMethod);const s={currency:t.currency.code,intent:o.intent,isCreditEnabled:o.isCreditEnabled,commit:!1};this.braintreePaypalWalletService.initialize(t.clientToken),yield this.braintreePaypalWalletService.loadPaypalCheckout(s,n,t.onError),this.renderButton(t,n,i,!!a.testMode,o.intent)})}deinitialize(){return Fr(this,null,function*(){yield this.braintreePaypalWalletService.teardown()})}renderButton(e,t,n,i,r){const{style:o,onEligibilityFailure:a}=e,{paypal:s}=this.braintreeHostWindow;if(!s)return void this.braintreePaypalWalletService.removeElement(t);const l=s.Buttons({env:i?"sandbox":"production",fundingSource:s.FUNDING.PAYLATER,style:(d=Ur({},Ui(o)),c={color:ue.GOLD},Ar(d,Lr(c))),createOrder:()=>this.setupPayment(e,r),onApprove:t=>this.tokenizePayment(t,n,e.cartId,e.onAuthorizeError)});var d,c;l.isEligible()?l.render(`#${t}`):a&&"function"==typeof a&&a()}setupPayment(e,t){return Fr(this,null,function*(){const{onPaymentError:n,amount:i,currency:r}=e,o=this.braintreePaypalWalletService.getBraintreePaypalCheckoutOrThrow();try{return yield o.createPayment({flow:"checkout",enableShippingAddress:!0,shippingAddressEditable:!1,amount:i,currency:r.code,offerCredit:!0,intent:t})}catch(e){throw(E(e)||e instanceof h)&&(null==n||n(e)),e}})}tokenizePayment(e,t,n,i){return Fr(this,null,function*(){try{yield this.braintreePaypalWalletService.proxyTokenizationPayment(e,t,n)}catch(e){throw(E(e)||e instanceof h)&&(null==i||i(e)),e}})}}const Yr=V(t=>{const n=window,i=new Me(new I(e(),n,new Pr),n);return new Vr(new Nr(t,i),n)},[{id:"braintreepaypalcredit"}]),Wr={[ue.WHITE]:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTE4IiBoZWlnaHQ9IjI5IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPgogICAgPGRlZnM+CiAgICAgICAgPGNsaXBQYXRoIGlkPSJjbGlwMCI+CiAgICAgICAgICAgIDxyZWN0IHdpZHRoPSIxOTgiIGhlaWdodD0iMzgiIGZpbGw9IndoaXRlIiBpZD0ic3ZnXzEiLz4KICAgICAgICA8L2NsaXBQYXRoPgogICAgPC9kZWZzPgogICAgPGc+CiAgICAgICAgPHRpdGxlPkxheWVyIDE8L3RpdGxlPgogICAgICAgIDxnIHN0cm9rZT0ibnVsbCIgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwKSIgaWQ9InN2Z18yIj4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtMjAuMDM2ODgsNGMwLjc1NDU4LDEuMjY3NTEgMS4wOTQ4NSwyLjU3Mjk0IDEuMDk0ODUsNC4yMjIwOGMwLDUuMjU5ODUgLTQuNDE0OTYsMTIuMDkyNzEgLTcuOTk4MjMsMTYuODkwNzVsLTguMTg0NDMsMGwtMy4yODI0LC0xOS45NjExN2w3LjE2NjM0LC0wLjY5MmwxLjczNTQ1LDE0LjIwMzY1YzEuNjIxNTQsLTIuNjg2NjQgMy42MjI1OSwtNi45MDg3MSAzLjYyMjU5LC05Ljc4NzMzYzAsLTEuNTc1NjMgLTAuMjY1NCwtMi42NDg4IC0wLjY4MDE3LC0zLjUzMjQzbDYuNTI2LC0xLjM0MzU0eiIgZmlsbD0id2hpdGUiIGlkPSJzdmdfMyIvPgogICAgICAgICAgICA8cGF0aCBzdHJva2U9Im51bGwiIGQ9Im0yOS4zMjQ3NCwxMi43ODk3NGMxLjMxODgsMCA0LjYzODc0LC0wLjYxMzUzIDQuNjM4NzQsLTIuNTMyNThjMCwtMC45MjE0NiAtMC42NDA2MiwtMS4zODEyIC0xLjM5NTY1LC0xLjM4MTJjLTEuMzIwODgsMCAtMy4wNTQxOCwxLjYxMDk0IC0zLjI0MzA5LDMuOTEzNzhsLTAuMDAwMDEsMHptLTAuMTUxMDgsMy44MDA2M2MwLDIuMzQzMyAxLjI4MTE0LDMuMjYyNTkgMi45Nzk1OCwzLjI2MjU5YzEuODQ5NjEsMCAzLjYyMDQ3LC0wLjQ1OTY1IDUuOTIyMjMsLTEuNjQ5MzFsLTAuODY3MDEsNS45ODcyNWMtMS42MjE2OCwwLjgwNTg4IC00LjE0OTExLDEuMzQzNTQgLTYuNjAyMzEsMS4zNDM1NGMtNi4yMjI5NCwwIC04LjQ1MDAyLC0zLjgzODEgLTguNDUwMDIsLTguNjM2MzJjMCwtNi4yMTg5NyAzLjYyMjczLC0xMi44MjIyOCAxMS4wOTE2OSwtMTIuODIyMjhjNC4xMTIxOCwwIDYuNDExNTksMi4zNDMwMyA2LjQxMTU5LDUuNjA1NjJjMC4wMDAzNiw1LjI1OTU4IC02LjYzNzI2LDYuODcwODggLTEwLjQ4NTc1LDYuOTA4OWwwLjAwMDAxLDB6IiBmaWxsPSJ3aGl0ZSIgaWQ9InN2Z180Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTYwLjM0MDQ5LDguNjg0MDdjMCwwLjc2NzY3IC0wLjExNDUsMS44ODEwMyAtMC4yMjgzOCwyLjYwODdsLTIuMTUwNDEsMTMuODIwMDRsLTYuOTc4MDcsMGwxLjk2MTQ5LC0xMi42Njg2N2MwLjAzNzIxLC0wLjM0MzYxIDAuMTUxNTMsLTEuMDM1MzQgMC4xNTE1MywtMS40MTkxM2MwLC0wLjkyMTU1IC0wLjU2NjEyLC0xLjE1MTQ3IC0xLjI0NjY0LC0xLjE1MTQ3Yy0wLjkwMzk1LDAgLTEuODEwMDUsMC40MjE4MSAtMi40MTM1NiwwLjcyOTg0bC0yLjIyNDgyLDE0LjUwOTQzbC03LjAxNzM1LDBsMy4yMDU4OSwtMjAuNjkwODNsNi4wNzM0OSwwbDAuMDc2OTQsMS42NTE0OGMxLjQzMjg1LC0wLjk1OTQ4IDMuMzE5NTgsLTEuOTk3MjYgNS45OTY1NSwtMS45OTcyNmMzLjU0NjcsLTAuMDAwMzYgNC43OTMzNCwxLjg0Mjg0IDQuNzkzMzQsNC42MDc4NmwwLjAwMDAxLDB6IiBmaWxsPSJ3aGl0ZSIgaWQ9InN2Z181Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTgxLjA1NjI0LDYuMzQwODZjMS45OTg1MiwtMS40NTcyMyAzLjg4NTcsLTIuMjY1MDEgNi40ODc3MiwtMi4yNjUwMWMzLjU4MzA5LDAgNC44Mjg5MiwxLjg0MzIgNC44Mjg5Miw0LjYwODIyYzAsMC43Njc2NyAtMC4xMTM3OCwxLjg4MTAzIC0wLjIyNzU3LDIuNjA4N2wtMi4xNDc5NywxMy44MTk4N2wtNi45Nzk5NiwwbDEuOTk4OTcsLTEyLjkzNjI0YzAuMDM2NzYsLTAuMzQ1NzcgMC4xMTQwNSwtMC43Njc1OCAwLjExNDA1LC0xLjAzNTE2YzAsLTEuMDM3NTkgLTAuNTY2MywtMS4yNjc2OSAtMS4yNDY2NCwtMS4yNjc2OWMtMC44NjY3NCwwIC0xLjczMzEyLDAuMzgzNzkgLTIuMzc2MzUsMC43Mjk3NWwtMi4yMjQzNywxNC41MDk2OWwtNi45NzgyNSwwbDEuOTk4ODgsLTEyLjkzNjQyYzAuMDM2ODQsLTAuMzQ1NzcgMC4xMTE3OSwtMC43Njc1OCAwLjExMTc5LC0xLjAzNTE2YzAsLTEuMDM3NSAtMC41NjY0OCwtMS4yNjc2OSAtMS4yNDQ0OCwtMS4yNjc2OWMtMC45MDU5MywwIC0xLjgxMDA1LDAuNDIxODEgLTIuNDEzNTYsMC43Mjk4NGwtMi4yMjY1NCwxNC41MDk0M2wtNy4wMTUwOSwwbDMuMjA1NTIsLTIwLjY5MDgzbDUuOTk5MjYsMGwwLjE4ODU1LDEuNzI3MzRjMS4zOTU2NSwtMS4wMzUxNiAzLjI4MDg0LC0yLjA3Mjg0IDUuODA4MDksLTIuMDcyODRjMi4xODgxNiwtMC4wMDA4MSAzLjYyMDgzLDAuOTU4ODUgNC4zMzkwMiwyLjI2NDE5bDAuMDAwMDEsMC4wMDAwMXoiIGZpbGw9IndoaXRlIiBpZD0ic3ZnXzYiLz4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtMTA2LjI2MDc1LDEyLjM2ODNjMCwtMS42ODkxNCAtMC40MTU0LC0yLjg0MDY5IC0xLjY1ODg4LC0yLjg0MDY5Yy0yLjc1NDI3LDAgLTMuMzE5NTgsNC45NTE0NyAtMy4zMTk1OCw3LjQ4NDRjMCwxLjkyMTY3IDAuNTI4MjgsMy4xMTA4OCAxLjc3MTc2LDMuMTEwODhjMi42MDM0NywwIDMuMjA2NywtNS4yMjE4NCAzLjIwNjcsLTcuNzU0NTl6bS0xMi4wNzAwNCw0LjMzNzk0YzAsLTYuNTI0OTIgMy4zOTQ1MywtMTIuNjMwMzggMTEuMjAzMTMsLTEyLjYzMDM4YzUuODg1MTIsMCA4LjAzNjE2LDMuNTMyNTEgOC4wMzYxNiw4LjQwODMxYzAsNi40NDkzNCAtMy4zNTc1MSwxMy4xMjgxMyAtMTEuMzU1NzMsMTMuMTI4MTNjLTUuOTIyMTQsMCAtNy44ODM1NSwtMy45NTQzMyAtNy44ODM1NSwtOC45MDYwNmwtMC4wMDAwMSwweiIgZmlsbD0id2hpdGUiIGlkPSJzdmdfNyIvPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+Cg==",[ue.BLUE]:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTE4IiBoZWlnaHQ9IjI5IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPgogICAgPGRlZnM+CiAgICAgICAgPGNsaXBQYXRoIGlkPSJjbGlwMCI+CiAgICAgICAgICAgIDxyZWN0IHdpZHRoPSIxOTgiIGhlaWdodD0iMzgiIGZpbGw9IiMwMDhDRkYiIGlkPSJzdmdfMSIvPgogICAgICAgIDwvY2xpcFBhdGg+CiAgICA8L2RlZnM+CiAgICA8Zz4KICAgICAgICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgICAgICAgPGcgc3Ryb2tlPSJudWxsIiBjbGlwLXBhdGg9InVybCgjY2xpcDApIiBpZD0ic3ZnXzIiPgogICAgICAgICAgICA8cGF0aCBzdHJva2U9Im51bGwiIGQ9Im0yMC4wMzY4OCw0YzAuNzU0NTgsMS4yNjc1MSAxLjA5NDg1LDIuNTcyOTQgMS4wOTQ4NSw0LjIyMjA4YzAsNS4yNTk4NSAtNC40MTQ5NiwxMi4wOTI3MSAtNy45OTgyMywxNi44OTA3NWwtOC4xODQ0MywwbC0zLjI4MjQsLTE5Ljk2MTE3bDcuMTY2MzQsLTAuNjkybDEuNzM1NDUsMTQuMjAzNjVjMS42MjE1NCwtMi42ODY2NCAzLjYyMjU5LC02LjkwODcxIDMuNjIyNTksLTkuNzg3MzNjMCwtMS41NzU2MyAtMC4yNjU0LC0yLjY0ODggLTAuNjgwMTcsLTMuNTMyNDNsNi41MjYsLTEuMzQzNTR6IiBmaWxsPSIjMDA4Q0ZGIiBpZD0ic3ZnXzMiLz4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtMjkuMzI0NzQsMTIuNzg5NzRjMS4zMTg4LDAgNC42Mzg3NCwtMC42MTM1MyA0LjYzODc0LC0yLjUzMjU4YzAsLTAuOTIxNDYgLTAuNjQwNjIsLTEuMzgxMiAtMS4zOTU2NSwtMS4zODEyYy0xLjMyMDg4LDAgLTMuMDU0MTgsMS42MTA5NCAtMy4yNDMwOSwzLjkxMzc4bC0wLjAwMDAxLDB6bS0wLjE1MTA4LDMuODAwNjNjMCwyLjM0MzMgMS4yODExNCwzLjI2MjU5IDIuOTc5NTgsMy4yNjI1OWMxLjg0OTYxLDAgMy42MjA0NywtMC40NTk2NSA1LjkyMjIzLC0xLjY0OTMxbC0wLjg2NzAxLDUuOTg3MjVjLTEuNjIxNjgsMC44MDU4OCAtNC4xNDkxMSwxLjM0MzU0IC02LjYwMjMxLDEuMzQzNTRjLTYuMjIyOTQsMCAtOC40NTAwMiwtMy44MzgxIC04LjQ1MDAyLC04LjYzNjMyYzAsLTYuMjE4OTcgMy42MjI3MywtMTIuODIyMjggMTEuMDkxNjksLTEyLjgyMjI4YzQuMTEyMTgsMCA2LjQxMTU5LDIuMzQzMDMgNi40MTE1OSw1LjYwNTYyYzAuMDAwMzYsNS4yNTk1OCAtNi42MzcyNiw2Ljg3MDg4IC0xMC40ODU3NSw2LjkwODlsMC4wMDAwMSwweiIgZmlsbD0iIzAwOENGRiIgaWQ9InN2Z180Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTYwLjM0MDQ5LDguNjg0MDdjMCwwLjc2NzY3IC0wLjExNDUsMS44ODEwMyAtMC4yMjgzOCwyLjYwODdsLTIuMTUwNDEsMTMuODIwMDRsLTYuOTc4MDcsMGwxLjk2MTQ5LC0xMi42Njg2N2MwLjAzNzIxLC0wLjM0MzYxIDAuMTUxNTMsLTEuMDM1MzQgMC4xNTE1MywtMS40MTkxM2MwLC0wLjkyMTU1IC0wLjU2NjEyLC0xLjE1MTQ3IC0xLjI0NjY0LC0xLjE1MTQ3Yy0wLjkwMzk1LDAgLTEuODEwMDUsMC40MjE4MSAtMi40MTM1NiwwLjcyOTg0bC0yLjIyNDgyLDE0LjUwOTQzbC03LjAxNzM1LDBsMy4yMDU4OSwtMjAuNjkwODNsNi4wNzM0OSwwbDAuMDc2OTQsMS42NTE0OGMxLjQzMjg1LC0wLjk1OTQ4IDMuMzE5NTgsLTEuOTk3MjYgNS45OTY1NSwtMS45OTcyNmMzLjU0NjcsLTAuMDAwMzYgNC43OTMzNCwxLjg0Mjg0IDQuNzkzMzQsNC42MDc4NmwwLjAwMDAxLDB6IiBmaWxsPSIjMDA4Q0ZGIiBpZD0ic3ZnXzUiLz4KICAgICAgICAgICAgPHBhdGggc3Ryb2tlPSJudWxsIiBkPSJtODEuMDU2MjQsNi4zNDA4NmMxLjk5ODUyLC0xLjQ1NzIzIDMuODg1NywtMi4yNjUwMSA2LjQ4NzcyLC0yLjI2NTAxYzMuNTgzMDksMCA0LjgyODkyLDEuODQzMiA0LjgyODkyLDQuNjA4MjJjMCwwLjc2NzY3IC0wLjExMzc4LDEuODgxMDMgLTAuMjI3NTcsMi42MDg3bC0yLjE0Nzk3LDEzLjgxOTg3bC02Ljk3OTk2LDBsMS45OTg5NywtMTIuOTM2MjRjMC4wMzY3NiwtMC4zNDU3NyAwLjExNDA1LC0wLjc2NzU4IDAuMTE0MDUsLTEuMDM1MTZjMCwtMS4wMzc1OSAtMC41NjYzLC0xLjI2NzY5IC0xLjI0NjY0LC0xLjI2NzY5Yy0wLjg2Njc0LDAgLTEuNzMzMTIsMC4zODM3OSAtMi4zNzYzNSwwLjcyOTc1bC0yLjIyNDM3LDE0LjUwOTY5bC02Ljk3ODI1LDBsMS45OTg4OCwtMTIuOTM2NDJjMC4wMzY4NCwtMC4zNDU3NyAwLjExMTc5LC0wLjc2NzU4IDAuMTExNzksLTEuMDM1MTZjMCwtMS4wMzc1IC0wLjU2NjQ4LC0xLjI2NzY5IC0xLjI0NDQ4LC0xLjI2NzY5Yy0wLjkwNTkzLDAgLTEuODEwMDUsMC40MjE4MSAtMi40MTM1NiwwLjcyOTg0bC0yLjIyNjU0LDE0LjUwOTQzbC03LjAxNTA5LDBsMy4yMDU1MiwtMjAuNjkwODNsNS45OTkyNiwwbDAuMTg4NTUsMS43MjczNGMxLjM5NTY1LC0xLjAzNTE2IDMuMjgwODQsLTIuMDcyODQgNS44MDgwOSwtMi4wNzI4NGMyLjE4ODE2LC0wLjAwMDgxIDMuNjIwODMsMC45NTg4NSA0LjMzOTAyLDIuMjY0MTlsMC4wMDAwMSwwLjAwMDAxeiIgZmlsbD0iIzAwOENGRiIgaWQ9InN2Z182Ii8+CiAgICAgICAgICAgIDxwYXRoIHN0cm9rZT0ibnVsbCIgZD0ibTEwNi4yNjA3NSwxMi4zNjgzYzAsLTEuNjg5MTQgLTAuNDE1NCwtMi44NDA2OSAtMS42NTg4OCwtMi44NDA2OWMtMi43NTQyNywwIC0zLjMxOTU4LDQuOTUxNDcgLTMuMzE5NTgsNy40ODQ0YzAsMS45MjE2NyAwLjUyODI4LDMuMTEwODggMS43NzE3NiwzLjExMDg4YzIuNjAzNDcsMCAzLjIwNjcsLTUuMjIxODQgMy4yMDY3LC03Ljc1NDU5em0tMTIuMDcwMDQsNC4zMzc5NGMwLC02LjUyNDkyIDMuMzk0NTMsLTEyLjYzMDM4IDExLjIwMzEzLC0xMi42MzAzOGM1Ljg4NTEyLDAgOC4wMzYxNiwzLjUzMjUxIDguMDM2MTYsOC40MDgzMWMwLDYuNDQ5MzQgLTMuMzU3NTEsMTMuMTI4MTMgLTExLjM1NTczLDEzLjEyODEzYy01LjkyMjE0LDAgLTcuODgzNTUsLTMuOTU0MzMgLTcuODgzNTUsLTguOTA2MDZsLTAuMDAwMDEsMHoiIGZpbGw9IiMwMDhDRkYiIGlkPSJzdmdfNyIvPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+Cg=="},Rr=e=>{const{color:t,height:n}=e;return{backgroundColor:(i=t||"",i===ue.WHITE?"#FFFFFF":"#3D95CE"),backgroundPosition:"50% 50%",backgroundSize:"80px auto",backgroundImage:`url("${Wr[t===ue.WHITE?ue.BLUE:ue.WHITE]}")`,backgroundRepeat:"no-repeat",borderRadius:"4px",cursor:"pointer",transition:"0.2s ease",minHeight:`${n||40}px`,minWidth:"150px",height:"100%",border:t===ue.WHITE?"1px solid black":"none"};var i};var Hr=(e,t,n)=>new Promise((i,r)=>{var o=e=>{try{s(n.next(e))}catch(e){r(e)}},a=e=>{try{s(n.throw(e))}catch(e){r(e)}},s=e=>e.done?i(e.value):Promise.resolve(e.value).then(o,a);s((n=n.apply(e,t)).next())});class Gr{constructor(e){this.braintreePaypalWalletService=e}initialize(e){return Hr(this,null,function*(){const{braintreevenmo:t,containerId:n,methodId:i}=e;if(!i)throw new Y('Unable to initialize payment because "options.methodId" argument is not provided.');if(!n)throw new Y('Unable to initialize payment because "options.containerId" argument is not provided.');if(!t)throw new Y('Unable to initialize payment because "options.braintreevenmo" argument is not provided.');let r;try{r=JSON.parse(atob(t.initializationData))}catch(e){throw new Y("Failed to parse payment method 'initializationData'.")}const{initializationData:o,config:a}=r;if(!t.clientToken||!o||!a)throw new R(W.MissingPaymentMethod);this.braintreePaypalWalletService.initialize(t.clientToken);try{yield this.braintreePaypalWalletService.loadVenmoCheckout(n)}catch(e){return void this.handleInitializationError(e,t)}this.renderButton(t,n,i,o)})}deinitialize(){return Hr(this,null,function*(){yield this.braintreePaypalWalletService.teardown()})}handleInitializationError(e,t){const{onError:n,onEligibilityFailure:i}=t;e instanceof M?null==i||i():(E(e)||e instanceof h)&&(null==n||n(e))}renderButton(e,t,n,i){const{style:r,onEligibilityFailure:o}=e,{cartButtonStyles:a}=i.paymentButtonStyles||{},s=r||a||{},{color:l}=s,d=document.getElementById(t);if(!d)return this.braintreePaypalWalletService.removeElement(t),void(null==o||o());d.setAttribute("aria-label","Venmo"),Object.assign(d.style,Rr(s)),d.addEventListener("click",()=>Hr(this,null,function*(){var t;d.setAttribute("disabled","true");try{yield this.braintreePaypalWalletService.proxyVenmoTokenizationPayment(n,e.cartId)}catch(n){(E(n)||n instanceof h)&&(null==(t=e.onAuthorizeError)||t.call(e,n))}finally{d.removeAttribute("disabled")}})),l===ue.BLUE&&(d.addEventListener("mouseenter",()=>{d.style.backgroundColor="#0a7fc2"}),d.addEventListener("mouseleave",()=>{d.style.backgroundColor=Rr(s).backgroundColor}))}}const Qr=V(t=>{const n=window,i=new Me(new I(e(),n,new Pr),n);return new Gr(new Nr(t,i))},[{id:"braintreevenmo"}]);export{se as createBraintreeAchPaymentStrategy,ni as createBraintreeCreditCardPaymentStrategy,Oi as createBraintreeFastlaneCustomerStrategy,sn as createBraintreeFastlanePaymentStrategy,Mt as createBraintreeLocalMethodsPaymentStrategy,Zi as createBraintreePaypalButtonStrategy,ir as createBraintreePaypalCreditButtonStrategy,Mi as createBraintreePaypalCreditCustomerStrategy,Yr as createBraintreePaypalCreditWalletStrategy,yi as createBraintreePaypalCustomerStrategy,$e as createBraintreePaypalPaymentStrategy,Er as createBraintreePaypalWalletStrategy,Sr as createBraintreeVenmoButtonStrategy,En as createBraintreeVenmoPaymentStrategy,Qr as createBraintreeVenmoWalletStrategy,yr as createBraintreeVisaCheckoutButtonStrategy,Bi as createBraintreeVisaCheckoutCustomerStrategy,wn as createBraintreeVisaCheckoutPaymentStrategy};
|
|
2
2
|
//# sourceMappingURL=braintree.js.map
|