lunixi-sdk 1.3.1 → 2.2.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +44 -9
  4. data/README.tr.md +39 -8
  5. data/docs/card-rewards.md +21 -0
  6. data/docs/ruby.en.md +11 -1
  7. data/docs/ruby.tr.md +11 -1
  8. data/lib/lunixi/bank_connect.rb +132 -15
  9. data/lib/lunixi/bank_connect_filters.rb +13 -3
  10. data/lib/lunixi/bank_connect_pos.rb +165 -0
  11. data/lib/lunixi/bank_connect_values.rb +127 -5
  12. data/lib/lunixi/card_requests.rb +34 -5
  13. data/lib/lunixi/client.rb +15 -8
  14. data/lib/lunixi/direct_method_payment_request.rb +27 -3
  15. data/lib/lunixi/fraud.rb +3 -2
  16. data/lib/lunixi/fraud_uk_claims.rb +127 -0
  17. data/lib/lunixi/fraud_values.rb +46 -0
  18. data/lib/lunixi/marketplace.rb +8 -2
  19. data/lib/lunixi/order_details.rb +115 -0
  20. data/lib/lunixi/payment_link_rules.rb +13 -1
  21. data/lib/lunixi/payment_link_values.rb +9 -3
  22. data/lib/lunixi/payment_links.rb +3 -1
  23. data/lib/lunixi/payment_values.rb +22 -2
  24. data/lib/lunixi/payments.rb +45 -9
  25. data/lib/lunixi/product_webhooks.rb +17 -1
  26. data/lib/lunixi/route_table.rb +10 -5
  27. data/lib/lunixi/routing_pin.rb +247 -0
  28. data/lib/lunixi/sanction.rb +77 -17
  29. data/lib/lunixi/sanction_batch.rb +215 -0
  30. data/lib/lunixi/sanction_values.rb +289 -5
  31. data/lib/lunixi/split_payment.rb +22 -2
  32. data/lib/lunixi/subscription_resources.rb +3 -1
  33. data/lib/lunixi/subscription_routing.rb +70 -0
  34. data/lib/lunixi/subscription_values.rb +40 -4
  35. data/lib/lunixi/subscriptions.rb +22 -2
  36. data/lib/lunixi/version.rb +1 -1
  37. data/lib/lunixi/wallet_resources.rb +7 -2
  38. data/lib/lunixi/wallet_routes.rb +5 -2
  39. data/lib/lunixi.rb +7 -0
  40. metadata +9 -1
@@ -16,19 +16,23 @@ module Lunixi
16
16
  # outside its set, limit outside 1–100, more than 100 account ids, a malformed amount or a bad date
17
17
  # window raises ConfigurationError. Filter keys are the wire names (snake_case works too).
18
18
  #
19
- # Money movement is on transfers (Lunixi::BankConnectTransfers) and fx (Lunixi::BankConnectFx), for a
20
- # connection whose capabilities include OUTGOING_TRANSFER / FX_EXCHANGE.
19
+ # Money movement is on transfers (Lunixi::BankConnectTransfers), transfer_recipients
20
+ # (Lunixi::BankConnectTransferRecipients) and fx (Lunixi::BankConnectFx), for a connection whose
21
+ # capabilities include OUTGOING_TRANSFER / FX_EXCHANGE. The bank's merchant (POS) records are read on
22
+ # pos_accounts (Lunixi::BankConnectPosAccounts) for a connection with POS_ACQUIRING.
21
23
  #
22
24
  # Answers are the envelope's data; lists return a Lunixi::ListPage.
23
25
  class BankConnect
24
26
  BASE = '/api/v1/bank-connect'
25
- attr_reader :transfers, :fx
27
+ attr_reader :transfers, :fx, :transfer_recipients, :pos_accounts
26
28
 
27
29
  def initialize(client, max_retries:, backoff:)
28
30
  @client = client
29
31
  invoker = BankTransferInvoker.new(client, max_retries: max_retries, backoff: backoff)
30
32
  @transfers = BankConnectTransfers.new(invoker)
31
33
  @fx = BankConnectFx.new(invoker)
34
+ @transfer_recipients = BankConnectTransferRecipients.new(invoker)
35
+ @pos_accounts = BankConnectPosAccounts.new(client)
32
36
  end
33
37
 
34
38
  # The bank catalogue: whether each bank can be connected and what is read from it.
@@ -129,8 +133,13 @@ module Lunixi
129
133
  # Every route, reads included, is signed and needs bank-connect:transfer; the key must have an IP
130
134
  # allowlist and the request must come from a listed IP (403 bank_connect.auth.ip_allowlist_required /
131
135
  # ip_not_allowed). With an API key there is no e-mail code: create answers SUBMITTED and the transfer
132
- # is queued for the bank. Follow it with get or the bank_transfer.* webhooks. The bank chooses the rail;
133
- # Lunixi does not check the balance.
136
+ # is queued for the bank. Follow it with get or the bank_transfer.* webhooks. The rail (own account,
137
+ # same bank, FAST or EFT) is set when the transfer is created; preview shows it beforehand. Lunixi does
138
+ # not check the balance.
139
+ #
140
+ # The receiver is exactly one of receiverIban (typed IBAN), recipientId (a saved recipient, see
141
+ # bank_connect.transfer_recipients) or receiverAccountId (your own account on the same connection:
142
+ # internal transfer).
134
143
  class BankConnectTransfers
135
144
  def initialize(invoker)
136
145
  @invoker = invoker
@@ -142,10 +151,26 @@ module Lunixi
142
151
  @invoker.data('listTransferPurposes', query: { 'connectionId' => RouteValue.text!(connection_id, 'connectionId') })
143
152
  end
144
153
 
145
- # Creates an outgoing transfer (HTTP 201): { transfer, stepUp, replayed }. request: accountId,
146
- # receiverIban (TR IBAN, at most 42 characters), receiverName (2–140 characters), amountMinor (a
147
- # positive minor-unit string: "150075" = 1,500.75 TRY), optional currency, paymentPurpose and
148
- # description (at most 140 characters).
154
+ # Route preview: { rail, arrival, receiverBank, receiverIbanMasked, ownAccount, fastStatus, notes }.
155
+ # Stores nothing and sends nothing to the bank. request: accountId, amountMinor, exactly one receiver
156
+ # field (receiverIban | recipientId | receiverAccountId), optional currency. rail UNKNOWN: the bank
157
+ # offers no preview; the transfer can still be sent. Creating the transfer applies the same rule
158
+ # (transfer.plannedRail). notes are BankTransferPreviewNote codes.
159
+ def preview(request)
160
+ body = @invoker.body!('previewTransfer', request)
161
+ BankTransferInvoker.check_receiver!('previewTransfer', body)
162
+ body['currency'] = RouteValue.currency!(body['currency'], 'currency') if body.key?('currency')
163
+ @invoker.post('previewTransfer', body)
164
+ end
165
+
166
+ # Creates an outgoing transfer (HTTP 201): { transfer, stepUp, replayed }. request: accountId, exactly
167
+ # one receiver field — receiverIban (TR IBAN, at most 42 characters), recipientId (saved recipient) or
168
+ # receiverAccountId (your own account, internal transfer) —, receiverName (2–140 characters; required
169
+ # with receiverIban, otherwise the saved / account name is used when left out), amountMinor (a
170
+ # positive minor-unit string: "150075" = 1,500.75 TRY), optional currency, paymentPurpose, description
171
+ # (at most 140 characters) and saveRecipient ({ nickname: }: add or update the receiver in your saved
172
+ # recipients once the bank accepts the transfer; ignored with receiverAccountId). The transfer
173
+ # carries plannedRail, railFallbackFrom, recipientId and receiverAccountId.
149
174
  #
150
175
  # idempotency_key (8–200 printable ASCII) is generated (UUID v4) when nil; a network error or a 5xx
151
176
  # is retried with the same key and body. Keep your own key (e.g. your payout id) to retry safely
@@ -178,6 +203,57 @@ module Lunixi
178
203
  end
179
204
  end
180
205
 
206
+ # bank_connect.transfer_recipients: saved recipients (/api/v1/bank-connect/transfer-recipients). Same
207
+ # scope and IP allowlist rule as transfers. The full IBAN is never returned (only ibanMasked); send
208
+ # money to a saved recipient with transfers.create(recipientId: ...). One recipient per IBAN and
209
+ # environment: creating an existing IBAN is 409 bank_connect.transfer.recipient_exists
210
+ # (details.recipientId).
211
+ class BankConnectTransferRecipients
212
+ def initialize(invoker)
213
+ @invoker = invoker
214
+ end
215
+
216
+ # Saved recipients, newest first. Filters: q (1–64 characters; name, nickname or bank name), limit
217
+ # 1–100, cursor.
218
+ def list(**filters)
219
+ @invoker.page('listTransferRecipients', query: BankConnectFilters.transfer_query!(filters, 'listTransferRecipients'))
220
+ end
221
+
222
+ def iterate(**filters, &block)
223
+ RouteResponse.each_item(filters, block) { |query| list(**query) }
224
+ end
225
+
226
+ # Adds a recipient (HTTP 201). request: iban (TR IBAN), name (2–140 characters), optional nickname (at
227
+ # most 64 characters).
228
+ def create(request)
229
+ body = @invoker.body!('createTransferRecipient', request)
230
+ body['name'] = BankTransferInvoker.name!('name', body['name'])
231
+ body['nickname'] = BankTransferInvoker.nickname!(body['nickname']) if body.key?('nickname')
232
+ @invoker.post('createTransferRecipient', body)
233
+ end
234
+
235
+ # Changes name and/or nickname; the IBAN cannot change. nickname: '' removes the nickname (sent as is).
236
+ def update(recipient_id, changes)
237
+ given = RouteRequest.wire_keys!(changes, %w[name nickname], 'updateTransferRecipient')
238
+ body = {}
239
+ body['name'] = BankTransferInvoker.name!('name', given['name']) if given.key?('name')
240
+ body['nickname'] = BankTransferInvoker.nickname!(given['nickname']) if given.key?('nickname')
241
+ raise ConfigurationError, 'updateTransferRecipient needs name or nickname.' if body.empty?
242
+
243
+ @invoker.post('updateTransferRecipient', body, params: { 'recipientId' => recipient_id })
244
+ end
245
+
246
+ # Removes a recipient: { deleted: true }. Past transfers are not affected and the IBAN can be added
247
+ # again.
248
+ def delete(recipient_id)
249
+ @invoker.data('deleteTransferRecipient', params: { 'recipientId' => recipient_id })
250
+ end
251
+
252
+ def inspect
253
+ '#<Lunixi::BankConnectTransferRecipients>'
254
+ end
255
+ end
256
+
181
257
  # bank_connect.fx: currency exchange between two active accounts of one connection in different
