Class: Pay::Charge
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Pay::Charge
- Defined in:
- app/models/pay/charge.rb
Class Method Summary collapse
Instance Method Summary collapse
- #charged_to ⇒ Object
- #full_refund? ⇒ Boolean
- #partial_refund? ⇒ Boolean
- #payment_processor ⇒ Object
- #processor_charge ⇒ Object
- #refund!(refund_amount = nil) ⇒ Object
- #refunded? ⇒ Boolean
Class Method Details
.find_by_processor_and_id(processor, processor_id) ⇒ Object
42 43 44 |
# File 'app/models/pay/charge.rb', line 42 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
46 47 48 |
# File 'app/models/pay/charge.rb', line 46 def self.pay_processor_for(name) "Pay::#{name.to_s.classify}::Charge".constantize end |
Instance Method Details
#charged_to ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/pay/charge.rb', line 75 def charged_to case payment_method_type when "card" "#{brand.titleize} (**** **** **** #{last4})" when "paypal" "#{brand} (#{email})" # Braintree when "venmo" "#{brand.titleize} #{username}" when "us_bank_account" "#{bank} #{last4}" # Stripe when "acss_debit" "#{bank} #{last4}" when "eps", "fpx", "ideal", "p24" bank when "au_becs_debit" "BECS Debit #{last4}" when "bacs_debit" "Bacs Debit #{last4}" when "sepa_debit" "SEPA Debit #{last4}" else payment_method_type&.titleize end end |
#full_refund? ⇒ Boolean
67 68 69 |
# File 'app/models/pay/charge.rb', line 67 def full_refund? refunded? && amount == amount_refunded end |
#partial_refund? ⇒ Boolean
71 72 73 |
# File 'app/models/pay/charge.rb', line 71 def partial_refund? refunded? && !full_refund? end |
#payment_processor ⇒ Object
50 51 52 |
# File 'app/models/pay/charge.rb', line 50 def payment_processor @payment_processor ||= self.class.pay_processor_for(customer.processor).new(self) end |
#processor_charge ⇒ Object
54 55 56 |
# File 'app/models/pay/charge.rb', line 54 def processor_charge payment_processor.charge end |
#refund!(refund_amount = nil) ⇒ Object
58 59 60 61 |
# File 'app/models/pay/charge.rb', line 58 def refund!(refund_amount = nil) refund_amount ||= amount payment_processor.refund!(refund_amount) end |
#refunded? ⇒ Boolean
63 64 65 |
# File 'app/models/pay/charge.rb', line 63 def refunded? amount_refunded.to_i > 0 end |