jamm 2.5.0 → 2.7.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 +4 -4
- data/CHANGELOG.md +29 -0
- data/Gemfile.lock +2 -4
- data/README.md +24 -0
- data/Rakefile +7 -1
- data/lib/jamm/api/api/webhook_endpoint_api.rb +294 -0
- data/lib/jamm/api/models/charge_message_api_source.rb +42 -0
- data/lib/jamm/api/models/customer_service_update_customer_body.rb +1 -1
- data/lib/jamm/api/models/v1_buyer.rb +1 -1
- data/lib/jamm/api/models/v1_charge_message.rb +27 -4
- data/lib/jamm/api/models/v1_create_webhook_endpoint_request.rb +225 -0
- data/lib/jamm/api/models/v1_create_webhook_endpoint_response.rb +214 -0
- data/lib/jamm/api/models/v1_error_type.rb +2 -1
- data/lib/jamm/api/models/v1_initial_charge.rb +1 -1
- data/lib/jamm/api/models/v1_message_response.rb +13 -4
- data/lib/jamm/api/models/v1_on_session_payment_request.rb +12 -1
- data/lib/jamm/api/models/v1_promote_webhook_endpoint_response.rb +214 -0
- data/lib/jamm/api/models/v1_refund_info.rb +7 -7
- data/lib/jamm/api/models/v1_refund_webhook_content.rb +224 -0
- data/lib/jamm/api/models/v1_rollback_webhook_endpoint_response.rb +214 -0
- data/lib/jamm/api/models/v1_trigger_webhook_event_request.rb +238 -0
- data/lib/jamm/api/models/v1_trigger_webhook_event_response.rb +214 -0
- data/lib/jamm/api/models/v1_webhook_endpoint.rb +307 -0
- data/lib/jamm/api/models/v1_webhook_endpoint_status.rb +42 -0
- data/lib/jamm/api.rb +11 -0
- data/lib/jamm/api_version.rb +10 -0
- data/lib/jamm/client.rb +13 -1
- data/lib/jamm/version.rb +1 -1
- data/lib/jamm/webhook.rb +157 -22
- data/lib/jamm.rb +24 -2
- 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
|
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['
|
|
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/version.rb
CHANGED
data/lib/jamm/webhook.rb
CHANGED
|
@@ -11,39 +11,174 @@ module Jamm
|
|
|
11
11
|
# Parse command is for parsing the received webhook message.
|
|
12
12
|
# It does not call anything remotely, instead returns the suitable object.
|
|
13
13
|
def self.parse(json)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
# Webhook payloads may arrive with string or symbol keys depending on how
|
|
15
|
+
# the caller decoded the JSON (e.g. JSON.parse with or without
|
|
16
|
+
# symbolize_names: true). Normalize to symbols so event-type routing,
|
|
17
|
+
# wrapper flattening, and field lookups are reliable either way.
|
|
18
|
+
json = deep_symbolize_keys(json)
|
|
19
|
+
|
|
20
|
+
out = build(Jamm::OpenAPI::MerchantWebhookMessage, json)
|
|
21
|
+
|
|
22
|
+
# Route on the coerced event type: the wire value is an enum string today,
|
|
23
|
+
# but `build` also resolves a numeric wire value onto its string constant,
|
|
24
|
+
# so routing survives either serialization.
|
|
25
|
+
case out.event_type
|
|
26
|
+
when Jamm::OpenAPI::EventType::CHARGE_CREATED,
|
|
27
|
+
Jamm::OpenAPI::EventType::CHARGE_UPDATED,
|
|
28
|
+
Jamm::OpenAPI::EventType::REFUND_SUCCEEDED,
|
|
29
|
+
Jamm::OpenAPI::EventType::REFUND_FAILED,
|
|
30
|
+
Jamm::OpenAPI::EventType::CHARGE_SUCCESS,
|
|
31
|
+
Jamm::OpenAPI::EventType::CHARGE_FAIL
|
|
32
|
+
out.content = build(Jamm::OpenAPI::ChargeMessage, flatten_charge_content(json[:content]))
|
|
19
33
|
return out
|
|
20
34
|
|
|
21
|
-
when Jamm::OpenAPI::EventType::
|
|
22
|
-
out.content = Jamm::OpenAPI::
|
|
35
|
+
when Jamm::OpenAPI::EventType::CONTRACT_ACTIVATED
|
|
36
|
+
out.content = build(Jamm::OpenAPI::ContractMessage, json[:content])
|
|
23
37
|
return out
|
|
24
38
|
|
|
25
|
-
when Jamm::OpenAPI::EventType::
|
|
26
|
-
out.content = Jamm::OpenAPI::
|
|
39
|
+
when Jamm::OpenAPI::EventType::USER_ACCOUNT_DELETED
|
|
40
|
+
out.content = build(Jamm::OpenAPI::UserAccountMessage, json[:content])
|
|
27
41
|
return out
|
|
42
|
+
end
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return out
|
|
44
|
+
raise 'Unknown event type'
|
|
45
|
+
end
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
# Build a generated model from a webhook payload while normalizing the
|
|
48
|
+
# quirks of the webhook wire format. Applied to every model, so charges,
|
|
49
|
+
# contracts, user-account and refund messages all benefit:
|
|
50
|
+
#
|
|
51
|
+
# 1. Forward-compat: the Jamm backend can add new fields to webhook
|
|
52
|
+
# payloads at any time. The generated model `initialize` raises
|
|
53
|
+
# ArgumentError on any key outside `attribute_map`, so unknown keys are
|
|
54
|
+
# dropped first. Known keys are snake_case, matching `attribute_map`.
|
|
55
|
+
# 2. Numeric enums: the backend serializes webhook payloads with Go's
|
|
56
|
+
# `json.Marshal` (not protojson), so every enum field (status,
|
|
57
|
+
# api_source, ...) arrives as its integer value, while the generated
|
|
58
|
+
# enums are string-based. Each integer is mapped back to the enum string
|
|
59
|
+
# so it matches the values returned by the REST API.
|
|
60
|
+
# 3. Nested models: the generated `initialize` assigns nested objects
|
|
61
|
+
# verbatim (the `_deserialize` coercion only runs from `build_from_hash`,
|
|
62
|
+
# which expects camelCase keys the webhook does not use). So a nested
|
|
63
|
+
# field like `refund.error` would stay a raw Hash and `error.code` would
|
|
64
|
+
# raise NoMethodError. We coerce nested model fields (and arrays of them)
|
|
65
|
+
# recursively so the typed accessors work.
|
|
66
|
+
def self.build(klass, attributes)
|
|
67
|
+
return nil if attributes.nil?
|
|
68
|
+
|
|
69
|
+
types = klass.openapi_types
|
|
70
|
+
filtered = attributes.each_with_object({}) do |(key, value), acc|
|
|
71
|
+
sym = attribute_for(klass, key)
|
|
72
|
+
next if sym.nil?
|
|
73
|
+
|
|
74
|
+
acc[sym] = coerce(types[sym], value)
|
|
75
|
+
end
|
|
36
76
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return out
|
|
77
|
+
klass.new(filtered)
|
|
78
|
+
end
|
|
40
79
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
|
|
95
|
+
# Refund webhooks (REFUND_SUCCEEDED / REFUND_FAILED) deliver `content` as a
|
|
96
|
+
# nested { transaction, refund } wrapper instead of a flat ChargeMessage.
|
|
97
|
+
# Flatten it back into a ChargeMessage so callers always receive the same shape.
|
|
98
|
+
def self.flatten_charge_content(content)
|
|
99
|
+
return content unless content.is_a?(Hash) && content.key?(:transaction)
|
|
100
|
+
|
|
101
|
+
refund = content[:refund]
|
|
102
|
+
# Keep `refund` as the raw Hash: `build` coerces it into a typed RefundInfo
|
|
103
|
+
# (and recursively types its nested `error`). Also surface the refund's
|
|
104
|
+
# `rfd-` id on the flat `refund_id` attribute the model documents.
|
|
105
|
+
charge = content[:transaction].merge(refund: refund)
|
|
106
|
+
charge[:refund_id] = refund[:id] if refund.is_a?(Hash) && !refund[:id].nil?
|
|
107
|
+
charge
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Coerce a raw webhook value into the shape the generated model expects,
|
|
111
|
+
# based on the field's openapi type: numeric enums become their string
|
|
112
|
+
# constant, nested models become typed instances, and `Array<T>` elements are
|
|
113
|
+
# coerced by `T`. Anything else passes through untouched.
|
|
114
|
+
def self.coerce(type, value)
|
|
115
|
+
return value if value.nil?
|
|
116
|
+
|
|
117
|
+
inner = array_inner_type(type)
|
|
118
|
+
return coerce_array(inner, value) unless inner.nil?
|
|
119
|
+
|
|
120
|
+
klass = openapi_const(type)
|
|
121
|
+
return value if klass.nil?
|
|
122
|
+
|
|
123
|
+
if klass.respond_to?(:all_vars)
|
|
124
|
+
resolve_enum(klass, value)
|
|
125
|
+
elsif klass.respond_to?(:openapi_types) && value.is_a?(Hash)
|
|
126
|
+
build(klass, value)
|
|
127
|
+
else
|
|
128
|
+
value
|
|
44
129
|
end
|
|
130
|
+
end
|
|
45
131
|
|
|
46
|
-
|
|
132
|
+
# Coerce each element of an `Array<T>` field by its inner type `T`.
|
|
133
|
+
def self.coerce_array(inner_type, value)
|
|
134
|
+
return value unless value.is_a?(Array)
|
|
135
|
+
|
|
136
|
+
value.map { |element| coerce(inner_type, element) }
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Extract `T` from an `Array<T>` openapi type, or nil when not an array type.
|
|
140
|
+
def self.array_inner_type(type)
|
|
141
|
+
match = type.to_s.match(/\AArray<(.+)>\z/)
|
|
142
|
+
match && match[1]
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Map a numeric enum wire value onto its string enum constant. A value that
|
|
146
|
+
# is already a string (REST-style) passes through untouched.
|
|
147
|
+
def self.resolve_enum(enum, value)
|
|
148
|
+
return value unless value.is_a?(Integer)
|
|
149
|
+
|
|
150
|
+
vars = enum.all_vars
|
|
151
|
+
# Guard the bounds explicitly: Ruby maps negative indices from the end of
|
|
152
|
+
# the array, so any unexpected wire value must fall back to the *_UNSPECIFIED
|
|
153
|
+
# member (index 0) rather than silently selecting the wrong constant.
|
|
154
|
+
value.between?(0, vars.length - 1) ? vars[value] : vars[0]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Resolve an openapi_types entry (e.g. :ChargeMessageApiSource, :RefundInfo)
|
|
158
|
+
# to its generated class, or nil when the type is a primitive (String,
|
|
159
|
+
# Integer, ...) or otherwise unresolvable.
|
|
160
|
+
def self.openapi_const(type)
|
|
161
|
+
return nil if type.nil?
|
|
162
|
+
|
|
163
|
+
name = type.to_s
|
|
164
|
+
return nil unless Jamm::OpenAPI.const_defined?(name)
|
|
165
|
+
|
|
166
|
+
Jamm::OpenAPI.const_get(name)
|
|
167
|
+
rescue NameError
|
|
168
|
+
nil
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Recursively convert Hash keys to symbols so parsing is robust regardless of
|
|
172
|
+
# how the caller decoded the webhook JSON.
|
|
173
|
+
def self.deep_symbolize_keys(value)
|
|
174
|
+
case value
|
|
175
|
+
when Hash
|
|
176
|
+
value.each_with_object({}) { |(k, v), acc| acc[k.to_sym] = deep_symbolize_keys(v) }
|
|
177
|
+
when Array
|
|
178
|
+
value.map { |v| deep_symbolize_keys(v) }
|
|
179
|
+
else
|
|
180
|
+
value
|
|
181
|
+
end
|
|
47
182
|
end
|
|
48
183
|
|
|
49
184
|
# Verify message.
|
data/lib/jamm.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'date'
|
|
3
4
|
require 'rest-client'
|
|
4
5
|
require 'openssl'
|
|
5
6
|
require 'json'
|
|
6
7
|
|
|
8
|
+
require 'jamm/api_version'
|
|
7
9
|
require 'jamm/client'
|
|
8
10
|
require 'jamm/errors'
|
|
9
11
|
require 'jamm/oauth'
|
|
@@ -38,13 +40,33 @@ module Jamm
|
|
|
38
40
|
@max_retry = 0
|
|
39
41
|
|
|
40
42
|
class << self
|
|
41
|
-
attr_accessor :api, :client_id, :client_secret, :api_base, :environment, :mode, :oauth_base, :
|
|
43
|
+
attr_accessor :api, :client_id, :client_secret, :api_base, :environment, :mode, :oauth_base, :connect_base,
|
|
42
44
|
:openapi, :open_timeout, :read_timeout, :max_retry, :retry_initial_delay, :retry_max_delay
|
|
43
45
|
end
|
|
44
46
|
|
|
47
|
+
# The Jamm-API-Version sent on every request; defaults to the version this SDK was built against.
|
|
48
|
+
def self.api_version
|
|
49
|
+
@api_version || Jamm::API_VERSION
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.api_version=(version)
|
|
53
|
+
if version.nil? || version.to_s.empty?
|
|
54
|
+
@api_version = nil
|
|
55
|
+
return
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
version = version.to_s
|
|
59
|
+
raise ArgumentError, "invalid api_version \"#{version}\": expected YYYY-MM-DD" unless version.match?(/\A\d{4}-\d{2}-\d{2}\z/) && Date.valid_date?(*version.split('-').map(&:to_i))
|
|
60
|
+
raise ArgumentError, "api_version #{version} is newer than this SDK supports (#{Jamm::API_VERSION}); upgrade the SDK to use it" if version > Jamm::API_VERSION
|
|
61
|
+
|
|
62
|
+
@api_version = version
|
|
63
|
+
end
|
|
64
|
+
|
|
45
65
|
# Configure SDK with Client ID and Secret.
|
|
46
66
|
# Optionally enable `platform` for platformers to call Jamm API on behalf of their merchant.
|
|
47
|
-
|
|
67
|
+
# Optionally pin `api_version` (YYYY-MM-DD) to an API version older than the one this SDK was built against.
|
|
68
|
+
def self.configure(client_id:, client_secret:, env:, platform: false, api_version: nil)
|
|
69
|
+
self.api_version = api_version
|
|
48
70
|
Jamm.client_id = client_id
|
|
49
71
|
Jamm.client_secret = client_secret
|
|
50
72
|
|