mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +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(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( $this, 'connect_manual' ),
|
'callback' => array( $this, 'connect_manual' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,36 +110,30 @@ class CommonRestEndpoint extends RestEndpoint {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( $this, 'get_details' ),
|
'callback' => array( $this, 'get_details' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( $this, 'update_details' ),
|
'callback' => array( $this, 'update_details' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
"/$this->rest_base/merchant",
|
"/$this->rest_base/merchant",
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( $this, 'get_merchant_details' ),
|
'callback' => array( $this, 'get_merchant_details' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,6 @@ class LoginLinkRestEndpoint extends RestEndpoint {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( $this, 'get_login_url' ),
|
'callback' => array( $this, 'get_login_url' ),
|
||||||
|
@ -76,7 +75,6 @@ class LoginLinkRestEndpoint extends RestEndpoint {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,24 +100,20 @@ class OnboardingRestEndpoint extends RestEndpoint {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( $this, 'get_details' ),
|
'callback' => array( $this, 'get_details' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( $this, 'update_details' ),
|
'callback' => array( $this, 'update_details' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
|
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types = 1 );
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
||||||
|
|
||||||
|
@ -86,12 +86,10 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_base,
|
||||||
array(
|
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
'callback' => array( $this, 'refresh_status' ),
|
'callback' => array( $this, 'refresh_status' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +100,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
|
||||||
* @param WP_REST_Request $request Full data about the request.
|
* @param WP_REST_Request $request Full data about the request.
|
||||||
* @return WP_REST_Response
|
* @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();
|
$now = time();
|
||||||
$last_request_time = $this->cache->get( self::CACHE_KEY ) ?: 0;
|
$last_request_time = $this->cache->get( self::CACHE_KEY ) ?: 0;
|
||||||
$seconds_missing = $last_request_time + self::TIMEOUT - $now;
|
$seconds_missing = $last_request_time + self::TIMEOUT - $now;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue