Actions
4 years ago
DataTransferObjects
4 years ago
Factories
4 years ago
LegacyListeners
4 years ago
Models
4 years ago
Properties
4 years ago
Repositories
4 years ago
ValueObjects
4 years ago
ServiceProvider.php
4 years ago
ServiceProvider.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Donations; |
| 4 | |
| 5 | use Give\Donations\LegacyListeners\DispatchGiveInsertPayment; |
| 6 | use Give\Donations\LegacyListeners\DispatchGiveRecurringAddSubscriptionPaymentAndRecordPayment; |
| 7 | use Give\Donations\LegacyListeners\DispatchGiveUpdatePaymentStatus; |
| 8 | use Give\Donations\LegacyListeners\InsertSequentialId; |
| 9 | use Give\Donations\LegacyListeners\RemoveSequentialId; |
| 10 | use Give\Donations\LegacyListeners\UpdateDonorPaymentIds; |
| 11 | use Give\Donations\LegacyListeners\UpdateSequentialId; |
| 12 | use Give\Donations\Models\Donation; |
| 13 | use Give\Donations\Repositories\DonationRepository; |
| 14 | use Give\Helpers\Call; |
| 15 | use Give\Helpers\Hooks; |
| 16 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 17 | |
| 18 | class ServiceProvider implements ServiceProviderInterface |
| 19 | { |
| 20 | /** |
| 21 | * @inheritDoc |
| 22 | */ |
| 23 | public function register() |
| 24 | { |
| 25 | give()->singleton('donations', DonationRepository::class); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @inheritDoc |
| 30 | */ |
| 31 | public function boot() |
| 32 | { |
| 33 | $this->bootLegacyListeners(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Legacy Listeners |
| 38 | * |
| 39 | * @since 2.19.6 |
| 40 | */ |
| 41 | private function bootLegacyListeners() |
| 42 | { |
| 43 | add_action('give_donation_created', function (Donation $donation) { |
| 44 | Call::invoke(InsertSequentialId::class, $donation); |
| 45 | Call::invoke(DispatchGiveInsertPayment::class, $donation); |
| 46 | Call::invoke(UpdateDonorPaymentIds::class, $donation); |
| 47 | |
| 48 | if ($donation->subscriptionId) { |
| 49 | Call::invoke(DispatchGiveRecurringAddSubscriptionPaymentAndRecordPayment::class, $donation); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @notice |
| 54 | * Anytime we call give_update_payment_status the donor purchase_value and purchase_count get affected. |
| 55 | * We are doing this in the gateway api and in many other places. |
| 56 | * The listener below matches the functionality but the count seems to be overwritten elsewhere. |
| 57 | * Leaving this commented out until resolved or needed. |
| 58 | */ |
| 59 | //Call::invoke(UpdateDonorPurchaseValueAndCount::class, $donation); |
| 60 | }); |
| 61 | |
| 62 | add_action('give_donation_updated', function (Donation $donation) { |
| 63 | Call::invoke(DispatchGiveUpdatePaymentStatus::class, $donation); |
| 64 | Call::invoke(UpdateSequentialId::class, $donation); |
| 65 | }); |
| 66 | |
| 67 | Hooks::addAction('give_donation_deleted', RemoveSequentialId::class); |
| 68 | } |
| 69 | } |
| 70 |