1import{g as e}from"./adyen-2xVWhjfd.js";import{G as t,o as a,k as i,f as s,e as o,y as r,m as n,d as l}from"./vendor-CV6ISSGl.js";import{_ as d,w as p,O as h,h as c,S as y,E as u}from"./index-DSlA2-3H.js";import{D as m,g,a as v,b as f,v as D}from"./walletHelpers-0QzXyuIl.js";const b={name:"DigitalWalletApple",components:{DigitalWalletAddressOverlay:m,OverlaySubmitLoader:h},mixins:[p],props:{configData:{type:Object,required:!0},orderData:{type:Object,required:!0},shippingData:{type:Object,required:!0}},data:()=>({applePayToken:null,isFormOverlayVisible:!1,showLoader:!1,processedPaymentData:null}),computed:{...l("config",["getDefaultConfig"]),...n("delivery",["deliveryFormConfiguration","deliveryAddress"]),...n("payments",["adyen"]),localeId(){return this.getDefaultConfig("localeId")},configuration(){return{clientKey:this.adyen.clientKey,environment:this.adyen.environment,locale:this.localeId,analytics:{enabled:!0},paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0}},paymentMethodsResponse:{paymentMethods:[{brands:this.configData.apple.supportedNetworks,configuration:{merchantId:this.configData.apple.merchantIdentifier,merchantName:this.configData.apple.merchantName},name:this.configData.apple.type,type:"applepay"}]},amount:{value:100*this.orderData.total.amount.value,currency:this.orderData.total.amount.currency}}},shippingMethods(){return this.shippingData.shippingOptions.map(({label:e,description:t,id:a,price:i})=>({label:e,detail:t,identifier:a,amount:i}))},newTotal(){return{label:this.orderData.total.label,type:"final",amount:this.orderData.total.amount.value}}},mounted(){this.initApplePay()},methods:{async initApplePay(){await this.updateDeliveryMode(this.shippingData.shippingOptions[0].id);const t=await e(this.configuration),a={shippingMethods:this.shippingMethods,requiredBillingContactFields:["postalAddress","name","phone","email"],requiredShippingContactFields:["postalAddress","name","phone","email"],onPaymentMethodSelected:this.onPaymentMethodSelected,onShippingMethodSelected:this.onShippingMethodSelected,onShippingContactSelected:this.onShippingContactSelected,onSubmit:this.onSubmit,onAuthorized:this.onAuthorized};t.create("applepay",a).mount(this.$refs.applepay)},onPaymentMethodSelected(e){e({newTotal:this.newTotal})},onShippingContactSelected(e,t,a){const i=D(a.shippingContact,this.configData);i.status===y.FAILURE?t({status:"FAILURE",errors:[new ApplePayError("shippingContactInvalid",i.type,this.i18n(i.message))],newTotal:this.newTotal}):this.configData.net&&a.shippingContact.administrativeArea&&a.shippingContact.postalCode?this.$store.dispatch("tax/getEstimatedTax",{zipCode:a.shippingContact.postalCode,state:a.shippingContact.administrativeArea,paymentMethod:"applePay"}).then(()=>{e({newTotal:this.newTotal})}).catch(e=>{t({status:"FAILURE",errors:[new ApplePayError("shippingContactInvalid","addressLines",e?.data?.errors?.[0]?.title||"")],newTotal:this.newTotal})}):e({newTotal:this.newTotal})},onShippingMethodSelected(e,t,a){const i=a.shippingMethod.identifier||a.shippingMethod.id;this.updateDeliveryMode(i).then(()=>{e({newTotal:this.newTotal})})},updateDeliveryMode(e){return this.$store.dispatch("delivery/updateDeliveryMode",{deliveryMode:e})},onSubmit(e){this.applePayToken=e?.data?.paymentMethod?.applePayToken},async onAuthorized(e,t,a){const i={billingContact:a.payment.billingContact,shippingContact:a.payment.shippingContact,token:this.applePayToken},s=this.generateSubmitOrderData(i,"ApplePay"),o=await f(s,this.deliveryFormConfiguration,"delivery");return o.status===y.SUCCESS?this.submitOrderData({orderData:s,resolve:e,reject:t}):o.type===u.OVERLAY?(this.updateDeliveryAddress(s),this.isFormOverlayVisible=!0,t({status:"FAILURE"})):(t({status:"FAILURE"}),this.notificationAlert(this.i18n(o.message)))},async submitOrderFromOverlay(){this.isFormOverlayVisible=!1,this.showLoader=!0,this.processedPaymentData.data.attributes.deliveryAddress=v(this.deliveryAddress);try{await this.submitOrderData({orderData:this.processedPaymentData,fromOverlay:!0})}finally{this.showLoader=!1}},submitOrderData({orderData:e,resolve:t,reject:a,fromOverlay:i}){return this.$store.dispatch("delivery/submitOrder",e).then(e=>{e?.attributes&&!e?.attributes?.actionType&&(window.location.href=`${this.configData.orderConfirmationUrl}?orderKey=${e.attributes.orderId}&authResult=Authorised&callbackType=success`,i||t({status:"SUCCESS"}))}).catch(e=>{c.call(this,e,i),i||a({status:"FAILURE"})})},notificationAlert(e){this.$store.dispatch("notification/updateErrorNotifications",{title:this.i18n("checkoutoverview.payment.cancel.title"),text:e},{root:!0})},updateDeliveryAddress(e){const t=g(e);this.processedPaymentData={...t},this.$store.dispatch("delivery/updateDeliveryAddress",t.data.attributes.deliveryAddress)},closeOverlay(){this.isFormOverlayVisible=!1,this.$refs.applepay.querySelector("button").click()}}},w={ref:"applepay",class:"digital-wallet__apple-pay"};const A=d(b,[["render",function(e,n,l,d,p,h){const c=t("digital-wallet-address-overlay"),y=t("overlay-submit-loader");return a(),i("section",null,[s("div",w,null,512),p.isFormOverlayVisible?(a(),o(c,{key:0,"wallet-type":"Apple Pay","close-overlay":h.closeOverlay,"submit-order":h.submitOrderFromOverlay},null,8,["close-overlay","submit-order"])):r("",!0),p.showLoader?(a(),o(y,{key:1})):r("",!0)])}]]);export{A as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.