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
CustomerNotificationProtocolRestServiceProvider.php
155 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Rest; |
| 4 | |
| 5 | use SureCart\Controllers\Rest\CustomerNotificationProtocolController; |
| 6 | use SureCart\Rest\RestServiceInterface; |
| 7 | |
| 8 | /** |
| 9 | * Service provider for Price Rest Requests |
| 10 | */ |
| 11 | class CustomerNotificationProtocolRestServiceProvider extends RestServiceProvider implements RestServiceInterface { |
| 12 | /** |
| 13 | * Endpoint. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $endpoint = 'customer_notification_protocol'; |
| 18 | |
| 19 | /** |
| 20 | * Rest Controller |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $controller = CustomerNotificationProtocolController::class; |
| 25 | |
| 26 | /** |
| 27 | * Methods allowed for the model. |
| 28 | * |
| 29 | * @var array |
| 30 | */ |
| 31 | protected $methods = []; |
| 32 | |
| 33 | /** |
| 34 | * Register REST Routes |
| 35 | * |
| 36 | * @return void |
| 37 | */ |
| 38 | public function registerRoutes() { |
| 39 | register_rest_route( |
| 40 | "$this->name/v$this->version", |
| 41 | "$this->endpoint", |
| 42 | array_filter( |
| 43 | [ |
| 44 | [ |
| 45 | 'methods' => \WP_REST_Server::READABLE, |
| 46 | 'callback' => $this->callback( $this->controller, 'find' ), |
| 47 | 'permission_callback' => [ $this, 'get_item_permissions_check' ], |
| 48 | 'args' => $this->get_collection_params(), |
| 49 | ], |
| 50 | [ |
| 51 | 'methods' => \WP_REST_Server::EDITABLE, |
| 52 | 'callback' => $this->callback( $this->controller, 'edit' ), |
| 53 | 'permission_callback' => [ $this, 'update_item_permissions_check' ], |
| 54 | ], |
| 55 | 'schema' => [ $this, 'get_item_schema' ], |
| 56 | ] |
| 57 | ) |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get our sample schema for a post. |
| 63 | * |
| 64 | * @return array The sample schema for a post |
| 65 | */ |
| 66 | public function get_item_schema() { |
| 67 | if ( $this->schema ) { |
| 68 | // Since WordPress 5.3, the schema can be cached in the $schema property. |
| 69 | return $this->schema; |
| 70 | } |
| 71 | |
| 72 | $this->schema = [ |
| 73 | // This tells the spec of JSON Schema we are using which is draft 4. |
| 74 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 75 | // The title property marks the identity of the resource. |
| 76 | 'title' => $this->endpoint, |
| 77 | 'type' => 'object', |
| 78 | // In JSON Schema you can specify object properties in the properties attribute. |
| 79 | 'properties' => [ |
| 80 | 'id' => [ |
| 81 | 'description' => esc_html__( 'Unique identifier for the object.', 'surecart' ), |
| 82 | 'type' => 'string', |
| 83 | 'context' => [ 'edit' ], |
| 84 | 'readonly' => true, |
| 85 | ], |
| 86 | 'created_at' => [ |
| 87 | 'type' => 'integer', |
| 88 | 'context' => [ 'edit' ], |
| 89 | ], |
| 90 | 'updated_at' => [ |
| 91 | 'type' => 'integer', |
| 92 | 'context' => [ 'edit' ], |
| 93 | ], |
| 94 | 'abandoned_order_enabled' => [ |
| 95 | 'description' => esc_html__( 'If set to true abandonded order reminder emails will be sent to customers.', 'surecart' ), |
| 96 | 'type' => 'boolean', |
| 97 | 'context' => [ 'view', 'edit' ], |
| 98 | ], |
| 99 | 'order_enabled' => [ |
| 100 | 'description' => esc_html__( 'If set to true order confirmation emails will be sent to customers.', 'surecart' ), |
| 101 | 'type' => 'boolean', |
| 102 | 'context' => [ 'view', 'edit' ], |
| 103 | ], |
| 104 | 'payment_failure_enabled' => [ |
| 105 | 'description' => esc_html__( 'If set to true subscription dunning emails will be sent to customers.', 'surecart' ), |
| 106 | 'type' => 'boolean', |
| 107 | 'context' => [ 'view', 'edit' ], |
| 108 | ], |
| 109 | 'refund_enabled' => [ |
| 110 | 'description' => esc_html__( 'If set to true refund emails will be sent to customers.', 'surecart' ), |
| 111 | 'type' => 'boolean', |
| 112 | 'context' => [ 'view', 'edit' ], |
| 113 | ], |
| 114 | 'from_name' => [ |
| 115 | 'description' => esc_html__( 'The from name to use when sending emails to customers.', 'surecart' ), |
| 116 | 'type' => 'string', |
| 117 | 'context' => [ 'view', 'edit' ], |
| 118 | ], |
| 119 | 'locale' => [ |
| 120 | 'description' => esc_html__( 'The language that will be used for all customer notifications. Current available locales are de, en, es, and fr.', 'surecart' ), |
| 121 | 'type' => 'string', |
| 122 | 'context' => [ 'view', 'edit' ], |
| 123 | ], |
| 124 | 'reply_to_email' => [ |
| 125 | 'description' => esc_html__( 'The reply-to email address to use when sending emails to customers.', 'surecart' ), |
| 126 | 'type' => 'string', |
| 127 | 'context' => [ 'view', 'edit' ], |
| 128 | ], |
| 129 | ], |
| 130 | ]; |
| 131 | |
| 132 | return $this->schema; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Anyone can get the protocols. |
| 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_item_permissions_check( $request ) { |
| 142 | return current_user_can( 'manage_options' ); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Need priveleges to update. |
| 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 update_item_permissions_check( $request ) { |
| 152 | return current_user_can( 'manage_options' ); |
| 153 | } |
| 154 | } |
| 155 |