rework on rules
This commit is contained in:
parent
2e33469987
commit
de8c7b4ac4
1 changed files with 13 additions and 16 deletions
|
@ -1,24 +1,22 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Somnambulist\Components\Validation\Factory;
|
require_once(__DIR__.'/validator.php');
|
||||||
|
|
||||||
function pixCobrancaImediataComValorRules(array $data)
|
function pixCobrancaImediataComValorRules(array $data)
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'expiracao' => 'integer',
|
'expiracao' => 'integer',
|
||||||
'devedor' => 'array',
|
'devedor' => 'sometimes|array',
|
||||||
'devedor.documento' => 'string|min:11|max:18',
|
'devedor.documento' => 'sometimes|string|min:11|max:18',
|
||||||
'devedor.nome' => 'required_with:devedor.documento|string|max:100',
|
'devedor.nome' => 'sometimes|required_with:devedor.documento|string|max:100',
|
||||||
'valor' => 'required|integer|min:1',
|
'valor' => 'required|integer|min:1',
|
||||||
'chave' => 'required|string',
|
'chave' => 'required|string',
|
||||||
'txid' => 'required|string|max:100',
|
'txid' => 'required|string|max:100',
|
||||||
'solicitacaoPagador' => 'string|max:140'
|
'solicitacaoPagador' => 'string|max:140'
|
||||||
];
|
];
|
||||||
|
$validate = validate($data, $rules);
|
||||||
$validation = (new Factory)->validate($data, $rules);
|
if (!$validate['valid']) {
|
||||||
|
throw new Exception(json_encode(array_slice($validate['errors'], 0, 1)), 500);
|
||||||
if ($validation->fails()) {
|
|
||||||
throw new Exception(json_encode($validation->errors()->firstOfAll()), 500);
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -29,19 +27,18 @@ function pixCobrancaImediataSemValorRules(array $data)
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'expiracao' => 'integer',
|
'expiracao' => 'integer',
|
||||||
'devedor' => 'array',
|
'devedor' => 'sometimes|array',
|
||||||
'devedor.documento' => 'string|min:11|max:18',
|
'devedor.documento' => 'sometimes|string|min:11|max:18',
|
||||||
'devedor.nome' => 'required_with:devedor.documento|string|max:100',
|
'devedor.nome' => 'sometimes|required_with:devedor.documento|string|max:100',
|
||||||
'valor' => 'sometimes|integer',
|
'valor' => 'sometimes|integer',
|
||||||
'chave' => 'required|string',
|
'chave' => 'required|string',
|
||||||
'txid' => 'required|string|max:100',
|
'txid' => 'required|string|max:100',
|
||||||
'solicitacaoPagador' => 'string|max:140'
|
'solicitacaoPagador' => 'string|max:140'
|
||||||
];
|
];
|
||||||
|
|
||||||
$validation = (new Factory)->validate($data, $rules);
|
$validate = validate($data, $rules);
|
||||||
|
if (!$validate['valid']) {
|
||||||
if ($validation->fails()) {
|
throw new Exception(json_encode(array_slice($validate['errors'], 0, 1)), 500);
|
||||||
throw new Exception(json_encode($validation->errors()->firstOfAll()), 500);
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue