delete-payment-endpoint.php
3 years ago
delete-payments-endpoint.php
3 years ago
gateway-endpoint.php
3 years ago
receive-payment.php
3 years ago
receive-payments.php
3 years ago
rest-api-controller.php
3 years ago
delete-payments-endpoint.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Gateways\Rest_Api; |
| 5 | |
| 6 | |
| 7 | use Jet_Form_Builder\Db_Queries\Views\View_Base; |
| 8 | use Jet_Form_Builder\Exceptions\Query_Builder_Exception; |
| 9 | use Jet_Form_Builder\Gateways\Query_Views\Payment_Count_View; |
| 10 | use Jet_Form_Builder\Gateways\Query_Views\Payment_View; |
| 11 | use Jet_Form_Builder\Gateways\Table_Views\Payments; |
| 12 | use Jet_Form_Builder\Rest_Api\Rest_Api_Endpoint_Base; |
| 13 | use Jet_Form_Builder\Rest_Api\Traits\Paginated_Args; |
| 14 | |
| 15 | class Delete_Payments_Endpoint extends Rest_Api_Endpoint_Base { |
| 16 | |
| 17 | use Paginated_Args; |
| 18 | |
| 19 | public static function get_rest_base() { |
| 20 | return 'payments/delete'; |
| 21 | } |
| 22 | |
| 23 | public static function get_methods() { |
| 24 | return \WP_REST_Server::DELETABLE; |
| 25 | } |
| 26 | |
| 27 | public function check_permission(): bool { |
| 28 | return current_user_can( 'manage_options' ); |
| 29 | } |
| 30 | |
| 31 | public function get_table_view() { |
| 32 | return new Payments(); |
| 33 | } |
| 34 | |
| 35 | public function run_callback( \WP_REST_Request $request ) { |
| 36 | $body = $request->get_json_params(); |
| 37 | $view = $this->get_table_view(); |
| 38 | |
| 39 | $args = View_Base::get_paginated_args( $this->get_paginate_args( $request ) ); |
| 40 | |
| 41 | try { |
| 42 | Payment_View::delete( |
| 43 | array( |
| 44 | array( |
| 45 | 'type' => 'in', |
| 46 | 'values' => array( 'id', $body['checked'] ?? array() ), |
| 47 | ), |
| 48 | ) |
| 49 | ); |
| 50 | } catch ( Query_Builder_Exception $exception ) { |
| 51 | return new \WP_REST_Response( |
| 52 | array( |
| 53 | 'message' => __( 'Something went wrong on delete.', 'jet-form-builder' ), |
| 54 | ), |
| 55 | 503 |
| 56 | ); |
| 57 | } |
| 58 | $list = $view->get_raw_list( $args ); |
| 59 | |
| 60 | return new \WP_REST_Response( |
| 61 | array( |
| 62 | 'message' => __( 'Successfully removed', 'jet-form-builder' ), |
| 63 | 'list' => $view->prepare_list( $list ), |
| 64 | 'total' => Payment_Count_View::count( $args ), |
| 65 | ) |
| 66 | ); |
| 67 | } |
| 68 | } |