Class: Spree::Gateway

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

Overview

A concrete implementation of `Spree::PaymentMethod` intended to provide a base for extension. See github.com/solidusio/solidus_gateway/ for offically supported payment gateway implementations.

Direct Known Subclasses

Bogus

Defined Under Namespace

Classes: Bogus, BogusSimple

Constant Summary

Constant Summary

Constants inherited from PaymentMethod

PaymentMethod::DISPLAY

Instance Method Summary (collapse)

Methods inherited from PaymentMethod

active?, #auto_capture?, available, #cancel, #display_on, #display_on=, 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

- (Object) method_type



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

def method_type
  'gateway'
end

- (Object) options



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

def options
  preferences.to_hash
end

- (Boolean) payment_profiles_supported?

Returns:

  • (Boolean)


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

def payment_profiles_supported?
  false
end

- (Object) payment_source_class



14
15
16
# File 'app/models/spree/gateway.rb', line 14

def payment_source_class
  CreditCard
end

- (Object) provider



18
19
20
21
22
23
24
25
# File 'app/models/spree/gateway.rb', line 18

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

- (Object) reusable_sources(order)



52
53
54
55
56
57
58
59
60
# File 'app/models/spree/gateway.rb', line 52

def reusable_sources(order)
  if order.completed?
    reusable_sources_by_order(order)
  elsif order.user_id
    order.user.wallet.wallet_payment_sources.map(&:payment_source).select(&:reusable?)
  else
    []
  end
end

- (Object) reusable_sources_by_order(order) Also known as: sources_by_order



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

def reusable_sources_by_order(order)
  source_ids = order.payments.where(payment_method_id: id).pluck(:source_id).uniq
  payment_source_class.where(id: source_ids).select(&:reusable?)
end

- (Boolean) supports?(source)

Returns:

  • (Boolean)


39
40
41
42
43
# File 'app/models/spree/gateway.rb', line 39

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