AbandonedCheckoutProtocolRestServiceProvider.php
3 years ago
AbandonedCheckoutRestServiceProvider.php
2 years ago
AccountRestServiceProvider.php
4 years ago
ActivationRestServiceProvider.php
1 year ago
AffiliationProductsRestServiceProvider.php
2 years ago
AffiliationProtocolRestServiceProvider.php
2 years ago
AffiliationRequestsRestServiceProvider.php
2 years ago
AffiliationsRestServiceProvider.php
11 months ago
AutoFeeProtocolRestServiceProvider.php
5 months ago
AutoFeeRestServiceProvider.php
5 months ago
BalanceTransactionRestServiceProvider.php
3 years ago
BatchesRestServiceProvider.php
1 week ago
BlockPatternsRestServiceProvider.php
3 years ago
BrandRestServiceProvider.php
5 days ago
BumpRestServiceProvider.php
5 days ago
BundleItemsRestServiceProvider.php
5 days ago
CancellationActRestServiceProvider.php
1 year ago
CancellationReasonRestServiceProvider.php
1 year ago
ChargesRestServiceProvider.php
4 years ago
CheckEmailRestServiceProvider.php
3 years ago
CheckoutRestServiceProvider.php
1 year ago
ClicksRestServiceProvider.php
2 years ago
CouponRestServiceProvider.php
4 years ago
CustomerNotificationProtocolRestServiceProvider.php
4 years ago
CustomerPortalProtocolRestServiceProvider.php
1 year ago
CustomerRestServiceProvider.php
1 month ago
DisplayCurrencyRestServiceProvider.php
1 year ago
DisputesRestServiceProvider.php
9 months ago
DownloadRestServiceProvider.php
3 months ago
DraftCheckoutRestServiceProvider.php
1 year ago
ExportsRestServiceProvider.php
2 years ago
FulfillmentRestServiceProvider.php
3 years ago
ImportRowsRestServiceProvider.php
2 months ago
IncomingWebhooksRestServiceProvider.php
2 years ago
IntegrationProvidersRestServiceProvider.php
4 years ago
IntegrationsCatalogRestServiceProvider.php
1 year ago
IntegrationsRestServiceProvider.php
4 years ago
InvoicesRestServiceProvider.php
1 year ago
LicenseRestServiceProvider.php
1 year ago
LineItemsRestServiceProvider.php
1 year ago
LoginRestServiceProvider.php
1 month ago
ManualPaymentMethodsRestServiceProvider.php
3 years ago
MediaRestServiceProvider.php
1 year ago
OrderProtocolRestServiceProvider.php
1 year ago
OrderRestServiceProvider.php
1 year ago
ParcelTemplateRestServiceProvider.php
4 months ago
PaymentIntentsRestServiceProvider.php
4 years ago
PaymentMethodsRestServiceProvider.php
2 years ago
PayoutGroupsRestServiceProvider.php
2 years ago
PayoutsRestServiceProvider.php
5 months ago
PeriodRestServiceProvider.php
3 years ago
PluginInstallerRestServiceProvider.php
1 week ago
PriceRestServiceProvider.php
5 days ago
ProcessorRestServiceProvider.php
3 years ago
ProductCollectionsRestServiceProvider.php
5 days ago
ProductGroupsRestServiceProvider.php
5 days ago
ProductMediaRestServiceProvider.php
5 days ago
ProductsRestServiceProvider.php
5 days ago
PromotionRestServiceProvider.php
4 years ago
ProvisionalAccountRestServiceProvider.php
3 years ago
PurchasesRestServiceProvider.php
4 years ago
ReferralItemsRestServiceProvider.php
2 years ago
ReferralsRestServiceProvider.php
2 years ago
RefundsRestServiceProvider.php
4 years ago
RegisteredWebhookRestServiceProvider.php
2 years ago
RestServiceInterface.php
4 years ago
RestServiceProvider.php
5 days ago
ReturnItemsRestServiceProvider.php
2 years ago
ReturnReasonsRestServiceProvider.php
2 years ago
ReturnRequestsRestServiceProvider.php
2 years ago
ReviewProtocolRestServiceProvider.php
5 months ago
ReviewsRestServiceProvider.php
1 week ago
RuleSchemaRestServiceProvider.php
5 months ago
SettingsRestServiceProvider.php
1 year ago
ShippingMethodRestServiceProvider.php
3 years ago
ShippingProfileRestServiceProvider.php
3 years ago
ShippingProtocolRestServiceProvider.php
1 year ago
ShippingRateRestServiceProvider.php
3 years ago
ShippingZoneRestServiceProvider.php
3 years ago
SiteHealthRestServiceProvider.php
2 years ago
StatisticRestServiceProvider.php
3 years ago
SubscriptionProtocolRestServiceProvider.php
5 months ago
SubscriptionRestServiceProvider.php
2 years ago
SwapRestServiceProvider.php
1 year ago
TaxOverrideRestServiceProvider.php
1 year ago
TaxProtocolRestServiceProvider.php
1 year ago
TaxRegistrationRestServiceProvider.php
1 year ago
TaxZoneRestServiceProvider.php
1 year ago
UploadsRestServiceProvider.php
4 years ago
UpsellFunnelRestServiceProvider.php
1 year ago
UpsellRestServiceProvider.php
5 days ago
VariantOptionsRestServiceProvider.php
5 days ago
VariantValuesRestServiceProvider.php
5 days ago
VariantsRestServiceProvider.php
5 days ago
VerificationCodeRestServiceProvider.php
3 years ago
WebhooksRestServiceProvider.php
4 years ago
UpsellRestServiceProvider.php
224 lines
| 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 | * Filter index list items by schema context. |
| 28 | * |
| 29 | * @var boolean |
| 30 | */ |
| 31 | protected $filters_list_items = true; |
| 32 | |
| 33 | /** |
| 34 | * Whether the rest service provider converts currency. |
| 35 | * |
| 36 | * @var boolean |
| 37 | */ |
| 38 | protected $converts_currency = true; |
| 39 | |
| 40 | /** |
| 41 | * Methods allowed for the model. |
| 42 | * |
| 43 | * @var array |
| 44 | */ |
| 45 | protected $methods = [ 'index', 'create', 'find', 'edit', 'delete' ]; |
| 46 | |
| 47 | /** |
| 48 | * Get our sample schema for a post. |
| 49 | * |
| 50 | * @return array The sample schema for a post |
| 51 | */ |
| 52 | public function get_item_schema() { |
| 53 | if ( $this->schema ) { |
| 54 | // Since WordPress 5.3, the schema can be cached in the $schema property. |
| 55 | return $this->schema; |
| 56 | } |
| 57 | |
| 58 | $this->schema = [ |
| 59 | // This tells the spec of JSON Schema we are using which is draft 4. |
| 60 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 61 | // The title property marks the identity of the resource. |
| 62 | 'title' => $this->endpoint, |
| 63 | 'type' => 'object', |
| 64 | // In JSON Schema you can specify object properties in the properties attribute. |
| 65 | 'properties' => [ |
| 66 | 'id' => [ |
| 67 | 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ), |
| 68 | 'type' => 'string', |
| 69 | 'context' => [ 'view', 'edit', 'embed' ], |
| 70 | 'readonly' => true, |
| 71 | ], |
| 72 | 'object' => [ |
| 73 | 'description' => esc_html__( 'Type of object (upsell)', 'surecart' ), |
| 74 | 'type' => 'string', |
| 75 | 'context' => [ 'view', 'edit', 'embed' ], |
| 76 | 'readonly' => true, |
| 77 | ], |
| 78 | 'created_at' => [ |
| 79 | 'description' => esc_html__( 'Created at timestamp', 'surecart' ), |
| 80 | 'type' => 'integer', |
| 81 | 'context' => [ 'view', 'edit', 'embed' ], |
| 82 | 'readonly' => true, |
| 83 | ], |
| 84 | 'updated_at' => [ |
| 85 | 'description' => esc_html__( 'Created at timestamp', 'surecart' ), |
| 86 | 'type' => 'integer', |
| 87 | 'context' => [ 'view', 'edit', 'embed' ], |
| 88 | 'readonly' => true, |
| 89 | ], |
| 90 | 'amount_off' => [ |
| 91 | 'description' => esc_html__( 'Amount (in the currency of the price) that will be taken off line items associated with this upsell.', 'surecart' ), |
| 92 | 'type' => [ 'integer', 'null' ], |
| 93 | 'context' => [ 'edit' ], |
| 94 | ], |
| 95 | 'duplicate_purchase_behavior' => [ |
| 96 | 'description' => esc_html__( 'How to handle duplicate purchases of the product – can be one of allow, block_within_checkout, or block.', 'surecart' ), |
| 97 | 'type' => 'string', |
| 98 | 'context' => [ 'view', 'edit', 'embed' ], |
| 99 | ], |
| 100 | 'replacement_behavior' => [ |
| 101 | 'description' => esc_html__( 'How this upsell replaces line items when accepted.', 'surecart' ), |
| 102 | 'type' => 'string', |
| 103 | 'context' => [ 'edit' ], |
| 104 | ], |
| 105 | 'fee_description' => [ |
| 106 | 'description' => esc_html__( 'The description for this upsell which will be visible to customers.', 'surecart' ), |
| 107 | 'type' => 'string', |
| 108 | 'context' => [ 'view', 'edit', 'embed' ], |
| 109 | ], |
| 110 | 'percent_off' => [ |
| 111 | 'description' => esc_html__( 'Percent that will be taken off line items associated with this upsell.', 'surecart' ), |
| 112 | 'type' => [ 'integer', 'null' ], |
| 113 | 'context' => [ 'edit' ], |
| 114 | ], |
| 115 | 'step' => [ |
| 116 | 'description' => esc_html__( 'Where this upsell falls in position within the upsell funnel – can be one of initial, accepted, or declined.', 'surecart' ), |
| 117 | 'type' => 'string', |
| 118 | 'context' => [ 'view', 'edit', 'embed' ], |
| 119 | ], |
| 120 | 'price' => [ |
| 121 | 'description' => esc_html__( 'The UUID of the price.', 'surecart' ), |
| 122 | 'type' => [ 'string', 'object' ], |
| 123 | 'context' => [ 'view', 'edit', 'embed' ], |
| 124 | ], |
| 125 | 'priority' => [ |
| 126 | 'description' => esc_html__( 'The priority of this upsell in relation to other upsells.', 'surecart' ), |
| 127 | 'type' => 'integer', |
| 128 | 'context' => [ 'edit' ], |
| 129 | ], |
| 130 | 'filter_price_ids' => [ |
| 131 | 'description' => esc_html__( 'The price ids that filter this upsell.', 'surecart' ), |
| 132 | 'type' => 'array', |
| 133 | 'context' => [ 'edit' ], |
| 134 | ], |
| 135 | 'filter_product_ids' => [ |
| 136 | 'description' => esc_html__( 'The product ids that filter this upsell.', 'surecart' ), |
| 137 | 'type' => 'array', |
| 138 | 'context' => [ 'edit' ], |
| 139 | ], |
| 140 | 'filter_product_group_ids' => [ |
| 141 | 'description' => esc_html__( 'The product group ids that filter this upsell.', 'surecart' ), |
| 142 | 'type' => 'array', |
| 143 | 'context' => [ 'edit' ], |
| 144 | ], |
| 145 | 'filter_match_type' => [ |
| 146 | 'description' => esc_html__( 'How the filter conditions are matched – can be one of all, any, or none.', 'surecart' ), |
| 147 | 'type' => 'string', |
| 148 | 'context' => [ 'edit' ], |
| 149 | ], |
| 150 | 'metadata' => [ |
| 151 | 'description' => esc_html__( 'Set of key-value pairs for custom data.', 'surecart' ), |
| 152 | 'type' => 'object', |
| 153 | 'context' => [ 'edit' ], |
| 154 | ], |
| 155 | ], |
| 156 | ]; |
| 157 | |
| 158 | return $this->schema; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Anyone can get a specific price. |
| 163 | * |
| 164 | * @param \WP_REST_Request $request Full details about the request. |
| 165 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 166 | */ |
| 167 | public function get_item_permissions_check( $request ) { |
| 168 | $check = $this->forbidEditContextWithout( $request, 'edit_sc_prices' ); |
| 169 | if ( is_wp_error( $check ) ) { |
| 170 | return $check; |
| 171 | } |
| 172 | |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Who can list prices |
| 178 | * |
| 179 | * @param \WP_REST_Request $request Full details about the request. |
| 180 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 181 | */ |
| 182 | public function get_items_permissions_check( $request ) { |
| 183 | $check = $this->forbidEditContextWithout( $request, 'edit_sc_prices' ); |
| 184 | if ( is_wp_error( $check ) ) { |
| 185 | return $check; |
| 186 | } |
| 187 | |
| 188 | if ( empty( $request['upsell_funnel_ids'] ) || count( $request['upsell_funnel_ids'] ) > 1 ) { |
| 189 | return current_user_can( 'edit_sc_prices' ); |
| 190 | } |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Create model. |
| 196 | * |
| 197 | * @param \WP_REST_Request $request Full details about the request. |
| 198 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 199 | */ |
| 200 | public function create_item_permissions_check( $request ) { |
| 201 | return current_user_can( 'publish_sc_prices' ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Update model. |
| 206 | * |
| 207 | * @param \WP_REST_Request $request Full details about the request. |
| 208 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 209 | */ |
| 210 | public function update_item_permissions_check( $request ) { |
| 211 | return current_user_can( 'edit_sc_prices' ); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Delete model. |
| 216 | * |
| 217 | * @param \WP_REST_Request $request Full details about the request. |
| 218 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 219 | */ |
| 220 | public function delete_item_permissions_check( $request ) { |
| 221 | return current_user_can( 'delete_sc_prices' ); |
| 222 | } |
| 223 | } |
| 224 |