Class: Pay::Charge
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Pay::Charge
- Defined in:
- app/models/pay/charge.rb
Class Method Summary collapse
Instance Method Summary collapse
- #amount_refunded_with_currency ⇒ Object
- #amount_with_currency ⇒ Object
- #captured? ⇒ Boolean
- #charged_to ⇒ Object
- #full_refund? ⇒ Boolean
- #line_items ⇒ Object
- #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
58 59 60 |
# File 'app/models/pay/charge.rb', line 58 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
62 63 64 |
# File 'app/models/pay/charge.rb', line 62 def self.pay_processor_for(name) "Pay::#{name.to_s.classify}::Charge".constantize end |
Instance Method Details
#amount_refunded_with_currency ⇒ Object
99 100 101 |
# File 'app/models/pay/charge.rb', line 99 def amount_refunded_with_currency Pay::Currency.format(amount_refunded, currency: currency) end |
#amount_with_currency ⇒ Object
95 96 97 |
# File 'app/models/pay/charge.rb', line 95 def amount_with_currency Pay::Currency.format(amount, currency: currency) end |
#captured? ⇒ Boolean
74 75 76 |
# File 'app/models/pay/charge.rb', line 74 def captured? amount_captured > 0 end |
#charged_to ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/pay/charge.rb', line 103 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
87 88 89 |
# File 'app/models/pay/charge.rb', line 87 def full_refund? refunded? && amount == amount_refunded end |
#line_items ⇒ Object
136 137 138 |
# File 'app/models/pay/charge.rb', line 136 def line_items Array.wrap(super) end |
#partial_refund? ⇒ Boolean
91 92 93 |
# File 'app/models/pay/charge.rb', line 91 def partial_refund? refunded? && !full_refund? end |
#payment_processor ⇒ Object
66 67 68 |
# File 'app/models/pay/charge.rb', line 66 def payment_processor @payment_processor ||= self.class.pay_processor_for(customer.processor).new(self) end |
#processor_charge ⇒ Object
70 71 72 |
# File 'app/models/pay/charge.rb', line 70 def processor_charge payment_processor.charge end |
#refund!(refund_amount = nil) ⇒ Object
78 79 80 81 |
# File 'app/models/pay/charge.rb', line 78 def refund!(refund_amount = nil) refund_amount ||= amount payment_processor.refund!(refund_amount) end |
#refunded? ⇒ Boolean
83 84 85 |
# File 'app/models/pay/charge.rb', line 83 def refunded? amount_refunded.to_i > 0 end |