feat: refactor purchase status handling and add finalize endpoint for purchases
This commit is contained in:
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user