subscription

package
v0.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

README ¶

Subscription Plugin for AuthSome

A comprehensive SaaS subscription and billing plugin for AuthSome, providing complete subscription management with organization-scoped billing.

🆕 New Features (December 2025)

Export & Import
  • Export all features and plans as JSON for backup or migration
  • Import features and plans from JSON to quickly set up new environments
  • Perfect for local development and multi-environment deployments
  • See Export/Import Guide
Enhanced Stripe Sync
  • Sync FROM Stripe - Import existing Stripe products into AuthSome
  • Sync TO Stripe - Push AuthSome plans to Stripe
  • Automatic metadata management for seamless bi-directional sync
  • Bulk sync all plans with one click

Features

  • Plan Management: Create and manage subscription plans with flexible pricing

    • Flat rate pricing
    • Per-seat pricing
    • Tiered pricing
    • Usage-based (metered) billing
    • Hybrid billing patterns
  • Subscription Lifecycle: Full subscription management

    • Trial periods
    • Plan upgrades/downgrades
    • Subscription pausing/resuming
    • Cancellation with grace periods
  • Add-ons: Additional features and services

    • One-time purchases
    • Recurring add-ons
    • Usage-based add-ons
  • Usage Tracking: Metered billing support

    • API call tracking
    • Storage usage
    • Custom metrics
  • Payment Providers: Pluggable payment gateway integration

    • Stripe (fully implemented)
    • Mock provider for development/testing
    • Custom provider support via WithProvider option
  • Enforcement: Plan limit enforcement via hooks

    • Seat/member limits
    • Feature access control
    • Usage limits

Installation

Add the subscription plugin when creating your AuthSome instance:

import (
    "github.com/xraph/authsome"
    "github.com/xraph/authsome/plugins/subscription"
)

// Create plugin with configuration
subPlugin := subscription.NewPlugin(
    subscription.WithStripeConfig(
        os.Getenv("STRIPE_SECRET_KEY"),
        os.Getenv("STRIPE_WEBHOOK_SECRET"),
        os.Getenv("STRIPE_PUBLISHABLE_KEY"),
    ),
    subscription.WithDefaultTrialDays(14),
    subscription.WithRequireSubscription(false),
    subscription.WithGracePeriodDays(7),
    subscription.WithAutoSyncSeats(true),
)

// Or use a custom payment provider
customProvider := mypackage.NewCustomProvider()
subPlugin := subscription.NewPlugin(
    subscription.WithProvider(customProvider),
    subscription.WithDefaultTrialDays(14),
)

// Register with AuthSome
auth, err := authsome.New(
    authsome.WithPlugins(subPlugin),
    // ... other options
)

Configuration

The plugin can be configured via YAML or environment variables:

auth:
  subscription:
    enabled: true
    requireSubscription: false
    defaultTrialDays: 14
    gracePeriodDays: 7
    autoSyncSeats: false
    provider: stripe
    stripe:
      secretKey: ${STRIPE_SECRET_KEY}
      webhookSecret: ${STRIPE_WEBHOOK_SECRET}
      publishableKey: ${STRIPE_PUBLISHABLE_KEY}

Custom Payment Provider

You can implement your own payment provider by implementing the providers.PaymentProvider interface:

import (
    "github.com/xraph/authsome/plugins/subscription/providers"
    "github.com/xraph/authsome/plugins/subscription/providers/types"
)

type CustomProvider struct {
    // Your custom fields
}

// Implement all PaymentProvider interface methods
func (p *CustomProvider) CreateCustomer(ctx context.Context, req *types.CreateCustomerRequest) (*types.ProviderCustomer, error) {
    // Your implementation
}

func (p *CustomProvider) CreateProduct(ctx context.Context, req *types.CreateProductRequest) (*types.ProviderProduct, error) {
    // Your implementation
}

// ... implement remaining methods

// Use your custom provider
customProvider := &CustomProvider{}
subPlugin := subscription.NewPlugin(
    subscription.WithProvider(customProvider),
)

This is useful for:

  • Integrating with payment providers other than Stripe (PayPal, Paddle, etc.)
  • Testing with mock providers
  • Custom billing logic specific to your application
  • Migrating from existing billing systems

API Endpoints

Plans
Method Endpoint Description
POST /subscription/plans Create a plan
GET /subscription/plans List all plans
GET /subscription/plans/:id Get plan details
PATCH /subscription/plans/:id Update a plan
DELETE /subscription/plans/:id Delete a plan
POST /subscription/plans/:id/sync Sync plan to provider
Subscriptions
Method Endpoint Description
POST /subscription/subscriptions Create subscription
GET /subscription/subscriptions List subscriptions
GET /subscription/subscriptions/:id Get subscription
GET /subscription/subscriptions/organization/:orgId Get org subscription
PATCH /subscription/subscriptions/:id Update subscription
POST /subscription/subscriptions/:id/cancel Cancel subscription
POST /subscription/subscriptions/:id/pause Pause subscription
POST /subscription/subscriptions/:id/resume Resume subscription
Add-ons
Method Endpoint Description
POST /subscription/addons Create add-on
GET /subscription/addons List add-ons
GET /subscription/addons/:id Get add-on
PATCH /subscription/addons/:id Update add-on
DELETE /subscription/addons/:id Delete add-on
Invoices
Method Endpoint Description
GET /subscription/invoices List invoices
GET /subscription/invoices/:id Get invoice
Usage
Method Endpoint Description
POST /subscription/usage Record usage
GET /subscription/usage/summary Get usage summary
Checkout
Method Endpoint Description
POST /subscription/checkout Create checkout session
POST /subscription/checkout/portal Create customer portal
Webhooks
Method Endpoint Description
POST /subscription/webhooks/stripe Stripe webhook handler

Using Services in Your Application

The subscription plugin registers its services with the Forge DI container:

// Get services from the plugin
plugin := auth.GetPlugin("subscription").(*subscription.Plugin)

