refactor(checkout): remove unused completion endpoint

This commit is contained in:
ncoronel 2026-08-27 12:11:08 -03:00
parent 2524f00dfd
commit 971c5f6cd9
6 changed files with 2 additions and 115 deletions

View File

@ -243,15 +243,6 @@ class PurchaseController extends Controller
], 400);
}
public function complete(Request $request, Tenant $tenant, Purchase $compra, CheckoutService $checkoutService): PurchaseResource
{
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
return PurchaseResource::make(
$checkoutService->completePurchase($compra)
);
}
public function submitForReview(
Request $request,
Tenant $tenant,

View File

@ -18,33 +18,6 @@ class CompleteCheckoutService
private readonly PurchaseStateGuard $purchaseState,
) {}
public function complete(Purchase $purchase): Purchase
{
return DB::transaction(function () use ($purchase): Purchase {
$purchase = $this->lockPurchase($purchase);
$this->purchaseState->assertNotExpired($purchase);
if ($purchase->payment_method === null) {
throw ValidationException::withMessages([
'payment_method' => __('api.purchase.payment_method_required'),
]);
}
if ($this->isTerminal($purchase)) {
return $this->loadPurchase($purchase);
}
$this->purchaseState->lockCurrentCart($purchase);
$purchase->update([
'status' => Purchase::STATUS_PENDING_PAYMENT,
'total' => $purchase->calculateCurrentTotalAmount(),
]);
return $this->loadPurchase($purchase);
});
}
public function submitForReview(Purchase $purchase): Purchase
{
return DB::transaction(function () use ($purchase): Purchase {
@ -171,18 +144,6 @@ class CompleteCheckoutService
});
}
private function isTerminal(Purchase $purchase): bool
{
return in_array($purchase->status, [
Purchase::STATUS_PAID,
Purchase::STATUS_IN_REVIEW,
Purchase::STATUS_CANCELLED,
Purchase::STATUS_REJECTED,
Purchase::STATUS_EXPIRED,
Purchase::STATUS_SUPERSEDED,
], true);
}
private function lockPurchase(Purchase $purchase): Purchase
{
/** @var Purchase */

View File

@ -30,11 +30,6 @@ class CheckoutService
return $this->starter->start($tenant, $userId, $purchaseData);
}
public function completePurchase(Purchase $purchase): Purchase
{
return $this->completer->complete($purchase);
}
public function submitForReview(Purchase $purchase): Purchase
{
return $this->completer->submitForReview($purchase);

View File

@ -9,7 +9,6 @@ Route::prefix('tenants/{tenant:codigo}')->middleware('auth:sanctum')->group(func
Route::get('compras/{compra}', [PurchaseController::class, 'show']);
Route::patch('compras/{compra}/customer-data', [PurchaseController::class, 'updateCustomerData']);
Route::post('compras/{compra}/payment-intent', [PurchaseController::class, 'paymentIntent']);
Route::post('compras/{compra}/complete', [PurchaseController::class, 'complete']);
Route::post('compras/{compra}/review', [PurchaseController::class, 'submitForReview']);
Route::post('compras/{compra}/cancel', [PurchaseController::class, 'cancel']);
});

View File

@ -199,7 +199,7 @@ class BundleCatalogItemTest extends TestCase
'email' => 'bundle@example.com',
]);
$purchase->update(['payment_method' => 'transfer']);
$checkoutService->confirmPurchase($checkoutService->completePurchase($purchase));
$checkoutService->confirmPurchase($purchase);
$this->assertDatabaseCount('compra_items', 1);
$this->assertDatabaseHas('compra_items', [

View File

@ -898,57 +898,6 @@ class StorePurchaseTest extends TestCase
]);
}
public function test_it_moves_a_created_purchase_to_pending_payment_when_finalized(): void
{
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create([
'email' => 'buyer@example.com',
]);
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
$cartId = $this->actingAs($user, 'sanctum')
->postJson('/api/tenants/sonder/cart/items', [
'catalog_item_id' => $variant->catalog_item_id,
'variant_id' => $variant->id,
'cantidad' => 2,
])
->assertOk()
->json('data.id');
$purchaseId = $this->actingAs($user, 'sanctum')
->postJson('/api/tenants/sonder/compras/start-checkout', [
'cart_id' => $cartId,
])
->assertCreated()
->json('data.id');
Purchase::query()
->whereKey($purchaseId)
->update([
'payment_method' => 'transfer',
]);
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchaseId}/complete")
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT);
$this->assertDatabaseHas('compras', [
'id' => $purchaseId,
'status' => Purchase::STATUS_PENDING_PAYMENT,
'payment_method' => 'transfer',
]);
$this->assertDatabaseHas('value_changes', [
'trackable_type' => (new Purchase)->getMorphClass(),
'trackable_id' => $purchaseId,
'attribute' => 'status',
'old_value' => Purchase::STATUS_CREATED,
'new_value' => Purchase::STATUS_PENDING_PAYMENT,
'actor_type' => 'user',
'user_id' => $user->id,
]);
}
public function test_it_moves_a_submitted_purchase_to_review_idempotently(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
@ -984,11 +933,6 @@ class StorePurchaseTest extends TestCase
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchase->id}/complete")
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchase->id}/payment-intent", [
'method' => 'qr',
@ -1204,10 +1148,9 @@ class StorePurchaseTest extends TestCase
$purchase->update([
'payment_method' => 'transfer',
'status' => Purchase::STATUS_PENDING_PAYMENT,
]);
app(CheckoutService::class)->completePurchase($purchase);
$this->actingAs($user, 'sanctum')
->getJson("/api/tenants/sonder/compras/{$purchase->id}")
->assertOk()
@ -1260,7 +1203,6 @@ class StorePurchaseTest extends TestCase
]);
$checkoutService = app(CheckoutService::class);
$purchase = $checkoutService->completePurchase($purchase);
$checkoutService->confirmPurchase($purchase);
$purchase->refresh()->markAsPaid();
@ -1478,7 +1420,6 @@ class StorePurchaseTest extends TestCase
$purchase->update(['payment_method' => 'transfer']);
$checkoutService = app(CheckoutService::class);
$purchase = $checkoutService->completePurchase($purchase);
$checkoutService->confirmPurchase($purchase);
$checkoutService->confirmPurchase($purchase);