Skip to content

armgit / spree

Public Imported from GitHub
0

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.

[SD-1117] Show N/A if brand for card is empty (#10779)

Agnieszka Jacek7b9e6a1e1dfd
diff --git a/backend/app/views/spree/admin/payments/source_forms/_gateway.html.erb b/backend/app/views/spree/admin/payments/source_forms/_gateway.html.erb
index 57af22041a..42f36001d6 100644
--- a/backend/app/views/spree/admin/payments/source_forms/_gateway.html.erb
+++ b/backend/app/views/spree/admin/payments/source_forms/_gateway.html.erb
@@ -6,11 +6,10 @@
</div>
<div class="form-group previous_cards card-body mb-0" data-hook="previous_cards">
<ul class="m-0 p-0">
-
<% previous_cards.each do |card| %>
<li>
<label>
- <%= radio_button_tag :card, card.id, card == previous_cards.first %> <%= card.brand.upcase + ' - ' + card.display_number %>
+ <%= radio_button_tag :card, card.id, card == previous_cards.first %> <%= card.display_brand + ' - ' + card.display_number %>
</label>
</li>
<% end %>
diff --git a/backend/app/views/spree/admin/payments/source_views/_gateway.html.erb b/backend/app/views/spree/admin/payments/source_views/_gateway.html.erb
index 1116c86e08..c5a99d88b1 100644
--- a/backend/app/views/spree/admin/payments/source_views/_gateway.html.erb
+++ b/backend/app/views/spree/admin/payments/source_views/_gateway.html.erb
@@ -8,7 +8,7 @@
</tr>
<tr>
<th><%= Spree.t(:card_type) %>:</th>
- <td><%= payment.source.cc_type %></td>
+ <td><%= payment.source.display_brand %></td>
</tr>
<tr>
<th><%= Spree.t(:card_number) %>:</th>
diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb
index 30fc99cd2f..9416d31662 100644
--- a/core/app/models/spree/credit_card.rb
+++ b/core/app/models/spree/credit_card.rb
@@ -127,6 +127,10 @@ module Spree
"XXXX-XXXX-XXXX-#{last_digits}"
end
+ def display_brand
+ brand.present? ? brand.upcase : Spree.t(:no_cc_type)
+ end
+
def actions
%w{capture void credit}
end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 14e71c4bb0..99886d9eb6 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -755,6 +755,7 @@ en:
new_order_notifications_email: New Order Notifications Email
cut: Cut
cvv: CVV
+ no_cc_type: N/A
cvv_response: CVV Response
date: Date
date_completed: Date Completed
diff --git a/core/spec/models/spree/credit_card_spec.rb b/core/spec/models/spree/credit_card_spec.rb
index dad4b0e2c6..8efcc373de 100644
--- a/core/spec/models/spree/credit_card_spec.rb
+++ b/core/spec/models/spree/credit_card_spec.rb
@@ -369,4 +369,20 @@ describe Spree::CreditCard, type: :model do
end
end
end
+
+ context '#display_brand' do
+ let(:credit_card) { create(:credit_card, cc_type: cc_type, user_id: @order.user_id) }
+
+ context 'when the cc_type does not exist' do
+ let(:cc_type) { nil }
+
+ it { expect(credit_card.display_brand).to eq('N/A') }
+ end
+
+ context 'when the cc_type exist' do
+ let(:cc_type) { 'visa' }
+
+ it { expect(credit_card.display_brand).to eq(cc_type.upcase) }
+ end
+ end
end