add receipt page for plan
This commit is contained in:
		@ -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)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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))
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										24
									
								
								cmd/web/templates/receipt-plan.page.gohtml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								cmd/web/templates/receipt-plan.page.gohtml
									
									
									
									
									
										Normal 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}}
 | 
			
		||||
@ -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";
 | 
			
		||||
            });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user