subscription

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 36 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
  • 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),
)

// 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}

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 (
	// Plan errors
	ErrPlanNotFound           = errors.ErrPlanNotFound
	ErrPlanAlreadyExists      = errors.ErrPlanAlreadyExists
	ErrPlanNotActive          = errors.ErrPlanNotActive
	ErrPlanHasSubscriptions   = errors.ErrPlanHasSubscriptions
	ErrInvalidPlanSlug        = errors.ErrInvalidPlanSlug
	ErrInvalidBillingPattern  = errors.ErrInvalidBillingPattern
	ErrInvalidBillingInterval = errors.ErrInvalidBillingInterval

	// Subscription errors
	ErrSubscriptionNotFound      = errors.ErrSubscriptionNotFound
	ErrSubscriptionAlreadyExists = errors.ErrSubscriptionAlreadyExists
	ErrSubscriptionNotActive     = errors.ErrSubscriptionNotActive
	ErrSubscriptionCanceled      = errors.ErrSubscriptionCanceled
	ErrSubscriptionPaused        = errors.ErrSubscriptionPaused
	ErrCannotDowngrade           = errors.ErrCannotDowngrade
	ErrInvalidQuantity           = errors.ErrInvalidQuantity

	// Add-on errors
	ErrAddOnNotFound        = errors.ErrAddOnNotFound
	ErrAddOnAlreadyExists   = errors.ErrAddOnAlreadyExists
	ErrAddOnNotActive       = errors.ErrAddOnNotActive
	ErrAddOnNotAvailable    = errors.ErrAddOnNotAvailable
	ErrAddOnAlreadyAttached = errors.ErrAddOnAlreadyAttached
	ErrAddOnNotAttached     = errors.ErrAddOnNotAttached
	ErrAddOnMaxQuantity     = errors.ErrAddOnMaxQuantity

	// Invoice errors
	ErrInvoiceNotFound    = errors.ErrInvoiceNotFound
	ErrInvoiceAlreadyPaid = errors.ErrInvoiceAlreadyPaid
	ErrInvoiceVoided      = errors.ErrInvoiceVoided
	ErrInvoiceNotOpen     = errors.ErrInvoiceNotOpen

	// Usage errors
	ErrUsageRecordNotFound  = errors.ErrUsageRecordNotFound
	ErrDuplicateUsageRecord = errors.ErrDuplicateUsageRecord
	ErrInvalidUsageMetric   = errors.ErrInvalidUsageMetric
	ErrInvalidUsageAction   = errors.ErrInvalidUsageAction

	// Payment method errors
	ErrPaymentMethodNotFound      = errors.ErrPaymentMethodNotFound
	ErrPaymentMethodRequired      = errors.ErrPaymentMethodRequired
	ErrPaymentMethodExpired       = errors.ErrPaymentMethodExpired
	ErrDefaultPaymentMethodDelete = errors.ErrDefaultPaymentMethodDelete

	// Customer errors
	ErrCustomerNotFound      = errors.ErrCustomerNotFound
	ErrCustomerAlreadyExists = errors.ErrCustomerAlreadyExists

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

	// Feature/limit errors
	ErrFeatureLimitExceeded = errors.ErrFeatureLimitExceeded
	ErrSeatLimitExceeded    = errors.ErrSeatLimitExceeded
	ErrSubscriptionRequired = errors.ErrSubscriptionRequired
	ErrTrialExpired         = errors.ErrTrialExpired

	// General errors
	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]interface{}
}

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) 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(c forge.Context) error

HandleArchivePlan handles plan archiving (deactivation)

func (*DashboardExtension) HandleCancelSubscription ¶

func (e *DashboardExtension) HandleCancelSubscription(c forge.Context) error

HandleCancelSubscription handles subscription cancellation

func (*DashboardExtension) HandleCreateAddOn ¶

func (e *DashboardExtension) HandleCreateAddOn(c forge.Context) error

HandleCreateAddOn handles add-on creation form submission

func (*DashboardExtension) HandleCreateCoupon ¶

func (e *DashboardExtension) HandleCreateCoupon(c forge.Context) error

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

func (*DashboardExtension) HandleCreateFeature ¶

func (e *DashboardExtension) HandleCreateFeature(c forge.Context) error

HandleCreateFeature handles the feature creation form submission

func (*DashboardExtension) HandleCreatePlan ¶

func (e *DashboardExtension) HandleCreatePlan(c forge.Context) error

HandleCreatePlan handles plan creation form submission

func (*DashboardExtension) HandleDeleteFeature ¶

