added comment for payment, changed intent and added amount ui in operations
This commit is contained in:
@@ -10,10 +10,8 @@ import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/crypto_address.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/methods/iban.dart';
|
||||
import 'package:pshared/models/payment/methods/ledger.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';
|
||||
@@ -27,6 +25,7 @@ import 'package:pshared/utils/payment/fx_helpers.dart';
|
||||
|
||||
class QuotationIntentBuilder {
|
||||
static const String _settlementCurrency = 'RUB';
|
||||
static const String _addressBookCustomerFallbackId = 'address_book_customer';
|
||||
|
||||
PaymentIntent? build({
|
||||
required PaymentAmountProvider payment,
|
||||
@@ -38,9 +37,11 @@ class QuotationIntentBuilder {
|
||||
final sourceCurrency = source.selectedCurrencyCode;
|
||||
final paymentData = flow.selectedPaymentData;
|
||||
final selectedMethod = flow.selectedMethod;
|
||||
final amountValue = payment.amount;
|
||||
if (sourceMethod == null || sourceCurrency == null || paymentData == null) {
|
||||
return null;
|
||||
}
|
||||
if (amountValue == null) return null;
|
||||
|
||||
final customer = _buildCustomer(
|
||||
recipient: recipients.currentObject,
|
||||
@@ -51,7 +52,7 @@ class QuotationIntentBuilder {
|
||||
? _settlementCurrency
|
||||
: sourceCurrency;
|
||||
final amount = Money(
|
||||
amount: payment.amount.toString(),
|
||||
amount: amountValue.toString(),
|
||||
currency: amountCurrency,
|
||||
);
|
||||
final isLedgerSource = source.selectedLedgerAccount != null;
|
||||
@@ -65,6 +66,7 @@ class QuotationIntentBuilder {
|
||||
isLedgerSource: isLedgerSource,
|
||||
enabled: !isCryptoToCrypto,
|
||||
);
|
||||
final comment = _resolveComment(payment.comment);
|
||||
return PaymentIntent(
|
||||
kind: PaymentKind.payout,
|
||||
amount: amount,
|
||||
@@ -75,6 +77,7 @@ class QuotationIntentBuilder {
|
||||
? FeeTreatment.addToSource
|
||||
: FeeTreatment.deductFromDestination,
|
||||
settlementMode: payment.settlementMode,
|
||||
comment: comment,
|
||||
customer: customer,
|
||||
);
|
||||
}
|
||||
@@ -134,17 +137,14 @@ class QuotationIntentBuilder {
|
||||
required PaymentMethod? method,
|
||||
required PaymentMethodData? data,
|
||||
}) {
|
||||
final id = recipient?.id ?? method?.recipientRef;
|
||||
if (id == null || id.isEmpty) return null;
|
||||
final name = recipient?.name.trim();
|
||||
if (name == null || name.isEmpty) return null;
|
||||
final id = recipient?.id.trim();
|
||||
final customerId = id == null || id.isEmpty
|
||||
? _addressBookCustomerFallbackId
|
||||
: id;
|
||||
|
||||
final name = _resolveCustomerName(
|
||||
method: method,
|
||||
data: data,
|
||||
recipient: recipient,
|
||||
);
|
||||
final parts = name == null || name.trim().isEmpty
|
||||
? const <String>[]
|
||||
: name.trim().split(RegExp(r'\s+'));
|
||||
final parts = name.split(RegExp(r'\s+'));
|
||||
final firstName = parts.isNotEmpty ? parts.first : null;
|
||||
final lastName = parts.length >= 2 ? parts.last : null;
|
||||
final middleName = parts.length > 2
|
||||
@@ -152,7 +152,7 @@ class QuotationIntentBuilder {
|
||||
: null;
|
||||
|
||||
return Customer(
|
||||
id: id,
|
||||
id: customerId,
|
||||
firstName: firstName,
|
||||
middleName: middleName,
|
||||
lastName: lastName,
|
||||
@@ -160,33 +160,6 @@ class QuotationIntentBuilder {
|
||||
);
|
||||
}
|
||||
|
||||
String? _resolveCustomerName({
|
||||
required PaymentMethod? method,
|
||||
required PaymentMethodData? data,
|
||||
required Recipient? recipient,
|
||||
}) {
|
||||
final card = method?.cardData ?? (data is CardPaymentMethod ? data : null);
|
||||
if (card != null) {
|
||||
final fullName = '${card.firstName} ${card.lastName}'.trim();
|
||||
if (fullName.isNotEmpty) return fullName;
|
||||
}
|
||||
|
||||
final iban = method?.ibanData ?? (data is IbanPaymentMethod ? data : null);
|
||||
if (iban != null && iban.accountHolder.trim().isNotEmpty) {
|
||||
return iban.accountHolder.trim();
|
||||
}
|
||||
|
||||
final bank =
|
||||
method?.bankAccountData ??
|
||||
(data is RussianBankAccountPaymentMethod ? data : null);
|
||||
if (bank != null && bank.recipientName.trim().isNotEmpty) {
|
||||
return bank.recipientName.trim();
|
||||
}
|
||||
|
||||
final recipientName = recipient?.name.trim();
|
||||
return recipientName?.isNotEmpty == true ? recipientName : null;
|
||||
}
|
||||
|
||||
String? _resolveCustomerCountry({
|
||||
required PaymentMethod? method,
|
||||
required PaymentMethodData? data,
|
||||
@@ -194,4 +167,9 @@ class QuotationIntentBuilder {
|
||||
final card = method?.cardData ?? (data is CardPaymentMethod ? data : null);
|
||||
return card?.country;
|
||||
}
|
||||
|
||||
String? _resolveComment(String comment) {
|
||||
final normalized = comment.trim();
|
||||
return normalized.isEmpty ? null : normalized;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user