AbandonedCheckoutProtocolController.php
3 years ago
AbandonedCheckoutsController.php
3 years ago
AccountController.php
3 years ago
ActivationsController.php
3 years ago
BalanceTransactionsController.php
3 years ago
BrandController.php
3 years ago
BumpsController.php
3 years ago
ChargesController.php
3 years ago
CheckEmailController.php
3 years ago
CheckoutsController.php
3 years ago
CouponsController.php
3 years ago
CustomerController.php
3 years ago
CustomerLinksController.php
3 years ago
CustomerNotificationProtocolController.php
3 years ago
DownloadsController.php
3 years ago
IntegrationProvidersController.php
3 years ago
IntegrationsController.php
3 years ago
InvoicesController.php
3 years ago
LicensesController.php
3 years ago
LoginController.php
3 years ago
ManualPaymentMethodsController.php
3 years ago
MediasController.php
3 years ago
OrderController.php
3 years ago
OrderProtocolController.php
3 years ago
PaymentIntentsController.php
3 years ago
PaymentMethodsController.php
3 years ago
PeriodsController.php
3 years ago
PortalProtocolController.php
3 years ago
PricesController.php
3 years ago
ProcessorController.php
3 years ago
ProductGroupsController.php
3 years ago
ProductsController.php
3 years ago
PromotionsController.php
3 years ago
PurchasesController.php
3 years ago
RefundsController.php
3 years ago
RestController.php
3 years ago
SettingsController.php
3 years ago
StatisticsController.php
3 years ago
SubscriptionProtocolController.php
3 years ago
SubscriptionsController.php
3 years ago
TaxProtocolController.php
3 years ago
TaxRegistrationController.php
3 years ago
TaxZoneController.php
3 years ago
UploadsController.php
3 years ago
VerificationCodeController.php
3 years ago
WebhookController.php
3 years ago
SubscriptionsController.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Rest; |
| 4 | |
| 5 | use SureCart\Models\Subscription; |
| 6 | |
| 7 | /** |
| 8 | * Handle Price requests through the REST API |
| 9 | */ |
| 10 | class SubscriptionsController extends RestController { |
| 11 | /** |
| 12 | * Class to make the requests. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $class = Subscription::class; |
| 17 | |
| 18 | /** |
| 19 | * Cancel a subscription. |
| 20 | * |
| 21 | * @param \WP_REST_Request $request Rest Request. |
| 22 | * |
| 23 | * @return \WP_REST_Response |
| 24 | */ |
| 25 | public function cancel( \WP_REST_Request $request ) { |
| 26 | $model = $this->middleware( new $this->class(), $request ); |
| 27 | if ( is_wp_error( $model ) ) { |
| 28 | return $model; |
| 29 | } |
| 30 | return $model->where( $request->get_query_params() )->cancel( $request['id'] ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Complete a subscription. |
| 35 | * |
| 36 | * @param \WP_REST_Request $request Rest Request. |
| 37 | * |
| 38 | * @return \WP_REST_Response |
| 39 | */ |
| 40 | public function complete( \WP_REST_Request $request ) { |
| 41 | $model = $this->middleware( new $this->class(), $request ); |
| 42 | if ( is_wp_error( $model ) ) { |
| 43 | return $model; |
| 44 | } |
| 45 | return $model->where( $request->get_query_params() )->complete( $request['id'] ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Restore a subscription. |
| 50 | * |
| 51 | * @param \WP_REST_Request $request Rest Request. |
| 52 | * |
| 53 | * @return \WP_REST_Response |
| 54 | */ |
| 55 | public function restore( \WP_REST_Request $request ) { |
| 56 | $model = $this->middleware( new $this->class(), $request ); |
| 57 | if ( is_wp_error( $model ) ) { |
| 58 | return $model; |
| 59 | } |
| 60 | return $model->where( $request->get_query_params() )->restore( $request['id'] ); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /** |
| 65 | * Renew a subscription. |
| 66 | * |
| 67 | * @param \WP_REST_Request $request Rest Request. |
| 68 | * |
| 69 | * @return \WP_REST_Response |
| 70 | */ |
| 71 | public function renew( \WP_REST_Request $request ) { |
| 72 | $model = $this->middleware( new $this->class(), $request ); |
| 73 | if ( is_wp_error( $model ) ) { |
| 74 | return $model; |
| 75 | } |
| 76 | return $model->where( $request->get_query_params() )->renew( $request['id'] ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Preview an upcoming invoice. |
| 81 | * |
| 82 | * @param \WP_REST_Request $request Rest Request. |
| 83 | * |
| 84 | * @return \WP_REST_Response |
| 85 | */ |
| 86 | public function upcomingPeriod( \WP_REST_Request $request ) { |
| 87 | $model = $this->middleware( new $this->class( $request['id'] ), $request ); |
| 88 | if ( is_wp_error( $model ) ) { |
| 89 | return $model; |
| 90 | } |
| 91 | return $model->where( $request->get_query_params() )->upcomingPeriod( array_diff_assoc( $request->get_params(), $request->get_query_params() ) ); |
| 92 | } |
| 93 | } |
| 94 |