Skip to content

Commit 9fb8bb1

Browse files
authored
Merge pull request #13951 from zilton7/fix/spree-credit-card-brand-deprecation
Fix Spree::CreditCard#brand= deprecation for Rails 7.2 compatibility
2 parents 8aa89c0 + 9488e9b commit 9fb8bb1

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

app/helpers/checkout_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def checkout_step?(step)
139139
def stripe_card_options(cards)
140140
cards.map do |cc|
141141
[
142-
"#{cc.brand} #{cc.last_digits} #{I18n.t(:card_expiry_abbreviation)}:" \
142+
"#{cc.cc_type} #{cc.last_digits} #{I18n.t(:card_expiry_abbreviation)}:" \
143143
"#{cc.month.to_s.rjust(2, '0')}/#{cc.year}", cc.id
144144
]
145145
end

app/models/spree/credit_card.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class CreditCard < ApplicationRecord
2525

2626
scope :with_payment_profile, -> { where.not(gateway_customer_profile_id: nil) }
2727

28-
# needed for some of the ActiveMerchant gateways (eg. SagePay)
29-
alias_attribute :brand, :cc_type
30-
3128
def expiry=(expiry)
3229
self[:month], self[:year] = expiry.split(" / ")
3330
self[:year] = "20#{self[:year]}"

app/models/spree/gateway.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def method_type
5252

5353
def supports?(source)
5454
return true unless provider_class.respond_to? :supports?
55-
return false unless source.brand
55+
return false unless source.cc_type
5656

57-
provider_class.supports?(source.brand)
57+
provider_class.supports?(source.cc_type)
5858
end
5959
end
6060
end

spec/helpers/checkout_helper_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,25 @@
193193
end
194194
end
195195
end
196+
197+
describe "#stripe_card_options" do
198+
let(:year) { Time.zone.now.year + 1 }
199+
let(:card) { create(:credit_card, cc_type: 'visa', last_digits: '1111', month: 1, year:) }
200+
let(:cards) { [card] }
201+
202+
it "formats credit cards for Stripe options" do
203+
options = helper.stripe_card_options(cards)
204+
205+
expect(options).to eq([
206+
["visa 1111 Exp:01/#{year}", card.id]
207+
])
208+
end
209+
210+
it "zero-pads the month" do
211+
card.update(month: 5)
212+
options = helper.stripe_card_options(cards)
213+
214+
expect(options.first.first).to match(%r{05/#{year}})
215+
end
216+
end
196217
end

0 commit comments

Comments
 (0)