Testing the transaction functionality

This commit is contained in:
2024-08-06 21:18:32 +02:00
parent f952caf3f6
commit 90918f25ae
5 changed files with 13 additions and 15 deletions

View File

@ -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() {
}
});
})();