add receipt page for plan

This commit is contained in:
vinchent 2024-08-12 19:23:44 +02:00
parent 5ab6ad85f7
commit 4dfb28ad3d
4 changed files with 37 additions and 2 deletions

View File

@ -277,3 +277,9 @@ func (app *application) BronzePlan(w http.ResponseWriter, r *http.Request) {
app.errorLog.Println(err)
}
}
func (app *application) BronzePlanReceipt(w http.ResponseWriter, r *http.Request) {
if err := app.renderTemplate(w, r, "receipt-plan", &templateData{}); err != nil {
app.errorLog.Println(err)
}
}

View File

@ -20,6 +20,7 @@ func (app *application) routes() http.Handler {
mux.Post("/payment-succeeded", app.PaymentSucceeded)
mux.Get("/plans/bronze", app.BronzePlan)
mux.Get("/receipt/bronze", app.BronzePlanReceipt)
fileServer := http.FileServer(http.Dir("./static"))
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))

View File

@ -0,0 +1,24 @@
{{ template "base" . }}
{{ define "title" }}
Payment Succedded!
{{ end }}
{{ define "content" }}
{{$txn := index .Data "txn"}}
<h2 class="mt-5">Payment Succeeded</h2>
<hr>
<p>Customer Name: <span id="first-name"></span> <span id="last-name"></span></p>
<p>Payment Amount: <span id="amount"></span></p>
<p>Last Four: <span id="last-four"></span></p>
{{ end }}
{{define "js"}}
<script>
if (sessionStorage.first_name) {
document.getElementById("first-name").innerHTML = sessionStorage.first_name;
document.getElementById("last-name").innerHTML = sessionStorage.last_name;
document.getElementById("amount").innerHTML = sessionStorage.amount;
document.getElementById("last-four").innerHTML = sessionStorage.last_four;
sessionStorage.clear();
}
</script>
{{end}}

View File

@ -66,8 +66,12 @@ function stripePaymentMethodHandler(result, plan_id, api) {
.then(function (data) {
console.log(data);
processing.classList.add("d-none");
// set hidden vars
// submit the form
showCardSuccess();
sessionStorage.first_name = document.getElementById("first-name").value;
sessionStorage.last_name = document.getElementById("last-name").value;
sessionStorage.amount = document.getElementById("amount").value;
sessionStorage.last_four = result.paymentMethod.card.last4;
location.href = "/receipt/bronze";
});
}
}