Refactor APM admin settings

This commit is contained in:
Pedro Silva 2023-08-30 11:28:18 +01:00
parent 78d58f1a03
commit d6f6d05431
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
2 changed files with 46 additions and 29 deletions

View file

@ -14,29 +14,31 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
return array(
'wcgateway.settings.fields' => static function ( ContainerInterface $container, array $fields ): array {
$fields['googlepay_heading'] = array(
'heading' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
'description' =>
__(
'Customize the behaviour of the GooglePay button.',
'woocommerce-paypal-payments'
),
'type' => 'ppcp-heading',
'screens' => array( State::STATE_ONBOARDED ),
'requirements' => array(),
'gateway' => 'paypal',
);
$fields['googlepay_button_enabled'] = array(
'title' => __( 'Google Pay Button', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable Google Pay button', 'woocommerce-paypal-payments' ),
'default' => 'yes',
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => 'paypal',
'requirements' => array(),
);
return $fields;
'wcgateway.settings.fields' => function ( ContainerInterface $container, array $fields ): array {
$insert_after = function( array $array, string $key, array $new ): array {
$keys = array_keys( $array );
$index = array_search( $key, $keys, true );
$pos = false === $index ? count( $array ) : $index + 1;
return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
};
return $insert_after(
$fields,
'allow_card_button_gateway',
array(
'googlepay_button_enabled' => array(
'title' => __( 'Google Pay Button', 'woocommerce-paypal-payments' ),
'type' => 'checkbox',
'label' => __( 'Enable Google Pay button', 'woocommerce-paypal-payments' ),
'default' => 'yes',
'screens' => array( State::STATE_ONBOARDED ),
'gateway' => 'paypal',
'requirements' => array(),
),
)
);
},
);