Start to implement payment method configuration

This commit is contained in:
Philipp Stracker 2025-02-13 19:37:42 +01:00
parent b5d717cac0
commit c854c8dceb
No known key found for this signature in database

View file

@ -19,6 +19,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\Settings\Data\StylingSettings; use WooCommerce\PayPalCommerce\Settings\Data\StylingSettings;
use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings; use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings;
use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel; use WooCommerce\PayPalCommerce\Settings\Data\SettingsModel;
use WooCommerce\PayPalCommerce\Settings\Data\PaymentSettings;
/** /**
* Class SettingsDataManager * Class SettingsDataManager
@ -49,6 +50,13 @@ class SettingsDataManager {
*/ */
private StylingSettings $styling_settings; private StylingSettings $styling_settings;
/**
* Model for handling payment methods.
*
* @var PaymentSettings
*/
private PaymentSettings $payment_methods;
/** /**
* Stores a list of all AbstractDataModel instances that are managed by * Stores a list of all AbstractDataModel instances that are managed by
* this service. * this service.
@ -64,6 +72,7 @@ class SettingsDataManager {
* @param GeneralSettings $general_settings The general settings model. * @param GeneralSettings $general_settings The general settings model.
* @param SettingsModel $payment_settings The settings model. * @param SettingsModel $payment_settings The settings model.
* @param StylingSettings $styling_settings The styling settings model. * @param StylingSettings $styling_settings The styling settings model.
* @param PaymentSettings $payment_methods The payment settings model.
* @param array ...$data_models List of additional data models to reset. * @param array ...$data_models List of additional data models to reset.
*/ */
public function __construct( public function __construct(
@ -71,6 +80,7 @@ class SettingsDataManager {
GeneralSettings $general_settings, GeneralSettings $general_settings,
SettingsModel $payment_settings, SettingsModel $payment_settings,
StylingSettings $styling_settings, StylingSettings $styling_settings,
PaymentSettings $payment_methods,
...$data_models ...$data_models
) { ) {
foreach ( $data_models as $data_model ) { foreach ( $data_models as $data_model ) {
@ -90,10 +100,12 @@ class SettingsDataManager {
$this->models_to_reset[] = $general_settings; $this->models_to_reset[] = $general_settings;
$this->models_to_reset[] = $payment_settings; $this->models_to_reset[] = $payment_settings;
$this->models_to_reset[] = $styling_settings; $this->models_to_reset[] = $styling_settings;
$this->models_to_reset[] = $payment_methods;
$this->onboarding_profile = $onboarding_profile; $this->onboarding_profile = $onboarding_profile;
$this->payment_settings = $payment_settings; $this->payment_settings = $payment_settings;
$this->styling_settings = $styling_settings; $this->styling_settings = $styling_settings;
$this->payment_methods = $payment_methods;
} }
/** /**
@ -145,6 +157,7 @@ class SettingsDataManager {
*/ */
protected function apply_configuration( ConfigurationFlagsDTO $flags ) : void { protected function apply_configuration( ConfigurationFlagsDTO $flags ) : void {
// Apply defaults for the "Payment Methods" tab. // Apply defaults for the "Payment Methods" tab.
$this->toggle_payment_gateways( $flags );
// Apply defaults for the "Settings" tab. // Apply defaults for the "Settings" tab.
$this->apply_payment_settings( $flags ); $this->apply_payment_settings( $flags );
@ -153,6 +166,19 @@ class SettingsDataManager {
$this->apply_location_styles( $flags ); $this->apply_location_styles( $flags );
} }
/**
* Enables or disables payment gateways depending on the provided
* configuration flags.
*
* @param ConfigurationFlagsDTO $flags Shop configuration flags.
* @return void
*/
protected function toggle_payment_gateways( ConfigurationFlagsDTO $flags ) : void {
// Always enable Venmo and Pay Later.
$this->payment_methods->set_venmo_enabled( true );
$this->payment_methods->set_paylater_enabled( true );
}
/** /**
* Applies the default payment settings that are relevant for the provided * Applies the default payment settings that are relevant for the provided
* configuration flags. * configuration flags.