Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Improve valid payment sources scope
KacperMekarski56af3cd70d0a
diff --git a/core/app/models/concerns/spree/user_payment_source.rb b/core/app/models/concerns/spree/user_payment_source.rbindex d9a745d50c..5c9bb1210f 100644--- a/core/app/models/concerns/spree/user_payment_source.rb+++ b/core/app/models/concerns/spree/user_payment_source.rb@@ -9,7 +9,7 @@ module Spreeenddef payment_sources- credit_cards.with_payment_profile.not_expired+ credit_cards.with_payment_profile.not_expired.where(payment_method: Spree::PaymentMethod.active)enddef drop_payment_source(source)diff --git a/core/spec/models/spree/concerns/user_methods_spec.rb b/core/spec/models/spree/concerns/user_methods_spec.rbindex 0b824bf2f2..40d80868b9 100644--- a/core/spec/models/spree/concerns/user_methods_spec.rb+++ b/core/spec/models/spree/concerns/user_methods_spec.rb@@ -85,11 +85,18 @@ describe Spree::UserMethods dolet(:previous_year) { DateTime.now.year - 1 }let(:gateway_customer_profile_id) { 'SDS-4231' }let(:other_user) { create :user }+ let(:active_payment_method) { create(:credit_card_payment_method, active: true) }+ let(:inactive_payment_method) { create(:credit_card_payment_method, active: false) }- let!(:valid_credit_card) { create(:credit_card, user: test_user, gateway_customer_profile_id: gateway_customer_profile_id, year: next_year) }+ let!(:valid_credit_card) do+ create(:credit_card, user: test_user, gateway_customer_profile_id: gateway_customer_profile_id, year: next_year, payment_method: active_payment_method)+ endlet!(:other_user_credit_card) { create(:credit_card, user: other_user, gateway_customer_profile_id: gateway_customer_profile_id, year: next_year) }let!(:blank_payment_profile_credit_card) { create(:credit_card, user: test_user, gateway_customer_profile_id: nil, year: next_year) }let!(:outdated_credit_card) { create(:credit_card, user: test_user, gateway_customer_profile_id: gateway_customer_profile_id, year: previous_year) }+ let!(:credit_card_with_inactive_payment_method) do+ create(:credit_card, user: test_user, gateway_customer_profile_id: gateway_customer_profile_id, year: next_year, payment_method: inactive_payment_method)+ endit 'includes only not expired credit cards with payment profile that belong to subject user' doexpect(subject).to include(valid_credit_card)@@ -106,5 +113,9 @@ describe Spree::UserMethods doit 'does not include outdated credit cards' doexpect(subject).not_to include(outdated_credit_card)end++ it 'does not include credit cards with inactive payment method' do+ expect(subject).not_to include(credit_card_with_inactive_payment_method)+ endendend