Skip to content

Don't explode if a subscription doesn't exist when being hit from Stripe webhook - #177

Open
jayelkaake wants to merge 1 commit into
andrewculver:masterfrom
jayelkaake:dont_die_on_stripe_webhooks
Open

jayelkaake wants to merge 1 commit into
andrewculver:masterfrom
jayelkaake:dont_die_on_stripe_webhooks

Conversation

@jayelkaake

Copy link
Copy Markdown

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 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!!

@jayelkaake jayelkaake changed the title Don't expload if a subscription doesn't exist when being hit from Stripe webhook Don't explode if a subscription doesn't exist when being hit from Stripe webhook May 24, 2017
@donnfelker

Copy link
Copy Markdown

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.
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

Successfully merging this pull request may close these issues.

2 participants