2023-02-16 14:25:14 +01:00
|
|
|
<?php
|
2023-02-16 19:47:25 +01:00
|
|
|
echo "test";
|
2023-02-16 19:48:17 +01:00
|
|
|
//echo date();
|
2023-02-16 19:47:25 +01:00
|
|
|
echo "test2";
|
|
|
|
echo mktime();
|
2023-02-16 19:41:27 +01:00
|
|
|
$dolibarrURL = "https://dolibarr.romanschenk.ch/";
|
|
|
|
function createDonation($amount, $dolibarrURL) {
|
2023-02-16 14:45:36 +01:00
|
|
|
$BusinesspartnerID = "220";
|
2023-02-16 14:52:26 +01:00
|
|
|
$pulicNote = "Automatisch generiert von genderwatchprotocol.com";
|
2023-02-16 14:25:14 +01:00
|
|
|
$ch = curl_init();
|
|
|
|
|
2023-02-16 19:41:27 +01:00
|
|
|
curl_setopt($ch, CURLOPT_URL, $dolibarrURL."api/index.php/donations");
|
2023-02-16 14:25:14 +01:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
2023-02-16 15:06:31 +01:00
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"amount\": ".$amount.", \"date\": 1676545200, \"socid\": ".$BusinesspartnerID.", \"note_public\": \"Automatisch generiert von genderwatchprotocol.com\"}");
|
2023-02-16 14:25:14 +01:00
|
|
|
|
|
|
|
$headers = array();
|
|
|
|
$headers[] = 'Content-Type: application/json';
|
|
|
|
$headers[] = 'Accept: application/json';
|
|
|
|
$headers[] = 'Dolapikey: 4mQX4x4x65MlkGZ9HUD5A4oElqTn92kl';
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
if (curl_errno($ch)) {
|
|
|
|
echo 'Error:' . curl_error($ch);
|
|
|
|
}
|
|
|
|
curl_close($ch);
|
2023-02-16 14:27:36 +01:00
|
|
|
return $result;
|
2023-02-16 14:25:14 +01:00
|
|
|
}
|
|
|
|
|
2023-02-16 19:41:27 +01:00
|
|
|
function validateDonation($donationID, $dolibarrURL) {
|
|
|
|
$ch = curl_init();
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $dolibarrURL."api/index.php/donations/".$donationID."/validate");
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}");
|
|
|
|
|
|
|
|
$headers = array();
|
|
|
|
$headers[] = 'Content-Type: application/json';
|
|
|
|
$headers[] = 'Accept: application/json';
|
|
|
|
$headers[] = 'Dolapikey: 4mQX4x4x65MlkGZ9HUD5A4oElqTn92kl';
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
if (curl_errno($ch)) {
|
|
|
|
echo 'Error:' . curl_error($ch);
|
|
|
|
}
|
|
|
|
curl_close($ch);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
function forwardToDonationPage($amount, $dolibarrURL){
|
|
|
|
$donationID = createDonation($amount, $dolibarrURL);
|
|
|
|
validateDonation($donationID, $dolibarrURL);
|
|
|
|
$payment_link = $dolibarrURL."public/payment/newpayment.php?source=donation&ref=".($donationID)."&securekey=NSmKzZ73HW1zWO8nAlpdq95mDt77Q32o";
|
2023-02-16 14:36:53 +01:00
|
|
|
header('Location: '.$payment_link);
|
|
|
|
}
|
|
|
|
|
|
|
|
$amount = (float)($_GET["amount"]);
|
2023-02-16 14:38:15 +01:00
|
|
|
if(is_numeric($amount) && $amount > 0) {
|
2023-02-16 19:41:27 +01:00
|
|
|
forwardToDonationPage($amount, $dolibarrURL);
|
2023-02-16 14:36:53 +01:00
|
|
|
} else {
|
2023-02-16 19:29:41 +01:00
|
|
|
$amount = (float)($_POST["amount"]);
|
|
|
|
if(is_numeric($amount) && $amount > 0) {
|
2023-02-16 19:41:27 +01:00
|
|
|
forwardToDonationPage($amount, $dolibarrURL);
|
2023-02-16 19:29:41 +01:00
|
|
|
} else {
|
|
|
|
echo "invalid amount!";
|
|
|
|
}
|
2023-02-16 14:36:53 +01:00
|
|
|
}
|