donations.php
This commit is contained in:
parent
c3f787f14a
commit
e6c89a06d3
|
@ -1,12 +1,13 @@
|
|||
<?php
|
||||
|
||||
function createDonation($amount) {
|
||||
$dolibarrURL = "https://dolibarr.romanschenk.ch/api/index.php/donations";
|
||||
|
||||
$dolibarrURL = "https://dolibarr.romanschenk.ch/";
|
||||
function createDonation($amount, $dolibarrURL) {
|
||||
$BusinesspartnerID = "220";
|
||||
$pulicNote = "Automatisch generiert von genderwatchprotocol.com";
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $dolibarrURL);
|
||||
curl_setopt($ch, CURLOPT_URL, $dolibarrURL."api/index.php/donations");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"amount\": ".$amount.", \"date\": 1676545200, \"socid\": ".$BusinesspartnerID.", \"note_public\": \"Automatisch generiert von genderwatchprotocol.com\"}");
|
||||
|
@ -25,18 +26,41 @@ function createDonation($amount) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
function forwardToDonationPage($amount){
|
||||
$payment_link = "https://dolibarr.romanschenk.ch/public/payment/newpayment.php?source=donation&ref=".(createDonation($amount))."&securekey=NSmKzZ73HW1zWO8nAlpdq95mDt77Q32o";
|
||||
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";
|
||||
header('Location: '.$payment_link);
|
||||
}
|
||||
|
||||
$amount = (float)($_GET["amount"]);
|
||||
if(is_numeric($amount) && $amount > 0) {
|
||||
forwardToDonationPage($amount);
|
||||
forwardToDonationPage($amount, $dolibarrURL);
|
||||
} else {
|
||||
$amount = (float)($_POST["amount"]);
|
||||
if(is_numeric($amount) && $amount > 0) {
|
||||
forwardToDonationPage($amount);
|
||||
forwardToDonationPage($amount, $dolibarrURL);
|
||||
} else {
|
||||
echo "invalid amount!";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue