multiquote service
This commit is contained in:
25
frontend/pshared/lib/api/requests/payment/quotes.dart
Normal file
25
frontend/pshared/lib/api/requests/payment/quotes.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:pshared/api/requests/payment/base.dart';
|
||||
import 'package:pshared/data/dto/payment/intent/payment.dart';
|
||||
|
||||
part 'quotes.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class QuotePaymentsRequest extends PaymentBaseRequest {
|
||||
final List<PaymentIntentDTO> intents;
|
||||
|
||||
@JsonKey(defaultValue: false)
|
||||
final bool previewOnly;
|
||||
|
||||
const QuotePaymentsRequest({
|
||||
required super.idempotencyKey,
|
||||
super.metadata,
|
||||
required this.intents,
|
||||
this.previewOnly = false,
|
||||
});
|
||||
|
||||
factory QuotePaymentsRequest.fromJson(Map<String, dynamic> json) => _$QuotePaymentsRequestFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$QuotePaymentsRequestToJson(this);
|
||||
}
|
||||
20
frontend/pshared/lib/api/responses/payment/quotes.dart
Normal file
20
frontend/pshared/lib/api/responses/payment/quotes.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/api/responses/base.dart';
|
||||
import 'package:pshared/api/responses/token.dart';
|
||||
import 'package:pshared/data/dto/payment/quotes.dart';
|
||||
|
||||
part 'quotes.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class PaymentQuotesResponse extends BaseAuthorizedResponse {
|
||||
|
||||
final PaymentQuotesDTO quote;
|
||||
|
||||
const PaymentQuotesResponse({required super.accessToken, required this.quote});
|
||||
|
||||
factory PaymentQuotesResponse.fromJson(Map<String, dynamic> json) => _$PaymentQuotesResponseFromJson(json);
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$PaymentQuotesResponseToJson(this);
|
||||
}
|
||||
24
frontend/pshared/lib/data/dto/payment/quote_aggregate.dart
Normal file
24
frontend/pshared/lib/data/dto/payment/quote_aggregate.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/payment/money.dart';
|
||||
|
||||
part 'quote_aggregate.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class PaymentQuoteAggregateDTO {
|
||||
final List<MoneyDTO>? debitAmounts;
|
||||
final List<MoneyDTO>? expectedSettlementAmounts;
|
||||
final List<MoneyDTO>? expectedFeeTotals;
|
||||
final List<MoneyDTO>? networkFeeTotals;
|
||||
|
||||
const PaymentQuoteAggregateDTO({
|
||||
this.debitAmounts,
|
||||
this.expectedSettlementAmounts,
|
||||
this.expectedFeeTotals,
|
||||
this.networkFeeTotals,
|
||||
});
|
||||
|
||||
factory PaymentQuoteAggregateDTO.fromJson(Map<String, dynamic> json) => _$PaymentQuoteAggregateDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PaymentQuoteAggregateDTOToJson(this);
|
||||
}
|
||||
23
frontend/pshared/lib/data/dto/payment/quotes.dart
Normal file
23
frontend/pshared/lib/data/dto/payment/quotes.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/payment/quote_aggregate.dart';
|
||||
import 'package:pshared/data/dto/payment/payment_quote.dart';
|
||||
|
||||
part 'quotes.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class PaymentQuotesDTO {
|
||||
final String quoteRef;
|
||||
final PaymentQuoteAggregateDTO? aggregate;
|
||||
final List<PaymentQuoteDTO>? quotes;
|
||||
|
||||
const PaymentQuotesDTO({
|
||||
required this.quoteRef,
|
||||
this.aggregate,
|
||||
this.quotes,
|
||||
});
|
||||
|
||||
factory PaymentQuotesDTO.fromJson(Map<String, dynamic> json) => _$PaymentQuotesDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PaymentQuotesDTOToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:pshared/data/dto/payment/quote_aggregate.dart';
|
||||
import 'package:pshared/data/mapper/payment/money.dart';
|
||||
import 'package:pshared/models/payment/quote_aggregate.dart';
|
||||
|
||||
|
||||
extension PaymentQuoteAggregateDTOMapper on PaymentQuoteAggregateDTO {
|
||||
PaymentQuoteAggregate toDomain() => PaymentQuoteAggregate(
|
||||
debitAmounts: debitAmounts?.map((amount) => amount.toDomain()).toList(),
|
||||
expectedSettlementAmounts: expectedSettlementAmounts?.map((amount) => amount.toDomain()).toList(),
|
||||
expectedFeeTotals: expectedFeeTotals?.map((amount) => amount.toDomain()).toList(),
|
||||
networkFeeTotals: networkFeeTotals?.map((amount) => amount.toDomain()).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentQuoteAggregateMapper on PaymentQuoteAggregate {
|
||||
PaymentQuoteAggregateDTO toDTO() => PaymentQuoteAggregateDTO(
|
||||
debitAmounts: debitAmounts?.map((amount) => amount.toDTO()).toList(),
|
||||
expectedSettlementAmounts: expectedSettlementAmounts?.map((amount) => amount.toDTO()).toList(),
|
||||
expectedFeeTotals: expectedFeeTotals?.map((amount) => amount.toDTO()).toList(),
|
||||
networkFeeTotals: networkFeeTotals?.map((amount) => amount.toDTO()).toList(),
|
||||
);
|
||||
}
|
||||
21
frontend/pshared/lib/data/mapper/payment/quotes.dart
Normal file
21
frontend/pshared/lib/data/mapper/payment/quotes.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:pshared/data/dto/payment/quotes.dart';
|
||||
import 'package:pshared/data/mapper/payment/payment_quote.dart';
|
||||
import 'package:pshared/data/mapper/payment/quote_aggregate.dart';
|
||||
import 'package:pshared/models/payment/quotes.dart';
|
||||
|
||||
|
||||
extension PaymentQuotesDTOMapper on PaymentQuotesDTO {
|
||||
PaymentQuotes toDomain() => PaymentQuotes(
|
||||
quoteRef: quoteRef,
|
||||
aggregate: aggregate?.toDomain(),
|
||||
quotes: quotes?.map((quote) => quote.toDomain()).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentQuotesMapper on PaymentQuotes {
|
||||
PaymentQuotesDTO toDTO() => PaymentQuotesDTO(
|
||||
quoteRef: quoteRef,
|
||||
aggregate: aggregate?.toDTO(),
|
||||
quotes: quotes?.map((quote) => quote.toDTO()).toList(),
|
||||
);
|
||||
}
|
||||
16
frontend/pshared/lib/models/payment/quote_aggregate.dart
Normal file
16
frontend/pshared/lib/models/payment/quote_aggregate.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:pshared/models/payment/money.dart';
|
||||
|
||||
|
||||
class PaymentQuoteAggregate {
|
||||
final List<Money>? debitAmounts;
|
||||
final List<Money>? expectedSettlementAmounts;
|
||||
final List<Money>? expectedFeeTotals;
|
||||
final List<Money>? networkFeeTotals;
|
||||
|
||||
const PaymentQuoteAggregate({
|
||||
required this.debitAmounts,
|
||||
required this.expectedSettlementAmounts,
|
||||
required this.expectedFeeTotals,
|
||||
required this.networkFeeTotals,
|
||||
});
|
||||
}
|
||||
15
frontend/pshared/lib/models/payment/quotes.dart
Normal file
15
frontend/pshared/lib/models/payment/quotes.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:pshared/models/payment/quote.dart';
|
||||
import 'package:pshared/models/payment/quote_aggregate.dart';
|
||||
|
||||
|
||||
class PaymentQuotes {
|
||||
final String quoteRef;
|
||||
final PaymentQuoteAggregate? aggregate;
|
||||
final List<PaymentQuote>? quotes;
|
||||
|
||||
const PaymentQuotes({
|
||||
required this.quoteRef,
|
||||
required this.aggregate,
|
||||
required this.quotes,
|
||||
});
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:pshared/api/requests/payment/quote.dart';
|
||||
import 'package:pshared/api/requests/payment/quotes.dart';
|
||||
import 'package:pshared/api/responses/payment/quotation.dart';
|
||||
import 'package:pshared/api/responses/payment/quotes.dart';
|
||||
import 'package:pshared/data/mapper/payment/payment_quote.dart';
|
||||
import 'package:pshared/data/mapper/payment/quotes.dart';
|
||||
import 'package:pshared/models/payment/quote.dart';
|
||||
import 'package:pshared/models/payment/quotes.dart';
|
||||
import 'package:pshared/service/authorization/service.dart';
|
||||
import 'package:pshared/service/services.dart';
|
||||
|
||||
@@ -21,4 +25,14 @@ class QuotationService {
|
||||
);
|
||||
return PaymentQuoteResponse.fromJson(response).quote.toDomain();
|
||||
}
|
||||
|
||||
static Future<PaymentQuotes> getMultipleQuotation(String organizationRef, QuotePaymentsRequest request) async {
|
||||
_logger.fine('Quoting payments for organization $organizationRef');
|
||||
final response = await AuthorizationService.getPOSTResponse(
|
||||
_objectType,
|
||||
'/quote-multiple/$organizationRef',
|
||||
request.toJson(),
|
||||
);
|
||||
return PaymentQuotesResponse.fromJson(response).quote.toDomain();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user