182
258
  # currencies (/api/v1/bank-connect/fx). Same scope and IP allowlist rule as transfers.
183
259
  #
@@ -239,12 +315,27 @@ module Lunixi
239
315
  # take the caller's key (checked) or a new UUID v4, and are retried with the same key and body after
240
316
  # a network error or a 5xx. Not a public API.
241
317
  class BankTransferInvoker
242
- def self.check_transfer!(body)
243
- raise ConfigurationError, "'receiverIban' must be at most #{BANK_TRANSFER_IBAN_MAX} characters." if body['receiverIban'].length > BANK_TRANSFER_IBAN_MAX
244
- unless body['receiverName'].length.between?(BANK_TRANSFER_RECEIVER_NAME_MIN, BANK_TRANSFER_RECEIVER_NAME_MAX)
245
- raise ConfigurationError, "'receiverName' must be #{BANK_TRANSFER_RECEIVER_NAME_MIN}-#{BANK_TRANSFER_RECEIVER_NAME_MAX} characters."
318
+ # Exactly one of receiverIban / recipientId / receiverAccountId (the gateway answers 400
319
+ # receiver.exactly_one_required otherwise); returns the receiver field.
320
+ def self.check_receiver!(name, body)
321
+ given = BANK_TRANSFER_RECEIVER_FIELDS.select { |key| body.key?(key) }
322
+ raise ConfigurationError, "#{name} takes exactly one of #{BANK_TRANSFER_RECEIVER_FIELDS.join(', ')}." unless given.length == 1
323
+
324
+ field = given.first
325
+ body[field] = RouteValue.text!(body[field], field)
326
+ if field == 'receiverIban' && body[field].length > BANK_TRANSFER_IBAN_MAX
327
+ raise ConfigurationError, "'receiverIban' must be at most #{BANK_TRANSFER_IBAN_MAX} characters."
246
328
  end
247
329
 
330
+ field
331
+ end
332
+
333
+ def self.check_transfer!(body)
334
+ receiver = check_receiver!('createTransfer', body)
335
+ raise ConfigurationError, 'createTransfer requires receiverName with receiverIban.' if receiver == 'receiverIban' && !body.key?('receiverName')
336
+
337
+ body['receiverName'] = name!('receiverName', body['receiverName']) if body.key?('receiverName')
338
+ body['saveRecipient'] = save_recipient!(body['saveRecipient']) if body.key?('saveRecipient')
248
339
  body['currency'] = RouteValue.currency!(body['currency'], 'currency') if body.key?('currency')
249
340
  if body.key?('paymentPurpose') && !(body['paymentPurpose'].is_a?(String) && body['paymentPurpose'].match?(BANK_TRANSFER_PAYMENT_PURPOSE_PATTERN))
250
341
  raise ConfigurationError, "'paymentPurpose' must be a code from list_purposes (letters, digits, underscore; at most 64)."
@@ -254,6 +345,31 @@ module Lunixi
254
345
  body
255
346
  end
256
347
 
348
+ # A receiver or recipient name: 2–140 characters, trimmed.
349
+ def self.name!(field, value)
350
+ name = RouteValue.text!(value, field)
351
+ return name if name.length.between?(BANK_TRANSFER_RECEIVER_NAME_MIN, BANK_TRANSFER_RECEIVER_NAME_MAX)
352
+
353
+ raise ConfigurationError, "'#{field}' must be #{BANK_TRANSFER_RECEIVER_NAME_MIN}-#{BANK_TRANSFER_RECEIVER_NAME_MAX} characters."
354
+ end
355
+
356
+ # A saved recipient nickname: a String of at most 64 characters, trimmed ('' is kept).
357
+ def self.nickname!(value)
358
+ return value.strip if value.is_a?(String) && value.strip.length <= BANK_TRANSFER_RECIPIENT_NICKNAME_MAX
359
+
360
+ raise ConfigurationError, "'nickname' must be a string of at most #{BANK_TRANSFER_RECIPIENT_NICKNAME_MAX} characters."
361
+ end
362
+
363
+ # saveRecipient: a Hash with an optional nickname; sent as {} or { 'nickname' => ... }.
364
+ def self.save_recipient!(value)
365
+ unless value.is_a?(Hash) && value.keys.all? { |key| key.to_s == 'nickname' }
366
+ raise ConfigurationError, "'saveRecipient' must be a Hash with an optional nickname."
367
+ end
368
+
369
+ nickname = value.find { |key, _| key.to_s == 'nickname' }&.last
370
+ nickname.nil? || nickname == '' ? {} : { 'nickname' => nickname!(nickname) }
371
+ end
372
+
257
373
  def self.check_description!(value)
