Class: Spree::Gateway

Inherits:
PaymentMethod show all
Defined in:
app/models/spree/gateway.rb

Direct Known Subclasses

Bogus

Defined Under Namespace

Classes: Bogus, BogusSimple

Constant Summary

Constants inherited from PaymentMethod

PaymentMethod::DISPLAY

Instance Method Summary collapse

Methods inherited from PaymentMethod

active?, #auto_capture?, available, #cancel, find_with_destroyed, #provider_class, providers, #source_required?, #store_credit?

Methods included from Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#disable_customer_profile(source) ⇒ Object



41
42
43
44
45
46
47
48
# File 'app/models/spree/gateway.rb', line 41

def disable_customer_profile(source)
  Spree::Deprecation.warn("Gateway#disable_customer_profile is deprecated")
  if source.is_a? CreditCard
    source.update_column :gateway_customer_profile_id, nil
  else
    raise 'You must implement disable_customer_profile method for this gateway.'
  end
end

#method_typeObject



31
32
33
# File 'app/models/spree/gateway.rb', line 31

def method_type
  'gateway'
end

#optionsObject



23
24
25
# File 'app/models/spree/gateway.rb', line 23

def options
  preferences.to_hash
end

#payment_profiles_supported?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/spree/gateway.rb', line 27

def payment_profiles_supported?
  false
end

#payment_source_classObject



10
11
12
# File 'app/models/spree/gateway.rb', line 10

def payment_source_class
  CreditCard
end

#providerObject



14
15
16
17
18
19
20
21
# File 'app/models/spree/gateway.rb', line 14

def provider
  gateway_options = options
  gateway_options.delete :login if gateway_options.key?(:login) && gateway_options[:login].nil?
  if gateway_options[:server]
    ActiveMerchant::Billing::Base.mode = gateway_options[:server].to_sym
  end
  @provider ||= provider_class.new(gateway_options)
end

#reusable_sources(order) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'app/models/spree/gateway.rb', line 55

def reusable_sources(order)
  if order.completed?
    sources_by_order(order)
  elsif order.user_id
    credit_cards.where(user_id: order.user_id).with_payment_profile
  else
    []
  end
end

#sources_by_order(order) ⇒ Object



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

def sources_by_order(order)
  source_ids = order.payments.where(payment_method_id: id).pluck(:source_id).uniq
  payment_source_class.where(id: source_ids).with_payment_profile
end

#supports?(source) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'app/models/spree/gateway.rb', line 35

def supports?(source)
  return true unless provider_class.respond_to? :supports?
  return true if source.brand && provider_class.supports?(source.brand)
  source.has_payment_profile?
end