Skip to content

[CC-4255] Fix Keypair plain-endpoint payment-type duplication - #250

Merged
Ryouzanpaku merged 3 commits into
mainfrom
CC-4255/keypair-payment-type-duplication
Nov 24, 2026
Merged

Ryouzanpaku merged 3 commits into
mainfrom
CC-4255/keypair-payment-type-duplication

Conversation

@Ryouzanpaku

Copy link
Copy Markdown
Contributor

Summary

For the plain keypair endpoint, availablePaymentTypes is an array of strings. AbstractUnzerResource::updateValues() does not skip string arrays, so it already populates $paymentTypes via the setter — then Keypair::handleResponse() appended the same list again, doubling every entry (22 → 44). The detailed endpoint is unaffected (its items are objects, which updateValues() skips).

Pre-existing bug (not a CC-4151 regression). Note: CC-3759 made the property protected, which is what first surfaced the duplication in expose()/jsonSerialize() too.

Fix: handleResponse() now replaces the list instead of appending, which also makes repeated handling idempotent.

Tests

  • Tightened the existing handleResponse assertion from assertArrayContains (passed on a duplicated list) to assertSame.
  • New plainKeypairPaymentTypesAreNotDuplicated: dedup + idempotency + expose()/jsonSerialize().
  • php-cs-fixer clean.

Scope

Independent of CC-4256 (string→boolean parsing), which is a separate PR. No merge-order dependency; both branch off main.

Follow-up (separate repo)

Remove the skip group from paymentTypesInModelMatchRawResponseTest in php-sdk-test-automation once released.

Keypair::handleResponse() appended availablePaymentTypes to $paymentTypes,
but for the plain endpoint AbstractUnzerResource::updateValues() had already
populated the list via the setter (the items are strings, not objects, so
updateValues does not skip them). This doubled every entry. Replace the list
instead of appending, which also makes repeated handling idempotent. The
detailed endpoint is unaffected (its items are objects, skipped by
updateValues). The existing unit test used assertArrayContains, which passed
on the duplicated list; tightened to assertSame.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Ryouzanpaku added a commit that referenced this pull request Nov 23, 2026
Document the merged fix (#251): Keypair boolean flags sent as strings
(validateBasket, cof) were coerced so "false" became true; now parsed
correctly. CC-4255 (payment-type duplication, #250) will be added once merged.
Ryouzanpaku added a commit that referenced this pull request Nov 23, 2026
Bump Unzer::SDK_VERSION to 4.1.0 and stage the remaining 4.1.0 changelog
entries: deprecate Sofort (CC-4344, #252) and the Keypair plain-fetch
payment-type de-duplication fix (CC-4255, #250). Those two feature PRs must
merge before this release-preparation PR.
@Ryouzanpaku
Ryouzanpaku marked this pull request as ready for review November 23, 2026 15:38
@Ryouzanpaku
Ryouzanpaku requested a review from a team as a code owner November 23, 2026 15:38
Ryouzanpaku added a commit that referenced this pull request Nov 23, 2026
…G) (#248)

* [CC-4078] Rename unreleased changelog section to planned 4.1.0

The PHP SDK release is planned as 4.1.0, not 5.0.0. Rename the top
unreleased CHANGELOG section header (and its compare URL) accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* [CC-4078] Add recurring entry to 4.1.0 changelog

Scope the SepaDirectDebit recurring changelog entry under the release
ticket (CC-4078) alongside the version rename, so the feature PR #247
(CC-4239) stays code-only and the two don't conflict.

* [CC-4078] Complete the 4.1.0 changelog with all released changes

Add the Keypair getRawResponse() addition (CC-4151) and the PIS payment-type
deprecation (CC-4064) to the 4.1.0 section, alongside the recurring flag
(CC-4239) and the PHP 8.1 removal (CC-4228) — the full set of merged changes
for the release.

* [CC-4078] Add CC-4256 Keypair boolean-parsing fix to 4.1.0 changelog

Document the merged fix (#251): Keypair boolean flags sent as strings
(validateBasket, cof) were coerced so "false" became true; now parsed
correctly. CC-4255 (payment-type duplication, #250) will be added once merged.

* [CC-4078] Prepare 4.1.0 release: bump SDK version and complete changelog

Bump Unzer::SDK_VERSION to 4.1.0 and stage the remaining 4.1.0 changelog
entries: deprecate Sofort (CC-4344, #252) and the Keypair plain-fetch
payment-type de-duplication fix (CC-4255, #250). Those two feature PRs must
merge before this release-preparation PR.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Ryouzanpaku and others added 2 commits November 24, 2026 11:12
Resolve the KeypairTest.php conflict by keeping both independently added
test methods: the plain-endpoint de-duplication test (CC-4255) and the
string-boolean parsing tests brought in via main (CC-4256, #251).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ponses

array_values() rejects a stdClass, so a payment-type list that arrives with
non-sequential keys (decoded as a JSON object, e.g. after an upstream
array_filter) crashed fetchKeypair() with a TypeError on both the plain and
detailed endpoints. Cast to array first to restore the tolerant behaviour the
previous foreach had, keeping the de-duplication fix intact. Addresses QA
finding on PR #250 and preserves the "detailed behaviour unchanged" AC.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Ryouzanpaku
Ryouzanpaku enabled auto-merge (squash) November 24, 2026 13:09

@sixer1182 sixer1182 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved. Reviewed against CC-4255 (PHP SDK: plain fetchKeypair() lists every payment type twice). Unit suite is green locally (799 tests, 2925 assertions) and CI is green.

Verified

  • Plain keypair: getPaymentTypes(), getAvailablePaymentTypes(), expose() and jsonSerialize() return the list exactly once, in API order. Duplicates sent by the API itself are kept as sent.
  • Handling a response again replaces the list instead of appending (on main the list grows with every call).
  • Detailed keypair behaviour is unchanged. Empty lists work, and a later response without a list key keeps the previous list.
  • The object-shaped list case found in QA ({"0":"card","2":"paypal"}, plain and detailed) is fixed by the array cast and covered by tests. The merge conflict in KeypairTest.php is resolved.

Notes (not blocking)

  1. A null payment type list still throws a TypeError from the setter. This already happens on main. Please make sure it is tracked in its own ticket.
  2. A scalar string instead of a list also throws a TypeError, also on main. Unlikely in practice.
  3. The follow-up in php-sdk-test-automation (remove the skip group from paymentTypesInModelMatchRawResponseTest) can only be done after the release.

@Ryouzanpaku
Ryouzanpaku merged commit 5baf51e into main Nov 24, 2026
7 checks passed
@Ryouzanpaku
Ryouzanpaku deleted the CC-4255/keypair-payment-type-duplication branch November 24, 2026 13:13
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.

2 participants