Disable vaulting checkbox and update message if not enabled for reference transactions

This commit is contained in:
Emili Castells Guasch 2024-02-15 16:05:56 +01:00
parent 8d1f45d19e
commit 8718270efb
3 changed files with 49 additions and 15 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_advance_wallet_message;
}
}
}
(() => { (() => {
removeDisabledCardIcons('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]'); removeDisabledCardIcons('select[name="ppcp[disable_cards][]"]', 'select[name="ppcp[card_icons][]"]');
@ -408,6 +422,8 @@ document.addEventListener(
); );
togglePayLaterMessageFields(); togglePayLaterMessageFields();
referenceTransactionsCheck()
})(); })();
} }
) )

View file

@ -9,12 +9,12 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Assets; namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\RefreshFeatureStatusEndpoint; use WooCommerce\PayPalCommerce\WcGateway\Endpoint\RefreshFeatureStatusEndpoint;
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper; use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\ResubscribeEndpoint;
/** /**
* Class SettingsPageAssets * Class SettingsPageAssets
@ -105,21 +105,29 @@ class SettingsPageAssets {
*/ */
private $is_acdc_enabled; private $is_acdc_enabled;
/**
* Billing Agreements endpoint.
*
* @var BillingAgreementsEndpoint
*/
private $billing_agreements_endpoint;
/** /**
* Assets constructor. * Assets constructor.
* *
* @param string $module_url The url of this module. * @param string $module_url The url of this module.
* @param string $version The assets version. * @param string $version The assets version.
* @param SubscriptionHelper $subscription_helper The subscription helper. * @param SubscriptionHelper $subscription_helper The subscription helper.
* @param string $client_id The PayPal SDK client ID. * @param string $client_id The PayPal SDK client ID.
* @param string $currency 3-letter currency code of the shop. * @param string $currency 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop. * @param string $country 2-letter country code of the shop.
* @param Environment $environment The environment object. * @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 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 $disabled_sources The list of disabled funding sources.
* @param array $all_funding_sources The list of all existing 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_settings_page Whether it's a settings page of this plugin.
* @param bool $is_acdc_enabled Whether the ACDC gateway is enabled. * @param bool $is_acdc_enabled Whether the ACDC gateway is enabled.
* @param BillingAgreementsEndpoint $billing_agreements_endpoint Billing Agreements endpoint.
*/ */
public function __construct( public function __construct(
string $module_url, string $module_url,
@ -133,7 +141,8 @@ class SettingsPageAssets {
array $disabled_sources, array $disabled_sources,
array $all_funding_sources, array $all_funding_sources,
bool $is_settings_page, bool $is_settings_page,
bool $is_acdc_enabled bool $is_acdc_enabled,
BillingAgreementsEndpoint $billing_agreements_endpoint
) { ) {
$this->module_url = $module_url; $this->module_url = $module_url;
$this->version = $version; $this->version = $version;
@ -147,6 +156,7 @@ class SettingsPageAssets {
$this->all_funding_sources = $all_funding_sources; $this->all_funding_sources = $all_funding_sources;
$this->is_settings_page = $is_settings_page; $this->is_settings_page = $is_settings_page;
$this->is_acdc_enabled = $is_acdc_enabled; $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_advance_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

@ -181,7 +181,8 @@ class WCGatewayModule implements ModuleInterface {
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(), $settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
$c->get( 'wcgateway.settings.funding-sources' ), $c->get( 'wcgateway.settings.funding-sources' ),
$c->get( 'wcgateway.is-ppcp-settings-page' ), $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(); $assets->register_assets();
} }