Intégration fonctionnalites V1
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/// Transaction de paiement externe (rechargement wallet).
|
||||
class PaymentTransaction {
|
||||
const PaymentTransaction({
|
||||
required this.uuid,
|
||||
required this.provider,
|
||||
required this.amount,
|
||||
required this.currency,
|
||||
required this.status,
|
||||
this.providerPaymentId,
|
||||
this.stripe,
|
||||
});
|
||||
|
||||
final String uuid;
|
||||
final String provider;
|
||||
final String? providerPaymentId;
|
||||
final double amount;
|
||||
final String currency;
|
||||
final String status;
|
||||
final StripePaymentDetails? stripe;
|
||||
|
||||
factory PaymentTransaction.fromJson(Map<String, dynamic> json) {
|
||||
final stripeJson = json['stripe'];
|
||||
return PaymentTransaction(
|
||||
uuid: json['uuid'] as String,
|
||||
provider: json['provider'] as String,
|
||||
providerPaymentId: json['provider_payment_id'] as String?,
|
||||
amount: (json['amount'] as num).toDouble(),
|
||||
currency: json['currency'] as String,
|
||||
status: json['status'] as String,
|
||||
stripe: stripeJson is Map<String, dynamic>
|
||||
? StripePaymentDetails.fromJson(stripeJson)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StripePaymentDetails {
|
||||
const StripePaymentDetails({
|
||||
required this.paymentIntentId,
|
||||
required this.clientSecret,
|
||||
required this.publishableKey,
|
||||
});
|
||||
|
||||
final String paymentIntentId;
|
||||
final String clientSecret;
|
||||
final String publishableKey;
|
||||
|
||||
factory StripePaymentDetails.fromJson(Map<String, dynamic> json) {
|
||||
return StripePaymentDetails(
|
||||
paymentIntentId: json['payment_intent_id'] as String,
|
||||
clientSecret: json['client_secret'] as String,
|
||||
publishableKey: json['publishable_key'] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TopUpResult {
|
||||
const TopUpResult({
|
||||
required this.payment,
|
||||
required this.balance,
|
||||
});
|
||||
|
||||
final PaymentTransaction payment;
|
||||
final double balance;
|
||||
|
||||
factory TopUpResult.fromJson(Map<String, dynamic> json) {
|
||||
return TopUpResult(
|
||||
payment: PaymentTransaction.fromJson(json['payment'] as Map<String, dynamic>),
|
||||
balance: (json['balance'] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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