Skip to content

Commit 081c1a0

Browse files
mrjbjdaveearley
andauthored
Handle CHARGE_REFUNDED and REFUND_CREATED events for Non-SaaS Stripe Integration on Refunds 🤖 (#1156)
Co-authored-by: Dave Earley <dave@hi.events>
1 parent 3109cad commit 081c1a0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

backend/app/Services/Application/Handlers/Order/Payment/Stripe/IncomingWebhookHandler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Cache\Repository;
1414
use Illuminate\Log\Logger;
1515
use JsonException;
16+
use Stripe\Charge;
1617
use Stripe\Event;
1718
use Stripe\Exception\SignatureVerificationException;
1819
use Stripe\Webhook;
@@ -27,6 +28,8 @@ class IncomingWebhookHandler
2728
Event::PAYMENT_INTENT_PAYMENT_FAILED,
2829
Event::ACCOUNT_UPDATED,
2930
Event::REFUND_UPDATED,
31+
Event::REFUND_CREATED,
32+
Event::CHARGE_REFUNDED,
3033
Event::CHARGE_SUCCEEDED,
3134
Event::CHARGE_UPDATED,
3235
Event::PAYOUT_PAID,
@@ -92,8 +95,12 @@ public function handle(StripeWebhookDTO $webhookDTO): void
9295
$this->chargeSucceededHandler->handleEvent($event->data->object);
9396
break;
9497
case Event::REFUND_UPDATED:
98+
case Event::REFUND_CREATED:
9599
$this->refundEventHandlerService->handleEvent($event->data->object);
96100
break;
101+
case Event::CHARGE_REFUNDED:
102+
$this->handleChargeRefunded($event->data->object);
103+
break;
97104
case Event::ACCOUNT_UPDATED:
98105
$this->accountUpdateHandler->handleEvent($event->data->object);
99106
break;
@@ -170,6 +177,15 @@ private function hasEventBeenHandled(Event $event): bool
170177
return $this->cache->has('stripe_event_' . $event->id);
171178
}
172179

180+
private function handleChargeRefunded(Charge $charge): void
181+
{
182+
$refunds = $charge->refunds->data ?? [];
183+
184+
foreach ($refunds as $refund) {
185+
$this->refundEventHandlerService->handleEvent($refund);
186+
}
187+
}
188+
173189
private function markEventAsHandled(Event $event): void
174190
{
175191
$this->logger->info('Marking Stripe event as handled', [

0 commit comments

Comments
 (0)