f2ff5af4f5
* Sync owner email to Stripe when changed When an account owner changes their email address, update the corresponding Stripe customer record via a background job. Also handles ownership transfers: when a user becomes the account owner, their email is synced to Stripe. Responsibility chain: - User::NotifiesAccountOfEmailChange triggers on owner identity change or when a user becomes owner - Account::Billing#owner_email_changed enqueues sync job - Account::SyncStripeCustomerEmailJob performs the update with polynomial backoff retries - Account::Subscription#sync_customer_email_to_stripe calls Stripe API * Address PR feedback: error handling and test coverage - Handle Stripe::InvalidRequestError in sync_customer_email_to_stripe (mirrors cancel method behavior for deleted customers) - Add test for deactivated owner (owner with nil identity) - Add test for deleted Stripe customer scenario
24 lines
618 B
Ruby
24 lines
618 B
Ruby
module User::NotifiesAccountOfEmailChange
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
after_update :notify_account_of_owner_change, if: :account_owner_changed?
|
|
end
|
|
|
|
private
|
|
# Account owner changed when:
|
|
# - The current owner changed their email
|
|
# - A user just became the owner (ownership transfer)
|
|
def account_owner_changed?
|
|
owner? && identity && (saved_change_to_identity_id? || became_owner?)
|
|
end
|
|
|
|
def became_owner?
|
|
saved_change_to_role? && role_before_last_save != "owner"
|
|
end
|
|
|
|
def notify_account_of_owner_change
|
|
account.owner_email_changed
|
|
end
|
|
end
|