mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Merge pull request #13951 from zilton7/fix/spree-credit-card-brand-deprecation
Fix Spree::CreditCard#brand= deprecation for Rails 7.2 compatibility
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]}"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user