Skip to content

Normalize authorized boolean to 1/0 in orders.all() (fixes dead normalizeBoolean)#483

Open
vku2018 wants to merge 1 commit into
razorpay:masterfrom
vku2018:fix/normalize-authorized-boolean
Open

Normalize authorized boolean to 1/0 in orders.all() (fixes dead normalizeBoolean)#483
vku2018 wants to merge 1 commit into
razorpay:masterfrom
vku2018:fix/normalize-authorized-boolean

Conversation

@vku2018

@vku2018 vku2018 commented Jul 3, 2026

Copy link
Copy Markdown

Summary

orders.all() accepts authorized (typed as boolean | 1 | 0), and the Orders API expects 1/0. The method contained a no-op self-assignment:

authorized = authorized

where the normalizeBoolean conversion was clearly intended. As a side effect, normalizeBoolean is exported from razorpay-utils but never called anywhere in the library. So passing authorized: true sent the raw boolean to the API instead of 1.

The existing test only exercised authorized: 1 (already binary), so its own assertion message — "authorized to binary" — passed by accident and the bug slipped through.

Fix

authorized = normalizeBoolean(authorized)

(imported into orders.js). normalizeBoolean(undefined) returns undefined, so callers that omit the flag are unaffected, and 1/0 pass through unchanged — backward compatible.

Tests

Added tests exercising authorized: true1 and authorized: false0. Verified they fail without the fix and pass with it. Full suite: 386 passing.

`orders.all()` accepts `authorized` typed as `boolean | 1 | 0`, and the
Razorpay Orders API expects `1`/`0`. The method had a no-op self-assignment
`authorized = authorized` where the `normalizeBoolean` conversion was
clearly intended — as a result `normalizeBoolean` was exported but never
called anywhere in the library, and passing `authorized: true` sent the raw
boolean to the API instead of `1`.

The existing test only exercised `authorized: 1` (already binary), so its
own assertion message ("authorized to binary") passed by accident and the
bug went undetected.

Fix: use `authorized = normalizeBoolean(authorized)` (imported into
orders.js). `normalizeBoolean(undefined)` returns `undefined`, so callers
omitting the flag are unaffected; `1`/`0` pass through unchanged — backward
compatible.

Added tests exercising `authorized: true` -> 1 and `authorized: false` -> 0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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