Add rest endpoint boilerplate

This commit is contained in:
Emili Castells Guasch 2025-01-29 16:41:50 +01:00
parent 696f50e404
commit 83912f2b93
3 changed files with 93 additions and 0 deletions

View file

@ -21,6 +21,7 @@ use WooCommerce\PayPalCommerce\Settings\Endpoint\AuthenticationRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\PayLaterMessagingEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\PaymentRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\PaymentRestEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint;
use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint;
@ -120,6 +121,9 @@ return array(
$container->get( 'webhook.status.simulation' ) $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 { 'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array {
return array( return array(
'AR', 'AR',

View file

@ -0,0 +1,88 @@
<?php
/**
* REST endpoint to manage the Pay Later Messaging configurator page.
*
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
*/
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
/**
* REST controller for the "Pay Later Messaging" settings tab.
*
* This API acts as the intermediary between the "external world" and our
* internal data model.
*/
class PayLaterMessagingEndpoint extends RestEndpoint {
/**
* The base path for this REST controller.
*
* @var string
*/
protected $rest_base = 'pay_later_messaging';
/**
* Configure REST API routes.
*/
public function register_routes() : void {
/**
* GET wc/v3/wc_paypal/pay_later_messaging
*/
register_rest_route(
$this->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();
}
}

View file

@ -238,6 +238,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
'settings' => $container->get( 'settings.rest.settings' ), 'settings' => $container->get( 'settings.rest.settings' ),
'styling' => $container->get( 'settings.rest.styling' ), 'styling' => $container->get( 'settings.rest.styling' ),
'todos' => $container->get( 'settings.rest.todos' ), 'todos' => $container->get( 'settings.rest.todos' ),
'pay_later_messaging' => $container->get( 'settings.rest.pay_later_messaging' ),
); );
foreach ( $endpoints as $endpoint ) { foreach ( $endpoints as $endpoint ) {