mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
♻️ Slightly simplify REST code
This commit is contained in:
parent
f73f1808a7
commit
5195748e76
5 changed files with 36 additions and 52 deletions
|
@ -90,12 +90,10 @@ class AuthenticationRestEndpoint extends RestEndpoint {
|
|||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'connect_manual' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -111,11 +111,9 @@ class CommonRestEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -123,11 +121,9 @@ class CommonRestEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -135,11 +131,9 @@ class CommonRestEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
"/$this->rest_base/merchant",
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_merchant_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_merchant_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -56,25 +56,23 @@ class LoginLinkRestEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'get_login_url' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
'args' => array(
|
||||
'environment' => array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
),
|
||||
'products' => array(
|
||||
'required' => true,
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'sanitize_callback' => function ( $products ) {
|
||||
return array_map( 'sanitize_text_field', $products );
|
||||
},
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'get_login_url' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
'args' => array(
|
||||
'environment' => array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
),
|
||||
'products' => array(
|
||||
'required' => true,
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'sanitize_callback' => function ( $products ) {
|
||||
return array_map( 'sanitize_text_field', $products );
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -101,11 +101,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -113,11 +111,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_details' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
||||
|
||||
|
@ -87,11 +87,9 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
|
|||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'refresh_status' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
),
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'refresh_status' ),
|
||||
'permission_callback' => array( $this, 'check_permission' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -102,7 +100,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
|
|||
* @param WP_REST_Request $request Full data about the request.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function refresh_status( WP_REST_Request $request ): WP_REST_Response {
|
||||
public function refresh_status( WP_REST_Request $request ) : WP_REST_Response {
|
||||
$now = time();
|
||||
$last_request_time = $this->cache->get( self::CACHE_KEY ) ?: 0;
|
||||
$seconds_missing = $last_request_time + self::TIMEOUT - $now;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue