subscription('default'); if ($subscription === null || $subscription->refunded_at !== null) { return; } $payment = $subscription->latestPayment(); if ($payment !== null) { $user->refund($payment->asStripePaymentIntent()->id); } $subscription->forceFill(['refunded_at' => now()])->save(); try { $subscription->cancelNow(); $user->bankingConnections()->get()->each(function (BankingConnection $connection): void { $this->disconnect->handle($connection, deleteAccounts: false); }); } catch (\Throwable $exception) { Log::error('Self-serve refund issued but post-refund cleanup failed', [ 'user_id' => $user->getKey(), 'subscription_id' => $subscription->getKey(), 'error' => $exception->getMessage(), ]); } } }