PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.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 / IncomingWebhooksRestServiceProvider.php
IncomingWebhooksRestServiceProvider.php
193 lines 5.2 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\IncomingWebhooksController;
6 use SureCart\Rest\RestServiceInterface;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class IncomingWebhooksRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12 /**
13 * Endpoint.
14 *
15 * @var string
16 */
17 protected $endpoint = 'incoming_webhooks';
18
19 /**
20 * Rest Controller
21 *
22 * @var string
23 */
24 protected $controller = IncomingWebhooksController::class;
25
26 /**
27 * Methods allowed for the model.
28 *
29 * @var array
30 */
31 protected $methods = [ 'index', 'create' ];
32
33 /**
34 * Register routes.
35 *
36 * @return void
37 */
38 public function registerRoutes() {
39 register_rest_route(
40 "$this->name/v$this->version",
41 $this->endpoint . '/(?P<id>\d+)',
42 [
43 [
44 'methods' => \WP_REST_Server::READABLE,
45 'callback' => $this->callback( $this->controller, 'find' ),
46 'permission_callback' => [ $this, 'get_item_permissions_check' ],
47 ],
48 [
49 'methods' => \WP_REST_Server::EDITABLE,
50 'callback' => $this->callback( $this->controller, 'edit' ),
51 'permission_callback' => [ $this, 'update_item_permissions_check' ],
52 ],
53 [
54 'methods' => \WP_REST_Server::DELETABLE,
55 'callback' => $this->callback( $this->controller, 'delete' ),
56 'permission_callback' => [ $this, 'delete_item_permissions_check' ],
57 ],
58 ]
59 );
60
61 // retry.
62 register_rest_route(
63 "$this->name/v$this->version",
64 $this->endpoint . '/(?P<id>\d+)/retry/',
65 [
66 [
67 'methods' => \WP_REST_Server::EDITABLE,
68 'callback' => $this->callback( $this->controller, 'retry' ),
69 'permission_callback' => [ $this, 'update_item_permissions_check' ],
70 ],
71 ]
72 );
73 }
74
75 /**
76 * Get our sample schema for a post.
77 *
78 * @return array The sample schema for a post
79 */
80 public function get_item_schema() {
81 if ( $this->schema ) {
82 // Since WordPress 5.3, the schema can be cached in the $schema property.
83 return $this->schema;
84 }
85
86 $this->schema = [
87 // This tells the spec of JSON Schema we are using which is draft 4.
88 '$schema' => 'http://json-schema.org/draft-04/schema#',
89 // The title property marks the identity of the resource.
90 'title' => $this->endpoint,
91 'type' => 'object',
92 // In JSON Schema you can specify object properties in the properties attribute.
93 'properties' => [
94 'id' => [
95 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
96 'type' => 'string',
97 'context' => [ 'view', 'edit', 'embed' ],
98 'readonly' => true,
99 ],
100 'model_name' => [
101 'description' => esc_html__( 'The SureCart model name.', 'surecart' ),
102 'type' => 'string',
103 'context' => [ 'view', 'edit', 'embed' ],
104 'required' => true,
105 ],
106 ],
107 ];
108
109 return $this->schema;
110 }
111
112 /**
113 * Get the collection params.
114 *
115 * @return array
116 */
117 public function get_collection_params() {
118 return [
119 'webhook_ids' => [
120 'description' => esc_html__( 'The SureCart model id.', 'surecart' ),
121 'type' => 'array',
122 'items' => [
123 'type' => 'string',
124 ],
125 'default' => [],
126 ],
127 'processed' => [
128 'type' => 'boolean',
129 ],
130 'page' => [
131 'description' => esc_html__( 'The page of items you want returned.', 'surecart' ),
132 'type' => 'integer',
133 ],
134 'per_page' => [
135 'description' => esc_html__( 'A limit on the number of items to be returned, between 1 and 100.', 'surecart' ),
136 'type' => 'integer',
137 'minimum' => 1,
138 'maximum' => 100,
139 ],
140 ];
141 }
142
143 /**
144 * Read permissions.
145 *
146 * @param \WP_REST_Request $request Full details about the request.
147 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
148 */
149 public function get_item_permissions_check( $request ) {
150 return current_user_can( 'manage_sc_shop_settings' );
151 }
152
153 /**
154 * List permissions.
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 get_items_permissions_check( $request ) {
160 return current_user_can( 'manage_sc_shop_settings' );
161 }
162
163 /**
164 * Create
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 create_item_permissions_check( $request ) {
170 return current_user_can( 'manage_sc_shop_settings' );
171 }
172
173 /**
174 * Update
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 update_item_permissions_check( $request ) {
180 return current_user_can( 'manage_sc_shop_settings' );
181 }
182
183 /**
184 * Delete.
185 *
186 * @param \WP_REST_Request $request Full details about the request.
187 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
188 */
189 public function delete_item_permissions_check( $request ) {
190 return current_user_can( 'manage_sc_shop_settings' );
191 }
192 }
193