Class: Pay::PaymentMethod

Inherits:
ApplicationRecord show all
Defined in:
app/models/pay/payment_method.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_processor_and_id(processor, processor_id) ⇒ Object



15
16
17
# File 'app/models/pay/payment_method.rb', line 15

def self.find_by_processor_and_id(processor, processor_id)
  joins(:customer).find_by(processor_id: processor_id, pay_customers: {processor: processor})
end

.pay_processor_for(name) ⇒ Object



19
20
21
# File 'app/models/pay/payment_method.rb', line 19

def self.pay_processor_for(name)
  "Pay::#{name.to_s.classify}::PaymentMethod".constantize
end

Instance Method Details

#make_default!Object



27
28
29
30
31
32
33
34
# File 'app/models/pay/payment_method.rb', line 27

def make_default!
  return if default?

  payment_processor.make_default!

  customer.payment_methods.update_all(default: false)
  update!(default: true)
end

#payment_processorObject



23
24
25
# File 'app/models/pay/payment_method.rb', line 23

def payment_processor
  @payment_processor ||= self.class.pay_processor_for(customer.processor).new(self)
end