Actions
2 weeks ago
DonationAbandoned.php
2 weeks ago
DonationCancelled.php
2 weeks ago
DonationCompleted.php
2 weeks ago
DonationFailed.php
2 weeks ago
DonationPending.php
2 weeks ago
DonationPreapproval.php
2 weeks ago
DonationProcessing.php
2 weeks ago
DonationRefunded.php
2 weeks ago
DonationRevoked.php
2 weeks ago
SubscriptionActive.php
2 years ago
SubscriptionCancelled.php
2 years ago
SubscriptionCompleted.php
2 years ago
SubscriptionExpired.php
2 years ago
SubscriptionFailing.php
2 years ago
SubscriptionFirstDonationCompleted.php
2 weeks ago
SubscriptionPaused.php
1 year ago
SubscriptionPending.php
1 year ago
SubscriptionRenewalDonationCreated.php
1 year ago
SubscriptionSuspended.php
2 years ago
DonationCompleted.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\PaymentGateways\Webhooks\EventHandlers; |
| 4 | |
| 5 | use Exception; |
| 6 | use Give\Donations\Models\Donation; |
| 7 | use Give\Donations\ValueObjects\DonationStatus; |
| 8 | use Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions\UpdateDonationStatus; |
| 9 | |
| 10 | /** |
| 11 | * @since 3.6.0 |
| 12 | */ |
| 13 | class DonationCompleted |
| 14 | { |
| 15 | /** |
| 16 | * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). |
| 17 | * @since 3.6.0 |
| 18 | * @throws Exception |
| 19 | */ |
| 20 | public function __invoke( |
| 21 | string $gatewayTransactionId, |
| 22 | string $message = '', |
| 23 | bool $skipRecurringDonations = false, |
| 24 | int $donationId = 0 |
| 25 | ) { |
| 26 | if ($donationId > 0) { |
| 27 | $donation = Donation::find($donationId); |
| 28 | |
| 29 | if ($donation) { |
| 30 | $donation->gatewayTransactionId = $gatewayTransactionId; |
| 31 | $donation->save(); |
| 32 | } |
| 33 | } else { |
| 34 | $donation = give()->donations->getByGatewayTransactionId($gatewayTransactionId); |
| 35 | } |
| 36 | |
| 37 | if ( ! $donation || $donation->status->isComplete()) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if ($skipRecurringDonations && ! $donation->type->isSingle()) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | (new UpdateDonationStatus())($donation, DonationStatus::COMPLETE(), $message); |
| 46 | } |
| 47 | } |
| 48 |