jamm 2.0.0 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3e4e58bcc8b6bba8c4f54b6102212fc8e8f220b7bf311ad6df4d3455636bdbe
4
- data.tar.gz: e3b4f96bcc5fa1b8b58e941884e300980e2b34074ce91733d31476c94a89253f
3
+ metadata.gz: 0dc69a9799a5215efa21041879db8ee9d8b67678dc6ac20dc92046c165eec6fd
4
+ data.tar.gz: 33bd5a72e96fdc0212e956762e5bb7983604a5d1a1e9792d577267a61a2d96bd
5
5
  SHA512:
6
- metadata.gz: 6a1ffa31922c27280624f72f00005f508f967b0efc8e1c3f1b369c77a4ab36cb40fd78ba23eed62c805b1722560c5e80a5a41e73675e021b9579e024368975ad
7
- data.tar.gz: 90a9a314ced4d6c3179f2369b9c601f58a824e9dc106fb0a42ff272fe1c3d1bd7d67b858a7bbf1847a4909dd22891ace8829211f2d7b2e0b855d063cb647ea74
6
+ metadata.gz: 82fd64ead34ca1e458d831d21874ccb6bd53774e27170944a2c8d4d1532dcad9db4e589ffe55ce4a24b60bbd658f8816aebcc674afc6f5d096ba931ec1ae2806
7
+ data.tar.gz: f8d88d108bcd9822c56a05133248bf759b100f31ef3af3bc5b7f5ed14ea4c7ba5d111ca96a482fec038e5de09ac10d769d7d559ab57ac53dcb64dbbc9ce21785
data/CHANGELOG.md ADDED
@@ -0,0 +1,66 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.2.0] - 2026-05-20
9
+
10
+ ### Added
11
+
12
+ - Added `Jamm::Payment.off_session_async` for async off-session charges
13
+ - Auto-fill `idempotency_key` with a UUID when `nil` or blank
14
+
15
+ ## [2.1.0] - 2026-04-06
16
+
17
+ ### Added
18
+
19
+ - Added `ChargeError` details on `ChargeResult` for failed charges
20
+
21
+ ## [2.0.0] - 2026-03-16
22
+
23
+ ### Added
24
+
25
+ - Platform authentication support
26
+ - Refund support and split refund webhook events (succeeded / rejected)
27
+
28
+ ### Changed
29
+
30
+ - Renamed `cancel` operations to `refund` across API and webhooks
31
+
32
+ ## [1.7.0] - 2025-11-11
33
+
34
+ ### Removed
35
+
36
+ - Deprecated legacy contract charge public APIs
37
+
38
+ ## [1.6.0] - 2025-11-11
39
+
40
+ ### Changed
41
+
42
+ - Version bump aligned with other SDKs
43
+
44
+ ## [1.5.0] - 2025-10-09
45
+
46
+ ### Changed
47
+
48
+ - `OnSessionPayment` redirect link is now optional
49
+
50
+ ## [1.4.1] - 2025-08-22
51
+
52
+ ### Changed
53
+
54
+ - Updated RubyGem GitHub source URL
55
+
56
+ ## [1.4.0] - 2025-08-22
57
+
58
+ ### Added
59
+
60
+ - On-session and off-session payment support
61
+
62
+ ## [1.3.0] - 2025-07-08
63
+
64
+ ### Added
65
+
66
+ - Embedded `error.v1` typed errors into OpenAPI proto
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
+ gem 'base64', '~> 0.2'
7
8
  gem 'rest-client', '~> 2.0'
8
9
  gem 'typhoeus', '~> 1.0', '>= 1.0.1'
9
10
 
data/Gemfile.lock CHANGED
@@ -1,16 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jamm (2.0.0)
4
+ jamm (2.2.0)
5
+ base64 (~> 0.2)
5
6
  rest-client (~> 2.0)
6
7
  typhoeus (~> 1.0, >= 1.0.1)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- addressable (2.8.6)
