Add stripe fees, fix price vars

master
Skylar Ittner 2 years ago
parent f8948179b4
commit 9854ec529d

@ -21,7 +21,7 @@ if (!empty($SETTINGS["disable_registration"]) && $SETTINGS["disable_registration
die("Online registration is now closed."); die("Online registration is now closed.");
} }
$database->action(function($database) { $database->action(function ($database) {
global $SETTINGS; global $SETTINGS;
$database->insert("families", []); $database->insert("families", []);
@ -143,8 +143,8 @@ $database->action(function($database) {
switch ($people["type"][$pid]) { switch ($people["type"][$pid]) {
case "camper": case "camper":
$dueusd += 50.0; $dueusd += $SETTINGS["prices"]["camp"];
echo "\nAdding $50 to the total for a camper, dueusd is $dueusd\n"; echo "\nAdding $$SETTINGS[prices][camp] to the total for a camper, dueusd is $dueusd\n";
$database->insert("campers", [ $database->insert("campers", [
"parentname" => $people["parentname"][$pid], "parentname" => $people["parentname"][$pid],
"rank" => $people["rank"][$pid] "rank" => $people["rank"][$pid]
@ -152,7 +152,7 @@ $database->action(function($database) {
$camperid = $database->id(); $camperid = $database->id();
break; break;
case "adult": case "adult":
$discount = 10.0 * (strlen($days) / 2); $discount = $SETTINGS["prices"]["adult_volunteer_daily_discount"] * (strlen($days) / 2);
$dueusd -= $discount; $dueusd -= $discount;
echo "Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n"; echo "Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n";
// Add shirt charge if not working all days // Add shirt charge if not working all days
@ -160,8 +160,8 @@ $database->action(function($database) {
// No shirt cost // No shirt cost
} else if ($SETTINGS["prices"]["adult_tshirt"] !== false) { } else if ($SETTINGS["prices"]["adult_tshirt"] !== false) {
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["adult_tshirt"]) { if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["adult_tshirt"]) {
echo "Adding $10 for a tshirt.\n"; echo "Adding $$SETTINGS[prices][tshirt] for a tshirt.\n";
$dueusd += 10.0; $dueusd += $SETTINGS["prices"]["tshirt"];
} }
} }
if (!empty($people["child_care"][$pid])) { if (!empty($people["child_care"][$pid])) {
@ -182,8 +182,8 @@ $database->action(function($database) {
case "youth": case "youth":
if ($SETTINGS["prices"]["youth_tshirt"] !== false) { if ($SETTINGS["prices"]["youth_tshirt"] !== false) {
if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["youth_tshirt"]) { if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["youth_tshirt"]) {
echo "Adding $10 for a tshirt.\n"; echo "Adding $$SETTINGS[prices][tshirt] for a tshirt.\n";
$dueusd += 10.0; $dueusd += $SETTINGS["prices"]["tshirt"];
} }
} }
$database->insert("youth", [ $database->insert("youth", [
@ -235,6 +235,12 @@ $database->action(function($database) {
$duecard = max(0, $dueusd - $campcoupons); $duecard = max(0, $dueusd - $campcoupons);
// Add Stripe fees
// https://support.stripe.com/questions/passing-the-stripe-fee-on-to-customers
if ($SETTINGS["prices"]["add_stripe_fees"]) {
$duecard = ($duecard + 0.30) / (1 - 0.029);
}
echo "\nCost $dueusd total: $duecard to Stripe, $campcoupons as coupons\n"; echo "\nCost $dueusd total: $duecard to Stripe, $campcoupons as coupons\n";
if ($dueusd != $_POST['totalcharge']) { if ($dueusd != $_POST['totalcharge']) {

@ -73,6 +73,10 @@ $("#youth_list").on("change", "select[data-name=shirt]", function () {
updateTotal(); updateTotal();
}); });
$("input[name=campcoupons]").on("input paste change blur", function () {
updateTotal();
});
$(".list-group").on("click", ".rmpersonbtn", function () { $(".list-group").on("click", ".rmpersonbtn", function () {
$(this).parent().remove(); $(this).parent().remove();
updateTotal(); updateTotal();
@ -114,7 +118,13 @@ function updateTotal() {
return false; return false;
}).length * prices.tshirt; }).length * prices.tshirt;
totalcharge = Math.max(totalcharge, 0); var couponcharge = ($("input[name=campcoupons]").val() * 1.0);
var cardcharge = Math.max(totalcharge - couponcharge, 0);
if (prices.add_stripe_fees) {
cardcharge = (cardcharge + 0.3) / (1 - 0.029);
}
totalcharge = Math.max(cardcharge + couponcharge, 0);
// The server will refuse to finish the registration if this doesn't match // The server will refuse to finish the registration if this doesn't match
// the backend-calculated amount, don't bother being a haxxor // the backend-calculated amount, don't bother being a haxxor

@ -38,6 +38,7 @@ $SETTINGS = [
"camp" => 50.0, "camp" => 50.0,
"tshirt" => 10.0, "tshirt" => 10.0,
"adult_volunteer_daily_discount" => 10.0, "adult_volunteer_daily_discount" => 10.0,
"add_stripe_fees" => true,
// Set to false to make shirts always free, set to a number to make them // Set to false to make shirts always free, set to a number to make them
// free for people who work at least that many days // free for people who work at least that many days
"youth_tshirt" => false, "youth_tshirt" => false,

Loading…
Cancel
Save