Map the "Instant payments only" & thee "Landing Page" option.

Currently, the "Instant payments only" option is not saved in DB so probably will be needed to update the new key later
This commit is contained in:
Narek Zakarian 2025-02-14 12:55:26 +04:00
parent 897106499c
commit 47f61cb543
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Compat\Settings;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Helper\PurchaseUnitSanitizer;
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
@ -32,7 +33,9 @@ class SettingsTabMapHelper {
'disable_cards' => 'disabled_cards',
'brand_name' => 'brand_name',
'soft_descriptor' => 'soft_descriptor',
'payee_preferred' => 'instant_payments_only',
'subtotal_mismatch_behavior' => 'subtotal_adjustment',
'landing_page' => 'landing_page',
);
}
@ -50,16 +53,19 @@ class SettingsTabMapHelper {
case 'subtotal_mismatch_behavior':
return $this->mapped_mismatch_behavior_value( $settings_model );
case 'landing_page':
return $this->mapped_landing_page_value( $settings_model );
default:
return $settings_model[ $new_key ] ?? null;
}
}
/**
* Retrieves the mapped mismatch_behavior value from the new settings.
* Retrieves the mapped value for the 'mismatch_behavior' from the new settings.
*
* @param array<string, scalar|array> $settings_model The new settings model data as an array.
* @return 'extra_line'|'ditch'|null The mapped mismatch_behavior value.
* @return 'extra_line'|'ditch'|null The mapped 'mismatch_behavior' setting value.
*/
protected function mapped_mismatch_behavior_value( array $settings_model ): ?string {
$subtotal_adjustment = $settings_model['subtotal_adjustment'] ?? false;
@ -70,4 +76,25 @@ class SettingsTabMapHelper {
return $subtotal_adjustment === 'correction' ? PurchaseUnitSanitizer::MODE_EXTRA_LINE : PurchaseUnitSanitizer::MODE_DITCH;
}
/**
* Retrieves the mapped value for the 'landing_page' from the new settings.
*
* @param array<string, scalar|array> $settings_model The new settings model data as an array.
* @return 'LOGIN'|'BILLING'|'NO_PREFERENCE'|null The mapped 'landing_page' setting value.
*/
protected function mapped_landing_page_value( array $settings_model ): ?string {
$landing_page = $settings_model['landing_page'] ?? false;
if ( ! $landing_page ) {
return null;
}
return $landing_page === 'login'
? ApplicationContext::LANDING_PAGE_LOGIN
: ( $landing_page === 'guest_checkout'
? ApplicationContext::LANDING_PAGE_BILLING
: ApplicationContext::LANDING_PAGE_NO_PREFERENCE
);
}
}