12
- public_suffix (>= 2.0.2, < 6.0)
12
+ addressable (2.9.0)
13
+ public_suffix (>= 2.0.2, < 8.0)
13
14
  ast (2.4.2)
15
+ base64 (0.3.0)
14
16
  bigdecimal (3.1.7)
15
17
  coderay (1.1.3)
16
18
  concurrent-ruby (1.3.4)
@@ -47,7 +49,7 @@ GEM
47
49
  pry (0.14.2)
48
50
  coderay (~> 1.1)
49
51
  method_source (~> 1.0)
50
- public_suffix (5.0.5)
52
+ public_suffix (5.1.1)
51
53
  racc (1.7.3)
52
54
  rainbow (3.1.1)
53
55
  rake (13.2.1)
@@ -90,6 +92,7 @@ PLATFORMS
90
92
  x86_64-linux
91
93
 
92
94
  DEPENDENCIES
95
+ base64 (~> 0.2)
93
96
  faker
94
97
  gimei
95
98
  jamm!
data/jamm.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.homepage = 'https://jamm-pay.jp'
16
16
  s.license = 'MIT'
17
17
 
18
+ s.add_dependency('base64', '~> 0.2')
18
19
  s.add_dependency('rest-client', '~> 2.0')
19
20
  s.add_dependency('typhoeus', '~> 1.0', '>= 1.0.1')
20
21
 
@@ -87,6 +87,74 @@ module Api
87
87
  return data, status_code, headers
88
88
  end
89
89
 
90
+ # Initiate async off-session payment
91
+ # Starts asynchronous off-session payment processing and returns request tracking information.
92
+ # @param body [OffSessionPaymentAsyncRequest] This message represents a request to process an off-session payment asynchronously. It contains the customer ID and the amount to charge. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
93
+ # @param [Hash] opts the optional parameters
94
+ # @return [OffSessionPaymentAsyncResponse]
95
+ def async_off_session_payment(body, opts = {})
96
+ data, _status_code, _headers = async_off_session_payment_with_http_info(body, opts)
97
+ data
98
+ end
99
+
100
+ # Initiate async off-session payment
101
+ # Starts asynchronous off-session payment processing and returns request tracking information.
102
+ # @param body [OffSessionPaymentAsyncRequest] This message represents a request to process an off-session payment asynchronously. It contains the customer ID and the amount to charge. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
103
+ # @param [Hash] opts the optional parameters
104
+ # @return [Array<(OffSessionPaymentAsyncResponse, Integer, Hash)>] OffSessionPaymentAsyncResponse data, response status code and response headers
105
+ def async_off_session_payment_with_http_info(body, opts = {})
106
+ if @api_client.config.debugging
107
+ @api_client.config.logger.debug 'Calling API: PaymentApi.async_off_session_payment ...'
108
+ end
109
+ # verify the required parameter 'body' is set
110
+ if @api_client.config.client_side_validation && body.nil?
111
+ fail ArgumentError, "Missing the required parameter 'body' when calling PaymentApi.async_off_session_payment"
112
+ end
113
+ # resource path
114
+ local_var_path = '/v1/payments/off-session/async'
115
+
116
+ # query parameters
117
+ query_params = opts[:query_params] || {}
118
+
119
+ # header parameters
120
+ header_params = opts[:header_params] || {}
121
+ # HTTP header 'Accept' (if needed)
122
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
123
+ # HTTP header 'Content-Type'
124
+ content_type = @api_client.select_header_content_type(['application/json'])
125
+ if !content_type.nil?
126
+ header_params['Content-Type'] = content_type
127
+ end
128
+
129
+ # form parameters
130
+ form_params = opts[:form_params] || {}
131
+
132
+ # http body (model)
133
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
134
+
135
+ # return_type
136
+ return_type = opts[:debug_return_type] || 'OffSessionPaymentAsyncResponse'
137
+
138
+ # auth_names
139
+ auth_names = opts[:debug_auth_names] || []
140
+
141
+ new_options = opts.merge(
142
+ :operation => :"PaymentApi.async_off_session_payment",
143
+ :header_params => header_params,
144
+ :query_params => query_params,
145
+ :form_params => form_params,
146
+ :body => post_body,
147
+ :auth_names => auth_names,
148
+ :return_type => return_type
149
+ )
150
+
151
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
152
+ if @api_client.config.debugging
153
+ @api_client.config.logger.debug "API called: PaymentApi#async_off_session_payment\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
154
+ end
155
+ return data, status_code, headers
156
+ end
157
+
90
158
  # Create a contract with initial charge
