abacatepay-ruby 0.1.0 → 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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +136 -0
  3. data/CHANGELOG.md +171 -1
  4. data/README.md +491 -87
  5. data/Rakefile +1 -1
  6. data/abacatepay-ruby.gemspec +17 -10
  7. data/lib/abacate_pay/clients/billing_client.rb +90 -0
  8. data/lib/abacate_pay/clients/checkout_client.rb +91 -0
  9. data/lib/abacate_pay/clients/client.rb +202 -0
  10. data/lib/abacate_pay/clients/coupon_client.rb +57 -0
  11. data/lib/abacate_pay/clients/customer_client.rb +58 -0
  12. data/lib/abacate_pay/clients/payment_link_client.rb +71 -0
  13. data/lib/abacate_pay/clients/payout_client.rb +41 -0
  14. data/lib/abacate_pay/clients/pix_client.rb +47 -0
  15. data/lib/abacate_pay/clients/product_client.rb +54 -0
  16. data/lib/abacate_pay/clients/store_client.rb +40 -0
  17. data/lib/abacate_pay/clients/subscription_client.rb +90 -0
  18. data/lib/abacate_pay/clients/transparent_client.rb +125 -0
  19. data/lib/abacate_pay/clients/webhook_client.rb +82 -0
  20. data/lib/abacate_pay/clients.rb +24 -0
  21. data/lib/abacate_pay/collection.rb +98 -0
  22. data/lib/abacate_pay/configuration.rb +83 -0
  23. data/lib/{abacatepay/enums/billing → abacate_pay/enums/billings}/frequencies.rb +9 -3
  24. data/lib/{abacatepay/enums/billing → abacate_pay/enums/billings}/methods.rb +12 -3
  25. data/lib/{abacatepay/enums/billing → abacate_pay/enums/billings}/statuses.rb +3 -2
  26. data/lib/abacate_pay/enums/checkouts/statuses.rb +29 -0
  27. data/lib/abacate_pay/enums/coupons/discount_kinds.rb +26 -0
  28. data/lib/abacate_pay/enums/coupons/statuses.rb +27 -0
  29. data/lib/abacate_pay/enums/payouts/statuses.rb +29 -0
  30. data/lib/abacate_pay/enums/pix/key_types.rb +30 -0
  31. data/lib/abacate_pay/enums/products/cycles.rb +28 -0
  32. data/lib/abacate_pay/enums/transfers/statuses.rb +30 -0
  33. data/lib/abacate_pay/enums/webhooks/event_types.rb +50 -0
  34. data/lib/abacate_pay/enums.rb +20 -0
  35. data/lib/{abacatepay/resources/billing → abacate_pay/resources/billings}/metadata.rb +2 -8
  36. data/lib/{abacatepay/resources/billing → abacate_pay/resources/billings}/product.rb +2 -8
  37. data/lib/{abacatepay/resources/billing.rb → abacate_pay/resources/billings.rb} +16 -16
  38. data/lib/abacate_pay/resources/checkouts.rb +84 -0
  39. data/lib/abacate_pay/resources/coupons.rb +41 -0
  40. data/lib/{abacatepay/resources/customer → abacate_pay/resources/customers}/metadata.rb +2 -8
  41. data/lib/{abacatepay/resources/customer.rb → abacate_pay/resources/customers.rb} +5 -5
  42. data/lib/abacate_pay/resources/payouts.rb +40 -0
  43. data/lib/abacate_pay/resources/pix_transfers.rb +41 -0
  44. data/lib/abacate_pay/resources/products.rb +40 -0
  45. data/lib/{abacatepay → abacate_pay}/resources/resource.rb +33 -21
  46. data/lib/abacate_pay/resources/store/balance.rb +20 -0
  47. data/lib/abacate_pay/resources/store.rb +36 -0
  48. data/lib/abacate_pay/resources/subscriptions.rb +72 -0
  49. data/lib/abacate_pay/resources/transparents.rb +53 -0
  50. data/lib/abacate_pay/resources/webhook_endpoints.rb +49 -0
  51. data/lib/abacate_pay/resources.rb +27 -0
  52. data/lib/{abacatepay → abacate_pay}/version.rb +2 -2
  53. data/lib/abacate_pay/webhooks/event.rb +20 -0
  54. data/lib/abacate_pay/webhooks.rb +100 -0
  55. data/lib/abacate_pay.rb +112 -4
  56. metadata +75 -47
  57. data/lib/abacatepay/clients/billing_client.rb +0 -60
  58. data/lib/abacatepay/clients/client.rb +0 -68
  59. data/lib/abacatepay/clients/customer_client.rb +0 -39
  60. data/lib/abacatepay/clients.rb +0 -12
  61. data/lib/abacatepay/configuration.rb +0 -56
  62. data/lib/abacatepay/enums.rb +0 -12
  63. data/lib/abacatepay/resources.rb +0 -15
  64. data/sig/abacatepay/rails.rbs +0 -6
data/lib/abacate_pay.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "abacate_pay/version"
4
4
  require "abacate_pay/configuration"
5
+ require "abacate_pay/collection"
5
6
 
6
7
  # Main module for AbacatePay SDK integration
7
8
  module AbacatePay
@@ -10,12 +11,26 @@ module AbacatePay
10
11
  class ApiError < Error; end
11
12
 
12
13
  class << self
13
- # Gets or sets the global configuration
14
- attr_accessor :configuration
14
+ # @return [Configuration, nil] The global configuration
15
+ attr_reader :configuration
16
+
17
+ # Replacing the configuration invalidates every memoized client, so a
18
+ # client built against the previous credentials can never outlive them.
19
+ #
20
+ # @param value [Configuration, nil] The new configuration
21
+ # @return [void]
22
+ def configuration=(value)
23
+ @configuration = value
24
+ reset_clients!
25
+ end
15
26
  end
16
27
 
17
28
  # Configures the SDK
18
29
  #
30
+ # Memoized clients are discarded so a token changed at runtime takes effect
31
+ # immediately. Without this, a client built before the change keeps sending
32
+ # the old bearer token.
33
+ #
19
34
  # @example
20
35
  # AbacatePay.configure do |config|
21
36
  # config.api_token = "your-token-here"
@@ -28,6 +43,7 @@ module AbacatePay
28
43
  self.configuration ||= Configuration.new
29
44
  yield(configuration)
30
45
  configuration.validate!
46
+ reset_clients!
31
47
  end
32
48
 
33
49
  # Resets the configuration to defaults
@@ -35,8 +51,100 @@ module AbacatePay
35
51
  # @return [void]
36
52
  def self.reset!
37
53
  self.configuration = Configuration.new
54
+ reset_clients!
55
+ end
56
+
57
+ # Returns the configuration, refusing to proceed if the SDK was never set up.
58
+ #
59
+ # Forgetting to call {configure} is the most common first-run mistake; without
60
+ # this the failure surfaces as `NoMethodError: undefined method 'api_url' for
61
+ # nil` from deep inside the client.
62
+ #
63
+ # @return [Configuration] The active configuration
64
+ # @raise [ConfigurationError] if {configure} has not been called
65
+ def self.configuration!
66
+ configuration || raise(
67
+ ConfigurationError,
68
+ "AbacatePay is not configured. Call AbacatePay.configure { |c| c.api_token = ENV['ABACATEPAY_API_KEY'] } first."
69
+ )
70
+ end
71
+
72
+ # Discards every memoized client so the next call rebuilds from current config
73
+ #
74
+ # @return [void]
75
+ def self.reset_clients!
76
+ @clients = {}
77
+ end
78
+
79
+ # @return [Hash{Symbol => Clients::Client}] Memoized clients, keyed by name
80
+ def self.clients
81
+ @clients ||= {}
82
+ end
83
+ private_class_method :clients
84
+
85
+ # @return [Clients::CustomerClient] Customer API client
86
+ def self.customers
87
+ clients[:customers] ||= Clients::CustomerClient.new
88
+ end
89
+
90
+ # @return [Clients::ProductClient] Product API client
91
+ def self.products
92
+ clients[:products] ||= Clients::ProductClient.new
93
+ end
94
+
95
+ # @return [Clients::CouponClient] Coupon API client
96
+ def self.coupons
97
+ clients[:coupons] ||= Clients::CouponClient.new
98
+ end
99
+
100
+ # @return [Clients::CheckoutClient] Checkout API client
101
+ def self.checkouts
102
+ clients[:checkouts] ||= Clients::CheckoutClient.new
103
+ end
104
+
105
+ # @return [Clients::SubscriptionClient] Subscription API client
106
+ def self.subscriptions
107
+ clients[:subscriptions] ||= Clients::SubscriptionClient.new
108
+ end
109
+
110
+ # @return [Clients::TransparentClient] PIX Transparent API client
111
+ def self.transparents
112
+ clients[:transparents] ||= Clients::TransparentClient.new
113
+ end
114
+
115
+ # @return [Clients::PixClient] PIX Transfer API client
116
+ def self.pix
117
+ clients[:pix] ||= Clients::PixClient.new
118
+ end
119
+
120
+ # @return [Clients::PayoutClient] Payout API client
121
+ def self.payouts
122
+ clients[:payouts] ||= Clients::PayoutClient.new
123
+ end
124
+
125
+ # @return [Clients::StoreClient] Store API client
126
+ def self.store
127
+ clients[:store] ||= Clients::StoreClient.new
128
+ end
129
+
130
+ # @return [Clients::PaymentLinkClient] Reusable payment link API client
131
+ def self.payment_links
132
+ clients[:payment_links] ||= Clients::PaymentLinkClient.new
133
+ end
134
+
135
+ # Webhook *endpoint registration*. To verify an inbound delivery, use
136
+ # {AbacatePay::Webhooks.construct_event}.
137
+ #
138
+ # @return [Clients::WebhookClient] Webhook management API client
139
+ def self.webhook_endpoints
140
+ clients[:webhook_endpoints] ||= Clients::WebhookClient.new
38
141
  end
39
142
  end
40
143
 
41
- # Autoload all components
42
- Dir[File.join(__dir__, "abacate_pay", "**", "*.rb")].sort.each { |file| require file }
144
+ # Components are required explicitly, in dependency order. A glob would load
145
+ # clients/billing_client.rb before clients/client.rb and blow up on the
146
+ # superclass, and it silently swallows files that were never wired up.
147
+ require "abacate_pay/enums"
148
+ require "abacate_pay/resources"
149
+ require "abacate_pay/clients"
150
+ require "abacate_pay/webhooks"
metadata CHANGED
@@ -1,105 +1,104 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abacatepay-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Cardoso
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: rails
13
+ name: faraday
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '7.0'
18
+ version: '2.14'
20
19
  - - ">="
21
20
  - !ruby/object:Gem::Version
22
- version: 7.0.0
21
+ version: 2.14.3
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - "~>"
28
27
  - !ruby/object:Gem::Version
29
- version: '7.0'
28
+ version: '2.14'
30
29
  - - ">="
31
30
  - !ruby/object:Gem::Version
32
- version: 7.0.0
31
+ version: 2.14.3
33
32
  - !ruby/object:Gem::Dependency
34
- name: faraday
33
+ name: faraday-retry
35
34
  requirement: !ruby/object:Gem::Requirement
36
35
  requirements:
37
36
  - - "~>"
38
37
  - !ruby/object:Gem::Version
39
- version: '2.9'
38
+ version: '2.3'
40
39
  type: :runtime
41
40
  prerelease: false
42
41
  version_requirements: !ruby/object:Gem::Requirement
43
42
  requirements:
44
43
  - - "~>"
45
44
  - !ruby/object:Gem::Version
46
- version: '2.9'
45
+ version: '2.3'
47
46
  - !ruby/object:Gem::Dependency
48
- name: rspec-rails
47
+ name: bundler-audit
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
50
  - - "~>"
52
51
  - !ruby/object:Gem::Version
53
- version: '6.0'
52
+ version: '0.9'
54
53
  type: :development
55
54
  prerelease: false
56
55
  version_requirements: !ruby/object:Gem::Requirement
57
56
  requirements:
58
57
  - - "~>"
59
58
  - !ruby/object:Gem::Version
60
- version: '6.0'
59
+ version: '0.9'
61
60
  - !ruby/object:Gem::Dependency
62
- name: rubocop
61
+ name: rspec
63
62
  requirement: !ruby/object:Gem::Requirement
64
63
  requirements:
65
64
  - - "~>"
66
65
  - !ruby/object:Gem::Version
67
- version: '1.57'
66
+ version: '3.12'
68
67
  type: :development
69
68
  prerelease: false
70
69
  version_requirements: !ruby/object:Gem::Requirement
71
70
  requirements:
72
71
  - - "~>"
73
72
  - !ruby/object:Gem::Version
74
- version: '1.57'
73
+ version: '3.12'
75
74
  - !ruby/object:Gem::Dependency
76
- name: rubocop-rails
75
+ name: rubocop
77
76
  requirement: !ruby/object:Gem::Requirement
78
77
  requirements:
79
78
  - - "~>"
80
79
  - !ruby/object:Gem::Version
81
- version: '2.22'
80
+ version: '1.57'
82
81
  type: :development
83
82
  prerelease: false
84
83
  version_requirements: !ruby/object:Gem::Requirement
85
84
  requirements:
86
85
  - - "~>"
87
86
  - !ruby/object:Gem::Version
88
- version: '2.22'
87
+ version: '1.57'
89
88
  - !ruby/object:Gem::Dependency
90
89
  name: rubocop-rspec
91
90
  requirement: !ruby/object:Gem::Requirement
92
91
  requirements:
93
92
  - - "~>"
94
93
  - !ruby/object:Gem::Version
95
- version: '2.25'
94
+ version: '3.0'
96
95
  type: :development
97
96
  prerelease: false
98
97
  version_requirements: !ruby/object:Gem::Requirement
99
98
  requirements:
100
99
  - - "~>"
101
100
  - !ruby/object:Gem::Version
102
- version: '2.25'
101
+ version: '3.0'
103
102
  - !ruby/object:Gem::Dependency
104
103
  name: simplecov
105
104
  requirement: !ruby/object:Gem::Requirement
@@ -114,8 +113,8 @@ dependencies:
114
113
  - - "~>"
115
114
  - !ruby/object:Gem::Version
116
115
  version: '0.22'
117
- description: The easiest way to integrate your Ruby on Rails SDK base code to AbacatePay
118
- Gateway with support to coroutines.
116
+ description: The easiest way to integrate your Ruby application with AbacatePay Gateway
117
+ for payments, subscriptions, PIX transfers, and more.
119
118
  email:
120
119
  - mathuscardoso@gmail.com
121
120
  executables: []
@@ -131,24 +130,54 @@ files:
131
130
  - Rakefile
132
131
  - abacatepay-ruby.gemspec
133
132
  - lib/abacate_pay.rb
134
- - lib/abacatepay/clients.rb
135
- - lib/abacatepay/clients/billing_client.rb
136
- - lib/abacatepay/clients/client.rb
137
- - lib/abacatepay/clients/customer_client.rb
138
- - lib/abacatepay/configuration.rb
139
- - lib/abacatepay/enums.rb
140
- - lib/abacatepay/enums/billing/frequencies.rb
141
- - lib/abacatepay/enums/billing/methods.rb
142
- - lib/abacatepay/enums/billing/statuses.rb
143
- - lib/abacatepay/resources.rb
144
- - lib/abacatepay/resources/billing.rb
145
- - lib/abacatepay/resources/billing/metadata.rb
146
- - lib/abacatepay/resources/billing/product.rb
147
- - lib/abacatepay/resources/customer.rb
148
- - lib/abacatepay/resources/customer/metadata.rb
149
- - lib/abacatepay/resources/resource.rb
150
- - lib/abacatepay/version.rb
151
- - sig/abacatepay/rails.rbs
133
+ - lib/abacate_pay/clients.rb
134
+ - lib/abacate_pay/clients/billing_client.rb
135
+ - lib/abacate_pay/clients/checkout_client.rb
136
+ - lib/abacate_pay/clients/client.rb
137
+ - lib/abacate_pay/clients/coupon_client.rb
138
+ - lib/abacate_pay/clients/customer_client.rb
139
+ - lib/abacate_pay/clients/payment_link_client.rb
140
+ - lib/abacate_pay/clients/payout_client.rb
141
+ - lib/abacate_pay/clients/pix_client.rb
142
+ - lib/abacate_pay/clients/product_client.rb
143
+ - lib/abacate_pay/clients/store_client.rb
144
+ - lib/abacate_pay/clients/subscription_client.rb
145
+ - lib/abacate_pay/clients/transparent_client.rb
146
+ - lib/abacate_pay/clients/webhook_client.rb
147
+ - lib/abacate_pay/collection.rb
148
+ - lib/abacate_pay/configuration.rb
149
+ - lib/abacate_pay/enums.rb
150
+ - lib/abacate_pay/enums/billings/frequencies.rb
151
+ - lib/abacate_pay/enums/billings/methods.rb
152
+ - lib/abacate_pay/enums/billings/statuses.rb
153
+ - lib/abacate_pay/enums/checkouts/statuses.rb
154
+ - lib/abacate_pay/enums/coupons/discount_kinds.rb
155
+ - lib/abacate_pay/enums/coupons/statuses.rb
156
+ - lib/abacate_pay/enums/payouts/statuses.rb
157
+ - lib/abacate_pay/enums/pix/key_types.rb
158
+ - lib/abacate_pay/enums/products/cycles.rb
159
+ - lib/abacate_pay/enums/transfers/statuses.rb
160
+ - lib/abacate_pay/enums/webhooks/event_types.rb
161
+ - lib/abacate_pay/resources.rb
162
+ - lib/abacate_pay/resources/billings.rb
163
+ - lib/abacate_pay/resources/billings/metadata.rb
164
+ - lib/abacate_pay/resources/billings/product.rb
165
+ - lib/abacate_pay/resources/checkouts.rb
166
+ - lib/abacate_pay/resources/coupons.rb
167
+ - lib/abacate_pay/resources/customers.rb
168
+ - lib/abacate_pay/resources/customers/metadata.rb
169
+ - lib/abacate_pay/resources/payouts.rb
170
+ - lib/abacate_pay/resources/pix_transfers.rb
171
+ - lib/abacate_pay/resources/products.rb
172
+ - lib/abacate_pay/resources/resource.rb
173
+ - lib/abacate_pay/resources/store.rb
174
+ - lib/abacate_pay/resources/store/balance.rb
175
+ - lib/abacate_pay/resources/subscriptions.rb
176
+ - lib/abacate_pay/resources/transparents.rb
177
+ - lib/abacate_pay/resources/webhook_endpoints.rb
178
+ - lib/abacate_pay/version.rb
179
+ - lib/abacate_pay/webhooks.rb
180
+ - lib/abacate_pay/webhooks/event.rb
152
181
  homepage: https://www.abacatepay.com/
153
182
  licenses:
154
183
  - MIT
@@ -156,7 +185,7 @@ metadata:
156
185
  homepage_uri: https://www.abacatepay.com/
157
186
  source_code_uri: https://github.com/AbacatePay/abacatepay-ruby-sdk
158
187
  changelog_uri: https://github.com/AbacatePay/abacatepay-ruby-sdk/blob/main/CHANGELOG.md
159
- post_install_message:
188
+ rubygems_mfa_required: 'true'
160
189
  rdoc_options: []
161
190
  require_paths:
162
191
  - lib
@@ -164,15 +193,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
193
  requirements:
165
194
  - - ">="
166
195
  - !ruby/object:Gem::Version
167
- version: 2.6.0
196
+ version: 3.2.0
168
197
  required_rubygems_version: !ruby/object:Gem::Requirement
169
198
  requirements:
170
199
  - - ">="
171
200
  - !ruby/object:Gem::Version
172
201
  version: '0'
173
202
  requirements: []
174
- rubygems_version: 3.4.10
175
- signing_key:
203
+ rubygems_version: 3.6.9
176
204
  specification_version: 4
177
- summary: AbacatePay Ruby on Rails SDK for you to start receiving payments in seconds
205
+ summary: AbacatePay Ruby SDK for you to start receiving payments in seconds
178
206
  test_files: []
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AbacatePay
4
- module Clients
5
- # Client class for managing billing-related operations in the AbacatePay API.
6
- class BillingClient < Client
7
- # API endpoint for billing-related operations
8
- URI = "billing"
9
-
10
- # @param client [Faraday::Connection, nil] Optional Faraday client for custom configurations
11
- def initialize(client = nil)
12
- super(URI, client)
13
- end
14
-
15
- # Retrieves a list of billings
16
- #
17
- # @return [Array<Resources::Billing>] Array of Billing objects
18
- def list
19
- response = request("GET", "list")
20
- response.map { |data| Resources::Billing.new(data) }
21
- end
22
-
23
- # Creates a new billing
24
- #
25
- # @param data [Resources::Billing] The billing data to be sent for creation
26
- # @return [Resources::Billing] The created Billing object
27
- def create(data)
28
- request_data = {
29
- frequency: data.frequency,
30
- methods: data.methods,
31
- returnUrl: data.metadata&.return_url,
32
- completionUrl: data.metadata&.completion_url,
33
- products: data.products&.map { |product|
34
- {
35
- externalId: product.external_id,
36
- name: product.name,
37
- description: product.description,
38
- quantity: product.quantity,
39
- price: product.price
40
- }
41
- }
42
- }
43
-
44
- if data.customer&.id
45
- request_data[:customerId] = data.customer.id
46
- else
47
- request_data[:customer] = {
48
- name: data.customer&.metadata&.name,
49
- email: data.customer&.metadata&.email,
50
- cellphone: data.customer&.metadata&.cellphone,
51
- taxId: data.customer&.metadata&.tax_id
52
- }
53
- end
54
-
55
- response = request("POST", "create", json: request_data)
56
- Resources::Billing.new(response)
57
- end
58
- end
59
- end
60
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
-
5
- module AbacatePay
6
- module Clients
7
- # Client class for interacting with the AbacatePay API.
8
- #
9
- # This class handles API requests using Faraday and provides a way to manage
10
- # authentication and communication with the AbacatePay service.
11
- class Client
12
- # @param uri [String] The specific API endpoint to interact with
13
- # @param client [Faraday::Connection, nil] Optional Faraday client for custom configurations
14
- def initialize(uri, client = nil)
15
- @client = client || build_client(uri)
16
- end
17
-
18
- private
19
-
20
- # Sends an HTTP request to the API
21
- #
22
- # @param method [String] The HTTP method (e.g., GET, POST)
23
- # @param uri [String] The endpoint URI relative to the base URI
24
- # @param options [Hash] Optional settings and parameters for the request
25
- # @return [Hash] The response data
26
- # @raise [ApiError] If an error occurs during the request
27
- def request(method, uri, options = {})
28
- response = @client.public_send(method.downcase) do |req|
29
- req.url uri
30
- req.body = options[:json].to_json if options[:json]
31
- end
32
-
33
- JSON.parse(response.body).fetch("data")
34
- rescue Faraday::Error => e
35
- handle_request_error(e)
36
- rescue StandardError => e
37
- raise ApiError, "Unexpected error: #{e.message}"
38
- end
39
-
40
- # Builds a new Faraday client with default configuration
41
- #
42
- # @param uri [String] The endpoint URI
43
- # @return [Faraday::Connection] Configured Faraday client
44
- def build_client(uri)
45
- Faraday.new(
46
- url: "#{AbacatePay.configuration.api_url}/#{uri}/",
47
- headers: {
48
- "Content-Type" => "application/json",
49
- "Authorization" => "Bearer #{AbacatePay.configuration.api_token}"
50
- }
51
- )
52
- end
53
-
54
- # Handles API request errors
55
- #
56
- # @param error [Faraday::Error] The error to handle
57
- # @raise [ApiError] With appropriate error message
58
- def handle_request_error(error)
59
- error_message = if error.response&.body
60
- response_body = JSON.parse(error.response.body)
61
- response_body["message"] || response_body["error"]
62
- end
63
-
64
- raise ApiError, "Request error: #{error_message || error.message}"
65
- end
66
- end
67
- end
68
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AbacatePay
4
- module Clients
5
- # Client class for managing customer-related operations in the AbacatePay API.
6
- class CustomerClient < Client
7
- # API endpoint for customer-related operations
8
- URI = "customer"
9
-
10
- # @param client [Faraday::Connection, nil] Optional Faraday client for custom configurations
11
- def initialize(client = nil)
12
- super(URI, client)
13
- end
14
-
15
- # Retrieves a list of customers
16
- #
17
- # @return [Array<Resources::Customer>] Array of Customer objects
18
- def list
19
- response = request("GET", "list")
20
- response.map { |data| Resources::Customer.new(data) }
21
- end
22
-
23
- # Creates a new customer
24
- #
25
- # @param data [Resources::Customer] The customer data to be sent for creation
26
- # @return [Resources::Customer] The created Customer object
27
- def create(data)
28
- response = request("POST", "create", json: {
29
- name: data.metadata&.name,
30
- email: data.metadata&.email,
31
- cellphone: data.metadata&.cellphone,
32
- taxId: data.metadata&.tax_id
33
- })
34
-
35
- Resources::Customer.new(response)
36
- end
37
- end
38
- end
39
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "abacate_pay/clients/client"
4
- require "abacate_pay/clients/billing_client"
5
- require "abacate_pay/clients/customer_client"
6
-
7
- module AbacatePay
8
- # The Clients module contains all API client implementations
9
- # for interacting with the AbacatePay API endpoints.
10
- module Clients
11
- end
12
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AbacatePay
4
- # Configuration class for the AbacatePay SDK
5
- #
6
- # This class handles all configuration options for the SDK, including
7
- # API credentials, environment settings, and other customizable options.
8
- #
9
- # @api public
10
- class Configuration
11
- # @return [String] API token for authentication
12
- attr_accessor :api_token
13
-
14
- # @return [Symbol] Current environment (:production or :sandbox)
15
- attr_accessor :environment
16
-
17
- # @return [Integer] Request timeout in seconds
18
- attr_accessor :timeout
19
-
20
- # @return [String] Base API URL
21
- attr_reader :api_url
22
-
23
- # Initialize a new configuration with default values
24
- #
25
- # @api public
26
- def initialize
27
- @environment = :sandbox
28
- @timeout = 30
29
- @api_token = nil
30
- end
31
-
32
- # Validates the configuration
33
- #
34
- # @raise [ConfigurationError] if any required settings are missing or invalid
35
- # @return [void]
36
- #
37
- # @api public
38
- def validate!
39
- raise ConfigurationError, "API token is required" if api_token.nil?
40
- raise ConfigurationError, "Invalid environment" unless %i[production sandbox].include?(environment)
41
- end
42
-
43
- # Gets the base API URL based on the environment
44
- #
45
- # @return [String] The base API URL
46
- #
47
- # @api public
48
- def api_url
49
- if environment == :production
50
- "https://api.abacatepay.com/v1"
51
- else
52
- "https://sandbox.api.abacatepay.com/v1"
53
- end
54
- end
55
- end
56
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "abacate_pay/enums/billing/frequencies"
4
- require "abacate_pay/enums/billing/methods"
5
- require "abacate_pay/enums/billing/statuses"
6
-
7
- module AbacatePay
8
- # The Enums module contains all enumeration classes used
9
- # throughout the AbacatePay SDK.
10
- module Enums
11
- end
12
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "abacate_pay/resources/resource"
4
- require "abacate_pay/resources/billing"
5
- require "abacate_pay/resources/customer"
6
- require "abacate_pay/resources/billing/metadata"
7
- require "abacate_pay/resources/billing/product"
8
- require "abacate_pay/resources/customer/metadata"
9
-
10
- module AbacatePay
11
- # The Resources module contains all resource classes that
12
- # represent the various entities in the AbacatePay system.
13
- module Resources
14
- end
15
- end
@@ -1,6 +0,0 @@
1
- module Abacatepay
2
- module Rails
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
- end
6
- end