fixed doc env vars + mongo v2 migration

This commit is contained in:
Stephan D
2026-01-31 00:26:42 +01:00
parent cbb7bd8ba6
commit 1aa7e287fb
356 changed files with 1705 additions and 1729 deletions

View File

@@ -24,7 +24,7 @@ require (
github.com/tech/sendico/pkg v0.1.0
github.com/testcontainers/testcontainers-go v0.33.0
github.com/testcontainers/testcontainers-go/modules/mongodb v0.33.0
go.mongodb.org/mongo-driver v1.17.8
go.mongodb.org/mongo-driver/v2 v2.5.0
go.uber.org/zap v1.27.1
google.golang.org/grpc v1.78.0
google.golang.org/protobuf v1.36.11
@@ -39,7 +39,7 @@ require (
github.com/bmatcuk/doublestar/v4 v4.10.0 // indirect
github.com/casbin/casbin/v2 v2.135.0 // indirect
github.com/casbin/govaluate v1.10.0 // indirect
github.com/casbin/mongodb-adapter/v3 v3.7.0 // indirect
github.com/casbin/mongodb-adapter/v4 v4.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
@@ -55,7 +55,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.18.3 // indirect
github.com/lufia/plan9stats v0.0.0-20250827001030-24949be3fa54 // indirect

View File

@@ -16,8 +16,8 @@ github.com/casbin/casbin/v2 v2.135.0/go.mod h1:FmcfntdXLTcYXv/hxgNntcRPqAbwOG9xs
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
github.com/casbin/govaluate v1.10.0 h1:ffGw51/hYH3w3rZcxO/KcaUIDOLP84w7nsidMVgaDG0=
github.com/casbin/govaluate v1.10.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
github.com/casbin/mongodb-adapter/v3 v3.7.0 h1:w9c3bea1BGK4eZTAmk17JkY52yv/xSZDSHKji8q+z6E=
github.com/casbin/mongodb-adapter/v3 v3.7.0/go.mod h1:F1mu4ojoJVE/8VhIMxMedhjfwRDdIXgANYs6Sd0MgVA=
github.com/casbin/mongodb-adapter/v4 v4.3.0 h1:yYXky9v1by6vj/0QK7OyHyd/xpz4vzh0lCi7JKrS4qQ=
github.com/casbin/mongodb-adapter/v4 v4.3.0/go.mod h1:bOTSYZUjX7I9E0ExEvgq46m3mcDNRII7g8iWjrM1BHE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -171,6 +171,8 @@ github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.mongodb.org/mongo-driver v1.17.8 h1:BDP3+U3Y8K0vTrpqDJIRaXNhb/bKyoVeg6tIJsW5EhM=
go.mongodb.org/mongo-driver v1.17.8/go.mod h1:LlOhpH5NUEfhxcAwG0UEkMqwYcc4JU18gtCdGudk/tQ=
go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE=
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s=

View File

@@ -14,7 +14,7 @@ import (
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -87,7 +87,7 @@ func TestSubmitCardFundingTransfers_PlansTopUpAndFunding(t *testing.T) {
payment := &model.Payment{
PaymentRef: "pay-1",
IdempotencyKey: "pay-1",
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()},
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,
Source: model.PaymentEndpoint{
@@ -249,7 +249,7 @@ func TestSubmitCardPayout_UsesSettlementAmount(t *testing.T) {
payment := &model.Payment{
PaymentRef: "pay-2",
IdempotencyKey: "pay-2",
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()},
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,
Source: model.PaymentEndpoint{
@@ -338,7 +338,7 @@ func TestSubmitCardFundingTransfers_RequiresFeeWalletRef(t *testing.T) {
payment := &model.Payment{
PaymentRef: "pay-3",
IdempotencyKey: "pay-3",
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()},
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,
Source: model.PaymentEndpoint{

View File

@@ -17,7 +17,7 @@ import (
"github.com/tech/sendico/pkg/mservice"
"github.com/tech/sendico/pkg/mutil/mzap"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
)
@@ -35,7 +35,7 @@ var (
type quoteCtx struct {
orgID string
orgRef primitive.ObjectID
orgRef bson.ObjectID
intent *orchestratorv1.PaymentIntent
previewOnly bool
idempotencyKey string
@@ -118,7 +118,7 @@ func (h *quotePaymentCommand) quotePayment(
h.logger.Warn("Failed to build preview payment quote", zap.Error(err), zap.String("org_ref", qc.orgID))
return nil, err
}
quote.QuoteRef = primitive.NewObjectID().Hex()
quote.QuoteRef = bson.NewObjectID().Hex()
return quote, nil
}
@@ -153,7 +153,7 @@ func (h *quotePaymentCommand) quotePayment(
return nil, err
}
quoteRef := primitive.NewObjectID().Hex()
quoteRef := bson.NewObjectID().Hex()
quote.QuoteRef = quoteRef
record := &model.PaymentQuoteRecord{
@@ -164,7 +164,7 @@ func (h *quotePaymentCommand) quotePayment(
Quote: quoteSnapshotToModel(quote),
ExpiresAt: expiresAt,
}
record.SetID(primitive.NewObjectID())
record.SetID(bson.NewObjectID())
record.SetOrganizationRef(qc.orgRef)
if err := quotesStore.Create(ctx, record); err != nil {
@@ -231,7 +231,7 @@ var (
type quotePaymentsCtx struct {
orgID string
orgRef primitive.ObjectID
orgRef bson.ObjectID
previewOnly bool
idempotencyKey string
hash string
@@ -293,7 +293,7 @@ func (h *quotePaymentsCommand) Execute(
return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err)
}
quoteRef := primitive.NewObjectID().Hex()
quoteRef := bson.NewObjectID().Hex()
for _, q := range quotes {
if q != nil {
q.QuoteRef = quoteRef
@@ -466,7 +466,7 @@ func (h *quotePaymentsCommand) storeBatch(
Quotes: quoteSnapshotsFromProto(quotes),
ExpiresAt: expiresAt,
}
record.SetID(primitive.NewObjectID())
record.SetID(bson.NewObjectID())
record.SetOrganizationRef(qc.orgRef)
if err := quotesStore.Create(ctx, record); err != nil {

View File

@@ -16,7 +16,7 @@ import (
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"
)
@@ -102,7 +102,7 @@ func TestExecutePaymentPlan_SourceBeforeDestination(t *testing.T) {
PaymentRef: "pay-plan-1",
IdempotencyKey: "pay-plan-1",
OrganizationBoundBase: mo.OrganizationBoundBase{
OrganizationRef: primitive.NewObjectID(),
OrganizationRef: bson.NewObjectID(),
},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,
@@ -239,7 +239,7 @@ func TestExecutePaymentPlan_RejectsLegacyLedgerOperations(t *testing.T) {
PaymentRef: "pay-legacy-1",
IdempotencyKey: "pay-legacy-1",
OrganizationBoundBase: mo.OrganizationBoundBase{
OrganizationRef: primitive.NewObjectID(),
OrganizationRef: bson.NewObjectID(),
},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,

View File

@@ -14,7 +14,7 @@ import (
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -84,7 +84,7 @@ func (p *paymentExecutor) postLedgerMove(ctx context.Context, payment *model.Pay
if payment == nil {
return "", merrors.InvalidArgument("ledger: payment is required")
}
if payment.OrganizationRef == primitive.NilObjectID {
if payment.OrganizationRef == bson.NilObjectID {
return "", merrors.InvalidArgument("ledger: organization_ref is required")
}
if step == nil {
@@ -156,7 +156,7 @@ func (p *paymentExecutor) postLedgerBlock(ctx context.Context, payment *model.Pa
if payment == nil {
return "", merrors.InvalidArgument("ledger: payment is required")
}
if payment.OrganizationRef == primitive.NilObjectID {
if payment.OrganizationRef == bson.NilObjectID {
return "", merrors.InvalidArgument("ledger: organization_ref is required")
}
if amount == nil || strings.TrimSpace(amount.GetAmount()) == "" || strings.TrimSpace(amount.GetCurrency()) == "" {
@@ -214,7 +214,7 @@ func (p *paymentExecutor) postLedgerRelease(ctx context.Context, payment *model.
if payment == nil {
return "", merrors.InvalidArgument("ledger: payment is required")
}
if payment.OrganizationRef == primitive.NilObjectID {
if payment.OrganizationRef == bson.NilObjectID {
return "", merrors.InvalidArgument("ledger: organization_ref is required")
}
if amount == nil || strings.TrimSpace(amount.GetAmount()) == "" || strings.TrimSpace(amount.GetCurrency()) == "" {
@@ -264,7 +264,7 @@ func (p *paymentExecutor) ledgerTxForAction(ctx context.Context, payment *model.
if payment == nil {
return rail.LedgerTx{}, merrors.InvalidArgument("ledger: payment is required")
}
if payment.OrganizationRef == primitive.NilObjectID {
if payment.OrganizationRef == bson.NilObjectID {
return rail.LedgerTx{}, merrors.InvalidArgument("ledger: organization_ref is required")
}
if amount == nil || strings.TrimSpace(amount.GetAmount()) == "" || strings.TrimSpace(amount.GetCurrency()) == "" {
@@ -454,7 +454,7 @@ func ledgerRoleFromAccountRole(role pmodel.AccountRole) ledgerv1.AccountRole {
return ledgerv1.AccountRole_ACCOUNT_ROLE_UNSPECIFIED
}
func (p *paymentExecutor) resolveAccount(ctx context.Context, orgRef primitive.ObjectID, asset string, rail model.Rail, role pmodel.AccountRole) (string, error) {
func (p *paymentExecutor) resolveAccount(ctx context.Context, orgRef bson.ObjectID, asset string, rail model.Rail, role pmodel.AccountRole) (string, error) {
switch rail {
case model.RailLedger:
return p.resolveLedgerAccountByRole(ctx, orgRef, asset, role)
@@ -463,11 +463,11 @@ func (p *paymentExecutor) resolveAccount(ctx context.Context, orgRef primitive.O
}
}
func (p *paymentExecutor) resolveLedgerAccountByRole(ctx context.Context, orgRef primitive.ObjectID, asset string, role pmodel.AccountRole) (string, error) {
func (p *paymentExecutor) resolveLedgerAccountByRole(ctx context.Context, orgRef bson.ObjectID, asset string, role pmodel.AccountRole) (string, error) {
if p == nil || p.deps == nil || p.deps.ledger.client == nil {
return "", merrors.Internal("ledger_client_unavailable")
}
if orgRef == primitive.NilObjectID {
if orgRef == bson.NilObjectID {
return "", merrors.InvalidArgument("ledger: organization_ref is required")
}
currency := strings.TrimSpace(asset)
@@ -544,7 +544,7 @@ func (p *paymentExecutor) resolveOrgOwnedLedgerAccount(ctx context.Context, paym
if payment == nil {
return "", merrors.InvalidArgument("ledger: payment is required")
}
if payment.OrganizationRef == primitive.NilObjectID {
if payment.OrganizationRef == bson.NilObjectID {
return "", merrors.InvalidArgument("ledger: organization_ref is required")
}
if amount == nil || strings.TrimSpace(amount.GetCurrency()) == "" {

View File

@@ -11,7 +11,7 @@ import (
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"
)
@@ -90,7 +90,7 @@ func TestLedgerAccountResolution_UsesRoleAccounts(t *testing.T) {
},
},
}
payment.OrganizationRef = primitive.NewObjectID()
payment.OrganizationRef = bson.NewObjectID()
store := newStubPaymentsStore()
store.payments[payment.PaymentRef] = payment

View File

@@ -9,7 +9,7 @@ import (
"github.com/tech/sendico/payments/orchestrator/storage/model"
mo "github.com/tech/sendico/pkg/model"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -38,7 +38,7 @@ func TestReleasePaymentHold_RejectsLegacyLedgerRelease(t *testing.T) {
PaymentRef: "pay-release-1",
IdempotencyKey: "pay-release-1",
OrganizationBoundBase: mo.OrganizationBoundBase{
OrganizationRef: primitive.NewObjectID(),
OrganizationRef: bson.NewObjectID(),
},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,

View File

@@ -9,19 +9,18 @@ import (
"testing"
"time"
storagemongo "github.com/tech/sendico/payments/orchestrator/storage/mongo"
"github.com/tech/sendico/payments/orchestrator/storage/model"
storagemongo "github.com/tech/sendico/payments/orchestrator/storage/mongo"
"github.com/tech/sendico/pkg/db/repository"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/mongodb"
"github.com/testcontainers/testcontainers-go/wait"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
"go.uber.org/zap"
)
@@ -80,7 +79,7 @@ func TestQuotePayment_IdempotencyReuseAfterExpiry(t *testing.T) {
now := time.Now()
svc := NewService(zap.NewNop(), store, WithClock(testClock{now: now}))
orgID := primitive.NewObjectID()
orgID := bson.NewObjectID()
req := &orchestratorv1.QuotePaymentRequest{
Meta: &orchestratorv1.RequestMeta{OrganizationRef: orgID.Hex()},
IdempotencyKey: "idem-expired-quote",

View File

@@ -12,21 +12,21 @@ import (
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"google.golang.org/protobuf/proto"
)
func validateMetaAndOrgRef(meta *orchestratorv1.RequestMeta) (string, primitive.ObjectID, error) {
func validateMetaAndOrgRef(meta *orchestratorv1.RequestMeta) (string, bson.ObjectID, error) {
if meta == nil {
return "", primitive.NilObjectID, merrors.InvalidArgument("meta is required")
return "", bson.NilObjectID, merrors.InvalidArgument("meta is required")
}
orgRef := strings.TrimSpace(meta.GetOrganizationRef())
if orgRef == "" {
return "", primitive.NilObjectID, merrors.InvalidArgument("organization_ref is required")
return "", bson.NilObjectID, merrors.InvalidArgument("organization_ref is required")
}
orgID, err := primitive.ObjectIDFromHex(orgRef)
orgID, err := bson.ObjectIDFromHex(orgRef)
if err != nil {
return "", primitive.NilObjectID, merrors.InvalidArgument("organization_ref must be a valid objectID")
return "", bson.NilObjectID, merrors.InvalidArgument("organization_ref must be a valid objectID")
}
return orgRef, orgID, nil
}
@@ -82,7 +82,7 @@ func ensureQuotesStore(repo storage.Repository) (storage.QuotesStore, error) {
return store, nil
}
func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore, orgID primitive.ObjectID, key string) (*model.Payment, error) {
func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore, orgID bson.ObjectID, key string) (*model.Payment, error) {
payment, err := store.GetByIdempotencyKey(ctx, orgID, key)
if err != nil {
return nil, err
@@ -92,7 +92,7 @@ func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore
type quoteResolutionInput struct {
OrgRef string
OrgID primitive.ObjectID
OrgID bson.ObjectID
Meta *orchestratorv1.RequestMeta
Intent *orchestratorv1.PaymentIntent
QuoteRef string
@@ -185,9 +185,9 @@ func recordQuoteFromQuote(record *model.PaymentQuoteRecord) (*orchestratorv1.Pay
return nil, merrors.InvalidArgument("stored quote is empty")
}
func newPayment(orgID primitive.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, metadata map[string]string, quote *orchestratorv1.PaymentQuote) *model.Payment {
func newPayment(orgID bson.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, metadata map[string]string, quote *orchestratorv1.PaymentQuote) *model.Payment {
entity := &model.Payment{}
entity.SetID(primitive.NewObjectID())
entity.SetID(bson.NewObjectID())
entity.SetOrganizationRef(orgID)
entity.PaymentRef = entity.GetID().Hex()
entity.IdempotencyKey = idempotencyKey

View File

@@ -16,12 +16,12 @@ import (
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"google.golang.org/protobuf/types/known/structpb"
)
func TestValidateMetaAndOrgRef(t *testing.T) {
org := primitive.NewObjectID()
org := bson.NewObjectID()
meta := &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()}
ref, id, err := validateMetaAndOrgRef(meta)
if err != nil {
@@ -52,7 +52,7 @@ func TestRequireIdempotencyKey(t *testing.T) {
}
func TestNewPayment(t *testing.T) {
org := primitive.NewObjectID()
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{
Amount: &moneyv1.Money{Currency: "USD", Amount: "10"},
SettlementMode: orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED,
@@ -75,7 +75,7 @@ func TestNewPayment(t *testing.T) {
}
func TestResolvePaymentQuote_NotFound(t *testing.T) {
org := primitive.NewObjectID()
org := bson.NewObjectID()
svc := &Service{
storage: stubRepo{quotes: &helperQuotesStore{}},
clock: clockpkg.NewSystem(),
@@ -93,7 +93,7 @@ func TestResolvePaymentQuote_NotFound(t *testing.T) {
}
func TestResolvePaymentQuote_Expired(t *testing.T) {
org := primitive.NewObjectID()
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"}
record := &model.PaymentQuoteRecord{
QuoteRef: "q1",
@@ -118,7 +118,7 @@ func TestResolvePaymentQuote_Expired(t *testing.T) {
}
func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) {
org := primitive.NewObjectID()
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"}
record := &model.PaymentQuoteRecord{
QuoteRef: "q1",
@@ -147,7 +147,7 @@ func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) {
}
func TestResolvePaymentQuote_QuoteRefSkipsQuoteRecompute(t *testing.T) {
org := primitive.NewObjectID()
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"},
SettlementCurrency: "USD",
@@ -193,7 +193,7 @@ func TestResolvePaymentQuote_QuoteRefSkipsQuoteRecompute(t *testing.T) {
func TestInitiatePaymentIdempotency(t *testing.T) {
logger := mloggerfactory.NewLogger(false)
org := primitive.NewObjectID()
org := bson.NewObjectID()
store := newHelperPaymentStore()
ledgerFake := &ledgerclient.Fake{
ListConnectorAccountsFn: func(ctx context.Context, req *connectorv1.ListAccountsRequest) (*connectorv1.ListAccountsResponse, error) {
@@ -264,7 +264,7 @@ func TestInitiatePaymentIdempotency(t *testing.T) {
func TestInitiatePaymentByQuoteRef(t *testing.T) {
logger := mloggerfactory.NewLogger(false)
org := primitive.NewObjectID()
org := bson.NewObjectID()
store := newHelperPaymentStore()
intent := &orchestratorv1.PaymentIntent{
Source: &orchestratorv1.PaymentEndpoint{
@@ -411,7 +411,7 @@ func (s *helperPaymentStore) GetByPaymentRef(_ context.Context, ref string) (*mo
return nil, storage.ErrPaymentNotFound
}
func (s *helperPaymentStore) GetByIdempotencyKey(_ context.Context, _ primitive.ObjectID, key string) (*model.Payment, error) {
func (s *helperPaymentStore) GetByIdempotencyKey(_ context.Context, _ bson.ObjectID, key string) (*model.Payment, error) {
if p, ok := s.byIdem[key]; ok {
return p, nil
}
@@ -435,7 +435,7 @@ type helperQuotesStore struct {
func (s *helperQuotesStore) Create(_ context.Context, _ *model.PaymentQuoteRecord) error { return nil }
func (s *helperQuotesStore) GetByRef(_ context.Context, _ primitive.ObjectID, ref string) (*model.PaymentQuoteRecord, error) {
func (s *helperQuotesStore) GetByRef(_ context.Context, _ bson.ObjectID, ref string) (*model.PaymentQuoteRecord, error) {
if s.records == nil {
return nil, storage.ErrQuoteNotFound
}
@@ -445,7 +445,7 @@ func (s *helperQuotesStore) GetByRef(_ context.Context, _ primitive.ObjectID, re
return nil, storage.ErrQuoteNotFound
}
func (s *helperQuotesStore) GetByIdempotencyKey(_ context.Context, orgRef primitive.ObjectID, ref string) (*model.PaymentQuoteRecord, error) {
func (s *helperQuotesStore) GetByIdempotencyKey(_ context.Context, orgRef bson.ObjectID, ref string) (*model.PaymentQuoteRecord, error) {
if s.records == nil {
return nil, storage.ErrQuoteNotFound
}

View File

@@ -20,7 +20,7 @@ import (
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -51,7 +51,7 @@ func TestExecutePayment_FXConversionSettled(t *testing.T) {
payment := &model.Payment{
PaymentRef: "fx-1",
IdempotencyKey: "fx-1",
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()},
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()},
Intent: model.PaymentIntent{
Kind: model.PaymentKindFXConversion,
Source: model.PaymentEndpoint{
@@ -154,7 +154,7 @@ func TestExecutePayment_ChainFailure(t *testing.T) {
payment := &model.Payment{
PaymentRef: "chain-1",
IdempotencyKey: "chain-1",
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: primitive.NewObjectID()},
OrganizationBoundBase: mo.OrganizationBoundBase{OrganizationRef: bson.NewObjectID()},
Intent: model.PaymentIntent{
Kind: model.PaymentKindPayout,
Source: model.PaymentEndpoint{
@@ -413,7 +413,7 @@ func (s *stubQuotesStore) Create(ctx context.Context, quote *model.PaymentQuoteR
return nil
}
func (s *stubQuotesStore) GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) {
func (s *stubQuotesStore) GetByRef(ctx context.Context, orgRef bson.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) {
if s.quotes == nil {
return nil, storage.ErrQuoteNotFound
}
@@ -423,7 +423,7 @@ func (s *stubQuotesStore) GetByRef(ctx context.Context, orgRef primitive.ObjectI
return nil, storage.ErrQuoteNotFound
}
func (s *stubQuotesStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) {
func (s *stubQuotesStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) {
if s.quotes == nil {
return nil, storage.ErrQuoteNotFound
}
@@ -450,7 +450,7 @@ func (s *stubRoutesStore) Update(ctx context.Context, route *model.PaymentRoute)
return merrors.InvalidArgument("routes store not implemented")
}
func (s *stubRoutesStore) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentRoute, error) {
func (s *stubRoutesStore) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentRoute, error) {
return nil, storage.ErrRouteNotFound
}
@@ -493,7 +493,7 @@ func (s *stubPlanTemplatesStore) Update(ctx context.Context, template *model.Pay
return merrors.InvalidArgument("plan templates store not implemented")
}
func (s *stubPlanTemplatesStore) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentPlanTemplate, error) {
func (s *stubPlanTemplatesStore) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error) {
return nil, storage.ErrPlanTemplateNotFound
}
@@ -562,7 +562,7 @@ func (s *stubPaymentsStore) GetByPaymentRef(ctx context.Context, paymentRef stri
return nil, storage.ErrPaymentNotFound
}
func (s *stubPaymentsStore) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, key string) (*model.Payment, error) {
func (s *stubPaymentsStore) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, key string) (*model.Payment, error) {
for _, p := range s.payments {
if p.OrganizationRef == orgRef && strings.TrimSpace(p.IdempotencyKey) == key {
return p, nil

View File

@@ -12,8 +12,8 @@ import (
ri "github.com/tech/sendico/pkg/db/repository/index"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -86,7 +86,7 @@ func (p *Payments) Create(ctx context.Context, payment *model.Payment) error {
if strings.TrimSpace(payment.IdempotencyKey) == "" {
return merrors.InvalidArgument("paymentsStore: empty idempotencyKey")
}
if payment.OrganizationRef == primitive.NilObjectID {
if payment.OrganizationRef == bson.NilObjectID {
return merrors.InvalidArgument("paymentsStore: organization_ref is required")
}
@@ -138,9 +138,9 @@ func (p *Payments) GetByPaymentRef(ctx context.Context, paymentRef string) (*mod
return entity, nil
}
func (p *Payments) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.Payment, error) {
func (p *Payments) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.Payment, error) {
idempotencyKey = strings.TrimSpace(idempotencyKey)
if orgRef == primitive.NilObjectID {
if orgRef == bson.NilObjectID {
return nil, merrors.InvalidArgument("paymentsStore: organization_ref is required")
}
if idempotencyKey == "" {
@@ -208,7 +208,7 @@ func (p *Payments) List(ctx context.Context, filter *model.PaymentFilter) (*mode
}
if cursor := strings.TrimSpace(filter.Cursor); cursor != "" {
if oid, err := primitive.ObjectIDFromHex(cursor); err == nil {
if oid, err := bson.ObjectIDFromHex(cursor); err == nil {
query = query.Comparison(repository.IDField(), builder.Gt, oid)
} else {
p.logger.Warn("ignoring invalid payments cursor", zap.String("cursor", cursor), zap.Error(err))

View File

@@ -11,8 +11,8 @@ import (
ri "github.com/tech/sendico/pkg/db/repository/index"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -75,7 +75,7 @@ func (p *PlanTemplates) Create(ctx context.Context, template *model.PaymentPlanT
return merrors.InvalidArgument("planTemplatesStore: steps are required")
}
if template.ID.IsZero() {
template.SetID(primitive.NewObjectID())
template.SetID(bson.NewObjectID())
} else {
template.Update()
}
@@ -112,8 +112,8 @@ func (p *PlanTemplates) Update(ctx context.Context, template *model.PaymentPlanT
return nil
}
func (p *PlanTemplates) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentPlanTemplate, error) {
if id == primitive.NilObjectID {
func (p *PlanTemplates) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error) {
if id == bson.NilObjectID {
return nil, merrors.InvalidArgument("planTemplatesStore: template id is required")
}
entity := &model.PaymentPlanTemplate{}

View File

@@ -14,7 +14,7 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -83,7 +83,7 @@ func (q *Quotes) Create(ctx context.Context, quote *model.PaymentQuoteRecord) er
if quote.QuoteRef == "" {
return merrors.InvalidArgument("quotesStore: empty quoteRef")
}
if quote.OrganizationRef == primitive.NilObjectID {
if quote.OrganizationRef == bson.NilObjectID {
return merrors.InvalidArgument("quotesStore: organization_ref is required")
}
quote.IdempotencyKey = strings.TrimSpace(quote.IdempotencyKey)
@@ -127,12 +127,12 @@ func (q *Quotes) Create(ctx context.Context, quote *model.PaymentQuoteRecord) er
return nil
}
func (q *Quotes) GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) {
func (q *Quotes) GetByRef(ctx context.Context, orgRef bson.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error) {
quoteRef = strings.TrimSpace(quoteRef)
if quoteRef == "" {
return nil, merrors.InvalidArgument("quotesStore: empty quoteRef")
}
if orgRef == primitive.NilObjectID {
if orgRef == bson.NilObjectID {
return nil, merrors.InvalidArgument("quotesStore: organization_ref is required")
}
entity := &model.PaymentQuoteRecord{}
@@ -152,12 +152,12 @@ func (q *Quotes) GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteR
return entity, nil
}
func (q *Quotes) GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) {
func (q *Quotes) GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error) {
idempotencyKey = strings.TrimSpace(idempotencyKey)
if idempotencyKey == "" {
return nil, merrors.InvalidArgument("quotesStore: empty idempotency key")
}
if orgRef == primitive.NilObjectID {
if orgRef == bson.NilObjectID {
return nil, merrors.InvalidArgument("quotesStore: organization_ref is required")
}
entity := &model.PaymentQuoteRecord{}

View File

@@ -11,8 +11,8 @@ import (
ri "github.com/tech/sendico/pkg/db/repository/index"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
)
@@ -72,7 +72,7 @@ func (r *Routes) Create(ctx context.Context, route *model.PaymentRoute) error {
return merrors.InvalidArgument("routesStore: to_rail is required")
}
if route.ID.IsZero() {
route.SetID(primitive.NewObjectID())
route.SetID(bson.NewObjectID())
} else {
route.Update()
}
@@ -109,8 +109,8 @@ func (r *Routes) Update(ctx context.Context, route *model.PaymentRoute) error {
return nil
}
func (r *Routes) GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentRoute, error) {
if id == primitive.NilObjectID {
func (r *Routes) GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentRoute, error) {
if id == bson.NilObjectID {
return nil, merrors.InvalidArgument("routesStore: route id is required")
}
entity := &model.PaymentRoute{}

View File

@@ -4,7 +4,7 @@ import (
"context"
"github.com/tech/sendico/payments/orchestrator/storage/model"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson"
)
type storageError string
@@ -46,7 +46,7 @@ type PaymentsStore interface {
Create(ctx context.Context, payment *model.Payment) error
Update(ctx context.Context, payment *model.Payment) error
GetByPaymentRef(ctx context.Context, paymentRef string) (*model.Payment, error)
GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.Payment, error)
GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.Payment, error)
GetByChainTransferRef(ctx context.Context, transferRef string) (*model.Payment, error)
List(ctx context.Context, filter *model.PaymentFilter) (*model.PaymentList, error)
}
@@ -54,15 +54,15 @@ type PaymentsStore interface {
// QuotesStore manages temporary stored payment quotes.
type QuotesStore interface {
Create(ctx context.Context, quote *model.PaymentQuoteRecord) error
GetByRef(ctx context.Context, orgRef primitive.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error)
GetByIdempotencyKey(ctx context.Context, orgRef primitive.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error)
GetByRef(ctx context.Context, orgRef bson.ObjectID, quoteRef string) (*model.PaymentQuoteRecord, error)
GetByIdempotencyKey(ctx context.Context, orgRef bson.ObjectID, idempotencyKey string) (*model.PaymentQuoteRecord, error)
}
// RoutesStore manages allowed routing transitions.
type RoutesStore interface {
Create(ctx context.Context, route *model.PaymentRoute) error
Update(ctx context.Context, route *model.PaymentRoute) error
GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentRoute, error)
GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentRoute, error)
List(ctx context.Context, filter *model.PaymentRouteFilter) (*model.PaymentRouteList, error)
}
@@ -70,6 +70,6 @@ type RoutesStore interface {
type PlanTemplatesStore interface {
Create(ctx context.Context, template *model.PaymentPlanTemplate) error
Update(ctx context.Context, template *model.PaymentPlanTemplate) error
GetByID(ctx context.Context, id primitive.ObjectID) (*model.PaymentPlanTemplate, error)
GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error)
List(ctx context.Context, filter *model.PaymentPlanTemplateFilter) (*model.PaymentPlanTemplateList, error)
}