feat: add payer_dni field and validation for transfer payments, update related logic and tests
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -19,6 +19,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
'payment_method',
|
||||
'total',
|
||||
'dni',
|
||||
'payer_dni',
|
||||
'telefono',
|
||||
'nombre_apellido',
|
||||
'email',
|
||||
|
||||
@@ -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}$/',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user