abacatepay-ruby 0.1.0 → 1.0.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +125 -0
  3. data/CHANGELOG.md +121 -1
  4. data/README.md +408 -87
  5. data/Rakefile +1 -1
  6. data/abacatepay-ruby.gemspec +16 -10
  7. data/lib/abacate_pay/clients/billing_client.rb +80 -0
  8. data/lib/abacate_pay/clients/checkout_client.rb +70 -0
  9. data/lib/{abacatepay → abacate_pay}/clients/client.rb +20 -7
  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 +55 -0
  18. data/lib/abacate_pay/clients/transparent_client.rb +73 -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/configuration.rb +67 -0
  22. data/lib/{abacatepay/enums/billing → abacate_pay/enums/billings}/frequencies.rb +9 -3
  23. data/lib/{abacatepay/enums/billing → abacate_pay/enums/billings}/methods.rb +5 -3
  24. data/lib/{abacatepay/enums/billing → abacate_pay/enums/billings}/statuses.rb +3 -2
  25. data/lib/abacate_pay/enums/checkouts/statuses.rb +29 -0
  26. data/lib/abacate_pay/enums/coupons/discount_kinds.rb +26 -0
  27. data/lib/abacate_pay/enums/coupons/statuses.rb +27 -0
  28. data/lib/abacate_pay/enums/payouts/statuses.rb +29 -0
  29. data/lib/abacate_pay/enums/pix/key_types.rb +30 -0
  30. data/lib/abacate_pay/enums/products/cycles.rb +28 -0
  31. data/lib/abacate_pay/enums/transfers/statuses.rb +30 -0
  32. data/lib/abacate_pay/enums/webhooks/event_types.rb +43 -0
  33. data/lib/abacate_pay/enums.rb +20 -0
  34. data/lib/{abacatepay/resources/billing → abacate_pay/resources/billings}/metadata.rb +2 -8
  35. data/lib/{abacatepay/resources/billing → abacate_pay/resources/billings}/product.rb +2 -8
  36. data/lib/{abacatepay/resources/billing.rb → abacate_pay/resources/billings.rb} +16 -16
  37. data/lib/abacate_pay/resources/checkouts.rb +76 -0
  38. data/lib/abacate_pay/resources/coupons.rb +41 -0
  39. data/lib/{abacatepay/resources/customer → abacate_pay/resources/customers}/metadata.rb +2 -8
  40. data/lib/{abacatepay/resources/customer.rb → abacate_pay/resources/customers.rb} +5 -5
  41. data/lib/abacate_pay/resources/payouts.rb +40 -0
  42. data/lib/abacate_pay/resources/pix_transfers.rb +41 -0
  43. data/lib/abacate_pay/resources/products.rb +40 -0
  44. data/lib/{abacatepay → abacate_pay}/resources/resource.rb +33 -21
  45. data/lib/abacate_pay/resources/store/balance.rb +20 -0
  46. data/lib/abacate_pay/resources/store.rb +36 -0
  47. data/lib/abacate_pay/resources/subscriptions.rb +72 -0
  48. data/lib/abacate_pay/resources/transparents.rb +46 -0
  49. data/lib/abacate_pay/resources/webhook_endpoints.rb +49 -0
  50. data/lib/abacate_pay/resources.rb +27 -0
  51. data/lib/{abacatepay → abacate_pay}/version.rb +2 -2
  52. data/lib/abacate_pay/webhooks/event.rb +20 -0
  53. data/lib/abacate_pay/webhooks.rb +100 -0
  54. data/lib/abacate_pay.rb +111 -4
  55. metadata +69 -56
  56. data/lib/abacatepay/clients/billing_client.rb +0 -60
  57. data/lib/abacatepay/clients/customer_client.rb +0 -39
  58. data/lib/abacatepay/clients.rb +0 -12
  59. data/lib/abacatepay/configuration.rb +0 -56
  60. data/lib/abacatepay/enums.rb +0 -12
  61. data/lib/abacatepay/resources.rb +0 -15
  62. data/sig/abacatepay/rails.rbs +0 -6
