phpkore/src/rules.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2025-07-03 17:15:31 -03:00
<?php
2025-07-03 18:40:11 -03:00
use Somnambulist\Components\Validation\Factory;
function pixCobrancaImediataComValorRules(array $data)
2025-07-03 18:40:11 -03:00
{
2025-07-03 17:15:31 -03:00
$rules = [
'expiracao' => 'integer',
2025-07-03 18:40:11 -03:00
'devedor' => 'array',
'devedor.documento' => 'string|min:11|max:18',
'devedor.nome' => 'required_with:devedor.documento|string|max:100',
'valor' => 'required|integer|min:1',
'chave' => 'required|string',
'txid' => 'required|string|max:100',
'solicitacaoPagador' => 'string|max:140'
2025-07-03 17:15:31 -03:00
];
2025-07-03 18:40:11 -03:00
$validation = (new Factory)->validate($data, $rules);
if ($validation->fails()) {
throw new Exception(json_encode($validation->errors()->firstOfAll()), 500);
} else {
return true;
}
2025-07-03 17:15:31 -03:00
}
function pixCobrancaImediataSemValorRules(array $data)
{
$rules = [
'expiracao' => 'integer',
'devedor' => 'array',
'devedor.documento' => 'string|min:11|max:18',
'devedor.nome' => 'required_with:devedor.documento|string|max:100',
'valor' => 'sometimes|integer',
'chave' => 'required|string',
'txid' => 'required|string|max:100',
'solicitacaoPagador' => 'string|max:140'
];
$validation = (new Factory)->validate($data, $rules);
if ($validation->fails()) {
throw new Exception(json_encode($validation->errors()->firstOfAll()), 500);
} else {
return true;
}
}