53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) {
|
|
stringMap := make(map[string]string)
|
|
stringMap["publishable_key"] = app.config.stripe.key
|
|
if err := app.renderTemplate(w, r, "terminal", &templateData{
|
|
StringMap: stringMap,
|
|
}, "stripe-js"); err != nil {
|
|
app.errorLog.Println(err)
|
|
}
|
|
}
|
|
|
|
func (app *application) PaymentSucceeded(w http.ResponseWriter, r *http.Request) {
|
|
err := r.ParseForm()
|
|
if err != nil {
|
|
app.errorLog.Println(err)
|
|
return
|
|
}
|
|
|
|
// read posted data
|
|
cardHolder := r.Form.Get("cardholder_name")
|
|
email := r.Form.Get("cardholder_email")
|
|
paymentIntent := r.Form.Get("payment_intent")
|
|
paymentMethod := r.Form.Get("payment_method")
|
|
paymentAmount := r.Form.Get("payment_amount")
|
|
paymentCurrency := r.Form.Get("payment_currency")
|
|
|
|
data := make(map[string]interface{})
|
|
data["cardholder"] = cardHolder
|
|
data["email"] = email
|
|
data["pi"] = paymentIntent
|
|
data["pm"] = paymentMethod
|
|
data["pa"] = paymentAmount
|
|
data["pc"] = paymentCurrency
|
|
|
|
if err := app.renderTemplate(w, r, "succeeded", &templateData{
|
|
Data: data,
|
|
}); err != nil {
|
|
app.errorLog.Println(err)
|
|
}
|
|
}
|
|
|
|
// ChargeOnce displays the page to buy one widget
|
|
func (app *application) ChargeOnce(w http.ResponseWriter, r *http.Request) {
|
|
if err := app.renderTemplate(w, r, "buy-once", nil, "stripe-js"); err != nil {
|
|
app.errorLog.Println(err)
|
|
}
|
|
}
|