Support expand[] in orders.fetch and send expand[] the way the API expects (#332) - #489
Open
yashbudhia wants to merge 1 commit into
Open
yashbudhia wants to merge 1 commit into
yashbudhia wants to merge 1 commit into
Conversation
…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
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.
Closes #332.
instance.orders.fetch(orderId)had no way to passexpand[], even though the HTTP API accepts it on that endpoint andorders.all()already exposes it. This adds an optionalparamsargument, mirroringpayments.fetch(paymentId, params):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:which the API does not recognise. Sending the value under the flat
"expand[]"key produces what the API reference documents, including oneexpand[]=per value when an array is passed: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.jsandtest/resources/payments.spec.jsassert the parsed query params and the formed URL forfetchandall, multipleexpand[]values, and the callback-as-second-argument path. Full suite: 384 passing.Also
documents/order.mddocuments the new parameter with an example.lib/types/orders.d.tsgainsOrders.ExpandDetailsand the matchingfetchoverloads.dist/is not included; it is rebuilt bynpm test.test/resources/orders.spec.js,test/resources/payments.spec.js.