jamm 2.6.0 → 2.8.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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +39 -0
  5. data/Rakefile +7 -1
  6. data/lib/jamm/api/api/webhook_endpoint_api.rb +294 -0
  7. data/lib/jamm/api/models/charge_message_api_source.rb +42 -0
  8. data/lib/jamm/api/models/customer_service_update_customer_body.rb +1 -1
  9. data/lib/jamm/api/models/v1_buyer.rb +1 -1
  10. data/lib/jamm/api/models/v1_charge_message.rb +27 -4
  11. data/lib/jamm/api/models/v1_create_webhook_endpoint_request.rb +225 -0
  12. data/lib/jamm/api/models/v1_create_webhook_endpoint_response.rb +214 -0
  13. data/lib/jamm/api/models/v1_error_type.rb +24 -1
  14. data/lib/jamm/api/models/v1_initial_charge.rb +1 -1
  15. data/lib/jamm/api/models/v1_message_response.rb +13 -4
  16. data/lib/jamm/api/models/v1_off_session_payment_request.rb +14 -4
  17. data/lib/jamm/api/models/v1_on_session_payment_request.rb +12 -1
  18. data/lib/jamm/api/models/v1_promote_webhook_endpoint_response.rb +214 -0
  19. data/lib/jamm/api/models/v1_refund_info.rb +18 -8
  20. data/lib/jamm/api/models/v1_refund_webhook_content.rb +224 -0
  21. data/lib/jamm/api/models/v1_rollback_webhook_endpoint_response.rb +214 -0
  22. data/lib/jamm/api/models/v1_trigger_webhook_event_request.rb +238 -0
  23. data/lib/jamm/api/models/v1_trigger_webhook_event_response.rb +214 -0
  24. data/lib/jamm/api/models/v1_webhook_endpoint.rb +307 -0
  25. data/lib/jamm/api/models/v1_webhook_endpoint_status.rb +42 -0
  26. data/lib/jamm/api/models/v1_withdraw_request.rb +14 -4
  27. data/lib/jamm/api.rb +11 -0
  28. data/lib/jamm/api_version.rb +10 -0
  29. data/lib/jamm/client.rb +13 -1
  30. data/lib/jamm/errors.rb +51 -16
  31. data/lib/jamm/payment.rb +3 -1
  32. data/lib/jamm/version.rb +1 -1
  33. data/lib/jamm/webhook.rb +17 -3
  34. data/lib/jamm.rb +24 -2
  35. metadata +14 -2
@@ -0,0 +1,307 @@
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
+ # WebhookEndpoint is a webhook receiver with its pinned API version. WebhookEndpoint は固定されたAPIバージョンを持つWebhook受信先です。
18
+ class WebhookEndpoint
19
+ # Endpoint ID, prefixed with `wep-`. エンドポイントID。`wep-` で始まります。
20
+ attr_accessor :id
21
+
22
+ # URL that receives deliveries. 配信先URL。
23
+ attr_accessor :url
24
+
25
+ attr_accessor :status
26
+
27
+ # API version deliveries are rendered at, as `YYYY-MM-DD`. Unset means the endpoint inherits the merchant's pinned version. 配信の形式を決めるAPIバージョン(`YYYY-MM-DD`)。 未設定の場合は加盟店に固定されたバージョンを継承します。
28
+ attr_accessor :api_version
29
+
30
+ # API version that was live before the last promote. Set only while a rollback is possible. 直前の昇格前に有効だったAPIバージョン。ロールバックが可能な間のみ設定されます。
31
+ attr_accessor :previous_api_version
32
+
33
+ # When the last promote happened. Set only while a rollback is possible. 直前の昇格が行われた時刻。ロールバックが可能な間のみ設定されます。
34
+ attr_accessor :promoted_at
35
+
36
+ attr_accessor :created_at
37
+
38
+ attr_accessor :updated_at
39
+
40
+ class EnumAttributeValidator
41
+ attr_reader :datatype
42
+ attr_reader :allowable_values
43
+
44
+ def initialize(datatype, allowable_values)
45
+ @allowable_values = allowable_values.map do |value|
46
+ case datatype.to_s
47
+ when /Integer/i
48
+ value.to_i
49
+ when /Float/i
50
+ value.to_f
51
+ else
52
+ value
53
+ end
54
+ end
55
+ end
56
+
57
+ def valid?(value)
58
+ !value || allowable_values.include?(value)
59
+ end
60
+ end
61
+
62
+ # Attribute mapping from ruby-style variable name to JSON key.
63
+ def self.attribute_map
64
+ {
65
+ :'id' => :'id',
66
+ :'url' => :'url',
67
+ :'status' => :'status',
68
+ :'api_version' => :'apiVersion',
69
+ :'previous_api_version' => :'previousApiVersion',
70
+ :'promoted_at' => :'promotedAt',
71
+ :'created_at' => :'createdAt',
72
+ :'updated_at' => :'updatedAt'
73
+ }
74
+ end
75
+
76
+ # Returns all the JSON keys this model knows about
77
+ def self.acceptable_attributes
78
+ attribute_map.values
79
+ end
80
+
81
+ # Attribute type mapping.
82
+ def self.openapi_types
83
+ {
84
+ :'id' => :'String',
85
+ :'url' => :'String',
86
+ :'status' => :'WebhookEndpointStatus',
87
+ :'api_version' => :'String',
88
+ :'previous_api_version' => :'String',
89
+ :'promoted_at' => :'Time',
90
+ :'created_at' => :'Time',
91
+ :'updated_at' => :'Time'
92
+ }
93
+ end
94
+
95
+ # List of attributes with nullable: true
96
+ def self.openapi_nullable
97
+ Set.new([
98
+ ])
99
+ end
100
+
101
+ # Initializes the object
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ def initialize(attributes = {})
104
+ if (!attributes.is_a?(Hash))
105
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Api::WebhookEndpoint` initialize method"
106
+ end
107
+
108
+ # check to see if the attribute exists and convert string to symbol for hash key
109
+ attributes = attributes.each_with_object({}) { |(k, v), h|
110
+ if (!self.class.attribute_map.key?(k.to_sym))
111
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Api::WebhookEndpoint`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
112
+ end
113
+ h[k.to_sym] = v
114
+ }
115
+
116
+ if attributes.key?(:'id')
117
+ self.id = attributes[:'id']
118
+ end
119
+
120
+ if attributes.key?(:'url')
121
+ self.url = attributes[:'url']
122
+ end
123
+
124
+ if attributes.key?(:'status')
125
+ self.status = attributes[:'status']
126
+ else
127
+ self.status = 'WEBHOOK_ENDPOINT_STATUS_UNSPECIFIED'
128
+ end
129
+
130
+ if attributes.key?(:'api_version')
131
+ self.api_version = attributes[:'api_version']
132
+ end
133
+
134
+ if attributes.key?(:'previous_api_version')
135
+ self.previous_api_version = attributes[:'previous_api_version']
136
+ end
137
+
138
+ if attributes.key?(:'promoted_at')
139
+ self.promoted_at = attributes[:'promoted_at']
140
+ end
141
+
142
+ if attributes.key?(:'created_at')
143
+ self.created_at = attributes[:'created_at']
144
+ end
145
+
146
+ if attributes.key?(:'updated_at')
147
+ self.updated_at = attributes[:'updated_at']
148
+ end
149
+ end
150
+
151
+ # Show invalid properties with the reasons. Usually used together with valid?
152
+ # @return Array for valid properties with the reasons
153
+ def list_invalid_properties
154
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
155
+ invalid_properties = Array.new
156
+ invalid_properties
157
+ end
158
+
159
+ # Check to see if the all the properties in the model are valid
160
+ # @return true if the model is valid
161
+ def valid?
162
+ warn '[DEPRECATED] the `valid?` method is obsolete'
163
+ true
164
+ end
165
+
166
+ # Checks equality by comparing each attribute.
167
+ # @param [Object] Object to be compared
168
+ def ==(o)
169
+ return true if self.equal?(o)
170
+ self.class == o.class &&
171
+ id == o.id &&
172
+ url == o.url &&
173
+ status == o.status &&
174
+ api_version == o.api_version &&
175
+ previous_api_version == o.previous_api_version &&
176
+ promoted_at == o.promoted_at &&
177
+ created_at == o.created_at &&
178
+ updated_at == o.updated_at
179
+ end
180
+
181
+ # @see the `==` method
182
+ # @param [Object] Object to be compared
183
+ def eql?(o)
184
+ self == o
185
+ end
186
+
187
+ # Calculates hash code according to all attributes.
188
+ # @return [Integer] Hash code
189
+ def hash
190
+ [id, url, status, api_version, previous_api_version, promoted_at, created_at, updated_at].hash
191
+ end
192
+
193
+ # Builds the object from hash
194
+ # @param [Hash] attributes Model attributes in the form of hash
195
+ # @return [Object] Returns the model itself
196
+ def self.build_from_hash(attributes)
197
+ return nil unless attributes.is_a?(Hash)
198
+ attributes = attributes.transform_keys(&:to_sym)
199
+ transformed_hash = {}
200
+ openapi_types.each_pair do |key, type|
201
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
202
+ transformed_hash["#{key}"] = nil
203
+ elsif type =~ /\AArray<(.*)>/i
204
+ # check to ensure the input is an array given that the attribute
205
+ # is documented as an array but the input is not
206
+ if attributes[attribute_map[key]].is_a?(Array)
207
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
208
+ end
209
+ elsif !attributes[attribute_map[key]].nil?
210
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
211
+ end
212
+ end
213
+ new(transformed_hash)
214
+ end
215
+
216
+ # Deserializes the data based on type
217
+ # @param string type Data type
218
+ # @param string value Value to be deserialized
219
+ # @return [Object] Deserialized data
220
+ def self._deserialize(type, value)
221
+ case type.to_sym
222
+ when :Time
223
+ Time.parse(value)
224
+ when :Date
225
+ Date.parse(value)
226
+ when :String
227
+ value.to_s
228
+ when :Integer
229
+ value.to_i
230
+ when :Float
231
+ value.to_f
232
+ when :Boolean
233
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
234
+ true
235
+ else
236
+ false
237
+ end
238
+ when :Object
239
+ # generic object (usually a Hash), return directly
240
+ value
241
+ when /\AArray<(?<inner_type>.+)>\z/
242
+ inner_type = Regexp.last_match[:inner_type]
243
+ value.map { |v| _deserialize(inner_type, v) }
244
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
245
+ k_type = Regexp.last_match[:k_type]
246
+ v_type = Regexp.last_match[:v_type]
247
+ {}.tap do |hash|
248
+ value.each do |k, v|
249
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
250
+ end
251
+ end
252
+ else # model
253
+ # models (e.g. Pet) or oneOf
254
+ klass = Api.const_get(type)
255
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
256
+ end
257
+ end
258
+
259
+ # Returns the string representation of the object
260
+ # @return [String] String presentation of the object
261
+ def to_s
262
+ to_hash.to_s
263
+ end
264
+
265
+ # to_body is an alias to to_hash (backward compatibility)
266
+ # @return [Hash] Returns the object in the form of hash
267
+ def to_body
268
+ to_hash
269
+ end
270
+
271
+ # Returns the object in the form of hash
272
+ # @return [Hash] Returns the object in the form of hash
273
+ def to_hash
274
+ hash = {}
275
+ self.class.attribute_map.each_pair do |attr, param|
276
+ value = self.send(attr)
277
+ if value.nil?
278
+ is_nullable = self.class.openapi_nullable.include?(attr)
279
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
280
+ end
281
+
282
+ hash[param] = _to_hash(value)
283
+ end
284
+ hash
285
+ end
286
+
287
+ # Outputs non-array value in the form of hash
288
+ # For object, use to_hash. Otherwise, just return the value
289
+ # @param [Object] value Any valid value
290
+ # @return [Hash] Returns the value in the form of hash
291
+ def _to_hash(value)
292
+ if value.is_a?(Array)
293
+ value.compact.map { |v| _to_hash(v) }
294
+ elsif value.is_a?(Hash)
295
+ {}.tap do |hash|
296
+ value.each { |k, v| hash[k] = _to_hash(v) }
297
+ end
298
+ elsif value.respond_to? :to_hash
299
+ value.to_hash
300
+ else
301
+ value
302
+ end
303
+ end
304
+
305
+ end
306
+
307
+ end
@@ -0,0 +1,42 @@
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
+ class WebhookEndpointStatus
18
+ UNSPECIFIED = "WEBHOOK_ENDPOINT_STATUS_UNSPECIFIED".freeze
19
+ LIVE = "WEBHOOK_ENDPOINT_STATUS_LIVE".freeze
20
+ TEST = "WEBHOOK_ENDPOINT_STATUS_TEST".freeze
21
+ DISABLED = "WEBHOOK_ENDPOINT_STATUS_DISABLED".freeze
22
+
23
+ def self.all_vars
24
+ @all_vars ||= [UNSPECIFIED, LIVE, TEST, DISABLED].freeze
25
+ end
26
+
27
+ # Builds the enum from string
28
+ # @param [String] The enum value in the form of the string
29
+ # @return [String] The enum value
30
+ def self.build_from_hash(value)
31
+ new.build_from_hash(value)
32
+ end
33
+
34
+ # Builds the enum from string
35
+ # @param [String] The enum value in the form of the string
36
+ # @return [String] The enum value
37
+ def build_from_hash(value)
38
+ return value if WebhookEndpointStatus.all_vars.include?(value)
39
+ raise "Invalid ENUM value #{value} for class #WebhookEndpointStatus"
40
+ end
41
+ end
42
+ end
@@ -20,11 +20,15 @@ module Api
20
20
 
21
21
  attr_accessor :charge
22
22
 
23
+ # Merchant-supplied idempotency key for retry safety. Not enabled yet: a request with a key is rejected with 400. ASCII only, 1-255 chars matching ^[a-zA-Z0-9_\\-]{1,255}$.
24
+ attr_accessor :idempotency_key
25
+
23
26
  # Attribute mapping from ruby-style variable name to JSON key.
24
27
  def self.attribute_map
25
28
  {
26
29
  :'customer' => :'customer',
27
- :'charge' => :'charge'
30
+ :'charge' => :'charge',
31
+ :'idempotency_key' => :'idempotencyKey'
28
32
  }
29
33
  end
30
34
 
@@ -37,7 +41,8 @@ module Api
37
41
  def self.openapi_types
38
42
  {
39
43
  :'customer' => :'String',
40
- :'charge' => :'InitialCharge'
44
+ :'charge' => :'InitialCharge',
45
+ :'idempotency_key' => :'String'
41
46
  }
42
47
  end
43
48
 
@@ -69,6 +74,10 @@ module Api
69
74
  if attributes.key?(:'charge')
70
75
  self.charge = attributes[:'charge']
71
76
  end
77
+
78
+ if attributes.key?(:'idempotency_key')
79
+ self.idempotency_key = attributes[:'idempotency_key']
80
+ end
72
81
  end
73
82
 
74
83
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -92,7 +101,8 @@ module Api
92
101
  return true if self.equal?(o)
93
102
  self.class == o.class &&
94
103
  customer == o.customer &&
95
- charge == o.charge
104
+ charge == o.charge &&
105
+ idempotency_key == o.idempotency_key
96
106
  end
97
107
 
98
108
  # @see the `==` method
@@ -104,7 +114,7 @@ module Api
104
114
  # Calculates hash code according to all attributes.
105
115
  # @return [Integer] Hash code
106
116
  def hash
107
- [customer, charge].hash
117
+ [customer, charge, idempotency_key].hash
108
118
  end
109
119
 
110
120
  # Builds the object from hash
data/lib/jamm/api.rb CHANGED
@@ -19,6 +19,7 @@ require 'jamm/api/configuration'
19
19
  # Models
20
20
  require 'jamm/api/models/apiv1_error'
21
21
  require 'jamm/api/models/apiv1_status'
22
+ require 'jamm/api/models/charge_message_api_source'
22
23
  require 'jamm/api/models/customer_service_update_customer_body'
23
24
  require 'jamm/api/models/googlerpc_status'
24
25
  require 'jamm/api/models/protobuf_any'
@@ -47,6 +48,8 @@ require 'jamm/api/models/v1_create_contract_without_charge_request'
47
48
  require 'jamm/api/models/v1_create_contract_without_charge_response'
