@bloonio/lokotro-pay 1.0.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.
package/README.md ADDED
@@ -0,0 +1,585 @@
1
+ # @bloonio/lokotro-pay
2
+
3
+ Angular SDK for Lokotro Pay - A comprehensive payment processing library with support for multiple payment methods including cards, mobile money, e-wallets, and more.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🎨 **Glassmorphism UI** - Beautiful dark theme with modern glass effects
8
+ - 🌍 **Multi-language Support** - 10 languages (EN, FR, ES, DE, IT, RU, HI, JA, ZH, LN)
9
+ - 💳 **Multiple Payment Methods** - Card (Mastercard Hosted Session), Mobile Money, E-Wallet, Flash, Bank Transfer
10
+ - 📱 **Responsive Design** - Works on all screen sizes
11
+ - ⚡ **Angular 17+** - Built with standalone components
12
+ - 🔒 **Secure** - Built-in encryption and secure payment handling
13
+ - 🎯 **Type Safe** - Full TypeScript support
14
+
15
+ ## 📦 Installation
16
+
17
+ ```bash
18
+ npm install @bloonio/lokotro-pay
19
+ # or
20
+ yarn add @bloonio/lokotro-pay
21
+ ```
22
+
23
+ ## 🚀 Quick Start
24
+
25
+ ### Basic Usage (Standalone Components - Recommended)
26
+
27
+ ```typescript
28
+ import { Component } from '@angular/core';
29
+ import {
30
+ LokotroCheckoutComponent,
31
+ LokotroPayConfig,
32
+ LokotroPaymentBody,
33
+ LokotroPayOnResponse,
34
+ LokotroPayOnError
35
+ } from '@bloonio/lokotro-pay';
36
+
37
+ @Component({
38
+ selector: 'app-payment',
39
+ standalone: true,
40
+ imports: [LokotroCheckoutComponent],
41
+ template: `
42
+ <lokotro-checkout
43
+ [configs]="configs"
44
+ [paymentBody]="paymentBody"
45
+ (onResponse)="handleSuccess($event)"
46
+ (onError)="handleError($event)"
47
+ />
48
+ `
49
+ })
50
+ export class PaymentComponent {
51
+ // API Configuration
52
+ configs: LokotroPayConfig = {
53
+ token: 'your_encrypted_app_key',
54
+ isProduction: false,
55
+ acceptLanguage: 'en'
56
+ };
57
+
58
+ // Payment Request
59
+ paymentBody: LokotroPaymentBody = {
60
+ customerReference: `ORDER_${Date.now()}`,
61
+ amount: '50.00',
62
+ currency: 'USD',
63
+ paymentMethod: 'wallet',
64
+ userInfo: 'full',
65
+ paymentMethodInfo: 'full',
66
+ feeCoveredBy: 'buyer',
67
+ deliveryBehaviour: 'direct_delivery',
68
+ // User information
69
+ firstName: 'John',
70
+ lastName: 'Doe',
71
+ phoneNumber: '2439978540000',
72
+ email: 'johndoe@email.com',
73
+ // E-wallet credentials
74
+ walletNumber: '3005710720108954',
75
+ walletPin: '048698',
76
+ // Callbacks
77
+ notifyUrl: 'https://yourserver.com/notify',
78
+ successRedirectUrl: 'https://yourserver.com/success',
79
+ failRedirectUrl: 'https://yourserver.com/failed',
80
+ // Merchant info
81
+ merchant: {
82
+ id: 'merchant_123',
83
+ name: 'My Store',
84
+ logoUrl: 'https://mystore.com/logo.png',
85
+ website: 'https://mystore.com'
86
+ },
87
+ metadata: { orderId: '12345' }
88
+ };
89
+
90
+ handleSuccess(response: LokotroPayOnResponse) {
91
+ console.log('Payment successful!', response);
92
+ }
93
+
94
+ handleError(error: LokotroPayOnError) {
95
+ console.error('Payment failed:', error.message);
96
+ }
97
+ }
98
+ ```
99
+
100
+ ### Using NgModule
101
+
102
+ ```typescript
103
+ import { NgModule } from '@angular/core';
104
+ import { LokotroPayModule } from '@bloonio/lokotro-pay';
105
+
106
+ @NgModule({
107
+ imports: [LokotroPayModule]
108
+ })
109
+ export class AppModule {}
110
+ ```
111
+
112
+ ## 📖 Configuration
113
+
114
+ ### LokotroPayConfig
115
+
116
+ Configure your payment environment and authentication:
117
+
118
+ ```typescript
119
+ const configs: LokotroPayConfig = {
120
+ token: 'your_encrypted_app_key', // Required: Encrypted API key
121
+ isProduction: false, // Optional: Environment (default: false)
122
+ customApiUrl: 'https://api.custom.com', // Optional: Custom API endpoint
123
+ timeout: 60000, // Optional: Request timeout in ms
124
+ acceptLanguage: 'en' // Optional: API response language
125
+ };
126
+ ```
127
+
128
+ | Property | Type | Required | Default | Description |
129
+ |----------|------|----------|---------|-------------|
130
+ | `token` | `string` | Yes | - | Encrypted API key from backend |
131
+ | `isProduction` | `boolean` | No | `false` | Use production environment |
132
+ | `customApiUrl` | `string` | No | - | Custom API endpoint |
133
+ | `timeout` | `number` | No | `30000` | Request timeout (ms) |
134
+ | `acceptLanguage` | `string` | No | `'fr'` | Language for API responses |
135
+
136
+ ### LokotroPaymentBody
137
+
138
+ Define your payment request details:
139
+
140
+ ```typescript
141
+ const paymentBody: LokotroPaymentBody = {
142
+ // Required fields
143
+ customerReference: 'ORDER_12345', // Unique customer reference
144
+ amount: '100.00', // Amount as string
145
+ currency: 'USD', // Currency code
146
+
147
+ // Payment configuration
148
+ paymentMethod: 'wallet', // wallet, card, mobile_money, flash, bank_transfer
149
+ userInfo: 'full', // full, partial, none - controls user form visibility
150
+ paymentMethodInfo: 'full', // full, partial, none - controls payment method form
151
+ feeCoveredBy: 'buyer', // buyer or seller
152
+ deliveryBehaviour: 'direct_delivery', // direct_delivery or escrow
153
+
154
+ // User information (required when userInfo = 'full')
155
+ firstName: 'John',
156
+ lastName: 'Doe',
157
+ phoneNumber: '2439978540000',
158
+ email: 'johndoe@email.com',
159
+
160
+ // E-wallet fields (when paymentMethod = 'wallet')
161
+ walletNumber: '3005710720108954',
162
+ walletPin: '048698',
163
+
164
+ // Mobile money fields (when paymentMethod = 'mobile_money')
165
+ mobileMoneyPhoneNumber: '2439978540000',
166
+
167
+ // Flash fields (when paymentMethod = 'flash')
168
+ flashNumber: '1234567890',
169
+ flashPin: '1234',
170
+
171
+ // Card fields (when paymentMethod = 'card' with DIRECT_CAPTURE)
172
+ cardNumber: '4111111111111111',
173
+ cardExpiryDate: '12/25',
174
+ cardCvv: '123',
175
+ cardHolderName: 'John Doe',
176
+
177
+ // Mastercard payment method (for card payments)
178
+ mastercardPaymentMethod: 'HOSTED_SESSION', // or 'DIRECT_CAPTURE'
179
+
180
+ // Callback URLs
181
+ notifyUrl: 'https://yourserver.com/notify',
182
+ successRedirectUrl: 'https://yourserver.com/success',
183
+ failRedirectUrl: 'https://yourserver.com/failed',
184
+
185
+ // Merchant information
186
+ merchant: {
187
+ id: 'merchant_123',
188
+ name: 'My Store',
189
+ logoUrl: 'https://mystore.com/logo.png',
190
+ website: 'https://mystore.com'
191
+ },
192
+
193
+ // Additional metadata
194
+ metadata: { orderId: '12345', source: 'web' }
195
+ };
196
+ ```
197
+
198
+ ## 💳 Payment Methods
199
+
200
+ ### Supported Payment Methods
201
+
202
+ | Method | Value | Description |
203
+ |--------|-------|-------------|
204
+ | E-Wallet | `wallet` | Lokotro wallet payments |
205
+ | Card | `card` | Credit/Debit card (Mastercard Hosted Session) |
206
+ | Mobile Money | `mobile_money` | Mobile money providers |
207
+ | Flash | `flash` | Lokotro Flash instant payments |
208
+ | Bank Transfer | `bank_transfer` | Direct bank transfers |
209
+
210
+ ### Payment Method Examples
211
+
212
+ #### E-Wallet Payment
213
+
214
+ ```typescript
215
+ const paymentBody: LokotroPaymentBody = {
216
+ customerReference: `WALLET_${Date.now()}`,
217
+ amount: '50.00',
218
+ currency: 'USD',
219
+ paymentMethod: 'wallet',
220
+ userInfo: 'full',
221
+ paymentMethodInfo: 'full',
222
+ firstName: 'John',
223
+ lastName: 'Doe',
224
+ phoneNumber: '2439978540000',
225
+ email: 'johndoe@email.com',
226
+ walletNumber: '3005710720108954',
227
+ walletPin: '048698'
228
+ };
229
+ ```
230
+
231
+ #### Mobile Money Payment
232
+
233
+ ```typescript
234
+ const paymentBody: LokotroPaymentBody = {
235
+ customerReference: `MOMO_${Date.now()}`,
236
+ amount: '25.00',
237
+ currency: 'USD',
238
+ paymentMethod: 'mobile_money',
239
+ userInfo: 'full',
240
+ paymentMethodInfo: 'full',
241
+ firstName: 'John',
242
+ lastName: 'Doe',
243
+ phoneNumber: '2439978540000',
244
+ email: 'johndoe@email.com',
245
+ mobileMoneyPhoneNumber: '2439978540000'
246
+ };
247
+ ```
248
+
249
+ #### Card Payment (Hosted Session - Recommended)
250
+
251
+ ```typescript
252
+ const paymentBody: LokotroPaymentBody = {
253
+ customerReference: `CARD_${Date.now()}`,
254
+ amount: '100.00',
255
+ currency: 'USD',
256
+ paymentMethod: 'card',
257
+ userInfo: 'full',
258
+ paymentMethodInfo: 'full',
259
+ mastercardPaymentMethod: 'HOSTED_SESSION',
260
+ firstName: 'John',
261
+ lastName: 'Doe',
262
+ phoneNumber: '2439978540000',
263
+ email: 'johndoe@email.com',
264
+ successRedirectUrl: 'https://yourserver.com/success',
265
+ failRedirectUrl: 'https://yourserver.com/failed',
266
+ notifyUrl: 'https://yourserver.com/notify'
267
+ };
268
+ ```
269
+
270
+ #### Flash Payment
271
+
272
+ ```typescript
273
+ const paymentBody: LokotroPaymentBody = {
274
+ customerReference: `FLASH_${Date.now()}`,
275
+ amount: '10.00',
276
+ currency: 'USD',
277
+ paymentMethod: 'flash',
278
+ userInfo: 'full',
279
+ paymentMethodInfo: 'full',
280
+ firstName: 'John',
281
+ lastName: 'Doe',
282
+ phoneNumber: '2439978540000',
283
+ email: 'johndoe@email.com',
284
+ flashNumber: '1234567890',
285
+ flashPin: '1234'
286
+ };
287
+ ```
288
+
289
+ ### User Info & Payment Method Info Options
290
+
291
+ Control which forms are shown to the user:
292
+
293
+ | `userInfo` | `paymentMethodInfo` | User Form | Payment Form |
294
+ |------------|---------------------|-----------|--------------|
295
+ | `none` | `none` | Visible | Visible |
296
+ | `full` | `none` | Hidden | Visible |
297
+ | `none` | `full` | Visible | Hidden |
298
+ | `full` | `full` | Hidden | Hidden |
299
+
300
+ ```typescript
301
+ // Show both forms (user enters all info)
302
+ const paymentBody: LokotroPaymentBody = {
303
+ userInfo: 'none',
304
+ paymentMethodInfo: 'none',
305
+ // ... other fields
306
+ };
307
+
308
+ // Pre-fill user info, show payment form only
309
+ const paymentBody: LokotroPaymentBody = {
310
+ userInfo: 'full',
311
+ paymentMethodInfo: 'none',
312
+ firstName: 'John',
313
+ lastName: 'Doe',
314
+ // ... other fields
315
+ };
316
+ ```
317
+
318
+ ## 🎨 Styling
319
+
320
+ ### Import Global Styles
321
+
322
+ Add to your `angular.json` or `styles.scss`:
323
+
324
+ ```scss
325
+ @import '@bloonio/lokotro-pay/styles/lokotro-pay.scss';
326
+ ```
327
+
328
+ ### CSS Variables
329
+
330
+ Override theme variables in your styles:
331
+
332
+ ```css
333
+ :root {
334
+ --lokotro-primary: #5A5E39;
335
+ --lokotro-accent: #3BFBDA;
336
+ --lokotro-background: #1C2621;
337
+ --lokotro-text-primary: #F2F0D5;
338
+ }
339
+ ```
340
+
341
+ ## 🌐 Multi-Language Support
342
+
343
+ ### Setting Language
344
+
345
+ ```typescript
346
+ import { LokotroLocalizationService, LokotroPayLanguage } from '@bloonio/lokotro-pay';
347
+
348
+ constructor(private localization: LokotroLocalizationService) {
349
+ this.localization.setLanguage(LokotroPayLanguage.French);
350
+ }
351
+ ```
352
+
353
+ ### Supported Languages
354
+
355
+ | Language | Code | Native Name |
356
+ |----------|------|-------------|
357
+ | English | `en` | English |
358
+ | French | `fr` | Français |
359
+ | German | `de` | Deutsch |
360
+ | Spanish | `es` | Español |
361
+ | Italian | `it` | Italiano |
362
+ | Russian | `ru` | Русский |
363
+ | Hindi | `hi` | हिंदी |
364
+ | Japanese | `ja` | 日本語 |
365
+ | Chinese | `zh` | 中文 |
366
+ | Lingala | `ln` | Lingala |
367
+
368
+ ## 🔧 Advanced Usage
369
+
370
+ ### Using the Payment Service Directly
371
+
372
+ ```typescript
373
+ import { LokotroPaymentService } from '@bloonio/lokotro-pay';
374
+
375
+ @Component({...})
376
+ export class MyComponent {
377
+ constructor(private paymentService: LokotroPaymentService) {
378
+ // Subscribe to payment state changes
379
+ this.paymentService.state$.subscribe(state => {
380
+ console.log('Payment state:', state);
381
+ });
382
+ }
383
+
384
+ async initiatePayment() {
385
+ await this.paymentService.initiatePayment(configs, paymentBody);
386
+ }
387
+ }
388
+ ```
389
+
390
+ ## API Reference
391
+
392
+ ### Services
393
+
394
+ #### LokotroPaymentService
395
+
396
+ | Method | Description |
397
+ |--------|-------------|
398
+ | `initiatePayment(config, body)` | Start a new payment |
399
+ | `submitPayment(channel, data)` | Submit payment with specific method |
400
+ | `verifyOtp(otp)` | Verify OTP code |
401
+ | `resendOtp()` | Resend OTP |
402
+ | `cancelPayment()` | Cancel current payment |
403
+ | `state$` | Observable of payment state |
404
+
405
+ #### LokotroLocalizationService
406
+
407
+ | Method | Description |
408
+ |--------|-------------|
409
+ | `setLanguage(lang)` | Set UI language |
410
+ | `translate(key, params?)` | Translate a key |
411
+ | `currentLanguage$` | Observable of current language |
412
+
413
+ #### LokotroHttpClientService
414
+
415
+ | Method | Description |
416
+ |--------|-------------|
417
+ | `get<T>(url)` | HTTP GET request |
418
+ | `post<T>(url, body)` | HTTP POST request |
419
+ | `setAppKey(key)` | Set API app key |
420
+
421
+ ### Components
422
+
423
+ | Component | Description |
424
+ |-----------|-------------|
425
+ | `LokotroCheckoutComponent` | Main checkout widget |
426
+ | `LokotroPaymentStatusComponent` | Payment status tracker (uses only paymentId) |
427
+ | `LokotroPaymentMethodSelectionComponent` | Payment method grid |
428
+ | `LokotroPaymentFormComponent` | Payment forms |
429
+ | `LokotroOtpVerificationComponent` | OTP input |
430
+ | `LokotroProcessingComponent` | Processing spinner |
431
+ | `LokotroResultComponent` | Success/error screens |
432
+ | `LokotroLoadingComponent` | Loading indicator |
433
+
434
+ ## Payment Status Tracking
435
+
436
+ Use `LokotroPaymentStatusComponent` when you only have a payment ID and want to track the payment status. This is useful for scenarios where the payment was initiated elsewhere (e.g., from a Flutter app or server-side).
437
+
438
+ ### Basic Usage
439
+
440
+ ```typescript
441
+ import { Component } from '@angular/core';
442
+ import {
443
+ LokotroPaymentStatusComponent,
444
+ LokotroPaymentStatusConfig,
445
+ LokotroPaymentStatusResponse,
446
+ LokotroPayLanguage
447
+ } from '@bloonio/lokotro-pay';
448
+
449
+ @Component({
450
+ selector: 'app-payment-status',
451
+ standalone: true,
452
+ imports: [LokotroPaymentStatusComponent],
453
+ template: `
454
+ <lokotro-payment-status
455
+ [statusConfig]="statusConfig"
456
+ (statusChange)="onStatusChange($event)"
457
+ (paymentComplete)="onPaymentComplete($event)"
458
+ (paymentFailed)="onPaymentFailed($event)"
459
+ (onClose)="onClose()"
460
+ />
461
+ `
462
+ })
463
+ export class PaymentStatusPageComponent {
464
+ statusConfig: LokotroPaymentStatusConfig = {
465
+ paymentId: 'your-payment-id', // Only the payment ID is required!
466
+ config: {
467
+ token: 'your-app-key',
468
+ isProduction: false
469
+ },
470
+ pollingInterval: 5000, // Check every 5 seconds
471
+ maxPollingAttempts: 60, // Stop after 5 minutes
472
+ language: LokotroPayLanguage.French
473
+ };
474
+
475
+ onStatusChange(response: LokotroPaymentStatusResponse) {
476
+ console.log('Status changed:', response.status);
477
+ }
478
+
479
+ onPaymentComplete(response: LokotroPaymentStatusResponse) {
480
+ console.log('Payment completed!', response);
481
+ // Navigate to success page or update UI
482
+ }
483
+
484
+ onPaymentFailed(response: LokotroPaymentStatusResponse) {
485
+ console.error('Payment failed:', response.message);
486
+ // Show error message or retry option
487
+ }
488
+
489
+ onClose() {
490
+ // Navigate away or close modal
491
+ }
492
+ }
493
+ ```
494
+
495
+ ### LokotroPaymentStatusConfig
496
+
497
+ | Property | Type | Required | Default | Description |
498
+ |----------|------|----------|---------|-------------|
499
+ | `paymentId` | `string` | Yes | - | The payment/transaction ID to track |
500
+ | `config` | `LokotroPayConfig` | Yes | - | API configuration with token |
501
+ | `pollingInterval` | `number` | No | `5000` | Polling interval in milliseconds |
502
+ | `maxPollingAttempts` | `number` | No | `60` | Max attempts before timeout |
503
+ | `language` | `LokotroPayLanguage` | No | `English` | UI language |
504
+ | `autoStart` | `boolean` | No | `true` | Auto-start polling on init |
505
+
506
+ ### Component Inputs/Outputs
507
+
508
+ #### Inputs
509
+
510
+ | Input | Type | Description |
511
+ |-------|------|-------------|
512
+ | `statusConfig` | `LokotroPaymentStatusConfig` | Configuration object |
513
+ | `showHeader` | `boolean` | Show/hide header (default: true) |
514
+ | `showCloseButton` | `boolean` | Show/hide close button (default: true) |
515
+
516
+ #### Outputs
517
+
518
+ | Output | Type | Description |
519
+ |--------|------|-------------|
520
+ | `statusChange` | `LokotroPaymentStatusResponse` | Emitted on every status check |
521
+ | `paymentComplete` | `LokotroPaymentStatusResponse` | Emitted when payment succeeds |
522
+ | `paymentFailed` | `LokotroPaymentStatusResponse` | Emitted when payment fails |
523
+ | `onClose` | `void` | Emitted when close/done is clicked |
524
+ | `onDoneEvent` | `LokotroPaymentStatusResponse` | Emitted with details when done |
525
+
526
+ ### Payment Status States
527
+
528
+ The component handles these payment states:
529
+
530
+ | Status | Description |
531
+ |--------|-------------|
532
+ | `pending` | Payment awaiting confirmation |
533
+ | `processing` | Payment being processed |
534
+ | `approved` | Payment completed successfully |
535
+ | `declined` | Payment was declined |
536
+ | `failed` | Payment failed |
537
+ | `cancelled` | Payment was cancelled |
538
+ | `expired` | Payment session expired |
539
+
540
+ ## 🔧 Environment Setup
541
+
542
+ ### Development
543
+
544
+ ```typescript
545
+ const devConfig: LokotroPayConfig = {
546
+ token: 'your_dev_token',
547
+ isProduction: false // Uses dev.apps.api.bloonio.com
548
+ };
549
+ ```
550
+
551
+ ### Production
552
+
553
+ ```typescript
554
+ const prodConfig: LokotroPayConfig = {
555
+ token: 'your_prod_token',
556
+ isProduction: true // Uses apps.api.bloonio.com
557
+ };
558
+ ```
559
+
560
+ ## 📋 Requirements
561
+
562
+ - Angular 17+
563
+ - TypeScript 5.0+
564
+ - RxJS 7.8+
565
+
566
+ ## 🌐 Browser Support
567
+
568
+ - Chrome (latest)
569
+ - Firefox (latest)
570
+ - Safari (latest)
571
+ - Edge (latest)
572
+
573
+ ## 📄 License
574
+
575
+ MIT © Bloonio
576
+
577
+ ## 🆘 Support
578
+
579
+ - 📧 Email: support@lokotroo.com
580
+ - 🐛 Issues: [GitHub Issues](https://github.com/bloonio/lokotro-pay-angular/issues)
581
+ - 📖 Documentation: [Full Documentation](https://docs.bloonio.com/pay)
582
+
583
+ ---
584
+
585
+ **Made with ❤️ for the Angular community**