updated document upload according to fresh api
This commit is contained in:
@@ -10,18 +10,18 @@ import 'package:pweb/utils/error/snackbar.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
Future<void> downloadPaymentAct(
|
||||
BuildContext context,
|
||||
String paymentRef, {
|
||||
String? operationRef,
|
||||
BuildContext context, {
|
||||
required String gatewayService,
|
||||
required String operationRef,
|
||||
}) async {
|
||||
final organizations = context.read<OrganizationsProvider>();
|
||||
if (!organizations.isOrganizationSet) {
|
||||
return;
|
||||
}
|
||||
final trimmed = paymentRef.trim();
|
||||
if (trimmed.isEmpty) {
|
||||
final gateway = gatewayService.trim();
|
||||
final operation = operationRef.trim();
|
||||
if (gateway.isEmpty || operation.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ Future<void> downloadPaymentAct(
|
||||
await executeActionWithNotification(
|
||||
context: context,
|
||||
action: () async {
|
||||
final file = await PaymentDocumentsService.getAct(
|
||||
final file = await PaymentDocumentsService.getOperationDocument(
|
||||
organizations.current.id,
|
||||
trimmed,
|
||||
operationRef: operationRef,
|
||||
gateway,
|
||||
operation,
|
||||
);
|
||||
await downloadFile(file);
|
||||
},
|
||||
|
||||
@@ -4,6 +4,9 @@ import 'package:pshared/models/payment/state.dart';
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/models/report/operation/document.dart';
|
||||
import 'package:pweb/utils/payment/operation_code.dart';
|
||||
|
||||
|
||||
OperationItem mapPaymentToOperation(Payment payment) {
|
||||
final debit = payment.lastQuote?.amounts?.sourceDebitTotal;
|
||||
@@ -33,6 +36,7 @@ OperationItem mapPaymentToOperation(Payment payment) {
|
||||
payment.state,
|
||||
]) ??
|
||||
'';
|
||||
final operationDocument = _resolveOperationDocument(payment);
|
||||
|
||||
return OperationItem(
|
||||
status: statusFromPayment(payment),
|
||||
@@ -43,6 +47,8 @@ OperationItem mapPaymentToOperation(Payment payment) {
|
||||
toCurrency: toCurrency,
|
||||
payId: payId,
|
||||
paymentRef: payment.paymentRef,
|
||||
operationRef: operationDocument?.operationRef,
|
||||
gatewayService: operationDocument?.gatewayService,
|
||||
cardNumber: null,
|
||||
name: name,
|
||||
date: resolvePaymentDate(payment),
|
||||
@@ -50,6 +56,25 @@ OperationItem mapPaymentToOperation(Payment payment) {
|
||||
);
|
||||
}
|
||||
|
||||
OperationDocumentInfo? _resolveOperationDocument(Payment payment) {
|
||||
for (final operation in payment.operations) {
|
||||
final operationRef = operation.operationRef;
|
||||
final gatewayService = operation.gateway;
|
||||
if (operationRef == null || operationRef.isEmpty) continue;
|
||||
if (gatewayService == null || gatewayService.isEmpty) continue;
|
||||
|
||||
final pair = parseOperationCodePair(operation.code);
|
||||
if (pair == null) continue;
|
||||
if (pair.operation != 'card_payout' || pair.action != 'send') continue;
|
||||
|
||||
return OperationDocumentInfo(
|
||||
operationRef: operationRef,
|
||||
gatewayService: gatewayService,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
OperationStatus statusFromPayment(Payment payment) {
|
||||
switch (payment.orchestrationState) {
|
||||
case PaymentOrchestrationState.failed:
|
||||
@@ -108,4 +133,4 @@ String? _firstNonEmpty(List<String?> values) {
|
||||
if (trimmed != null && trimmed.isNotEmpty) return trimmed;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user