fixes for multiple payout
This commit is contained in:
@@ -4,7 +4,7 @@ import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/quote/quote.dart';
|
||||
import 'package:pshared/models/payment/quote/status_type.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/provider/payment/multiple/provider.dart';
|
||||
import 'package:pshared/provider/payment/multiple/quotation.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
@@ -76,12 +76,12 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
return quoteRef != null && quoteRef.isNotEmpty;
|
||||
}
|
||||
|
||||
Money? aggregateDebitAmountFor(Wallet? sourceWallet) {
|
||||
Money? aggregateDebitAmountForCurrency(String? sourceCurrencyCode) {
|
||||
if (_rows.isEmpty) return null;
|
||||
final totals = aggregateMoneyByCurrency(
|
||||
_quoteItems().map((quote) => quote.amounts?.sourceDebitTotal),
|
||||
);
|
||||
return _moneyForSourceCurrency(totals, sourceWallet);
|
||||
return _moneyForSourceCurrency(totals, sourceCurrencyCode);
|
||||
}
|
||||
|
||||
Money? get requestedSentAmount {
|
||||
@@ -97,23 +97,23 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
return Money(amount: amountToString(total), currency: currency);
|
||||
}
|
||||
|
||||
Money? aggregateSettlementAmountFor(Wallet? sourceWallet) {
|
||||
Money? aggregateSettlementAmountForCurrency(String? sourceCurrencyCode) {
|
||||
if (_rows.isEmpty) return null;
|
||||
final totals = aggregateMoneyByCurrency(
|
||||
_quoteItems().map((quote) => quote.amounts?.destinationSettlement),
|
||||
);
|
||||
return _moneyForSourceCurrency(totals, sourceWallet);
|
||||
return _moneyForSourceCurrency(totals, sourceCurrencyCode);
|
||||
}
|
||||
|
||||
Money? aggregateFeeAmountFor(Wallet? sourceWallet) {
|
||||
Money? aggregateFeeAmountForCurrency(String? sourceCurrencyCode) {
|
||||
if (_rows.isEmpty) return null;
|
||||
final totals = aggregateMoneyByCurrency(_quoteItems().map(quoteFeeTotal));
|
||||
return _moneyForSourceCurrency(totals, sourceWallet);
|
||||
return _moneyForSourceCurrency(totals, sourceCurrencyCode);
|
||||
}
|
||||
|
||||
double? aggregateFeePercentFor(Wallet? sourceWallet) {
|
||||
final debit = aggregateDebitAmountFor(sourceWallet);
|
||||
final fee = aggregateFeeAmountFor(sourceWallet);
|
||||
double? aggregateFeePercentForCurrency(String? sourceCurrencyCode) {
|
||||
final debit = aggregateDebitAmountForCurrency(sourceCurrencyCode);
|
||||
final fee = aggregateFeeAmountForCurrency(sourceCurrencyCode);
|
||||
if (debit == null || fee == null) return null;
|
||||
|
||||
final debitValue = parseMoneyAmount(debit.amount, fallback: double.nan);
|
||||
@@ -126,7 +126,8 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
Future<void> quoteFromCsv({
|
||||
required String fileName,
|
||||
required String content,
|
||||
required Wallet sourceWallet,
|
||||
required PaymentMethodData sourceMethod,
|
||||
required String sourceCurrencyCode,
|
||||
}) async {
|
||||
if (isBusy) return;
|
||||
|
||||
@@ -144,18 +145,43 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
_sentCount = 0;
|
||||
|
||||
final rows = _csvParser.parseRows(content);
|
||||
final intents = _intentBuilder.buildIntents(sourceWallet, rows);
|
||||
await _quoteRows(
|
||||
quotation: quotation,
|
||||
fileName: fileName,
|
||||
rows: rows,
|
||||
sourceMethod: sourceMethod,
|
||||
sourceCurrencyCode: sourceCurrencyCode,
|
||||
);
|
||||
|
||||
_selectedFileName = fileName;
|
||||
_rows = rows;
|
||||
if (quotation.error != null) {
|
||||
_setErrorObject(quotation.error!);
|
||||
}
|
||||
} catch (e) {
|
||||
_setErrorObject(e);
|
||||
} finally {
|
||||
_setState(MultiplePayoutsState.idle);
|
||||
}
|
||||
}
|
||||
|
||||
await quotation.quotePayments(
|
||||
intents,
|
||||
metadata: <String, String>{
|
||||
'upload_filename': fileName,
|
||||
'upload_rows': rows.length.toString(),
|
||||
...?_uploadAmountMetadata(),
|
||||
},
|
||||
Future<void> requoteUploadedRows({
|
||||
required PaymentMethodData sourceMethod,
|
||||
required String sourceCurrencyCode,
|
||||
}) async {
|
||||
if (isBusy || _rows.isEmpty || _selectedFileName == null) return;
|
||||
final quotation = _quotation;
|
||||
if (quotation == null) return;
|
||||
|
||||
try {
|
||||
_setState(MultiplePayoutsState.quoting);
|
||||
_error = null;
|
||||
_sentCount = 0;
|
||||
|
||||
await _quoteRows(
|
||||
quotation: quotation,
|
||||
fileName: _selectedFileName!,
|
||||
rows: _rows,
|
||||
sourceMethod: sourceMethod,
|
||||
sourceCurrencyCode: sourceCurrencyCode,
|
||||
);
|
||||
|
||||
if (quotation.error != null) {
|
||||
@@ -254,13 +280,16 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
};
|
||||
}
|
||||
|
||||
Money? _moneyForSourceCurrency(List<Money>? values, Wallet? sourceWallet) {
|
||||
Money? _moneyForSourceCurrency(
|
||||
List<Money>? values,
|
||||
String? sourceCurrencyCode,
|
||||
) {
|
||||
if (values == null || values.isEmpty) return null;
|
||||
|
||||
if (sourceWallet != null) {
|
||||
final sourceCurrency = currencyCodeToString(sourceWallet.currency);
|
||||
if (sourceCurrencyCode != null && sourceCurrencyCode.isNotEmpty) {
|
||||
final sourceCurrency = sourceCurrencyCode.trim().toUpperCase();
|
||||
for (final value in values) {
|
||||
if (value.currency.toUpperCase() == sourceCurrency.toUpperCase()) {
|
||||
if (value.currency.toUpperCase() == sourceCurrency) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -272,6 +301,32 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
List<PaymentQuote> _quoteItems() =>
|
||||
_quotation?.quotation?.items ?? const <PaymentQuote>[];
|
||||
|
||||
Future<void> _quoteRows({
|
||||
required MultiQuotationProvider quotation,
|
||||
required String fileName,
|
||||
required List<CsvPayoutRow> rows,
|
||||
required PaymentMethodData sourceMethod,
|
||||
required String sourceCurrencyCode,
|
||||
}) async {
|
||||
final intents = _intentBuilder.buildIntents(
|
||||
sourceMethod: sourceMethod,
|
||||
sourceCurrency: sourceCurrencyCode,
|
||||
rows: rows,
|
||||
);
|
||||
|
||||
_selectedFileName = fileName;
|
||||
_rows = rows;
|
||||
|
||||
await quotation.quotePayments(
|
||||
intents,
|
||||
metadata: <String, String>{
|
||||
'upload_filename': fileName,
|
||||
'upload_rows': rows.length.toString(),
|
||||
...?_uploadAmountMetadata(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_quotation?.removeListener(_onQuotationChanged);
|
||||
|
||||
Reference in New Issue
Block a user