tonder-web-sdk 1.12.0-beta.13 → 1.12.0-beta.14
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/.idea/workspace.xml +24 -27
- package/README.md +34 -3
- package/package.json +1 -1
- package/src/classes/BaseInlineCheckout.js +0 -1
- package/src/classes/LiteInlineCheckout.js +11 -3
- package/src/helpers/utils.js +4 -4
- package/src/helpers/validations.js +54 -0
- package/src/index.js +7 -1
- package/types/card.d.ts +1 -0
- package/v1/bundle.min.js +3 -3
- package/webpack.config.js +4 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function validateCardNumber(cardNumber) {
|
|
2
|
+
const regex = /^\d{12,19}$/;
|
|
3
|
+
return regex.test(cardNumber) && luhnCheck(cardNumber);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function validateCardholderName(name) {
|
|
7
|
+
const regex = /^([a-zA-Z\\ \\,\\.\\-\\']{2,})$/;
|
|
8
|
+
return regex.test(name);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function validateCVV(cvv) {
|
|
12
|
+
const regex = /^\d{3,4}$/;
|
|
13
|
+
return regex.test(cvv);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function validateExpirationDate(expirationDate) {
|
|
17
|
+
const regex = /^(0[1-9]|1[0-2])\/\d{2}$/;
|
|
18
|
+
if (!regex.test(expirationDate)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const [month, year] = expirationDate.split('/');
|
|
22
|
+
const currentDate = new Date();
|
|
23
|
+
const expiration = new Date(`20${year}`, month - 1);
|
|
24
|
+
return expiration >= currentDate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function validateExpirationMonth(month) {
|
|
28
|
+
const regex = /^(0[1-9]|1[0-2])$/;
|
|
29
|
+
return regex.test(month);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function validateExpirationYear(year) {
|
|
33
|
+
const regex = /^\d{2}$/;
|
|
34
|
+
if (!regex.test(year)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const currentYear = new Date().getFullYear() % 100;
|
|
38
|
+
return parseInt(year, 10) >= currentYear;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const luhnCheck = num => {
|
|
42
|
+
const arr = `${num}`
|
|
43
|
+
.split('')
|
|
44
|
+
.reverse()
|
|
45
|
+
.map(x => Number.parseInt(x));
|
|
46
|
+
const lastDigit = arr.shift();
|
|
47
|
+
let sum = arr.reduce(
|
|
48
|
+
(acc, val, i) =>
|
|
49
|
+
i % 2 !== 0 ? acc + val : acc + ((val *= 2) > 9 ? val - 9 : val),
|
|
50
|
+
0
|
|
51
|
+
);
|
|
52
|
+
sum += lastDigit;
|
|
53
|
+
return sum % 10 === 0;
|
|
54
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { Checkout } from './classes/checkout'
|
|
2
2
|
import { InlineCheckout } from './classes/inlineCheckout'
|
|
3
3
|
import { LiteInlineCheckout } from './classes/LiteInlineCheckout'
|
|
4
|
+
import { validateCVV, validateCardNumber, validateCardholderName, validateExpirationMonth, validateExpirationYear } from "./helpers/validations";
|
|
4
5
|
|
|
5
6
|
export {
|
|
6
7
|
Checkout,
|
|
7
8
|
InlineCheckout,
|
|
8
|
-
LiteInlineCheckout
|
|
9
|
+
LiteInlineCheckout,
|
|
10
|
+
validateCVV,
|
|
11
|
+
validateCardNumber,
|
|
12
|
+
validateCardholderName,
|
|
13
|
+
validateExpirationMonth,
|
|
14
|
+
validateExpirationYear
|
|
9
15
|
}
|