Don't explode if a subscription doesn't exist when being hit from Stripe webhook - #177
Open
jayelkaake wants to merge 1 commit into
Open
jayelkaake wants to merge 1 commit into
jayelkaake wants to merge 1 commit into
Conversation
|
Good stuff. I agree, this should be in the gem. I recently ran into this as well after manually migrating from a Wordpress Plugin to a custom rails site that uses Koudoku. Kudos for this. |
donnfelker
added a commit
to donnfelker/koudoku
that referenced
this pull request
Jan 3, 2018
Inspiration: andrewculver#177 This happens when you use Stripe for other things other than subscriptions, such as gift coupons. If stripe gets an error while sending a webhook it will continue to try to send the webhook and will eventually threaten to kill off your webhook if the errors keep continuing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_idthat 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 methodpayment_succeeded' for nil:NilClass, just log a warning if the subscription doesn't exist for thestripe_id` that was posted.Also...
Using dynamic
find_by's likefind_by_blehis deprecated in Rails 4 and you should usefind_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!!