couponredemption

package
v1.49.21 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package couponredemption is the once-per-user redemption guard for coupons.

Each CouponRedemption is one immutable fact: "user U redeemed coupon C". The storage id is DeterministicID(couponCode, userId) and the model registers WithStringKey, so a second redeem by the same user for the same coupon resolves to the SAME row via the backend ON CONFLICT(id, kind, namespace) upsert — the guard cannot be bypassed.

This replaces a guard that queried the credit grant by Tags="coupon:CODE" while the grant was written Tags="promo,coupon:CODE": the datastore Tags= filter is exact-string, so it never matched and the same user re-minted a fresh spendable grant on every submit. A structured redemption record, keyed by (code, user), makes the check exact and forgery-proof.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeterministicID

func DeterministicID(couponCode, userId string) string

DeterministicID derives the stable storage id for a (couponCode, userId) pair. Same inputs → same id → ON CONFLICT dedup at the storage layer. Prefixed so the id is human-recognizable in logs/audits.

func Query

Types

type CouponRedemption

type CouponRedemption struct {
	mixin.Model[CouponRedemption]

	CouponCode string `json:"couponCode"`
	UserId     string `json:"userId"`
}

CouponRedemption records that a user redeemed a coupon. One row per (CouponCode, UserId); the deterministic id makes a duplicate submit a no-op replay rather than a second mint.

func New

func (*CouponRedemption) Load

func (r *CouponRedemption) Load(ps []datastore.Property) error

func (*CouponRedemption) Save

func (r *CouponRedemption) Save() ([]datastore.Property, error)

Jump to

Keyboard shortcuts

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