Class: Spree::Payment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#source_attributesObject

Returns the value of attribute source_attributes.



15
16
17
# File 'app/models/spree/payment.rb', line 15

def source_attributes
  @source_attributes
end

Instance Method Details

#actionsObject



87
88
89
90
# File 'app/models/spree/payment.rb', line 87

def actions
  return [] unless payment_source and payment_source.respond_to? :actions
  payment_source.actions.select { |action| !payment_source.respond_to?("can_#{action}?") or payment_source.send("can_#{action}?", self) }
end

#build_sourceObject



66
67
68
69
70
71
72
# File 'app/models/spree/payment.rb', line 66

def build_source
  return if source_attributes.nil?

  if payment_method and payment_method.payment_source_class
    self.source = payment_method.payment_source_class.new(source_attributes)
  end
end

#can_credit?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/spree/payment.rb', line 55

def can_credit?
  credit_allowed > 0
end

#credit(amount) ⇒ Object



59
60
61
62
63
# File 'app/models/spree/payment.rb', line 59

def credit(amount)
  return if amount > credit_allowed
  started_processing!
  source.credit(self, amount)
end

#credit_allowedObject



51
52
53
# File 'app/models/spree/payment.rb', line 51

def credit_allowed
  amount - offsets_total
end

#offsets_totalObject



47
48
49
# File 'app/models/spree/payment.rb', line 47

def offsets_total
  offsets.map(&:amount).sum
end

#payment_sourceObject



92
93
94
95
# File 'app/models/spree/payment.rb', line 92

def payment_source
  res = source.is_a?(Payment) ? source.source : source
  res || payment_method
end

#process!Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/spree/payment.rb', line 74

def process!
  if payment_method && payment_method.source_required?
    if source
      if !processing? && source.respond_to?(:process!)
        started_processing!
        source.process!(self) # source is responsible for updating the payment state when it's done processing
      end
    else
      raise Core::GatewayError.new(I18n.t(:payment_processing_failed))
    end
  end
end