mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
Determine if venmo button is clicked and do not pass shipping callback handlers
This commit is contained in:
parent
b54bb7f807
commit
0245fa640b
1 changed files with 25 additions and 12 deletions
|
@ -68,14 +68,6 @@ class Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldHandleShippingInPaypal = (venmoButtonClicked) => {
|
|
||||||
if (!this.defaultSettings.should_handle_shipping_in_paypal) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !venmoButtonClicked || !this.defaultSettings.vaultingEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderButtons(wrapper, style, contextConfig, hasEnabledSeparateGateways, fundingSource = null) {
|
renderButtons(wrapper, style, contextConfig, hasEnabledSeparateGateways, fundingSource = null) {
|
||||||
if (! document.querySelector(wrapper) || this.isAlreadyRendered(wrapper, fundingSource, hasEnabledSeparateGateways) ) {
|
if (! document.querySelector(wrapper) || this.isAlreadyRendered(wrapper, fundingSource, hasEnabledSeparateGateways) ) {
|
||||||
// Try to render registered buttons again in case they were removed from the DOM by an external source.
|
// Try to render registered buttons again in case they were removed from the DOM by an external source.
|
||||||
|
@ -93,7 +85,16 @@ class Renderer {
|
||||||
const options = {
|
const options = {
|
||||||
style,
|
style,
|
||||||
...contextConfig,
|
...contextConfig,
|
||||||
onClick: this.onSmartButtonClick,
|
onClick: (data, actions) => {
|
||||||
|
if (this.onSmartButtonClick) {
|
||||||
|
this.onSmartButtonClick(data, actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
venmoButtonClicked = false;
|
||||||
|
if (data.fundingSource === 'venmo') {
|
||||||
|
venmoButtonClicked = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
onInit: (data, actions) => {
|
onInit: (data, actions) => {
|
||||||
if (this.onSmartButtonsInit) {
|
if (this.onSmartButtonsInit) {
|
||||||
this.onSmartButtonsInit(data, actions);
|
this.onSmartButtonsInit(data, actions);
|
||||||
|
@ -103,9 +104,17 @@ class Renderer {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check the condition and add the handler if needed
|
// Check the condition and add the handler if needed
|
||||||
if (this.shouldHandleShippingInPaypal(venmoButtonClicked)) {
|
if (this.defaultSettings.should_handle_shipping_in_paypal) {
|
||||||
options.onShippingOptionsChange = (data, actions) => handleShippingOptionsChange(data, actions, this.defaultSettings);
|
options.onShippingOptionsChange = (data, actions) => {
|
||||||
options.onShippingAddressChange = (data, actions) => handleShippingAddressChange(data, actions, this.defaultSettings);
|
!this.isVenmoButtonClickedWhenVaultingIsEnabled(venmoButtonClicked)
|
||||||
|
? handleShippingOptionsChange(data, actions, this.defaultSettings)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
options.onShippingAddressChange = (data, actions) => {
|
||||||
|
!this.isVenmoButtonClickedWhenVaultingIsEnabled(venmoButtonClicked)
|
||||||
|
? handleShippingAddressChange(data, actions, this.defaultSettings)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
@ -139,6 +148,10 @@ class Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isVenmoButtonClickedWhenVaultingIsEnabled = (venmoButtonClicked) => {
|
||||||
|
return venmoButtonClicked && this.defaultSettings.vaultingEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
isAlreadyRendered(wrapper, fundingSource) {
|
isAlreadyRendered(wrapper, fundingSource) {
|
||||||
return this.renderedSources.has(wrapper + (fundingSource ?? ''));
|
return this.renderedSources.has(wrapper + (fundingSource ?? ''));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue