LegacyListeners
2 years ago
Listeners
5 months ago
Migrations
9 months ago
Repositories
1 year ago
DonationHandler.php
1 year ago
RevenueServiceProvider.php
5 months ago
DonationHandler.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Revenue; |
| 4 | |
| 5 | use Give\Revenue\Repositories\Revenue; |
| 6 | use Give\ValueObjects\Money; |
| 7 | |
| 8 | /** |
| 9 | * Class OnDonationHandler |
| 10 | * @package Give\Revenue |
| 11 | * @since 2.9.0 |
| 12 | * |
| 13 | * use this class to insert revenue when new donation create. |
| 14 | */ |
| 15 | class DonationHandler |
| 16 | { |
| 17 | /** |
| 18 | * Handle new donation. |
| 19 | * |
| 20 | * @since 4.0.0 - set campaign id |
| 21 | * @since 2.9.0 |
| 22 | * |
| 23 | * @param int $donationId |
| 24 | * |
| 25 | */ |
| 26 | public function handle($donationId) |
| 27 | { |
| 28 | $amount = give_donation_amount($donationId); |
| 29 | $currency = give_get_option('currency'); |
| 30 | $formId = give_get_payment_form_id($donationId); |
| 31 | $campaign = give()->campaigns->getByFormId($formId); |
| 32 | |
| 33 | $data = [ |
| 34 | 'donation_id' => $donationId, |
| 35 | 'form_id' => $formId, |
| 36 | 'amount' => Money::of($amount, $currency)->getMinorAmount(), |
| 37 | 'campaign_id' => $campaign ? $campaign->id : null, |
| 38 | ]; |
| 39 | |
| 40 | give(Revenue::class)->insert($data); |
| 41 | } |
| 42 | } |
| 43 |