Documentation
¶
Index ¶
- Constants
- Variables
- func IsOrganizationDefaultTaxCodesNotFoundError(err error) bool
- func IsTaxCodeIsOrganizationDefaultError(err error) bool
- func IsTaxCodeNotFoundError(err error) bool
- func IsTaxCodeOrphanedKeyError(err error) bool
- func NewOrganizationDefaultTaxCodesNotFoundError(namespace string) error
- func NewTaxCodeByAppMappingNotFoundError(appType, taxCode string) error
- func NewTaxCodeByKeyNotFoundError(key string) error
- func NewTaxCodeNotFoundError(id string) error
- type CreateTaxCodeInput
- type DeleteTaxCodeInput
- type GetOrCreateByAppMappingInput
- type GetOrganizationDefaultTaxCodesInput
- type GetTaxCodeByAppMappingInput
- type GetTaxCodeByKeyInput
- type GetTaxCodeInput
- type ListTaxCodesInput
- type NamespaceHandler
- type NamespaceHandlerConfig
- type OrganizationDefaultTaxCodes
- type OrganizationDefaultTaxCodesExpand
- type OrganizationDefaultTaxCodesService
- type Repository
- type SeedEntry
- type Service
- type TaxCode
- type TaxCodeAppMapping
- type TaxCodeAppMappings
- type TaxCodeService
- type UpdateTaxCodeInput
- type UpsertOrganizationDefaultTaxCodesInput
Constants ¶
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" )
const ErrCodeAppTypesMustBeUnique models.ErrorCode = "app_types_must_be_unique"
const ErrCodeOrganizationDefaultTaxCodesNotFound models.ErrorCode = "organization_default_tax_codes_not_found"
const ErrCodeResourceIDEmpty models.ErrorCode = "resource_id_empty"
const ErrCodeResourceKeyEmpty models.ErrorCode = "resource_key_empty"
const ErrCodeResourceNameEmpty models.ErrorCode = "resource_name_empty"
const ErrCodeResourceNamespaceEmpty models.ErrorCode = "resource_namespace_empty"
const ErrCodeTaxCodeEmpty models.ErrorCode = "tax_code_empty"
const ErrCodeTaxCodeIsOrganizationDefault models.ErrorCode = "tax_code_is_organization_default"
const ErrCodeTaxCodeManagedBySystem models.ErrorCode = "tax_code_managed_by_system"
const ErrCodeTaxCodeNotFound models.ErrorCode = "tax_code_not_found"
const ErrCodeTaxCodeStripeInvalid models.ErrorCode = "tax_code_stripe_invalid"
const ProviderDefaultTaxCodeKey = "default"
Variables ¶
var ErrAppTypesMustBeUnique = models.NewValidationIssue( ErrCodeAppTypesMustBeUnique, "app types must be unique", models.WithFieldString("app_mappings"), models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest), )
var ErrOrganizationDefaultTaxCodesNotFound = models.NewValidationIssue( ErrCodeOrganizationDefaultTaxCodesNotFound, "organization default tax codes not found", models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusNotFound), )
var ErrResourceIDEmpty = models.NewValidationIssue( ErrCodeResourceIDEmpty, "id must not be empty", models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest), )
var ErrResourceKeyEmpty = models.NewValidationIssue( ErrCodeResourceKeyEmpty, "key must not be empty", models.WithFieldString("key"), models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest), )
var ErrResourceNameEmpty = models.NewValidationIssue( ErrCodeResourceNameEmpty, "name must not be empty", models.WithFieldString("name"), models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest), )
var ErrResourceNamespaceEmpty = models.NewValidationIssue( ErrCodeResourceNamespaceEmpty, "namespace must not be empty", models.WithFieldString("namespace"), models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest), )
var ErrTaxCodeEmpty = models.NewValidationIssue( ErrCodeTaxCodeEmpty, "tax code cannot be empty", models.WithFieldString("app_mappings"), models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusBadRequest), )
var ErrTaxCodeIsOrganizationDefault = models.NewValidationIssue( ErrCodeTaxCodeIsOrganizationDefault, "tax code is set as an organization default and cannot be deleted", models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusConflict), )
var ErrTaxCodeManagedBySystem = models.NewValidationIssue( ErrCodeTaxCodeManagedBySystem, "tax code is managed by the system and cannot be modified or deleted", models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusConflict), )
var ErrTaxCodeNotFound = models.NewValidationIssue( ErrCodeTaxCodeNotFound, "tax code not found", models.WithCriticalSeverity(), commonhttp.WithHTTPStatusCodeAttribute(http.StatusNotFound), )
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).
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), )
var OrganizationDefaultTaxCodesExpandAll = OrganizationDefaultTaxCodesExpand{ InvoicingTaxCode: true, CreditGrantTaxCode: true, }
OrganizationDefaultTaxCodesExpandAll loads all related objects.
var TaxCodeStripeRegexp = regexp.MustCompile(`^txcd_\d{8}$`)
Functions ¶
func IsTaxCodeNotFoundError ¶
func NewTaxCodeNotFoundError ¶
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 ¶
func (GetOrCreateByAppMappingInput) Validate ¶
func (i GetOrCreateByAppMappingInput) Validate() error
type GetOrganizationDefaultTaxCodesInput ¶
type GetOrganizationDefaultTaxCodesInput struct {
Namespace string
Expand OrganizationDefaultTaxCodesExpand
}
func (GetOrganizationDefaultTaxCodesInput) Validate ¶
func (i GetOrganizationDefaultTaxCodesInput) Validate() error
type GetTaxCodeByAppMappingInput ¶
func (GetTaxCodeByAppMappingInput) Validate ¶
func (i GetTaxCodeByAppMappingInput) Validate() error
type GetTaxCodeByKeyInput ¶
func (GetTaxCodeByKeyInput) Validate ¶
func (i GetTaxCodeByKeyInput) 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 ¶
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)
GetTaxCodeByKey(ctx context.Context, input GetTaxCodeByKeyInput) (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 Service ¶
type Service interface {
TaxCodeService
OrganizationDefaultTaxCodesService
}
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 ¶
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 ¶
IsManagedBySystem returns true when this tax code was auto-created by the system.
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)
GetTaxCodeByKey(ctx context.Context, input GetTaxCodeByKeyInput) (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 ¶
func (i UpsertOrganizationDefaultTaxCodesInput) Validate() error