48
49
  require 'jamm/api/models/v1_create_customer_request'
49
50
  require 'jamm/api/models/v1_create_customer_response'
51
+ require 'jamm/api/models/v1_create_webhook_endpoint_request'
52
+ require 'jamm/api/models/v1_create_webhook_endpoint_response'
50
53
  require 'jamm/api/models/v1_customer'
51
54
  require 'jamm/api/models/v1_delete_customer_response'
52
55
  require 'jamm/api/models/v1_deposit_type'
@@ -80,14 +83,21 @@ require 'jamm/api/models/v1_pagination'
80
83
  require 'jamm/api/models/v1_payment_authorization_status'
81
84
  require 'jamm/api/models/v1_payment_link'
82
85
  require 'jamm/api/models/v1_ping_response'
86
+ require 'jamm/api/models/v1_promote_webhook_endpoint_response'
83
87
  require 'jamm/api/models/v1_refund_info'
84
88
  require 'jamm/api/models/v1_refund_request'
85
89
  require 'jamm/api/models/v1_refund_response'
90
+ require 'jamm/api/models/v1_refund_webhook_content'
91
+ require 'jamm/api/models/v1_rollback_webhook_endpoint_response'
86
92
  require 'jamm/api/models/v1_search_banks_response'
87
93
  require 'jamm/api/models/v1_search_branches_response'
94
+ require 'jamm/api/models/v1_trigger_webhook_event_request'
95
+ require 'jamm/api/models/v1_trigger_webhook_event_response'
88
96
  require 'jamm/api/models/v1_url'
89
97
  require 'jamm/api/models/v1_update_customer_response'
90
98
  require 'jamm/api/models/v1_user_account_message'
99
+ require 'jamm/api/models/v1_webhook_endpoint'
100
+ require 'jamm/api/models/v1_webhook_endpoint_status'
91
101
  require 'jamm/api/models/v1_withdraw_async_request'
92
102
  require 'jamm/api/models/v1_withdraw_async_response'
93
103
  require 'jamm/api/models/v1_withdraw_async_status_request'
@@ -99,6 +109,7 @@ require 'jamm/api/models/v1_withdraw_response'
99
109
  require 'jamm/api/api/customer_api'
100
110
  require 'jamm/api/api/healthcheck_api'
101
111
  require 'jamm/api/api/payment_api'
112
+ require 'jamm/api/api/webhook_endpoint_api'
102
113
  require 'jamm/api/api/webhook_service_api'
103
114
 
104
115
  module Api
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by make sdkversions. DO NOT EDIT.
4
+ #
5
+ # Bumped only by the release workflow, which checks the API serves it first.
6
+
7
+ module Jamm
8
+ # The Jamm API version this SDK was built against.
9
+ API_VERSION = '2026-08-26'
10
+ end
data/lib/jamm/client.rb CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  module Jamm
4
4
  module Client
5
+ # Applied after header_params are merged so per-call or default_headers overrides cannot change the version.
6
+ module PinAPIVersion
7
+ def build_request(http_method, path, opts = {})
8
+ request = super
9
+ headers = request.options[:headers]
10
+ headers.delete_if { |k, _| k.to_s.casecmp?('Jamm-API-Version') }
11
+ headers['Jamm-API-Version'] = Jamm.api_version
12
+ request
13
+ end
14
+ end
15
+
5
16
  def self.handler(merchant: nil)
6
17
  base = Jamm::OpenAPI::ApiClient.new
7
18
 
@@ -9,7 +20,8 @@ module Jamm
9
20
  base.config.host = Jamm.openapi.config.host
