<script>
function findGetParameter(parameterName) {
var result = null,
tmp = [];
location.search.substr(1).split("&").forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;
};
$(document).ready(function(){
let qrcode = localStorage.getItem("qrcode");
if(qrcode){
localStorage.removeItem("qrcode");
return false;
}
let myVoucher = findGetParameter('voucher');
if(myVoucher){
$('#vcode').val(myVoucher);
setTimeout(function() {
$.ajax({
type:"POST",
url:"/admin/index?svouchers=1",
data:{vcode:myVoucher},
success:function(msg){
if(msg=="1"){
localStorage.setItem("qrcode",myVoucher);
$("#rtime").html('<div class="spinner-border text-primary" role="status"> <span class="sr-only">Loading...</span> </div>');
document.getElementById("vcode").value="";
toastr.success("Voucher code "+myVoucher+" successfully redeemed","",{"timeOut":"1000","positionClass":"toast-top-right"});
$("#sub-voucher").attr("disabled",false);
}
else{
document.getElementById("vcode").value="";
toastr.error(msg,'Error');
$("#sub-voucher").attr("disabled",false);
}
}
});
}, 1000);
}
});
</script>