jamm 2.1.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 +82 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +8 -5
- data/jamm.gemspec +1 -0
- data/lib/jamm/api/api/payment_api.rb +10 -10
- 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 +4 -1
- data/lib/jamm/api/models/v1_initial_charge.rb +1 -1
- data/lib/jamm/api/models/v1_off_session_payment_async_request.rb +15 -5
- data/lib/jamm/api/models/v1_off_session_payment_request.rb +1 -1
- data/lib/jamm/api/models/v1_on_session_payment_request.rb +1 -1
- data/lib/jamm/api/models/v1_refund_info.rb +7 -7
- data/lib/jamm/api/models/v1_withdraw_async_request.rb +15 -5
- data/lib/jamm/api/models/v1_withdraw_request.rb +1 -1
- data/lib/jamm/api.rb +1 -0
- data/lib/jamm/payment.rb +24 -0
- data/lib/jamm/version.rb +1 -1
- data/lib/jamm/webhook.rb +138 -20
- metadata +18 -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
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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.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
|
+
|
|
24
|
+
## [2.2.0] - 2026-05-20
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- Added `Jamm::Payment.off_session_async` for async off-session charges
|
|
29
|
+
- Auto-fill `idempotency_key` with a UUID when `nil` or blank
|
|
30
|
+
|
|
31
|
+
## [2.1.0] - 2026-04-06
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- Added `ChargeError` details on `ChargeResult` for failed charges
|
|
36
|
+
|
|
37
|
+
## [2.0.0] - 2026-03-16
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- Platform authentication support
|
|
42
|
+
- Refund support and split refund webhook events (succeeded / rejected)
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- Renamed `cancel` operations to `refund` across API and webhooks
|
|
47
|
+
|
|
48
|
+
## [1.7.0] - 2025-11-11
|
|
49
|
+
|
|
50
|
+
### Removed
|
|
51
|
+
|
|
52
|
+
- Deprecated legacy contract charge public APIs
|
|
53
|
+
|
|
54
|
+
## [1.6.0] - 2025-11-11
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- Version bump aligned with other SDKs
|
|
59
|
+
|
|
60
|
+
## [1.5.0] - 2025-10-09
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
|
|
64
|
+
- `OnSessionPayment` redirect link is now optional
|
|
65
|
+
|
|
66
|
+
## [1.4.1] - 2025-08-22
|
|
67
|
+
|
|
68
|
+
### Changed
|
|
69
|
+
|
|
70
|
+
- Updated RubyGem GitHub source URL
|
|
71
|
+
|
|
72
|
+
## [1.4.0] - 2025-08-22
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
|
|
76
|
+
- On-session and off-session payment support
|
|
77
|
+
|
|
78
|
+
## [1.3.0] - 2025-07-08
|
|
79
|
+
|
|
80
|
+
### Added
|
|
81
|
+
|
|
82
|
+
- Embedded `error.v1` typed errors into OpenAPI proto
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
jamm (2.
|
|
4
|
+
jamm (2.3.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.
|
|
12
|
-
public_suffix (>= 2.0.2, <
|
|
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
|
-
concurrent-ruby (1.3.
|
|
18
|
+
concurrent-ruby (1.3.7)
|
|
17
19
|
crack (1.0.0)
|
|
18
20
|
bigdecimal
|
|
19
21
|
rexml
|
|
@@ -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.
|
|
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
|
@@ -89,7 +89,7 @@ module Api
|
|
|
89
89
|
|
|
90
90
|
# Initiate async off-session payment
|
|
91
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.
|
|
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
93
|
# @param [Hash] opts the optional parameters
|
|
94
94
|
# @return [OffSessionPaymentAsyncResponse]
|
|
95
95
|
def async_off_session_payment(body, opts = {})
|
|
@@ -99,7 +99,7 @@ module Api
|
|
|
99
99
|
|
|
100
100
|
# Initiate async off-session payment
|
|
101
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.
|
|
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
103
|
# @param [Hash] opts the optional parameters
|
|
104
104
|
# @return [Array<(OffSessionPaymentAsyncResponse, Integer, Hash)>] OffSessionPaymentAsyncResponse data, response status code and response headers
|
|
105
105
|
def async_off_session_payment_with_http_info(body, opts = {})
|
|
@@ -425,7 +425,7 @@ module Api
|
|
|
425
425
|
|
|
426
426
|
# Initiate async withdraw (internal)
|
|
427
427
|
# Internal-only endpoint for initiating asynchronous withdrawal processing.
|
|
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.
|
|
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.
|
|
429
429
|
# @param [Hash] opts the optional parameters
|
|
430
430
|
# @return [WithdrawAsyncResponse]
|
|
431
431
|
def internal_withdraw_async(body, opts = {})
|
|
@@ -435,7 +435,7 @@ module Api
|
|
|
435
435
|
|
|
436
436
|
# Initiate async withdraw (internal)
|
|
437
437
|
# Internal-only endpoint for initiating asynchronous withdrawal processing.
|
|
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.
|
|
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.
|
|
439
439
|
# @param [Hash] opts the optional parameters
|
|
440
440
|
# @return [Array<(WithdrawAsyncResponse, Integer, Hash)>] WithdrawAsyncResponse data, response status code and response headers
|
|
441
441
|
def internal_withdraw_async_with_http_info(body, opts = {})
|
|
@@ -561,7 +561,7 @@ module Api
|
|
|
561
561
|
|
|
562
562
|
# Process payment directly without redirect
|
|
563
563
|
# Execute a payment off-session within your application without redirecting to a payment page.
|
|
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.
|
|
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.
|
|
565
565
|
# @param [Hash] opts the optional parameters
|
|
566
566
|
# @return [OffSessionPaymentResponse]
|
|
567
567
|
def off_session_payment(body, opts = {})
|
|
@@ -571,7 +571,7 @@ module Api
|
|
|
571
571
|
|
|
572
572
|
# Process payment directly without redirect
|
|
573
573
|
# Execute a payment off-session within your application without redirecting to a payment page.
|
|
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.
|
|
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.
|
|
575
575
|
# @param [Hash] opts the optional parameters
|
|
576
576
|
# @return [Array<(OffSessionPaymentResponse, Integer, Hash)>] OffSessionPaymentResponse data, response status code and response headers
|
|
577
577
|
def off_session_payment_with_http_info(body, opts = {})
|
|
@@ -629,7 +629,7 @@ module Api
|
|
|
629
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 = {})
|
|
@@ -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 = {})
|
|
@@ -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
|
|
@@ -35,6 +35,9 @@ module Api
|
|
|
35
35
|
PAYMENT_CHARGE_SUBSCRIPTION_EXPIRED = "ERROR_TYPE_PAYMENT_CHARGE_SUBSCRIPTION_EXPIRED".freeze
|
|
36
36
|
PAYMENT_LINK_EXPIRED = "ERROR_TYPE_PAYMENT_LINK_EXPIRED".freeze
|
|
37
37
|
PAYMENT_CHARGE_INSUFFICIENT_FUNDS = "ERROR_TYPE_PAYMENT_CHARGE_INSUFFICIENT_FUNDS".freeze
|
|
38
|
+
PAYMENT_CUSTOMER_NOT_FOUND = "ERROR_TYPE_PAYMENT_CUSTOMER_NOT_FOUND".freeze
|
|
39
|
+
PAYMENT_CUSTOMER_INACTIVE = "ERROR_TYPE_PAYMENT_CUSTOMER_INACTIVE".freeze
|
|
40
|
+
PAYMENT_SERVICE_DISABLED = "ERROR_TYPE_PAYMENT_SERVICE_DISABLED".freeze
|
|
38
41
|
CSV_VALIDATION_FAILED = "ERROR_TYPE_CSV_VALIDATION_FAILED".freeze
|
|
39
42
|
CSV_TOTP_REQUIRED = "ERROR_TYPE_CSV_TOTP_REQUIRED".freeze
|
|
40
43
|
CSV_TOTP_INVALID = "ERROR_TYPE_CSV_TOTP_INVALID".freeze
|
|
@@ -52,7 +55,7 @@ module Api
|
|
|
52
55
|
TOTP_DISABLE_FAILED = "ERROR_TYPE_TOTP_DISABLE_FAILED".freeze
|
|
53
56
|
|
|
54
57
|
def self.all_vars
|
|
55
|
-
@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, 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
|
|
56
59
|
end
|
|
57
60
|
|
|
58
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. Chargeに関する任意のキーと値の追加情報。 加盟店ダッシュボードで確認できます。
|
|
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手数料以上である必要があります。
|
|
@@ -14,17 +14,21 @@ require 'date'
|
|
|
14
14
|
require 'time'
|
|
15
15
|
|
|
16
16
|
module Api
|
|
17
|
-
# This message represents a request to process an off-session payment asynchronously. It contains the customer ID and the amount to charge.
|
|
17
|
+
# 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.
|
|
18
18
|
class OffSessionPaymentAsyncRequest
|
|
19
19
|
attr_accessor :customer
|
|
20
20
|
|
|
21
21
|
attr_accessor :charge
|
|
22
22
|
|
|
23
|
+
# Merchant-supplied idempotency key for retry safety. When present, a retry with the same (merchant, idempotency_key) returns the original charge instead of creating a new one. When absent (empty), the server generates a UUID per call (current behavior). 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
|
|
@@ -14,7 +14,7 @@ require 'date'
|
|
|
14
14
|
require 'time'
|
|
15
15
|
|
|
16
16
|
module Api
|
|
17
|
-
# This message represents a request to process a payment directly within the application. It contains the customer ID and charge details to be processed.
|
|
17
|
+
# 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.
|
|
18
18
|
class OffSessionPaymentRequest
|
|
19
19
|
attr_accessor :customer
|
|
20
20
|
|
|
@@ -14,7 +14,7 @@ require 'date'
|
|
|
14
14
|
require 'time'
|
|
15
15
|
|
|
16
16
|
module Api
|
|
17
|
-
# Request message for the unified payment interface. The system intelligently routes the request to the appropriate payment method based on the provided parameters.
|
|
17
|
+
# 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.
|
|
18
18
|
class OnSessionPaymentRequest
|
|
19
19
|
attr_accessor :customer
|
|
20
20
|
|
|
@@ -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
|
|
@@ -14,17 +14,21 @@ require 'date'
|
|
|
14
14
|
require 'time'
|
|
15
15
|
|
|
16
16
|
module Api
|
|
17
|
-
# This message represents a request to withdraw money from a customer asynchronously. It contains the customer ID and the amount to withdraw.
|
|
17
|
+
# 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.
|
|
18
18
|
class WithdrawAsyncRequest
|
|
19
19
|
attr_accessor :customer
|
|
20
20
|
|
|
21
21
|
attr_accessor :charge
|
|
22
22
|
|
|
23
|
+
# Merchant-supplied idempotency key for retry safety. When present, a retry with the same (merchant, idempotency_key) returns the original charge instead of creating a new one. When absent (empty), the server generates a UUID per call (current behavior). 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
|
|
@@ -14,7 +14,7 @@ require 'date'
|
|
|
14
14
|
require 'time'
|
|
15
15
|
|
|
16
16
|
module Api
|
|
17
|
-
# This message represents a request to withdraw money from a customer. It contains the customer ID and the amount to withdraw.
|
|
17
|
+
# 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.
|
|
18
18
|
class WithdrawRequest
|
|
19
19
|
attr_accessor :customer
|
|
20
20
|
|
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/payment.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require 'rest-client'
|
|
4
4
|
require 'json'
|
|
5
5
|
require 'base64'
|
|
6
|
+
require 'securerandom'
|
|
6
7
|
require 'jamm/errors'
|
|
7
8
|
|
|
8
9
|
module Jamm
|
|
@@ -50,6 +51,29 @@ module Jamm
|
|
|
50
51
|
raise Jamm::ApiError.from_error(e)
|
|
51
52
|
end
|
|
52
53
|
|
|
54
|
+
# Auto-fills idempotency_key with a UUID when the caller did not supply one,
|
|
55
|
+
# so every async charge is retry-safe by default. A caller-supplied key is
|
|
56
|
+
# left untouched so explicit retries reuse the same value.
|
|
57
|
+
def self.off_session_async(customer:, charge:, idempotency_key: nil, merchant: nil)
|
|
58
|
+
key =
|
|
59
|
+
if idempotency_key.nil? || idempotency_key.strip.empty?
|
|
60
|
+
SecureRandom.uuid
|
|
61
|
+
else
|
|
62
|
+
idempotency_key
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
request = Jamm::OpenAPI::OffSessionPaymentAsyncRequest.new(
|
|
66
|
+
customer: customer,
|
|
67
|
+
charge: charge,
|
|
68
|
+
idempotency_key: key
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
handler = Jamm::Client.handler(merchant: merchant)
|
|
72
|
+
Jamm::OpenAPI::PaymentApi.new(handler).async_off_session_payment(request)
|
|
73
|
+
rescue Jamm::OpenAPI::ApiError => e
|
|
74
|
+
raise Jamm::ApiError.from_error(e)
|
|
75
|
+
end
|
|
76
|
+
|
|
53
77
|
def self.get(charge_id, merchant: nil)
|
|
54
78
|
handler = Jamm::Client.handler(merchant: merchant)
|
|
55
79
|
|
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,15 +1,29 @@
|
|
|
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
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: base64
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.2'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.2'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: rest-client
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,6 +66,7 @@ extra_rdoc_files: []
|
|
|
52
66
|
files:
|
|
53
67
|
- ".gitignore"
|
|
54
68
|
- ".rubocop.yml"
|
|
69
|
+
- CHANGELOG.md
|
|
55
70
|
- Gemfile
|
|
56
71
|
- Gemfile.lock
|
|
57
72
|
- LICENSE
|
|
@@ -69,6 +84,7 @@ files:
|
|
|
69
84
|
- lib/jamm/api/configuration.rb
|
|
70
85
|
- lib/jamm/api/models/apiv1_error.rb
|
|
71
86
|
- lib/jamm/api/models/apiv1_status.rb
|
|
87
|
+
- lib/jamm/api/models/charge_message_api_source.rb
|
|
72
88
|
- lib/jamm/api/models/customer_service_update_customer_body.rb
|
|
73
89
|
- lib/jamm/api/models/googlerpc_status.rb
|
|
74
90
|
- lib/jamm/api/models/protobuf_any.rb
|