fixed rail & operation names
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model/account_role"
|
||||
"github.com/tech/sendico/pkg/payments/rail"
|
||||
@@ -29,9 +30,9 @@ type chainRailGateway struct {
|
||||
|
||||
// NewRailGateway wraps a chain gateway client into a rail gateway adapter.
|
||||
func NewRailGateway(client Client, cfg RailGatewayConfig) rail.RailGateway {
|
||||
railName := strings.ToUpper(strings.TrimSpace(cfg.Rail))
|
||||
railName := discovery.NormalizeRail(cfg.Rail)
|
||||
if railName == "" {
|
||||
railName = "CRYPTO"
|
||||
railName = discovery.RailCrypto
|
||||
}
|
||||
return &chainRailGateway{
|
||||
client: client,
|
||||
|
||||
21
api/gateway/chain/client/rail_gateway_test.go
Normal file
21
api/gateway/chain/client/rail_gateway_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
)
|
||||
|
||||
func TestNewRailGateway_NormalizesRail(t *testing.T) {
|
||||
gw := NewRailGateway(nil, RailGatewayConfig{Rail: "card_payout", Network: "tron"})
|
||||
if got, want := gw.Rail(), discovery.RailCardPayout; got != want {
|
||||
t.Fatalf("unexpected rail: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRailGateway_DefaultsToCryptoRail(t *testing.T) {
|
||||
gw := NewRailGateway(nil, RailGatewayConfig{})
|
||||
if got, want := gw.Rail(), discovery.RailCrypto; got != want {
|
||||
t.Fatalf("unexpected rail: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ gateway:
|
||||
currencies: ["RUB"]
|
||||
limits:
|
||||
per_tx_min_amount: "100.00"
|
||||
per_tx_max_amount: "150000.00"
|
||||
|
||||
http:
|
||||
callback:
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/model/account_role"
|
||||
"github.com/tech/sendico/pkg/payments/rail"
|
||||
@@ -29,9 +30,9 @@ type chainRailGateway struct {
|
||||
|
||||
// NewRailGateway wraps a chain gateway client into a rail gateway adapter.
|
||||
func NewRailGateway(client Client, cfg RailGatewayConfig) rail.RailGateway {
|
||||
railName := strings.ToUpper(strings.TrimSpace(cfg.Rail))
|
||||
railName := discovery.NormalizeRail(cfg.Rail)
|
||||
if railName == "" {
|
||||
railName = "CRYPTO"
|
||||
railName = discovery.RailCrypto
|
||||
}
|
||||
return &chainRailGateway{
|
||||
client: client,
|
||||
|
||||
21
api/gateway/tron/client/rail_gateway_test.go
Normal file
21
api/gateway/tron/client/rail_gateway_test.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tech/sendico/pkg/discovery"
|
||||
)
|
||||
|
||||
func TestNewRailGateway_NormalizesRail(t *testing.T) {
|
||||
gw := NewRailGateway(nil, RailGatewayConfig{Rail: "card_payout", Network: "tron"})
|
||||
if got, want := gw.Rail(), discovery.RailCardPayout; got != want {
|
||||
t.Fatalf("unexpected rail: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRailGateway_DefaultsToCryptoRail(t *testing.T) {
|
||||
gw := NewRailGateway(nil, RailGatewayConfig{})
|
||||
if got, want := gw.Rail(), discovery.RailCrypto; got != want {
|
||||
t.Fatalf("unexpected rail: got=%q want=%q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user