10
21
  base.config.scheme = Jamm.openapi.config.scheme
11
22
  base.default_headers['Authorization'] = "Bearer #{Jamm::OAuth.token}"
12
- base.default_headers['X-SDK-Version'] = "ruby:#{Jamm::VERSION}"
23
+ base.default_headers['Jamm-SDK-Version'] = "ruby:#{Jamm::VERSION}"
24
+ base.extend(PinAPIVersion)
13
25
 
14
26
  # Platform feature, optionally set merchant id to call Jamm API
15
27
  # on behalf of the merchant.
data/lib/jamm/errors.rb CHANGED
@@ -35,38 +35,72 @@ module Jamm
35
35
  # - Jamm: code is string, message is string originating from Jamm's protobuf definition.
36
36
  # - OpenAPI: code is integer, message is string originating from ConnectRPC error format.
37
37
  class ApiError < StandardError
38
- attr_reader :code, :error_code, :error_type, :message, :headers, :body
38
+ # error_type is kept for compatibility (it reads ERROR_TYPE_UNSPECIFIED for REST answers); use api_error_type.
39
+ attr_reader :code, :error_code, :error_type, :api_error_type, :charge_id, :message, :headers, :body
40
+
41
+ VALUE_DETAIL = 'type.googleapis.com/google.protobuf.Value'
42
+ CHARGE_PENDING_DETAIL = 'type.googleapis.com/api.v1.ChargePendingDetail'
43
+ private_constant :VALUE_DETAIL, :CHARGE_PENDING_DETAIL
39
44
 
40
45
  # Add this class method to convert StandardError to ApiError
41
46
  def self.from_error(e)
42
- error_type = Api::ErrorType::UNSPECIFIED
43
-
44
- # Convert Protobuf oriented error to error type.
45
- details = JSON.parse(e.response_body)['details']
46
-
47
- if details.is_a?(Array) && details.any?
48
- details.each do |d|
49
- # Loop through all error types to find a match
50
- Api::ErrorType.all_vars.each do |type|
51
- error_type = type.to_s if d['debug'] == type.to_s
52
- end
53
- end
54
- end
47
+ details = parse_details(e.response_body)
55
48
 
56
49
  new(
57
50
  code: e.code,
58
51
  message: e.message,
59
- error_type: error_type,
52
+ error_type: legacy_error_type_from(details),
53
+ api_error_type: api_error_type_from(details),
54
+ charge_id: charge_id_from(details),
60
55
  response_headers: e.response_headers,
61
56
  response_body: e.response_body
62
57
  )
63
58
  end
64
59
 
60
+ # A connection timeout has no body, and a proxy error page isn't JSON: keep the real error.
61
+ def self.parse_details(body)
62
+ parsed = body.is_a?(Hash) ? body : JSON.parse(body.to_s)
63
+ return [] unless parsed.is_a?(Hash) && parsed['details'].is_a?(Array)
64
+
65
+ parsed['details'].select { |d| d.is_a?(Hash) }
66
+ rescue JSON::ParserError, TypeError
67
+ []
68
+ end
69
+
70
+ # error_type keeps its historic rule (a known type in `debug`), which REST answers never match.
71
+ def self.legacy_error_type_from(details)
72
+ error_type = Api::ErrorType::UNSPECIFIED
73
+ details.each do |d|
74
+ Api::ErrorType.all_vars.each { |type| error_type = type.to_s if d['debug'] == type.to_s }
75
+ end
76
+ error_type
77
+ end
78
+
79
+ # REST answers carry the type as a google.protobuf.Value detail, Connect as `debug`.
80
+ # An unknown ERROR_TYPE_* passes through, so a newer server's type isn't lost.
81
+ def self.api_error_type_from(details)
82
+ details.each do |d|
83
+ type = d['@type'] == VALUE_DETAIL ? d['value'] : d['debug']
84
+ return type if type.is_a?(String) && type.start_with?('ERROR_TYPE_')
85
+ end
86
+ Api::ErrorType::UNSPECIFIED
87
+ end
88
+
89
+ # The charge ID of a pending sync charge (outcome unknown): retry only with the same idempotency_key.
90
+ def self.charge_id_from(details)
91
+ pending = details.find { |d| d['@type'] == CHARGE_PENDING_DETAIL }
92
+ id = pending && pending['chargeId']
93
+ id.is_a?(String) && !id.empty? ? id : nil
94
+ end
95
+ private_class_method :parse_details, :legacy_error_type_from, :api_error_type_from, :charge_id_from
96
+
65
97
  def initialize(args = {})
