From a9e0cc0cf716bf9ba173da8ef097956788c47bd6 Mon Sep 17 00:00:00 2001 From: David Remer Date: Tue, 28 Apr 2020 09:14:05 +0300 Subject: [PATCH] PCP-13 // add payer information to mini-cart, cart and single product --- modules.local/ppcp-button/assets/js/button.js | 2 +- .../ppcp-button/assets/js/button.js.map | 2 +- modules.local/ppcp-button/package-lock.json | 11 +++++-- .../resources/js/modules/CartActionHandler.js | 3 ++ .../js/modules/CheckoutActionHandler.js | 23 ++------------ .../ppcp-button/resources/js/modules/Payer.js | 27 ++++++++++++++++ .../js/modules/SingleProductActionHandler.js | 5 ++- .../ppcp-button/src/Assets/SmartButton.php | 31 ++++++++++++++++++- .../src/Endpoint/CreateOrderEndpoint.php | 2 +- 9 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 modules.local/ppcp-button/resources/js/modules/Payer.js diff --git a/modules.local/ppcp-button/assets/js/button.js b/modules.local/ppcp-button/assets/js/button.js index 82c8192ac..43f76b5cc 100644 --- a/modules.local/ppcp-button/assets/js/button.js +++ b/modules.local/ppcp-button/assets/js/button.js @@ -1,2 +1,2 @@ -!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n=class{constructor(){this.wrapper=document.querySelector(".woocommerce-notices-wrapper")}message(e){this.wrapper.classList.add("woocommerce-error"),this.wrapper.innerText=this.sanitize(e)}sanitize(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}clear(){this.wrapper.classList.contains("woocommerce-error")&&(this.wrapper.classList.remove("woocommerce-error"),this.wrapper.innerText="")}};var o=e=>(t,r)=>fetch(e.config.ajax.approve_order.endpoint,{method:"POST",body:JSON.stringify({nonce:e.config.ajax.approve_order.nonce,order_id:t.orderID})}).then(e=>e.json()).then(t=>{t.success&&(location.href=e.config.redirect)});var a=class{constructor(e,t){this.config=e,this.errorHandler=t}configuration(){return{createOrder:(e,t)=>fetch(this.config.ajax.create_order.endpoint,{method:"POST",body:JSON.stringify({nonce:this.config.ajax.create_order.nonce,purchase_units:[]})}).then((function(e){return e.json()})).then((function(e){if(e.success)return e.data.id})),onApprove:o(this),onError:e=>{this.errorHandler.message(e)}}}};var i=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.render(),jQuery(document.body).on("wc_fragments_loaded wc_fragments_refreshed",()=>{this.render()})}shouldRender(){return null!==document.querySelector(this.gateway.button.mini_cart_wrapper)}render(){if(!this.shouldRender())return;const e=new a(PayPalCommerceGateway,new n);this.renderer.render(this.gateway.button.mini_cart_wrapper,e.configuration())}};var s=class{constructor(e,t,r){this.id=e,this.quantity=t,this.variations=r}data(){return{id:this.id,quantity:this.quantity,variations:this.variations}}};var c=class{constructor(e,t){this.endpoint=e,this.nonce=t}update(e,t){return new Promise((r,n)=>{fetch(this.endpoint,{method:"POST",body:JSON.stringify({nonce:this.nonce,products:t})}).then(e=>e.json()).then(t=>{if(!t.success)return void n(t.data);const o=e(t.data);r(o)})})}};var u=class{constructor(e,t,r){this.element=e,this.showCallback=t,this.hideCallback=r,this.observer=null}init(){const e=()=>{this.element.classList.contains("disabled")?this.hideCallback():this.showCallback()};this.observer=new MutationObserver(e),this.observer.observe(this.element,{attributes:!0}),e()}disconnect(){this.observer.disconnect()}};var d=class{constructor(e,t,r,n,o,a){this.config=e,this.updateCart=t,this.showButtonCallback=r,this.hideButtonCallback=n,this.formElement=o,this.errorHandler=a}configuration(){if(this.hasVariations()){new u(this.formElement.querySelector(".single_add_to_cart_button"),this.showButtonCallback,this.hideButtonCallback).init()}return{createOrder:this.createOrder(),onApprove:o(this),onError:e=>{this.errorHandler.message(e)}}}createOrder(){var e=null;e=this.isGroupedProduct()?()=>{const e=[];return this.formElement.querySelectorAll('input[type="number"]').forEach(t=>{if(!t.value)return;const r=t.getAttribute("name").match(/quantity\[([\d]*)\]/);if(2!==r.length)return;const n=parseInt(r[1]),o=parseInt(t.value);e.push(new s(n,o,null))}),e}:()=>{const e=document.querySelector('[name="add-to-cart"]').value,t=document.querySelector('[name="quantity"]').value,r=this.variations();return[new s(e,t,r)]};return(t,r)=>{this.errorHandler.clear();return this.updateCart.update(e=>fetch(this.config.ajax.create_order.endpoint,{method:"POST",body:JSON.stringify({nonce:this.config.ajax.create_order.nonce,purchase_units:e})}).then((function(e){return e.json()})).then((function(e){if(e.success)return e.data.id})),e())}}variations(){if(!this.hasVariations())return null;return[...this.formElement.querySelectorAll("[name^='attribute_']")].map(e=>({value:e.value,name:e.name}))}hasVariations(){return this.formElement.classList.contains("variations_form")}isGroupedProduct(){return this.formElement.classList.contains("grouped_form")}};var l=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.shouldRender()&&this.render()}shouldRender(){return null!==document.querySelector("form.cart")&&null!==document.querySelector(this.gateway.button.wrapper)}render(){const e=new d(this.gateway,new c(this.gateway.ajax.change_cart.endpoint,this.gateway.ajax.change_cart.nonce),()=>{this.renderer.showButtons(this.gateway.button.wrapper)},()=>{this.renderer.hideButtons(this.gateway.button.wrapper)},document.querySelector("form.cart"),new n);this.renderer.render(this.gateway.button.wrapper,e.configuration())}};var h=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.shouldRender()&&(this.render(),jQuery(document.body).on("updated_cart_totals updated_checkout",()=>{this.render()}))}shouldRender(){return null!==document.querySelector(this.gateway.button.wrapper)}render(){const e=new a(PayPalCommerceGateway,new n);this.renderer.render(this.gateway.button.wrapper,e.configuration())}};var m=e=>(t,r)=>fetch(e.config.ajax.approve_order.endpoint,{method:"POST",body:JSON.stringify({nonce:e.config.ajax.approve_order.nonce,order_id:t.orderID})}).then(e=>e.json()).then(e=>{e.success&&document.querySelector("#place_order").click()});var y=class{constructor(e,t){this.config=e,this.errorHandler=t}configuration(){return{createOrder:(e,t)=>{const r={email_address:document.querySelector("#billing_email")?document.querySelector("#billing_email").value:"",name:{surname:document.querySelector("#billing_last_name")?document.querySelector("#billing_last_name").value:"",given_name:document.querySelector("#billing_first_name")?document.querySelector("#billing_first_name").value:""},address:{country_code:document.querySelector("#billing_country")?document.querySelector("#billing_country").value:"",address_line_1:document.querySelector("#billing_address_1")?document.querySelector("#billing_address_1").value:"",address_line_2:document.querySelector("#billing_address_2")?document.querySelector("#billing_address_2").value:"",admin_area_1:document.querySelector("#billing_city")?document.querySelector("#billing_city").value:"",admin_area_2:document.querySelector("#billing_state")?document.querySelector("#billing_state").value:"",postal_code:document.querySelector("#billing_postcode")?document.querySelector("#billing_postcode").value:""},phone:{phone_type:"HOME",phone_number:{national_number:document.querySelector("#billing_phone")?document.querySelector("#billing_phone").value:""}}};return fetch(this.config.ajax.create_order.endpoint,{method:"POST",body:JSON.stringify({nonce:this.config.ajax.create_order.nonce,payer:r})}).then((function(e){return e.json()})).then((function(e){if(e.success)return e.data.id}))},onApprove:m(this),onError:e=>{this.errorHandler.message(e)}}}};var p=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.shouldRender()&&(this.render(),jQuery(document.body).on("updated_checkout",()=>{this.render()}),jQuery(document.body).on("updated_checkout payment_method_selected",()=>{this.switchBetweenPayPalandOrderButton()}))}shouldRender(){return!document.querySelector(this.gateway.button.cancel_wrapper)&&null!==document.querySelector(this.gateway.button.wrapper)}render(){const e=new y(PayPalCommerceGateway,new n);this.renderer.render(this.gateway.button.wrapper,e.configuration())}switchBetweenPayPalandOrderButton(){"ppcp-gateway"!==jQuery('input[name="payment_method"]:checked').val()?(this.renderer.hideButtons(this.gateway.button.wrapper),jQuery("#place_order").show()):(this.renderer.showButtons(this.gateway.button.wrapper),jQuery("#place_order").hide())}};var f=class{constructor(e){this.defaultConfig=e}render(e,t){if(this.isAlreadyRendered(e))return;const r=this.defaultConfig.button.style;paypal.Buttons({style:r,...t}).render(e)}isAlreadyRendered(e){return document.querySelector(e).hasChildNodes()}hideButtons(e){document.querySelector(e).style.display="none"}showButtons(e){document.querySelector(e).style.display="block"}};document.addEventListener("DOMContentLoaded",()=>{const e=document.createElement("script");e.setAttribute("src",PayPalCommerceGateway.button.url),e.addEventListener("load",e=>{(()=>{const e=new f(PayPalCommerceGateway),t=PayPalCommerceGateway.context;if("mini-cart"===t||"product"===t){new i(PayPalCommerceGateway,e).init()}if("product"===t){new l(PayPalCommerceGateway,e).init()}if("cart"===t){new h(PayPalCommerceGateway,e).init()}if("checkout"===t){new p(PayPalCommerceGateway,e).init()}})()}),document.body.append(e)})}]); +!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n=class{constructor(){this.wrapper=document.querySelector(".woocommerce-notices-wrapper")}message(e){this.wrapper.classList.add("woocommerce-error"),this.wrapper.innerText=this.sanitize(e)}sanitize(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value.replace("Error: ","")}clear(){this.wrapper.classList.contains("woocommerce-error")&&(this.wrapper.classList.remove("woocommerce-error"),this.wrapper.innerText="")}};var o=e=>(t,r)=>fetch(e.config.ajax.approve_order.endpoint,{method:"POST",body:JSON.stringify({nonce:e.config.ajax.approve_order.nonce,order_id:t.orderID})}).then(e=>e.json()).then(t=>{if(!t.success)throw Error(t.data);location.href=e.config.redirect});const a=()=>{const e=PayPalCommerceGateway.payer;return e?{email_address:document.querySelector("#billing_email")?document.querySelector("#billing_email").value:e.email_address,name:{surname:document.querySelector("#billing_last_name")?document.querySelector("#billing_last_name").value:e.name.surname,given_name:document.querySelector("#billing_first_name")?document.querySelector("#billing_first_name").value:e.name.given_name},address:{country_code:document.querySelector("#billing_country")?document.querySelector("#billing_country").value:e.address.country_code,address_line_1:document.querySelector("#billing_address_1")?document.querySelector("#billing_address_1").value:e.address.address_line_1,address_line_2:document.querySelector("#billing_address_2")?document.querySelector("#billing_address_2").value:e.address.address_line_2,admin_area_1:document.querySelector("#billing_city")?document.querySelector("#billing_city").value:e.address.admin_area_1,admin_area_2:document.querySelector("#billing_state")?document.querySelector("#billing_state").value:e.address.admin_area_2,postal_code:document.querySelector("#billing_postcode")?document.querySelector("#billing_postcode").value:e.address.postal_code},phone:{phone_type:"HOME",phone_number:{national_number:document.querySelector("#billing_phone")?document.querySelector("#billing_phone").value:e.phone.phone_number.national_number}}}:null};var i=class{constructor(e,t){this.config=e,this.errorHandler=t}configuration(){return{createOrder:(e,t)=>{const r=a();return fetch(this.config.ajax.create_order.endpoint,{method:"POST",body:JSON.stringify({nonce:this.config.ajax.create_order.nonce,purchase_units:[],payer:r})}).then((function(e){return e.json()})).then((function(e){if(!e.success)throw Error(e.data);return e.data.id}))},onApprove:o(this),onError:e=>{this.errorHandler.message(e)}}}};var s=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.render(),jQuery(document.body).on("wc_fragments_loaded wc_fragments_refreshed",()=>{this.render()})}shouldRender(){return null!==document.querySelector(this.gateway.button.mini_cart_wrapper)}render(){if(!this.shouldRender())return;const e=new i(PayPalCommerceGateway,new n);this.renderer.render(this.gateway.button.mini_cart_wrapper,e.configuration())}};var c=class{constructor(e,t,r){this.id=e,this.quantity=t,this.variations=r}data(){return{id:this.id,quantity:this.quantity,variations:this.variations}}};var u=class{constructor(e,t){this.endpoint=e,this.nonce=t}update(e,t){return new Promise((r,n)=>{fetch(this.endpoint,{method:"POST",body:JSON.stringify({nonce:this.nonce,products:t})}).then(e=>e.json()).then(t=>{if(!t.success)return void n(t.data);const o=e(t.data);r(o)})})}};var d=class{constructor(e,t,r){this.element=e,this.showCallback=t,this.hideCallback=r,this.observer=null}init(){const e=()=>{this.element.classList.contains("disabled")?this.hideCallback():this.showCallback()};this.observer=new MutationObserver(e),this.observer.observe(this.element,{attributes:!0}),e()}disconnect(){this.observer.disconnect()}};var l=class{constructor(e,t,r,n,o,a){this.config=e,this.updateCart=t,this.showButtonCallback=r,this.hideButtonCallback=n,this.formElement=o,this.errorHandler=a}configuration(){if(this.hasVariations()){new d(this.formElement.querySelector(".single_add_to_cart_button"),this.showButtonCallback,this.hideButtonCallback).init()}return{createOrder:this.createOrder(),onApprove:o(this),onError:e=>{this.errorHandler.message(e)}}}createOrder(){var e=null;e=this.isGroupedProduct()?()=>{const e=[];return this.formElement.querySelectorAll('input[type="number"]').forEach(t=>{if(!t.value)return;const r=t.getAttribute("name").match(/quantity\[([\d]*)\]/);if(2!==r.length)return;const n=parseInt(r[1]),o=parseInt(t.value);e.push(new c(n,o,null))}),e}:()=>{const e=document.querySelector('[name="add-to-cart"]').value,t=document.querySelector('[name="quantity"]').value,r=this.variations();return[new c(e,t,r)]};return(t,r)=>{this.errorHandler.clear();return this.updateCart.update(e=>{const t=a();return fetch(this.config.ajax.create_order.endpoint,{method:"POST",body:JSON.stringify({nonce:this.config.ajax.create_order.nonce,purchase_units:e,payer:t})}).then((function(e){return e.json()})).then((function(e){if(!e.success)throw Error(e.data);return e.data.id}))},e())}}variations(){if(!this.hasVariations())return null;return[...this.formElement.querySelectorAll("[name^='attribute_']")].map(e=>({value:e.value,name:e.name}))}hasVariations(){return this.formElement.classList.contains("variations_form")}isGroupedProduct(){return this.formElement.classList.contains("grouped_form")}};var h=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.shouldRender()&&this.render()}shouldRender(){return null!==document.querySelector("form.cart")&&null!==document.querySelector(this.gateway.button.wrapper)}render(){const e=new l(this.gateway,new u(this.gateway.ajax.change_cart.endpoint,this.gateway.ajax.change_cart.nonce),()=>{this.renderer.showButtons(this.gateway.button.wrapper)},()=>{this.renderer.hideButtons(this.gateway.button.wrapper)},document.querySelector("form.cart"),new n);this.renderer.render(this.gateway.button.wrapper,e.configuration())}};var m=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.shouldRender()&&(this.render(),jQuery(document.body).on("updated_cart_totals updated_checkout",()=>{this.render()}))}shouldRender(){return null!==document.querySelector(this.gateway.button.wrapper)}render(){const e=new i(PayPalCommerceGateway,new n);this.renderer.render(this.gateway.button.wrapper,e.configuration())}};var y=e=>(t,r)=>fetch(e.config.ajax.approve_order.endpoint,{method:"POST",body:JSON.stringify({nonce:e.config.ajax.approve_order.nonce,order_id:t.orderID})}).then(e=>e.json()).then(e=>{if(!e.success)throw Error(e.data);document.querySelector("#place_order").click()});var p=class{constructor(e,t){this.config=e,this.errorHandler=t}configuration(){return{createOrder:(e,t)=>{const r=a();return fetch(this.config.ajax.create_order.endpoint,{method:"POST",body:JSON.stringify({nonce:this.config.ajax.create_order.nonce,payer:r})}).then((function(e){return e.json()})).then((function(e){if(!e.success)throw Error(e.data);return e.data.id}))},onApprove:y(this),onError:e=>{this.errorHandler.message(e)}}}};var _=class{constructor(e,t){this.gateway=e,this.renderer=t}init(){this.shouldRender()&&(this.render(),jQuery(document.body).on("updated_checkout",()=>{this.render()}),jQuery(document.body).on("updated_checkout payment_method_selected",()=>{this.switchBetweenPayPalandOrderButton()}))}shouldRender(){return!document.querySelector(this.gateway.button.cancel_wrapper)&&null!==document.querySelector(this.gateway.button.wrapper)}render(){const e=new p(PayPalCommerceGateway,new n);this.renderer.render(this.gateway.button.wrapper,e.configuration())}switchBetweenPayPalandOrderButton(){"ppcp-gateway"!==jQuery('input[name="payment_method"]:checked').val()?(this.renderer.hideButtons(this.gateway.button.wrapper),jQuery("#place_order").show()):(this.renderer.showButtons(this.gateway.button.wrapper),jQuery("#place_order").hide())}};var f=class{constructor(e){this.defaultConfig=e}render(e,t){if(this.isAlreadyRendered(e))return;const r=this.defaultConfig.button.style;paypal.Buttons({style:r,...t}).render(e)}isAlreadyRendered(e){return document.querySelector(e).hasChildNodes()}hideButtons(e){document.querySelector(e).style.display="none"}showButtons(e){document.querySelector(e).style.display="block"}};document.addEventListener("DOMContentLoaded",()=>{const e=document.createElement("script");e.setAttribute("src",PayPalCommerceGateway.button.url),e.addEventListener("load",e=>{(()=>{const e=new f(PayPalCommerceGateway),t=PayPalCommerceGateway.context;if("mini-cart"===t||"product"===t){new s(PayPalCommerceGateway,e).init()}if("product"===t){new h(PayPalCommerceGateway,e).init()}if("cart"===t){new m(PayPalCommerceGateway,e).init()}if("checkout"===t){new _(PayPalCommerceGateway,e).init()}})()}),document.body.append(e)})}]); //# sourceMappingURL=button.js.map \ No newline at end of file diff --git a/modules.local/ppcp-button/assets/js/button.js.map b/modules.local/ppcp-button/assets/js/button.js.map index e3be58cb8..35033b45b 100644 --- a/modules.local/ppcp-button/assets/js/button.js.map +++ b/modules.local/ppcp-button/assets/js/button.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./resources/js/modules/ErrorHandler.js","webpack:///./resources/js/modules/onApproveForContinue.js","webpack:///./resources/js/modules/CartActionHandler.js","webpack:///./resources/js/modules/MiniCartBootstap.js","webpack:///./resources/js/modules/Product.js","webpack:///./resources/js/modules/UpdateCart.js","webpack:///./resources/js/modules/ButtonsToggleListener.js","webpack:///./resources/js/modules/SingleProductActionHandler.js","webpack:///./resources/js/modules/SingleProductBootstap.js","webpack:///./resources/js/modules/CartBootstap.js","webpack:///./resources/js/modules/onApproveForPayNow.js","webpack:///./resources/js/modules/CheckoutActionHandler.js","webpack:///./resources/js/modules/CheckoutBootstap.js","webpack:///./resources/js/modules/Renderer.js","webpack:///./resources/js/button.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","ErrorHandler","constructor","this","wrapper","document","querySelector","message","text","classList","add","innerText","sanitize","textarea","createElement","innerHTML","clear","contains","remove","onApprove","context","data","actions","fetch","config","ajax","approve_order","endpoint","method","body","JSON","stringify","nonce","order_id","orderID","then","res","json","success","location","href","redirect","CartActionHandler","errorHandler","configuration","createOrder","create_order","purchase_units","id","onError","error","MiniCartBootstap","gateway","renderer","init","render","jQuery","on","shouldRender","button","mini_cart_wrapper","actionHandler","PayPalCommerceGateway","Product","quantity","variations","UpdateCart","update","onResolve","products","Promise","resolve","reject","result","resolved","ButtonsToggleListener","element","showCallback","hideCallback","observer","callback","MutationObserver","observe","attributes","disconnect","SingleProductActionHandler","updateCart","showButtonCallback","hideButtonCallback","formElement","hasVariations","getProducts","isGroupedProduct","querySelectorAll","forEach","elementName","getAttribute","match","length","parseInt","push","qty","map","SingleProductBootstap","change_cart","showButtons","hideButtons","CartBootstrap","click","CheckoutActionHandler","payer","email_address","surname","given_name","address","country_code","address_line_1","address_line_2","admin_area_1","admin_area_2","postal_code","phone","phone_type","phone_number","national_number","CheckoutBootstap","switchBetweenPayPalandOrderButton","cancel_wrapper","val","show","hide","Renderer","defaultConfig","contextConfig","isAlreadyRendered","style","paypal","Buttons","hasChildNodes","display","addEventListener","script","setAttribute","url","event","bootstrap","append"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,EAAOE,GAEvC,GADU,EAAPA,IAAUF,EAAQrB,EAAoBqB,IAC/B,EAAPE,EAAU,OAAOF,EACpB,GAAW,EAAPE,GAA8B,iBAAVF,GAAsBA,GAASA,EAAMG,WAAY,OAAOH,EAChF,IAAII,EAAKX,OAAOY,OAAO,MAGvB,GAFA1B,EAAoBkB,EAAEO,GACtBX,OAAOC,eAAeU,EAAI,UAAW,CAAET,YAAY,EAAMK,MAAOA,IACtD,EAAPE,GAA4B,iBAATF,EAAmB,IAAI,IAAIM,KAAON,EAAOrB,EAAoBU,EAAEe,EAAIE,EAAK,SAASA,GAAO,OAAON,EAAMM,IAAQ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B,KAAKqH,OAAOL","file":"js/button.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","class ErrorHandler {\n\n constructor()\n {\n this.wrapper = document.querySelector('.woocommerce-notices-wrapper');\n }\n\n message(text)\n {\n this.wrapper.classList.add('woocommerce-error');\n this.wrapper.innerText = this.sanitize(text);\n }\n\n sanitize(text)\n {\n const textarea = document.createElement('textarea');\n textarea.innerHTML = text;\n return textarea.value;\n }\n\n clear()\n {\n if (! this.wrapper.classList.contains('woocommerce-error')) {\n return;\n }\n this.wrapper.classList.remove('woocommerce-error');\n this.wrapper.innerText = '';\n }\n}\n\nexport default ErrorHandler;","const onApprove = (context) => {\n return (data, actions) => {\n return fetch(context.config.ajax.approve_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: context.config.ajax.approve_order.nonce,\n order_id:data.orderID\n })\n }).then((res)=>{\n return res.json();\n }).then((data)=>{\n if (!data.success) {\n //Todo: Error handling\n return;\n }\n location.href = context.config.redirect;\n });\n\n }\n}\n\nexport default onApprove;\n","import onApprove from './onApproveForContinue.js';\n\nclass CartActionHandler {\n\n constructor(config, errorHandler) {\n this.config = config;\n this.errorHandler = errorHandler;\n }\n\n configuration() {\n const createOrder = (data, actions) => {\n return fetch(this.config.ajax.create_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.config.ajax.create_order.nonce,\n purchase_units: [],\n }),\n }).then(function(res) {\n return res.json();\n }).then(function(data) {\n if (!data.success) {\n //Todo: Error handling\n return;\n }\n return data.data.id;\n });\n };\n\n return {\n createOrder,\n onApprove: onApprove(this),\n onError: (error) => {\n this.errorHandler.message(error);\n }\n };\n }\n}\n\nexport default CartActionHandler;","import ErrorHandler from './ErrorHandler';\nimport CartActionHandler from './CartActionHandler';\n\nclass MiniCartBootstap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n this.render();\n\n jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {\n this.render();\n });\n }\n\n shouldRender() {\n return document.querySelector(this.gateway.button.mini_cart_wrapper) !==\n null;\n }\n\n render() {\n if (!this.shouldRender()) {\n return;\n }\n\n const actionHandler = new CartActionHandler(\n PayPalCommerceGateway,\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.mini_cart_wrapper,\n actionHandler.configuration()\n );\n }\n}\n\nexport default MiniCartBootstap;","class Product {\n\n constructor(id, quantity, variations) {\n this.id = id;\n this.quantity = quantity;\n this.variations = variations;\n }\n\n data() {\n return {\n id:this.id,\n quantity:this.quantity,\n variations:this.variations\n }\n }\n}\n\nexport default Product;","import Product from \"./Product\";\nclass UpdateCart {\n\n constructor(endpoint, nonce)\n {\n this.endpoint = endpoint;\n this.nonce = nonce;\n }\n\n /**\n *\n * @param onResolve\n * @param {Product[]} products\n * @returns {Promise}\n */\n update(onResolve, products)\n {\n return new Promise((resolve, reject) => {\n fetch(\n this.endpoint,\n {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.nonce,\n products,\n })\n }\n ).then(\n (result) => {\n return result.json();\n }\n ).then((result) => {\n if (! result.success) {\n reject(result.data);\n return;\n }\n\n const resolved = onResolve(result.data);\n resolve(resolved);\n })\n });\n }\n}\n\nexport default UpdateCart;","/**\n * When you can't add something to the cart, the PayPal buttons should not show.\n * Therefore we listen for changes on the add to cart button and show/hide the buttons accordingly.\n */\n\nclass ButtonsToggleListener {\n constructor(element, showCallback, hideCallback)\n {\n this.element = element;\n this.showCallback = showCallback;\n this.hideCallback = hideCallback;\n this.observer = null;\n }\n\n init()\n {\n const config = { attributes : true };\n const callback = () => {\n if (this.element.classList.contains('disabled')) {\n this.hideCallback();\n return;\n }\n this.showCallback();\n }\n this.observer = new MutationObserver(callback);\n this.observer.observe(this.element, config);\n callback();\n }\n\n disconnect()\n {\n this.observer.disconnect();\n }\n}\n\nexport default ButtonsToggleListener;","import ButtonsToggleListener from './ButtonsToggleListener';\nimport Product from './Product';\nimport onApprove from './onApproveForContinue';\n\nclass SingleProductActionHandler {\n\n constructor(\n config,\n updateCart,\n showButtonCallback,\n hideButtonCallback,\n formElement,\n errorHandler\n ) {\n this.config = config;\n this.updateCart = updateCart;\n this.showButtonCallback = showButtonCallback;\n this.hideButtonCallback = hideButtonCallback;\n this.formElement = formElement;\n this.errorHandler = errorHandler;\n }\n\n configuration()\n {\n\n if ( this.hasVariations() ) {\n const observer = new ButtonsToggleListener(\n this.formElement.querySelector('.single_add_to_cart_button'),\n this.showButtonCallback,\n this.hideButtonCallback\n );\n observer.init();\n }\n\n return {\n createOrder: this.createOrder(),\n onApprove: onApprove(this),\n onError: (error) => {\n this.errorHandler.message(error);\n }\n }\n }\n\n createOrder()\n {\n var getProducts = null;\n if (! this.isGroupedProduct() ) {\n getProducts = () => {\n const id = document.querySelector('[name=\"add-to-cart\"]').value;\n const qty = document.querySelector('[name=\"quantity\"]').value;\n const variations = this.variations();\n return [new Product(id, qty, variations)];\n }\n } else {\n getProducts = () => {\n const products = [];\n this.formElement.querySelectorAll('input[type=\"number\"]').forEach((element) => {\n if (! element.value) {\n return;\n }\n const elementName = element.getAttribute('name').match(/quantity\\[([\\d]*)\\]/);\n if (elementName.length !== 2) {\n return;\n }\n const id = parseInt(elementName[1]);\n const quantity = parseInt(element.value);\n products.push(new Product(id, quantity, null));\n })\n return products;\n }\n }\n const createOrder = (data, actions) => {\n this.errorHandler.clear();\n\n const onResolve = (purchase_units) => {\n return fetch(this.config.ajax.create_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.config.ajax.create_order.nonce,\n purchase_units\n })\n }).then(function (res) {\n return res.json();\n }).then(function (data) {\n if (!data.success) {\n //Todo: Error handling\n return;\n }\n return data.data.id;\n });\n };\n\n const promise = this.updateCart.update(onResolve, getProducts());\n return promise;\n };\n return createOrder;\n }\n\n variations()\n {\n\n if (! this.hasVariations()) {\n return null;\n }\n const attributes = [...this.formElement.querySelectorAll(\"[name^='attribute_']\")].map(\n (element) => {\n return {\n value:element.value,\n name:element.name\n }\n }\n );\n return attributes;\n }\n\n hasVariations()\n {\n return this.formElement.classList.contains('variations_form');\n }\n\n isGroupedProduct()\n {\n return this.formElement.classList.contains('grouped_form');\n }\n}\nexport default SingleProductActionHandler;","import ErrorHandler from './ErrorHandler';\nimport UpdateCart from './UpdateCart';\nimport SingleProductActionHandler from './SingleProductActionHandler';\n\nclass SingleProductBootstap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n if (!this.shouldRender()) {\n return;\n }\n\n this.render();\n }\n\n shouldRender() {\n if (document.querySelector('form.cart') === null) {\n return false;\n }\n\n return document.querySelector(this.gateway.button.wrapper) !== null;\n }\n\n render() {\n const actionHandler = new SingleProductActionHandler(\n this.gateway,\n new UpdateCart(\n this.gateway.ajax.change_cart.endpoint,\n this.gateway.ajax.change_cart.nonce,\n ),\n () => {\n this.renderer.showButtons(this.gateway.button.wrapper);\n },\n () => {\n this.renderer.hideButtons(this.gateway.button.wrapper);\n },\n document.querySelector('form.cart'),\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.wrapper,\n actionHandler.configuration(),\n );\n }\n}\n\nexport default SingleProductBootstap;","import CartActionHandler from './CartActionHandler';\nimport ErrorHandler from './ErrorHandler';\n\nclass CartBootstrap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n if (!this.shouldRender()) {\n return;\n }\n\n this.render();\n\n jQuery(document.body).on('updated_cart_totals updated_checkout', () => {\n this.render();\n });\n }\n\n shouldRender() {\n return document.querySelector(this.gateway.button.wrapper) !== null;\n }\n\n render() {\n const actionHandler = new CartActionHandler(\n PayPalCommerceGateway,\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.wrapper,\n actionHandler.configuration(),\n );\n }\n}\n\nexport default CartBootstrap;","const onApprove = (context) => {\n return (data, actions) => {\n return fetch(context.config.ajax.approve_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: context.config.ajax.approve_order.nonce,\n order_id:data.orderID\n })\n }).then((res)=>{\n return res.json();\n }).then((data)=>{\n if (!data.success) {\n //Todo: Error handling\n return;\n }\n document.querySelector('#place_order').click()\n });\n\n }\n}\n\nexport default onApprove;","import onApprove from './onApproveForPayNow.js';\n\nclass CheckoutActionHandler {\n\n constructor(config, errorHandler) {\n this.config = config;\n this.errorHandler = errorHandler;\n }\n\n configuration() {\n\n const createOrder = (data, actions) => {\n const payer = {\n email_address:(document.querySelector('#billing_email')) ? document.querySelector('#billing_email').value : \"\",\n name : {\n surname: (document.querySelector('#billing_last_name')) ? document.querySelector('#billing_last_name').value : \"\",\n given_name: (document.querySelector('#billing_first_name')) ? document.querySelector('#billing_first_name').value : \"\"\n },\n address : {\n country_code : (document.querySelector('#billing_country')) ? document.querySelector('#billing_country').value : \"\",\n address_line_1 : (document.querySelector('#billing_address_1')) ? document.querySelector('#billing_address_1').value : \"\",\n address_line_2 : (document.querySelector('#billing_address_2')) ? document.querySelector('#billing_address_2').value : \"\",\n admin_area_1 : (document.querySelector('#billing_city')) ? document.querySelector('#billing_city').value : \"\",\n admin_area_2 : (document.querySelector('#billing_state')) ? document.querySelector('#billing_state').value : \"\",\n postal_code : (document.querySelector('#billing_postcode')) ? document.querySelector('#billing_postcode').value : \"\"\n },\n phone : {\n phone_type:\"HOME\",\n phone_number:{\n national_number : (document.querySelector('#billing_phone')) ? document.querySelector('#billing_phone').value : \"\"\n }\n }\n };\n return fetch(this.config.ajax.create_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.config.ajax.create_order.nonce,\n payer\n })\n }).then(function (res) {\n return res.json();\n }).then(function (data) {\n if (!data.success) {\n //Todo: Error handling\n return;\n }\n return data.data.id;\n });\n }\n return {\n createOrder,\n onApprove:onApprove(this),\n onError: (error) => {\n this.errorHandler.message(error);\n }\n }\n }\n}\n\nexport default CheckoutActionHandler;","import ErrorHandler from './ErrorHandler';\nimport CheckoutActionHandler from './CheckoutActionHandler';\n\nclass CheckoutBootstap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n if (!this.shouldRender()) {\n return;\n }\n\n this.render();\n\n jQuery(document.body).on('updated_checkout', () => {\n this.render();\n });\n\n jQuery(document.body).\n on('updated_checkout payment_method_selected', () => {\n this.switchBetweenPayPalandOrderButton();\n });\n }\n\n shouldRender() {\n if (document.querySelector(this.gateway.button.cancel_wrapper)) {\n return false;\n }\n\n return document.querySelector(this.gateway.button.wrapper) !== null;\n }\n\n render() {\n const actionHandler = new CheckoutActionHandler(\n PayPalCommerceGateway,\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.wrapper,\n actionHandler.configuration(),\n );\n }\n\n switchBetweenPayPalandOrderButton() {\n const currentPaymentMethod = jQuery(\n 'input[name=\"payment_method\"]:checked').val();\n\n if (currentPaymentMethod !== 'ppcp-gateway') {\n this.renderer.hideButtons(this.gateway.button.wrapper);\n jQuery('#place_order').show();\n }\n else {\n this.renderer.showButtons(this.gateway.button.wrapper);\n jQuery('#place_order').hide();\n }\n }\n}\n\nexport default CheckoutBootstap;","class Renderer {\n constructor(defaultConfig) {\n this.defaultConfig = defaultConfig;\n }\n\n render(wrapper, contextConfig) {\n if (this.isAlreadyRendered(wrapper)) {\n return;\n }\n\n const style = this.defaultConfig.button.style;\n paypal.Buttons({\n style,\n ...contextConfig,\n }).render(wrapper);\n }\n\n isAlreadyRendered(wrapper) {\n return document.querySelector(wrapper).hasChildNodes();\n }\n\n hideButtons(element) {\n document.querySelector(element).style.display = 'none';\n }\n\n showButtons(element) {\n document.querySelector(element).style.display = 'block';\n }\n}\n\nexport default Renderer;","import MiniCartBootstap from './modules/MiniCartBootstap';\nimport SingleProductBootstap from './modules/SingleProductBootstap';\nimport CartBootstrap from './modules/CartBootstap';\nimport CheckoutBootstap from './modules/CheckoutBootstap';\nimport Renderer from './modules/Renderer';\n\nconst bootstrap = () => {\n const renderer = new Renderer(PayPalCommerceGateway);\n const context = PayPalCommerceGateway.context;\n\n if (context === 'mini-cart' || context === 'product') {\n const miniCartBootstrap = new MiniCartBootstap(\n PayPalCommerceGateway,\n renderer\n );\n\n miniCartBootstrap.init();\n }\n\n if (context === 'product') {\n const singleProductBootstrap = new SingleProductBootstap(\n PayPalCommerceGateway,\n renderer,\n );\n\n singleProductBootstrap.init();\n }\n\n if (context === 'cart') {\n const cartBootstrap = new CartBootstrap(\n PayPalCommerceGateway,\n renderer,\n );\n\n cartBootstrap.init();\n }\n\n if (context === 'checkout') {\n const checkoutBootstap = new CheckoutBootstap(\n PayPalCommerceGateway,\n renderer\n );\n\n checkoutBootstap.init();\n }\n};\ndocument.addEventListener(\n 'DOMContentLoaded',\n () => {\n if (!typeof (PayPalCommerceGateway)) {\n console.error('PayPal button could not be configured.');\n return;\n }\n\n const script = document.createElement('script');\n\n script.setAttribute('src', PayPalCommerceGateway.button.url);\n script.addEventListener('load', (event) => {\n bootstrap();\n });\n\n document.body.append(script);\n },\n);"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./resources/js/modules/ErrorHandler.js","webpack:///./resources/js/modules/onApproveForContinue.js","webpack:///./resources/js/modules/Payer.js","webpack:///./resources/js/modules/CartActionHandler.js","webpack:///./resources/js/modules/MiniCartBootstap.js","webpack:///./resources/js/modules/Product.js","webpack:///./resources/js/modules/UpdateCart.js","webpack:///./resources/js/modules/ButtonsToggleListener.js","webpack:///./resources/js/modules/SingleProductActionHandler.js","webpack:///./resources/js/modules/SingleProductBootstap.js","webpack:///./resources/js/modules/CartBootstap.js","webpack:///./resources/js/modules/onApproveForPayNow.js","webpack:///./resources/js/modules/CheckoutActionHandler.js","webpack:///./resources/js/modules/CheckoutBootstap.js","webpack:///./resources/js/modules/Renderer.js","webpack:///./resources/js/button.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","ErrorHandler","constructor","this","wrapper","document","querySelector","message","text","classList","add","innerText","sanitize","textarea","createElement","innerHTML","replace","clear","contains","remove","onApprove","context","data","actions","fetch","config","ajax","approve_order","endpoint","method","body","JSON","stringify","nonce","order_id","orderID","then","res","json","success","Error","location","href","redirect","payerData","payer","PayPalCommerceGateway","email_address","surname","given_name","address","country_code","address_line_1","address_line_2","admin_area_1","admin_area_2","postal_code","phone","phone_type","phone_number","national_number","CartActionHandler","errorHandler","configuration","createOrder","create_order","purchase_units","id","onError","error","MiniCartBootstap","gateway","renderer","init","render","jQuery","on","shouldRender","button","mini_cart_wrapper","actionHandler","Product","quantity","variations","UpdateCart","update","onResolve","products","Promise","resolve","reject","result","resolved","ButtonsToggleListener","element","showCallback","hideCallback","observer","callback","MutationObserver","observe","attributes","disconnect","SingleProductActionHandler","updateCart","showButtonCallback","hideButtonCallback","formElement","hasVariations","getProducts","isGroupedProduct","querySelectorAll","forEach","elementName","getAttribute","match","length","parseInt","push","qty","map","SingleProductBootstap","change_cart","showButtons","hideButtons","CartBootstrap","click","CheckoutActionHandler","CheckoutBootstap","switchBetweenPayPalandOrderButton","cancel_wrapper","val","show","hide","Renderer","defaultConfig","contextConfig","isAlreadyRendered","style","paypal","Buttons","hasChildNodes","display","addEventListener","script","setAttribute","url","event","bootstrap","append"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,G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B,sBACA0B,GAGcC,OAGtB,GAAgB,YAAZpD,EAAuB,CACQ,IAAIoG,EAC/B3E,sBACA0B,GAGmBC,OAG3B,GAAgB,SAAZpD,EAAoB,CACE,IAAIwG,EACtB/E,sBACA0B,GAGUC,OAGlB,GAAgB,aAAZpD,EAAwB,CACC,IAAI2G,EACzBlF,sBACA0B,GAGaC,SAeb2E,KAGJ/I,SAASyB,KAAKuH,OAAOL","file":"js/button.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","class ErrorHandler {\n\n constructor()\n {\n this.wrapper = document.querySelector('.woocommerce-notices-wrapper');\n }\n\n message(text)\n {\n this.wrapper.classList.add('woocommerce-error');\n this.wrapper.innerText = this.sanitize(text);\n }\n\n sanitize(text)\n {\n const textarea = document.createElement('textarea');\n textarea.innerHTML = text;\n return textarea.value.replace('Error: ', '');\n }\n\n clear()\n {\n if (! this.wrapper.classList.contains('woocommerce-error')) {\n return;\n }\n this.wrapper.classList.remove('woocommerce-error');\n this.wrapper.innerText = '';\n }\n}\n\nexport default ErrorHandler;\n","const onApprove = (context) => {\n return (data, actions) => {\n return fetch(context.config.ajax.approve_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: context.config.ajax.approve_order.nonce,\n order_id:data.orderID\n })\n }).then((res)=>{\n return res.json();\n }).then((data)=>{\n if (!data.success) {\n throw Error(data.data);\n }\n location.href = context.config.redirect;\n });\n\n }\n}\n\nexport default onApprove;\n","export const payerData = () => {\n const payer = PayPalCommerceGateway.payer;\n if (! payer) {\n return null;\n }\n return {\n email_address:(document.querySelector('#billing_email')) ? document.querySelector('#billing_email').value : payer.email_address,\n name : {\n surname: (document.querySelector('#billing_last_name')) ? document.querySelector('#billing_last_name').value : payer.name.surname,\n given_name: (document.querySelector('#billing_first_name')) ? document.querySelector('#billing_first_name').value : payer.name.given_name\n },\n address : {\n country_code : (document.querySelector('#billing_country')) ? document.querySelector('#billing_country').value : payer.address.country_code,\n address_line_1 : (document.querySelector('#billing_address_1')) ? document.querySelector('#billing_address_1').value : payer.address.address_line_1,\n address_line_2 : (document.querySelector('#billing_address_2')) ? document.querySelector('#billing_address_2').value : payer.address.address_line_2,\n admin_area_1 : (document.querySelector('#billing_city')) ? document.querySelector('#billing_city').value : payer.address.admin_area_1,\n admin_area_2 : (document.querySelector('#billing_state')) ? document.querySelector('#billing_state').value : payer.address.admin_area_2,\n postal_code : (document.querySelector('#billing_postcode')) ? document.querySelector('#billing_postcode').value : payer.address.postal_code\n },\n phone : {\n phone_type:\"HOME\",\n phone_number:{\n national_number : (document.querySelector('#billing_phone')) ? document.querySelector('#billing_phone').value : payer.phone.phone_number.national_number\n }\n }\n };\n}\n","import onApprove from './onApproveForContinue.js';\nimport {payerData} from \"./Payer\";\n\nclass CartActionHandler {\n\n constructor(config, errorHandler) {\n this.config = config;\n this.errorHandler = errorHandler;\n }\n\n configuration() {\n const createOrder = (data, actions) => {\n const payer = payerData();\n return fetch(this.config.ajax.create_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.config.ajax.create_order.nonce,\n purchase_units: [],\n payer\n }),\n }).then(function(res) {\n return res.json();\n }).then(function(data) {\n if (!data.success) {\n throw Error(data.data);\n }\n return data.data.id;\n });\n };\n\n return {\n createOrder,\n onApprove: onApprove(this),\n onError: (error) => {\n this.errorHandler.message(error);\n }\n };\n }\n}\n\nexport default CartActionHandler;\n","import ErrorHandler from './ErrorHandler';\nimport CartActionHandler from './CartActionHandler';\n\nclass MiniCartBootstap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n this.render();\n\n jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {\n this.render();\n });\n }\n\n shouldRender() {\n return document.querySelector(this.gateway.button.mini_cart_wrapper) !==\n null;\n }\n\n render() {\n if (!this.shouldRender()) {\n return;\n }\n\n const actionHandler = new CartActionHandler(\n PayPalCommerceGateway,\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.mini_cart_wrapper,\n actionHandler.configuration()\n );\n }\n}\n\nexport default MiniCartBootstap;","class Product {\n\n constructor(id, quantity, variations) {\n this.id = id;\n this.quantity = quantity;\n this.variations = variations;\n }\n\n data() {\n return {\n id:this.id,\n quantity:this.quantity,\n variations:this.variations\n }\n }\n}\n\nexport default Product;","import Product from \"./Product\";\nclass UpdateCart {\n\n constructor(endpoint, nonce)\n {\n this.endpoint = endpoint;\n this.nonce = nonce;\n }\n\n /**\n *\n * @param onResolve\n * @param {Product[]} products\n * @returns {Promise}\n */\n update(onResolve, products)\n {\n return new Promise((resolve, reject) => {\n fetch(\n this.endpoint,\n {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.nonce,\n products,\n })\n }\n ).then(\n (result) => {\n return result.json();\n }\n ).then((result) => {\n if (! result.success) {\n reject(result.data);\n return;\n }\n\n const resolved = onResolve(result.data);\n resolve(resolved);\n })\n });\n }\n}\n\nexport default UpdateCart;","/**\n * When you can't add something to the cart, the PayPal buttons should not show.\n * Therefore we listen for changes on the add to cart button and show/hide the buttons accordingly.\n */\n\nclass ButtonsToggleListener {\n constructor(element, showCallback, hideCallback)\n {\n this.element = element;\n this.showCallback = showCallback;\n this.hideCallback = hideCallback;\n this.observer = null;\n }\n\n init()\n {\n const config = { attributes : true };\n const callback = () => {\n if (this.element.classList.contains('disabled')) {\n this.hideCallback();\n return;\n }\n this.showCallback();\n }\n this.observer = new MutationObserver(callback);\n this.observer.observe(this.element, config);\n callback();\n }\n\n disconnect()\n {\n this.observer.disconnect();\n }\n}\n\nexport default ButtonsToggleListener;","import ButtonsToggleListener from './ButtonsToggleListener';\nimport Product from './Product';\nimport onApprove from './onApproveForContinue';\nimport {payerData} from \"./Payer\";\n\nclass SingleProductActionHandler {\n\n constructor(\n config,\n updateCart,\n showButtonCallback,\n hideButtonCallback,\n formElement,\n errorHandler\n ) {\n this.config = config;\n this.updateCart = updateCart;\n this.showButtonCallback = showButtonCallback;\n this.hideButtonCallback = hideButtonCallback;\n this.formElement = formElement;\n this.errorHandler = errorHandler;\n }\n\n configuration()\n {\n\n if ( this.hasVariations() ) {\n const observer = new ButtonsToggleListener(\n this.formElement.querySelector('.single_add_to_cart_button'),\n this.showButtonCallback,\n this.hideButtonCallback\n );\n observer.init();\n }\n\n return {\n createOrder: this.createOrder(),\n onApprove: onApprove(this),\n onError: (error) => {\n this.errorHandler.message(error);\n }\n }\n }\n\n createOrder()\n {\n var getProducts = null;\n if (! this.isGroupedProduct() ) {\n getProducts = () => {\n const id = document.querySelector('[name=\"add-to-cart\"]').value;\n const qty = document.querySelector('[name=\"quantity\"]').value;\n const variations = this.variations();\n return [new Product(id, qty, variations)];\n }\n } else {\n getProducts = () => {\n const products = [];\n this.formElement.querySelectorAll('input[type=\"number\"]').forEach((element) => {\n if (! element.value) {\n return;\n }\n const elementName = element.getAttribute('name').match(/quantity\\[([\\d]*)\\]/);\n if (elementName.length !== 2) {\n return;\n }\n const id = parseInt(elementName[1]);\n const quantity = parseInt(element.value);\n products.push(new Product(id, quantity, null));\n })\n return products;\n }\n }\n const createOrder = (data, actions) => {\n this.errorHandler.clear();\n\n const onResolve = (purchase_units) => {\n const payer = payerData();\n return fetch(this.config.ajax.create_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.config.ajax.create_order.nonce,\n purchase_units,\n payer\n })\n }).then(function (res) {\n return res.json();\n }).then(function (data) {\n if (!data.success) {\n throw Error(data.data);\n }\n return data.data.id;\n });\n };\n\n const promise = this.updateCart.update(onResolve, getProducts());\n return promise;\n };\n return createOrder;\n }\n\n variations()\n {\n\n if (! this.hasVariations()) {\n return null;\n }\n const attributes = [...this.formElement.querySelectorAll(\"[name^='attribute_']\")].map(\n (element) => {\n return {\n value:element.value,\n name:element.name\n }\n }\n );\n return attributes;\n }\n\n hasVariations()\n {\n return this.formElement.classList.contains('variations_form');\n }\n\n isGroupedProduct()\n {\n return this.formElement.classList.contains('grouped_form');\n }\n}\nexport default SingleProductActionHandler;\n","import ErrorHandler from './ErrorHandler';\nimport UpdateCart from './UpdateCart';\nimport SingleProductActionHandler from './SingleProductActionHandler';\n\nclass SingleProductBootstap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n if (!this.shouldRender()) {\n return;\n }\n\n this.render();\n }\n\n shouldRender() {\n if (document.querySelector('form.cart') === null) {\n return false;\n }\n\n return document.querySelector(this.gateway.button.wrapper) !== null;\n }\n\n render() {\n const actionHandler = new SingleProductActionHandler(\n this.gateway,\n new UpdateCart(\n this.gateway.ajax.change_cart.endpoint,\n this.gateway.ajax.change_cart.nonce,\n ),\n () => {\n this.renderer.showButtons(this.gateway.button.wrapper);\n },\n () => {\n this.renderer.hideButtons(this.gateway.button.wrapper);\n },\n document.querySelector('form.cart'),\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.wrapper,\n actionHandler.configuration(),\n );\n }\n}\n\nexport default SingleProductBootstap;","import CartActionHandler from './CartActionHandler';\nimport ErrorHandler from './ErrorHandler';\n\nclass CartBootstrap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n if (!this.shouldRender()) {\n return;\n }\n\n this.render();\n\n jQuery(document.body).on('updated_cart_totals updated_checkout', () => {\n this.render();\n });\n }\n\n shouldRender() {\n return document.querySelector(this.gateway.button.wrapper) !== null;\n }\n\n render() {\n const actionHandler = new CartActionHandler(\n PayPalCommerceGateway,\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.wrapper,\n actionHandler.configuration(),\n );\n }\n}\n\nexport default CartBootstrap;","const onApprove = (context) => {\n return (data, actions) => {\n return fetch(context.config.ajax.approve_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: context.config.ajax.approve_order.nonce,\n order_id:data.orderID\n })\n }).then((res)=>{\n return res.json();\n }).then((data)=>{\n if (!data.success) {\n throw Error(data.data);\n }\n document.querySelector('#place_order').click()\n });\n\n }\n}\n\nexport default onApprove;\n","import onApprove from './onApproveForPayNow.js';\nimport {payerData} from \"./Payer\";\n\nclass CheckoutActionHandler {\n\n constructor(config, errorHandler) {\n this.config = config;\n this.errorHandler = errorHandler;\n }\n\n configuration() {\n\n const createOrder = (data, actions) => {\n const payer = payerData();\n return fetch(this.config.ajax.create_order.endpoint, {\n method: 'POST',\n body: JSON.stringify({\n nonce: this.config.ajax.create_order.nonce,\n payer\n })\n }).then(function (res) {\n return res.json();\n }).then(function (data) {\n if (!data.success) {\n throw Error(data.data);\n }\n return data.data.id;\n });\n }\n return {\n createOrder,\n onApprove:onApprove(this),\n onError: (error) => {\n this.errorHandler.message(error);\n }\n }\n }\n}\n\nexport default CheckoutActionHandler;\n","import ErrorHandler from './ErrorHandler';\nimport CheckoutActionHandler from './CheckoutActionHandler';\n\nclass CheckoutBootstap {\n constructor(gateway, renderer) {\n this.gateway = gateway;\n this.renderer = renderer;\n }\n\n init() {\n if (!this.shouldRender()) {\n return;\n }\n\n this.render();\n\n jQuery(document.body).on('updated_checkout', () => {\n this.render();\n });\n\n jQuery(document.body).\n on('updated_checkout payment_method_selected', () => {\n this.switchBetweenPayPalandOrderButton();\n });\n }\n\n shouldRender() {\n if (document.querySelector(this.gateway.button.cancel_wrapper)) {\n return false;\n }\n\n return document.querySelector(this.gateway.button.wrapper) !== null;\n }\n\n render() {\n const actionHandler = new CheckoutActionHandler(\n PayPalCommerceGateway,\n new ErrorHandler(),\n );\n\n this.renderer.render(\n this.gateway.button.wrapper,\n actionHandler.configuration(),\n );\n }\n\n switchBetweenPayPalandOrderButton() {\n const currentPaymentMethod = jQuery(\n 'input[name=\"payment_method\"]:checked').val();\n\n if (currentPaymentMethod !== 'ppcp-gateway') {\n this.renderer.hideButtons(this.gateway.button.wrapper);\n jQuery('#place_order').show();\n }\n else {\n this.renderer.showButtons(this.gateway.button.wrapper);\n jQuery('#place_order').hide();\n }\n }\n}\n\nexport default CheckoutBootstap;","class Renderer {\n constructor(defaultConfig) {\n this.defaultConfig = defaultConfig;\n }\n\n render(wrapper, contextConfig) {\n if (this.isAlreadyRendered(wrapper)) {\n return;\n }\n\n const style = this.defaultConfig.button.style;\n paypal.Buttons({\n style,\n ...contextConfig,\n }).render(wrapper);\n }\n\n isAlreadyRendered(wrapper) {\n return document.querySelector(wrapper).hasChildNodes();\n }\n\n hideButtons(element) {\n document.querySelector(element).style.display = 'none';\n }\n\n showButtons(element) {\n document.querySelector(element).style.display = 'block';\n }\n}\n\nexport default Renderer;","import MiniCartBootstap from './modules/MiniCartBootstap';\nimport SingleProductBootstap from './modules/SingleProductBootstap';\nimport CartBootstrap from './modules/CartBootstap';\nimport CheckoutBootstap from './modules/CheckoutBootstap';\nimport Renderer from './modules/Renderer';\n\nconst bootstrap = () => {\n const renderer = new Renderer(PayPalCommerceGateway);\n const context = PayPalCommerceGateway.context;\n\n if (context === 'mini-cart' || context === 'product') {\n const miniCartBootstrap = new MiniCartBootstap(\n PayPalCommerceGateway,\n renderer\n );\n\n miniCartBootstrap.init();\n }\n\n if (context === 'product') {\n const singleProductBootstrap = new SingleProductBootstap(\n PayPalCommerceGateway,\n renderer,\n );\n\n singleProductBootstrap.init();\n }\n\n if (context === 'cart') {\n const cartBootstrap = new CartBootstrap(\n PayPalCommerceGateway,\n renderer,\n );\n\n cartBootstrap.init();\n }\n\n if (context === 'checkout') {\n const checkoutBootstap = new CheckoutBootstap(\n PayPalCommerceGateway,\n renderer\n );\n\n checkoutBootstap.init();\n }\n};\ndocument.addEventListener(\n 'DOMContentLoaded',\n () => {\n if (!typeof (PayPalCommerceGateway)) {\n console.error('PayPal button could not be configured.');\n return;\n }\n\n const script = document.createElement('script');\n\n script.setAttribute('src', PayPalCommerceGateway.button.url);\n script.addEventListener('load', (event) => {\n bootstrap();\n });\n\n document.body.append(script);\n },\n);"],"sourceRoot":""} \ No newline at end of file diff --git a/modules.local/ppcp-button/package-lock.json b/modules.local/ppcp-button/package-lock.json index ec9630b95..937651335 100644 --- a/modules.local/ppcp-button/package-lock.json +++ b/modules.local/ppcp-button/package-lock.json @@ -1545,12 +1545,14 @@ "babel-plugin-syntax-object-rest-spread": { "version": "6.13.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", - "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=" + "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=", + "dev": true }, "babel-plugin-transform-object-rest-spread": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz", "integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=", + "dev": true, "requires": { "babel-plugin-syntax-object-rest-spread": "^6.8.0", "babel-runtime": "^6.26.0" @@ -1560,6 +1562,7 @@ "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", + "dev": true, "requires": { "core-js": "^2.4.0", "regenerator-runtime": "^0.11.0" @@ -2149,7 +2152,8 @@ "core-js": { "version": "2.6.11", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", - "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", + "dev": true }, "core-js-compat": { "version": "3.6.4", @@ -5313,7 +5317,8 @@ "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", - "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", + "dev": true }, "regex-not": { "version": "1.0.2", diff --git a/modules.local/ppcp-button/resources/js/modules/CartActionHandler.js b/modules.local/ppcp-button/resources/js/modules/CartActionHandler.js index a56654208..8040d53a3 100644 --- a/modules.local/ppcp-button/resources/js/modules/CartActionHandler.js +++ b/modules.local/ppcp-button/resources/js/modules/CartActionHandler.js @@ -1,4 +1,5 @@ import onApprove from './onApproveForContinue.js'; +import {payerData} from "./Payer"; class CartActionHandler { @@ -9,11 +10,13 @@ class CartActionHandler { configuration() { const createOrder = (data, actions) => { + const payer = payerData(); return fetch(this.config.ajax.create_order.endpoint, { method: 'POST', body: JSON.stringify({ nonce: this.config.ajax.create_order.nonce, purchase_units: [], + payer }), }).then(function(res) { return res.json(); diff --git a/modules.local/ppcp-button/resources/js/modules/CheckoutActionHandler.js b/modules.local/ppcp-button/resources/js/modules/CheckoutActionHandler.js index 42aa91c15..34d16c47d 100644 --- a/modules.local/ppcp-button/resources/js/modules/CheckoutActionHandler.js +++ b/modules.local/ppcp-button/resources/js/modules/CheckoutActionHandler.js @@ -1,4 +1,5 @@ import onApprove from './onApproveForPayNow.js'; +import {payerData} from "./Payer"; class CheckoutActionHandler { @@ -10,27 +11,7 @@ class CheckoutActionHandler { configuration() { const createOrder = (data, actions) => { - const payer = { - email_address:(document.querySelector('#billing_email')) ? document.querySelector('#billing_email').value : "", - name : { - surname: (document.querySelector('#billing_last_name')) ? document.querySelector('#billing_last_name').value : "", - given_name: (document.querySelector('#billing_first_name')) ? document.querySelector('#billing_first_name').value : "" - }, - address : { - country_code : (document.querySelector('#billing_country')) ? document.querySelector('#billing_country').value : "", - address_line_1 : (document.querySelector('#billing_address_1')) ? document.querySelector('#billing_address_1').value : "", - address_line_2 : (document.querySelector('#billing_address_2')) ? document.querySelector('#billing_address_2').value : "", - admin_area_1 : (document.querySelector('#billing_city')) ? document.querySelector('#billing_city').value : "", - admin_area_2 : (document.querySelector('#billing_state')) ? document.querySelector('#billing_state').value : "", - postal_code : (document.querySelector('#billing_postcode')) ? document.querySelector('#billing_postcode').value : "" - }, - phone : { - phone_type:"HOME", - phone_number:{ - national_number : (document.querySelector('#billing_phone')) ? document.querySelector('#billing_phone').value : "" - } - } - }; + const payer = payerData(); return fetch(this.config.ajax.create_order.endpoint, { method: 'POST', body: JSON.stringify({ diff --git a/modules.local/ppcp-button/resources/js/modules/Payer.js b/modules.local/ppcp-button/resources/js/modules/Payer.js new file mode 100644 index 000000000..ec8ff1aa6 --- /dev/null +++ b/modules.local/ppcp-button/resources/js/modules/Payer.js @@ -0,0 +1,27 @@ +export const payerData = () => { + const payer = PayPalCommerceGateway.payer; + if (! payer) { + return null; + } + return { + email_address:(document.querySelector('#billing_email')) ? document.querySelector('#billing_email').value : payer.email_address, + name : { + surname: (document.querySelector('#billing_last_name')) ? document.querySelector('#billing_last_name').value : payer.name.surname, + given_name: (document.querySelector('#billing_first_name')) ? document.querySelector('#billing_first_name').value : payer.name.given_name + }, + address : { + country_code : (document.querySelector('#billing_country')) ? document.querySelector('#billing_country').value : payer.address.country_code, + address_line_1 : (document.querySelector('#billing_address_1')) ? document.querySelector('#billing_address_1').value : payer.address.address_line_1, + address_line_2 : (document.querySelector('#billing_address_2')) ? document.querySelector('#billing_address_2').value : payer.address.address_line_2, + admin_area_1 : (document.querySelector('#billing_city')) ? document.querySelector('#billing_city').value : payer.address.admin_area_1, + admin_area_2 : (document.querySelector('#billing_state')) ? document.querySelector('#billing_state').value : payer.address.admin_area_2, + postal_code : (document.querySelector('#billing_postcode')) ? document.querySelector('#billing_postcode').value : payer.address.postal_code + }, + phone : { + phone_type:"HOME", + phone_number:{ + national_number : (document.querySelector('#billing_phone')) ? document.querySelector('#billing_phone').value : payer.phone.phone_number.national_number + } + } + }; +} diff --git a/modules.local/ppcp-button/resources/js/modules/SingleProductActionHandler.js b/modules.local/ppcp-button/resources/js/modules/SingleProductActionHandler.js index 335ce3343..f00c9e8fb 100644 --- a/modules.local/ppcp-button/resources/js/modules/SingleProductActionHandler.js +++ b/modules.local/ppcp-button/resources/js/modules/SingleProductActionHandler.js @@ -1,6 +1,7 @@ import ButtonsToggleListener from './ButtonsToggleListener'; import Product from './Product'; import onApprove from './onApproveForContinue'; +import {payerData} from "./Payer"; class SingleProductActionHandler { @@ -73,11 +74,13 @@ class SingleProductActionHandler { this.errorHandler.clear(); const onResolve = (purchase_units) => { + const payer = payerData(); return fetch(this.config.ajax.create_order.endpoint, { method: 'POST', body: JSON.stringify({ nonce: this.config.ajax.create_order.nonce, - purchase_units + purchase_units, + payer }) }).then(function (res) { return res.json(); diff --git a/modules.local/ppcp-button/src/Assets/SmartButton.php b/modules.local/ppcp-button/src/Assets/SmartButton.php index 71082cbff..a8cfc87fb 100644 --- a/modules.local/ppcp-button/src/Assets/SmartButton.php +++ b/modules.local/ppcp-button/src/Assets/SmartButton.php @@ -100,6 +100,7 @@ class SmartButton implements SmartButtonInterface 'nonce' => wp_create_nonce(ApproveOrderEndpoint::nonce()), ], ], + 'payer' => $this->payerData(), 'button' => [ 'wrapper' => '#ppc-button', 'mini_cart_wrapper' => '#ppc-button-minicart', @@ -116,6 +117,34 @@ class SmartButton implements SmartButtonInterface return $localize; } + private function payerData() : ?array { + $customer = WC()->customer; + if (! is_user_logged_in() || ! is_a($customer, \WC_Customer::class)) { + return null; + } + return [ + 'email_address' => $customer->get_billing_email(), + 'name' => [ + 'surname' => $customer->get_billing_last_name(), + 'given_name' => $customer->get_billing_last_name(), + ], + 'address' => [ + 'country_code' => $customer->get_billing_country(), + 'address_line_1' => $customer->get_billing_address_1(), + 'address_line_2' => $customer->get_billing_address_2(), + 'admin_area_1' => $customer->get_billing_city(), + 'admin_area_2' => $customer->get_billing_state(), + 'postal_code' => $customer->get_billing_postcode(), + ], + 'phone' => [ + 'phone_type' => 'HOME', + 'phone_number' => [ + 'national_number' => $customer->get_billing_phone(), + ], + ], + ]; + } + private function url() : string { $params = [ @@ -130,7 +159,7 @@ class SmartButton implements SmartButtonInterface //ToDo: Probably only needed, when DCC 'vault' => 'false', 'commit' => is_checkout() ? 'true' : 'false', - 'intent' => $this->settings->get('intent') + 'intent' => $this->settings->get('intent'), ]; $payee = $this->payeeRepository->payee(); if ($payee->merchantId()) { diff --git a/modules.local/ppcp-button/src/Endpoint/CreateOrderEndpoint.php b/modules.local/ppcp-button/src/Endpoint/CreateOrderEndpoint.php index f3da749f5..d501109eb 100644 --- a/modules.local/ppcp-button/src/Endpoint/CreateOrderEndpoint.php +++ b/modules.local/ppcp-button/src/Endpoint/CreateOrderEndpoint.php @@ -41,7 +41,7 @@ class CreateOrderEndpoint implements EndpointInterface $data = $this->requestData->readRequest($this->nonce()); $purchaseUnits = $this->repository->all(); $payer = null; - if (isset($data['payer'])) { + if (isset($data['payer']) && $data['payer']) { if (isset($data['payer']['phone']['phone_number']['national_number'])) { // make sure the phone number contains only numbers and is max 14. chars long. $number = $data['payer']['phone']['phone_number']['national_number'];