From de8c7b4ac42e86f78e3b44c97c662b00003fbddd Mon Sep 17 00:00:00 2001 From: Eduardo Bacarin Date: Fri, 4 Jul 2025 11:43:43 -0300 Subject: [PATCH] rework on rules --- src/rules.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/rules.php b/src/rules.php index 33d877a..d54bfa2 100644 --- a/src/rules.php +++ b/src/rules.php @@ -1,24 +1,22 @@ 'integer', - 'devedor' => 'array', - 'devedor.documento' => 'string|min:11|max:18', - 'devedor.nome' => 'required_with:devedor.documento|string|max:100', + 'devedor' => 'sometimes|array', + 'devedor.documento' => 'sometimes|string|min:11|max:18', + 'devedor.nome' => 'sometimes|required_with:devedor.documento|string|max:100', 'valor' => 'required|integer|min:1', '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); + $validate = validate($data, $rules); + if (!$validate['valid']) { + throw new Exception(json_encode(array_slice($validate['errors'], 0, 1)), 500); } else { return true; } @@ -29,19 +27,18 @@ 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', + 'devedor' => 'sometimes|array', + 'devedor.documento' => 'sometimes|string|min:11|max:18', + 'devedor.nome' => 'sometimes|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); + $validate = validate($data, $rules); + if (!$validate['valid']) { + throw new Exception(json_encode(array_slice($validate['errors'], 0, 1)), 500); } else { return true; }