Class: Spree::PaymentMethod::CreditCard

Inherits:
Spree::PaymentMethod show all
Defined in:
app/models/spree/payment_method/credit_card.rb

Overview

An implementation of a ‘Spree::PaymentMethod` for credit card payments.

It’s a good candidate as base class for other credit card based payment methods.

See github.com/solidusio/solidus_gateway/ for officially supported payment method implementations.

Direct Known Subclasses

Gateway, BogusCreditCard

Instance Method Summary collapse

Methods inherited from Spree::PaymentMethod

active?, #auto_capture?, available, const_missing, #deprecated_method_type_override, #display_on, #display_on=, find_with_destroyed, #gateway, #method_type, model_name, #options, #payment_profiles_supported?, providers, #source_required?, #store_credit?, #try_void

Methods included from Spree::Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods included from Spree::ParanoiaDeprecations

#paranoia_delete, #paranoia_destroy

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

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

Instance Method Details

#partial_nameObject



16
17
18
# File 'app/models/spree/payment_method/credit_card.rb', line 16

def partial_name
  deprecated_method_type_override || 'gateway'
end

#payment_source_classObject



12
13
14
# File 'app/models/spree/payment_method/credit_card.rb', line 12

def payment_source_class
  Spree::CreditCard
end

#reusable_sources(order) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/models/spree/payment_method/credit_card.rb', line 33

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

#reusable_sources_by_order(order) ⇒ Object Also known as: sources_by_order



26
27
28
29
# File 'app/models/spree/payment_method/credit_card.rb', line 26

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

#supports?(source) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'app/models/spree/payment_method/credit_card.rb', line 20

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