Class: Yoomoney::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/yoomoney/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

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(username: ENV["YOOMONEY_USERNAME"], password: ENV["YOOMONEY_PASSWORD"], base_url: ENV["YOOMONEY_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.

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

Parameters:

  • username (String, nil) (defaults to: ENV["YOOMONEY_USERNAME"])

    HTTP Basic аутентификация клиента ЮKassa Defaults to ‘ENV`

  • password (String, nil) (defaults to: ENV["YOOMONEY_PASSWORD"])

    HTTP Basic аутентификация клиента ЮKassa Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["YOOMONEY_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)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/yoomoney/client.rb', line 75

def initialize(
  username: ENV["YOOMONEY_USERNAME"],
  password: ENV["YOOMONEY_PASSWORD"],
  base_url: ENV["YOOMONEY_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 ||= "https://api.yookassa.ru/v3"

  @username = username&.to_s
  @password = password&.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
  )

  @payments = Yoomoney::Resources::Payments.new(client: self)
  @payment_methods = Yoomoney::Resources::PaymentMethods.new(client: self)
  @invoices = Yoomoney::Resources::Invoices.new(client: self)
  @refunds = Yoomoney::Resources::Refunds.new(client: self)
  @receipts = Yoomoney::Resources::Receipts.new(client: self)
  @deals = Yoomoney::Resources::Deals.new(client: self)
  @payouts = Yoomoney::Resources::Payouts.new(client: self)
  @sbp_banks = Yoomoney::Resources::SbpBanks.new(client: self)
  @personal_data = Yoomoney::Resources::PersonalData.new(client: self)
  @webhooks = Yoomoney::Resources::Webhooks.new(client: self)
  @me = Yoomoney::Resources::Me.new(client: self)
end

Instance Attribute Details

#dealsYoomoney::Resources::Deals (readonly)



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

def deals
  @deals
end

#invoicesYoomoney::Resources::Invoices (readonly)



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

def invoices
  @invoices
end

#meYoomoney::Resources::Me (readonly)



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

def me
  @me
end

#passwordString? (readonly)

HTTP Basic аутентификация клиента ЮKassa

Returns:

  • (String, nil)


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

def password
  @password
end

#payment_methodsYoomoney::Resources::PaymentMethods (readonly)



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

def payment_methods
  @payment_methods
end

#paymentsYoomoney::Resources::Payments (readonly)



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

def payments
  @payments
end

#payoutsYoomoney::Resources::Payouts (readonly)



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

def payouts
  @payouts
end

#personal_dataYoomoney::Resources::PersonalData (readonly)



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

def personal_data
  @personal_data
end

#receiptsYoomoney::Resources::Receipts (readonly)



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

def receipts
  @receipts
end

#refundsYoomoney::Resources::Refunds (readonly)



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

def refunds
  @refunds
end

#sbp_banksYoomoney::Resources::SbpBanks (readonly)



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

def sbp_banks
  @sbp_banks
end

#usernameString? (readonly)

HTTP Basic аутентификация клиента ЮKassa

Returns:

  • (String, nil)


20
21
22
# File 'lib/yoomoney/client.rb', line 20

def username
  @username
end

#webhooksYoomoney::Resources::Webhooks (readonly)



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

def webhooks
  @webhooks
end