Skip to content

PAY-7046 Fix update on json 3, Ruby 3.3 floor and boolean validator - #82

Merged
fz-jamesf merged 6 commits into
mainfrom
PAY-7046-gem-fixes
Dec 1, 2026
Merged

fz-jamesf merged 6 commits into
mainfrom
PAY-7046-gem-fixes

Conversation

@fz-jamesf

@fz-jamesf fz-jamesf commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

update on any resource raises JSON::GeneratorError for merchants on json 3. Save#save merges the object's string-keyed attributes with the caller's params, so web_hook.update(name: 'x') builds a payload with both "name" and :name. json 2.x sends both keys and the gateway's parser keeps the last one; json 3 refuses to generate it. Merchants on json 2.x see no change.

  • Save#save now sends each attribute once, whether it arrives as a string or a symbol, from the stored attributes or the caller (PaymentPlan#suspend!('new_status' => …) used to send both). The caller's value wins, under the caller's key, so a multipart save's :multipart and :file keep working. The id is never sent as "id" or :id.
  • Test mode replaces a caller's string 'test' with :test instead of adding a second key.
  • The :boolean validator's /\Atrue|false\z/ anchored only one side of each word, so "trueish" passed. Only Batch.create uses it, and it always sets true, so no request changes.
  • The gemspec allowed Ruby 3.2, which CI stopped testing in February and which went end of life in March 2026. The floor is now 3.3; merchants on 3.2 keep resolving to 3.3.3.
  • Drops an unused JSON_ENV_VARS env var from the release job.

Ticket: PAY-7046. Released as 3.4.0, a minor version because of the Ruby floor change.

Security Impact

No new data sent. Save#save now also drops a caller's symbol :id, so an update body never carries the id. No change to authentication, card data handling or the gem's dependencies.

Rollback

Revert and tag a new release. Until then, merchants can pin fat_zebra to 3.2.9. No data involved.

Testing

E2E testing evidence provided in a comment: on Ruby 4 with json 3, update works against a local gateway and raises from main.

  • New specs on the payload Save#save builds: each attribute once, with the caller's value and no id, a name passed as both a string and a symbol sent once, suspend! with a string new_status sent once, and in test mode test sent once whichever key type the caller used. The first fails on main with the duplicated "name"/:name and the symbol :id in the payload.
  • New specs for the boolean validator accept true and false and reject "trueish" and "notfalse".
  • rspec (283 examples) and rubocop pass locally on Ruby 3.3, 3.4 and 4 (json 3.2.0), including the two WebHook#update examples that failed on Ruby 4 before.

🤖 Generated with Claude Code

Claude sessions
  • Created by: PR Reviews · 57e8f9d7-6655-4c30-84cd-74040767eca2 · 2026-11-26
  • Last touched by: PR Reviews · 57e8f9d7-6655-4c30-84cd-74040767eca2 · 2026-12-01 · owner

@snyk-io-au

snyk-io-au Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@fz-jamesf
fz-jamesf marked this pull request as ready for review November 29, 2026 20:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Key stringification introduces duplicate test-mode keys that fail JSON serialization and breaks multipart instance saves by converting required transport keys to strings.

2 open issues
What changed in this PR

This PR addresses json 3 compatibility in the FatZebra Ruby client’s instance updates and aligns Ruby support with the tested versions. It complements #77’s Ruby 4 CI fixes.

Changes:

  • Normalizes save payload keys before merging and removing id, with regression coverage.
  • Tightens boolean validation to reject partial matches and adds tests.
  • Raises the Ruby minimum to 3.3 and removes an unused release-job environment variable.
File Description
spec/​lib/​fat_zebra/​web_hook_spec.rb Adds assertions for normalized update payloads.
spec/​lib/​fat_zebra/​validation_spec.rb Covers valid booleans and invalid partial matches.
lib/​fat_zebra/​validation.rb Anchors both boolean alternatives fully.
lib/​fat_zebra/​api_operation/​save.rb Stringifies attribute and parameter keys before merging.
fat_zebra.gemspec Raises the required Ruby version to 3.3.
.rubocop.yml Aligns linting with the Ruby 3.3 minimum.
.github/​workflows/​ci.yml Removes the unused JSON_ENV_VARS variable.

Review effort: Balanced

Comment thread lib/fat_zebra/api_operation/save.rb Resolved
Comment thread lib/fat_zebra/api_operation/save.rb Resolved
@fz-jamesf

Copy link
Copy Markdown
Contributor Author

E2E test results

🤖 Claude ran these for James.

fat_zebra from this branch at c027dc5, on Ruby 4.0.10 with json 3.2.0, against a local Fat Zebra gateway with a test merchant and test_mode on. Scenario 1 runs the same calls from main (5874915) for comparison. Ruby 3.3 and 3.4 with json 2 are covered by CI. This repo is public, so the extracts below are the gem's own output only; gateway's side is summarised in each scenario.

# Scenario Result
1 Before: WebHook#update(name:) from main ✅ reproduces the bug: JSON::GeneratorError, no request sent
2 WebHook#update(name:) ✅ 200, name updated
3 WebHook#update(name:, test: true) in test mode ✅ 200, test sent once
4 Batch.create(file:, filename:) ⚠️ passes the :boolean check and is sent; the local test stack couldn't store the upload
5 Ruby floor ✅ refuses to install on Ruby 3.2.2, installs on 3.3.7

1. Before: WebHook#update(name:) from main

Created a web hook, then updated its name, once plainly and once with test: true. Both updates raise in the gem, because the payload has "name" (from the object) and :name (from the caller). Gateway received the two creates and no update.

