chargify / chargify_api_ares

A Chargify API wrapper for Ruby using ActiveResource
http://chargify.com
MIT License
161 stars 95 forks source link

change product #100

Closed bbrealnex closed 9 years ago

bbrealnex commented 9 years ago

I want to be able to change the product of a subscription (not an upgrade/downgrade, but a change product with no migration). This doesn't seem to be working. For example:

subscription.product = p2 subscription.save (doesn't return an error but has no effect)

subscription.product.id = p2.id subscription.save (doesn't return an error but has no effect)

I saw another issue where it said to do:

subscription.product_id = p2.id

but subscription.product_id is not present

Let me know.

Thanks,

Ben

bbrealnex commented 9 years ago

Is doing a change product not possible with the current version of this gem? I can get migrations to work but a simple change product does not work. Please advise. Thanks!

wsmoak commented 9 years ago

Based on https://github.com/chargify/chargify_api_ares/blob/master/lib/chargify_api_ares/resources/subscription.rb#L13 any changes to subscription.product.[anything] will be ignored as the nested product gets stripped out before the save.

According to the API docs, to change the product you need to send something like

{"subscription": {"product_handle": "annual-plan"}}

So I tried

subscription.product_handle="annual-plan"
subscription.save

but that doesn't work. (No error, but it doesn't change the product.)

However, I've got it working locally by modifying the code and simply adding

      self.product_handle = self.product.handle

to subscription.rb before the product gets stripped out.

Then

subscription.product.handle = "new-product"
subscription.save

works.

I'll open a PR and see if that's the right way to go about it.

wsmoak commented 9 years ago

I submitted https://github.com/chargify/chargify_api_ares/pull/102 for discussion.