payjpv2 1.0.11 → 1.2.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +8 -2
  4. data/docs/CheckoutSessionCreateRequest.md +2 -0
  5. data/docs/CheckoutSessionDetailsResponse.md +2 -0
  6. data/docs/CheckoutSessionsApi.md +70 -0
  7. data/docs/CustomerUpdateRequest.md +1 -1
  8. data/docs/LineItemRequest.md +3 -1
  9. data/docs/PaymentFlowCreateRequest.md +2 -0
  10. data/docs/PaymentFlowResponse.md +2 -0
  11. data/docs/PaymentFlowUpdateRequest.md +2 -0
  12. data/docs/PriceDataRequest.md +24 -0
  13. data/docs/ProductDataRequest.md +20 -0
  14. data/docs/RedirectOptionsRequest.md +18 -0
  15. data/docs/RedirectOptionsResponse.md +18 -0
  16. data/docs/SetupFlowCancelRequest.md +1 -1
  17. data/docs/SetupFlowCreateRequest.md +2 -0
  18. data/docs/SetupFlowResponse.md +2 -0
  19. data/docs/SetupFlowUpdateRequest.md +2 -0
  20. data/docs/TaxRateCreateRequest.md +2 -0
  21. data/docs/TaxRateDetailsResponse.md +2 -0
  22. data/docs/TaxRateUpdateRequest.md +2 -0
  23. data/docs/TaxType.md +15 -0
  24. data/lib/payjpv2/api/checkout_sessions_api.rb +60 -0
  25. data/lib/payjpv2/models/checkout_session_create_request.rb +11 -1
  26. data/lib/payjpv2/models/checkout_session_details_response.rb +23 -1
  27. data/lib/payjpv2/models/customer_update_request.rb +1 -1
  28. data/lib/payjpv2/models/line_item_request.rb +26 -14
  29. data/lib/payjpv2/models/payment_flow_create_request.rb +11 -1
  30. data/lib/payjpv2/models/payment_flow_response.rb +23 -1
  31. data/lib/payjpv2/models/payment_flow_update_request.rb +11 -1
  32. data/lib/payjpv2/models/price_data_request.rb +286 -0
  33. data/lib/payjpv2/models/product_data_request.rb +228 -0
  34. data/lib/payjpv2/models/redirect_options_request.rb +206 -0
  35. data/lib/payjpv2/models/redirect_options_response.rb +208 -0
  36. data/lib/payjpv2/models/setup_flow_cancel_request.rb +1 -1
  37. data/lib/payjpv2/models/setup_flow_cancellation_reason.rb +2 -1
  38. data/lib/payjpv2/models/setup_flow_create_request.rb +11 -1
  39. data/lib/payjpv2/models/setup_flow_response.rb +23 -1
  40. data/lib/payjpv2/models/setup_flow_update_request.rb +11 -1
  41. data/lib/payjpv2/models/tax_rate_create_request.rb +11 -1
  42. data/lib/payjpv2/models/tax_rate_details_response.rb +13 -1
  43. data/lib/payjpv2/models/tax_rate_update_request.rb +11 -1
  44. data/lib/payjpv2/models/tax_type.rb +39 -0
  45. data/lib/payjpv2/version.rb +1 -1
  46. data/lib/payjpv2.rb +5 -0
  47. data/spec/api/checkout_sessions_api_spec.rb +33 -0
  48. data/spec/models/checkout_session_create_request_spec.rb +6 -0
  49. data/spec/models/checkout_session_details_response_spec.rb +6 -0
  50. data/spec/models/line_item_request_spec.rb +6 -0
  51. data/spec/models/payment_flow_create_request_spec.rb +6 -0
  52. data/spec/models/payment_flow_response_spec.rb +6 -0
  53. data/spec/models/payment_flow_update_request_spec.rb +6 -0
  54. data/spec/models/price_data_request_spec.rb +54 -0
  55. data/spec/models/product_data_request_spec.rb +42 -0
  56. data/spec/models/redirect_options_request_spec.rb +36 -0
  57. data/spec/models/redirect_options_response_spec.rb +36 -0
  58. data/spec/models/setup_flow_create_request_spec.rb +6 -0
  59. data/spec/models/setup_flow_response_spec.rb +6 -0
  60. data/spec/models/setup_flow_update_request_spec.rb +6 -0
  61. data/spec/models/tax_rate_create_request_spec.rb +6 -0
  62. data/spec/models/tax_rate_details_response_spec.rb +6 -0
  63. data/spec/models/tax_rate_update_request_spec.rb +6 -0
  64. data/spec/models/tax_type_spec.rb +30 -0
  65. metadata +21 -1
@@ -63,6 +63,9 @@ module PAYJPv2
63
63
 
64
64
  attr_accessor :cancel_url
65
65
 
66
+ # success_url へリダイレクトする際のオプション
67
+ attr_accessor :redirect_options
68
+
66
69
  # URL
67
70
  attr_accessor :url
68
71
 
@@ -121,6 +124,7 @@ module PAYJPv2
121
124
  :status => :status,
122
125
  :success_url => :success_url,
123
126
  :cancel_url => :cancel_url,
127
+ :redirect_options => :redirect_options,
124
128
  :url => :url,
125
129
  :metadata => :metadata,
126
130
  :created_at => :created_at,
@@ -162,6 +166,7 @@ module PAYJPv2
162
166
  :status => :'CheckoutSessionStatus',
163
167
  :success_url => :'String',
164
168
  :cancel_url => :'String',
169
+ :redirect_options => :'RedirectOptionsResponse',
165
170
  :url => :'String',
166
171
  :metadata => :'Hash<String, MetadataValue>',
167
172
  :created_at => :'Time',
@@ -329,6 +334,12 @@ module PAYJPv2
329
334
  self.cancel_url = nil
330
335
  end
331
336
 
337
+ if attributes.key?(:redirect_options)
338
+ self.redirect_options = attributes[:redirect_options]
339
+ else
340
+ self.redirect_options = nil
341
+ end
342
+
332
343
  if attributes.key?(:url)
333
344
  self.url = attributes[:url]
334
345
  else
@@ -426,6 +437,16 @@ module PAYJPv2
426
437
  @status = status
427
438
  end
428
439
 
440
+ # Custom attribute writer method with validation
441
+ # @param [Object] redirect_options Value to be assigned
442
+ def redirect_options=(redirect_options)
443
+ if redirect_options.nil?
444
+ raise ArgumentError, 'redirect_options cannot be nil'
445
+ end
446
+
447
+ @redirect_options = redirect_options
448
+ end
449
+
429
450
  # Custom attribute writer method with validation
430
451
  # @param [Object] url Value to be assigned
431
452
  def url=(url)
@@ -492,6 +513,7 @@ module PAYJPv2
492
513
  status == o.status &&
493
514
  success_url == o.success_url &&
494
515
  cancel_url == o.cancel_url &&
516
+ redirect_options == o.redirect_options &&
495
517
  url == o.url &&
496
518
  metadata == o.metadata &&
497
519
  created_at == o.created_at &&
@@ -507,7 +529,7 @@ module PAYJPv2
507
529
  # Calculates hash code according to all attributes.
508
530
  # @return [Integer] Hash code
509
531
  def hash
510
- [object, id, livemode, amount_subtotal, amount_total, customer_id, customer_email, customer_details, expires_at, currency, locale, payment_flow_id, payment_method_types, payment_method_options, setup_flow_id, submit_type, mode, ui_mode, status, success_url, cancel_url, url, metadata, created_at, updated_at].hash
532
+ [object, id, livemode, amount_subtotal, amount_total, customer_id, customer_email, customer_details, expires_at, currency, locale, payment_flow_id, payment_method_types, payment_method_options, setup_flow_id, submit_type, mode, ui_mode, status, success_url, cancel_url, redirect_options, url, metadata, created_at, updated_at].hash
511
533
  end
512
534
 
513
535
  # Builds the object from hash
@@ -15,6 +15,7 @@ require 'time'
15
15
 
16
16
  module PAYJPv2
17
17
  class CustomerUpdateRequest
18
+ # 支払いにデフォルトで使用される支払い方法 ID
18
19
  attr_accessor :default_payment_method_id
19
20
 
20
21
  # 顧客のメールアドレス。メールアドレスの形式が正しいかどうかは検証されます。
@@ -59,7 +60,6 @@ module PAYJPv2
59
60
  # List of attributes with nullable: true
60
61
  def self.openapi_nullable
61
62
  Set.new([
62
- :default_payment_method_id,
63
63
  ])
64
64
  end
65
65
 
@@ -15,9 +15,10 @@ require 'time'
15
15
 
16
16
  module PAYJPv2
17
17
  class LineItemRequest
18
- # 料金 ID
19
18
  attr_accessor :price_id
20
19
 
20
+ attr_accessor :price_data
21
+
21
22
  # 購入する商品の数量
22
23
  attr_accessor :quantity
23
24
 
@@ -28,6 +29,7 @@ module PAYJPv2
28
29
  def self.attribute_map
29
30
  {
30
31
  :price_id => :price_id,
32
+ :price_data => :price_data,
31
33
  :quantity => :quantity,
32
34
  :tax_rates => :tax_rates
33
35
  }
@@ -47,6 +49,7 @@ module PAYJPv2
47
49
  def self.openapi_types
48
50
  {
49
51
  :price_id => :'String',
52
+ :price_data => :'PriceDataRequest',
50
53
  :quantity => :'Integer',
51
54
  :tax_rates => :'Array<String>'
52
55
  }
@@ -55,6 +58,8 @@ module PAYJPv2
55
58
  # List of attributes with nullable: true
56
59
  def self.openapi_nullable
57
60
  Set.new([
61
+ :price_id,
62
+ :price_data,
58
63
  ])
59
64
  end
60
65
 
@@ -76,8 +81,10 @@ module PAYJPv2
76
81
 
77
82
  if attributes.key?(:price_id)
78
83
  self.price_id = attributes[:price_id]
79
- else
80
- self.price_id = nil
84
+ end
85
+
86
+ if attributes.key?(:price_data)
87
+ self.price_data = attributes[:price_data]
81
88
  end
82
89
 
83
90
  if attributes.key?(:quantity)
@@ -93,16 +100,6 @@ module PAYJPv2
93
100
  end
94
101
  end
95
102
 
96
- # Custom attribute writer method with validation
97
- # @param [Object] price_id Value to be assigned
98
- def price_id=(price_id)
99
- if price_id.nil?
100
- raise ArgumentError, 'price_id cannot be nil'
101
- end
102
-
103
- @price_id = price_id
104
- end
105
-
106
103
  # Custom attribute writer method with validation
107
104
  # @param [Object] quantity Value to be assigned
108
105
  def quantity=(quantity)
@@ -113,12 +110,27 @@ module PAYJPv2
113
110
  @quantity = quantity
114
111
  end
115
112
 
113
+ # Custom attribute writer method with validation
114
+ # @param [Object] tax_rates Value to be assigned
115
+ def tax_rates=(tax_rates)
116
+ if tax_rates.nil?
117
+ raise ArgumentError, 'tax_rates cannot be nil'
118
+ end
119
+
120
+ if tax_rates.length > 1
121
+ raise ArgumentError, 'invalid value for "tax_rates", number of items must be less than or equal to 1.'
122
+ end
123
+
124
+ @tax_rates = tax_rates
125
+ end
126
+
116
127
  # Checks equality by comparing each attribute.
117
128
  # @param [Object] Object to be compared
118
129
  def ==(o)
119
130
  return true if self.equal?(o)
120
131
  self.class == o.class &&
121
132
  price_id == o.price_id &&
133
+ price_data == o.price_data &&
122
134
  quantity == o.quantity &&
123
135
  tax_rates == o.tax_rates
124
136
  end
@@ -132,7 +144,7 @@ module PAYJPv2
132
144
  # Calculates hash code according to all attributes.
133
145
  # @return [Integer] Hash code
134
146
  def hash
135
- [price_id, quantity, tax_rates].hash
147
+ [price_id, price_data, quantity, tax_rates].hash
136
148
  end
137
149
 
138
150
  # Builds the object from hash
@@ -42,6 +42,9 @@ module PAYJPv2
42
42
  # 顧客が支払いを完了後かキャンセルした後にリダイレクトされる URL。アプリにリダイレクトしたい場合は URI Scheme を指定できます。confirm=true の場合のみ指定できます。
43
43
  attr_accessor :return_url
44
44
 
45
+ # return_url へリダイレクトする際のオプション
46
+ attr_accessor :redirect_options
47
+
45
48
  # オブジェクトにセットする任意の文字列。
46
49
  attr_accessor :description
47
50
 
