mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
🚧 Implement requireShipping getter
This commit is contained in:
parent
6a48c07236
commit
560ec32e26
1 changed files with 23 additions and 19 deletions
|
@ -135,6 +135,24 @@ class ApplePayButton extends PaymentButton {
|
|||
this.log( 'Create instance' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
get requiresShipping() {
|
||||
if ( ! super.requiresShipping ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! this.buttonConfig.product?.needShipping ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
PaymentContext.Checkout !== this.context ||
|
||||
this.shouldUpdateButtonWithFormData()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Details about the processed transaction.
|
||||
*
|
||||
|
@ -345,7 +363,7 @@ class ApplePayButton extends PaymentButton {
|
|||
const session = new ApplePaySession( 4, paymentRequest );
|
||||
session.begin();
|
||||
|
||||
if ( this.shouldRequireShippingInButton() ) {
|
||||
if ( this.requiresShipping ) {
|
||||
session.onshippingmethodselected =
|
||||
this.onShippingMethodSelected( session );
|
||||
session.onshippingcontactselected =
|
||||
|
@ -463,20 +481,6 @@ class ApplePayButton extends PaymentButton {
|
|||
this.applePaySession( paymentRequest );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the button should show the shipping fields.
|
||||
*
|
||||
* @return {boolean} True, if shipping fields should be captured by ApplePay.
|
||||
*/
|
||||
shouldRequireShippingInButton() {
|
||||
return (
|
||||
this.contextHandler.shippingAllowed() &&
|
||||
this.buttonConfig.product.needShipping &&
|
||||
( PaymentContext.Checkout !== this.context ||
|
||||
this.shouldUpdateButtonWithFormData() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the button should be updated with the form addresses.
|
||||
*
|
||||
|
@ -526,7 +530,7 @@ class ApplePayButton extends PaymentButton {
|
|||
this.#formData
|
||||
);
|
||||
|
||||
if ( ! this.shouldRequireShippingInButton() ) {
|
||||
if ( ! this.requiresShipping ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -594,7 +598,7 @@ class ApplePayButton extends PaymentButton {
|
|||
// email and phone fields.
|
||||
};
|
||||
|
||||
if ( ! this.shouldRequireShippingInButton() ) {
|
||||
if ( ! this.requiresShipping ) {
|
||||
if ( this.shouldCompletePaymentWithContextHandler() ) {
|
||||
// Data needs handled externally.
|
||||
baseRequest.requiredShippingContactFields = [];
|
||||
|
@ -781,7 +785,7 @@ class ApplePayButton extends PaymentButton {
|
|||
caller_page: 'productDetail',
|
||||
product_quantity: this.productQuantity,
|
||||
simplified_contact: event.shippingContact,
|
||||
need_shipping: this.shouldRequireShippingInButton(),
|
||||
need_shipping: this.requiresShipping,
|
||||
'woocommerce-process-checkout-nonce': this.nonce,
|
||||
};
|
||||
|
||||
|
@ -794,7 +798,7 @@ class ApplePayButton extends PaymentButton {
|
|||
action: 'ppcp_update_shipping_contact',
|
||||
simplified_contact: event.shippingContact,
|
||||
caller_page: 'cart',
|
||||
need_shipping: this.shouldRequireShippingInButton(),
|
||||
need_shipping: this.requiresShipping,
|
||||
'woocommerce-process-checkout-nonce': this.nonce,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue