Class: CreditcardPayment

Inherits:
Payment show all
Defined in:
app/models/creditcard_payment.rb

Instance Method Summary collapse

Instance Method Details

#authorizationObject



19
20
21
22
23
24
# File 'app/models/creditcard_payment.rb', line 19

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

#can_capture?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'app/models/creditcard_payment.rb', line 8

def can_capture?
  txns.present? and txns.last == authorization
end

#captureObject



12
13
14
15
16
17
# File 'app/models/creditcard_payment.rb', line 12

def capture
  return unless can_capture?
  original_auth = authorization
  creditcard.capture(original_auth)
  update_attribute("amount", original_auth.amount)
end