mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
PCP-13 // add payer information to mini-cart, cart and single product
This commit is contained in:
parent
05aac334e7
commit
a9e0cc0cf7
9 changed files with 77 additions and 29 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
11
modules.local/ppcp-button/package-lock.json
generated
11
modules.local/ppcp-button/package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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({
|
||||
|
|
27
modules.local/ppcp-button/resources/js/modules/Payer.js
Normal file
27
modules.local/ppcp-button/resources/js/modules/Payer.js
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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'];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue