Skip to content
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

Issue canceling subscription on stripe's website - leaves plan_id in db to make the subscription appear active. #178

Open
gwalshington opened this issue Jun 23, 2017 · 8 comments

Comments

@gwalshington
Copy link

gwalshington commented Jun 23, 2017

The issue:

When subscriptions are cancelled on Stripe's dashboard instead of in the rails app, Subscription in the database still has a plan_id present, which makes

Subscription.exists?(:user_id => current_user.id)
true

This makes it appear on the views as if the subscription is still active. So when the user clicks cancel, there is an error. Then, I tried setting plan_id to nil manually in the console, and got the same error:

irb(main):021:0>s = Subscription.find(1)
irb(main):022:0> s.plan_id = nil
=> nil
irb(main):023:0> s.save
   (6.5ms)  BEGIN
   (5.2ms)  ROLLBACK
Stripe::InvalidRequestError: (Status 404) (Request req_AtnzH4egKHi6Xt) No active subscriptions for customer: cus_9zB6PvzSrfqfWb
@gwalshington gwalshington changed the title No active subscriptions for customer: cus_9zB6PvzSrfqfVb Issue canceling subscription on stripe's website - leaves plan_id in db to make the subscription appear active. Jun 23, 2017
@yas4891
Copy link
Collaborator

yas4891 commented Jun 24, 2017

Hi @gwalshington

can you please point a webhook to /koudoku/webhooks on your app?

Koudoku should then handle this via this code: https://github.com/andrewculver/koudoku/blob/master/config/initializers/stripe_event.rb#L22

If not, please add a #cancel method to your subscription_owner class

@amloelxer
Copy link

@yas4891 any idea of what that webhook should look like? I have a similar problem and in my routes.rb file I have this, and it obviously isn't working. Any help is greatly appreciated!
post '/koudoku/webhooks' => "controller#my_method"

@yas4891
Copy link
Collaborator

yas4891 commented Jul 25, 2017

@amloelxer
You don't need to add a controller to handle this. You just point the webhook in to /koudoku/webhooks via the Stripe Dashboard.

Then you follow the instructions here: https://github.com/andrewculver/koudoku#webhooks

If you need further help, let me know!

@amloelxer
Copy link

amloelxer commented Jul 25, 2017

@yas4891 ahh that makes a lot more sense. I added the webhook of https://www.mywebsite.com/koudoku/webhooks and got a success on the stripe side, but still have the active subscription in my database. Is there anyway to log that Koudoku has indeed received the hook?

@yas4891
Copy link
Collaborator

yas4891 commented Jul 25, 2017 via email

@amloelxer
Copy link

@yas4891 thanks so much for your help! Sorry for all the novice questions. I'm new to web dev

@amloelxer
Copy link

@yas4891 one more question. When I respond to the webhook that cancels the payment (which I canceled from the stripe dashboard), I try to set my local subscription plan_id to nil and save it. Unfortunately when I do this, it tries to send the update remotely as well and obviously errors out because there is no active subscription on the stripe servers/dashboard once I cancel it. Is there way to do an update to my local db of subscriptions and not affect the ones in stripe?

@yas4891
Copy link
Collaborator

yas4891 commented Jul 27, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants