Don't explode if a subscription doesn't exist when being hit from Stripe webhook #177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
If you use your Stripe account for other things other than the stuff you are linking to Koudoku then Stripe still hits the Koudoku webhooks with events from the other stuff. The result is that the
stripe_id
that hits the Koudoku registered webhooks throws a 500 error to Stripe.Now that would be fine, and maybe even a good thing, HOWEVER Stripe will keep retrying to hit the webhook until it gets a 200 response. Eventually Stripe will threaten to even kill your webhook.
The Solution
Instead of letting it throw errors like
NoMethodError: undefined method
payment_succeeded' for nil:NilClass, just log a warning if the subscription doesn't exist for the
stripe_id` that was posted.Also...
Using dynamic
find_by's like
find_by_blehis deprecated in Rails 4 and you should use
find_by(stripe_id: strip_id)` instead, so I updated these lines. See http://edgeguides.rubyonrails.org/4_0_release_notes.html#active-record-deprecations for reference.Great gem BTW! Very useful!!