payment recipient data

This commit is contained in:
Stephan D
2025-12-26 15:14:31 +01:00
parent 3836ff5ef3
commit 8adfab94b5
20 changed files with 442 additions and 68 deletions

View File

@@ -8,18 +8,22 @@ import 'package:pshared/api/requests/payment/quote.dart';
import 'package:pshared/data/mapper/payment/intent/payment.dart';
import 'package:pshared/models/asset.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/managed_wallet.dart';
import 'package:pshared/models/payment/methods/type.dart';
import 'package:pshared/models/payment/money.dart';
import 'package:pshared/models/payment/settlement_mode.dart';
import 'package:pshared/models/payment/intent.dart';
import 'package:pshared/models/payment/quote.dart';
import 'package:pshared/models/recipient/recipient.dart';
import 'package:pshared/provider/organizations.dart';
import 'package:pshared/provider/payment/amount.dart';
import 'package:pshared/provider/payment/flow.dart';
import 'package:pshared/provider/payment/wallets.dart';
import 'package:pshared/provider/recipient/provider.dart';
import 'package:pshared/provider/recipient/pmethods.dart';
import 'package:pshared/provider/resource.dart';
import 'package:pshared/service/payment/quotation.dart';
@@ -36,12 +40,17 @@ class QuotationProvider extends ChangeNotifier {
PaymentAmountProvider payment,
WalletsProvider wallets,
PaymentFlowProvider flow,
RecipientsProvider recipients,
PaymentMethodsProvider methods,
) {
_organizations = venue;
final t = flow.selectedType;
final method = methods.methods.firstWhereOrNull((m) => m.type == t);
if ((wallets.selectedWallet != null) && (method != null)) {
final customer = _buildCustomer(
recipient: recipients.currentObject,
method: method,
);
getQuotation(PaymentIntent(
kind: PaymentKind.payout,
amount: Money(
@@ -61,6 +70,7 @@ class QuotationProvider extends ChangeNotifier {
side: FxSide.sellBaseBuyQuote,
),
settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource,
customer: customer,
));
}
}
@@ -108,3 +118,42 @@ 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,
);
}