← All changes
|
src/Framework/PaymentGateways/Webhooks/EventHandlers/SubscriptionFirstDonationCompleted.php
+18
-3
4.17.0
→
4.18.0
View file →
| @@ -16,8 +16,9 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | class SubscriptionFirstDonationCompleted |
| 18 | 18 | { |
| 19 | 19 | /** |
| 20 | + * @since 4.18.0 Guard against a null initial donation and a missing subscription instead of fataling on them. | |
| 20 | 21 | * @since 4.16.0 Add $donationId to support gateways that only receive the transaction ID via webhook (e.g. PayFast). |
| 21 | 22 | * @since 4.5.0 Add $setDonationComplete and $gatewaySubscriptionId parameters |
| 22 | 23 | * @since 3.6.0 |
| 23 | 24 | */ |
| @@ -46,14 +47,28 @@ | ||
| 46 | 47 | $donation = give()->donations->getByGatewayTransactionId($gatewayTransactionId); |
| 47 | 48 | |
| 48 | 49 | if (! $donation && ! empty($gatewaySubscriptionId) && $subscription = give()->subscriptions->getByGatewaySubscriptionId($gatewaySubscriptionId)) { |
| 49 | 50 | $donation = $subscription->initialDonation(); |
| 50 | - $donation->gatewayTransactionId = $gatewayTransactionId; | |
| 51 | - $donation->save(); | |
| 51 | + | |
| 52 | + if ($donation) { | |
| 53 | + $donation->gatewayTransactionId = $gatewayTransactionId; | |
| 54 | + $donation->save(); | |
| 55 | + } | |
| 52 | 56 | } |
| 53 | 57 | } |
| 54 | 58 | |
| 55 | - if ( ! $donation || ! $donation->type->isSubscription() || $donation->id !== $donation->subscription->initialDonation()->id) { | |
| 59 | + if ( ! $donation || ! $donation->subscription || ! $donation->type->isSubscription()) { | |
| 60 | + PaymentGatewayLog::error( | |
| 61 | + sprintf('The first donation was not updated for the gateway transaction ID %s because no valid subscription donation was found to update.', | |
| 62 | + $gatewayTransactionId), | |
| 63 | + [ | |
| 64 | + 'Gateway Subscription ID' => $gatewaySubscriptionId, | |
| 65 | + 'Gateway Transaction ID' => $gatewayTransactionId, | |
| 66 | + 'Donation ID' => $donationId, | |
| 67 | + 'Message' => $message, | |
| 68 | + ] | |
| 69 | + ); | |
| 70 | + | |
| 56 | 71 | return; |
| 57 | 72 | } |
| 58 | 73 | |
| 59 | 74 | try { |