3

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.

Community
  • 1
  • 1
softcode
  • 4,358
  • 12
  • 41
  • 68

2 Answers2

5

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

SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53
  • Thanks for a quick reply. They actually ask for a 200 ... I updated my answer, you might want to update yours. @SteveTurczyn – softcode Jan 30 '15 at 21:21
1

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.

smathy
  • 26,283
  • 5
  • 48
  • 68