app/models/creditcard_payment.rb in spree-0.8.5 vs app/models/creditcard_payment.rb in spree-0.9.0
- old
+ new
@@ -3,16 +3,24 @@
belongs_to :creditcard
accepts_nested_attributes_for :creditcard
alias :txns :creditcard_txns
- def find_authorization
+ 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],
+ :conditions => ["txn_type = ? AND response_code IS NOT NULL", CreditcardTxn::TxnType::AUTHORIZE.to_s],
:order => 'created_at DESC')
end
- def can_capture?
- txns.last == find_authorization
- end
end
\ No newline at end of file