258
374
  return if value.is_a?(String) && value.length <= BANK_TRANSFER_DESCRIPTION_MAX
259
375
 
@@ -297,8 +413,9 @@ module Lunixi
297
413
  RouteResponse.page(@client.request(route['method'], route['path'], query: query))
298
414
  end
299
415
 
300
- def post(name, body)
301
- RouteResponse.unwrap(@client.request('POST', BANK_TRANSFER_ROUTES.fetch(name)['path'], body: body))
416
+ def post(name, body, params: {})
417
+ route = BANK_TRANSFER_ROUTES.fetch(name)
418
+ RouteResponse.unwrap(@client.request(route['method'], RouteRequest.path!(route['path'], params), body: body))
302
419
  end
303
420
 
304
421
  # 1 + max_retries attempts with the same key and body; a network error or a 5xx is retried, anything
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lunixi
4
- # Local checks of the bank-connect read filters (BANK_CONNECT_FILTERS) and of the transfer and FX list
5
- # filters (BANK_TRANSFER_ROUTES query lists). Not a public API.
4
+ # Local checks of the bank-connect read filters (BANK_CONNECT_FILTERS) and of the transfer, recipient and
5
+ # FX list filters (BANK_TRANSFER_ROUTES query lists). Not a public API; the POS account filters are in
6
+ # BankPosFilters.
6
7
  module BankConnectFilters
7
8
  DAY_SECONDS = 24 * 60 * 60
8
9
  AMOUNT_FILTERS = %w[minAmountMinor maxAmountMinor].freeze
@@ -21,7 +22,7 @@ module Lunixi
21
22
  query
22
23
  end
23
24
 
24
- # The query of listTransfers / listFxOrders.
25
+ # The query of listTransfers / listFxOrders / listTransferRecipients.
25
26
  def transfer_query!(filters, route)
26
27
  given = RouteRequest.wire_keys!(filters || {}, BANK_TRANSFER_ROUTES.fetch(route)['query'], 'bank-connect transfer', 'filter')
27
28
  given.each_with_object({}) do |(key, value), out|
@@ -48,10 +49,19 @@ module Lunixi
48
49
  when 'limit', 'cursor' then page_value(key, value)
49
50
  when 'status' then list_of(key, value, route == 'listFxOrders' ? BankFxOrderStatus::ALL : BankTransferStatus::ALL)
50
51
  when 'accountId' then RouteValue.text!(value, key)
52
+ when 'q' then search(value)
51
53
  else RouteValue.iso_time!(value, key)
52
54
  end
53
55
  end
54
56
 
57
+ def search(value)
58
+ unless value.is_a?(String) && !value.strip.empty? && value.strip.length <= BANK_TRANSFER_RECIPIENT_SEARCH_MAX
59
+ raise ConfigurationError, "'q' must be 1-#{BANK_TRANSFER_RECIPIENT_SEARCH_MAX} characters."
60
+ end
61
+
62
+ value.strip
63
+ end
64
+
55
65
  def page_value(key, value)
56
66
  if key == 'limit'
