From 3e5f151bbb9d14db848def213bdd74490b07e9c0 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:31:56 +0400 Subject: [PATCH] Map the "Order intent" --- .../src/Settings/SettingsTabMapHelper.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index 5e43c7745..99f93c4ce 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -37,7 +37,8 @@ class SettingsTabMapHelper { 'subtotal_mismatch_behavior' => 'subtotal_adjustment', 'landing_page' => 'landing_page', 'smart_button_language' => 'button_language', - 'prefix' => 'invoice_prefix', + 'prefix' => 'invoice_prefix', + 'intent' => '', ); } @@ -58,6 +59,9 @@ class SettingsTabMapHelper { case 'landing_page': return $this->mapped_landing_page_value( $settings_model ); + case 'intent': + return $this->mapped_intent_value( $settings_model ); + default: return $settings_model[ $new_key ] ?? null; } @@ -99,4 +103,21 @@ class SettingsTabMapHelper { : ApplicationContext::LANDING_PAGE_NO_PREFERENCE ); } + + /** + * Retrieves the mapped value for the order intent from the new settings. + * + * @param array $settings_model The new settings model data as an array. + * @return 'AUTHORIZE'|'CAPTURE'|null The mapped 'intent' setting value. + */ + protected function mapped_intent_value( array $settings_model ): ?string { + $authorize_only = $settings_model['authorize_only'] ?? null; + $capture_virtual_orders = $settings_model['capture_virtual_orders'] ?? null; + + if ( is_null( $authorize_only ) && is_null( $capture_virtual_orders ) ) { + return null; + } + + return $authorize_only ? 'AUTHORIZE' : 'CAPTURE'; + } }