Intégration fonctionnalites V1
This commit is contained in:
@@ -27,6 +27,7 @@ class WalletTransaction {
|
||||
required this.amount,
|
||||
required this.balanceAfter,
|
||||
required this.createdAt,
|
||||
this.metadata = const {},
|
||||
});
|
||||
|
||||
final String uuid;
|
||||
@@ -34,6 +35,64 @@ class WalletTransaction {
|
||||
final double amount;
|
||||
final double balanceAfter;
|
||||
final DateTime? createdAt;
|
||||
final Map<String, dynamic> metadata;
|
||||
|
||||
String get displayLabel {
|
||||
final label = metadata['label'];
|
||||
if (label is String && label.isNotEmpty) {
|
||||
return label;
|
||||
}
|
||||
|
||||
return switch (type) {
|
||||
'credit' => 'Crédit',
|
||||
'debit' => 'Débit',
|
||||
'refund' => 'Remboursement',
|
||||
'hold' => 'Blocage',
|
||||
'release' => 'Libération',
|
||||
'adjustment' => 'Ajustement',
|
||||
_ => type,
|
||||
};
|
||||
}
|
||||
|
||||
String? get displaySubtitle {
|
||||
final stripeMap = _asStringMap(metadata['stripe']);
|
||||
if (stripeMap != null) {
|
||||
final brand = stripeMap['card_brand'];
|
||||
final last4 = stripeMap['card_last4'];
|
||||
if (brand is String && last4 is String) {
|
||||
return '${_formatCardBrand(brand)} •••• $last4';
|
||||
}
|
||||
|
||||
final paymentIntentId = stripeMap['payment_intent_id'];
|
||||
if (paymentIntentId is String && paymentIntentId.isNotEmpty) {
|
||||
return 'Stripe $paymentIntentId';
|
||||
}
|
||||
}
|
||||
|
||||
final providerPaymentId = metadata['provider_payment_id'];
|
||||
if (providerPaymentId is String && providerPaymentId.isNotEmpty) {
|
||||
return providerPaymentId;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static Map<String, dynamic>? _asStringMap(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is Map<String, dynamic>) return value;
|
||||
if (value is Map) return Map<String, dynamic>.from(value);
|
||||
return null;
|
||||
}
|
||||
|
||||
static String _formatCardBrand(String brand) {
|
||||
if (brand.isEmpty) return 'Carte';
|
||||
return switch (brand.toLowerCase()) {
|
||||
'visa' => 'Visa',
|
||||
'mastercard' => 'Mastercard',
|
||||
'amex' => 'Amex',
|
||||
_ => brand[0].toUpperCase() + brand.substring(1),
|
||||
};
|
||||
}
|
||||
|
||||
factory WalletTransaction.fromJson(Map<String, dynamic> json) {
|
||||
return WalletTransaction(
|
||||
@@ -44,6 +103,20 @@ class WalletTransaction {
|
||||
createdAt: json['created_at'] != null
|
||||
? DateTime.tryParse(json['created_at'] as String)
|
||||
: null,
|
||||
metadata: _parseMetadata(json['metadata']),
|
||||
);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _parseMetadata(dynamic value) {
|
||||
if (value == null) {
|
||||
return const {};
|
||||
}
|
||||
if (value is Map<String, dynamic>) {
|
||||
return value;
|
||||
}
|
||||
if (value is Map) {
|
||||
return Map<String, dynamic>.from(value);
|
||||
}
|
||||
return const {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user