payments.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Gateways\Table_Views; |
| 5 | |
| 6 | use Jet_Form_Builder\Admin\Pages\Pages_Manager; |
| 7 | use Jet_Form_Builder\Admin\Table_Views\Column_Base; |
| 8 | use Jet_Form_Builder\Admin\Table_Views\Columns\Record_Id_Column_Advanced; |
| 9 | use Jet_Form_Builder\Admin\Table_Views\View_Advanced_Base; |
| 10 | use Jet_Form_Builder\Exceptions\Query_Builder_Exception; |
| 11 | use JFB_Modules\Gateways\Db_Models\Payment_To_Payer_Shipping_Model; |
| 12 | use JFB_Modules\Gateways\Db_Models\Payment_To_Record; |
| 13 | use JFB_Modules\Gateways\Query_Views\Payment_Count_View; |
| 14 | use JFB_Modules\Gateways\Query_Views\Payment_View; |
| 15 | use Jet_Form_Builder\Admin\Table_Views\Columns\Created_At_Column; |
| 16 | use JFB_Modules\Gateways\Table_Views\Columns\Gross_Column; |
| 17 | use JFB_Modules\Gateways\Table_Views\Columns\Header_Actions_Column; |
| 18 | use JFB_Modules\Gateways\Table_Views\Columns\Payer_Column; |
| 19 | use JFB_Modules\Gateways\Table_Views\Columns\Payment_Status_Column; |
| 20 | use JFB_Modules\Gateways\Table_Views\Columns\Payment_Type_Column; |
| 21 | use JFB_Modules\Gateways\Table_Views\Columns\Row_Actions_Column; |
| 22 | use JFB_Modules\Gateways\Table_Views\Columns\Transaction_Column; |
| 23 | use JFB_Modules\Gateways\Rest_Api; |
| 24 | |
| 25 | // If this file is called directly, abort. |
| 26 | if ( ! defined( 'WPINC' ) ) { |
| 27 | die; |
| 28 | } |
| 29 | |
| 30 | class Payments extends View_Advanced_Base { |
| 31 | |
| 32 | public function get_raw_list( array $args ): array { |
| 33 | try { |
| 34 | return ( new Payment_View() ) |
| 35 | ->set_table_args( $args ) |
| 36 | ->query() |
| 37 | ->query_all(); |
| 38 | } catch ( Query_Builder_Exception $exception ) { |
| 39 | return array(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public function get_dependencies(): array { |
| 44 | return array( |
| 45 | new Payment_To_Payer_Shipping_Model(), |
| 46 | new Payment_To_Record(), |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | public function get_rest_url(): string { |
| 51 | return Rest_Api\Receive_Payments::rest_url(); |
| 52 | } |
| 53 | |
| 54 | public function get_rest_methods(): string { |
| 55 | return Rest_Api\Receive_Payments::get_methods(); |
| 56 | } |
| 57 | |
| 58 | public function get_total(): int { |
| 59 | return Payment_Count_View::count(); |
| 60 | } |
| 61 | |
| 62 | public function get_empty_message(): string { |
| 63 | return __( 'No payments found.', 'jet-form-builder' ); |
| 64 | } |
| 65 | |
| 66 | public function get_global_actions(): array { |
| 67 | return ( new Header_Actions_Column() )->get_value(); |
| 68 | } |
| 69 | |
| 70 | public function get_columns(): array { |
| 71 | return array( |
| 72 | Column_Base::CHOOSE => new Record_Id_Column_Advanced(), |
| 73 | Column_Base::ACTIONS => new Row_Actions_Column(), |
| 74 | 'type' => new Payment_Type_Column(), |
| 75 | 'date' => new Created_At_Column(), |
| 76 | 'payment_status' => new Payment_Status_Column(), |
| 77 | 'gross' => new Gross_Column(), |
| 78 | 'payer' => new Payer_Column(), |
| 79 | 'transaction' => new Transaction_Column(), |
| 80 | 'id' => new Record_Id_Column_Advanced(), |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | public function load_data(): array { |
| 85 | return array( |
| 86 | 'export_url' => Pages_Manager::instance()->get_action_url( 'payments-export' ), |
| 87 | 'counter_endpoint' => Rest_Api\Count_Payments_Endpoint::get_endpoint(), |
| 88 | 'messages' => array( |
| 89 | 'empty_checked' => __( 'You have not selected any payment.', 'jet-form-builder' ), |
| 90 | 'empty_action' => __( 'You have not selected an action.', 'jet-form-builder' ), |
| 91 | ), |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | } |
| 96 |