Module: Billy::Attributes::AccountExtension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/billy/attributes.rb
Instance Method Summary collapse
-
#set_billy_account(processor_name, **attributes) ⇒ Object
Changes a user’s payment processor.
Instance Method Details
#set_billy_account(processor_name, **attributes) ⇒ Object
Changes a user’s payment processor
This has several effects:
-
Finds or creates a Billy::Account for the process and marks it as default
-
Removes the default flag from all other Billy::Customers
-
Removes the default flag from all Billy::PaymentMethods
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/billy/attributes.rb', line 23 def set_billy_account(processor_name, **attributes) # raise Billy::Error, "Processor `#{processor_name}` is not allowed" if processor_name.to_s == "fake_processor" && !allow_fake ActiveRecord::Base.transaction do billy_accounts.update_all(default: false) billy_account = billy_accounts.active.where(processor: processor_name).first_or_initialize billy_account.update!(attributes.merge(default: true)) end # Return new payment processor reload_billy_account end |