feat: add payer_dni field and validation for transfer payments, update related logic and tests

This commit is contained in:
2026-07-12 19:48:56 +00:00
parent ca4fea6bcd
commit ca7a2ae55c
7 changed files with 102 additions and 4 deletions

View File

@@ -54,7 +54,7 @@ class TelepagosWebhookService
$dni = substr($cuit, 2, -1);
$compra = Purchase::where('tenant_codigo', $tenantCodigo)
->whereRaw("REPLACE(dni, '.', '') = ?", [$dni])
->where('payer_dni', $dni)
->whereIn('status', [Purchase::STATUS_CREATED, Purchase::STATUS_PENDING_PAYMENT])
->where('payment_method', 'transfer')
->where('total', $amount)

View File

@@ -57,10 +57,16 @@ class PurchaseController extends Controller
$method = $request->validated('method');
$totalAmount = $compra->calculateCurrentTotalAmount();
$compra->update([
$purchaseUpdate = [
'payment_method' => $method,
'total' => $totalAmount,
]);
];
if ($method === 'transfer') {
$purchaseUpdate['payer_dni'] = preg_replace('/\D+/', '', (string) $request->validated('payer_dni'));
}
$compra->update($purchaseUpdate);
if ($method === 'transfer') {
$telepagosService = new \App\Domains\Integration\Services\TelepagosIntegrationService();

View File

@@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
'payment_method',
'total',
'dni',
'payer_dni',
'telefono',
'nombre_apellido',
'email',

View File

@@ -19,6 +19,11 @@ class PaymentIntentRequest extends FormRequest
{
return [
'method' => ['required', 'string', Rule::in(['qr', 'transfer'])],
'payer_dni' => [
Rule::requiredIf(fn (): bool => $this->input('method') === 'transfer'),
'string',
'regex:/^\d{7,8}$/',
],
];
}
}

View File

@@ -43,6 +43,7 @@ class PurchaseResource extends JsonResource
'status' => $this->status,
'payment_method' => $this->payment_method,
'dni' => $this->dni,
'payer_dni' => $this->payer_dni,
'telefono' => $this->telefono,
'nombre_apellido' => $this->nombre_apellido,
'email' => $this->email,