Class: KktShoppe::Payment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- KktShoppe::Payment
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- app/models/kkt_shoppe/payment.rb
Instance Method Summary collapse
-
#order ⇒ KktShoppe::Order
The associated order.
-
#parent ⇒ KktShoppe::Payment
An associated payment (only applies to refunds).
-
#refund!(amount) ⇒ Boolean
Process a refund from this payment.
-
#refund? ⇒ Boolean
Is this payment a refund?.
-
#refundable_amount ⇒ BigDecimal
How much of the payment can be refunded.
-
#refunded? ⇒ Boolean
Has this payment had any refunds taken from it?.
-
#transaction_url ⇒ String
Return a transaction URL for viewing further information about this payment.
Instance Method Details
#order ⇒ KktShoppe::Order
The associated order
11 |
# File 'app/models/kkt_shoppe/payment.rb', line 11 belongs_to :order, :class_name => 'KktShoppe::Order' |
#parent ⇒ KktShoppe::Payment
An associated payment (only applies to refunds)
16 |
# File 'app/models/kkt_shoppe/payment.rb', line 16 belongs_to :parent, :class_name => "KktShoppe::Payment", :foreign_key => "parent_payment_id" |
#refund!(amount) ⇒ Boolean
Process a refund from this payment.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/kkt_shoppe/payment.rb', line 56 def refund!(amount) run_callbacks :refund do amount = BigDecimal(amount) if refundable_amount >= amount transaction do self.class.create(:parent => self, :order_id => self.order_id, :amount => 0-amount, :method => self.method, :reference => reference) self.update_attribute(:amount_refunded, self.amount_refunded + amount) true end else raise KktShoppe::Errors::RefundFailed, :message => I18n.t('.refund_failed', refundable_amount: refundable_amount) end end end |
#refund? ⇒ Boolean
Is this payment a refund?
34 35 36 |
# File 'app/models/kkt_shoppe/payment.rb', line 34 def refund? self.amount < BigDecimal(0) end |
#refundable_amount ⇒ BigDecimal
How much of the payment can be refunded
48 49 50 |
# File 'app/models/kkt_shoppe/payment.rb', line 48 def refundable_amount refundable? ? (self.amount - self.amount_refunded) : BigDecimal(0) end |
#refunded? ⇒ Boolean
Has this payment had any refunds taken from it?
41 42 43 |
# File 'app/models/kkt_shoppe/payment.rb', line 41 def refunded? self.amount_refunded > BigDecimal(0) end |
#transaction_url ⇒ String
Return a transaction URL for viewing further information about this payment.
75 76 77 |
# File 'app/models/kkt_shoppe/payment.rb', line 75 def transaction_url nil end |