diff --git a/modules/ppcp-compat/src/Settings/GeneralSettingsMapHelper.php b/modules/ppcp-compat/src/Settings/GeneralSettingsMapHelper.php new file mode 100644 index 000000000..1d872471c --- /dev/null +++ b/modules/ppcp-compat/src/Settings/GeneralSettingsMapHelper.php @@ -0,0 +1,69 @@ + + */ + public function map(): array { + return array( + 'merchant_id' => 'merchant_id', + 'client_id' => 'client_id', + 'client_secret' => 'client_secret', + 'sandbox_on' => 'sandbox_merchant', + 'live_client_id' => 'client_id', + 'live_client_secret' => 'client_secret', + 'live_merchant_id' => 'merchant_id', + 'live_merchant_email' => 'merchant_email', + 'sandbox_client_id' => 'client_id', + 'sandbox_client_secret' => 'client_secret', + 'sandbox_merchant_id' => 'merchant_id', + 'sandbox_merchant_email' => 'merchant_email', + 'enabled' => '', + 'allow_local_apm_gateways' => '', + ); + } + + /** + * Retrieves the mapped value for the given key from the new settings. + * + * @param string $old_key The key from the legacy settings. + * @param array $settings_model The new settings model data as an array. + * @return mixed The value of the mapped setting, or null if not applicable. + */ + public function mapped_value( string $old_key, array $settings_model ) { + $settings_map = $this->map(); + $new_key = $settings_map[ $old_key ] ?? false; + switch ( $old_key ) { + case 'enabled': + case 'allow_local_apm_gateways': + return true; + + default: + return $settings_model[ $new_key ] ?? null; + } + } +}