Connect customer quotations and payment execution to Sendico (#50)

This commit is contained in:
Stephan D committed 2026-10-16 09:57:28 +02:00
1 parent 5d67c25c8e
commit 7a6510d1a8
45 files changed
+2696 -45

No files matched your search

@@ -0,0 +1,78 @@
import 'dart:convert';
import 'wallet.dart';
/// Local BFF transport only; provider and widgets never parse response maps.
class BackendDTO {
BackendDTO.decode(String body) {
final envelope = jsonDecode(body) as Map<String, dynamic>;
accepted = envelope['status'] == 'success';
data = envelope['data'];
}
late final bool accepted;
late final dynamic data;
String get error =>
(data as Map<String, dynamic>?)?['error'] as String? ?? 'unavailable';
String get locale => (data as Map<String, dynamic>)['locale'] as String;
String get key => (data as Map<String, dynamic>)['idempotencyKey'] as String;
List<AccountDTO> get accounts =>
((data as Map<String, dynamic>)['accounts'] as List).map((v) {
final d = v as Map<String, dynamic>;
return AccountDTO(
d['id'] as String,
d['currency'] as String,
d['precision'] as int,
d['available'] as int,
payoutMethod: d['payoutMethod'] as String,
payoutLabel: d['payoutLabel'] as String,
canFund: d['canFund'] as bool,
);
}).toList();
List<OperationDTO> get operations =>
((data as Map<String, dynamic>)['operations'] as List)
.map((v) => operation(v as Map<String, dynamic>))
.toList();
QuoteDTO get quoteValue => quote(data as Map<String, dynamic>);
OperationDTO? get operationValue =>
data == null ? null : operation(data as Map<String, dynamic>);
static QuoteDTO quote(Map<String, dynamic> d) {
final r = d['request'] as Map<String, dynamic>;
return QuoteDTO(
d['id'] as String,
RequestDTO(
r['kind'] as String,
r['source'] as String,
(r['destination'] as String?)?.isEmpty == true
? null
: r['destination'] as String?,
r['amount'] as int,
r['recipient'] as String? ?? '',
),
d['fee'] as int,
d['debit'] as int,
d['credit'] as int,
DateTime.parse(d['expiresAt'] as String),
d['rateNumerator'] as int,
d['rateDenominator'] as int,
);
}
static OperationDTO operation(Map<String, dynamic> d) => OperationDTO(
d['id'] as String,
quote(d['quote'] as Map<String, dynamic>),
DateTime.parse(d['createdAt'] as String),
DateTime.parse(d['createdAt'] as String),
status: d['status'] as String,
);
ChallengeDTO get challenge => ChallengeDTO(data as Map<String, dynamic>);
}
class ChallengeDTO {
ChallengeDTO(Map<String, dynamic> d)
: id = d['challengeId'] as String,
target = d['target'] as String,
expires = DateTime.parse(d['expiresAt'] as String),
resend = DateTime.parse(d['resendAt'] as String);
final String id, target;
final DateTime expires, resend;
}
@@ -1,7 +1,17 @@
import '../models/wallet.dart';
class AccountDTO {
AccountDTO(this.id, this.currency, this.precision, this.available);
AccountDTO(
this.id,
this.currency,
this.precision,
this.available, {
this.payoutMethod = '',
this.payoutLabel = '',
this.canFund = true,
});
final String payoutMethod, payoutLabel;
final bool canFund;
final String id, currency;
final int precision;
int available;
@@ -64,6 +74,9 @@ abstract final class WalletMapper {
currency: d.currency,
precision: d.precision,
available: d.available,
payoutMethod: d.payoutMethod,
payoutLabel: d.payoutLabel,
canFund: d.canFund,
);
static RequestDTO request(TransferRequest r) =>
RequestDTO(r.kind.name, r.source, r.destination, r.amount, r.recipient);