Module: Pay::Attributes::MerchantExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/pay/attributes.rb

Instance Method Summary collapse

Instance Method Details

#set_merchant_processor(processor_name, **attributes) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/pay/attributes.rb', line 83

def set_merchant_processor(processor_name, **attributes)
  ActiveRecord::Base.transaction do
    pay_merchants.update_all(default: false)
    pay_merchant = pay_merchants.where(processor: processor_name, type: "Pay::#{processor_name.to_s.classify}::Merchant").first_or_initialize
    pay_merchant.update!(attributes.merge(default: true))
  end

  # Return new payment processor
  reload_merchant_processor
end