taxcode

package
v1.0.0-beta.229 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AnnotationKeyManagedBy indicates what created/owns this tax code.
	AnnotationKeyManagedBy = "managed_by"

	// AnnotationValueManagedBySystem is set when the tax code was auto-created
	// by the system (e.g. via GetOrCreateByAppMapping).
	AnnotationValueManagedBySystem = "system"
)
View Source
const ErrCodeAppTypesMustBeUnique models.ErrorCode = "app_types_must_be_unique"
View Source
const ErrCodeOrganizationDefaultTaxCodesNotFound models.ErrorCode = "organization_default_tax_codes_not_found"
View Source
const ErrCodeResourceIDEmpty models.ErrorCode = "resource_id_empty"
View Source
const ErrCodeResourceKeyEmpty models.ErrorCode = "resource_key_empty"
View Source
const ErrCodeResourceNameEmpty models.ErrorCode = "resource_name_empty"
View Source
const ErrCodeResourceNamespaceEmpty models.ErrorCode = "resource_namespace_empty"
View Source
const ErrCodeTaxCodeEmpty models.ErrorCode = "tax_code_empty"
View Source
const ErrCodeTaxCodeIsOrganizationDefault models.ErrorCode = "tax_code_is_organization_default"
View Source
const ErrCodeTaxCodeManagedBySystem models.ErrorCode = "tax_code_managed_by_system"
View Source
const ErrCodeTaxCodeNotFound models.ErrorCode = "tax_code_not_found"
View Source
const ErrCodeTaxCodeStripeInvalid models.ErrorCode = "tax_code_stripe_invalid"

Variables

View Source
var ErrOrganizationDefaultTaxCodesNotFound = models.NewValidationIssue(
	ErrCodeOrganizationDefaultTaxCodesNotFound,
	"organization default tax codes not found",
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusNotFound),
)
View Source
var ErrTaxCodeIsOrganizationDefault = models.NewValidationIssue(
	ErrCodeTaxCodeIsOrganizationDefault,
	"tax code is set as an organization default and cannot be deleted",
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusConflict),
)
View Source
var ErrTaxCodeManagedBySystem = models.NewValidationIssue(
	ErrCodeTaxCodeManagedBySystem,
	"tax code is managed by the system and cannot be modified or deleted",
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusConflict),
)
View Source
var ErrTaxCodeOrphanedKey = errors.New("tax code key exists but app mapping is orphaned")

ErrTaxCodeOrphanedKey is returned by GetOrCreateByAppMapping when a key derived from the Stripe code already exists but no longer carries that app mapping (the mapping was changed after the key was auto-created). The typed error prevents a raw constraint error from poisoning the pg transaction (25P02).

View Source
var ErrTaxCodeStripeInvalid = models.NewValidationIssue(
	ErrCodeTaxCodeStripeInvalid,
	"stripe tax code must be in the format of txcd_12345678",
	models.WithFieldString("app_mappings"),
	models.WithCriticalSeverity(),
	commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest),
)
View Source
var OrganizationDefaultTaxCodesExpandAll = OrganizationDefaultTaxCodesExpand{
	InvoicingTaxCode:   true,
	CreditGrantTaxCode: true,
}

OrganizationDefaultTaxCodesExpandAll loads all related objects.

View Source
var TaxCodeStripeRegexp = regexp.MustCompile(`^txcd_\d{8}$`)

Functions

func IsOrganizationDefaultTaxCodesNotFoundError

func IsOrganizationDefaultTaxCodesNotFoundError(err error) bool

func IsTaxCodeIsOrganizationDefaultError

func IsTaxCodeIsOrganizationDefaultError(err error) bool

func IsTaxCodeNotFoundError

func IsTaxCodeNotFoundError(err error) bool

func IsTaxCodeOrphanedKeyError

func IsTaxCodeOrphanedKeyError(err error) bool

func NewOrganizationDefaultTaxCodesNotFoundError

func NewOrganizationDefaultTaxCodesNotFoundError(namespace string) error

func NewTaxCodeByAppMappingNotFoundError

func NewTaxCodeByAppMappingNotFoundError(appType, taxCode string) error

func NewTaxCodeNotFoundError

func NewTaxCodeNotFoundError(id string) error

Types

type CreateTaxCodeInput

type CreateTaxCodeInput struct {
	Namespace   string
	Key         string
	Name        string
	Description *string
	AppMappings TaxCodeAppMappings
	Metadata    models.Metadata
	Annotations models.Annotations
}

func (CreateTaxCodeInput) Validate

func (i CreateTaxCodeInput) Validate() error

type DeleteTaxCodeInput

type DeleteTaxCodeInput struct {
	models.NamespacedID
	// contains filtered or unexported fields
}

