straddle 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +84 -89
  4. data/SKILL.md +4 -2
  5. data/api.md +23 -23
  6. data/lib/straddle/client.rb +24 -7
  7. data/lib/straddle/errors.rb +40 -0
  8. data/lib/straddle/file_part.rb +13 -1
  9. data/lib/straddle/internal/transport/base_client.rb +186 -42
  10. data/lib/straddle/internal/transport/connection_pool.rb +160 -0
  11. data/lib/straddle/internal/transport/pooled_net_requester.rb +77 -10
  12. data/lib/straddle/internal/type/base_model.rb +69 -18
  13. data/lib/straddle/internal/type/base_page.rb +14 -0
  14. data/lib/straddle/internal/type/boolean.rb +3 -1
  15. data/lib/straddle/internal/type/converter.rb +13 -3
  16. data/lib/straddle/internal/type/enum.rb +9 -4
  17. data/lib/straddle/internal/type/file_input.rb +8 -2
  18. data/lib/straddle/internal/type/hash_of.rb +3 -1
  19. data/lib/straddle/internal/type/union.rb +21 -7
  20. data/lib/straddle/internal/type/unknown.rb +3 -1
  21. data/lib/straddle/internal/util.rb +273 -15
  22. data/lib/straddle/internal/webhook_verifier.rb +240 -0
  23. data/lib/straddle/internal.rb +5 -1
  24. data/lib/straddle/models/capability_request_create_params.rb +18 -18
  25. data/lib/straddle/models/paykey.rb +3 -2
  26. data/lib/straddle/models/paykey_created_v1_webhook_event.rb +7 -2
  27. data/lib/straddle/models/paykey_event_v1_webhook_event.rb +7 -2
  28. data/lib/straddle/models/webhook_unwrap_params.rb +2 -0
  29. data/lib/straddle/models.rb +30 -31
  30. data/lib/straddle/request_options.rb +13 -5
  31. data/lib/straddle/resources/accounts.rb +11 -12
  32. data/lib/straddle/resources/bridge.rb +8 -4
  33. data/lib/straddle/resources/capability_requests.rb +4 -5
  34. data/lib/straddle/resources/charges.rb +18 -15
  35. data/lib/straddle/resources/customers/review.rb +5 -6
  36. data/lib/straddle/resources/customers.rb +34 -35
  37. data/lib/straddle/resources/funding_events.rb +20 -20
  38. data/lib/straddle/resources/linked_bank_accounts.rb +9 -11
  39. data/lib/straddle/resources/organizations.rb +6 -6
  40. data/lib/straddle/resources/paykeys/review.rb +5 -6
  41. data/lib/straddle/resources/paykeys.rb +34 -39
  42. data/lib/straddle/resources/payments.rb +8 -7
  43. data/lib/straddle/resources/payouts.rb +18 -15
  44. data/lib/straddle/resources/representatives.rb +7 -6
  45. data/lib/straddle/resources/webhooks.rb +63 -6
  46. data/lib/straddle/version.rb +1 -1
  47. data/lib/straddle.rb +5 -6
  48. data/rbi/straddle/client.rbi +13 -0
  49. data/rbi/straddle/errors.rbi +25 -27
  50. data/rbi/straddle/internal/transport/base_client.rbi +45 -54
  51. data/rbi/straddle/internal/transport/connection_pool.rbi +44 -0
  52. data/rbi/straddle/internal/transport/pooled_net_requester.rbi +15 -16
  53. data/rbi/straddle/internal/type/base_model.rbi +24 -38
  54. data/rbi/straddle/internal/type/base_page.rbi +5 -0
  55. data/rbi/straddle/internal/type/converter.rbi +9 -42
  56. data/rbi/straddle/internal/type/enum.rbi +1 -5
  57. data/rbi/straddle/internal/type/request_parameters.rbi +1 -3
  58. data/rbi/straddle/internal/type/union.rbi +2 -11
  59. data/rbi/straddle/internal/util.rbi +101 -115
  60. data/rbi/straddle/internal/webhook_verifier.rbi +86 -0
  61. data/rbi/straddle/internal.rbi +1 -2
  62. data/rbi/straddle/models/capability_request_create_params.rbi +18 -18
  63. data/rbi/straddle/models/paykey.rbi +4 -2
  64. data/rbi/straddle/models/paykey_created_v1_webhook_event.rbi +6 -2
  65. data/rbi/straddle/models/paykey_event_v1_webhook_event.rbi +6 -2
  66. data/rbi/straddle/models/webhook_unwrap_params.rbi +2 -0
  67. data/rbi/straddle/models.rbi +2 -0
  68. data/rbi/straddle/request_options.rbi +4 -10
  69. data/rbi/straddle/resources/accounts.rbi +2 -1
  70. data/rbi/straddle/resources/bridge.rbi +8 -4
  71. data/rbi/straddle/resources/charges.rbi +4 -2
  72. data/rbi/straddle/resources/customers.rbi +7 -3
  73. data/rbi/straddle/resources/funding_events.rbi +5 -2
  74. data/rbi/straddle/resources/organizations.rbi +2 -1
  75. data/rbi/straddle/resources/paykeys.rbi +2 -1
  76. data/rbi/straddle/resources/payments.rbi +3 -1
  77. data/rbi/straddle/resources/payouts.rbi +4 -2
  78. data/rbi/straddle/resources/representatives.rbi +3 -1
  79. data/rbi/straddle/resources/webhooks.rbi +107 -2
  80. data/sig/straddle/client.rbs +4 -0
  81. data/sig/straddle/errors.rbs +13 -0
  82. data/sig/straddle/internal/transport/base_client.rbs +19 -1
  83. data/sig/straddle/internal/transport/connection_pool.rbs +19 -0
  84. data/sig/straddle/internal/transport/pooled_net_requester.rbs +11 -1
  85. data/sig/straddle/internal/type/base_model.rbs +4 -0
  86. data/sig/straddle/internal/type/base_page.rbs +2 -0
  87. data/sig/straddle/internal/util.rbs +29 -1
  88. data/sig/straddle/internal/webhook_verifier.rbs +53 -0
  89. data/sig/straddle/models/capability_request_create_params.rbs +24 -24
  90. data/sig/straddle/models/webhook_unwrap_params.rbs +4 -0
  91. data/sig/straddle/models.rbs +2 -0
  92. data/sig/straddle/resources/webhooks.rbs +59 -1
  93. metadata +12 -60
@@ -0,0 +1,240 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The two error classes the `standardwebhooks` gem raised verification failures as, declared with the
4
+ # gem's own hierarchy so that whichever of the gem and this file loads second reopens them instead of
5
+ # conflicting. They come first because this SDK's verification error subclasses the second one, so code
6
+ # written against the gem (`rescue StandardWebhooks::WebhookVerificationError`, `is_a?`, `rescue_from`)
7
+ # keeps catching it whether or not the gem is installed.
8
+ module StandardWebhooks
9
+ class StandardWebhooksError < StandardError
10
+ end
11
+
12
+ class WebhookVerificationError < StandardWebhooksError
13
+ end
14
+ end
15
+
16
+ module Straddle
17
+ module Errors
18
+ # Raised when a webhook delivery fails signature verification: a required header is missing, the
19
+ # timestamp is unreadable or outside the tolerance, no signature matches, or the helper is signed
20
+ # with an algorithm this SDK cannot verify, which refuses every delivery.
21
+ #
22
+ # A `StandardWebhooks::WebhookVerificationError`, as the `standardwebhooks` gem's own failures
23
+ # were, and deliberately not an `Errors::Error`: a handler rescuing this SDK's API errors is not
24
+ # meant to swallow a forged or stale delivery.
25
+ class WebhookVerificationError < ::StandardWebhooks::WebhookVerificationError
26
+ # @param message [String, nil]
27
+ def initialize(message = nil)
28
+ super
29
+ # The gem's `StandardWebhooksError#initialize` keeps the message in `@message` without calling
30
+ # `Exception#initialize`, so with the gem loaded `to_s`, `inspect` and string interpolation
31
+ # would report the class name instead. Setting it here keeps the message either way.
32
+ ::Exception.instance_method(:initialize).bind_call(self, message)
33
+ end
34
+ end
35
+ end
36
+
37
+ module Internal
38
+ # @api private
39
+ #
40
+ # Verifies Standard Webhooks signatures with the standard library alone: an HMAC (SHA-256 unless
41
+ # the helper's scheme names SHA-1 or SHA-512) over `"<id>.<timestamp>.<payload>"`, keyed with the
42
+ # base64-decoded secret, which the `webhook-signature` header carries as one or more
43
+ # space-separated `v1,<base64>` entries. The header names and the replay window come from the
44
+ # helper's scheme too; each generated helper passes the ones it differs from the defaults in.
45
+ #
46
+ # @see https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md
47
+ module WebhookVerifier
48
+ # Prefix the Standard Webhooks dashboards put on a signing secret; it is not part of the key.
49
+ SECRET_PREFIX = "whsec_"
50
+
51
+ # How far, in seconds, the `webhook-timestamp` may sit from now in either direction. The
52
+ # signature covers the timestamp, so this bounds how long a captured delivery can be replayed;
53
+ # the future side allows for a sender whose clock runs ahead.
54
+ TOLERANCE_SECONDS = 5 * 60
55
+
56
+ # The scheme a helper verifies with when it names none: Standard Webhooks' HMAC-SHA256.
57
+ DEFAULT_ALGORITHM = "hmac-sha256"
58
+
59
+ # The `OpenSSL::Digest` each HMAC scheme a config can name is computed with. A scheme missing
60
+ # here (`ed25519`, `rsa-sha256`) is one this runtime cannot check, and `verify!` refuses every
61
+ # delivery for it rather than accepting one unchecked.
62
+ HMAC_DIGESTS = {"hmac-sha1" => "SHA1", "hmac-sha256" => "SHA256", "hmac-sha512" => "SHA512"}.freeze
63
+
64
+ class << self
65
+ # @api private
66
+ #
67
+ # @param payload [String] the raw request body, exactly as received
68
+ # @param headers [Hash{String, Symbol=>String, Array<String>}] names match in any case; see
69
+ # {header_value}
70
+ # @param secret [String] the signing secret, with or without the `whsec_` prefix
71
+ # @param algorithm [String] the helper's configured scheme, as config spells it (`hmac-sha512`)
72
+ # @param id_header [String] the lowercase name of the header carrying the message id
73
+ # @param timestamp_header [String] the lowercase name of the header carrying the timestamp
74
+ # @param signature_header [String] the lowercase name of the header carrying the signatures
75
+ # @param tolerance [Integer] how far, in seconds, the timestamp may sit from now either way
76
+ # @param decoder [String, nil] the helper's decode-only method, named in the error an
77
+ # unsupported algorithm raises; `nil` when the helper generates none
78
+ #
79
+ # @raise [ArgumentError] when the secret decodes to no key bytes at all
80
+ # @raise [Straddle::Errors::WebhookVerificationError] also for an algorithm this runtime
81
+ # cannot check, whatever the delivery carries
82
+ # @return [void]
83
+ def verify!(
84
+ payload,
85
+ headers,
86
+ secret,
87
+ algorithm: DEFAULT_ALGORITHM,
88
+ id_header: "webhook-id",
89
+ timestamp_header: "webhook-timestamp",
90
+ signature_header: "webhook-signature",
91
+ tolerance: TOLERANCE_SECONDS,
92
+ decoder: nil
93
+ )
94
+ # Checked before anything else, the secret included: no delivery can verify under a scheme
95
+ # this runtime does not implement, so none is ever accepted, and the message says what to do.
96
+ digest = HMAC_DIGESTS[algorithm]
97
+ unless digest
98
+ # The decode-only method is configurable (and can be turned off), so the helper names it.
99
+ decode = decoder ? "decode the payload with #{decoder}" : "decode the payload yourself"
100
+ raise Straddle::Errors::WebhookVerificationError,
101
+ "Unsupported webhook signature algorithm #{algorithm}: this SDK cannot verify it; " \
102
+ "check the signature yourself, then #{decode}"
103
+ end
104
+
105
+ key = decode_secret(secret)
106
+
107
+ msg_id = header_value(headers, id_header)
108
+ msg_timestamp = header_value(headers, timestamp_header)
109
+ msg_signature = header_value(headers, signature_header)
110
+ if !msg_id || !msg_timestamp || !msg_signature
111
+ raise Straddle::Errors::WebhookVerificationError, "Missing required headers"
112
+ end
113
+
114
+ verify_timestamp!(msg_timestamp, tolerance)
115
+
116
+ # Every part is joined as binary (`.b`), byte for byte as received. The id and the body come
117
+ # from the sender, so their encodings need not agree: interpolating a UTF-8 id with non-ASCII
118
+ # characters beside a binary body (or the reverse) raises `Encoding::CompatibilityError`,
119
+ # where the delivery has to be refused as unsigned instead.
120
+ signed = [msg_id, msg_timestamp, payload].map { |part| part.to_s.b }.join(".")
121
+ expected = [OpenSSL::HMAC.digest(OpenSSL::Digest.new(digest), key, signed)].pack("m0")
122
+ # `split(" ")` splits on any run of whitespace, so a header folded with tabs or newlines
123
+ # still yields its entries. The explicit pattern matters: a bare `split` uses `$;` when the
124
+ # host process has set it. Entries for other versions are skipped rather than rejected,
125
+ # which is what lets a sender add a new scheme beside `v1`. The header is split as binary:
126
+ # a UTF-8 string holding an invalid byte sequence raises `ArgumentError` from `split`, so a
127
+ # garbled entry would otherwise escape as that error and hide a valid entry beside it, where
128
+ # it has to be one more signature that does not match.
129
+ entries = msg_signature.to_s.b.split(" ")
130
+ matched =
131
+ entries.any? do |entry|
132
+ version, signature = entry.split(",", 2)
133
+ version == "v1" && secure_compare(expected, signature)
134
+ end
135
+ return if matched
136
+
137
+ raise Straddle::Errors::WebhookVerificationError, "No matching signature found"
138
+ end
139
+
140
+ # @api private
141
+ #
142
+ # HTTP header names are case-insensitive, and callers spell them differently: a hash built by
143
+ # hand or copied from a log is often title-cased (`Webhook-Id`), upper-cased, or keyed by
144
+ # Symbol. The exact lowercase String key wins when present; otherwise the first String or Symbol
145
+ # key matching in any case is used. A multi-valued header (an Array, as
146
+ # `Net::HTTPHeader#to_hash` returns them) yields its first value. A Rack `env` hash is not a
147
+ # header hash: its `HTTP_WEBHOOK_ID` keys do not match, so pass the request's headers instead.
148
+ #
149
+ # @param headers [Hash{String, Symbol=>String, Array<String>}]
150
+ # @param name [String] the lowercase header name
151
+ #
152
+ # @return [String, nil]
153
+ private def header_value(headers, name)
154
+ value = headers[name]
155
+ # An object that only answers `[]` (some framework header wrappers fold case there) has
156
+ # nothing to scan, so a miss stays a miss.
157
+ if value.nil? && headers.respond_to?(:each)
158
+ headers.each do |key, candidate|
159
+ next unless !candidate.nil? && (key.is_a?(String) || key.is_a?(Symbol))
160
+ # Folded as binary, so only ASCII letters change case: HTTP header names are ASCII, and
161
+ # `downcase` on a UTF-8 name holding an invalid byte sequence raises `ArgumentError`.
162
+ next unless key.to_s.b.downcase == name
163
+
164
+ value = candidate
165
+ break
166
+ end
167
+ end
168
+ value.is_a?(Array) ? value.first : value
169
+ end
170
+
171
+ # @api private
172
+ #
173
+ # The secret is base64 after its optional `whsec_` prefix. It is decoded leniently, the way
174
+ # `Base64.decode64` does it, skipping characters outside the alphabet and tolerating missing
175
+ # padding, so every secret that verified before still does; strict decoding would turn a
176
+ # pasted secret with a stray newline into a crash.
177
+ #
178
+ # A secret that decodes to nothing (`""`, a bare `whsec_`, an unset variable read as an empty
179
+ # string) is refused rather than used: an HMAC keyed with no bytes is one anyone can compute,
180
+ # so every forged delivery would verify. A misconfiguration, so it is an `ArgumentError`, like
181
+ # the missing-key check in the helper that calls this, not a verification failure.
182
+ #
183
+ # @param secret [String]
184
+ #
185
+ # @raise [ArgumentError]
186
+ # @return [String]
187
+ private def decode_secret(secret)
188
+ key = secret.delete_prefix(SECRET_PREFIX).unpack1("m")
189
+ raise ArgumentError, "Webhook secret decodes to an empty key" if key.empty?
190
+
191
+ key
192
+ end
193
+
194
+ # @api private
195
+ #
196
+ # `Integer()` accepts an optional sign, surrounding whitespace, `_` separators and a `0x`-style
197
+ # prefix, and rejects anything else, so the comparison below only ever sees a whole number of
198
+ # seconds. The signature is still computed over the header exactly as it was sent.
199
+ #
200
+ # @param msg_timestamp [String]
201
+ # @param tolerance [Integer] the replay window, in seconds, on each side of now
202
+ #
203
+ # @raise [Straddle::Errors::WebhookVerificationError]
204
+ private def verify_timestamp!(msg_timestamp, tolerance = TOLERANCE_SECONDS)
205
+ timestamp =
206
+ begin
207
+ Integer(msg_timestamp)
208
+ rescue StandardError
209
+ raise Straddle::Errors::WebhookVerificationError, "Invalid Signature Headers"
210
+ end
211
+
212
+ now = Time.now.to_i
213
+ if timestamp < now - tolerance
214
+ raise Straddle::Errors::WebhookVerificationError, "Message timestamp too old"
215
+ end
216
+ return unless timestamp > now + tolerance
217
+
218
+ raise Straddle::Errors::WebhookVerificationError, "Message timestamp too new"
219
+ end
220
+
221
+ # @api private
222
+ #
223
+ # Compares in constant time, so how long a mismatch takes says nothing about how many leading
224
+ # bytes of a forged signature were right. `OpenSSL.fixed_length_secure_compare` raises on
225
+ # inputs of different lengths, so the lengths are checked first; that only reveals the length,
226
+ # which every valid signature shares.
227
+ #
228
+ # @param expected [String]
229
+ # @param signature [String, nil]
230
+ #
231
+ # @return [Boolean]
232
+ private def secure_compare(expected, signature)
233
+ return false unless signature.is_a?(String) && expected.bytesize == signature.bytesize
234
+
235
+ OpenSSL.fixed_length_secure_compare(expected, signature)
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
@@ -4,7 +4,11 @@ module Straddle
4
4
  module Internal
5
5
  extend Straddle::Internal::Util::SorbetRuntimeSupport
6
6
 
7
- OMIT = Object.new.tap { _1.define_singleton_method(:inspect) { "#<#{Straddle::Internal}::OMIT>" } }.freeze
7
+ OMIT =
8
+ Object
9
+ .new
10
+ .tap { _1.define_singleton_method(:inspect) { "#<#{Straddle::Internal}::OMIT>" } }
11
+ .freeze
8
12
 
9
13
  define_sorbet_constant!(:AnyHash) { T.type_alias { T::Hash[Symbol, T.anything] } }
10
14
  define_sorbet_constant!(:FileInput) do
@@ -106,8 +106,8 @@ module Straddle
106
106
  # @!attribute daily_amount
107
107
  # Daily charge amount limit in cents.
108
108
  #
109
- # @return [Float]
110
- required :daily_amount, Float
109
+ # @return [Integer]
110
+ required :daily_amount, Integer
111
111
 
112
112
  # @!attribute enable
113
113
  # Whether to enable or disable charges for the account.
@@ -118,14 +118,14 @@ module Straddle
118
118
  # @!attribute max_amount
119
119
  # Maximum amount in cents for one charge.
120
120
  #
121
- # @return [Float]
122
- required :max_amount, Float
121
+ # @return [Integer]
122
+ required :max_amount, Integer
123
123
 
124
124
  # @!attribute monthly_amount
125
125
  # Monthly charge amount limit in cents.
126
126
  #
127
- # @return [Float]
128
- required :monthly_amount, Float
127
+ # @return [Integer]
128
+ required :monthly_amount, Integer
129
129
 
130
130
  # @!attribute monthly_count
131
131
  # Maximum number of charges per calendar month.
@@ -136,13 +136,13 @@ module Straddle
136
136
  # @!method initialize(daily_amount:, enable:, max_amount:, monthly_amount:, monthly_count:)
137
137
  # Requested charge capability and limits.
138
138
  #
139
- # @param daily_amount [Float] Daily charge amount limit in cents.
139
+ # @param daily_amount [Integer] Daily charge amount limit in cents.
140
140
  #
141
141
  # @param enable [Boolean] Whether to enable or disable charges for the account.
142
142
  #
143
- # @param max_amount [Float] Maximum amount in cents for one charge.
143
+ # @param max_amount [Integer] Maximum amount in cents for one charge.
144
144
  #
145
- # @param monthly_amount [Float] Monthly charge amount limit in cents.
145
+ # @param monthly_amount [Integer] Monthly charge amount limit in cents.
146
146
  #
147
147
  # @param monthly_count [Integer] Maximum number of charges per calendar month.
148
148
  end
@@ -177,8 +177,8 @@ module Straddle
177
177
  # @!attribute daily_amount
178
178
  # Daily payout amount limit in cents.
179
179
  #
180
- # @return [Float]
181
- required :daily_amount, Float
180
+ # @return [Integer]
181
+ required :daily_amount, Integer
182
182
 
183
183
  # @!attribute enable
184
184
  # Whether to enable or disable payouts for the account.
@@ -189,14 +189,14 @@ module Straddle
189
189
  # @!attribute max_amount
190
190
  # Maximum amount in cents for one payout.
191
191
  #
192
- # @return [Float]
193
- required :max_amount, Float
192
+ # @return [Integer]
193
+ required :max_amount, Integer
194
194
 
195
195
  # @!attribute monthly_amount
196
196
  # Monthly payout amount limit in cents.
197
197
  #
198
- # @return [Float]
199
- required :monthly_amount, Float
198
+ # @return [Integer]
199
+ required :monthly_amount, Integer
200
200
 
201
201
  # @!attribute monthly_count
202
202
  # Maximum number of payouts per calendar month.
@@ -207,13 +207,13 @@ module Straddle
207
207
  # @!method initialize(daily_amount:, enable:, max_amount:, monthly_amount:, monthly_count:)
208
208
  # Requested payout capability and limits.
209
209
  #
210
- # @param daily_amount [Float] Daily payout amount limit in cents.
210
+ # @param daily_amount [Integer] Daily payout amount limit in cents.
211
211
  #
212
212
  # @param enable [Boolean] Whether to enable or disable payouts for the account.
213
213
  #
214
- # @param max_amount [Float] Maximum amount in cents for one payout.
214
+ # @param max_amount [Integer] Maximum amount in cents for one payout.
215
215
  #
216
- # @param monthly_amount [Float] Monthly payout amount limit in cents.
216
+ # @param monthly_amount [Integer] Monthly payout amount limit in cents.
217
217
  #
218
218
  # @param monthly_count [Integer] Maximum number of payouts per calendar month.
219
219
  end
@@ -27,7 +27,8 @@ module Straddle
27
27
  required :label, String
28
28
 
29
29
  # @!attribute paykey
30
- # Masked paykey value.
30
+ # Paykey value. Paykey create responses return the full value for creating
31
+ # payments. Store it securely. Other responses return it masked.
31
32
  #
32
33
  # @return [String]
33
34
  required :paykey, String
@@ -113,7 +114,7 @@ module Straddle
113
114
  #
114
115
  # @param label [String] Human-readable label for the paykey.
115
116
  #
116
- # @param paykey [String] Masked paykey value.
117
+ # @param paykey [String] Paykey value. Paykey create responses return the full value for creating payment
117
118
  #
118
119
  # @param source [Symbol, Straddle::Models::PaykeySource]
119
120
  #
@@ -168,7 +168,9 @@ module Straddle
168
168
  required :status, enum: -> { Straddle::PaykeyBalanceRefreshStatus }
169
169
 
170
170
  # @!attribute account_balance
171
- # Most recently retrieved account balance in dollars.
171
+ # Most recently retrieved account balance in dollars. Unlike REST paykey
172
+ # responses, which report `account_balance` in cents, this webhook field uses
173
+ # dollars.
172
174
  #
173
175
  # @return [Float, nil]
174
176
  optional :account_balance, Float, nil?: true
@@ -180,9 +182,12 @@ module Straddle
180
182
  optional :updated_at, Time, nil?: true
181
183
 
182
184
  # @!method initialize(status:, account_balance: nil, updated_at: nil)
185
+ # Some parameter documentations has been truncated, see
186
+ # {Straddle::Models::PaykeyCreatedV1WebhookEvent::Data::Balance} for more details.
187
+ #
183
188
  # @param status [Symbol, Straddle::Models::PaykeyBalanceRefreshStatus]
184
189
  #
185
- # @param account_balance [Float, nil] Most recently retrieved account balance in dollars.
190
+ # @param account_balance [Float, nil] Most recently retrieved account balance in dollars. Unlike REST paykey responses
186
191
  #
187
192
  # @param updated_at [Time, nil] Timestamp of the most recent account balance update.
188
193
  end
@@ -168,7 +168,9 @@ module Straddle
168
168
  required :status, enum: -> { Straddle::PaykeyBalanceRefreshStatus }
169
169
 
170
170
  # @!attribute account_balance
171
- # Most recently retrieved account balance in dollars.
171
+ # Most recently retrieved account balance in dollars. Unlike REST paykey
172
+ # responses, which report `account_balance` in cents, this webhook field uses
173
+ # dollars.
172
174
  #
173
175
  # @return [Float, nil]
174
176
  optional :account_balance, Float, nil?: true
@@ -180,9 +182,12 @@ module Straddle
180
182
  optional :updated_at, Time, nil?: true
181
183
 
182
184
  # @!method initialize(status:, account_balance: nil, updated_at: nil)
185
+ # Some parameter documentations has been truncated, see
186
+ # {Straddle::Models::PaykeyEventV1WebhookEvent::Data::Balance} for more details.
187
+ #
183
188
  # @param status [Symbol, Straddle::Models::PaykeyBalanceRefreshStatus]
184
189
  #
185
- # @param account_balance [Float, nil] Most recently retrieved account balance in dollars.
190
+ # @param account_balance [Float, nil] Most recently retrieved account balance in dollars. Unlike REST paykey responses
186
191
  #
187
192
  # @param updated_at [Time, nil] Timestamp of the most recent account balance update.
188
193
  end
@@ -10,5 +10,7 @@ module Straddle
10
10
  # @!method initialize(request_options: {})
11
11
  # @param request_options [Straddle::RequestOptions, Hash{Symbol=>Object}]
12
12
  end
13
+
14
+ WebhookParsedParams = WebhookUnwrapParams
13
15
  end
14
16
  end
@@ -5,42 +5,39 @@ module Straddle
5
5
  cls.define_sorbet_constant!(:OrHash) { T.type_alias { T.any(cls, Straddle::Internal::AnyHash) } }
6
6
  end
7
7
 
8
- Straddle::Internal::Util
9
- .walk_namespaces(Straddle::Models)
10
- .each do |mod|
11
- case mod
12
- in Straddle::Internal::Type::Enum | Straddle::Internal::Type::Union
13
- mod.constants.each do |name|
14
- case mod.const_get(name)
15
- in true | false
16
- mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T::Boolean } }
17
- mod.define_sorbet_constant!(:OrBoolean) { T.type_alias { T::Boolean } }
18
- in Integer
19
- mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { Integer } }
20
- mod.define_sorbet_constant!(:OrInteger) { T.type_alias { Integer } }
21
- in Float
22
- mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { Float } }
23
- mod.define_sorbet_constant!(:OrFloat) { T.type_alias { Float } }
24
- in Symbol
25
- mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { Symbol } }
26
- mod.define_sorbet_constant!(:OrSymbol) { T.type_alias { T.any(Symbol, String) } }
27
- else
28
- end
8
+ Straddle::Internal::Util.walk_namespaces(Straddle::Models).each do |mod|
9
+ case mod
10
+ in Straddle::Internal::Type::Enum | Straddle::Internal::Type::Union
11
+ mod.constants.each do |name|
12
+ case mod.const_get(name)
13
+ in true | false
14
+ mod.define_sorbet_constant!(:TaggedBoolean) { T.type_alias { T::Boolean } }
15
+ mod.define_sorbet_constant!(:OrBoolean) { T.type_alias { T::Boolean } }
16
+ in Integer
17
+ mod.define_sorbet_constant!(:TaggedInteger) { T.type_alias { Integer } }
18
+ mod.define_sorbet_constant!(:OrInteger) { T.type_alias { Integer } }
19
+ in Float
20
+ mod.define_sorbet_constant!(:TaggedFloat) { T.type_alias { Float } }
21
+ mod.define_sorbet_constant!(:OrFloat) { T.type_alias { Float } }
22
+ in Symbol
23
+ mod.define_sorbet_constant!(:TaggedSymbol) { T.type_alias { Symbol } }
24
+ mod.define_sorbet_constant!(:OrSymbol) { T.type_alias { T.any(Symbol, String) } }
25
+ else
29
26
  end
30
- else
31
27
  end
28
+ else
32
29
  end
30
+ end
33
31
 
34
- Straddle::Internal::Util
35
- .walk_namespaces(Straddle::Models)
36
- .lazy
37
- .grep(Straddle::Internal::Type::Union)
38
- .each do |mod|
39
- const = :Variants
40
- next if mod.sorbet_constant_defined?(const)
32
+ Straddle::Internal::Util.walk_namespaces(Straddle::Models)
33
+ .lazy
34
+ .grep(Straddle::Internal::Type::Union)
35
+ .each do |mod|
36
+ const = :Variants
37
+ next if mod.sorbet_constant_defined?(const)
41
38
 
42
- mod.define_sorbet_constant!(const) { T.type_alias { mod.to_sorbet_type } }
43
- end
39
+ mod.define_sorbet_constant!(const) { T.type_alias { mod.to_sorbet_type } }
40
+ end
44
41
 
45
42
  Account = Straddle::Models::Account
46
43
 
@@ -482,5 +479,7 @@ module Straddle
482
479
 
483
480
  UserEventV1WebhookEvent = Straddle::Models::UserEventV1WebhookEvent
484
481
 
482
+ WebhookParsedParams = Straddle::Models::WebhookParsedParams
483
+
485
484
  WebhookUnwrapParams = Straddle::Models::WebhookUnwrapParams
486
485
  end
@@ -26,8 +26,8 @@ module Straddle
26
26
  end
27
27
 
28
28
  # @!attribute idempotency_key
29
- # Idempotency key to send with request and all associated retries. Will only be
30
- # sent for write requests.
29
+ # Idempotency key to send with this request and its retries when the client
30
+ # has an idempotency header configured.
31
31
  #
32
32
  # @return [String, nil]
33
33
  optional :idempotency_key, String
@@ -37,7 +37,10 @@ module Straddle
37
37
  # `query` given at the client level.
38
38
  #
39
39
  # @return [Hash{String=>Array<String>, String, nil}, nil]
40
- optional :extra_query, Straddle::Internal::Type::HashOf[Straddle::Internal::Type::ArrayOf[String]]
40
+ optional :extra_query,
41
+ Straddle::Internal::Type::HashOf[
42
+ Straddle::Internal::Type::ArrayOf[String]
43
+ ]
41
44
 
42
45
  # @!attribute extra_headers
43
46
  # Extra headers to send with the request. These are `.merged`’d into any
@@ -51,7 +54,10 @@ module Straddle
51
54
  # generated as part of the normal request.
52
55
  #
53
56
  # @return [Object, nil]
54
- optional :extra_body, Straddle::Internal::Type::HashOf[Straddle::Internal::Type::Unknown]
57
+ optional :extra_body,
58
+ Straddle::Internal::Type::HashOf[
59
+ Straddle::Internal::Type::Unknown
60
+ ]
55
61
 
56
62
  # @!attribute max_retries
57
63
  # Maximum number of retries to attempt after a failed initial request.
@@ -71,7 +77,9 @@ module Straddle
71
77
  # @param values [Hash{Symbol=>Object}]
72
78
 
73
79
  define_sorbet_constant!(:OrHash) do
74
- T.type_alias { T.any(Straddle::RequestOptions, Straddle::Internal::AnyHash) }
80
+ T.type_alias do
81
+ T.any(Straddle::RequestOptions, Straddle::Internal::AnyHash)
82
+ end
75
83
  end
76
84
  end
77
85
  end
@@ -52,7 +52,8 @@ module Straddle
52
52
  )
53
53
  end
54
54
 
55
- # Returns the account with the specified ID.
55
+ # Returns the account with the specified `account_id`. Includes the account's
56
+ # status, business profile, capabilities, settings, and access level.
56
57
  #
