outbox for gateways
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
pkgmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
mutil "github.com/tech/sendico/pkg/mutil/db"
|
||||
mauth "github.com/tech/sendico/pkg/mutil/db/auth"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
@@ -50,7 +51,7 @@ func NewPaymentMethods(logger mlogger.Logger, repo repository.Repository, enforc
|
||||
|
||||
for _, def := range indexes {
|
||||
if err := repo.CreateIndex(def); err != nil {
|
||||
logger.Error("failed to ensure payment methods index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
logger.Error("Failed to ensure payment methods index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -112,6 +113,18 @@ func (p *PaymentMethods) Get(ctx context.Context, accountRef, methodRef bson.Obj
|
||||
return method, nil
|
||||
}
|
||||
|
||||
func (p *PaymentMethods) GetPrivate(ctx context.Context, methodRef bson.ObjectID) (*pkgmodel.PaymentMethod, error) {
|
||||
if methodRef == bson.NilObjectID {
|
||||
return nil, merrors.InvalidArgument("paymentMethodsStore: method_ref is required")
|
||||
}
|
||||
|
||||
method := &pkgmodel.PaymentMethod{}
|
||||
if err := p.repo.Get(ctx, methodRef, method); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return method, nil
|
||||
}
|
||||
|
||||
func (p *PaymentMethods) Update(ctx context.Context, accountRef bson.ObjectID, method *pkgmodel.PaymentMethod) error {
|
||||
if method == nil {
|
||||
return merrors.InvalidArgument("paymentMethodsStore: nil payment method")
|
||||
@@ -193,6 +206,27 @@ func (p *PaymentMethods) List(ctx context.Context, accountRef, organizationRef,
|
||||
return items, err
|
||||
}
|
||||
|
||||
func (p *PaymentMethods) ListPrivate(ctx context.Context, organizationRef, recipientRef bson.ObjectID, cursor *pkgmodel.ViewCursor) ([]pkgmodel.PaymentMethod, error) {
|
||||
if organizationRef == bson.NilObjectID {
|
||||
return nil, merrors.InvalidArgument("paymentMethodsStore: organization_ref is required")
|
||||
}
|
||||
if recipientRef == bson.NilObjectID {
|
||||
return nil, merrors.InvalidArgument("paymentMethodsStore: recipient_ref is required")
|
||||
}
|
||||
|
||||
items, err := mutil.GetObjects[pkgmodel.PaymentMethod](
|
||||
ctx,
|
||||
p.logger,
|
||||
repository.OrgFilter(organizationRef).And(repository.Filter("recipientRef", recipientRef)),
|
||||
cursor,
|
||||
p.repo,
|
||||
)
|
||||
if errors.Is(err, merrors.ErrNoData) {
|
||||
return []pkgmodel.PaymentMethod{}, nil
|
||||
}
|
||||
return items, err
|
||||
}
|
||||
|
||||
func (p *PaymentMethods) SetArchivedByRecipient(ctx context.Context, recipientRef bson.ObjectID, archived bool) (int, error) {
|
||||
if recipientRef == bson.NilObjectID {
|
||||
return 0, merrors.InvalidArgument("paymentMethodsStore: recipient_ref is required")
|
||||
|
||||
@@ -61,13 +61,13 @@ func NewPayments(logger mlogger.Logger, repo repository.Repository) (*Payments,
|
||||
|
||||
for _, def := range indexes {
|
||||
if err := repo.CreateIndex(def); err != nil {
|
||||
logger.Error("failed to ensure payments index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
logger.Error("Failed to ensure payments index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
childLogger := logger.Named("payments")
|
||||
childLogger.Debug("payments store initialised")
|
||||
childLogger.Debug("Payments store initialised")
|
||||
|
||||
return &Payments{
|
||||
logger: childLogger,
|
||||
@@ -101,7 +101,7 @@ func (p *Payments) Create(ctx context.Context, payment *model.Payment) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
p.logger.Debug("payment created", zap.String("payment_ref", payment.PaymentRef))
|
||||
p.logger.Debug("Payment created", zap.String("payment_ref", payment.PaymentRef))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (p *Payments) List(ctx context.Context, filter *model.PaymentFilter) (*mode
|
||||
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))
|
||||
p.logger.Warn("Ignoring invalid payments cursor", zap.String("cursor", cursor), zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func NewPlanTemplates(logger mlogger.Logger, repo repository.Repository) (*PlanT
|
||||
|
||||
for _, def := range indexes {
|
||||
if err := repo.CreateIndex(def); err != nil {
|
||||
logger.Error("failed to ensure plan templates index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
logger.Error("Failed to ensure plan templates index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func NewRoutes(logger mlogger.Logger, repo repository.Repository) (*Routes, erro
|
||||
|
||||
for _, def := range indexes {
|
||||
if err := repo.CreateIndex(def); err != nil {
|
||||
logger.Error("failed to ensure routes index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
logger.Error("Failed to ensure routes index", zap.Error(err), zap.String("collection", repo.Collection()))
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user