PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.4.1
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Rest / IntegrationsCatalogRestServiceProvider.php
IntegrationsCatalogRestServiceProvider.php
131 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Rest;
4
5 use SureCart\Controllers\Rest\IntegrationCatalogController;
6 use SureCart\Rest\RestServiceInterface;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class IntegrationsCatalogRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12 /**
13 * Rest Controller
14 *
15 * @var string
16 */
17 protected $controller = IntegrationCatalogController::class;
18
19 /**
20 * Register Additional REST Routes
21 *
22 * @return void
23 */
24 public function registerModelRoutes() {
25 // List available providers for a specific model.
26 register_rest_route(
27 "$this->name/v$this->version",
28 'integration_catalog',
29 [
30 [
31 'methods' => \WP_REST_Server::READABLE,
32 'callback' => $this->callback( $this->controller, 'index' ),
33 'permission_callback' => [ $this, 'get_items_permission_check' ],
34 ],
35 // Register our schema callback.
36 'schema' => [ $this, 'get_item_schema' ],
37 ]
38 );
39
40 // Find a specific provider data.
41 register_rest_route(
42 "$this->name/v$this->version",
43 'integration_catalog/(?P<id>\d+)',
44 [
45 [
46 'methods' => \WP_REST_Server::READABLE,
47 'callback' => $this->callback( $this->controller, 'find' ),
48 'permission_callback' => [ $this, 'get_item_permission_check' ],
49 ],
50 // Register our schema callback.
51 'schema' => [ $this, 'get_item_schema' ],
52 ]
53 );
54 }
55
56 /**
57 * Get our sample schema for a post.
58 *
59 * @return array The sample schema for a post
60 */
61 public function get_item_schema() {
62 if ( $this->schema ) {
63 // Since WordPress 5.3, the schema can be cached in the $schema property.
64 return $this->schema;
65 }
66
67 $this->schema = [
68 // This tells the spec of JSON Schema we are using which is draft 4.
69 '$schema' => 'http://json-schema.org/draft-04/schema#',
70 // The title property marks the identity of the resource.
71 'title' => $this->endpoint,
72 'type' => 'object',
73 // In JSON Schema you can specify object properties in the properties attribute.
74 'properties' => [
75 'id' => [
76 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
77 'type' => 'string',
78 'context' => [ 'view', 'edit', 'embed' ],
79 'readonly' => true,
80 ],
81 ],
82 ];
83
84 return $this->schema;
85 }
86
87 /**
88 * Get the collection params.
89 *
90 * @return array
91 */
92 public function get_collection_params() {
93 return [
94 'model' => [
95 'description' => __( 'The model to get integration providers for.', 'surecart' ),
96 'type' => 'string',
97 ],
98 'page' => [
99 'description' => esc_html__( 'The page of items you want returned.', 'surecart' ),
100 'type' => 'integer',
101 ],
102 'per_page' => [
103 'description' => esc_html__( 'A limit on the number of items to be returned, between 1 and 100.', 'surecart' ),
104 'type' => 'integer',
105 'minimum' => 1,
106 'maximum' => 100,
107 ],
108 ];
109 }
110
111 /**
112 * List permissions.
113 *
114 * @param \WP_REST_Request $request Full details about the request.
115 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
116 */
117 public function get_items_permission_check( $request ) {
118 return current_user_can( 'read_sc_products' );
119 }
120
121 /**
122 * List permissions.
123 *
124 * @param \WP_REST_Request $request Full details about the request.
125 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
126 */
127 public function get_item_permission_check( $request ) {
128 return current_user_can( 'read_sc_products' );
129 }
130 }
131