PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.1.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.1.0
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 / DraftCheckoutRestServiceProvider.php
DraftCheckoutRestServiceProvider.php
175 lines 4.8 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\DraftCheckoutsController;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class DraftCheckoutRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12 /**
13 * Endpoint.
14 *
15 * @var string
16 */
17 protected $endpoint = 'draft-checkouts';
18
19 /**
20 * Rest Controller
21 *
22 * @var string
23 */
24 protected $controller = DraftCheckoutsController::class;
25
26 /**
27 * Methods allowed for the model.
28 *
29 * @var array
30 */
31 protected $methods = [ 'index', 'create', 'find', 'edit' ];
32
33 /**
34 * Register Additional REST 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>\S+)/finalize/',
42 [
43 [
44 'methods' => \WP_REST_Server::EDITABLE,
45 'callback' => $this->callback( $this->controller, 'finalize' ),
46 'permission_callback' => [ $this, 'update_item_permissions_check' ],
47 ],
48 // Register our schema callback.
49 'schema' => [ $this, 'get_item_schema' ],
50 ]
51 );
52
53 register_rest_route(
54 "$this->name/v$this->version",
55 $this->endpoint . '/(?P<id>\S+)/manually_pay/',
56 [
57 [
58 'methods' => \WP_REST_Server::EDITABLE,
59 'callback' => $this->callback( $this->controller, 'manuallyPay' ),
60 'permission_callback' => [ $this, 'update_item_permissions_check' ],
61 ],
62 // Register our schema callback.
63 'schema' => [ $this, 'get_item_schema' ],
64 ]
65 );
66 }
67
68 /**
69 * Get our sample schema for a post.
70 *
71 * @return array The sample schema for a post
72 */
73 public function get_item_schema() {
74 if ( $this->schema ) {
75 // Since WordPress 5.3, the schema can be cached in the $schema property.
76 return $this->schema;
77 }
78
79 $this->schema = [
80 // This tells the spec of JSON Schema we are using which is draft 4.
81 '$schema' => 'http://json-schema.org/draft-04/schema#',
82 // The title property marks the identity of the resource.
83 'title' => $this->endpoint,
84 'type' => 'object',
85 // In JSON Schema you can specify object properties in the properties attribute.
86 'properties' => [
87 'id' => [
88 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
89 'type' => 'string',
90 'context' => [ 'view', 'edit', 'embed' ],
91 'readonly' => true,
92 ],
93 'currency' => [
94 'description' => esc_html__( 'The currency for the session.', 'surecart' ),
95 'type' => 'string',
96 ],
97 'metadata' => [
98 'description' => esc_html__( 'Metadata for the order.', 'surecart' ),
99 'type' => 'object',
100 ],
101 'customer_id' => [
102 'description' => esc_html__( 'The customer id for the order.', 'surecart' ),
103 'type' => 'string',
104 'context' => [ 'edit' ],
105 ],
106 'customer' => [
107 'description' => esc_html__( 'The customer for the session.', 'surecart' ),
108 'type' => 'object',
109 'context' => [ 'edit' ],
110 ],
111 'line_items' => [
112 'description' => esc_html__( 'The line items for the session.', 'surecart' ),
113 'type' => 'object',
114 ],
115 'discount' => [
116 'description' => esc_html__( 'The discount for the session.', 'surecart' ),
117 'type' => 'object',
118 ],
119 ],
120 ];
121
122 return $this->schema;
123 }
124
125 /**
126 * Read checkout.
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( 'read_sc_checkouts' );
133 }
134
135 /**
136 * List checkouts.
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 get_items_permissions_check( $request ) {
142 return current_user_can( 'read_sc_checkouts' );
143 }
144
145 /**
146 * Create checkout.
147 *
148 * @param \WP_REST_Request $request Full details about the request.
149 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
150 */
151 public function create_item_permissions_check( $request ) {
152 return $this->update_item_permissions_check( $request );
153 }
154
155 /**
156 * Update checkout.
157 *
158 * @param \WP_REST_Request $request Full details about the request.
159 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
160 */
161 public function update_item_permissions_check( $request ) {
162 return current_user_can( 'edit_sc_checkouts' );
163 }
164
165 /**
166 * Nobody can delete.
167 *
168 * @param \WP_REST_Request $request Full details about the request.
169 * @return false
170 */
171 public function delete_item_permissions_check( $request ) {
172 return $this->update_item_permissions_check( $request );
173 }
174 }
175