156 lines
4.4 KiB
PHP
Executable File
156 lines
4.4 KiB
PHP
Executable File
<?php
|
|
|
|
require("../../include/variables.php");
|
|
require("../../include/init.php");
|
|
|
|
if (isset($_SESSION['userID']) == false || empty($_SESSION['userID'])) {
|
|
header("Location: /login?p=pay");
|
|
die('Veuillez vous connecter dans <a href="/login">/login</a>');
|
|
}
|
|
|
|
require("../../include/main-functions.php");
|
|
require("../../include/inputs.php");
|
|
require("../../include/panels.php");
|
|
|
|
$pdo = sqlConnect($sqlDatabaseHost, $sqlDatabaseName, $sqlDatabaseUser, $sqlDatabasePass);
|
|
|
|
$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'];
|
|
|
|
|
|
$request = $pdo->prepare("SELECT etape_adhesion FROM adherents WHERE userid = :userID");
|
|
$request->bindParam(":userID", $_SESSION['userID']);
|
|
$request->execute();
|
|
$user_data = $request->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$amount = 10;
|
|
$description = "DON@" . $_SESSION['userName'];
|
|
$title = "Don de 10 €";
|
|
$adhesion = 0;
|
|
|
|
if (isset($_GET['type'])) {
|
|
if ($_GET['type'] == 1) {
|
|
if (filter_var($_GET['amount'], FILTER_VALIDATE_INT)) {
|
|
$amount = $_GET['amount'];
|
|
$description = "DON@" . $_SESSION['userName'];
|
|
$title = "Don de $amount €";
|
|
}
|
|
} else if ($_GET['type'] == 2){
|
|
if ($_GET['article'] == 1) {
|
|
if ($user_data[0]['etape_adhesion'] == 2) {
|
|
$amount = 1;
|
|
$description = "BUYADH@" . $_SESSION['userName'];
|
|
$title = "Cotisation";
|
|
$adhesion = 1;
|
|
} else {
|
|
$amount = 1;
|
|
$description = "DON@" . $_SESSION['userName'];
|
|
$title = "Don de 1 €";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$return_url = "https://e59.fr/pay/check_payment.php";
|
|
$redirect_url = "https://e59.fr/adhesion?step2";
|
|
$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;"><?=$title?></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?>'
|
|
});
|
|
</script>
|
|
</main>
|
|
<footer>
|
|
<div class="panel-content">
|
|
<?php fillFooter($footerText);?>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|