straddle_pay 0.1.0 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23aebc721853de383064f4e317d3f9a6e73705d06f2f4d0e8376873dbf05bace
4
- data.tar.gz: 1996288b18fc0434b255e7638e8e75b83db350687eeca1dc93cd46f091525ac9
3
+ metadata.gz: bf56e36b8c5ad31abdb73a507b57e21646f5996fdbba44ba4b14f4f3509a3576
4
+ data.tar.gz: 0a2e227e8e70a8bed554b0372fb2d2e54ea058c96649cea773b4e983dc95aa69
5
5
  SHA512:
6
- metadata.gz: 36203c68e86e4df953735bdcb7b811a7d9db9c7867a8fa10c1ace55663ce894146621983a7d56f5490e8b1dc9cd62be65a27bb314bd4aed467e63215d78e0967
7
- data.tar.gz: ff082a8507a7146e55ddee23a5286834212d7b97924821ce55f7a6c4c516c9653897b480173d5e363c333d6050504cd13399450972405ff2665d31bfb3ef9b72
6
+ metadata.gz: ba3e1707a861e85fd772f9cb31495f0e7a0e7f6f80f50cc2c023fa9b1e64abf49114d1304a492ef970d5e0d808e947721b1f8c530b63428a56572f43fc875f65
7
+ data.tar.gz: bb7814818ac4e160d38b6113cf2d56fa1d834de49beb93502244720eb31f0028eddb96fcd6be5df7dcb76a71540b8cfeb0d67943ffd8fa1c5c9b57f0b0b14c98
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --markup markdown
2
+ --no-private
3
+ lib/**/*.rb
4
+ - README.md
5
+ - CHANGELOG.md
6
+ - LICENSE.txt
@@ -4,9 +4,23 @@ require "faraday"
4
4
  require "json"
5
5
 
6
6
  module StraddlePay
7
+ # HTTP client for the Straddle API. Uses Faraday under the hood.
8
+ #
9
+ # @example
10
+ # client = StraddlePay::Client.new
11
+ # client.charges.create(paykey: "pk_abc", amount: 10_000, ...)
7
12
  class Client
8
- attr_reader :api_key, :base_url
9
-
13
+ # @return [String] API key used for authentication
14
+ attr_reader :api_key
15
+ # @return [String] base URL for API requests
16
+ attr_reader :base_url
17
+
18
+ # @param api_key [String, nil] override global API key
19
+ # @param base_url [String, nil] override global base URL
20
+ # @param logger [Logger, nil] override global logger
21
+ # @param open_timeout [Integer, nil] connection open timeout in seconds
22
+ # @param read_timeout [Integer, nil] response read timeout in seconds
23
+ # @raise [ArgumentError] if no API key is configured
10
24
  def initialize(api_key: nil, base_url: nil, logger: nil, open_timeout: nil, read_timeout: nil)
11
25
  configuration = StraddlePay.config
12
26
  @api_key = api_key || configuration.api_key
@@ -18,32 +32,61 @@ module StraddlePay
18
32
  raise ArgumentError, "Missing API key for StraddlePay" if @api_key.to_s.empty?
19
33
  end
20
34
 
35
+ # @return [Resources::Customers]
21
36
  def customers = @customers ||= Resources::Customers.new(self)
37
+ # @return [Resources::Bridge]
22
38
  def bridge = @bridge ||= Resources::Bridge.new(self)
39
+ # @return [Resources::Paykeys]
23
40
  def paykeys = @paykeys ||= Resources::Paykeys.new(self)
41
+ # @return [Resources::Charges]
24
42
  def charges = @charges ||= Resources::Charges.new(self)
43
+ # @return [Resources::Payouts]
25
44
  def payouts = @payouts ||= Resources::Payouts.new(self)
45
+ # @return [Resources::Payments]
26
46
  def payments = @payments ||= Resources::Payments.new(self)
47
+ # @return [Resources::FundingEvents]
27
48
  def funding_events = @funding_events ||= Resources::FundingEvents.new(self)
49
+ # @return [Resources::Reports]
28
50
  def reports = @reports ||= Resources::Reports.new(self)
51
+ # @return [Resources::Embed]
29
52
  def embed = @embed ||= Resources::Embed.new(self)
30
53
 
54
+ # @param path [String] API endpoint path
55
+ # @param params [Hash, nil] query parameters
56
+ # @param headers [Hash] additional HTTP headers
57
+ # @return [Hash] parsed response data
31
58
  def get(path, params: nil, headers: {})
32
59
  request(:get, path, params: params, headers: headers)
33
60
  end
34
61
 
62
+ # @param path [String] API endpoint path
63
+ # @param body [Hash, nil] request body (JSON-encoded)
64
+ # @param headers [Hash] additional HTTP headers
65
+ # @return [Hash] parsed response data
35
66
  def post(path, body = nil, headers: {})
36
67
  request(:post, path, body: body, headers: headers)
37
68
  end
38
69
 
70
+ # @param path [String] API endpoint path
71
+ # @param body [Hash, nil] request body (JSON-encoded)
72
+ # @param headers [Hash] additional HTTP headers
73
+ # @return [Hash] parsed response data
39
74
  def put(path, body = nil, headers: {})
40
75
  request(:put, path, body: body, headers: headers)
41
76
  end
42
77
 
78
+ # @param path [String] API endpoint path
79
+ # @param body [Hash, nil] request body (JSON-encoded)
80
+ # @param headers [Hash] additional HTTP headers
81
+ # @return [Hash] parsed response data
43
82
  def patch(path, body = nil, headers: {})
44
83
  request(:patch, path, body: body, headers: headers)
45
84
  end
46
85
 
86
+ # @param path [String] API endpoint path
87
+ # @param body [Hash, nil] request body (JSON-encoded)
88
+ # @param headers [Hash] additional HTTP headers
89
+ # @return [Hash] parsed response data
47
90
  def delete(path, body = nil, headers: {})
48
91
  request(:delete, path, body: body, headers: headers)
49
92
  end
@@ -3,11 +3,29 @@
3
3
  require "logger"
4
4
 
5
5
  module StraddlePay
6
+ # Configuration for the StraddlePay client.
7
+ #
8
+ # @example
9
+ # StraddlePay.configure do |config|
10
+ # config.api_key = "sk_test_..."
11
+ # config.base_url = StraddlePay::Config::PRODUCTION_URL
12
+ # config.logger = Rails.logger
13
+ # end
6
14
  class Config
15
+ # @return [String] Sandbox API base URL
7
16
  SANDBOX_URL = "https://sandbox.straddle.io"
17
+ # @return [String] Production API base URL
8
18
  PRODUCTION_URL = "https://production.straddle.io"
9
19
 
10
- attr_accessor :api_key, :base_url, :open_timeout, :read_timeout
20
+ # @return [String, nil] API key for authentication
21
+ attr_accessor :api_key
22
+ # @return [String] Base URL for API requests (default: sandbox)
23
+ attr_accessor :base_url
24
+ # @return [Integer] Connection open timeout in seconds (default: 5)
25
+ attr_accessor :open_timeout
26
+ # @return [Integer] Response read timeout in seconds (default: 30)
27
+ attr_accessor :read_timeout
28
+ # @return [Logger] Logger instance
11
29
  attr_writer :logger
12
30
 
13
31
  def initialize
@@ -17,6 +35,7 @@ module StraddlePay
17
35
  @read_timeout = integer_or_default("STRADDLE_READ_TIMEOUT", 30)
18
36
  end
19
37
 
38
+ # @return [Logger] configured logger, falls back to Rails.logger or $stderr
20
39
  def logger
21
40
  @logger ||= (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) || Logger.new($stderr)
22
41
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module StraddlePay
4
4
  if defined?(Rails)
5
+ # Rails engine for StraddlePay gem integration.
5
6
  class Engine < ::Rails::Engine
6
7
  isolate_namespace StraddlePay
7
8
  end
@@ -1,9 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StraddlePay
4
+ # Base error for all Straddle API errors.
5
+ #
6
+ # @example
7
+ # rescue StraddlePay::Error => e
8
+ # e.status # => 422
9
+ # e.error_type # => "validation_error"
10
+ # e.error_items # => [{"reference" => "email", "detail" => "is invalid"}]
4
11
  class Error < StandardError
5
- attr_reader :status, :body, :error_type, :error_items
12
+ # @return [Integer, nil] HTTP status code
13
+ attr_reader :status
14
+ # @return [Hash, nil] full response body
15
+ attr_reader :body
16
+ # @return [String, nil] Straddle error type (e.g. "validation_error")
17
+ attr_reader :error_type
18
+ # @return [Array<Hash>] Straddle error items with reference and detail
19
+ attr_reader :error_items
6
20
 
21
+ # @param message [String, nil] error message
22
+ # @param status [Integer, nil] HTTP status code
23
+ # @param body [Hash, nil] parsed response body
7
24
  def initialize(message = nil, status: nil, body: nil)
8
25
  error_hash = body.is_a?(Hash) ? (body["error"] || {}) : {}
9
26
  @error_type = error_hash["type"] if error_hash.is_a?(Hash)
@@ -14,9 +31,18 @@ module StraddlePay
14
31
  end
15
32
  end
16
33
 
34
+ # Raised on 401/403 responses.
17
35
  class AuthenticationError < Error; end
36
+
37
+ # Raised on 400, 404, 409, 422 responses.
18
38
  class ClientError < Error; end
39
+
40
+ # Raised on 429 responses. Retry with backoff.
19
41
  class RateLimitError < Error; end
42
+
43
+ # Raised on 500+ responses.
20
44
  class ServerError < Error; end
45
+
46
+ # Raised on timeout or connection failure.
21
47
  class NetworkError < Error; end
22
48
  end
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StraddlePay
4
+ # Namespace for all API resource classes.
4
5
  module Resources
6
+ # Base class for API resources. Provides header extraction for
7
+ # Straddle-specific headers (account scoping, request tracking, idempotency).
5
8
  class Base
9
+ # @api private
6
10
  HEADER_KEYS = {
7
11
  straddle_account_id: "Straddle-Account-Id",
8
12
  request_id: "Request-Id",
@@ -10,6 +14,7 @@ module StraddlePay
10
14
  idempotency_key: "Idempotency-Key"
11
15
  }.freeze
12
16
 
17
+ # @param client [Client] the HTTP client instance
13
18
  def initialize(client)
14
19
  @client = client
15
20
  end
@@ -2,9 +2,15 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Bank account linking via Bridge.
5
6
  class Bridge < Base
7
+ # @return [BridgeLinks] bank account link sub-resource
6
8
  def links = @links ||= BridgeLinks.new(@client)
7
9
 
10
+ # Initialize a Bridge session for a customer.
11
+ #
12
+ # @param customer_id [String] customer ID
13
+ # @return [Hash] session details
8
14
  def initialize_session(customer_id:, **options)
9
15
  payload = { customer_id: customer_id, **options }.compact
10
16
  headers = extract_headers(payload)
@@ -2,7 +2,16 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Link bank accounts via direct details, Plaid, Quiltt, or TAN.
6
+ # Accessed via {Bridge#links}.
5
7
  class BridgeLinks < Base
8
+ # Link a bank account directly.
9
+ #
10
+ # @param customer_id [String] customer ID
11
+ # @param account_number [String] bank account number
12
+ # @param routing_number [String] bank routing number
13
+ # @param account_type [String] "checking" or "savings"
14
+ # @return [Hash] linked bank account
6
15
  def bank_account(customer_id:, account_number:, routing_number:, account_type:, **options)
7
16
  payload = {
8
17
  customer_id: customer_id, account_number: account_number,
@@ -12,18 +21,35 @@ module StraddlePay
12
21
  @client.post("v1/bridge/bank_account", payload, headers: headers)
13
22
  end
14
23
 
24
+ # Link a bank account via Plaid.
25
+ #
26
+ # @param customer_id [String] customer ID
27
+ # @param plaid_token [String] Plaid processor token
28
+ # @return [Hash] linked bank account
15
29
  def plaid(customer_id:, plaid_token:, **options)
16
30
  payload = { customer_id: customer_id, plaid_token: plaid_token, **options }.compact
17
31
  headers = extract_headers(payload)
18
32
  @client.post("v1/bridge/plaid", payload, headers: headers)
19
33
  end
20
34
 
35
+ # Link a bank account via Quiltt.
36
+ #
37
+ # @param customer_id [String] customer ID
38
+ # @param quiltt_token [String] Quiltt session token
39
+ # @return [Hash] linked bank account
21
40
  def quiltt(customer_id:, quiltt_token:, **options)
22
41
  payload = { customer_id: customer_id, quiltt_token: quiltt_token, **options }.compact
23
42
  headers = extract_headers(payload)
24
43
  @client.post("v1/bridge/quiltt", payload, headers: headers)
25
44
  end
26
45
 
46
+ # Link a bank account via TAN (Tokenized Account Number).
47
+ #
48
+ # @param customer_id [String] customer ID
49
+ # @param routing_number [String] bank routing number
50
+ # @param account_type [String] "checking" or "savings"
51
+ # @param tan [String] tokenized account number
52
+ # @return [Hash] linked bank account
27
53
  def tan(customer_id:, routing_number:, account_type:, tan:, **options)
28
54
  payload = {
29
55
  customer_id: customer_id, routing_number: routing_number,
@@ -2,7 +2,22 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage ACH charge (debit) transactions.
6
+ #
7
+ # @see https://straddle.dev/api-reference Straddle API Reference
5
8
  class Charges < Base
9
+ # Create a new charge.
10
+ #
11
+ # @param paykey [String] paykey identifier
12
+ # @param amount [Integer] amount in cents
13
+ # @param currency [String] three-letter currency code (e.g. "usd")
14
+ # @param description [String] charge description
15
+ # @param payment_date [String] date in YYYY-MM-DD format
16
+ # @param consent_type [String] consent type (e.g. "internet")
17
+ # @param device [Hash] device info (must include :ip_address)
18
+ # @param external_id [String] your external reference ID
19
+ # @param options [Hash] additional fields or header params
20
+ # @return [Hash] created charge
6
21
  def create(paykey:, amount:, currency:, description:, payment_date:, consent_type:, device:, external_id:,
7
22
  **options)
8
23
  payload = {
@@ -14,31 +29,55 @@ module StraddlePay
14
29
  @client.post("v1/charges", payload, headers: headers)
15
30
  end
16
31
 
32
+ # Retrieve a charge by ID.
33
+ #
34
+ # @param id [String] charge ID
35
+ # @return [Hash] charge details
17
36
  def get(id, **options)
18
37
  headers = extract_headers(options)
19
38
  @client.get("v1/charges/#{id}", headers: headers)
20
39
  end
21
40
 
41
+ # Update a charge.
42
+ #
43
+ # @param id [String] charge ID
44
+ # @return [Hash] updated charge
22
45
  def update(id, **options)
23
46
  headers = extract_headers(options)
24
47
  @client.put("v1/charges/#{id}", options, headers: headers)
25
48
  end
26
49
 
50
+ # Cancel a charge.
51
+ #
52
+ # @param id [String] charge ID
53
+ # @return [Hash] cancelled charge
27
54
  def cancel(id, **options)
28
55
  headers = extract_headers(options)
29
56
  @client.put("v1/charges/#{id}/cancel", options, headers: headers)
30
57
  end
31
58
 
59
+ # Place a charge on hold.
60
+ #
61
+ # @param id [String] charge ID
62
+ # @return [Hash] held charge
32
63
  def hold(id, **options)
33
64
  headers = extract_headers(options)
34
65
  @client.put("v1/charges/#{id}/hold", options, headers: headers)
35
66
  end
36
67
 
68
+ # Release a held charge.
69
+ #
70
+ # @param id [String] charge ID
71
+ # @return [Hash] released charge
37
72
  def release(id, **options)
38
73
  headers = extract_headers(options)
39
74
  @client.put("v1/charges/#{id}/release", options, headers: headers)
40
75
  end
41
76
 
77
+ # Retrieve unmasked charge details.
78
+ #
79
+ # @param id [String] charge ID
80
+ # @return [Hash] unmasked charge details
42
81
  def unmask(id, **options)
43
82
  headers = extract_headers(options)
44
83
  @client.get("v1/charges/#{id}/unmask", headers: headers)
@@ -2,18 +2,33 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage customer identity reviews.
6
+ # Accessed via {Customers#reviews}.
5
7
  class CustomerReviews < Base
8
+ # Get the identity review for a customer.
9
+ #
10
+ # @param customer_id [String] customer ID
11
+ # @return [Hash] review details
6
12
  def get(customer_id, **options)
7
13
  headers = extract_headers(options)
8
14
  @client.get("v1/customers/#{customer_id}/review", headers: headers)
9
15
  end
10
16
 
17
+ # Submit a review decision.
18
+ #
19
+ # @param customer_id [String] customer ID
20
+ # @param status [String] decision status (e.g. "approved", "rejected")
21
+ # @return [Hash] updated review
11
22
  def decision(customer_id, status:, **options)
12
23
  payload = { status: status, **options }.compact
13
24
  headers = extract_headers(payload)
14
25
  @client.patch("v1/customers/#{customer_id}/review", payload, headers: headers)
15
26
  end
16
27
 
28
+ # Refresh a customer's identity review.
29
+ #
30
+ # @param customer_id [String] customer ID
31
+ # @return [Hash] refreshed review
17
32
  def refresh(customer_id, **options)
18
33
  headers = extract_headers(options)
19
34
  @client.put("v1/customers/#{customer_id}/refresh_review", options, headers: headers)
@@ -2,35 +2,65 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage customers and their identity reviews.
5
6
  class Customers < Base
7
+ # @return [CustomerReviews] customer identity review sub-resource
6
8
  def reviews = @reviews ||= CustomerReviews.new(@client)
7
9
 
10
+ # Create a new customer.
11
+ #
12
+ # @param name [String] customer full name
13
+ # @param type [String] "individual" or "business"
14
+ # @param email [String] customer email
15
+ # @param phone [String] phone in E.164 format (e.g. "+15551234567")
16
+ # @param device [Hash] device info (must include :ip_address)
17
+ # @return [Hash] created customer
8
18
  def create(name:, type:, email:, phone:, device:, **options)
9
19
  payload = { name: name, type: type, email: email, phone: phone, device: device, **options }.compact
10
20
  headers = extract_headers(payload)
11
21
  @client.post("v1/customers", payload, headers: headers)
12
22
  end
13
23
 
24
+ # Retrieve a customer by ID.
25
+ #
26
+ # @param id [String] customer ID
27
+ # @return [Hash] customer details
14
28
  def get(id, **options)
15
29
  headers = extract_headers(options)
16
30
  @client.get("v1/customers/#{id}", headers: headers)
17
31
  end
18
32
 
33
+ # List customers with optional pagination.
34
+ #
35
+ # @param options [Hash] filter/pagination params (page_number, page_size, etc.)
36
+ # @return [Hash] paginated customer list
19
37
  def list(**options)
20
38
  headers = extract_headers(options)
21
39
  @client.get("v1/customers", params: options, headers: headers)
22
40
  end
23
41
 
42
+ # Update a customer.
43
+ #
44
+ # @param id [String] customer ID
45
+ # @return [Hash] updated customer
24
46
  def update(id, **options)
25
47
  headers = extract_headers(options)
26
48
  @client.put("v1/customers/#{id}", options, headers: headers)
27
49
  end
28
50
 
51
+ # Delete a customer.
52
+ #
53
+ # @param id [String] customer ID
54
+ # @return [Hash] deletion confirmation
29
55
  def delete(id, **options)
30
56
  headers = extract_headers(options)
31
57
  @client.delete("v1/customers/#{id}", headers: headers)
32
58
  end
33
59
 
60
+ # Retrieve unmasked customer details.
61
+ #
62
+ # @param id [String] customer ID
63
+ # @return [Hash] unmasked customer details
34
64
  def unmasked(id, **options)
35
65
  headers = extract_headers(options)
36
66
  @client.get("v1/customers/#{id}/unmasked", headers: headers)
@@ -2,10 +2,16 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Namespace for embedded account management (multi-tenant/platform use).
6
+ # Access sub-resources via +client.embed.accounts+, +client.embed.organizations+, etc.
5
7
  class Embed < Base
8
+ # @return [EmbedAccounts]
6
9
  def accounts = @accounts ||= EmbedAccounts.new(@client)
10
+ # @return [EmbedOrganizations]
7
11
  def organizations = @organizations ||= EmbedOrganizations.new(@client)
12
+ # @return [EmbedRepresentatives]
8
13
  def representatives = @representatives ||= EmbedRepresentatives.new(@client)
14
+ # @return [EmbedLinkedBankAccounts]
9
15
  def linked_bank_accounts = @linked_bank_accounts ||= EmbedLinkedBankAccounts.new(@client)
10
16
  end
11
17
  end
@@ -2,7 +2,16 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage embedded accounts for platform/marketplace use.
6
+ # Accessed via {Embed#accounts}.
5
7
  class EmbedAccounts < Base
8
+ # Create an embedded account.
9
+ #
10
+ # @param organization_id [String] parent organization ID
11
+ # @param account_type [String] account type (e.g. "standard")
12
+ # @param business_profile [Hash] business details (must include :name)
13
+ # @param access_level [String] access level (e.g. "standard")
14
+ # @return [Hash] created account
6
15
  def create(organization_id:, account_type:, business_profile:, access_level:, **options)
7
16
  payload = {
8
17
  organization_id: organization_id, account_type: account_type,
@@ -12,27 +21,48 @@ module StraddlePay
12
21
  @client.post("v1/accounts", payload, headers: headers)
13
22
  end
14
23
 
24
+ # Retrieve an account by ID.
25
+ #
26
+ # @param id [String] account ID
27
+ # @return [Hash] account details
15
28
  def get(id, **options)
16
29
  headers = extract_headers(options)
17
30
  @client.get("v1/accounts/#{id}", headers: headers)
18
31
  end
19
32
 
33
+ # List accounts with optional filters.
34
+ #
35
+ # @return [Hash] paginated account list
20
36
  def list(**options)
21
37
  headers = extract_headers(options)
22
38
  @client.get("v1/accounts", params: options, headers: headers)
23
39
  end
24
40
 
41
+ # Update an account.
42
+ #
43
+ # @param id [String] account ID
44
+ # @return [Hash] updated account
25
45
  def update(id, **options)
26
46
  headers = extract_headers(options)
27
47
  @client.put("v1/accounts/#{id}", options, headers: headers)
28
48
  end
29
49
 
50
+ # Onboard an account (accept terms of service).
51
+ #
52
+ # @param id [String] account ID
53
+ # @param terms_of_service [Hash] ToS acceptance (must include accepted: true)
54
+ # @return [Hash] onboarded account
30
55
  def onboard(id, terms_of_service:, **options)
31
56
  payload = { terms_of_service: terms_of_service, **options }.compact
32
57
  headers = extract_headers(payload)
33
58
  @client.post("v1/accounts/#{id}/onboard", payload, headers: headers)
34
59
  end
35
60
 
61
+ # Simulate account status change (sandbox only).
62
+ #
63
+ # @param id [String] account ID
64
+ # @param final_status [String] target status to simulate
65
+ # @return [Hash] simulated account
36
66
  def simulate(id, final_status:, **options)
37
67
  payload = { final_status: final_status, **options }.compact
38
68
  headers = extract_headers(payload)
@@ -2,7 +2,15 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage linked bank accounts for embedded accounts.
6
+ # Accessed via {Embed#linked_bank_accounts}.
5
7
  class EmbedLinkedBankAccounts < Base
8
+ # Link a bank account to an embedded account.
9
+ #
10
+ # @param account_id [String] parent account ID
11
+ # @param bank_account [Hash] bank details (account_number, routing_number)
12
+ # @param description [String] account description
13
+ # @return [Hash] created linked bank account
6
14
  def create(account_id:, bank_account:, description:, **options)
7
15
  payload = {
8
16
  account_id: account_id, bank_account: bank_account,
@@ -12,26 +20,45 @@ module StraddlePay
12
20
  @client.post("v1/linked_bank_accounts", payload, headers: headers)
13
21
  end
14
22
 
23
+ # Retrieve a linked bank account by ID.
24
+ #
25
+ # @param id [String] linked bank account ID
26
+ # @return [Hash] linked bank account details
15
27
  def get(id, **options)
16
28
  headers = extract_headers(options)
17
29
  @client.get("v1/linked_bank_accounts/#{id}", headers: headers)
18
30
  end
19
31
 
32
+ # List linked bank accounts with optional filters.
33
+ #
34
+ # @return [Hash] paginated linked bank account list
20
35
  def list(**options)
21
36
  headers = extract_headers(options)
22
37
  @client.get("v1/linked_bank_accounts", params: options, headers: headers)
23
38
  end
24
39
 
40
+ # Update a linked bank account.
41
+ #
42
+ # @param id [String] linked bank account ID
43
+ # @return [Hash] updated linked bank account
25
44
  def update(id, **options)
26
45
  headers = extract_headers(options)
27
46
  @client.put("v1/linked_bank_accounts/#{id}", options, headers: headers)
28
47
  end
29
48
 
49
+ # Cancel a linked bank account.
50
+ #
51
+ # @param id [String] linked bank account ID
52
+ # @return [Hash] cancelled linked bank account
30
53
  def cancel(id, **options)
31
54
  headers = extract_headers(options)
32
55
  @client.patch("v1/linked_bank_accounts/#{id}/cancel", options.empty? ? nil : options, headers: headers)
33
56
  end
34
57
 
58
+ # Retrieve unmasked linked bank account details.
59
+ #
60
+ # @param id [String] linked bank account ID
61
+ # @return [Hash] unmasked linked bank account details
35
62
  def unmask(id, **options)
36
63
  headers = extract_headers(options)
37
64
  @client.get("v1/linked_bank_accounts/#{id}/unmask", headers: headers)
@@ -2,18 +2,31 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage organizations for embedded accounts.
6
+ # Accessed via {Embed#organizations}.
5
7
  class EmbedOrganizations < Base
8
+ # Create an organization.
9
+ #
10
+ # @param name [String] organization name
11
+ # @return [Hash] created organization
6
12
  def create(name:, **options)
7
13
  payload = { name: name, **options }.compact
8
14
  headers = extract_headers(payload)
9
15
  @client.post("v1/organizations", payload, headers: headers)
10
16
  end
11
17
 
18
+ # Retrieve an organization by ID.
19
+ #
20
+ # @param id [String] organization ID
21
+ # @return [Hash] organization details
12
22
  def get(id, **options)
13
23
  headers = extract_headers(options)
14
24
  @client.get("v1/organizations/#{id}", headers: headers)
15
25
  end
16
26
 
27
+ # List organizations with optional filters.
28
+ #
29
+ # @return [Hash] paginated organization list
17
30
  def list(**options)
18
31
  headers = extract_headers(options)
19
32
  @client.get("v1/organizations", params: options, headers: headers)
@@ -2,7 +2,20 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage representatives for embedded accounts.
6
+ # Accessed via {Embed#representatives}.
5
7
  class EmbedRepresentatives < Base
8
+ # Create a representative.
9
+ #
10
+ # @param account_id [String] parent account ID
11
+ # @param first_name [String] first name
12
+ # @param last_name [String] last name
13
+ # @param email [String] email address
14
+ # @param dob [String] date of birth (YYYY-MM-DD)
15
+ # @param mobile_number [String] phone in E.164 format
16
+ # @param relationship [String] relationship to business (e.g. "owner")
17
+ # @param ssn_last4 [String] last 4 digits of SSN
18
+ # @return [Hash] created representative
6
19
  def create(account_id:, first_name:, last_name:, email:, dob:, mobile_number:, relationship:, ssn_last4:,
7
20
  **options)
8
21
  payload = {
@@ -14,21 +27,36 @@ module StraddlePay
14
27
  @client.post("v1/representatives", payload, headers: headers)
15
28
  end
16
29
 
30
+ # Retrieve a representative by ID.
31
+ #
32
+ # @param id [String] representative ID
33
+ # @return [Hash] representative details
17
34
  def get(id, **options)
18
35
  headers = extract_headers(options)
19
36
  @client.get("v1/representatives/#{id}", headers: headers)
20
37
  end
21
38
 
39
+ # List representatives with optional filters.
40
+ #
41
+ # @return [Hash] paginated representative list
22
42
  def list(**options)
23
43
  headers = extract_headers(options)
24
44
  @client.get("v1/representatives", params: options, headers: headers)
25
45
  end
26
46
 
47
+ # Update a representative.
48
+ #
49
+ # @param id [String] representative ID
50
+ # @return [Hash] updated representative
27
51
  def update(id, **options)
28
52
  headers = extract_headers(options)
29
53
  @client.put("v1/representatives/#{id}", options, headers: headers)
30
54
  end
31
55
 
56
+ # Retrieve unmasked representative details.
57
+ #
58
+ # @param id [String] representative ID
59
+ # @return [Hash] unmasked representative details
32
60
  def unmask(id, **options)
33
61
  headers = extract_headers(options)
34
62
  @client.get("v1/representatives/#{id}/unmask", headers: headers)
@@ -2,12 +2,21 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Query funding events (bank settlement records).
5
6
  class FundingEvents < Base
7
+ # List funding events with optional filters.
8
+ #
9
+ # @param options [Hash] filter/pagination params
10
+ # @return [Hash] paginated funding event list
6
11
  def list(**options)
7
12
  headers = extract_headers(options)
8
13
  @client.get("v1/funding-events", params: options, headers: headers)
9
14
  end
10
15
 
16
+ # Retrieve a funding event by ID.
17
+ #
18
+ # @param id [String] funding event ID
19
+ # @return [Hash] funding event details
11
20
  def get(id, **options)
12
21
  headers = extract_headers(options)
13
22
  @client.get("v1/funding-events/#{id}", headers: headers)
@@ -2,32 +2,56 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage paykeys (tokenized bank account references).
5
6
  class Paykeys < Base
7
+ # Retrieve a paykey by ID.
8
+ #
9
+ # @param id [String] paykey ID
10
+ # @return [Hash] paykey details
6
11
  def get(id, **options)
7
12
  headers = extract_headers(options)
8
13
  @client.get("v1/paykeys/#{id}", headers: headers)
9
14
  end
10
15
 
16
+ # List paykeys with optional filters.
17
+ #
18
+ # @return [Hash] paginated paykey list
11
19
  def list(**options)
12
20
  headers = extract_headers(options)
13
21
  @client.get("v1/paykeys", params: options, headers: headers)
14
22
  end
15
23
 
24
+ # Retrieve unmasked paykey details.
25
+ #
26
+ # @param id [String] paykey ID
27
+ # @return [Hash] unmasked paykey details
16
28
  def unmasked(id, **options)
17
29
  headers = extract_headers(options)
18
30
  @client.get("v1/paykeys/#{id}/unmasked", headers: headers)
19
31
  end
20
32
 
33
+ # Reveal full paykey details (sensitive).
34
+ #
35
+ # @param id [String] paykey ID
36
+ # @return [Hash] revealed paykey
21
37
  def reveal(id, **options)
22
38
  headers = extract_headers(options)
23
39
  @client.get("v1/paykeys/#{id}/reveal", headers: headers)
24
40
  end
25
41
 
42
+ # Cancel a paykey.
43
+ #
44
+ # @param id [String] paykey ID
45
+ # @return [Hash] cancelled paykey
26
46
  def cancel(id, **options)
27
47
  headers = extract_headers(options)
28
48
  @client.put("v1/paykeys/#{id}/cancel", options, headers: headers)
29
49
  end
30
50
 
51
+ # Submit a paykey for review.
52
+ #
53
+ # @param id [String] paykey ID
54
+ # @return [Hash] review result
31
55
  def review(id, **options)
32
56
  headers = extract_headers(options)
33
57
  @client.patch("v1/paykeys/#{id}/review", options, headers: headers)
@@ -2,7 +2,12 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Query unified payment records (charges and payouts).
5
6
  class Payments < Base
7
+ # List payments with optional filters.
8
+ #
9
+ # @param options [Hash] filter/pagination params
10
+ # @return [Hash] paginated payment list
6
11
  def list(**options)
7
12
  headers = extract_headers(options)
8
13
  @client.get("v1/payments", params: options, headers: headers)
@@ -2,7 +2,20 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Manage ACH payout (credit) transactions.
6
+ #
7
+ # @see https://straddle.dev/api-reference Straddle API Reference
5
8
  class Payouts < Base
9
+ # Create a new payout.
10
+ #
11
+ # @param paykey [String] paykey identifier
12
+ # @param amount [Integer] amount in cents
13
+ # @param currency [String] three-letter currency code
14
+ # @param description [String] payout description
15
+ # @param payment_date [String] date in YYYY-MM-DD format
16
+ # @param device [Hash] device info (must include :ip_address)
17
+ # @param external_id [String] your external reference ID
18
+ # @return [Hash] created payout
6
19
  def create(paykey:, amount:, currency:, description:, payment_date:, device:, external_id:, **options)
7
20
  payload = {
8
21
  paykey: paykey, amount: amount, currency: currency, description: description,
@@ -12,34 +25,61 @@ module StraddlePay
12
25
  @client.post("v1/payouts", payload, headers: headers)
13
26
  end
14
27
 
28
+ # Retrieve a payout by ID.
29
+ #
30
+ # @param id [String] payout ID
31
+ # @return [Hash] payout details
15
32
  def get(id, **options)
16
33
  headers = extract_headers(options)
17
34
  @client.get("v1/payouts/#{id}", headers: headers)
18
35
  end
19
36
 
37
+ # Update a payout.
38
+ #
39
+ # @param id [String] payout ID
40
+ # @return [Hash] updated payout
20
41
  def update(id, **options)
21
42
  headers = extract_headers(options)
22
43
  @client.put("v1/payouts/#{id}", options, headers: headers)
23
44
  end
24
45
 
46
+ # Cancel a payout.
47
+ #
48
+ # @param id [String] payout ID
49
+ # @param reason [String] cancellation reason (required)
50
+ # @return [Hash] cancelled payout
25
51
  def cancel(id, reason:, **options)
26
52
  payload = { reason: reason, **options }.compact
27
53
  headers = extract_headers(payload)
28
54
  @client.put("v1/payouts/#{id}/cancel", payload, headers: headers)
29
55
  end
30
56
 
57
+ # Place a payout on hold.
58
+ #
59
+ # @param id [String] payout ID
60
+ # @param reason [String] hold reason (required)
61
+ # @return [Hash] held payout
31
62
  def hold(id, reason:, **options)
32
63
  payload = { reason: reason, **options }.compact
33
64
  headers = extract_headers(payload)
34
65
  @client.put("v1/payouts/#{id}/hold", payload, headers: headers)
35
66
  end
36
67
 
68
+ # Release a held payout.
69
+ #
70
+ # @param id [String] payout ID
71
+ # @param reason [String] release reason (required)
72
+ # @return [Hash] released payout
37
73
  def release(id, reason:, **options)
38
74
  payload = { reason: reason, **options }.compact
39
75
  headers = extract_headers(payload)
40
76
  @client.put("v1/payouts/#{id}/release", payload, headers: headers)
41
77
  end
42
78
 
79
+ # Retrieve unmasked payout details.
80
+ #
81
+ # @param id [String] payout ID
82
+ # @return [Hash] unmasked payout details
43
83
  def unmask(id, **options)
44
84
  headers = extract_headers(options)
45
85
  @client.get("v1/payouts/#{id}/unmask", headers: headers)
@@ -2,7 +2,12 @@
2
2
 
3
3
  module StraddlePay
4
4
  module Resources
5
+ # Generate reports from the Straddle API.
5
6
  class Reports < Base
7
+ # Get total customers grouped by status.
8
+ #
9
+ # @param options [Hash] optional filters
10
+ # @return [Hash] report data
6
11
  def total_customers_by_status(**options)
7
12
  headers = extract_headers(options)
8
13
  @client.post("v1/reports/total_customers_by_status", options.empty? ? nil : options, headers: headers)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StraddlePay
4
- VERSION = "0.1.0"
4
+ # @return [String] current gem version
5
+ VERSION = "0.1.2"
5
6
  end
data/lib/straddle_pay.rb CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  require_relative "straddle_pay/version"
4
4
 
5
+ # Ruby client for the Straddle payment infrastructure API.
6
+ #
7
+ # @example Global configuration
8
+ # StraddlePay.configure do |config|
9
+ # config.api_key = ENV.fetch("STRADDLE_API_KEY")
10
+ # config.base_url = StraddlePay::Config::PRODUCTION_URL
11
+ # end
12
+ #
13
+ # @example Per-instance client
14
+ # client = StraddlePay::Client.new(api_key: "sk_test_...")
15
+ #
16
+ # @see https://straddle.dev/api-reference Straddle API Reference
5
17
  module StraddlePay
6
18
  autoload :Config, "straddle_pay/config"
7
19
  autoload :Client, "straddle_pay/client"
@@ -32,14 +44,20 @@ module StraddlePay
32
44
  end
33
45
 
34
46
  class << self
47
+ # @return [Config] current configuration instance
35
48
  def config
36
49
  @config ||= Config.new
37
50
  end
38
51
 
52
+ # Yields the global configuration for modification.
53
+ #
54
+ # @yieldparam config [Config] the configuration instance
39
55
  def configure
40
56
  yield(config)
41
57
  end
42
58
 
59
+ # Reset configuration to defaults.
60
+ # @return [void]
43
61
  def reset_configuration!
44
62
  @config = nil
45
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straddle_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dpaluy
@@ -35,6 +35,7 @@ extra_rdoc_files:
35
35
  - LICENSE.txt
36
36
  - README.md
37
37
  files:
38
+ - ".yardopts"
38
39
  - CHANGELOG.md
39
40
  - LICENSE.txt
40
41
  - README.md
@@ -77,14 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
78
  requirements:
78
79
  - - ">="
79
80
  - !ruby/object:Gem::Version
80
- version: 3.2.0
81
+ version: 3.4.0
81
82
  required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  requirements:
83
84
  - - ">="
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements: []
87
- rubygems_version: 4.0.3
88
+ rubygems_version: 3.6.9
88
89
  specification_version: 4
89
90
  summary: Ruby client for the Straddle payment infrastructure API.
90
91
  test_files: []