fix for quote and operations addition
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/money.dart';
|
||||
import 'package:pshared/data/dto/payment/operation_money.dart';
|
||||
|
||||
part 'operation.g.dart';
|
||||
|
||||
@@ -13,8 +13,7 @@ class PaymentOperationDTO {
|
||||
final String? code;
|
||||
final String? state;
|
||||
final String? label;
|
||||
final MoneyDTO? amount;
|
||||
final MoneyDTO? convertedAmount;
|
||||
final PaymentOperationMoneyDTO? money;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
final String? startedAt;
|
||||
@@ -27,8 +26,7 @@ class PaymentOperationDTO {
|
||||
this.code,
|
||||
this.state,
|
||||
this.label,
|
||||
this.amount,
|
||||
this.convertedAmount,
|
||||
this.money,
|
||||
this.failureCode,
|
||||
this.failureReason,
|
||||
this.startedAt,
|
||||
|
||||
31
frontend/pshared/lib/data/dto/payment/operation_money.dart
Normal file
31
frontend/pshared/lib/data/dto/payment/operation_money.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:pshared/data/dto/money.dart';
|
||||
|
||||
part 'operation_money.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class PaymentOperationMoneySnapshotDTO {
|
||||
final MoneyDTO? amount;
|
||||
final MoneyDTO? convertedAmount;
|
||||
|
||||
const PaymentOperationMoneySnapshotDTO({this.amount, this.convertedAmount});
|
||||
|
||||
factory PaymentOperationMoneySnapshotDTO.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$PaymentOperationMoneySnapshotDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() =>
|
||||
_$PaymentOperationMoneySnapshotDTOToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class PaymentOperationMoneyDTO {
|
||||
final PaymentOperationMoneySnapshotDTO? planned;
|
||||
final PaymentOperationMoneySnapshotDTO? executed;
|
||||
|
||||
const PaymentOperationMoneyDTO({this.planned, this.executed});
|
||||
|
||||
factory PaymentOperationMoneyDTO.fromJson(Map<String, dynamic> json) =>
|
||||
_$PaymentOperationMoneyDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PaymentOperationMoneyDTOToJson(this);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:pshared/data/dto/payment/operation.dart';
|
||||
import 'package:pshared/data/dto/payment/operation_money.dart';
|
||||
import 'package:pshared/data/mapper/money.dart';
|
||||
import 'package:pshared/models/payment/execution_operation.dart';
|
||||
|
||||
@@ -11,8 +12,7 @@ extension PaymentOperationDTOMapper on PaymentOperationDTO {
|
||||
code: code,
|
||||
state: state,
|
||||
label: label,
|
||||
amount: amount?.toDomain(),
|
||||
convertedAmount: convertedAmount?.toDomain(),
|
||||
money: money?.toDomain(),
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
startedAt: _parseDateTime(startedAt),
|
||||
@@ -28,8 +28,7 @@ extension PaymentExecutionOperationMapper on PaymentExecutionOperation {
|
||||
code: code,
|
||||
state: state,
|
||||
label: label,
|
||||
amount: amount?.toDTO(),
|
||||
convertedAmount: convertedAmount?.toDTO(),
|
||||
money: money?.toDTO(),
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
startedAt: startedAt?.toUtc().toIso8601String(),
|
||||
@@ -37,6 +36,35 @@ extension PaymentExecutionOperationMapper on PaymentExecutionOperation {
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentOperationMoneyDTOMapper on PaymentOperationMoneyDTO {
|
||||
PaymentOperationMoney toDomain() => PaymentOperationMoney(
|
||||
planned: planned?.toDomain(),
|
||||
executed: executed?.toDomain(),
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentOperationMoneyMapper on PaymentOperationMoney {
|
||||
PaymentOperationMoneyDTO toDTO() => PaymentOperationMoneyDTO(
|
||||
planned: planned?.toDTO(),
|
||||
executed: executed?.toDTO(),
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentOperationMoneySnapshotDTOMapper
|
||||
on PaymentOperationMoneySnapshotDTO {
|
||||
PaymentOperationMoneySnapshot toDomain() => PaymentOperationMoneySnapshot(
|
||||
amount: amount?.toDomain(),
|
||||
convertedAmount: convertedAmount?.toDomain(),
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentOperationMoneySnapshotMapper on PaymentOperationMoneySnapshot {
|
||||
PaymentOperationMoneySnapshotDTO toDTO() => PaymentOperationMoneySnapshotDTO(
|
||||
amount: amount?.toDTO(),
|
||||
convertedAmount: convertedAmount?.toDTO(),
|
||||
);
|
||||
}
|
||||
|
||||
DateTime? _parseDateTime(String? value) {
|
||||
final normalized = value?.trim();
|
||||
if (normalized == null || normalized.isEmpty) return null;
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
|
||||
class PaymentOperationMoneySnapshot {
|
||||
final Money? amount;
|
||||
final Money? convertedAmount;
|
||||
|
||||
const PaymentOperationMoneySnapshot({
|
||||
required this.amount,
|
||||
required this.convertedAmount,
|
||||
});
|
||||
}
|
||||
|
||||
class PaymentOperationMoney {
|
||||
final PaymentOperationMoneySnapshot? planned;
|
||||
final PaymentOperationMoneySnapshot? executed;
|
||||
|
||||
const PaymentOperationMoney({required this.planned, required this.executed});
|
||||
}
|
||||
|
||||
class PaymentExecutionOperation {
|
||||
final String? stepRef;
|
||||
final String? operationRef;
|
||||
@@ -8,8 +25,7 @@ class PaymentExecutionOperation {
|
||||
final String? code;
|
||||
final String? state;
|
||||
final String? label;
|
||||
final Money? amount;
|
||||
final Money? convertedAmount;
|
||||
final PaymentOperationMoney? money;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
final DateTime? startedAt;
|
||||
@@ -22,11 +38,18 @@ class PaymentExecutionOperation {
|
||||
required this.code,
|
||||
required this.state,
|
||||
required this.label,
|
||||
required this.amount,
|
||||
required this.convertedAmount,
|
||||
required this.money,
|
||||
required this.failureCode,
|
||||
required this.failureReason,
|
||||
required this.startedAt,
|
||||
required this.completedAt,
|
||||
});
|
||||
|
||||
Money? get amount => money?.executed?.amount ?? money?.planned?.amount;
|
||||
Money? get convertedAmount =>
|
||||
money?.executed?.convertedAmount ?? money?.planned?.convertedAmount;
|
||||
Money? get plannedAmount => money?.planned?.amount;
|
||||
Money? get plannedConvertedAmount => money?.planned?.convertedAmount;
|
||||
Money? get executedAmount => money?.executed?.amount;
|
||||
Money? get executedConvertedAmount => money?.executed?.convertedAmount;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class OperationItem {
|
||||
final PaymentMethod? paymentMethod;
|
||||
final String name;
|
||||
final DateTime date;
|
||||
final String comment;
|
||||
// final String comment;
|
||||
|
||||
OperationItem({
|
||||
required this.status,
|
||||
@@ -34,6 +34,6 @@ class OperationItem {
|
||||
this.paymentMethod,
|
||||
required this.name,
|
||||
required this.date,
|
||||
required this.comment,
|
||||
// required this.comment,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:uuid/uuid.dart';
|
||||
import 'package:pshared/api/requests/payment/quotes.dart';
|
||||
import 'package:pshared/data/mapper/payment/intent/payment.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/quote/quotes.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/payment/auto_refresh.dart';
|
||||
@@ -12,6 +13,7 @@ import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/service/payment/multiple.dart';
|
||||
import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class MultiQuotationProvider extends ChangeNotifier {
|
||||
static const Duration _autoRefreshLead = Duration(seconds: 5);
|
||||
|
||||
@@ -77,6 +79,11 @@ class MultiQuotationProvider extends ChangeNotifier {
|
||||
if (intents.isEmpty) {
|
||||
throw StateError('At least one payment intent is required');
|
||||
}
|
||||
if (intents.any((intent) => !_isQuotable(intent))) {
|
||||
throw StateError(
|
||||
'Each payment intent must include kind, source, destination, and amount',
|
||||
);
|
||||
}
|
||||
|
||||
_lastIntents = List<PaymentIntent>.from(intents);
|
||||
_lastPreviewOnly = previewOnly;
|
||||
@@ -135,6 +142,13 @@ class MultiQuotationProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool _isQuotable(PaymentIntent intent) {
|
||||
if (intent.kind == PaymentKind.unspecified) return false;
|
||||
if (intent.source == null) return false;
|
||||
if (intent.destination == null) return false;
|
||||
return intent.amount != null;
|
||||
}
|
||||
|
||||
void _setResource(Resource<PaymentQuotes> quotation) {
|
||||
_quotation = quotation;
|
||||
_syncAutoRefresh();
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:pshared/api/requests/payment/quote.dart';
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/data/mapper/payment/intent/payment.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/quote/quote.dart';
|
||||
import 'package:pshared/models/auto_refresh_mode.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
@@ -52,13 +53,17 @@ class QuotationProvider extends ChangeNotifier {
|
||||
) {
|
||||
_organizations = venue;
|
||||
_sourceCurrencyCode = source.selectedCurrencyCode;
|
||||
final intent = _intentBuilder.build(
|
||||
final builtIntent = _intentBuilder.build(
|
||||
payment: payment,
|
||||
source: source,
|
||||
flow: flow,
|
||||
recipients: recipients,
|
||||
);
|
||||
if (intent == null) return;
|
||||
if (!_isQuotable(builtIntent)) {
|
||||
_clearQuotation();
|
||||
return;
|
||||
}
|
||||
final intent = builtIntent!;
|
||||
final intentKey = _buildIntentKey(intent);
|
||||
final lastIntent = _lastIntent;
|
||||
if (lastIntent != null && intentKey == _buildIntentKey(lastIntent)) return;
|
||||
@@ -100,12 +105,19 @@ class QuotationProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> refreshQuotation() async {
|
||||
final intent = _lastIntent;
|
||||
if (intent == null) return null;
|
||||
return getQuotation(intent);
|
||||
final lastIntent = _lastIntent;
|
||||
if (!_isQuotable(lastIntent)) {
|
||||
_clearQuotation();
|
||||
return null;
|
||||
}
|
||||
return getQuotation(lastIntent!);
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> getQuotation(PaymentIntent intent) async {
|
||||
if (!_isQuotable(intent)) {
|
||||
_clearQuotation();
|
||||
return null;
|
||||
}
|
||||
if (!_organizations.isOrganizationSet) {
|
||||
throw StateError('Organization is not set');
|
||||
}
|
||||
@@ -138,8 +150,20 @@ class QuotationProvider extends ChangeNotifier {
|
||||
|
||||
void reset() {
|
||||
_isLoaded = false;
|
||||
_lastIntent = null;
|
||||
_sourceCurrencyCode = null;
|
||||
_clearQuotation();
|
||||
}
|
||||
|
||||
bool _isQuotable(PaymentIntent? intent) {
|
||||
if (intent == null) return false;
|
||||
if (intent.kind == PaymentKind.unspecified) return false;
|
||||
if (intent.source == null) return false;
|
||||
if (intent.destination == null) return false;
|
||||
return intent.amount != null;
|
||||
}
|
||||
|
||||
void _clearQuotation() {
|
||||
_lastIntent = null;
|
||||
_setResource(Resource(data: null, isLoading: false, error: null));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user