small fixes for single payout and big chunck for multiple payouts

This commit is contained in:
Arseni
2026-02-05 21:58:37 +03:00
parent 8034847e46
commit b9748b8ab2
37 changed files with 1708 additions and 224 deletions

View File

@@ -0,0 +1,60 @@
import 'package:logging/logging.dart';
import 'package:uuid/uuid.dart';
import 'package:pshared/api/requests/payment/initiate_payments.dart';
import 'package:pshared/api/requests/payment/quotes.dart';
import 'package:pshared/api/responses/payment/payments.dart';
import 'package:pshared/api/responses/payment/quotes.dart';
import 'package:pshared/data/mapper/payment/payment_response.dart';
import 'package:pshared/data/mapper/payment/quote/quotes.dart';
import 'package:pshared/models/payment/payment.dart';
import 'package:pshared/models/payment/quote/quotes.dart';
import 'package:pshared/service/authorization/service.dart';
import 'package:pshared/service/services.dart';
class MultiplePaymentsService {
static final _logger = Logger('service.payment.multiple');
static const String _objectType = Services.payments;
static Future<PaymentQuotes> getQuotation(
String organizationRef,
QuotePaymentsRequest request,
) async {
_logger.fine('Quoting multiple payments for organization $organizationRef');
final response = await AuthorizationService.getPOSTResponse(
_objectType,
'/multiquote/$organizationRef',
request.toJson(),
);
final parsed = PaymentQuotesResponse.fromJson(response);
return parsed.quote.toDomain();
}
static Future<List<Payment>> payByQuote(
String organizationRef,
String quoteRef, {
String? idempotencyKey,
Map<String, String>? metadata,
}) async {
_logger.fine(
'Executing multiple payments for quote $quoteRef in $organizationRef',
);
final request = InitiatePaymentsRequest(
idempotencyKey: idempotencyKey ?? const Uuid().v4(),
quoteRef: quoteRef,
metadata: metadata,
);
final response = await AuthorizationService.getPOSTResponse(
_objectType,
'/by-multiquote/$organizationRef',
request.toJson(),
);
final parsed = PaymentsResponse.fromJson(response);
return parsed.payments.map((payment) => payment.toDomain()).toList();
}
}

View File

@@ -16,18 +16,24 @@ class QuotationService {
static final _logger = Logger('service.payment.quotation');
static const String _objectType = Services.payments;
static Future<PaymentQuote> getQuotation(String organizationRef, QuotePaymentRequest request) async {
static Future<PaymentQuote> getQuotation(
String organizationRef,
QuotePaymentRequest request,
) async {
_logger.fine('Quoting payment for organization $organizationRef');
final response = await AuthorizationService.getPOSTResponse(
_objectType,
'/quote/$organizationRef',
_objectType,
'/quote/$organizationRef',
request.toJson(),
);
final parsed = PaymentQuoteResponse.fromJson(response);
return parsed.quote.toDomain(idempotencyKey: parsed.idempotencyKey);
}
static Future<PaymentQuotes> getMultiQuotation(String organizationRef, QuotePaymentsRequest request) async {
static Future<PaymentQuotes> getMultiQuotation(
String organizationRef,
QuotePaymentsRequest request,
) async {
_logger.fine('Quoting payments for organization $organizationRef');
final response = await AuthorizationService.getPOSTResponse(
_objectType,
@@ -35,7 +41,6 @@ class QuotationService {
request.toJson(),
);
final parsed = PaymentQuotesResponse.fromJson(response);
final idempotencyKey = response['idempotencyKey'] as String?;
return parsed.quote.toDomain(idempotencyKey: idempotencyKey);
return parsed.quote.toDomain();
}
}