Gem output
...
created 010-WH-WPZ2RKV4 name="e2e hook" accepted=true
update(name:): JSON::GeneratorError: detected duplicate key "name" in {"address" => "http://example.com/e2e-hook", "events" => "*", "mode" => "Test", "authentication_username" => nil, "authentication_password" => "", "is_active" => nil, "name" => "e2e hook", name: "e2e hook renamed", test: true}
created 010-WH-SJTQKAGT name="e2e hook" accepted=true
update(name:, test: true): JSON::GeneratorError: detected duplicate key "name" in {"address" => "http://example.com/e2e-hook", "events" => "*", "mode" => "Test", "authentication_username" => nil, "authentication_password" => "", "is_active" => nil, "name" => "e2e hook", name: "e2e hook test flag", test: true}

2. WebHook#update(name:)

With this branch the update goes through. Gateway received name once, with the new value, and answered 200.

Gem output
...
created 010-WH-FHH3PTJD name="e2e hook" accepted=true
update(name:): accepted=true name="e2e hook renamed"

3. WebHook#update(name:, test: true) in test mode

The caller's :test and the one test mode adds are the same key, so it's sent once. Gateway received test: true and the new name, and answered 200.

Gem output
...
created 010-WH-TLYRVCOY name="e2e hook" accepted=true
update(name:, test: true): accepted=true name="e2e hook test flag"

4. Batch.create(file:, filename:)

Batch.create sets multipart: true and checks it with the :boolean validator this PR tightens. The check passed and the upload was sent, rather than raising RequestValidationError. The local test stack then couldn't store the file, so the upload itself isn't proven here; the Batch.create specs still pass.

Unrelated to this PR: run from a bare script, the multipart code raises NameError for StringIO, which it uses without requiring stringio. Rails and Rack apps load it already. This run loads stringio first, as a host app would.

Gem output
...
Batch.create(file:): FatZebra::RequestError: Status 500: Server Error, please check with service

5. Ruby floor

Built the gem from this branch and installed it locally.

Gem install
$ gem install --local fat_zebra-pr82.gem  # on Ruby 3.2.2
...
	fat_zebra-0.0.0.pre.build requires Ruby version >= 3.3. The current ruby version is 3.2.2.
$ gem install --local fat_zebra-pr82.gem  # on Ruby 3.3.7
Successfully installed fat_zebra-0.0.0.pre.build
1 gem installed

Conclusion

On json 3, update works with this branch and raises without it. Test mode still sends test once, the boolean validator lets Batch.create through, and Ruby 3.2 can't install it.

fz-jamesf and others added 5 commits December 1, 2026 12:28
- An object's attributes are string-keyed (they come from the API's JSON)
  but callers pass symbols, so web_hook.update(name: 'x') built a payload
  with both "name" and :name. json 2.x sent both keys; json 3 raises
  JSON::GeneratorError, so update failed outright for merchants on json 3.
- Normalising both sides to strings makes the caller's value replace the
  old one, and lets the existing delete('id') catch a symbol :id too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- \A and \z bound only one alternative each, so /\Atrue|false\z/ accepted
  anything starting with "true" or ending in "false".
- Only Batch.create uses it, and it always sets multipart to true, so no
  merchant request changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CI stopped testing Ruby 3.2 in February and 3.2 went end of life in March
  2026, but the gemspec still allowed it, so Bundler would install releases
  on 3.2 that nobody had run there.
- Merchants still on 3.2 keep resolving to the last release that allowed it.
- rubocop's target follows the floor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The base-ref check set JSON_ENV_VARS from inputs.credentials_json, but the
  workflow has no inputs (it runs on push) and the step never reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stringifying every key fixed the "name"/:name duplicate, but made new
ones: in test mode, save(test: true) sent both "test" and the :test that
APIResource.request adds, which json 3 refuses to generate, and a
multipart save lost the symbol :multipart, :file and :filename keys
Request#post and the multipart encoder read.

- Save#save now drops the old value of any attribute the caller sets,
  whatever its key type, and sends the caller's keys unchanged.
- The id is still never sent, as "id" or :id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Duplicate string/symbol keys can still survive update merges and test-mode injection, causing JSON 3 to reject requests before they are sent.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Remove string-keyed :test conflicts before request serialization

lib/​fat_zebra/​api_operation/​save.rb:57

web_hook.update('test' => true) still retains "test", and APIResource.request adds :test in test mode (lib/fat_zebra/api_resource.rb:29), so json 3 raises before sending the request. An existing "test" attribute causes the same failure even without a test parameter. Remove the string form when injecting :test, and cover string-keyed parameters and stored attributes through request preparation.

2 resolved since last review

Review effort: Balanced

Comment thread lib/fat_zebra/api_operation/save.rb Resolved
json 3 still raised when one name arrived as both a string and a
symbol inside the caller's own params, not just across stored and new
values. PaymentPlan#suspend! and #active! merge a symbol default into
the caller's hash, so suspend!('new_status' => 'Cancelled') sent both,
and in test mode a caller's string 'test' sat beside the :test that
APIResource.request adds.

- Save#save keeps one value per name across the stored attributes and
  the caller's params, the last one given, under its own key type, so
  multipart's symbol keys still reach Request#post.
- Test mode replaces a string 'test' rather than adding beside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the JSON 3 compatibility and boolean validation changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@fz-jamesf
fz-jamesf merged commit 7d3f973 into main Dec 1, 2026
8 checks passed
@fz-jamesf
fz-jamesf deleted the PAY-7046-gem-fixes branch December 1, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants