2024-08-03 20:26:40 +00:00
|
|
|
{{ template "base" . }}
|
|
|
|
{{ define "title" }}
|
|
|
|
Virtual Terminal
|
|
|
|
{{ end }}
|
|
|
|
{{ define "content" }}
|
2024-08-04 12:40:32 +00:00
|
|
|
<h2 class="mt-3 text-center">Virtual Terminal</h2>
|
|
|
|
<hr>
|
2024-08-04 13:06:41 +00:00
|
|
|
<div class="alert alert-danger text-center d-none" id="card-messages"></div>
|
2024-08-04 12:40:32 +00:00
|
|
|
<form action="/payment-succecded"
|
|
|
|
method="post"
|
|
|
|
name="charge_form"
|
|
|
|
id="charge_form"
|
|
|
|
class="d-blick needs-validation charge-form"
|
|
|
|
autocomplete="off"
|
|
|
|
novalidate="">
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="amount" class="form-label">Amount</label>
|
|
|
|
<input type="text"
|
|
|
|
id="amount"
|
|
|
|
name="amount"
|
|
|
|
autocomplete="amount-new"
|
|
|
|
required=""
|
|
|
|
class="form-control">
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="cardholder-name" class="form-label">Cardholder Name</label>
|
|
|
|
<input type="text"
|
|
|
|
id="cardholder-name"
|
|
|
|
name="cardholder_name"
|
|
|
|
autocomplete="cardholder-name-new"
|
|
|
|
required=""
|
|
|
|
class="form-control">
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="cardholder-email" class="form-label">Cardholder Email</label>
|
|
|
|
<input type="text"
|
|
|
|
id="cardholder-email"
|
|
|
|
name="cardholder_email"
|
|
|
|
autocomplete="cardholder-email-new"
|
|
|
|
required=""
|
|
|
|
class="form-control">
|
|
|
|
</div>
|
|
|
|
<!-- card number will be built by stripe -->
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="card-element" class="form-label">Credit Card</label>
|
|
|
|
<div class="form-control" id="card-element"></div>
|
|
|
|
<div class="alert-danger text-center" id="card-errors" role="alert"></div>
|
|
|
|
<div class="alert-success text-center" id="card-success" role="alert"></div>
|
|
|
|
</div>
|
|
|
|
<hr>
|
2024-08-04 13:06:41 +00:00
|
|
|
<a href="javascript:void(0)"
|
2024-08-04 12:40:32 +00:00
|
|
|
id="pay-button"
|
|
|
|
class="btn btn-primary"
|
|
|
|
onclick="val()">Charge Card</a>
|
2024-08-04 13:06:41 +00:00
|
|
|
<div class="text-center d-none" id="processing-payment">
|
|
|
|
<div class="spinner-border text-primary" role="status">
|
|
|
|
<span class="visually-hidden">Loading...</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-08-04 12:40:32 +00:00
|
|
|
</form>
|
2024-08-03 20:26:40 +00:00
|
|
|
{{ end }}
|
|
|
|
{{ define "js" }}
|
2024-08-04 12:40:32 +00:00
|
|
|
<script src="https://js.stripe.com/v3/"></script>
|
|
|
|
<script>
|
2024-08-04 12:55:29 +00:00
|
|
|
|
|
|
|
let card;
|
|
|
|
let stripe;
|
2024-08-04 13:06:41 +00:00
|
|
|
const cardMessages = document.getElementById("card-messages");
|
|
|
|
const payButton = document.getElementById("pay-button");
|
|
|
|
const processing = document.getElementById("processing-payment");
|
2024-08-04 12:55:29 +00:00
|
|
|
|
|
|
|
stripe = Stripe(''); // TODO: Publish key to be added
|
|
|
|
|
2024-08-04 14:24:01 +00:00
|
|
|
function hidePayButton() {
|
|
|
|
payButton.classList.add("d-none");
|
|
|
|
processing.classList.remove("d-none");
|
|
|
|
}
|
|
|
|
|
2024-08-04 12:40:32 +00:00
|
|
|
function val() {
|
2024-08-04 13:06:41 +00:00
|
|
|
let form = document.getElementById("charge_form");
|
2024-08-04 12:40:32 +00:00
|
|
|
|
2024-08-04 13:06:41 +00:00
|
|
|
if (form.checkValidity() === false) {
|
|
|
|
this.event.preventDefault();
|
|
|
|
this.event.stopPropagation();
|
|
|
|
form.classList.add("was-validated");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
form.classList.add("was-validated");
|
2024-08-04 14:24:01 +00:00
|
|
|
hidePayButton();
|
2024-08-04 12:40:32 +00:00
|
|
|
}
|
2024-08-04 12:55:29 +00:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
// create stripe & elements
|
|
|
|
const elements = stripe.elements();
|
|
|
|
const style = {
|
|
|
|
base: {
|
|
|
|
fontSize: '16px',
|
|
|
|
lineHeight: '24px',
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// create card entry
|
|
|
|
card = elements.create('card', {
|
|
|
|
style:style,
|
|
|
|
hidePostalCode: true,
|
|
|
|
});
|
|
|
|
card.mount("#card-element");
|
|
|
|
|
|
|
|
// check for input errors
|
|
|
|
card.addEventListener('change', function(event) {
|
|
|
|
var displayError = document.getElementById("card-errors");
|
|
|
|
if (event.error) {
|
|
|
|
displayError.classList.remove('d-none');
|
|
|
|
displayError.textContent = event.error.message;
|
|
|
|
} else {
|
|
|
|
displayError.classList.add('d-none');
|
|
|
|
displayError.textContent = "";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|
2024-08-04 12:40:32 +00:00
|
|
|
</script>
|
2024-08-03 20:26:40 +00:00
|
|
|
{{ end }}
|