fix for quote and operations addition
This commit is contained in:
@@ -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