Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET requests with arrays in data not handled correctly by stripe API #561

Closed
richie3366 opened this issue Feb 2, 2019 · 4 comments
Closed
Labels

Comments

@richie3366
Copy link

richie3366 commented Feb 2, 2019

I noticed (and found a workaround to solve) a bug occurring in GET requests with data containing arrays.

For example: stripe.invoices.retrieve('upcoming', {..., subscription_items: [..., ...] })

This will try to make a GET request with url-encoded data (in the body of the request apparently(?)), but the converted querystring doesn't** have array indexes.
**: purposely, according to the commit found via blame ; and also according to the 'Stripe-specific cases' test in utils.spec.js)

Thing is: Stripe API seems to need them to understand the query.

Current code in utils.js:

  /**
   * Stringifies an Object, accommodating nested objects
   * (forming the conventional key 'parent[child]=value')
   */
  stringifyRequestData: function(data) {
    // console.log('stringifyRequestData', data, qs.stringify(data, {arrayFormat: 'brackets'}))
    return qs.stringify(data, {arrayFormat: 'brackets'});
  },

outputs:

subscription=sub_ES6MM9DZExqcN0&subscription_prorate=true&subscription_items%5B%5D%5Bid%5D=si_ES6MwymN93s0Fh&subscription_items%5B%5D%5Bdeleted%5D=true&subscription_items%5B%5D%5Bplan%5D=business_monthly&subscription_items%5B%5D%5Bquantity%5D=1&coupon=redacted

urldecoded:

subscription=sub_ES6MM9DZExqcN0&subscription_prorate=true&subscription_items[][id]=si_ES6MwymN93s0Fh&subscription_items[][deleted]=true&subscription_items[][plan]=business_monthly&subscription_items[][quantity]=1&coupon=redacted

Log trace in Stripe Dashboard:
screenshot at 02-05-39

With workaround:

  /**
   * Stringifies an Object, accommodating nested objects
   * (forming the conventional key 'parent[child]=value')
   */
  stringifyRequestData: function(data) {
    // console.log('stringifyRequestData', data, qs.stringify(data, {arrayFormat: 'brackets'}))
    return qs.stringify(data);
  },

outputs:

subscription=sub_ES6MM9DZExqcN0&subscription_prorate=true&subscription_items%5B0%5D%5Bid%5D=si_ES6MwymN93s0Fh&subscription_items%5B0%5D%5Bdeleted%5D=true&subscription_items%5B1%5D%5Bplan%5D=business_monthly&subscription_items%5B1%5D%5Bquantity%5D=1&coupon=redacted

urldecoded:

subscription=sub_ES6MM9DZExqcN0&subscription_prorate=true&subscription_items[0][id]=si_ES6MwymN93s0Fh&subscription_items[0][deleted]=true&subscription_items[1][plan]=business_monthly&subscription_items[1][quantity]=1&coupon=redacted

Log trace in Stripe Dashboard:
screenshot at 02-06-32

So, either you have to fix it in your API backend (to accept unindexed array backets), or fix it here (to provide API compatible format).

Thanks.

@remi-stripe
Copy link
Contributor

@richie3366 Thanks a lot for the detailed bug report! This is something that has happened in some of our other libraries such as reported here.

We're going to take a look to ensure we fix it properly on all requests in stripe-node.

@remi-stripe remi-stripe added the bug label Feb 2, 2019
@abrisene
Copy link

This also appears to happen with POST requests. I discovered while trying to create products with attributes for the first time and encountered range errors.

Converting the array to an integer indexed object (as shown in the workaround posted by @richie3366) fixed the issue.

@remi-stripe
Copy link
Contributor

@abrisene Thanks for the extra details here and sorry for the delay on that one. We are investigating and will try to fix that next week!

@ob-stripe
Copy link
Contributor

This should be fixed in 6.25.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants