Make all five BasketItem fields required constructor params - #3
Merged
Conversation
Verified against the live API: a basket item is all-or-nothing. Any partial item is rejected with per-field 'is missing' errors for every omitted field (qty, item_no, item_name, item_price, vat_rate), so there is no valid BasketItem with a missing field. The nullable design also had a dangerous edge: an all-null BasketItem normalized to [] nested inside the basket list, and a basket containing a []-shaped item does not even get a validation error - it triggers an HTTP 500 on Quickpay's side. Required fields make that unrepresentable. Address stays all-optional (verified: the API accepts a partial address and stores omitted fields as null); Shipping is unverified and left untouched. Adds a serialization test for basket items.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.x #3 +/- ##
============================================
+ Coverage 92.30% 92.55% +0.24%
Complexity 148 148
============================================
Files 24 24
Lines 403 403
============================================
+ Hits 372 373 +1
+ Misses 31 30 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… set) Probed against the live API: partial shipping objects are accepted and stored with nulls, so all-nullable fields are correct — no tightening. Shipping::method, when present, is server-validated against a fixed value set (home_delivery accepted, pickup rejected). Also verified that an all-empty nested Payload set as a direct property is stripped from the body entirely, so only empty items inside a list could ever reach the wire — which BasketItem's required fields now prevent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2, closing the gap it deliberately left open: the nested DTOs were unverified, and
BasketItem's all-nullable fields turned out to be wrong.Verified against the live API
POST /paymentswith abasket)basket: [{qty: 2}](partial item)item_no,item_name,item_price,vat_rateallis missingbasket: [{item_name: …}]qty,item_no,item_price,vat_rateis missingbasket: [full item]basket: [{}](empty object item)[null](API quirk)basket: [[]](empty array item)A basket item is all-or-nothing: if present, all five fields are jointly required — there is no valid
BasketItemwith a missing field.The last row matters most: an all-null
BasketItemnormalized to[](the nested cousin of the empty-Payloadbug fixed in #2 — thesend()guard only rewrites the top-level body), and that shape doesn't get a validation error, it crashes Quickpay's backend. Making the fields required makes an empty item unrepresentable, killing that failure mode at the type level.What
BasketItem:qty,itemNo,itemName,itemPrice,vatRateare now required, non-nullable constructor parameters (same order as before, so positional callers are unaffected).Address: stays all-optional, now documented as verified lenient (the API accepts a partial address — e.g. onlyname— and stores omitted fields asnull).Shipping: also probed — verified lenient (partial accepted, stored with nulls), so it stays all-optional too. One gotcha now documented:method, when present, is server-validated against a fixed value set (home_deliveryaccepted,pickuprejected withdoes not have a valid value).Payloadset as a direct property (shipping/invoiceAddress) is stripped from the body entirely by the parent's[]-strip, so it never reaches the wire — only empty items inside a list could, which requiredBasketItemfields now prevent.it_serializes_basket_items_as_a_list_of_snake_case_objects.BC
Breaking for consumers constructing partial
BasketItems — but every such request was either rejected by the API or (if fully empty) triggered a server-side 500. Same alpha-window reasoning as #2; should land before 1.0.0 stable.Tests
PHPUnit (94), PHPStan max, ECS, Rector, Infection all green (covered MSI 76% ≥ 70 gate).