2011-12-07 22:00:27 +00:00
|
|
|
class Spree::PaypalAccount < ActiveRecord::Base
|
2012-05-01 16:47:04 +00:00
|
|
|
attr_accessible :email, :payer_id, :payer_country, :payer_status
|
2010-02-24 20:43:18 +00:00
|
|
|
has_many :payments, :as => :source
|
|
|
|
|
2010-02-25 16:20:15 +00:00
|
|
|
def actions
|
2011-12-02 20:37:42 +00:00
|
|
|
%w{capture credit adjust}
|
2010-02-25 16:20:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_capture?(payment)
|
2010-11-28 14:31:31 +00:00
|
|
|
!echeck?(payment) && payment.state == "pending"
|
2010-02-25 16:20:15 +00:00
|
|
|
end
|
|
|
|
|
2011-12-02 20:37:42 +00:00
|
|
|
def can_adjust?(payment)
|
|
|
|
can_capture?(payment)
|
|
|
|
end
|
|
|
|
|
2010-02-25 16:20:15 +00:00
|
|
|
def can_credit?(payment)
|
2010-11-28 14:31:31 +00:00
|
|
|
return false unless payment.state == "completed"
|
|
|
|
return false unless payment.order.payment_state == "credit_owed"
|
|
|
|
payment.credit_allowed > 0
|
2012-05-31 22:06:16 +00:00
|
|
|
!payment.payment_method.find_capture(payment).nil?
|
2010-02-25 16:20:15 +00:00
|
|
|
end
|
2010-05-12 16:06:24 +00:00
|
|
|
|
2010-03-05 11:59:20 +00:00
|
|
|
# fix for Payment#payment_profiles_supported?
|
|
|
|
def payment_gateway
|
|
|
|
false
|
|
|
|
end
|
2010-02-25 16:20:15 +00:00
|
|
|
|
2010-12-23 13:46:57 +00:00
|
|
|
def echeck?(payment)
|
2011-01-18 16:11:33 +00:00
|
|
|
logs = payment.log_entries.all(:order => 'created_at DESC')
|
|
|
|
logs.each do |log|
|
|
|
|
details = YAML.load(log.details) # return the transaction details
|
|
|
|
if details.params['payment_type'] == 'echeck'
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2010-02-24 20:43:18 +00:00
|
|
|
end
|