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