Finally Fixed search field in payment page and cleaned up payment flow
This commit is contained in:
@@ -83,6 +83,58 @@ class QuotationProvider extends ChangeNotifier {
|
||||
Asset? get total => quotation == null ? null : createAsset(quotation!.debitAmount!.currency, quotation!.debitAmount!.amount);
|
||||
Asset? get recipientGets => quotation == null ? null : createAsset(quotation!.expectedSettlementAmount!.currency, quotation!.expectedSettlementAmount!.amount);
|
||||
|
||||
Customer _buildCustomer({
|
||||
required Recipient? recipient,
|
||||
required PaymentMethod method,
|
||||
}) {
|
||||
final name = _resolveCustomerName(method, recipient);
|
||||
String? firstName;
|
||||
String? middleName;
|
||||
String? lastName;
|
||||
|
||||
if (name != null && name.isNotEmpty) {
|
||||
final parts = name.split(RegExp(r'\s+'));
|
||||
if (parts.length == 1) {
|
||||
firstName = parts.first;
|
||||
} else if (parts.length == 2) {
|
||||
firstName = parts.first;
|
||||
lastName = parts.last;
|
||||
} else {
|
||||
firstName = parts.first;
|
||||
lastName = parts.last;
|
||||
middleName = parts.sublist(1, parts.length - 1).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
return Customer(
|
||||
id: recipient?.id ?? method.recipientRef,
|
||||
firstName: firstName,
|
||||
middleName: middleName,
|
||||
lastName: lastName,
|
||||
country: method.cardData?.country,
|
||||
);
|
||||
}
|
||||
|
||||
String? _resolveCustomerName(PaymentMethod method, Recipient? recipient) {
|
||||
final card = method.cardData;
|
||||
if (card != null) {
|
||||
return '${card.firstName} ${card.lastName}'.trim();
|
||||
}
|
||||
|
||||
final iban = method.ibanData;
|
||||
if (iban != null && iban.accountHolder.trim().isNotEmpty) {
|
||||
return iban.accountHolder.trim();
|
||||
}
|
||||
|
||||
final bank = method.bankAccountData;
|
||||
if (bank != null && bank.recipientName.trim().isNotEmpty) {
|
||||
return bank.recipientName.trim();
|
||||
}
|
||||
|
||||
final recipientName = recipient?.name.trim();
|
||||
return recipientName?.isNotEmpty == true ? recipientName : null;
|
||||
}
|
||||
|
||||
void _setResource(Resource<PaymentQuote> quotation) {
|
||||
_quotation = quotation;
|
||||
notifyListeners();
|
||||
@@ -118,42 +170,3 @@ class QuotationProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Customer? _buildCustomer({
|
||||
required Recipient? recipient,
|
||||
required PaymentMethod method,
|
||||
}) {
|
||||
final recipientId = (recipient?.id ?? method.recipientRef).trim();
|
||||
if (recipientId.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var firstName = '';
|
||||
var lastName = '';
|
||||
final cardData = method.cardData;
|
||||
if (cardData != null) {
|
||||
firstName = cardData.firstName.trim();
|
||||
lastName = cardData.lastName.trim();
|
||||
}
|
||||
|
||||
if ((firstName.isEmpty || lastName.isEmpty) && recipient != null) {
|
||||
final parts = recipient.name.trim().split(RegExp(r'\s+'));
|
||||
if (parts.isNotEmpty && firstName.isEmpty) {
|
||||
firstName = parts.first;
|
||||
}
|
||||
if (parts.length > 1 && lastName.isEmpty) {
|
||||
lastName = parts.sublist(1).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (lastName.isEmpty) {
|
||||
lastName = firstName;
|
||||
}
|
||||
|
||||
return Customer(
|
||||
id: recipientId,
|
||||
firstName: firstName.isEmpty ? null : firstName,
|
||||
lastName: lastName.isEmpty ? null : lastName,
|
||||
country: cardData?.country,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user