Class: Users::CreditCardValidation

Inherits:
ApplicationRecord show all
Defined in:
app/models/users/credit_card_validation.rb

Constant Summary collapse

DAILY_VERIFICATION_LIMIT =
5

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Instance Attribute Details

#expiration_dateObject

Returns the value of attribute expiration_date.



9
10
11
# File 'app/models/users/credit_card_validation.rb', line 9

def expiration_date
  @expiration_date
end

#holder_nameObject

Returns the value of attribute holder_name.



9
10
11
# File 'app/models/users/credit_card_validation.rb', line 9

def holder_name
  @holder_name
end

#last_digitsObject

Returns the value of attribute last_digits.



9
10
11
# File 'app/models/users/credit_card_validation.rb', line 9

def last_digits
  @last_digits
end

#networkObject

Returns the value of attribute network.



9
10
11
# File 'app/models/users/credit_card_validation.rb', line 9

def network
  @network
end

Instance Method Details

#exceeded_daily_verification_limit?Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
# File 'app/models/users/credit_card_validation.rb', line 82

def exceeded_daily_verification_limit?
  duplicate_record_count = self.class
    .where(stripe_card_fingerprint: stripe_card_fingerprint)
    .where('credit_card_validated_at > ?', 24.hours.ago)
    .count

  duplicate_record_count >= DAILY_VERIFICATION_LIMIT
end

#set_expiration_date_hashObject



78
79
80
# File 'app/models/users/credit_card_validation.rb', line 78

def set_expiration_date_hash
  self.expiration_date_hash = Gitlab::CryptoHelper.sha256(expiration_date.to_s)
end

#set_holder_name_hashObject



70
71
72
# File 'app/models/users/credit_card_validation.rb', line 70

def set_holder_name_hash
  self.holder_name_hash = Gitlab::CryptoHelper.sha256(holder_name.downcase)
end

#set_last_digits_hashObject



66
67
68
# File 'app/models/users/credit_card_validation.rb', line 66

def set_last_digits_hash
  self.last_digits_hash = Gitlab::CryptoHelper.sha256(last_digits)
end

#set_network_hashObject



74
75
76
# File 'app/models/users/credit_card_validation.rb', line 74

def set_network_hash
  self.network_hash = Gitlab::CryptoHelper.sha256(network.downcase)
end

#similar_holder_names_countObject



58
59
60
# File 'app/models/users/credit_card_validation.rb', line 58

def similar_holder_names_count
  self.class.similar_by_holder_name(holder_name_hash).count
end

#similar_recordsObject



54
55
56
# File 'app/models/users/credit_card_validation.rb', line 54

def similar_records
  self.class.similar_to(self).order(credit_card_validated_at: :desc).includes(:user)
end

#used_by_banned_user?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/users/credit_card_validation.rb', line 62

def used_by_banned_user?
  self.class.by_banned_user.similar_to(self).similar_by_holder_name(holder_name_hash).exists?
end