lunixi-sdk 2.2.1 → 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.
@@ -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
@@ -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
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ipaddr'
4
+
5
+ module Lunixi
6
+ # Field checks shared by the wallet merchant client and the wallet portal client: per-field rules,
7
+ # checked query parameters, customerContact and the end-user IP. Every check runs before anything is
8
+ # sent and fails with a ConfigurationError that names the field, never its value (passwords and codes
9
+ # included). Not a public API.
10
+ module WalletRules
11
+ EMAIL = /\A[^\s@]+@[^\s@]+\.[^\s@]+\z/
12
+
13
+ module_function
14
+
15
+ # Applies the rules to the fields that are present:
16
+ # pattern the string must match
17
+ # min/max string length (UTF-16 code units, as the gateway counts)
18
+ # trim the gateway trims the value; the trimmed value is checked and sent
19
+ # oneOf one of the listed strings
20
+ # int { min, max }: an integer (Integer or digit string), sent as an Integer
21
+ # list { max, pattern }: an Array of strings (or a comma-separated String), sent comma-separated
22
+ # Returns a copy with the values to send.
23
+ def apply!(label, rules, values)
24
+ values.to_h do |field, value|
25
+ rule = rules[field]
26
+ [field, rule ? check!("#{label}.#{field}", rule, value) : value]
27
+ end
28
+ end
29
+
30
+ def check!(label, rule, value)
31
+ return integer!(label, rule['int'], value) if rule['int']
32
+ return list!(label, rule['list'], value) if rule['list']
33
+ raise ConfigurationError, "#{label} must be a string." unless value.is_a?(String)
34
+
35
+ text = rule['trim'] ? value.strip : value
36
+ length = utf16_length(text)
37
+ raise ConfigurationError, "#{label} must be at least #{rule['min']} characters." if rule['min'] && length < rule['min']
38
+ raise ConfigurationError, "#{label} must be at most #{rule['max']} characters." if rule['max'] && length > rule['max']
39
+ raise ConfigurationError, "#{label} must be one of #{rule['oneOf'].join(', ')}." if rule['oneOf'] && !rule['oneOf'].include?(text)
40
+ raise ConfigurationError, "#{label} has an invalid format." if rule['pattern'] && !matches?(rule['pattern'], text)
41
+
42
+ text
43
+ end
44
+
45
+ def integer!(label, bounds, value)
46
+ number = value.is_a?(String) && value.match?(/\A\d+\z/) ? value.to_i : value
47
+ min = bounds['min']
48
+ max = bounds['max']
49
+ unless number.is_a?(Integer) && (min.nil? || number >= min) && (max.nil? || number <= max)
50
+ raise ConfigurationError, "#{label} must be an integer#{" #{min}" if min}#{"-#{max}" if max}."
51
+ end
52
+
53
+ number
54
+ end
55
+
56
+ def list!(label, spec, value)
57
+ items = value.is_a?(String) ? value.split(',', -1) : value
58
+ unless items.is_a?(Array) && !items.empty? && (spec['max'].nil? || items.length <= spec['max'])
59
+ raise ConfigurationError, "#{label} must be a list of 1-#{spec['max']} values."
60
+ end
61
+
62
+ items.each do |item|
63
+ raise ConfigurationError, "#{label} has an invalid value." unless item.is_a?(String) && (spec['pattern'].nil? || matches?(spec['pattern'], item))
64
+ end
65
+ items.join(',')
66
+ end
67
+
68
+ # The accepted query parameters of a route: unknown filters are refused, nil and '' are left out,
69
+ # requiredQuery must be present and the rules are applied.
70
+ def query!(name, route, filters)
71
+ given = RouteRequest.wire_keys!(filters || {}, route['query'] || [], name, 'filter').reject { |_, value| value == '' }
72
+ missing = (route['requiredQuery'] || []).reject { |key| given.key?(key) }
73
+ raise ConfigurationError, "#{name} requires #{missing.join(', ')}." unless missing.empty?
74
+
75
+ checked = route['rules'] ? apply!(name, route['rules'], given) : given
76
+ checked.each do |key, value|
77
+ unless value.is_a?(String) || value.is_a?(Integer) || value == true || value == false
78
+ raise ConfigurationError, "#{name} filter '#{key}' must be a string, an integer or a boolean."
79
+ end
80
+ end
81
+ checked
82
+ end
83
+
84
+ # customerContact: { email } pins the address the customer session code goes to; it cannot be changed
85
+ # through the API later. The gateway requires externalCustomerId and accountType PERSONAL with it.
86
+ def customer_contact!(name, plain)
87
+ contact = plain['customerContact']
88
+ raise ConfigurationError, "#{name}.customerContact must be a Hash." unless contact.is_a?(Hash)
89
+
90
+ fields = RouteRequest.wire_keys!(contact, WALLET_CUSTOMER_CONTACT_FIELDS, "#{name}.customerContact")
91
+ email = fields['email'].is_a?(String) ? fields['email'].strip : ''
92
+ unless !email.empty? && email.length <= WALLET_CUSTOMER_CONTACT_EMAIL_MAX && email.match?(EMAIL)
93
+ raise ConfigurationError, "#{name}.customerContact.email must be an e-mail address of at most #{WALLET_CUSTOMER_CONTACT_EMAIL_MAX} characters."
94
+ end
95
+
96
+ external = plain['externalCustomerId']
97
+ raise ConfigurationError, "#{name} requires externalCustomerId with customerContact." unless external.is_a?(String) && !external.strip.empty?
98
+ raise ConfigurationError, "#{name} takes customerContact only with accountType PERSONAL." unless plain['accountType'] == WalletAccountType::PERSONAL
99
+
100
+ { 'email' => email }
101
+ end
102
+
103
+ # X-Lunixi-End-User-Ip: the end user's IP as you saw it (IPv4 or IPv6), a signal only (not signed).
104
+ def end_user_ip!(value)
105
+ text = value.is_a?(String) ? value.strip : ''
106
+ raise ConfigurationError, 'end_user_ip must be an IPv4 or IPv6 address.' unless !text.empty? && !text.include?('/') && valid_ip?(text)
107
+
108
+ text
109
+ end
110
+
111
+ def valid_ip?(text)
112
+ IPAddr.new(text)
113
+ true
114
+ rescue ArgumentError # IPAddr::Error is an ArgumentError
115
+ false
116
+ end
117
+
118
+ # String length in UTF-16 code units (the gateway's count).
119
+ def utf16_length(text)
120
+ text.each_char.sum { |char| char.ord > 0xFFFF ? 2 : 1 }
121
+ rescue ArgumentError, EncodingError
122
+ text.length
123
+ end
124
+
125
+ def matches?(pattern, text)
126
+ text.match?(pattern)
127
+ rescue ArgumentError, EncodingError
128
+ false
129
+ end
130
+ end
131
+ end
@@ -56,6 +56,157 @@ module Lunixi
56
56
  ALL = [ACTIVE, ARCHIVED].freeze
57
57
  end
58
58
 
59
+ # Merchant-vouched customer session (/api/v1/wallet/customer-sessions). The code goes to the contact
60
+ # pinned when the end user was created (customerContact); the channel is the platform's notification
61
+ # policy and is never sent by the merchant.
62
+ module WalletCustomerSessionRevokeReason
63
+ USER_DELETED = 'USER_DELETED'
64
+ WALLET_DETACHED = 'WALLET_DETACHED'
65
+ CREDENTIALS_CHANGED = 'CREDENTIALS_CHANGED'
66
+ ALL = [USER_DELETED, WALLET_DETACHED, CREDENTIALS_CHANGED].freeze
67
+ end
68
+
69
+ # Where the code was sent (information only; the merchant does not choose it).
70
+ module WalletCustomerSessionDeliveryChannel
71
+ EMAIL = 'EMAIL'
72
+ SMS = 'SMS'
73
+ ALL = [EMAIL, SMS].freeze
74
+ end
75
+
76
+ # MERCHANT_LOGIN = first activation; LOGIN / DEVICE_VERIFY = an active customer signing in again.
77
+ module WalletCustomerSessionOtpPurpose
78
+ MERCHANT_LOGIN = 'MERCHANT_LOGIN'
79
+ LOGIN = 'LOGIN'
80
+ DEVICE_VERIFY = 'DEVICE_VERIFY'
81
+ ALL = [MERCHANT_LOGIN, LOGIN, DEVICE_VERIFY].freeze
82
+ end
83
+
84
+ # enrollment of a create-end-user answer that carried customerContact.
85
+ module WalletCustomerEnrollmentStatus
86
+ CREATED = 'CREATED'
87
+ ALREADY_ENROLLED = 'ALREADY_ENROLLED'
88
+ LINKED_EXISTING = 'LINKED_EXISTING'
89
+ ALL = [CREATED, ALREADY_ENROLLED, LINKED_EXISTING].freeze
90
+ end
91
+
92
+ module WalletCustomerIdentityStatus
93
+ PENDING_ACTIVATION = 'PENDING_ACTIVATION'
94
+ ACTIVE = 'ACTIVE'
95
+ ALL = [PENDING_ACTIVATION, ACTIVE].freeze
96
+ end
97
+
98
+ module WalletCustomerAttachStatus
99
+ ATTACHED = 'ATTACHED'
100
+ ALREADY_ATTACHED = 'ALREADY_ATTACHED'
101
+ ALL = [ATTACHED, ALREADY_ATTACHED].freeze
102
+ end
103
+
104
+ # Error codes of the customer session routes and of the portal calls made with its tokens: only the
105
+ # codes the gateway really returns. A missing key permission is always 403 auth.permission.forbidden
106
+ # (body required, missing) on these routes, never WALLET_INSUFFICIENT_SCOPE.
107
+ module WalletCustomerSessionErrorCode
108
+ PERMISSION_FORBIDDEN = 'auth.permission.forbidden'
109
+ RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED'
110
+ # Wallet side
111
+ NOT_FOUND = 'WALLET_NOT_FOUND'
112
+ CONTACT_PINNED = 'WALLET_CUSTOMER_CONTACT_PINNED'
113
+ CONTACT_CONFLICT = 'WALLET_CUSTOMER_CONTACT_CONFLICT'
114
+ ENDUSER_ATTACH_MISMATCH = 'WALLET_ENDUSER_ATTACH_MISMATCH'
115
+ ATTACH_UNCONFIRMED = 'WALLET_CUSTOMER_ATTACH_UNCONFIRMED'
116
+ NOT_ENROLLED = 'WALLET_CUSTOMER_NOT_ENROLLED'
117
+ STATE_INVALID = 'WALLET_STATE_INVALID'
118
+ STORE_NAME_UNAVAILABLE = 'WALLET_STORE_NAME_UNAVAILABLE'
119
+ SESSION_NOT_ISSUED = 'WALLET_CUSTOMER_SESSION_NOT_ISSUED'
120
+ REVOKE_INCOMPLETE = 'WALLET_CUSTOMER_REVOKE_INCOMPLETE'
121
+ # Session tokens (refresh and portal)
122
+ SESSION_BINDING_MISMATCH = 'AUTH_SESSION_BINDING_MISMATCH'
123
+ SESSION_BINDING_REQUIRED = 'AUTH_SESSION_BINDING_REQUIRED'
124
+ REFRESH_REUSED = 'AUTH_REFRESH_REUSED'
125
+ REFRESH_INVALID = 'AUTH_REFRESH_INVALID'
126
+ REFRESH_IN_PROGRESS = 'AUTH_REFRESH_IN_PROGRESS'
127
+ SESSION_EXPIRED = 'AUTH_SESSION_EXPIRED'
128
+ CUSTOMER_SESSION_INVALID = 'AUTH_CUSTOMER_SESSION_INVALID'
129
+ CUSTOMER_REAUTH_REQUIRED = 'AUTH_CUSTOMER_REAUTH_REQUIRED'
130
+ DEVICE_REVERIFY_REQUIRED = 'AUTH_DEVICE_REVERIFY_REQUIRED'
131
+ # Customer authentication
132
+ MERCHANT_SESSION_INPUT_INVALID = 'AUTH_MERCHANT_SESSION_INPUT_INVALID'
133
+ MERCHANT_SESSION_UNAVAILABLE = 'AUTH_MERCHANT_SESSION_UNAVAILABLE'
134
+ MERCHANT_SESSION_RATE_LIMITED = 'AUTH_MERCHANT_SESSION_RATE_LIMITED'
135
+ MERCHANT_SESSION_PASSWORD_NOT_EXPECTED = 'AUTH_MERCHANT_SESSION_PASSWORD_NOT_EXPECTED'
136
+ MERCHANT_REVOKE_REASON_INVALID = 'AUTH_MERCHANT_REVOKE_REASON_INVALID'
137
+ CUSTOMER_PHONE_INVALID = 'AUTH_CUSTOMER_PHONE_INVALID'
138
+ CUSTOMER_EMAIL_REQUIRED = 'AUTH_CUSTOMER_EMAIL_REQUIRED'
139
+ CUSTOMER_PASSWORD_REQUIRED = 'AUTH_CUSTOMER_PASSWORD_REQUIRED'
140
+ CUSTOMER_PASSWORD_EXPIRED = 'AUTH_CUSTOMER_PASSWORD_EXPIRED'
141
+ CUSTOMER_OTP_DESTINATION_NOT_VERIFIED = 'AUTH_CUSTOMER_OTP_DESTINATION_NOT_VERIFIED'
142
+ INVALID_CREDENTIALS = 'AUTH_INVALID_CREDENTIALS'
143
+ CREDENTIAL_BINDING_MISMATCH = 'AUTH_CREDENTIAL_BINDING_MISMATCH'
144
+ ACCOUNT_NOT_ACTIVE = 'AUTH_ACCOUNT_NOT_ACTIVE'
145
+ ACCOUNT_LOCKED = 'AUTH_ACCOUNT_LOCKED'
146
+ CONTACT_SYNC_PENDING = 'AUTH_CONTACT_SYNC_PENDING'
147
+ OTP_INVALID = 'AUTH_OTP_INVALID'
148
+ OTP_INVALID_INPUT = 'AUTH_OTP_INVALID_INPUT'
149
+ OTP_VERIFY_FAILED = 'AUTH_OTP_VERIFY_FAILED'
150
+ OTP_EXPIRED = 'AUTH_OTP_EXPIRED'
151
+ OTP_NOT_PENDING = 'AUTH_OTP_NOT_PENDING'
152
+ OTP_FRESH_START_REQUIRED = 'AUTH_OTP_FRESH_START_REQUIRED'
153
+ OTP_RESEND_THROTTLED = 'AUTH_OTP_RESEND_THROTTLED'
154
+ OTP_ACCOUNT_LOCKED = 'AUTH_OTP_ACCOUNT_LOCKED'
155
+ OTP_ACCOUNT_UNAVAILABLE = 'AUTH_OTP_ACCOUNT_UNAVAILABLE'
156
+ OTP_DEVICE_UNAVAILABLE = 'AUTH_OTP_DEVICE_UNAVAILABLE'
157
+ OTP_CHANNEL_UNAVAILABLE = 'AUTH_OTP_CHANNEL_UNAVAILABLE'
158
+ SERVICE_UNAVAILABLE = 'AUTH_SERVICE_UNAVAILABLE'
159
+ INTERNAL_ERROR = 'AUTH_INTERNAL_ERROR'
160
+ # 502, customer-session endpoints only: auth answered with a code the gateway does not map.
161
+ UPSTREAM_ERROR = 'AUTH_UPSTREAM_ERROR'
162
+ # Phone verification (portal me/phone-verification/*)
163
+ CONTACT_CHANGE_IN_PROGRESS = 'AUTH_CONTACT_CHANGE_IN_PROGRESS'
164
+ CUSTOMER_IDENTITY_NOT_FOUND = 'AUTH_CUSTOMER_IDENTITY_NOT_FOUND'
165
+ PHONE_VERIFICATION_BINDING_INVALID = 'AUTH_CUSTOMER_PHONE_VERIFICATION_BINDING_INVALID'
166
+ PHONE_VERIFICATION_REJECTED = 'AUTH_CUSTOMER_PHONE_VERIFICATION_REJECTED'
167
+ PHONE_VERIFICATION_UNAVAILABLE = 'AUTH_CUSTOMER_PHONE_VERIFICATION_UNAVAILABLE'
168
+ end
169
+
170
+ # 422 password policy refusals of complete (newPassword). The code is not consumed: ask for another
171
+ # password and complete again with the same code.
172
+ WALLET_CUSTOMER_PASSWORD_POLICY_CODES = %w[
173
+ AUTH_CUSTOMER_PASSWORD_TOO_SHORT AUTH_CUSTOMER_PASSWORD_TOO_LONG AUTH_CUSTOMER_PASSWORD_SEQUENTIAL
174
+ AUTH_CUSTOMER_PASSWORD_REPEATED AUTH_CUSTOMER_PASSWORD_DATE_PATTERN AUTH_CUSTOMER_PASSWORD_CONTAINS_PHONE
175
+ AUTH_CUSTOMER_PASSWORD_TOO_COMMON AUTH_CUSTOMER_PASSWORD_INVALID AUTH_CUSTOMER_PASSWORD_REUSED
176
+ ].freeze
177
+
178
+ WALLET_UUID_PATTERN = /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
179
+ # The plugin installation id (one per installation, stable): the customer's MERCHANT device is derived
180
+ # from it.
181
+ WALLET_CLIENT_INSTANCE_ID_PATTERN = /\A[A-Za-z0-9][A-Za-z0-9._:-]{7,127}\z/
182
+ # The device name the customer sees ("Mağaza: example.com"): 2–64 characters, starts with a letter or
183
+ # digit, no < > { } " and no line break. It is not a trust source; the shop name in the message comes
184
+ # from your registered organization name.
185
+ WALLET_CLIENT_LABEL_PATTERN = /\A[\p{L}\p{N}][^<>{}"\x00-\x1f\x7f]{1,63}\z/ # \x00-\x1f covers \r and \n
186
+ WALLET_LOCALE_PATTERN = /\A[a-z]{2,3}(?:-[A-Za-z]{2,4})?\z/
187
+ WALLET_SESSION_CODE_PATTERN = /\A\d{4,10}\z/
188
+ WALLET_CUSTOMER_REFRESH_TOKEN_PATTERN = /\Aat_custr_/
189
+ # customerContact of create end user: the code address, pinned for good.
190
+ WALLET_CUSTOMER_CONTACT_FIELDS = %w[email].freeze
191
+ WALLET_CUSTOMER_CONTACT_EMAIL_MAX = 160
192
+
193
+ # Per-field checks of the customer session routes, run before sending (the gateway DTO rules). trim:
194
+ # the gateway trims the value, so the SDK sends it trimmed. Strings only; lengths are UTF-16 code
195
+ # units, as the gateway counts.
196
+ WALLET_CUSTOMER_SESSION_RULES = {
197
+ 'programId' => { 'pattern' => WALLET_UUID_PATTERN }.freeze,
198
+ 'externalCustomerId' => { 'trim' => true, 'min' => 1, 'max' => 128 }.freeze,
199
+ 'clientInstanceId' => { 'pattern' => WALLET_CLIENT_INSTANCE_ID_PATTERN }.freeze,
200
+ 'clientLabel' => { 'trim' => true, 'pattern' => WALLET_CLIENT_LABEL_PATTERN }.freeze,
201
+ 'locale' => { 'pattern' => WALLET_LOCALE_PATTERN }.freeze,
202
+ 'password' => { 'min' => 1, 'max' => 256 }.freeze,
203
+ 'challengeId' => { 'pattern' => WALLET_UUID_PATTERN }.freeze,
204
+ 'code' => { 'pattern' => WALLET_SESSION_CODE_PATTERN }.freeze,
205
+ 'newPassword' => { 'min' => 8, 'max' => 256 }.freeze,
206
+ 'refreshToken' => { 'pattern' => WALLET_CUSTOMER_REFRESH_TOKEN_PATTERN, 'max' => 200 }.freeze,
207
+ 'reason' => { 'oneOf' => WalletCustomerSessionRevokeReason::ALL }.freeze
208
+ }.freeze
209
+
59
210
  # Minor units as a decimal string: "12550" is 125.50 TRY. Never a number.
60
211
  WALLET_AMOUNT_PATTERN = /\A\d{1,18}\z/
61
212
  # The gateway trims the Idempotency-Key header and accepts 1–128 characters.
data/lib/lunixi.rb CHANGED
@@ -18,6 +18,7 @@ require_relative 'lunixi/split_payment'
18
18
  require_relative 'lunixi/direct_method_payment_request'
19
19
  require_relative 'lunixi/enabled_installments'
20
20
  require_relative 'lunixi/card_requests'
21
+ require_relative 'lunixi/refund_to_wallet'
21
22
  require_relative 'lunixi/payments'
22
23
  require_relative 'lunixi/reference'
23
24
  require_relative 'lunixi/checkout'
@@ -49,8 +50,13 @@ require_relative 'lunixi/route_response'
49
50
  require_relative 'lunixi/route_value'
50
51
  require_relative 'lunixi/wallet_values'
51
52
  require_relative 'lunixi/wallet_routes'
53
+ require_relative 'lunixi/wallet_portal_routes'
54
+ require_relative 'lunixi/wallet_rules'
52
55
  require_relative 'lunixi/wallet'
53
56
  require_relative 'lunixi/wallet_resources'
57
+ require_relative 'lunixi/wallet_customer_tokens'
58
+ require_relative 'lunixi/wallet_customer_sessions'
59
+ require_relative 'lunixi/wallet_portal'
54
60
  require_relative 'lunixi/bank_connect_values'
55
61
  require_relative 'lunixi/bank_connect_filters'
56
62
  require_relative 'lunixi/bank_connect'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunixi-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lunixi
@@ -166,6 +166,7 @@ files:
166
166
  - lib/lunixi/product_webhooks.rb
167
167
  - lib/lunixi/promissory_note.rb
168
168
  - lib/lunixi/reference.rb
169
+ - lib/lunixi/refund_to_wallet.rb
169
170
  - lib/lunixi/route_request.rb
170
171
  - lib/lunixi/route_response.rb
171
172
  - lib/lunixi/route_table.rb
@@ -183,8 +184,13 @@ files:
183
184
  - lib/lunixi/transport.rb
184
185
  - lib/lunixi/version.rb
185
186
  - lib/lunixi/wallet.rb
187
+ - lib/lunixi/wallet_customer_sessions.rb
188
+ - lib/lunixi/wallet_customer_tokens.rb
189
+ - lib/lunixi/wallet_portal.rb
190
+ - lib/lunixi/wallet_portal_routes.rb
186
191
  - lib/lunixi/wallet_resources.rb
187
192
  - lib/lunixi/wallet_routes.rb
193
+ - lib/lunixi/wallet_rules.rb
188
194
  - lib/lunixi/wallet_values.rb
189
195
  - lib/lunixi/webhook.rb
190
196
  - lib/lunixi/wire_money.rb