credit

package
v1.42.21 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package credit provides reusable starter credit logic. Shared between api/billing handlers and middleware/iammiddleware.

Index

Constants

View Source
const (
	StarterCreditCents = 500 // $5.00 USD
	StarterCreditDays  = 30  // expires in 30 days
	StarterCreditTag   = "starter-credit"
)

Starter credit constants.

Variables

This section is empty.

Functions

func GrantIfEligible

func GrantIfEligible(db *datastore.Datastore, userId, trigger string)

GrantIfEligible checks if the user already has a starter credit and grants one if not. It is idempotent: duplicate calls for the same user are safe. The trigger parameter records what initiated the grant (e.g. "payment-method-added", "org-created").

The check-and-create runs inside a transaction to prevent race conditions where concurrent goroutines could both pass the existence check and grant duplicate credits.

This function is intended to be called from a goroutine; it only logs on failure and never panics.

Types

This section is empty.

Jump to

Keyboard shortcuts

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