feat(payments): add gift card system v2 with management, expiry, inventory, audit log

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-11 22:08:18 +01:00
co-authored by Sisyphus
parent 6756723c60
commit 30ded0bb95
7 changed files with 1479 additions and 69 deletions
+4 -4
View File
@@ -248,7 +248,7 @@ func CreateTerminalPayment(w http.ResponseWriter, r *http.Request) {
}
// Deduct directly from card remaining amount
_, err = tx.Exec(r.Context(), "UPDATE gift_cards SET amount_remaining = amount_remaining - $1 WHERE id = $2", amountPounds, cleanCardID)
_, err = tx.Exec(r.Context(), "UPDATE gift_cards SET amount_remaining = amount_remaining - $1, last_used_at = NOW() WHERE id = $2", amountPounds, cleanCardID)
if err != nil {
log.Printf("Failed to deduct gift card amount: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -366,7 +366,7 @@ func GetCheckoutStatus(w http.ResponseWriter, r *http.Request) {
UpdatedAt: time.Now(),
}
paymentID, err := service.CreatePaymentRecord(r.Context(), record)
paymentID, err := service.CreatePaymentRecord(r.Context(), record, nil)
if err != nil {
log.Printf("Failed to create payment record: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -540,7 +540,7 @@ func CreateBookingPayment(w http.ResponseWriter, r *http.Request) {
CreatedBy: &userID,
}
paymentID, err := service.CreatePaymentRecord(r.Context(), record)
paymentID, err := service.CreatePaymentRecord(r.Context(), record, nil)
if err != nil {
log.Printf("Failed to create payment record: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
@@ -879,7 +879,7 @@ func CreateTipPayment(w http.ResponseWriter, r *http.Request) {
CreatedBy: &userID,
}
paymentID, err := service.CreatePaymentRecord(r.Context(), record)
paymentID, err := service.CreatePaymentRecord(r.Context(), record, nil)
if err != nil {
log.Printf("Failed to create payment record: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)