propagated payment commentto bff
This commit is contained in:
@@ -140,6 +140,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
|
||||
}
|
||||
|
||||
@@ -171,6 +172,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
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,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
|
||||
}
|
||||
@@ -182,6 +185,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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1099,6 +1103,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(),
|
||||
@@ -1259,6 +1264,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(),
|
||||
|
||||
@@ -93,6 +93,7 @@ func TestCardPayoutProcessor_Submit_Success(t *testing.T) {
|
||||
|
||||
req := validCardPayoutRequest()
|
||||
req.ProjectId = 0
|
||||
req.Comment = "invoice-2002"
|
||||
|
||||
resp, err := processor.Submit(context.Background(), req)
|
||||
if err != nil {
|
||||
@@ -118,6 +119,12 @@ func TestCardPayoutProcessor_Submit_Success(t *testing.T) {
|
||||
if stored.ProviderPaymentID == "" {
|
||||
t.Fatalf("expected provider payment id")
|
||||
}
|
||||
if got, want := stored.Comment, "invoice-2002"; got != want {
|
||||
t.Fatalf("expected stored comment %q, got %q", want, got)
|
||||
}
|
||||
if got, want := resp.GetPayout().GetComment(), "invoice-2002"; 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)
|
||||
}
|
||||
|
||||
@@ -129,6 +129,7 @@ func connectorOperationParams() []*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
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user