genderwatchprotocol/donations/donations.php

67 lines
2.4 KiB
PHP
Raw Normal View History

2023-02-16 14:25:14 +01:00
<?php
2023-02-16 19:41:27 +01:00
$dolibarrURL = "https://dolibarr.romanschenk.ch/";
2023-02-16 20:14:11 +01:00
$dolibarrAPIKey = "4mQX4x4x65MlkGZ9HUD5A4oElqTn92kl";
function createDonation($amount, $dolibarrURL, $dolibarrAPIKey) {
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 20:03:25 +01:00
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"amount\": ".$amount.", \"date\": ".time().", \"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';
2023-02-16 20:14:11 +01:00
$headers[] = 'Dolapikey: '.$dolibarrAPIKey;
2023-02-16 14:25:14 +01:00
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 20:14:11 +01:00
function validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey) {
2023-02-16 19:41:27 +01:00
$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';
2023-02-16 20:14:11 +01:00
$headers[] = 'Dolapikey: '.$dolibarrAPIKey;
2023-02-16 19:41:27 +01:00
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
}
2023-02-16 20:14:11 +01:00
function forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey){
$donationID = createDonation($amount, $dolibarrURL, $dolibarrAPIKey);
validateDonation($donationID, $dolibarrURL, $dolibarrAPIKey);
2023-02-16 19:41:27 +01:00
$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 20:14:11 +01:00
forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey);
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 20:14:11 +01:00
forwardToDonationPage($amount, $dolibarrURL, $dolibarrAPIKey);
2023-02-16 19:29:41 +01:00
} else {
echo "invalid amount!";
}
2023-02-16 14:36:53 +01:00
}