kbit, 'up' => kbit, 'quota_mb' => MB] * @param int|null $userId angemeldeter Benutzer, sonst null * @param int|null $kioskId Herkunft, falls ueber eine Display-Seite geholt * * @return array{code:string,site_name:string,max_uses:int,expire_min:int,expiry_date:string,expiry_time:string} * @throws Exception wenn der Controller keinen gueltigen Voucher liefert */ public static function create( $db, array $site, string $voucherName, int $maxUses, int $expireMinutes, ?int $userId = null, array $qos = [], ?int $kioskId = null ): array { $fullName = date('Y-m-d') . '_' . $voucherName; $controller = new UniFiController( $site['unifi_controller_url'], $site['unifi_username'], Crypto::decrypt($site['unifi_password']), $site['site_id'] ); $voucher = $controller->createVoucher($fullName, $maxUses, $expireMinutes, $qos); if (!is_array($voucher) || empty($voucher['formatted_code'])) { throw new Exception(function_exists('__') ? __('error_voucher_invalid') : 'Ungueltige Antwort des Controllers'); } $db->execute( "INSERT INTO vouchers (site_id, user_id, kiosk_id, voucher_code, voucher_name, max_uses, expire_minutes, unifi_voucher_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [$site['id'], $userId, $kioskId, $voucher['code'], $fullName, $maxUses, $expireMinutes, $voucher['unifi_id'] ?? null] ); $expiryTs = time() + ($expireMinutes * 60); return [ 'code' => $voucher['formatted_code'], 'site_name' => $site['name'], 'max_uses' => $maxUses, 'expire_min' => $expireMinutes, 'expiry_date' => date('d.m.Y', $expiryTs), 'expiry_time' => date('H:i', $expiryTs), ]; } }