Files
member-console/internal/workflows/billing/activities.go
T
cgalo5758 88db730fcc Add dual licensing and SPDX headers
Introduce a commercial license option alongside AGPL-3.0-only, require a
CLA for contributors, and document the terms in COMMERCIAL.md and
NOTICE. Add a script to stamp SPDX headers on Go files and apply it
across the tree.
2026-09-06 02:29:42 -05:00

46 lines
1.5 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
// Package billing holds Temporal workflows and activities for billing
// maintenance — currently the periodic sweep that fires due subscription
// scheduled changes as a backstop to the Stripe-webhook-primary firing path.
package billing
import (
"context"
"database/sql"
"log/slog"
"git.coopcloud.tech/wiki-cafe/member-console/internal/fulfillment"
)
// Activities holds dependencies for billing maintenance activities.
type Activities struct {
db *sql.DB
logger *slog.Logger
}
// NewActivities constructs an Activities ready for registration.
func NewActivities(db *sql.DB, logger *slog.Logger) *Activities {
if logger == nil {
logger = slog.Default()
}
return &Activities{db: db, logger: logger}
}
// SweepScheduledChangesOutput reports how many due scheduled changes fired.
type SweepScheduledChangesOutput struct {
Fired int
}
// SweepScheduledChangesActivity fires every due subscription scheduled change.
// It is idempotent (each row is claimed via a conditional scheduled->applied
// update), so re-running it — or racing the webhook path — is safe.
func (a *Activities) SweepScheduledChangesActivity(ctx context.Context) (SweepScheduledChangesOutput, error) {
fired, err := fulfillment.SweepDueScheduledChanges(ctx, a.db, a.logger)
if err != nil {
return SweepScheduledChangesOutput{}, err
}
return SweepScheduledChangesOutput{Fired: fired}, nil
}