Testing the transaction functionality
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@ -2,7 +2,7 @@ STRIPE_SECRET=$(shell sed '2q;d' cred.txt)
 | 
				
			|||||||
STRIPE_KEY=$(shell sed '2q;d' cred.txt)
 | 
					STRIPE_KEY=$(shell sed '2q;d' cred.txt)
 | 
				
			||||||
GOSTRIPE_PORT=4000
 | 
					GOSTRIPE_PORT=4000
 | 
				
			||||||
API_PORT=4001
 | 
					API_PORT=4001
 | 
				
			||||||
DSN=root@tcp(localhost:6379)/widgets?parseTime=true&tls=false
 | 
					DSN=vinchent:secret@tcp(localhost:3306)/widgets?parseTime=true&tls=false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## build: builds all binaries
 | 
					## build: builds all binaries
 | 
				
			||||||
build: clean build_front build_back
 | 
					build: clean build_front build_back
 | 
				
			||||||
 | 
				
			|||||||
@ -6,11 +6,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) {
 | 
					func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
	stringMap := make(map[string]string)
 | 
						if err := app.renderTemplate(w, r, "terminal", &templateData{}, "stripe-js"); err != nil {
 | 
				
			||||||
	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)
 | 
							app.errorLog.Println(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,8 @@ type templateData struct {
 | 
				
			|||||||
	API             string
 | 
						API             string
 | 
				
			||||||
	CSSVersion      string
 | 
						CSSVersion      string
 | 
				
			||||||
	IsAuthenticated int
 | 
						IsAuthenticated int
 | 
				
			||||||
 | 
						StripeSecretKey string
 | 
				
			||||||
 | 
						StripePubKey    string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var functions = template.FuncMap{
 | 
					var functions = template.FuncMap{
 | 
				
			||||||
@ -36,6 +38,8 @@ var templateFS embed.FS
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (app *application) addDefaultData(td *templateData, r *http.Request) *templateData {
 | 
					func (app *application) addDefaultData(td *templateData, r *http.Request) *templateData {
 | 
				
			||||||
	td.API = app.config.api
 | 
						td.API = app.config.api
 | 
				
			||||||
 | 
						td.StripePubKey = app.config.stripe.key
 | 
				
			||||||
 | 
						td.StripeSecretKey = app.config.stripe.secret
 | 
				
			||||||
	return td
 | 
						return td
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@ const cardMessages = document.getElementById("card-messages");
 | 
				
			|||||||
const payButton = document.getElementById("pay-button");
 | 
					const payButton = document.getElementById("pay-button");
 | 
				
			||||||
const processing = document.getElementById("processing-payment");
 | 
					const processing = document.getElementById("processing-payment");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
stripe = Stripe('{{index .StringMap "publishable_key"}}');
 | 
					stripe = Stripe('{{.StripePubKey}}');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function hidePayButton() {
 | 
					function hidePayButton() {
 | 
				
			||||||
    payButton.classList.add("d-none");
 | 
					    payButton.classList.add("d-none");
 | 
				
			||||||
@ -46,7 +46,7 @@ function val() {
 | 
				
			|||||||
    form.classList.add("was-validated");
 | 
					    form.classList.add("was-validated");
 | 
				
			||||||
    hidePayButton();
 | 
					    hidePayButton();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let amountToCharge = String(parseFloat(document.getElementById("amount").value) * 100);
 | 
					    let amountToCharge = String(parseFloat(document.getElementById("amount").value));
 | 
				
			||||||
    let payload = {
 | 
					    let payload = {
 | 
				
			||||||
        amount: amountToCharge,
 | 
					        amount: amountToCharge,
 | 
				
			||||||
        currency: 'eur',
 | 
					        currency: 'eur',
 | 
				
			||||||
@ -61,7 +61,7 @@ function val() {
 | 
				
			|||||||
        body: JSON.stringify(payload),
 | 
					        body: JSON.stringify(payload),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fetch("{{index .API}}/api/payment-intent", requestOptions)
 | 
					    fetch("{{.API}}/api/payment-intent", requestOptions)
 | 
				
			||||||
    .then(response => response.text())
 | 
					    .then(response => response.text())
 | 
				
			||||||
        .then(response => {
 | 
					        .then(response => {
 | 
				
			||||||
            let data;
 | 
					            let data;
 | 
				
			||||||
 | 
				
			|||||||
@ -4,8 +4,7 @@ const cardMessages = document.getElementById("card-messages");
 | 
				
			|||||||
const payButton = document.getElementById("pay-button");
 | 
					const payButton = document.getElementById("pay-button");
 | 
				
			||||||
const processing = document.getElementById("processing-payment");
 | 
					const processing = document.getElementById("processing-payment");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FIXME: not working in this way
 | 
					stripe = Stripe('{{.StripePubKey}}');
 | 
				
			||||||
stripe = Stripe('{{index .StringMap "publishable_key"}}');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function hidePayButton() {
 | 
					function hidePayButton() {
 | 
				
			||||||
    payButton.classList.add("d-none");
 | 
					    payButton.classList.add("d-none");
 | 
				
			||||||
@ -31,7 +30,7 @@ function showCardSuccess() {
 | 
				
			|||||||
    cardMessages.innerText = "Trasaction successful";
 | 
					    cardMessages.innerText = "Trasaction successful";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function val() {
 | 
					function val(stripe) {
 | 
				
			||||||
    let form = document.getElementById("charge_form");
 | 
					    let form = document.getElementById("charge_form");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (form.checkValidity() === false) {
 | 
					    if (form.checkValidity() === false) {
 | 
				
			||||||
@ -43,7 +42,7 @@ function val() {
 | 
				
			|||||||
    form.classList.add("was-validated");
 | 
					    form.classList.add("was-validated");
 | 
				
			||||||
    hidePayButton();
 | 
					    hidePayButton();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let amountToCharge = String(parseFloat(document.getElementById("amount").value) * 100);
 | 
					    let amountToCharge = String(parseFloat(document.getElementById("amount").value));
 | 
				
			||||||
    let payload = {
 | 
					    let payload = {
 | 
				
			||||||
        amount: amountToCharge,
 | 
					        amount: amountToCharge,
 | 
				
			||||||
        currency: 'eur',
 | 
					        currency: 'eur',
 | 
				
			||||||
@ -58,7 +57,7 @@ function val() {
 | 
				
			|||||||
        body: JSON.stringify(payload),
 | 
					        body: JSON.stringify(payload),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fetch("{{index .API}}/api/payment-intent", requestOptions)
 | 
					    fetch("{{.API}}/api/payment-intent", requestOptions)
 | 
				
			||||||
    .then(response => response.text())
 | 
					    .then(response => response.text())
 | 
				
			||||||
        .then(response => {
 | 
					        .then(response => {
 | 
				
			||||||
            let data;
 | 
					            let data;
 | 
				
			||||||
@ -128,4 +127,3 @@ function val() {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user