AverageDonation.php
5 years ago
DonationsVsIncome.php
5 years ago
Endpoint.php
5 years ago
FormPerformance.php
5 years ago
Income.php
5 years ago
IncomeBreakdown.php
5 years ago
PaymentMethods.php
5 years ago
PaymentStatuses.php
5 years ago
RecentDonations.php
5 years ago
TopDonors.php
5 years ago
TotalDonors.php
5 years ago
TotalIncome.php
5 years ago
TotalRefunds.php
5 years ago
RecentDonations.php
58 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 getReport( $request ) { |
| 18 | |
| 19 | $paymentObjects = $this->getPayments( $request->get_param( 'start' ), $request->get_param( 'end' ), 'date', 50 ); |
| 20 | |
| 21 | // Populate $list with arrays in correct shape for frontend RESTList component |
| 22 | $data = []; |
| 23 | foreach ( $paymentObjects as $paymentObject ) { |
| 24 | $amount = give_currency_symbol( $paymentObject->currency, true ) . give_format_amount( $paymentObject->total, [ 'sanitize' => false ] ); |
| 25 | $status = null; |
| 26 | switch ( $paymentObject->status ) { |
| 27 | case 'publish': |
| 28 | $meta = $paymentObject->payment_meta; |
| 29 | $status = isset( $meta['_give_is_donation_recurring'] ) && $meta['_give_is_donation_recurring'] ? 'first_renewal' : 'completed'; |
| 30 | break; |
| 31 | case 'give_subscription': |
| 32 | $status = 'renewal'; |
| 33 | break; |
| 34 | default: |
| 35 | $status = $paymentObject->status; |
| 36 | } |
| 37 | $url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . absint( $paymentObject->ID ) ); |
| 38 | |
| 39 | $data[] = [ |
| 40 | 'type' => 'donation', |
| 41 | 'donation' => $paymentObject, |
| 42 | 'status' => $status, |
| 43 | 'amount' => $amount, |
| 44 | 'url' => $url, |
| 45 | 'time' => $paymentObject->date, |
| 46 | 'donor' => [ |
| 47 | 'name' => "{$paymentObject->first_name} {$paymentObject->last_name}", |
| 48 | 'id' => $paymentObject->donor_id, |
| 49 | ], |
| 50 | 'source' => $paymentObject->form_title, |
| 51 | ]; |
| 52 | } |
| 53 | |
| 54 | // Return $list of donations for RESTList component |
| 55 | return $data; |
| 56 | } |
| 57 | } |
| 58 |