Files
openfoodnetwork/app/models/stripe_account.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

24 lines
702 B
Ruby

# frozen_string_literal: true
class StripeAccount < ApplicationRecord
belongs_to :enterprise
validates :stripe_user_id, :stripe_publishable_key, presence: true
validates :enterprise_id, uniqueness: true
def deauthorize_and_destroy
accounts = StripeAccount.where(stripe_user_id: stripe_user_id)
# Only deauthorize the user if it is not linked to multiple accounts
return destroy if accounts.count > 1
destroy && Stripe::OAuth.deauthorize(stripe_user_id: stripe_user_id)
rescue Stripe::OAuth::OAuthError
Bugsnag.notify(
RuntimeError.new("StripeDeauthorizeFailure"),
stripe_account: stripe_user_id,
enterprise_id: enterprise_id
)
true
end
end