manza 0.3.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.
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Manza
4
+ module Resources
5
+ # Webhook endpoint configuration.
6
+ class WebhookEndpoints < Base
7
+ # GET /api/webhook_endpoints
8
+ def list(limit: MAX_PER_PAGE, cursor: nil)
9
+ list_page("api/webhook_endpoints", limit: limit, cursor: cursor)
10
+ end
11
+
12
+ # GET /api/webhook_endpoints/:id
13
+ def get(id)
14
+ http_get(encode_path("api/webhook_endpoints", id))
15
+ end
16
+
17
+ # POST /api/webhook_endpoints
18
+ #
19
+ # @param url [String] the URL to deliver events to
20
+ # @param events [Array<String>] event names to subscribe to
21
+ # @param description [String, nil]
22
+ def create(url:, events:, description: nil)
23
+ http_post(
24
+ "api/webhook_endpoints",
25
+ body: { url: url, events: events, description: description }.compact
26
+ )
27
+ end
28
+
29
+ # PATCH /api/webhook_endpoints/:id
30
+ #
31
+ # Changing `url` on the endpoint enrolled as transfer authorizer
32
+ # raises {Manza::ValidationError}.
33
+ def update(id, **attributes)
34
+ http_patch(encode_path("api/webhook_endpoints", id), body: attributes)
35
+ end
36
+
37
+ # DELETE /api/webhook_endpoints/:id
38
+ #
39
+ # A soft delete (still 204).
40
+ def delete(id)
41
+ http_delete(encode_path("api/webhook_endpoints", id))
42
+ end
43
+
44
+ # POST /api/webhook_endpoints/:id/test
45
+ def test_endpoint(id)
46
+ http_post(encode_path("api/webhook_endpoints", id, "test"))
47
+ end
48
+
49
+ # POST /api/webhook_endpoints/:id/regenerate_secret
50
+ #
51
+ # Raises {Manza::ValidationError} on the enrolled transfer authorizer.
52
+ def regenerate_secret(id)
53
+ http_post(encode_path("api/webhook_endpoints", id, "regenerate_secret"))
54
+ end
55
+
56
+ # POST /api/webhook_endpoints/:id/enable
57
+ def enable(id)
58
+ http_post(encode_path("api/webhook_endpoints", id, "enable"))
59
+ end
60
+
61
+ # POST /api/webhook_endpoints/:id/disable
62
+ def disable(id)
63
+ http_post(encode_path("api/webhook_endpoints", id, "disable"))
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Manza
4
+ # Wraps a Faraday response with the few helpers callers actually
5
+ # want. Cheap value object — no parsing or normalization is done
6
+ # eagerly; `body`, `data`, `headers` all read straight through.
7
+ #
8
+ # The SDK's resource methods return one of these directly when the
9
+ # endpoint is a single-record fetch. List endpoints return a
10
+ # {Manza::Page} instead, which composes a Response.
11
+ class Response
12
+ attr_reader :raw, :request_id
13
+
14
+ def initialize(raw, request_id: nil)
15
+ @raw = raw
16
+ @request_id = request_id || raw.headers["x-request-id"]
17
+ end
18
+
19
+ def status
20
+ raw.status
21
+ end
22
+
23
+ def headers
24
+ raw.headers
25
+ end
26
+
27
+ def body
28
+ raw.body
29
+ end
30
+
31
+ def success?
32
+ status.between?(200, 299)
33
+ end
34
+
35
+ # Returns the response body without the `data` envelope when one
36
+ # is present. List endpoints wrap their items in `{"data": [...]}`
37
+ # — this returns the array. Single-record endpoints return the
38
+ # body as-is.
39
+ def data
40
+ return body unless body.is_a?(Hash)
41
+
42
+ body.key?("data") ? body["data"] : body
43
+ end
44
+
45
+ # The Manza-Version header echoed by the server, or the legacy
46
+ # Zazu-Version one. Useful for debugging migration mismatches.
47
+ def api_version
48
+ headers["manza-version"] || headers["zazu-version"]
49
+ end
50
+
51
+ def to_h
52
+ {
53
+ status:,
54
+ request_id:,
55
+ api_version:,
56
+ body:
57
+ }.compact
58
+ end
59
+
60
+ def inspect
61
+ "#<#{self.class.name} status=#{status} request_id=#{request_id.inspect}>"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "openssl"
4
+
5
+ module Manza
6
+ # Signs a machine-authorization challenge for an API-created transfer
7
+ # draft. Pure functions — no HTTP.
8
+ #
9
+ # The `payment.authorization_requested` webhook delivers the
10
+ # authorization id and a one-time nonce. Build the signature input
11
+ # from your *own* record of the transfer (not the webhook's
12
+ # `signature_input`, which is there only to compare against), sign
13
+ # it with the authorizer endpoint's signing secret, and pass the
14
+ # result to {Resources::TransferDrafts#authorize}:
15
+ #
16
+ # input = Manza::TransferAuthorization.signature_input(
17
+ # payment_id: draft["id"], nonce: nonce, amount: draft["amount"],
18
+ # currency_code: draft["currency_code"], account_id: draft["account_id"],
19
+ # payee: Manza::TransferAuthorization.payee_for(external_account_id: draft["external_account_id"]),
20
+ # client_reference: draft["client_reference"]
21
+ # )
22
+ # signature = Manza::TransferAuthorization.sign(secret: signing_secret, signature_input: input)
23
+ # manza.transfer_drafts.authorize(draft["id"], authorization_id: authorization_id, signature: signature)
24
+ module TransferAuthorization
25
+ SIGNATURE_VERSION = "manza.transfer-authorization.v1"
26
+
27
+ module_function
28
+
29
+ # `amount` must be the API's decimal string verbatim (e.g. "2500.0").
30
+ # `client_reference` is empty when the transfer has none.
31
+ def signature_input(payment_id:, nonce:, amount:, currency_code:, account_id:, payee:, client_reference: nil)
32
+ raise Manza::ArgumentError, "amount must be the API's decimal string (got #{amount.inspect})" unless amount.is_a?(String)
33
+
34
+ [
35
+ SIGNATURE_VERSION, payment_id, nonce, amount, currency_code, account_id, payee, client_reference.to_s
36
+ ].join("|")
37
+ end
38
+
39
+ # Hex HMAC-SHA256 of the signature input under the authorizer
40
+ # endpoint's signing secret.
41
+ def sign(secret:, signature_input:)
42
+ OpenSSL::HMAC.hexdigest("SHA256", secret, signature_input)
43
+ end
44
+
45
+ # The payee token: `ext:<id>` for a beneficiary's bank account,
46
+ # `own:<id>` for one of the entity's own accounts. Pass exactly one.
47
+ def payee_for(external_account_id: nil, destination_account_id: nil)
48
+ unless external_account_id.nil? ^ destination_account_id.nil?
49
+ raise Manza::ArgumentError, "pass exactly one of external_account_id or destination_account_id"
50
+ end
51
+
52
+ destination_account_id ? "own:#{destination_account_id}" : "ext:#{external_account_id}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Manza
4
+ VERSION = "0.3.0"
5
+ end
data/lib/manza.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby SDK for the Manza API.
4
+ #
5
+ # Usage:
6
+ #
7
+ # manza = Manza.new(api_key: ENV["MANZA_API_KEY"])
8
+ # manza.entity.get
9
+ # manza.accounts.list(limit: 50)
10
+ #
11
+ # See README.md for full documentation.
12
+ module Manza
13
+ # Module-level shortcut. Equivalent to Manza::Client.new(...).
14
+ def self.new(**)
15
+ Client.new(**)
16
+ end
17
+ end
18
+
19
+ require_relative "manza/version"
20
+ require_relative "manza/errors"
21
+ require_relative "manza/response"
22
+ require_relative "manza/page"
23
+ require_relative "manza/transfer_authorization"
24
+ require_relative "manza/resources/base"
25
+ require_relative "manza/resources/accounts"
26
+ require_relative "manza/resources/beneficiaries"
27
+ require_relative "manza/resources/checkout_sessions"
28
+ require_relative "manza/resources/customers"
29
+ require_relative "manza/resources/entity"
30
+ require_relative "manza/resources/invoices"
31
+ require_relative "manza/resources/payee_trust_requests"
32
+ require_relative "manza/resources/payment_links"
33
+ require_relative "manza/resources/transfer_drafts"
34
+ require_relative "manza/resources/webhook_endpoints"
35
+ require_relative "manza/client"
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: manza
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Manza
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-retry
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: httpx
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ description: Faraday-based Ruby SDK for the Manza payment platform API. Wraps accounts,
55
+ customers, invoices, payment links, transactions, and webhook endpoints. HTTPX adapter
56
+ for HTTP/2 + persistent connections.
57
+ email:
58
+ - hello@get-manza.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - CHANGELOG.md
64
+ - LICENSE
65
+ - README.md
66
+ - lib/manza.rb
67
+ - lib/manza/client.rb
68
+ - lib/manza/errors.rb
69
+ - lib/manza/page.rb
70
+ - lib/manza/resources/accounts.rb
71
+ - lib/manza/resources/base.rb
72
+ - lib/manza/resources/beneficiaries.rb
73
+ - lib/manza/resources/checkout_sessions.rb
74
+ - lib/manza/resources/customers.rb
75
+ - lib/manza/resources/entity.rb
76
+ - lib/manza/resources/invoices.rb
77
+ - lib/manza/resources/payee_trust_requests.rb
78
+ - lib/manza/resources/payment_links.rb
79
+ - lib/manza/resources/transfer_drafts.rb
80
+ - lib/manza/resources/webhook_endpoints.rb
81
+ - lib/manza/response.rb
82
+ - lib/manza/transfer_authorization.rb
83
+ - lib/manza/version.rb
84
+ homepage: https://github.com/getmanza/manza-ruby
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ source_code_uri: https://github.com/getmanza/manza-ruby/tree/main
89
+ changelog_uri: https://github.com/getmanza/manza-ruby/blob/main/CHANGELOG.md
90
+ bug_tracker_uri: https://github.com/getmanza/manza-ruby/issues
91
+ documentation_uri: https://github.com/getmanza/manza-ruby#readme
92
+ rubygems_mfa_required: 'true'
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 3.3.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 4.0.6
108
+ specification_version: 4
109
+ summary: Ruby SDK for the Manza API
110
+ test_files: []