Testing the transaction functionality
This commit is contained in:
		@ -6,11 +6,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
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 {
 | 
			
		||||
	if err := app.renderTemplate(w, r, "terminal", &templateData{}, "stripe-js"); err != nil {
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -20,6 +20,8 @@ type templateData struct {
 | 
			
		||||
	API             string
 | 
			
		||||
	CSSVersion      string
 | 
			
		||||
	IsAuthenticated int
 | 
			
		||||
	StripeSecretKey string
 | 
			
		||||
	StripePubKey    string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var functions = template.FuncMap{
 | 
			
		||||
@ -36,6 +38,8 @@ var templateFS embed.FS
 | 
			
		||||
 | 
			
		||||
func (app *application) addDefaultData(td *templateData, r *http.Request) *templateData {
 | 
			
		||||
	td.API = app.config.api
 | 
			
		||||
	td.StripePubKey = app.config.stripe.key
 | 
			
		||||
	td.StripeSecretKey = app.config.stripe.secret
 | 
			
		||||
	return td
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@ const cardMessages = document.getElementById("card-messages");
 | 
			
		||||
const payButton = document.getElementById("pay-button");
 | 
			
		||||
const processing = document.getElementById("processing-payment");
 | 
			
		||||
 | 
			
		||||
stripe = Stripe('{{index .StringMap "publishable_key"}}');
 | 
			
		||||
stripe = Stripe('{{.StripePubKey}}');
 | 
			
		||||
 | 
			
		||||
function hidePayButton() {
 | 
			
		||||
    payButton.classList.add("d-none");
 | 
			
		||||
@ -46,7 +46,7 @@ function val() {
 | 
			
		||||
    form.classList.add("was-validated");
 | 
			
		||||
    hidePayButton();
 | 
			
		||||
 | 
			
		||||
    let amountToCharge = String(parseFloat(document.getElementById("amount").value) * 100);
 | 
			
		||||
    let amountToCharge = String(parseFloat(document.getElementById("amount").value));
 | 
			
		||||
    let payload = {
 | 
			
		||||
        amount: amountToCharge,
 | 
			
		||||
        currency: 'eur',
 | 
			
		||||
@ -61,7 +61,7 @@ function val() {
 | 
			
		||||
        body: JSON.stringify(payload),
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    fetch("{{index .API}}/api/payment-intent", requestOptions)
 | 
			
		||||
    fetch("{{.API}}/api/payment-intent", requestOptions)
 | 
			
		||||
    .then(response => response.text())
 | 
			
		||||
        .then(response => {
 | 
			
		||||
            let data;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user