fixed rail & operation names
This commit is contained in:
@@ -98,7 +98,7 @@ func (s *Service) SubmitOperation(ctx context.Context, req *connectorv1.SubmitOp
|
||||
if targetChatID != "" {
|
||||
metadata[metadataTargetChatID] = targetChatID
|
||||
}
|
||||
outgoingLeg := strings.TrimSpace(reader.String("outgoing_leg"))
|
||||
outgoingLeg := normalizeRail(reader.String("outgoing_leg"))
|
||||
if outgoingLeg != "" {
|
||||
metadata[metadataOutgoingLeg] = outgoingLeg
|
||||
}
|
||||
|
||||
@@ -428,9 +428,9 @@ func (s *Service) buildConfirmationRequest(intent *model.PaymentGatewayIntent) (
|
||||
if targetChatID == "" {
|
||||
return nil, merrors.InvalidArgument("target_chat_id is required", "target_chat_id")
|
||||
}
|
||||
rail := strings.TrimSpace(intent.OutgoingLeg)
|
||||
rail := normalizeRail(intent.OutgoingLeg)
|
||||
if rail == "" {
|
||||
rail = s.rail
|
||||
rail = normalizeRail(s.rail)
|
||||
}
|
||||
timeout := s.cfg.TimeoutSeconds
|
||||
if timeout <= 0 {
|
||||
@@ -549,7 +549,7 @@ func normalizeIntent(intent *model.PaymentGatewayIntent) *model.PaymentGatewayIn
|
||||
cp := *intent
|
||||
cp.PaymentIntentID = strings.TrimSpace(cp.PaymentIntentID)
|
||||
cp.IdempotencyKey = strings.TrimSpace(cp.IdempotencyKey)
|
||||
cp.OutgoingLeg = strings.TrimSpace(cp.OutgoingLeg)
|
||||
cp.OutgoingLeg = normalizeRail(cp.OutgoingLeg)
|
||||
cp.QuoteRef = strings.TrimSpace(cp.QuoteRef)
|
||||
if cp.RequestedMoney != nil {
|
||||
cp.RequestedMoney.Amount = strings.TrimSpace(cp.RequestedMoney.Amount)
|
||||
@@ -568,7 +568,7 @@ func paymentRecordFromIntent(intent *model.PaymentGatewayIntent, confirmReq *mod
|
||||
record.IdempotencyKey = strings.TrimSpace(intent.IdempotencyKey)
|
||||
record.PaymentIntentID = strings.TrimSpace(intent.PaymentIntentID)
|
||||
record.QuoteRef = strings.TrimSpace(intent.QuoteRef)
|
||||
record.OutgoingLeg = strings.TrimSpace(intent.OutgoingLeg)
|
||||
record.OutgoingLeg = normalizeRail(intent.OutgoingLeg)
|
||||
record.RequestedMoney = intent.RequestedMoney
|
||||
record.IntentRef = intent.IntentRef
|
||||
record.OperationRef = intent.OperationRef
|
||||
@@ -578,7 +578,7 @@ func paymentRecordFromIntent(intent *model.PaymentGatewayIntent, confirmReq *mod
|
||||
record.IdempotencyKey = strings.TrimSpace(confirmReq.RequestID)
|
||||
record.PaymentIntentID = strings.TrimSpace(confirmReq.PaymentIntentID)
|
||||
record.QuoteRef = strings.TrimSpace(confirmReq.QuoteRef)
|
||||
record.OutgoingLeg = strings.TrimSpace(confirmReq.Rail)
|
||||
record.OutgoingLeg = normalizeRail(confirmReq.Rail)
|
||||
record.RequestedMoney = confirmReq.RequestedMoney
|
||||
record.IntentRef = strings.TrimSpace(confirmReq.IntentRef)
|
||||
record.OperationRef = strings.TrimSpace(confirmReq.OperationRef)
|
||||
@@ -640,9 +640,9 @@ func intentFromSubmitTransfer(req *chainv1.SubmitTransferRequest, defaultRail, d
|
||||
}
|
||||
quoteRef := strings.TrimSpace(metadata[metadataQuoteRef])
|
||||
targetChatID := strings.TrimSpace(metadata[metadataTargetChatID])
|
||||
outgoingLeg := strings.TrimSpace(metadata[metadataOutgoingLeg])
|
||||
outgoingLeg := normalizeRail(metadata[metadataOutgoingLeg])
|
||||
if outgoingLeg == "" {
|
||||
outgoingLeg = strings.TrimSpace(defaultRail)
|
||||
outgoingLeg = normalizeRail(defaultRail)
|
||||
}
|
||||
if targetChatID == "" {
|
||||
targetChatID = strings.TrimSpace(defaultChatID)
|
||||
@@ -659,6 +659,10 @@ func intentFromSubmitTransfer(req *chainv1.SubmitTransferRequest, defaultRail, d
|
||||
}, nil
|
||||
}
|
||||
|
||||
func normalizeRail(value string) string {
|
||||
return discovery.NormalizeRail(value)
|
||||
}
|
||||
|
||||
func transferFromRequest(req *chainv1.SubmitTransferRequest) *chainv1.Transfer {
|
||||
if req == nil {
|
||||
return nil
|
||||
|
||||
@@ -8,12 +8,15 @@ import (
|
||||
|
||||
"github.com/tech/sendico/gateway/tgsettle/storage"
|
||||
storagemodel "github.com/tech/sendico/gateway/tgsettle/storage/model"
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
envelope "github.com/tech/sendico/pkg/messaging/envelope"
|
||||
tnotifications "github.com/tech/sendico/pkg/messaging/notifications/telegram"
|
||||
mloggerfactory "github.com/tech/sendico/pkg/mlogger/factory"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -370,3 +373,22 @@ func TestTimeout(t *testing.T) {
|
||||
t.Fatalf("timeout must not publish reaction")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntentFromSubmitTransfer_NormalizesOutgoingLeg(t *testing.T) {
|
||||
intent, err := intentFromSubmitTransfer(&chainv1.SubmitTransferRequest{
|
||||
IdempotencyKey: "idem-5",
|
||||
IntentRef: "pi-5",
|
||||
OperationRef: "op-5",
|
||||
PaymentRef: "pay-5",
|
||||
Amount: &moneyv1.Money{Amount: "10", Currency: "USD"},
|
||||
Metadata: map[string]string{
|
||||
metadataOutgoingLeg: "card_payout",
|
||||
},
|
||||
}, "provider_settlement", "")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if got, want := intent.OutgoingLeg, discovery.RailCardPayout; got != want {
|
||||
t.Fatalf("unexpected outgoing leg: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user