swell-js 5.5.1 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.mjs +1 -1
- package/dist/card.mjs +77 -49
- package/dist/payment.mjs +777 -432
- package/dist/swell.cjs +847 -475
- package/dist/swell.cjs.map +1 -1
- package/dist/swell.umd.min.js +847 -475
- package/dist/swell.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/api.mjs
CHANGED
package/dist/card.mjs
CHANGED
|
@@ -66,32 +66,40 @@ const cardApi = {
|
|
|
66
66
|
|
|
67
67
|
const parts = new String(value).split(/[\s/-]+/, 2);
|
|
68
68
|
const month = parts[0];
|
|
69
|
-
let year = parts[1];
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const currentYear = new Date().getUTCFullYear().toString();
|
|
71
|
+
let strYear = parts[1];
|
|
72
|
+
|
|
73
|
+
if (strYear.length < currentYear.length) {
|
|
74
|
+
let fullYear =
|
|
75
|
+
currentYear.slice(0, currentYear.length - strYear.length) + strYear;
|
|
76
|
+
|
|
77
|
+
// If the expiration year is less than the current year,
|
|
78
|
+
// then the expiration year is in the next century.
|
|
79
|
+
if (fullYear < currentYear) {
|
|
80
|
+
let year = Number(fullYear);
|
|
81
|
+
year += 10 ** strYear.length;
|
|
82
|
+
fullYear = year.toString();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
strYear = fullYear;
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
return {
|
|
78
|
-
month:
|
|
79
|
-
year:
|
|
89
|
+
month: Number.parseInt(month, 10),
|
|
90
|
+
year: Number.parseInt(strYear, 10),
|
|
80
91
|
};
|
|
81
92
|
},
|
|
82
93
|
|
|
83
94
|
types() {
|
|
84
|
-
let
|
|
85
|
-
t =
|
|
86
|
-
for (e =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
(t[30] = t[36] = t[38] = t[39] = 'Diners Club'),
|
|
93
|
-
t
|
|
94
|
-
);
|
|
95
|
+
let t = {};
|
|
96
|
+
for (let e = 40; e <= 49; ++e) t[e] = 'Visa';
|
|
97
|
+
for (let e = 50; e <= 59; ++e) t[e] = 'MasterCard';
|
|
98
|
+
t[34] = t[37] = 'American Express';
|
|
99
|
+
t[60] = t[62] = t[64] = t[65] = 'Discover';
|
|
100
|
+
t[35] = 'JCB';
|
|
101
|
+
t[30] = t[36] = t[38] = t[39] = 'Diners Club';
|
|
102
|
+
return t;
|
|
95
103
|
},
|
|
96
104
|
|
|
97
105
|
type(num) {
|
|
@@ -99,47 +107,67 @@ const cardApi = {
|
|
|
99
107
|
},
|
|
100
108
|
|
|
101
109
|
luhnCheck(num) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
const numbers = String(num);
|
|
111
|
+
let odd = false;
|
|
112
|
+
let sum = 0;
|
|
113
|
+
|
|
114
|
+
for (let i = numbers.length - 1; i >= 0; --i) {
|
|
115
|
+
let digit = Number.parseInt(numbers[i], 10);
|
|
116
|
+
|
|
117
|
+
if (odd) {
|
|
118
|
+
digit *= 2;
|
|
119
|
+
|
|
120
|
+
if (digit > 9) {
|
|
121
|
+
digit -= 9;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
sum += digit;
|
|
126
|
+
odd = !odd;
|
|
108
127
|
}
|
|
109
|
-
|
|
128
|
+
|
|
129
|
+
return sum % 10 === 0;
|
|
110
130
|
},
|
|
111
131
|
|
|
112
132
|
validateNumber(num) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
133
|
+
num = String(num).replace(/\s+|-/g, '');
|
|
134
|
+
|
|
135
|
+
return num.length >= 10 && num.length <= 16 && this.luhnCheck(num);
|
|
117
136
|
},
|
|
118
137
|
|
|
119
138
|
validateExpiry(month, year) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
);
|
|
139
|
+
month = String(month).trim();
|
|
140
|
+
year = String(year).trim();
|
|
141
|
+
|
|
142
|
+
if (!/^\d+$/.test(month) || !/^\d+$/.test(year)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const numMonth = Number.parseInt(month, 10);
|
|
147
|
+
|
|
148
|
+
if (numMonth <= 0 || numMonth > 12) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const date = new Date(year, month);
|
|
153
|
+
date.setMonth(date.getMonth() - 1);
|
|
154
|
+
date.setMonth(date.getMonth() + 1, 1);
|
|
155
|
+
|
|
156
|
+
const diff = date.getTime() - Date.now();
|
|
157
|
+
|
|
158
|
+
// The card has expired
|
|
159
|
+
if (diff < 0) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The card's validity period must not exceed 50 years from the current time.
|
|
164
|
+
return Math.round(diff / 31_557_600_000) < 50;
|
|
136
165
|
},
|
|
137
166
|
|
|
138
167
|
validateCVC(val) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
168
|
+
val = String(val).trim();
|
|
169
|
+
|
|
170
|
+
return /^\d+$/.test(val) && val.length >= 3 && val.length <= 4;
|
|
143
171
|
},
|
|
144
172
|
};
|
|
145
173
|
|