mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
♻️ Move 3D Secure settings from Payment Methods to Settings tab
This commit is contained in:
parent
a362780c8e
commit
6a904e1b1d
11 changed files with 125 additions and 80 deletions
|
@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\Compat\Settings;
|
|||
|
||||
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\PaymentSettings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
|
||||
/**
|
||||
|
@ -22,15 +21,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
|||
*/
|
||||
class PaymentMethodSettingsMapHelper {
|
||||
|
||||
/**
|
||||
* A map of new to old 3d secure values.
|
||||
*/
|
||||
protected const THREE_D_SECURE_VALUES_MAP = array(
|
||||
'no-3d-secure' => 'NO_3D_SECURE',
|
||||
'only-required-3d-secure' => 'SCA_WHEN_REQUIRED',
|
||||
'always-3d-secure' => 'SCA_ALWAYS',
|
||||
);
|
||||
|
||||
/**
|
||||
* Maps old setting keys to new payment method settings names.
|
||||
*
|
||||
|
@ -40,7 +30,6 @@ class PaymentMethodSettingsMapHelper {
|
|||
return array(
|
||||
'dcc_enabled' => CreditCardGateway::ID,
|
||||
'axo_enabled' => AxoGateway::ID,
|
||||
'3d_secure_contingency' => 'three_d_secure',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -52,25 +41,13 @@ class PaymentMethodSettingsMapHelper {
|
|||
* @return mixed The value of the mapped setting, (null if not found).
|
||||
*/
|
||||
public function mapped_value( string $old_key, ?AbstractDataModel $payment_settings ) {
|
||||
switch ( $old_key ) {
|
||||
case '3d_secure_contingency':
|
||||
if ( is_null( $payment_settings ) ) {
|
||||
return null;
|
||||
}
|
||||
$payment_method = $this->map()[ $old_key ] ?? false;
|
||||
|
||||
assert( $payment_settings instanceof PaymentSettings );
|
||||
$selected_three_d_secure = $payment_settings->get_three_d_secure();
|
||||
return self::THREE_D_SECURE_VALUES_MAP[ $selected_three_d_secure ] ?? null;
|
||||
|
||||
default:
|
||||
$payment_method = $this->map()[ $old_key ] ?? false;
|
||||
|
||||
if ( ! $payment_method ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->is_gateway_enabled( $payment_method );
|
||||
if ( ! $payment_method ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->is_gateway_enabled( $payment_method );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,15 @@ class SettingsTabMapHelper {
|
|||
|
||||
use ContextTrait;
|
||||
|
||||
/**
|
||||
* A map of new to old 3d secure values.
|
||||
*/
|
||||
protected const THREE_D_SECURE_VALUES_MAP = array(
|
||||
'no-3d-secure' => 'NO_3D_SECURE',
|
||||
'only-required-3d-secure' => 'SCA_WHEN_REQUIRED',
|
||||
'always-3d-secure' => 'SCA_ALWAYS',
|
||||
);
|
||||
|
||||
/**
|
||||
* Maps old setting keys to new setting keys.
|
||||
*
|
||||
|
@ -43,6 +52,7 @@ class SettingsTabMapHelper {
|
|||
'blocks_final_review_enabled' => 'enable_pay_now',
|
||||
'logging_enabled' => 'enable_logging',
|
||||
'vault_enabled' => 'save_paypal_and_venmo',
|
||||
'3d_secure_contingency' => 'threeDSecure',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -69,11 +79,30 @@ class SettingsTabMapHelper {
|
|||
case 'blocks_final_review_enabled':
|
||||
return $this->mapped_pay_now_value( $settings_model );
|
||||
|
||||
case '3d_secure_contingency':
|
||||
return $this->mapped_3d_secure_value( $settings_model );
|
||||
|
||||
default:
|
||||
return $settings_model[ $new_key ] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the mapped value for the '3d_secure_contingency' from the new settings.
|
||||
*
|
||||
* @param array<string, scalar|array> $settings_model The new settings model data as an array.
|
||||
* @return string|null The mapped '3d_secure_contingency' setting value.
|
||||
*/
|
||||
protected function mapped_3d_secure_value( array $settings_model ): ?string {
|
||||
$three_d_secure = $settings_model['threeDSecure'] ?? null;
|
||||
|
||||
if ( is_null( $three_d_secure ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::THREE_D_SECURE_VALUES_MAP[ $three_d_secure ] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the mapped value for the 'mismatch_behavior' from the new settings.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue