Module: SpreeStripe::CheckoutHelperDecorator

Defined in:
app/helpers/spree_stripe/checkout_helper_decorator.rb

Instance Method Summary collapse

Instance Method Details

#checkout_payment_sources(payment_method = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/helpers/spree_stripe/checkout_helper_decorator.rb', line 3

def checkout_payment_sources(payment_method = nil)
  payment_sources = super(payment_method)
  return payment_sources if payment_sources.empty? || !payment_method.stripe?

  wallet_sources, non_wallet_sources = payment_sources.partition { |source| source.wallet_type.present? }
  unique_wallet_sources = wallet_sources.sort_by(&:created_at).reverse.uniq { |source| [source.wallet_type, source.cc_type, source.last_digits, source.month, source.year] }

  non_wallet_sources + unique_wallet_sources
end