1"use strict";(globalThis.webpackChunksfra_boilerplate=globalThis.webpackChunksfra_boilerplate||[]).push([[2595],{6943:(e,t,s)=>{s.r(t),s.d(t,{default:()=>n});var r=s(900),i=s(5131);function n(e){return class extends e{stripe={};stripeOptions={};stripePaymentElements={};paymentIntent={};shippingForm={shippingOption:{},shippingAddress:{}};paymentRequest={};prefs(){return{apiVersion:"",publicKey:"",urlCancelIntent:"",customCardGroup:"stripe-custom-card-group",stripeCreditCard:"stripeCreditCard",billingForm:"dwfrm_billing",shippingForm:"dwfrm_shipping",beforePaymentSubmitURL:"beforePaymentSubmitURL",getStripeOrderItemsURL:"getStripeOrderItemsURL",paymentMethod:"stripe_source_id",stripeScriptUrl:"",errorFieldClass:"m-invalid",cartInvalid:!1,requiredField:"",techicalError:"",action:"",addShippingAndBillingToBasketUrl:"",urlPlaceOrder:"",getShippingOptionsUrl:"",selectShippingMethodUrl:"",updateShippingAddressUrl:"",errors:{general_error:"",payment_error:"",payment_rejected:"",validation_city:"Please enter a valid city name",validation_address:"Please enter a valid address"},paymentRequestDivElementClass:"payment-request-button",currentError:"",isGooglePayEnabled:"",isApplePayEnabled:"",isValidateApplePayShipping:"",...super.prefs()}}onRefresh(){this.init()}init(){(0,r.ve)(this.prefs().stripeScriptUrl).then(()=>{this.stripe=Stripe(this.prefs().publicKey,this.getOptions()),this.createElements()}),this.eventBus().on("cart.updated","onCartUpdated"),this.prefs().cartInvalid&&this.hide()}onCartUpdated(){this.ref("button").empty()}getOptions(){return this.prefs().apiVersion&&(this.stripeOptions.apiversion=this.prefs().apiVersion),this.stripeOptions}getShippingOptions(){return(0,i.I7)(this.prefs().getShippingOptionsUrl,void 0,"GET").then(e=>e.shippingOptions).catch(e=>{this.showError(e.message||this.prefs().errors.general_error)})}createElements(){(0,i.I7)(this.prefs().getStripeOrderItemsURL,void 0,"GET").then(async e=>{if(e&&e.amount&&e.currency&&e.country){this.stripePaymentElements=this.stripe.elements(),this.paymentRequest=this.stripe.paymentRequest({country:e.country,currency:e.currency,shippingOptions:[],total:{label:"Total",amount:e.amount},requestPayerName:!0,requestPayerEmail:!0,requestPayerPhone:!0,requestShipping:!0,disableWallets:this.getDisableWallets(),displayItems:this.getDisplayItems(JSON.parse(e.orderItems))});let t=this.stripePaymentElements.getElement("paymentRequestButton");if(t||(t=this.stripePaymentElements.create("paymentRequestButton",{paymentRequest:this.paymentRequest})),await this.paymentRequest.canMakePayment()){const e=this.ref("self").get()?.querySelector("."+this.prefs().paymentRequestDivElementClass);e&&t.mount(e)}else document.querySelector("."+this.prefs().paymentRequestDivElementClass).style.display="none",this.eventBus().emit("hide.stripe.button");this.addEventListeners()}}).catch(e=>{this.showError(e.message)})}addEventListeners(){this.paymentRequest.on("shippingoptionchange",async e=>{var t=e.updateWith,s=e.shippingOption;let r=await this.updateShippingOption(s);r&&t(r)}),this.paymentRequest.on("shippingaddresschange",async e=>{var t=e.updateWith,s=e.shippingAddress;let r=await this.updateShippingAddress(s);r&&t(r)}),this.paymentRequest.on("paymentmethod",async e=>{const t="apple-pay"===e.methodName,s=this.checkBeforeValidate(t,e.shippingAddress);if(!s.valid)throw e.complete("fail"),this.eventBus().emit("alert.error",{accessibilityAlert:s.errors.join("; "),vitalError:!0}),new Error(this.prefs().errors.general_error);{await(0,i.Zx)(this.prefs().updateShippingAddressUrl,e.shippingAddress),this.paymentIntent=await this.retreivePaymentIntent(e);let t=await this.confirmCardPayment(this.paymentIntent.client_secret,e.paymentMethod.id,!1);if(t.errorMessage)throw this.cancelPaymentIntent(this.paymentIntent.id),e.complete("fail"),new Error(this.prefs().errors.general_error);if(t.paymentIntent)return void this.placeAndConfirmOrderWithPR(t.paymentIntent,e)}})}checkBeforeValidate(e,t){if(!e||!this.prefs().isValidateApplePayShipping)return{valid:!0,errors:[]};const s=/[\u0400-\u04FF]/,r=[];return s.test(t.city)&&r.push(this.prefs().errors.validation_city),s.test(t.addressLine[0])&&r.push(this.prefs().errors.validation_address),r.length>0?{valid:!1,errors:r}:{valid:!0,errors:[]}}getDisableWallets(){let e=[];return this.prefs().isGooglePayEnabled||e.push("googlePay"),this.prefs().isApplePayEnabled||e.push("applePay"),e}getDisplayItems(e){return e.map(e=>({label:e.description,amount:e.amount}))}retreivePaymentIntent(e){return(0,i.I7)(this.prefs().beforePaymentSubmitURL,{type:"paymentelement",payerEmail:e&&e.payerEmail?e.payerEmail:"",payerName:e&&e.payerName?e.payerName:""},"POST").then(e=>e.paymentIntent)}confirmCardPayment(e,t,s){return this.stripe.confirmCardPayment(e,{payment_method:t},{handleActions:s}).then(e=>e.error?Promise.reject({errorMessage:e.error.message}):Promise.resolve(e)).catch(()=>({errorMessage:"Stripe Confirm Error"}))}
1showError(e){this.emit("error",e)}updateShippingAddress(e){return(0,i.Zx)(this.prefs().updateShippingAddressUrl,e).then(async e=>e&&!e.success?{status:"invalid_shipping_address"}:e.success&&e.total&&e.displayItems?{status:"success",total:{amount:e.total.amount,label:"Total"},shippingOptions:await this.getShippingOptions(),displayItems:this.getDisplayItems(JSON.parse(e.displayItems))}:void 0)}updateShippingOption(e){return(0,i.I7)(this.prefs().selectShippingMethodUrl,{methodID:e?e.id:"001"}).then(e=>e.success&&e.amount&&e.displayItems?{status:"success",total:{amount:e.amount,label:"Total"},displayItems:this.getDisplayItems(JSON.parse(e.displayItems))}:{status:"fail"})}placeAndConfirmOrderWithPR(e,t){(0,i.Zx)(this.prefs().addShippingAndBillingToBasketUrl,{paymentIntent:e,eventData:t}).then(s=>{if(s.addressFailed)return this.cancelPaymentIntent(this.paymentIntent.id),t.complete("invalid_shipping_address");const r="Payment Method: "+e.payment_method+" Intent Status: "+e.status;(0,i.I7)(this.prefs().urlPlaceOrder,{agreeToPrivacy:!0,confirmNote:r}).then(e=>{this.handlePlaceOrderSubmissionResponse(e,t)}).catch(e=>{this.showError(e.message)})})}handlePlaceOrderSubmissionResponse(e,t){if(e&&e.redirectUrl)t.complete("fail"),window.location.assign(e.redirectUrl);else{if(e&&!e.success)throw t.complete("fail"),new Error(e.errorMessage||this.prefs().errors.general_error);e&&e.continueUrl&&(t.complete("success"),window.location.assign((0,r.mq)(e.continueUrl,{ID:e.orderID,token:e.orderToken})))}}
1cancelPaymentIntent(e){(0,i.I7)(this.prefs().urlCancelIntent,{paymentIntentId:e},"POST").catch(e=>{console.log("cancelIntent failed",e)})}}}}}]);
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.