AverageDonation.php
4 years ago
DonationsVsIncome.php
4 years ago
Endpoint.php
1 year ago
FormPerformance.php
4 years ago
Income.php
4 years ago
IncomeBreakdown.php
4 years ago
PaymentMethods.php
4 years ago
PaymentStatuses.php
4 years ago
RecentDonations.php
4 years ago
TopDonors.php
4 years ago
TotalDonors.php
4 years ago
TotalIncome.php
4 years ago
TotalRefunds.php
4 years ago
PaymentMethods.php
90 lines
| 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 |