Documentation
¶
Overview ¶
Copyright 2026 Sneat.co
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Copyright 2026 Sneat.co ¶
Package checkout4datatug is the DataTug side of the shared Sneat checkout: the Paymentus ports that turn paid subscriptions into DataTug plans, the account-reconciliation sweep, the readiness check, the Business space-service checkout, usage-invoice composition and the isolated TEST checkout profile. Hosts wire it; they keep only environment reading, the Paymentus mount and the database. A host that takes payments calls ConfigureAccountCheckout and ConfigureSignedEvents on its subscriptions.Config and mounts BusinessLiveCheckoutHandler or BusinessTestCheckoutHandler; a host that only reads entitlements calls NewBusinessCurrentSubscriptionReader.
Environment of the read-only Business reader ¶
BusinessReaderConfigFromEnv reads exactly these variables and needs no Stripe publishable key and no webhook secret:
LIVE: DATATUG_BUSINESS_LIVE_CHECKOUT_ENABLED=1, STRIPE_SECRET_KEY_LIVE,
DATATUG_BUSINESS_STRIPE_LIVE_ACCOUNT_ID, DATATUG_BUSINESS_STRIPE_LIVE_COUPON_ID
TEST: DATATUG_STRIPE_TEST_PREVIEW=1, DATATUG_BUSINESS_TEST_CHECKOUT_ENABLED=1,
STRIPE_SECRET_KEY_TEST, DATATUG_BUSINESS_STRIPE_TEST_ACCOUNT_ID,
DATATUG_BUSINESS_STRIPE_TEST_COUPON_ID
The checkout host's own environment (publishable keys, webhook secrets, DATATUG_PRO_CHECKOUT_ENABLED, DATATUG_PRO_CHECKOUT_PLANS, DATATUG_PERSONAL_PLAN_SETTINGS_JSON, DATATUG_BUSINESS_USAGE_ENABLED, DATATUG_BUSINESS_STRIPE_LIVE_PRODUCT_ID and the TEST profile variables) is unchanged by the move into this package.
Copyright 2026 Sneat.co
Index ¶
- Constants
- Variables
- func BusinessLiveCheckoutEnabled() (bool, error)
- func BusinessLiveCheckoutHandler(db dal.DB) (http.Handler, error)
- func BusinessProjectAccessOptions(db dal.DB) (facade4datatug.BusinessSharedProjectOptions, error)
- func BusinessTestAdmissionEnabled() bool
- func BusinessTestAdmissionIssuerReady() bool
- func BusinessTestCheckoutEnabled() bool
- func BusinessTestCheckoutHandler(db dal.DB) (http.Handler, error)
- func BusinessUsageRuntime(db dal.DB) (*facade4datatug.BusinessUsageRuntime, error)
- func ConfigureAccountCheckout(db dal.DB, cfg *subscriptions.Config) error
- func ConfigureBusinessTestAdmission(db dal.DB) error
- func ConfigureSignedEvents(db dal.DB, cfg *subscriptions.Config) error
- func ConfiguredBusinessTestAdmissionConfig() subscriptions.TestServiceAdmissionIssuerConfig
- func ConfiguredBusinessTestCouponID() (string, error)
- func EnabledProPlans(value string) map[string]bool
- func IssueBusinessTestAdmission(ctx context.Context) error
- func NewBusinessCurrentSubscriptionAccess(db dal.DB, cfg BusinessReaderConfig) (*subscriptions.PurchaseSpaceReader, ...)
- func NewBusinessCurrentSubscriptionReader(db dal.DB, cfg BusinessReaderConfig) (*subscriptions.PurchaseSpaceReader, error)
- func ReviewedCheckoutSettings(plans map[string]bool) bool
- func SetBusinessTestAdmissionConfig(config subscriptions.TestServiceAdmissionIssuerConfig)
- func SetBusinessTestAdmissionIssuer(issuer *subscriptions.TestServiceAdmissionIssuer)
- func Sweep(ctx context.Context, now time.Time, db dal.DB, cfg subscriptions.Config) (any, error)
- func TestPreviewBusinessPlanIDs() []string
- func TestPreviewBuyerUID() string
- func TestPreviewEnabled() bool
- func TestPreviewProPlanIDs() []string
- func TestPreviewSignedEventScope(uid string) subscriptions.SignedEventScope
- type AccountSweep
- type AccountSweepReport
- type BusinessReaderConfig
- type ProCheckoutReadinessReason
- type TestBuyerAuthenticator
Constants ¶
const ( // BusinessLiveCheckoutEnabledEnv arms the Business LIVE checkout: empty or // "0" leaves it closed, "1" arms it. BusinessLiveCheckoutEnabledEnv = "DATATUG_BUSINESS_LIVE_CHECKOUT_ENABLED" // BusinessLiveAccountEnv holds the fixed LIVE Stripe account ID (acct_...). BusinessLiveAccountEnv = "DATATUG_BUSINESS_STRIPE_LIVE_ACCOUNT_ID" // BusinessLiveCouponEnv holds the LIVE Stripe coupon ID of the founding offer. BusinessLiveCouponEnv = "DATATUG_BUSINESS_STRIPE_LIVE_COUPON_ID" )
const ( // BusinessTestAccountEnv holds the fixed TEST Stripe account ID (acct_...). BusinessTestAccountEnv = "DATATUG_BUSINESS_STRIPE_TEST_ACCOUNT_ID" // BusinessTestCouponEnv holds the TEST Stripe coupon ID of the founding offer. BusinessTestCouponEnv = "DATATUG_BUSINESS_STRIPE_TEST_COUPON_ID" // BusinessServicePrefix is the path prefix, under the checkout mount, of the // Business space-service checkout. BusinessServicePrefix = "/space-service" // BusinessTestAdmissionTaskKey is the delayer key of IssueBusinessTestAdmission. BusinessTestAdmissionTaskKey = "IssueBusinessTestAdmission" )
const ( // BusinessUsageEnabledEnv arms the Business usage runtime: empty or "0" // leaves it closed, "1" arms it. BusinessUsageEnabledEnv = "DATATUG_BUSINESS_USAGE_ENABLED" // BusinessUsageLiveProductEnv holds the LIVE Stripe product ID of Business usage. BusinessUsageLiveProductEnv = "DATATUG_BUSINESS_STRIPE_LIVE_PRODUCT_ID" )
const ( AccountCheckoutArmEnv = "DATATUG_PRO_CHECKOUT_ENABLED" AccountPlansEnv = "DATATUG_PRO_CHECKOUT_PLANS" )
const ( // TestPreviewEnv opts a process into the isolated TEST checkout profile. TestPreviewEnv = "DATATUG_STRIPE_TEST_PREVIEW" // TestBuyerEnv names the one Firebase UID allowed to buy in the profile. TestBuyerEnv = "DATATUG_TEST_CHECKOUT_BUYER_UID" // TestOrigin is the local DataTug site origin of the TEST profile. TestOrigin = "http://datatug.localhost:4328" // TestPublicOrigin is the public DataTug site origin. TestPublicOrigin = "https://datatug.io" // TestAppOrigin is the DataTug app origin. TestAppOrigin = "https://datatug.app" // BusinessTestArmEnv arms the Business TEST checkout inside the profile. BusinessTestArmEnv = "DATATUG_BUSINESS_TEST_CHECKOUT_ENABLED" )
The isolated DataTug TEST checkout profile is a process-level deployment choice. These environment names, origins and plan lists are shared by the checkout composition in this package and by the host that validates and mounts the TEST profile.
Variables ¶
var ErrAccountSweepRetry = errors.New("DataTug account reconciliation has retryable work")
ErrAccountSweepRetry reports that the sweep left retryable work behind.
Functions ¶
func BusinessProjectAccessOptions ¶
func BusinessProjectAccessOptions(db dal.DB) (facade4datatug.BusinessSharedProjectOptions, error)
BusinessProjectAccessOptions supplies the same mode-pinned native current owner authority used by checkout to the DataTug route composition. Empty configuration deliberately leaves the existing Pro-only service selected.
func BusinessTestAdmissionEnabled ¶
func BusinessTestAdmissionEnabled() bool
BusinessTestAdmissionEnabled reports whether the admission exercise is armed.
func BusinessTestAdmissionIssuerReady ¶
func BusinessTestAdmissionIssuerReady() bool
BusinessTestAdmissionIssuerReady reports whether the admission issuer has been constructed by ConfigureBusinessTestAdmission.
func BusinessTestCheckoutEnabled ¶
func BusinessTestCheckoutEnabled() bool
BusinessTestCheckoutEnabled reports whether the isolated TEST process armed the Business TEST checkout.
func BusinessTestCheckoutHandler ¶
BusinessTestCheckoutHandler creates a handler only on the isolated TEST process with its separate arm. It performs no provider request at startup.
func BusinessUsageRuntime ¶
func BusinessUsageRuntime(db dal.DB) (*facade4datatug.BusinessUsageRuntime, error)
BusinessUsageRuntime composes the owning modules only after explicit server activation. Checkout alone never arms activity intake or invoice collection.
func ConfigureAccountCheckout ¶
func ConfigureAccountCheckout(db dal.DB, cfg *subscriptions.Config) error
ConfigureAccountCheckout adds the DataTug account-checkout ports to the shared Paymentus checkout configuration: the personal Pro plan writer and reconciliation, and, when armed, the Business account checkout. The legacy entitlement store, provisioner, mode keys and other storefronts remain the caller's values.
func ConfigureBusinessTestAdmission ¶
ConfigureBusinessTestAdmission constructs the released Paymentus issuer after the shared DAL provider is initialized. All evidence policy and the transaction that records the fact remain inside Paymentus.
func ConfigureSignedEvents ¶
func ConfigureSignedEvents(db dal.DB, cfg *subscriptions.Config) error
ConfigureSignedEvents binds the Business TEST (only on the isolated TEST process) and LIVE receipt and signed-event rails to the checkout configuration. The caller must have configured the money ports first, because the rails reuse them.
func ConfiguredBusinessTestAdmissionConfig ¶
func ConfiguredBusinessTestAdmissionConfig() subscriptions.TestServiceAdmissionIssuerConfig
ConfiguredBusinessTestAdmissionConfig returns the stored admission facts.
func EnabledProPlans ¶
func IssueBusinessTestAdmission ¶
IssueBusinessTestAdmission is a zero-argument Cloud Tasks worker. Its reviewed Space, buyer and inventory facts are frozen at startup.
func NewBusinessCurrentSubscriptionAccess ¶
func NewBusinessCurrentSubscriptionAccess(db dal.DB, cfg BusinessReaderConfig) (*subscriptions.PurchaseSpaceReader, facade4datatug.BusinessSpaceEvidenceEnsurer, error)
NewBusinessCurrentSubscriptionAccess composes a provider-free reader and a separate bounded, GET-only evidence capability. Construction performs no database or provider reads; explicit authorized commands invoke the ensurer.
func NewBusinessCurrentSubscriptionReader ¶
func NewBusinessCurrentSubscriptionReader(db dal.DB, cfg BusinessReaderConfig) (*subscriptions.PurchaseSpaceReader, error)
NewBusinessCurrentSubscriptionReader returns the read-only reader of a Space's current Business subscription for hosts that do not take payments. It performs no provider request at construction and never mounts a checkout route or webhook. Every value is validated before any client is built.
func SetBusinessTestAdmissionConfig ¶
func SetBusinessTestAdmissionConfig(config subscriptions.TestServiceAdmissionIssuerConfig)
SetBusinessTestAdmissionConfig stores the startup-validated admission exercise facts, or the zero value to clear them.
func SetBusinessTestAdmissionIssuer ¶
func SetBusinessTestAdmissionIssuer(issuer *subscriptions.TestServiceAdmissionIssuer)
SetBusinessTestAdmissionIssuer replaces the admission issuer; hosts clear it at startup.
func Sweep ¶
Sweep retries bounded DataTug checkout work for the given database and the checkout configuration the host built for its HTTP route, so the sweep and the route share one composition. It constructs a provider client but makes no provider request unless a configured mode has durable work to reconcile.
func TestPreviewBusinessPlanIDs ¶
func TestPreviewBusinessPlanIDs() []string
TestPreviewBusinessPlanIDs lists the Business plans sold by the TEST profile.
func TestPreviewBuyerUID ¶
func TestPreviewBuyerUID() string
TestPreviewBuyerUID returns the startup-validated Firebase UID for the isolated test service. It is never derived from a request or email alias.
func TestPreviewEnabled ¶
func TestPreviewEnabled() bool
TestPreviewEnabled is a process-level deployment choice, never a request parameter. The shared production service leaves it unset.
func TestPreviewProPlanIDs ¶
func TestPreviewProPlanIDs() []string
TestPreviewProPlanIDs lists the personal Pro plans sold by the TEST profile.
func TestPreviewSignedEventScope ¶
func TestPreviewSignedEventScope(uid string) subscriptions.SignedEventScope
TestPreviewSignedEventScope is the signed-event scope of the TEST profile for the given buyer UID.
Types ¶
type AccountSweep ¶
type AccountSweep struct {
// contains filtered or unexported fields
}
AccountSweep carries only an opaque, process-local scan cursor. The durable Paymentus collections remain the source of work after a restart.
func (*AccountSweep) Run ¶
func (s *AccountSweep) Run(ctx context.Context, now time.Time, db dal.DB, cfg subscriptions.Config, gateway func(subscriptions.Mode, subscriptions.Keys) subscriptions.StripeGateway) (AccountSweepReport, error)
Run scans the durable Paymentus reconciliation work of each mode and tries to finish it with the gateway that gatewayFor returns for the mode; a nil gateway leaves provider-reading work retryable.
type AccountSweepReport ¶
type AccountSweepReport struct {
ConfiguredModes int `json:"configuredModes"`
ScannedPages int `json:"scannedPages"`
Attempted int `json:"attempted"`
Retryable int `json:"retryable"`
BusinessRefreshPages int `json:"businessRefreshPages"`
BusinessRefreshAttempted int `json:"businessRefreshAttempted"`
BusinessRefreshRetryable int `json:"businessRefreshRetryable"`
BusinessUsage *facade4datatug.BusinessUsageLifecycleResult `json:"businessUsage,omitempty"`
}
AccountSweepReport counts what one account-reconciliation sweep scanned, attempted and left retryable. It is the JSON result of the cron route.
type BusinessReaderConfig ¶
type BusinessReaderConfig struct {
// Mode is subscriptions.ModeLive or subscriptions.ModeTest.
Mode subscriptions.Mode
// SecretKey is the Stripe secret key: sk_live_... for LIVE, sk_test_... for TEST.
SecretKey string
// AccountID is the fixed Stripe account ID (acct_...) of the mode.
AccountID string
// CouponID is the Stripe coupon ID of the founding offer in the mode.
CouponID string
}
BusinessReaderConfig is everything the read-only Business current subscription reader needs. Unlike the checkout host it does not need the Stripe publishable key or the webhook secret, because the reader never opens a checkout session and never receives a webhook.
func BusinessReaderConfigFromEnv ¶
func BusinessReaderConfigFromEnv() (cfg BusinessReaderConfig, armed bool, err error)
BusinessReaderConfigFromEnv reads the reader configuration from the process environment. armed is false, with no error, when neither Business arm is set.
The environment variables it reads:
LIVE: DATATUG_BUSINESS_LIVE_CHECKOUT_ENABLED=1, STRIPE_SECRET_KEY_LIVE,
DATATUG_BUSINESS_STRIPE_LIVE_ACCOUNT_ID, DATATUG_BUSINESS_STRIPE_LIVE_COUPON_ID
TEST: DATATUG_STRIPE_TEST_PREVIEW=1, DATATUG_BUSINESS_TEST_CHECKOUT_ENABLED=1,
STRIPE_SECRET_KEY_TEST, DATATUG_BUSINESS_STRIPE_TEST_ACCOUNT_ID,
DATATUG_BUSINESS_STRIPE_TEST_COUPON_ID
Arming both modes, or the LIVE arm inside the isolated TEST preview profile, is a configuration error. The values themselves are validated by NewBusinessCurrentSubscriptionReader.
type ProCheckoutReadinessReason ¶
type ProCheckoutReadinessReason string
ProCheckoutReadinessReason contains only a safe, stable configuration outcome. It never includes environment-variable or provider values.
const ( ProCheckoutReadinessDisabled ProCheckoutReadinessReason = "disabled" ProCheckoutReadinessReady ProCheckoutReadinessReason = "ready" ProCheckoutReadinessPlanAllowlistMissing ProCheckoutReadinessReason = "plan_allowlist_missing" ProCheckoutReadinessPlanAllowlistInvalid ProCheckoutReadinessReason = "plan_allowlist_invalid" ProCheckoutReadinessPlanSettingsMissing ProCheckoutReadinessReason = "plan_settings_missing" ProCheckoutReadinessPlanSettingsInvalid ProCheckoutReadinessReason = "plan_settings_invalid" ProCheckoutReadinessPlanSettingsUnversioned ProCheckoutReadinessReason = "plan_settings_unversioned" ProCheckoutReadinessPlanConfigInvalid ProCheckoutReadinessReason = "plan_config_invalid" ProCheckoutReadinessCataloguePolicyMismatch ProCheckoutReadinessReason = "catalogue_policy_mismatch" )
func DataTugProCheckoutReadiness ¶
func DataTugProCheckoutReadiness() ProCheckoutReadinessReason
DataTugProCheckoutReadiness reports the same startup configuration decision used to arm account checkout, without exposing the underlying values.
type TestBuyerAuthenticator ¶
type TestBuyerAuthenticator struct {
Delegate subscriptions.CheckoutAuthenticator
UID string
}
TestBuyerAuthenticator adds one deployment-owned UID restriction after the normal Firebase token verification. An email alias never selects the buyer.
func (TestBuyerAuthenticator) AuthenticateCheckout ¶
func (a TestBuyerAuthenticator) AuthenticateCheckout(ctx context.Context, token string) (subscriptions.BuyerIdentity, error)
AuthenticateCheckout implements subscriptions.CheckoutAuthenticator.