saveinmed/backend/internal/http/handler/admin_handler.go
Gabbriiel 90467db1ec refactor: substitui backend Medusa por backend Go e corrige testes do marketplace
- Remove backend Medusa.js (TypeScript) e substitui pelo backend Go (saveinmed-performance-core)
- Corrige testes auth.test.ts: alinha paths de API (v1/ sem barra inicial) e campo access_token
- Corrige GroupedProductCard.test.tsx: ajusta distância formatada (toFixed) e troca userEvent por fireEvent com fakeTimers
- Corrige AuthContext.test.tsx: usa vi.hoisted() para mocks e corrige parênteses no waitFor

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 04:56:37 -06:00

57 lines
1.7 KiB
Go

package handler
import (
stdjson "encoding/json"
"net/http"
"github.com/saveinmed/backend-go/internal/domain"
)
// GetPaymentGatewayConfig returns the global config for a provider
func (h *Handler) GetPaymentGatewayConfig(w http.ResponseWriter, r *http.Request) {
provider := r.PathValue("provider")
cfg, err := h.svc.GetPaymentGatewayConfig(r.Context(), provider)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
stdjson.NewEncoder(w).Encode(cfg)
}
// UpdatePaymentGatewayConfig updates or creates global gateway settings
func (h *Handler) UpdatePaymentGatewayConfig(w http.ResponseWriter, r *http.Request) {
provider := r.PathValue("provider")
var req struct {
Active bool `json:"active"`
Credentials string `json:"credentials"` // Encrypted ideally, for MVP raw or simple encrypt
Environment string `json:"environment"`
Commission float64 `json:"commission"`
}
if err := stdjson.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
cfg := &domain.PaymentGatewayConfig{
Provider: provider,
Active: req.Active,
Credentials: req.Credentials,
Environment: req.Environment,
Commission: req.Commission,
}
if err := h.svc.UpsertPaymentGatewayConfig(r.Context(), cfg); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
// TestPaymentGateway simulates a connection check
func (h *Handler) TestPaymentGateway(w http.ResponseWriter, r *http.Request) {
// Mock success for now
w.WriteHeader(http.StatusOK)
stdjson.NewEncoder(w).Encode(map[string]string{"status": "ok", "message": "Connection successful"})
}