func (e *DashboardExtension) HandleDeleteFeature(c forge.Context) error

HandleDeleteFeature handles feature deletion

func (*DashboardExtension) HandleDeletePlan ¶

func (e *DashboardExtension) HandleDeletePlan(c forge.Context) error

HandleDeletePlan handles permanent plan deletion

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

func (e *DashboardExtension) HandleExportFeaturesAndPlans(c forge.Context) error

HandleExportFeaturesAndPlans exports features and plans as JSON

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

func (e *DashboardExtension) HandleImportFeaturesAndPlans(c forge.Context) error

HandleImportFeaturesAndPlans imports features and plans from JSON

func (*DashboardExtension) HandleLinkFeatureToPlan ¶

func (e *DashboardExtension) HandleLinkFeatureToPlan(c forge.Context) error

HandleLinkFeatureToPlan handles linking a feature to a plan

func (*DashboardExtension) HandleMarkInvoicePaid ¶

func (e *DashboardExtension) HandleMarkInvoicePaid(c forge.Context) error

HandleMarkInvoicePaid handles marking an invoice as paid

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

func (e *DashboardExtension) HandleRemovePaymentMethod(c forge.Context) error

HandleRemovePaymentMethod removes a payment method via HTMX

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

func (e *DashboardExtension) HandleSetDefaultPaymentMethod(c forge.Context) error

HandleSetDefaultPaymentMethod sets a payment method as default via HTMX

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

func (e *DashboardExtension) HandleShowImportForm(c forge.Context) error

HandleShowImportForm displays the import form page

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

func (e *DashboardExtension) HandleSyncAllFeaturesFromProvider(c forge.Context) error

HandleSyncAllFeaturesFromProvider syncs all features from the payment provider

func (*DashboardExtension) HandleSyncAllPlansFromProvider ¶

func (e *DashboardExtension) HandleSyncAllPlansFromProvider(c forge.Context) error

HandleSyncAllPlansFromProvider syncs all plans from the payment provider

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

func (e *DashboardExtension) HandleSyncFeature(c forge.Context) error

HandleSyncFeature handles syncing a feature to the provider

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

func (e *DashboardExtension) HandleSyncFeatureFromProvider(c forge.Context) error

HandleSyncFeatureFromProvider syncs a feature from the payment provider

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

func (e *DashboardExtension) HandleSyncInvoices(c forge.Context) error

HandleSyncInvoices handles syncing invoices from Stripe

func (*DashboardExtension) HandleSyncPlan ¶

func (e *DashboardExtension) HandleSyncPlan(c forge.Context) error

HandleSyncPlan handles syncing a plan to the payment provider

func (*DashboardExtension) HandleSyncPlanFromProvider ¶

func (e *DashboardExtension) HandleSyncPlanFromProvider(c forge.Context) error

HandleSyncPlanFromProvider syncs a single plan from the payment provider

func (*DashboardExtension) HandleUnlinkFeatureFromPlan ¶

func (e *DashboardExtension) HandleUnlinkFeatureFromPlan(c forge.Context) error

HandleUnlinkFeatureFromPlan handles unlinking a feature from a plan

func (*DashboardExtension) HandleUpdateFeature ¶

func (e *DashboardExtension) HandleUpdateFeature(c forge.Context) error

HandleUpdateFeature handles the feature update form submission

func (*DashboardExtension) HandleUpdatePlan ¶

func (e *DashboardExtension) HandleUpdatePlan(c forge.Context) error

HandleUpdatePlan handles plan update form submission

func (e *DashboardExtension) HandleUpdatePlanFeatureLink(c forge.Context) 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(c forge.Context) error

ServeAddOnCreatePage renders the add-on creation form

func (*DashboardExtension) ServeAddOnDetailPage ¶

func (e *DashboardExtension) ServeAddOnDetailPage(c forge.Context) error

ServeAddOnDetailPage renders the add-on detail page

func (*DashboardExtension) ServeAddOnsListPage ¶

func (e *DashboardExtension) ServeAddOnsListPage(c forge.Context) error

ServeAddOnsListPage renders the add-ons list page

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

func (e *DashboardExtension) ServeAddPaymentMethodPage(c forge.Context) error

ServeAddPaymentMethodPage renders the add payment method page with Stripe Elements

func (*DashboardExtension) ServeAlertsListPage ¶

func (e *DashboardExtension) ServeAlertsListPage(c forge.Context) error

ServeAlertsListPage renders the alerts list page

