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.
See github.com/solidusio/solidus_gateway/ for officially supported payment method implementations.
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
16 17 18 |
# File 'app/models/spree/payment_method/credit_card.rb', line 16 def partial_name 'gateway' end |
#payment_source_class ⇒ Object
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
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
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
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 |