PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.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 / UpsellRestServiceProvider.php
UpsellRestServiceProvider.php
172 lines 5.5 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\UpsellsController;
7
8 /**
9 * Service provider for Price Rest Requests
10 */
11 class UpsellRestServiceProvider extends RestServiceProvider implements RestServiceInterface {
12 /**
13 * Endpoint.
14 *
15 * @var string
16 */
17 protected $endpoint = 'upsells';
18
19 /**
20 * Rest Controller
21 *
22 * @var string
23 */
24 protected $controller = UpsellsController::class;
25
26 /**
27 * Whether the rest service provider converts currency.
28 *
29 * @var boolean
30 */
31 protected $converts_currency = true;
32
33 /**
34 * Methods allowed for the model.
35 *
36 * @var array
37 */
38 protected $methods = [ 'index', 'create', 'find', 'edit', 'delete' ];
39
40 /**
41 * Get our sample schema for a post.
42 *
43 * @return array The sample schema for a post
44 */
45 public function get_item_schema() {
46 if ( $this->schema ) {
47 // Since WordPress 5.3, the schema can be cached in the $schema property.
48 return $this->schema;
49 }
50
51 $this->schema = [
52 // This tells the spec of JSON Schema we are using which is draft 4.
53 '$schema' => 'http://json-schema.org/draft-04/schema#',
54 // The title property marks the identity of the resource.
55 'title' => $this->endpoint,
56 'type' => 'object',
57 // In JSON Schema you can specify object properties in the properties attribute.
58 'properties' => [
59 'id' => [
60 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ),
61 'type' => 'string',
62 'context' => [ 'view', 'edit', 'embed' ],
63 'readonly' => true,
64 ],
65 'object' => [
66 'description' => esc_html__( 'Type of object (upsell)', 'surecart' ),
67 'type' => 'string',
68 'context' => [ 'view', 'edit', 'embed' ],
69 'readonly' => true,
70 ],
71 'created_at' => [
72 'description' => esc_html__( 'Created at timestamp', 'surecart' ),
73 'type' => 'integer',
74 'context' => [ 'view', 'edit', 'embed' ],
75 'readonly' => true,
76 ],
77 'updated_at' => [
78 'description' => esc_html__( 'Created at timestamp', 'surecart' ),
79 'type' => 'integer',
80 'context' => [ 'view', 'edit', 'embed' ],
81 'readonly' => true,
82 ],
83 'amount_off' => [
84 'description' => esc_html__( 'Amount (in the currency of the price) that will be taken off line items associated with this upsell.', 'surecart' ),
85 'type' => [ 'integer', 'null' ],
86 'context' => [ 'view', 'edit', 'embed' ],
87 ],
88 'duplicate_purchase_behavior' => [
89 'description' => esc_html__( 'How to handle duplicate purchases of the product – can be one of allow, block_within_checkout, or block.', 'surecart' ),
90 'type' => 'string',
91 'context' => [ 'view', 'edit', 'embed' ],
92 ],
93 'fee_description' => [
94 'description' => esc_html__( 'The description for this upsell which will be visible to customers.', 'surecart' ),
95 'type' => 'string',
96 'context' => [ 'view', 'edit', 'embed' ],
97 ],
98 'percent_off' => [
99 'description' => esc_html__( 'Percent that will be taken off line items associated with this upsell.', 'surecart' ),
100 'type' => [ 'integer', 'null' ],
101 'context' => [ 'view', 'edit', 'embed' ],
102 ],
103 'step' => [
104 'description' => esc_html__( 'Where this upsell falls in position within the upsell funnel – can be one of initial, accepted, or declined.', 'surecart' ),
105 'type' => 'string',
106 'context' => [ 'view', 'edit', 'embed' ],
107 ],
108 'price' => [
109 'description' => esc_html__( 'The UUID of the price.', 'surecart' ),
110 'type' => [ 'string', 'object' ],
111 'context' => [ 'view', 'edit', 'embed' ],
112 ],
113 ],
114 ];
115
116 return $this->schema;
117 }
118
119 /**
120 * Anyone can get a specific price.
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 get_item_permissions_check( $request ) {
126 return true;
127 }
128
129 /**
130 * Who can list prices
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 get_items_permissions_check( $request ) {
136 if ( empty( $request['upsell_funnel_ids'] ) || count( $request['upsell_funnel_ids'] ) > 1 ) {
137 return current_user_can( 'edit_sc_prices' );
138 }
139 return true;
140 }
141
142 /**
143 * Create model.
144 *
145 * @param \WP_REST_Request $request Full details about the request.
146 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
147 */
148 public function create_item_permissions_check( $request ) {
149 return current_user_can( 'publish_sc_prices' );
150 }
151
152 /**
153 * Update model.
154 *
155 * @param \WP_REST_Request $request Full details about the request.
156 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
157 */
158 public function update_item_permissions_check( $request ) {
159 return current_user_can( 'edit_sc_prices' );
160 }
161
162 /**
163 * Delete model.
164 *
165 * @param \WP_REST_Request $request Full details about the request.
166 * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise.
167 */
168 public function delete_item_permissions_check( $request ) {
169 return current_user_can( 'delete_sc_prices' );
170 }
171 }
172