Sha256: beb00a65533707cfb5ee88782ec3c3672adf72951957335f46e186bd9f976b6a

Contents?: true

Size: 1.32 KB

Versions: 66

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Spree
  # 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 https://github.com/solidusio/solidus_gateway/ for
  # officially supported payment method implementations.
  #
  class PaymentMethod::CreditCard < PaymentMethod
    def payment_source_class
      Spree::CreditCard
    end

    def partial_name
      deprecated_method_type_override || 'gateway'
    end

    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

    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
    alias_method :sources_by_order, :reusable_sources_by_order
    deprecate sources_by_order: :reusable_sources_by_order, deprecator: Spree::Deprecation

    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
  end
end

Version data entries

66 entries across 66 versions & 2 rubygems

Version Path
solidus_core-2.11.17 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.16 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.15 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.14 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.13 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.12 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.11 app/models/spree/payment_method/credit_card.rb
solidus_core-2.10.5 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.10 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.9 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.8 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.7 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.6 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.5 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.4 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.3 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.2 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.1 app/models/spree/payment_method/credit_card.rb
solidus_core-2.10.3 app/models/spree/payment_method/credit_card.rb
solidus_core-2.11.0 app/models/spree/payment_method/credit_card.rb