idempotency key delivery fix
This commit is contained in:
@@ -69,7 +69,10 @@ func (h *quotePaymentCommand) Execute(
|
||||
return h.mapQuoteErr(err)
|
||||
}
|
||||
|
||||
return gsresponse.Success(&orchestratorv1.QuotePaymentResponse{Quote: quoteProto})
|
||||
return gsresponse.Success(&orchestratorv1.QuotePaymentResponse{
|
||||
IdempotencyKey: req.GetIdempotencyKey(),
|
||||
Quote: quoteProto,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *quotePaymentCommand) prepareQuoteCtx(req *orchestratorv1.QuotePaymentRequest) (*quoteCtx, error) {
|
||||
@@ -315,9 +318,10 @@ func (h *quotePaymentsCommand) Execute(
|
||||
)
|
||||
|
||||
return gsresponse.Success(&orchestratorv1.QuotePaymentsResponse{
|
||||
QuoteRef: quoteRef,
|
||||
Aggregate: aggregate,
|
||||
Quotes: quotes,
|
||||
IdempotencyKey: req.GetIdempotencyKey(),
|
||||
QuoteRef: quoteRef,
|
||||
Aggregate: aggregate,
|
||||
Quotes: quotes,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -248,6 +248,7 @@ message QuotePaymentsResponse {
|
||||
string quote_ref = 1;
|
||||
PaymentQuoteAggregate aggregate = 2;
|
||||
repeated PaymentQuote quotes = 3;
|
||||
string idempotency_key = 4;
|
||||
}
|
||||
|
||||
message InitiatePaymentsRequest {
|
||||
|
||||
@@ -35,7 +35,6 @@ type FxQuote struct {
|
||||
}
|
||||
|
||||
type PaymentQuote struct {
|
||||
IdempotencyKey string `json:"idempotencyKey"`
|
||||
QuoteRef string `json:"quoteRef,omitempty"`
|
||||
DebitAmount *model.Money `json:"debitAmount,omitempty"`
|
||||
ExpectedSettlementAmount *model.Money `json:"expectedSettlementAmount,omitempty"`
|
||||
@@ -67,8 +66,9 @@ type Payment struct {
|
||||
}
|
||||
|
||||
type paymentQuoteResponse struct {
|
||||
authResponse `json:",inline"`
|
||||
Quote *PaymentQuote `json:"quote"`
|
||||
authResponse `json:",inline"`
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
Quote *PaymentQuote `json:"quote"`
|
||||
}
|
||||
|
||||
type paymentQuotesResponse struct {
|
||||
@@ -88,10 +88,11 @@ type paymentResponse struct {
|
||||
}
|
||||
|
||||
// PaymentQuote wraps a payment quote with refreshed access token.
|
||||
func PaymentQuoteResponse(logger mlogger.Logger, quote *orchestratorv1.PaymentQuote, token *TokenData) http.HandlerFunc {
|
||||
func PaymentQuoteResponse(logger mlogger.Logger, idempotencyKey string, quote *orchestratorv1.PaymentQuote, token *TokenData) http.HandlerFunc {
|
||||
return response.Ok(logger, paymentQuoteResponse{
|
||||
Quote: toPaymentQuote(quote),
|
||||
authResponse: authResponse{AccessToken: *token},
|
||||
Quote: toPaymentQuote(quote),
|
||||
IdempotencyKey: idempotencyKey,
|
||||
authResponse: authResponse{AccessToken: *token},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -216,9 +217,10 @@ func toPaymentQuotes(resp *orchestratorv1.QuotePaymentsResponse) *PaymentQuotes
|
||||
quotes = nil
|
||||
}
|
||||
return &PaymentQuotes{
|
||||
QuoteRef: resp.GetQuoteRef(),
|
||||
Aggregate: toPaymentQuoteAggregate(resp.GetAggregate()),
|
||||
Quotes: quotes,
|
||||
IdempotencyKey: resp.GetIdempotencyKey(),
|
||||
QuoteRef: resp.GetQuoteRef(),
|
||||
Aggregate: toPaymentQuoteAggregate(resp.GetAggregate()),
|
||||
Quotes: quotes,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ func (a *PaymentAPI) quotePayment(r *http.Request, account *model.Account, token
|
||||
return response.Auto(a.logger, a.Name(), err)
|
||||
}
|
||||
|
||||
return sresponse.PaymentQuoteResponse(a.logger, resp.GetQuote(), token)
|
||||
return sresponse.PaymentQuoteResponse(a.logger, resp.GetIdempotencyKey(), resp.GetQuote(), token)
|
||||
}
|
||||
|
||||
func (a *PaymentAPI) quotePayments(r *http.Request, account *model.Account, token *sresponse.TokenData) http.HandlerFunc {
|
||||
|
||||
@@ -11,8 +11,9 @@ part 'quotation.g.dart';
|
||||
class PaymentQuoteResponse extends BaseAuthorizedResponse {
|
||||
|
||||
final PaymentQuoteDTO quote;
|
||||
final String idempotencyKey;
|
||||
|
||||
const PaymentQuoteResponse({required super.accessToken, required this.quote});
|
||||
const PaymentQuoteResponse({required super.accessToken, required this.idempotencyKey, required this.quote});
|
||||
|
||||
factory PaymentQuoteResponse.fromJson(Map<String, dynamic> json) => _$PaymentQuoteResponseFromJson(json);
|
||||
@override
|
||||
|
||||
@@ -9,6 +9,7 @@ part 'quotes.g.dart';
|
||||
@JsonSerializable()
|
||||
class PaymentQuotesDTO {
|
||||
final String quoteRef;
|
||||
final String idempotencyKey;
|
||||
final PaymentQuoteAggregateDTO? aggregate;
|
||||
final List<PaymentQuoteDTO>? quotes;
|
||||
|
||||
@@ -16,6 +17,7 @@ class PaymentQuotesDTO {
|
||||
required this.quoteRef,
|
||||
this.aggregate,
|
||||
this.quotes,
|
||||
required this.idempotencyKey,
|
||||
});
|
||||
|
||||
factory PaymentQuotesDTO.fromJson(Map<String, dynamic> json) => _$PaymentQuotesDTOFromJson(json);
|
||||
|
||||
@@ -9,11 +9,13 @@ extension PaymentQuotesDTOMapper on PaymentQuotesDTO {
|
||||
quoteRef: quoteRef,
|
||||
aggregate: aggregate?.toDomain(),
|
||||
quotes: quotes?.map((quote) => quote.toDomain()).toList(),
|
||||
idempotencyKey: idempotencyKey
|
||||
);
|
||||
}
|
||||
|
||||
extension PaymentQuotesMapper on PaymentQuotes {
|
||||
PaymentQuotesDTO toDTO() => PaymentQuotesDTO(
|
||||
idempotencyKey: idempotencyKey,
|
||||
quoteRef: quoteRef,
|
||||
aggregate: aggregate?.toDTO(),
|
||||
quotes: quotes?.map((quote) => quote.toDTO()).toList(),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:pshared/api/responses/payment/quotation.dart';
|
||||
import 'package:pshared/models/payment/fees/line.dart';
|
||||
import 'package:pshared/models/payment/fx/quote.dart';
|
||||
import 'package:pshared/models/payment/money.dart';
|
||||
@@ -23,3 +24,29 @@ class PaymentQuote {
|
||||
required this.fxQuote,
|
||||
});
|
||||
}
|
||||
|
||||
class PaymentQuoteX extends PaymentQuote {
|
||||
final String idempotencyKey;
|
||||
|
||||
const PaymentQuoteX({
|
||||
required super.quoteRef,
|
||||
required super.debitAmount,
|
||||
required super.expectedSettlementAmount,
|
||||
required super.expectedFeeTotal,
|
||||
required super.feeLines,
|
||||
required super.networkFee,
|
||||
required super.fxQuote,
|
||||
required this.idempotencyKey,
|
||||
});
|
||||
|
||||
factory PaymentQuoteX.build({required PaymentQuote quote, required String idempotencyKey}) => PaymentQuoteX(
|
||||
quoteRef: quote.quoteRef,
|
||||
debitAmount: quote.debitAmount,
|
||||
expectedSettlementAmount: quote.expectedSettlementAmount,
|
||||
expectedFeeTotal: quote.expectedFeeTotal,
|
||||
feeLines: quote.feeLines,
|
||||
networkFee: quote.networkFee,
|
||||
fxQuote: quote.fxQuote,
|
||||
idempotencyKey: idempotencyKey,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:pshared/models/payment/quote_aggregate.dart';
|
||||
|
||||
class PaymentQuotes {
|
||||
final String quoteRef;
|
||||
final String idempotencyKey;
|
||||
final PaymentQuoteAggregate? aggregate;
|
||||
final List<PaymentQuote>? quotes;
|
||||
|
||||
@@ -11,5 +12,6 @@ class PaymentQuotes {
|
||||
required this.quoteRef,
|
||||
required this.aggregate,
|
||||
required this.quotes,
|
||||
required this.idempotencyKey,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/service/payment/quotation.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/utils/exception.dart';
|
||||
|
||||
|
||||
class QuotationProvider extends ChangeNotifier {
|
||||
Resource<PaymentQuote> _quotation = Resource(data: null, isLoading: false, error: null);
|
||||
Resource<PaymentQuoteX> _quotation = Resource(data: null, isLoading: false, error: null);
|
||||
late OrganizationsProvider _organizations;
|
||||
bool _isLoaded = false;
|
||||
|
||||
@@ -162,7 +163,7 @@ class QuotationProvider extends ChangeNotifier {
|
||||
return recipientName?.isNotEmpty == true ? recipientName : null;
|
||||
}
|
||||
|
||||
void _setResource(Resource<PaymentQuote> quotation) {
|
||||
void _setResource(Resource<PaymentQuoteX> quotation) {
|
||||
_quotation = quotation;
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -181,11 +182,7 @@ class QuotationProvider extends ChangeNotifier {
|
||||
_isLoaded = true;
|
||||
_setResource(_quotation.copyWith(data: response, isLoading: false, error: null));
|
||||
} catch (e) {
|
||||
_setResource(_quotation.copyWith(
|
||||
data: null,
|
||||
error: e is Exception ? e : Exception(e.toString()),
|
||||
isLoading: false,
|
||||
));
|
||||
_setResource(_quotation.copyWith(data: null, error: toException(e), isLoading: false));
|
||||
}
|
||||
notifyListeners();
|
||||
return _quotation.data;
|
||||
|
||||
@@ -16,14 +16,15 @@ 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<PaymentQuoteX> getQuotation(String organizationRef, QuotePaymentRequest request) async {
|
||||
_logger.fine('Quoting payment for organization $organizationRef');
|
||||
final response = await AuthorizationService.getPOSTResponse(
|
||||
_objectType,
|
||||
'/quote/$organizationRef',
|
||||
request.toJson(),
|
||||
);
|
||||
return PaymentQuoteResponse.fromJson(response).quote.toDomain();
|
||||
final resp = PaymentQuoteResponse.fromJson(response);
|
||||
return PaymentQuoteX.build(quote: resp.quote.toDomain(), idempotencyKey: resp.idempotencyKey);
|
||||
}
|
||||
|
||||
static Future<PaymentQuotes> getMultiQuotation(String organizationRef, QuotePaymentsRequest request) async {
|
||||
|
||||
Reference in New Issue
Block a user