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.



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

def source_attributes
  @source_attributes
end

Instance Method Details

#actionsObject



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

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



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

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)


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

def can_credit?
  credit_allowed > 0
end

#credit_allowedObject



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

def credit_allowed
  amount - offsets_total
end

#currencyObject



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

def currency
  order.currency
end

#moneyObject Also known as: display_amount



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

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

#offsets_totalObject



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

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

#payment_sourceObject



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

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

#persist_invalidObject



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

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