@@ -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,76 @@
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
+
25
+ def initialize(data)
26
+ fill(data)
27
+ end
28
+
29
+ def dev_mode?
30
+ @dev_mode
31
+ end
32
+
33
+ private
34
+
35
+ def process_value(property, value)
36
+ return nil if value.nil?
37
+
38
+ if DATETIME_PROPERTIES.include?(property)
39
+ initialize_date_time(value)
40
+ elsif ENUM_PROPERTIES.key?(property.to_sym)
41
+ process_enum_value(property, value)
42
+ elsif RESOURCE_PROPERTIES.key?(property.to_sym)
43
+ process_resource_value(property, value)
44
+ else
45
+ value
46
+ end
47
+ end
48
+
49
+ def process_enum_value(property, value)
50
+ enum_class = Object.const_get(ENUM_PROPERTIES[property.to_sym])
51
+
52
+ if value.is_a?(Array)
53
+ value.map { |item| initialize_enum(enum_class, item) }
54
+ else
55
+ initialize_enum(enum_class, value)
56
+ end
57
+ end
58
+
59
+ def process_resource_value(property, value)
60
+ resource_class = Object.const_get(RESOURCE_PROPERTIES[property.to_sym])
61
+
62
+ if property.to_s == "products" && value.is_a?(Array)
63
+ value.map { |item| initialize_resource(resource_class, item) }
64
+ else
65
+ initialize_resource(resource_class, value)
66
+ end
67
+ end
68
+
69
+ protected
70
+
71
+ attr_writer :id, :url, :amount, :status, :dev_mode, :methods,
72
+ :products, :metadata, :customer, :coupons, :external_id,
73
+ :frequency, :created_at, :updated_at
74
+ end
75
+ end
76
+ 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
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents an outbound PIX transfer in the AbacatePay system.
6
+ class PixTransfers < Resource
7
+ ENUM_PROPERTIES = {
8
+ status: "AbacatePay::Enums::Transfers::Statuses",
9
+ key_type: "AbacatePay::Enums::Pix::KeyTypes"
10
+ }.freeze
11
+
12
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
13
+
14
+ attr_reader :id, :amount, :external_id, :description,
15
+ :key, :key_type, :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, :amount, :external_id, :description,
38
+ :key, :key_type, :status, :created_at, :updated_at
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents a catalogue product in the AbacatePay system.
6
+ class Products < Resource
7
+ ENUM_PROPERTIES = {
8
+ cycle: "AbacatePay::Enums::Products::Cycles"
9
+ }.freeze
10
+
11
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
12
+
13
+ attr_reader :id, :external_id, :name, :price, :currency,
14
+ :description, :image_url, :cycle, :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, :external_id, :name, :price, :currency,
37
+ :description, :image_url, :cycle, :created_at, :updated_at
38
+ end
39
+ end
40
+ end
@@ -12,8 +12,9 @@ module AbacatePay
12
12
  # @return [DateTime, nil] The initialized DateTime object or nil
13
13
  # @raise [ArgumentError] If the value is invalid
14
14
  def initialize_date_time(value)
15
- return nil if value.nil? || value.empty?
15
+ return nil if value.nil?
16
16
  return value.clone if value.is_a?(DateTime)
17
+ return nil if value.empty?
17
18
 
18
19
  DateTime.parse(value)
19
20
  rescue Date::Error
@@ -28,7 +29,7 @@ module AbacatePay
28
29
  # @raise [ArgumentError] If the value is invalid
29
30
  def initialize_enum(enum_class, value)
30
31
  return nil if value.nil? || value.empty?
31
-
32
+
32
33
  enum_class.validate!(value)
33
34
  end
34
35
 
@@ -39,8 +40,9 @@ module AbacatePay
39
40
  # @return [Object, nil] The initialized resource or nil
40
41
  # @raise [ArgumentError] If the value is invalid
41
42
  def initialize_resource(resource_class, value)
