diff --git a/composer.json b/composer.json index e4787ba..0a60726 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ } ], "require": { - "phpseclib/phpseclib": "~3.0" + "phpseclib/phpseclib": "~3.0", + "somnambulist/validation": "^1.12" } } diff --git a/src/rules.php b/src/rules.php index 04560f5..727ad18 100644 --- a/src/rules.php +++ b/src/rules.php @@ -1,9 +1,25 @@ 'required|integer', 'expiracao' => 'integer', - 'devedor' => 'sometimes|string' + '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' ]; + + $validation = (new Factory)->validate($data, $rules); + + if ($validation->fails()) { + throw new Exception(json_encode($validation->errors()->firstOfAll()), 500); + } else { + return true; + } }