diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 971a080863..e795645261 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -141,6 +141,15 @@ module Admin end end + def stripe_disconnect + if deauthorize_stripe(params[:account_id]) + respond_to do |format| + format.html { redirect_to main_app.edit_admin_enterprise_path(@enterprise), notice: "Stripe account disconnected."} + format.json { render json: "Disconnected" } + end + end + end + protected def build_resource_with_address diff --git a/app/helpers/admin/stripe_helper.rb b/app/helpers/admin/stripe_helper.rb index 2e54158b83..f7400dd9e3 100644 --- a/app/helpers/admin/stripe_helper.rb +++ b/app/helpers/admin/stripe_helper.rb @@ -3,6 +3,7 @@ require File.join(Rails.root, '/lib/oauth2/client') require 'oauth2' module Admin module StripeHelper + class << self attr_accessor :client, :options end @@ -34,7 +35,11 @@ module Admin stripe_account = StripeAccount.find(account_id) if stripe_account response = StripeHelper.client.deauthorize(stripe_account.stripe_user_id).deauthorize_request + if response # Response from OAuth2 only returned if successful + stripe_account.destroy + end end end + end end diff --git a/app/views/admin/enterprises/form/_stripe_connect.html.haml b/app/views/admin/enterprises/form/_stripe_connect.html.haml index acc36ff87d..eb84e97ad9 100644 --- a/app/views/admin/enterprises/form/_stripe_connect.html.haml +++ b/app/views/admin/enterprises/form/_stripe_connect.html.haml @@ -1,7 +1,6 @@ -- if stripe_account = @enterprise.stripe_account +- if @stripe_account = @enterprise.stripe_account = t :stripe_account_connected - = stripe_account.inspect - .span (Link to disconnect Stripe Acct) + = link_to 'Delete', main_app.admin_enterprise_stripe_account_path(@enterprise,@stripe_account), method: :delete - else %a.stripe-connect{href: 'stripe_connect'} .span= t :connect_with_stripe diff --git a/config/routes.rb b/config/routes.rb index 1e6f681f8b..a369de8051 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,7 +72,6 @@ Openfoodnetwork::Application.routes.draw do post :search get :check_permalink end - member do get :shop @@ -102,7 +101,7 @@ Openfoodnetwork::Application.routes.draw do end get "/stripe_connect", to: "enterprises#stripe_connect" - + resources :stripe_accounts member do get :welcome