stripe-ruby icon indicating copy to clipboard operation
stripe-ruby copied to clipboard

"expand" doesn't work.

Open BKucherevych opened this issue 6 years ago • 4 comments

Versions: ruby: 2.3.7 stripe: 5.25.0

2.3.7 :002 > customer = Stripe::Customer.retrieve(subscription.user.stripe_customer_id, expand: ['subscriptions'])
  User Load (1.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = $1 LIMIT 1  [["id", 94831]]
NoMethodError: undefined method `strip' for ["subscriptions"]:Array
        from /Users/BKucherevych/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/net/http/header.rb:18:in `block in initialize_http_header'
        from /Users/BKucherevych/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/net/http/header.rb:16:in `each'
        from /Users/BKucherevych/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/net/http/header.rb:16:in `initialize_http_header'
        from /Users/BKucherevych/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/net/http/generic_request.rb:44:in `initialize'
        from /Users/BKucherevych/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/net/http.rb:1363:in `new'
        from /Users/BKucherevych/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/net/http.rb:1363:in `send_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/connection_manager.rb:94:in `block in execute_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/connection_manager.rb:93:in `synchronize'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/connection_manager.rb:93:in `execute_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/stripe_client.rb:234:in `block in execute_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/stripe_client.rb:462:in `execute_request_with_rescues'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/stripe_client.rb:233:in `execute_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/api_operations/request.rb:25:in `execute_resource_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/api_operations/request.rb:89:in `execute_resource_request'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/api_resource.rb:96:in `refresh'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/stripe-5.25.0/lib/stripe/api_resource.rb:104:in `retrieve'
        from (irb):2
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/railties-4.1.16/lib/rails/commands/console.rb:90:in `start'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/railties-4.1.16/lib/rails/commands/console.rb:9:in `start'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:69:in `console'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/railties-4.1.16/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from /Users/BKucherevych/.rvm/gems/ruby-2.3.7/gems/railties-4.1.16/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

BKucherevych avatar Sep 17 '20 09:09 BKucherevych

@BKucherevych Try this instead:

Stripe::Customer.retrieve({
  id: subscription.user.stripe_customer_id,
  expand: ['subscriptions'],
})

remi-stripe avatar Sep 17 '20 19:09 remi-stripe

Before I end up here, I tried to expand invoice_settings.default_payment_method and my first thought was - maybe it's not supported. Only after checking expansion with Stripe CLI I realized this is some bug in the gem.

The workaround above worked for me, thank you @remi-stripe . Although, I believe other people can easily run into the same issue, so would be great to have a fix.

cris avatar Jul 16 '21 13:07 cris

This isn't really a bug in the gem though, it's how it's supposed to work today. We plan to improve the interface of the library in the future to have a client/service infra similar to what we shipped in PHP recently https://github.com/stripe/stripe-php/wiki/Migration-to-StripeClient-and-services-in-7.33.0 which should help make this more discoverable.

remi-stripe avatar Jul 16 '21 16:07 remi-stripe

Well the doc says %w[latest_invoice.payment_intent], not ['latest_invoice.payment_intent'].

The gem is buggy or the doc is wrong, but for sure, in my eyes, closing this issue is a mistake :)


Edit: Actually, checking more carefully I saw that id: ... part. So the doc and the gem are aligned. Sorry for the noise.

zedtux avatar Jul 28 '21 19:07 zedtux