migration to address book service
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/utils/payment/masking.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
@@ -15,3 +18,15 @@ String getPaymentTypeLabel(BuildContext context, PaymentType type) {
|
||||
PaymentType.cryptoAddress => l10n.paymentTypeCryptoAddress,
|
||||
};
|
||||
}
|
||||
|
||||
String? _displayString(PaymentMethod m) => switch (m.type) {
|
||||
PaymentType.card => maskCardNumber(m.cardData?.pan),
|
||||
PaymentType.bankAccount => m.bankAccountData?.accountNumber,
|
||||
PaymentType.iban => m.ibanData?.iban,
|
||||
PaymentType.wallet => m.walletData?.walletId,
|
||||
PaymentType.cryptoAddress => m.cryptoAddressData?.address,
|
||||
};
|
||||
|
||||
String getPaymentTypeDescription(BuildContext context, PaymentMethod m) {
|
||||
return _displayString(m) ?? AppLocalizations.of(context)!.notSet;
|
||||
}
|
||||
25
frontend/pweb/lib/utils/payment/masking.dart
Normal file
25
frontend/pweb/lib/utils/payment/masking.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'dart:math';
|
||||
|
||||
|
||||
/// Masks a card number, leaving only the last 4 digits visible.
|
||||
/// Returns 'N/A' when the input is null or empty.
|
||||
String? maskCardNumber(String? pan) {
|
||||
if (pan == null || pan.isEmpty) return null;
|
||||
|
||||
// Strip non-digits to avoid leaking formatting patterns.
|
||||
final digits = pan.replaceAll(RegExp(r'\D'), '');
|
||||
if (digits.length <= 4) return digits;
|
||||
|
||||
final last4 = digits.substring(digits.length - 4);
|
||||
final maskedPrefix = '*' * (digits.length - 4);
|
||||
final masked = '$maskedPrefix$last4';
|
||||
|
||||
// Group into blocks of 4 for readability.
|
||||
final groups = <String>[];
|
||||
for (var i = 0; i < masked.length; i += 4) {
|
||||
final end = min(i + 4, masked.length);
|
||||
groups.add(masked.substring(i, end));
|
||||
}
|
||||
|
||||
return groups.join(' ');
|
||||
}
|
||||
Reference in New Issue
Block a user