mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
✨ Add REST endpoint for the Onboarding store
This commit is contained in:
parent
d4aa87dff4
commit
b2e662e246
4 changed files with 109 additions and 1 deletions
|
@ -10,9 +10,10 @@ declare( strict_types = 1 );
|
||||||
namespace WooCommerce\PayPalCommerce\Settings;
|
namespace WooCommerce\PayPalCommerce\Settings;
|
||||||
|
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'settings.url' => static function ( ContainerInterface $container ) : string {
|
'settings.url' => static function ( ContainerInterface $container ) : string {
|
||||||
/**
|
/**
|
||||||
* The path cannot be false.
|
* The path cannot be false.
|
||||||
*
|
*
|
||||||
|
@ -23,4 +24,7 @@ return array(
|
||||||
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint {
|
||||||
|
return new OnboardingRestEndpoint();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* REST endpoint to manage the onboarding module.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare( strict_types = 1 );
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
||||||
|
|
||||||
|
use WP_REST_Server;
|
||||||
|
use WP_REST_Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST controller for the onboarding module.
|
||||||
|
*
|
||||||
|
* Responsible for persisting and loading the state of the onboarding wizard.
|
||||||
|
*/
|
||||||
|
class OnboardingRestEndpoint extends RestEndpoint {
|
||||||
|
/**
|
||||||
|
* The base path for this REST controller.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $rest_base = 'onboarding';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure REST API routes.
|
||||||
|
*/
|
||||||
|
public function register_routes() {
|
||||||
|
register_rest_route(
|
||||||
|
$this->namespace,
|
||||||
|
'/' . $this->rest_base,
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => array( $this, 'get_details' ),
|
||||||
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an object with all details of the current onboarding wizard
|
||||||
|
* progress.
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response The current state of the onboarding wizard.
|
||||||
|
*/
|
||||||
|
public function get_details() : WP_REST_Response {
|
||||||
|
// TODO: Retrieve the onboarding details from the database.
|
||||||
|
$details = array(
|
||||||
|
'step' => 1,
|
||||||
|
'completed' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
return rest_ensure_response( $details );
|
||||||
|
}
|
||||||
|
}
|
36
modules/ppcp-settings/src/Endpoint/RestEndpoint.php
Normal file
36
modules/ppcp-settings/src/Endpoint/RestEndpoint.php
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* REST endpoint to manage the onboarding module.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare( strict_types = 1 );
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
||||||
|
|
||||||
|
use WC_REST_Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for REST controllers in the settings module.
|
||||||
|
*
|
||||||
|
* This is a base class for specific REST endpoints; do not instantiate this
|
||||||
|
* class directly.
|
||||||
|
*/
|
||||||
|
class RestEndpoint extends WC_REST_Controller {
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $namespace = 'wc/v3/wc_paypal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify access.
|
||||||
|
*
|
||||||
|
* Override this method if custom permissions required.
|
||||||
|
*/
|
||||||
|
public function check_permission() : bool {
|
||||||
|
return current_user_can( 'manage_woocommerce' );
|
||||||
|
}
|
||||||
|
}
|
|
@ -91,6 +91,14 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'rest_api_init',
|
||||||
|
static function () use ( $container ) : void {
|
||||||
|
$onboarding_endpoint = $container->get( 'settings.rest.onboarding' );
|
||||||
|
$onboarding_endpoint->register_routes();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue