Fix some payment-related bugs
This commit is contained in:
parent
4076cd3059
commit
1b8847ec1d
@ -41,6 +41,10 @@ $database->action(function($database) {
|
||||
];
|
||||
|
||||
foreach ($people['ids'] as $pid) {
|
||||
// Clear these out
|
||||
$camperid = null;
|
||||
$adultid = null;
|
||||
$youthid = null;
|
||||
switch ($people["type"][$pid]) {
|
||||
case "camper":
|
||||
$checkfields = array_merge($requiredfields, [
|
||||
@ -172,11 +176,17 @@ $database->action(function($database) {
|
||||
|
||||
$campcoupons = (!empty($_POST['campcoupons']) && preg_match("/[0-9]+/", $_POST['campcoupons'])) ? $_POST['campcoupons'] * 1 : 0;
|
||||
|
||||
$duecard = $dueusd - $campcoupons;
|
||||
if ($campcoupons < 0) {
|
||||
$campcoupons = 0;
|
||||
}
|
||||
|
||||
$dueusd = max(0, $dueusd);
|
||||
|
||||
$duecard = max(0, $dueusd - $campcoupons);
|
||||
|
||||
echo "\nCost $dueusd total: $duecard to Stripe, $campcoupons as coupons\n";
|
||||
|
||||
if ($_POST['totalcharge'] != $dueusd) {
|
||||
if ($dueusd != $_POST['totalcharge']) {
|
||||
errorBack("There was a discrepency between the total you saw and the total the server calculated. The transaction has been cancelled and you were not charged.");
|
||||
}
|
||||
|
||||
@ -212,13 +222,12 @@ $database->action(function($database) {
|
||||
|
||||
$database->insert("payments", [
|
||||
"familyid" => $familyid,
|
||||
"amount" => ($dueusd),
|
||||
"amountpaid" => ($duecard),
|
||||
"amount" => $dueusd,
|
||||
"amountpaid" => $duecard,
|
||||
"date" => date("Y-m-d H:i:s"),
|
||||
"type" => "Online"
|
||||
]);
|
||||
|
||||
header("Location: ../?page=thanks");
|
||||
var_dump($_POST);
|
||||
return true;
|
||||
});
|
||||
|
@ -126,13 +126,13 @@ $("#savebutton").click(function (event) {
|
||||
$("#registrationform").on("submit", function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
// prevent multiple clicks since Stripe can take a few seconds
|
||||
$("#savebutton").prop("disabled", true);
|
||||
$("#savebutton-text").addClass("d-none");
|
||||
$("#savebutton-wait").removeClass("d-none");
|
||||
|
||||
// If we have any charge left after subtracting camp coupons/scout bucks
|
||||
if ($("input[name=totalcharge]").val() - $("input[name=campcoupons]").val() > 0) {
|
||||
console.log("Charging card...");
|
||||
// prevent multiple clicks since Stripe can take a few seconds
|
||||
$("#savebutton").prop("disabled", true);
|
||||
$("#savebutton-text").addClass("d-none");
|
||||
$("#savebutton-wait").removeClass("d-none");
|
||||
stripe.createToken(card).then(function (result) {
|
||||
if (result.error) {
|
||||
// Inform the customer that there was an error.
|
||||
@ -144,9 +144,11 @@ $("#registrationform").on("submit", function (event) {
|
||||
} else {
|
||||
$("#stripe-token").val(result.token.id);
|
||||
console.log(result.token);
|
||||
document.getElementById('registrationform').submit();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("Submitting without card...");
|
||||
document.getElementById('registrationform').submit();
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user