passing key using form

This commit is contained in:
vinchent 2024-08-04 18:35:34 +02:00
parent bfaf8965b3
commit d3e477eebd
3 changed files with 8 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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;