propagated payment commentto bff

This commit is contained in:
Stephan D
2026-03-12 00:42:49 +01:00
parent 4958bdb500
commit b440df97d5
94 changed files with 626 additions and 119 deletions

View File

@@ -141,6 +141,7 @@ func sanitizeCardPayoutRequest(req *mntxv1.CardPayoutRequest) *mntxv1.CardPayout
r.OperationRef = strings.TrimSpace(r.GetOperationRef())
r.IdempotencyKey = strings.TrimSpace(r.GetIdempotencyKey())
r.IntentRef = strings.TrimSpace(r.GetIntentRef())
r.Comment = strings.TrimSpace(r.GetComment())
return r
}
@@ -172,6 +173,7 @@ func sanitizeCardTokenPayoutRequest(req *mntxv1.CardTokenPayoutRequest) *mntxv1.
r.OperationRef = strings.TrimSpace(r.GetOperationRef())
r.IdempotencyKey = strings.TrimSpace(r.GetIdempotencyKey())
r.IntentRef = strings.TrimSpace(r.GetIntentRef())
r.Comment = strings.TrimSpace(r.GetComment())
return r
}

View File

@@ -87,6 +87,9 @@ func mergePayoutStateWithExisting(state, existing *model.CardPayout) {
if state.IntentRef == "" {
state.IntentRef = existing.IntentRef
}
if state.Comment == "" {
state.Comment = existing.Comment
}
if existing.PaymentRef != "" {
state.PaymentRef = existing.PaymentRef
}
@@ -168,6 +171,7 @@ func payoutStateLogFields(state *model.CardPayout) []zap.Field {
zap.String("operation_ref", state.OperationRef),
zap.String("idempotency_key", state.IdempotencyKey),
zap.String("intent_ref", state.IntentRef),
zap.String("comment", state.Comment),
}
}
@@ -1070,6 +1074,7 @@ func (p *cardPayoutProcessor) Submit(ctx context.Context, req *mntxv1.CardPayout
OperationRef: operationRef,
IdempotencyKey: strings.TrimSpace(req.GetIdempotencyKey()),
IntentRef: strings.TrimSpace(req.GetIntentRef()),
Comment: strings.TrimSpace(req.GetComment()),
ProjectID: projectID,
CustomerID: strings.TrimSpace(req.GetCustomerId()),
AmountMinor: req.GetAmountMinor(),
@@ -1237,6 +1242,7 @@ func (p *cardPayoutProcessor) SubmitToken(ctx context.Context, req *mntxv1.CardT
OperationRef: operationRef,
IdempotencyKey: strings.TrimSpace(req.GetIdempotencyKey()),
IntentRef: strings.TrimSpace(req.GetIntentRef()),
Comment: strings.TrimSpace(req.GetComment()),
ProjectID: projectID,
CustomerID: strings.TrimSpace(req.GetCustomerId()),
AmountMinor: req.GetAmountMinor(),

View File

@@ -80,6 +80,7 @@ func TestCardPayoutProcessor_Submit_Success(t *testing.T) {
req := validCardPayoutRequest()
req.ProjectId = 0
req.Comment = "invoice-1001"
resp, err := processor.Submit(context.Background(), req)
if err != nil {
@@ -105,6 +106,12 @@ func TestCardPayoutProcessor_Submit_Success(t *testing.T) {
if stored.ProviderPaymentID == "" {
t.Fatalf("expected provider payment id")
}
if got, want := stored.Comment, "invoice-1001"; got != want {
t.Fatalf("expected stored comment %q, got %q", want, got)
}
if got, want := resp.GetPayout().GetComment(), "invoice-1001"; got != want {
t.Fatalf("expected response comment %q, got %q", want, got)
}
if !stored.CreatedAt.Equal(existingCreated) {
t.Fatalf("expected created_at preserved in model, got %v", stored.CreatedAt)
}

View File

@@ -129,6 +129,7 @@ func mntxOperationParams() []*connectorv1.OperationParamSpec {
{Key: "amount_minor", Type: connectorv1.ParamType_INT, Required: false},
{Key: "project_id", Type: connectorv1.ParamType_INT, Required: false},
{Key: "parent_payment_ref", Type: connectorv1.ParamType_STRING, Required: true},
{Key: "comment", Type: connectorv1.ParamType_STRING, Required: false},
{Key: "customer_middle_name", Type: connectorv1.ParamType_STRING, Required: false},
{Key: "customer_country", Type: connectorv1.ParamType_STRING, Required: false},
{Key: "customer_state", Type: connectorv1.ParamType_STRING, Required: false},
@@ -188,7 +189,18 @@ func metadataFromReader(reader params.Reader) map[string]string {
if len(metadata) == 0 {
return nil
}
return metadata
out := make(map[string]string, len(metadata))
for key, value := range metadata {
k := strings.TrimSpace(key)
if k == "" || strings.EqualFold(k, "comment") {
continue
}
out[k] = strings.TrimSpace(value)
}
if len(out) == 0 {
return nil
}
return out
}
func buildCardTokenPayoutRequestFromParams(reader params.Reader,
@@ -218,6 +230,7 @@ func buildCardTokenPayoutRequestFromParams(reader params.Reader,
CardToken: strings.TrimSpace(reader.String("card_token")),
CardHolder: strings.TrimSpace(reader.String("card_holder")),
MaskedPan: strings.TrimSpace(reader.String("masked_pan")),
Comment: strings.TrimSpace(reader.String("comment")),
Metadata: metadataFromReader(reader),
OperationRef: operationRef,
IdempotencyKey: strings.TrimSpace(idempotencyKey),
@@ -254,6 +267,7 @@ func buildCardPayoutRequestFromParams(reader params.Reader,
CardExpYear: uint32(readerInt64(reader, "card_exp_year")), //nolint:gosec // values are validated by request validators
CardExpMonth: uint32(readerInt64(reader, "card_exp_month")), //nolint:gosec // values are validated by request validators
CardHolder: strings.TrimSpace(reader.String("card_holder")),
Comment: strings.TrimSpace(reader.String("comment")),
Metadata: metadataFromReader(reader),
OperationRef: operationRef,
IdempotencyKey: strings.TrimSpace(idempotencyKey),
@@ -305,6 +319,9 @@ func payoutToOperation(state *mntxv1.CardPayoutState) *connectorv1.Operation {
params["payment_ref"] = paymentRef
params["parent_payment_ref"] = paymentRef
}
if comment := strings.TrimSpace(state.GetComment()); comment != "" {
params["comment"] = comment
}
if providerCode := strings.TrimSpace(state.GetProviderCode()); providerCode != "" {
params["provider_code"] = providerCode
}

View File

@@ -26,6 +26,7 @@ func CardPayoutStateFromProto(clock clockpkg.Clock, p *mntxv1.CardPayoutState) *
PaymentRef: strings.TrimSpace(p.GetParentPaymentRef()),
OperationRef: p.GetOperationRef(),
IntentRef: p.GetIntentRef(),
Comment: strings.TrimSpace(p.GetComment()),
IdempotencyKey: p.GetIdempotencyKey(),
ProjectID: p.ProjectId,
CustomerID: p.CustomerId,
@@ -52,6 +53,7 @@ func StateToProto(m *model.CardPayout) *mntxv1.CardPayoutState {
ProviderCode: m.ProviderCode,
ProviderMessage: m.ProviderMessage,
ProviderPaymentId: m.ProviderPaymentID,
Comment: strings.TrimSpace(m.Comment),
CreatedAt: timestamppb.New(m.CreatedAt),
UpdatedAt: timestamppb.New(m.UpdatedAt),
}