42
- return nil if value.nil? || value.empty?
43
+ return nil if value.nil?
43
44
  return value.clone if value.is_a?(resource_class)
45
+ return nil if value.respond_to?(:empty?) && value.empty?
44
46
 
45
47
  unless value.is_a?(Hash)
46
48
  raise ArgumentError, "Invalid resource value. Expected Hash or #{resource_class}, got #{value.class}"
@@ -49,6 +51,16 @@ module AbacatePay
49
51
  resource_class.new(value)
50
52
  end
51
53
 
54
+ # Default value processor — returns the value as-is.
55
+ # Subclasses override this to handle enums, datetimes, and nested resources.
56
+ #
57
+ # @param _property [String] The property name
58
+ # @param value [Object] The raw value
59
+ # @return [Object] The processed value
60
+ def process_value(_property, value)
61
+ value
62
+ end
63
+
52
64
  # Fill the object with data
53
65
  #
54
66
  # @param data [Hash] The data to fill with
@@ -57,7 +69,7 @@ module AbacatePay
57
69
  data.each do |key, value|
58
70
  property = camel_to_snake(key)
59
71
  next unless respond_to?("#{property}=", true)
60
-
72
+
61
73
  send("#{property}=", process_value(property, value))
62
74
  end
63
75
  end
@@ -78,7 +90,7 @@ module AbacatePay
78
90
  # @param str [String] The string to convert
79
91
  # @return [String] The converted string
80
92
  def snake_to_camel(str)
81
- str.split('_')
93
+ str.split("_")
82
94
  .map.with_index { |word, i| i.zero? ? word : word.capitalize }
83
95
  .join
84
96
  end
@@ -90,25 +102,25 @@ module AbacatePay
90
102
  # @return [Hash] The hash representation
91
103
  def to_hash
92
104
  instance_variables.each_with_object({}) do |var, hash|
93
- next if var.to_s.start_with?('@__')
94
-
105
+ next if var.to_s.start_with?("@__")
106
+
95
107
  value = instance_variable_get(var)
96
- key = snake_to_camel(var.to_s.delete('@'))
97
-
108
+ key = snake_to_camel(var.to_s.delete("@"))
109
+
98
110
  hash[key] = case value
99
- when DateTime
100
- value.iso8601
101
- when Resource
102
- value.to_hash
103
- when Module
104
- value.respond_to?(:value) ? value.value : value
105
- when Array
106
- value.map { |v| v.respond_to?(:to_hash) ? v.to_hash : v }
107
- else
108
- value
109
- end
111
+ when DateTime
112
+ value.iso8601
113
+ when Resource
114
+ value.to_hash
115
+ when Module
116
+ value.respond_to?(:value) ? value.value : value
117
+ when Array
118
+ value.map { |v| v.respond_to?(:to_hash) ? v.to_hash : v }
119
+ else
120
+ value
121
+ end
110
122
  end.compact
111
123
  end
112
124
  end
113
125
  end