91
159
  # Create a contract with initial charge
92
160
  # @param body [CreateContractWithChargeRequest] Request message for creating a new contract with an immediate initial charge. This combines contract creation and charging in a single operation.
@@ -357,7 +425,7 @@ module Api
357
425
 
358
426
  # Initiate async withdraw (internal)
359
427
  # Internal-only endpoint for initiating asynchronous withdrawal processing.
360
- # @param body [WithdrawAsyncRequest] This message represents a request to withdraw money from a customer asynchronously. It contains the customer ID and the amount to withdraw.
428
+ # @param body [WithdrawAsyncRequest] This message represents a request to withdraw money from a customer asynchronously. It contains the customer ID and the amount to withdraw. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
361
429
  # @param [Hash] opts the optional parameters
362
430
  # @return [WithdrawAsyncResponse]
363
431
  def internal_withdraw_async(body, opts = {})
@@ -367,7 +435,7 @@ module Api
367
435
 
368
436
  # Initiate async withdraw (internal)
369
437
  # Internal-only endpoint for initiating asynchronous withdrawal processing.
370
- # @param body [WithdrawAsyncRequest] This message represents a request to withdraw money from a customer asynchronously. It contains the customer ID and the amount to withdraw.
438
+ # @param body [WithdrawAsyncRequest] This message represents a request to withdraw money from a customer asynchronously. It contains the customer ID and the amount to withdraw. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
371
439
  # @param [Hash] opts the optional parameters
372
440
  # @return [Array<(WithdrawAsyncResponse, Integer, Hash)>] WithdrawAsyncResponse data, response status code and response headers
373
441
  def internal_withdraw_async_with_http_info(body, opts = {})
@@ -493,7 +561,7 @@ module Api
493
561
 
494
562
  # Process payment directly without redirect
495
563
  # Execute a payment off-session within your application without redirecting to a payment page.
496
- # @param body [OffSessionPaymentRequest] This message represents a request to process a payment directly within the application. It contains the customer ID and charge details to be processed.
564
+ # @param body [OffSessionPaymentRequest] This message represents a request to process a payment directly within the application. It contains the customer ID and charge details to be processed. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
497
565
  # @param [Hash] opts the optional parameters
498
566
  # @return [OffSessionPaymentResponse]
499
567
  def off_session_payment(body, opts = {})
@@ -503,7 +571,7 @@ module Api
503
571
 
504
572
  # Process payment directly without redirect
505
573
  # Execute a payment off-session within your application without redirecting to a payment page.
506
- # @param body [OffSessionPaymentRequest] This message represents a request to process a payment directly within the application. It contains the customer ID and charge details to be processed.
574
+ # @param body [OffSessionPaymentRequest] This message represents a request to process a payment directly within the application. It contains the customer ID and charge details to be processed. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
507
575
  # @param [Hash] opts the optional parameters
508
576
  # @return [Array<(OffSessionPaymentResponse, Integer, Hash)>] OffSessionPaymentResponse data, response status code and response headers
509
577
  def off_session_payment_with_http_info(body, opts = {})
@@ -559,77 +627,9 @@ module Api
559
627
  return data, status_code, headers
560
628
  end
561
629
 
562
- # Initiate async off-session payment
563
- # Starts asynchronous off-session payment processing and returns request tracking information.
564
- # @param body [OffSessionPaymentAsyncRequest] This message represents a request to process an off-session payment asynchronously. It contains the customer ID and the amount to charge.
565
- # @param [Hash] opts the optional parameters
566
- # @return [OffSessionPaymentAsyncResponse]
567
- def off_session_payment_async(body, opts = {})
568
- data, _status_code, _headers = off_session_payment_async_with_http_info(body, opts)
569
- data
570
- end
571
-
572
- # Initiate async off-session payment
573
- # Starts asynchronous off-session payment processing and returns request tracking information.
574
- # @param body [OffSessionPaymentAsyncRequest] This message represents a request to process an off-session payment asynchronously. It contains the customer ID and the amount to charge.
575
- # @param [Hash] opts the optional parameters
576
- # @return [Array<(OffSessionPaymentAsyncResponse, Integer, Hash)>] OffSessionPaymentAsyncResponse data, response status code and response headers
577
- def off_session_payment_async_with_http_info(body, opts = {})
578
- if @api_client.config.debugging
579
- @api_client.config.logger.debug 'Calling API: PaymentApi.off_session_payment_async ...'
580
- end
581
- # verify the required parameter 'body' is set
582
- if @api_client.config.client_side_validation && body.nil?
583
- fail ArgumentError, "Missing the required parameter 'body' when calling PaymentApi.off_session_payment_async"
584
- end
585
- # resource path
586
- local_var_path = '/v1/payments/off-session/async'
587
-
588
- # query parameters
589
- query_params = opts[:query_params] || {}
590
-
591
- # header parameters
592
- header_params = opts[:header_params] || {}
593
- # HTTP header 'Accept' (if needed)
594
- header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
595
- # HTTP header 'Content-Type'
596
- content_type = @api_client.select_header_content_type(['application/json'])
597
- if !content_type.nil?
598
- header_params['Content-Type'] = content_type
599
- end
600
-
601
- # form parameters
602
- form_params = opts[:form_params] || {}
603
-
604
- # http body (model)
605
- post_body = opts[:debug_body] || @api_client.object_to_http_body(body)
606
-
607
- # return_type
608
- return_type = opts[:debug_return_type] || 'OffSessionPaymentAsyncResponse'
609
-
610
- # auth_names
611
- auth_names = opts[:debug_auth_names] || []
612
-
613
- new_options = opts.merge(
614
- :operation => :"PaymentApi.off_session_payment_async",
615
- :header_params => header_params,
616
- :query_params => query_params,
617
- :form_params => form_params,
618
- :body => post_body,
619
- :auth_names => auth_names,
620
- :return_type => return_type
621
- )
622
-
623
- data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
624
- if @api_client.config.debugging
625
- @api_client.config.logger.debug "API called: PaymentApi#off_session_payment_async\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
626
- end
627
- return data, status_code, headers
628
- end
629
-
630
630
  # Process payment with optional redirect
631
631
  # Unified interface for creating payments - supports existing customers, new customers with charges, and contract-only creation.
632
- # @param body [OnSessionPaymentRequest] Request message for the unified payment interface. The system intelligently routes the request to the appropriate payment method based on the provided parameters.
632
+ # @param body [OnSessionPaymentRequest] Request message for the unified payment interface. The system intelligently routes the request to the appropriate payment method based on the provided parameters. Supports triggerError for test error simulation via the core InitiatePayment/ApprovePayment flow. See InitialCharge.metadata for details on behavior differences by stage.
633
633
  # @param [Hash] opts the optional parameters
634
634
  # @return [OnSessionPaymentResponse]
635
635
  def on_session_payment(body, opts = {})
@@ -639,7 +639,7 @@ module Api
639
639
 
640
640
  # Process payment with optional redirect
641
641
  # Unified interface for creating payments - supports existing customers, new customers with charges, and contract-only creation.
642
- # @param body [OnSessionPaymentRequest] Request message for the unified payment interface. The system intelligently routes the request to the appropriate payment method based on the provided parameters.
642
+ # @param body [OnSessionPaymentRequest] Request message for the unified payment interface. The system intelligently routes the request to the appropriate payment method based on the provided parameters. Supports triggerError for test error simulation via the core InitiatePayment/ApprovePayment flow. See InitialCharge.metadata for details on behavior differences by stage.
643
643
  # @param [Hash] opts the optional parameters
644
644
  # @return [Array<(OnSessionPaymentResponse, Integer, Hash)>] OnSessionPaymentResponse data, response status code and response headers
645
645
  def on_session_payment_with_http_info(body, opts = {})
@@ -697,7 +697,7 @@ module Api
697
697
 
698
698
  # Refund a charge
699
699
  # Refunds a charge. If the same-day cancellation window has not passed, cancels the charge directly. Otherwise, creates a bank transfer refund request.
700
- # @param body [RefundRequest] Request message for refunding a charge. The refund is always processed asynchronously. The final result is delivered via webhook (&#x60;charge_refund&#x60;).
700
+ # @param body [RefundRequest] Request message for refunding a charge. The refund is always processed asynchronously. The final result is delivered via webhook (&#x60;refund_succeeded&#x60;).
701
701
  # @param [Hash] opts the optional parameters
702
702
  # @return [RefundResponse]
703
703
  def refund(body, opts = {})
@@ -707,7 +707,7 @@ module Api
707
707
 
708
708
  # Refund a charge
709
709
  # Refunds a charge. If the same-day cancellation window has not passed, cancels the charge directly. Otherwise, creates a bank transfer refund request.
710
- # @param body [RefundRequest] Request message for refunding a charge. The refund is always processed asynchronously. The final result is delivered via webhook (&#x60;charge_refund&#x60;).
710
+ # @param body [RefundRequest] Request message for refunding a charge. The refund is always processed asynchronously. The final result is delivered via webhook (&#x60;refund_succeeded&#x60;).
711
711
  # @param [Hash] opts the optional parameters
712
712
  # @return [Array<(RefundResponse, Integer, Hash)>] RefundResponse data, response status code and response headers
713
713
  def refund_with_http_info(body, opts = {})
@@ -765,7 +765,7 @@ module Api
765
765
 
766
766
  # Withdraw money from customer immediately, without redirect
767
767
  # This call is synchronous. The money will be withdrawn immediately.
768
- # @param body [WithdrawRequest] This message represents a request to withdraw money from a customer. It contains the customer ID and the amount to withdraw.
768
+ # @param body [WithdrawRequest] This message represents a request to withdraw money from a customer. It contains the customer ID and the amount to withdraw. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
769
769
  # @param [Hash] opts the optional parameters
770
770
  # @return [WithdrawResponse]
771
771
  def withdraw(body, opts = {})
@@ -775,7 +775,7 @@ module Api
775
775
 
776
776
  # Withdraw money from customer immediately, without redirect
777
777
  # This call is synchronous. The money will be withdrawn immediately.
778
- # @param body [WithdrawRequest] This message represents a request to withdraw money from a customer. It contains the customer ID and the amount to withdraw.
778
+ # @param body [WithdrawRequest] This message represents a request to withdraw money from a customer. It contains the customer ID and the amount to withdraw. Supports triggerError in charge.metadata for test error simulation. See InitialCharge.metadata.
779
779
  # @param [Hash] opts the optional parameters
780
780
  # @return [Array<(WithdrawResponse, Integer, Hash)>] WithdrawResponse data, response status code and response headers
781
781
  def withdraw_with_http_info(body, opts = {})
@@ -22,7 +22,7 @@ module Api
22
22
  # A flag whether Jamm to force KYC for the customer. 初回購入時に購入者に対してKYCを強制するかどうかのフラグです。
23
23
  attr_accessor :force_kyc
24
24
 
25
- # Phone number of the customer. You can update this value later through the UpdateCustomer endpoint. e.g. - 09012345678 Customerの電話番号。 この値は UpdateCustomer エンドポイントを通じて後で更新できます。
25
+ # Phone number of the customer. You can update this value later through the UpdateCustomer endpoint. Accepts Japanese phone numbers (10-11 digits). Note that only mobile numbers (070/080/090) will be stored; non-mobile numbers are silently ignored. e.g. - 09012345678 (mobile) - 08012345678 (mobile) - 07012345678 (mobile) - 05012345678 (IP phone, not stored) - 0312345678 (landline, not stored) Customerの電話番号。 この値は UpdateCustomer エンドポイントを通じて後で更新できます。 携帯電話番号(070/080/090)のみ保存され、それ以外の番号は無視されます。
26
26
  attr_accessor :phone
27
27
 
28
28
  # Name of the customer. You can update this value later through the UpdateCustomer endpoint. e.g. - John Appleseed - 山田太郎 購入者の氏名。 この値は UpdateCustomer エンドポイントを通じて後で更新できます。
@@ -22,7 +22,7 @@ module Api
22
22
  # Amount of the charge in Japanese Yen. The amount must be the total price of the product/service including tax. 決済金額。日本円で指定してください。 金額は商品/サービスの合計金額 (税込) を指定してください。 @gotags: validate:\"gte=1,lte=500000\"
23
23
  attr_accessor :price
24
24
 
25
- # Description is an arbitrary string for merchant to track the charge. This information is displayed on Merchant Dashboard. 決済の説明。ショップが決済を追跡するための任意の文字列です。 @gotags: validate:\"required\"
25
+ # Description is an arbitrary string for merchant to track the charge. This information is displayed on Merchant Dashboard. 決済の説明。ショップが決済を追跡するための任意の文字列です。 @gotags: validate:\"required,max=1024\"
26
26
  attr_accessor :description
27
27
 
28
28
  # Arbitrary key-value additional information about the charge. You can see this information in our merchant dashboard. Chargeに関する任意のキーと値の追加情報。 加盟店ダッシュボードで確認できます。
@@ -0,0 +1,226 @@
1
+ =begin
2
+ #Jamm API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.9.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Api
17
+ # Contains error details for a failed charge.
18
+ class ChargeError
19
+ # Jamm defined error code (e.g. \"ERROR_TYPE_PAYMENT_CHARGE_OVER_LIMIT\").
20
+ attr_accessor :code
21
+
22
+ # Human readable error message.
23
+ attr_accessor :message
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'code' => :'code',
29
+ :'message' => :'message'
30
+ }
31
+ end
32
+
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ attribute_map.values
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'code' => :'String',
42
+ :'message' => :'String'
43
+ }
44
+ end
45
+
46
+ # List of attributes with nullable: true
47
+ def self.openapi_nullable
48
+ Set.new([
49
+ ])
50
+ end
51
+
52
+ # Initializes the object
53
+ # @param [Hash] attributes Model attributes in the form of hash
54
+ def initialize(attributes = {})
55
+ if (!attributes.is_a?(Hash))
56
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Api::ChargeError` initialize method"
57
+ end
58
+
59
+ # check to see if the attribute exists and convert string to symbol for hash key
60
+ attributes = attributes.each_with_object({}) { |(k, v), h|
61
+ if (!self.class.attribute_map.key?(k.to_sym))
62
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Api::ChargeError`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
63
+ end
64
+ h[k.to_sym] = v
65
+ }
66
+
67
+ if attributes.key?(:'code')
68
+ self.code = attributes[:'code']
69
+ end
70
+
71
+ if attributes.key?(:'message')
72
+ self.message = attributes[:'message']
73
+ end
74
+ end
75
+
76
+ # Show invalid properties with the reasons. Usually used together with valid?
77
+ # @return Array for valid properties with the reasons
78
+ def list_invalid_properties
79
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
80
+ invalid_properties = Array.new
81
+ invalid_properties
82
+ end
83
+
84
+ # Check to see if the all the properties in the model are valid
85
+ # @return true if the model is valid
86
+ def valid?
87
+ warn '[DEPRECATED] the `valid?` method is obsolete'
88
+ true
89
+ end
90
+
91
+ # Checks equality by comparing each attribute.
92
+ # @param [Object] Object to be compared
93
+ def ==(o)
94
+ return true if self.equal?(o)
95
+ self.class == o.class &&
96
+ code == o.code &&
97
+ message == o.message
98
+ end
99
+
100
+ # @see the `==` method
101
+ # @param [Object] Object to be compared
102
+ def eql?(o)
103
+ self == o
104
+ end
105
+
106
+ # Calculates hash code according to all attributes.
107
+ # @return [Integer] Hash code
108
+ def hash
109
+ [code, message].hash
110
+ end
111
+
112
+ # Builds the object from hash
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ # @return [Object] Returns the model itself
115
+ def self.build_from_hash(attributes)
116
+ return nil unless attributes.is_a?(Hash)
117
+ attributes = attributes.transform_keys(&:to_sym)
118
+ transformed_hash = {}
119
+ openapi_types.each_pair do |key, type|
120
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
121
+ transformed_hash["#{key}"] = nil
122
+ elsif type =~ /\AArray<(.*)>/i
123
+ # check to ensure the input is an array given that the attribute
124
+ # is documented as an array but the input is not
125
+ if attributes[attribute_map[key]].is_a?(Array)
126
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
127
+ end
128
+ elsif !attributes[attribute_map[key]].nil?
129
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
130
+ end
131
+ end
132
+ new(transformed_hash)
133
+ end
134
+
135
+ # Deserializes the data based on type
136
+ # @param string type Data type
137
+ # @param string value Value to be deserialized
138
+ # @return [Object] Deserialized data
139
+ def self._deserialize(type, value)
140
+ case type.to_sym
141
+ when :Time
142
+ Time.parse(value)
143
+ when :Date
144
+ Date.parse(value)
145
+ when :String
146
+ value.to_s
147
+ when :Integer
148
+ value.to_i
149
+ when :Float
150
+ value.to_f
151
+ when :Boolean
152
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
153
+ true
154
+ else
155
+ false
156
+ end
157
+ when :Object
158
+ # generic object (usually a Hash), return directly
159
+ value
160
+ when /\AArray<(?<inner_type>.+)>\z/
161
+ inner_type = Regexp.last_match[:inner_type]
162
+ value.map { |v| _deserialize(inner_type, v) }
163
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
164
+ k_type = Regexp.last_match[:k_type]
165
+ v_type = Regexp.last_match[:v_type]
166
+ {}.tap do |hash|
167
+ value.each do |k, v|
168
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
169
+ end
170
+ end
171
+ else # model
172
+ # models (e.g. Pet) or oneOf
173
+ klass = Api.const_get(type)
174
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
175
+ end
176
+ end
177
+
178
+ # Returns the string representation of the object
179
+ # @return [String] String presentation of the object
180
+ def to_s
181
+ to_hash.to_s
182
+ end
183
+
184
+ # to_body is an alias to to_hash (backward compatibility)
185
+ # @return [Hash] Returns the object in the form of hash
186
+ def to_body
187
+ to_hash
188
+ end
189
+
190
+ # Returns the object in the form of hash
191
+ # @return [Hash] Returns the object in the form of hash
192
+ def to_hash
193
+ hash = {}
194
+ self.class.attribute_map.each_pair do |attr, param|
195
+ value = self.send(attr)
196
+ if value.nil?
197
+ is_nullable = self.class.openapi_nullable.include?(attr)
198
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
199
+ end
200
+
201
+ hash[param] = _to_hash(value)
202
+ end
203
+ hash
204
+ end
205
+
206
+ # Outputs non-array value in the form of hash
207
+ # For object, use to_hash. Otherwise, just return the value
208
+ # @param [Object] value Any valid value
209
+ # @return [Hash] Returns the value in the form of hash
210
+ def _to_hash(value)
211
+ if value.is_a?(Array)
212
+ value.compact.map { |v| _to_hash(v) }
213
+ elsif value.is_a?(Hash)
214
+ {}.tap do |hash|
215
+ value.each { |k, v| hash[k] = _to_hash(v) }
216
+ end
217
+ elsif value.respond_to? :to_hash
218
+ value.to_hash
219
+ else
220
+ value
221
+ end
222
+ end
223
+
224
+ end
225
+
226
+ end