feat: voucher purchase flow
This commit is contained in:
1 parent
a628e96d06
commit
f3dd122678
70 files changed
+3672
-122
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Model\PurchaseFlow;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Tells the login page which purchase flow, if any, it is the entry to.
|
||||
*
|
||||
* Both a booking and a voucher purchase can be pending in the same session, e.g. when they were
|
||||
* started in two tabs. The one started last wins, which is what the visitor just clicked.
|
||||
*/
|
||||
class PurchaseFlowResolver
|
||||
{
|
||||
public const string LAST_STARTED_KEY = 'purchase_flow_last_started';
|
||||
|
||||
public function markStarted(Request $request, PurchaseFlow $flow): void
|
||||
{
|
||||
$request->getSession()->set(self::LAST_STARTED_KEY, $flow->value);
|
||||
}
|
||||
|
||||
public function resolvePending(Request $request): ?PurchaseFlow
|
||||
{
|
||||
$session = $request->getSession();
|
||||
$hasBooking = $session->has(BookingSessionManager::BOOKING_CREATE_KEY);
|
||||
$hasVoucher = $session->has(VoucherPurchaseSessionManager::SESSION_KEY);
|
||||
|
||||
if (true === $hasBooking && true === $hasVoucher) {
|
||||
return PurchaseFlow::tryFrom((string) $session->get(self::LAST_STARTED_KEY)) ?? PurchaseFlow::Booking;
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$hasBooking => PurchaseFlow::Booking,
|
||||
$hasVoucher => PurchaseFlow::Voucher,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user