v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/includes/config.php';
- require_once __DIR__ . '/includes/database.php';
- require_once __DIR__ . '/includes/user-auth.php';
- require_once __DIR__ . '/includes/language.php';
- require_once __DIR__ . '/includes/site-front.php';
- require_once __DIR__ . '/includes/cart.php';
- require_once __DIR__ . '/includes/currency.php';
-
- UserAuth::boot();
-
- $settings = SiteFront::settings();
- $sessionId = trim((string) ($_GET['session_id'] ?? ''));
- $orderId = (int) ($_GET['order_id'] ?? 0);
-
- $order = null;
- $orderItems = [];
-
- if ($orderId > 0) {
- $usersDb = Database::users();
- $statement = $usersDb->prepare('SELECT * FROM orders WHERE id = :id LIMIT 1');
- $statement->execute(['id' => $orderId]);
- $candidateOrder = $statement->fetch();
-
- $currentCustomer = UserAuth::user();
- $sessionOwnsOrder = isset($_SESSION['checkout_order_ids']) && is_array($_SESSION['checkout_order_ids'])
- && in_array($orderId, $_SESSION['checkout_order_ids'], true);
- $accountOwnsOrder = $candidateOrder && $currentCustomer !== null
- && $candidateOrder['user_account_id'] !== null
- && (int) $candidateOrder['user_account_id'] === (int) $currentCustomer['id'];
-
- if ($candidateOrder && ($sessionOwnsOrder || $accountOwnsOrder)) {
- $order = $candidateOrder;
- $itemsStatement = $usersDb->prepare('SELECT * FROM order_items WHERE order_id = :id ORDER BY id ASC');
- $itemsStatement->execute(['id' => $orderId]);
- $orderItems = $itemsStatement->fetchAll();
- }
- }
-
- if ($sessionId !== '' || $order !== null) {
- Cart::clear();
- }
-
- require_once __DIR__ . '/includes/digital-files.php';
-
- $orderHasDownloads = false;
- $orderDownloads = [];
- if ($order !== null) {
- $orderIsPaid = in_array($order['status'], DigitalFiles::PAID_ORDER_STATUSES, true);
- $orderTokens = $orderIsPaid ? DigitalFiles::tokensForOrder((int) $order['id']) : [];
- $viewer = UserAuth::user();
- $viewerOwnsAccountOrder = $viewer !== null && $order['user_account_id'] !== null && (int) $order['user_account_id'] === (int) $viewer['id'];
-
- foreach (array_unique(array_map(static fn(array $item): int => (int) $item['product_id'], $orderItems)) as $orderProductId) {
- $orderProductFiles = DigitalFiles::filesForProduct($orderProductId);
- if (empty($orderProductFiles)) {
- continue;
- }
- $orderHasDownloads = true;
-
- if (!$orderIsPaid) {
- continue;
- }
-
- $productToken = $viewerOwnsAccountOrder ? null : ($orderTokens[$orderProductId] ?? null);
- if (!$viewerOwnsAccountOrder && $productToken === null) {
- continue;
- }
-
- foreach ($orderProductFiles as $orderProductFile) {
- $orderDownloads[] = [
- 'name' => DigitalFiles::displayName($orderProductFile),
- 'size' => (int) $orderProductFile['size_bytes'],
- 'url' => DigitalFiles::downloadUrl((int) $orderProductFile['id'], $productToken),
- ];
- }
- }
- }
-
- $pageTitle = Language::get('order_confirmation_title', 'Thank you') . ' - ' . $settings['site_name'];
- $pageDescription = '';
-
- require __DIR__ . '/includes/front-header.php';
-
- ?>
- <h1 class="article-title"><?= htmlspecialchars(Language::get('order_confirmation_title', 'Thank you')) ?></h1>
-
- <?php if ($order !== null): ?>
- <?php if ($order['status'] === 'pending'): ?>
- <p><?= htmlspecialchars(Language::get('order_confirmation_processing', 'Your payment is still being processed. This page will show your final order status once confirmed — you will also receive a confirmation email.')) ?></p>
- <?php else: ?>
- <p><?= htmlspecialchars(Language::get('order_confirmation_success', 'Your order has been placed successfully.')) ?></p>
- <?php endif; ?>
-
- <div class="order-summary">
- <p><strong><?= htmlspecialchars(Language::get('order_number_label', 'Order number')) ?>:</strong> <?= htmlspecialchars($order['order_number']) ?></p>
- <p><strong><?= htmlspecialchars(Language::get('order_status_label', 'Status')) ?>:</strong> <span class="status-pill status-<?= htmlspecialchars($order['status']) ?>"><?= htmlspecialchars(Language::get('order_status_' . $order['status'], ucfirst($order['status']))) ?></span></p>
-
- <table class="dash-table">
- <thead>
- <tr>
- <th><?= htmlspecialchars(Language::get('cart_column_product', 'Product')) ?></th>
- <th><?= htmlspecialchars(Language::get('cart_column_quantity', 'Quantity')) ?></th>
- <th><?= htmlspecialchars(Language::get('cart_column_total', 'Total')) ?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ($orderItems as $item): ?>
- <tr>
- <td><?= htmlspecialchars($item['product_title_snapshot']) ?><?= $item['variant_name_snapshot'] !== null ? ' — ' . htmlspecialchars($item['variant_name_snapshot']) : '' ?></td>
- <td><?= (int) $item['quantity'] ?></td>
- <td><?= htmlspecialchars(Currency::format((int) $item['total_cents'], $order['currency'])) ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
-
- <div class="cart-summary">
- <div class="cart-summary-row"><span><?= htmlspecialchars(Language::get('cart_subtotal', 'Subtotal')) ?></span><span><?= htmlspecialchars(Currency::format((int) $order['subtotal_cents'], $order['currency'])) ?></span></div>
- <?php if ((int) $order['discount_cents'] > 0): ?>
- <div class="cart-summary-row"><span><?= htmlspecialchars(Language::get('cart_discount', 'Discount')) ?></span><span>-<?= htmlspecialchars(Currency::format((int) $order['discount_cents'], $order['currency'])) ?></span></div>
- <?php endif; ?>
- <?php if ((int) $order['shipping_cents'] > 0): ?>
- <div class="cart-summary-row"><span><?= htmlspecialchars(Language::get('order_shipping_label', 'Shipping')) ?></span><span><?= htmlspecialchars(Currency::format((int) $order['shipping_cents'], $order['currency'])) ?></span></div>
- <?php endif; ?>
- <div class="cart-summary-row cart-summary-total"><span><?= htmlspecialchars(Language::get('cart_total', 'Total')) ?></span><span><?= htmlspecialchars(Currency::format((int) $order['total_cents'], $order['currency'])) ?></span></div>
- </div>
- </div>
-
- <?php if ($orderHasDownloads): ?>
- <h2><?= htmlspecialchars(Language::get('order_downloads_title', 'Your downloads')) ?></h2>
- <?php if (!empty($orderDownloads)): ?>
- <ul class="download-list">
- <?php foreach ($orderDownloads as $orderDownload): ?>
- <li>
- <a href="<?= htmlspecialchars($orderDownload['url']) ?>" rel="nofollow"><?= Icons::icon('download', 'icon icon-sm') ?><?= htmlspecialchars($orderDownload['name']) ?></a>
- <small><?= htmlspecialchars(DigitalFiles::formatSize($orderDownload['size'])) ?></small>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php else: ?>
- <p><?= htmlspecialchars(Language::get('order_downloads_pending', 'Your download links will appear here and be emailed to you as soon as the payment is confirmed. Refresh this page in a moment.')) ?></p>
- <?php endif; ?>
- <?php endif; ?>
-
- <?php if (UserAuth::check()): ?>
- <p><a href="account.php?order=<?= (int) $order['id'] ?>"><?= htmlspecialchars(Language::get('order_confirmation_view_account', 'View this order in your account')) ?></a></p>
- <?php endif; ?>
- <?php else: ?>
- <p><?= htmlspecialchars(Language::get('order_confirmation_generic', 'Thank you! Your purchase is being confirmed — you will receive an email shortly.')) ?></p>
- <?php if (UserAuth::check()): ?>
- <p><a href="account.php"><?= htmlspecialchars(Language::get('order_confirmation_view_account', 'Go to your account')) ?></a></p>
- <?php endif; ?>
- <?php endif; ?>
-
- <p><a href="index.php"><?= htmlspecialchars(Language::get('order_confirmation_continue_shopping', 'Continue shopping')) ?></a></p>
-
- <?php require __DIR__ . '/includes/front-footer.php'; ?>
-