From 7daa4ac69844d8ea573ce14d82df3777b10112be Mon Sep 17 00:00:00 2001 From: Radoslav Georgiev Date: Thu, 12 Dec 2024 23:22:08 +0200 Subject: [PATCH] Extract gateway fields into a separate method --- includes/class-wc-payment-gateway-wcpay.php | 78 +++++++++++---------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index cb087fc9de4..4e231e588bf 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -327,8 +327,47 @@ public function __construct( $this->method_title = "WooPayments ($this->title)"; } - // Define setting fields. - add_action( 'after_setup_theme', function() { + // Capabilities have different keys than the payment method ID's, + // so instead of appending '_payments' to the end of the ID, it'll be better + // to have a map for it instead, just in case the pattern changes. + $this->payment_method_capability_key_map = [ + 'sofort' => 'sofort_payments', + 'giropay' => 'giropay_payments', + 'bancontact' => 'bancontact_payments', + 'eps' => 'eps_payments', + 'ideal' => 'ideal_payments', + 'p24' => 'p24_payments', + 'card' => 'card_payments', + 'sepa_debit' => 'sepa_debit_payments', + 'au_becs_debit' => 'au_becs_debit_payments', + 'link' => 'link_payments', + 'affirm' => 'affirm_payments', + 'afterpay_clearpay' => 'afterpay_clearpay_payments', + 'klarna' => 'klarna_payments', + 'jcb' => 'jcb_payments', + ]; + + // WooPay utilities. + $this->woopay_util = new WooPay_Utilities(); + + // Load the settings. + $this->init_settings(); + + // Check if subscriptions are enabled and add support for them. + $this->maybe_init_subscriptions(); + + // If the setting to enable saved cards is enabled, then we should support tokenization and adding payment methods. + if ( $this->is_saved_cards_enabled() ) { + array_push( $this->supports, 'tokenization', 'add_payment_method' ); + } + } + + /** + * Get the form fields after they are initialized. + * + * @return array of options + */ + public function get_form_fields() { $this->form_fields = [ 'enabled' => [ 'title' => __( 'Enable/disable', 'woocommerce-payments' ), @@ -497,41 +536,8 @@ public function __construct( ], 'platform_checkout_custom_message' => [ 'default' => __( 'By placing this order, you agree to our [terms] and understand our [privacy_policy].', 'woocommerce-payments' ) ], ]; - }); - // Capabilities have different keys than the payment method ID's, - // so instead of appending '_payments' to the end of the ID, it'll be better - // to have a map for it instead, just in case the pattern changes. - $this->payment_method_capability_key_map = [ - 'sofort' => 'sofort_payments', - 'giropay' => 'giropay_payments', - 'bancontact' => 'bancontact_payments', - 'eps' => 'eps_payments', - 'ideal' => 'ideal_payments', - 'p24' => 'p24_payments', - 'card' => 'card_payments', - 'sepa_debit' => 'sepa_debit_payments', - 'au_becs_debit' => 'au_becs_debit_payments', - 'link' => 'link_payments', - 'affirm' => 'affirm_payments', - 'afterpay_clearpay' => 'afterpay_clearpay_payments', - 'klarna' => 'klarna_payments', - 'jcb' => 'jcb_payments', - ]; - - // WooPay utilities. - $this->woopay_util = new WooPay_Utilities(); - - // Load the settings. - $this->init_settings(); - - // Check if subscriptions are enabled and add support for them. - $this->maybe_init_subscriptions(); - - // If the setting to enable saved cards is enabled, then we should support tokenization and adding payment methods. - if ( $this->is_saved_cards_enabled() ) { - array_push( $this->supports, 'tokenization', 'add_payment_method' ); - } + return parent::get_form_fields(); } /**