Files
openfoodnetwork/app/models/stripe_account.rb
David Cook f14f325441 Record exception details
Why mask the actual exception with a made-up one? The name did convey a bit more context, but Bugsnag tracks the context anyway. It would be more helpful to record the details of the error.

Just in case, I checked if there were any recorded instances of StripeDeauthorizeFailure. I couldn't find any in Bugsnag (last 3 months) for AU, Germany, Katuma, NZ, Norway, UK, USA. Also no mention in GitHub issues.
2024-01-17 15:16:51 +11:00

26 lines
667 B
Ruby

# frozen_string_literal: true
class StripeAccount < ApplicationRecord
self.belongs_to_required_by_default = false
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:)
# 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:)
rescue Stripe::OAuth::OAuthError => e
Bugsnag.notify(
e,
stripe_account: stripe_user_id,
enterprise_id:
)
true
end
end