Merge pull request #2029 from woocommerce/PCP-2616-disable-pay-pal-vaulting-setting-instead-of-hiding-it-when-reference-transactions-not-available

Disable PayPal Vaulting setting instead of hiding it when Reference Transactions not available (2616)
This commit is contained in:
Emili Castells 2024-02-16 14:52:20 +01:00 committed by GitHub
commit a718186d76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 21 deletions

View file

@ -359,6 +359,20 @@ document.addEventListener(
);
}
const referenceTransactionsCheck = () => {
if (
typeof PayPalCommerceGatewaySettings !== 'undefined'
&& PayPalCommerceGatewaySettings.reference_transaction_enabled !== '1'
) {
document.getElementById('ppcp-vault_enabled')?.setAttribute('disabled', 'disabled');
const description = document.getElementById('field-vault_enabled')?.getElementsByClassName('description')[0];
if (description) {
description.innerHTML = PayPalCommerceGatewaySettings.vaulting_must_enable_advanced_wallet_message;
}
}
}
(() => {
removeDisabledCardIcons('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]');
@ -408,6 +422,8 @@ document.addEventListener(
);
togglePayLaterMessageFields();
referenceTransactionsCheck()
})();
}
)

View file

@ -910,11 +910,6 @@ return array(
unset( $fields['subscriptions_mode'] );
}
$billing_agreements_endpoint = $container->get( 'api.endpoint.billing-agreements' );
if ( ! $billing_agreements_endpoint->reference_transaction_enabled() ) {
unset( $fields['vault_enabled'] );
}
/**
* Depending on your store location, some credit cards can't be used.
* Here, we filter them out.

View file

@ -9,12 +9,12 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\RefreshFeatureStatusEndpoint;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\ResubscribeEndpoint;
/**
* Class SettingsPageAssets
@ -105,21 +105,29 @@ class SettingsPageAssets {
*/
private $is_acdc_enabled;
/**
* Billing Agreements endpoint.
*
* @var BillingAgreementsEndpoint
*/
private $billing_agreements_endpoint;
/**
* Assets constructor.
*
* @param string $module_url The url of this module.
* @param string $version The assets version.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param string $client_id The PayPal SDK client ID.
* @param string $currency 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop.
* @param Environment $environment The environment object.
* @param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout, cart or product page.
* @param array $disabled_sources The list of disabled funding sources.
* @param array $all_funding_sources The list of all existing funding sources.
* @param bool $is_settings_page Whether it's a settings page of this plugin.
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
* @param string $module_url The url of this module.
* @param string $version The assets version.
* @param SubscriptionHelper $subscription_helper The subscription helper.
* @param string $client_id The PayPal SDK client ID.
* @param string $currency 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop.
* @param Environment $environment The environment object.
* @param bool $is_pay_later_button_enabled Whether Pay Later button is enabled either for checkout, cart or product page.
* @param array $disabled_sources The list of disabled funding sources.
* @param array $all_funding_sources The list of all existing funding sources.
* @param bool $is_settings_page Whether it's a settings page of this plugin.
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
* @param BillingAgreementsEndpoint $billing_agreements_endpoint Billing Agreements endpoint.
*/
public function __construct(
string $module_url,
@ -133,7 +141,8 @@ class SettingsPageAssets {
array $disabled_sources,
array $all_funding_sources,
bool $is_settings_page,
bool $is_acdc_enabled
bool $is_acdc_enabled,
BillingAgreementsEndpoint $billing_agreements_endpoint
) {
$this->module_url = $module_url;
$this->version = $version;
@ -147,6 +156,7 @@ class SettingsPageAssets {
$this->all_funding_sources = $all_funding_sources;
$this->is_settings_page = $is_settings_page;
$this->is_acdc_enabled = $is_acdc_enabled;
$this->billing_agreements_endpoint = $billing_agreements_endpoint;
}
/**
@ -250,6 +260,13 @@ class SettingsPageAssets {
),
),
),
'reference_transaction_enabled' => $this->billing_agreements_endpoint->reference_transaction_enabled(),
'vaulting_must_enable_advanced_wallet_message' => sprintf(
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
esc_html__( 'Your PayPal account must be enabled for the %1$sAdvanced PayPal Wallet%2$s to use PayPal Vaulting.', 'woocommerce-paypal-payments' ),
'<a href="/wp-admin/admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-connection#field-credentials_feature_onboarding_heading">',
'</a>'
),
)
)
);

View file

@ -381,6 +381,11 @@ class SettingsListener {
$reference_transaction_enabled = $this->billing_agreements_endpoint->reference_transaction_enabled();
if ( $reference_transaction_enabled !== true ) {
$this->settings->set( 'vault_enabled', false );
$this->settings->persist();
}
if ( $subscription_mode === 'vaulting_api' && $vault_enabled !== '1' && $reference_transaction_enabled === true ) {
$this->settings->set( 'vault_enabled', true );
$this->settings->persist();

View file

@ -181,7 +181,8 @@ class WCGatewayModule implements ModuleInterface {
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
$c->get( 'wcgateway.settings.funding-sources' ),
$c->get( 'wcgateway.is-ppcp-settings-page' ),
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' )
$settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' ),
$c->get( 'api.endpoint.billing-agreements' )
);
$assets->register_assets();
}