fixed ledger account listing + quotation listing
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
import 'package:pshared/controllers/wallets.dart';
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/models/payment/currency_pair.dart';
|
||||
import 'package:pshared/models/payment/customer.dart';
|
||||
import 'package:pshared/models/payment/fx/intent.dart';
|
||||
import 'package:pshared/models/payment/fx/side.dart';
|
||||
import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/methods/iban.dart';
|
||||
import 'package:pshared/models/payment/methods/managed_wallet.dart';
|
||||
import 'package:pshared/models/payment/methods/russian_bank.dart';
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/settlement_mode.dart';
|
||||
@@ -15,7 +17,6 @@ import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/provider/payment/flow.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
@@ -25,15 +26,16 @@ class QuotationIntentBuilder {
|
||||
required WalletsController wallets,
|
||||
required PaymentFlowProvider flow,
|
||||
required RecipientsProvider recipients,
|
||||
required PaymentMethodsProvider methods,
|
||||
}) {
|
||||
final selectedWallet = wallets.selectedWallet;
|
||||
final method = methods.methods.firstWhereOrNull((m) => m.type == flow.selectedType);
|
||||
if (selectedWallet == null || method == null) return null;
|
||||
final paymentData = flow.selectedPaymentData;
|
||||
final selectedMethod = flow.selectedMethod;
|
||||
if (selectedWallet == null || paymentData == null) return null;
|
||||
|
||||
final customer = _buildCustomer(
|
||||
recipient: recipients.currentObject,
|
||||
method: method,
|
||||
method: selectedMethod,
|
||||
data: paymentData,
|
||||
);
|
||||
final amount = Money(
|
||||
amount: payment.amount.toString(),
|
||||
@@ -50,7 +52,7 @@ class QuotationIntentBuilder {
|
||||
return PaymentIntent(
|
||||
kind: PaymentKind.payout,
|
||||
amount: amount,
|
||||
destination: method.data,
|
||||
destination: paymentData,
|
||||
source: ManagedWalletPaymentMethod(
|
||||
managedWalletRef: selectedWallet.id,
|
||||
),
|
||||
@@ -85,11 +87,19 @@ class QuotationIntentBuilder {
|
||||
return amount.currency;
|
||||
}
|
||||
|
||||
Customer _buildCustomer({
|
||||
Customer? _buildCustomer({
|
||||
required Recipient? recipient,
|
||||
required PaymentMethod method,
|
||||
required PaymentMethod? method,
|
||||
required PaymentMethodData? data,
|
||||
}) {
|
||||
final name = _resolveCustomerName(method, recipient);
|
||||
final id = recipient?.id ?? method?.recipientRef;
|
||||
if (id == null || id.isEmpty) return null;
|
||||
|
||||
final name = _resolveCustomerName(
|
||||
method: method,
|
||||
data: data,
|
||||
recipient: recipient,
|
||||
);
|
||||
final parts = name == null || name.trim().isEmpty
|
||||
? const <String>[]
|
||||
: name.trim().split(RegExp(r'\s+'));
|
||||
@@ -99,26 +109,31 @@ class QuotationIntentBuilder {
|
||||
parts.length > 2 ? parts.sublist(1, parts.length - 1).join(' ') : null;
|
||||
|
||||
return Customer(
|
||||
id: recipient?.id ?? method.recipientRef,
|
||||
id: id,
|
||||
firstName: firstName,
|
||||
middleName: middleName,
|
||||
lastName: lastName,
|
||||
country: method.cardData?.country,
|
||||
country: _resolveCustomerCountry(method: method, data: data),
|
||||
);
|
||||
}
|
||||
|
||||
String? _resolveCustomerName(PaymentMethod method, Recipient? recipient) {
|
||||
final card = method.cardData;
|
||||
String? _resolveCustomerName({
|
||||
required PaymentMethod? method,
|
||||
required PaymentMethodData? data,
|
||||
required Recipient? recipient,
|
||||
}) {
|
||||
final card = method?.cardData ?? (data is CardPaymentMethod ? data : null);
|
||||
if (card != null) {
|
||||
return '${card.firstName} ${card.lastName}'.trim();
|
||||
final fullName = '${card.firstName} ${card.lastName}'.trim();
|
||||
if (fullName.isNotEmpty) return fullName;
|
||||
}
|
||||
|
||||
final iban = method.ibanData;
|
||||
final iban = method?.ibanData ?? (data is IbanPaymentMethod ? data : null);
|
||||
if (iban != null && iban.accountHolder.trim().isNotEmpty) {
|
||||
return iban.accountHolder.trim();
|
||||
}
|
||||
|
||||
final bank = method.bankAccountData;
|
||||
final bank = method?.bankAccountData ?? (data is RussianBankAccountPaymentMethod ? data : null);
|
||||
if (bank != null && bank.recipientName.trim().isNotEmpty) {
|
||||
return bank.recipientName.trim();
|
||||
}
|
||||
@@ -126,4 +141,12 @@ class QuotationIntentBuilder {
|
||||
final recipientName = recipient?.name.trim();
|
||||
return recipientName?.isNotEmpty == true ? recipientName : null;
|
||||
}
|
||||
|
||||
String? _resolveCustomerCountry({
|
||||
required PaymentMethod? method,
|
||||
required PaymentMethodData? data,
|
||||
}) {
|
||||
final card = method?.cardData ?? (data is CardPaymentMethod ? data : null);
|
||||
return card?.country;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user