Class: Tienda::Payment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tienda::Payment
- Defined in:
- app/models/tienda/payment.rb
Instance Method Summary collapse
-
#order ⇒ Tienda::Order
The associated order.
-
#parent ⇒ Tienda::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 ⇒ Tienda::Order
The associated order
7 |
# File 'app/models/tienda/payment.rb', line 7 belongs_to :order, :class_name => 'Tienda::Order' |
#parent ⇒ Tienda::Payment
An associated payment (only applies to refunds)
12 |
# File 'app/models/tienda/payment.rb', line 12 belongs_to :parent, :class_name => "Tienda::Payment", :foreign_key => "parent_payment_id" |
#refund!(amount) ⇒ Boolean
Process a refund from this payment.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/tienda/payment.rb', line 52 def refund!(amount) 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 Tienda::Errors::RefundFailed, :message => I18n.t('.refund_failed', refundable_amount: refundable_amount) end end |
#refund? ⇒ Boolean
Is this payment a refund?
30 31 32 |
# File 'app/models/tienda/payment.rb', line 30 def refund? self.amount < BigDecimal(0) end |
#refundable_amount ⇒ BigDecimal
How much of the payment can be refunded
44 45 46 |
# File 'app/models/tienda/payment.rb', line 44 def refundable_amount refundable? ? (self.amount - self.amount_refunded) : BigDecimal(0) end |
#refunded? ⇒ Boolean
Has this payment had any refunds taken from it?
37 38 39 |
# File 'app/models/tienda/payment.rb', line 37 def refunded? self.amount_refunded > BigDecimal(0) end |
#transaction_url ⇒ String
Return a transaction URL for viewing further information about this payment.
69 70 71 |
# File 'app/models/tienda/payment.rb', line 69 def transaction_url nil end |