// Plan Service
planSvc := plugin.GetPlanService()
plan, err := planSvc.Create(ctx, &core.CreatePlanRequest{
    Name:            "Pro Plan",
    Slug:            "pro",
    BillingPattern:  "per_seat",
    BillingInterval: "monthly",
    BasePrice:       2999, // $29.99 in cents
    Currency:        "usd",
})

// Subscription Service
subSvc := plugin.GetSubscriptionService()
sub, err := subSvc.Create(ctx, &core.CreateSubscriptionRequest{
    OrganizationID: orgID,
    PlanID:         plan.ID,
    Quantity:       5,
})

// Usage Service
usageSvc := plugin.GetUsageService()
err := usageSvc.RecordUsage(ctx, &core.CreateUsageRecordRequest{
    SubscriptionID: sub.ID,
    MetricKey:      "api_calls",
    Quantity:       1000,
})

// Enforcement Service
enforceSvc := plugin.GetEnforcementService()
hasAccess, err := enforceSvc.CheckFeatureAccess(ctx, orgID, "advanced_analytics")

Resolving Services from Container

// Using helper functions
planSvc, err := subscription.ResolvePlanService(container)
subSvc, err := subscription.ResolveSubscriptionService(container)
enforceSvc, err := subscription.ResolveEnforcementService(container)

// Or resolve directly
svc, err := container.Resolve("subscription.plan")
planSvc := svc.(*service.PlanService)

Hooks

The plugin provides hooks for subscription lifecycle events:

// Get hook registry
hookRegistry := plugin.GetHookRegistry()

// Before subscription creation
hookRegistry.RegisterBeforeSubscriptionCreate(func(ctx context.Context, orgID, planID xid.ID) error {
    // Custom validation logic
    return nil
})

// After subscription creation
hookRegistry.RegisterAfterSubscriptionCreate(func(ctx context.Context, sub *core.Subscription) error {
    // Send welcome email, provision resources, etc.
    return nil
})

// On payment success
hookRegistry.RegisterOnPaymentSuccess(func(ctx context.Context, subID, invoiceID xid.ID, amount int64, currency string) error {
    // Record in analytics, send receipt, etc.
    return nil
})

// On payment failure
hookRegistry.RegisterOnPaymentFailed(func(ctx context.Context, subID, invoiceID xid.ID, amount int64, currency string, reason string) error {
    // Send notification, flag account, etc.
    return nil
})

// On trial ending (typically 3 days before)
hookRegistry.RegisterOnTrialEnding(func(ctx context.Context, subID xid.ID, daysRemaining int) error {
    // Send reminder email
    return nil
})

Organization Enforcement

The plugin automatically integrates with AuthSome's organization service:

// These hooks are registered automatically
// Enforces seat limits when adding members
hooks.RegisterBeforeMemberAdd(enforcementSvc.EnforceSeatLimit)

// Enforces subscription requirement for org creation (if enabled)
hooks.RegisterBeforeOrganizationCreate(enforcementSvc.EnforceSubscriptionRequired)

Dashboard UI

The plugin provides a dashboard extension with:

  • Billing overview page
  • Plans management
  • Subscriptions list
  • Add-ons management
  • Invoices viewer
  • Usage dashboard
  • Billing settings

Plan Features

Plans can include features with different types:

plan := &core.Plan{
    Features: []core.PlanFeature{
        {
            Key:   "max_members",
            Type:  "limit",
            Value: "10",  // JSON value
        },
        {
            Key:   "api_access",
            Type:  "boolean",
            Value: "true",
        },
        {
            Key:   "storage",
            Type:  "limit",
            Value: "5368709120", // 5GB in bytes
        },
        {
            Key:   "unlimited_projects",
            Type:  "unlimited",
            Value: "",
        },
    },
}

Billing Patterns

Flat Rate
plan := &core.CreatePlanRequest{
    BillingPattern: "flat",
    BasePrice:      9999, // $99.99/month
}
Per-Seat
plan := &core.CreatePlanRequest{
    BillingPattern: "per_seat",
    BasePrice:      1999, // $19.99/seat/month
}
Tiered
plan := &core.CreatePlanRequest{
    BillingPattern: "tiered",
    TierMode:       "graduated",
    PriceTiers: []core.PriceTier{
        {UpTo: 10, UnitPrice: 1000},    // First 10: $10/each
        {UpTo: 50, UnitPrice: 800},     // 11-50: $8/each
        {UpTo: 0, UnitPrice: 500},      // 51+: $5/each (0 = unlimited)
    },
}
Usage-Based
plan := &core.CreatePlanRequest{
    BillingPattern: "usage",
    MeteredFeatures: []core.MeteredFeature{
        {Key: "api_calls", UnitPrice: 1, UnitName: "request"},
    },
}

License

See the main AuthSome LICENSE file.

Documentation ¶

Overview ¶

Package subscription provides a comprehensive SaaS subscription and billing plugin for AuthSome. It supports multiple billing patterns, payment provider integration (Stripe), and organization-scoped subscriptions.

Index ¶

Constants ¶

View Source
const (
	ServiceNamePlugin              = "subscription.plugin"
	ServiceNamePlanService         = "subscription.plan"
	ServiceNameSubService          = "subscription.subscription"
	ServiceNameAddOnService        = "subscription.addon"
	ServiceNameInvoiceService      = "subscription.invoice"
	ServiceNameUsageService        = "subscription.usage"
	ServiceNamePaymentService      = "subscription.payment"
	ServiceNameCustomerService     = "subscription.customer"
	ServiceNameEnforcementService  = "subscription.enforcement"
	ServiceNameFeatureService      = "subscription.feature"
	ServiceNameFeatureUsageService = "subscription.feature_usage"
	ServiceNameAlertService        = "subscription.alert"
	ServiceNameAnalyticsService    = "subscription.analytics"
	ServiceNameCouponService       = "subscription.coupon"
	ServiceNameCurrencyService     = "subscription.currency"
	ServiceNameTaxService          = "subscription.tax"
	ServiceNameHookRegistry        = "subscription.hook_registry"
)

Service name constants for DI container registration.

Variables ¶

View Source
var (
	// ErrPlanNotFound is returned when a plan is not found.
	ErrPlanNotFound           = errors.ErrPlanNotFound
	ErrPlanAlreadyExists      = errors.ErrPlanAlreadyExists
	ErrPlanNotActive          = errors.ErrPlanNotActive
	ErrPlanHasSubscriptions   = errors.ErrPlanHasSubscriptions
	ErrInvalidPlanSlug        = errors.ErrInvalidPlanSlug
	ErrInvalidBillingPattern  = errors.ErrInvalidBillingPattern
	ErrInvalidBillingInterval = errors.ErrInvalidBillingInterval

	// ErrSubscriptionNotFound is returned when a subscription is not found.
	ErrSubscriptionNotFound      = errors.ErrSubscriptionNotFound
	ErrSubscriptionAlreadyExists = errors.ErrSubscriptionAlreadyExists
	ErrSubscriptionNotActive     = errors.ErrSubscriptionNotActive
	ErrSubscriptionCanceled      = errors.ErrSubscriptionCanceled
	ErrSubscriptionPaused        = errors.ErrSubscriptionPaused
	ErrCannotDowngrade           = errors.ErrCannotDowngrade
	ErrInvalidQuantity           = errors.ErrInvalidQuantity

	// ErrAddOnNotFound is returned when an add-on is not found.
	ErrAddOnNotFound        = errors.ErrAddOnNotFound
	ErrAddOnAlreadyExists   = errors.ErrAddOnAlreadyExists
	ErrAddOnNotActive       = errors.ErrAddOnNotActive
	ErrAddOnNotAvailable    = errors.ErrAddOnNotAvailable
	ErrAddOnAlreadyAttached = errors.ErrAddOnAlreadyAttached
	ErrAddOnNotAttached     = errors.ErrAddOnNotAttached
	ErrAddOnMaxQuantity     = errors.ErrAddOnMaxQuantity

	// ErrInvoiceNotFound is returned when an invoice is not found.
	ErrInvoiceNotFound    = errors.ErrInvoiceNotFound
	ErrInvoiceAlreadyPaid = errors.ErrInvoiceAlreadyPaid
	ErrInvoiceVoided      = errors.ErrInvoiceVoided
	ErrInvoiceNotOpen     = errors.ErrInvoiceNotOpen

	// ErrUsageRecordNotFound is returned when a usage record is not found.
	ErrUsageRecordNotFound  = errors.ErrUsageRecordNotFound
	ErrDuplicateUsageRecord = errors.ErrDuplicateUsageRecord
	ErrInvalidUsageMetric   = errors.ErrInvalidUsageMetric
	ErrInvalidUsageAction   = errors.ErrInvalidUsageAction

	// ErrPaymentMethodNotFound is returned when a payment method is not found.
	ErrPaymentMethodNotFound      = errors.ErrPaymentMethodNotFound
	ErrPaymentMethodRequired      = errors.ErrPaymentMethodRequired
	ErrPaymentMethodExpired       = errors.ErrPaymentMethodExpired
	ErrDefaultPaymentMethodDelete = errors.ErrDefaultPaymentMethodDelete

	// ErrCustomerNotFound is returned when a customer is not found.
	ErrCustomerNotFound      = errors.ErrCustomerNotFound
	ErrCustomerAlreadyExists = errors.ErrCustomerAlreadyExists

	// ErrProviderNotConfigured errors.
	ErrProviderNotConfigured   = errors.ErrProviderNotConfigured
	ErrProviderAPIError        = errors.ErrProviderAPIError
	ErrWebhookSignatureInvalid = errors.ErrWebhookSignatureInvalid
	ErrWebhookEventUnhandled   = errors.ErrWebhookEventUnhandled

	// ErrFeatureLimitExceeded is returned when a feature limit is exceeded.
	ErrFeatureLimitExceeded = errors.ErrFeatureLimitExceeded
	ErrSeatLimitExceeded    = errors.ErrSeatLimitExceeded
	ErrSubscriptionRequired = errors.ErrSubscriptionRequired
	ErrTrialExpired         = errors.ErrTrialExpired

	// ErrInvalidCurrency is returned when currency is invalid.
	ErrInvalidCurrency = errors.ErrInvalidCurrency
	ErrInvalidAppID    = errors.ErrInvalidAppID
	ErrInvalidOrgID    = errors.ErrInvalidOrgID
	ErrUnauthorized    = errors.ErrUnauthorized
)

Re-export domain errors.

View Source
var (
	IsNotFoundError   = errors.IsNotFoundError
	IsValidationError = errors.IsValidationError
	IsConflictError   = errors.IsConflictError
	IsLimitError      = errors.IsLimitError
	IsPaymentError    = errors.IsPaymentError
)

Re-export error helper functions.

View Source
var DefaultConfig = core.DefaultConfig

DefaultConfig returns the default plugin configuration.

View Source
var NewSubscriptionError = errors.New

NewSubscriptionError creates a new subscription error with context.

View Source
var NewSubscriptionHookRegistry = hooks.NewSubscriptionHookRegistry

NewSubscriptionHookRegistry creates a new hook registry.

Functions ¶

func ResolveAddOnService ¶

func ResolveAddOnService(container forge.Container) (*service.AddOnService, error)

ResolveAddOnService resolves the add-on service from the container.

func ResolveAlertService ¶

func ResolveAlertService(container forge.Container) (*service.AlertService, error)

ResolveAlertService resolves the alert service from the container.

func ResolveAnalyticsService ¶

func ResolveAnalyticsService(container forge.Container) (*service.AnalyticsService, error)

ResolveAnalyticsService resolves the analytics service from the container.

func ResolveCouponService ¶

