Class: Dodopayments::Client
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
{live_mode: "https://live.dodopayments.com", test_mode: "https://test.dodopayments.com"}
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary
collapse
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(bearer_token: ENV["DODO_PAYMENTS_API_KEY"], webhook_key: ENV["DODO_PAYMENTS_WEBHOOK_KEY"], environment: nil, base_url: ENV["DODO_PAYMENTS_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`
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/dodopayments/client.rb', line 128
def initialize(
bearer_token: ENV["DODO_PAYMENTS_API_KEY"],
webhook_key: ENV["DODO_PAYMENTS_WEBHOOK_KEY"],
environment: nil,
base_url: ENV["DODO_PAYMENTS_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 ||= Dodopayments::Client::ENVIRONMENTS.fetch(environment&.to_sym || :live_mode) do
message = "environment must be one of #{Dodopayments::Client::ENVIRONMENTS.keys}, got #{environment}"
raise ArgumentError.new(message)
end
if bearer_token.nil?
raise ArgumentError.new("bearer_token is required, and can be set via environ: \"DODO_PAYMENTS_API_KEY\"")
end
@bearer_token = bearer_token.to_s
@webhook_key = webhook_key&.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
)
@checkout_sessions = Dodopayments::Resources::CheckoutSessions.new(client: self)
@payments = Dodopayments::Resources::Payments.new(client: self)
@subscriptions = Dodopayments::Resources::Subscriptions.new(client: self)
@invoices = Dodopayments::Resources::Invoices.new(client: self)
@licenses = Dodopayments::Resources::Licenses.new(client: self)
@license_keys = Dodopayments::Resources::LicenseKeys.new(client: self)
@license_key_instances = Dodopayments::Resources::LicenseKeyInstances.new(client: self)
@customers = Dodopayments::Resources::Customers.new(client: self)
@refunds = Dodopayments::Resources::Refunds.new(client: self)
@disputes = Dodopayments::Resources::Disputes.new(client: self)
@payouts = Dodopayments::Resources::Payouts.new(client: self)
@products = Dodopayments::Resources::Products.new(client: self)
@misc = Dodopayments::Resources::Misc.new(client: self)
@discounts = Dodopayments::Resources::Discounts.new(client: self)
@addons = Dodopayments::Resources::Addons.new(client: self)
@brands = Dodopayments::Resources::Brands.new(client: self)
@webhooks = Dodopayments::Resources::Webhooks.new(client: self)
@webhook_events = Dodopayments::Resources::WebhookEvents.new(client: self)
@usage_events = Dodopayments::Resources::UsageEvents.new(client: self)
@meters = Dodopayments::Resources::Meters.new(client: self)
@balances = Dodopayments::Resources::Balances.new(client: self)
@credit_entitlements = Dodopayments::Resources::CreditEntitlements.new(client: self)
end
|
Instance Attribute Details
73
74
75
|
# File 'lib/dodopayments/client.rb', line 73
def addons
@addons
end
|
91
92
93
|
# File 'lib/dodopayments/client.rb', line 91
def balances
@balances
end
|
#bearer_token ⇒ String
Bearer Token for API authentication
25
26
27
|
# File 'lib/dodopayments/client.rb', line 25
def bearer_token
@bearer_token
end
|
76
77
78
|
# File 'lib/dodopayments/client.rb', line 76
def brands
@brands
end
|
31
32
33
|
# File 'lib/dodopayments/client.rb', line 31
def checkout_sessions
@checkout_sessions
end
|
94
95
96
|
# File 'lib/dodopayments/client.rb', line 94
def credit_entitlements
@credit_entitlements
end
|
52
53
54
|
# File 'lib/dodopayments/client.rb', line 52
def customers
@customers
end
|
70
71
72
|
# File 'lib/dodopayments/client.rb', line 70
def discounts
@discounts
end
|
58
59
60
|
# File 'lib/dodopayments/client.rb', line 58
def disputes
@disputes
end
|
40
41
42
|
# File 'lib/dodopayments/client.rb', line 40
def invoices
@invoices
end
|
49
50
51
|
# File 'lib/dodopayments/client.rb', line 49
def license_key_instances
@license_key_instances
end
|
46
47
48
|
# File 'lib/dodopayments/client.rb', line 46
def license_keys
@license_keys
end
|
43
44
45
|
# File 'lib/dodopayments/client.rb', line 43
def licenses
@licenses
end
|
88
89
90
|
# File 'lib/dodopayments/client.rb', line 88
def meters
@meters
end
|
67
68
69
|
# File 'lib/dodopayments/client.rb', line 67
def misc
@misc
end
|
34
35
36
|
# File 'lib/dodopayments/client.rb', line 34
def payments
@payments
end
|
61
62
63
|
# File 'lib/dodopayments/client.rb', line 61
def payouts
@payouts
end
|
64
65
66
|
# File 'lib/dodopayments/client.rb', line 64
def products
@products
end
|
55
56
57
|
# File 'lib/dodopayments/client.rb', line 55
def refunds
@refunds
end
|
37
38
39
|
# File 'lib/dodopayments/client.rb', line 37
def subscriptions
@subscriptions
end
|
85
86
87
|
# File 'lib/dodopayments/client.rb', line 85
def usage_events
@usage_events
end
|
82
83
84
|
# File 'lib/dodopayments/client.rb', line 82
def webhook_events
@webhook_events
end
|
#webhook_key ⇒ String?
28
29
30
|
# File 'lib/dodopayments/client.rb', line 28
def webhook_key
@webhook_key
end
|
79
80
81
|
# File 'lib/dodopayments/client.rb', line 79
def webhooks
@webhooks
end
|