PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Mobile / Events / ScanEventTicketCommandHandler.php
ameliabooking / src / Application / Commands / Mobile / Events Last commit date
ScanEventTicketCommand.php 2 weeks ago ScanEventTicketCommandHandler.php 2 weeks ago
ScanEventTicketCommandHandler.php
51 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Mobile\Events;
4
5 use AmeliaBooking\Application\Commands\CommandResult;
6 use AmeliaBooking\Application\Commands\QrCode\ScanQrCodeCommand;
7 use AmeliaBooking\Application\Commands\QrCode\ScanQrCodeCommandHandler;
8
9 /**
10 * Mobile-API wrapper around ScanQrCodeCommandHandler.
11 *
12 * Key differences from the web scanner:
13 * - scannedAt is generated server-side (current date); the client does not send it.
14 * - "Already scanned" cases are returned as HTTP 200 with alreadyScanned:true
15 * instead of HTTP 409, so the mobile app can show a distinct UI state.
16 */
17 class ScanEventTicketCommandHandler extends ScanQrCodeCommandHandler
18 {
19 public $mandatoryFields = ['ticketManualCode'];
20
21 private const ALREADY_SCANNED_CODES = [
22 'ticket_already_scanned',
23 'group_ticket_already_scanned',
24 'all_already_scanned',
25 ];
26
27 public function handle(ScanQrCodeCommand $command)
28 {
29 // Generate the scan date server-side so the client cannot forge it.
30 $command->setField('scannedAt', date('Y-m-d'));
31
32 $result = parent::handle($command);
33
34 if ($result->getResult() === CommandResult::RESULT_ERROR) {
35 $data = $result->getData();
36 $message = isset($data['message']) ? (string) $data['message'] : '';
37
38 if (in_array($message, self::ALREADY_SCANNED_CODES, true)) {
39 $result->setResult(CommandResult::RESULT_SUCCESS);
40 $result->setData(['alreadyScanned' => true]);
41 }
42
43 return $result;
44 }
45
46 $result->setData(['alreadyScanned' => false]);
47
48 return $result;
49 }
50 }
51