billing

package
v0.0.0-...-7ad5d0e Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCreditsFromPurchase

func AddCreditsFromPurchase(ctx context.Context, queries *db.Queries, params CreditPackPurchaseParams, log *logger.Logger) (*db.CreditBalance, error)

AddCreditsFromPurchase adds credits to an organization's balance from a credit pack purchase This is the core business logic for credit purchases, used by webhooks

func EnsureCreditBalance

func EnsureCreditBalance(ctx context.Context, orgUID uuid.UUID, queries *db.Queries) (*db.CreditBalance, error)

EnsureCreditBalance gets or creates a credit balance for an organization

func GetOrCreateSubscriptionRecord

func GetOrCreateSubscriptionRecord(ctx context.Context, queries *db.Queries, params SubscriptionRecordParams, log *logger.Logger) (*db.OrganizationSubscription, error)

GetOrCreateSubscriptionRecord gets an existing subscription or creates a new one

Types

type CheckoutSessionConfig

type CheckoutSessionConfig struct {
	CustomerID           string
	Mode                 stripe.CheckoutSessionMode
	LineItems            []*stripe.CheckoutSessionCreateLineItemParams
	Metadata             map[string]string
	SubscriptionMetadata map[string]string // Only for subscription mode
}

CheckoutSessionConfig holds configuration for creating a Stripe checkout session

type CreditPackPurchaseParams

type CreditPackPurchaseParams struct {
	OrganizationUID uuid.UUID
	PackUID         uuid.UUID
	Credits         int64
	SessionID       string // Stripe checkout session ID for transaction record
}

CreditPackPurchaseParams holds parameters for processing a credit pack purchase

type StripeClient

type StripeClient struct {
	Client *stripe.Client
	Config *config.StripeConfig
}

StripeClient wraps the Stripe client API

func NewStripeClient

func NewStripeClient(cfg *config.StripeConfig) *StripeClient

NewStripeClient creates a new Stripe client

func (*StripeClient) CreateCheckoutSession

func (c *StripeClient) CreateCheckoutSession(ctx context.Context, sessionConfig CheckoutSessionConfig) (*stripe.CheckoutSession, error)

CreateCheckoutSession creates a Stripe checkout session with the given configuration It uses the URLs from the config for success and cancel redirects

func (*StripeClient) EnsureStripeCustomer

func (c *StripeClient) EnsureStripeCustomer(ctx context.Context, org *db.Organization, queries *db.Queries, log *logger.Logger) (string, error)

EnsureStripeCustomer gets or creates a Stripe customer for an organization

type SubscriptionRecordParams

type SubscriptionRecordParams struct {
	OrganizationUID      uuid.UUID
	PlanUID              uuid.UUID
	StripeSubscriptionID string
	Status               string
	BillingInterval      string
	Seats                int32
	CurrentPeriodStart   pgtype.Timestamptz
	CurrentPeriodEnd     pgtype.Timestamptz
}

SubscriptionRecordParams holds parameters for creating a subscription record

type WebhookHandler

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

WebhookHandler processes Stripe webhook events

func NewWebhookHandler

func NewWebhookHandler(cfg *config.StripeConfig, log *logger.Logger) *WebhookHandler

NewWebhookHandler creates a new webhook handler with event routing

func (*WebhookHandler) HandleStripeWebhook

func (h *WebhookHandler) HandleStripeWebhook(ctx context.Context, payload []byte, signature string) (success bool, message string, err error)

HandleStripeWebhook processes a Stripe webhook event It handles signature verification, idempotency checking, event routing, and recording

Jump to

Keyboard shortcuts

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