Skip to content

fix(shipping-guide): index each package in the price query - #69

Merged
crakter merged 1 commit into
masterfrom
claude/price-calculator-bug-ak1a0q
Sep 11, 2026
Merged

crakter merged 1 commit into
masterfrom
claude/price-calculator-bug-ak1a0q

Conversation

@crakter

@crakter crakter commented Sep 11, 2026

Copy link
Copy Markdown
Owner

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]), and AbstractJsonEndpoint::uri() deliberately strips the numeric subscripts — so the URL came out as repeated bare keys:

&weightInGrams=2000&weightInGrams=2000&weightInGrams=9000

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 product and additional, and is unchanged.

Why

The index-suffix shape is what the v3 client sent (ShippingGuideEntity::addWeightInGrams() wrote weightInGrams0, weightInGrams1, … via its per-parameter counters); the suffixes were lost in the v4 rewrite, and testShippingPriceQueryBuildsBareRepeatedKeys pinned 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:

1 package:  weightInGrams=2000&length=8&width=6&height=6
3 packages: weightInGrams0=2000&length0=8&width0=6&height0=6
            &weightInGrams1=2000&length1=8&width1=6&height1=6
            &weightInGrams2=9000

Test plan

  • PriceRequestTest::testEachPackageGetsItsOwnIndexedParameters — multi-package requests emit weightInGrams0/1/2 plus per-package dimensions, and no bare weightInGrams
  • PriceRequestTest::testSinglePackageUsesUnsuffixedParameterNames — one package still emits weightInGrams / length / width / height
  • TransportTest::testShippingPriceQueryIndexesEachPackage — the built URI carries the suffixed keys (replaces testShippingPriceQueryBuildsBareRepeatedKeys, which asserted the broken shape)
  • TransportTest::testShippingPriceQueryKeepsBareKeysForASinglePackage — single-package URI unchanged
  • product / additional still serialise as repeated bare keys (covered by the existing product tests)
  • Note: composer qa was not run in the authoring environment — composer install could 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

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
@crakter
crakter merged commit 045a06d into master Sep 11, 2026
18 checks passed
@crakter
crakter deleted the claude/price-calculator-bug-ak1a0q branch September 11, 2026 23:08
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.

1 participant