← All changes
|
src/Framework/PaymentGateways/Webhooks/EventHandlers/DonationCompleted.php
+18
-3
4.15.5
→
4.18.0
View file →
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Give\Framework\PaymentGateways\Webhooks\EventHandlers; |
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | +use Give\Donations\Models\Donation; | |
| 6 | 7 | use Give\Donations\ValueObjects\DonationStatus; |
| 7 | 8 | use Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions\UpdateDonationStatus; |
| 8 | 9 | |
| 9 | 10 | /** |
| @@ -11,14 +12,28 @@ | ||
| 11 | 12 | */ |
| 12 | 13 | class DonationCompleted |
| 13 | 14 | { |
| 14 | 15 | /** |
| 16 | + * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). | |
| 15 | 17 | * @since 3.6.0 |
| 16 | 18 | * @throws Exception |
| 17 | 19 | */ |
| 18 | - public function __invoke(string $gatewayTransactionId, string $message = '', $skipRecurringDonations = false) | |
| 19 | - { | |
| 20 | - $donation = give()->donations->getByGatewayTransactionId($gatewayTransactionId); | |
| 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 | + } | |
| 21 | 36 | |
| 22 | 37 | if ( ! $donation || $donation->status->isComplete()) { |
| 23 | 38 | return; |
| 24 | 39 | } |