func ResolveCouponService(container forge.Container) (*service.CouponService, error)

ResolveCouponService resolves the coupon service from the container.

func ResolveCurrencyService ¶

func ResolveCurrencyService(container forge.Container) (*service.CurrencyService, error)

ResolveCurrencyService resolves the currency service from the container.

func ResolveCustomerService ¶

func ResolveCustomerService(container forge.Container) (*service.CustomerService, error)

ResolveCustomerService resolves the customer service from the container.

func ResolveEnforcementService ¶

func ResolveEnforcementService(container forge.Container) (*service.EnforcementService, error)

ResolveEnforcementService resolves the enforcement service from the container.

func ResolveFeatureService ¶

func ResolveFeatureService(container forge.Container) (*service.FeatureService, error)

ResolveFeatureService resolves the feature service from the container.

func ResolveFeatureUsageService ¶

func ResolveFeatureUsageService(container forge.Container) (*service.FeatureUsageService, error)

ResolveFeatureUsageService resolves the feature usage service from the container.

func ResolveInvoiceService ¶

func ResolveInvoiceService(container forge.Container) (*service.InvoiceService, error)

ResolveInvoiceService resolves the invoice service from the container.

func ResolvePaymentService ¶

func ResolvePaymentService(container forge.Container) (*service.PaymentService, error)

ResolvePaymentService resolves the payment service from the container.

func ResolvePlanService ¶

func ResolvePlanService(container forge.Container) (*service.PlanService, error)

ResolvePlanService resolves the plan service from the container.

func ResolveSubscriptionService ¶

func ResolveSubscriptionService(container forge.Container) (*service.SubscriptionService, error)

ResolveSubscriptionService resolves the subscription service from the container.

func ResolveTaxService ¶

func ResolveTaxService(container forge.Container) (*service.TaxService, error)

ResolveTaxService resolves the tax service from the container.

func ResolveUsageService ¶

func ResolveUsageService(container forge.Container) (*service.UsageService, error)

ResolveUsageService resolves the usage service from the container.

Types ¶

type AfterAddOnAttachHook ¶

type AfterAddOnAttachHook = hooks.AfterAddOnAttachHook

Re-export hook types for convenience.

type AfterAddOnDetachHook ¶

type AfterAddOnDetachHook = hooks.AfterAddOnDetachHook

Re-export hook types for convenience.

type AfterPlanChangeHook ¶

type AfterPlanChangeHook = hooks.AfterPlanChangeHook

Re-export hook types for convenience.

type AfterSubscriptionCancelHook ¶

type AfterSubscriptionCancelHook = hooks.AfterSubscriptionCancelHook

Re-export hook types for convenience.

type AfterSubscriptionCreateHook ¶

type AfterSubscriptionCreateHook = hooks.AfterSubscriptionCreateHook

Re-export hook types for convenience.

type AfterSubscriptionPauseHook ¶

type AfterSubscriptionPauseHook = hooks.AfterSubscriptionPauseHook

Re-export hook types for convenience.

type AfterSubscriptionResumeHook ¶

type AfterSubscriptionResumeHook = hooks.AfterSubscriptionResumeHook

Re-export hook types for convenience.

type AfterSubscriptionUpdateHook ¶

type AfterSubscriptionUpdateHook = hooks.AfterSubscriptionUpdateHook

Re-export hook types for convenience.

type BeforeAddOnAttachHook ¶

type BeforeAddOnAttachHook = hooks.BeforeAddOnAttachHook

Re-export hook types for convenience.

type BeforeAddOnDetachHook ¶

type BeforeAddOnDetachHook = hooks.BeforeAddOnDetachHook

Re-export hook types for convenience.

type BeforePlanChangeHook ¶

type BeforePlanChangeHook = hooks.BeforePlanChangeHook

Re-export hook types for convenience.

type BeforeSubscriptionCancelHook ¶

type BeforeSubscriptionCancelHook = hooks.BeforeSubscriptionCancelHook

Re-export hook types for convenience.

type BeforeSubscriptionCreateHook ¶

type BeforeSubscriptionCreateHook = hooks.BeforeSubscriptionCreateHook

Re-export hook types for convenience.

type BeforeSubscriptionPauseHook ¶

type BeforeSubscriptionPauseHook = hooks.BeforeSubscriptionPauseHook

Re-export hook types for convenience.

type BeforeSubscriptionResumeHook ¶

type BeforeSubscriptionResumeHook = hooks.BeforeSubscriptionResumeHook

Re-export hook types for convenience.

type BeforeSubscriptionUpdateHook ¶

type BeforeSubscriptionUpdateHook = hooks.BeforeSubscriptionUpdateHook

Re-export hook types for convenience.

type CheckoutRequest ¶

type CheckoutRequest struct {
	CustomerID      string
	PriceID         string
	Quantity        int
	SuccessURL      string
	CancelURL       string
	AllowPromoCodes bool
	TrialDays       int
	Metadata        map[string]any
}

CheckoutRequest for internal use.

type Config ¶

type Config = core.Config

Re-export Config types for convenience.

type DashboardExtension ¶

type DashboardExtension struct {
	// contains filtered or unexported fields
}

DashboardExtension implements ui.DashboardExtension for the subscription plugin.

func NewDashboardExtension ¶

func NewDashboardExtension(plugin *Plugin) *DashboardExtension

NewDashboardExtension creates a new dashboard extension.

func (*DashboardExtension) BridgeFunctions ¶ added in v0.0.15

func (e *DashboardExtension) BridgeFunctions() []ui.BridgeFunction

BridgeFunctions returns bridge functions for the subscription plugin.

func (*DashboardExtension) DashboardWidgets ¶

func (e *DashboardExtension) DashboardWidgets() []ui.DashboardWidget

DashboardWidgets returns dashboard widgets.

func (*DashboardExtension) ExtensionID ¶

func (e *DashboardExtension) ExtensionID() string

ExtensionID returns the unique identifier for this extension.

