-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment_process.php
More file actions
39 lines (33 loc) · 1.14 KB
/
payment_process.php
File metadata and controls
39 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require 'vendor/autoload.php';
require 'db.php';
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$user_id = $_SESSION['user_id'];
$plan = $_GET['plan'];
$stripe = new \Stripe\StripeClient('sk_test_51QNWQKG2zxFLmtj9w1HsGLgAkVByklUMkMC59EYOk9A2XNaL5azhcTTlFT2LE5oJMkYPxOysXU4cdJidanITC70n00S49ksdJ4'); // Use your secret key
$amount = $plan === 'monthly' ? 99900 : 1008000;
$description = $plan === 'monthly' ? 'Monthly Premium Plan' : 'Annual Premium Plan';
// Create a checkout session
$checkout_session = $stripe->checkout->sessions->create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => 'lkr',
'product_data' => [
'name' => $description,
],
'unit_amount' => $amount,
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => 'http://localhost/petiverse/payment_success.php?session_id={CHECKOUT_SESSION_ID}&plan='.$plan,
'cancel_url' => 'http://localhost/petiverse/subscription.php',
]);
header('Location: ' . $checkout_session->url);
exit;
?>