89 lines
4.1 KiB
Go
89 lines
4.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/tech/sendico/payments/storage/model"
|
|
quotestorage "github.com/tech/sendico/payments/storage/quote"
|
|
pkgmodel "github.com/tech/sendico/pkg/model"
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
)
|
|
|
|
type storageError string
|
|
|
|
func (e storageError) Error() string {
|
|
return string(e)
|
|
}
|
|
|
|
var (
|
|
// ErrPaymentNotFound signals that a payment record does not exist.
|
|
ErrPaymentNotFound = storageError("payments.storage: payment not found")
|
|
// ErrDuplicatePayment signals that idempotency constraints were violated.
|
|
ErrDuplicatePayment = storageError("payments.storage: duplicate payment")
|
|
// ErrRouteNotFound signals that a payment route record does not exist.
|
|
ErrRouteNotFound = storageError("payments.storage: route not found")
|
|
// ErrDuplicateRoute signals that a route already exists for the same transition.
|
|
ErrDuplicateRoute = storageError("payments.storage: duplicate route")
|
|
// ErrPlanTemplateNotFound signals that a plan template record does not exist.
|
|
ErrPlanTemplateNotFound = storageError("payments.storage: plan template not found")
|
|
// ErrDuplicatePlanTemplate signals that a plan template already exists for the same transition.
|
|
ErrDuplicatePlanTemplate = storageError("payments.storage: duplicate plan template")
|
|
)
|
|
|
|
var (
|
|
// Deprecated: use quote/storage.ErrQuoteNotFound.
|
|
ErrQuoteNotFound = quotestorage.ErrQuoteNotFound
|
|
// Deprecated: use quote/storage.ErrDuplicateQuote.
|
|
ErrDuplicateQuote = quotestorage.ErrDuplicateQuote
|
|
)
|
|
|
|
// Repository exposes persistence primitives for the payments domain.
|
|
type Repository interface {
|
|
Ping(ctx context.Context) error
|
|
Payments() PaymentsStore
|
|
PaymentMethods() PaymentMethodsStore
|
|
Quotes() quotestorage.QuotesStore
|
|
Routes() RoutesStore
|
|
PlanTemplates() PlanTemplatesStore
|
|
}
|
|
|
|
// PaymentsStore manages payment lifecycle state.
|
|
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 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)
|
|
}
|
|
|
|
// PaymentMethodsStore manages recipient-linked payment methods.
|
|
type PaymentMethodsStore interface {
|
|
Create(ctx context.Context, accountRef, organizationRef bson.ObjectID, method *pkgmodel.PaymentMethod) error
|
|
Get(ctx context.Context, accountRef, methodRef bson.ObjectID) (*pkgmodel.PaymentMethod, error)
|
|
Update(ctx context.Context, accountRef bson.ObjectID, method *pkgmodel.PaymentMethod) error
|
|
Delete(ctx context.Context, accountRef, methodRef bson.ObjectID) error
|
|
DeleteCascade(ctx context.Context, accountRef, methodRef bson.ObjectID) error
|
|
SetArchived(ctx context.Context, accountRef, organizationRef, methodRef bson.ObjectID, archived, cascade bool) error
|
|
List(ctx context.Context, accountRef, organizationRef, recipientRef bson.ObjectID, cursor *pkgmodel.ViewCursor) ([]pkgmodel.PaymentMethod, error)
|
|
|
|
SetArchivedByRecipient(ctx context.Context, recipientRef bson.ObjectID, archived bool) (int, error)
|
|
DeleteByRecipient(ctx context.Context, recipientRef bson.ObjectID) 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 bson.ObjectID) (*model.PaymentRoute, error)
|
|
List(ctx context.Context, filter *model.PaymentRouteFilter) (*model.PaymentRouteList, error)
|
|
}
|
|
|
|
// PlanTemplatesStore manages orchestration plan templates.
|
|
type PlanTemplatesStore interface {
|
|
Create(ctx context.Context, template *model.PaymentPlanTemplate) error
|
|
Update(ctx context.Context, template *model.PaymentPlanTemplate) error
|
|
GetByID(ctx context.Context, id bson.ObjectID) (*model.PaymentPlanTemplate, error)
|
|
List(ctx context.Context, filter *model.PaymentPlanTemplateFilter) (*model.PaymentPlanTemplateList, error)
|
|
}
|