1313use Illuminate \Cache \Repository ;
1414use Illuminate \Log \Logger ;
1515use JsonException ;
16+ use Stripe \Charge ;
1617use Stripe \Event ;
1718use Stripe \Exception \SignatureVerificationException ;
1819use 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