PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.8
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / abilities / orders / list-transactions.php
latepoint / lib / abilities / orders Last commit date
abstract-order-ability.php 1 day ago change-invoice-status.php 1 day ago change-order-status.php 1 day ago create-invoice.php 1 day ago create-order.php 4 months ago delete-order.php 1 day ago get-invoice.php 1 day ago get-order-price-breakdown.php 1 day ago get-order.php 1 day ago get-transaction.php 1 day ago list-invoices.php 1 day ago list-orders.php 1 day ago list-transactions.php 1 day ago refund-transaction.php 1 day ago update-order.php 1 day ago
list-transactions.php
87 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityListTransactions extends LatePointAbstractOrderAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/list-transactions';
10 $this->label = __( 'List transactions', 'latepoint' );
11 $this->description = __( 'Returns a paginated list of payment transactions.', 'latepoint' );
12 $this->permission = 'transaction__view';
13 $this->read_only = true;
14 }
15
16 public function get_input_schema(): array {
17 return [
18 'type' => 'object',
19 'properties' => array_merge(
20 [
21 'order_id' => [ 'type' => 'integer' ],
22 'customer_id' => [ 'type' => 'integer' ],
23 ],
24 self::pagination()
25 ),
26 ];
27 }
28
29 public function get_output_schema(): array {
30 return [
31 'type' => 'object',
32 'properties' => [
33 'transactions' => [
34 'type' => 'array',
35 'items' => $this->transaction_output_schema(),
36 ],
37 'total' => [ 'type' => 'integer' ],
38 'page' => [ 'type' => 'integer' ],
39 'per_page' => [ 'type' => 'integer' ],
40 ],
41 ];
42 }
43
44 public function execute( array $args ) {
45 $page = max( 1, (int) ( $args['page'] ?? 1 ) );
46 $per_page = min( 100, max( 1, (int) ( $args['per_page'] ?? 20 ) ) );
47 $offset = ( $page - 1 ) * $per_page;
48
49 $query = new OsTransactionModel();
50
51 if ( ! empty( $args['order_id'] ) ) {
52 $query->where( [ 'order_id' => (int) $args['order_id'] ] );
53 }
54 if ( ! empty( $args['customer_id'] ) ) {
55 $query->where( [ 'customer_id' => (int) $args['customer_id'] ] );
56 }
57
58 // Transactions have no own record-scope — restrict to orders the current user may access.
59 $allowed_order_ids = $this->allowed_order_ids();
60 if ( ! is_null( $allowed_order_ids ) ) {
61 if ( empty( $allowed_order_ids ) ) {
62 return [
63 'transactions' => [],
64 'total' => 0,
65 'page' => $page,
66 'per_page' => $per_page,
67 ];
68 }
69 $query->where_in( 'order_id', $allowed_order_ids );
70 }
71
72 $transactions = ( clone $query )
73 ->order_by( 'created_at DESC' )
74 ->set_limit( $per_page )
75 ->set_offset( $offset )
76 ->get_results_as_models();
77 $total = $query->count();
78
79 return [
80 'transactions' => array_map( [ $this, 'serialize_transaction' ], $transactions ),
81 'total' => (int) $total,
82 'page' => $page,
83 'per_page' => $per_page,
84 ];
85 }
86 }
87