Class: Users::UpsertCreditCardValidationService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/users/upsert_credit_card_validation_service.rb

Constant Summary

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(params) ⇒ UpsertCreditCardValidationService

Returns a new instance of UpsertCreditCardValidationService.



7
8
9
# File 'app/services/users/upsert_credit_card_validation_service.rb', line 7

def initialize(params)
  @params = params.to_h.with_indifferent_access
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'app/services/users/upsert_credit_card_validation_service.rb', line 5

def params
  @params
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/users/upsert_credit_card_validation_service.rb', line 11

def execute
  credit_card = Users::CreditCardValidation.find_or_initialize_by_user(user_id)

  credit_card_attributes = {
    credit_card_validated_at: credit_card_validated_at,
    last_digits: last_digits,
    holder_name: holder_name,
    network: network,
    expiration_date: expiration_date,
    zuora_payment_method_xid: zuora_payment_method_xid,
    stripe_setup_intent_xid: stripe_setup_intent_xid,
    stripe_payment_method_xid: stripe_payment_method_xid,
    stripe_card_fingerprint: stripe_card_fingerprint
  }

  credit_card.assign_attributes(credit_card_attributes)

  return blocked if credit_card.exceeded_daily_verification_limit?

  credit_card.save!

  success
rescue ActiveRecord::InvalidForeignKey, ActiveRecord::NotNullViolation, ActiveRecord::RecordInvalid
  error
rescue StandardError => e
  Gitlab::ErrorTracking.track_exception(e)
  error
end