From 9854ec529d6bbee20286e6cb5f8e8a6212d4435d Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 20 Apr 2022 14:15:24 -0600 Subject: [PATCH] Add stripe fees, fix price vars --- public/actions/submit.php | 22 ++++++++++++++-------- public/static/signup.js | 12 +++++++++++- settings.template.php | 1 + 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/public/actions/submit.php b/public/actions/submit.php index bdc4d65..4d4e82f 100644 --- a/public/actions/submit.php +++ b/public/actions/submit.php @@ -21,7 +21,7 @@ if (!empty($SETTINGS["disable_registration"]) && $SETTINGS["disable_registration die("Online registration is now closed."); } -$database->action(function($database) { +$database->action(function ($database) { global $SETTINGS; $database->insert("families", []); @@ -143,8 +143,8 @@ $database->action(function($database) { switch ($people["type"][$pid]) { case "camper": - $dueusd += 50.0; - echo "\nAdding $50 to the total for a camper, dueusd is $dueusd\n"; + $dueusd += $SETTINGS["prices"]["camp"]; + echo "\nAdding $$SETTINGS[prices][camp] to the total for a camper, dueusd is $dueusd\n"; $database->insert("campers", [ "parentname" => $people["parentname"][$pid], "rank" => $people["rank"][$pid] @@ -152,7 +152,7 @@ $database->action(function($database) { $camperid = $database->id(); break; case "adult": - $discount = 10.0 * (strlen($days) / 2); + $discount = $SETTINGS["prices"]["adult_volunteer_daily_discount"] * (strlen($days) / 2); $dueusd -= $discount; echo "Subtracting $$discount from the total for an adult volunteer, dueusd is $dueusd\n"; // Add shirt charge if not working all days @@ -160,8 +160,8 @@ $database->action(function($database) { // No shirt cost } else if ($SETTINGS["prices"]["adult_tshirt"] !== false) { if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["adult_tshirt"]) { - echo "Adding $10 for a tshirt.\n"; - $dueusd += 10.0; + echo "Adding $$SETTINGS[prices][tshirt] for a tshirt.\n"; + $dueusd += $SETTINGS["prices"]["tshirt"]; } } if (!empty($people["child_care"][$pid])) { @@ -182,8 +182,8 @@ $database->action(function($database) { case "youth": if ($SETTINGS["prices"]["youth_tshirt"] !== false) { if ($people["shirt"][$pid] != "NO" && (strlen($days) / 2) < $SETTINGS["prices"]["youth_tshirt"]) { - echo "Adding $10 for a tshirt.\n"; - $dueusd += 10.0; + echo "Adding $$SETTINGS[prices][tshirt] for a tshirt.\n"; + $dueusd += $SETTINGS["prices"]["tshirt"]; } } $database->insert("youth", [ @@ -235,6 +235,12 @@ $database->action(function($database) { $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"; if ($dueusd != $_POST['totalcharge']) { diff --git a/public/static/signup.js b/public/static/signup.js index dd3eee6..9bf4739 100644 --- a/public/static/signup.js +++ b/public/static/signup.js @@ -73,6 +73,10 @@ $("#youth_list").on("change", "select[data-name=shirt]", function () { updateTotal(); }); +$("input[name=campcoupons]").on("input paste change blur", function () { + updateTotal(); +}); + $(".list-group").on("click", ".rmpersonbtn", function () { $(this).parent().remove(); updateTotal(); @@ -114,7 +118,13 @@ function updateTotal() { return false; }).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 backend-calculated amount, don't bother being a haxxor diff --git a/settings.template.php b/settings.template.php index 9a757c6..9a4da2b 100644 --- a/settings.template.php +++ b/settings.template.php @@ -38,6 +38,7 @@ $SETTINGS = [ "camp" => 50.0, "tshirt" => 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 // free for people who work at least that many days "youth_tshirt" => false,