fix tt and update promo code error display

This commit is contained in:
Kukks
2024-01-19 10:07:57 +01:00
parent 8a73acd3b2
commit 2f86ad5f3b
4 changed files with 79 additions and 5 deletions

View File

@@ -9,7 +9,7 @@
<PropertyGroup>
<Product>TicketTailor</Product>
<Description>Allows you to integrate with TicketTailor.com to sell tickets for Bitcoin</Description>
<Version>2.0.0</Version>
<Version>2.0.1</Version>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<!-- Plugin development properties -->

View File

@@ -152,6 +152,13 @@ namespace BTCPayServer.Plugins.TicketTailor
!new[] {"on_sale", "locked"}.Contains(ticketType.Status.ToLowerInvariant())
|| specificTicket?.Hidden is true)
{
if (preview)
{
return Json(new
{
Error = "The ticket was not found."
});
}
TempData.SetStatusMessageModel(new StatusMessageModel
{
Severity = StatusMessageModel.StatusSeverity.Error,
@@ -163,6 +170,14 @@ namespace BTCPayServer.Plugins.TicketTailor
if (purchaseRequestItem.Quantity > ticketType.MaxPerOrder ||
purchaseRequestItem.Quantity < ticketType.MinPerOrder)
{
if (preview)
{
return Json(new
{
Error = "The amount of tickets was not allowed."
});
}
TempData.SetStatusMessageModel(new StatusMessageModel
{
Severity = StatusMessageModel.StatusSeverity.Error,

View File

@@ -54,7 +54,7 @@
<span asp-validation-for="AppName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ApiKey" class="form-label" data-required>TicketTailor API Key</label>
<label asp-for="ApiKey" class="form-label" data-required>TicketTailor API Key (<a href="https://get.tickettailor.com/8z1ee1o4xrne" target="_blank">get it here</a>)</label>
<input asp-for="ApiKey" class="form-control" required/>
<span asp-validation-for="ApiKey" class="text-danger"></span>
</div>
@@ -86,7 +86,7 @@
</div>
<div class="form-group form-check">
<input asp-for="AllowDiscountCodes" type="checkbox" class="form-check-input"/>
<label asp-for="AllowDiscountCodes" class="form-check-label">Allow discount codes (due to the nature of Ticket Tailor's API, redemption limit is not applied.</label>
<label asp-for="AllowDiscountCodes" class="form-check-label">Allow discount codes (due to the nature of Ticket Tailor's API, redemption limit is not applied)</label>
<span asp-validation-for="AllowDiscountCodes" class="text-danger"></span>
</div>
<div class="form-group form-check">

View File

@@ -29,8 +29,67 @@
{
@Safe.Raw(Model.Settings.CustomCSS)
}
</style>
<script>
document.addEventListener("DOMContentLoaded", ()=>{
const form = document.querySelector("form");
const btn = document.querySelector("button[type='submit']");
const inputs = document.querySelectorAll("input");
const discountCode = document.querySelector("#DiscountCode");
inputs.forEach(value => value.addEventListener("input", (evt)=>{
let total = 0;
let totalQty = 0;
document.querySelectorAll("[data-price]").forEach(value1 => {
if (!!value1.value){
const qty = parseInt(value1.value);
if (qty > 0){
const price = parseFloat(value1.dataset.price).toPrecision(12);
total += price * qty;
totalQty += qty;
}
}
});
btn.classList.remove("btn-warning");
if (totalQty > 0){
btn.removeAttribute("disabled");
}
else{
btn.setAttribute("disabled", "disabled");
}
btn.textContent = `Purchase for ${total.toFixed(2)} @Model.Event.Currency.ToUpperInvariant()`
if (discountCode && discountCode.value && totalQty > 0){
const data = new FormData(form);
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
const response = JSON.parse(this.responseText);
if (response.error){
console.error(response.error);
btn.setAttribute("disabled", "disabled");
btn.classList.add("btn-warning");
btn.textContent = `Purchase unavailable due to ${response.error.toLowerCase()}`
return;
}
if (response.discountedAmount){
btn.innerHTML = `Purchase for ${response.total.toFixed(2)} @Model.Event.Currency.ToUpperInvariant()<br/><span class="">${response.discountedAmount.toFixed(2)} @Model.Event.Currency.ToUpperInvariant() discount</span>`
} else{
btn.textContent = `Purchase for ${response.total.toFixed(2)} @Model.Event.Currency.ToUpperInvariant()`
}
}
}
xhttp.open("POST", "@Url.Action("Purchase", new {appId, preview = true})", true);
xhttp.send(data);
}
}))
form.addEventListener("submit", ()=>{
btn.setAttribute("disabled", "disabled");
inputs.forEach(value => value.setAttribute("readonly", "readonly"));
})
})
</script>
</head>
<body class="min-vh-100">
<div id="TicketTailor" class="public-page-wrap">