/login'); } 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']; ?>