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

Inline object expansion not working again on master

Open flats opened this issue 10 years ago • 4 comments

Reprise of https://github.com/stripe/stripe-ruby/issues/206.

I believe that this issue has cropped up again - I'm not able to get inline object expansion working on master using the following (from the docs):

stripe_charge = Stripe::Charge.retrieve("ch_18WWaW4QFaGycgRKreD14QhN", :expand => ['customer'])
=> #<Stripe::Charge:0x36fe64c id=ch_18WWaW4QFaGycgRKreD14QhN> JSON: {
  "id": "ch_18WWaW4QFaGycgRKreD14QhN",
  "object": "charge"
  ...
stripe_charge.customer
=> "cus_8o8s5t5T0fqezB"

The docs cover the necessary arguments for #retrieve, but there's no example of object expansion in action. Am I missing something here? stripe_charge.customer here should return a Stripe::Customer object, correct?

flats avatar Jul 12 '16 20:07 flats

Hi @flats,

Sorry about the delayed response here!

Short answer. Do this instead:

stripe_charge = Stripe::Charge.retrieve({:id => "ch_18WrTH2eZvKYlo2C1yiR1O3s", :expand => ['customer']})

The parameters to .retrieve are a little unfortunate, and currently require expand to be sent as part of a hash which goes into the first position parameter.

I believe this is my fault in that I made a recent tweak to the expansion docs for Ruby, and they are currently incorrect. I'm taking a look at either reverting them or seeing if we can make this method's signature slightly less terrible so that you can use it with the code above. I'll post back here once I've found something.

brandur avatar Jul 13 '16 18:07 brandur

Also added a proof of concept that allows the alternative syntax in #445.

brandur avatar Jul 13 '16 22:07 brandur

Thanks so much for your prompt response, @brandur! Just tried it out and it worked like a charm. I'll use this syntax moving forward.

flats avatar Jul 14 '16 15:07 flats

NP! I've shipped a correction to our documentation, so I've closed this out for the time being. I'll take a little time to mull over #445.

brandur avatar Jul 14 '16 18:07 brandur