fix(shipping-guide): index each package in the price query - #69
Merged
Merged
Conversation
Shipping Guide v2 addresses a multi-package request by suffixing every package parameter with its index (weightInGrams0, length0, ..., weightInGrams1, ...). PriceRequest::toQuery() instead emitted an array per parameter, which AbstractJsonEndpoint flattens into repeated bare keys (weightInGrams=1200&weightInGrams=800). Bring keeps a single value for a repeated key, so every request was priced as one package and the quote was identical for 1, 2 or 20 packages. Emit suffixed names as soon as a request carries more than one package; a single package keeps the unsuffixed names it has always used. The repeated-key form still applies to `product` and `additional`, which do take repeated bare keys. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QWNnuSeJNRdXzETx48HA5C
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.
What
PriceRequest::toQuery()now gives every package its own indexed query parameters (weightInGrams0,length0, …,weightInGrams1, …) when a request carries more than one package. A single-package request keeps the unsuffixed names it has always used.Before this,
toQuery()built an array per parameter ($q['weightInGrams'][$i]), andAbstractJsonEndpoint::uri()deliberately strips the numeric subscripts — so the URL came out as repeated bare keys:Shipping Guide v2 collapses a repeated key to a single value, so every multi-package request was priced as one package: a caller asking for 1, 2 or 20 packages got the same quote back. The repeated-key form is still correct for
productandadditional, and is unchanged.Why
The index-suffix shape is what the v3 client sent (
ShippingGuideEntity::addWeightInGrams()wroteweightInGrams0,weightInGrams1, … via its per-parameter counters); the suffixes were lost in the v4 rewrite, andtestShippingPriceQueryBuildsBareRepeatedKeyspinned the broken shape as the expected one.Suffixing only from the second package onward — rather than always emitting
weightInGrams0— keeps the single-package URL byte-for-byte identical to what ships today, so the known-good path can't regress on this change.Generated URLs after the fix:
Test plan
PriceRequestTest::testEachPackageGetsItsOwnIndexedParameters— multi-package requests emitweightInGrams0/1/2plus per-package dimensions, and no bareweightInGramsPriceRequestTest::testSinglePackageUsesUnsuffixedParameterNames— one package still emitsweightInGrams/length/width/heightTransportTest::testShippingPriceQueryIndexesEachPackage— the built URI carries the suffixed keys (replacestestShippingPriceQueryBuildsBareRepeatedKeys, which asserted the broken shape)TransportTest::testShippingPriceQueryKeepsBareKeysForASinglePackage— single-package URI unchangedproduct/additionalstill serialise as repeated bare keys (covered by the existing product tests)composer qawas not run in the authoring environment —composer installcould not authenticate against github.com there, so the query strings were verified with a standalone script against the real class. CI is the first full run.Bring docs link
https://developer.bring.com/api/shipping-guide/ — Shipping Guide v2
/products, multi-package section (parameters are suffixed with a per-package index).🤖 Generated with Claude Code
https://claude.ai/code/session_01QWNnuSeJNRdXzETx48HA5C
Generated by Claude Code