PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.6
GiveWP – Donation Plugin and Fundraising Platform v4.16.6
4.18.0.1 4.18.0 4.17.0 4.16.9 4.16.8.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 All 258 releases
give / src / API / Endpoints / Reports / PaymentMethods.php
src/API/Endpoints/Reports
AverageDonation.php 6.9 KB 4 years ago DonationsVsIncome.php 3.0 KB 4 years ago Endpoint.php 11.7 KB 8 months ago FormPerformance.php 4.1 KB 4 years ago Income.php 4.3 KB 4 years ago IncomeBreakdown.php 4.3 KB 4 years ago PaymentMethods.php 2.4 KB 4 years ago PaymentStatuses.php 3.8 KB 4 years ago RecentDonations.php 2.1 KB 4 years ago TopDonors.php 3.0 KB 4 years ago TotalDonors.php 5.5 KB 4 years ago TotalIncome.php 6.0 KB 4 years ago TotalRefunds.php 5.3 KB 4 years ago

PaymentMethods.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.6, at src/API/Endpoints/Reports/PaymentMethods.php

90 lines 2.4 KB 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
14 public function __construct()
15 {
16 $this->endpoint = 'payment-methods';
17 }
18
19 public function getReport($request)
20 {
21 $paymentObjects = $this->getPayments($request->get_param('start'), $request->get_param('end'), 'date', -1);
22 $gatewayObjects = give_get_payment_gateways();
23
24 if ($this->testMode === false) {
25 unset($gatewayObjects['manual']);
26 }
27
28 $gateways = [];
29 foreach ($gatewayObjects as $gatewayId => $gatewayObject) {
30 $gateways[$gatewayId] = [
31 'label' => $gatewayObject['admin_label'],
32 'count' => 0,
33 'amount' => 0,
34 ];
35 }
36
37 if (count($paymentObjects) > 0) {
38 foreach ($paymentObjects as $paymentObject) {
39 $gateways[$paymentObject->gateway]['count'] += 1;
40 $gateways[$paymentObject->gateway]['amount'] += $paymentObject->total;
41 }
42 }
43
44 $gatewaysSorted = usort(
45 $gateways,
46 function ($a, $b) {
47 if ($a['amount'] == $b['amount']) {
48 return 0;
49 }
50
51 return ($a['amount'] > $b['amount']) ? -1 : 1;
52 }
53 );
54
55 $data = [];
56 $labels = [];
57 $tooltips = [];
58
59 if ($gatewaysSorted == true) {
60 $gateways = array_slice($gateways, 0, 5);
61 foreach ($gateways as $gateway) {
62 $labels[] = $gateway['label'];
63 $data[] = $gateway['amount'];
64 $tooltips[] = [
65 'title' => give_currency_filter(
66 give_format_amount($gateway['amount']),
67 [
68 'currency_code' => $this->currency,
69 'decode_currency' => true,
70 'sanitize' => false,
71 ]
72 ),
73 'body' => $gateway['count'] . ' ' . __('Payments', 'give'),
74 'footer' => $gateway['label'],
75 ];
76 }
77 }
78
79 return [
80 'labels' => $labels,
81 'datasets' => [
82 [
83 'data' => $data,
84 'tooltips' => $tooltips,
85 ],
86 ],
87 ];
88 }
89 }
90