jamm 2.2.0 → 2.3.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 +16 -0
- data/Gemfile.lock +2 -2
- data/lib/jamm/api/models/charge_message_api_source.rb +42 -0
- data/lib/jamm/api/models/v1_charge_message.rb +15 -4
- 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_refund_info.rb +7 -7
- data/lib/jamm/api.rb +1 -0
- data/lib/jamm/version.rb +1 -1
- data/lib/jamm/webhook.rb +138 -20
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb73f3a736756e42ca49cedb1fb255e011fb39e0c34dabc2f85bfd537836afe1
|
|
4
|
+
data.tar.gz: d5ce67a32f315473bca8800024d19b939b9dafefb358a077e7f30fa551dd01ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff218dca883cf3515ce3d37a89147c6ce1a615fc53568f0916edb48211f6de1a5b4af7c5613066a74a3df017cd81ec76d734c9ecec259b3a78457af4eb3d4900
|
|
7
|
+
data.tar.gz: 69cd60e93b565297f43fd08f7b6a768a6ae5955dddd47d4553b18756e5a3123cdb6548e596e1c9317928f613064c96c66630de9783fab57229d146e78ecfcbe2
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.3.0] - 2026-06-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Resolve numeric enum wire values (`status`, `api_source`, …) onto their string enum constants on every webhook model, matching REST API responses (the backend serializes webhooks with `json.Marshal`, so all enums arrive numeric)
|
|
13
|
+
- Surface the refund `rfd-` id on the flat `refund_id` attribute in addition to the nested `refund.id`
|
|
14
|
+
- Parse `EVENT_TYPE_USER_ACCOUNT_DELETED` webhooks (previously raised `Unknown event type`)
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Webhook parsing no longer fails on new fields added by the backend (forward-compatible)
|
|
19
|
+
- Refund webhooks now expose the nested transaction fields and the refund's `rfd-` id (`refund.id`)
|
|
20
|
+
- `status` on refund/charge webhooks is no longer left as a raw integer
|
|
21
|
+
- Nested webhook fields (e.g. `refund.error`) are now typed model instances instead of raw Hashes, so `error.code` / `error.message` work instead of raising `NoMethodError`
|
|
22
|
+
- `Webhook.parse` now accepts payloads with either string or symbol keys
|
|
23
|
+
|
|
8
24
|
## [2.2.0] - 2026-05-20
|
|
9
25
|
|
|
10
26
|
### Added
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
jamm (2.
|
|
4
|
+
jamm (2.3.0)
|
|
5
5
|
base64 (~> 0.2)
|
|
6
6
|
rest-client (~> 2.0)
|
|
7
7
|
typhoeus (~> 1.0, >= 1.0.1)
|
|
@@ -15,7 +15,7 @@ GEM
|
|
|
15
15
|
base64 (0.3.0)
|
|
16
16
|
bigdecimal (3.1.7)
|
|
17
17
|
coderay (1.1.3)
|
|
18
|
-
concurrent-ruby (1.3.
|
|
18
|
+
concurrent-ruby (1.3.7)
|
|
19
19
|
crack (1.0.0)
|
|
20
20
|
bigdecimal
|
|
21
21
|
rexml
|
|
@@ -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 ChargeMessageApiSource
|
|
18
|
+
UNSPECIFIED = "API_SOURCE_UNSPECIFIED".freeze
|
|
19
|
+
OFF_SESSION_SYNC = "API_SOURCE_OFF_SESSION_SYNC".freeze
|
|
20
|
+
OFF_SESSION_ASYNC = "API_SOURCE_OFF_SESSION_ASYNC".freeze
|
|
21
|
+
ON_SESSION = "API_SOURCE_ON_SESSION".freeze
|
|
22
|
+
|
|
23
|
+
def self.all_vars
|
|
24
|
+
@all_vars ||= [UNSPECIFIED, OFF_SESSION_SYNC, OFF_SESSION_ASYNC, ON_SESSION].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 ChargeMessageApiSource.all_vars.include?(value)
|
|
39
|
+
raise "Invalid ENUM value #{value} for class #ChargeMessageApiSource"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -62,6 +62,8 @@ module Api
|
|
|
62
62
|
|
|
63
63
|
attr_accessor :refund
|
|
64
64
|
|
|
65
|
+
attr_accessor :api_source
|
|
66
|
+
|
|
65
67
|
class EnumAttributeValidator
|
|
66
68
|
attr_reader :datatype
|
|
67
69
|
attr_reader :allowable_values
|
|
@@ -105,7 +107,8 @@ module Api
|
|
|
105
107
|
:'consumption_tax' => :'consumptionTax',
|
|
106
108
|
:'error' => :'error',
|
|
107
109
|
:'refund_id' => :'refundId',
|
|
108
|
-
:'refund' => :'refund'
|
|
110
|
+
:'refund' => :'refund',
|
|
111
|
+
:'api_source' => :'apiSource'
|
|
109
112
|
}
|
|
110
113
|
end
|
|
111
114
|
|
|
@@ -135,7 +138,8 @@ module Api
|
|
|
135
138
|
:'consumption_tax' => :'Integer',
|
|
136
139
|
:'error' => :'Apiv1Error',
|
|
137
140
|
:'refund_id' => :'String',
|
|
138
|
-
:'refund' => :'RefundInfo'
|
|
141
|
+
:'refund' => :'RefundInfo',
|
|
142
|
+
:'api_source' => :'ChargeMessageApiSource'
|
|
139
143
|
}
|
|
140
144
|
end
|
|
141
145
|
|
|
@@ -237,6 +241,12 @@ module Api
|
|
|
237
241
|
if attributes.key?(:'refund')
|
|
238
242
|
self.refund = attributes[:'refund']
|
|
239
243
|
end
|
|
244
|
+
|
|
245
|
+
if attributes.key?(:'api_source')
|
|
246
|
+
self.api_source = attributes[:'api_source']
|
|
247
|
+
else
|
|
248
|
+
self.api_source = 'API_SOURCE_UNSPECIFIED'
|
|
249
|
+
end
|
|
240
250
|
end
|
|
241
251
|
|
|
242
252
|
# Show invalid properties with the reasons. Usually used together with valid?
|
|
@@ -277,7 +287,8 @@ module Api
|
|
|
277
287
|
consumption_tax == o.consumption_tax &&
|
|
278
288
|
error == o.error &&
|
|
279
289
|
refund_id == o.refund_id &&
|
|
280
|
-
refund == o.refund
|
|
290
|
+
refund == o.refund &&
|
|
291
|
+
api_source == o.api_source
|
|
281
292
|
end
|
|
282
293
|
|
|
283
294
|
# @see the `==` method
|
|
@@ -289,7 +300,7 @@ module Api
|
|
|
289
300
|
# Calculates hash code according to all attributes.
|
|
290
301
|
# @return [Integer] Hash code
|
|
291
302
|
def hash
|
|
292
|
-
[id, customer, status, description, merchant_name, initial_amount, discount, final_amount, amount_refunded, currency, processed_at, jamm_fee, created_at, updated_at, original_transaction_jamm_fee, consumption_tax, error, refund_id, refund].hash
|
|
303
|
+
[id, customer, status, description, merchant_name, initial_amount, discount, final_amount, amount_refunded, currency, processed_at, jamm_fee, created_at, updated_at, original_transaction_jamm_fee, consumption_tax, error, refund_id, refund, api_source].hash
|
|
293
304
|
end
|
|
294
305
|
|
|
295
306
|
# Builds the object from hash
|
|
@@ -37,6 +37,7 @@ module Api
|
|
|
37
37
|
PAYMENT_CHARGE_INSUFFICIENT_FUNDS = "ERROR_TYPE_PAYMENT_CHARGE_INSUFFICIENT_FUNDS".freeze
|
|
38
38
|
PAYMENT_CUSTOMER_NOT_FOUND = "ERROR_TYPE_PAYMENT_CUSTOMER_NOT_FOUND".freeze
|
|
39
39
|
PAYMENT_CUSTOMER_INACTIVE = "ERROR_TYPE_PAYMENT_CUSTOMER_INACTIVE".freeze
|
|
40
|
+
PAYMENT_SERVICE_DISABLED = "ERROR_TYPE_PAYMENT_SERVICE_DISABLED".freeze
|
|
40
41
|
CSV_VALIDATION_FAILED = "ERROR_TYPE_CSV_VALIDATION_FAILED".freeze
|
|
41
42
|
CSV_TOTP_REQUIRED = "ERROR_TYPE_CSV_TOTP_REQUIRED".freeze
|
|
42
43
|
CSV_TOTP_INVALID = "ERROR_TYPE_CSV_TOTP_INVALID".freeze
|
|
@@ -54,7 +55,7 @@ module Api
|
|
|
54
55
|
TOTP_DISABLE_FAILED = "ERROR_TYPE_TOTP_DISABLE_FAILED".freeze
|
|
55
56
|
|
|
56
57
|
def self.all_vars
|
|
57
|
-
@all_vars ||= [UNSPECIFIED, AUTH_FAILED, AUTH_REJECTED, ACCOUNT_CREATION_FAILED, ACCOUNT_MODIFICATION_FAILED, ACCOUNT_DELETION_FAILED, ACCOUNT_BANK_REGISTRATION_FAILED, KYC_REJECTED, NOTIFICATION_WEBHOOK_FAILED, NOTIFICATION_EMAIL_FAILED, NOTIFICATION_SMS_FAILED, PAYMENT_GATEWAY_UNAVAILABLE, PAYMENT_GATEWAY_FAILED, PAYMENT_VALIDATION_FAILED, PAYMENT_CHARGE_FAILED, PAYMENT_CHARGE_REJECTED, PAYMENT_CHARGE_OVER_LIMIT, PAYMENT_CHARGE_SUBSCRIPTION_EXPIRED, PAYMENT_LINK_EXPIRED, PAYMENT_CHARGE_INSUFFICIENT_FUNDS, PAYMENT_CUSTOMER_NOT_FOUND, PAYMENT_CUSTOMER_INACTIVE, CSV_VALIDATION_FAILED, CSV_TOTP_REQUIRED, CSV_TOTP_INVALID, CSV_TOTP_EXPIRED, CSV_TOTP_LOCKED, CSV_BATCH_TOO_LARGE, CSV_CUSTOMER_NOT_FOUND, CSV_PROCESSING_FAILED, CSV_CHALLENGE_NOT_FOUND, CSV_DUPLICATE_USER, TOTP_SETUP_FAILED, TOTP_ALREADY_ENABLED, TOTP_NOT_ENABLED, TOTP_SETUP_INVALID, TOTP_DISABLE_FAILED].freeze
|
|
58
|
+
@all_vars ||= [UNSPECIFIED, AUTH_FAILED, AUTH_REJECTED, ACCOUNT_CREATION_FAILED, ACCOUNT_MODIFICATION_FAILED, ACCOUNT_DELETION_FAILED, ACCOUNT_BANK_REGISTRATION_FAILED, KYC_REJECTED, NOTIFICATION_WEBHOOK_FAILED, NOTIFICATION_EMAIL_FAILED, NOTIFICATION_SMS_FAILED, PAYMENT_GATEWAY_UNAVAILABLE, PAYMENT_GATEWAY_FAILED, PAYMENT_VALIDATION_FAILED, PAYMENT_CHARGE_FAILED, PAYMENT_CHARGE_REJECTED, PAYMENT_CHARGE_OVER_LIMIT, PAYMENT_CHARGE_SUBSCRIPTION_EXPIRED, PAYMENT_LINK_EXPIRED, PAYMENT_CHARGE_INSUFFICIENT_FUNDS, PAYMENT_CUSTOMER_NOT_FOUND, PAYMENT_CUSTOMER_INACTIVE, PAYMENT_SERVICE_DISABLED, CSV_VALIDATION_FAILED, CSV_TOTP_REQUIRED, CSV_TOTP_INVALID, CSV_TOTP_EXPIRED, CSV_TOTP_LOCKED, CSV_BATCH_TOO_LARGE, CSV_CUSTOMER_NOT_FOUND, CSV_PROCESSING_FAILED, CSV_CHALLENGE_NOT_FOUND, CSV_DUPLICATE_USER, TOTP_SETUP_FAILED, TOTP_ALREADY_ENABLED, TOTP_NOT_ENABLED, TOTP_SETUP_INVALID, TOTP_DISABLE_FAILED].freeze
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
# Builds the enum from string
|
|
@@ -22,7 +22,7 @@ module Api
|
|
|
22
22
|
# Description is an arbitrary string for merchant to track the charge. This information is displayed on Merchant Dashboard. 決済の説明。ショップが決済を追跡するための任意の文字列です。 @gotags: validate:\"required,max=1024\"
|
|
23
23
|
attr_accessor :description
|
|
24
24
|
|
|
25
|
-
# Arbitrary key-value additional information about the charge. You can see this information in our merchant dashboard. ## Testing with triggerError Set the key \"triggerError\" to a valid ERROR_TYPE_* enum name (e.g. \"ERROR_TYPE_PAYMENT_CHARGE_FAILED\") to simulate a payment failure. Behavior differs by flow: Off-session (Withdraw, WithdrawAsync, OffSessionPayment, OffSessionPaymentAsync): Reads triggerError from this field (charge.metadata). Creates a failed transaction record and sends a failure webhook. Returns transport-level 400 for ERROR_TYPE_PAYMENT_VALIDATION_FAILED, 500 for all other ERROR_TYPE_* values. On-session (InitiatePayment / ApprovePayment — consumer-facing core service): Reads triggerError from the payment's stored metadata (charge or merchant-customer). Initiate stage: only ERROR_TYPE_PAYMENT_VALIDATION_FAILED and ERROR_TYPE_PAYMENT_LINK_EXPIRED are honored; other types are ignored. No failed transaction or webhook is created. Returns 200 OK with an embedded InitiatePaymentError payload. Approve stage: all ERROR_TYPE_* values are honored. Creates workflow-specific failure records (cancelled contract and/or failed transaction depending on the workflow type). Returns 200 OK with
|
|
25
|
+
# Arbitrary key-value additional information about the charge. You can see this information in our merchant dashboard. ## Testing with triggerError Set the key \"triggerError\" to a valid ERROR_TYPE_* enum name (e.g. \"ERROR_TYPE_PAYMENT_CHARGE_FAILED\") to simulate a payment failure. Behavior differs by flow: Off-session (Withdraw, WithdrawAsync, OffSessionPayment, OffSessionPaymentAsync): Reads triggerError from this field (charge.metadata). Creates a failed transaction record and sends a failure webhook. Returns transport-level 400 for ERROR_TYPE_PAYMENT_VALIDATION_FAILED, 500 for all other ERROR_TYPE_* values. On-session (InitiatePayment / ApprovePayment — consumer-facing core service): Reads triggerError from the payment's stored metadata (charge or merchant-customer). Initiate stage: only ERROR_TYPE_PAYMENT_VALIDATION_FAILED and ERROR_TYPE_PAYMENT_LINK_EXPIRED are honored; other types are ignored. No failed transaction or webhook is created. Returns 200 OK with an embedded InitiatePaymentError payload. Approve stage: all ERROR_TYPE_* values are honored. Creates workflow-specific failure records (cancelled contract and/or failed transaction depending on the workflow type). For charge-bearing workflows it also sends a charge.fail webhook (api_source ON_SESSION), mirroring off-session triggerError and real on-session failures. Returns 200 OK with an embedded ApprovePaymentError payload. Note: CreateContractWithoutCharge has no charge, so this field does not apply. On-session triggerError for that flow is read from merchant-customer metadata instead. ## Error types by payment stage Initiate (payment session setup, workflow creation): - ERROR_TYPE_PAYMENT_VALIDATION_FAILED — invalid request - ERROR_TYPE_PAYMENT_LINK_EXPIRED — payment link expired Approve (pre-charge validation + BankPay charge execution): - ERROR_TYPE_PAYMENT_VALIDATION_FAILED — invalid request (e.g. deleted/inactive customer) - ERROR_TYPE_PAYMENT_CHARGE_REJECTED — KYC not approved - ERROR_TYPE_PAYMENT_CHARGE_OVER_LIMIT — charge exceeds bank quota - ERROR_TYPE_PAYMENT_LINK_EXPIRED — payment link expired - ERROR_TYPE_PAYMENT_GATEWAY_UNAVAILABLE — BankPay/bank under maintenance - ERROR_TYPE_PAYMENT_CHARGE_INSUFFICIENT_FUNDS — insufficient funds in customer's account - ERROR_TYPE_PAYMENT_GATEWAY_FAILED — BankPay rejected the charge - ERROR_TYPE_PAYMENT_CHARGE_FAILED — generic charge failure (internal, not found, etc.) Chargeに関する任意のキーと値の追加情報。 加盟店ダッシュボードで確認できます。 テスト環境では、\"triggerError\" キーに ERROR_TYPE_* の列挙名を設定すると 決済エラーをシミュレートできます。動作はフローによって異なります。 詳細は上記の英語コメントを参照してください。
|
|
26
26
|
attr_accessor :metadata
|
|
27
27
|
|
|
28
28
|
# Fee charged by the platform (in JPY). Must be >= the Jamm fee for the merchant. Only meaningful when the caller is a platform. Ignored for direct merchant calls. プラットフォームが徴収する手数料(日本円)。加盟店のJamm手数料以上である必要があります。
|
|
@@ -17,7 +17,7 @@ module Api
|
|
|
17
17
|
# RefundInfo contains refund-specific details for refund and refund_failed webhook events.
|
|
18
18
|
class RefundInfo
|
|
19
19
|
# External refund identifier (rfd-*).
|
|
20
|
-
attr_accessor :
|
|
20
|
+
attr_accessor :id
|
|
21
21
|
|
|
22
22
|
# Amount refunded for this event.
|
|
23
23
|
attr_accessor :amount_refunded
|
|
@@ -39,7 +39,7 @@ module Api
|
|
|
39
39
|
# Attribute mapping from ruby-style variable name to JSON key.
|
|
40
40
|
def self.attribute_map
|
|
41
41
|
{
|
|
42
|
-
:'
|
|
42
|
+
:'id' => :'id',
|
|
43
43
|
:'amount_refunded' => :'amountRefunded',
|
|
44
44
|
:'jamm_fee' => :'jammFee',
|
|
45
45
|
:'consumption_tax' => :'consumptionTax',
|
|
@@ -57,7 +57,7 @@ module Api
|
|
|
57
57
|
# Attribute type mapping.
|
|
58
58
|
def self.openapi_types
|
|
59
59
|
{
|
|
60
|
-
:'
|
|
60
|
+
:'id' => :'String',
|
|
61
61
|
:'amount_refunded' => :'Integer',
|
|
62
62
|
:'jamm_fee' => :'Integer',
|
|
63
63
|
:'consumption_tax' => :'Integer',
|
|
@@ -88,8 +88,8 @@ module Api
|
|
|
88
88
|
h[k.to_sym] = v
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
if attributes.key?(:'
|
|
92
|
-
self.
|
|
91
|
+
if attributes.key?(:'id')
|
|
92
|
+
self.id = attributes[:'id']
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
if attributes.key?(:'amount_refunded')
|
|
@@ -137,7 +137,7 @@ module Api
|
|
|
137
137
|
def ==(o)
|
|
138
138
|
return true if self.equal?(o)
|
|
139
139
|
self.class == o.class &&
|
|
140
|
-
|
|
140
|
+
id == o.id &&
|
|
141
141
|
amount_refunded == o.amount_refunded &&
|
|
142
142
|
jamm_fee == o.jamm_fee &&
|
|
143
143
|
consumption_tax == o.consumption_tax &&
|
|
@@ -155,7 +155,7 @@ module Api
|
|
|
155
155
|
# Calculates hash code according to all attributes.
|
|
156
156
|
# @return [Integer] Hash code
|
|
157
157
|
def hash
|
|
158
|
-
[
|
|
158
|
+
[id, amount_refunded, jamm_fee, consumption_tax, original_transaction_fee_waived, error, processed_at].hash
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
# 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'
|
data/lib/jamm/version.rb
CHANGED
data/lib/jamm/webhook.rb
CHANGED
|
@@ -11,39 +11,157 @@ 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
|
-
|
|
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)
|
|
15
21
|
|
|
16
22
|
case json[:event_type]
|
|
17
|
-
when Jamm::OpenAPI::EventType::CHARGE_CREATED
|
|
18
|
-
|
|
23
|
+
when Jamm::OpenAPI::EventType::CHARGE_CREATED,
|
|
24
|
+
Jamm::OpenAPI::EventType::CHARGE_UPDATED,
|
|
25
|
+
Jamm::OpenAPI::EventType::REFUND_SUCCEEDED,
|
|
26
|
+
Jamm::OpenAPI::EventType::REFUND_FAILED,
|
|
27
|
+
Jamm::OpenAPI::EventType::CHARGE_SUCCESS,
|
|
28
|
+
Jamm::OpenAPI::EventType::CHARGE_FAIL
|
|
29
|
+
out.content = build(Jamm::OpenAPI::ChargeMessage, flatten_charge_content(json[:content]))
|
|
19
30
|
return out
|
|
20
31
|
|
|
21
|
-
when Jamm::OpenAPI::EventType::
|
|
22
|
-
out.content = Jamm::OpenAPI::
|
|
32
|
+
when Jamm::OpenAPI::EventType::CONTRACT_ACTIVATED
|
|
33
|
+
out.content = build(Jamm::OpenAPI::ContractMessage, json[:content])
|
|
23
34
|
return out
|
|
24
35
|
|
|
25
|
-
when Jamm::OpenAPI::EventType::
|
|
26
|
-
out.content = Jamm::OpenAPI::
|
|
36
|
+
when Jamm::OpenAPI::EventType::USER_ACCOUNT_DELETED
|
|
37
|
+
out.content = build(Jamm::OpenAPI::UserAccountMessage, json[:content])
|
|
27
38
|
return out
|
|
39
|
+
end
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return out
|
|
41
|
+
raise 'Unknown event type'
|
|
42
|
+
end
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
# Build a generated model from a webhook payload while normalizing the
|
|
45
|
+
# quirks of the webhook wire format. Applied to every model, so charges,
|
|
46
|
+
# contracts, user-account and refund messages all benefit:
|
|
47
|
+
#
|
|
48
|
+
# 1. Forward-compat: the Jamm backend can add new fields to webhook
|
|
49
|
+
# payloads at any time. The generated model `initialize` raises
|
|
50
|
+
# ArgumentError on any key outside `attribute_map`, so unknown keys are
|
|
51
|
+
# dropped first. Known keys are snake_case, matching `attribute_map`.
|
|
52
|
+
# 2. Numeric enums: the backend serializes webhook payloads with Go's
|
|
53
|
+
# `json.Marshal` (not protojson), so every enum field (status,
|
|
54
|
+
# api_source, ...) arrives as its integer value, while the generated
|
|
55
|
+
# enums are string-based. Each integer is mapped back to the enum string
|
|
56
|
+
# so it matches the values returned by the REST API.
|
|
57
|
+
# 3. Nested models: the generated `initialize` assigns nested objects
|
|
58
|
+
# verbatim (the `_deserialize` coercion only runs from `build_from_hash`,
|
|
59
|
+
# which expects camelCase keys the webhook does not use). So a nested
|
|
60
|
+
# field like `refund.error` would stay a raw Hash and `error.code` would
|
|
61
|
+
# raise NoMethodError. We coerce nested model fields (and arrays of them)
|
|
62
|
+
# recursively so the typed accessors work.
|
|
63
|
+
def self.build(klass, attributes)
|
|
64
|
+
return nil if attributes.nil?
|
|
65
|
+
|
|
66
|
+
known = klass.attribute_map
|
|
67
|
+
types = klass.openapi_types
|
|
68
|
+
filtered = attributes.each_with_object({}) do |(key, value), acc|
|
|
69
|
+
sym = key.to_sym
|
|
70
|
+
next unless known.key?(sym)
|
|
71
|
+
|
|
72
|
+
acc[sym] = coerce(types[sym], value)
|
|
73
|
+
end
|
|
36
74
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return out
|
|
75
|
+
klass.new(filtered)
|
|
76
|
+
end
|
|
40
77
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
78
|
+
# Refund webhooks (REFUND_SUCCEEDED / REFUND_FAILED) deliver `content` as a
|
|
79
|
+
# nested { transaction, refund } wrapper instead of a flat ChargeMessage.
|
|
80
|
+
# Flatten it back into a ChargeMessage so callers always receive the same shape.
|
|
81
|
+
def self.flatten_charge_content(content)
|
|
82
|
+
return content unless content.is_a?(Hash) && content.key?(:transaction)
|
|
83
|
+
|
|
84
|
+
refund = content[:refund]
|
|
85
|
+
# Keep `refund` as the raw Hash: `build` coerces it into a typed RefundInfo
|
|
86
|
+
# (and recursively types its nested `error`). Also surface the refund's
|
|
87
|
+
# `rfd-` id on the flat `refund_id` attribute the model documents.
|
|
88
|
+
charge = content[:transaction].merge(refund: refund)
|
|
89
|
+
charge[:refund_id] = refund[:id] if refund.is_a?(Hash) && !refund[:id].nil?
|
|
90
|
+
charge
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Coerce a raw webhook value into the shape the generated model expects,
|
|
94
|
+
# based on the field's openapi type: numeric enums become their string
|
|
95
|
+
# constant, nested models become typed instances, and `Array<T>` elements are
|
|
96
|
+
# coerced by `T`. Anything else passes through untouched.
|
|
97
|
+
def self.coerce(type, value)
|
|
98
|
+
return value if value.nil?
|
|
99
|
+
|
|
100
|
+
inner = array_inner_type(type)
|
|
101
|
+
return coerce_array(inner, value) unless inner.nil?
|
|
102
|
+
|
|
103
|
+
klass = openapi_const(type)
|
|
104
|
+
return value if klass.nil?
|
|
105
|
+
|
|
106
|
+
if klass.respond_to?(:all_vars)
|
|
107
|
+
resolve_enum(klass, value)
|
|
108
|
+
elsif klass.respond_to?(:openapi_types) && value.is_a?(Hash)
|
|
109
|
+
build(klass, value)
|
|
110
|
+
else
|
|
111
|
+
value
|
|
44
112
|
end
|
|
113
|
+
end
|
|
45
114
|
|
|
46
|
-
|
|
115
|
+
# Coerce each element of an `Array<T>` field by its inner type `T`.
|
|
116
|
+
def self.coerce_array(inner_type, value)
|
|
117
|
+
return value unless value.is_a?(Array)
|
|
118
|
+
|
|
119
|
+
value.map { |element| coerce(inner_type, element) }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Extract `T` from an `Array<T>` openapi type, or nil when not an array type.
|
|
123
|
+
def self.array_inner_type(type)
|
|
124
|
+
match = type.to_s.match(/\AArray<(.+)>\z/)
|
|
125
|
+
match && match[1]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Map a numeric enum wire value onto its string enum constant. A value that
|
|
129
|
+
# is already a string (REST-style) passes through untouched.
|
|
130
|
+
def self.resolve_enum(enum, value)
|
|
131
|
+
return value unless value.is_a?(Integer)
|
|
132
|
+
|
|
133
|
+
vars = enum.all_vars
|
|
134
|
+
# Guard the bounds explicitly: Ruby maps negative indices from the end of
|
|
135
|
+
# the array, so any unexpected wire value must fall back to the *_UNSPECIFIED
|
|
136
|
+
# member (index 0) rather than silently selecting the wrong constant.
|
|
137
|
+
value.between?(0, vars.length - 1) ? vars[value] : vars[0]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Resolve an openapi_types entry (e.g. :ChargeMessageApiSource, :RefundInfo)
|
|
141
|
+
# to its generated class, or nil when the type is a primitive (String,
|
|
142
|
+
# Integer, ...) or otherwise unresolvable.
|
|
143
|
+
def self.openapi_const(type)
|
|
144
|
+
return nil if type.nil?
|
|
145
|
+
|
|
146
|
+
name = type.to_s
|
|
147
|
+
return nil unless Jamm::OpenAPI.const_defined?(name)
|
|
148
|
+
|
|
149
|
+
Jamm::OpenAPI.const_get(name)
|
|
150
|
+
rescue NameError
|
|
151
|
+
nil
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Recursively convert Hash keys to symbols so parsing is robust regardless of
|
|
155
|
+
# how the caller decoded the webhook JSON.
|
|
156
|
+
def self.deep_symbolize_keys(value)
|
|
157
|
+
case value
|
|
158
|
+
when Hash
|
|
159
|
+
value.each_with_object({}) { |(k, v), acc| acc[k.to_sym] = deep_symbolize_keys(v) }
|
|
160
|
+
when Array
|
|
161
|
+
value.map { |v| deep_symbolize_keys(v) }
|
|
162
|
+
else
|
|
163
|
+
value
|
|
164
|
+
end
|
|
47
165
|
end
|
|
48
166
|
|
|
49
167
|
# Verify message.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jamm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jamm
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- lib/jamm/api/configuration.rb
|
|
85
85
|
- lib/jamm/api/models/apiv1_error.rb
|
|
86
86
|
- lib/jamm/api/models/apiv1_status.rb
|
|
87
|
+
- lib/jamm/api/models/charge_message_api_source.rb
|
|
87
88
|
- lib/jamm/api/models/customer_service_update_customer_body.rb
|
|
88
89
|
- lib/jamm/api/models/googlerpc_status.rb
|
|
89
90
|
- lib/jamm/api/models/protobuf_any.rb
|