Connect customer quotations and payment execution to Sendico (#50)
This commit is contained in:
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;
|
||||
}
|
||||
Reference in new issue
Block a user