diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index a7005e3..33dcf7e 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -5,7 +5,11 @@ import ( ) func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "terminal", nil); err != nil { + stringMap := make(map[string]string) + stringMap["publishable_key"] = app.config.stripe.key + if err := app.renderTemplate(w, r, "terminal", &templateData{ + StringMap: stringMap, + }); err != nil { app.errorLog.Println(err) } } diff --git a/cmd/web/render.go b/cmd/web/render.go index 672c0d9..951221f 100644 --- a/cmd/web/render.go +++ b/cmd/web/render.go @@ -28,6 +28,7 @@ var functions = template.FuncMap{} var templateFS embed.FS func (app *application) addDefaultData(td *templateData, r *http.Request) *templateData { + td.API = app.config.api return td } diff --git a/cmd/web/templates/terminal.page.gohtml b/cmd/web/templates/terminal.page.gohtml index c02942a..b1e000b 100644 --- a/cmd/web/templates/terminal.page.gohtml +++ b/cmd/web/templates/terminal.page.gohtml @@ -75,7 +75,7 @@ const cardMessages = document.getElementById("card-messages"); const payButton = document.getElementById("pay-button"); const processing = document.getElementById("processing-payment"); -stripe = Stripe(''); // TODO: Publish key to be added +stripe = Stripe('{{index .StringMap "publishable_key"}}'); function hidePayButton() { payButton.classList.add("d-none"); @@ -128,7 +128,7 @@ function val() { body: JSON.stringify(payload), }; - fetch("http://localhost:4001/api/payment-intent", requestOptions) + fetch("{{index .API}}/api/payment-intent", requestOptions) .then(response => response.text()) .then(response => { let data;