- Introduced a new configuration file for purchase settings, including checkout and payment expiration times. - Added a migration to include a `reservation_status` column in the `compra_items` table, defaulting to 'active' and updating existing records based on purchase status. - Created a migration to add an `expires_at` timestamp to the `compras` table, updating it for existing records based on their status. - Scoped unique indexes in the `carritos` table to only active carts, adding virtual columns for active user and guest tokens. - Implemented a console command to expire overdue purchases and release stock reservations, scheduled to run every minute. - Added tests for Google token exchange and login functionality, ensuring proper cart handling and user authentication. - Updated purchase-related tests to reflect changes in item handling and customer data validation.
51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Auth\Controllers;
|
|
|
|
use App\Domains\Auth\Requests\GoogleTokenExchangeRequest;
|
|
use App\Domains\Auth\Resources\UserResource;
|
|
use App\Domains\Auth\Services\GoogleAuthService;
|
|
use App\Domains\Cart\Services\GuestCartMergeService;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Cookie;
|
|
|
|
class GoogleTokenExchangeController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly GoogleAuthService $googleAuthService,
|
|
private readonly GuestCartMergeService $guestCartMergeService,
|
|
) {}
|
|
|
|
public function __invoke(GoogleTokenExchangeRequest $request): JsonResponse
|
|
{
|
|
$authentication = $this->googleAuthService->exchange(
|
|
$request->validated('oauth_code'),
|
|
$request->validated('tenant_codigo'),
|
|
);
|
|
|
|
$guestTokenCookie = $request->cookie('guest_token');
|
|
$guestToken = is_string($guestTokenCookie) && $guestTokenCookie !== ''
|
|
? $guestTokenCookie
|
|
: null;
|
|
$this->guestCartMergeService->merge(
|
|
$authentication['tenant_codigo'],
|
|
$authentication['user'],
|
|
$guestToken,
|
|
);
|
|
|
|
$response = response()->json([
|
|
'message' => 'Sesion iniciada correctamente.',
|
|
'token' => $authentication['token'],
|
|
'token_type' => 'Bearer',
|
|
'user' => UserResource::make($authentication['user']),
|
|
]);
|
|
|
|
if ($guestToken !== null) {
|
|
$response->withCookie(Cookie::forget('guest_token'));
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|