PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.1.5
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.1.5
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 / AccountRestServiceProvider.php
AccountRestServiceProvider.php
145 lines 4.0 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\AccountController;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class AccountRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12 /**
13 * Endpoint.
14 *
15 * @var string
16 */
17 protected $endpoint = 'account';
18
19 /**
20 * Rest Controller
21 *
22 * @var string
23 */
24 protected $controller = AccountController::class;
25
26 /**
27 * Methods allowed for the model.
28 *
29 * @var array
30 */
31 protected $methods = [];
32
33 public function registerRoutes() {
34 register_rest_route(
35 "$this->name/v$this->version",
36 "$this->endpoint",
37 array_filter(
38 [
39 [
40 'methods' => \WP_REST_Server::READABLE,
41 'callback' => $this->callback( $this->controller, 'find' ),
42 'permission_callback' => [ $this, 'get_item_permissions_check' ],
43 'args' => $this->get_collection_params(),
44 ],
45 [
46 'methods' => \WP_REST_Server::EDITABLE,
47 'callback' => $this->callback( $this->controller, 'edit' ),
48 'permission_callback' => [ $this, 'update_item_permissions_check' ],
49 ],
50 'schema' => [ $this, 'get_item_schema' ],
51 ]
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' => [ 'edit' ],
79 'readonly' => true,
80 ],
81 'object' => [
82 'description' => esc_html__( 'Type of object (Account)', 'surecart' ),
83 'type' => 'string',
84 'context' => [ 'view', 'edit' ],
85 'readonly' => true,
86 ],
87 'created_at' => [
88 'description' => esc_html__( 'Created at timestamp', 'surecart' ),
89 'type' => 'integer',
90 'context' => [ 'edit' ],
91 'readonly' => true,
92 ],
93 'updated_at' => [
94 'description' => esc_html__( 'Created at timestamp', 'surecart' ),
95 'type' => 'integer',
96 'context' => [ 'edit' ],
97 'readonly' => true,
98 ],
99 'name' => [
100 'description' => esc_html__( 'The name of the account.', 'surecart' ),
101 'type' => 'string',
102 'context' => [ 'view', 'edit' ],
103 ],
104 'currency' => [
105 'description' => esc_html__( 'The default currency for the account.', 'surecart' ),
106 'type' => 'string',
107 'context' => [ 'view', 'edit' ],
108 ],
109 'owner' => [
110 'description' => esc_html__( 'Owner data.', 'surecart' ),
111 'type' => 'object',
112 'context' => [ 'edit' ],
113 ],
114 'processors' => [
115 'description' => esc_html__( 'Connected processors', 'surecart' ),
116 'type' => 'object',
117 'context' => [ 'edit' ],
118 ],
119 ],
120 ];
121
122 return $this->schema;
123 }
124
125 /**
126 * Get items
127 *
128 * @param \WP_REST_Request $request Full details about the request.
129 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
130 */
131 public function get_item_permissions_check( $request ) {
132 return current_user_can( 'manage_options' );
133 }
134
135 /**
136 * Update item
137 *
138 * @param \WP_REST_Request $request Full details about the request.
139 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
140 */
141 public function update_item_permissions_check( $request ) {
142 return current_user_can( 'manage_options' );
143 }
144 }
145