66
98
  # Check code existence and convert to string if it's integer
67
99
  @code = args[:code]
68
100
  @message = args[:message]
69
101
  @error_type = args[:error_type]
102
+ @api_error_type = args[:api_error_type]
103
+ @charge_id = args[:charge_id]
70
104
  @headers = args[:response_headers]
71
105
 
72
106
  raw_body = if args[:response_body].nil?
@@ -75,7 +109,8 @@ module Jamm
75
109
  args[:response_body]
76
110
  elsif args[:response_body].is_a?(String)
77
111
  begin
78
- JSON.parse(args[:response_body])
112
+ parsed = JSON.parse(args[:response_body])
113
+ parsed.is_a?(Hash) ? parsed : {}
79
114
  rescue StandardError
80
115
  {}
81
116
  end
data/lib/jamm/payment.rb CHANGED
@@ -39,11 +39,13 @@ module Jamm
39
39
  raise Jamm::ApiError.from_error(e)
40
40
  end
41
41
 
42
- def self.off_session(customer:, charge:, merchant: nil)
42
+ # Sends idempotency_key only when given: unlike off_session_async, no key is generated.
43
+ def self.off_session(customer:, charge:, idempotency_key: nil, merchant: nil)
43
44
  request = Jamm::OpenAPI::OffSessionPaymentRequest.new(
44
45
  customer: customer,
45
46
  charge: charge
46
47
  )
48
+ request.idempotency_key = idempotency_key unless idempotency_key.nil? || idempotency_key.strip.empty?
47
49
 
48
50
  handler = Jamm::Client.handler(merchant: merchant)
49
51
  Jamm::OpenAPI::PaymentApi.new(handler).off_session_payment(request)
data/lib/jamm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jamm
4
- VERSION = '2.6.0'
4
+ VERSION = '2.8.0'
5
5
  end
data/lib/jamm/webhook.rb CHANGED
@@ -66,11 +66,10 @@ module Jamm
66
66
  def self.build(klass, attributes)
67
67
  return nil if attributes.nil?
68
68
 
69
- known = klass.attribute_map
70
69
  types = klass.openapi_types
71
70
  filtered = attributes.each_with_object({}) do |(key, value), acc|
72
- sym = key.to_sym
73
- next unless known.key?(sym)
71
+ sym = attribute_for(klass, key)
72
+ next if sym.nil?
74
73
 
75
74
  acc[sym] = coerce(types[sym], value)
76
75
  end
@@ -78,6 +77,21 @@ module Jamm
78
77
  klass.new(filtered)
79
78
  end
80
79
 
80
+ # attribute_map is { snake_symbol => jsonCamelName }; accept either
81
+ # spelling. Both cannot arrive together; the last would win.
82
+ def self.attribute_for(klass, key)
83
+ sym = key.to_sym
84
+ return sym if klass.attribute_map.key?(sym)
85
+
86
+ by_serialized(klass)[sym]
87
+ end
88
+
89
+ # Memoised per class: Hash#key is a linear scan, paid once per field otherwise.
90
+ def self.by_serialized(klass)
91
+ @by_serialized ||= {}
92
+ @by_serialized[klass] ||= klass.attribute_map.invert
93
+ end
94
+
81
95
  # Refund webhooks (REFUND_SUCCEEDED / REFUND_FAILED) deliver `content` as a
82
96
  # nested { transaction, refund } wrapper instead of a flat ChargeMessage.
83
97
  # Flatten it back into a ChargeMessage so callers always receive the same shape.