1(()=>{"use strict";var t={n:e=>{var i=e&&e.__esModule?()=>e.default:()=>e;return t.d(i,{a:i}),i},d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wcPPCP.cart;var i=t.n(e);const n=window.wcPPCP.utils,a=window.wcPPCP.controllers,s=window.wcPPCP.context;var l=t.n(s);const o=window.jQuery;var p=t.n(o);const r=window.wcPPCP.actions;var c=t.n(r);const h=class{constructor({id:t,settings:e,controller:i}){this.id=t,this.settings=e,this.controller=i,this.paypal=null,this.capabilities=[],"payment_method"===this.settings.buttonPlacement&&this.capabilities.push("place_order_button"),this.actions=new(c())}initialize(){}setController(t){this.controller=t}setPayPal(t){this.paypal=t}async canMakePayment(){return!0}shouldCreateElement(t){return!0}async createPaymentElement(t){throw new Error("Must implement createPaymentElement()")}getOrderFieldKey(){return`${this.id}_paypal_order_id`}getTokenFieldKey(){return`${this.id}_payment_token`}enablePaymentElement(){}disablePaymentElement(){}destroyPaymentElement(){}validatePaymentElement(){return!0}supports(t){return this.capabilities.includes(t)}},d=class extends h{constructor(t){super(t),this.capabilities=[...this.capabilities,"api_form_validation"],this._applepay=null}get applepay(){return!this._applepay&&this.paypal?.Applepay&&(this._applepay=this.paypal.Applepay()),this._applepay}async canMakePayment(){if(!this.paypal?.Applepay)return!1;if(!window.ApplePaySession)return!1;if(!this.settings.supported_currencies.includes(this.controller.getCurrency()))return!1;if(!ApplePaySession.canMakePayments())return!1;try{return this.applepayConfig||(this.applepayConfig=await this.applepay.config()),this.applepayConfig.isEligible}catch(t){throw console.log(t),new n.ConfigurationError(t.message)}}shouldCreateElement(t){return!p()(t).find("button.wc-ppcp_applepay-button").length}async createPaymentElement(t){const e=p()(this.settings.html.button);e.addClass(`${this.controller.context.getPage()}-context`),e.attr("id",`wc-ppcp_applepay-button-${this.controller.context.getPage()}`),e.css({"-webkit-appearance":"-apple-pay-button","-apple-pay-button-type":this.settings.button.type,"-apple-pay-button-style":this.settings.button.style,"border-radius":this.settings.button.radius,height:this.settings.button.height}),e.on("click",this.onButtonClick.bind(this)),this.$button=e,p()(t).append(e)}onButtonClick(t){try{t.preventDefault(),this.controller.onClick();const e=new ApplePaySession(4,this.createPaymentRequest());e.oncancel=this.onCancel.bind(this),e.onvalidatemerchant=this.onValidateMerchant.bind(this,e),e.onpaymentauthorized=this.onPaymentAuthorized.bind(this,e),e.onshippingmethodselected=this.onShippingMethodSelected.bind(this,e),e.onshippingcontactselected=this.onShippingContactSelected.bind(this,e),this.controller.needsShipping()||this.controller.context.
1isOrderPay()||(e.onpaymentmethodselected=this.onPaymentMethodSelected.bind(this,e)),e.begin()}catch(t){this.controller.submitError(t?.statusMessage||t)}}createPaymentRequest(){const t=this.controller.context,e=this.controller.needsShipping()&&!t.isCheckout(),i={countryCode:this.applepayConfig.countryCode,merchantCapabilities:this.applepayConfig.merchantCapabilities,supportedNetworks:this.applepayConfig.supportedNetworks,currencyCode:this.controller.getCurrency(),total:{label:this.settings.i18n.total_label,type:"final",amount:this.controller.getTotal()},lineItems:this.mapLineItemsToApplePay(this.controller.getLineItems()),requiredShippingContactFields:[]};return!t.isCheckout()&&(i.requiredBillingContactFields=["postalAddress"],((0,n.isFieldRequired)("shipping_phone")||(0,n.isFieldRequired)("billing_phone"))&&i.requiredShippingContactFields.push("phone"),((0,n.isFieldRequired)("shipping_email")||(0,n.isFieldRequired)("billing_email"))&&i.requiredShippingContactFields.push("email")),e&&(i.requiredShippingContactFields.push("name","postalAddress"),this.controller.getShippingOptions().length>0&&(i.shippingMethods=this.mapShippingOptionsToApplePay(this.controller.getShippingOptions(),this.controller.getSelectedShippingMethod()))),this.actions.applyFilters("applepay_payment_request",i,this)}onCancel(){this.controller.onCancel()}async onValidateMerchant(t,e){try{const i=this.controller.context,n=await this.applepay.validateMerchant({validationUrl:e.validationURL,displayName:this.settings.display_name});i.isCheckout()||i.isOrderPay()?await this.controller.validate()||t.abort():i.isProduct()&&await this.controller.addToCart(),t.completeMerchantValidation(n.merchantSession)}catch(e){t.abort(),this.controller.submitError({code:e.errorName,message:e.message})}}async onPaymentMethodSelected(t,e){try{const{billingContact:i=null}=e.paymentMethod,n=await this.controller.onBillingChange({address:this.formatShippingAddress(i)});t.completePaymentMethodSelection(this.actions.applyFilters("applepay_complete_payment_method_selection",{newTotal:{label:this.settings.i18n.total_label,type:"final",amount:n.total},newLineItems:this.mapLineItemsToApplePay(n.lineItems)},this))}catch(e){t.completePaymentMethodSelection(this.actions.applyFilters("applepay_complete_payment_method_selection",{newTotal:{label:this.settings.i18n.total_label,type:"final",amount:this.controller.getTotal()},newLineItems:this.mapLineItemsToApplePay(this.controller.getLineItems())},this))}}async onShippingMethodSelected(t,e){const{identifier:i=null}=e.shippingMethod;try{const e=await this.controller.onShippingChange({address:null,shipping_method:i});t.completeShippingMethodSelection(this.actions.applyFilters("applepay_complete_shipping_method_selection",{newLineItems:this.mapLineItemsToApplePay(e.lineItems),newTotal:{label:this.settings.i18n.total_label,type:"final",amount:e.total}},this))}catch(e){t.abort(),this.controller.submitError(e)}}async onShippingContactSelected(t,e){try{const{shippingContact:i}=e,n=this.formatShippingAddress(i),a=await this.controller.onShippingChange({address:n,shipping_method:null});t.completeShippingContactSelection(this.actions.applyFilters("applepay_complete_shipping_contact_selection",{newLineItems:this.mapLineItemsToApplePay(a.lineItems),newShippingMethods:this.mapShippingOptionsToApplePay(a.shippingOptions,a.selectedShippingMethod),newTotal:{label:this.settings.i18n.total_label,type:"final",amount:a.total}},this))}catch(e){t.completeShippingContactSelection(this.actions.applyFilters("applepay_complete_shipping_contact_selection",{newTotal:{label:this.settings.i18n.total_label,type:"final",amount:this.controller.getTotal()},errors:[new ApplePayError("addressUnserviceable")]},this))}}async onPaymentAuthorized(t,e){try{const i=await this.controller.createOrder(),n=e.payment.billingContact||this.getBillingContact(),a=await this.applepay.confirmOrder({orderId:i,token:e.payment.token,billingContact:n});t.completePayment(ApplePaySession.STATUS_SUCCESS),await this.handleOrderStatus(a,i);const s=this.extractStandardizedCheckoutData(e);this.controller.submit(s)}catch(e){this.controller.submitError(e.message),t.completePayment(ApplePaySession.STATUS_FAILURE)}}async handleOrderStatus(t,e){"APPROVED"===t.approveApplePayPayment.status&&(0,n.setFieldValue)(this.getOrderFieldKey(),e,null)}getBillingContact(){return{givenName:(0,n.getFieldValue)("billing_first_name"),familyName:(0,n.getFieldValue)("billing_last_name"),locality:(0,n.getFieldValue)("billing_city"),addressLines:[(0,n.getFieldValue)("billing_address_1"),(0,n.getFieldValue)("billing_address_2")].filter(
1Boolean),postalCode:(0,n.getFieldValue)("billing_postcode"),administrativeArea:(0,n.getFieldValue)("billing_state"),countryCode:(0,n.getFieldValue)("billing_country")}}mapLineItemsToApplePay(t){return t.map(t=>({type:"final",label:t.label,amount:t.amount}))}mapShippingOptionsToApplePay(t,e){return t.map(t=>({label:t.label,detail:t.description||"",amount:t.amount,identifier:t.id})).sort((t,i)=>t.identifier===e?-1:i.identifier===e?1:parseFloat(t.amount)-parseFloat(i.amount))}extractStandardizedCheckoutData(t){let e={billing:{},shipping:{}};if(!t.payment)return e;const i=t.payment;if(i.billingContact){const t=i.billingContact,n={};n.first_name=t.givenName||"",n.last_name=t.familyName||"",n.address_1=t.addressLines?.[0]||"",n.address_2=t.addressLines?.slice(1).join(" ")||"",n.city=t.locality||"",n.state=t.administrativeArea||"",n.postcode=t.postalCode||"",n.country=t.countryCode||"",t.phoneNumber&&(n.phone=t.phoneNumber),t.emailAddress&&(n.email=t.emailAddress),e.billing=n}if(i.shippingContact){const t=i.shippingContact,n={};n.first_name=t.givenName||"",n.last_name=t.familyName||"",n.address_1=t.addressLines?.[0]||"",n.address_2=t.addressLines?.slice(1).join(" ")||"",n.city=t.locality||"",n.state=t.administrativeArea||"",n.postcode=t.postalCode||"",n.country=t.countryCode||"",t.phoneNumber&&(n.phone=t.phoneNumber,e.billing.phone=t.phoneNumber),t.emailAddress&&(n.email=t.emailAddress,e.billing.email=t.emailAddress),e.shipping=n}return e}formatShippingAddress(t){return{postcode:t.postalCode,city:t.locality,state:t.administrativeArea?.toUpperCase(),country:t.countryCode?.toUpperCase()}}
1disablePaymentElement(){this.controller.context.isOrderPay()||(this.$button?.prop("disabled",!0),this.$button?.addClass("disabled"))}enablePaymentElement(){this.$button?.prop("disabled",!1)}destroyPaymentElement(){this.$button?.remove()}},m=(0,n.getSetting)("ppcp_applepay_data"),{disabled:y=!1}=m;if(!y){const t=new d({id:"ppcp_applepay",cart:i(),settings:m}),e=new(l())("cart");new a.CartController({id:"ppcp_applepay",cart:i(),context:e,gateway:t,settings:m}).initialize()}(this.wcPPCP=this.wcPPCP||{}).applepayCart={}})(); 2//# sourceMappingURL=applepay-cart.js.map
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.