diff --git a/app/serializers/api/credit_card_serializer.rb b/app/serializers/api/credit_card_serializer.rb index 855f62c81d..60e17c0fe6 100644 --- a/app/serializers/api/credit_card_serializer.rb +++ b/app/serializers/api/credit_card_serializer.rb @@ -1,15 +1,15 @@ class Api::CreditCardSerializer < ActiveModel::Serializer - attributes :id, :month, :year, :cc_type, :last_digits, :first_name, :last_name, :formatted + attributes :id, :formatted def formatted elements = [] - elements << cc_type.capitalize if cc_type - if last_digits + elements << object.cc_type.capitalize if object.cc_type + if object.last_digits 3.times { elements << I18n.t(:card_masked_digit) * 4 } + elements << object.last_digits end - elements << last_digits if last_digits elements << I18n.t(:card_expiry_abbreviation) - elements << month.to_s + "/" + year.to_s if month # TODO: I18n + elements << object.month.to_s + "/" + object.year.to_s if object.month # TODO: I18n elements.join(" ") end end diff --git a/app/views/spree/checkout/payment/_gateway.html.haml b/app/views/spree/checkout/payment/_gateway.html.haml index 0a1cd913e6..33dcbda8fc 100644 --- a/app/views/spree/checkout/payment/_gateway.html.haml +++ b/app/views/spree/checkout/payment/_gateway.html.haml @@ -1,10 +1,3 @@ -.row - .small-12.columns - %label - = t :previously_used_credit_cards - %select{"ng-model" => "selected_card", "ng-options" => "card.id as card.formatted for card in savedCreditCards", name: "secrets.card_year", required: true} - - .row .small-6.columns %label diff --git a/app/views/spree/checkout/payment/_stripe.html.haml b/app/views/spree/checkout/payment/_stripe.html.haml index ed69bdb1cd..8564f91744 100644 --- a/app/views/spree/checkout/payment/_stripe.html.haml +++ b/app/views/spree/checkout/payment/_stripe.html.haml @@ -1,3 +1,9 @@ +.row{ "ng-show" => "savedCreditCards != null && savedCreditCards.length > 0" } + .small-12.columns + %label + = t :previously_used_credit_cards + %select{"ng-model" => "selected_card", "ng-options" => "card.id as card.formatted for card in savedCreditCards", name: "secrets.card_year", required: true} + = render "spree/checkout/payment/gateway", payment_method: payment_method :javascript diff --git a/db/migrate/20170225203658_add_user_id_to_spree_credit_cards.rb b/db/migrate/20170225203658_add_user_id_to_spree_credit_cards.rb index 837343be7d..29e50e0c1a 100644 --- a/db/migrate/20170225203658_add_user_id_to_spree_credit_cards.rb +++ b/db/migrate/20170225203658_add_user_id_to_spree_credit_cards.rb @@ -4,10 +4,5 @@ class AddUserIdToSpreeCreditCards < ActiveRecord::Migration add_column :spree_credit_cards, :user_id, :integer add_index :spree_credit_cards, :user_id end - - unless Spree::CreditCard.column_names.include? "payment_method_id" - add_column :spree_credit_cards, :payment_method_id, :integer - add_index :spree_credit_cards, :payment_method_id - end end end diff --git a/db/migrate/20170304151129_add_payment_method_to_spree_credit_cards.rb b/db/migrate/20170304151129_add_payment_method_to_spree_credit_cards.rb new file mode 100644 index 0000000000..76c1cab805 --- /dev/null +++ b/db/migrate/20170304151129_add_payment_method_to_spree_credit_cards.rb @@ -0,0 +1,8 @@ +class AddPaymentMethodToSpreeCreditCards < ActiveRecord::Migration + def change + unless Spree::CreditCard.column_names.include? "payment_method_id" + add_column :spree_credit_cards, :payment_method_id, :integer + add_index :spree_credit_cards, :payment_method_id + end + end +end