func (DeleteTaxCodeInput) Validate

func (i DeleteTaxCodeInput) Validate() error

type GetOrCreateByAppMappingInput

type GetOrCreateByAppMappingInput struct {
	Namespace string
	AppType   app.AppType
	TaxCode   string
}

func (GetOrCreateByAppMappingInput) Validate

func (i GetOrCreateByAppMappingInput) Validate() error

type GetOrganizationDefaultTaxCodesInput

type GetOrganizationDefaultTaxCodesInput struct {
	Namespace string
	Expand    OrganizationDefaultTaxCodesExpand
}

func (GetOrganizationDefaultTaxCodesInput) Validate

type GetTaxCodeByAppMappingInput

type GetTaxCodeByAppMappingInput struct {
	Namespace string
	AppType   app.AppType
	TaxCode   string
}

func (GetTaxCodeByAppMappingInput) Validate

func (i GetTaxCodeByAppMappingInput) Validate() error

type GetTaxCodeInput

type GetTaxCodeInput struct {
	models.NamespacedID

	// IncludeDeleted controls whether soft-deleted records are returned.
	// Only for internal service-to-service use; never set from API handlers.
	IncludeDeleted bool
}

func (GetTaxCodeInput) Validate

func (i GetTaxCodeInput) Validate() error

type ListTaxCodesInput

type ListTaxCodesInput struct {
	Namespace string
	pagination.Page

	IncludeDeleted bool
}

func (ListTaxCodesInput) Validate

func (i ListTaxCodesInput) Validate() error

type NamespaceHandler

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

NamespaceHandler implements namespace.Handler for the taxcode domain.

func NewNamespaceHandler

func NewNamespaceHandler(cfg NamespaceHandlerConfig) (*NamespaceHandler, error)

NewNamespaceHandler creates a *NamespaceHandler that seeds tax codes and org defaults when a new namespace is provisioned.

func (*NamespaceHandler) CreateNamespace

func (h *NamespaceHandler) CreateNamespace(ctx context.Context, ns string) error

CreateNamespace provisions the configured seed tax codes and sets the per-namespace OrganizationDefaultTaxCodes. The operation is idempotent: pre-existing tax codes are left unchanged and a pre-existing org-defaults row skips the org-defaults upsert (seed creation always runs regardless). All seed creates and the org-defaults upsert run inside a single transaction.

func (*NamespaceHandler) DeleteNamespace

func (h *NamespaceHandler) DeleteNamespace(_ context.Context, _ string) error

DeleteNamespace is a no-op; tax codes belong to the namespace and are cleaned up by the database cascade or a dedicated purge job.

type NamespaceHandlerConfig

type NamespaceHandlerConfig struct {
	Logger             *slog.Logger
	Service            Service
	Seeds              []SeedEntry
	TransactionManager transaction.Creator
}

NamespaceHandlerConfig holds the dependencies for the taxcode namespace handler.

type OrganizationDefaultTaxCodes

type OrganizationDefaultTaxCodes struct {
	models.NamespacedID
	models.ManagedModel

	InvoicingTaxCodeID string   `json:"invoicing_tax_code_id"`
	InvoicingTaxCode   *TaxCode `json:"invoicing_tax_code,omitempty"`

	CreditGrantTaxCodeID string   `json:"credit_grant_tax_code_id"`
	CreditGrantTaxCode   *TaxCode `json:"credit_grant_tax_code,omitempty"`
}

OrganizationDefaultTaxCodes stores the per-namespace default tax code references.

func (OrganizationDefaultTaxCodes) Validate

func (o OrganizationDefaultTaxCodes) Validate() error

type OrganizationDefaultTaxCodesExpand

type OrganizationDefaultTaxCodesExpand struct {
	InvoicingTaxCode   bool
	CreditGrantTaxCode bool
}

OrganizationDefaultTaxCodesExpand controls which related objects are loaded.

type OrganizationDefaultTaxCodesService

type OrganizationDefaultTaxCodesService interface {
	GetOrganizationDefaultTaxCodes(ctx context.Context, input GetOrganizationDefaultTaxCodesInput) (OrganizationDefaultTaxCodes, error)
	UpsertOrganizationDefaultTaxCodes(ctx context.Context, input UpsertOrganizationDefaultTaxCodesInput) (OrganizationDefaultTaxCodes, error)
}

type Repository

