PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.25.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.25.2
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 / PriceRestServiceProvider.php
PriceRestServiceProvider.php
162 lines 4.4 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\Rest\RestServiceInterface;
6 use SureCart\Controllers\Rest\PricesController;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class PriceRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12
13 /**
14 * Endpoint.
15 *
16 * @var string
17 */
18 protected $endpoint = 'prices';
19
20 /**
21 * Rest Controller
22 *
23 * @var string
24 */
25 protected $controller = PricesController::class;
26
27 /**
28 * Get our sample schema for a post.
29 *
30 * @return array The sample schema for a post
31 */
32 public function get_item_schema() {
33 if ( $this->schema ) {
34 // Since WordPress 5.3, the schema can be cached in the $schema property.
35 return $this->schema;
36 }
37
38 $this->schema = [
39 // This tells the spec of JSON Schema we are using which is draft 4.
40 '$schema' => 'http://json-schema.org/draft-04/schema#',
41 // The title property marks the identity of the resource.
42 'title' => $this->endpoint,
43 'type' => 'object',
44 // In JSON Schema you can specify object properties in the properties attribute.
45 'properties' => [
46 'id' => [
47 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
48 'type' => 'string',
49 'context' => array( 'view', 'edit', 'embed' ),
50 'readonly' => true,
51 ],
52 'content' => array(
53 'description' => esc_html__( 'The content for the object.', 'surecart' ),
54 'type' => 'string',
55 ),
56 ],
57 ];
58
59 return $this->schema;
60 }
61
62 /**
63 * Get the collection params.
64 *
65 * @return array
66 */
67 public function get_collection_params() {
68 return [
69 'archived' => [
70 'description' => esc_html__( 'Whether to get archived products or not.', 'surecart' ),
71 'type' => 'boolean',
72 ],
73 'ad_hoc' => [
74 'description' => esc_html__( 'Only return prices that allow ad hoc amounts or not.', 'surecart' ),
75 'type' => 'boolean',
76 ],
77 'query' => [
78 'description' => __( 'The query to be used for full text search of this collection.', 'surecart' ),
79 'type' => 'string',
80 ],
81 'ids' => [
82 'description' => __( 'Ensure result set excludes specific IDs.', 'surecart' ),
83 'type' => 'array',
84 'items' => [
85 'type' => 'string',
86 ],
87 'default' => [],
88 ],
89 'product_ids' => [
90 'description' => __( 'Only return objects that belong to the given products.', 'surecart' ),
91 'type' => 'array',
92 'items' => [
93 'type' => 'string',
94 ],
95 'default' => [],
96 ],
97 'page' => [
98 'description' => esc_html__( 'The page of items you want returned.', 'surecart' ),
99 'type' => 'integer',
100 ],
101 'per_page' => [
102 'description' => esc_html__( 'A limit on the number of items to be returned, between 1 and 100.', 'surecart' ),
103 'type' => 'integer',
104 ],
105 ];
106 }
107
108 /**
109 * Anyone can get a specific price.
110 *
111 * @param \WP_REST_Request $request Full details about the request.
112 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
113 */
114 public function get_item_permissions_check( $request ) {
115 return true;
116 }
117
118 /**
119 * Who can list prices
120 *
121 * @param \WP_REST_Request $request Full details about the request.
122 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
123 */
124 public function get_items_permissions_check( $request ) {
125 if ( $request['archived'] ) {
126 return current_user_can( 'edit_sc_prices' );
127 }
128
129 return true;
130 }
131
132 /**
133 * Create model.
134 *
135 * @param \WP_REST_Request $request Full details about the request.
136 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
137 */
138 public function create_item_permissions_check( $request ) {
139 return current_user_can( 'publish_sc_prices' );
140 }
141
142 /**
143 * Update model.
144 *
145 * @param \WP_REST_Request $request Full details about the request.
146 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
147 */
148 public function update_item_permissions_check( $request ) {
149 return current_user_can( 'edit_sc_prices' );
150 }
151
152 /**
153 * Delete model.
154 *
155 * @param \WP_REST_Request $request Full details about the request.
156 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
157 */
158 public function delete_item_permissions_check( $request ) {
159 return current_user_can( 'delete_sc_prices' );
160 }
161 }
162