Fixes for build

This commit is contained in:
Arseni
2025-12-26 19:26:19 +03:00
parent f339630115
commit ad3d44f137
8 changed files with 198 additions and 26 deletions

View File

@@ -0,0 +1,41 @@
import 'package:json_annotation/json_annotation.dart';
part 'customer.g.dart';
@JsonSerializable()
class CustomerDTO {
final String id;
@JsonKey(name: 'first_name')
final String? firstName;
@JsonKey(name: 'middle_name')
final String? middleName;
@JsonKey(name: 'last_name')
final String? lastName;
final String? ip;
final String? zip;
final String? country;
final String? state;
final String? city;
final String? address;
const CustomerDTO({
required this.id,
this.firstName,
this.middleName,
this.lastName,
this.ip,
this.zip,
this.country,
this.state,
this.city,
this.address,
});
factory CustomerDTO.fromJson(Map<String, dynamic> json) => _$CustomerDTOFromJson(json);
Map<String, dynamic> toJson() => _$CustomerDTOToJson(this);
}

View File

@@ -1,6 +1,7 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:pshared/data/dto/payment/endpoint.dart'; import 'package:pshared/data/dto/payment/endpoint.dart';
import 'package:pshared/data/dto/payment/intent/customer.dart';
import 'package:pshared/data/dto/payment/intent/fx.dart'; import 'package:pshared/data/dto/payment/intent/fx.dart';
import 'package:pshared/data/dto/payment/money.dart'; import 'package:pshared/data/dto/payment/money.dart';
@@ -20,6 +21,7 @@ class PaymentIntentDTO {
final String? settlementMode; final String? settlementMode;
final Map<String, String>? attributes; final Map<String, String>? attributes;
final CustomerDTO? customer;
const PaymentIntentDTO({ const PaymentIntentDTO({
this.kind, this.kind,
@@ -29,6 +31,7 @@ class PaymentIntentDTO {
this.fx, this.fx,
this.settlementMode, this.settlementMode,
this.attributes, this.attributes,
this.customer,
}); });
factory PaymentIntentDTO.fromJson(Map<String, dynamic> json) => _$PaymentIntentDTOFromJson(json); factory PaymentIntentDTO.fromJson(Map<String, dynamic> json) => _$PaymentIntentDTOFromJson(json);

View File

@@ -0,0 +1,33 @@
import 'package:pshared/data/dto/payment/intent/customer.dart';
import 'package:pshared/models/payment/customer.dart';
extension CustomerMapper on Customer {
CustomerDTO toDTO() => CustomerDTO(
id: id,
firstName: firstName,
middleName: middleName,
lastName: lastName,
ip: ip,
zip: zip,
country: country,
state: state,
city: city,
address: address,
);
}
extension CustomerDTOMapper on CustomerDTO {
Customer toDomain() => Customer(
id: id,
firstName: firstName,
middleName: middleName,
lastName: lastName,
ip: ip,
zip: zip,
country: country,
state: state,
city: city,
address: address,
);
}

View File

@@ -1,30 +1,34 @@
import 'package:pshared/data/dto/payment/intent/payment.dart'; import 'package:pshared/data/dto/payment/intent/payment.dart';
import 'package:pshared/data/mapper/payment/payment.dart'; import 'package:pshared/data/mapper/payment/payment.dart';
import 'package:pshared/data/mapper/payment/enums.dart'; import 'package:pshared/data/mapper/payment/enums.dart';
import 'package:pshared/data/mapper/payment/intent/customer.dart';
import 'package:pshared/data/mapper/payment/intent/fx.dart'; import 'package:pshared/data/mapper/payment/intent/fx.dart';
import 'package:pshared/data/mapper/payment/money.dart'; import 'package:pshared/data/mapper/payment/money.dart';
import 'package:pshared/models/payment/intent.dart'; import 'package:pshared/models/payment/intent.dart';
extension PaymentIntentMapper on PaymentIntent { extension PaymentIntentMapper on PaymentIntent {
PaymentIntentDTO toDTO() => PaymentIntentDTO( PaymentIntentDTO toDTO() => PaymentIntentDTO(
kind: paymentKindToValue(kind), kind: paymentKindToValue(kind),
source: source?.toDTO(), source: source?.toDTO(),
destination: destination?.toDTO(), destination: destination?.toDTO(),
amount: amount?.toDTO(), amount: amount?.toDTO(),
fx: fx?.toDTO(), fx: fx?.toDTO(),
settlementMode: settlementModeToValue(settlementMode), settlementMode: settlementModeToValue(settlementMode),
attributes: attributes, attributes: attributes,
); customer: customer?.toDTO(),
);
} }
extension PaymentIntentDTOMapper on PaymentIntentDTO { extension PaymentIntentDTOMapper on PaymentIntentDTO {
PaymentIntent toDomain() => PaymentIntent( PaymentIntent toDomain() => PaymentIntent(
kind: paymentKindFromValue(kind), kind: paymentKindFromValue(kind),
source: source?.toDomain(), source: source?.toDomain(),
destination: destination?.toDomain(), destination: destination?.toDomain(),
amount: amount?.toDomain(), amount: amount?.toDomain(),
fx: fx?.toDomain(), fx: fx?.toDomain(),
settlementMode: settlementModeFromValue(settlementMode), settlementMode: settlementModeFromValue(settlementMode),
attributes: attributes, attributes: attributes,
); customer: customer?.toDomain(),
);
} }

View File

@@ -0,0 +1,25 @@
class Customer {
final String id;
final String? firstName;
final String? middleName;
final String? lastName;
final String? ip;
final String? zip;
final String? country;
final String? state;
final String? city;
final String? address;
const Customer({
required this.id,
this.firstName,
this.middleName,
this.lastName,
this.ip,
this.zip,
this.country,
this.state,
this.city,
this.address,
});
}

View File

@@ -1,5 +1,6 @@
import 'package:pshared/models/payment/fx/intent.dart'; import 'package:pshared/models/payment/fx/intent.dart';
import 'package:pshared/models/payment/kind.dart'; import 'package:pshared/models/payment/kind.dart';
import 'package:pshared/models/payment/customer.dart';
import 'package:pshared/models/payment/methods/data.dart'; import 'package:pshared/models/payment/methods/data.dart';
import 'package:pshared/models/payment/money.dart'; import 'package:pshared/models/payment/money.dart';
import 'package:pshared/models/payment/settlement_mode.dart'; import 'package:pshared/models/payment/settlement_mode.dart';
@@ -13,6 +14,7 @@ class PaymentIntent {
final FxIntent? fx; final FxIntent? fx;
final SettlementMode settlementMode; final SettlementMode settlementMode;
final Map<String, String>? attributes; final Map<String, String>? attributes;
final Customer? customer;
const PaymentIntent({ const PaymentIntent({
this.kind = PaymentKind.unspecified, this.kind = PaymentKind.unspecified,
@@ -22,5 +24,6 @@ class PaymentIntent {
this.fx, this.fx,
this.settlementMode = SettlementMode.unspecified, this.settlementMode = SettlementMode.unspecified,
this.attributes, this.attributes,
this.customer,
}); });
} }

View File

@@ -1,23 +1,30 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import 'package:pshared/api/requests/payment/quote.dart'; import 'package:pshared/api/requests/payment/quote.dart';
import 'package:pshared/data/mapper/payment/intent/payment.dart'; import 'package:pshared/data/mapper/payment/intent/payment.dart';
import 'package:pshared/models/asset.dart'; import 'package:pshared/models/asset.dart';
import 'package:pshared/models/payment/currency_pair.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/intent.dart';
import 'package:pshared/models/payment/fx/side.dart'; import 'package:pshared/models/payment/fx/side.dart';
import 'package:pshared/models/payment/kind.dart'; import 'package:pshared/models/payment/kind.dart';
import 'package:pshared/models/payment/methods/managed_wallet.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/money.dart';
import 'package:pshared/models/payment/settlement_mode.dart'; import 'package:pshared/models/payment/settlement_mode.dart';
import 'package:pshared/models/payment/intent.dart'; import 'package:pshared/models/payment/intent.dart';
import 'package:pshared/models/payment/quote.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/organizations.dart';
import 'package:pshared/provider/payment/amount.dart'; import 'package:pshared/provider/payment/amount.dart';
import 'package:pshared/provider/payment/flow.dart'; import 'package:pshared/provider/payment/flow.dart';
import 'package:pshared/provider/payment/wallets.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/provider/resource.dart';
import 'package:pshared/service/payment/quotation.dart'; import 'package:pshared/service/payment/quotation.dart';
import 'package:pshared/utils/currency.dart'; import 'package:pshared/utils/currency.dart';
@@ -33,10 +40,17 @@ class QuotationProvider extends ChangeNotifier {
PaymentAmountProvider payment, PaymentAmountProvider payment,
WalletsProvider wallets, WalletsProvider wallets,
PaymentFlowProvider flow, PaymentFlowProvider flow,
RecipientsProvider recipients,
PaymentMethodsProvider methods,
) { ) {
_organizations = venue; _organizations = venue;
final destination = flow.selectedPaymentData; final t = flow.selectedType;
if ((wallets.selectedWallet != null) && (destination != null)) { 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( getQuotation(PaymentIntent(
kind: PaymentKind.payout, kind: PaymentKind.payout,
amount: Money( amount: Money(
@@ -44,7 +58,7 @@ class QuotationProvider extends ChangeNotifier {
// TODO: adapt to possible other sources // TODO: adapt to possible other sources
currency: currencyCodeToString(wallets.selectedWallet!.currency), currency: currencyCodeToString(wallets.selectedWallet!.currency),
), ),
destination: destination, destination: method.data,
source: ManagedWalletPaymentMethod( source: ManagedWalletPaymentMethod(
managedWalletRef: wallets.selectedWallet!.id, managedWalletRef: wallets.selectedWallet!.id,
), ),
@@ -56,6 +70,7 @@ class QuotationProvider extends ChangeNotifier {
side: FxSide.sellBaseBuyQuote, side: FxSide.sellBaseBuyQuote,
), ),
settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource, settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource,
customer: customer,
)); ));
} }
} }
@@ -68,6 +83,58 @@ class QuotationProvider extends ChangeNotifier {
Asset? get total => quotation == null ? null : createAsset(quotation!.debitAmount!.currency, quotation!.debitAmount!.amount); 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); 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) { void _setResource(Resource<PaymentQuote> quotation) {
_quotation = quotation; _quotation = quotation;
notifyListeners(); notifyListeners();

View File

@@ -105,14 +105,10 @@ void main() async {
ChangeNotifierProvider( ChangeNotifierProvider(
create: (_) => PaymentAmountProvider(), create: (_) => PaymentAmountProvider(),
), ),
ChangeNotifierProxyProvider4<OrganizationsProvider, PaymentAmountProvider, WalletsProvider, PaymentFlowProvider, QuotationProvider>( ChangeNotifierProxyProvider6<OrganizationsProvider, PaymentAmountProvider, WalletsProvider, PaymentFlowProvider, RecipientsProvider, PaymentMethodsProvider, QuotationProvider>(
create: (_) => QuotationProvider(), create: (_) => QuotationProvider(),
update: (context, organization, payment, wallets, flow, provider) => provider!..update( update: (_, organization, payment, wallet, flow, recipients, methods, provider) =>
organization, provider!..update(organization, payment, wallet, flow, recipients, methods),
payment,
wallets,
flow,
),
), ),
ChangeNotifierProxyProvider2<OrganizationsProvider, QuotationProvider, PaymentProvider>( ChangeNotifierProxyProvider2<OrganizationsProvider, QuotationProvider, PaymentProvider>(
create: (_) => PaymentProvider(), create: (_) => PaymentProvider(),