func (*DashboardExtension) HandleArchivePlan ¶

func (e *DashboardExtension) HandleArchivePlan(ctx *router.PageContext) (g.Node, error)

HandleArchivePlan handles plan archiving (deactivation).

func (*DashboardExtension) HandleCancelSubscription ¶

func (e *DashboardExtension) HandleCancelSubscription(ctx *router.PageContext) (g.Node, error)

HandleCancelSubscription handles subscription cancellation.

func (*DashboardExtension) HandleCreateAddOn ¶

func (e *DashboardExtension) HandleCreateAddOn(ctx *router.PageContext) (g.Node, error)

HandleCreateAddOn handles add-on creation form submission.

func (*DashboardExtension) HandleCreateCoupon ¶

func (e *DashboardExtension) HandleCreateCoupon(ctx *router.PageContext) (g.Node, error)

HandleCreateCoupon handles coupon creation form submission TODO: Implement when couponSvc is added to Plugin.

func (*DashboardExtension) HandleCreateFeature ¶

func (e *DashboardExtension) HandleCreateFeature(ctx *router.PageContext) (g.Node, error)

HandleCreateFeature handles the feature creation form submission.

func (*DashboardExtension) HandleCreatePlan ¶

func (e *DashboardExtension) HandleCreatePlan(ctx *router.PageContext) (g.Node, error)

HandleCreatePlan handles plan creation form submission.

func (*DashboardExtension) HandleDeleteFeature ¶

func (e *DashboardExtension) HandleDeleteFeature(ctx *router.PageContext) (g.Node, error)

HandleDeleteFeature handles feature deletion.

func (*DashboardExtension) HandleDeletePlan ¶

func (e *DashboardExtension) HandleDeletePlan(ctx *router.PageContext) (g.Node, error)

HandleDeletePlan handles permanent plan deletion.

func (*DashboardExtension) HandleExportFeaturesAndPlans ¶ added in v0.0.4

func (e *DashboardExtension) HandleExportFeaturesAndPlans(ctx *router.PageContext) (g.Node, error)

HandleExportFeaturesAndPlans exports features and plans as JSON.

func (*DashboardExtension) HandleImportFeaturesAndPlans ¶ added in v0.0.4

func (e *DashboardExtension) HandleImportFeaturesAndPlans(ctx *router.PageContext) (g.Node, error)

HandleImportFeaturesAndPlans imports features and plans from JSON.

func (*DashboardExtension) HandleLinkFeatureToPlan ¶

func (e *DashboardExtension) HandleLinkFeatureToPlan(ctx *router.PageContext) (g.Node, error)

HandleLinkFeatureToPlan handles linking a feature to a plan.

func (*DashboardExtension) HandleMarkInvoicePaid ¶

func (e *DashboardExtension) HandleMarkInvoicePaid(ctx *router.PageContext) (g.Node, error)

HandleMarkInvoicePaid handles marking an invoice as paid.

func (*DashboardExtension) HandleRemovePaymentMethod ¶ added in v0.0.9

func (e *DashboardExtension) HandleRemovePaymentMethod(ctx *router.PageContext) (g.Node, error)

HandleRemovePaymentMethod removes a payment method via HTMX.

func (*DashboardExtension) HandleSetDefaultPaymentMethod ¶ added in v0.0.9

func (e *DashboardExtension) HandleSetDefaultPaymentMethod(ctx *router.PageContext) (g.Node, error)

HandleSetDefaultPaymentMethod sets a payment method as default via HTMX.

func (*DashboardExtension) HandleShowImportForm ¶ added in v0.0.4

func (e *DashboardExtension) HandleShowImportForm(ctx *router.PageContext) (g.Node, error)

HandleShowImportForm displays the import form page.

func (*DashboardExtension) HandleSyncAllFeaturesFromProvider ¶ added in v0.0.5

func (e *DashboardExtension) HandleSyncAllFeaturesFromProvider(ctx *router.PageContext) (g.Node, error)

HandleSyncAllFeaturesFromProvider syncs all features from the payment provider.

func (*DashboardExtension) HandleSyncAllPlansFromProvider ¶

func (e *DashboardExtension) HandleSyncAllPlansFromProvider(ctx *router.PageContext) (g.Node, error)

HandleSyncAllPlansFromProvider syncs all plans from the payment provider.

func (*DashboardExtension) HandleSyncFeature ¶ added in v0.0.5

func (e *DashboardExtension) HandleSyncFeature(ctx *router.PageContext) (g.Node, error)

HandleSyncFeature handles syncing a feature to the provider.

func (*DashboardExtension) HandleSyncFeatureFromProvider ¶ added in v0.0.5

func (e *DashboardExtension) HandleSyncFeatureFromProvider(ctx *router.PageContext) (g.Node, error)

HandleSyncFeatureFromProvider syncs a feature from the payment provider.

func (*DashboardExtension) HandleSyncInvoices ¶ added in v0.0.6

func (e *DashboardExtension) HandleSyncInvoices(ctx *router.PageContext) (g.Node, error)

HandleSyncInvoices handles syncing invoices from Stripe.

func (*DashboardExtension) HandleSyncPlan ¶

func (e *DashboardExtension) HandleSyncPlan(ctx *router.PageContext) (g.Node, error)

HandleSyncPlan handles syncing a plan to the payment provider.

func (*DashboardExtension) HandleSyncPlanFromProvider ¶

func (e *DashboardExtension) HandleSyncPlanFromProvider(ctx *router.PageContext) (g.Node, error)

HandleSyncPlanFromProvider syncs a single plan from the payment provider.

func (*DashboardExtension) HandleUnlinkFeatureFromPlan ¶

func (e *DashboardExtension) HandleUnlinkFeatureFromPlan(ctx *router.PageContext) (g.Node, error)

HandleUnlinkFeatureFromPlan handles unlinking a feature from a plan.

func (*DashboardExtension) HandleUpdateFeature ¶

