billing

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BillingHistoryEntry

type BillingHistoryEntry struct {
	ID            int64                   `json:"id"`
	ActionType    model.BillingActionType `json:"action_type"`
	AmountSeconds int64                   `json:"amount_seconds"`
	BalanceAfter  int64                   `json:"balance_after"`
	Description   string                  `json:"description"`
	JobUUID       *string                 `json:"job_uuid,omitempty"`
	CreatedAt     string                  `json:"created_at"`
}

BillingHistoryEntry is a billing history entry returned to the frontend.

type CreateOrderInput

type CreateOrderInput struct {
	ProductName string `json:"product_name"`
	Provider    string `json:"provider"`
}

CreateOrderInput is the input for creating an order.

type EntitlementInfo

type EntitlementInfo struct {
	ID                 int64                   `json:"id"`
	SourceType         model.EntitlementType   `json:"source_type"`
	TotalSeconds       int64                   `json:"total_seconds"`
	UsedSeconds        int64                   `json:"used_seconds"`
	AvailableSeconds   int64                   `json:"available_seconds"`
	ValidFrom          string                  `json:"valid_from"`
	ValidUntil         *string                 `json:"valid_until,omitempty"`
	Status             model.EntitlementStatus `json:"status"`
	CasdoorProductName string                  `json:"casdoor_product_name"`
	DisplayName        string                  `json:"display_name"`
	CreatedAt          string                  `json:"created_at"`
}

EntitlementInfo is the entitlement info returned to the frontend.

type EntitlementService

type EntitlementService interface {
	GetWallet(ctx context.Context, userID string) (*UserWalletInfo, error)
	ListEntitlements(ctx context.Context, userID string, limit, offset int) ([]EntitlementInfo, int64, error)
	FreezeForTask(ctx context.Context, userID string, taskRef string, requiredSeconds int64) error
	ConsumeTask(ctx context.Context, taskRef string) error
	UnfreezeTask(ctx context.Context, taskRef string) error
	GrantEntitlement(ctx context.Context, userID string, productName string, orderID int64) (*model.UserEntitlement, error)
	GetBillingHistory(ctx context.Context, userID string, limit, offset int) ([]BillingHistoryEntry, int64, error)
}

EntitlementService manages user entitlements and billing.

func NewEntitlementService

func NewEntitlementService(billingRepo repo.BillingRepository, cfg *config.EntitlementConfig) EntitlementService

NewEntitlementService creates an entitlement service.

type OrderHistory

type OrderHistory struct {
	OrderID     string     `json:"order_id"`
	ProductName string     `json:"product_name"`
	DisplayName string     `json:"display_name"`
	Price       float64    `json:"price"`
	Currency    string     `json:"currency"`
	Status      string     `json:"status"`
	CreatedAt   time.Time  `json:"created_at"`
	PaidAt      *time.Time `json:"paid_at,omitempty"`
}

OrderHistory is an order history entry.

type OrderSyncResult

type OrderSyncResult struct {
	OrderStatus  string `json:"order_status"`
	QuotaSeconds int64  `json:"quota_seconds"`
	Message      string `json:"message"`
}

OrderSyncResult is the result of an order sync.

type PaymentResult

type PaymentResult struct {
	OrderID    string  `json:"order_id"`
	PaymentURL string  `json:"payment_url"`
	Amount     float64 `json:"amount"`
	Currency   string  `json:"currency"`
}

PaymentResult is the result of a payment initiation.

type PaymentService

type PaymentService interface {
	GetProducts(ctx context.Context, userID string) ([]ProductWithEntitlement, error)
	CreateOrder(ctx context.Context, userID string, req *CreateOrderInput) (*PaymentResult, error)
	GetOrders(ctx context.Context, userID string, limit, offset int) ([]OrderHistory, int64, error)
	CancelOrder(ctx context.Context, userID string, orderName string) error
	PayOrder(ctx context.Context, userID string, orderName string, provider string) (*PaymentResult, error)
	HandlePaymentCallback(ctx context.Context, orderName string) error
	SyncOrder(ctx context.Context, userID string, orderName string) (*OrderSyncResult, error)
}

PaymentService handles payment and order operations.

func NewPaymentService

func NewPaymentService(
	casdoorClient *casdoor.Client,
	authService authz.AuthService,
	entitlementRepo repo.BillingRepository,
	entitlementService EntitlementService,
) PaymentService

NewPaymentService creates a payment service.

type ProductWithEntitlement

type ProductWithEntitlement struct {
	Name            string   `json:"name"`
	DisplayName     string   `json:"display_name"`
	Description     string   `json:"description"`
	Image           string   `json:"image"`
	Price           float64  `json:"price"`
	Currency        string   `json:"currency"`
	IsRecharge      bool     `json:"is_recharge"`
	Providers       []string `json:"providers"`
	QuotaSeconds    int64    `json:"quota_seconds"`
	EntitlementType string   `json:"entitlement_type"`
	PeriodMonths    int      `json:"period_months"`
	State           string   `json:"state"`
}

ProductWithEntitlement combines Casdoor product with local entitlement info.

type UserWalletInfo

type UserWalletInfo struct {
	TotalSeconds      int64 `json:"total_seconds"`
	FrozenSeconds     int64 `json:"frozen_seconds"`
	AvailableSeconds  int64 `json:"available_seconds"`
	EntitlementsCount int   `json:"entitlements_count"`
}

UserWalletInfo is the wallet info returned to the frontend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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