Skip to content

Commit

Permalink
Add endpoint save config
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinamiko committed Jan 29, 2025
1 parent 40edcdf commit 442a337
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function handle_request(): bool {
*
* @param array $config The configurator config.
*/
private function save_config( array $config ): void {
public function save_config( array $config ): void {
$this->settings->set( 'pay_later_enable_styling_per_messaging_location', true );
$this->settings->set( 'pay_later_messaging_enabled', true );

Expand Down
3 changes: 2 additions & 1 deletion modules/ppcp-settings/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
},
'settings.rest.pay_later_messaging' => static function ( ContainerInterface $container ) : PayLaterMessagingEndpoint {
return new PayLaterMessagingEndpoint(
$container->get( 'wcgateway.settings' )
$container->get( 'wcgateway.settings' ),
$container->get( 'paylater-configurator.endpoint.save-config' )
);
},
'settings.rest.settings' => static function ( ContainerInterface $container ) : SettingsRestEndpoint {
Expand Down
23 changes: 17 additions & 6 deletions modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace WooCommerce\PayPalCommerce\Settings\Endpoint;

use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WP_REST_Request;
Expand Down Expand Up @@ -36,13 +37,22 @@ class PayLaterMessagingEndpoint extends RestEndpoint {
*/
protected $settings;

/**
* Save config handler.
*
* @var SaveConfig
*/
private $save_config;

/**
* PayLaterMessagingEndpoint constructor.
*
* @param Settings $settings The settings.
* @param Settings $settings The settings.
* @param SaveConfig $save_config Save config handler.
*/
public function __construct( Settings $settings ) {
$this->settings = $settings;
public function __construct( Settings $settings, SaveConfig $save_config ) {
$this->settings = $settings;
$this->save_config = $save_config;
}

/**
Expand Down Expand Up @@ -77,7 +87,7 @@ public function register_routes() : void {
}

/**
* Returns all payment methods details.
* Returns Pay Later Messaging configuration details.
*
* @return WP_REST_Response The current payment methods details.
*/
Expand All @@ -86,14 +96,15 @@ public function get_details() : WP_REST_Response {
}

/**
* Updates payment methods details based on the request.
* Updates Pay Later Messaging configuration details based on the request.
*
* @param WP_REST_Request $request Full data about the request.
*
* @return WP_REST_Response The updated payment methods details.
*/
public function update_details( WP_REST_Request $request ) : WP_REST_Response {
$this->save_config->save_config( $request->get_params() );

return $this->get_details();
}

}

0 comments on commit 442a337

Please sign in to comment.