57
58
  # @overload retrieve(account_id, correlation_id: nil, request_id: nil, request_options: {})
58
59
  #
@@ -163,11 +164,10 @@ module Straddle
163
164
  method: :get,
164
165
  path: "v1/accounts",
165
166
  query: query,
166
- headers:
167
- parsed.except(*query_params).transform_keys(
168
- correlation_id: "correlation-id",
169
- request_id: "request-id"
170
- ),
167
+ headers: parsed.except(*query_params).transform_keys(
168
+ correlation_id: "correlation-id",
169
+ request_id: "request-id"
170
+ ),
171
171
  model: Straddle::AccountList,
172
172
  options: options
173
173
  )
@@ -246,12 +246,11 @@ module Straddle
246
246
  method: :post,
247
247
  path: ["v1/accounts/%1$s/simulate", account_id],
248
248
  query: query,
249
- headers:
250
- parsed.except(*query_params).transform_keys(
251
- correlation_id: "correlation-id",
252
- idempotency_key: "idempotency-key",
253
- request_id: "request-id"
254
- ),
249
+ headers: parsed.except(*query_params).transform_keys(
250
+ correlation_id: "correlation-id",
251
+ idempotency_key: "idempotency-key",
252
+ request_id: "request-id"
253
+ ),
255
254
  model: Straddle::AccountResponse,
256
255
  options: options
257
256
  )
@@ -8,7 +8,8 @@ module Straddle
8
8
  # Some parameter documentations has been truncated, see
9
9
  # {Straddle::Models::BridgeCreateBankAccountPaykeyParams} for more details.
10
10
  #
11
- # Creates a paykey from a routing number, account number, and account type.
11
+ # Creates a paykey directly from a customer's `routing_number`, `account_number`,
12
+ # and `account_type`. Returns the new paykey with its status and bank details.
12
13
  #
13
14
  # @overload create_bank_account_paykey(account_number:, account_type:, customer_id:, routing_number:, config: nil, external_id: nil, metadata: nil, correlation_id: nil, idempotency_key: nil, request_id: nil, straddle_account_id: nil, request_options: {})
14
15
  #
@@ -60,7 +61,8 @@ module Straddle
60
61
  # Some parameter documentations has been truncated, see
61
62
  # {Straddle::Models::BridgeCreatePlaidPaykeyParams} for more details.
62
63
  #
63
- # Creates a paykey from a Plaid processor token.
64
+ # Creates a paykey from a customer's `plaid_token`. Returns the created paykey
65
+ # with its status, institution name, and bank details.
64
66
  #
65
67
  # @overload create_plaid_paykey(customer_id:, plaid_token:, config: nil, external_id: nil, metadata: nil, correlation_id: nil, idempotency_key: nil, request_id: nil, straddle_account_id: nil, request_options: {})
66
68
  #
@@ -108,7 +110,8 @@ module Straddle
108
110
  # Some parameter documentations has been truncated, see
109
111
  # {Straddle::Models::BridgeCreateQuilttPaykeyParams} for more details.
110
112
  #
111
- # Creates a paykey from a Quiltt processor token.
113
+ # Creates a paykey from a customer's `quiltt_token`. Returns the created paykey
114
+ # with its unmasked `paykey` value, status, and bank details.
112
115
  #
113
116
  # @overload create_quiltt_paykey(customer_id:, quiltt_token:, config: nil, external_id: nil, metadata: nil, correlation_id: nil, idempotency_key: nil, request_id: nil, straddle_account_id: nil, request_options: {})
114
117
  #
@@ -156,7 +159,8 @@ module Straddle
156
159
  # Some parameter documentations has been truncated, see
157
160
  # {Straddle::Models::BridgeCreateTokenParams} for more details.
158
161
  #
159
- # Creates a session token for the Bridge widget.
162
+ # Creates a `bridge_token` for a customer to initialize the Bridge widget. Use
163
+ # this token to connect bank accounts and create paykeys.
160
164
  #
161
165
  # @overload create_token(customer_id:, config: nil, external_id: nil, correlation_id: nil, idempotency_key: nil, request_id: nil, straddle_account_id: nil, request_options: {})
162
166
  #
@@ -96,11 +96,10 @@ module Straddle
96
96
  method: :get,
97
97
  path: ["v1/accounts/%1$s/capability_requests", account_id],
98
98
  query: query,
99
- headers:
100
- parsed.except(*query_params).transform_keys(
101
- correlation_id: "correlation-id",
102
- request_id: "request-id"
103
- ),
99
+ headers: parsed.except(*query_params).transform_keys(
100
+ correlation_id: "correlation-id",
101
+ request_id: "request-id"
102
+ ),
104
103
  model: Straddle::CapabilityRequestList,
105
104
  options: options
106
105
  )