Class: Spree::PaymentMethod::CreditCard
- Inherits:
-
Spree::PaymentMethod
- Object
- ActiveRecord::Base
- Base
- Spree::PaymentMethod
- Spree::PaymentMethod::CreditCard
- 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
Instance Method Summary collapse
- #partial_name ⇒ Object
- #payment_source_class ⇒ Object
- #reusable_sources(order) ⇒ Object
- #reusable_sources_by_order(order) ⇒ Object
- #supports?(source) ⇒ Boolean
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
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Instance Method Details
#partial_name ⇒ Object
12 13 14 |
# File 'app/models/spree/payment_method/credit_card.rb', line 12 def partial_name 'gateway' end |
#payment_source_class ⇒ Object
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
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 |