Only show credit cards if previously saved, split credit card db migrations and tidy up serializer

This commit is contained in:
stveep
2017-03-04 15:14:38 +00:00
committed by Rob Harrington
parent 298fd057f5
commit a1cad82564
5 changed files with 19 additions and 17 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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