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) {
|
foreach ($people['ids'] as $pid) {
|
||||||
|
// Clear these out
|
||||||
|
$camperid = null;
|
||||||
|
$adultid = null;
|
||||||
|
$youthid = null;
|
||||||
switch ($people["type"][$pid]) {
|
switch ($people["type"][$pid]) {
|
||||||
case "camper":
|
case "camper":
|
||||||
$checkfields = array_merge($requiredfields, [
|
$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;
|
$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";
|
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.");
|
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", [
|
$database->insert("payments", [
|
||||||
"familyid" => $familyid,
|
"familyid" => $familyid,
|
||||||
"amount" => ($dueusd),
|
"amount" => $dueusd,
|
||||||
"amountpaid" => ($duecard),
|
"amountpaid" => $duecard,
|
||||||
"date" => date("Y-m-d H:i:s"),
|
"date" => date("Y-m-d H:i:s"),
|
||||||
"type" => "Online"
|
"type" => "Online"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
header("Location: ../?page=thanks");
|
header("Location: ../?page=thanks");
|
||||||
var_dump($_POST);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -126,13 +126,13 @@ $("#savebutton").click(function (event) {
|
|||||||
$("#registrationform").on("submit", function (event) {
|
$("#registrationform").on("submit", function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
// 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
|
// prevent multiple clicks since Stripe can take a few seconds
|
||||||
$("#savebutton").prop("disabled", true);
|
$("#savebutton").prop("disabled", true);
|
||||||
$("#savebutton-text").addClass("d-none");
|
$("#savebutton-text").addClass("d-none");
|
||||||
$("#savebutton-wait").removeClass("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) {
|
|
||||||
stripe.createToken(card).then(function (result) {
|
stripe.createToken(card).then(function (result) {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
// Inform the customer that there was an error.
|
// Inform the customer that there was an error.
|
||||||
@ -144,9 +144,11 @@ $("#registrationform").on("submit", function (event) {
|
|||||||
} else {
|
} else {
|
||||||
$("#stripe-token").val(result.token.id);
|
$("#stripe-token").val(result.token.id);
|
||||||
console.log(result.token);
|
console.log(result.token);
|
||||||
}
|
document.getElementById('registrationform').submit();
|
||||||
});
|
}
|
||||||
} else {
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Submitting without card...");
|
||||||
document.getElementById('registrationform').submit();
|
document.getElementById('registrationform').submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user