@africode/core 5.0.11 → 5.0.13
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.
- package/AGENTS.md +585 -585
- package/AGENT_INSTRUCTIONS.md +595 -595
- package/COMPONENT_SCHEMA.json +1826 -1800
- package/LICENSE +623 -623
- package/README.md +476 -476
- package/bin/africode.js +73 -73
- package/bin/cli.ts +82 -82
- package/bin/create-africode.js +220 -220
- package/bin/scaffold.ts +218 -218
- package/components/accordion.js +183 -183
- package/components/alert.js +131 -131
- package/components/auth-form.js +154 -154
- package/components/auth.js +172 -172
- package/components/avatar.js +117 -117
- package/components/badge.js +104 -104
- package/components/base.d.ts +139 -139
- package/components/base.js +234 -234
- package/components/breadcrumb.js +76 -72
- package/components/button.js +164 -164
- package/components/card.js +144 -137
- package/components/carousel.js +32 -32
- package/components/cart-drawer.js +28 -28
- package/components/code-block.js +20 -20
- package/components/contact-form.js +25 -25
- package/components/cookie-consent.js +23 -23
- package/components/cta-banner.js +38 -38
- package/components/cultural-card.js +243 -243
- package/components/dashboard-activity-list.js +103 -103
- package/components/dashboard-card.js +85 -85
- package/components/dashboard-metric.js +81 -81
- package/components/dashboard-shell.js +85 -85
- package/components/dashboard-topbar.js +84 -84
- package/components/divider.js +83 -83
- package/components/dropdown.js +171 -171
- package/components/error-boundary.js +155 -155
- package/components/faq-accordion.js +23 -23
- package/components/feature-grid.js +85 -85
- package/components/file-uploader.js +22 -22
- package/components/filter-bar.js +19 -19
- package/components/footer.js +113 -113
- package/components/form.js +131 -131
- package/components/gallery.js +22 -22
- package/components/hero.js +140 -138
- package/components/icon.js +36 -36
- package/components/index.js +128 -128
- package/components/input.js +252 -256
- package/components/kanga-card.js +185 -185
- package/components/kyc-upload.js +173 -173
- package/components/language-switcher.js +108 -108
- package/components/loader.js +80 -80
- package/components/modal.js +262 -262
- package/components/motion.js +84 -84
- package/components/nav-drawer.js +216 -216
- package/components/navbar.js +243 -236
- package/components/newsletter-signup.js +24 -24
- package/components/pagination.js +31 -31
- package/components/pattern-showcase.js +225 -225
- package/components/pricing-card.js +100 -100
- package/components/product-card.js +41 -41
- package/components/progress.js +132 -134
- package/components/react.js +111 -111
- package/components/search-box.js +24 -24
- package/components/section.js +54 -54
- package/components/select.js +321 -322
- package/components/sidebar.js +180 -180
- package/components/simple-chart.js +22 -22
- package/components/skeleton.js +85 -85
- package/components/stepper.js +28 -28
- package/components/table.js +181 -181
- package/components/tabs.js +202 -202
- package/components/team-grid.js +23 -23
- package/components/testimonial.js +94 -94
- package/components/theme-toggle.js +82 -82
- package/components/toast.js +139 -139
- package/components/tooltip.js +167 -167
- package/components/transaction-ledger.js +138 -138
- package/components/ui-avatar.js +79 -79
- package/components/ui-badge.js +61 -61
- package/components/ui-button.js +149 -149
- package/components/ui-card.js +74 -75
- package/components/ui-chip.js +87 -87
- package/components/ui-input.js +110 -110
- package/components/ui-popover.js +84 -84
- package/components/ui-progress-ring.js +60 -60
- package/components/ui-select.js +85 -85
- package/components/ui-stat.js +75 -75
- package/components/ui-switch.js +85 -85
- package/components/ui-table.js +69 -69
- package/components/ui-tabs.js +99 -99
- package/components/ui-tag.js +64 -64
- package/components/ui-textarea.js +84 -84
- package/components/ui-tooltip.js +66 -66
- package/components/video-player.js +22 -22
- package/components/wallet-balance.js +114 -114
- package/core/a2ui-schema-manager.js +351 -351
- package/core/a2ui.js +696 -696
- package/core/actions.js +27 -27
- package/core/bun-runtime.js +396 -396
- package/core/cli/commands/add.js +23 -23
- package/core/cli/commands/audit.js +58 -58
- package/core/cli/commands/build.js +193 -193
- package/core/cli/commands/create-plugin.js +241 -241
- package/core/cli/commands/dev.js +248 -283
- package/core/cli/commands/lint.js +23 -23
- package/core/cli/commands/test.js +33 -34
- package/core/cli/migrator.js +71 -71
- package/core/cli/ui.js +56 -56
- package/core/compliance.js +823 -823
- package/core/config.js +265 -265
- package/core/db-advanced.js +478 -481
- package/core/db.js +282 -284
- package/core/enhanced-hmr.js +406 -406
- package/core/errors.js +222 -222
- package/core/file-router.js +47 -47
- package/core/hmr-client.js +203 -204
- package/core/hmr.js +205 -197
- package/core/html.d.ts +30 -30
- package/core/html.js +84 -84
- package/core/hydration.js +52 -52
- package/core/lipa-namba-journey.js +548 -605
- package/core/logging.js +14 -14
- package/core/middleware.js +145 -145
- package/core/motion.js +106 -106
- package/core/nida-cig-middleware.js +417 -460
- package/core/patterns.d.ts +124 -124
- package/core/patterns.js +947 -1001
- package/core/plugins/index.js +345 -345
- package/core/request-analytics.js +253 -253
- package/core/request-identity.js +93 -93
- package/core/router.js +386 -386
- package/core/sdk-browser.js +140 -140
- package/core/sdk-client.js +61 -61
- package/core/sdk.d.ts +133 -133
- package/core/sdk.js +148 -148
- package/core/seo.js +76 -76
- package/core/server/auth-endpoints.js +339 -339
- package/core/server/auth.js +180 -180
- package/core/server/csrf.js +200 -206
- package/core/server/db.js +39 -39
- package/core/server/middleware.js +324 -324
- package/core/server/rate-limit.js +238 -238
- package/core/server/render.js +67 -69
- package/core/server/router.js +23 -11
- package/core/session-store.js +68 -68
- package/core/shim.js +28 -28
- package/core/state.d.ts +86 -86
- package/core/state.js +276 -276
- package/core/store.d.ts +122 -122
- package/core/store.js +61 -61
- package/core/validation.d.ts +232 -232
- package/core/validation.js +602 -602
- package/core/websocket.js +656 -641
- package/dist/africode.js +233 -230
- package/dist/africode.js.map +83 -83
- package/dist/build-info.json +3 -3
- package/dist/components.js +195 -192
- package/dist/components.js.map +73 -73
- package/dist/styles/africanity.css +321 -321
- package/dist/styles/typography.css +140 -140
- package/docs/IDE-Guide.md +50 -50
- package/package.json +113 -113
- package/scripts/generate-component-schema.js +82 -79
- package/styles/africanity.css +321 -321
- package/styles/typography.css +140 -140
- package/templates/starter/.env.example +15 -15
- package/templates/starter/africode.config.js +40 -40
- package/templates/starter/package.json +13 -13
- package/templates/starter/src/index.js +18 -18
- package/templates/starter/src/pages/index.html +55 -55
- package/templates/starter/src/pages/index.js +17 -17
- package/templates/starter/src/styles/main.css +3 -3
- package/templates/starter-3d/.env.example +7 -7
- package/templates/starter-3d/africode.config.js +29 -29
- package/templates/starter-3d/components/af-model-viewer.js +125 -125
- package/templates/starter-3d/package.json +14 -14
- package/templates/starter-3d/src/pages/index.html +55 -55
- package/templates/starter-3d/src/pages/index.js +50 -50
- package/templates/starter-3d/src/styles/main.css +3 -3
- package/templates/starter-dashboard/.env.example +21 -21
- package/templates/starter-dashboard/africode.config.js +20 -20
- package/templates/starter-dashboard/package.json +14 -14
- package/templates/starter-dashboard/src/index.js +17 -17
- package/templates/starter-dashboard/src/pages/api/analytics.js +24 -24
- package/templates/starter-dashboard/src/pages/index.html +118 -118
- package/templates/starter-dashboard/src/pages/index.js +110 -110
- package/templates/starter-dashboard/src/styles/main.css +172 -172
- package/templates/starter-fintech/.env.example +28 -28
- package/templates/starter-fintech/africode.config.js +20 -20
- package/templates/starter-fintech/package.json +15 -15
- package/templates/starter-fintech/src/index.js +17 -17
- package/templates/starter-fintech/src/pages/api/auth.js +45 -45
- package/templates/starter-fintech/src/pages/api/transfer.js +65 -65
- package/templates/starter-fintech/src/pages/api/wallet.js +39 -39
- package/templates/starter-fintech/src/pages/api/webhooks/payment.js +32 -32
- package/templates/starter-fintech/src/pages/index.html +169 -169
- package/templates/starter-fintech/src/pages/index.js +161 -161
- package/templates/starter-fintech/src/styles/main.css +246 -246
- package/templates/starter-react/.env.example +15 -15
- package/templates/starter-react/africode.config.js +40 -40
- package/templates/starter-react/package.json +15 -15
- package/templates/starter-react/src/pages/index.html +55 -55
- package/templates/starter-react/src/pages/index.js +68 -68
- package/templates/starter-react/src/styles/main.css +3 -3
- package/templates/starter-tailwind/.env.example +15 -15
- package/templates/starter-tailwind/africode.config.js +40 -40
- package/templates/starter-tailwind/package.json +19 -19
- package/templates/starter-tailwind/src/pages/index.html +55 -55
- package/templates/starter-tailwind/src/pages/index.js +67 -67
- package/templates/starter-tailwind/src/styles/main.css +3 -3
- package/templates/starter-tailwind/src/styles/tailwind.css +1 -1
- package/templates/starter-tailwind/src/tailwind-loader.js +30 -30
- package/templates/starter-tailwind/tailwind.config.cjs +18 -18
- package/templates/starter-website/.env.example +18 -18
- package/templates/starter-website/africode.config.js +20 -20
- package/templates/starter-website/package.json +14 -14
- package/templates/starter-website/src/index.js +17 -17
- package/templates/starter-website/src/pages/index.html +124 -124
- package/templates/starter-website/src/pages/index.js +116 -116
- package/templates/starter-website/src/styles/main.css +195 -195
- package/bin/africode.js.1758507140 +0 -343
- package/core/heartbeat.js +0 -64
|
@@ -1,605 +1,548 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lipa Namba Journey - Framework-Native Primitive
|
|
3
|
-
* Bank of Tanzania (BoT) Compliant Payment Flows
|
|
4
|
-
*
|
|
5
|
-
* Implements complete merchant payment lifecycle:
|
|
6
|
-
* - Lipa Namba (Pay by Phone Number)
|
|
7
|
-
* - Lipa kwa Simu (Pay by SIM)
|
|
8
|
-
* - Merchant KYC/AML compliance
|
|
9
|
-
* - Real-time transaction processing
|
|
10
|
-
* - Automated regulatory reporting
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { z } from 'zod';
|
|
14
|
-
import { EventEmitter } from 'events';
|
|
15
|
-
import { frameworkLog } from './logging.js';
|
|
16
|
-
|
|
17
|
-
export class LipaNambaJourney extends EventEmitter {
|
|
18
|
-
constructor(config = {}) {
|
|
19
|
-
super();
|
|
20
|
-
|
|
21
|
-
this.config = {
|
|
22
|
-
tipsEndpoint: config.tipsEndpoint || 'https://api.tips.go.tz',
|
|
23
|
-
nidaMiddleware: config.nidaMiddleware,
|
|
24
|
-
amlEngine: config.amlEngine,
|
|
25
|
-
database: config.database,
|
|
26
|
-
redis: config.redis, // For session management
|
|
27
|
-
...config
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
this.sessions = new Map();
|
|
31
|
-
|
|
32
|
-
// BoT Regulatory Limits (as of 2026)
|
|
33
|
-
this.regulatoryLimits = {
|
|
34
|
-
merchant: {
|
|
35
|
-
daily: 100_000_000, // 100M TZS
|
|
36
|
-
perTransaction: 25_000_000, // 25M TZS
|
|
37
|
-
monthlyVolume: 1_000_000_000 // 1B TZS
|
|
38
|
-
},
|
|
39
|
-
customer: {
|
|
40
|
-
daily: 50_000_000, // 50M TZS
|
|
41
|
-
perTransaction: 10_000_000, // 10M TZS
|
|
42
|
-
monthlyVolume: 500_000_000 // 500M TZS
|
|
43
|
-
},
|
|
44
|
-
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
45
|
-
otpTimeout: 5 * 60 * 1000 // 5 minutes
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
this._initializeEventHandlers();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Initialize event handlers for journey lifecycle
|
|
53
|
-
*/
|
|
54
|
-
_initializeEventHandlers() {
|
|
55
|
-
this.on('payment:initiated', this._handlePaymentInitiated.bind(this));
|
|
56
|
-
this.on('customer:identified', this._handleCustomerIdentified.bind(this));
|
|
57
|
-
this.on('aml:screened', this._handleAMLScreened.bind(this));
|
|
58
|
-
this.on('payment:confirmed', this._handlePaymentConfirmed.bind(this));
|
|
59
|
-
this.on('payment:completed', this._handlePaymentCompleted.bind(this));
|
|
60
|
-
this.on('payment:failed', this._handlePaymentFailed.bind(this));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
return { ok: false, error:
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
//
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
ok:
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
return
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
//
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
// Simulate successful lookup
|
|
551
|
-
return { verified: true, nin, firstName: 'John', lastName: 'Doe' };
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
async _checkFIUList(customerId) {
|
|
555
|
-
// Query FIU database
|
|
556
|
-
// For now, return false (not flagged)
|
|
557
|
-
return false;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
async _storePaymentRequest(request) {
|
|
561
|
-
this.sessions.set(request.id, { ...request });
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
async _storePaymentSession(sessionData) {
|
|
565
|
-
this.sessions.set(sessionData.id, { ...sessionData });
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
async _getPaymentRequest(id) {
|
|
569
|
-
return this.sessions.get(id) || null;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
async _updatePaymentRequest(id, updates) {
|
|
573
|
-
const current = this.sessions.get(id);
|
|
574
|
-
if (current) {
|
|
575
|
-
this.sessions.set(id, { ...current, ...updates });
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
async _getMerchantDailyTotal(merchantId) {
|
|
580
|
-
return 0;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
async _getCustomerDailyTotal(customerId) {
|
|
584
|
-
return 0;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
async _queueForMonitoring(paymentRequestId, customerId) {
|
|
588
|
-
// Queue for AML transaction monitoring
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
async _submitToTIPS(txData) {
|
|
592
|
-
// Submit to TIPS
|
|
593
|
-
return { ok: true, transactionId: 'TIPS_' + Date.now() };
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
async _logAMLTransaction(paymentRequestId, transactionId) {
|
|
597
|
-
// Log for FIU reporting
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
async _notifyMerchant(callbackUrl, data) {
|
|
601
|
-
// POST callback to merchant
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
export default LipaNambaJourney;
|
|
1
|
+
/**
|
|
2
|
+
* Lipa Namba Journey - Framework-Native Primitive
|
|
3
|
+
* Bank of Tanzania (BoT) Compliant Payment Flows
|
|
4
|
+
*
|
|
5
|
+
* Implements complete merchant payment lifecycle:
|
|
6
|
+
* - Lipa Namba (Pay by Phone Number)
|
|
7
|
+
* - Lipa kwa Simu (Pay by SIM)
|
|
8
|
+
* - Merchant KYC/AML compliance
|
|
9
|
+
* - Real-time transaction processing
|
|
10
|
+
* - Automated regulatory reporting
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { EventEmitter } from 'events';
|
|
15
|
+
import { frameworkLog } from './logging.js';
|
|
16
|
+
|
|
17
|
+
export class LipaNambaJourney extends EventEmitter {
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
super();
|
|
20
|
+
|
|
21
|
+
this.config = {
|
|
22
|
+
tipsEndpoint: config.tipsEndpoint || 'https://api.tips.go.tz',
|
|
23
|
+
nidaMiddleware: config.nidaMiddleware,
|
|
24
|
+
amlEngine: config.amlEngine,
|
|
25
|
+
database: config.database,
|
|
26
|
+
redis: config.redis, // For session management
|
|
27
|
+
...config
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.sessions = new Map();
|
|
31
|
+
|
|
32
|
+
// BoT Regulatory Limits (as of 2026)
|
|
33
|
+
this.regulatoryLimits = {
|
|
34
|
+
merchant: {
|
|
35
|
+
daily: 100_000_000, // 100M TZS
|
|
36
|
+
perTransaction: 25_000_000, // 25M TZS
|
|
37
|
+
monthlyVolume: 1_000_000_000 // 1B TZS
|
|
38
|
+
},
|
|
39
|
+
customer: {
|
|
40
|
+
daily: 50_000_000, // 50M TZS
|
|
41
|
+
perTransaction: 10_000_000, // 10M TZS
|
|
42
|
+
monthlyVolume: 500_000_000 // 500M TZS
|
|
43
|
+
},
|
|
44
|
+
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
45
|
+
otpTimeout: 5 * 60 * 1000 // 5 minutes
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
this._initializeEventHandlers();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initialize event handlers for journey lifecycle
|
|
53
|
+
*/
|
|
54
|
+
_initializeEventHandlers() {
|
|
55
|
+
this.on('payment:initiated', this._handlePaymentInitiated.bind(this));
|
|
56
|
+
this.on('customer:identified', this._handleCustomerIdentified.bind(this));
|
|
57
|
+
this.on('aml:screened', this._handleAMLScreened.bind(this));
|
|
58
|
+
this.on('payment:confirmed', this._handlePaymentConfirmed.bind(this));
|
|
59
|
+
this.on('payment:completed', this._handlePaymentCompleted.bind(this));
|
|
60
|
+
this.on('payment:failed', this._handlePaymentFailed.bind(this));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Step 1: Merchant Payment Initiation with BoT Compliance
|
|
65
|
+
*/
|
|
66
|
+
async initiateMerchantPayment(request) {
|
|
67
|
+
const schema = z.object({
|
|
68
|
+
merchantId: z.string().min(1),
|
|
69
|
+
customerPhone: z.string().regex(/^255\d{9}$/), // Tanzanian format
|
|
70
|
+
amount: z.number().positive().max(this.regulatoryLimits.merchant.daily),
|
|
71
|
+
currency: z.string().default('TZS'),
|
|
72
|
+
description: z.string().min(1).max(100),
|
|
73
|
+
reference: z.string().optional(),
|
|
74
|
+
callbackUrl: z.string().url().optional(),
|
|
75
|
+
metadata: z.object({}).optional()
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const validated = schema.parse(request);
|
|
79
|
+
|
|
80
|
+
// Deduplicate by reference when provided: return existing session if found
|
|
81
|
+
if (validated.reference) {
|
|
82
|
+
for (const session of this.sessions.values()) {
|
|
83
|
+
if (session.reference === validated.reference) {
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
paymentRequestId: session.id,
|
|
87
|
+
sessionData: session,
|
|
88
|
+
message: 'DUPLICATE_REFERENCE',
|
|
89
|
+
nextStep: session.status === 'INITIATED' ? 'IDENTIFY_CUSTOMER' : undefined,
|
|
90
|
+
expiresIn: Math.max(0, Math.floor((new Date(session.expiresAt) - Date.now()) / 1000))
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Verify merchant is registered and compliant
|
|
97
|
+
const merchantStatus = await this._verifyMerchantCompliance(validated.merchantId);
|
|
98
|
+
if (!merchantStatus.ok) {
|
|
99
|
+
return { ok: false, error: merchantStatus.error };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Check merchant transaction limits
|
|
103
|
+
const limitCheck = await this._checkMerchantLimits(validated.merchantId, validated.amount);
|
|
104
|
+
if (!limitCheck.ok) {
|
|
105
|
+
return { ok: false, error: limitCheck.error };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Generate secure payment request ID
|
|
109
|
+
const paymentRequestId = this._generateSecurePaymentId();
|
|
110
|
+
|
|
111
|
+
// Create payment session in Redis
|
|
112
|
+
const sessionData = {
|
|
113
|
+
id: paymentRequestId,
|
|
114
|
+
merchantId: validated.merchantId,
|
|
115
|
+
customerPhone: validated.customerPhone,
|
|
116
|
+
amount: validated.amount,
|
|
117
|
+
currency: validated.currency,
|
|
118
|
+
description: validated.description,
|
|
119
|
+
reference: validated.reference || paymentRequestId,
|
|
120
|
+
status: 'INITIATED',
|
|
121
|
+
createdAt: new Date(),
|
|
122
|
+
expiresAt: new Date(Date.now() + this.regulatoryLimits.sessionTimeout),
|
|
123
|
+
callbackUrl: validated.callbackUrl,
|
|
124
|
+
metadata: validated.metadata || {}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
await this._storePaymentSession(sessionData);
|
|
128
|
+
|
|
129
|
+
this.emit('payment:initiated', sessionData);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
paymentRequestId,
|
|
134
|
+
redirectUrl: `/pay/${paymentRequestId}`,
|
|
135
|
+
sessionData,
|
|
136
|
+
nextStep: 'IDENTIFY_CUSTOMER',
|
|
137
|
+
expiresIn: this.regulatoryLimits.sessionTimeout / 1000
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async initiatePayment(request) {
|
|
142
|
+
return this.initiateMerchantPayment(request);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Step 2: Customer Identification (via Prompt)
|
|
147
|
+
* Customer enters PIN to identify with NIDA
|
|
148
|
+
*/
|
|
149
|
+
async identifyCustomer(paymentRequestId, nin, pin) {
|
|
150
|
+
// Get payment request
|
|
151
|
+
const paymentRequest = await this._getPaymentRequest(paymentRequestId);
|
|
152
|
+
|
|
153
|
+
if (!paymentRequest) {
|
|
154
|
+
return { ok: false, error: 'PAYMENT_REQUEST_NOT_FOUND' };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (paymentRequest.status !== 'INITIATED') {
|
|
158
|
+
return { ok: false, error: 'INVALID_PAYMENT_STATUS' };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (new Date() > paymentRequest.expiresAt) {
|
|
162
|
+
return { ok: false, error: 'PAYMENT_EXPIRED' };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Verify NIN with NIDA CIG
|
|
166
|
+
const nidaResult = await this._verifyNIDA(nin, pin);
|
|
167
|
+
|
|
168
|
+
if (!nidaResult.verified) {
|
|
169
|
+
return { ok: false, error: 'NIDA_VERIFICATION_FAILED' };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Check customer limits
|
|
173
|
+
const customerStatus = await this._checkCustomerLimits(
|
|
174
|
+
nidaResult.nin,
|
|
175
|
+
paymentRequest.amount
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
if (!customerStatus.ok) {
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
error: customerStatus.error,
|
|
182
|
+
code: 'CUSTOMER_LIMIT_EXCEEDED'
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Update payment request with customer
|
|
187
|
+
await this._updatePaymentRequest(paymentRequestId, {
|
|
188
|
+
status: 'IDENTIFIED',
|
|
189
|
+
customerId: nidaResult.nin,
|
|
190
|
+
customerName: `${nidaResult.firstName} ${nidaResult.lastName}`,
|
|
191
|
+
identifiedAt: new Date()
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
ok: true,
|
|
196
|
+
customerId: nidaResult.nin,
|
|
197
|
+
customerName: `${nidaResult.firstName} ${nidaResult.lastName}`,
|
|
198
|
+
customerData: {
|
|
199
|
+
nin: nidaResult.nin,
|
|
200
|
+
firstName: nidaResult.firstName,
|
|
201
|
+
lastName: nidaResult.lastName,
|
|
202
|
+
customerName: `${nidaResult.firstName} ${nidaResult.lastName}`
|
|
203
|
+
},
|
|
204
|
+
nextStep: 'CONFIRM'
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async verifyCustomerIdentity(paymentRequestId, customerIdentity) {
|
|
209
|
+
const identity = customerIdentity || {};
|
|
210
|
+
return this.identifyCustomer(paymentRequestId, identity.nin, identity.pin);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Step 3: AML Screening
|
|
215
|
+
* Check customer against FIU suspicious persons list
|
|
216
|
+
*/
|
|
217
|
+
async performAMLScreening(paymentRequestId, customerId) {
|
|
218
|
+
// Check FIU list
|
|
219
|
+
const isBlocked = await this._checkFIUList(customerId);
|
|
220
|
+
|
|
221
|
+
if (isBlocked) {
|
|
222
|
+
await this._updatePaymentRequest(paymentRequestId, {
|
|
223
|
+
status: 'BLOCKED',
|
|
224
|
+
blockReason: 'AML_SCREENING_FAILED'
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
error: 'AML_SCREENING_FAILED',
|
|
230
|
+
blocked: true
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Queue for transaction monitoring
|
|
235
|
+
await this._queueForMonitoring(paymentRequestId, customerId);
|
|
236
|
+
|
|
237
|
+
return { ok: true };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Step 4: Confirmation
|
|
242
|
+
* Customer confirms payment details
|
|
243
|
+
*/
|
|
244
|
+
async confirmPayment(paymentRequestId, customerId, _confirmationCode) {
|
|
245
|
+
const paymentRequest = await this._getPaymentRequest(paymentRequestId);
|
|
246
|
+
|
|
247
|
+
if (!paymentRequest) {
|
|
248
|
+
return { ok: false, error: 'PAYMENT_REQUEST_NOT_FOUND' };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (paymentRequest.status !== 'IDENTIFIED') {
|
|
252
|
+
return { ok: false, error: 'INVALID_PAYMENT_STATUS' };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (paymentRequest.customerId !== customerId) {
|
|
256
|
+
return { ok: false, error: 'CUSTOMER_MISMATCH' };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Verify confirmation code (could be OTP)
|
|
260
|
+
// const isValidCode = await this._verifyConfirmationCode(customerId, confirmationCode);
|
|
261
|
+
// if (!isValidCode) {
|
|
262
|
+
// return { ok: false, error: 'INVALID_CONFIRMATION_CODE' };
|
|
263
|
+
// }
|
|
264
|
+
|
|
265
|
+
// Update payment request status
|
|
266
|
+
await this._updatePaymentRequest(paymentRequestId, {
|
|
267
|
+
status: 'CONFIRMED',
|
|
268
|
+
confirmedAt: new Date()
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
ok: true,
|
|
273
|
+
nextStep: 'PROCESS'
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Step 5: Process Payment via TIPS
|
|
279
|
+
* Submit to Tanzania Instant Payment System
|
|
280
|
+
*/
|
|
281
|
+
async processPayment(paymentRequestId, customerId) {
|
|
282
|
+
const paymentRequest = await this._getPaymentRequest(paymentRequestId);
|
|
283
|
+
|
|
284
|
+
if (!paymentRequest) {
|
|
285
|
+
return { ok: false, error: 'PAYMENT_REQUEST_NOT_FOUND' };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (paymentRequest.status !== 'CONFIRMED') {
|
|
289
|
+
return { ok: false, error: 'PAYMENT_NOT_CONFIRMED' };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
// Initiate TIPS transaction
|
|
294
|
+
const tipsResult = await this._submitToTIPS({
|
|
295
|
+
customerId,
|
|
296
|
+
merchantId: paymentRequest.merchantId,
|
|
297
|
+
amount: paymentRequest.amount,
|
|
298
|
+
reference: paymentRequest.reference,
|
|
299
|
+
description: paymentRequest.description
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
if (!tipsResult.ok) {
|
|
303
|
+
await this._updatePaymentRequest(paymentRequestId, {
|
|
304
|
+
status: 'FAILED',
|
|
305
|
+
failureReason: tipsResult.error
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
ok: false,
|
|
310
|
+
error: 'TIPS_TRANSACTION_FAILED'
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Update payment request
|
|
315
|
+
await this._updatePaymentRequest(paymentRequestId, {
|
|
316
|
+
status: 'COMPLETED',
|
|
317
|
+
transactionId: tipsResult.transactionId,
|
|
318
|
+
completedAt: new Date()
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Log for AML/FIU reporting
|
|
322
|
+
await this._logAMLTransaction(paymentRequestId, tipsResult.transactionId);
|
|
323
|
+
|
|
324
|
+
// Call merchant callback if configured
|
|
325
|
+
if (paymentRequest.callbackUrl) {
|
|
326
|
+
await this._notifyMerchant(paymentRequest.callbackUrl, {
|
|
327
|
+
paymentRequestId,
|
|
328
|
+
transactionId: tipsResult.transactionId,
|
|
329
|
+
status: 'COMPLETED',
|
|
330
|
+
amount: paymentRequest.amount,
|
|
331
|
+
timestamp: new Date().toISOString()
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
ok: true,
|
|
337
|
+
transactionId: tipsResult.transactionId,
|
|
338
|
+
status: 'COMPLETED',
|
|
339
|
+
amount: paymentRequest.amount,
|
|
340
|
+
reference: paymentRequest.reference
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
} catch (error) {
|
|
344
|
+
frameworkLog('error', '[Lipa Namba] Processing error:', error);
|
|
345
|
+
return {
|
|
346
|
+
ok: false,
|
|
347
|
+
error: error.message,
|
|
348
|
+
code: 'PROCESSING_ERROR'
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Full journey orchestrator
|
|
355
|
+
*/
|
|
356
|
+
async executeFullJourney(request, credentials, confirmation) {
|
|
357
|
+
const steps = [];
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
// Step 1: Initiate
|
|
361
|
+
const init = await this.initiatePayment(request);
|
|
362
|
+
if (!init.ok) {return { ok: false, error: init.error || 'INITIATION_FAILED', completedSteps: steps };}
|
|
363
|
+
steps.push({ step: 'INITIATE', ok: true });
|
|
364
|
+
|
|
365
|
+
// Step 2: Identify
|
|
366
|
+
const identify = await this.identifyCustomer(
|
|
367
|
+
init.paymentRequestId,
|
|
368
|
+
credentials.nin,
|
|
369
|
+
credentials.pin
|
|
370
|
+
);
|
|
371
|
+
if (!identify.ok) {return { ok: false, error: identify.error || 'IDENTIFICATION_FAILED', completedSteps: steps };}
|
|
372
|
+
steps.push({ step: 'IDENTIFY', ok: true });
|
|
373
|
+
|
|
374
|
+
// Step 3: AML Screen
|
|
375
|
+
const aml = await this.performAMLScreening(
|
|
376
|
+
init.paymentRequestId,
|
|
377
|
+
identify.customerId
|
|
378
|
+
);
|
|
379
|
+
if (!aml.ok) {return { ok: false, error: aml.error || 'AML_SCREEN_FAILED', completedSteps: steps };}
|
|
380
|
+
steps.push({ step: 'AML_SCREEN', ok: true });
|
|
381
|
+
|
|
382
|
+
// Step 4: Confirm
|
|
383
|
+
const confirm = await this.confirmPayment(
|
|
384
|
+
init.paymentRequestId,
|
|
385
|
+
identify.customerId,
|
|
386
|
+
confirmation.code
|
|
387
|
+
);
|
|
388
|
+
if (!confirm.ok) {return { ok: false, error: confirm.error || 'CONFIRMATION_FAILED', completedSteps: steps };}
|
|
389
|
+
steps.push({ step: 'CONFIRM', ok: true });
|
|
390
|
+
|
|
391
|
+
// Step 5: Process
|
|
392
|
+
const process = await this.processPayment(
|
|
393
|
+
init.paymentRequestId,
|
|
394
|
+
identify.customerId
|
|
395
|
+
);
|
|
396
|
+
if (!process.ok) {return { ok: false, error: process.error || 'PROCESSING_FAILED', completedSteps: steps };}
|
|
397
|
+
steps.push({ step: 'PROCESS', ok: true });
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
ok: true,
|
|
401
|
+
transactionId: process.transactionId,
|
|
402
|
+
status: 'COMPLETED',
|
|
403
|
+
steps
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
} catch (error) {
|
|
407
|
+
return {
|
|
408
|
+
ok: false,
|
|
409
|
+
error: error.message,
|
|
410
|
+
completedSteps: steps
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ==================== Private Helpers ====================
|
|
416
|
+
|
|
417
|
+
async _checkMerchantLimits(merchantId, amount) {
|
|
418
|
+
// Check daily limit
|
|
419
|
+
const dailyTotal = await this._getMerchantDailyTotal(merchantId);
|
|
420
|
+
if (dailyTotal + amount > this.regulatoryLimits.merchant.daily) {
|
|
421
|
+
return { ok: false, error: 'DAILY_LIMIT_EXCEEDED' };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// Check per-transaction limit
|
|
425
|
+
if (amount > this.regulatoryLimits.merchant.perTransaction) {
|
|
426
|
+
return { ok: false, error: 'TRANSACTION_LIMIT_EXCEEDED' };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return { ok: true };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async _checkCustomerLimits(customerId, amount) {
|
|
433
|
+
const dailyTotal = await this._getCustomerDailyTotal(customerId);
|
|
434
|
+
if (dailyTotal + amount > this.regulatoryLimits.customer.daily) {
|
|
435
|
+
return { ok: false, error: 'DAILY_LIMIT_EXCEEDED' };
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (amount > this.regulatoryLimits.customer.perTransaction) {
|
|
439
|
+
return { ok: false, error: 'TRANSACTION_LIMIT_EXCEEDED' };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return { ok: true };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
_generatePaymentId() {
|
|
446
|
+
return `LN_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
_generateSecurePaymentId() {
|
|
450
|
+
return this._generatePaymentId();
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async _verifyMerchantCompliance(merchantId) {
|
|
454
|
+
if (!merchantId) {
|
|
455
|
+
return { ok: false, error: 'MERCHANT_NOT_FOUND' };
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return { ok: true };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
_handlePaymentInitiated(sessionData) {
|
|
462
|
+
return sessionData;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
_handleCustomerIdentified(data) {
|
|
466
|
+
return data;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
_handleAMLScreened(data) {
|
|
470
|
+
return data;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
_handlePaymentConfirmed(data) {
|
|
474
|
+
return data;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
_handlePaymentCompleted(data) {
|
|
478
|
+
return data;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
_handlePaymentFailed(data) {
|
|
482
|
+
return data;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
async _verifyNIDA(nin, _pin) {
|
|
486
|
+
// Implementation calls NIDA CIG
|
|
487
|
+
// For now, provide a deterministic mock: valid NIN is 20 digits
|
|
488
|
+
const ninPattern = /^[0-9]{20}$/;
|
|
489
|
+
if (!nin || !ninPattern.test(nin)) {
|
|
490
|
+
return { verified: false, nin };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Simulate successful lookup
|
|
494
|
+
return { verified: true, nin, firstName: 'John', lastName: 'Doe' };
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async _checkFIUList(_customerId) {
|
|
498
|
+
// Query FIU database
|
|
499
|
+
// For now, return false (not flagged)
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
async _storePaymentRequest(request) {
|
|
504
|
+
this.sessions.set(request.id, { ...request });
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async _storePaymentSession(sessionData) {
|
|
508
|
+
this.sessions.set(sessionData.id, { ...sessionData });
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
async _getPaymentRequest(id) {
|
|
512
|
+
return this.sessions.get(id) || null;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async _updatePaymentRequest(id, updates) {
|
|
516
|
+
const current = this.sessions.get(id);
|
|
517
|
+
if (current) {
|
|
518
|
+
this.sessions.set(id, { ...current, ...updates });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async _getMerchantDailyTotal(_merchantId) {
|
|
523
|
+
return 0;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
async _getCustomerDailyTotal(_customerId) {
|
|
527
|
+
return 0;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
async _queueForMonitoring(_paymentRequestId, _customerId) {
|
|
531
|
+
// Queue for AML transaction monitoring
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
async _submitToTIPS(_txData) {
|
|
535
|
+
// Submit to TIPS
|
|
536
|
+
return { ok: true, transactionId: 'TIPS_' + Date.now() };
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
async _logAMLTransaction(_paymentRequestId, _transactionId) {
|
|
540
|
+
// Log for FIU reporting
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
async _notifyMerchant(_callbackUrl, _data) {
|
|
544
|
+
// POST callback to merchant
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export default LipaNambaJourney;
|