lunixi-sdk 1.2.2 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -0
  3. data/README.md +262 -9
  4. data/README.tr.md +266 -7
  5. data/lib/lunixi/bank_connect.rb +340 -0
  6. data/lib/lunixi/bank_connect_filters.rb +114 -0
  7. data/lib/lunixi/bank_connect_values.rb +205 -0
  8. data/lib/lunixi/bank_transfer.rb +106 -0
  9. data/lib/lunixi/card_requests.rb +150 -0
  10. data/lib/lunixi/client.rb +57 -16
  11. data/lib/lunixi/direct_method_payment_request.rb +243 -0
  12. data/lib/lunixi/enabled_installments.rb +28 -0
  13. data/lib/lunixi/errors.rb +69 -3
  14. data/lib/lunixi/fraud.rb +81 -5
  15. data/lib/lunixi/identity.rb +94 -0
  16. data/lib/lunixi/identity_values.rb +28 -0
  17. data/lib/lunixi/insurance.rb +294 -0
  18. data/lib/lunixi/insurance_request.rb +134 -0
  19. data/lib/lunixi/insurance_values.rb +200 -0
  20. data/lib/lunixi/kyc.rb +189 -0
  21. data/lib/lunixi/kyc_values.rb +158 -0
  22. data/lib/lunixi/marketplace.rb +264 -0
  23. data/lib/lunixi/marketplace_values.rb +86 -0
  24. data/lib/lunixi/method_fields.rb +142 -0
  25. data/lib/lunixi/money.rb +7 -4
  26. data/lib/lunixi/payment_link_filters.rb +32 -0
  27. data/lib/lunixi/payment_link_image_rules.rb +85 -0
  28. data/lib/lunixi/payment_link_rules.rb +132 -0
  29. data/lib/lunixi/payment_link_values.rb +134 -0
  30. data/lib/lunixi/payment_links.rb +152 -0
  31. data/lib/lunixi/payment_values.rb +86 -0
  32. data/lib/lunixi/payments.rb +154 -5
  33. data/lib/lunixi/physical_pos.rb +183 -0
  34. data/lib/lunixi/physical_pos_card_data.rb +117 -0
  35. data/lib/lunixi/physical_pos_card_number.rb +65 -0
  36. data/lib/lunixi/physical_pos_device_identity.rb +44 -0
  37. data/lib/lunixi/physical_pos_filters.rb +58 -0
  38. data/lib/lunixi/physical_pos_gateway.rb +153 -0
  39. data/lib/lunixi/physical_pos_identifiers.rb +62 -0
  40. data/lib/lunixi/physical_pos_management.rb +326 -0
  41. data/lib/lunixi/physical_pos_money.rb +46 -0
  42. data/lib/lunixi/physical_pos_request.rb +126 -0
  43. data/lib/lunixi/physical_pos_responses.rb +102 -0
  44. data/lib/lunixi/physical_pos_results.rb +52 -0
  45. data/lib/lunixi/physical_pos_settlement_policies.rb +71 -0
  46. data/lib/lunixi/physical_pos_value.rb +43 -0
  47. data/lib/lunixi/physical_pos_values.rb +203 -0
  48. data/lib/lunixi/physical_pos_webhook.rb +147 -0
  49. data/lib/lunixi/product_webhooks.rb +106 -0
  50. data/lib/lunixi/promissory_note.rb +155 -0
  51. data/lib/lunixi/reference.rb +41 -0
  52. data/lib/lunixi/route_request.rb +121 -0
  53. data/lib/lunixi/route_response.rb +101 -0
  54. data/lib/lunixi/route_table.rb +128 -0
  55. data/lib/lunixi/route_value.rb +60 -0
  56. data/lib/lunixi/sanction.rb +244 -0
  57. data/lib/lunixi/sanction_values.rb +132 -0
  58. data/lib/lunixi/split_payment.rb +145 -0
  59. data/lib/lunixi/subscription_resources.rb +355 -0
  60. data/lib/lunixi/subscription_values.rb +220 -0
  61. data/lib/lunixi/subscriptions.rb +202 -0
  62. data/lib/lunixi/version.rb +1 -1
  63. data/lib/lunixi/wallet.rb +153 -0
  64. data/lib/lunixi/wallet_resources.rb +402 -0
  65. data/lib/lunixi/wallet_routes.rb +123 -0
  66. data/lib/lunixi/wallet_values.rb +71 -0
  67. data/lib/lunixi/wire_money.rb +67 -0
  68. data/lib/lunixi.rb +57 -0
  69. metadata +58 -1
