-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.php
More file actions
63 lines (49 loc) · 1.97 KB
/
checkout.php
File metadata and controls
63 lines (49 loc) · 1.97 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
require __DIR__ . '/vendor/autoload.php';
// secret key declaration removed for security
\Stripe\Stripe::setApiKey($stripe_secret_key);
$order = json_decode($_POST['form_data']);
$cookbook_price_id = $order->cookbook->price_id;
$grimm_price_id = $order->grimm->price_id;
$isCookbookPurchased = false;
$isGrimmPurchased = false;
if (isset($cookbook_price_id) && $cookbook_price_id != "") {
$isCookbookPurchased = true;
}
if (isset($grimm_price_id) && $grimm_price_id != "") {
$isGrimmPurchased = true;
}
$line_items = [];
if (isset($order->cookbook) && isset($order->cookbook->price_id) && isset($order->cookbook->quantity)) {
$cookbook_quantity = (int) $order->cookbook->quantity;
if ($cookbook_quantity > 0) { // Ensure quantity is valid
$line_items[] = [
"quantity" => $cookbook_quantity,
"price" => $order->cookbook->price_id,
];
}
}
if (isset($order->grimm) && isset($order->grimm->price_id) && isset($order->grimm->quantity)) {
$grimm_quantity = (int) $order->grimm->quantity;
if ($grimm_quantity > 0) { // Ensure quantity is valid
$line_items[] = [
"quantity" => $grimm_quantity,
"price" => $order->grimm->price_id,
];
}
}
if (!empty($line_items)) {
$checkout_session = \Stripe\Checkout\Session::create([
"mode" => "payment",
"success_url" => "https://www.christophersaid.com/wdv351/success.php",
"cancel_url" => "https://www.christophersaid.com/wdv351/cancel.php",
"line_items" => $line_items,
]);
} else {
die('Error: No valid items to purchase.');
}
session_start();
$_SESSION["cookbook_purchased"] = $isCookbookPurchased;
$_SESSION["grimm_purchased"] = $isGrimmPurchased;
http_response_code(303);
header('Location: ' . $checkout_session->url);