donations.php

cleanup
This commit is contained in:
schrom01 2023-02-16 21:03:06 +01:00
parent 32df2cde0a
commit 6aa0eb362d
2 changed files with 10 additions and 9 deletions

View File

@ -5,17 +5,18 @@ $conn = getDatabaseConnection();
$sql = "SELECT `value` FROM `dolibarrInformation` WHERE `information` = 'apiKey'"; $sql = "SELECT `value` FROM `dolibarrInformation` WHERE `information` = 'apiKey'";
$result = $conn->query($sql); $result = $conn->query($sql);
$dolibarrAPIKey = $result->fetch_assoc()["value"]; $dolibarrAPIKey = $result->fetch_assoc()["value"];
//$dolibarrAPIKey = "eM6A2bQP36Q7dhELq02qnD7sY4do5KRa";
$conn = getDatabaseConnection(); $conn = getDatabaseConnection();
$sql = "SELECT `value` FROM `dolibarrInformation` WHERE `information` = 'url'"; $sql = "SELECT `value` FROM `dolibarrInformation` WHERE `information` = 'url'";
$result = $conn->query($sql); $result = $conn->query($sql);
$dolibarrURL = $result->fetch_assoc()["value"]; $dolibarrURL = $result->fetch_assoc()["value"];
//$dolibarrURL = "https://dolibarr.romanschenk.ch/";
$conn = getDatabaseConnection();
$sql = "SELECT `value` FROM `dolibarrInformation` WHERE `information` = 'socid'";
$result = $conn->query($sql);
$BusinesspartnerID = $result->fetch_assoc()["value"];
function createDonation($amount, $dolibarrURL, $dolibarrAPIKey) { function createDonation($amount, $dolibarrURL, $dolibarrAPIKey, $BusinesspartnerID) {
$BusinesspartnerID = "220";
$pulicNote = "Automatisch generiert von genderwatchprotocol"; $pulicNote = "Automatisch generiert von genderwatchprotocol";
$ch = curl_init(); $ch = curl_init();
@ -59,8 +60,8 @@ function validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey) {
curl_close($ch); curl_close($ch);
return $result; return $result;
} }
function forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey){ function forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey, $BusinesspartnerID){
$donationID = createDonation($amount, $dolibarrURL, $dolibarrAPIKey); $donationID = createDonation($amount, $dolibarrURL, $dolibarrAPIKey, $BusinesspartnerID);
validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey); validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey);
$payment_link = $dolibarrURL."public/payment/newpayment.php?source=donation&ref=".($donationID)."&securekey=NSmKzZ73HW1zWO8nAlpdq95mDt77Q32o"; $payment_link = $dolibarrURL."public/payment/newpayment.php?source=donation&ref=".($donationID)."&securekey=NSmKzZ73HW1zWO8nAlpdq95mDt77Q32o";
header('Location: '.$payment_link); header('Location: '.$payment_link);
@ -68,11 +69,11 @@ function forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey){
$amount = (float)($_GET["amount"]); $amount = (float)($_GET["amount"]);
if(is_numeric($amount) && $amount > 0) { if(is_numeric($amount) && $amount > 0) {
forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey); forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey, $BusinesspartnerID);
} else { } else {
$amount = (float)($_POST["amount"]); $amount = (float)($_POST["amount"]);
if(is_numeric($amount) && $amount > 0) { if(is_numeric($amount) && $amount > 0) {
forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey); forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey, $BusinesspartnerID);
} else { } else {
echo "invalid amount!"; echo "invalid amount!";
} }

View File

@ -172,7 +172,7 @@
Diese Webseite wird ausschliesslich durch Spenden finanziert.<br>Helfen Sie bei der Fianzierung mit einer freiwilligen Spende. Diese Webseite wird ausschliesslich durch Spenden finanziert.<br>Helfen Sie bei der Fianzierung mit einer freiwilligen Spende.
</p> </p>
<form method="post" action="donations/donations.php" target="_blank"> <form method="post" action="donations/donations.php" target="_blank">
<input type="number" name="amount" placeholder="Betrag eingeben"> <input required type="number" name="amount" placeholder="Betrag eingeben">
<button type="submit">Jetzt spenden</button> <button type="submit">Jetzt spenden</button>
</form> </form>
</td> </td>