'int', 'campaignId' => 'int', 'formId' => 'int', 'formTitle' => 'string', 'purchaseKey' => 'string', 'donorIp' => 'string', 'createdAt' => DateTime::class, 'updatedAt' => DateTime::class, 'status' => DonationStatus::class, 'type' => DonationType::class, 'mode' => DonationMode::class, 'amount' => Money::class, 'feeAmountRecovered' => Money::class, 'exchangeRate' => ['string', '1'], 'gatewayId' => 'string', 'donorId' => 'int', 'honorific' => 'string', 'firstName' => 'string', 'lastName' => 'string', 'email' => 'string', 'phone' => 'string', 'subscriptionId' => ['int', 0], 'billingAddress' => BillingAddress::class, 'anonymous' => ['bool', false], 'levelId' => ['string', ''], 'gatewayTransactionId' => 'string', 'company' => 'string', 'comment' => 'string', ]; /** * @inheritdoc */ protected $relationships = [ 'campaign' => Relationship::BELONGS_TO, 'donor' => Relationship::BELONGS_TO, 'subscription' => Relationship::BELONGS_TO, 'notes' => Relationship::HAS_MANY, 'eventTickets' => Relationship::HAS_MANY, ]; /** * Find donation by ID * * @since 2.19.6 * * @param int $id * * @return Donation|null */ public static function find($id) { return give()->donations->getById($id); } /** * @since 2.20.0 return mutated model instance * @since 2.19.6 * * @throws Exception|InvalidArgumentException */ public static function create(array $attributes): Donation { $donation = new static($attributes); give()->donations->insert($donation); return $donation; } /** * @since 2.20.0 mutate model in repository and return void * @since 2.19.6 * * @return void * * @throws Exception|InvalidArgumentException */ public function save() { if (!$this->id) { give()->donations->insert($this); } else { give()->donations->update($this); } } /** * @since 2.19.6 * * @throws Exception|InvalidArgumentException */ public function delete(): bool { return give()->donations->delete($this); } /** * @since 4.6.0 * * @throws Exception|InvalidArgumentException */ public function trash(): bool { return give()->donations->trash($this); } /** * @since 4.12.0 * * @throws Exception|InvalidArgumentException */ public function unTrash(): bool { return give()->donations->unTrash($this); } /** * @since 2.19.6 * * @return ModelQueryBuilder */ public function donor(): ModelQueryBuilder { return give()->donors->queryById($this->donorId); } /** * @since 2.19.6 * * @return ModelQueryBuilder */ public function subscription(): ModelQueryBuilder { if ($this->subscriptionId) { return give()->subscriptions->queryById($this->subscriptionId); } return give()->subscriptions->queryByDonationId($this->id); } /** * @since 4.0.0 * * @return ModelQueryBuilder */ public function campaign(): ModelQueryBuilder { return give()->campaigns->queryById($this->campaignId); } /** * @since 2.19.6 * * @return int|null */ public function getSequentialId() { return give()->donations->getSequentialId($this->id); } /** * @since 2.19.6 * * @return ModelQueryBuilder */ public function notes(): ModelQueryBuilder { return give()->donations->notes->queryByDonationId($this->id); } /** * Returns the amount charged in the currency the GiveWP site is set to * * @since 2.20.0 */ public function amountInBaseCurrency(): Money { return $this->amount->inBaseCurrency($this->exchangeRate); } /** * Returns the donation amount the donor "intended", which means it is the amount without recovered fees. So if the * donor paid $100, but the donation was charged $105 with a $5 fee, this method will return $100. * * @since 2.20.0 */ public function intendedAmount(): Money { return $this->feeAmountRecovered === null ? $this->amount : $this->amount->subtract($this->feeAmountRecovered); } /** * @since 4.6.0 */ public function eventTicketsAmount(): Money { return give(EventTicketRepository::class)->getTotalByDonation($this); } /** * @since 4.6.0 */ public function eventTickets(): ModelQueryBuilder { return give(EventTicketRepository::class)->queryByDonationId($this->id); } /** * Returns the amount intended in the currency the GiveWP site is set to * * @since 2.20.0 */ public function intendedAmountInBaseCurrency(): Money { return $this->intendedAmount()->inBaseCurrency($this->exchangeRate); } /** * Returns the gateway instance for this donation * * @since 2.20.0 */ public function gateway(): PaymentGateway { return give()->gateways->getPaymentGateway($this->gatewayId); } /** * @since 4.3.0 */ public function receipt(): DonationReceipt { return give()->donations->getConfirmationPageReceipt($this); } /** * @since 2.20.0 * * @inheritDoc */ protected function getPropertyDefaults(): array { return array_merge(parent::getPropertyDefaults(), [ 'mode' => give_is_test_mode() ? DonationMode::TEST() : DonationMode::LIVE(), 'donorIp' => give_get_ip(), 'billingAddress' => new BillingAddress(), ]); } /** * @since 2.19.6 * * @return ModelQueryBuilder */ public static function query(): ModelQueryBuilder { return give()->donations->prepareQuery(); } /** * @since 2.19.6 * * @param object $object */ public static function fromQueryBuilderObject($object): Donation { return DonationQueryData::fromObject($object)->toDonation(); } /** * @since 2.19.6 */ public static function factory(): DonationFactory { return new DonationFactory(static::class); } }