feat: implement email logging and test price mode functionality with QR code generation for order confirmations
This commit is contained in:
@@ -4,6 +4,144 @@ namespace controls;
|
||||
|
||||
class Tickets
|
||||
{
|
||||
private static function sendPaidOrderSummaryEmail(array $order)
|
||||
{
|
||||
$hash = trim((string) ($order['hash'] ?? ''));
|
||||
$email = trim((string) ($order['email'] ?? ''));
|
||||
|
||||
if ($hash === '' || $email === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dir = 'orders/' . $hash[0] . '/' . $hash[1] . '/';
|
||||
$qrFilePath = $dir . $hash . '.png';
|
||||
|
||||
if (!file_exists($qrFilePath)) {
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
\QRcode::png($hash, $qrFilePath, QR_ECLEVEL_H, 4);
|
||||
}
|
||||
|
||||
$orderId = (int) ($order['id'] ?? 0);
|
||||
$orderPrice = $order['order_price'] ?? '0';
|
||||
$invoiceUrl = trim((string) ($order['invoice_url'] ?? ''));
|
||||
$orderLink = 'https://bilety.brzezovka.pl/tickets/order_confirm/order=' . $hash;
|
||||
|
||||
$subject = 'brzezovka.pl - potwierdzenie platnosci zamowienia #' . $orderId;
|
||||
$message = '<div style="width:100%; max-width: 600px; margin: 0 auto;">';
|
||||
$message .= '<h2>Platnosc zostala potwierdzona</h2>';
|
||||
$message .= '<p>Numer zamowienia: <strong>' . $orderId . '</strong></p>';
|
||||
$message .= '<p>Kwota: <strong>' . $orderPrice . ' zl</strong></p>';
|
||||
$message .= '<p>Szczegoly zamowienia: <a href="' . $orderLink . '">' . $orderLink . '</a></p>';
|
||||
if ($invoiceUrl !== '') {
|
||||
$message .= '<p>Dokument sprzedazy: <a href="' . $invoiceUrl . '">' . $invoiceUrl . '</a></p>';
|
||||
}
|
||||
$message .= '<p>W zalaczniku dodany jest kod QR biletu (PNG).</p>';
|
||||
$message .= '</div>';
|
||||
|
||||
return \S::send_email($email, $subject, $message, $qrFilePath);
|
||||
}
|
||||
|
||||
private static function isValidTestPriceSecret($secret)
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$expectedSecret = trim((string) ($settings['test_price_mode_secret'] ?? ''));
|
||||
$providedSecret = trim((string) $secret);
|
||||
|
||||
if ($expectedSecret === '' || $providedSecret === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hash_equals($expectedSecret, $providedSecret);
|
||||
}
|
||||
|
||||
private static function applyTestPriceToBasket()
|
||||
{
|
||||
$basket = \S::get_session('basket');
|
||||
|
||||
if (!is_array($basket) || empty($basket)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($basket as $ticketId => &$variants) {
|
||||
if (!is_array($variants)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($variants as &$variant) {
|
||||
if (!is_array($variant)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$variant['ticket_price'] = 1.0;
|
||||
}
|
||||
unset($variant);
|
||||
}
|
||||
unset($variants);
|
||||
|
||||
\S::set_session('basket', $basket);
|
||||
}
|
||||
|
||||
static public function test_price_mode_on()
|
||||
{
|
||||
$secret = \S::get('secret');
|
||||
|
||||
if (!self::isValidTestPriceSecret($secret)) {
|
||||
header('Location: /tickets/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
\S::set_session('lower_price_ticket', true);
|
||||
self::applyTestPriceToBasket();
|
||||
\S::alert('Test mode: all ticket prices are set to 1 zl.');
|
||||
|
||||
header('Location: /tickets/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function test_price_mode_off()
|
||||
{
|
||||
$secret = \S::get('secret');
|
||||
|
||||
if (!self::isValidTestPriceSecret($secret)) {
|
||||
header('Location: /tickets/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
\S::del_session('lower_price_ticket');
|
||||
\S::del_session('basket');
|
||||
\S::alert('Test mode disabled. Basket has been cleared.');
|
||||
|
||||
header('Location: /tickets/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function resend_order_email()
|
||||
{
|
||||
$secret = \S::get('secret');
|
||||
$hash = trim((string) \S::get('order'));
|
||||
|
||||
if (!self::isValidTestPriceSecret($secret) || $hash === '') {
|
||||
header('Location: /tickets/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
$order = \factory\Tickets::get_order_details_by_hash($hash);
|
||||
if (!$order) {
|
||||
\S::alert('Order not found.');
|
||||
header('Location: /tickets/main_view/');
|
||||
exit;
|
||||
}
|
||||
|
||||
$isSent = self::sendPaidOrderSummaryEmail($order);
|
||||
\S::alert($isSent ? 'Order e-mail has been resent.' : 'Could not resend e-mail. Check SMTP logs.');
|
||||
|
||||
header('Location: /tickets/order_confirm/order=' . $hash);
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function main_view()
|
||||
{
|
||||
global $settings;
|
||||
@@ -667,13 +805,16 @@ class Tickets
|
||||
if ($order['payment_status'])
|
||||
{
|
||||
$order_successful = true;
|
||||
$mailSent = self::sendPaidOrderSummaryEmail($order);
|
||||
if ($mailSent) {
|
||||
$mdb->update('orders', ['informed_user' => 1], ['id' => $order['id']]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$order_fail = true;
|
||||
$mdb->update('orders', ['informed_user' => 1], ['id' => $order['id']]);
|
||||
}
|
||||
|
||||
$mdb->update('orders', ['informed_user' => 1], ['id' => $order['id']]);
|
||||
}
|
||||
|
||||
return \Tpl::view( 'tickets/order-confirm', [
|
||||
|
||||
Reference in New Issue
Block a user