Skip to content

Commit 5e08a8c

Browse files
authored
Fix: Expired order refund handler (#856)
1 parent 9a6ec8d commit 5e08a8c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

backend/app/Services/Domain/Payment/Stripe/StripeRefundExpiredOrderService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use HiEvents\DomainObjects\OrderDomainObject;
1111
use HiEvents\DomainObjects\OrganizerDomainObject;
1212
use HiEvents\DomainObjects\StripePaymentDomainObject;
13+
use HiEvents\Exceptions\Stripe\StripeClientConfigurationException;
1314
use HiEvents\Mail\Order\PaymentSuccessButOrderExpiredMail;
1415
use HiEvents\Repository\Eloquent\Value\Relationship;
1516
use HiEvents\Repository\Interfaces\EventRepositoryInterface;
17+
use HiEvents\Services\Infrastructure\Stripe\StripeClientFactory;
1618
use HiEvents\Values\MoneyValue;
1719
use Illuminate\Contracts\Mail\Mailer;
1820
use 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

Comments
 (0)