donations.php

cleanup
This commit is contained in:
schrom01 2023-02-16 20:14:11 +01:00
parent ec71770847
commit f0a1149558
1 changed files with 10 additions and 9 deletions

View File

@ -1,6 +1,7 @@
<?php
$dolibarrURL = "https://dolibarr.romanschenk.ch/";
function createDonation($amount, $dolibarrURL) {
$dolibarrAPIKey = "4mQX4x4x65MlkGZ9HUD5A4oElqTn92kl";
function createDonation($amount, $dolibarrURL, $dolibarrAPIKey) {
$BusinesspartnerID = "220";
$pulicNote = "Automatisch generiert von genderwatchprotocol.com";
$ch = curl_init();
@ -13,7 +14,7 @@ function createDonation($amount, $dolibarrURL) {
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
$headers[] = 'Dolapikey: 4mQX4x4x65MlkGZ9HUD5A4oElqTn92kl';
$headers[] = 'Dolapikey: '.$dolibarrAPIKey;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
@ -24,7 +25,7 @@ function createDonation($amount, $dolibarrURL) {
return $result;
}
function validateDonation($donationID, $dolibarrURL) {
function validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $dolibarrURL."api/index.php/donations/".$donationID."/validate");
@ -35,7 +36,7 @@ function validateDonation($donationID, $dolibarrURL) {
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
$headers[] = 'Dolapikey: 4mQX4x4x65MlkGZ9HUD5A4oElqTn92kl';
$headers[] = 'Dolapikey: '.$dolibarrAPIKey;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
@ -45,20 +46,20 @@ function validateDonation($donationID, $dolibarrURL) {
curl_close($ch);
return $result;
}
function forwardToDonationPage($amount, $dolibarrURL){
$donationID = createDonation($amount, $dolibarrURL);
validateDonation($donationID, $dolibarrURL);
function forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey){
$donationID = createDonation($amount, $dolibarrURL, $dolibarrAPIKey);
validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey);
$payment_link = $dolibarrURL."public/payment/newpayment.php?source=donation&ref=".($donationID)."&securekey=NSmKzZ73HW1zWO8nAlpdq95mDt77Q32o";
header('Location: '.$payment_link);
}
$amount = (float)($_GET["amount"]);
if(is_numeric($amount) && $amount > 0) {
forwardToDonationPage($amount, $dolibarrURL);
forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey);
} else {
$amount = (float)($_POST["amount"]);
if(is_numeric($amount) && $amount > 0) {
forwardToDonationPage($amount, $dolibarrURL);
forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey);
} else {
echo "invalid amount!";
}