Class: Spree::PaymentMethod

Inherits:
Object
  • Object
show all
Includes:
DisplayOn, Metadata, MultiStoreResource, Security::PaymentMethods
Defined in:
app/models/spree/payment_method.rb

Direct Known Subclasses

Gateway, Check, StoreCredit

Defined Under Namespace

Classes: Check, StoreCredit

Constant Summary

Constants included from DisplayOn

DisplayOn::DISPLAY

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_with_destroyed(*args) ⇒ Object



61
62
63
# File 'app/models/spree/payment_method.rb', line 61

def self.find_with_destroyed(*args)
  unscoped { find(*args) }
end

.providersObject



32
33
34
# File 'app/models/spree/payment_method.rb', line 32

def self.providers
  Rails.application.config.spree.payment_methods
end

Instance Method Details

#auto_capture?Boolean

Returns:

  • (Boolean)


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

def auto_capture?
  auto_capture.nil? ? Spree::Config[:auto_capture] : auto_capture
end

#available_for_order?(order) ⇒ Boolean

Custom PaymentMethod/Gateway can redefine this method to check method availability for concrete order.

Returns:

  • (Boolean)


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

def available_for_order?(order)
  !order.covered_by_store_credit?
end

#available_for_store?(store) ⇒ Boolean

Returns:

  • (Boolean)


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

def available_for_store?(store)
  return true if store.blank?

  store_ids.include?(store.id)
end

#cancel(_response) ⇒ Object

Raises:

  • (::NotImplementedError)


91
92
93
# File 'app/models/spree/payment_method.rb', line 91

def cancel(_response)
  raise ::NotImplementedError, 'You must implement cancel method for this payment method.'
end

#default_nameObject



53
54
55
# File 'app/models/spree/payment_method.rb', line 53

def default_name
  self.class.name.demodulize.titleize.gsub(/Gateway/, '').strip
end

#method_typeObject



49
50
51
# File 'app/models/spree/payment_method.rb', line 49

def method_type
  type.demodulize.downcase
end

#payment_icon_nameObject



57
58
59
# File 'app/models/spree/payment_method.rb', line 57

def payment_icon_name
  type.demodulize.gsub(/(^Spree::Gateway::|Gateway$)/, '').downcase.gsub(/\s+/, '').strip
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/spree/payment_method.rb', line 65

def payment_profiles_supported?
  false
end

#payment_source_classObject

The class that will process payments for this payment type, used for @payment.source e.g. CreditCard in the case of a the Gateway payment type nil means the payment method doesn’t require a source e.g. check

Raises:

  • (::NotImplementedError)


43
44
45
46
47
# File 'app/models/spree/payment_method.rb', line 43

def payment_source_class
  return unless source_required?

  raise ::NotImplementedError, 'You must implement payment_source_class method for this gateway.'
end

#provider_classObject

Raises:

  • (::NotImplementedError)


36
37
38
# File 'app/models/spree/payment_method.rb', line 36

def provider_class
  raise ::NotImplementedError, 'You must implement provider_class method for this gateway.'
end

#public_preferencesObject



111
112
113
114
115
# File 'app/models/spree/payment_method.rb', line 111

def public_preferences
  public_preference_keys.each_with_object({}) do |key, hash|
    hash[key] = preferences[key]
  end
end

#reusable_sources(_order) ⇒ Object

Custom gateways should redefine this method. See Gateway implementation as an example



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

def reusable_sources(_order)
  []
end

#show_in_admin?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/spree/payment_method.rb', line 73

def show_in_admin?
  true
end

#source_required?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/spree/payment_method.rb', line 69

def source_required?
  true
end

#store_credit?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/spree/payment_method.rb', line 95

def store_credit?
  self.class == Spree::PaymentMethod::StoreCredit
end

#supports?(_source) ⇒ Boolean

Returns:

  • (Boolean)


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

def supports?(_source)
  true
end