Class: Lithic::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/lithic/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0
ENVIRONMENTS =

rubocop:disable Style/MutableConstant

{production: "https://api.lithic.com", sandbox: "https://sandbox.lithic.com"}

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: ENV["LITHIC_API_KEY"], webhook_secret: ENV["LITHIC_WEBHOOK_SECRET"], environment: nil, base_url: ENV["LITHIC_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

Each environment maps to a different base URL:

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["LITHIC_API_KEY"])

    Defaults to ‘ENV`

  • webhook_secret (String, nil) (defaults to: ENV["LITHIC_WEBHOOK_SECRET"])

    Defaults to ‘ENV`

  • environment (:production, :sandbox, nil) (defaults to: nil)

    Specifies the environment to use for the API.

  • base_url (String, nil) (defaults to: ENV["LITHIC_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/lithic/client.rb', line 177

def initialize(
  api_key: ENV["LITHIC_API_KEY"],
  webhook_secret: ENV["LITHIC_WEBHOOK_SECRET"],
  environment: nil,
  base_url: ENV["LITHIC_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= Lithic::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do
    message = "environment must be one of #{Lithic::Client::ENVIRONMENTS.keys}, got #{environment}"
    raise ArgumentError.new(message)
  end

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"LITHIC_API_KEY\"")
  end

  headers = {}
  custom_headers_env = ENV["LITHIC_CUSTOM_HEADERS"]
  unless custom_headers_env.nil?
    parsed = {}
    custom_headers_env.split("\n").each do |line|
      colon = line.index(":")
      unless colon.nil?
        parsed[line[0...colon].strip] = line[(colon + 1)..].strip
      end
    end
    headers = parsed.merge(headers)
  end

  @api_key = api_key.to_s
  @webhook_secret = webhook_secret&.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay,
    headers: headers
  )

  @accounts = Lithic::Resources::Accounts.new(client: self)
  @account_holders = Lithic::Resources::AccountHolders.new(client: self)
  @auth_rules = Lithic::Resources::AuthRules.new(client: self)
  @auth_stream_enrollment = Lithic::Resources::AuthStreamEnrollment.new(client: self)
  @tokenization_decisioning = Lithic::Resources::TokenizationDecisioning.new(client: self)
  @tokenizations = Lithic::Resources::Tokenizations.new(client: self)
  @cards = Lithic::Resources::Cards.new(client: self)
  @card_authorizations = Lithic::Resources::CardAuthorizations.new(client: self)
  @card_bulk_orders = Lithic::Resources::CardBulkOrders.new(client: self)
  @balances = Lithic::Resources::Balances.new(client: self)
  @disputes = Lithic::Resources::Disputes.new(client: self)
  @disputes_v2 = Lithic::Resources::DisputesV2.new(client: self)
  @events = Lithic::Resources::Events.new(client: self)
  @transfers = Lithic::Resources::Transfers.new(client: self)
  @financial_accounts = Lithic::Resources::FinancialAccounts.new(client: self)
  @transactions = Lithic::Resources::Transactions.new(client: self)
  @responder_endpoints = Lithic::Resources::ResponderEndpoints.new(client: self)
  @external_bank_accounts = Lithic::Resources::ExternalBankAccounts.new(client: self)
  @payments = Lithic::Resources::Payments.new(client: self)
  @three_ds = Lithic::Resources::ThreeDS.new(client: self)
  @reports = Lithic::Resources::Reports.new(client: self)
  @card_programs = Lithic::Resources::CardPrograms.new(client: self)
  @digital_card_art = Lithic::Resources::DigitalCardArt.new(client: self)
  @book_transfers = Lithic::Resources::BookTransfers.new(client: self)
  @credit_products = Lithic::Resources::CreditProducts.new(client: self)
  @external_payments = Lithic::Resources::ExternalPayments.new(client: self)
  @management_operations = Lithic::Resources::ManagementOperations.new(client: self)
  @internal_transaction = Lithic::Resources::InternalTransaction.new(client: self)
  @funding_events = Lithic::Resources::FundingEvents.new(client: self)
  @fraud = Lithic::Resources::Fraud.new(client: self)
  @network_programs = Lithic::Resources::NetworkPrograms.new(client: self)
  @holds = Lithic::Resources::Holds.new(client: self)
  @account_activity = Lithic::Resources::AccountActivity.new(client: self)
  @transfer_limits = Lithic::Resources::TransferLimits.new(client: self)
  @webhooks = Lithic::Resources::Webhooks.new(client: self)
end

Instance Attribute Details

#account_activityLithic::Resources::AccountActivity (readonly)



126
127
128
# File 'lib/lithic/client.rb', line 126

def 
  @account_activity
end

#account_holdersLithic::Resources::AccountHolders (readonly)



33
34
35
# File 'lib/lithic/client.rb', line 33

def 
  @account_holders
end

#accountsLithic::Resources::Accounts (readonly)



30
31
32
# File 'lib/lithic/client.rb', line 30

def accounts
  @accounts
end

#api_keyString (readonly)

Returns:

  • (String)


24
25
26
# File 'lib/lithic/client.rb', line 24

def api_key
  @api_key
end

#auth_rulesLithic::Resources::AuthRules (readonly)



36
37
38
# File 'lib/lithic/client.rb', line 36

def auth_rules
  @auth_rules
end

#auth_stream_enrollmentLithic::Resources::AuthStreamEnrollment (readonly)



39
40
41
# File 'lib/lithic/client.rb', line 39

def auth_stream_enrollment
  @auth_stream_enrollment
end

#balancesLithic::Resources::Balances (readonly)



57
58
59
# File 'lib/lithic/client.rb', line 57

def balances
  @balances
end

#book_transfersLithic::Resources::BookTransfers (readonly)



99
100
101
# File 'lib/lithic/client.rb', line 99

def book_transfers
  @book_transfers
end

#card_authorizationsLithic::Resources::CardAuthorizations (readonly)



51
52
53
# File 'lib/lithic/client.rb', line 51

def card_authorizations
  @card_authorizations
end

#card_bulk_ordersLithic::Resources::CardBulkOrders (readonly)



54
55
56
# File 'lib/lithic/client.rb', line 54

def card_bulk_orders
  @card_bulk_orders
end

#card_programsLithic::Resources::CardPrograms (readonly)



93
94
95
# File 'lib/lithic/client.rb', line 93

def card_programs
  @card_programs
end

#cardsLithic::Resources::Cards (readonly)



48
49
50
# File 'lib/lithic/client.rb', line 48

def cards
  @cards
end

#credit_productsLithic::Resources::CreditProducts (readonly)



102
103
104
# File 'lib/lithic/client.rb', line 102

def credit_products
  @credit_products
end

#digital_card_artLithic::Resources::DigitalCardArt (readonly)



96
97
98
# File 'lib/lithic/client.rb', line 96

def digital_card_art
  @digital_card_art
end

#disputesLithic::Resources::Disputes (readonly)



60
61
62
# File 'lib/lithic/client.rb', line 60

def disputes
  @disputes
end

#disputes_v2Lithic::Resources::DisputesV2 (readonly)



63
64
65
# File 'lib/lithic/client.rb', line 63

def disputes_v2
  @disputes_v2
end

#eventsLithic::Resources::Events (readonly)



66
67
68
# File 'lib/lithic/client.rb', line 66

def events
  @events
end

#external_bank_accountsLithic::Resources::ExternalBankAccounts (readonly)



81
82
83
# File 'lib/lithic/client.rb', line 81

def external_bank_accounts
  @external_bank_accounts
end

#external_paymentsLithic::Resources::ExternalPayments (readonly)



105
106
107
# File 'lib/lithic/client.rb', line 105

def external_payments
  @external_payments
end

#financial_accountsLithic::Resources::FinancialAccounts (readonly)



72
73
74
# File 'lib/lithic/client.rb', line 72

def financial_accounts
  @financial_accounts
end

#fraudLithic::Resources::Fraud (readonly)



117
118
119
# File 'lib/lithic/client.rb', line 117

def fraud
  @fraud
end

#funding_eventsLithic::Resources::FundingEvents (readonly)



114
115
116
# File 'lib/lithic/client.rb', line 114

def funding_events
  @funding_events
end

#holdsLithic::Resources::Holds (readonly)



123
124
125
# File 'lib/lithic/client.rb', line 123

def holds
  @holds
end

#internal_transactionLithic::Resources::InternalTransaction (readonly)



111
112
113
# File 'lib/lithic/client.rb', line 111

def internal_transaction
  @internal_transaction
end

#management_operationsLithic::Resources::ManagementOperations (readonly)



108
109
110
# File 'lib/lithic/client.rb', line 108

def management_operations
  @management_operations
end

#network_programsLithic::Resources::NetworkPrograms (readonly)



120
121
122
# File 'lib/lithic/client.rb', line 120

def network_programs
  @network_programs
end

#paymentsLithic::Resources::Payments (readonly)



84
85
86
# File 'lib/lithic/client.rb', line 84

def payments
  @payments
end

#reportsLithic::Resources::Reports (readonly)



90
91
92
# File 'lib/lithic/client.rb', line 90

def reports
  @reports
end

#responder_endpointsLithic::Resources::ResponderEndpoints (readonly)



78
79
80
# File 'lib/lithic/client.rb', line 78

def responder_endpoints
  @responder_endpoints
end

#three_dsLithic::Resources::ThreeDS (readonly)



87
88
89
# File 'lib/lithic/client.rb', line 87

def three_ds
  @three_ds
end

#tokenization_decisioningLithic::Resources::TokenizationDecisioning (readonly)



42
43
44
# File 'lib/lithic/client.rb', line 42

def tokenization_decisioning
  @tokenization_decisioning
end

#tokenizationsLithic::Resources::Tokenizations (readonly)



45
46
47
# File 'lib/lithic/client.rb', line 45

def tokenizations
  @tokenizations
end

#transactionsLithic::Resources::Transactions (readonly)



75
76
77
# File 'lib/lithic/client.rb', line 75

def transactions
  @transactions
end

#transfer_limitsLithic::Resources::TransferLimits (readonly)



129
130
131
# File 'lib/lithic/client.rb', line 129

def transfer_limits
  @transfer_limits
end

#transfersLithic::Resources::Transfers (readonly)



69
70
71
# File 'lib/lithic/client.rb', line 69

def transfers
  @transfers
end

#webhook_secretString? (readonly)

Returns:

  • (String, nil)


27
28
29
# File 'lib/lithic/client.rb', line 27

def webhook_secret
  @webhook_secret
end

#webhooksLithic::Resources::Webhooks (readonly)



132
133
134
# File 'lib/lithic/client.rb', line 132

def webhooks
  @webhooks
end

Instance Method Details

#api_status(request_options: {}) ⇒ Lithic::Models::APIStatus

Status of api

Parameters:

Returns:

See Also:



143
144
145
# File 'lib/lithic/client.rb', line 143

def api_status(params = {})
  request(method: :get, path: "v1/status", model: Lithic::APIStatus, options: params[:request_options])
end