-
Notifications
You must be signed in to change notification settings - Fork 553
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
subscription_items
on Subscription::update() is failing
#554
Comments
Arg, good catch. I'm a little surprised we didn't add support for this back when we decided to make the indexed map style calls kosher for subscriptions. We should probably add an alternate encoding method with the expectation that will eventually be general purpose enough to be usable for encoding all parameters. I think the expectation right now is that although the indexed map style calls only work for subscription items (and maybe a few other places that have been moved to the new abstract API method infrastructure), eventually we'll support it on every endpoint. |
I believe I am experiencing a related issue. Given this:
I get the following error:
So, it seems maybe the encoding is reordering the keys? |
Perhaps using SubscriptionItem (update|delete|create) is the "workaround"... but that'll obviously require a handful of separate API calls to accomplish the same thing. |
Okay, so here's what's happening:
To illustrate: subscription = Stripe::Subscription.new
subscription.items = [{plan: 'test-1', id: 'si_blah_blah'}, {plan: 'test-2'}]
subscription.serialize_params returns: {:items=>[{:id=>"si_blah_blah", :plan=>"test-1"}, {:plan=>"test-2"}]}
subscription.items = {'0': {plan: 'test-1', id: 'si_blah_blah'}, '1': {plan: 'test-2'}}
subscription.save (Edit: nevermind, the workaround doesn't actually work :( ) This should be handled internally by the client library itself though. We'll work on a fix. |
Thanks @ob-stripe, very helpful. Also, good to hear about the "workaround". I'll try that! |
The workaround doesn't do it for me: subscription.items = {'0': {deleted: true, id: 'si_blah_blah'}, '1': {plan: 'test-2'}}
subscription.serialize_params
{:items=>
{:object=>"",
:data=>"",
:has_more=>"",
:total_count=>"",
:url=>"",
:"0"=>{:deleted=>true, :id=>"si_blah_blah"},
:"1"=>{:plan=>"test-2"}},
:metadata=>{}} and Stripe::InvalidRequestError: (Status 400) (Request req_f5Bv7SMfohtOey) Invalid array Am I missing something? |
my work around has been to simply use the https API for this type of subscription update. Something like this: items = [ { id: 'plan_1', deleted: true }, { plan: 'plan_2' } ]
query = {}
# this format worked well for the http request e.g.,
# {'0': { id: 'plan_1', deleted: true }, '1': { plan: 'plan_2' } }
items.each_with_index { |item, index| query[index] = item }
HTTParty.post(
"https://api.stripe.com/v1/subscriptions/#{subscription_id}",
query: query,
headers: { 'Authorization': "Bearer #{api_key}" }
) |
Hey everyone, I just wanted to let you know that we haven't forgotten about this. I can confirm that the workaround I offered above does not actually work because of a different issue in the library (sorry about that! I thought I tested it but apparently got confused). For now, you can certainly bypass the gem and send the HTTP request to the API using another client as @joebartels suggested just above. This obviously isn't ideal and we'll work on a fix to ensure that the stripe gem does what's expected. |
Fixed released as part of 3.5.3. |
Update the Stripe Gem up a few versions (not to the latest one), so we can fix [this issue](stripe/stripe-ruby#554).
Nested objects in an array are expected to all be the same shape, but that isn't the case for
subscription_items
, so the following won't currently work because it expects the second object to have anid
attribute:Probably better to switch this up to just use indexed maps like PHP and Node do.
I'm hoping to take a run at this in the next couple of days, but anyone else please feel free to push me out of the way and jump on it. :)
The text was updated successfully, but these errors were encountered: