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
RecentDonations.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Recent Donations endpoint |
| 5 | * |
| 6 | * @package Give |
| 7 | */ |
| 8 | |
| 9 | namespace Give\API\Endpoints\Reports; |
| 10 | |
| 11 | class RecentDonations extends Endpoint { |
| 12 | |
| 13 | public function __construct() { |
| 14 | $this->endpoint = 'recent-donations'; |
| 15 | } |
| 16 | |
| 17 | public function get_report( $request ) { |
| 18 | // Setup donation query args (get sanitized start/end date from request) |
| 19 | $args = array( |
| 20 | 'number' => 50, |
| 21 | 'paged' => 1, |
| 22 | 'orderby' => 'date', |
| 23 | 'order' => 'DESC', |
| 24 | 'start_date' => $request->get_param( 'start' ), |
| 25 | 'end_date' => $request->get_param( 'end' ), |
| 26 | ); |
| 27 | |
| 28 | // Get array of 50 recent donations |
| 29 | $donations = new \Give_Payments_Query( $args ); |
| 30 | $donations = $donations->get_payments(); |
| 31 | |
| 32 | // Populate $list with arrays in correct shape for frontend RESTList component |
| 33 | $data = array(); |
| 34 | foreach ( $donations as $donation ) { |
| 35 | |
| 36 | $donation = new \Give_Payment( $donation->ID ); |
| 37 | |
| 38 | $amount = give_currency_symbol( $donation->currency, true ) . give_format_amount( $donation->total, array( 'sanitize' => false ) ); |
| 39 | $status = null; |
| 40 | switch ( $donation->status ) { |
| 41 | case 'publish': |
| 42 | $meta = $donation->payment_meta; |
| 43 | $status = isset( $meta['_give_is_donation_recurring'] ) && $meta['_give_is_donation_recurring'] ? 'first_renewal' : 'completed'; |
| 44 | break; |
| 45 | case 'give_subscription': |
| 46 | $status = 'renewal'; |
| 47 | break; |
| 48 | default: |
| 49 | $status = $donation->status; |
| 50 | } |
| 51 | $url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . absint( $donation->ID ) ); |
| 52 | |
| 53 | $data[] = [ |
| 54 | 'type' => 'donation', |
| 55 | 'donation' => $donation, |
| 56 | 'status' => $status, |
| 57 | 'amount' => $amount, |
| 58 | 'url' => $url, |
| 59 | 'time' => $donation->date, |
| 60 | 'donor' => array( |
| 61 | 'name' => "{$donation->first_name} {$donation->last_name}", |
| 62 | 'id' => $donation->donor_id, |
| 63 | ), |
| 64 | 'source' => $donation->form_title, |
| 65 | ]; |
| 66 | } |
| 67 | |
| 68 | // Return $list of donations for RESTList component |
| 69 | return $data; |
| 70 | } |
| 71 | } |
| 72 |