AverageDonation.php
6 years ago
DonationsVsIncome.php
6 years ago
Endpoint.php
6 years ago
FormPerformance.php
6 years ago
Income.php
6 years ago
IncomeBreakdown.php
6 years ago
PaymentMethods.php
6 years ago
PaymentStatuses.php
6 years ago
RecentDonations.php
6 years ago
TopDonors.php
6 years ago
TotalDonors.php
6 years ago
TotalIncome.php
6 years ago
TotalRefunds.php
6 years ago
PaymentMethods.php
70 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 | public function __construct() { |
| 14 | $this->endpoint = 'payment-methods'; |
| 15 | } |
| 16 | |
| 17 | public function get_report( $request ) { |
| 18 | |
| 19 | // Use give_count_payments logic to get payments |
| 20 | $gateways = give_get_payment_gateways(); |
| 21 | $stats = new \Give_Payment_Stats(); |
| 22 | |
| 23 | $gatewaysArr = array(); |
| 24 | |
| 25 | foreach ( $gateways as $gateway_id => $gateway ) { |
| 26 | $gatewaysArr[] = array( |
| 27 | 'admin_label' => $gateway['admin_label'], |
| 28 | 'count' => $stats->get_sales( 0, date( $request->get_param( 'start' ) ), date( $request->get_param( 'end' ) ), $gateway_id ), |
| 29 | 'amount' => $stats->get_earnings( 0, date( $request->get_param( 'start' ) ), date( $request->get_param( 'end' ) ), $gateway_id ), |
| 30 | ); |
| 31 | } |
| 32 | $sorted = usort( |
| 33 | $gatewaysArr, |
| 34 | function ( $a, $b ) { |
| 35 | if ( $a['amount'] == $b['amount'] ) { |
| 36 | return 0; |
| 37 | } |
| 38 | return ( $a['amount'] > $b['amount'] ) ? -1 : 1; |
| 39 | } |
| 40 | ); |
| 41 | |
| 42 | $labels = array(); |
| 43 | $data = array(); |
| 44 | $tooltips = array(); |
| 45 | |
| 46 | if ( $sorted == true ) { |
| 47 | $gatewaysArr = array_slice( $gatewaysArr, 0, 5 ); |
| 48 | foreach ( $gatewaysArr as $gateway ) { |
| 49 | $labels[] = $gateway['admin_label']; |
| 50 | $data[] = $gateway['amount']; |
| 51 | $tooltips[] = array( |
| 52 | 'title' => give_currency_filter( give_format_amount( $gateway['amount'] ), array( 'decode_currency' => true ) ), |
| 53 | 'body' => $gateway['count'] . ' ' . __( 'Payments', 'give' ), |
| 54 | 'footer' => $gateway['admin_label'], |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return array( |
| 60 | 'labels' => $labels, |
| 61 | 'datasets' => array( |
| 62 | array( |
| 63 | 'data' => $data, |
| 64 | 'tooltips' => $tooltips, |
| 65 | ), |
| 66 | ), |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 |