From 9597079b08f3a52f06992648d85ce7c695d7c888 Mon Sep 17 00:00:00 2001 From: Dave Earley Date: Thu, 23 Oct 2025 19:16:17 +0100 Subject: [PATCH] Fix: Expired order refund handler --- .../Stripe/StripeRefundExpiredOrderService.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/app/Services/Domain/Payment/Stripe/StripeRefundExpiredOrderService.php b/backend/app/Services/Domain/Payment/Stripe/StripeRefundExpiredOrderService.php index c5473ce8c9..4336f53864 100644 --- a/backend/app/Services/Domain/Payment/Stripe/StripeRefundExpiredOrderService.php +++ b/backend/app/Services/Domain/Payment/Stripe/StripeRefundExpiredOrderService.php @@ -10,9 +10,11 @@ use HiEvents\DomainObjects\OrderDomainObject; use HiEvents\DomainObjects\OrganizerDomainObject; use HiEvents\DomainObjects\StripePaymentDomainObject; +use HiEvents\Exceptions\Stripe\StripeClientConfigurationException; use HiEvents\Mail\Order\PaymentSuccessButOrderExpiredMail; use HiEvents\Repository\Eloquent\Value\Relationship; use HiEvents\Repository\Interfaces\EventRepositoryInterface; +use HiEvents\Services\Infrastructure\Stripe\StripeClientFactory; use HiEvents\Values\MoneyValue; use Illuminate\Contracts\Mail\Mailer; use Psr\Log\LoggerInterface; @@ -26,6 +28,8 @@ public function __construct( private Mailer $mailer, private LoggerInterface $logger, private EventRepositoryInterface $eventRepository, + private StripeClientFactory $stripeClientFactory, + ) { } @@ -36,6 +40,7 @@ public function __construct( * @throws MathException * @throws UnknownCurrencyException * @throws NumberFormatException + * @throws StripeClientConfigurationException */ public function refundExpiredOrder( PaymentIntent $paymentIntent, @@ -48,10 +53,17 @@ public function refundExpiredOrder( ->loadRelation(new Relationship(OrganizerDomainObject::class, name: 'organizer')) ->findById($order->getEventId()); + // Determine the correct Stripe platform for this refund + // Use the platform that was used for the original payment + $paymentPlatform = $stripePayment->getStripePlatformEnum(); + + // Create Stripe client for the original payment's platform + $stripeClient = $this->stripeClientFactory->createForPlatform($paymentPlatform); $this->refundService->refundPayment( MoneyValue::fromMinorUnit($paymentIntent->amount, strtoupper($paymentIntent->currency)), $stripePayment, + $stripeClient ); $this->mailer