Merge pull request #1832 from woocommerce/PCP-2158-apple-pay-use-checkout-form-data-to-update-shipping-and-billing

ApplePay use checkout form data to update shipping and billing (2158)
This commit is contained in:
Emili Castells 2023-11-15 12:02:57 +01:00 committed by GitHub
commit aec5e6431c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 421 additions and 212 deletions

View file

@ -22,12 +22,14 @@ class BaseHandler {
transactionInfo() {
return new Promise((resolve, reject) => {
const endpoint = this.ppcpConfig.ajax.cart_script_params.endpoint;
const separator = (endpoint.indexOf('?') !== -1) ? '&' : '?';
fetch(
this.ppcpConfig.ajax.cart_script_params.endpoint,
endpoint + separator + 'shipping=1',
{
method: 'GET',
credentials: 'same-origin',
credentials: 'same-origin'
}
)
.then(result => result.json())
@ -43,7 +45,9 @@ class BaseHandler {
countryCode: data.country_code,
currencyCode: data.currency_code,
totalPriceStatus: 'FINAL',
totalPrice: data.total_str
totalPrice: data.total_str,
chosenShippingMethods: data.chosen_shipping_methods || null,
shippingPackages: data.shipping_packages || null,
});
});

View file

@ -1,28 +1,17 @@
import Spinner from "../../../../ppcp-button/resources/js/modules/Helper/Spinner";
import CheckoutActionHandler
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler";
import ErrorHandler from "../../../../ppcp-button/resources/js/modules/ErrorHandler";
import BaseHandler from "./BaseHandler";
class CheckoutHandler extends BaseHandler {
createOrder() {
const errorHandler = new ErrorHandler(
this.ppcpConfig.labels.error.generic,
document.querySelector('.woocommerce-notices-wrapper')
);
const spinner = new Spinner();
const actionHandler = new CheckoutActionHandler(
actionHandler() {
return new CheckoutActionHandler(
this.ppcpConfig,
errorHandler,
spinner
this.errorHandler(),
new Spinner()
);
return actionHandler.configuration().createOrder(null, null);
}
}
export default CheckoutHandler;