type Repository interface {
	entutils.TxCreator

	CreateTaxCode(ctx context.Context, input CreateTaxCodeInput) (TaxCode, error)
	UpdateTaxCode(ctx context.Context, input UpdateTaxCodeInput) (TaxCode, error)
	ListTaxCodes(ctx context.Context, input ListTaxCodesInput) (pagination.Result[TaxCode], error)
	GetTaxCode(ctx context.Context, input GetTaxCodeInput) (TaxCode, error)
	GetTaxCodeByAppMapping(ctx context.Context, input GetTaxCodeByAppMappingInput) (TaxCode, error)
	DeleteTaxCode(ctx context.Context, input DeleteTaxCodeInput) error

	GetOrganizationDefaultTaxCodes(ctx context.Context, input GetOrganizationDefaultTaxCodesInput) (OrganizationDefaultTaxCodes, error)
	UpsertOrganizationDefaultTaxCodes(ctx context.Context, input UpsertOrganizationDefaultTaxCodesInput) (OrganizationDefaultTaxCodes, error)
}

type SeedEntry

type SeedEntry struct {
	Key                string
	Name               string
	Description        *string
	AppMappings        TaxCodeAppMappings
	DefaultInvoicing   bool
	DefaultCreditGrant bool
}

SeedEntry defines a tax code that should be provisioned for every namespace.

type TaxCode

type TaxCode struct {
	models.NamespacedID
	models.ManagedModel

	// Key is the unique key for TaxCode.
	Key string `json:"key"`

	// Name is the display name for TaxCode.
	Name string `json:"name"`

	// Description is the description for TaxCode.
	Description *string `json:"description,omitempty"`

	// AppMappings is the mapping of app types to tax codes.
	AppMappings TaxCodeAppMappings `json:"app_mappings"`

	// Metadata
	Metadata models.Metadata `json:"metadata,omitempty"`

	// Annotations are system-managed key/value pairs stored alongside the tax code.
	Annotations models.Annotations `json:"annotations,omitempty"`
}

TaxCode represents a tax code with mappings to app types.

func (*TaxCode) Equal

func (t *TaxCode) Equal(v *TaxCode) bool

Equal returns true when both TaxCode values carry identical semantic data. Compares ID, Namespace, Key, Name, Description, and AppMappings. ManagedModel timestamps, Metadata, and Annotations are excluded.

func (TaxCode) GetAppMapping

func (t TaxCode) GetAppMapping(appType app.AppType) (TaxCodeAppMapping, bool)

GetAppMapping returns the app mapping for the given app type, if it exists.

func (TaxCode) IsManagedBySystem

func (t TaxCode) IsManagedBySystem() bool

IsManagedBySystem returns true when this tax code was auto-created by the system.

func (TaxCode) Validate

func (t TaxCode) Validate() error

type TaxCodeAppMapping

type TaxCodeAppMapping struct {
	AppType app.AppType `json:"app_type"`
	TaxCode string      `json:"tax_code"`
}

TaxCodeAppMapping represents a mapping of an app type to a tax code.

func (TaxCodeAppMapping) Validate

func (t TaxCodeAppMapping) Validate() error

type TaxCodeAppMappings

type TaxCodeAppMappings []TaxCodeAppMapping

TaxCodeAppMappings is a list of TaxCodeAppMapping.

func (TaxCodeAppMappings) Validate

func (t TaxCodeAppMappings) Validate() error

type TaxCodeService

type TaxCodeService interface {
	CreateTaxCode(ctx context.Context, input CreateTaxCodeInput) (TaxCode, error)
	UpdateTaxCode(ctx context.Context, input UpdateTaxCodeInput) (TaxCode, error)
	ListTaxCodes(ctx context.Context, input ListTaxCodesInput) (pagination.Result[TaxCode], error)
	GetTaxCode(ctx context.Context, input GetTaxCodeInput) (TaxCode, error)
	GetTaxCodeByAppMapping(ctx context.Context, input GetTaxCodeByAppMappingInput) (TaxCode, error)
	GetOrCreateByAppMapping(ctx context.Context, input GetOrCreateByAppMappingInput) (TaxCode, error)
	DeleteTaxCode(ctx context.Context, input DeleteTaxCodeInput) error
}

type UpdateTaxCodeInput

type UpdateTaxCodeInput struct {
	models.NamespacedID

	Name        string
	Description *string
	AppMappings TaxCodeAppMappings
	Metadata    models.Metadata
	Annotations models.Annotations
	// contains filtered or unexported fields
}

func (UpdateTaxCodeInput) Validate

func (i UpdateTaxCodeInput) Validate() error

type UpsertOrganizationDefaultTaxCodesInput

type UpsertOrganizationDefaultTaxCodesInput struct {
	Namespace            string
	InvoicingTaxCodeID   string
	CreditGrantTaxCodeID string
	Expand               OrganizationDefaultTaxCodesExpand
}

func (UpsertOrganizationDefaultTaxCodesInput) Validate

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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