spree_paypal_express/app/models/spree/paypal_account.rb

41 lines
980 B
Ruby
Raw Normal View History

2011-12-07 22:00:27 +00:00
class Spree::PaypalAccount < ActiveRecord::Base
attr_accessible :email, :payer_id, :payer_country, :payer_status
has_many :payments, :as => :source
2010-02-25 16:20:15 +00:00
def actions
%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
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
!payment.payment_method.find_capture(payment).nil?
2010-02-25 16:20:15 +00:00
end
2010-05-12 16:06:24 +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
end