57
67
  unless value.is_a?(Integer) && value.between?(1, BANK_CONNECT_MAX_LIMIT)
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lunixi
4
+ # bank_connect.pos_accounts: your merchant (acquiring) records at a connected bank
5
+ # (/api/v1/bank-connect/pos-accounts) — merchant accounts, terminals, POS transactions, the value date
6
+ # calendar and the end-of-day summary.
7
+ #
8
+ # These are the bank's records: every terminal of yours at the bank is included (other devices, virtual
9
+ # POS, e-commerce). They are read only on a connection whose capabilities has POS_ACQUIRING. Card
10
+ # numbers are masked; amounts are minor-unit strings; a field without a value is nil.
11
+ #
12
+ # Scopes: bank-connect:view for accounts, terminals and request_sync; bank-connect:transactions:view for
13
+ # transactions, the statement and the day summary. Every call is signed, reads included. 404
14
+ # bank_connect.acquiring_account.not_found for an unknown POS account; 400
15
+ # bank_connect.acquiring.range_invalid for a range the service rejects. Filters are checked against
16
+ # BANK_POS_FILTERS before anything is sent.
17
+ class BankConnectPosAccounts
18
+ BASE = '/api/v1/bank-connect/pos-accounts'
19
+
20
+ def initialize(client)
21
+ @client = client
22
+ end
23
+
24
+ # Your POS accounts. connectionId narrows to one connection.
25
+ def list_accounts(**filters)
26
+ page('', 'listPosAccounts', filters)
27
+ end
28
+
29
+ def iterate_accounts(**filters, &block)
30
+ RouteResponse.each_item(filters, block) { |query| list_accounts(**query) }
31
+ end
32
+
33
+ # 404 bank_connect.acquiring_account.not_found for an unknown POS account.
34
+ def get_account(pos_account_id)
35
+ read(account_path(pos_account_id))
36
+ end
37
+
38
+ def list_terminals(pos_account_id, **filters)
39
+ page("#{account_path(pos_account_id)}/terminals", 'listPosTerminals', filters)
40
+ end
41
+
42
+ def iterate_terminals(pos_account_id, **filters, &block)
43
+ RouteResponse.each_item(filters, block) { |query| list_terminals(pos_account_id, **query) }
44
+ end
45
+
46
+ # POS transactions (bank-connect:transactions:view). from (inclusive) / to (exclusive) filter on the
47
+ # transaction time: a Time or an ISO 8601 string with a time zone, at most 92 days apart; without them
48
+ # the last 30 days. type takes one value or an Array of BankPosTransactionType. minAmountMinor /
49
+ # maxAmountMinor are non-negative minor-unit strings. provisional true returns only intraday rows,
50
+ # false only final ones; an intraday row is updated in place by the bank's end-of-day record.
51
+ def list_transactions(pos_account_id, **filters)
52
+ page("#{account_path(pos_account_id)}/transactions", 'listPosTransactions', filters)
53
+ end
54
+
55
+ def iterate_transactions(pos_account_id, **filters, &block)
56
+ RouteResponse.each_item(filters, block) { |query| list_transactions(pos_account_id, **query) }
57
+ end
58
+
59
+ # The value date calendar: amounts to be credited per value date (gross, commission, service fee,
60
+ # net), oldest value date first. from / to are YYYY-MM-DD value dates, both inclusive; without from
61
+ # today, without to 60 days after today.
62
+ def list_statement(pos_account_id, **filters)
63
+ page("#{account_path(pos_account_id)}/statement", 'listPosStatement', filters)
64
+ end
65
+
66
+ def iterate_statement(pos_account_id, **filters, &block)
67
+ RouteResponse.each_item(filters, block) { |query| list_statement(pos_account_id, **query) }
68
+ end
69
+
70
+ # End-of-day status and totals of one day (YYYY-MM-DD, Turkey time).
71
+ def get_day_summary(pos_account_id, business_date)
72
+ day = BankPosFilters.day!(business_date, 'businessDate')
73
+ read("#{account_path(pos_account_id)}/days/#{day}")
74
+ end
75
+
76
+ # Brings the intraday read forward (no body, no Idempotency-Key). SCHEDULED with scheduledAt when the
77
+ # bank's read interval has not passed; a request while one is waiting joins it (coalesced: true).
78
+ def request_sync(pos_account_id)
79
+ RouteResponse.unwrap(@client.request('POST', "#{BASE}#{account_path(pos_account_id)}/sync"))
80
+ end
81
+
82
+ def inspect
83
+ '#<Lunixi::BankConnectPosAccounts>'
84
+ end
85
+
86
+ private
87
+
88
+ def page(path, route, filters)
89
+ RouteResponse.page(@client.request('GET', BASE + path, query: BankPosFilters.query!(filters, route)))
90
+ end
91
+
92
+ def read(path)
93
+ RouteResponse.unwrap(@client.request('GET', BASE + path))
94
+ end
95
+
96
+ def account_path(pos_account_id)
97
+ "/#{RouteRequest.path!(':posAccountId', 'posAccountId' => pos_account_id)}"
98
+ end
99
+ end
100
+
101
+ # Local checks of the POS account filters (BANK_POS_FILTERS). Not a public API.
102
+ module BankPosFilters
103
+ DAY = /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/
104
+
105
+ module_function
106
+
107
+ # The query of a POS account list: unknown filters, a type outside BankPosTransactionType, a bad card
108
+ # brand, a negative or malformed amount, a non-boolean provisional, limit outside 1–100 or a from … to
109
+ # window over 92 days raise ConfigurationError. The statement's from / to are YYYY-MM-DD value dates.
110
+ def query!(filters, route)
111
+ given = RouteRequest.wire_keys!(filters || {}, BANK_POS_FILTERS.fetch(route), 'POS account', 'filter')
112
+ query = given.each_with_object({}) do |(key, value), out|
113
+ out[key] = filter_value(key, value, route) if RouteRequest.present?(value)
114
+ end
115
+ check_window!(query) if route == 'listPosTransactions'
116
+ query
117
+ end
118
+
119
+ # A YYYY-MM-DD date (trimmed).
120
+ def day!(value, field)
121
+ raise ConfigurationError, "'#{field}' must be a date in YYYY-MM-DD form." unless value.is_a?(String) && value.strip.match?(DAY)
122
+
123
+ value.strip
124
+ end
125
+
126
+ def filter_value(key, value, route)
127
+ case key
128
+ when 'limit', 'cursor' then BankConnectFilters.page_value(key, value)
129
+ when 'connectionId', 'terminalId' then RouteValue.text!(value, key)
130
+ when 'from', 'to' then route == 'listPosStatement' ? day!(value, key) : RouteValue.iso_time!(value, key)
131
+ when 'type' then BankConnectFilters.list_of(key, value, BankPosTransactionType::ALL)
132
+ when 'cardBrand' then card_brand(value)
133
+ when 'provisional'
134
+ raise ConfigurationError, "'provisional' must be true or false." unless [true, false].include?(value)
135
+
136
+ value.to_s
137
+ else BankConnectFilters.amount(key, value)
138
+ end
139
+ end
140
+
141
+ def card_brand(value)
142
+ unless value.is_a?(String) && value.strip.match?(BANK_POS_CARD_BRAND_PATTERN)
143
+ raise ConfigurationError, "'cardBrand' must be a card brand such as VISA, MASTERCARD, TROY or AMEX."
144
+ end
145
+
146
+ value.strip
147
+ end
148
+
149
+ # When both are readable from <= to and at most 92 days apart; minAmountMinor <= maxAmountMinor.
150
+ def check_window!(query)
151
+ from = RouteValue.instant(query['from'])
152
+ to = RouteValue.instant(query['to'])
153
+ if from && to
154
+ raise ConfigurationError, "'from' must not be after 'to'." if from > to
155
+ if to - from > BANK_POS_TRANSACTION_RANGE_MAX_DAYS * BankConnectFilters::DAY_SECONDS
156
+ raise ConfigurationError, "'from' and 'to' may be at most #{BANK_POS_TRANSACTION_RANGE_MAX_DAYS} days apart."
157
+ end
158
+ end
159
+ return unless query.key?('minAmountMinor') && query.key?('maxAmountMinor')
160
+ return unless query['minAmountMinor'].to_i > query['maxAmountMinor'].to_i
161
+
162
+ raise ConfigurationError, "'minAmountMinor' must not be greater than 'maxAmountMinor'."
163
+ end
164
+ end
165
+ end
@@ -59,14 +59,16 @@ module Lunixi
59
59
  end
60
60
 
61
61
  # What a bank or a connection offers. OUTGOING_TRANSFER and FX_EXCHANGE open bank_connect.transfers and
62
- # bank_connect.fx.
62
+ # bank_connect.fx. POS_ACQUIRING: the bank's merchant (POS) records are read (bank_connect.pos_accounts);
63
+ # it cannot be turned off.
63
64
  module BankCapability
64
65
  ACCOUNT_LIST = 'ACCOUNT_LIST'
65
66
  BALANCE = 'BALANCE'
66
67
  TRANSACTIONS = 'TRANSACTIONS'
67
68
  OUTGOING_TRANSFER = 'OUTGOING_TRANSFER'
68
69
  FX_EXCHANGE = 'FX_EXCHANGE'
69
- ALL = [ACCOUNT_LIST, BALANCE, TRANSACTIONS, OUTGOING_TRANSFER, FX_EXCHANGE].freeze
70
+ POS_ACQUIRING = 'POS_ACQUIRING'
71
+ ALL = [ACCOUNT_LIST, BALANCE, TRANSACTIONS, OUTGOING_TRANSFER, FX_EXCHANGE, POS_ACQUIRING].freeze
70
72
  end
71
73
 
72
74
  # QUEUED: the read starts now or is already waiting. SCHEDULED: it runs at scheduledAt.
@@ -110,6 +112,38 @@ module Lunixi
110
112
  ALL = [INTERNAL, INTRABANK, FAST, EFT, UNKNOWN].freeze
111
113
  end
112
114
 
115
+ # When a previewed transfer arrives: INSTANT (internal, same bank, FAST) or BANK_HOURS (EFT).
116
+ module BankTransferArrival
117
+ INSTANT = 'INSTANT'
118
+ BANK_HOURS = 'BANK_HOURS'
119
+ UNKNOWN = 'UNKNOWN'
120
+ ALL = [INSTANT, BANK_HOURS, UNKNOWN].freeze
121
+ end
122
+
123
+ # The receiving bank's FAST status in a route preview; UNKNOWN means EFT is used (safe default).
124
+ module BankFastStatus
125
+ ACTIVE = 'ACTIVE'
126
+ NOT_PARTICIPANT = 'NOT_PARTICIPANT'
127
+ OUT_OF_SERVICE = 'OUT_OF_SERVICE'
128
+ UNKNOWN = 'UNKNOWN'
129
+ ALL = [ACTIVE, NOT_PARTICIPANT, OUT_OF_SERVICE, UNKNOWN].freeze
130
+ end
131
+
132
+ # Machine codes in transfers.preview's notes; they explain why a route was chosen.
133
+ module BankTransferPreviewNote
134
+ OWN_ACCOUNT_INTERNAL = 'own_account_internal'
135
+ OWN_ACCOUNT_OTHER_CONNECTION = 'own_account_other_connection'
136
+ OWN_ACCOUNT_CURRENCY_MISMATCH = 'own_account_currency_mismatch'
137
+ FAST_LIMIT_EXCEEDED = 'fast_limit_exceeded'
138
+ FAST_RECEIVER_NOT_PARTICIPANT = 'fast_receiver_not_participant'
139
+ FAST_RECEIVER_OUT_OF_SERVICE = 'fast_receiver_out_of_service'
140
+ FAST_PARTICIPANTS_UNKNOWN = 'fast_participants_unknown'
141
+ FAST_SENDER_IDENTITY_MISSING = 'fast_sender_identity_missing'
142
+ EFT_LARGE_AMOUNT_DESCRIPTION_REQUIRED = 'eft_large_amount_description_required'
143
+ ALL = [OWN_ACCOUNT_INTERNAL, OWN_ACCOUNT_OTHER_CONNECTION, OWN_ACCOUNT_CURRENCY_MISMATCH, FAST_LIMIT_EXCEEDED, FAST_RECEIVER_NOT_PARTICIPANT,
144
+ FAST_RECEIVER_OUT_OF_SERVICE, FAST_PARTICIPANTS_UNKNOWN, FAST_SENDER_IDENTITY_MISSING, EFT_LARGE_AMOUNT_DESCRIPTION_REQUIRED].freeze
145
+ end
146
+
113
147
  module BankTransferInitiatedVia
