1010use HiEvents \DomainObjects \OrderDomainObject ;
1111use HiEvents \DomainObjects \OrganizerDomainObject ;
1212use HiEvents \DomainObjects \StripePaymentDomainObject ;
13+ use HiEvents \Exceptions \Stripe \StripeClientConfigurationException ;
1314use HiEvents \Mail \Order \PaymentSuccessButOrderExpiredMail ;
1415use HiEvents \Repository \Eloquent \Value \Relationship ;
1516use HiEvents \Repository \Interfaces \EventRepositoryInterface ;
17+ use HiEvents \Services \Infrastructure \Stripe \StripeClientFactory ;
1618use HiEvents \Values \MoneyValue ;
1719use Illuminate \Contracts \Mail \Mailer ;
1820use Psr \Log \LoggerInterface ;
@@ -26,6 +28,8 @@ public function __construct(
2628 private Mailer $ mailer ,
2729 private LoggerInterface $ logger ,
2830 private EventRepositoryInterface $ eventRepository ,
31+ private StripeClientFactory $ stripeClientFactory ,
32+
2933 )
3034 {
3135 }
@@ -36,6 +40,7 @@ public function __construct(
3640 * @throws MathException
3741 * @throws UnknownCurrencyException
3842 * @throws NumberFormatException
43+ * @throws StripeClientConfigurationException
3944 */
4045 public function refundExpiredOrder (
4146 PaymentIntent $ paymentIntent ,
@@ -48,10 +53,17 @@ public function refundExpiredOrder(
4853 ->loadRelation (new Relationship (OrganizerDomainObject::class, name: 'organizer ' ))
4954 ->findById ($ order ->getEventId ());
5055
56+ // Determine the correct Stripe platform for this refund
57+ // Use the platform that was used for the original payment
58+ $ paymentPlatform = $ stripePayment ->getStripePlatformEnum ();
59+
60+ // Create Stripe client for the original payment's platform
61+ $ stripeClient = $ this ->stripeClientFactory ->createForPlatform ($ paymentPlatform );
5162
5263 $ this ->refundService ->refundPayment (
5364 MoneyValue::fromMinorUnit ($ paymentIntent ->amount , strtoupper ($ paymentIntent ->currency )),
5465 $ stripePayment ,
66+ $ stripeClient
5567 );
5668
5769 $ this ->mailer
0 commit comments