PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / API / Endpoints / Reports / RecentDonations.php

RecentDonations.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/API/Endpoints/Reports/RecentDonations.php

65 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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