chore: add crypto payment

This commit is contained in:
2026-03-18 18:41:07 +01:00
parent a82097a228
commit adf68201fd
12 changed files with 788 additions and 2 deletions
+30
View File
@@ -162,6 +162,36 @@ func InitDB() *Database {
log.Fatalf("❌ Erreur migration commandes.referral_used: %v", err)
}
// Migration: méthode de paiement (cash par défaut, crypto si paiement NowPayments)
if _, err = database.Exec(`ALTER TABLE commandes ADD COLUMN IF NOT EXISTS payment_method VARCHAR(20) NOT NULL DEFAULT 'cash'`); err != nil {
log.Fatalf("❌ Erreur migration commandes.payment_method: %v", err)
}
// Migration: table de suivi des paiements crypto
if _, err = database.Exec(`
CREATE TABLE IF NOT EXISTS crypto_payments (
id SERIAL PRIMARY KEY,
command_id INTEGER NOT NULL REFERENCES commandes(id) ON DELETE CASCADE,
nowpayment_id TEXT NOT NULL,
status VARCHAR(50) NOT NULL DEFAULT 'waiting',
price_amount NUMERIC(10,2) NOT NULL,
price_currency VARCHAR(10) NOT NULL DEFAULT 'eur',
pay_currency VARCHAR(20) NOT NULL,
pay_address TEXT NOT NULL,
pay_amount NUMERIC(20,8) DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`); err != nil {
log.Fatalf("❌ Erreur migration crypto_payments: %v", err)
}
if _, err = database.Exec(`CREATE INDEX IF NOT EXISTS idx_crypto_payments_command_id ON crypto_payments(command_id)`); err != nil {
log.Fatalf("❌ Erreur index crypto_payments.command_id: %v", err)
}
if _, err = database.Exec(`CREATE INDEX IF NOT EXISTS idx_crypto_payments_nowpayment_id ON crypto_payments(nowpayment_id)`); err != nil {
log.Fatalf("❌ Erreur index crypto_payments.nowpayment_id: %v", err)
}
// Migration: points extra pour tous les pools de points (stockage dynamique par clé)
if _, err = database.Exec(`ALTER TABLE clients ADD COLUMN IF NOT EXISTS points_extra JSONB NOT NULL DEFAULT '{}'::jsonb`); err != nil {
log.Fatalf("❌ Erreur migration clients.points_extra: %v", err)