Skip to content

Commit

Permalink
Extract gateway fields into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoslavGeorgiev committed Dec 12, 2024
1 parent 8c826fd commit 7daa4ac
Showing 1 changed file with 42 additions and 36 deletions.
78 changes: 42 additions & 36 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 7daa4ac

Please sign in to comment.