lunixi-sdk 2.0.2 → 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 +28 -0
- data/README.md +43 -4
- data/README.tr.md +28 -3
- data/docs/card-rewards.md +21 -0
- data/lib/lunixi/bank_connect.rb +132 -15
- data/lib/lunixi/bank_connect_filters.rb +13 -3
- data/lib/lunixi/bank_connect_pos.rb +165 -0
- data/lib/lunixi/bank_connect_values.rb +127 -5
- data/lib/lunixi/card_requests.rb +9 -1
- data/lib/lunixi/client.rb +38 -14
- data/lib/lunixi/direct_method_payment_request.rb +24 -2
- data/lib/lunixi/errors.rb +49 -0
- data/lib/lunixi/fraud.rb +3 -2
- data/lib/lunixi/fraud_uk_claims.rb +127 -0
- data/lib/lunixi/fraud_values.rb +46 -0
- data/lib/lunixi/marketplace.rb +2 -0
- data/lib/lunixi/payment_link_rules.rb +13 -1
- data/lib/lunixi/payment_link_values.rb +4 -0
- data/lib/lunixi/payment_links.rb +3 -1
- data/lib/lunixi/payment_values.rb +22 -2
- data/lib/lunixi/payments.rb +62 -6
- data/lib/lunixi/product_webhooks.rb +17 -1
- data/lib/lunixi/refund_to_wallet.rb +94 -0
- data/lib/lunixi/route_table.rb +10 -5
- data/lib/lunixi/routing_pin.rb +247 -0
- data/lib/lunixi/sanction.rb +77 -17
- data/lib/lunixi/sanction_batch.rb +215 -0
- data/lib/lunixi/sanction_values.rb +289 -5
- data/lib/lunixi/split_payment.rb +17 -2
- data/lib/lunixi/subscription_routing.rb +70 -0
- data/lib/lunixi/subscription_values.rb +26 -3
- data/lib/lunixi/subscriptions.rb +22 -2
- data/lib/lunixi/version.rb +1 -1
- data/lib/lunixi/wallet.rb +43 -7
- data/lib/lunixi/wallet_customer_sessions.rb +75 -0
- data/lib/lunixi/wallet_customer_tokens.rb +238 -0
- data/lib/lunixi/wallet_portal.rb +340 -0
- data/lib/lunixi/wallet_portal_routes.rb +171 -0
- data/lib/lunixi/wallet_routes.rb +28 -3
- data/lib/lunixi/wallet_rules.rb +131 -0
- data/lib/lunixi/wallet_values.rb +151 -0
- data/lib/lunixi.rb +12 -0
- metadata +14 -1
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi
|
|
4
|
+
# Wallet portal for one customer: /api/portal/v1/wallet/me/* and auth/email-change with the merchant-vouched session stored
|
|
5
|
+
# under customer_key (client.wallet.portal(customer_key:, token_store:)).
|
|
6
|
+
#
|
|
7
|
+
# Every call sends Authorization: Bearer <accessToken> and the Ed25519 signature of this client's key.
|
|
8
|
+
# The access token is refreshed when it expires within refresh_skew_seconds (default 30) or when the
|
|
9
|
+
# gateway answers 401 AUTH_CUSTOMER_SESSION_INVALID (the request is then sent once more with the new
|
|
10
|
+
# token: it was refused before any work was done).
|
|
11
|
+
#
|
|
12
|
+
# Errors: WalletCustomerSessionExpiredError / WalletCustomerRefreshReusedError (session_ended: the stored
|
|
13
|
+
# tokens are deleted; start a new session), WalletCustomerSessionBindingError (signed with another key
|
|
14
|
+
# than the one that opened the session), otherwise the gateway's ApiError.
|
|
15
|
+
#
|
|
16
|
+
# Money moves in two steps as on the merchant API: initiate_w2w / pay_qr return { operationId,
|
|
17
|
+
# integrityHash, nonce, otpRequired, stepUpRequired, … }; when a step-up is required,
|
|
18
|
+
# start_operation_step_up(operation_id, { password: }) sends a code bound to the operation and
|
|
19
|
+
# verify_operation_step_up(operation_id, { challengeId:, code: }) returns the single-use trustedActionToken
|
|
20
|
+
# for complete_w2w / complete_qr_pay. Bodies are taken whole and checked against WALLET_PORTAL_ROUTES (an
|
|
21
|
+
# unknown field is a ConfigurationError, never dropped); they take the wire names (String or Symbol;
|
|
22
|
+
# snake_case works too).
|
|
23
|
+
class WalletPortal
|
|
24
|
+
ROUTE = %r{\A/api/portal/v1/wallet/}
|
|
25
|
+
DEFAULT_REFRESH_SKEW_SECONDS = 30
|
|
26
|
+
CUSTOMER_KEY_MAX = 512
|
|
27
|
+
|
|
28
|
+
attr_reader :customer_key, :refresh_skew_seconds, :end_user_ip
|
|
29
|
+
|
|
30
|
+
# end_user_ip: sent as X-Lunixi-End-User-Ip on every call of this portal (IPv4 or IPv6, a signal only).
|
|
31
|
+
def initialize(client, tokens, customer_key:, token_store:, refresh_skew_seconds: DEFAULT_REFRESH_SKEW_SECONDS, end_user_ip: nil)
|
|
32
|
+
unless customer_key.is_a?(String) && !customer_key.strip.empty? && customer_key.length <= CUSTOMER_KEY_MAX
|
|
33
|
+
raise ConfigurationError, "customer_key must be a non-empty string of at most #{CUSTOMER_KEY_MAX} characters."
|
|
34
|
+
end
|
|
35
|
+
unless %i[get set delete].all? { |name| token_store.respond_to?(name) }
|
|
36
|
+
raise ConfigurationError, 'token_store must implement get(customer_key), set(customer_key, record) and delete(customer_key).'
|
|
37
|
+
end
|
|
38
|
+
unless refresh_skew_seconds.is_a?(Integer) && refresh_skew_seconds.between?(0, 600)
|
|
39
|
+
raise ConfigurationError, 'refresh_skew_seconds must be an integer 0-600.'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
@client = client
|
|
43
|
+
@tokens = tokens
|
|
44
|
+
@token_store = token_store
|
|
45
|
+
@customer_key = customer_key
|
|
46
|
+
@refresh_skew_seconds = refresh_skew_seconds
|
|
47
|
+
@end_user_ip = end_user_ip.nil? ? nil : WalletRules.end_user_ip!(end_user_ip)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The same portal sending the end user's IP (X-Lunixi-End-User-Ip) on every call.
|
|
51
|
+
def with_end_user_ip(end_user_ip)
|
|
52
|
+
self.class.new(@client, @tokens, customer_key: @customer_key, token_store: @token_store,
|
|
53
|
+
refresh_skew_seconds: @refresh_skew_seconds, end_user_ip: end_user_ip)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Session record
|
|
57
|
+
|
|
58
|
+
# Stores the answer of customer_sessions.complete (or of a refresh you made yourself) for this customer.
|
|
59
|
+
# Returns { 'sessionId', 'expiresAt', 'refreshExpiresAt' } (epoch seconds).
|
|
60
|
+
def save_session(issued)
|
|
61
|
+
record = @tokens.save(@customer_key, @token_store, issued)
|
|
62
|
+
record.slice('sessionId', 'expiresAt', 'refreshExpiresAt')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# True when a session is stored whose refresh token has not expired.
|
|
66
|
+
def has_session? # rubocop:disable Naming/PredicatePrefix -- public portal API (hasSession in every SDK)
|
|
67
|
+
record = @token_store.get(@customer_key)
|
|
68
|
+
record = record.transform_keys(&:to_s) if record.is_a?(Hash)
|
|
69
|
+
record.is_a?(Hash) && record['refreshExpiresAt'].is_a?(Integer) && record['refreshExpiresAt'] > @tokens.now
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Deletes the stored tokens (your logout). It does not revoke anything at the gateway; revoke this
|
|
73
|
+
# installation's access with wallet.customer_sessions.revoke.
|
|
74
|
+
def forget_session
|
|
75
|
+
@token_store.delete(@customer_key)
|
|
76
|
+
nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Account
|
|
80
|
+
|
|
81
|
+
# Identity, program and wallet provisioning state.
|
|
82
|
+
def get_me # rubocop:disable Naming/AccessorMethodName -- portal operation (same name in every SDK)
|
|
83
|
+
data('getMe')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def get_balances # rubocop:disable Naming/AccessorMethodName -- portal operation (same name in every SDK)
|
|
87
|
+
data('getBalances')
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def list_wallets
|
|
91
|
+
data('listWallets')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def get_limits(operation_type: nil, currency: nil)
|
|
95
|
+
data('getLimits', query: { 'operationType' => operation_type, 'currency' => currency })
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Current and effective KYC level and what each level unlocks.
|
|
99
|
+
def get_kyc_level # rubocop:disable Naming/AccessorMethodName -- portal operation (same name in every SDK)
|
|
100
|
+
data('getKycLevel')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Operations
|
|
104
|
+
|
|
105
|
+
# A Lunixi::ListPage; statuses may be an Array (sent comma-separated).
|
|
106
|
+
def list_operations(**filters)
|
|
107
|
+
RouteResponse.page(send_route('listOperations', query: filters))
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def iterate_operations(**filters, &block)
|
|
111
|
+
RouteResponse.each_item(filters, block) { |query| list_operations(**query) }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def get_operation(operation_id)
|
|
115
|
+
data('getOperation', params: { 'operationId' => operation_id })
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def get_operation_receipt(operation_id)
|
|
119
|
+
data('getOperationReceipt', params: { 'operationId' => operation_id })
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Top-up
|
|
123
|
+
|
|
124
|
+
# Card top-up into one of the customer's accounts. Render the answer's form or follow its 3-D Secure
|
|
125
|
+
# redirect; the wallet is credited when the card payment completes.
|
|
126
|
+
def start_card_topup(request, idempotency_key: nil)
|
|
127
|
+
data('startCardTopup', body: request, idempotency_key: idempotency_key)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def get_topup(operation_id)
|
|
131
|
+
data('getTopup', params: { 'operationId' => operation_id })
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Wallet-to-wallet transfer
|
|
135
|
+
|
|
136
|
+
def quote_w2w(request)
|
|
137
|
+
data('quoteW2W', body: request)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def initiate_w2w(request, idempotency_key: nil)
|
|
141
|
+
data('initiateW2W', body: request, idempotency_key: idempotency_key)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# { integrityHash, nonce } from initiate_w2w, plus otpCode and/or trustedActionToken.
|
|
145
|
+
def complete_w2w(operation_id, request, idempotency_key: nil)
|
|
146
|
+
data('completeW2W', params: { 'operationId' => operation_id }, body: request, idempotency_key: idempotency_key)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Step-up (wallet password + operation code)
|
|
150
|
+
|
|
151
|
+
# Checks the wallet password and sends a code bound to this operation (its amount and beneficiary). The
|
|
152
|
+
# key (8–100 of [A-Za-z0-9_-]) is required. Answer: { requiresOtp, otpPurpose, otpChallengeId,
|
|
153
|
+
# otpExpiresAt, otpCodeLength, otpResendAvailableAt, destinationMasked }.
|
|
154
|
+
# request: { password, locale? }.
|
|
155
|
+
def start_operation_step_up(operation_id, request, idempotency_key: nil)
|
|
156
|
+
data('startOperationStepUp', params: { 'operationId' => operation_id }, body: request, idempotency_key: idempotency_key)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# request: { challengeId, code }. Answer: { operationId, trustedActionToken, expiresAt }: the token is
|
|
160
|
+
# single-use and short-lived. The route takes no Idempotency-Key (one given is refused).
|
|
161
|
+
def verify_operation_step_up(operation_id, request, idempotency_key: nil)
|
|
162
|
+
data('verifyOperationStepUp', params: { 'operationId' => operation_id }, body: request, idempotency_key: idempotency_key)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# QR payment
|
|
166
|
+
|
|
167
|
+
# Pays a scanned QR: amount only for a static QR.
|
|
168
|
+
def pay_qr(request, idempotency_key: nil)
|
|
169
|
+
data('payQr', body: request, idempotency_key: idempotency_key)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# { operationId, integrityHash, nonce } from pay_qr, plus otpCode and/or trustedActionToken.
|
|
173
|
+
def complete_qr_pay(qr_id, request, idempotency_key: nil)
|
|
174
|
+
data('completeQrPay', params: { 'qrId' => qr_id }, body: request, idempotency_key: idempotency_key)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Payment code (shown at the till)
|
|
178
|
+
|
|
179
|
+
# The plain code is only in this answer; a new code revokes the previous one.
|
|
180
|
+
def mint_payment_code(currency)
|
|
181
|
+
data('mintPaymentCode', body: { 'currency' => currency })
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def revoke_payment_code
|
|
185
|
+
data('revokePaymentCode')
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Loyalty, cashback, tier
|
|
189
|
+
|
|
190
|
+
def list_loyalty_programs
|
|
191
|
+
data('listLoyaltyPrograms')
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def get_loyalty_balance(loyalty_program_id, lot_limit: nil)
|
|
195
|
+
data('getLoyaltyBalance', query: { 'loyaltyProgramId' => loyalty_program_id, 'lotLimit' => lot_limit })
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def get_loyalty_history(loyalty_program_id, limit: nil)
|
|
199
|
+
data('getLoyaltyHistory', query: { 'loyaltyProgramId' => loyalty_program_id, 'limit' => limit })
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Redeems points into a wallet account. request: { loyaltyProgramId, walletAccountId, points }; the key
|
|
203
|
+
# (8–128 characters) is sent in the body as idempotencyKey.
|
|
204
|
+
def redeem_loyalty_points(request, idempotency_key: nil)
|
|
205
|
+
key = WalletInvoker.idempotency_key!(idempotency_key, 'redeemLoyaltyPoints')
|
|
206
|
+
plain = RouteRequest.wire_hash!(request || {}, 'redeemLoyaltyPoints')
|
|
207
|
+
raise ConfigurationError, 'redeemLoyaltyPoints takes the key as idempotency_key:, not in the body.' if plain.key?('idempotencyKey')
|
|
208
|
+
|
|
209
|
+
data('redeemLoyaltyPoints', body: plain.merge('idempotencyKey' => key))
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def get_cashback(limit: nil)
|
|
213
|
+
data('getCashback', query: { 'limit' => limit })
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def get_tier # rubocop:disable Naming/AccessorMethodName -- portal operation (same name in every SDK)
|
|
217
|
+
data('getTier')
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Phone verification (SMS)
|
|
221
|
+
|
|
222
|
+
# Sends a code by SMS to the identity's phone. Answer: { phoneVerified: false, challengeId,
|
|
223
|
+
# destinationMasked, deliveryChannel: 'SMS', expiresAt, codeLength, resendAvailableAt }, or
|
|
224
|
+
# { phoneVerified: true, phoneVerifiedAt } when it is already verified (no code is sent). 503
|
|
225
|
+
# AUTH_OTP_CHANNEL_UNAVAILABLE while the SMS channel is off. The optional key is 16–64 of [A-Za-z0-9_-].
|
|
226
|
+
# request: { locale? } (an empty body is sent as {}).
|
|
227
|
+
def start_phone_verification(request = {}, idempotency_key: nil)
|
|
228
|
+
data('startPhoneVerification', body: request, idempotency_key: idempotency_key)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# request: { challengeId, code }. Answer: { phoneVerified: true, phoneVerifiedAt }. Only the session that
|
|
232
|
+
# started it can complete it. The route takes no Idempotency-Key (one given is refused).
|
|
233
|
+
def complete_phone_verification(request, idempotency_key: nil)
|
|
234
|
+
data('completePhoneVerification', body: request, idempotency_key: idempotency_key)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Wallet e-mail change (wallet password + a code to the current address + a code to the new address)
|
|
238
|
+
|
|
239
|
+
# request: { newEmail, password, locale? }; the key (16–64 of [A-Za-z0-9_-]) is required. Answer: the
|
|
240
|
+
# change request (changeId, phase, destinationMasked …); a code goes to the current address.
|
|
241
|
+
def start_email_change(request, idempotency_key: nil)
|
|
242
|
+
data('startEmailChange', body: request, idempotency_key: idempotency_key)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
# The change request: changeId, phase (CURRENT | NEW | COMPLETED | EXPIRED …), masks.
|
|
246
|
+
def get_email_change(change_id)
|
|
247
|
+
data('getEmailChange', params: { 'changeId' => change_id })
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# A new code to the address of the current phase. request: { locale? }.
|
|
251
|
+
def resend_email_change(change_id, request = {}, idempotency_key: nil)
|
|
252
|
+
data('resendEmailChange', params: { 'changeId' => change_id }, body: request, idempotency_key: idempotency_key)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# The code sent to the current address (6–10 digits). request: { code, locale? }; a code then goes to the
|
|
256
|
+
# new address.
|
|
257
|
+
def verify_current_email_change(change_id, request, idempotency_key: nil)
|
|
258
|
+
data('verifyCurrentEmailChange', params: { 'changeId' => change_id }, body: request, idempotency_key: idempotency_key)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# The code sent to the new address. request: { code, locale? }. On success (phase COMPLETED,
|
|
262
|
+
# reauthRequired: true) the platform ends the customer's sessions: the stored record is deleted and the
|
|
263
|
+
# customer signs in again (codes now go to the new address).
|
|
264
|
+
def complete_email_change(change_id, request, idempotency_key: nil)
|
|
265
|
+
answer = data('completeEmailChange', params: { 'changeId' => change_id }, body: request, idempotency_key: idempotency_key)
|
|
266
|
+
@token_store.delete(@customer_key) if answer.is_a?(Hash) && answer['reauthRequired'] == true
|
|
267
|
+
answer
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
def inspect
|
|
271
|
+
"#<Lunixi::WalletPortal customer_key=#{@customer_key.inspect}>"
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
private
|
|
275
|
+
|
|
276
|
+
def data(name, **)
|
|
277
|
+
RouteResponse.unwrap(send_route(name, **))
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
# Sends one route of WALLET_PORTAL_ROUTES with the customer's bearer token and the client's signature,
|
|
281
|
+
# checked before sending like the merchant wallet routes. A 401 AUTH_CUSTOMER_SESSION_INVALID (access
|
|
282
|
+
# token expired or rotated elsewhere) refreshes once and re-sends; if the fresh token is refused too, the
|
|
283
|
+
# session was revoked: the record is deleted.
|
|
284
|
+
def send_route(name, params: {}, body: nil, query: nil, idempotency_key: nil)
|
|
285
|
+
route = WALLET_PORTAL_ROUTES.fetch(name)
|
|
286
|
+
path = RouteRequest.path!(route['path'], params)
|
|
287
|
+
filters = query.nil? ? {} : WalletRules.query!(name, route, query)
|
|
288
|
+
payload = body_for(name, route, body)
|
|
289
|
+
key = key_for(name, route, idempotency_key)
|
|
290
|
+
token = @tokens.access_token(@customer_key, @token_store, @refresh_skew_seconds)
|
|
291
|
+
attempt = 0
|
|
292
|
+
begin
|
|
293
|
+
@client.request(route['method'], path, body: payload, query: filters, idempotency_key: key, bearer: token, end_user_ip: @end_user_ip)
|
|
294
|
+
rescue ApiError => e
|
|
295
|
+
expired = e.status == 401 && e.code == WalletCustomerSessionErrorCode::CUSTOMER_SESSION_INVALID
|
|
296
|
+
if expired && attempt.zero?
|
|
297
|
+
attempt += 1
|
|
298
|
+
token = @tokens.refresh(@customer_key, @token_store, token).fetch('accessToken')
|
|
299
|
+
retry
|
|
300
|
+
end
|
|
301
|
+
typed = WalletCustomerTokens.typed_error(e, customer_key: @customer_key, session_ended: expired ? true : nil)
|
|
302
|
+
@token_store.delete(@customer_key) if typed.is_a?(WalletCustomerSessionError) && typed.session_ended
|
|
303
|
+
raise typed
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def body_for(name, route, body)
|
|
308
|
+
return nil unless route['method'] == 'POST' && (route.key?('required') || route.key?('optional'))
|
|
309
|
+
|
|
310
|
+
plain = RouteRequest.fields!(body || {}, route['required'] || [], route['optional'] || [], name)
|
|
311
|
+
plain = WalletRules.apply!(name, route['rules'], plain) if route['rules']
|
|
312
|
+
(route['passThrough'] || []).each do |field|
|
|
313
|
+
raise ConfigurationError, "#{name}.#{field} must be a Hash." if plain.key?(field) && !plain[field].is_a?(Hash)
|
|
314
|
+
end
|
|
315
|
+
WALLET_PORTAL_AMOUNT_FIELDS.each do |field|
|
|
316
|
+
plain[field] = WalletInvoker.amount!(plain[field], "#{name}.#{field}") if plain.key?(field)
|
|
317
|
+
end
|
|
318
|
+
plain
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
def key_for(name, route, key)
|
|
322
|
+
pattern = route['idempotencyKeyPattern']
|
|
323
|
+
return portal_key!(name, key, pattern) if route['idempotencyKey']
|
|
324
|
+
return nil if key.nil?
|
|
325
|
+
raise ConfigurationError, "#{name} does not take an Idempotency-Key." unless route['idempotencyKeyOptional']
|
|
326
|
+
|
|
327
|
+
portal_key!(name, key, pattern)
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def portal_key!(name, key, pattern)
|
|
331
|
+
return WalletInvoker.idempotency_key!(key, name) unless pattern
|
|
332
|
+
|
|
333
|
+
value = key.is_a?(String) ? key.strip : ''
|
|
334
|
+
raise ConfigurationError, "A stable Idempotency-Key is required for #{name}. Reuse the same key when retrying the same operation." if value.empty?
|
|
335
|
+
raise ConfigurationError, "Idempotency-Key for #{name} has an invalid format." unless value.match?(pattern)
|
|
336
|
+
|
|
337
|
+
value
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lunixi # rubocop:disable Metrics/ModuleLength -- one row per catalog route
|
|
4
|
+
# The step-up start takes a stable request key: 8–100 of [A-Za-z0-9_-].
|
|
5
|
+
WALLET_PORTAL_ACTION_KEY_PATTERN = /\A[A-Za-z0-9_-]{8,100}\z/
|
|
6
|
+
# The step-up verification code: 6–10 digits.
|
|
7
|
+
WALLET_PORTAL_ACTION_CODE_PATTERN = /\A\d{6,10}\z/
|
|
8
|
+
# Phone verification start takes an optional key: 16–64 of [A-Za-z0-9_-].
|
|
9
|
+
WALLET_PORTAL_PHONE_VERIFICATION_KEY_PATTERN = /\A[A-Za-z0-9_-]{16,64}\z/
|
|
10
|
+
# The e-mail change start takes a required key: 16–64 of [A-Za-z0-9_-].
|
|
11
|
+
WALLET_PORTAL_CONTACT_CHANGE_KEY_PATTERN = /\A[A-Za-z0-9_-]{16,64}\z/
|
|
12
|
+
# An e-mail change code: 6–10 digits.
|
|
13
|
+
WALLET_PORTAL_CONTACT_CODE_PATTERN = /\A\d{6,10}\z/
|
|
14
|
+
# newEmail of the e-mail change (the gateway's IsEmail, at most 160 characters).
|
|
15
|
+
WALLET_PORTAL_EMAIL_PATTERN = /\A[^\s@]+@[^\s@]+\.[^\s@]+\z/
|
|
16
|
+
# Body fields that carry a minor-unit amount string.
|
|
17
|
+
WALLET_PORTAL_AMOUNT_FIELDS = %w[amount].freeze
|
|
18
|
+
|
|
19
|
+
portal_uuid = { 'pattern' => WALLET_UUID_PATTERN }.freeze
|
|
20
|
+
portal_currency = { 'pattern' => /\A[A-Za-z]{3,8}\z/ }.freeze
|
|
21
|
+
portal_text = ->(max) { { 'max' => max }.freeze }
|
|
22
|
+
portal_date = { 'pattern' => /\A\d{4}-\d{2}-\d{2}(?:T[\d:.]+(?:Z|[+-]\d{2}:\d{2})?)?\z/ }.freeze
|
|
23
|
+
portal_transfer = {
|
|
24
|
+
'easyAddressResolutionId' => portal_uuid,
|
|
25
|
+
'sourceWalletAccountId' => portal_uuid,
|
|
26
|
+
'destinationWalletNo' => { 'pattern' => /\A\d{10}\z/ }.freeze,
|
|
27
|
+
'destinationPhone' => { 'pattern' => /\A[+0-9 ()-]{8,20}\z/ }.freeze,
|
|
28
|
+
'currency' => portal_currency,
|
|
29
|
+
'paymentPurpose' => portal_text.call(64),
|
|
30
|
+
'scheduleVersionId' => portal_text.call(64),
|
|
31
|
+
'locale' => portal_text.call(8)
|
|
32
|
+
}.freeze
|
|
33
|
+
# Every path below is relative to /api/portal/v1/wallet.
|
|
34
|
+
portal_route = ->(method, path, **fields) { RouteRequest.route(method, "/api/portal/v1/wallet#{path}", **fields) }
|
|
35
|
+
|
|
36
|
+
# The customer's own routes (/api/portal/v1/wallet/me/* and auth/email-change), called by your server with a merchant-vouched
|
|
37
|
+
# customer session (client.wallet.portal). Same shape as WALLET_ROUTES and the Node SDK's
|
|
38
|
+
# WALLET_PORTAL_ROUTES. idempotencyKey: true means the SDK requires one (the gateway passes it through on
|
|
39
|
+
# these money routes and the step-up start refuses to run without it); idempotencyKeyPattern is the
|
|
40
|
+
# key's format when the gateway checks it. No route takes an end-user id or an OTP channel.
|
|
41
|
+
# passThrough: body objects the gateway validates (sent as given). rules: per-field checks (pattern,
|
|
42
|
+
# min / max length, oneOf, trim, int { min, max }, list { max, pattern }).
|
|
43
|
+
WALLET_PORTAL_ROUTES = {
|
|
44
|
+
'getMe' => portal_route.call('GET', '/me', idempotency_key: false),
|
|
45
|
+
'getBalances' => portal_route.call('GET', '/me/balances', idempotency_key: false),
|
|
46
|
+
'listWallets' => portal_route.call('GET', '/me/wallets', idempotency_key: false),
|
|
47
|
+
'getLimits' => portal_route.call('GET', '/me/limits', idempotency_key: false, query: %w[operationType currency],
|
|
48
|
+
rules: { 'operationType' => { 'pattern' => /\A[A-Za-z0-9_]{1,32}\z/ }.freeze,
|
|
49
|
+
'currency' => portal_currency }.freeze),
|
|
50
|
+
'getKycLevel' => portal_route.call('GET', '/me/kyc-level', idempotency_key: false),
|
|
51
|
+
|
|
52
|
+
'listOperations' => portal_route.call('GET', '/me/operations',
|
|
53
|
+
idempotency_key: false,
|
|
54
|
+
query: %w[operationType createdFrom createdTo search statuses walletAccountId status limit cursor],
|
|
55
|
+
rules: {
|
|
56
|
+
'operationType' => { 'pattern' => /\A[A-Z0-9_]{3,64}\z/ }.freeze,
|
|
57
|
+
'createdFrom' => portal_date,
|
|
58
|
+
'createdTo' => portal_date,
|
|
59
|
+
'search' => portal_text.call(140),
|
|
60
|
+
'statuses' => { 'list' => { 'max' => 12, 'pattern' => /\A[A-Z_]{3,24}\z/ }.freeze }.freeze,
|
|
61
|
+
'walletAccountId' => portal_uuid,
|
|
62
|
+
'status' => { 'pattern' => /\A[A-Z_]{3,24}\z/ }.freeze,
|
|
63
|
+
'limit' => { 'int' => { 'min' => 1, 'max' => 100 }.freeze }.freeze,
|
|
64
|
+
'cursor' => portal_text.call(512)
|
|
65
|
+
}.freeze),
|
|
66
|
+
'getOperation' => portal_route.call('GET', '/me/operations/:operationId', idempotency_key: false),
|
|
67
|
+
'getOperationReceipt' => portal_route.call('GET', '/me/operations/:operationId/receipt', idempotency_key: false),
|
|
68
|
+
|
|
69
|
+
# Card top-up into my own wallet (3-D Secure).
|
|
70
|
+
'startCardTopup' => portal_route.call('POST', '/me/topups/card',
|
|
71
|
+
idempotency_key: true, required: %w[creditWalletAccountId amount currency],
|
|
72
|
+
optional: %w[fundingCardId returnUrl buyer billingAddress shippingAddress],
|
|
73
|
+
pass_through: %w[buyer billingAddress shippingAddress],
|
|
74
|
+
rules: { 'creditWalletAccountId' => portal_uuid, 'currency' => portal_currency,
|
|
75
|
+
'fundingCardId' => portal_uuid, 'returnUrl' => portal_text.call(2048) }.freeze),
|
|
76
|
+
'getTopup' => portal_route.call('GET', '/me/topups/:operationId', idempotency_key: false),
|
|
77
|
+
|
|
78
|
+
# Wallet-to-wallet transfer.
|
|
79
|
+
'quoteW2W' => portal_route.call('POST', '/me/transfers/w2w/quote',
|
|
80
|
+
idempotency_key: false, required: %w[sourceWalletAccountId amount currency],
|
|
81
|
+
optional: %w[easyAddressResolutionId destinationWalletNo destinationPhone paymentPurpose],
|
|
82
|
+
rules: portal_transfer),
|
|
83
|
+
'initiateW2W' => portal_route.call('POST', '/me/transfers/w2w',
|
|
84
|
+
idempotency_key: true, required: %w[sourceWalletAccountId amount currency],
|
|
85
|
+
optional: %w[easyAddressResolutionId destinationWalletNo destinationPhone paymentPurpose scheduleVersionId
|
|
86
|
+
locale],
|
|
87
|
+
rules: portal_transfer),
|
|
88
|
+
'completeW2W' => portal_route.call('POST', '/me/transfers/w2w/:operationId/complete',
|
|
89
|
+
idempotency_key: true, required: %w[integrityHash nonce], optional: %w[otpCode trustedActionToken],
|
|
90
|
+
rules: { 'integrityHash' => portal_text.call(128), 'nonce' => portal_text.call(64),
|
|
91
|
+
'otpCode' => portal_text.call(16), 'trustedActionToken' => portal_text.call(2048) }.freeze),
|
|
92
|
+
|
|
93
|
+
# Step-up of a money operation: wallet password + a code bound to the operation
|
|
94
|
+
# (PASSWORD_AND_ACTION_OTP) -> a single-use trustedActionToken for complete.
|
|
95
|
+
'startOperationStepUp' => portal_route.call('POST', '/me/operations/:operationId/step-up',
|
|
96
|
+
idempotency_key: true, idempotency_key_pattern: WALLET_PORTAL_ACTION_KEY_PATTERN,
|
|
97
|
+
required: %w[password], optional: %w[locale],
|
|
98
|
+
rules: { 'password' => { 'min' => 1, 'max' => 256 }.freeze, 'locale' => portal_text.call(8) }.freeze),
|
|
99
|
+
'verifyOperationStepUp' => portal_route.call('POST', '/me/operations/:operationId/step-up/verify',
|
|
100
|
+
idempotency_key: false, required: %w[challengeId code],
|
|
101
|
+
rules: { 'challengeId' => portal_uuid,
|
|
102
|
+
'code' => { 'pattern' => WALLET_PORTAL_ACTION_CODE_PATTERN }.freeze }.freeze),
|
|
103
|
+
|
|
104
|
+
# Pay a scanned QR: amount only for a static QR (a dynamic QR carries its own).
|
|
105
|
+
'payQr' => portal_route.call('POST', '/me/qr/pay',
|
|
106
|
+
idempotency_key: true, required: %w[payload sourceWalletAccountId], optional: %w[amount locale],
|
|
107
|
+
rules: { 'payload' => portal_text.call(2048), 'sourceWalletAccountId' => portal_uuid,
|
|
108
|
+
'locale' => portal_text.call(8) }.freeze),
|
|
109
|
+
'completeQrPay' => portal_route.call('POST', '/me/qr/pay/:qrId/complete',
|
|
110
|
+
idempotency_key: true, required: %w[operationId integrityHash nonce], optional: %w[otpCode trustedActionToken],
|
|
111
|
+
rules: { 'operationId' => portal_uuid, 'integrityHash' => portal_text.call(256),
|
|
112
|
+
'nonce' => portal_text.call(128), 'otpCode' => portal_text.call(16),
|
|
113
|
+
'trustedActionToken' => portal_text.call(2048) }.freeze),
|
|
114
|
+
|
|
115
|
+
# Payment code shown at the till (customer-presented).
|
|
116
|
+
'mintPaymentCode' => portal_route.call('POST', '/me/payment-code', idempotency_key: false, required: %w[currency],
|
|
117
|
+
rules: { 'currency' => portal_currency }.freeze),
|
|
118
|
+
'revokePaymentCode' => portal_route.call('DELETE', '/me/payment-code', idempotency_key: false),
|
|
119
|
+
|
|
120
|
+
# Loyalty, cashback, tier.
|
|
121
|
+
'listLoyaltyPrograms' => portal_route.call('GET', '/me/loyalty/programs', idempotency_key: false),
|
|
122
|
+
'getLoyaltyBalance' => portal_route.call('GET', '/me/loyalty/balance',
|
|
123
|
+
idempotency_key: false, query: %w[loyaltyProgramId lotLimit], required_query: %w[loyaltyProgramId],
|
|
124
|
+
rules: { 'loyaltyProgramId' => portal_uuid,
|
|
125
|
+
'lotLimit' => { 'int' => { 'min' => 1, 'max' => 500 }.freeze }.freeze }.freeze),
|
|
126
|
+
'getLoyaltyHistory' => portal_route.call('GET', '/me/loyalty/history',
|
|
127
|
+
idempotency_key: false, query: %w[loyaltyProgramId limit], required_query: %w[loyaltyProgramId],
|
|
128
|
+
rules: { 'loyaltyProgramId' => portal_uuid,
|
|
129
|
+
'limit' => { 'int' => { 'min' => 1, 'max' => 200 }.freeze }.freeze }.freeze),
|
|
130
|
+
# The idempotency key travels in the body (idempotencyKey), not as a header.
|
|
131
|
+
'redeemLoyaltyPoints' => portal_route.call('POST', '/me/loyalty/redeem',
|
|
132
|
+
idempotency_key: false, required: %w[loyaltyProgramId walletAccountId points idempotencyKey],
|
|
133
|
+
rules: { 'loyaltyProgramId' => portal_uuid, 'walletAccountId' => portal_uuid,
|
|
134
|
+
'points' => { 'pattern' => /\A\d{1,19}\z/ }.freeze,
|
|
135
|
+
'idempotencyKey' => { 'min' => 8, 'max' => 128 }.freeze }.freeze),
|
|
136
|
+
'getCashback' => portal_route.call('GET', '/me/cashback', idempotency_key: false, query: %w[limit],
|
|
137
|
+
rules: { 'limit' => { 'int' => { 'min' => 1 }.freeze }.freeze }.freeze),
|
|
138
|
+
'getTier' => portal_route.call('GET', '/me/tier', idempotency_key: false),
|
|
139
|
+
|
|
140
|
+
# Phone verification of the session's identity (always by SMS). Needed before the platform moves codes
|
|
141
|
+
# to SMS: an unverified phone cannot receive them.
|
|
142
|
+
'startPhoneVerification' => portal_route.call('POST', '/me/phone-verification/start',
|
|
143
|
+
idempotency_key: false, idempotency_key_optional: true,
|
|
144
|
+
idempotency_key_pattern: WALLET_PORTAL_PHONE_VERIFICATION_KEY_PATTERN,
|
|
145
|
+
optional: %w[locale], rules: { 'locale' => { 'pattern' => WALLET_LOCALE_PATTERN }.freeze }.freeze),
|
|
146
|
+
'completePhoneVerification' => portal_route.call('POST', '/me/phone-verification/complete',
|
|
147
|
+
idempotency_key: false, required: %w[challengeId code],
|
|
148
|
+
rules: { 'challengeId' => portal_uuid,
|
|
149
|
+
'code' => { 'pattern' => WALLET_SESSION_CODE_PATTERN }.freeze }.freeze),
|
|
150
|
+
|
|
151
|
+
# Wallet e-mail change: wallet password + a code to the current address + a code to the new address.
|
|
152
|
+
# Completion answers reauthRequired: true (the platform ends the sessions; sign in again).
|
|
153
|
+
'startEmailChange' => portal_route.call('POST', '/auth/email-change',
|
|
154
|
+
idempotency_key: true, idempotency_key_pattern: WALLET_PORTAL_CONTACT_CHANGE_KEY_PATTERN,
|
|
155
|
+
required: %w[newEmail password], optional: %w[locale],
|
|
156
|
+
rules: { 'newEmail' => { 'max' => 160, 'pattern' => WALLET_PORTAL_EMAIL_PATTERN }.freeze,
|
|
157
|
+
'password' => { 'min' => 1, 'max' => 256 }.freeze,
|
|
158
|
+
'locale' => portal_text.call(8) }.freeze),
|
|
159
|
+
'getEmailChange' => portal_route.call('GET', '/auth/email-change/:changeId', idempotency_key: false),
|
|
160
|
+
'resendEmailChange' => portal_route.call('POST', '/auth/email-change/:changeId/resend',
|
|
161
|
+
idempotency_key: false, optional: %w[locale], rules: { 'locale' => portal_text.call(8) }.freeze),
|
|
162
|
+
'verifyCurrentEmailChange' => portal_route.call('POST', '/auth/email-change/:changeId/current',
|
|
163
|
+
idempotency_key: false, required: %w[code], optional: %w[locale],
|
|
164
|
+
rules: { 'code' => { 'pattern' => WALLET_PORTAL_CONTACT_CODE_PATTERN }.freeze,
|
|
165
|
+
'locale' => portal_text.call(8) }.freeze),
|
|
166
|
+
'completeEmailChange' => portal_route.call('POST', '/auth/email-change/:changeId/complete',
|
|
167
|
+
idempotency_key: false, required: %w[code], optional: %w[locale],
|
|
168
|
+
rules: { 'code' => { 'pattern' => WALLET_PORTAL_CONTACT_CODE_PATTERN }.freeze,
|
|
169
|
+
'locale' => portal_text.call(8) }.freeze)
|
|
170
|
+
}.freeze
|
|
171
|
+
end
|
data/lib/lunixi/wallet_routes.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Lunixi
|
|
3
|
+
module Lunixi # rubocop:disable Metrics/ModuleLength -- one row per catalog route
|
|
4
4
|
wallet_page = %w[limit cursor].freeze
|
|
5
5
|
money_move = %w[endUserId sourceWalletAccountId amount currency].freeze
|
|
6
6
|
iban_move = %w[endUserId sourceWalletAccountId beneficiaryName iban amount currency].freeze
|
|
@@ -21,9 +21,12 @@ module Lunixi
|
|
|
21
21
|
'setCollectionAnchor' => route.call('PUT', '/programs/:programId/collection-anchor',
|
|
22
22
|
idempotency_key: false, optional: %w[collectionEndUserId reason expectedVersion]),
|
|
23
23
|
|
|
24
|
+
# customerContact: { email } pins the code address of the customer session (requires externalCustomerId
|
|
25
|
+
# and accountType PERSONAL).
|
|
24
26
|
'createEndUser' => route.call('POST', '/end-users',
|
|
25
27
|
idempotency_key: true, required: %w[programId accountType phone],
|
|
26
|
-
optional: %w[externalCustomerId kycRef kycLevelCache displayName corporateAccountId defaultCurrency
|
|
28
|
+
optional: %w[externalCustomerId kycRef kycLevelCache displayName corporateAccountId defaultCurrency
|
|
29
|
+
customerContact]),
|
|
27
30
|
'listEndUsers' => route.call('GET', '/end-users',
|
|
28
31
|
idempotency_key: false, query: %w[programId accountType status corporateAccountId merchantCategoryState] + wallet_page),
|
|
29
32
|
'getEndUserByExternalId' => route.call('GET', '/end-users/by-external/:externalCustomerId', idempotency_key: false, query: %w[programId]),
|
|
@@ -121,6 +124,28 @@ module Lunixi
|
|
|
121
124
|
'approveBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/approve', idempotency_key: false, required: %w[approve], optional: %w[reason]),
|
|
122
125
|
'rejectBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/reject', idempotency_key: false, optional: %w[reason]),
|
|
123
126
|
'processBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/process', idempotency_key: false),
|
|
124
|
-
'retryFailedBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/retry-failed', idempotency_key: false)
|
|
127
|
+
'retryFailedBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/retry-failed', idempotency_key: false),
|
|
128
|
+
|
|
129
|
+
# Merchant-vouched customer session (permission wallet:customer-session:create). No end-user id,
|
|
130
|
+
# identity id, tenant, channel or shop name in the body (400). password: required when the customer is
|
|
131
|
+
# ACTIVE (signing in again, or an enrollment answered LINKED_EXISTING); refused (400) while
|
|
132
|
+
# PENDING_ACTIVATION. newPassword: required on first activation (passwordSetupRequired).
|
|
133
|
+
'startCustomerSession' => route.call('POST', '/customer-sessions',
|
|
134
|
+
idempotency_key: true, required: %w[programId externalCustomerId clientInstanceId clientLabel locale],
|
|
135
|
+
optional: %w[password], rules: WALLET_CUSTOMER_SESSION_RULES),
|
|
136
|
+
'resendCustomerSession' => route.call('POST', '/customer-sessions/resend',
|
|
137
|
+
idempotency_key: false, idempotency_key_optional: true,
|
|
138
|
+
required: %w[programId externalCustomerId clientInstanceId challengeId], optional: %w[locale],
|
|
139
|
+
rules: WALLET_CUSTOMER_SESSION_RULES),
|
|
140
|
+
'completeCustomerSession' => route.call('POST', '/customer-sessions/complete',
|
|
141
|
+
idempotency_key: false, idempotency_key_optional: true,
|
|
142
|
+
required: %w[programId externalCustomerId clientInstanceId challengeId code],
|
|
143
|
+
optional: %w[newPassword locale], rules: WALLET_CUSTOMER_SESSION_RULES),
|
|
144
|
+
'refreshCustomerSession' => route.call('POST', '/customer-sessions/refresh',
|
|
145
|
+
idempotency_key: false, required: %w[refreshToken], rules: WALLET_CUSTOMER_SESSION_RULES),
|
|
146
|
+
'revokeCustomerSession' => route.call('DELETE', '/customer-sessions',
|
|
147
|
+
idempotency_key: false, query: %w[programId externalCustomerId clientInstanceId reason],
|
|
148
|
+
required_query: %w[programId externalCustomerId clientInstanceId],
|
|
149
|
+
rules: WALLET_CUSTOMER_SESSION_RULES)
|
|
125
150
|
}.freeze
|
|
126
151
|
end
|