LegacyListeners
2 years ago
Listeners
2 years ago
Migrations
4 years ago
Repositories
2 years ago
DonationHandler.php
4 years ago
RevenueServiceProvider.php
2 years ago
DonationHandler.php
57 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 2.9.0 |
| 21 | * |
| 22 | * @param int $donationId |
| 23 | * |
| 24 | */ |
| 25 | public function handle($donationId) |
| 26 | { |
| 27 | /* @var Revenue $revenue */ |
| 28 | $revenue = give(Revenue::class); |
| 29 | |
| 30 | $revenue->insert($this->getData($donationId)); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get revenue data. |
| 35 | * |
| 36 | * @since 2.9.0 |
| 37 | * |
| 38 | * @param int $donationId |
| 39 | * |
| 40 | * @return array |
| 41 | */ |
| 42 | public function getData($donationId) |
| 43 | { |
| 44 | /* @var Revenue $revenue */ |
| 45 | $amount = give_donation_amount($donationId); |
| 46 | $currency = give_get_option('currency'); |
| 47 | $money = Money::of($amount, $currency); |
| 48 | $formId = give_get_payment_form_id($donationId); |
| 49 | |
| 50 | return [ |
| 51 | 'donation_id' => $donationId, |
| 52 | 'form_id' => $formId, |
| 53 | 'amount' => $money->getMinorAmount(), |
| 54 | ]; |
| 55 | } |
| 56 | } |
| 57 |