From 4dfb28ad3d6ca066842b8fb5a4a443eb527aabd6 Mon Sep 17 00:00:00 2001 From: vinchent Date: Mon, 12 Aug 2024 19:23:44 +0200 Subject: [PATCH] add receipt page for plan --- cmd/web/handlers.go | 6 ++++++ cmd/web/routes.go | 1 + cmd/web/templates/receipt-plan.page.gohtml | 24 ++++++++++++++++++++++ static/js/stripe-plan.js | 8 ++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 cmd/web/templates/receipt-plan.page.gohtml diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index b872c8a..401d524 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -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) + } +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 054ade4..9b8c681 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -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)) diff --git a/cmd/web/templates/receipt-plan.page.gohtml b/cmd/web/templates/receipt-plan.page.gohtml new file mode 100644 index 0000000..91d3a04 --- /dev/null +++ b/cmd/web/templates/receipt-plan.page.gohtml @@ -0,0 +1,24 @@ +{{ template "base" . }} +{{ define "title" }} +Payment Succedded! +{{ end }} +{{ define "content" }} +{{$txn := index .Data "txn"}} +

Payment Succeeded

+
+

Customer Name:

+

Payment Amount:

+

Last Four:

+{{ end }} + +{{define "js"}} + +{{end}} diff --git a/static/js/stripe-plan.js b/static/js/stripe-plan.js index c99d62c..048ec77 100644 --- a/static/js/stripe-plan.js +++ b/static/js/stripe-plan.js @@ -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"; }); } }