Determine if venmo button is clicked and do not pass shipping callback handlers

This commit is contained in:
Narek Zakarian 2024-05-27 19:57:00 +04:00
parent b54bb7f807
commit 0245fa640b
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -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 ?? ''));
} }