From 5da8edc42661706fca0abf6075cf55fab178900a Mon Sep 17 00:00:00 2001 From: Eduardo Bacarin Date: Fri, 4 Jul 2025 17:28:56 -0300 Subject: [PATCH] =?UTF-8?q?Pix=20Cobran=C3=A7a=20Din=C3=A2mico=20Imediata?= =?UTF-8?q?=20Troco=20Com=20Valor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Pix.php | 42 ++++++++++++++++++++++++++++++++++++++++++ src/rules.php | 23 +++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/Pix.php b/src/Pix.php index e508a6d..9f3e61f 100644 --- a/src/Pix.php +++ b/src/Pix.php @@ -212,5 +212,47 @@ class Pix extends Kore $payload ); } + public function pixCobrancaDinamicoImediatoTrocoComValor($payload) + { + pixCobrancaImediataTrocoComValorRules($payload); + $korePayload = [ + 'calendario' => [ + 'expiracao' => $payload['expiracao'] ?? 86400, + ], + 'valor' => [ + 'original' => 0, + 'retirada' => [ + 'troco' => [ + 'valor' => $payload['valor'], + 'modalidadeAlteracao' => 0, + 'prestadorDoServicoDeSaque' => $payload['ispb'], + 'modalidadeAgente' => $payload['modalidadeAgente'] + ] + ] + ], + 'chave' => $payload['chave'], + 'txid' => $payload['txid'], + 'solicitacaoPagador' => $payload['solicitacaoPagador'] ?? null + ]; + if (isset($payload['devedor'])) { + if (strlen($payload['devedor']['documento']) > 11) { + $korePayload['devedor']['cnpj'] = $payload['devedor']['documento']; + } else { + $korePayload['devedor']['cpf'] = $payload['devedor']['documento']; + } + $korePayload['devedor']['nome'] = $payload['devedor']; + } + + return curlRequest( + $this->url . '/post', + 'POST', + [], + [ + 'x-kore-drone-uid: drone:' . $this->drone, + 'x-kore-drone-sign: ' . $this->signBody($korePayload) + ], + $payload + ); + } } diff --git a/src/rules.php b/src/rules.php index f8d4051..83a4231 100644 --- a/src/rules.php +++ b/src/rules.php @@ -111,3 +111,26 @@ function pixCobrancaImediataTrocoSemValorRules(array $data) return true; } } + +function pixCobrancaImediataTrocoComValorRules(array $data) +{ + $rules = [ + 'expiracao' => 'sometimes|integer', + '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', + 'ispb' => 'required|string', + 'modalidadeAgente' => 'required|string|in:agtec,agtot' + ]; + + $validate = validate($data, $rules); + if (!$validate['valid']) { + throw new Exception(json_encode(array_slice($validate['errors'], 0, 1)), 500); + } else { + return true; + } +}