package widget import ( "html/template" "net/http" "go.uber.org/fx" "payouts/internal/service/yookassa" yookassaConf "payouts/internal/service/yookassa/config" "payouts/internal/templates" ) const WidgetPage = "/payout/widget" type Handler interface { WidgetHandler(http.ResponseWriter, *http.Request) } type widgetHandler struct { template *template.Template config yookassaConf.YooKassa } // Params represents the module input params type Params struct { fx.In YookassaService yookassa.Service } func NewWidgetHandler(p Params) (Handler, error) { return &widgetHandler{ template: templates.Templates, config: p.YookassaService.GetConfig(), }, nil } // WidgetHandler renders the payouts widget page func (h *widgetHandler) WidgetHandler(w http.ResponseWriter, r *http.Request) { data := struct { ApiPayoutKey string WidgetVersion string }{ ApiPayoutKey: h.config.ApiPayoutKey, WidgetVersion: h.config.WidgetVersion, } w.Header().Set("Content-Type", "text/html; charset=utf-8") err := h.template.ExecuteTemplate(w, "payouts-widget.html", data) if err != nil { http.Error(w, "internal error", http.StatusInternalServerError) return } }