114
148
  PANEL = 'PANEL'
115
149
  API = 'API'
@@ -143,6 +177,60 @@ module Lunixi
143
177
  ALL = [CREATED, COMPLETED, FAILED, RETURNED].freeze
144
178
  end
145
179
 
180
+ # Type of a POS transaction in the bank's records; the amount is positive, the direction comes from the
181
+ # type.
182
+ module BankPosTransactionType
183
+ SALE = 'SALE'
184
+ INSTALLMENT_SALE = 'INSTALLMENT_SALE'
185
+ REFUND = 'REFUND'
186
+ VOID = 'VOID'
187
+ PREAUTH_CLOSE = 'PREAUTH_CLOSE'
188
+ BONUS_SALE = 'BONUS_SALE'
189
+ OTHER = 'OTHER'
190
+ ALL = [SALE, INSTALLMENT_SALE, REFUND, VOID, PREAUTH_CLOSE, BONUS_SALE, OTHER].freeze
191
+ end
192
+
193
+ # CARD_PRESENT, ECOMMERCE, MOTO (mail/telephone order) or UNKNOWN.
194
+ module BankPosChannel
195
+ CARD_PRESENT = 'CARD_PRESENT'
196
+ ECOMMERCE = 'ECOMMERCE'
197
+ MOTO = 'MOTO'
198
+ UNKNOWN = 'UNKNOWN'
199
+ ALL = [CARD_PRESENT, ECOMMERCE, MOTO, UNKNOWN].freeze
200
+ end
201
+
202
+ # DAILY: intraday (provisional). END_OF_DAY: the bank's final record. FORWARD: forward value date list.
203
+ module BankPosTransactionSource
204
+ DAILY = 'DAILY'
205
+ END_OF_DAY = 'END_OF_DAY'
206
+ FORWARD = 'FORWARD'
207
+ ALL = [DAILY, END_OF_DAY, FORWARD].freeze
208
+ end
209
+
210
+ # POS account and terminal status. MISSING: not in the bank's latest list; the record is kept.
211
+ module BankPosRecordStatus
212
+ ACTIVE = 'ACTIVE'
213
+ MISSING = 'MISSING'
214
+ ALL = [ACTIVE, MISSING].freeze
215
+ end
216
+
217
+ # End-of-day read status of one POS account day.
218
+ module BankPosDayStatus
219
+ PENDING = 'PENDING'
220
+ COMPLETE = 'COMPLETE'
221
+ FAILED = 'FAILED'
222
+ ALL = [PENDING, COMPLETE, FAILED].freeze
223
+ end
224
+
225
+ # POS account webhook events (subscription bank_pos.*). DAY_CLOSED: a POS account's day closed, the
226
+ # bank's end of day was read for the first time (once per account and day, usually after 01:30 the next
227
+ # day). Read it with Lunixi::BankPosWebhook.parse; data holds BANK_POS_DAY_CLOSED_FIELDS.
228
+ module BankPosEvents
229
+ DAY_CLOSED = 'bank_pos.day_closed'
230
+ PATTERN = 'bank_pos.*'
231
+ ALL = [DAY_CLOSED].freeze
232
+ end
233
+
146
234
  # Query filters each read route accepts (the gateway rejects any other with 400).
