Block.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\Dashboard\CustomerCharges; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\Dashboard\DashboardPage; |
| 6 | |
| 7 | /** |
| 8 | * Checkout block |
| 9 | */ |
| 10 | class Block extends DashboardPage { |
| 11 | /** |
| 12 | * Render the block |
| 13 | * |
| 14 | * @param array $attributes Block attributes. |
| 15 | * @param string $content Post content. |
| 16 | * |
| 17 | * @return function |
| 18 | */ |
| 19 | public function render( $attributes, $content ) { |
| 20 | // get the current page tab and possible id. |
| 21 | $id = sanitize_text_field( $_GET['charge']['id'] ?? null ); |
| 22 | $page = sanitize_text_field( $_GET['charge']['page'] ?? 1 ); |
| 23 | |
| 24 | return $id ? $this->show( $id ) : $this->index( $page ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Show and individual checkout session. |
| 29 | * |
| 30 | * @param string $id Session ID. |
| 31 | * |
| 32 | * @return function |
| 33 | */ |
| 34 | public function show( $id ) { |
| 35 | return \SureCart::blocks()->render( |
| 36 | 'web/dashboard/charges/show', |
| 37 | [ |
| 38 | 'id' => $id, |
| 39 | 'customer_id' => $this->customer_id, |
| 40 | 'order' => [ |
| 41 | 'query' => [ |
| 42 | 'expand' => [], |
| 43 | ], |
| 44 | ], |
| 45 | 'subscriptions' => [ |
| 46 | 'query' => [ |
| 47 | 'order_ids' => [ $id ], |
| 48 | 'customer_ids' => [ $this->customer_id ], |
| 49 | 'status' => [ 'active', 'trialing' ], |
| 50 | 'page' => 1, |
| 51 | 'per_page' => 10, |
| 52 | ], |
| 53 | ], |
| 54 | 'charges' => [ |
| 55 | 'query' => [ |
| 56 | 'order_ids' => [ $id ], |
| 57 | 'customer_ids' => [ $this->customer_id ], |
| 58 | 'page' => 1, |
| 59 | 'per_page' => 10, |
| 60 | ], |
| 61 | ], |
| 62 | ] |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Show and individual checkout session. |
| 68 | * |
| 69 | * @param array $page Current page. |
| 70 | * |
| 71 | * @return function |
| 72 | */ |
| 73 | public function index( $page ) { |
| 74 | if ( empty( $this->customer_id ) ) { |
| 75 | return; |
| 76 | } |
| 77 | return \SureCart::blocks()->render( |
| 78 | 'web/dashboard/charges/index', |
| 79 | [ |
| 80 | 'query' => [ |
| 81 | 'customer_ids' => [ $this->customer_id ], |
| 82 | 'page' => 1, |
| 83 | 'per_page' => 10, |
| 84 | ], |
| 85 | ] |
| 86 | ); |
| 87 | } |
| 88 | } |
| 89 |