mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Namespace stripe webhook controller in Stripe module
This commit is contained in:
16
app/controllers/stripe/webhooks_controller.rb
Normal file
16
app/controllers/stripe/webhooks_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'stripe/webhook_handler'
|
||||
|
||||
module Stripe
|
||||
class WebhooksController < BaseController
|
||||
protect_from_forgery except: :create
|
||||
|
||||
# POST /stripe/webhook
|
||||
def create
|
||||
# TODO is there a sensible way to confirm this webhook call is actually from Stripe?
|
||||
handler = WebhookHandler.new(params)
|
||||
status = handler.handle ? 200 : 204
|
||||
|
||||
render nothing: true, status: status
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
require 'stripe/webhook_handler'
|
||||
|
||||
class StripeController < BaseController
|
||||
def webhook
|
||||
# TODO is there a sensible way to confirm this webhook call is actually from Stripe?
|
||||
handler = Stripe::WebhookHandler.new(params)
|
||||
status = handler.handle ? 200 : 204
|
||||
|
||||
render nothing: true, status: status
|
||||
end
|
||||
end
|
||||
@@ -30,7 +30,7 @@ CURRENCY: AUD
|
||||
# Stripe Connect details for instance account
|
||||
# Find these under 'API keys' and 'Connect' in your Stripe account dashboard -> Account Settings
|
||||
# Under 'Connect', the Redirect URI should be set to https://YOUR_SERVER_URL/stripe/callback (e.g. https://openfoodnetwork.org.uk/stripe/connect)
|
||||
# Under 'Webhooks', you should set up a Connect endpoint pointing to https://YOUR_SERVER_URL/stripe/webhook e.g. (https://openfoodnetwork.org.uk/stripe/webhook)
|
||||
# Under 'Webhooks', you should set up a Connect endpoint pointing to https://YOUR_SERVER_URL/stripe/webhooks e.g. (https://openfoodnetwork.org.uk/stripe/webhooks)
|
||||
# STRIPE_INSTANCE_SECRET_KEY: "sk_test_xxxxxx" # This can be a test key or a live key
|
||||
# STRIPE_INSTANCE_PUBLISHABLE_KEY: "pk_test_xxxx" # This can be a test key or a live key
|
||||
# STRIPE_CLIENT_ID: "ca_xxxx" # This can be a development ID or a production ID
|
||||
|
||||
@@ -53,8 +53,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resource :stripe, only: [] do
|
||||
post :webhook
|
||||
namespace :stripe do
|
||||
resources :webhooks, only: [:create]
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe StripeController do
|
||||
describe "#webhook" do
|
||||
describe Stripe::WebhooksController do
|
||||
describe "#create" do
|
||||
let!(:stripe_account) { create(:stripe_account, stripe_user_id: "webhook_id") }
|
||||
let(:params) do
|
||||
{
|
||||
@@ -15,7 +15,7 @@ describe StripeController do
|
||||
end
|
||||
|
||||
it "deletes Stripe accounts in response to a webhook" do
|
||||
post 'webhook', params
|
||||
post 'create', params
|
||||
expect(response.status).to eq 200
|
||||
expect(StripeAccount.all).not_to include stripe_account
|
||||
end
|
||||
@@ -26,7 +26,7 @@ describe StripeController do
|
||||
end
|
||||
|
||||
it "does nothing" do
|
||||
post 'webhook', params
|
||||
post 'create', params
|
||||
expect(response.status).to eq 204
|
||||
expect(StripeAccount.all).to include stripe_account
|
||||
end
|
||||
@@ -38,7 +38,7 @@ describe StripeController do
|
||||
end
|
||||
|
||||
it "does nothing" do
|
||||
post 'webhook', params
|
||||
post 'create', params
|
||||
expect(response.status).to eq 204
|
||||
expect(StripeAccount.all).to include stripe_account
|
||||
end
|
||||
Reference in New Issue
Block a user