Create Temporal billing sweep schedule, workflow and activities and register them in the worker/start initialization. Add an HTMX preview route and banner for plan switches (switch button now GETs a preview; Confirm posts the switch). Extend the Stripe test mock to support invoice previews and add integration tests for PreviewSwitch behavior.
26 lines
1.0 KiB
Go
26 lines
1.0 KiB
Go
package billing
|
|
|
|
import (
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/workflows/common"
|
|
"go.temporal.io/sdk/workflow"
|
|
)
|
|
|
|
// SweepScheduledChangesWorkflow fires due subscription scheduled changes. It runs
|
|
// on a recurring schedule as the backstop to the webhook-primary firing path:
|
|
// a period-end cancellation normally fires via Stripe's customer.subscription
|
|
// .deleted webhook, but the sweep catches missed webhooks and term-boundary
|
|
// ('block'-deferred) changes that Stripe does not fire on its own.
|
|
func SweepScheduledChangesWorkflow(ctx workflow.Context) error {
|
|
logger := workflow.GetLogger(ctx)
|
|
ctx = workflow.WithActivityOptions(ctx, common.DefaultActivityOptions())
|
|
|
|
var activities *Activities
|
|
var out SweepScheduledChangesOutput
|
|
if err := workflow.ExecuteActivity(ctx, activities.SweepScheduledChangesActivity).Get(ctx, &out); err != nil {
|
|
logger.Error("SweepScheduledChangesActivity failed", "error", err)
|
|
return err
|
|
}
|
|
logger.Info("SweepScheduledChangesWorkflow completed", "fired", out.Fired)
|
|
return nil
|
|
}
|