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



51
52
53
# File 'app/models/pay/charge.rb', line 51

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

#payment_processorObject



34
35
36
# File 'app/models/pay/charge.rb', line 34

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

#payment_processor_for(name) ⇒ Object



38
39
40
# File 'app/models/pay/charge.rb', line 38

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

#paypal?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/pay/charge.rb', line 55

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

#processor_chargeObject



42
43
44
# File 'app/models/pay/charge.rb', line 42

def processor_charge
  payment_processor.charge
end

#refund!(refund_amount = nil) ⇒ Object



46
47
48
49
# File 'app/models/pay/charge.rb', line 46

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