PCP-13 // add payer information to mini-cart, cart and single product

This commit is contained in:
David Remer 2020-04-28 09:14:05 +03:00
parent 05aac334e7
commit a9e0cc0cf7
9 changed files with 77 additions and 29 deletions

View file

@ -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();

View file

@ -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({

View file

@ -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
}
}
};
}

View file

@ -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();