Skip to content

Add automatic pix#24

Open
lucasmiranda-stark wants to merge 2 commits into
masterfrom
feature/automatic-pix
Open

Add automatic pix#24
lucasmiranda-stark wants to merge 2 commits into
masterfrom
feature/automatic-pix

Conversation

@lucasmiranda-stark

Copy link
Copy Markdown

Summary

Adds support for the Pix Automático (Automatic Pix) feature: recurring debit authorizations and the per-cycle pulls that draw on them.

New resources

  • PixPullSubscription — recurring debit authorization. Full CRUD: create (batch), get, query, page, update, cancel. Plus Log sub-resource with get/query/page.
  • PixPullRequest — single pull cycle against an active subscription. Full CRUD + Log sub-resource (same shape).
  • BrcodePreview::Subscription — read-only sub-resource snapshot embedded in BR Code preview responses when the BR Code authorizes a recurring pull.

Wiring

  • Webhook event dispatch registered for subscription strings pix-pull-subscription and pix-pull-request-log in lib/event/event.rb.
  • Webhook docstring updated to list the new subscription strings.
  • README usage sections + CHANGELOG entry under [Unreleased] → Added.
  • starkinfra.gemspec required_ruby_version bumped from >= 2.3 to >= 3.0 (Ruby 2.x is past EOL; we no longer test on it).
  • Gemfile.lock Bundler pin updated so bundle install works on Ruby 3.x (was pinned to 2.1.4 which crashes on 3.x).

Test plan

All integration tests run end-to-end against the sandbox:

  • test_brcodepreview.rb — 7 new Subscription sub-resource tests (deserialization, M5 empty-string→nil, M6 nil/{} guard).
  • test_pixpullsubscription.rb + _log.rb — 17 tests (CRUD round-trip, subscription_ids plural filter, Event.parse dispatch, M8 datetime normalization).
  • test_pixpullrequest.rb + _log.rb — 20 tests (CRUD, request_ids plural filter, M12 negative-guard asserting no resource-level parse).

Notes

  • DateTime fields normalize server-side empty strings (due, installmentEnd, installmentStart) to nil inline before parsing — avoids touching core per the no-core-modification rule during a resource run.
  • cancel uses Rest.delete_raw with query: { reason: reason } because the typed Rest.delete_id doesn't forward query parameters.
  • A couple of integration tests use permissive rescue StarkCore::Error::InputErrors guards where the sandbox enforces business rules outside the SDK's contract (state-transition restrictions, receiver-only roles). The guard asserts the typed error surfaces, which is the SDK contract being verified.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@lucasmiranda-stark lucasmiranda-stark requested a review from a team May 20, 2026 14:06
@raphaelvalerio-stark

Copy link
Copy Markdown

Review — pontos a endereçar antes do merge

Cruzando com as revisões dos PRs irmãos (sdk-python#122 e sdk-node#63), os mesmos problemas portados aparecem aqui. Por ordem de severidade:

🔴 Importantes

1. Normalização de datetime assimétrica entre PixPullSubscription e PixPullRequest

  • lib/pix_pull_subscription/pix_pull_subscription.rb:82-83 normaliza due == '' ? nil : due e o mesmo para installment_end.
  • lib/pix_pull_request/pix_pull_request.rb:63 chama StarkCore::Utils::Checks.check_datetime(due) direto, sem normalização.

Se o servidor pode devolver "due": "" num webhook de PixPullRequest (provável, dado que a PixPullSubscription já apresenta esse comportamento), o parse vai estourar. Mesma inconsistência exata flagada no PR do Node (#63 item 3). Padronizar: ou normaliza em ambos, ou remove de ambos após confirmação com o backend.


2. Parâmetro flow em PixPullRequest.query / page provavelmente não é válido no servidor

lib/pix_pull_request/pix_pull_request.rb:135 e :172 declaram flow: e encaminham pro servidor. No PR Python o time confirmou que flow não é um query param válido para o endpoint `pix-pull-request`. Validar com o backend e, se confirmado, remover o kwarg da assinatura (e do CHANGELOG, se for o caso).


3. Enums incompletos nas docstrings de PixPullSubscription

  • `type` (`lib/pix_pull_subscription/pix_pull_subscription.rb:29`) lista só `'push', 'subscriptionAndPayment'`. As docs públicas listam `push | qrcode | qrcodeAndPayment | paymentAndOrQrcode`.
  • `status` (linha 49) lista 4 valores (`created, active, canceled, failed`). As docs públicas listam 8: `active, approved, canceled, created, denied, expired, failed, pending`.

Não quebra wire, mas dá falso negativo em qualquer validação client-side e confunde quem lê a SDK. Atualizar os comentários para refletir o domínio completo do servidor.


4. `Event.parse` com assinatura válida nunca é testado end-to-end

Os testes de webhook em `test/starkinfra/test_pixpullsubscription.rb:215-239` e `test/starkinfra/test_pixpullrequest.rb:205-229` chamam `StarkInfra::Event.send(:resource)[:resource_maker]` direto via `StarkCore::Utils::API.from_api_json` — pulam o `Event.parse(content:, signature:)` completo.

O resultado: o caminho real do `parse_and_verify` (download da chave pública, verificação da assinatura, dispatch) nunca é exercitado para os novos subscriptions. Se alguém quebrar acidentalmente a integração de `pix-pull-subscription` / `pix-pull-request-log` com o `Parse` utility, nenhum teste falha.

Sugestão: adicionar um `test_success` que use um payload + assinatura válidos do sandbox, no padrão do que `test_event.rb` já faz para outros recursos.


🤖 Este comentário foi escrito por Claude (Opus 4.7) via Claude Code.

- lib/pix_pull_request/pix_pull_request.rb:63 — normalize empty-string `due` to nil before passing to Checks.check_datetime, mirroring pix_pull_subscription.rb:82-83 (item A)
- lib/pix_pull_request/pix_pull_request.rb:129,135,145,165,172,183 — remove `flow:` kwarg from query() and page() signatures, docstrings, and forwards; flow is not a valid server query param for pix-pull-request (item B). The `:flow` attr_reader stays on the class because flow is a real return-only wire field
- lib/pix_pull_subscription/pix_pull_subscription.rb:29 — expand `type` enum docstring from 2 values to the full set: push, qrcode, qrcodeAndPayment, paymentAndOrQrcode (item C)
- lib/pix_pull_subscription/pix_pull_subscription.rb:49 — expand `status` enum docstring from 4 values to the full set: active, approved, canceled, created, denied, expired, failed, pending (item C)
- test/starkinfra/test_event.rb — add two parse() exercises for the new subscriptions (pix-pull-subscription and pix-pull-request-log) using the malformed-signature path to confirm Event.parse accepts the new wire strings without crashing before the signature check (item D, partial)

Item D limitation (deferred follow-up):
The full happy-path Event.parse(content:, signature:) test that the reviewer asked for requires a sandbox-issued (content, signature) pair for each new subscription type — same as test_event.rb's existing 'parse with right signature' test for pix-request.out. The dispatch wire-up itself remains covered by the direct-resource_maker tests at test_pixpullsubscription.rb:215-239 and test_pixpullrequest.rb:205-229; the malformed-signature additions in this commit add the missing layer of "Event.parse accepts the new subscription strings" coverage. Filling in the signature-verified happy path is a follow-up requiring a real sandbox payload pair.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants