Testing the transaction functionality
This commit is contained in:
parent
f952caf3f6
commit
90918f25ae
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ STRIPE_SECRET=$(shell sed '2q;d' cred.txt)
|
||||
STRIPE_KEY=$(shell sed '2q;d' cred.txt)
|
||||
GOSTRIPE_PORT=4000
|
||||
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: clean build_front build_back
|
||||
|
@ -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;
|
||||
|
@ -4,8 +4,7 @@ const cardMessages = document.getElementById("card-messages");
|
||||
const payButton = document.getElementById("pay-button");
|
||||
const processing = document.getElementById("processing-payment");
|
||||
|
||||
// FIXME: not working in this way
|
||||
stripe = Stripe('{{index .StringMap "publishable_key"}}');
|
||||
stripe = Stripe('{{.StripePubKey}}');
|
||||
|
||||
function hidePayButton() {
|
||||
payButton.classList.add("d-none");
|
||||
@ -31,7 +30,7 @@ function showCardSuccess() {
|
||||
cardMessages.innerText = "Trasaction successful";
|
||||
}
|
||||
|
||||
function val() {
|
||||
function val(stripe) {
|
||||
let form = document.getElementById("charge_form");
|
||||
|
||||
if (form.checkValidity() === false) {
|
||||
@ -43,7 +42,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',
|
||||
@ -58,7 +57,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;
|
||||
@ -128,4 +127,3 @@ function val() {
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user