Skip to content

Commit

Permalink
Refactor limits, add backdoor
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 28, 2022
1 parent 70f9d11 commit 69c41ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ $mollie_apikey_live = "live_...";
$mollie_apikey_test = "test_...";

$mollie_test = true; # set to false to use the live environment

$limit_min = 13.37;
$limit_max = 150;
$limit_backdoor = "boardgavepermission";
11 changes: 6 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta name=robots content=noindex,nofollow>
<title>RevBank Deposit</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php include("config.php"); ?>
<style>
body, a {
background: black;
Expand Down Expand Up @@ -53,8 +54,8 @@
</style>
<script>
function ch(e) {
document.getElementById("exceeded").style.visibility = e.value && e.value > 150 ? "visible" : "hidden";
document.getElementById("insufficient").style.visibility = e.value && e.value < 13.37 ? "visible" : "hidden";
document.getElementById("exceeded").style.visibility = e.value && e.value > <?php print($limit_max); ?> ? "visible" : "hidden";
document.getElementById("insufficient").style.visibility = e.value && e.value < <?php print($limit_min); ?> ? "visible" : "hidden";
return true;
}
function x() {
Expand Down Expand Up @@ -106,9 +107,9 @@ function x() {
<h1>Deposit</h1>
Here, you can buy an Aztec barcode that you can scan to add money to your RevBank account.
<form method=post action=mollie.php>
Amount: <input id=custom type=text size=6 maxlength=6 style="width:6ch" name=amount pattern="(?:[0-9]+(?:[,.][0-9]{2})?)?" title="42 or 42.00 or 42,00" onkeyup="return ch(this)" value="<?php echo($prefill); ?>"> <input type=submit value=ok><br>
<div id=insufficient>Note: the minimum amount is 13.37 because of transaction fees that we can't (legally) pass on to you.</div>
<div id=exceeded>Note: the maximum amount is 150.</div>
Amount: <input id=custom type=text size=6 maxlength=21 style="width:6ch" name=amount pattern="(?:[0-9]+(?:[,.][0-9]{2})?)?(?:!\w+)?" title="42 or 42.00 or 42,00" onkeyup="return ch(this)" value="<?php echo($prefill); ?>"> <input type=submit value=ok><br>
<div id=insufficient>Note: the minimum amount is <?php print($limit_min); ?> because of transaction fees that we can't (legally) pass on to you.</div>
<div id=exceeded>Note: the maximum amount is <?php print($limit_max); ?>.</div>
<p>
<br><br>
Or pick a preset:<br>
Expand Down
13 changes: 10 additions & 3 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@
// client is user

$amount = $_POST["amount"];
$ignore_limits = preg_match("/!$limit_backdoor$/", $amount);
if ($ignore_limits) {
$amount = preg_replace("/!$limit_backdoor$/", "", $amount);
}

if (! preg_match("/^[0-9]+(?:[,.][0-9]{2})?\\z/", $amount)) die("Invalid amount");
$amount = preg_replace("/,/", ".", $amount);
if (! preg_match("/\\./", $amount)) $amount .= ".00";

if ($amount < 13.37) die("Minimum 13.37");
if ($amount > 150) die("Maximum 150.00");

if (!$ignore_limits) {
if ($amount < $limit_min) die("Minimum $limit_min");
if ($amount > $limit_max) die("Maximum $limit_max");
}

$payment = $mollie->payments->create([
"amount" => [ "value" => $amount, "currency" => "EUR" ],
Expand Down

0 comments on commit 69c41ce

Please sign in to comment.