PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / API / Endpoints / Reports / PaymentMethods.php
PaymentMethods.php
87 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Reports base endpoint
5 *
6 * @package Give
7 */
8
9 namespace Give\API\Endpoints\Reports;
10
11 class PaymentMethods extends Endpoint {
12
13 public function __construct() {
14 $this->endpoint = 'payment-methods';
15 }
16
17 public function getReport( $request ) {
18
19 $paymentObjects = $this->getPayments( $request->get_param( 'start' ), $request->get_param( 'end' ), 'date', -1 );
20 $gatewayObjects = give_get_payment_gateways();
21
22 if ( $this->testMode === false ) {
23 unset( $gatewayObjects['manual'] );
24 }
25
26 $gateways = [];
27 foreach ( $gatewayObjects as $gatewayId => $gatewayObject ) {
28 $gateways[ $gatewayId ] = [
29 'label' => $gatewayObject['admin_label'],
30 'count' => 0,
31 'amount' => 0,
32 ];
33 }
34
35 if ( count( $paymentObjects ) > 0 ) {
36 foreach ( $paymentObjects as $paymentObject ) {
37 $gateways[ $paymentObject->gateway ]['count'] += 1;
38 $gateways[ $paymentObject->gateway ]['amount'] += $paymentObject->total;
39 }
40 }
41
42 $gatewaysSorted = usort(
43 $gateways,
44 function ( $a, $b ) {
45 if ( $a['amount'] == $b['amount'] ) {
46 return 0;
47 }
48 return ( $a['amount'] > $b['amount'] ) ? -1 : 1;
49 }
50 );
51
52 $data = [];
53 $labels = [];
54 $tooltips = [];
55
56 if ( $gatewaysSorted == true ) {
57 $gateways = array_slice( $gateways, 0, 5 );
58 foreach ( $gateways as $gateway ) {
59 $labels[] = $gateway['label'];
60 $data[] = $gateway['amount'];
61 $tooltips[] = [
62 'title' => give_currency_filter(
63 give_format_amount( $gateway['amount'] ),
64 [
65 'currency_code' => $this->currency,
66 'decode_currency' => true,
67 'sanitize' => false,
68 ]
69 ),
70 'body' => $gateway['count'] . ' ' . __( 'Payments', 'give' ),
71 'footer' => $gateway['label'],
72 ];
73 }
74 }
75
76 return [
77 'labels' => $labels,
78 'datasets' => [
79 [
80 'data' => $data,
81 'tooltips' => $tooltips,
82 ],
83 ],
84 ];
85 }
86 }
87