feat: refactor purchase status handling and add finalize endpoint for purchases

This commit is contained in:
2026-07-07 15:33:29 -03:00
parent 786b4eb6a9
commit c276ccd311
11 changed files with 220 additions and 27 deletions

View File

@@ -55,7 +55,7 @@ class TelepagosWebhookService
$compra = Purchase::where('tenant_codigo', $tenantCodigo)
->where('dni', $dni)
->where('status', 'pending')
->where('status', Purchase::STATUS_PENDING_PAYMENT)
->where('payment_method', 'transfer')
->where('total', $amount)
->latest()
@@ -85,6 +85,11 @@ class TelepagosWebhookService
return;
}
if ($compra->status !== Purchase::STATUS_PENDING_PAYMENT) {
Log::warning("Telepagos webhook: Purchase {$compra->id} is not awaiting payment confirmation");
return;
}
$totalAmount = $this->normalizeAmount($compra->getTotalAmount());
if ($amount !== $totalAmount) {
@@ -112,7 +117,7 @@ class TelepagosWebhookService
\Illuminate\Support\Facades\DB::transaction(function () use ($compra, $paymentData) {
TelepagosPayment::create($paymentData);
$this->checkoutService->confirmPurchase($compra);
$compra->finalize();
$compra->markAsPaid();
});
Log::info("Telepagos webhook: Successfully processed cashin {$cashinId} for purchase {$compra->id}");