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

Constant Summary

Constants inherited from Spree::PaymentMethod

DISPLAY

Instance Method Summary collapse

Methods inherited from Spree::PaymentMethod

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

Methods included from Spree::Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Spree::Preferences::Preferable

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

Instance Method Details

#partial_nameObject



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

def partial_name
  deprecated_method_type_override || 'gateway'
end

#payment_source_classObject



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

def payment_source_class
  CreditCard
end

#reusable_sources(order) ⇒ Object



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

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



24
25
26
27
# File 'app/models/spree/payment_method/credit_card.rb', line 24

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)


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

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