From 3fead84a70e6c5f14b2228d506ad0e9946cc8c19 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 17 Mar 2025 15:23:29 +0100
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20DCC=20hooks=20to=20?=
=?UTF-8?q?separate=20helper=20method?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ppcp-button/src/Assets/SmartButton.php | 129 ++++++++++--------
1 file changed, 69 insertions(+), 60 deletions(-)
diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php
index 054fe8c41..477f73cb8 100644
--- a/modules/ppcp-button/src/Assets/SmartButton.php
+++ b/modules/ppcp-button/src/Assets/SmartButton.php
@@ -342,66 +342,7 @@ class SmartButton implements SmartButtonInterface {
}
if ( $this->dcc_configuration->is_enabled() ) {
- add_action(
- $this->checkout_dcc_button_renderer_hook(),
- array( $this, 'dcc_renderer' ),
- 11
- );
-
- add_action(
- $this->pay_order_renderer_hook(),
- array( $this, 'dcc_renderer' ),
- 11
- );
-
- $subscription_helper = $this->subscription_helper;
- add_filter(
- 'woocommerce_credit_card_form_fields',
- function ( array $default_fields, $id ) use ( $subscription_helper ) : array {
- if (
- is_user_logged_in()
- && $this->settings->has( 'vault_enabled_dcc' )
- && $this->settings->get( 'vault_enabled_dcc' )
- && CreditCardGateway::ID === $id
- && apply_filters( 'woocommerce_paypal_payments_should_render_card_custom_fields', true )
- ) {
-
- $default_fields['card-vault'] = sprintf(
- '',
- esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' )
- );
- if ( $subscription_helper->cart_contains_subscription() || $subscription_helper->order_pay_contains_subscription() ) {
- $default_fields['card-vault'] = '';
- }
-
- $tokens = $this->payment_token_repository->all_for_user_id( get_current_user_id() );
- if ( $tokens && $this->payment_token_repository->tokens_contains_card( $tokens ) ) {
- $output = sprintf(
- '';
-
- $default_fields['saved-credit-card'] = $output;
- }
- }
-
- return $default_fields;
- },
- 10,
- 2
- );
+ $this->render_dcc_wrapper();
}
if ( $this->is_free_trial_cart() ) {
@@ -440,6 +381,74 @@ class SmartButton implements SmartButtonInterface {
return true;
}
+ /**
+ * Registers hooks and callbacks that are only relevant for DCC (ACDC) payments.
+ *
+ * @return void
+ */
+ private function render_dcc_wrapper(): void {
+ add_action(
+ $this->checkout_dcc_button_renderer_hook(),
+ array( $this, 'dcc_renderer' ),
+ 11
+ );
+
+ add_action(
+ $this->pay_order_renderer_hook(),
+ array( $this, 'dcc_renderer' ),
+ 11
+ );
+
+ $subscription_helper = $this->subscription_helper;
+ add_filter(
+ 'woocommerce_credit_card_form_fields',
+ function ( array $default_fields, $id ) use ( $subscription_helper ) : array {
+ if (
+ CreditCardGateway::ID === $id
+ && is_user_logged_in()
+ && $this->settings->has( 'vault_enabled_dcc' )
+ && $this->settings->get( 'vault_enabled_dcc' )
+ && apply_filters( 'woocommerce_paypal_payments_should_render_card_custom_fields', true )
+ ) {
+
+ $default_fields['card-vault'] = sprintf(
+ '',
+ esc_html__( 'Save your Credit Card', 'woocommerce-paypal-payments' )
+ );
+ if ( $subscription_helper->cart_contains_subscription() || $subscription_helper->order_pay_contains_subscription() ) {
+ $default_fields['card-vault'] = '';
+ }
+
+ $tokens = $this->payment_token_repository->all_for_user_id( get_current_user_id() );
+ if ( $tokens && $this->payment_token_repository->tokens_contains_card( $tokens ) ) {
+ $output = sprintf(
+ '';
+
+ $default_fields['saved-credit-card'] = $output;
+ }
+ }
+
+ return $default_fields;
+ },
+ 10,
+ 2
+ );
+ }
+
/**
* Registers the hooks to render the credit messaging HTML depending on the settings.
*