2 Commits

3 changed files with 31 additions and 2 deletions

View File

@@ -98,7 +98,10 @@ class CheckoutService
->findOrFail($purchase->getKey());
if (
$purchase->status !== Purchase::STATUS_CREATED
! in_array($purchase->status, [
Purchase::STATUS_CREATED,
Purchase::STATUS_PENDING_PAYMENT,
], true)
|| ($purchase->expires_at !== null && $purchase->expires_at->isPast())
) {
throw ValidationException::withMessages([

View File

@@ -37,7 +37,7 @@ return [
'required_with' => 'El campo :attribute es obligatorio cuando :values está presente.',
'required_without' => 'El campo :attribute es obligatorio cuando :values no está presente.',
'string' => ':Attribute debe ser texto.',
'unique' => 'El valor de :attribute ya está en uso.',
'unique' => 'El :attribute ya está en uso.',
'url' => ':Attribute debe ser una URL válida.',
'uuid' => ':Attribute debe ser un UUID válido.',
'attributes' => [

View File

@@ -304,6 +304,32 @@ class StorePurchaseTest extends TestCase
]);
}
public function test_it_updates_customer_data_for_a_pending_payment_purchase(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
$purchase->update(['status' => Purchase::STATUS_PENDING_PAYMENT]);
$this->actingAs($user, 'sanctum')
->patchJson("/api/tenants/sonder/compras/{$purchase->id}/customer-data", [
'dni' => '987654321',
'telefono' => '+54 9 341 555-4321',
'nombre_apellido' => 'Juan Perez',
'email' => 'juan.perez@example.com',
])
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT)
->assertJsonPath('data.dni', '987654321');
$this->assertDatabaseHas('compras', [
'id' => $purchase->id,
'status' => Purchase::STATUS_PENDING_PAYMENT,
'dni' => '987654321',
]);
}
public function test_it_updates_a_created_purchase_item_quantity_and_its_stock_reservation(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');