Skip to content

Support expand[] in orders.fetch and send expand[] the way the API expects (#332) - #489

Open
yashbudhia wants to merge 1 commit into
razorpay:masterfrom
yashbudhia:orders-fetch-expand-332
Open

yashbudhia wants to merge 1 commit into
razorpay:masterfrom
yashbudhia:orders-fetch-expand-332

Conversation

@yashbudhia

Copy link
Copy Markdown

Closes #332.

instance.orders.fetch(orderId) had no way to pass expand[], even though the HTTP API accepts it on that endpoint and orders.all() already exposes it. This adds an optional params argument, mirroring payments.fetch(paymentId, params):

instance.orders.fetch(orderId, { "expand[]": "payments" })

A callback is still accepted as the second argument, so existing orders.fetch(orderId, cb) callers are unaffected.

A serialisation bug this uncovered

Every existing expand[] site (orders.all, payments.all, payments.fetch, and both on-demand settlement calls) built the query as { expand: { "expand[]": value } }. With the axios version this package depends on (^1.18.1) that serialises to:

?expand[expand][0]=payments

which the API does not recognise. Sending the value under the flat "expand[]" key produces what the API reference documents, including one expand[]= per value when an array is passed:

?expand[]=payments
?expand[]=payments&expand[]=transfers

All five sites now use the flat key. Verified with a nock intercept on the built package: /v1/orders/order_x?expand%5B%5D=payments.

Tests

New cases in test/resources/orders.spec.js and test/resources/payments.spec.js assert the parsed query params and the formed URL for fetch and all, multiple expand[] values, and the callback-as-second-argument path. Full suite: 384 passing.

Also

  • documents/order.md documents the new parameter with an example.
  • lib/types/orders.d.ts gains Orders.ExpandDetails and the matching fetch overloads.
  • dist/ is not included; it is rebuilt by npm test.
Test Case Document URL
N/A, external contribution. Tests are in the PR: test/resources/orders.spec.js, test/resources/payments.spec.js.

…pects (razorpay#332)

orders.fetch() had no way to pass expand[], although the HTTP API accepts
it and orders.all() already did. It now takes an optional params object
the same way payments.fetch() does, and still accepts a callback as the
second argument so existing callers are unaffected.

While adding it I found that every existing expand[] site (orders.all,
payments.all, payments.fetch and both on-demand settlement calls) wrapped
the value as { expand: { "expand[]": value } }. With the axios version
this package depends on, that serialises to expand[expand][0]=payments,
which the API does not recognise. The value is now sent under the flat
"expand[]" key, which serialises to expand[]=payments (and one
expand[]=... per value for arrays), matching the API reference.

Tests cover the fetch and all query strings, multiple values, and the
callback-as-second-argument compatibility path. The order docs and the
TypeScript declarations for orders.fetch are updated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZJQzxtgWvkWobxsDcuLoW
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.

[expands] is not available in the instance.orders.fetch(orderId) while its available on the http API

1 participant