79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// Ensure user is logged in
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// Include the Stripe PHP library (assuming it's installed via Composer)
|
|
// require_once 'vendor/autoload.php';
|
|
|
|
// Set your Stripe API key
|
|
// \Stripe\Stripe::setApiKey('YOUR_STRIPE_SECRET_KEY');
|
|
|
|
$plan = $_GET['plan'] ?? 'basic';
|
|
|
|
$line_items = [];
|
|
|
|
if ($plan === 'basic') {
|
|
$line_items[] = [
|
|
'price_data' => [
|
|
'currency' => 'usd',
|
|
'product_data' => [
|
|
'name' => 'Basic Plan',
|
|
],
|
|
'unit_amount' => 500, // $5.00
|
|
'recurring' => [
|
|
'interval' => 'month',
|
|
],
|
|
],
|
|
'quantity' => 1,
|
|
];
|
|
} elseif ($plan === 'pro') {
|
|
$line_items[] = [
|
|
'price_data' => [
|
|
'currency' => 'usd',
|
|
'product_data' => [
|
|
'name' => 'Pro Plan',
|
|
],
|
|
'unit_amount' => 1500, // $15.00
|
|
'recurring' => [
|
|
'interval' => 'month',
|
|
],
|
|
],
|
|
'quantity' => 1,
|
|
];
|
|
} else {
|
|
// Redirect to pricing page if plan is not recognized
|
|
header('Location: pricing.php');
|
|
exit;
|
|
}
|
|
|
|
/*
|
|
try {
|
|
$checkout_session = \Stripe\Checkout\Session::create([
|
|
'payment_method_types' => ['card'],
|
|
'line_items' => $line_items,
|
|
'mode' => 'subscription',
|
|
'success_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/ritual.php',
|
|
'cancel_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/pricing.php',
|
|
'customer_email' => $_SESSION['user_email'], // Pre-fill email
|
|
'client_reference_id' => $_SESSION['user_id'],
|
|
]);
|
|
|
|
header("Location: " . $checkout_session->url);
|
|
exit;
|
|
} catch (Exception $e) {
|
|
// Handle any errors that occur
|
|
error_log('Stripe Error: ' . $e->getMessage());
|
|
header('Location: pricing.php?error=1');
|
|
exit;
|
|
}
|
|
*/
|
|
|
|
// For now, we will simulate a successful payment and redirect to the ritual page.
|
|
header('Location: ritual.php?payment=success');
|
|
exit;
|
|
?>
|