Class: Spree::Payment

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

Defined Under Namespace

Modules: Processing

Constant Summary collapse

IDENTIFIER_CHARS =
(('A'..'Z').to_a + ('0'..'9').to_a - %w(0 1 I O)).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Processing

#authorize!, #capture!, #credit!, #gateway_options, #partial_credit, #process!, #purchase!, #void_transaction!

Instance Attribute Details

#source_attributesObject

Returns the value of attribute source_attributes.



25
26
27
# File 'app/models/spree/payment.rb', line 25

def source_attributes
  @source_attributes
end

Instance Method Details

#actionsObject



99
100
101
102
# File 'app/models/spree/payment.rb', line 99

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



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

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)


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

def can_credit?
  credit_allowed > 0
end

#credit_allowedObject



83
84
85
# File 'app/models/spree/payment.rb', line 83

def credit_allowed
  amount - offsets_total
end

#currencyObject



70
71
72
# File 'app/models/spree/payment.rb', line 70

def currency
  order.currency
end

#moneyObject Also known as: display_amount



74
75
76
# File 'app/models/spree/payment.rb', line 74

def money
  Spree::Money.new(amount, { currency: currency })
end

#offsets_totalObject



79
80
81
# File 'app/models/spree/payment.rb', line 79

def offsets_total
  offsets.pluck(:amount).sum
end

#payment_sourceObject



104
105
106
107
# File 'app/models/spree/payment.rb', line 104

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

#persist_invalidObject



37
38
39
40
41
# File 'app/models/spree/payment.rb', line 37

def persist_invalid
  return unless ['failed', 'invalid'].include?(state)
  state_will_change!
  save 
end