Sha256: 63a13990ae9509fbb0389d89461f7c0fbed555a0a9b8c9b4e51bdb2ef3e0054e

Contents?: true

Size: 718 Bytes

Versions: 6

Compression:

Stored size: 718 Bytes

Contents

class CreditcardPayment < Payment
  has_many :creditcard_txns
  belongs_to :creditcard
  accepts_nested_attributes_for :creditcard
  
  alias :txns :creditcard_txns
  
  def can_capture?
    txns.present? and txns.last == authorization
  end
  
  def capture
    return unless can_capture?
    original_auth = authorization
    creditcard.capture(original_auth)
    update_attribute("amount", original_auth.amount)
  end
  
  def authorization
    #find the transaction associated with the original authorization/capture 
    txns.find(:first, 
              :conditions => ["txn_type = ? AND response_code IS NOT NULL", CreditcardTxn::TxnType::AUTHORIZE.to_s],
              :order => 'created_at DESC')
  end 
  
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
spree-enriquez-0.9.4 app/models/creditcard_payment.rb
spree-0.9.4 app/models/creditcard_payment.rb
spree-0.9.3 app/models/creditcard_payment.rb
spree-0.9.2 app/models/creditcard_payment.rb
spree-0.9.1 app/models/creditcard_payment.rb
spree-0.9.0 app/models/creditcard_payment.rb