1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
<?php
/**
* Template für die Integration der Kundeneingaben für das Modul "Kreditkarte" in den Checkout2
* @version 4.6.1
*/
if (!isset($this->view['error'])) $this->view['error'] = [];
?>
<br /><br />
<div class="wpsg_mod_creditcard">
<div class="wpsg_mod_creditcard_name wpsg_mod_creditcard_field">
<label>
<?php echo __('Typ der Kreditkarte', 'wpsg'); ?><span class="wpsg_required">*</span>:
<select name="wpsg_mod_creditcard[typ]" id="wpsg_mod_creditcard_typ"
class="<?php echo ((in_array('mod_creditcard_typ', (array)$this->view['error']))?'wpsg_error':''); ?>" >
<option value="VISA" <?php echo (($this->view['wpsg_mod_creditcard']['typ'] === 'VISA')?'selected="selected"':''); ?>>VISA</option>
<option value="MasterCard" <?php echo (($this->view['wpsg_mod_creditcard']['typ'] === 'MasterCard')?'selected="selected"':''); ?>>MasterCard</option>
</select>
</label>
</div>
<div class="wpsg_clear"></div>
<div class="wpsg_mod_creditcard_inhaber wpsg_mod_creditcard_field">
<label>
<?php echo __('Inhaber', 'wpsg'); ?><span class="wpsg_required">*</span>:
<input class="<?php echo ((in_array("mod_creditcard_inhaber", (array)$this->view['error']))?'wpsg_error':''); ?>" type="text" autocomplete="cc-name" name="wpsg_mod_creditcard[inhaber]" value="<?php echo wpsg_hspc($this->view['wpsg_mod_creditcard']['inhaber']); ?>" />
</label>
</div>
<div class="wpsg_clear"></div>
<div class="wpsg_mod_creditcard_knr wpsg_mod_creditcard_field">
<label>
<?php echo __('Kartennummer', 'wpsg'); ?><span class="wpsg_required">*</span>:
<input class="<?php echo ((in_array("mod_creditcard_knr", (array)$this->view['error']))?'wpsg_error':''); ?>" type="text" inputmode="numeric" autocomplete="cc-number" maxlength="23" id="wpsg_mod_creditcard_knr" name="wpsg_mod_creditcard[knr]" value="<?php echo wpsg_hspc($this->view['wpsg_mod_creditcard']['knr']); ?>" />
</label>
</div>
<div class="wpsg_clear"></div>
<div class="wpsg_mod_creditcard_knr wpsg_mod_creditcard_field">
<label>
<?php echo __('Prüfziffer', 'wpsg'); ?><span class="wpsg_required">*</span>:
<input class="<?php echo ((in_array("mod_creditcard_pruefz", (array)$this->view['error']))?'wpsg_error':''); ?>" type="text" inputmode="numeric" autocomplete="cc-csc" maxlength="3" name="wpsg_mod_creditcard[pruefz]" value="<?php echo wpsg_hspc($this->view['wpsg_mod_creditcard']['pruefz']); ?>" />
</label>
</div>
<div class="wpsg_clear"></div>
<div class="wpsg_mod_creditcard_knr wpsg_mod_creditcard_field">
<label>
<?php echo __('Gültigkeit', 'wpsg'); ?><span class="wpsg_required">*</span>:
<!-- <input class="<?php echo ((in_array("mod_creditcard_gueltig", (array)$this->view['error']))?'wpsg_error':''); ?>" type="text" name="wpsg_mod_creditcard[gueltig]" value="<?php echo wpsg_hspc(wpsg_getStr($this->view['wpsg_mod_creditcard']['gueltig'])); ?>" /> -->
<?php
// Monat und Jahr werden serverseitig ausgegeben, damit die Auswahl auch ohne Script (z.B. im SmartCheckout) funktioniert
$strMonth = wpsg_getStr($this->view['wpsg_mod_creditcard']['gueltigm'], '12');
$strYear = wpsg_getStr($this->view['wpsg_mod_creditcard']['gueltigj']);
?>
<select name="wpsg_mod_creditcard[gueltigm]" id="wpsg_mod_creditcard_gueltigm"
class="<?php echo ((in_array('mod_creditcard_gueltigm', (array)$this->view['error']))?'wpsg_error':''); ?>" >
<?php for ($m = 1; $m <= 12; $m++) { $strValue = sprintf('%02d', $m); ?>
<option value="<?php echo esc_attr($strValue); ?>" <?php echo (($strValue === $strMonth)?'selected="selected"':''); ?>><?php echo esc_html($strValue); ?></option>
<?php } ?>
</select>
<select name="wpsg_mod_creditcard[gueltigj]" id="wpsg_mod_creditcard_gueltigj"
class="<?php echo ((in_array('mod_creditcard_gueltigj', (array)$this->view['error']))?'wpsg_error':''); ?>" >
<?php for ($y = intval(date('Y')); $y < intval(date('Y')) + 6; $y++) { $strValue = strval($y); ?>
<option value="<?php echo esc_attr($strValue); ?>" <?php echo (($strValue === $strYear)?'selected="selected"':''); ?>><?php echo esc_html($strValue); ?></option>
<?php } ?>
</select>
</label>
</div>
<div class="wpsg_clear"></div>
<div class="wpsg_mandatoryfield_hint">
<?php echo wpsg_translate(__('Mit #1# gekennzeichnete Felder sind Pflichtfelder.', 'wpsg'), '<span class="wpsg_required">*</span>'); ?>
</div>
</div>
<script>
//alert(jQuery("#wpsg_mod_creditcard_knr").length);
//$(document).on("input", "#wpsg_mod_creditcard_knr", function () {
jQuery("#wpsg_mod_creditcard_knr").on("input", function () {
var
knr,
typ,
a1,
ai,
isANumber,
bb = true,
sum = 0,
k = 2,
i;
//alert("onchange");
knr = jQuery('#wpsg_mod_creditcard_knr').val();
typ = jQuery('#wpsg_mod_creditcard_typ').val();
knr = knr.replace(/ /g, "");
if (knr.length < 16) { return; }
isANumber = (isNaN(knr) === false);
if (isANumber === false) { bb = false; }
a1 = knr.substr(0, 1);
ai = parseInt(knr.substr(15, 1), 10);
if (!(((a1 === "4") && (typ === "VISA")) || ((a1 === "5") && (typ === "MasterCard")))) { bb = false; }
for (i = 14; i >= 0; i--) {
dig = k * parseInt(knr.substr(i, 1), 10);
if (dig > 9) { dig = dig - 9;}
sum = sum + dig;
//sum = sum + k * parseInt(knr.substr(i, 1), 10);
if (k === 2) { k = 1; } else { k = 2; }
}
sum = sum % 10;
if (sum > 0) { sum = 10 - sum; }
if (sum !== ai) { bb = false; }
if (bb === false) {
alert('Kartennummer fehlerhaft');
}
});
</script>
|