func (e *DashboardExtension) HandleUpdateFeature(ctx *router.PageContext) (g.Node, error)

HandleUpdateFeature handles the feature update form submission.

func (*DashboardExtension) HandleUpdatePlan ¶

func (e *DashboardExtension) HandleUpdatePlan(ctx *router.PageContext) (g.Node, error)

HandleUpdatePlan handles plan update form submission.

func (e *DashboardExtension) HandleUpdatePlanFeatureLink(ctx *router.PageContext) (g.Node, error)

HandleUpdatePlanFeatureLink handles updating a feature-plan link.

func (*DashboardExtension) NavigationItems ¶

func (e *DashboardExtension) NavigationItems() []ui.NavigationItem

NavigationItems returns the navigation items for the dashboard.

func (*DashboardExtension) Routes ¶

func (e *DashboardExtension) Routes() []ui.Route

Routes returns the dashboard routes.

func (*DashboardExtension) ServeAddOnCreatePage ¶

func (e *DashboardExtension) ServeAddOnCreatePage(ctx *router.PageContext) (g.Node, error)

ServeAddOnCreatePage renders the add-on creation form.

func (*DashboardExtension) ServeAddOnDetailPage ¶

func (e *DashboardExtension) ServeAddOnDetailPage(ctx *router.PageContext) (g.Node, error)

ServeAddOnDetailPage renders the add-on detail page.

func (*DashboardExtension) ServeAddOnsListPage ¶

func (e *DashboardExtension) ServeAddOnsListPage(ctx *router.PageContext) (g.Node, error)

ServeAddOnsListPage renders the add-ons list page.

func (*DashboardExtension) ServeAddPaymentMethodPage ¶ added in v0.0.9

func (e *DashboardExtension) ServeAddPaymentMethodPage(ctx *router.PageContext) (g.Node, error)

ServeAddPaymentMethodPage renders the add payment method page with Stripe Elements.

func (*DashboardExtension) ServeAlertsListPage ¶

func (e *DashboardExtension) ServeAlertsListPage(ctx *router.PageContext) (g.Node, error)

ServeAlertsListPage renders the alerts list page.

func (*DashboardExtension) ServeAnalyticsDashboardPage ¶

func (e *DashboardExtension) ServeAnalyticsDashboardPage(ctx *router.PageContext) (g.Node, error)

ServeAnalyticsDashboardPage renders the analytics dashboard.

func (*DashboardExtension) ServeBillingOverviewPage ¶

func (e *DashboardExtension) ServeBillingOverviewPage(ctx *router.PageContext) (g.Node, error)

ServeBillingOverviewPage renders the billing overview dashboard.

func (*DashboardExtension) ServeCouponCreatePage ¶

func (e *DashboardExtension) ServeCouponCreatePage(ctx *router.PageContext) (g.Node, error)

ServeCouponCreatePage renders the coupon creation form.

func (*DashboardExtension) ServeCouponsListPage ¶

func (e *DashboardExtension) ServeCouponsListPage(ctx *router.PageContext) (g.Node, error)

ServeCouponsListPage renders the coupons list page.

func (*DashboardExtension) ServeFeatureCreatePage ¶

func (e *DashboardExtension) ServeFeatureCreatePage(ctx *router.PageContext) (g.Node, error)

ServeFeatureCreatePage renders the feature creation form.

func (*DashboardExtension) ServeFeatureDetailPage ¶

func (e *DashboardExtension) ServeFeatureDetailPage(ctx *router.PageContext) (g.Node, error)

ServeFeatureDetailPage renders the feature detail page.

func (*DashboardExtension) ServeFeatureEditPage ¶

func (e *DashboardExtension) ServeFeatureEditPage(ctx *router.PageContext) (g.Node, error)

ServeFeatureEditPage renders the feature edit form.

func (*DashboardExtension) ServeFeatureUsagePage ¶

func (e *DashboardExtension) ServeFeatureUsagePage(ctx *router.PageContext) (g.Node, error)

ServeFeatureUsagePage renders the feature usage monitoring page.

func (*DashboardExtension) ServeFeaturesListPage ¶

func (e *DashboardExtension) ServeFeaturesListPage(ctx *router.PageContext) (g.Node, error)

ServeFeaturesListPage renders the features list dashboard.

func (*DashboardExtension) ServeInvoiceDetailPage ¶

func (e *DashboardExtension) ServeInvoiceDetailPage(ctx *router.PageContext) (g.Node, error)

ServeInvoiceDetailPage renders the invoice detail page.

func (*DashboardExtension) ServeInvoicesListPage ¶

func (e *DashboardExtension) ServeInvoicesListPage(ctx *router.PageContext) (g.Node, error)

ServeInvoicesListPage renders the invoices list page.

func (*DashboardExtension) ServePaymentMethodsPage ¶ added in v0.0.9

func (e *DashboardExtension) ServePaymentMethodsPage(ctx *router.PageContext) (g.Node, error)

ServePaymentMethodsPage renders the payment methods management page.

func (*DashboardExtension) ServePlanCreatePage ¶

func (e *DashboardExtension) ServePlanCreatePage(ctx *router.PageContext) (g.Node, error)

ServePlanCreatePage renders the plan creation form.

func (*DashboardExtension) ServePlanDetailPage ¶

func (e *DashboardExtension) ServePlanDetailPage(ctx *router.PageContext) (g.Node, error)

ServePlanDetailPage renders the plan detail page.

func (*DashboardExtension) ServePlanEditPage ¶

func (e *DashboardExtension) ServePlanEditPage(ctx *router.PageContext) (g.Node, error)

ServePlanEditPage renders the plan edit form.

func (*DashboardExtension) ServePlanFeaturesPage ¶

func (e *DashboardExtension) ServePlanFeaturesPage(ctx *router.PageContext) (g.Node, error)

ServePlanFeaturesPage renders the plan features management page.

func (*DashboardExtension) ServePlansListPage ¶

