From 433e7f7c8bf68b7f5cd790eed3d7c2063626535b Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 14 Mar 2025 16:27:01 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20redundant=20checks=20fr?=
=?UTF-8?q?om=20SmartButton?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Most checks are already implemented in the CardPaymentsConfiguration class.
---
.../ppcp-button/src/Assets/SmartButton.php | 29 +++----------------
1 file changed, 4 insertions(+), 25 deletions(-)
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index 62dcd9f0f..8e284e0a4 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -720,9 +720,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
* Whether DCC fields can be rendered.
*/
public function can_render_dcc() : bool {
- return $this->dcc_configuration->is_enabled()
- && $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' )
- && $this->dcc_applies->for_country_currency()
+ return $this->dcc_configuration->is_acdc_enabled()
&& in_array(
$this->context(),
apply_filters( 'woocommerce_paypal_payments_can_render_dcc_contexts', array( 'checkout', 'pay-now', 'add-payment-method' ) ),
@@ -1126,7 +1124,7 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
'client_id' => $this->client_id,
'currency' => $this->currency->get(),
'data_client_id' => array(
- 'set_attribute' => ( is_checkout() && $this->dcc_is_enabled() ) || $this->can_save_vault_token(),
+ 'set_attribute' => $this->dcc_is_enabled() || $this->can_save_vault_token(),
'endpoint' => \WC_AJAX::get_endpoint( DataClientIdEndpoint::ENDPOINT ),
'nonce' => wp_create_nonce( DataClientIdEndpoint::nonce() ),
'user' => get_current_user_id(),
@@ -1595,31 +1593,12 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
}
/**
- * Whether DCC is enabled or not.
+ * Whether ACDC is available on the current page.
*
* @return bool
*/
private function dcc_is_enabled() : bool {
- // Card payments are only available on the checkout page, and for certain seller countries.
- if ( ! is_checkout() || ! $this->dcc_applies->for_country_currency() ) {
- return false;
- }
-
- try {
- // Bail, if the merchant is not fully onboarded yet.
- if (
- ! $this->settings->get( 'client_id' )
- || ! $this->settings->get( 'client_secret' )
- ) {
- return false;
- }
-
- // The actual condition that must be met.
- return $this->dcc_configuration->is_enabled();
- } catch ( NotFoundException $e ) {
- // Bail, if the settings DB entries are missing.
- return false;
- }
+ return is_checkout() && $this->dcc_configuration->is_acdc_enabled();
}
/**