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.

Direct Known Subclasses

BogusCreditCard

Instance Method Summary collapse

Methods inherited from Spree::PaymentMethod

#auto_capture?, find_sti_class, #gateway, model_name, #options, #payment_profiles_supported?, #source_required?, #store_credit?, #try_void

Methods included from Spree::Preferences::StaticallyConfigurable

#preference_source=, #preferences, #preferences=

Methods inherited from Base

display_includes

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Instance Method Details

#partial_nameObject



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

def partial_name
  'gateway'
end

#payment_source_classObject



8
9
10
# File 'app/models/spree/payment_method/credit_card.rb', line 8

def payment_source_class
  Spree::CreditCard
end

#reusable_sources(order) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/models/spree/payment_method/credit_card.rb', line 27

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



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

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)


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

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