Skip to content

fix: hydrate unknown enum values as UNKNOWN and add BANCOMAT card type - #128

Closed
lanz1 wants to merge 2 commits into
sumup:mainfrom
lanz1:fix/unknown-enum-fallback
Closed

lanz1 wants to merge 2 commits into
sumup:mainfrom
lanz1:fix/unknown-enum-fallback

Conversation

@lanz1

@lanz1 lanz1 commented Oct 14, 2026

Copy link
Copy Markdown

Fixes #127

Problem

The Transactions API returns card.type = "BANCOMAT" for Italian PagoBancomat debit cards. The value is missing from the CardType schema, so the hydrator throws a ValueError and Transactions::get() cannot return a successful transaction at all.

Changes

This PR has two independent commits, so they can be reviewed (or taken) separately:

  1. fix(hydrator): when tryFrom() does not recognise a value, Hydrator::castEnumValue() now returns the enum's UNKNOWN case if the enum declares one (CardType, CardResponseType, ReaderStatus, MemberStatus, …). Enums without UNKNOWN keep the current strict behaviour, so testHydrateInvalidBackedEnumValueThrowsValueError is unchanged and still passes. This keeps responses readable when the API adds a value before the SDK is regenerated.
  2. feat: add BANCOMAT card type: adds BANCOMAT to components.schemas.CardType in openapi.json and regenerates the four derived enums with the codegen (go -C codegen run . generate ../openapi.json ../src). Running the generator on the unmodified spec produces no diff, so the only changes are the BANCOMAT cases.

I noticed openapi.json is synced from sumup/apis. If the spec change should go there instead, I'm happy to drop the second commit; the first one fixes the crash on its own.

Tests

  • testHydrateUnknownValueOfEnumWithUnknownCaseFallsBackToUnknown: an unknown card network hydrates to CardResponseType::UNKNOWN and the other fields are kept.
  • testHydrateBancomatCardType: BANCOMAT hydrates to CardResponseType::BANCOMAT.

Locally on PHP 8.5: PHPUnit is green (37 tests) and php-cs-fixer reports no changes. PHPStan reports the same 2 errors in HttpClient/GuzzleClient.php that are already present on main.

fabio added 2 commits October 15, 2026 09:48
…know

The API can return enum values added after the SDK was generated. For
example, Italian PagoBancomat cards are returned with card type
"BANCOMAT", which is missing from CardResponseType: Transactions::get()
then throws a ValueError and the whole transaction is unreadable, even
though it is SUCCESSFUL and every other field is valid.

Enums that declare an UNKNOWN case now map unrecognised values to it.
Enums without UNKNOWN keep the current strict behaviour (ValueError).
Italian PagoBancomat debit cards are reported by the API with card type
"BANCOMAT". Add it to the CardType schema and regenerate the card type
enums.
@matoous
matoous force-pushed the fix/unknown-enum-fallback branch from 9fd1d60 to 99170fb Compare October 15, 2026 07:51
@matoous

matoous commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Hi! Thanks for the contribution. We generate the SDKs from our OpenAPI specs, so the fix needed to go there (done) and #119 re-generates the SDK from updated specs. I will close your PR in favor of the automatic sync.

Separately, I am taking a look into keeping the enums open (which should have been the behavior in the first place).

Thank you 🙇

@matoous matoous closed this Oct 15, 2026
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.

[Bug]: Transactions::get() throws ValueError for card type BANCOMAT

2 participants