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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AbacatePay
4
4
  module Enums
5
- module Billing
5
+ module Billings
6
6
  # Enumeration defining billing methods.
7
7
  #
8
8
  # This enumeration is used to represent different payment methods available for billing.
@@ -11,10 +11,18 @@ module AbacatePay
11
11
  # @return [String] Represents the PIX payment method, a popular instant payment system in Brazil
12
12
  PIX = "PIX"
13
13
 
14
+ # @return [String] Credit card payment
15
+ CARD = "CARD"
16
+
17
+ # Boleto bancário. Supports a due date and late-payment interest/fine —
18
+ # see Resources::Checkouts#due_date, #interest and #fine.
19
+ # @return [String] Boleto payment method
20
+ BOLETO = "BOLETO"
21
+
14
22
  # Gets all valid method values
15
23
  # @return [Array<String>] List of all valid payment methods
16
24
  def self.values
17
- [PIX]
25
+ [PIX, CARD, BOLETO]
18
26
  end
19
27
 
20
28
  # Validates if a given value is a valid method
@@ -30,9 +38,10 @@ module AbacatePay
30
38
  # @raise [ArgumentError] if value is invalid
31
39
  def self.validate!(value)
32
40
  raise ArgumentError, "Invalid payment method: #{value}" unless valid?(value)
41
+
33
42
  value
34
43
  end
35
44
  end
36
45
  end
37
46
  end
38
- end
47
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AbacatePay
4
4
  module Enums
5
- module Billing
5
+ module Billings
6
6
  # Enumeration defining billing statuses.
7
7
  #
8
8
  # This enumeration is used to represent the various statuses that a billing process can have.
@@ -46,9 +46,10 @@ module AbacatePay
46
46
  # @raise [ArgumentError] if value is invalid
47
47
  def self.validate!(value)
48
48
  raise ArgumentError, "Invalid status: #{value}" unless valid?(value)
49
+
49
50
  value
50
51
  end
51
52
  end
52
53
  end
53
54
  end
54
- end
55
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Checkouts
6
+ class Statuses
7
+ PENDING = "PENDING"
8
+ EXPIRED = "EXPIRED"
9
+ CANCELLED = "CANCELLED"
10
+ PAID = "PAID"
11
+ REFUNDED = "REFUNDED"
12
+
13
+ def self.values
14
+ [PENDING, EXPIRED, CANCELLED, PAID, REFUNDED]
15
+ end
16
+
17
+ def self.valid?(value)
18
+ values.include?(value)
19
+ end
20
+
21
+ def self.validate!(value)
22
+ raise ArgumentError, "Invalid checkout status: #{value}" unless valid?(value)
23
+
24
+ value
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Coupons
6
+ class DiscountKinds
7
+ PERCENTAGE = "PERCENTAGE"
8
+ FIXED = "FIXED"
9
+
10
+ def self.values
11
+ [PERCENTAGE, FIXED]
12
+ end
13
+
14
+ def self.valid?(value)
15
+ values.include?(value)
16
+ end
17
+
18
+ def self.validate!(value)
19
+ raise ArgumentError, "Invalid discount kind: #{value}" unless valid?(value)
20
+
21
+ value
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Coupons
6
+ class Statuses
7
+ ACTIVE = "ACTIVE"
8
+ INACTIVE = "INACTIVE"
9
+ EXPIRED = "EXPIRED"
10
+
11
+ def self.values
12
+ [ACTIVE, INACTIVE, EXPIRED]
13
+ end
14
+
15
+ def self.valid?(value)
16
+ values.include?(value)
17
+ end
18
+
19
+ def self.validate!(value)
20
+ raise ArgumentError, "Invalid coupon status: #{value}" unless valid?(value)
21
+
22
+ value
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Payouts
6
+ class Statuses
7
+ PENDING = "PENDING"
8
+ COMPLETE = "COMPLETE"
9
+ CANCELLED = "CANCELLED"
10
+ EXPIRED = "EXPIRED"
11
+ REFUNDED = "REFUNDED"
12
+
13
+ def self.values
14
+ [PENDING, COMPLETE, CANCELLED, EXPIRED, REFUNDED]
15
+ end
16
+
17
+ def self.valid?(value)
18
+ values.include?(value)
19
+ end
20
+
21
+ def self.validate!(value)
22
+ raise ArgumentError, "Invalid payout status: #{value}" unless valid?(value)
23
+
24
+ value
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Pix
6
+ class KeyTypes
7
+ CPF = "CPF"
8
+ CNPJ = "CNPJ"
9
+ PHONE = "PHONE"
10
+ EMAIL = "EMAIL"
11
+ RANDOM = "RANDOM"
12
+ BR_CODE = "BR_CODE"
13
+
14
+ def self.values
15
+ [CPF, CNPJ, PHONE, EMAIL, RANDOM, BR_CODE]
16
+ end
17
+
18
+ def self.valid?(value)
19
+ values.include?(value)
20
+ end
21
+
22
+ def self.validate!(value)
23
+ raise ArgumentError, "Invalid PIX key type: #{value}" unless valid?(value)
24
+
25
+ value
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Products
6
+ class Cycles
7
+ WEEKLY = "WEEKLY"
8
+ MONTHLY = "MONTHLY"
9
+ SEMIANNUALLY = "SEMIANNUALLY"
10
+ ANNUALLY = "ANNUALLY"
11
+
12
+ def self.values
13
+ [WEEKLY, MONTHLY, SEMIANNUALLY, ANNUALLY]
14
+ end
15
+
16
+ def self.valid?(value)
17
+ values.include?(value)
18
+ end
19
+
20
+ def self.validate!(value)
21
+ raise ArgumentError, "Invalid product cycle: #{value}" unless valid?(value)
22
+
23
+ value
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Transfers
6
+ class Statuses
7
+ PENDING = "PENDING"
8
+ COMPLETE = "COMPLETE"
9
+ CANCELLED = "CANCELLED"
10
+ EXPIRED = "EXPIRED"
11
+ REFUNDED = "REFUNDED"
12
+ FAILED = "FAILED"
13
+
14
+ def self.values
15
+ [PENDING, COMPLETE, CANCELLED, EXPIRED, REFUNDED, FAILED]
16
+ end
17
+
18
+ def self.valid?(value)
19
+ values.include?(value)
20
+ end
21
+
22
+ def self.validate!(value)
23
+ raise ArgumentError, "Invalid transfer status: #{value}" unless valid?(value)
24
+
25
+ value
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Enums
5
+ module Webhooks
6
+ class EventTypes
7
+ CHECKOUT_COMPLETED = "checkout.completed"
8
+ CHECKOUT_REFUNDED = "checkout.refunded"
9
+ CHECKOUT_DISPUTED = "checkout.disputed"
10
+ TRANSPARENT_COMPLETED = "transparent.completed"
11
+ TRANSPARENT_REFUNDED = "transparent.refunded"
12
+ TRANSPARENT_DISPUTED = "transparent.disputed"
13
+ SUBSCRIPTION_COMPLETED = "subscription.completed"
14
+ SUBSCRIPTION_RENEWED = "subscription.renewed"
15
+ SUBSCRIPTION_CANCELLED = "subscription.cancelled"
16
+
17
+ # Recurring charge failed — the dunning signal. Without handling this,
18
+ # a failing subscription looks identical to a healthy one.
19
+ SUBSCRIPTION_PAYMENT_FAILED = "subscription.payment_failed"
20
+
21
+ SUBSCRIPTION_TRIAL_STARTED = "subscription.trial_started"
22
+ TRANSFER_COMPLETED = "transfer.completed"
23
+ TRANSFER_FAILED = "transfer.failed"
24
+ PAYOUT_COMPLETED = "payout.completed"
25
+ PAYOUT_FAILED = "payout.failed"
26
+
27
+ def self.values
28
+ [
29
+ CHECKOUT_COMPLETED, CHECKOUT_REFUNDED, CHECKOUT_DISPUTED,
30
+ TRANSPARENT_COMPLETED, TRANSPARENT_REFUNDED, TRANSPARENT_DISPUTED,
31
+ SUBSCRIPTION_COMPLETED, SUBSCRIPTION_RENEWED, SUBSCRIPTION_CANCELLED,
32
+ SUBSCRIPTION_PAYMENT_FAILED, SUBSCRIPTION_TRIAL_STARTED,
33
+ TRANSFER_COMPLETED, TRANSFER_FAILED,
34
+ PAYOUT_COMPLETED, PAYOUT_FAILED
35
+ ]
36
+ end
37
+
38
+ def self.valid?(value)
39
+ values.include?(value)
40
+ end
41
+
42
+ def self.validate!(value)
43
+ raise ArgumentError, "Invalid webhook event type: #{value}" unless valid?(value)
44
+
45
+ value
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "abacate_pay/enums/billings/frequencies"
4
+ require "abacate_pay/enums/billings/methods"
5
+ require "abacate_pay/enums/billings/statuses"
6
+ require "abacate_pay/enums/checkouts/statuses"
7
+ require "abacate_pay/enums/coupons/discount_kinds"
8
+ require "abacate_pay/enums/coupons/statuses"
9
+ require "abacate_pay/enums/payouts/statuses"
10
+ require "abacate_pay/enums/pix/key_types"
11
+ require "abacate_pay/enums/products/cycles"
12
+ require "abacate_pay/enums/transfers/statuses"
13
+ require "abacate_pay/enums/webhooks/event_types"
14
+
15
+ module AbacatePay
16
+ # The Enums module contains all enumeration classes used
17
+ # throughout the AbacatePay SDK.
18
+ module Enums
19
+ end
20
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AbacatePay
4
4
  module Resources
5
- module Billing
5
+ class Billings
6
6
  # Represents metadata for a billing resource in the AbacatePay system.
7
7
  #
8
8
  # This class contains additional information related to a billing resource,
@@ -23,13 +23,7 @@ module AbacatePay
23
23
  def initialize(data)
24
24
  fill(data)
25
25
  end
26
-
27
- protected
28
-
29
- def to_hash
30
- super
31
- end
32
26
  end
33
27
  end
34
28
  end
35
- end
29
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AbacatePay
4
4
  module Resources
5
- module Billing
5
+ class Billings
6
6
  # Represents a product in a billing resource in the AbacatePay system.
7
7
  #
8
8
  # This class contains information about a product, such as its identifier,
@@ -32,13 +32,7 @@ module AbacatePay
32
32
  def initialize(data)
33
33
  fill(data)
34
34
  end
35
-
36
- protected
37
-
38
- def to_hash
39
- super
40
- end
41
35
  end
42
36
  end
43
37
  end
44
- end
38
+ end
@@ -1,27 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "abacate_pay/resources/billing/metadata"
4
- require "abacate_pay/resources/billing/product"
5
-
6
3
  module AbacatePay
7
4
  module Resources
8
5
  # Represents a billing resource in the AbacatePay payment system.
9
6
  #
10
7
  # Manages billing-related data including payment methods, products, scheduling,
11
8
  # and customer information for recurring and one-time payments.
12
- class Billing < Resource
9
+ class Billings < Resource
13
10
  # Maps property names to their corresponding resource classes
14
11
  RESOURCE_PROPERTIES = {
15
- metadata: 'AbacatePay::Resources::Billing::Metadata',
16
- customer: 'AbacatePay::Resources::Customer',
17
- products: 'AbacatePay::Resources::Billing::Product'
12
+ metadata: "AbacatePay::Resources::Billings::Metadata",
13
+ customer: "AbacatePay::Resources::Customers",
14
+ products: "AbacatePay::Resources::Billings::Product"
18
15
  }.freeze
19
16
 
20
17
  # Maps property names to their corresponding enum classes
21
18
  ENUM_PROPERTIES = {
22
- status: 'AbacatePay::Enums::Billing::Statuses',
23
- frequency: 'AbacatePay::Enums::Billing::Frequencies',
24
- methods: 'AbacatePay::Enums::Billing::Methods'
19
+ status: "AbacatePay::Enums::Billings::Statuses",
20
+ frequency: "AbacatePay::Enums::Billings::Frequencies",
21
+ methods: "AbacatePay::Enums::Billings::Methods"
25
22
  }.freeze
26
23
 
27
24
  # Properties that should be handled as DateTime objects
@@ -86,7 +83,7 @@ module AbacatePay
86
83
  # @return [Object] The processed value
87
84
  def process_enum_value(property, value)
88
85
  enum_class = Object.const_get(ENUM_PROPERTIES[property.to_sym])
89
-
86
+
90
87
  if value.is_a?(Array)
91
88
  value.map { |item| initialize_enum(enum_class, item) }
92
89
  else
@@ -101,8 +98,8 @@ module AbacatePay
101
98
  # @return [Object] The processed value
102
99
  def process_resource_value(property, value)
103
100
  resource_class = Object.const_get(RESOURCE_PROPERTIES[property.to_sym])
104
-
105
- if property.to_s == 'products' && value.is_a?(Array)
101
+
102
+ if property.to_s == "products" && value.is_a?(Array)
106
103
  value.map { |item| initialize_resource(resource_class, item) }
107
104
  else
108
105
  initialize_resource(resource_class, value)
@@ -113,8 +110,11 @@ module AbacatePay
113
110
 
114
111
  # @!visibility private
115
112
  attr_writer :id, :account_id, :url, :methods, :products,
116
- :dev_mode, :amount, :metadata, :frequency, :status,
117
- :customer, :next_billing, :created_at, :updated_at
113
+ :dev_mode, :amount, :metadata, :frequency, :status,
114
+ :customer, :next_billing, :created_at, :updated_at
118
115
  end
119
116
  end
120
- end
117
+ end
118
+
119
+ require "abacate_pay/resources/billings/metadata"
120
+ require "abacate_pay/resources/billings/product"
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents a checkout session in the AbacatePay system.
6
+ class Checkouts < Resource
7
+ RESOURCE_PROPERTIES = {
8
+ metadata: "AbacatePay::Resources::Billings::Metadata",
9
+ customer: "AbacatePay::Resources::Customers",
10
+ products: "AbacatePay::Resources::Billings::Product"
11
+ }.freeze
12
+
13
+ ENUM_PROPERTIES = {
14
+ status: "AbacatePay::Enums::Checkouts::Statuses",
15
+ frequency: "AbacatePay::Enums::Billings::Frequencies",
16
+ methods: "AbacatePay::Enums::Billings::Methods"
17
+ }.freeze
18
+
19
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
20
+
21
+ attr_reader :id, :url, :amount, :status, :dev_mode, :methods,
22
+ :products, :metadata, :customer, :coupons, :external_id,
23
+ :frequency, :created_at, :updated_at,
24
+ # BOLETO-only: due date (YYYY-MM-DD) plus late-payment charges.
25
+ :due_date, :interest, :fine,
26
+ # CARD-only: maximum number of instalments offered.
27
+ :max_installments,
28
+ # Order bump shown at checkout, and free-form merchant data.
29
+ :up_sell_product_id, :custom_metadata
30
+
31
+ def initialize(data)
32
+ fill(data)
33
+ end
34
+
35
+ def dev_mode?
36
+ @dev_mode
37
+ end
38
+
39
+ private
40
+
41
+ def process_value(property, value)
42
+ return nil if value.nil?
43
+
44
+ if DATETIME_PROPERTIES.include?(property)
45
+ initialize_date_time(value)
46
+ elsif ENUM_PROPERTIES.key?(property.to_sym)
47
+ process_enum_value(property, value)
48
+ elsif RESOURCE_PROPERTIES.key?(property.to_sym)
49
+ process_resource_value(property, value)
50
+ else
51
+ value
52
+ end
53
+ end
54
+
55
+ def process_enum_value(property, value)
56
+ enum_class = Object.const_get(ENUM_PROPERTIES[property.to_sym])
57
+
58
+ if value.is_a?(Array)
59
+ value.map { |item| initialize_enum(enum_class, item) }
60
+ else
61
+ initialize_enum(enum_class, value)
62
+ end
63
+ end
64
+
65
+ def process_resource_value(property, value)
66
+ resource_class = Object.const_get(RESOURCE_PROPERTIES[property.to_sym])
67
+
68
+ if property.to_s == "products" && value.is_a?(Array)
69
+ value.map { |item| initialize_resource(resource_class, item) }
70
+ else
71
+ initialize_resource(resource_class, value)
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ attr_writer :id, :url, :amount, :status, :dev_mode, :methods,
78
+ :products, :metadata, :customer, :coupons, :external_id,
79
+ :frequency, :created_at, :updated_at,
80
+ :due_date, :interest, :fine, :max_installments,
81
+ :up_sell_product_id, :custom_metadata
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents a discount coupon in the AbacatePay system.
6
+ class Coupons < Resource
7
+ ENUM_PROPERTIES = {
8
+ status: "AbacatePay::Enums::Coupons::Statuses",
9
+ discount_kind: "AbacatePay::Enums::Coupons::DiscountKinds"
10
+ }.freeze
11
+
12
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
13
+
14
+ attr_reader :id, :code, :discount, :discount_kind, :max_redeems,
15
+ :current_redeems, :status, :created_at, :updated_at
16
+
17
+ def initialize(data)
18
+ fill(data)
19
+ end
20
+
21
+ private
22
+
23
+ def process_value(property, value)
24
+ return nil if value.nil?
25
+
26
+ if DATETIME_PROPERTIES.include?(property)
27
+ initialize_date_time(value)
28
+ elsif ENUM_PROPERTIES.key?(property.to_sym)
29
+ initialize_enum(Object.const_get(ENUM_PROPERTIES[property.to_sym]), value)
30
+ else
31
+ value
32
+ end
33
+ end
34
+
35
+ protected
36
+
37
+ attr_writer :id, :code, :discount, :discount_kind, :max_redeems,
38
+ :current_redeems, :status, :created_at, :updated_at
39
+ end
40
+ end
41
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AbacatePay
4
4
  module Resources
5
- module Customer
5
+ class Customers
6
6
  # Represents metadata for a customer in the AbacatePay system.
7
7
  #
8
8
  # This class contains additional information about a customer, such as their name,
@@ -26,13 +26,7 @@ module AbacatePay
26
26
  def initialize(data)
27
27
  fill(data)
28
28
  end
29
-
30
- protected
31
-
32
- def to_hash
33
- super
34
- end
35
29
  end
36
30
  end
37
31
  end
38
- end
32
+ end
@@ -1,17 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "abacate_pay/resources/customer/metadata"
4
-
5
3
  module AbacatePay
6
4
  module Resources
7
5
  # Represents a customer resource in the AbacatePay payment system.
8
6
  #
9
7
  # This class handles customer data including identification and metadata,
10
8
  # providing a structured way to manage customer information within the system.
11
- class Customer < Resource
9
+ class Customers < Resource
12
10
  # Maps property names to their corresponding resource classes
13
11
  RESOURCE_PROPERTIES = {
14
- metadata: 'AbacatePay::Resources::Customer::Metadata'
12
+ metadata: "AbacatePay::Resources::Customers::Metadata"
15
13
  }.freeze
16
14
 
17
15
  # @return [String, nil] The unique identifier for the customer
@@ -54,4 +52,6 @@ module AbacatePay
54
52
  attr_writer :id, :metadata
55
53
  end
56
54
  end
57
- end
55
+ end
56
+
57
+ require "abacate_pay/resources/customers/metadata"
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents a payout (withdrawal) in the AbacatePay system.
6
+ class Payouts < Resource
7
+ ENUM_PROPERTIES = {
8
+ status: "AbacatePay::Enums::Payouts::Statuses"
9
+ }.freeze
10
+
11
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
12
+
13
+ attr_reader :id, :amount, :external_id, :description,
14
+ :status, :created_at, :updated_at
15
+
16
+ def initialize(data)
17
+ fill(data)
18
+ end
19
+
20
+ private
21
+
22
+ def process_value(property, value)
23
+ return nil if value.nil?
24
+
25
+ if DATETIME_PROPERTIES.include?(property)
26
+ initialize_date_time(value)
27
+ elsif ENUM_PROPERTIES.key?(property.to_sym)
28
+ initialize_enum(Object.const_get(ENUM_PROPERTIES[property.to_sym]), value)
29
+ else
30
+ value
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ attr_writer :id, :amount, :external_id, :description,
37
+ :status, :created_at, :updated_at
38
+ end
39
+ end
40
+ end