e59-website/html/pay/index.php
2024-08-13 23:54:15 +00:00

135 lines
3.7 KiB
PHP

<?php
die("Feature disabled");
$amount = 10;
$description = "Don de 10 EUR";
if ($_GET['type'] == 1) {
if (filter_var($_GET['amount'], FILTER_VALIDATE_INT)) {
$amount = $_GET['amount'];
$description = "Don de " . $_GET['amount'] . " EUR";
}
} else if ($_GET['type'] == 2){
if ($_GET['article'] == 1) {
$amount = 1;
$description = "Adhésion";
}
}
require("../../include/variables.php");
require("../../include/init.php");
if (isset($_SESSION['userID']) == false || empty($_SESSION['userID'])) {
header("Location: /login?p=adhesion");
die('Veuillez vous connecter dans <a href="/login">/login</a>');
}
require("../../include/main-functions.php");
require("../../include/inputs.php");
require("../../include/panels.php");
$client_id = 'cc_classic_znsSCWtxQRTJJVFaGqBgIjCqdES0e';
$client_secret = 'cc_sk_classic_WA2N5s5qZBk0aN0qozTfQh7RxXXjzFYa6JlYnRi7GNmQxIgeF1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sumup.com/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'client_credentials',
'client_id' => $client_id,
'client_secret' => $client_secret
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
$access_token = $responseData['access_token'];
$return_url = "https://e59.fr/pay/check_payment.php";
$merchant_code = "MCDYTE6Q";
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$charactersLength = strlen($characters);
$checkout_reference = 'E59';
for ($i = 0; $i < 5; $i++) {
$checkout_reference .= $characters[rand(0, $charactersLength - 1)];
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sumup.com/v0.1/checkouts");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $access_token",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'amount' => $amount,
'currency' => 'EUR',
'description' => $description,
'return_url' => $return_url,
'checkout_reference' => $checkout_reference,
'merchant_code' => $merchant_code
]));
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
$checkout_id = $responseData['id'];
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<?php fillHead($rootPageURL, "Pay - " . $pageName, $darkTheme, $lightTheme);?>
<style>
#sumup-card {
margin-top: 4em;
}
label {
text-wrap: wrap;
}
</style>
</head>
<body class="body">
<header>
<div class="panel-content">
<?php fillHeader($rootPageURL, $headerTitle, $headerSubtitle, $social);?>
</div>
</header>
<nav>
<div class="panel-content">
<?php fillNav($rootPageURL);?>
</div>
</nav>
<main>
<div class="content">
<div id="sumup-card"><h2 style="text-align : center;"><?=$description?></h2></div>
</div>
<script type="text/javascript" src="https://gateway.sumup.com/gateway/ecom/card/v2/sdk.js"></script>
<script type="text/javascript">
SumUpCard.mount({
id: 'sumup-card',
checkoutId: '<?=$checkout_id?>',
theme: 'dark'
});
</script>
</main>
<footer>
<div class="panel-content">
<?php fillFooter($footerText);?>
</div>
</footer>
</body>
</html>