@@ -82,6 +85,7 @@ module PAYJPv2
82
85
  :capture_method => :capture_method,
83
86
  :confirm => :confirm,
84
87
  :return_url => :return_url,
88
+ :redirect_options => :redirect_options,
85
89
  :description => :description,
86
90
  :metadata => :metadata
87
91
  }
@@ -109,6 +113,7 @@ module PAYJPv2
109
113
  :capture_method => :'CaptureMethod',
110
114
  :confirm => :'Boolean',
111
115
  :return_url => :'String',
116
+ :redirect_options => :'RedirectOptionsRequest',
112
117
  :description => :'String',
113
118
  :metadata => :'Hash<String, MetadataValue>'
114
119
  }
@@ -180,6 +185,10 @@ module PAYJPv2
180
185
  self.return_url = attributes[:return_url]
181
186
  end
182
187
 
188
+ if attributes.key?(:redirect_options)
189
+ self.redirect_options = attributes[:redirect_options]
190
+ end
191
+
183
192
  if attributes.key?(:description)
184
193
  self.description = attributes[:description]
185
194
  end
@@ -233,6 +242,7 @@ module PAYJPv2
233
242
  capture_method == o.capture_method &&
234
243
  confirm == o.confirm &&
235
244
  return_url == o.return_url &&
245
+ redirect_options == o.redirect_options &&
236
246
  description == o.description &&
237
247
  metadata == o.metadata
238
248
  end
@@ -246,7 +256,7 @@ module PAYJPv2
246
256
  # Calculates hash code according to all attributes.
247
257
  # @return [Integer] Hash code
248
258
  def hash
249
- [amount, customer_id, payment_method_id, payment_method_options, payment_method_types, currency, capture_method, confirm, return_url, description, metadata].hash
259
+ [amount, customer_id, payment_method_id, payment_method_options, payment_method_types, currency, capture_method, confirm, return_url, redirect_options, description, metadata].hash
250
260
  end
251
261
 
252
262
  # Builds the object from hash
@@ -54,6 +54,9 @@ module PAYJPv2
54
54
 
55
55
  attr_accessor :return_url
56
56
 
57
+ # return_url へリダイレクトする際のオプション
58
+ attr_accessor :redirect_options
59
+
57
60
  # 支払いの確定方法 | 値 | |:---| | **automatic**: (デフォルト) 顧客が支払いを承認すると、自動的に確定させます。 | | **manual**: 顧客が支払いを承認すると一旦確定を保留し、後で Capture API を使用して確定します。(すべての支払い方法がこれをサポートしているわけではありません)。 |
58
61
  attr_accessor :capture_method
59
62
 
@@ -115,6 +118,7 @@ module PAYJPv2
115
118
  :status => :status,
116
119
  :next_action => :next_action,
117
120
  :return_url => :return_url,
121
+ :redirect_options => :redirect_options,
118
122
  :capture_method => :capture_method,
119
123
  :last_payment_error => :last_payment_error,
120
124
  :cancellation_reason => :cancellation_reason,
@@ -155,6 +159,7 @@ module PAYJPv2
155
159
  :status => :'PaymentFlowStatus',
156
160
  :next_action => :'Hash<String, Object>',
157
161
  :return_url => :'String',
162
+ :redirect_options => :'RedirectOptionsResponse',
158
163
  :capture_method => :'CaptureMethod',
159
164
  :last_payment_error => :'Hash<String, Object>',
160
165
  :cancellation_reason => :'PaymentFlowCancellationReason',
@@ -302,6 +307,12 @@ module PAYJPv2
302
307
  self.return_url = nil
303
308
  end
304
309
 
310
+ if attributes.key?(:redirect_options)
311
+ self.redirect_options = attributes[:redirect_options]
312
+ else
313
+ self.redirect_options = nil
314
+ end
315
+
305
316
  if attributes.key?(:capture_method)
306
317
  self.capture_method = attributes[:capture_method]
307
318
  else
@@ -433,6 +444,16 @@ module PAYJPv2
433
444
  @status = status
434
445
  end
435
446
 
447
+ # Custom attribute writer method with validation
448
+ # @param [Object] redirect_options Value to be assigned
449
+ def redirect_options=(redirect_options)
450
+ if redirect_options.nil?
451
+ raise ArgumentError, 'redirect_options cannot be nil'
452
+ end
453
+
454
+ @redirect_options = redirect_options
455
+ end
456
+
436
457
  # Custom attribute writer method with validation
437
458
  # @param [Object] capture_method Value to be assigned
438
459
  def capture_method=(capture_method)
@@ -494,6 +515,7 @@ module PAYJPv2
494
515
  status == o.status &&
495
516
  next_action == o.next_action &&
496
517
  return_url == o.return_url &&
518
+ redirect_options == o.redirect_options &&
497
519
  capture_method == o.capture_method &&
498
520
  last_payment_error == o.last_payment_error &&
499
521
  cancellation_reason == o.cancellation_reason &&
@@ -513,7 +535,7 @@ module PAYJPv2
513
535
  # Calculates hash code according to all attributes.
514
536
  # @return [Integer] Hash code
515
537
  def hash
516
- [object, id, livemode, amount, currency, amount_capturable, amount_received, client_secret, customer_id, description, payment_method_id, payment_method_options, payment_method_types, status, next_action, return_url, capture_method, last_payment_error, cancellation_reason, canceled_at, expired_at, metadata, created_at, updated_at].hash
538
+ [object, id, livemode, amount, currency, amount_capturable, amount_received, client_secret, customer_id, description, payment_method_id, payment_method_options, payment_method_types, status, next_action, return_url, redirect_options, capture_method, last_payment_error, cancellation_reason, canceled_at, expired_at, metadata, created_at, updated_at].hash
517
539
  end
518
540
 
519
541
  # Builds the object from hash
@@ -33,6 +33,9 @@ module PAYJPv2
33
33
  # 顧客が支払いを完了後かキャンセルした後にリダイレクトされる URL。アプリにリダイレクトしたい場合は URI Scheme を指定できます。
34
34
  attr_accessor :return_url
35
35
 
36
+ # return_url へリダイレクトする際のオプション
37
+ attr_accessor :redirect_options
38
+
36
39
  # オブジェクトにセットする任意の文字列。
37
40
  attr_accessor :description
38
41
 
@@ -48,6 +51,7 @@ module PAYJPv2
48
51
  :payment_method_options => :payment_method_options,
49
52
  :payment_method_types => :payment_method_types,
50
53
  :return_url => :return_url,
54
+ :redirect_options => :redirect_options,
51
55
  :description => :description,
52
56
  :metadata => :metadata
53
57
  }
@@ -72,6 +76,7 @@ module PAYJPv2
72
76
  :payment_method_options => :'PaymentFlowPaymentMethodOptionsRequest',
73
77
  :payment_method_types => :'Array<PaymentMethodTypes>',
74
78
  :return_url => :'String',
79
+ :redirect_options => :'RedirectOptionsRequest',
75
80
  :description => :'String',
76
81
  :metadata => :'Hash<String, MetadataValue>'
77
82
  }
@@ -125,6 +130,10 @@ module PAYJPv2
125
130
  self.return_url = attributes[:return_url]
126
131
  end
127
132
 
133
+ if attributes.key?(:redirect_options)
134
+ self.redirect_options = attributes[:redirect_options]
135
+ end
136
+
128
137
  if attributes.key?(:description)
129
138
  self.description = attributes[:description]
130
139
  end
@@ -165,6 +174,7 @@ module PAYJPv2
165
174
  payment_method_options == o.payment_method_options &&
166
175
  payment_method_types == o.payment_method_types &&
167
176
  return_url == o.return_url &&
177
+ redirect_options == o.redirect_options &&
168
178
  description == o.description &&
169
179
  metadata == o.metadata
170
180
  end
@@ -178,7 +188,7 @@ module PAYJPv2
178
188
  # Calculates hash code according to all attributes.
179
189
  # @return [Integer] Hash code
180
190
  def hash
181
- [amount, customer_id, payment_method_id, payment_method_options, payment_method_types, return_url, description, metadata].hash
191
+ [amount, customer_id, payment_method_id, payment_method_options, payment_method_types, return_url, redirect_options, description, metadata].hash
182
192
  end
183
193
 
184
194
  # Builds the object from hash
@@ -0,0 +1,286 @@
1
+ =begin
2
+ #PAY.JP API v2
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.14.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module PAYJPv2
17
+ class PriceDataRequest
18
+ # 通貨。現在は `jpy` のみサポートしています。
19
+ attr_accessor :currency
20
+
21
+ # 単価(0以上の整数)
22
+ attr_accessor :unit_amount
23
+
24
+ attr_accessor :product_id
25
+
26
+ attr_accessor :product_data
27
+
28
+ class EnumAttributeValidator
29
+ attr_reader :datatype
30
+ attr_reader :allowable_values
31
+
32
+ def initialize(datatype, allowable_values)
33
+ @allowable_values = allowable_values.map do |value|
34
+ case datatype.to_s
35
+ when /Integer/i
36
+ value.to_i
37
+ when /Float/i
38
+ value.to_f
39
+ else
40
+ value
41
+ end
42
+ end
43
+ end
44
+
45
+ def valid?(value)
46
+ !value || allowable_values.include?(value)
47
+ end
48
+ end
49
+
50
+ # Attribute mapping from ruby-style variable name to JSON key.
51
+ def self.attribute_map
52
+ {
53
+ :currency => :currency,
54
+ :unit_amount => :unit_amount,
55
+ :product_id => :product_id,
56
+ :product_data => :product_data
57
+ }
58
+ end
59
+
60
+ # Returns attribute mapping this model knows about
61
+ def self.acceptable_attribute_map
62
+ attribute_map
63
+ end
64
+
65
+ # Returns all the JSON keys this model knows about
66
+ def self.acceptable_attributes
67
+ acceptable_attribute_map.values
68
+ end
69
+
70
+ # Attribute type mapping.
71
+ def self.openapi_types
72
+ {
73
+ :currency => :'Currency',
74
+ :unit_amount => :'Integer',
75
+ :product_id => :'String',
76
+ :product_data => :'ProductDataRequest'
77
+ }
78
+ end
79
+
80
+ # List of attributes with nullable: true
81
+ def self.openapi_nullable
82
+ Set.new([
83
+ :product_id,
84
+ :product_data
85
+ ])
86
+ end
87
+
88
+ # Initializes the object
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ def initialize(attributes = {})
91
+ if (!attributes.is_a?(Hash))
92
+ raise ArgumentError, "The input argument (attributes) must be a hash in `PAYJPv2::PriceDataRequest` initialize method"
93
+ end
94
+
95
+ # check to see if the attribute exists and convert string to symbol for hash key
96
+ acceptable_attribute_map = self.class.acceptable_attribute_map
97
+ attributes = attributes.each_with_object({}) { |(k, v), h|
98
+ if (!acceptable_attribute_map.key?(k.to_sym))
99
+ raise ArgumentError, "`#{k}` is not a valid attribute in `PAYJPv2::PriceDataRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
100
+ end
101
+ h[k.to_sym] = v
102
+ }
103
+
104
+ if attributes.key?(:currency)
105
+ self.currency = attributes[:currency]
106
+ else
107
+ self.currency = nil
108
+ end
109
+
110
+ if attributes.key?(:unit_amount)
111
+ self.unit_amount = attributes[:unit_amount]
112
+ else
113
+ self.unit_amount = nil
114
+ end
115
+
116
+ if attributes.key?(:product_id)
117
+ self.product_id = attributes[:product_id]
118
+ end
119
+
120
+ if attributes.key?(:product_data)
121
+ self.product_data = attributes[:product_data]
122
+ end
123
+ end
124
+
125
+ # Custom attribute writer method with validation
126
+ # @param [Object] currency Value to be assigned
127
+ def currency=(currency)
128
+ if currency.nil?
129
+ raise ArgumentError, 'currency cannot be nil'
130
+ end
131
+
132
+ @currency = currency
133
+ end
134
+
135
+ # Custom attribute writer method with validation
136
+ # @param [Object] unit_amount Value to be assigned
137
+ def unit_amount=(unit_amount)
138
+ if unit_amount.nil?
139
+ raise ArgumentError, 'unit_amount cannot be nil'
140
+ end
141
+
142
+ if unit_amount < 0
143
+ raise ArgumentError, 'invalid value for "unit_amount", must be greater than or equal to 0.'
144
+ end
145
+
146
+ @unit_amount = unit_amount
147
+ end
148
+
149
+ # Checks equality by comparing each attribute.
150
+ # @param [Object] Object to be compared
151
+ def ==(o)
152
+ return true if self.equal?(o)
153
+ self.class == o.class &&
154
+ currency == o.currency &&
155
+ unit_amount == o.unit_amount &&
156
+ product_id == o.product_id &&
157
+ product_data == o.product_data
158
+ end
159
+
160
+ # @see the `==` method
161
+ # @param [Object] Object to be compared
162
+ def eql?(o)
163
+ self == o
164
+ end
165
+
166
+ # Calculates hash code according to all attributes.
167
+ # @return [Integer] Hash code
168
+ def hash
169
+ [currency, unit_amount, product_id, product_data].hash
170
+ end
171
+
172
+ # Builds the object from hash
173
+ # @param [Hash] attributes Model attributes in the form of hash
174
+ # @return [Object] Returns the model itself
175
+ def self.build_from_hash(attributes)
176
+ return nil unless attributes.is_a?(Hash)
177
+ attributes = attributes.transform_keys(&:to_sym)
178
+ transformed_hash = {}
179
+ openapi_types.each_pair do |key, type|
180
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
181
+ transformed_hash["#{key}"] = nil
182
+ elsif type =~ /\AArray<(.*)>/i
183
+ # check to ensure the input is an array given that the attribute
184
+ # is documented as an array but the input is not
185
+ if attributes[attribute_map[key]].is_a?(Array)
186
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
187
+ end
188
+ elsif !attributes[attribute_map[key]].nil?
189
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
190
+ end
191
+ end
192
+ new(transformed_hash)
193
+ end
194
+
195
+ # Deserializes the data based on type
196
+ # @param string type Data type
197
+ # @param string value Value to be deserialized
198
+ # @return [Object] Deserialized data
199
+ def self._deserialize(type, value)
200
+ case type.to_sym
201
+ when :Time
202
+ Time.parse(value)
203
+ when :Date
204
+ Date.parse(value)
205
+ when :String
206
+ value.to_s
207
+ when :Integer
208
+ value.to_i
209
+ when :Float
210
+ value.to_f
211
+ when :Boolean
212
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
213
+ true
214
+ else
215
+ false
216
+ end
217
+ when :Object
218
+ # generic object (usually a Hash), return directly
219
+ value
220
+ when /\AArray<(?<inner_type>.+)>\z/
221
+ inner_type = Regexp.last_match[:inner_type]
222
+ value.map { |v| _deserialize(inner_type, v) }
223
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
224
+ k_type = Regexp.last_match[:k_type]
225
+ v_type = Regexp.last_match[:v_type]
226
+ {}.tap do |hash|
227
+ value.each do |k, v|
228
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
229
+ end
230
+ end
231
+ else # model
232
+ # models (e.g. Pet) or oneOf
233
+ klass = PAYJPv2.const_get(type)
234
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
235
+ end
236
+ end
237
+
238
+ # Returns the string representation of the object
239
+ # @return [String] String presentation of the object
240
+ def to_s
241
+ to_hash.to_s
242
+ end
243
+
244
+ # to_body is an alias to to_hash (backward compatibility)
245
+ # @return [Hash] Returns the object in the form of hash
246
+ def to_body
247
+ to_hash
248
+ end
249
+
250
+ # Returns the object in the form of hash
251
+ # @return [Hash] Returns the object in the form of hash
252
+ def to_hash
253
+ hash = {}
254
+ self.class.attribute_map.each_pair do |attr, param|
255
+ value = self.send(attr)
256
+ if value.nil?
257
+ is_nullable = self.class.openapi_nullable.include?(attr)
258
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
259
+ end
260
+
261
+ hash[param] = _to_hash(value)
262
+ end
263
+ hash
264
+ end
265
+
266
+ # Outputs non-array value in the form of hash
267
+ # For object, use to_hash. Otherwise, just return the value
268
+ # @param [Object] value Any valid value
269
+ # @return [Hash] Returns the value in the form of hash
270
+ def _to_hash(value)
271
+ if value.is_a?(Array)
272
+ value.compact.map { |v| _to_hash(v) }
273
+ elsif value.is_a?(Hash)
274
+ {}.tap do |hash|
275
+ value.each { |k, v| hash[k] = _to_hash(v) }
276
+ end
277
+ elsif value.respond_to? :to_hash
278
+ value.to_hash
279
+ else
280
+ value
281
+ end
282
+ end
283
+
284
+ end
285
+
286
+ end