Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create mapping for the 3d_secure_contingency setting. (4410) #3262

Merged
merged 3 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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;

/**
Expand All @@ -20,33 +22,55 @@
*/
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.
*
* @psalm-return array<oldSettingsKey, newSettingsKey>
*/
public function map(): array {
return array(
'dcc_enabled' => CreditCardGateway::ID,
'axo_enabled' => AxoGateway::ID,
'dcc_enabled' => CreditCardGateway::ID,
'axo_enabled' => AxoGateway::ID,
'3d_secure_contingency' => 'three_d_secure',
);
}

/**
* Retrieves the value of a mapped key from the new settings.
*
* @param string $old_key The key from the legacy settings.
* @param string $old_key The key from the legacy settings.
* @param AbstractDataModel|null $payment_settings The payment settings model.
* @return mixed The value of the mapped setting, (null if not found).
*/
public function mapped_value( string $old_key ): ?bool {
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;

if ( ! $payment_method ) {
return null;
}
default:
$payment_method = $this->map()[ $old_key ] ?? false;

if ( ! $payment_method ) {
return null;
}

return $this->is_gateway_enabled( $payment_method );
return $this->is_gateway_enabled( $payment_method );
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/ppcp-compat/src/Settings/SettingsMapHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function get_cached_model_value( int $model_id, string $old_key, strin
: $this->settings_tab_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );

case $model instanceof PaymentSettings:
return $this->payment_method_settings_map_helper->mapped_value( $old_key );
return $this->payment_method_settings_map_helper->mapped_value( $old_key, $this->get_payment_settings_model() );

default:
return $this->model_cache[ $model_id ][ $new_key ] ?? null;
Expand Down
Loading