Commit 44a6f14a authored by Mark Chao's avatar Mark Chao Committed by Markus Koller

Persist credit card network

Changelog: added
parent b0f4bd85
......@@ -9,6 +9,7 @@ module Users
belongs_to :user
validates :holder_name, length: { maximum: 26 }
validates :network, length: { maximum: 32 }
validates :last_digits, allow_nil: true, numericality: {
greater_than_or_equal_to: 0, less_than_or_equal_to: 9999
}
......
......@@ -12,6 +12,7 @@ module Users
credit_card_validated_at: params.fetch(:credit_card_validated_at),
expiration_date: get_expiration_date(params),
last_digits: Integer(params.fetch(:credit_card_mask_number), 10),
network: params.fetch(:credit_card_type),
holder_name: params.fetch(:credit_card_holder_name)
}
......
# frozen_string_literal: true
class AddNetworkToUserCreditCardValidations < Gitlab::Database::Migration[1.0]
# rubocop:disable Migration/AddLimitToTextColumns
def change
add_column :user_credit_card_validations, :network, :text
end
# rubocop:enable Migration/AddLimitToTextColumns
end
# frozen_string_literal: true
class LimitNetworkOnUserCreditCardValidations < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
add_text_limit :user_credit_card_validations, :network, 32
end
def down
remove_text_limit :user_credit_card_validations, :network
end
end
# frozen_string_literal: true
class IndexIncludeNetworkOnUserCreditCardValidations < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
INDEX_NAME = 'index_user_credit_card_validations_meta_data_partial_match'
def up
add_concurrent_index :user_credit_card_validations,
[:expiration_date, :last_digits, :network, :credit_card_validated_at],
name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :user_credit_card_validations, INDEX_NAME
end
end
5c5adaf0f6f053c7e737051fbccf61d1fc36e20360a82d5fca142883d3e3bfdd
\ No newline at end of file
06d6458f7b85b3e729c3c8a8ae29c29f7c5504ea330ae3a3bcf1e0074ed66cf6
\ No newline at end of file
a5928cef69626ad5e972e8cb7a570ca83201cdfe7ec4f2401f2aa14c34b9cfb8
\ No newline at end of file
......@@ -19843,6 +19843,8 @@ CREATE TABLE user_credit_card_validations (
expiration_date date,
last_digits smallint,
holder_name text,
network text,
CONSTRAINT check_1765e2b30f CHECK ((char_length(network) <= 32)),
CONSTRAINT check_3eea080c91 CHECK (((last_digits >= 0) AND (last_digits <= 9999))),
CONSTRAINT check_eafe45d88b CHECK ((char_length(holder_name) <= 26))
);
......@@ -26821,6 +26823,8 @@ CREATE UNIQUE INDEX index_user_canonical_emails_on_user_id_and_canonical_email O
CREATE INDEX index_user_credit_card_validations_meta_data_full_match ON user_credit_card_validations USING btree (holder_name, expiration_date, last_digits, credit_card_validated_at);
CREATE INDEX index_user_credit_card_validations_meta_data_partial_match ON user_credit_card_validations USING btree (expiration_date, last_digits, network, credit_card_validated_at);
CREATE INDEX index_user_custom_attributes_on_key_and_value ON user_custom_attributes USING btree (key, value);
CREATE UNIQUE INDEX index_user_custom_attributes_on_user_id_and_key ON user_custom_attributes USING btree (user_id, key);
......@@ -7,5 +7,6 @@ FactoryBot.modify do
expiration_date { 1.year.from_now.end_of_month }
last_digits { 10 }
holder_name { 'John Smith' }
network { 'AmericanExpress' }
end
end
......@@ -1062,6 +1062,7 @@ module API
requires :credit_card_expiration_year, type: Integer, desc: 'The year the credit card expires'
requires :credit_card_holder_name, type: String, desc: 'The credit card holder name'
requires :credit_card_mask_number, type: String, desc: 'The last 4 digits of credit card number'
requires :credit_card_type, type: String, desc: 'The credit card network name'
end
put ":user_id/credit_card_validation", feature_category: :users do
authenticated_as_admin!
......
......@@ -6,6 +6,7 @@ RSpec.describe Users::CreditCardValidation do
it { is_expected.to belong_to(:user) }
it { is_expected.to validate_length_of(:holder_name).is_at_most(26) }
it { is_expected.to validate_length_of(:network).is_at_most(32) }
it { is_expected.to validate_numericality_of(:last_digits).is_less_than_or_equal_to(9999) }
describe '.similar_records' do
......
......@@ -1464,6 +1464,7 @@ RSpec.describe API::Users do
credit_card_expiration_year: expiration_year,
credit_card_expiration_month: 1,
credit_card_holder_name: 'John Smith',
credit_card_type: 'AmericanExpress',
credit_card_mask_number: '1111'
}
end
......@@ -1495,6 +1496,7 @@ RSpec.describe API::Users do
credit_card_validated_at: credit_card_validated_time,
expiration_date: Date.new(expiration_year, 1, 31),
last_digits: 1111,
network: 'AmericanExpress',
holder_name: 'John Smith'
)
end
......
......@@ -15,6 +15,7 @@ RSpec.describe Users::UpsertCreditCardValidationService do
credit_card_expiration_year: expiration_year,
credit_card_expiration_month: 1,
credit_card_holder_name: 'John Smith',
credit_card_type: 'AmericanExpress',
credit_card_mask_number: '1111'
}
end
......@@ -30,7 +31,16 @@ RSpec.describe Users::UpsertCreditCardValidationService do
result = service.execute
expect(result.status).to eq(:success)
expect(user.reload.credit_card_validated_at).to eq(credit_card_validated_time)
user.reload
expect(user.credit_card_validation).to have_attributes(
credit_card_validated_at: credit_card_validated_time,
network: 'AmericanExpress',
holder_name: 'John Smith',
last_digits: 1111,
expiration_date: Date.new(expiration_year, 1, 31)
)
end
end
......@@ -97,6 +107,7 @@ RSpec.describe Users::UpsertCreditCardValidationService do
expiration_date: Date.new(expiration_year, 1, 31),
holder_name: "John Smith",
last_digits: 1111,
network: "AmericanExpress",
user_id: user_id
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment