package storage import ( "context" "errors" "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" ) var ( // ErrPaymentNotFound signals that a payment record does not exist. ErrPaymentNotFound = errors.New("payments.storage: payment not found") // ErrDuplicatePayment signals that idempotency constraints were violated. ErrDuplicatePayment = errors.New("payments.storage: duplicate payment") // ErrRouteNotFound signals that a payment route record does not exist. ErrRouteNotFound = errors.New("payments.storage: route not found") // ErrDuplicateRoute signals that a route already exists for the same transition. ErrDuplicateRoute = errors.New("payments.storage: duplicate route") // ErrPlanTemplateNotFound signals that a plan template record does not exist. ErrPlanTemplateNotFound = errors.New("payments.storage: plan template not found") // ErrDuplicatePlanTemplate signals that a plan template already exists for the same transition. ErrDuplicatePlanTemplate = errors.New("payments.storage: duplicate plan template") ) // 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) GetPrivate(ctx context.Context, 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) ListPrivate(ctx context.Context, 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) }