Class: Pay::Charge

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

Instance Method Summary collapse

Methods inherited from ApplicationRecord

json_column?

Instance Method Details

#charged_toObject



49
50
51
# File 'app/models/pay/charge.rb', line 49

def charged_to
  "#{card_type} (**** **** **** #{card_last4})"
end

#payment_processorObject



32
33
34
# File 'app/models/pay/charge.rb', line 32

def payment_processor
  @payment_processor ||= payment_processor_for(processor).new(self)
end

#payment_processor_for(name) ⇒ Object



36
37
38
# File 'app/models/pay/charge.rb', line 36

def payment_processor_for(name)
  "Pay::#{name.to_s.classify}::Charge".constantize
end

#paypal?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/pay/charge.rb', line 53

def paypal?
  braintree? && card_type == "PayPal"
end

#processor_chargeObject



40
41
42
# File 'app/models/pay/charge.rb', line 40

def processor_charge
  payment_processor.charge
end

#refund!(refund_amount = nil) ⇒ Object



44
45
46
47
# File 'app/models/pay/charge.rb', line 44

def refund!(refund_amount = nil)
  refund_amount ||= amount
  payment_processor.refund!(refund_amount)
end