1(()=>{"use strict";var e={n:t=>{var i=t&&t.__esModule?()=>t.default:()=>t;return e.d(i,{a:i}),i},d:(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.jQuery;var i=e.n(t);const s=window.wp.apiFetch;var n=e.n(s);const a=window.wp.hooks,r=window.wcPPCP.utils,l=window.lodash,o=class{constructor({id:e,context:t,actions:i,container:s=null}){this.id=e,this.actions=i,this.buttons={},this.buttonActions={},this.context=t,this.settings=(0,r.getSetting)(`${e}_data`),this.container=s||`li.payment_method_${e}`,this.order_field_key=`${this.id}_paypal_order_id`,this.billing_token_key=`${this.id}_billing_token`}initialize(){this.loadPayPalScript().then(()=>{this.initializeEvents(),this.createButton()})}initializeEvents(){}isActive(){return null!==this.getData()}loadPayPalScript(){return new Promise((e,t)=>{(0,r.loadPayPalSdk)(this.getPayPalSDKArgs()).then(t=>{this.paypal=t,e()}).catch(e=>{console.log(e),e?.code&&this.submitError((0,r.getErrorMessage)(e)),t()})})}getPayPalSDKArgs(){return(0,r.getPayPalQueryParams)()}getClientId(){let{clientId:e=null,environment:t}=(0,r.getSetting)("generalData");return e||"sandbox"!=t||(e="sb"),e}getData(){return i()(`${this.container}`).find(".wc-ppcp-payment-method-data").data("payment-method-data")||null}setData(e){i()(`${this.container}`).find(".wc-ppcp-payment-method-data").data("payment-method-data",e)}setOption(e,t){const i=this.getData();i&&(i[e]=t,this.setData(i))}setVariable(e,t){(0,r.getSetting)(`${this.id}_data`)[e]=t}getVariable(e,t=null){const i=(0,r.getSetting)(`${this.id}_data`);return i.hasOwnProperty(e)?i[e]:(t&&this.setVariable(e,t),t)}getOption(e,t=null){const i=this.getData();return i.hasOwnProperty(e)?i[e]:(t&&this.setOption(e,t),t)}createButton(){const e=this.getButtonContainer();e&&!i()(e).find(".paypal-buttons").length&&(this.getSortedFunding(this.getFunding()).forEach(t=>{const i=this.paypal.Buttons(this.getButtonOptions(t));if(this.buttons[t]=i,i.isEligible())if(e instanceof NodeList)for(const t of e)i.render(t);else i.render(e)}),this.$button=i()(e),a.defaultHooks.doAction("wcPPCPButtonCreated",this))}getButton(){return this.$button}destroyButtons(){Object.keys(this.buttons).forEach(e=>{this.buttons[e].close&&this.buttons[e].close()})}disableButtons(){Object.keys(this.buttonActions).forEach(e=>{this.buttonActions[e].disable()})}enableButtons(){Object.keys(this.buttonActions).forEach(e=>{this.buttonActions[e].enable()})}getFunding(){const e=[],t=this.settings?.funding||[];return this.settings?.paypal_sections?.includes(this.getPage())&&e.push(paypal.FUNDING.PAYPAL),t.includes("paylater")&&this.settings?.paylater_sections?.includes(this.getPage())&&this.isCheckoutFlow()&&e.push(paypal.FUNDING.PAYLATER),t.includes("card")&&this.settings?.credit_card_sections?.includes(this.getPage())&&e.push(paypal.FUNDING.CARD),e}isFundingActive(e){return this.settings?.funding?.includes(e)}isSectionEnabled(e,t){const i=`${e}_sections`;return this.settings?.[i]?.includes(t)}getSortedFunding(e){const t=this.settings.buttons_order||[];return e.sort((e,i)=>t.indexOf(e)<t.indexOf(i)?-1:1),e}getButtonContainer(){return null}getButtonOptions(e){const t={fundingSource:e,style:this.getButtonStyle(e),onInit:(...t)=>{this.onInit(e,...t),i()(document.body).triggerHandler("wc_ppcp_on_init",[this,e])},onClick:(...t)=>{this.onClick(...t),i()(document.body).triggerHandler("wc_ppcp_on_click",[this,e])},onApprove:(t,s)=>{this.onApprove(t,s),i()(document.body).triggerHandler("wc_ppcp_on_approve",[this,e])},onCancel:t=>{this.orderId=t.orderID,i()(document.body).triggerHandler("wc_ppcp_on_cancel",[this,e,t])},onError:t=>{this.currentError?(this.submitError(this.currentError),this.currentError=null):this.submitError(t),i()(document.body).triggerHandler("wc_ppcp_on_error",[this,e,t])},onDestroy:()=>{i()(document.body).triggerHandler("wc_ppcp_on_destroy",[this,e])}};return this.isCheckoutFlow()?(t.createOrder=(e,t)=>this.createOrder(e,t),this.needsShipping()&&e!==paypal.FUNDING.VENMO&&!this.settings.serverSideShippingCallback&&(t.onShippingChange=(...e)=>this.onShippingChange(...e))):t.createBillingAgreement=(...e)=>this.createBillingAgreement(...e),t}needsShipping(){return this.getOption("needsShipping",!1)}isCheckoutFlow(){return"true"!==(0,r.getPayPalQueryParams)()?.vault}getTotal(){return this.getOption("total",0)}getButtonStyle(e){let t=null;switch(e){case paypal.FUNDING.PAYPAL:t=this.settings?.buttons?.payp
1al;break;case paypal.FUNDING.PAYLATER:t=this.settings?.buttons?.paylater;break;case paypal.FUNDING.CARD:t={...this.settings?.buttons?.card},t.tagline?(delete t.tagline,t.layout="vertical"):t.layout="horizontal";break;case paypal.FUNDING.VENMO:const{color:e="",label:i="",...s}=this.settings?.buttons?.paypal;t=s}return t?.height&&(t.height=parseInt(t.height)),t}onApprove(e,t){if((0,r.setFieldValue)(this.order_field_key,e.orderID,""),e.billingToken)return(0,r.setFieldValue)(this.billing_token_key,e.billingToken,""),this.fetchBillingToken(e.billingToken).then(t=>{this.handleBillingToken(t,e)}).catch(e=>this.submitError(e?.message));t.order.get().then(t=>{this.handleOnApproveResponse(e,t)}).catch(e=>this.submitError(e))}handleOnApproveResponse(e,t){this.populateCheckoutFields(t),this.processCartCheckout()}fetchBillingToken(e){return n()({method:"GET",path:`/wc-ppcp/v1/billing-agreement/token/${e}`})}handleBillingToken(e,t){if((0,l.isEmpty)(e.payer_info.billing_address)||this.populateBillingAddressFields((0,r.convertPayPalAddressToCart)(e.payer_info.billing_address)),e?.payer_info?.first_name&&((0,r.isValid)("billing_first_name")||(0,r.setFieldValue)("first_name",e.payer_info.first_name,"billing")),e?.payer_info?.last_name&&((0,r.isValid)("billing_last_name")||(0,r.setFieldValue)("last_name",e.payer_info.last_name,"billing")),e?.payer_info?.email&&((0,r.isValid)("billing_email")||(0,r.setFieldValue)("billing_email",e.payer_info.email)),e?.payer_info?.phone&&((0,r.isValid)("billing_phone")||(0,r.setFieldValue)("billing_phone",e.payer_info.phone)),this.needsShipping()&&e.shipping_address&&!(0,l.isEmpty)(e.shipping_address)){var i;let t=(0,r.convertPayPalAddressToCart)(e.shipping_address);var s;if(this.populateNameFields((0,r.extractFullName)(null!==(i=e.shipping_address.recipient_name)&&void 0!==i?i:""),"shipping"),this.populateShippingAddressFields(t),!(0,r.isValidAddress)(this.getCartFullAddress("billing"),["phone","email"]))(0,r.isValidFieldValue)((0,r.getFieldValue)("billing_first_name"))||(0,r.isValidFieldValue)((0,r.getFieldValue)("billing_last_name"))||this.populateNameFields(null!==(s=e.shipping_address.recipient_name)&&void 0!==s?s:"","billing"),this.populateBillingAddressFields(t)}}createOrder(e,t){return t.order.create(args)}async createBillingAgreement(e,t,i=null){return n()({method:"POST",url:(0,r.getRestPath)("/wc-ppcp/v1/billing-agreement/token"),data:await this.actions.applyFiltersAsync("create_billing_agreement_data",{payment_method:this.id,c
1ontext:this.getPage(),...i})}).then(e=>e).catch(e=>{this.currentError=e})}onShippingChange(e,t,i={}){const s=(0,r.convertPayPalAddressToCart)(e?.shipping_address||{},!0),a=e?.selected_shipping_option?.id||"";return n()({method:"POST",url:(0,r.getRestRoute)("cart/shipping"),data:{order_id:e.orderID,address:s,shipping_method:a,payment_method:this.id,...i}}).then(e=>e.code?t.reject():t.resolve()).catch(e=>t.reject())}submitError(e){}getShippingPrefix(){return"shipping"}getCartAddress(e){return{address_1:(0,r.getFieldValue)("address_1",e),address_2:(0,r.getFieldValue)("address_2",e),state:(0,r.getFieldValue)("state",e),city:(0,r.getFieldValue)("city",e),postcode:(0,r.getFieldValue)("postcode",e),country:(0,r.getFieldValue)("country",e)}}getCartFullAddress(e){return{first_name:(0,r.getFieldValue)("first_name",e),last_name:(0,r.getFieldValue)("last_name",e),address_1:(0,r.getFieldValue)("address_1",e),address_2:(0,r.getFieldValue)("address_2",e),state:(0,r.getFieldValue)("state",e),city:(0,r.getFieldValue)("city",e),postcode:(0,r.getFieldValue)("postcode",e),country:(0,r.getFieldValue)("country",e)}}onInit(e,t,i){this.buttonActions[e]=i}onClick(e,t){}isPage(e){return this.getPage()===e}getPage(){let e=(0,r.getSetting)("generalData")?.page;return"cart"==e&&i()(document.body).is(".woocommerce-checkout")&&(e="checkout"),e}populateShippingAddressFields(e){for(let t in e)(0,r.setFieldValue)(t,e[t],"shipping")}populateBillingAddressFields(e){for(let t in e)(0,r.setFieldValue)(t,e[t],"billing")}populateNameFields(e,t=""){let i,s;Array.isArray(e)?[i,s]=e:({given_name:i,surname:s}=e),(0,r.setFieldValue)("first_name",i,t),(0,r.setFieldValue)("last_name",s,t)}populateCheckoutFields(e){if(!(0,l.isEmpty)(e?.payer?.address)){let t=(0,r.convertPayPalAddressToCart)(e.payer.address);this.populateBillingAddressFields(t)}if(e?.payer?.name&&this.populateNameFields(e.payer.name,"billing"),e?.payer?.email_address&&(0,r.setFieldValue)("billing_email",e.payer.email_address),e?.payer?.phone?.phone_number?.national_number&&((0,r.setFieldValue)("billing_phone",e.payer.phone.phone_number.national_number),(0,r.setFieldValue)("shipping_phone",e.payer.phone.phone_number.national_number)),this.needsShipping()&&e?.purchase_units?.[0]?.shipping){const t=(0,r.convertPayPalAddressToCart)(e.purchase_units[0].shipping.address);if(this.populateShippingAddressFields(t),e.purchase_units[0].shipping?.name?.full_name){const t=(0,r.extractFullName)(e.purchase_units[0].shipping.name.full_name);this.populateNameFields(t,"shipping")}(0,r.isValidAddress)(this.getCartFullAddress("billing"),["phone","email"])||this.populateBillingAddressFields(t)}}processCartCheckout(){return this.showProcessing(),n()({method:"POST",url:(0,r.getRestRoute)("cart/checkout"),data:this.getCartCheckoutData()}).then(e=>{if(e.result&&"success"==e.result)window.location=e.redirect;else if(e.messages)return this.submitError(e.messages)}).catch(e=>{e.code&&this.submitError(e.message)})}
1getCartCheckoutData(){return{payment_method:this.id,context:this.getPage(),...(0,r.fieldsToJson)()}}getProcessingSelector(){return"body"}showProcessing(){i()(this.getProcessingSelector())?.block({message:this.getProcessingMessage(),overlayCSS:{background:"#fff",opacity:.6}})}hideProcessing(){i()(this.getProcessingSelector())?.unblock()}getProcessingMessage(){return'<div class="wc-ppcp-loader">\n <div></div>\n <div></div>\n <div></div>\n </div>'}getFullName(e){const t=[(0,r.getFieldValue)("first_name",e),(0,r.getFieldValue)("last_name",e)].filter(Boolean);return 0==t.length?null:1==t.length?t[0]:`${t[0]} ${t[1]}`}},d=window.wcPPCP.cart;var p=e.n(d);const c=window.wcPPCP.actions;var h=e.n(c);new class extends o{constructor(e,t){super(t),this.cart=e,this.initialize()}initialize(){this.actions.addAction("cart_updated",this.onCartUpdated.bind(this)),i()(window).on("resize",this.doCartHtml.bind(this)),super.initialize(),this.doCartHtml()}onInit(...e){super.onInit(...e),this.cart.trigger("cart_button_on_init")}needsShipping(){return this.cart.needsShipping()}getButtonContainer(){return document.getElementById("wc-ppcp-cart-button-container")}onCartUpdated(){super.initialize(),this.doCartHtml()}submitError(e){this.hideProcessing(),(0,r.submitErrorMessage)(e,"div.woocommerce-notices-wrapper","checkout")}handleBillingToken(e){super.handleBillingToken(e),this.processCartCheckout()}createOrder(e,t){return this.cart.createOrder({payment_method:this.id}).catch(e=>(this.currentError=e,e))}doCartHtml(){const e=i()(".checkout-button"),t=e.outerWidth();t&&i()(".wc-ppcp-cart-payments__container").length&&i()(".wc-ppcp-cart-payments__container").width(t),"none"!==e.css("float")&&i()(".wc-ppcp-cart-payments__container ").css("float",e.css("float")),i()(".wc-ppcp-cart-payments__container").show()}}(p(),{id:"ppcp",actions:new(h()),context:"cart"}),(this.wcPPCP=this.wcPPCP||{}).paypalCart={}})(); 2//# sourceMappingURL=paypal-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.