PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 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 All 257 releases
give / src / Donations / ServiceProvider.php

ServiceProvider.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/Donations/ServiceProvider.php

171 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Donations;
4
5 use Give\Donations\Actions\LoadDonationAdminOptions;
6 use Give\Donations\CustomFields\Controllers\DonationDetailsController;
7 use Give\Donations\LegacyListeners\ClearDonationPostCache;
8 use Give\Donations\LegacyListeners\DispatchDonationNoteEmailNotification;
9 use Give\Donations\LegacyListeners\DispatchGiveInsertPayment;
10 use Give\Donations\LegacyListeners\DispatchGivePreInsertPayment;
11 use Give\Donations\LegacyListeners\DispatchGiveRecurringAddSubscriptionPaymentAndRecordPayment;
12 use Give\Donations\LegacyListeners\DispatchGiveUpdatePaymentStatus;
13 use Give\Donations\LegacyListeners\InsertSequentialId;
14 use Give\Donations\LegacyListeners\RemoveSequentialId;
15 use Give\Donations\LegacyListeners\UpdateDonorPaymentIds;
16 use Give\Donations\LegacyListeners\UpdateDonationMetaWithLegacyFormCurrencySettings;
17 use Give\Donations\Listeners\DonationCreated\UpdateDonationMetaWithCurrencySettings;
18 use Give\Donations\Listeners\DonationCreated\UpdateDonorMetaWithLastDonatedCurrency;
19 use Give\Donations\ListTable\DonationsListTable;
20 use Give\Donations\Migrations\AddIndexesToDonationMetaTable;
21 use Give\Donations\Migrations\AddMissingDonorIdToDonationComments;
22 use Give\Donations\Migrations\MoveDonationCommentToDonationMetaTable;
23 use Give\Donations\Migrations\RecalculateExchangeRate;
24 use Give\Donations\Migrations\SanitizeSerializedObjectPayloads;
25 use Give\Donations\Migrations\SetAutomaticFormattingOption;
26 use Give\Donations\Migrations\UnserializeTitlePrefix;
27 use Give\Donations\Models\Donation;
28 use Give\Donations\Repositories\DonationNotesRepository;
29 use Give\Donations\Repositories\DonationRepository;
30 use Give\Framework\Migrations\MigrationsRegister;
31 use Give\Helpers\Hooks;
32 use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
33
34 class ServiceProvider implements ServiceProviderInterface
35 {
36 /**
37 * @inheritDoc
38 */
39 public function register()
40 {
41 give()->singleton('donations', DonationRepository::class);
42 give()->singleton('donationNotes', DonationNotesRepository::class);
43 give()->singleton(DonationsListTable::class, function () {
44 $listTable = new DonationsListTable();
45 Hooks::doAction('givewp_donations_list_table', $listTable);
46
47 return $listTable;
48 });
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function boot()
55 {
56 $this->bootListeners();
57 $this->bootLegacyListeners();
58 $this->registerDonationsAdminPage();
59 $this->addCustomFieldsToDonationDetails();
60 $this->loadDonationAdminOptions();
61
62 give(MigrationsRegister::class)->addMigrations([
63 AddMissingDonorIdToDonationComments::class,
64 SetAutomaticFormattingOption::class,
65 MoveDonationCommentToDonationMetaTable::class,
66 UnserializeTitlePrefix::class,
67 RecalculateExchangeRate::class,
68 SanitizeSerializedObjectPayloads::class,
69 AddIndexesToDonationMetaTable::class,
70 ]);
71 }
72
73 /**
74 * Legacy Listeners
75 * @since 2.25.0 Call ClearDonationPostCache on the "givewp_donation_updated" hook
76 * @since 2.24.0 Remove UpdateSequentialId from "givewp_donation_updated" action hook.
77 * @since 2.19.6
78 */
79 private function bootLegacyListeners()
80 {
81 Hooks::addAction('givewp_donation_creating', DispatchGivePreInsertPayment::class);
82
83 add_action('givewp_donation_created', static function (Donation $donation) {
84 (new UpdateDonationMetaWithLegacyFormCurrencySettings())($donation);
85 (new InsertSequentialId())($donation);
86 (new DispatchGiveInsertPayment())($donation);
87 (new UpdateDonorPaymentIds())($donation);
88
89 if ($donation->subscriptionId && $donation->type->isRenewal()) {
90 (new DispatchGiveRecurringAddSubscriptionPaymentAndRecordPayment())($donation);
91 }
92
93 /**
94 * @notice
95 * Anytime we call give_update_payment_status the donor purchase_value and purchase_count get affected.
96 * We are doing this in the gateway api and in many other places.
97 * The listener below matches the functionality but the count seems to be overwritten elsewhere.
98 * Leaving this commented out until resolved or needed.
99 */
100 //Call::invoke(UpdateDonorPurchaseValueAndCount::class, $donation);
101 });
102
103 add_action('givewp_donation_updated', function (Donation $donation) {
104 (new ClearDonationPostCache())($donation);
105 (new DispatchGiveUpdatePaymentStatus())($donation);
106 });
107
108 Hooks::addAction('givewp_donation_deleted', RemoveSequentialId::class);
109
110 add_action('givewp_donation_note_created', static function ($donationNote) {
111 if ($donationNote->type->isDonor()) {
112 (new DispatchDonationNoteEmailNotification())($donationNote);
113 }
114 });
115 }
116
117 /**
118 * Donations Admin page
119 *
120 * @since 4.14.0 defer conditionals and DB queries to admin_menu hook.
121 * @since 2.20.0
122 */
123 private function registerDonationsAdminPage()
124 {
125 add_action('admin_menu', function () {
126 $userId = get_current_user_id();
127 $showLegacy = get_user_meta($userId, '_give_donations_archive_show_legacy', true);
128
129 // only register new admin page if user hasn't chosen to use the old one
130 if (empty($showLegacy)) {
131 give(DonationsAdminPage::class)->registerMenuItem();
132 }
133 }, 20);
134 }
135
136 /**
137 * @since 3.0.0
138 */
139 private function addCustomFieldsToDonationDetails()
140 {
141 add_action('give_view_donation_details_billing_after', static function ($donationId) {
142 echo (new DonationDetailsController())->show($donationId);
143 });
144 }
145
146 /**
147 * @since 4.2.0
148 */
149 private function bootListeners()
150 {
151 add_action('givewp_donation_created', static function (Donation $donation) {
152 (new UpdateDonationMetaWithCurrencySettings())($donation);
153
154 (new UpdateDonorMetaWithLastDonatedCurrency())($donation);
155 });
156 }
157
158 /**
159 * @since 4.6.1 Move to admin_enqueue_scripts hook
160 * @since 4.6.0
161 */
162 private function loadDonationAdminOptions()
163 {
164 add_action('admin_enqueue_scripts', function () {
165 if (DonationsAdminPage::isShowingDetailsPage()) {
166 give(LoadDonationAdminOptions::class)();
167 }
168 });
169 }
170 }
171