load('/resources/includes/.env'); \Stripe\Stripe::setApiKey($_ENV['STRIPETESTKEY']); $stripe = new \Stripe\StripeClient($_ENV['STRIPETESTKEY']); header('Content-Type: application/json'); $YOUR_DOMAIN = 'https://id.jconet.co.uk'; ini_set('session.cookie_domain', '.jconet.co.uk'); session_start(); $code = uniqid('stripeAPI_'); $product = $_GET['product']; define('dbHost', $_ENV['DATABASEHOSTNAME']); define('dbUser', $_ENV['DATABASEUSERNAME']); define('dbPass', $_ENV['DATABASEPASSWORD']); define('dbName', $_ENV['DATABASENAME']); $conn = mysqli_connect(dbHost,dbUser,dbPass,dbName); if ($product == 'buyVerify') { $_SESSION['code'] = $code; // live price price_1Jm2SYEOJsqRXL0Rm2xIZkZI // test price price_1K2GvGEOJsqRXL0R7vj4Lyvq define('price', "price_1K2GvGEOJsqRXL0R7vj4Lyvq"); $result = mysqli_query($conn, "SELECT * FROM customers WHERE ID ='".$_SESSION['userID']."'"); $num_rows = mysqli_num_rows($result); $customerDB = mysqli_fetch_all($result, MYSQLI_ASSOC); if ($num_rows > 0) { $custID = $customerDB[0]['stripeID']; $stripeSession = \Stripe\Checkout\Session::create([ 'payment_method_types' => [ 'card', ], 'line_items' => [[ # TODO: replace this with the `price` of the product you want to sell 'price' => price, 'quantity' => 1, 'description' => "JCoNet Digital ID verification fee. Payment gets you one(1) token to verify your identity and age on your JCN Digital ID via our supplier (Stripe Identity)", ]], 'mode' => 'payment', 'customer' => $custID, 'allow_promotion_codes' => true, 'success_url' => $YOUR_DOMAIN . '/idfunctions.php?status=SUCCESS&code='.$code, 'cancel_url' => $YOUR_DOMAIN . '/idfunctions.php?status=CANCEL&code='.$code, ]); echo ("What went wrong?"); } else { echo("no result"); $result2 = mysqli_query($conn, "SELECT * FROM users WHERE ID ='".$_SESSION['userID']."'"); $num_rows2 = mysqli_num_rows($result2); $userDB = mysqli_fetch_all($result2, MYSQLI_ASSOC); $stripeSession = \Stripe\Checkout\Session::create([ 'payment_method_types' => [ 'card', ], 'line_items' => [[ # TODO: replace this with the `price` of the product you want to sell 'price' => price, 'quantity' => 1, 'description' => "JCoNet Digital ID verification fee. Payment gets you one(1) token to verify your identity and age on your JCN Digital ID via our supplier (Stripe Identity)" ]], 'mode' => 'payment', 'customer_email' => $userDB[0]['Email'], 'allow_promotion_codes' => true, 'success_url' => $YOUR_DOMAIN . '/idfunctions.php?status=SUCCESS&code='.$code.'&session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => $YOUR_DOMAIN . '/idfunctions.php?status=CANCEL&code='.$code, ]); }; } elseif ($product == 'Verify') { $_SESSION['code'] = $code; $stripeSession = $stripe->identity->verificationSessions->create([ 'type' => 'document', 'options' => [ 'document' => [ 'require_matching_selfie' => true, ], ], 'return_url' => $YOUR_DOMAIN.'/idfunctions.php?status=VERIFIED&code='.$code, 'metadata' => [ 'user_id' => $_SESSION['userID'], ], ]); }; header("HTTP/1.1 303 See Other"); header("Location: " . $stripeSession->url);