@@ -0,0 +1,402 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # wallet.programs
5
+ class WalletPrograms
6
+ def initialize(invoker)
7
+ @invoker = invoker
8
+ end
9
+
10
+ # The wallet programs of the signing merchant.
11
+ def list_mine
12
+ @invoker.page('listMyPrograms')
13
+ end
14
+
15
+ # Sets the end user whose wallet collects the program's merchant payments; leaving
16
+ # collection_end_user_id out clears the anchor.
17
+ def set_collection_anchor(program_id, collection_end_user_id: nil, reason: nil, expected_version: nil)
18
+ body = { 'collectionEndUserId' => collection_end_user_id, 'reason' => reason, 'expectedVersion' => expected_version }
19
+ @invoker.data('setCollectionAnchor', params: { 'programId' => program_id }, body: RouteRequest.compact(body))
20
+ end
21
+ end
22
+
23
+ # wallet.end_users
24
+ class WalletEndUsers
25
+ def initialize(invoker)
26
+ @invoker = invoker
27
+ end
28
+
29
+ # Creates an end user and their default wallet (Idempotency-Key required).
30
+ def create(request, idempotency_key: nil)
31
+ @invoker.data('createEndUser', body: request, idempotency_key: idempotency_key)
32
+ end
33
+
34
+ def list(**filters)
35
+ @invoker.page('listEndUsers', query: filters)
36
+ end
37
+
38
+ def iterate(**filters, &block)
39
+ RouteResponse.each_item(filters, block) { |query| list(**query) }
40
+ end
41
+
42
+ def get(end_user_id)
43
+ @invoker.data('getEndUser', params: { 'endUserId' => end_user_id })
44
+ end
45
+
46
+ # Finds an end user by your own customer id.
47
+ def get_by_external_id(external_customer_id, program_id: nil)
48
+ @invoker.data('getEndUserByExternalId', params: { 'externalCustomerId' => external_customer_id },
49
+ query: RouteRequest.compact('programId' => program_id))
50
+ end
51
+
52
+ # Freezes the end user (POST /end-users/{id}/freeze). Named freeze_end_user so Object#freeze is
53
+ # left alone (the catalog operation is wallet.endUsers.freeze).
54
+ def freeze_end_user(end_user_id, reason: nil, idempotency_key: nil)
55
+ @invoker.data('freezeEndUser', params: { 'endUserId' => end_user_id }, body: RouteRequest.compact('reason' => reason),
56
+ idempotency_key: idempotency_key)
57
+ end
58
+
59
+ def get_balances(end_user_id)
60
+ @invoker.data('getBalances', params: { 'endUserId' => end_user_id })
61
+ end
62
+
63
+ def get_kyc_level(end_user_id)
64
+ @invoker.data('getKycLevel', params: { 'endUserId' => end_user_id })
65
+ end
66
+
67
+ # Records the KYC level from your own verification (sourceRef: your KYC session id).
68
+ def update_kyc_level(end_user_id, request, idempotency_key: nil)
69
+ @invoker.data('updateKycLevel', params: { 'endUserId' => end_user_id }, body: request, idempotency_key: idempotency_key)
70
+ end
71
+
72
+ # Limit usage per operation type; operation_type and currency narrow the answer.
73
+ def get_limits(end_user_id, operation_type: nil, currency: nil)
74
+ @invoker.data('getLimits', params: { 'endUserId' => end_user_id },
75
+ query: RouteRequest.compact('operationType' => operation_type, 'currency' => currency))
76
+ end
77
+
78
+ def create_wallet(end_user_id, name: nil, currencies: nil, idempotency_key: nil)
79
+ @invoker.data('createWallet', params: { 'endUserId' => end_user_id },
80
+ body: RouteRequest.compact('name' => name, 'currencies' => currencies), idempotency_key: idempotency_key)
81
+ end
82
+ end
83
+
84
+ # wallet.wallets
85
+ class WalletAccounts
86
+ def initialize(invoker)
87
+ @invoker = invoker
88
+ end
89
+
90
+ # Adds a currency account to a wallet.
91
+ def create_account(wallet_id, currency, idempotency_key: nil)
92
+ @invoker.data('createWalletAccount', params: { 'walletId' => wallet_id }, body: { 'currency' => currency }, idempotency_key: idempotency_key)
93
+ end
94
+
95
+ # Resolves a wallet number or phone to { exists, walletNo, maskedName } before a transfer.
96
+ def lookup(request)
97
+ @invoker.data('lookupWallet', body: request)
98
+ end
99
+ end
100
+
101
+ # wallet.deposits: bank transfer details an end user pays into to top up.
102
+ class WalletDeposits
103
+ def initialize(invoker)
104
+ @invoker = invoker
105
+ end
106
+
107
+ def list_instructions(end_user_id)
108
+ @invoker.data('listDepositInstructions', params: { 'endUserId' => end_user_id })
109
+ end
110
+
111
+ def create_instruction(end_user_id, wallet_account_id: nil, currency: nil)
112
+ @invoker.data('createDepositInstruction', params: { 'endUserId' => end_user_id },
113
+ body: RouteRequest.compact('walletAccountId' => wallet_account_id, 'currency' => currency))
114
+ end
115
+
116
+ # Test only: books an incoming bank transfer as the bank rail would.
117
+ def simulate_inbound_credit(request)
118
+ @invoker.data('simulateInboundCredit', body: request)
119
+ end
120
+ end
121
+
122
+ # wallet.corporate
123
+ class WalletCorporate
124
+ def initialize(invoker)
125
+ @invoker = invoker
126
+ end
127
+
128
+ def create(request, idempotency_key: nil)
129
+ @invoker.data('createCorporateAccount', body: request, idempotency_key: idempotency_key)
130
+ end
131
+
132
+ def list(**filters)
133
+ @invoker.page('listCorporateAccounts', query: filters)
134
+ end
135
+
136
+ def iterate(**filters, &block)
137
+ RouteResponse.each_item(filters, block) { |query| list(**query) }
138
+ end
139
+
140
+ # Imports up to 1000 employees at once; all or nothing (a 422 writes nothing). rows: [{ phone, ... }].
141
+ def import_employees(corporate_account_id, rows, idempotency_key: nil)
142
+ @invoker.data('importCorporateEmployees', params: { 'corporateAccountId' => corporate_account_id }, body: { 'rows' => rows },
143
+ idempotency_key: idempotency_key)
144
+ end
145
+
146
+ def offboard_employees(corporate_account_id, rows, reason: nil, idempotency_key: nil)
147
+ @invoker.data('offboardCorporateEmployees', params: { 'corporateAccountId' => corporate_account_id },
148
+ body: RouteRequest.compact('rows' => rows, 'reason' => reason), idempotency_key: idempotency_key)
149
+ end
150
+ end
151
+
152
+ # wallet.fees
153
+ class WalletFees
154
+ def initialize(invoker)
155
+ @invoker = invoker
156
+ end
157
+
158
+ # The fee, tax and total charge an operation would cost.
159
+ def quote(request)
160
+ @invoker.data('quoteFees', body: request)
161
+ end
162
+ end
163
+
164
+ # wallet.transfers: money moves in two steps. initiate_* reserves the limit and answers
165
+ # { operationId, integrityHash, nonce, otpRequired, ... }; complete_* with the same integrityHash and
166
+ # nonce (and the OTP when otpRequired) commits it. Quote first to show the fee; pass its
167
+ # scheduleVersionId to initiate_* to hold that fee. complete_* puts operationId in the body itself.
168
+ class WalletTransfers
169
+ def initialize(invoker)
170
+ @invoker = invoker
171
+ end
172
+
173
+ def quote_w2w(request)
174
+ @invoker.data('quoteW2W', body: request)
175
+ end
176
+
177
+ def initiate_w2w(request, idempotency_key: nil)
178
+ @invoker.data('initiateW2W', body: request, idempotency_key: idempotency_key)
179
+ end
180
+
181
+ def complete_w2w(operation_id, request, idempotency_key: nil)
182
+ complete('completeW2W', operation_id, request, idempotency_key)
183
+ end
184
+
185
+ def quote_w2_iban(request)
186
+ @invoker.data('quoteW2Iban', body: request)
187
+ end
188
+
189
+ def initiate_w2_iban(request, idempotency_key: nil)
190
+ @invoker.data('initiateW2Iban', body: request, idempotency_key: idempotency_key)
191
+ end
192
+
193
+ def complete_w2_iban(operation_id, request, idempotency_key: nil)
194
+ complete('completeW2Iban', operation_id, request, idempotency_key)
195
+ end
196
+
197
+ private
198
+
199
+ def complete(name, operation_id, request, key)
200
+ body = @invoker.with_operation_id(name, operation_id, request)
201
+ @invoker.data(name, params: { 'operationId' => operation_id }, body: body, idempotency_key: key)
202
+ end
203
+ end
204
+
205
+ # wallet.withdrawals: to the end user's own bank account, in the same two steps as transfers.
206
+ class WalletWithdrawals
207
+ def initialize(invoker)
208
+ @invoker = invoker
209
+ end
210
+
211
+ def quote(request)
212
+ @invoker.data('quoteBankWithdrawal', body: request)
213
+ end
214
+
215
+ def initiate(request, idempotency_key: nil)
216
+ @invoker.data('initiateBankWithdrawal', body: request, idempotency_key: idempotency_key)
217
+ end
218
+
219
+ def complete(operation_id, request, idempotency_key: nil)
220
+ body = @invoker.with_operation_id('completeBankWithdrawal', operation_id, request)
221
+ @invoker.data('completeBankWithdrawal', params: { 'operationId' => operation_id }, body: body, idempotency_key: idempotency_key)
222
+ end
223
+
224
+ # { operation, history }
225
+ def get(operation_id)
226
+ @invoker.data('getWithdrawal', params: { 'operationId' => operation_id })
227
+ end
228
+ end
229
+
230
+ # wallet.operations
231
+ class WalletOperations
232
+ def initialize(invoker)
233
+ @invoker = invoker
234
+ end
235
+
236
+ def list(**filters)
237
+ @invoker.page('listOperations', query: filters)
238
+ end
239
+
240
+ def iterate(**filters, &block)
241
+ RouteResponse.each_item(filters, block) { |query| list(**query) }
242
+ end
243
+
244
+ # { operation, history }
245
+ def get(operation_id)
246
+ @invoker.data('getOperation', params: { 'operationId' => operation_id })
247
+ end
248
+
249
+ def get_receipt(operation_id)
250
+ @invoker.data('getOperationReceipt', params: { 'operationId' => operation_id })
251
+ end
252
+ end
253
+
254
+ # wallet.topups
255
+ class WalletTopups
256
+ def initialize(invoker)
257
+ @invoker = invoker
258
+ end
259
+
260
+ # Starts a card top-up. Render checkoutFormContent (or follow redirectUrl / threeDsHtml); the wallet is
261
+ # credited when the payment completes (wallet.topup.completed).
262
+ def start_card(request, idempotency_key: nil)
263
+ @invoker.data('startCardTopup', body: request, idempotency_key: idempotency_key)
264
+ end
265
+
266
+ # { operation, history }
267
+ def get(operation_id)
268
+ @invoker.data('getTopup', params: { 'operationId' => operation_id })
269
+ end
270
+
271
+ # Refunds a card top-up to the card. Four eyes: approverPrincipal is required and must differ from
272
+ # requesterPrincipal; binding them to two real people is your approval flow's job.
273
+ def refund(operation_id, request)
274
+ @invoker.data('refundTopup', params: { 'operationId' => operation_id }, body: request)
275
+ end
276
+
277
+ # Cash top-up through an agent of the program.
278
+ def agent(request, idempotency_key: nil)
279
+ @invoker.data('agentTopup', body: request, idempotency_key: idempotency_key)
280
+ end
281
+ end
282
+
283
+ # wallet.payments: the end user pays the merchant. The creditor is the wallet terminal bound to the
284
+ # signing key (403 WALLET_TERMINAL_* without one); a businessAccountId in the body is refused.
285
+ class WalletPayments
286
+ def initialize(invoker)
287
+ @invoker = invoker
288
+ end
289
+
290
+ # Asks the buyer (by wallet number or phone) to pay; approve it with approve.
291
+ def request(request, idempotency_key: nil)
292
+ @invoker.data('requestPayment', body: request, idempotency_key: idempotency_key)
293
+ end
294
+
295
+ def approve(operation_id, request, idempotency_key: nil)
296
+ @invoker.data('approvePayment', params: { 'operationId' => operation_id }, body: request, idempotency_key: idempotency_key)
297
+ end
298
+
299
+ # Collects with the payment code the buyer shows (customer-presented).
300
+ def collect(request, idempotency_key: nil)
301
+ @invoker.data('collectByCode', body: request, idempotency_key: idempotency_key)
302
+ end
303
+
304
+ # { operation, history }
305
+ def get(operation_id)
306
+ @invoker.data('getPayment', params: { 'operationId' => operation_id })
307
+ end
308
+
309
+ def get_commission(business_account_id)
310
+ @invoker.data('getBusinessCommission', params: { 'businessAccountId' => business_account_id })
311
+ end
312
+ end
313
+
314
+ # wallet.qr
315
+ class WalletQr
316
+ def initialize(invoker)
317
+ @invoker = invoker
318
+ end
319
+
320
+ # Static QR codes carry no amount; dynamic ones require it.
321
+ def create(request, idempotency_key: nil)
322
+ @invoker.data('createQr', body: request, idempotency_key: idempotency_key)
323
+ end
324
+
325
+ def list(**filters)
326
+ @invoker.page('listQr', query: filters)
327
+ end
328
+
329
+ def iterate(**filters, &block)
330
+ RouteResponse.each_item(filters, block) { |query| list(**query) }
331
+ end
332
+
333
+ def get(qr_id)
334
+ @invoker.data('getQr', params: { 'qrId' => qr_id })
335
+ end
336
+
337
+ # The QR image as frozen bytes: format svg (the default) or png (WalletQrImageFormat), scale 1–20.
338
+ def image(qr_id, format: nil, scale: nil)
339
+ unless format.nil? || WalletQrImageFormat::ALL.include?(format)
340
+ raise ConfigurationError, "QR image format must be one of #{WalletQrImageFormat::ALL.join(', ')}."
341
+ end
342
+ raise ConfigurationError, 'QR image scale must be an integer 1-20.' unless scale.nil? || (scale.is_a?(Integer) && scale.between?(1, 20))
343
+
344
+ @invoker.call('getQrImage', params: { 'qrId' => qr_id }, query: RouteRequest.compact('format' => format, 'scale' => scale))
345
+ end
346
+
347
+ def revoke(qr_id)
348
+ @invoker.data('revokeQr', params: { 'qrId' => qr_id })
349
+ end
350
+
351
+ # Decodes a scanned QR payload.
352
+ def parse(payload)
353
+ @invoker.data('parseQr', body: { 'payload' => payload })
354
+ end
355
+ end
356
+
357
+ # wallet.bulk_payouts: maker-checker. The approver must be a different key than the creator (the
358
+ # principal is the signing key id). Creating needs wallet:bulk:create; submit, approve, process and
359
+ # retry_failed need wallet:bulk:approve.
360
+ class WalletBulkPayouts
361
+ def initialize(invoker)
362
+ @invoker = invoker
363
+ end
364
+
365
+ def create(request, idempotency_key: nil)
366
+ @invoker.data('createBulkPayout', body: request, idempotency_key: idempotency_key)
367
+ end
368
+
369
+ def list(**filters)
370
+ @invoker.page('listBulkPayouts', query: filters)
371
+ end
372
+
373
+ def get(batch_id)
374
+ @invoker.data('getBulkPayout', params: { 'batchId' => batch_id })
375
+ end
376
+
377
+ def list_items(batch_id, **filters)
378
+ @invoker.page('listBulkPayoutItems', params: { 'batchId' => batch_id }, query: filters)
379
+ end
380
+
381
+ def submit(batch_id)
382
+ @invoker.data('submitBulkPayout', params: { 'batchId' => batch_id })
383
+ end
384
+
385
+ # approve: false declines the batch with reason.
386
+ def approve(batch_id, approve: true, reason: nil)
387
+ @invoker.data('approveBulkPayout', params: { 'batchId' => batch_id }, body: RouteRequest.compact('approve' => approve, 'reason' => reason))
388
+ end
389
+
390
+ def reject(batch_id, reason: nil)
391
+ @invoker.data('rejectBulkPayout', params: { 'batchId' => batch_id }, body: RouteRequest.compact('reason' => reason))
392
+ end
393
+
394
+ def process(batch_id)
395
+ @invoker.data('processBulkPayout', params: { 'batchId' => batch_id })
396
+ end
397
+
398
+ def retry_failed(batch_id)
399
+ @invoker.data('retryFailedBulkPayout', params: { 'batchId' => batch_id })
400
+ end
401
+ end
402
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ wallet_page = %w[limit cursor].freeze
5
+ money_move = %w[endUserId sourceWalletAccountId amount currency].freeze
6
+ iban_move = %w[endUserId sourceWalletAccountId beneficiaryName iban amount currency].freeze
7
+ initiate_extra = %w[scheduleVersionId otpDestination otpChannel locale].freeze
8
+ complete_required = %w[endUserId operationId integrityHash nonce].freeze
9
+ complete_optional = %w[otpCode trustedActionToken].freeze
10
+ # Every path below is relative to /api/v1/wallet.
11
+ route = ->(method, path, **fields) { RouteRequest.route(method, "/api/v1/wallet#{path}", **fields) }
12
+
13
+ # Every wallet route the SDK calls: method, path template, whether the gateway requires an
14
+ # Idempotency-Key, the body fields it accepts (required / optional; forbidNonWhitelisted, so any other
15
+ # field is a 400) and the query parameters. The same table as the Node SDK's WALLET_ROUTES; the parity
16
+ # test compares it with the shared catalog field by field.
17
+ WALLET_ROUTES = {
18
+ 'ping' => route.call('GET', '/ping', idempotency_key: false),
19
+
20
+ 'listMyPrograms' => route.call('GET', '/programs/me', idempotency_key: false),
21
+ 'setCollectionAnchor' => route.call('PUT', '/programs/:programId/collection-anchor',
22
+ idempotency_key: false, optional: %w[collectionEndUserId reason expectedVersion]),
23
+
24
+ 'createEndUser' => route.call('POST', '/end-users',
25
+ idempotency_key: true, required: %w[programId accountType phone],
26
+ optional: %w[externalCustomerId kycRef kycLevelCache displayName corporateAccountId defaultCurrency]),
27
+ 'listEndUsers' => route.call('GET', '/end-users',
28
+ idempotency_key: false, query: %w[programId accountType status corporateAccountId merchantCategoryState] + wallet_page),
29
+ 'getEndUserByExternalId' => route.call('GET', '/end-users/by-external/:externalCustomerId', idempotency_key: false, query: %w[programId]),
30
+ 'getEndUser' => route.call('GET', '/end-users/:endUserId', idempotency_key: false),
31
+ 'freezeEndUser' => route.call('POST', '/end-users/:endUserId/freeze', idempotency_key: true, optional: %w[reason]),
32
+ 'getBalances' => route.call('GET', '/end-users/:endUserId/balances', idempotency_key: false),
33
+ 'getKycLevel' => route.call('GET', '/end-users/:endUserId/kyc-level', idempotency_key: false),
34
+ 'updateKycLevel' => route.call('PUT', '/end-users/:endUserId/kyc-level',
35
+ idempotency_key: true, required: %w[kycLevel sourceRef],
36
+ optional: %w[externalCustomerId programId reason effectiveAt expectedCurrentLevel]),
37
+ 'getLimits' => route.call('GET', '/end-users/:endUserId/limits', idempotency_key: false, query: %w[operationType currency]),
38
+ 'createWallet' => route.call('POST', '/end-users/:endUserId/wallets', idempotency_key: true, optional: %w[name currencies]),
39
+
40
+ 'createWalletAccount' => route.call('POST', '/wallets/:walletId/accounts', idempotency_key: true, required: %w[currency]),
41
+ 'lookupWallet' => route.call('POST', '/wallets/lookup', idempotency_key: false, optional: %w[programId phone walletNo]),
42
+
43
+ 'listDepositInstructions' => route.call('GET', '/end-users/:endUserId/deposit-instructions', idempotency_key: false),
44
+ 'createDepositInstruction' => route.call('POST', '/end-users/:endUserId/deposit-instructions',
45
+ idempotency_key: false, required: %w[walletAccountId], optional: %w[currency]),
46
+ 'simulateInboundCredit' => route.call('POST', '/bank-integrations/inbound-credits',
47
+ idempotency_key: false, required: %w[programId railId amount currency rawReference],
48
+ optional: %w[senderName senderIban creditedIban receiptNumber]),
49
+
50
+ 'createCorporateAccount' => route.call('POST', '/corporate-accounts',
51
+ idempotency_key: true, required: %w[programId code name ownerEndUserId], optional: %w[fundingCurrency]),
52
+ 'listCorporateAccounts' => route.call('GET', '/corporate-accounts', idempotency_key: false, query: %w[programId status] + wallet_page),
53
+ 'importCorporateEmployees' => route.call('POST', '/corporate-accounts/:corporateAccountId/employees/import', idempotency_key: true, required: %w[rows]),
54
+ 'offboardCorporateEmployees' => route.call('POST', '/corporate-accounts/:corporateAccountId/employees/offboard',
55
+ idempotency_key: true, required: %w[rows], optional: %w[reason]),
56
+
57
+ 'quoteFees' => route.call('POST', '/fees/quote', idempotency_key: false, required: %w[programId operationType currency amount], optional: %w[at]),
58
+
59
+ 'quoteW2W' => route.call('POST', '/transfers/w2w/quote',
60
+ idempotency_key: false, required: money_move, optional: %w[destinationWalletNo destinationPhone paymentPurpose]),
61
+ 'initiateW2W' => route.call('POST', '/transfers/w2w',
62
+ idempotency_key: true, required: money_move,
63
+ optional: %w[destinationWalletNo destinationPhone paymentPurpose] + initiate_extra),
64
+ 'completeW2W' => route.call('POST', '/transfers/w2w/:operationId/complete',
65
+ idempotency_key: true, required: complete_required, optional: complete_optional),
66
+
67
+ 'quoteW2Iban' => route.call('POST', '/transfers/w2iban/quote', idempotency_key: false, required: iban_move, optional: %w[bankCode paymentPurpose]),
68
+ 'initiateW2Iban' => route.call('POST', '/transfers/w2iban',
69
+ idempotency_key: true, required: iban_move, optional: %w[bankCode paymentPurpose] + initiate_extra),
70
+ 'completeW2Iban' => route.call('POST', '/transfers/w2iban/:operationId/complete',
71
+ idempotency_key: true, required: complete_required, optional: complete_optional),
72
+
73
+ 'quoteBankWithdrawal' => route.call('POST', '/withdrawals/bank/quote', idempotency_key: false, required: iban_move, optional: %w[bankCode paymentPurpose]),
74
+ 'initiateBankWithdrawal' => route.call('POST', '/withdrawals/bank',
75
+ idempotency_key: true, required: iban_move, optional: %w[bankCode paymentPurpose] + initiate_extra),
76
+ 'completeBankWithdrawal' => route.call('POST', '/withdrawals/bank/:operationId/complete',
77
+ idempotency_key: true, required: complete_required, optional: complete_optional),
78
+ 'getWithdrawal' => route.call('GET', '/withdrawals/:operationId', idempotency_key: false),
79
+
80
+ 'listOperations' => route.call('GET', '/operations',
81
+ idempotency_key: false, query: %w[endUserId walletAccountId status operationType destinationWalletAccountId] + wallet_page),
82
+ 'getOperation' => route.call('GET', '/operations/:operationId', idempotency_key: false),
83
+ 'getOperationReceipt' => route.call('GET', '/operations/:operationId/receipt', idempotency_key: false),
84
+
85
+ 'startCardTopup' => route.call('POST', '/topups/card',
86
+ idempotency_key: true, required: %w[creditWalletAccountId amount currency],
87
+ optional: %w[fundingMerchantId savedCardUserKey savedCardToken savedConsumerToken savedPublicCardStorageToken returnUrl]),
88
+ 'getTopup' => route.call('GET', '/topups/:operationId', idempotency_key: false),
89
+ # The gateway DTO marks approverPrincipal optional, but the wallet service refuses the refund without
90
+ # it (400 WALLET_VALIDATION): it is required in practice.
91
+ 'refundTopup' => route.call('POST', '/topups/:operationId/refund', idempotency_key: false, required: %w[reason requesterPrincipal approverPrincipal]),
92
+ 'agentTopup' => route.call('POST', '/agent-topups', idempotency_key: true, required: %w[agentId creditWalletAccountId amount currency]),
93
+
94
+ 'requestPayment' => route.call('POST', '/payments/buy',
95
+ idempotency_key: true, required: %w[amount currency paymentPurpose],
96
+ optional: %w[buyerWalletNo buyerPhone orderRef cashierRef otpDestination otpChannel locale]),
97
+ 'approvePayment' => route.call('POST', '/payments/:operationId/approve',
98
+ idempotency_key: true, required: %w[buyerEndUserId integrityHash nonce], optional: complete_optional),
99
+ 'collectByCode' => route.call('POST', '/collect', idempotency_key: true, required: %w[code amount currency], optional: %w[orderRef paymentPurpose locale]),
100
+ 'getPayment' => route.call('GET', '/payments/:operationId', idempotency_key: false),
101
+ 'getBusinessCommission' => route.call('GET', '/business-accounts/:businessAccountId/commission', idempotency_key: false),
102
+
103
+ 'createQr' => route.call('POST', '/qr',
104
+ idempotency_key: true, required: %w[qrType currency],
105
+ optional: %w[targetEndUserId targetExternalCustomerId programId amount expiresInSeconds metadata]),
106
+ 'listQr' => route.call('GET', '/qr', idempotency_key: false, query: %w[programId qrType status targetEndUserId] + wallet_page),
107
+ 'getQr' => route.call('GET', '/qr/:qrId', idempotency_key: false),
108
+ 'getQrImage' => route.call('GET', '/qr/:qrId/image', idempotency_key: false, binary: true, query: %w[format scale]),
109
+ 'revokeQr' => route.call('POST', '/qr/:qrId/revoke', idempotency_key: false),
110
+ 'parseQr' => route.call('POST', '/qr/parse', idempotency_key: false, required: %w[payload]),
111
+
112
+ 'createBulkPayout' => route.call('POST', '/bulk-payouts',
113
+ idempotency_key: true, required: %w[programId sourceWalletAccountId currency items], optional: %w[reason]),
114
+ 'listBulkPayouts' => route.call('GET', '/bulk-payouts', idempotency_key: false, query: %w[programId status limit]),
115
+ 'getBulkPayout' => route.call('GET', '/bulk-payouts/:batchId', idempotency_key: false),
116
+ 'listBulkPayoutItems' => route.call('GET', '/bulk-payouts/:batchId/items', idempotency_key: false, query: %w[status limit]),
117
+ 'submitBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/submit', idempotency_key: false),
118
+ 'approveBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/approve', idempotency_key: false, required: %w[approve], optional: %w[reason]),
119
+ 'rejectBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/reject', idempotency_key: false, optional: %w[reason]),
120
+ 'processBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/process', idempotency_key: false),
121
+ 'retryFailedBulkPayout' => route.call('POST', '/bulk-payouts/:batchId/retry-failed', idempotency_key: false)
122
+ }.freeze
123
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # Wallet values (/api/v1/wallet, product WALLET_SERVICE); the route table is in wallet_routes.rb.
5
+ module WalletAccountType
6
+ PERSONAL = 'PERSONAL'
7
+ BUSINESS = 'BUSINESS'
8
+ ALL = [PERSONAL, BUSINESS].freeze
9
+ end
10
+
11
+ module WalletEndUserStatus
12
+ ACTIVE = 'ACTIVE'
13
+ FROZEN = 'FROZEN'
14
+ CLOSED = 'CLOSED'
15
+ ALL = [ACTIVE, FROZEN, CLOSED].freeze
16
+ end
17
+
18
+ module WalletKycLevel
19
+ NONE = 'NONE'
20
+ LOW = 'LOW'
21
+ SUBSTANTIAL = 'SUBSTANTIAL'
22
+ HIGH = 'HIGH'
23
+ ALL = [NONE, LOW, SUBSTANTIAL, HIGH].freeze
24
+ end
25
+
26
+ module WalletOtpChannel
27
+ EMAIL = 'EMAIL'
28
+ SMS = 'SMS'
29
+ PUSH = 'PUSH'
30
+ ALL = [EMAIL, SMS, PUSH].freeze
31
+ end
32
+
33
+ module WalletQrType
34
+ P2P_STATIC = 'P2P_STATIC'
35
+ P2P_DYNAMIC = 'P2P_DYNAMIC'
36
+ MERCHANT_STATIC = 'MERCHANT_STATIC'
37
+ MERCHANT_DYNAMIC = 'MERCHANT_DYNAMIC'
38
+ ALL = [P2P_STATIC, P2P_DYNAMIC, MERCHANT_STATIC, MERCHANT_DYNAMIC].freeze
39
+ end
40
+
41
+ module WalletQrImageFormat
42
+ SVG = 'svg'
43
+ PNG = 'png'
44
+ ALL = [SVG, PNG].freeze
45
+ end
46
+
47
+ module WalletBulkTargetType
48
+ WALLET = 'WALLET'
49
+ IBAN = 'IBAN'
50
+ ALL = [WALLET, IBAN].freeze
51
+ end
52
+
53
+ module WalletCorporateAccountStatus
54
+ ACTIVE = 'ACTIVE'
55
+ ARCHIVED = 'ARCHIVED'
56
+ ALL = [ACTIVE, ARCHIVED].freeze
57
+ end
58
+
59
+ # Minor units as a decimal string: "12550" is 125.50 TRY. Never a number.
60
+ WALLET_AMOUNT_PATTERN = /\A\d{1,18}\z/
61
+ # The gateway trims the Idempotency-Key header and accepts 1–128 characters.
62
+ WALLET_IDEMPOTENCY_KEY_MAX = 128
63
+ # Body fields that carry a minor-unit amount string.
64
+ WALLET_AMOUNT_FIELDS = %w[amount].freeze
65
+ # Fields of the nested rows / items the gateway validates element by element ("route.field").
66
+ WALLET_NESTED_FIELDS = {
67
+ 'importCorporateEmployees.rows' => { 'required' => %w[phone].freeze, 'optional' => %w[displayName externalCustomerId kycRef].freeze }.freeze,
68
+ 'offboardCorporateEmployees.rows' => { 'required' => [].freeze, 'optional' => %w[endUserId externalCustomerId].freeze }.freeze,
69
+ 'createBulkPayout.items' => { 'required' => %w[targetType targetRef amount].freeze, 'optional' => %w[beneficiaryName].freeze }.freeze
70
+ }.freeze
71
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # Canonical money of the subscription and marketplace contracts (bodies, filters and answers).
5
+ module WireMoney
6
+ # Money members of the subscription and marketplace contracts: canonical minor-unit strings, signed
7
+ # only for balances. The same list as the Node SDK's validateWireMoney.
8
+ FIELDS = %w[
9
+ amount amountMinor price priceAmount paidAmount totalAmount subtotalAmount taxAmount amountPaid
10
+ legAmount chargeAmount capturedAmount refundedAmount authorizedAmount compensatedAmount
11
+ requestedAmount refundableAmount nonRefundableAmount disputedAmount legsAmount
12
+ minAmount maxAmount minAmountMinor maxAmountMinor unitPriceMinor collectedAmountMinor
13
+ premiumAmount collectedPremiumAmount inForcePremiumAmount cancelledPremiumAmount
14
+ refundedPremiumAmount refundOpenPremiumAmount insuranceValueAmount priceSnapshotAmount
15
+ sourceAmountMinor targetAmountMinor taxAmountMinor balanceMinor balanceAfterMinor
16
+ availableMinor blockedMinor availableWithoutOverdraftMinor overdraftAvailableMinor
17
+ sourceBalanceAfterMinor targetBalanceAfterMinor balance availableBalance blockedBalance
18
+ feeAmount feeAmountMinor fixedAmountMinor minTransactionMinor commissionAmountMinor payoutAmountMinor
19
+ settlementAmountMinor netAmountMinor grossAmountMinor fixedAmount fixedFee fixedFeeMinor mtdVolumeMinor
20
+ orderAmountMinor capturedAmountMinor cumulativeCapturedMinor remainingCapturableMinor
21
+ refundAmountMinor cumulativeRefundedMinor remainingRefundableMinor netAmount grossAmount
22
+ ].freeze
23
+ # Closed schema containers of those contracts; metadata, custom fields and provider bodies are opaque.
24
+ CONTAINERS = %w[
25
+ data items legs steps pendingSteps schedule promissoryNote notes
26
+ aggregate refund dispute details payment basketItems sellers scenario
27
+ counters balances totals orders policies options quote order transfer
28
+ commission commissionRule fee settlement payout context
29
+ ].freeze
30
+ SIGNED_FIELDS = %w[availableMinor availableWithoutOverdraftMinor].freeze
31
+
32
+ module_function
33
+
34
+ # Subscription and marketplace bodies, filters and answers: every FIELDS member is a canonical
35
+ # minor-unit string ("0" allowed; signed only for balances), checked the same way in both directions
36
+ # without coercion. The error names the field, never its value.
37
+ def validate_wire(value)
38
+ case value
39
+ when Array
40
+ value.each { |entry| validate_wire(entry) }
41
+ when Hash
42
+ value.each do |name, entry|
43
+ key = name.to_s
44
+ next if entry.nil?
45
+
46
+ if FIELDS.include?(key)
47
+ wire_minor!(entry, key, positive: false, signed: key.downcase.include?('balance') || SIGNED_FIELDS.include?(key))
48
+ elsif key == 'suggestedAmountsMinor'
49
+ raise ConfigurationError, 'suggestedAmountsMinor must be an array.' unless entry.is_a?(Array)
50
+
51
+ entry.each { |amount| wire_minor!(amount, key) }
52
+ elsif CONTAINERS.include?(key)
53
+ validate_wire(entry)
54
+ end
55
+ end
56
+ end
57
+ value
58
+ end
59
+
60
+ # Money.minor with the field named in the error.
61
+ def wire_minor!(value, field, positive: true, signed: false)
62
+ Money.minor(value, positive: positive, signed: signed)
63
+ rescue ConfigurationError
64
+ raise ConfigurationError, "#{field} must be a canonical string in minor units (e.g. \"9900\" for 99.00).", cause: nil
65
+ end
66
+ end
67
+ end