PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.6
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.6
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 / PaymentIntentsRestServiceProvider.php
PaymentIntentsRestServiceProvider.php
139 lines 3.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\Controllers\Rest\PaymentIntentsController;
6 use SureCart\Rest\RestServiceInterface;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class PaymentIntentsRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12
13 /**
14 * Endpoint.
15 *
16 * @var string
17 */
18 protected $endpoint = 'payment_intents';
19
20 /**
21 * Rest Controller
22 *
23 * @var string
24 */
25 protected $controller = PaymentIntentsController::class;
26
27 /**
28 * Methods allowed for the model.
29 *
30 * @var array
31 */
32 protected $methods = [ 'create', 'find', 'edit' ];
33
34 /**
35 * Register REST Routes
36 *
37 * @return void
38 */
39 public function registerRoutes() {
40 register_rest_route(
41 "$this->name/v$this->version",
42 $this->endpoint . '/(?P<id>\S+)/capture/',
43 [
44 [
45 'methods' => \WP_REST_Server::EDITABLE,
46 'callback' => $this->callback( $this->controller, 'capture' ),
47 'permission_callback' => [ $this, 'capture_item_permissions_check' ],
48 ],
49 // Register our schema callback.
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' => [ 'view', 'edit', 'embed' ],
79 'readonly' => true,
80 ],
81 ],
82 ];
83
84 return $this->schema;
85 }
86
87 /**
88 * Read permissions.
89 *
90 * @param \WP_REST_Request $request Full details about the request.
91 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
92 */
93 public function get_item_permissions_check( $request ) {
94 return true;
95 }
96
97 /**
98 * List permissions.
99 * Nobody can list these.
100 *
101 * @param \WP_REST_Request $request Full details about the request.
102 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
103 */
104 public function get_items_permissions_check( $request ) {
105 return false;
106 }
107
108 /**
109 * Create permissions.
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 create_item_permissions_check( $request ) {
115 return true;
116 }
117
118
119 /**
120 * Capture permissions.
121 *
122 * @param \WP_REST_Request $request Full details about the request.
123 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
124 */
125 public function capture_item_permissions_check( $request ) {
126 return true;
127 }
128
129 /**
130 * Update permissions.
131 *
132 * @param \WP_REST_Request $request Full details about the request.
133 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
134 */
135 public function update_item_permissions_check( $request ) {
136 return true;
137 }
138 }
139