Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +28,8 @@ public function __construct(
private Mailer $mailer,
private LoggerInterface $logger,
private EventRepositoryInterface $eventRepository,
private StripeClientFactory $stripeClientFactory,

)
{
}
Expand All @@ -36,6 +40,7 @@ public function __construct(
* @throws MathException
* @throws UnknownCurrencyException
* @throws NumberFormatException
* @throws StripeClientConfigurationException
*/
public function refundExpiredOrder(
PaymentIntent $paymentIntent,
Expand All @@ -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
Expand Down
Loading