From 83912f2b93e2b0aea8f6657631ff35caadef9c60 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 29 Jan 2025 16:41:50 +0100 Subject: [PATCH] Add rest endpoint boilerplate --- modules/ppcp-settings/services.php | 4 + .../Endpoint/PayLaterMessagingEndpoint.php | 88 +++++++++++++++++++ modules/ppcp-settings/src/SettingsModule.php | 1 + 3 files changed, 93 insertions(+) create mode 100644 modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index cf397b8bf..cc993f0d6 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -21,6 +21,7 @@ use WooCommerce\PayPalCommerce\Settings\Endpoint\AuthenticationRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint; +use WooCommerce\PayPalCommerce\Settings\Endpoint\PayLaterMessagingEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\PaymentRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint; @@ -120,6 +121,9 @@ return array( $container->get( 'webhook.status.simulation' ) ); }, + 'settings.rest.pay_later_messaging' => static function ( ContainerInterface $container ) : PayLaterMessagingEndpoint { + return new PayLaterMessagingEndpoint(); + }, 'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array { return array( 'AR', diff --git a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php new file mode 100644 index 000000000..5e5643261 --- /dev/null +++ b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php @@ -0,0 +1,88 @@ +namespace, + '/' . $this->rest_base, + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_details' ), + 'permission_callback' => array( $this, 'check_permission' ), + ) + ); + + /** + * POST wc/v3/wc_paypal/pay_later_messaging + * { + * [gateway_id]: { + * enabled + * title + * description + * } + * } + */ + register_rest_route( + $this->namespace, + '/' . $this->rest_base, + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_details' ), + 'permission_callback' => array( $this, 'check_permission' ), + ) + ); + } + + /** + * Returns all payment methods details. + * + * @return WP_REST_Response The current payment methods details. + */ + public function get_details() : WP_REST_Response { + return $this->return_success( array() ); + } + + /** + * Updates payment methods 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 { + return $this->get_details(); + } + +} diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php index b7c334425..c6fea6621 100644 --- a/modules/ppcp-settings/src/SettingsModule.php +++ b/modules/ppcp-settings/src/SettingsModule.php @@ -238,6 +238,7 @@ class SettingsModule implements ServiceModule, ExecutableModule { 'settings' => $container->get( 'settings.rest.settings' ), 'styling' => $container->get( 'settings.rest.styling' ), 'todos' => $container->get( 'settings.rest.todos' ), + 'pay_later_messaging' => $container->get( 'settings.rest.pay_later_messaging' ), ); foreach ( $endpoints as $endpoint ) {