RailsApps / rails-stripe-membership-saas

An example Rails 4.2 app with Stripe and the Payola gem for a membership or subscription site.
http://railsapps.github.io/rails-stripe-membership-saas
1.14k stars 232 forks source link

Can't change subscription after account update with new email #134

Closed ghost closed 9 years ago

ghost commented 9 years ago

When a user updates their account with a new email address, it doesn't update the email address for the Payola subscription or on Stripe. So when the user decides to change subscriptions, there is an error that no subscription is found (because none exists for the new email).

It sounds like it would be better if Payola could key on something else other than an email address. Something that shouldn't change (like stripe token or subscription ID or something).

UPDATE: This issue still should be addressed but in the meantime, I've updated the registrations controller to find the subscription by owner_id instead for updating and cancelling the subscriptions so you don't get the error:

Update: subscription = Payola::Subscription.find_by!(owner_id: current_user.id)

Cancel: subscription = Payola::Subscription.find_by!(owner_id: current_user.id, state: 'active')

ghost commented 9 years ago

Actually, the issue with the email address not updating. Wouldn't that be an issue with this app? Updating the email via "edit account" seems like there should be some code to also make the change in the subscription in the DB which should then trigger some kind of webhook event to update the email on stripe....

kathyonu commented 9 years ago

May I recommend we enter the Stripe customer id into the database, and use that as the fixed focal point when changing email and subscription. It seems odd we do not record that Stripe assigned datum in the User table as it is the stable key relating the StripeCustomer to our User. I found that in the writing of the tests on the User / StripeCustomer connection, I could not draw on the StripeCustomer id because we do not yet record it.

ghost commented 9 years ago

I created code to update the Payola_Subscription table and Stripe.com when user updates email on the account edit page. This puts everything in sync.