# give/4.16.9/src/Revenue/DonationHandler.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.16.9. 43 lines.

- Page: https://pluginprobe.com/plugins/give/4.16.9/code/src/Revenue/DonationHandler.php
- Raw: https://pluginprobe.com/plugins/give/4.16.9/raw/src/Revenue/DonationHandler.php
- Modified: 2025-03-31T19:17:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.16.9/code/src/Revenue/DonationHandler.php#L10-L20`.

```php
<?php

namespace Give\Revenue;

use Give\Revenue\Repositories\Revenue;
use Give\ValueObjects\Money;

/**
 * Class OnDonationHandler
 * @package Give\Revenue
 * @since 2.9.0
 *
 * use this class to insert revenue when new donation create.
 */
class DonationHandler
{
    /**
     * Handle new donation.
     *
     * @since 4.0.0 - set campaign id
     * @since 2.9.0
     *
     * @param int $donationId
     *
     */
    public function handle($donationId)
    {
        $amount = give_donation_amount($donationId);
        $currency = give_get_option('currency');
        $formId = give_get_payment_form_id($donationId);
        $campaign = give()->campaigns->getByFormId($formId);

        $data = [
            'donation_id' => $donationId,
            'form_id' =>  $formId,
            'amount' => Money::of($amount, $currency)->getMinorAmount(),
            'campaign_id' => $campaign ? $campaign->id : null,
        ];

        give(Revenue::class)->insert($data);
    }
}

```
