Listeners
5 years ago
Migrations
5 years ago
Repositories
5 years ago
DonationHandler.php
5 years ago
RevenueServiceProvider.php
5 years ago
DonationHandler.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Revenue; |
| 4 | |
| 5 | use Give\Revenue\Repositories\Revenue; |
| 6 | use Give\ValueObjects\Money; |
| 7 | use WP_Post; |
| 8 | |
| 9 | /** |
| 10 | * Class OnDonationHandler |
| 11 | * @package Give\Revenue |
| 12 | * @since 2.9.0 |
| 13 | * |
| 14 | * use this class to insert revenue when new donation create. |
| 15 | */ |
| 16 | class DonationHandler { |
| 17 | /** |
| 18 | * Handle new donation. |
| 19 | * |
| 20 | * @since 2.9.0 |
| 21 | * |
| 22 | * @param int $donationId |
| 23 | * |
| 24 | */ |
| 25 | public function handle( $donationId ) { |
| 26 | /* @var Revenue $revenue */ |
| 27 | $revenue = give( Revenue::class ); |
| 28 | |
| 29 | $revenue->insert( $this->getData( $donationId ) ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get revenue data. |
| 34 | * |
| 35 | * @since 2.9.0 |
| 36 | * |
| 37 | * @param int $donationId |
| 38 | * |
| 39 | * @return array |
| 40 | */ |
| 41 | public function getData( $donationId ) { |
| 42 | /* @var Revenue $revenue */ |
| 43 | $amount = give_donation_amount( $donationId ); |
| 44 | $currency = give_get_option( 'currency' ); |
| 45 | $money = Money::of( $amount, $currency ); |
| 46 | $formId = give_get_payment_form_id( $donationId ); |
| 47 | |
| 48 | return [ |
| 49 | 'donation_id' => $donationId, |
| 50 | 'form_id' => $formId, |
| 51 | 'amount' => $money->getMinorAmount(), |
| 52 | ]; |
| 53 | } |
| 54 | } |
| 55 |