diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index a8ac1702b6..ac56d20d8f 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -139,7 +139,7 @@ module CheckoutHelper def stripe_card_options(cards) cards.map do |cc| [ - "#{cc.brand} #{cc.last_digits} #{I18n.t(:card_expiry_abbreviation)}:" \ + "#{cc.cc_type} #{cc.last_digits} #{I18n.t(:card_expiry_abbreviation)}:" \ "#{cc.month.to_s.rjust(2, '0')}/#{cc.year}", cc.id ] end diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb index 74e40596a0..47fa1b8fca 100644 --- a/app/models/spree/credit_card.rb +++ b/app/models/spree/credit_card.rb @@ -25,9 +25,6 @@ module Spree scope :with_payment_profile, -> { where.not(gateway_customer_profile_id: nil) } - # needed for some of the ActiveMerchant gateways (eg. SagePay) - alias_attribute :brand, :cc_type - def expiry=(expiry) self[:month], self[:year] = expiry.split(" / ") self[:year] = "20#{self[:year]}" diff --git a/app/models/spree/gateway.rb b/app/models/spree/gateway.rb index c480d9c251..08f6d20e27 100644 --- a/app/models/spree/gateway.rb +++ b/app/models/spree/gateway.rb @@ -52,9 +52,9 @@ module Spree def supports?(source) return true unless provider_class.respond_to? :supports? - return false unless source.brand + return false unless source.cc_type - provider_class.supports?(source.brand) + provider_class.supports?(source.cc_type) end end end diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index d42ef87e87..f949a237fc 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -193,4 +193,25 @@ RSpec.describe CheckoutHelper do end end end + + describe "#stripe_card_options" do + let(:year) { Time.zone.now.year + 1 } + let(:card) { create(:credit_card, cc_type: 'visa', last_digits: '1111', month: 1, year:) } + let(:cards) { [card] } + + it "formats credit cards for Stripe options" do + options = helper.stripe_card_options(cards) + + expect(options).to eq([ + ["visa 1111 Exp:01/#{year}", card.id] + ]) + end + + it "zero-pads the month" do + card.update(month: 5) + options = helper.stripe_card_options(cards) + + expect(options.first.first).to match(%r{05/#{year}}) + end + end end