147
235
  BANK_CONNECT_FILTERS = {
148
236
  'listBanks' => %w[limit cursor].freeze,
@@ -159,15 +247,31 @@ module Lunixi
159
247
  BANK_CONNECT_BOOKED_RANGE_MAX_DAYS = 92
160
248
  BANK_CONNECT_CURSOR_MAX_LENGTH = 2048
161
249
 
250
+ # Query fields each POS account list accepts (the gateway rejects any other with 400).
251
+ BANK_POS_FILTERS = {
252
+ 'listPosAccounts' => %w[limit cursor connectionId].freeze,
253
+ 'listPosTerminals' => %w[limit cursor].freeze,
254
+ 'listPosTransactions' => %w[limit cursor terminalId from to type cardBrand minAmountMinor maxAmountMinor provisional].freeze,
255
+ 'listPosStatement' => %w[limit cursor terminalId from to].freeze
256
+ }.freeze
257
+ # Widest from … to window of one POS transaction request, in days.
258
+ BANK_POS_TRANSACTION_RANGE_MAX_DAYS = 92
259
+ # Card brands the POS transaction filter takes (the gateway accepts 1–16 letters).
260
+ BANK_POS_CARD_BRAND_PATTERN = /\A[A-Za-z]{1,16}\z/
261
+
162
262
  # Transfer and exchange routes: method, path, body fields, query fields and the Idempotency-Key rule.
163
263
  # The same table as the Node SDK's BANK_TRANSFER_ROUTES (forbidNonWhitelisted: any other field is a
164
264
  # 400); the parity test compares it with the shared catalog. Every route is signed and needs
165
265
  # bank-connect:transfer plus a key with an IP allowlist.
166
266
  BANK_TRANSFER_ROUTES = {
167
267
  'listTransferPurposes' => RouteRequest.route('GET', '/api/v1/bank-connect/transfer-purposes', idempotency_key: false, query: %w[connectionId]),
268
+ 'previewTransfer' => RouteRequest.route('POST', '/api/v1/bank-connect/transfers/preview',
269
+ idempotency_key: false, required: %w[accountId amountMinor],
270
+ optional: %w[receiverIban recipientId receiverAccountId currency]),
168
271
  'createTransfer' => RouteRequest.route('POST', '/api/v1/bank-connect/transfers',
169
- idempotency_key: true, required: %w[accountId receiverIban receiverName amountMinor],
170
- optional: %w[currency paymentPurpose description]),
272
+ idempotency_key: true, required: %w[accountId amountMinor],
273
+ optional: %w[receiverIban recipientId receiverAccountId receiverName currency paymentPurpose description
274
+ saveRecipient]),
171
275
  'listTransfers' => RouteRequest.route('GET', '/api/v1/bank-connect/transfers',
172
276
  idempotency_key: false, query: %w[limit cursor accountId status createdFrom createdTo]),
173
277
  'getTransfer' => RouteRequest.route('GET', '/api/v1/bank-connect/transfers/:transferId', idempotency_key: false),
@@ -177,9 +281,22 @@ module Lunixi
177
281
  optional: %w[sourceAmountMinor targetAmountMinor]),
178
282
  'createFxOrder' => RouteRequest.route('POST', '/api/v1/bank-connect/fx/orders', idempotency_key: true, required: %w[quoteId], optional: %w[description]),
179
283
  'listFxOrders' => RouteRequest.route('GET', '/api/v1/bank-connect/fx/orders', idempotency_key: false, query: %w[limit cursor status]),
180
- 'getFxOrder' => RouteRequest.route('GET', '/api/v1/bank-connect/fx/orders/:orderId', idempotency_key: false)
284
+ 'getFxOrder' => RouteRequest.route('GET', '/api/v1/bank-connect/fx/orders/:orderId', idempotency_key: false),
285
+ 'listTransferRecipients' => RouteRequest.route('GET', '/api/v1/bank-connect/transfer-recipients', idempotency_key: false, query: %w[limit cursor q]),
286
+ 'createTransferRecipient' => RouteRequest.route('POST', '/api/v1/bank-connect/transfer-recipients',
287
+ idempotency_key: false, required: %w[iban name], optional: %w[nickname]),
288
+ 'updateTransferRecipient' => RouteRequest.route('PATCH', '/api/v1/bank-connect/transfer-recipients/:recipientId',
289
+ idempotency_key: false, required: [], optional: %w[name nickname]),
290
+ 'deleteTransferRecipient' => RouteRequest.route('DELETE', '/api/v1/bank-connect/transfer-recipients/:recipientId', idempotency_key: false)
181
291
  }.freeze
182
292
 
293
+ # The receiver of a transfer or a preview: exactly one of these fields.
294
+ BANK_TRANSFER_RECEIVER_FIELDS = %w[receiverIban recipientId receiverAccountId].freeze
295
+ # Longest saved recipient nickname.
296
+ BANK_TRANSFER_RECIPIENT_NICKNAME_MAX = 64
297
+ # Longest q of transfer_recipients.list.
298
+ BANK_TRANSFER_RECIPIENT_SEARCH_MAX = 64
299
+
183
300
  # Idempotency-Key of create_transfer / create_order: 8–200 printable ASCII characters.
184
301
  BANK_TRANSFER_IDEMPOTENCY_KEY_PATTERN = RouteRequest::PRINTABLE_IDEMPOTENCY_KEY
185
302
  # paymentPurpose: a code from transfers.list_purposes.
@@ -202,4 +319,9 @@ module Lunixi
202
319
  transferId connectionId accountId bankEftCode bankName status rail amountMinor currency receiverIbanMasked receiverNameMasked
203
320
  paymentPurpose description failureCode idempotencyKey createdAt completedAt failedAt returnedAt
204
321
  ].freeze
322
+ # data fields of the bank_pos.day_closed webhook (amounts are minor-unit strings, counts integers).
323
+ BANK_POS_DAY_CLOSED_FIELDS = %w[
324
+ acquiringAccountId connectionId bankEftCode bankName merchantNumber businessDate saleCount saleAmountMinor refundCount
325
+ refundAmountMinor netAmountMinor commissionAmountMinor currency
326
+ ].freeze
205
327
  end