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 / BumpRestServiceProvider.php
BumpRestServiceProvider.php
183 lines 5.7 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\BumpsController;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class BumpRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12 /**
13 * Endpoint.
14 *
15 * @var string
16 */
17 protected $endpoint = 'bumps';
18
19 /**
20 * Rest Controller
21 *
22 * @var string
23 */
24 protected $controller = BumpsController::class;
25
26 /**
27 * Methods allowed for the model.
28 *
29 * @var array
30 */
31 protected $methods = [ 'index', 'create', 'find', 'edit', 'delete' ];
32
33
34 /**
35 * Get our sample schema for a post.
36 *
37 * @return array The sample schema for a post
38 */
39 public function get_item_schema() {
40 if ( $this->schema ) {
41 // Since WordPress 5.3, the schema can be cached in the $schema property.
42 return $this->schema;
43 }
44
45 $this->schema = [
46 // This tells the spec of JSON Schema we are using which is draft 4.
47 '$schema' => 'http://json-schema.org/draft-04/schema#',
48 // The title property marks the identity of the resource.
49 'title' => $this->endpoint,
50 'type' => 'object',
51 // In JSON Schema you can specify object properties in the properties attribute.
52 'properties' => [
53 'id' => [
54 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
55 'type' => 'string',
56 'context' => [ 'view', 'edit', 'embed' ],
57 'readonly' => true,
58 ],
59 'object' => [
60 'description' => esc_html__( 'Type of object (bump)', 'surecart' ),
61 'type' => 'string',
62 'context' => [ 'view', 'edit' ],
63 'readonly' => true,
64 ],
65 'created_at' => [
66 'description' => esc_html__( 'Created at timestamp', 'surecart' ),
67 'type' => 'integer',
68 'context' => [ 'edit' ],
69 'readonly' => true,
70 ],
71 'updated_at' => [
72 'description' => esc_html__( 'Created at timestamp', 'surecart' ),
73 'type' => 'integer',
74 'context' => [ 'edit' ],
75 'readonly' => true,
76 ],
77 'amount_off' => [
78 'description' => esc_html__( 'Amount (in the currency of the price) that will be taken off line items associated with this bump.', 'surecart' ),
79 'type' => 'integer',
80 'context' => [ 'view', 'edit', 'embed' ],
81 ],
82 'enabled' => [
83 'description' => esc_html__( 'Whether or not this bump is currently enabled and being shown to customers.', 'surecart' ),
84 'type' => 'boolean',
85 'context' => [ 'view', 'edit', 'embed' ],
86 ],
87 'filters' => [
88 'description' => esc_html__( 'The conditions that will filter this bump to be recommeneded. Accepted keys are price_ids, product_ids, and product_group_ids with array values.', 'surecart' ),
89 'type' => 'string',
90 'context' => [ 'view', 'edit', 'embed' ],
91 ],
92 'name' => [
93 'description' => esc_html__( 'This is shown to the customer on invoices and line items.', 'surecart' ),
94 'type' => 'string',
95 'context' => [ 'view', 'edit', 'embed' ],
96 ],
97 'percent_off' => [
98 'description' => esc_html__( 'Percent that will be taken off line items associated with this bump.', 'surecart' ),
99 'type' => 'integer',
100 'context' => [ 'view', 'edit', 'embed' ],
101 ],
102 'priority' => [
103 'description' => esc_html__( 'The priority of this bump in relation to other bumps. Must be in the range of 1 - 5.', 'surecart' ),
104 'type' => 'integer',
105 'context' => [ 'view', 'edit', 'embed' ],
106 ],
107 'price' => [
108 'description' => esc_html__( 'The UUID of the price.', 'surecart' ),
109 'type' => 'string',
110 'context' => [ 'view', 'edit', 'embed' ],
111 ],
112 'metadata' => [
113 'description' => esc_html__( 'Set of key-value pairs for custom data.', 'surecart' ),
114 'type' => 'object',
115 'context' => [ 'view', 'edit', 'embed' ],
116 'properties' => [
117 'description' => [
118 'description' => esc_html__( 'Offer description.', 'surecart' ),
119 'type' => 'string',
120 'sanitize_callback' => 'wp_kses_post',
121 ],
122 ],
123 ],
124 ],
125 ];
126
127 return $this->schema;
128 }
129
130 /**
131 * Anyone can get a specific price.
132 *
133 * @param \WP_REST_Request $request Full details about the request.
134 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
135 */
136 public function get_item_permissions_check( $request ) {
137 return true;
138 }
139
140 /**
141 * Who can list prices
142 *
143 * @param \WP_REST_Request $request Full details about the request.
144 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
145 */
146 public function get_items_permissions_check( $request ) {
147 if ( ! $request['enabled'] ) {
148 return current_user_can( 'edit_sc_prices' );
149 }
150 return true;
151 }
152
153 /**
154 * Create model.
155 *
156 * @param \WP_REST_Request $request Full details about the request.
157 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
158 */
159 public function create_item_permissions_check( $request ) {
160 return current_user_can( 'publish_sc_prices' );
161 }
162
163 /**
164 * Update model.
165 *
166 * @param \WP_REST_Request $request Full details about the request.
167 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
168 */
169 public function update_item_permissions_check( $request ) {
170 return current_user_can( 'edit_sc_prices' );
171 }
172
173 /**
174 * Delete model.
175 *
176 * @param \WP_REST_Request $request Full details about the request.
177 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
178 */
179 public function delete_item_permissions_check( $request ) {
180 return current_user_can( 'delete_sc_prices' );
181 }
182 }
183