114
- end
126
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ class Store < Resource
6
+ # Represents the available balance of a store.
7
+ class Balance < Resource
8
+ attr_reader :available, :pending, :blocked
9
+
10
+ def initialize(data)
11
+ fill(data)
12
+ end
13
+
14
+ protected
15
+
16
+ attr_writer :available, :pending, :blocked
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents store-level account data in the AbacatePay system.
6
+ class Store < Resource
7
+ RESOURCE_PROPERTIES = {
8
+ balance: "AbacatePay::Resources::Store::Balance"
9
+ }.freeze
10
+
11
+ attr_reader :id, :name, :balance
12
+
13
+ def initialize(data)
14
+ fill(data)
15
+ end
16
+
17
+ private
18
+
19
+ def process_value(property, value)
20
+ return nil if value.nil?
21
+
22
+ if RESOURCE_PROPERTIES.key?(property.to_sym)
23
+ initialize_resource(Object.const_get(RESOURCE_PROPERTIES[property.to_sym]), value)
24
+ else
25
+ value
26
+ end
27
+ end
28
+
29
+ protected
30
+
31
+ attr_writer :id, :name, :balance
32
+ end
33
+ end
34
+ end
35
+
36
+ require "abacate_pay/resources/store/balance"
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents a recurring subscription in the AbacatePay system.
6
+ class Subscriptions < Resource
7
+ RESOURCE_PROPERTIES = {
8
+ customer: "AbacatePay::Resources::Customers",
9
+ products: "AbacatePay::Resources::Billings::Product"
10
+ }.freeze
11
+
12
+ ENUM_PROPERTIES = {
13
+ status: "AbacatePay::Enums::Checkouts::Statuses",
14
+ methods: "AbacatePay::Enums::Billings::Methods"
15
+ }.freeze
16
+
17
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
18
+
19
+ attr_reader :id, :url, :customer, :products, :methods, :status,
20
+ :external_id, :metadata, :dev_mode, :created_at, :updated_at
21
+
22
+ def initialize(data)
23
+ fill(data)
24
+ end
25
+
26
+ def dev_mode?
27
+ @dev_mode
28
+ end
29
+
30
+ private
31
+
32
+ def process_value(property, value)
33
+ return nil if value.nil?
34
+
35
+ if DATETIME_PROPERTIES.include?(property)
36
+ initialize_date_time(value)
37
+ elsif ENUM_PROPERTIES.key?(property.to_sym)
38
+ process_enum_value(property, value)
39
+ elsif RESOURCE_PROPERTIES.key?(property.to_sym)
40
+ process_resource_value(property, value)
41
+ else
42
+ value
43
+ end
44
+ end
45
+
46
+ def process_enum_value(property, value)
47
+ enum_class = Object.const_get(ENUM_PROPERTIES[property.to_sym])
48
+
49
+ if value.is_a?(Array)
50
+ value.map { |item| initialize_enum(enum_class, item) }
51
+ else
52
+ initialize_enum(enum_class, value)
53
+ end
54
+ end
55
+
56
+ def process_resource_value(property, value)
57
+ resource_class = Object.const_get(RESOURCE_PROPERTIES[property.to_sym])
58
+
59
+ if property.to_s == "products" && value.is_a?(Array)
60
+ value.map { |item| initialize_resource(resource_class, item) }
61
+ else
62
+ initialize_resource(resource_class, value)
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ attr_writer :id, :url, :customer, :products, :methods, :status,
69
+ :external_id, :metadata, :dev_mode, :created_at, :updated_at
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AbacatePay
4
+ module Resources
5
+ # Represents a transparent PIX checkout in the AbacatePay system.
6
+ class Transparents < Resource
7
+ RESOURCE_PROPERTIES = {
8
+ customer: "AbacatePay::Resources::Customers"
9
+ }.freeze
10
+
11
+ DATETIME_PROPERTIES = %w[created_at updated_at].freeze
12
+
13
+ attr_reader :id, :amount, :status, :method, :description,
14
+ :expires_in, :qr_code, :qr_code_image, :customer,
15
+ :metadata, :dev_mode, :created_at, :updated_at
16
+
17
+ def initialize(data)
18
+ fill(data)
19
+ end
20
+
21
+ def dev_mode?
22
+ @dev_mode
23
+ end
24
+
25
+ private
26
+
27
+ def process_value(property, value)
28
+ return nil if value.nil?
29
+
30
+ if DATETIME_PROPERTIES.include?(property)
31
+ initialize_date_time(value)
32
+ elsif RESOURCE_PROPERTIES.key?(property.to_sym)
33
+ initialize_resource(Object.const_get(RESOURCE_PROPERTIES[property.to_sym]), value)
34
+ else
35
+ value
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+ attr_writer :id, :amount, :status, :method, :description,
42
+ :expires_in, :qr_code, :qr_code_image, :customer,
43
+ :metadata, :dev_mode, :created_at, :updated_at
44
+ end
45
+ end
46
+ end