fix(rest/nodejs): block completion when fulfillment methods array is empty - #155
Merged
Conversation
…empty
The completion gate used `checkout.fulfillment?.methods?.every(...)`, which
is vacuously true when `methods` is an empty array. A checkout created with
`fulfillment: { methods: [] }` therefore passed the "fulfillment selected"
check and could be completed (order placed) with no fulfillment at all,
while a checkout with no fulfillment field was correctly rejected.
Require the methods array to be non-empty before applying `.every(...)`,
matching the Python sample, which blocks completion when methods is empty.
Adds a regression test that creates a checkout with
`fulfillment: { methods: [] }` and asserts the complete call is rejected
with 400.
damaz91
approved these changes
Jul 31, 2026
nicholasjameshall
approved these changes
Jul 31, 2026
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.
Description
The Node.js completion gate used
checkout.fulfillment?.methods?.every(...), which is vacuously true whenmethodsis an empty array. A checkout created withfulfillment: { methods: [] }therefore passed the "fulfillment selected" check and could be completed (order placed) with no fulfillment at all — while a checkout with nofulfillmentfield is correctly rejected.Repro:
POST /checkout-sessionswithfulfillment: { methods: [] }returns 201, thenPOST /checkout-sessions/{id}/completecurrently returns 200 (order placed, no fulfillment).Root cause —
rest/nodejs/src/api/checkout.ts,completeCheckout:[].every(fn)evaluates totrue, so an empty methods array satisfies the gate.Fix: require the methods array to be non-empty before applying
.every(...)(Array.isArray(methods) && methods.length > 0 && methods.every(...)). This matches the Python sample, whosecomplete_checkoutblocks completion whenmethodsis empty.Category (Required)
Related Issues
None — newly identified bug in the Node.js sample server.
Checklist
!for breaking changes).tsc --noEmitclean;prettierclean.)empty fulfillment methods array blocks completion.)Screenshots / Logs (if applicable)
Before/after — completing a checkout created with
fulfillment: { methods: [] }:Before (bug):
After (fix):
Full Node.js suite: