41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
require_once 'vendor/autoload.php';
|
|
require_once 'db/config.php';
|
|
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$stripe_secret_key = getenv('STRIPE_SECRET_KEY');
|
|
if (!$stripe_secret_key) {
|
|
die('Stripe secret key is not configured.');
|
|
}
|
|
|
|
\Stripe\Stripe::setApiKey($stripe_secret_key);
|
|
|
|
$price_id = $_GET['price_id'] ?? null;
|
|
if (!$price_id) {
|
|
header('Location: pricing.php');
|
|
exit;
|
|
}
|
|
|
|
$user_email = $_SESSION['user_email']; // Assuming user_email is stored in session from login
|
|
|
|
$checkout_session = \Stripe\Checkout\Session::create([
|
|
'payment_method_types' => ['card'],
|
|
'line_items' => [[
|
|
'price' => $price_id,
|
|
'quantity' => 1,
|
|
]],
|
|
'mode' => 'subscription',
|
|
'success_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?payment=success',
|
|
'cancel_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/pricing.php?payment=cancel',
|
|
'customer_email' => $user_email,
|
|
'client_reference_id' => $_SESSION['user_id']
|
|
]);
|
|
|
|
header("Location: " . $checkout_session->url);
|