func (*DashboardExtension) ServeAnalyticsDashboardPage ¶

func (e *DashboardExtension) ServeAnalyticsDashboardPage(c forge.Context) error

ServeAnalyticsDashboardPage renders the analytics dashboard

func (*DashboardExtension) ServeBillingOverviewPage ¶

func (e *DashboardExtension) ServeBillingOverviewPage(c forge.Context) error

ServeBillingOverviewPage renders the billing overview dashboard

func (*DashboardExtension) ServeCouponCreatePage ¶

func (e *DashboardExtension) ServeCouponCreatePage(c forge.Context) error

ServeCouponCreatePage renders the coupon creation form

func (*DashboardExtension) ServeCouponsListPage ¶

func (e *DashboardExtension) ServeCouponsListPage(c forge.Context) error

ServeCouponsListPage renders the coupons list page

func (*DashboardExtension) ServeFeatureCreatePage ¶

func (e *DashboardExtension) ServeFeatureCreatePage(c forge.Context) error

ServeFeatureCreatePage renders the feature creation form

func (*DashboardExtension) ServeFeatureDetailPage ¶

func (e *DashboardExtension) ServeFeatureDetailPage(c forge.Context) error

ServeFeatureDetailPage renders the feature detail page

func (*DashboardExtension) ServeFeatureEditPage ¶

func (e *DashboardExtension) ServeFeatureEditPage(c forge.Context) error

ServeFeatureEditPage renders the feature edit form

func (*DashboardExtension) ServeFeatureUsagePage ¶

func (e *DashboardExtension) ServeFeatureUsagePage(c forge.Context) error

ServeFeatureUsagePage renders the feature usage monitoring page

func (*DashboardExtension) ServeFeaturesListPage ¶

func (e *DashboardExtension) ServeFeaturesListPage(c forge.Context) error

ServeFeaturesListPage renders the features list dashboard

func (*DashboardExtension) ServeInvoiceDetailPage ¶

func (e *DashboardExtension) ServeInvoiceDetailPage(c forge.Context) error

ServeInvoiceDetailPage renders the invoice detail page

func (*DashboardExtension) ServeInvoicesListPage ¶

func (e *DashboardExtension) ServeInvoicesListPage(c forge.Context) error

ServeInvoicesListPage renders the invoices list page

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

func (e *DashboardExtension) ServePaymentMethodsPage(c forge.Context) error

ServePaymentMethodsPage renders the payment methods management page

func (*DashboardExtension) ServePlanCreatePage ¶

func (e *DashboardExtension) ServePlanCreatePage(c forge.Context) error

ServePlanCreatePage renders the plan creation form

func (*DashboardExtension) ServePlanDetailPage ¶

func (e *DashboardExtension) ServePlanDetailPage(c forge.Context) error

ServePlanDetailPage renders the plan detail page

func (*DashboardExtension) ServePlanEditPage ¶

func (e *DashboardExtension) ServePlanEditPage(c forge.Context) error

ServePlanEditPage renders the plan edit form

func (*DashboardExtension) ServePlanFeaturesPage ¶

func (e *DashboardExtension) ServePlanFeaturesPage(c forge.Context) error

ServePlanFeaturesPage renders the plan features management page

func (*DashboardExtension) ServePlansListPage ¶

func (e *DashboardExtension) ServePlansListPage(c forge.Context) error

ServePlansListPage renders the plans list page

func (*DashboardExtension) ServeSettingsPage ¶

func (e *DashboardExtension) ServeSettingsPage(c forge.Context) error

Settings Page

func (*DashboardExtension) ServeSubscriptionDetailPage ¶

func (e *DashboardExtension) ServeSubscriptionDetailPage(c forge.Context) error

ServeSubscriptionDetailPage renders the subscription detail page

func (*DashboardExtension) ServeSubscriptionsListPage ¶

func (e *DashboardExtension) ServeSubscriptionsListPage(c forge.Context) error

ServeSubscriptionsListPage renders the subscriptions list page

func (*DashboardExtension) ServeUsageDashboardPage ¶

func (e *DashboardExtension) ServeUsageDashboardPage(c forge.Context) error

ServeUsageDashboardPage renders the usage dashboard page

func (*DashboardExtension) SetRegistry ¶

func (e *DashboardExtension) SetRegistry(registry *dashboard.ExtensionRegistry)

SetRegistry sets the extension registry reference (called by dashboard after registration)

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) GetServices ¶

func (p *Plugin) GetServices() map[string]interface{}

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 interface{}) 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

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 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

Re-export error types for convenience

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