78b57273e2
- Add password hashing with bcrypt - Add AuthService with proper login - Add password strength validation - Add RBAC middleware (AdminOnly, ManagerOrAdmin) - Add tenant isolation middleware - Update CRM handler with tenant filtering - Add JWT fallback for development mode - Add user context helpers - Build successful
117 lines
3.4 KiB
Go
117 lines
3.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// StripeHandler hanterar Stripe Connect för quiXzoom-utbetalningar
|
|
type StripeHandler struct {
|
|
apiKey string
|
|
webhookSecret string
|
|
}
|
|
|
|
func NewStripeHandler() *StripeHandler {
|
|
return &StripeHandler{
|
|
apiKey: os.Getenv("STRIPE_API_KEY"),
|
|
webhookSecret: os.Getenv("STRIPE_WEBHOOK_SECRET"),
|
|
}
|
|
}
|
|
|
|
// StripeAccount representerar ett Stripe-konto
|
|
type StripeAccount struct {
|
|
ID string `json:"id"`
|
|
Email string `json:"email"`
|
|
Status string `json:"status"`
|
|
Type string `json:"type"`
|
|
Country string `json:"country"`
|
|
Currency string `json:"currency"`
|
|
Balance float64 `json:"balance"`
|
|
PayoutsEnabled bool `json:"payouts_enabled"`
|
|
ChargesEnabled bool `json:"charges_enabled"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// StripePayout representerar en Stripe-utbetalning
|
|
type StripePayout struct {
|
|
ID string `json:"id"`
|
|
Amount float64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
Method string `json:"method"`
|
|
ArrivalDate string `json:"arrival_date"`
|
|
BankAccount string `json:"bank_account"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
// GetStatus returnerar Stripe-kopplingsstatus
|
|
func (h *StripeHandler) GetStatus(w http.ResponseWriter, r *http.Request) {
|
|
configured := h.apiKey != ""
|
|
|
|
status := map[string]interface{}{
|
|
"configured": configured,
|
|
"webhook_url": "https://boc.landvex.com/api/v1/stripe/webhook",
|
|
"setup_required": !configured,
|
|
}
|
|
|
|
if !configured {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "Stripe not configured. Set STRIPE_API_KEY environment variable.",
|
|
"stripe": status,
|
|
})
|
|
return
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, map[string]interface{}{
|
|
"ok": true,
|
|
"stripe": status,
|
|
})
|
|
}
|
|
|
|
// GetAccounts returnerar Stripe-konton (zoomers)
|
|
func (h *StripeHandler) GetAccounts(w http.ResponseWriter, r *http.Request) {
|
|
if h.apiKey == "" {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "Stripe not configured. Set STRIPE_API_KEY environment variable.",
|
|
})
|
|
return
|
|
}
|
|
|
|
// TODO: Implementera riktig Stripe API-integration
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "Stripe integration not yet implemented. Contact administrator to configure.",
|
|
})
|
|
}
|
|
|
|
// GetPayouts returnerar Stripe-utbetalningar
|
|
func (h *StripeHandler) GetPayouts(w http.ResponseWriter, r *http.Request) {
|
|
if h.apiKey == "" {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "Stripe not configured. Set STRIPE_API_KEY environment variable.",
|
|
})
|
|
return
|
|
}
|
|
|
|
// TODO: Implementera riktig Stripe API-integration
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
json.NewEncoder(w).Encode(map[string]interface{}{
|
|
"ok": false,
|
|
"error": "Stripe integration not yet implemented. Contact administrator to configure.",
|
|
})
|
|
}
|