func (e *DashboardExtension) ServePlansListPage(ctx *router.PageContext) (g.Node, error)

ServePlansListPage renders the plans list page.

func (*DashboardExtension) ServeSettingsPage ¶

func (e *DashboardExtension) ServeSettingsPage(ctx *router.PageContext) (g.Node, error)

ServeSettingsPage renders the subscription settings page.

func (*DashboardExtension) ServeSubscriptionDetailPage ¶

func (e *DashboardExtension) ServeSubscriptionDetailPage(ctx *router.PageContext) (g.Node, error)

ServeSubscriptionDetailPage renders the subscription detail page.

func (*DashboardExtension) ServeSubscriptionsListPage ¶

func (e *DashboardExtension) ServeSubscriptionsListPage(ctx *router.PageContext) (g.Node, error)

ServeSubscriptionsListPage renders the subscriptions list page.

func (*DashboardExtension) ServeUsageDashboardPage ¶

func (e *DashboardExtension) ServeUsageDashboardPage(ctx *router.PageContext) (g.Node, error)

ServeUsageDashboardPage renders the usage dashboard page.

func (*DashboardExtension) SettingsPages ¶

func (e *DashboardExtension) SettingsPages() []ui.SettingsPage

SettingsPages returns settings pages for the plugin.

func (*DashboardExtension) SettingsSections ¶

func (e *DashboardExtension) SettingsSections() []ui.SettingsSection

SettingsSections returns settings sections (deprecated, using SettingsPages instead).

type OnInvoiceCreatedHook ¶

type OnInvoiceCreatedHook = hooks.OnInvoiceCreatedHook

Re-export hook types for convenience.

type OnInvoicePaidHook ¶

type OnInvoicePaidHook = hooks.OnInvoicePaidHook

Re-export hook types for convenience.

type OnPaymentFailedHook ¶

type OnPaymentFailedHook = hooks.OnPaymentFailedHook

Re-export hook types for convenience.

type OnPaymentSuccessHook ¶

type OnPaymentSuccessHook = hooks.OnPaymentSuccessHook

Re-export hook types for convenience.

type OnSubscriptionStatusChangeHook ¶

type OnSubscriptionStatusChangeHook = hooks.OnSubscriptionStatusChangeHook

Re-export hook types for convenience.

type OnTrialEndedHook ¶

type OnTrialEndedHook = hooks.OnTrialEndedHook

Re-export hook types for convenience.

type OnTrialEndingHook ¶

type OnTrialEndingHook = hooks.OnTrialEndingHook

Re-export hook types for convenience.

type OnUsageLimitApproachingHook ¶

type OnUsageLimitApproachingHook = hooks.OnUsageLimitApproachingHook

Re-export hook types for convenience.

type OnUsageLimitExceededHook ¶

type OnUsageLimitExceededHook = hooks.OnUsageLimitExceededHook

Re-export hook types for convenience.

type Plugin ¶

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin implements the subscription plugin for AuthSome.

func NewPlugin ¶

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new subscription plugin instance.

func ResolveSubscriptionPlugin ¶

func ResolveSubscriptionPlugin(container forge.Container) (*Plugin, error)

ResolveSubscriptionPlugin resolves the subscription plugin from the container.

func (*Plugin) DashboardExtension ¶

func (p *Plugin) DashboardExtension() ui.DashboardExtension

DashboardExtension returns the dashboard extension.

func (*Plugin) Dependencies ¶

func (p *Plugin) Dependencies() []string

Dependencies declares the plugin dependencies.

func (*Plugin) GetAddOnService ¶

func (p *Plugin) GetAddOnService() *service.AddOnService

GetAddOnService returns the add-on service.

func (*Plugin) GetAlertService ¶

func (p *Plugin) GetAlertService() *service.AlertService

GetAlertService returns the alert service.

func (*Plugin) GetAnalyticsService ¶

func (p *Plugin) GetAnalyticsService() *service.AnalyticsService

GetAnalyticsService returns the analytics service.

func (*Plugin) GetConfig ¶

func (p *Plugin) GetConfig() Config

GetConfig returns the plugin configuration.

func (*Plugin) GetCouponService ¶

func (p *Plugin) GetCouponService() *service.CouponService

GetCouponService returns the coupon service.

func (*Plugin) GetCurrencyService ¶

func (p *Plugin) GetCurrencyService() *service.CurrencyService

GetCurrencyService returns the currency service.

func (*Plugin) GetCustomerService ¶

func (p *Plugin) GetCustomerService() *service.CustomerService

GetCustomerService returns the customer service.

func (*Plugin) GetEnforcementService ¶

func (p *Plugin) GetEnforcementService() *service.EnforcementService

GetEnforcementService returns the enforcement service.

func (*Plugin) GetExportImportService ¶ added in v0.0.4

func (p *Plugin) GetExportImportService() *service.ExportImportService

GetExportImportService returns the export/import service.

func (*Plugin) GetFeatureService ¶

func (p *Plugin) GetFeatureService() *service.FeatureService

GetFeatureService returns the feature service.

func (*Plugin) GetFeatureUsageService ¶

func (p *Plugin) GetFeatureUsageService() *service.FeatureUsageService

GetFeatureUsageService returns the feature usage service.

func (*Plugin) GetHookRegistry ¶

func (p *Plugin) GetHookRegistry() *SubscriptionHookRegistry

GetHookRegistry returns the subscription hook registry.

func (*Plugin) GetInvoiceService ¶

func (p *Plugin) GetInvoiceService() *service.InvoiceService

GetInvoiceService returns the invoice service.

func (*Plugin) GetPaymentService ¶

func (p *Plugin) GetPaymentService() *service.PaymentService

GetPaymentService returns the payment service.

func (*Plugin) GetPlanService ¶

func (p *Plugin) GetPlanService() *service.PlanService

GetPlanService returns the plan service.

func (*Plugin) GetProvider ¶ added in v0.0.15

func (p *Plugin) GetProvider() providers.PaymentProvider

GetProvider returns the payment provider.

func (*Plugin) GetServices ¶

func (p *Plugin) GetServices() map[string]any

GetServices returns a map of all available services for inspection.

func (*Plugin) GetSubscriptionService ¶

func (p *Plugin) GetSubscriptionService() *service.SubscriptionService

GetSubscriptionService returns the subscription service.

func (*Plugin) GetTaxService ¶

func (p *Plugin) GetTaxService() *service.TaxService

GetTaxService returns the tax service.

func (*Plugin) GetUsageService ¶

func (p *Plugin) GetUsageService() *service.UsageService

GetUsageService returns the usage service.

func (*Plugin) ID ¶

func (p *Plugin) ID() string

ID returns the unique identifier for this plugin.

func (*Plugin) Init ¶

func (p *Plugin) Init(authInstance core.Authsome) error

Init initializes the plugin with dependencies.

func (*Plugin) Migrate ¶

func (p *Plugin) Migrate() error

Migrate runs database migrations for the subscription plugin.

func (*Plugin) RegisterHooks ¶

func (p *Plugin) RegisterHooks(hooks *hooks.HookRegistry) error

RegisterHooks registers hooks for the subscription plugin.

func (*Plugin) RegisterRoles ¶

func (p *Plugin) RegisterRoles(reg any) error

RegisterRoles implements the PluginWithRoles interface.

func (*Plugin) RegisterRoutes ¶

func (p *Plugin) RegisterRoutes(router forge.Router) error

RegisterRoutes registers the plugin's HTTP routes.

func (*Plugin) RegisterServiceDecorators ¶

func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error

RegisterServiceDecorators registers service decorators.

func (*Plugin) RegisterServices ¶

func (p *Plugin) RegisterServices(container forge.Container) error

RegisterServices registers all subscription services in the DI container Uses vessel.ProvideConstructor for type-safe, constructor-based dependency injection.

func (*Plugin) SyncInvoicesFromStripe ¶ added in v0.0.6

func (p *Plugin) SyncInvoicesFromStripe(ctx context.Context, subID *xid.ID) (int, error)

SyncInvoicesFromStripe syncs invoices from Stripe to the local database (exported for dashboard use).

type PluginOption ¶

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the plugin.

func WithAutoSyncPlans ¶

func WithAutoSyncPlans(enabled bool) PluginOption

WithAutoSyncPlans enables automatic plan synchronization to payment provider on create/update.

func WithAutoSyncSeats ¶

func WithAutoSyncSeats(enabled bool) PluginOption

WithAutoSyncSeats enables automatic seat synchronization.

func WithDefaultConfig ¶

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin.

func WithDefaultTrialDays ¶

func WithDefaultTrialDays(days int) PluginOption

WithDefaultTrialDays sets the default trial days.

func WithGracePeriodDays ¶

func WithGracePeriodDays(days int) PluginOption

WithGracePeriodDays sets the grace period for failed payments.

func WithProvider ¶ added in v0.0.15

func WithProvider(provider providers.PaymentProvider) PluginOption

WithProvider sets a custom payment provider implementation This allows users to inject their own provider instead of using Stripe or mock provider.

func WithRequireSubscription ¶

func WithRequireSubscription(required bool) PluginOption

WithRequireSubscription sets whether subscription is required for org creation.

func WithStripeConfig ¶

func WithStripeConfig(secretKey, webhookSecret, publishableKey string) PluginOption

WithStripeConfig sets the Stripe configuration.

type StripeConfig ¶

type StripeConfig = core.StripeConfig

Re-export Config types for convenience.

type SubscriptionError ¶

type SubscriptionError = errors.SubscriptionError

SubscriptionError is the subscription error type.

type SubscriptionHookRegistry ¶

type SubscriptionHookRegistry = hooks.SubscriptionHookRegistry

Re-export hook types for convenience.

func ResolveSubscriptionHookRegistry ¶

func ResolveSubscriptionHookRegistry(container forge.Container) (*SubscriptionHookRegistry, error)

ResolveSubscriptionHookRegistry resolves the subscription hook registry from the container.

Directories ¶

Path Synopsis
Package core defines the core domain types for the subscription plugin.
Package core defines the core domain types for the subscription plugin.
Package errors defines domain errors for the subscription plugin.
Package errors defines domain errors for the subscription plugin.
Package handlers provides HTTP handlers for the subscription plugin.
Package handlers provides HTTP handlers for the subscription plugin.
internal
hooks
Package hooks provides subscription-specific hook types and registry.
Package hooks provides subscription-specific hook types and registry.
Package migrations provides migration utilities for the subscription plugin.
Package migrations provides migration utilities for the subscription plugin.
Package providers defines the payment provider abstraction for the subscription plugin.
Package providers defines the payment provider abstraction for the subscription plugin.
mock
Package mock provides a mock payment provider for testing.
Package mock provides a mock payment provider for testing.
paddle
Package paddle provides a stub implementation of the PaymentProvider interface for Paddle.
Package paddle provides a stub implementation of the PaymentProvider interface for Paddle.
paypal
Package paypal provides a stub implementation of the PaymentProvider interface for PayPal.
Package paypal provides a stub implementation of the PaymentProvider interface for PayPal.
stripe
Package stripe provides Stripe payment provider implementation.
Package stripe provides Stripe payment provider implementation.
types
Package types defines shared types for payment providers.
Package types defines shared types for payment providers.
Package repository provides data access interfaces and implementations for the subscription plugin.
Package repository provides data access interfaces and implementations for the subscription plugin.
Package schema defines the database models for the subscription plugin.
Package schema defines the database models for the subscription plugin.
Package service provides business logic services for the subscription plugin.
Package service provides business logic services for the subscription plugin.
Package ui provides Pine UI components for the subscription plugin dashboard
Package ui provides Pine UI components for the subscription plugin dashboard

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL