abacatepay-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ec476ed39de31a64c6de7517af308b971922f06a8a554de6764ea4992052b641
4
+ data.tar.gz: cf82e3363dfa431419b29b120fcabddb671d91e3789ec90880dd131b46a08684
5
+ SHA512:
6
+ metadata.gz: 84f338ecbd8a318c44987d7417579f812b5002c66eb04929e59511b61a4de9a378df861449ce98d7d24753cf4ef8bd373886b6ce602fd53c500bcca5f5254274
7
+ data.tar.gz: 7e87dd6972d35d967bb1cece1e825579f96a26b0da3f624ead50734195bcf15c193674a5c0e6cbffd1e167ea28a8ee2fb63f6d78ec4151633ed4037445b0825d
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
File without changes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-12-11
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mathuscardoso@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 user-matth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # AbacatePay SDK for Ruby on Rails
2
+
3
+ ## 💻 Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'abacatepay-ruby'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ ```bash
14
+ bundle install
15
+ ```
16
+
17
+ Or install it yourself as:
18
+
19
+ ```bash
20
+ gem install abacatepay-ruby
21
+ ```
22
+
23
+ ## 🔧 Configuration
24
+
25
+ Configure your API token and environment in an initializer:
26
+
27
+ ```ruby
28
+ # config/initializers/abacatepay.rb
29
+ AbacatePay.configure do |config|
30
+ config.api_token = ENV['ABACATEPAY_TOKEN']
31
+ config.environment = :sandbox # or :production
32
+ end
33
+ ```
34
+
35
+ ## 🌟 Resources
36
+
37
+ ### Billing
38
+
39
+ **Initialize the Billing Client**
40
+
41
+ ```ruby
42
+ billing_client = AbacatePay::Clients::BillingClient.new
43
+ ```
44
+
45
+ **List Billings**
46
+
47
+ Retrieve a list of all billings:
48
+
49
+ ```ruby
50
+ billing_client.list
51
+ ```
52
+
53
+ **Create a Billing**
54
+
55
+ To create a billing, use the following code:
56
+
57
+ ```ruby
58
+ billing_client.create(
59
+ AbacatePay::Resources::Billing.new(
60
+ frequency: AbacatePay::Enums::Billing::Frequencies::ONE_TIME,
61
+ methods: [AbacatePay::Enums::Billing::Methods::PIX],
62
+ products: [
63
+ AbacatePay::Resources::Billing::Product.new(
64
+ external_id: 'abc_123',
65
+ name: 'Product A',
66
+ description: 'Description of product A',
67
+ quantity: 1,
68
+ price: 100 # Price in cents
69
+ )
70
+ ],
71
+ metadata: AbacatePay::Resources::Billing::Metadata.new(
72
+ return_url: 'https://www.abacatepay.com',
73
+ completion_url: 'https://www.abacatepay.com'
74
+ ),
75
+ customer: AbacatePay::Resources::Customer.new(
76
+ metadata: AbacatePay::Resources::Customer::Metadata.new(
77
+ name: 'Abacate Lover',
78
+ cellphone: '01912341234',
79
+ email: 'lover@abacate.com',
80
+ tax_id: '13827826837'
81
+ )
82
+ )
83
+ )
84
+ )
85
+ ```
86
+
87
+ Alternatively, you can use a previously created customer by specifying their ID:
88
+
89
+ ```ruby
90
+ AbacatePay::Resources::Customer.new(
91
+ id: 'cust_DEbpqcN...'
92
+ )
93
+ ```
94
+
95
+ ### Customer
96
+
97
+ **Initialize the Customer Client**
98
+
99
+ ```ruby
100
+ customer_client = AbacatePay::Clients::CustomerClient.new
101
+ ```
102
+
103
+ **List Customers**
104
+
105
+ Retrieve a list of all customers:
106
+
107
+ ```ruby
108
+ customer_client.list
109
+ ```
110
+
111
+ **Create a Customer**
112
+
113
+ To create a customer, use the following code:
114
+
115
+ ```ruby
116
+ customer_client.create(
117
+ AbacatePay::Resources::Customer.new(
118
+ metadata: AbacatePay::Resources::Customer::Metadata.new(
119
+ name: 'Abacate Lover',
120
+ cellphone: '01912341234',
121
+ email: 'lover@abacate.com',
122
+ tax_id: '13827826837'
123
+ )
124
+ )
125
+ )
126
+ ```
127
+
128
+ ## 📚 Documentation
129
+
130
+ For detailed information about the API and SDK, refer to the official documentation:
131
+ https://abacatepay.readme.io/reference
132
+
133
+ ## 🤝 Contribution
134
+
135
+ Contributions are welcome! If you wish to contribute:
136
+
137
+ 1. Fork the repository
138
+ 2. Create a new branch for your feature or fix:
139
+
140
+ ```bash
141
+ git checkout -b feature/your-feature-name
142
+ ```
143
+
144
+ 3. Make your changes and commit them:
145
+
146
+ ```bash
147
+ git commit -m "Add your detailed commit message here"
148
+ ```
149
+
150
+ 4. Push to your branch:
151
+
152
+ ```bash
153
+ git push origin feature/your-feature-name
154
+ ```
155
+
156
+ 5. Open a pull request with a clear description of your changes
157
+
158
+ Please ensure your code:
159
+
160
+ - Includes proper documentation
161
+ - Follows Ruby style guidelines
162
+ - Includes appropriate tests
163
+ - Passes all existing tests (bundle exec rspec)
164
+ - Passes code style checks (bundle exec rubocop)
165
+
166
+ ### Happy coding! 🚀
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/abacatepay/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "abacatepay-ruby"
7
+ spec.version = AbacatePay::VERSION
8
+ spec.authors = ["Matheus Cardoso"]
9
+ spec.email = ["mathuscardoso@gmail.com"]
10
+
11
+ spec.summary = "AbacatePay Ruby on Rails SDK for you to start receiving payments in seconds"
12
+ spec.description = "The easiest way to integrate your Ruby on Rails SDK base code to AbacatePay Gateway with support to coroutines."
13
+ spec.homepage = "https://www.abacatepay.com/"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "https://github.com/AbacatePay/abacatepay-ruby-sdk"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/AbacatePay/abacatepay-ruby-sdk"
21
+ spec.metadata["changelog_uri"] = "https://github.com/AbacatePay/abacatepay-ruby-sdk/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (File.expand_path(f) == __FILE__) ||
28
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
29
+ end
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ # Runtime dependencies
36
+ spec.add_dependency "rails", "~> 7.0", ">= 7.0.0"
37
+ spec.add_dependency "faraday", "~> 2.9"
38
+
39
+ # Development dependencies
40
+ spec.add_development_dependency "rspec-rails", "~> 6.0"
41
+ spec.add_development_dependency "rubocop", "~> 1.57"
42
+ spec.add_development_dependency "rubocop-rails", "~> 2.22"
43
+ spec.add_development_dependency "rubocop-rspec", "~> 2.25"
44
+ spec.add_development_dependency "simplecov", "~> 0.22"
45
+
46
+ # For more information and examples about making a new gem, check out our
47
+ # guide at: https://bundler.io/guides/creating_gem.html
48
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "abacate_pay/version"
4
+ require "abacate_pay/configuration"
5
+
6
+ # Main module for AbacatePay SDK integration
7
+ module AbacatePay
8
+ class Error < StandardError; end
9
+ class ConfigurationError < Error; end
10
+ class ApiError < Error; end
11
+
12
+ class << self
13
+ # Gets or sets the global configuration
14
+ attr_accessor :configuration
15
+ end
16
+
17
+ # Configures the SDK
18
+ #
19
+ # @example
20
+ # AbacatePay.configure do |config|
21
+ # config.api_token = "your-token-here"
22
+ # config.environment = :sandbox
23
+ # end
24
+ #
25
+ # @yield [config] Configuration object
26
+ # @return [void]
27
+ def self.configure
28
+ self.configuration ||= Configuration.new
29
+ yield(configuration)
30
+ configuration.validate!
31
+ end
32
+
33
+ # Resets the configuration to defaults
34
+ #
35
+ # @return [void]
36
+ def self.reset!
37
+ self.configuration = Configuration.new
38
+ end
39
+ end
40
+
41
+ # Autoload all components
42
+ Dir[File.join(__dir__, "abacate_pay", "**", "*.rb")].sort.each { |file| require file }
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,68 @@
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
@@ -0,0 +1,39 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,56 @@
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
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Billing
6
+ # Enumeration defining billing frequencies.
7
+ #
8
+ # This enumeration is used to categorize different payment or billing frequencies.
9
+ class Frequencies
10
+ # One-time billing.
11
+ # @return [String] Represents a billing that occurs only once
12
+ ONE_TIME = "ONE_TIME"
13
+
14
+ # Gets all valid frequency values
15
+ # @return [Array<String>] List of all valid frequencies
16
+ def self.values
17
+ [ONE_TIME]
18
+ end
19
+
20
+ # Validates if a given value is a valid frequency
21
+ # @param value [String] The value to validate
22
+ # @return [Boolean] true if valid, false otherwise
23
+ def self.valid?(value)
24
+ values.include?(value)
25
+ end
26
+
27
+ # Validates and returns the value if valid
28
+ # @param value [String] The value to validate
29
+ # @return [String] The validated value
30
+ # @raise [ArgumentError] if value is invalid
31
+ def self.validate!(value)
32
+ raise ArgumentError, "Invalid frequency: #{value}" unless valid?(value)
33
+ value
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end