softcode
softcode

Reputation: 4678

Can't return 200 to Stripe Webhook

I am trying to test receive JSON webhooks from Stripe.

I have read:

Stripe Webhook on Rails

https://stripe.com/docs/webhooks

They require a 200 status response in order to acknowledge receipt.

I want to solve this before moving on to dealing with the JSON.

routes

post 'webhook'       => 'web_hook#webhook'

controller

Stripe.api_key = "sk_test_whatsupbuttercup"
class WebHookController < ApplicationController
  protect_from_forgery :except => :webhook

  def webhook
    render status: 200
  end

end

With this setup, when I test a webhook, Stripe receives a 500 error.

Upvotes: 3

Views: 1750

Answers (2)

SteveTurczyn
SteveTurczyn

Reputation: 36880

If you only want to return a status use

head :ok

Instead of render. :ok is the corresponding symbol for 200 but you can also use it with the status code itself.

head 200

A full list of codes and corresponding symbols can be found here...

http://guides.rubyonrails.org/layouts_and_rendering.html

Upvotes: 5

smathy
smathy

Reputation: 27971

Whenever you get a 500 error (or any time you're confused about how your app is behaving actually) you should look in your logs. In this case you'll probably find that there's an ActionView::MissingTemplate error because you're rendering but not including anything to render.

Upvotes: 1

Related Questions