fixed linting config
This commit is contained in:
@@ -43,6 +43,11 @@ type quoteCtx struct {
|
||||
hash string
|
||||
}
|
||||
|
||||
type quotePaymentResult struct {
|
||||
quote *sharedv1.PaymentQuote
|
||||
executionNote string
|
||||
}
|
||||
|
||||
func (h *quotePaymentCommand) Execute(
|
||||
ctx context.Context,
|
||||
req *quotationv1.QuotePaymentRequest,
|
||||
@@ -65,14 +70,15 @@ func (h *quotePaymentCommand) Execute(
|
||||
return gsresponse.Unavailable[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err)
|
||||
}
|
||||
|
||||
quoteProto, err := h.quotePayment(ctx, quotesStore, qc, req)
|
||||
result, err := h.quotePayment(ctx, quotesStore, qc, req)
|
||||
if err != nil {
|
||||
return h.mapQuoteErr(err)
|
||||
}
|
||||
|
||||
return gsresponse.Success("ationv1.QuotePaymentResponse{
|
||||
IdempotencyKey: req.GetIdempotencyKey(),
|
||||
Quote: quoteProto,
|
||||
Quote: result.quote,
|
||||
ExecutionNote: result.executionNote,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -111,7 +117,7 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
quotesStore storage.QuotesStore,
|
||||
qc *quoteCtx,
|
||||
req *quotationv1.QuotePaymentRequest,
|
||||
) (*sharedv1.PaymentQuote, error) {
|
||||
) (*quotePaymentResult, error) {
|
||||
|
||||
if qc.previewOnly {
|
||||
quote, _, err := h.engine.BuildPaymentQuote(ctx, qc.orgID, req)
|
||||
@@ -120,7 +126,7 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
return nil, err
|
||||
}
|
||||
quote.QuoteRef = bson.NewObjectID().Hex()
|
||||
return quote, nil
|
||||
return "ePaymentResult{quote: quote}, nil
|
||||
}
|
||||
|
||||
existing, err := quotesStore.GetByIdempotencyKey(ctx, qc.orgRef, qc.idempotencyKey)
|
||||
@@ -140,7 +146,10 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
zap.String("idempotency_key", qc.idempotencyKey),
|
||||
zap.String("quote_ref", existing.QuoteRef),
|
||||
)
|
||||
return modelQuoteToProto(existing.Quote), nil
|
||||
return "ePaymentResult{
|
||||
quote: modelQuoteToProto(existing.Quote),
|
||||
executionNote: strings.TrimSpace(existing.ExecutionNote),
|
||||
}, nil
|
||||
}
|
||||
|
||||
quote, expiresAt, err := h.engine.BuildPaymentQuote(ctx, qc.orgID, req)
|
||||
@@ -157,17 +166,28 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
quoteRef := bson.NewObjectID().Hex()
|
||||
quote.QuoteRef = quoteRef
|
||||
|
||||
executionNote := ""
|
||||
plan, err := h.engine.BuildPaymentPlan(ctx, qc.orgRef, qc.intent, qc.idempotencyKey, quote)
|
||||
if err != nil {
|
||||
h.logger.Warn(
|
||||
"Failed to build payment plan",
|
||||
zap.Error(err),
|
||||
mzap.ObjRef("org_ref", qc.orgRef),
|
||||
zap.String("idempotency_key", qc.idempotencyKey),
|
||||
)
|
||||
return nil, err
|
||||
if errors.Is(err, merrors.ErrInvalidArg) {
|
||||
executionNote = quoteNonExecutableNote(err)
|
||||
h.logger.Info(
|
||||
"Payment quote marked as non-executable",
|
||||
mzap.ObjRef("org_ref", qc.orgRef),
|
||||
zap.String("idempotency_key", qc.idempotencyKey),
|
||||
zap.String("quote_ref", quoteRef),
|
||||
zap.String("execution_note", executionNote),
|
||||
)
|
||||
} else {
|
||||
h.logger.Warn(
|
||||
"Failed to build payment plan",
|
||||
zap.Error(err),
|
||||
mzap.ObjRef("org_ref", qc.orgRef),
|
||||
zap.String("idempotency_key", qc.idempotencyKey),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
record := &model.PaymentQuoteRecord{
|
||||
QuoteRef: quoteRef,
|
||||
IdempotencyKey: qc.idempotencyKey,
|
||||
@@ -175,6 +195,7 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
Intent: intentFromProto(qc.intent),
|
||||
Quote: quoteSnapshotToModel(quote),
|
||||
Plan: cloneStoredPaymentPlan(plan),
|
||||
ExecutionNote: executionNote,
|
||||
ExpiresAt: expiresAt,
|
||||
}
|
||||
record.SetID(bson.NewObjectID())
|
||||
@@ -187,7 +208,10 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
if existing.Hash != qc.hash {
|
||||
return nil, errIdempotencyParamMismatch
|
||||
}
|
||||
return modelQuoteToProto(existing.Quote), nil
|
||||
return "ePaymentResult{
|
||||
quote: modelQuoteToProto(existing.Quote),
|
||||
executionNote: strings.TrimSpace(existing.ExecutionNote),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
@@ -201,7 +225,10 @@ func (h *quotePaymentCommand) quotePayment(
|
||||
zap.String("kind", qc.intent.GetKind().String()),
|
||||
)
|
||||
|
||||
return quote, nil
|
||||
return "ePaymentResult{
|
||||
quote: quote,
|
||||
executionNote: executionNote,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h *quotePaymentCommand) mapQuoteErr(err error) gsresponse.Responder[quotationv1.QuotePaymentResponse] {
|
||||
@@ -213,6 +240,16 @@ func (h *quotePaymentCommand) mapQuoteErr(err error) gsresponse.Responder[quotat
|
||||
return gsresponse.Auto[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err)
|
||||
}
|
||||
|
||||
func quoteNonExecutableNote(err error) string {
|
||||
reason := strings.TrimSpace(err.Error())
|
||||
reason = strings.TrimPrefix(reason, merrors.ErrInvalidArg.Error()+":")
|
||||
reason = strings.TrimSpace(reason)
|
||||
if reason == "" {
|
||||
return "quote will not be executed"
|
||||
}
|
||||
return "quote will not be executed: " + reason
|
||||
}
|
||||
|
||||
// TODO: temprorarary hashing function, replace with a proper solution later
|
||||
func hashQuoteRequest(req *quotationv1.QuotePaymentRequest) string {
|
||||
cloned := proto.Clone(req).(*quotationv1.QuotePaymentRequest)
|
||||
|
||||
Reference in New Issue
Block a user