AbandonedCheckoutProtocolRestServiceProvider.php
3 years ago
AbandonedCheckoutRestServiceProvider.php
3 years ago
AccountRestServiceProvider.php
3 years ago
ActivationRestServiceProvider.php
3 years ago
BalanceTransactionRestServiceProvider.php
3 years ago
BlockPatternsRestServiceProvider.php
3 years ago
BrandRestServiceProvider.php
3 years ago
BumpRestServiceProvider.php
3 years ago
CancellationActRestServiceProvider.php
3 years ago
CancellationReasonRestServiceProvider.php
3 years ago
ChargesRestServiceProvider.php
3 years ago
CheckEmailRestServiceProvider.php
3 years ago
CheckoutRestServiceProvider.php
3 years ago
CouponRestServiceProvider.php
3 years ago
CustomerLinksRestServiceProvider.php
3 years ago
CustomerNotificationProtocolRestServiceProvider.php
3 years ago
CustomerRestServiceProvider.php
3 years ago
DownloadRestServiceProvider.php
3 years ago
DraftCheckoutRestServiceProvider.php
2 years ago
FulfillmentRestServiceProvider.php
3 years ago
IncomingWebhooksRestServiceProvider.php
2 years ago
IntegrationProvidersRestServiceProvider.php
3 years ago
IntegrationsRestServiceProvider.php
3 years ago
InvoicesRestServiceProvider.php
3 years ago
LicenseRestServiceProvider.php
3 years ago
LineItemsRestServiceProvider.php
3 years ago
LoginRestServiceProvider.php
3 years ago
ManualPaymentMethodsRestServiceProvider.php
3 years ago
MediaRestServiceProvider.php
3 years ago
OrderProtocolRestServiceProvider.php
3 years ago
OrderRestServiceProvider.php
3 years ago
PaymentIntentsRestServiceProvider.php
3 years ago
PaymentMethodsRestServiceProvider.php
2 years ago
PeriodRestServiceProvider.php
3 years ago
PortalProtocolRestServiceProvider.php
3 years ago
PriceRestServiceProvider.php
3 years ago
ProcessorRestServiceProvider.php
3 years ago
ProductGroupsRestServiceProvider.php
3 years ago
ProductMediaRestServiceProvider.php
3 years ago
ProductsRestServiceProvider.php
3 years ago
PromotionRestServiceProvider.php
3 years ago
ProvisionalAccountRestServiceProvider.php
3 years ago
PurchasesRestServiceProvider.php
3 years ago
RefundsRestServiceProvider.php
3 years ago
RegisteredWebhookRestServiceProvider.php
2 years ago
RestServiceInterface.php
3 years ago
RestServiceProvider.php
3 years ago
SettingsRestServiceProvider.php
3 years ago
ShippingMethodRestServiceProvider.php
3 years ago
ShippingProfileRestServiceProvider.php
3 years ago
ShippingProtocolRestServiceProvider.php
3 years ago
ShippingRateRestServiceProvider.php
3 years ago
ShippingZoneRestServiceProvider.php
3 years ago
SiteHealthRestServiceProvider.php
2 years ago
StatisticRestServiceProvider.php
3 years ago
SubscriptionProtocolRestServiceProvider.php
3 years ago
SubscriptionRestServiceProvider.php
3 years ago
TaxProtocolRestServiceProvider.php
3 years ago
TaxRegistrationRestServiceProvider.php
3 years ago
TaxZoneRestServiceProvider.php
3 years ago
UploadsRestServiceProvider.php
3 years ago
VerificationCodeRestServiceProvider.php
3 years ago
WebhooksRestServiceProvider.php
3 years ago
PriceRestServiceProvider.php
162 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Rest; |
| 4 | |
| 5 | use SureCart\Rest\RestServiceInterface; |
| 6 | use SureCart\Controllers\Rest\PricesController; |
| 7 | |
| 8 | /** |
| 9 | * Service provider for Price Rest Requests |
| 10 | */ |
| 11 | class PriceRestServiceProvider extends RestServiceProvider implements RestServiceInterface { |
| 12 | |
| 13 | /** |
| 14 | * Endpoint. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | protected $endpoint = 'prices'; |
| 19 | |
| 20 | /** |
| 21 | * Rest Controller |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $controller = PricesController::class; |
| 26 | |
| 27 | /** |
| 28 | * Get our sample schema for a post. |
| 29 | * |
| 30 | * @return array The sample schema for a post |
| 31 | */ |
| 32 | public function get_item_schema() { |
| 33 | if ( $this->schema ) { |
| 34 | // Since WordPress 5.3, the schema can be cached in the $schema property. |
| 35 | return $this->schema; |
| 36 | } |
| 37 | |
| 38 | $this->schema = [ |
| 39 | // This tells the spec of JSON Schema we are using which is draft 4. |
| 40 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 41 | // The title property marks the identity of the resource. |
| 42 | 'title' => $this->endpoint, |
| 43 | 'type' => 'object', |
| 44 | // In JSON Schema you can specify object properties in the properties attribute. |
| 45 | 'properties' => [ |
| 46 | 'id' => [ |
| 47 | 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ), |
| 48 | 'type' => 'string', |
| 49 | 'context' => array( 'view', 'edit', 'embed' ), |
| 50 | 'readonly' => true, |
| 51 | ], |
| 52 | 'content' => array( |
| 53 | 'description' => esc_html__( 'The content for the object.', 'surecart' ), |
| 54 | 'type' => 'string', |
| 55 | ), |
| 56 | ], |
| 57 | ]; |
| 58 | |
| 59 | return $this->schema; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the collection params. |
| 64 | * |
| 65 | * @return array |
| 66 | */ |
| 67 | public function get_collection_params() { |
| 68 | return [ |
| 69 | 'archived' => [ |
| 70 | 'description' => esc_html__( 'Whether to get archived products or not.', 'surecart' ), |
| 71 | 'type' => 'boolean', |
| 72 | ], |
| 73 | 'ad_hoc' => [ |
| 74 | 'description' => esc_html__( 'Only return prices that allow ad hoc amounts or not.', 'surecart' ), |
| 75 | 'type' => 'boolean', |
| 76 | ], |
| 77 | 'query' => [ |
| 78 | 'description' => __( 'The query to be used for full text search of this collection.', 'surecart' ), |
| 79 | 'type' => 'string', |
| 80 | ], |
| 81 | 'ids' => [ |
| 82 | 'description' => __( 'Ensure result set excludes specific IDs.', 'surecart' ), |
| 83 | 'type' => 'array', |
| 84 | 'items' => [ |
| 85 | 'type' => 'string', |
| 86 | ], |
| 87 | 'default' => [], |
| 88 | ], |
| 89 | 'product_ids' => [ |
| 90 | 'description' => __( 'Only return objects that belong to the given products.', 'surecart' ), |
| 91 | 'type' => 'array', |
| 92 | 'items' => [ |
| 93 | 'type' => 'string', |
| 94 | ], |
| 95 | 'default' => [], |
| 96 | ], |
| 97 | 'page' => [ |
| 98 | 'description' => esc_html__( 'The page of items you want returned.', 'surecart' ), |
| 99 | 'type' => 'integer', |
| 100 | ], |
| 101 | 'per_page' => [ |
| 102 | 'description' => esc_html__( 'A limit on the number of items to be returned, between 1 and 100.', 'surecart' ), |
| 103 | 'type' => 'integer', |
| 104 | ], |
| 105 | ]; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Anyone can get a specific price. |
| 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 get_item_permissions_check( $request ) { |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Who can list prices |
| 120 | * |
| 121 | * @param \WP_REST_Request $request Full details about the request. |
| 122 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 123 | */ |
| 124 | public function get_items_permissions_check( $request ) { |
| 125 | if ( $request['archived'] ) { |
| 126 | return current_user_can( 'edit_sc_prices' ); |
| 127 | } |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Create model. |
| 134 | * |
| 135 | * @param \WP_REST_Request $request Full details about the request. |
| 136 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 137 | */ |
| 138 | public function create_item_permissions_check( $request ) { |
| 139 | return current_user_can( 'publish_sc_prices' ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Update 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 update_item_permissions_check( $request ) { |
| 149 | return current_user_can( 'edit_sc_prices' ); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Delete 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 delete_item_permissions_check( $request ) { |
| 159 | return current_user_can( 'delete_sc_prices' ); |
| 160 | } |
| 161 | } |
| 162 |