@test-glide/payment-react-native 0.1.3 → 0.1.4
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/README.md +1 -1
- package/lib/module/components/BivoCVCInput.js +4 -4
- package/lib/module/components/BivoCVCInput.js.map +1 -1
- package/lib/module/components/BivoCardInput.js +4 -4
- package/lib/module/components/BivoCardInput.js.map +1 -1
- package/lib/module/components/BivoTextInput.js +4 -4
- package/lib/module/components/BivoTextInput.js.map +1 -1
- package/lib/module/core/{Collector.js → BivoSecureStore.js} +40 -28
- package/lib/module/core/BivoSecureStore.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/components/BivoCVCInput.d.ts +2 -2
- package/lib/typescript/src/components/BivoCVCInput.d.ts.map +1 -1
- package/lib/typescript/src/components/BivoCardInput.d.ts +2 -2
- package/lib/typescript/src/components/BivoCardInput.d.ts.map +1 -1
- package/lib/typescript/src/components/BivoTextInput.d.ts +2 -2
- package/lib/typescript/src/components/BivoTextInput.d.ts.map +1 -1
- package/lib/typescript/src/core/{Collector.d.ts → BivoSecureStore.d.ts} +5 -13
- package/lib/typescript/src/core/BivoSecureStore.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/BivoCVCInput.tsx +6 -6
- package/src/components/BivoCardInput.tsx +6 -6
- package/src/components/BivoTextInput.tsx +6 -6
- package/src/core/BivoSecureStore.ts +164 -0
- package/src/index.ts +1 -1
- package/lib/module/core/Collector.js.map +0 -1
- package/lib/typescript/src/core/Collector.d.ts.map +0 -1
- package/src/core/Collector.ts +0 -131
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @bivo/payment-react-native
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
```js
|
|
17
|
-
import {
|
|
17
|
+
import { BivoSecureStore, BivoTextInput, BivoCardInput, BivoCVCInput } from '@bivo/payment-react-native';
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -5,7 +5,7 @@ import { View, TextInput, Text, StyleSheet, Image } from 'react-native';
|
|
|
5
5
|
import { Icons } from "../assets/index.js";
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
7
|
export const BivoCVCInput = ({
|
|
8
|
-
|
|
8
|
+
bivoStore,
|
|
9
9
|
fieldName,
|
|
10
10
|
placeholder,
|
|
11
11
|
onStateChange,
|
|
@@ -18,12 +18,12 @@ export const BivoCVCInput = ({
|
|
|
18
18
|
const [value, setValue] = useState('');
|
|
19
19
|
const handleChange = text => {
|
|
20
20
|
setValue(text);
|
|
21
|
-
|
|
21
|
+
bivoStore.setField(fieldName, text, onStateChange, required, regex, errorMsg);
|
|
22
22
|
};
|
|
23
23
|
const handleBlur = () => {
|
|
24
|
-
|
|
24
|
+
bivoStore.setField(fieldName, value, onStateChange, required, regex, errorMsg);
|
|
25
25
|
};
|
|
26
|
-
const error =
|
|
26
|
+
const error = bivoStore.errors[fieldName];
|
|
27
27
|
return /*#__PURE__*/_jsxs(View, {
|
|
28
28
|
style: [styles.container, containerStyle],
|
|
29
29
|
children: [/*#__PURE__*/_jsx(TextInput, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","jsx","_jsx","jsxs","_jsxs","BivoCVCInput","
|
|
1
|
+
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","jsx","_jsx","jsxs","_jsxs","BivoCVCInput","bivoStore","fieldName","placeholder","onStateChange","required","regex","errorMsg","containerStyle","textStyle","value","setValue","handleChange","text","setField","handleBlur","error","errors","style","styles","container","children","onChangeText","onBlur","secureTextEntry","keyboardType","input","borderColor","errorContainer","source","alert","errorIcon","create","marginVertical","borderWidth","borderRadius","padding","flexDirection","alignItems","marginTop","minHeight","width","height","marginRight","color","fontSize"],"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C,MAAM,CAACO,KAAK,EAAEjB,SAAS,EAAEO,KAAK,GAAG;QAAEW,WAAW,EAAE;MAAM,CAAC,GAAG,CAAC,CAAC;IAAE,CACvE,CAAC,EACDX,KAAK,iBACJjB,KAAA,CAACT,IAAI;MAAC4B,KAAK,EAAEC,MAAM,CAACS,cAAe;MAAAP,QAAA,gBACjCxB,IAAA,CAACH,KAAK;QAACmC,MAAM,EAAElC,KAAK,CAACmC,KAAM;QAACZ,KAAK,EAAEC,MAAM,CAACY;MAAU,CAAE,CAAC,eACvDlC,IAAA,CAACL,IAAI;QAAC0B,KAAK,EAAEC,MAAM,CAACH,KAAM;QAAAK,QAAA,EAAEL;MAAK,CAAO,CAAC;IAAA,CACrC,CACP;EAAA,CACG,CAAC;AAEX,CAAC;AAED,MAAMG,MAAM,GAAG1B,UAAU,CAACuC,MAAM,CAAC;EAC/BZ,SAAS,EAAE;IAAEa,cAAc,EAAE;EAAE,CAAC;EAChCP,KAAK,EAAE;IAAEQ,WAAW,EAAE,CAAC;IAAEP,WAAW,EAAE,MAAM;IAAEQ,YAAY,EAAE,CAAC;IAAEC,OAAO,EAAE;EAAG,CAAC;EAC5ER,cAAc,EAAE;IACdS,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBC,SAAS,EAAE,CAAC;IACZC,SAAS,EAAE;EACb,CAAC;EACDT,SAAS,EAAE;IAAEU,KAAK,EAAE,EAAE;IAAEC,MAAM,EAAE,EAAE;IAAEC,WAAW,EAAE;EAAE,CAAC;EACpD3B,KAAK,EAAE;IAAE4B,KAAK,EAAE,KAAK;IAAEC,QAAQ,EAAE;EAAG;AACtC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -13,7 +13,7 @@ const cardIcons = {
|
|
|
13
13
|
unknown: Icons.card
|
|
14
14
|
};
|
|
15
15
|
export const BivoCardInput = ({
|
|
16
|
-
|
|
16
|
+
bivoStore,
|
|
17
17
|
fieldName,
|
|
18
18
|
placeholder,
|
|
19
19
|
onStateChange,
|
|
@@ -31,12 +31,12 @@ export const BivoCardInput = ({
|
|
|
31
31
|
setValue(formatted);
|
|
32
32
|
const cleaned = text.replace(/\D/g, '');
|
|
33
33
|
if (/^4/.test(cleaned)) setCardType('visa');else if (/^5[1-5]/.test(cleaned)) setCardType('mastercard');else if (/^3[47]/.test(cleaned)) setCardType('amex');else if (/^6(?:011|5)/.test(cleaned)) setCardType('discover');else setCardType('unknown');
|
|
34
|
-
|
|
34
|
+
bivoStore.setField(fieldName, text, onStateChange, required, regex, errorMsg);
|
|
35
35
|
};
|
|
36
36
|
const handleBlur = () => {
|
|
37
|
-
|
|
37
|
+
bivoStore.setField(fieldName, value, onStateChange, required, regex, errorMsg);
|
|
38
38
|
};
|
|
39
|
-
const error =
|
|
39
|
+
const error = bivoStore.errors[fieldName];
|
|
40
40
|
return /*#__PURE__*/_jsxs(View, {
|
|
41
41
|
style: [styles.container, containerStyle],
|
|
42
42
|
children: [/*#__PURE__*/_jsxs(View, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","View","TextInput","Image","Text","StyleSheet","Icons","formatCardNumber","jsx","_jsx","jsxs","_jsxs","cardIcons","visa","mastercard","amex","discover","unknown","card","BivoCardInput","
|
|
1
|
+
{"version":3,"names":["React","useState","View","TextInput","Image","Text","StyleSheet","Icons","formatCardNumber","jsx","_jsx","jsxs","_jsxs","cardIcons","visa","mastercard","amex","discover","unknown","card","BivoCardInput","bivoStore","fieldName","placeholder","onStateChange","required","regex","errorMsg","containerStyle","textStyle","value","setValue","cardType","setCardType","handleChange","text","formatted","cleaned","replace","test","setField","handleBlur","error","errors","style","styles","container","children","row","source","icon","onChangeText","onBlur","keyboardType","input","borderColor","errorContainer","alert","errorIcon","create","marginVertical","flexDirection","alignItems","flex","borderWidth","borderRadius","padding","width","height","resizeMode","marginRight","marginLeft","marginTop","minHeight","color","fontSize"],"sourceRoot":"../../../src","sources":["components/BivoCardInput.tsx"],"mappings":";;AAAA,OAAOA,K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T,QAAA,gBACjCrC,IAAA,CAACN,KAAK;QAAC6C,MAAM,EAAE1C,KAAK,CAACkD,KAAM;QAACb,KAAK,EAAEC,MAAM,CAACa;MAAU,CAAE,CAAC,eACvDhD,IAAA,CAACL,IAAI;QAACuC,KAAK,EAAEC,MAAM,CAACH,KAAM;QAAAK,QAAA,EAAEL;MAAK,CAAO,CAAC;IAAA,CACrC,CACP;EAAA,CACG,CAAC;AAEX,CAAC;AAED,MAAMG,MAAM,GAAGvC,UAAU,CAACqD,MAAM,CAAC;EAC/Bb,SAAS,EAAE;IAAEc,cAAc,EAAE;EAAE,CAAC;EAChCZ,GAAG,EAAE;IAAEa,aAAa,EAAE,KAAK;IAAEC,UAAU,EAAE;EAAS,CAAC;EACnDR,KAAK,EAAE;IACLS,IAAI,EAAE,CAAC;IACPC,WAAW,EAAE,CAAC;IACdT,WAAW,EAAE,MAAM;IACnBU,YAAY,EAAE,CAAC;IACfC,OAAO,EAAE;EACX,CAAC;EACDhB,IAAI,EAAE;IAAEiB,KAAK,EAAE,EAAE;IAAEC,MAAM,EAAE,EAAE;IAAEC,UAAU,EAAE,SAAS;IAAEC,WAAW,EAAE;EAAE,CAAC;EACtEd,cAAc,EAAE;IACdK,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBS,UAAU,EAAE,EAAE;IACdC,SAAS,EAAE,CAAC;IACZC,SAAS,EAAE;EACb,CAAC;EACDf,SAAS,EAAE;IAAES,KAAK,EAAE,EAAE;IAAEC,MAAM,EAAE,EAAE;IAAEE,WAAW,EAAE;EAAE,CAAC;EACpD5B,KAAK,EAAE;IAAEgC,KAAK,EAAE,KAAK;IAAEC,QAAQ,EAAE;EAAG;AACtC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -6,7 +6,7 @@ import { Icons } from "../assets/index.js";
|
|
|
6
6
|
import { formatExpiry } from "../utils/utils.js";
|
|
7
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
8
|
export const BivoTextInput = ({
|
|
9
|
-
|
|
9
|
+
bivoStore,
|
|
10
10
|
fieldName,
|
|
11
11
|
placeholder,
|
|
12
12
|
onStateChange,
|
|
@@ -25,12 +25,12 @@ export const BivoTextInput = ({
|
|
|
25
25
|
updatedValue = text;
|
|
26
26
|
}
|
|
27
27
|
setValue(updatedValue);
|
|
28
|
-
|
|
28
|
+
bivoStore.setField(fieldName, updatedValue, onStateChange, required, regex, errorMsg);
|
|
29
29
|
};
|
|
30
30
|
const handleBlur = () => {
|
|
31
|
-
|
|
31
|
+
bivoStore.setField(fieldName, value, onStateChange, required, regex, errorMsg);
|
|
32
32
|
};
|
|
33
|
-
const error =
|
|
33
|
+
const error = bivoStore.errors[fieldName];
|
|
34
34
|
return /*#__PURE__*/_jsxs(View, {
|
|
35
35
|
style: [styles.container, containerStyle],
|
|
36
36
|
children: [/*#__PURE__*/_jsx(TextInput, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","formatExpiry","jsx","_jsx","jsxs","_jsxs","BivoTextInput","
|
|
1
|
+
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","formatExpiry","jsx","_jsx","jsxs","_jsxs","BivoTextInput","bivoStore","fieldName","placeholder","onStateChange","required","regex","errorMsg","containerStyle","textStyle","value","setValue","handleChange","text","updatedValue","setField","handleBlur","error","errors","style","styles","container","children","onChangeText","onBlur","input","borderColor","errorContainer","source","alert","errorIcon","create","marginVertical","borderWidth","borderRadius","padding","flexDirection","alignItems","marginTop","minHeight","width","height","marginRight","color","fontSize"],"sourceRoot":"../../../src","sources":["components/BivoTextInput.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,SAASC,IAAI,EAAEC,SAAS,EAAEC,IAAI,EAAEC,UAAU,EAAEC,KAAK,QAAQ,cAAc;AAGvE,SAASC,KAAK,QAAQ,oBAAW;AACjC,SAASC,YA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AC,GAAG,CAAC,CAAC;IAAE,CACvE,CAAC,EACDT,KAAK,iBACJlB,KAAA,CAACV,IAAI;MAAC8B,KAAK,EAAEC,MAAM,CAACO,cAAe;MAAAL,QAAA,gBACjCzB,IAAA,CAACJ,KAAK;QAACmC,MAAM,EAAElC,KAAK,CAACmC,KAAM;QAACV,KAAK,EAAEC,MAAM,CAACU;MAAU,CAAE,CAAC,eACvDjC,IAAA,CAACN,IAAI;QAAC4B,KAAK,EAAEC,MAAM,CAACH,KAAM;QAAAK,QAAA,EAAEL;MAAK,CAAO,CAAC;IAAA,CACrC,CACP;EAAA,CACG,CAAC;AAEX,CAAC;AAED,MAAMG,MAAM,GAAG5B,UAAU,CAACuC,MAAM,CAAC;EAC/BV,SAAS,EAAE;IAAEW,cAAc,EAAE;EAAE,CAAC;EAChCP,KAAK,EAAE;IAAEQ,WAAW,EAAE,CAAC;IAAEP,WAAW,EAAE,MAAM;IAAEQ,YAAY,EAAE,CAAC;IAAEC,OAAO,EAAE;EAAG,CAAC;EAC5ER,cAAc,EAAE;IACdS,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBC,SAAS,EAAE,CAAC;IACZC,SAAS,EAAE;EACb,CAAC;EACDT,SAAS,EAAE;IAAEU,KAAK,EAAE,EAAE;IAAEC,MAAM,EAAE,EAAE;IAAEC,WAAW,EAAE;EAAE,CAAC;EACpDzB,KAAK,EAAE;IAAE0B,KAAK,EAAE,KAAK;IAAEC,QAAQ,EAAE;EAAG;AACtC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { fetchData } from "../utils/fetch.js";
|
|
4
4
|
import { formatCardYear, formatString } from "../utils/utils.js";
|
|
5
|
-
export class
|
|
5
|
+
export class BivoSecureStore {
|
|
6
6
|
form = {};
|
|
7
7
|
errors = {};
|
|
8
8
|
fieldConfig = {};
|
|
@@ -12,13 +12,24 @@ export class BivoCollect {
|
|
|
12
12
|
}
|
|
13
13
|
setField(fieldName, value, onStateChange, required = false, regex, errorMsg) {
|
|
14
14
|
this.form[fieldName] = value;
|
|
15
|
+
// convert string regex to RegExp
|
|
16
|
+
let parsedRegex = undefined;
|
|
17
|
+
if (typeof regex === 'string') {
|
|
18
|
+
try {
|
|
19
|
+
parsedRegex = new RegExp(regex);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error('Invalid regex:', regex, e);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
parsedRegex = regex;
|
|
25
|
+
}
|
|
15
26
|
this.fieldConfig[fieldName] = {
|
|
16
27
|
required,
|
|
17
|
-
regex,
|
|
28
|
+
regex: parsedRegex,
|
|
18
29
|
errorMsg
|
|
19
30
|
};
|
|
20
|
-
const error = this.validateField(fieldName, value, required,
|
|
21
|
-
this.errors[fieldName] = error ||
|
|
31
|
+
const error = this.validateField(fieldName, value, required, parsedRegex, errorMsg);
|
|
32
|
+
this.errors[fieldName] = error || '';
|
|
22
33
|
onStateChange?.({
|
|
23
34
|
value,
|
|
24
35
|
error
|
|
@@ -28,45 +39,45 @@ export class BivoCollect {
|
|
|
28
39
|
const trimmedValue = value?.trim();
|
|
29
40
|
|
|
30
41
|
// Required check
|
|
31
|
-
if (!trimmedValue && required) return
|
|
42
|
+
if (!trimmedValue && required) return 'Required';
|
|
32
43
|
|
|
33
44
|
// If custom regex is provided → use it first
|
|
34
45
|
if (regex && trimmedValue) {
|
|
35
46
|
if (!regex.test(trimmedValue)) {
|
|
36
|
-
return errorMsg ||
|
|
47
|
+
return errorMsg || 'Invalid value';
|
|
37
48
|
}
|
|
38
|
-
return
|
|
49
|
+
return '';
|
|
39
50
|
}
|
|
40
51
|
|
|
41
52
|
// Default validations
|
|
42
53
|
switch (fieldName) {
|
|
43
|
-
case
|
|
54
|
+
case 'card':
|
|
44
55
|
{
|
|
45
|
-
const digits = trimmedValue.replace(/\D/g,
|
|
46
|
-
if (digits.length < 12) return
|
|
56
|
+
const digits = trimmedValue.replace(/\D/g, '');
|
|
57
|
+
if (digits.length < 12) return 'Invalid card number';
|
|
47
58
|
break;
|
|
48
59
|
}
|
|
49
|
-
case
|
|
60
|
+
case 'cvv':
|
|
50
61
|
{
|
|
51
62
|
if (!/^\d{3,4}$/.test(trimmedValue)) {
|
|
52
|
-
return
|
|
63
|
+
return 'Invalid CVV';
|
|
53
64
|
}
|
|
54
65
|
break;
|
|
55
66
|
}
|
|
56
|
-
case
|
|
67
|
+
case 'exp':
|
|
57
68
|
{
|
|
58
69
|
// Format check MM/YY
|
|
59
70
|
if (!/^\d{2}\/\d{2}$/.test(trimmedValue)) {
|
|
60
|
-
return
|
|
71
|
+
return 'Invalid expiry';
|
|
61
72
|
}
|
|
62
|
-
const [monthStr, yearStr] = trimmedValue.split(
|
|
73
|
+
const [monthStr, yearStr] = trimmedValue.split('/');
|
|
63
74
|
if (!monthStr || !yearStr) {
|
|
64
|
-
return
|
|
75
|
+
return 'Invalid expiry';
|
|
65
76
|
}
|
|
66
77
|
const month = parseInt(monthStr, 10);
|
|
67
78
|
const year = parseInt(yearStr, 10);
|
|
68
79
|
if (month < 1 || month > 12) {
|
|
69
|
-
return
|
|
80
|
+
return 'Invalid month';
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
// Convert YY → YYYY (assume 2000-2099)
|
|
@@ -77,51 +88,52 @@ export class BivoCollect {
|
|
|
77
88
|
|
|
78
89
|
// Expiry check
|
|
79
90
|
if (fullYear < currentYear || fullYear === currentYear && month < currentMonth) {
|
|
80
|
-
return
|
|
91
|
+
return 'Card expired';
|
|
81
92
|
}
|
|
82
93
|
break;
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
|
-
return
|
|
96
|
+
return '';
|
|
86
97
|
}
|
|
87
98
|
isSubmitDisabled(fieldNames) {
|
|
88
99
|
return fieldNames.some(fieldName => {
|
|
89
|
-
const value = this.form[fieldName]?.trim() ??
|
|
100
|
+
const value = this.form[fieldName]?.trim() ?? '';
|
|
90
101
|
const error = this.errors[fieldName];
|
|
91
102
|
return !value || !!error;
|
|
92
103
|
});
|
|
93
104
|
}
|
|
94
105
|
async submit(endpoint, token) {
|
|
95
106
|
// console.log("Submitting form:", this.form, this.errors);
|
|
96
|
-
const expiry = this.form.expiryDate?.split(
|
|
107
|
+
const expiry = this.form.expiryDate?.split('/') || [];
|
|
97
108
|
|
|
98
109
|
// Replace fetchData with your API call
|
|
99
110
|
const response = await fetchData(endpoint, {
|
|
100
|
-
method:
|
|
111
|
+
method: 'POST',
|
|
101
112
|
body: {
|
|
102
113
|
token,
|
|
103
|
-
pan: formatString(this.form.cardNumber ||
|
|
114
|
+
pan: formatString(this.form.cardNumber || ''),
|
|
104
115
|
expiry_month: Number(expiry[0] || 0) || null,
|
|
105
|
-
expiry_year: formatCardYear(expiry[1] ||
|
|
116
|
+
expiry_year: formatCardYear(expiry[1] || '') || null,
|
|
106
117
|
cvv: this.form.cvc ? formatString(this.form.cvc) : null,
|
|
107
118
|
address: {
|
|
108
119
|
postal_code: this.form.zipCode ? formatString(this.form.zipCode) : null
|
|
109
120
|
}
|
|
110
121
|
}
|
|
111
122
|
});
|
|
112
|
-
console.log("🚀 ~ BivoCollect ~ submit ~ response:", response, endpoint, token);
|
|
113
123
|
if (response.error) {
|
|
114
124
|
return {
|
|
115
125
|
success: false,
|
|
116
|
-
error: response.error
|
|
126
|
+
error: response.error,
|
|
127
|
+
data: response
|
|
117
128
|
};
|
|
118
129
|
} else {
|
|
119
130
|
return {
|
|
120
131
|
success: true,
|
|
121
|
-
data: response.data
|
|
132
|
+
data: response.data,
|
|
133
|
+
info: response
|
|
122
134
|
};
|
|
123
135
|
}
|
|
124
136
|
// return response.json();
|
|
125
137
|
}
|
|
126
138
|
}
|
|
127
|
-
//# sourceMappingURL=
|
|
139
|
+
//# sourceMappingURL=BivoSecureStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["fetchData","formatCardYear","formatString","BivoSecureStore","form","errors","fieldConfig","constructor","vaultId","environment","setField","fieldName","value","onStateChange","required","regex","errorMsg","parsedRegex","undefined","RegExp","e","console","error","validateField","trimmedValue","trim","test","digits","replace","length","monthStr","yearStr","split","month","parseInt","year","fullYear","now","Date","currentMonth","getMonth","currentYear","getFullYear","isSubmitDisabled","fieldNames","some","submit","endpoint","token","expiry","expiryDate","response","method","body","pan","cardNumber","expiry_month","Number","expiry_year","cvv","cvc","address","postal_code","zipCode","success","data","info"],"sourceRoot":"../../../src","sources":["core/BivoSecureStore.ts"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,mBAAgB;AAC1C,SAASC,cAAc,EAAEC,YAAY,QAAQ,mBAAgB;AAI7D,OAAO,MAAMC,eAAe,CAAC;EAG3BC,IAAI,GAA2B,CAAC,CAAC;EACjCC,MAAM,GAA2B,CAAC,CAAC;EACnCC,WAAW,GAGP,CAAC,CAAC;EAENC,WAAWA,CAACC,OAAe,EAAEC,WAA+B,EAAE;IAC5D,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,WAAW,GAAGA,WAAW;EAChC;EAEAC,QAAQA,CACNC,SAAiB,EACjBC,KAAa,EACbC,aAA2C,EAC3CC,QAAiB,GAAG,KAAK,EACzBC,KAAc,EACdC,QAAiB,EACjB;IACA,IAAI,CAACZ,IAAI,CAACO,SAAS,CAAC,GAAGC,KAAK;IAC5B;IACA,IAAIK,WAA+B,GAAGC,SAAS;IAE/C,IAAI,OAAOH,KAAK,KAAK,QAAQ,EAAE;MAC7B,IAAI;QACFE,WAAW,GAAG,IAAIE,MAAM,CAACJ,KAAK,CAAC;MACjC,CAAC,CAAC,OAAOK,CAAC,EAAE;QACVC,OAAO,CAACC,KAAK,CAAC,gBAAgB,EAAEP,KAAK,EAAEK,CAAC,CAAC;MAC3C;IACF,CAAC,MAAM;MACLH,WAAW,GAAGF,KAAK;IACrB;IACA,IAAI,CAACT,WAAW,CAACK,SAAS,CAAC,GAAG;MAAEG,QAAQ;MAAEC,KAAK,EAAEE,WAAW;MA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YAAY,CAAC,IAAI,CAACE,IAAI,CAACmD,UAAU,IAAI,EAAE,CAAC;QAC7CC,YAAY,EAAEC,MAAM,CAACR,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI;QAC5CS,WAAW,EAAEzD,cAAc,CAACgD,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;QACpDU,GAAG,EAAE,IAAI,CAACvD,IAAI,CAACwD,GAAG,GAAG1D,YAAY,CAAC,IAAI,CAACE,IAAI,CAACwD,GAAG,CAAC,GAAG,IAAI;QACvDC,OAAO,EAAE;UACPC,WAAW,EAAE,IAAI,CAAC1D,IAAI,CAAC2D,OAAO,GAC1B7D,YAAY,CAAC,IAAI,CAACE,IAAI,CAAC2D,OAAO,CAAC,GAC/B;QACN;MACF;IACF,CAAC,CAAC;IAEF,IAAIZ,QAAQ,CAAC7B,KAAK,EAAE;MAClB,OAAO;QAAE0C,OAAO,EAAE,KAAK;QAAE1C,KAAK,EAAE6B,QAAQ,CAAC7B,KAAK;QAAE2C,IAAI,EAACd;MAAS,CAAC;IACjE,CAAC,MAAM;MACL,OAAO;QAAEa,OAAO,EAAE,IAAI;QAAEC,IAAI,EAAEd,QAAQ,CAACc,IAAI;QAAEC,IAAI,EAACf;MAAS,CAAC;IAC9D;IACA;EACF;AACF","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { BivoSecureStore } from "./core/BivoSecureStore.js";
|
|
4
4
|
export { BivoTextInput } from "./components/BivoTextInput.js";
|
|
5
5
|
export { BivoCardInput } from "./components/BivoCardInput.js";
|
|
6
6
|
export { BivoCVCInput } from "./components/BivoCVCInput.js";
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["BivoSecureStore","BivoTextInput","BivoCardInput","BivoCVCInput"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAQ,2BAAwB;AAExD,SAASC,aAAa,QAAQ,+BAA4B;AAC1D,SAASC,aAAa,QAAQ,+BAA4B;AAC1D,SAASC,YAAY,QAAQ,8BAA2B","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
bivoStore: BivoSecureStore;
|
|
6
6
|
fieldName: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
onStateChange?: (state: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BivoCVCInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCVCInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BivoCVCInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCVCInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,UAAU,KAAK;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyDxC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
bivoStore: BivoSecureStore;
|
|
6
6
|
fieldName: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
onStateChange?: (state: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BivoCardInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCardInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BivoCardInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCardInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI1D,UAAU,KAAK;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAUD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAoEzC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BivoSecureStore } from '../core/BivoSecureStore';
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
bivoStore: BivoSecureStore;
|
|
6
6
|
fieldName: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
onStateChange?: (state: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BivoTextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoTextInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"BivoTextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoTextInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI/D,UAAU,KAAK;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA6DzC,CAAC"}
|
|
@@ -2,9 +2,9 @@ type FieldState = {
|
|
|
2
2
|
value: string;
|
|
3
3
|
error?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class BivoSecureStore {
|
|
6
6
|
vaultId: string;
|
|
7
|
-
environment:
|
|
7
|
+
environment: 'sandbox' | 'live';
|
|
8
8
|
form: Record<string, string>;
|
|
9
9
|
errors: Record<string, string>;
|
|
10
10
|
fieldConfig: Record<string, {
|
|
@@ -12,19 +12,11 @@ export declare class BivoCollect {
|
|
|
12
12
|
regex?: RegExp;
|
|
13
13
|
errorMsg?: string;
|
|
14
14
|
}>;
|
|
15
|
-
constructor(vaultId: string, environment:
|
|
15
|
+
constructor(vaultId: string, environment: 'sandbox' | 'live');
|
|
16
16
|
setField(fieldName: string, value: string, onStateChange?: (state: FieldState) => void, required?: boolean, regex?: RegExp, errorMsg?: string): void;
|
|
17
17
|
validateField(fieldName: string, value: string, required?: boolean, regex?: RegExp, errorMsg?: string): string;
|
|
18
18
|
isSubmitDisabled(fieldNames: string[]): boolean;
|
|
19
|
-
submit(endpoint: string, token: string): Promise<
|
|
20
|
-
success: boolean;
|
|
21
|
-
error: string;
|
|
22
|
-
data?: undefined;
|
|
23
|
-
} | {
|
|
24
|
-
success: boolean;
|
|
25
|
-
data: unknown;
|
|
26
|
-
error?: undefined;
|
|
27
|
-
}>;
|
|
19
|
+
submit(endpoint: string, token: string): Promise<any>;
|
|
28
20
|
}
|
|
29
21
|
export {};
|
|
30
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=BivoSecureStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BivoSecureStore.d.ts","sourceRoot":"","sources":["../../../../src/core/BivoSecureStore.ts"],"names":[],"mappings":"AAGA,KAAK,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,qBAAa,eAAe;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,SAAS,GAAG,MAAM,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACpC,WAAW,EAAE,MAAM,CACjB,MAAM,EACN;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAC1D,CAAM;gBAEK,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,GAAG,MAAM;IAK5D,QAAQ,CACN,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EAC3C,QAAQ,GAAE,OAAe,EACzB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM;IA2BnB,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,EAClB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM;IAqEnB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE;IAQ/B,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAE,OAAO,CAAC,GAAG,CAAC;CA4B3D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BivoSecureStore } from "./core/BivoSecureStore";
|
|
2
2
|
export { BivoTextInput } from "./components/BivoTextInput";
|
|
3
3
|
export { BivoCardInput } from "./components/BivoCardInput";
|
|
4
4
|
export { BivoCVCInput } from "./components/BivoCVCInput";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { View, TextInput, Text, StyleSheet, Image } from 'react-native';
|
|
3
3
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
4
|
-
import {
|
|
4
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
5
5
|
import { Icons } from '../assets';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
|
-
|
|
8
|
+
bivoStore: BivoSecureStore;
|
|
9
9
|
fieldName: string;
|
|
10
10
|
placeholder?: string;
|
|
11
11
|
onStateChange?: (state: any) => void;
|
|
@@ -17,7 +17,7 @@ interface Props {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const BivoCVCInput: React.FC<Props> = ({
|
|
20
|
-
|
|
20
|
+
bivoStore,
|
|
21
21
|
fieldName,
|
|
22
22
|
placeholder,
|
|
23
23
|
onStateChange,
|
|
@@ -31,7 +31,7 @@ export const BivoCVCInput: React.FC<Props> = ({
|
|
|
31
31
|
|
|
32
32
|
const handleChange = (text: string) => {
|
|
33
33
|
setValue(text);
|
|
34
|
-
|
|
34
|
+
bivoStore.setField(
|
|
35
35
|
fieldName,
|
|
36
36
|
text,
|
|
37
37
|
onStateChange,
|
|
@@ -42,7 +42,7 @@ export const BivoCVCInput: React.FC<Props> = ({
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const handleBlur = () => {
|
|
45
|
-
|
|
45
|
+
bivoStore.setField(
|
|
46
46
|
fieldName,
|
|
47
47
|
value,
|
|
48
48
|
onStateChange,
|
|
@@ -52,7 +52,7 @@ export const BivoCVCInput: React.FC<Props> = ({
|
|
|
52
52
|
);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const error =
|
|
55
|
+
const error = bivoStore.errors[fieldName];
|
|
56
56
|
|
|
57
57
|
return (
|
|
58
58
|
<View style={[styles.container, containerStyle]}>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { View, TextInput, Image, Text, StyleSheet } from 'react-native';
|
|
3
3
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
4
|
-
import {
|
|
4
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
5
5
|
import { Icons } from '../assets';
|
|
6
6
|
import { formatCardNumber } from '../utils/utils';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
|
|
9
|
+
bivoStore: BivoSecureStore;
|
|
10
10
|
fieldName: string;
|
|
11
11
|
placeholder?: string;
|
|
12
12
|
onStateChange?: (state: any) => void;
|
|
@@ -26,7 +26,7 @@ const cardIcons: any = {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export const BivoCardInput: React.FC<Props> = ({
|
|
29
|
-
|
|
29
|
+
bivoStore,
|
|
30
30
|
fieldName,
|
|
31
31
|
placeholder,
|
|
32
32
|
onStateChange,
|
|
@@ -49,7 +49,7 @@ export const BivoCardInput: React.FC<Props> = ({
|
|
|
49
49
|
else if (/^6(?:011|5)/.test(cleaned)) setCardType('discover');
|
|
50
50
|
else setCardType('unknown');
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
bivoStore.setField(
|
|
53
53
|
fieldName,
|
|
54
54
|
text,
|
|
55
55
|
onStateChange,
|
|
@@ -60,7 +60,7 @@ export const BivoCardInput: React.FC<Props> = ({
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const handleBlur = () => {
|
|
63
|
-
|
|
63
|
+
bivoStore.setField(
|
|
64
64
|
fieldName,
|
|
65
65
|
value,
|
|
66
66
|
onStateChange,
|
|
@@ -70,7 +70,7 @@ export const BivoCardInput: React.FC<Props> = ({
|
|
|
70
70
|
);
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
const error =
|
|
73
|
+
const error = bivoStore.errors[fieldName];
|
|
74
74
|
|
|
75
75
|
return (
|
|
76
76
|
<View style={[styles.container, containerStyle]}>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { View, TextInput, Text, StyleSheet, Image } from 'react-native';
|
|
3
3
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BivoSecureStore } from '../core/BivoSecureStore';
|
|
5
5
|
import { Icons } from '../assets';
|
|
6
6
|
import { formatExpiry } from '../utils/utils';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
|
|
9
|
+
bivoStore: BivoSecureStore;
|
|
10
10
|
fieldName: string;
|
|
11
11
|
placeholder?: string;
|
|
12
12
|
onStateChange?: (state: any) => void;
|
|
@@ -18,7 +18,7 @@ interface Props {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export const BivoTextInput: React.FC<Props> = ({
|
|
21
|
-
|
|
21
|
+
bivoStore,
|
|
22
22
|
fieldName,
|
|
23
23
|
placeholder,
|
|
24
24
|
onStateChange,
|
|
@@ -38,7 +38,7 @@ export const BivoTextInput: React.FC<Props> = ({
|
|
|
38
38
|
updatedValue = text;
|
|
39
39
|
}
|
|
40
40
|
setValue(updatedValue);
|
|
41
|
-
|
|
41
|
+
bivoStore.setField(
|
|
42
42
|
fieldName,
|
|
43
43
|
updatedValue,
|
|
44
44
|
onStateChange,
|
|
@@ -49,7 +49,7 @@ export const BivoTextInput: React.FC<Props> = ({
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const handleBlur = () => {
|
|
52
|
-
|
|
52
|
+
bivoStore.setField(
|
|
53
53
|
fieldName,
|
|
54
54
|
value,
|
|
55
55
|
onStateChange,
|
|
@@ -59,7 +59,7 @@ export const BivoTextInput: React.FC<Props> = ({
|
|
|
59
59
|
);
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
const error =
|
|
62
|
+
const error = bivoStore.errors[fieldName];
|
|
63
63
|
|
|
64
64
|
return (
|
|
65
65
|
<View style={[styles.container, containerStyle]}>
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { fetchData } from '../utils/fetch';
|
|
2
|
+
import { formatCardYear, formatString } from '../utils/utils';
|
|
3
|
+
|
|
4
|
+
type FieldState = { value: string; error?: string };
|
|
5
|
+
|
|
6
|
+
export class BivoSecureStore {
|
|
7
|
+
vaultId: string;
|
|
8
|
+
environment: 'sandbox' | 'live';
|
|
9
|
+
form: Record<string, string> = {};
|
|
10
|
+
errors: Record<string, string> = {};
|
|
11
|
+
fieldConfig: Record<
|
|
12
|
+
string,
|
|
13
|
+
{ required?: boolean; regex?: RegExp; errorMsg?: string }
|
|
14
|
+
> = {};
|
|
15
|
+
|
|
16
|
+
constructor(vaultId: string, environment: 'sandbox' | 'live') {
|
|
17
|
+
this.vaultId = vaultId;
|
|
18
|
+
this.environment = environment;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setField(
|
|
22
|
+
fieldName: string,
|
|
23
|
+
value: string,
|
|
24
|
+
onStateChange?: (state: FieldState) => void,
|
|
25
|
+
required: boolean = false,
|
|
26
|
+
regex?: RegExp,
|
|
27
|
+
errorMsg?: string
|
|
28
|
+
) {
|
|
29
|
+
this.form[fieldName] = value;
|
|
30
|
+
// convert string regex to RegExp
|
|
31
|
+
let parsedRegex: RegExp | undefined = undefined;
|
|
32
|
+
|
|
33
|
+
if (typeof regex === 'string') {
|
|
34
|
+
try {
|
|
35
|
+
parsedRegex = new RegExp(regex);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.error('Invalid regex:', regex, e);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
parsedRegex = regex;
|
|
41
|
+
}
|
|
42
|
+
this.fieldConfig[fieldName] = { required, regex: parsedRegex, errorMsg };
|
|
43
|
+
const error = this.validateField(
|
|
44
|
+
fieldName,
|
|
45
|
+
value,
|
|
46
|
+
required,
|
|
47
|
+
parsedRegex,
|
|
48
|
+
errorMsg
|
|
49
|
+
);
|
|
50
|
+
this.errors[fieldName] = error || '';
|
|
51
|
+
onStateChange?.({ value, error });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
validateField(
|
|
55
|
+
fieldName: string,
|
|
56
|
+
value: string,
|
|
57
|
+
required?: boolean,
|
|
58
|
+
regex?: RegExp,
|
|
59
|
+
errorMsg?: string
|
|
60
|
+
) {
|
|
61
|
+
const trimmedValue = value?.trim();
|
|
62
|
+
|
|
63
|
+
// Required check
|
|
64
|
+
if (!trimmedValue && required) return 'Required';
|
|
65
|
+
|
|
66
|
+
// If custom regex is provided → use it first
|
|
67
|
+
if (regex && trimmedValue) {
|
|
68
|
+
if (!regex.test(trimmedValue)) {
|
|
69
|
+
return errorMsg || 'Invalid value';
|
|
70
|
+
}
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Default validations
|
|
75
|
+
switch (fieldName) {
|
|
76
|
+
case 'card': {
|
|
77
|
+
const digits = trimmedValue.replace(/\D/g, '');
|
|
78
|
+
if (digits.length < 12) return 'Invalid card number';
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
case 'cvv': {
|
|
83
|
+
if (!/^\d{3,4}$/.test(trimmedValue)) {
|
|
84
|
+
return 'Invalid CVV';
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
case 'exp': {
|
|
90
|
+
// Format check MM/YY
|
|
91
|
+
if (!/^\d{2}\/\d{2}$/.test(trimmedValue)) {
|
|
92
|
+
return 'Invalid expiry';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const [monthStr, yearStr] = trimmedValue.split('/');
|
|
96
|
+
if (!monthStr || !yearStr) {
|
|
97
|
+
return 'Invalid expiry';
|
|
98
|
+
}
|
|
99
|
+
const month = parseInt(monthStr, 10);
|
|
100
|
+
const year = parseInt(yearStr, 10);
|
|
101
|
+
|
|
102
|
+
if (month < 1 || month > 12) {
|
|
103
|
+
return 'Invalid month';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Convert YY → YYYY (assume 2000-2099)
|
|
107
|
+
const fullYear = 2000 + year;
|
|
108
|
+
|
|
109
|
+
const now = new Date();
|
|
110
|
+
const currentMonth = now.getMonth() + 1;
|
|
111
|
+
const currentYear = now.getFullYear();
|
|
112
|
+
|
|
113
|
+
// Expiry check
|
|
114
|
+
if (
|
|
115
|
+
fullYear < currentYear ||
|
|
116
|
+
(fullYear === currentYear && month < currentMonth)
|
|
117
|
+
) {
|
|
118
|
+
return 'Card expired';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
isSubmitDisabled(fieldNames: string[]) {
|
|
129
|
+
return fieldNames.some((fieldName) => {
|
|
130
|
+
const value = this.form[fieldName]?.trim() ?? '';
|
|
131
|
+
const error = this.errors[fieldName];
|
|
132
|
+
return !value || !!error;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async submit(endpoint: string, token: string):Promise<any> {
|
|
137
|
+
// console.log("Submitting form:", this.form, this.errors);
|
|
138
|
+
const expiry = this.form.expiryDate?.split('/') || [];
|
|
139
|
+
|
|
140
|
+
// Replace fetchData with your API call
|
|
141
|
+
const response = await fetchData(endpoint, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
body: {
|
|
144
|
+
token,
|
|
145
|
+
pan: formatString(this.form.cardNumber || ''),
|
|
146
|
+
expiry_month: Number(expiry[0] || 0) || null,
|
|
147
|
+
expiry_year: formatCardYear(expiry[1] || '') || null,
|
|
148
|
+
cvv: this.form.cvc ? formatString(this.form.cvc) : null,
|
|
149
|
+
address: {
|
|
150
|
+
postal_code: this.form.zipCode
|
|
151
|
+
? formatString(this.form.zipCode)
|
|
152
|
+
: null,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (response.error) {
|
|
158
|
+
return { success: false, error: response.error, data:response };
|
|
159
|
+
} else {
|
|
160
|
+
return { success: true, data: response.data, info:response };
|
|
161
|
+
}
|
|
162
|
+
// return response.json();
|
|
163
|
+
}
|
|
164
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fetchData","formatCardYear","formatString","BivoCollect","form","errors","fieldConfig","constructor","vaultId","environment","setField","fieldName","value","onStateChange","required","regex","errorMsg","error","validateField","trimmedValue","trim","test","digits","replace","length","monthStr","yearStr","split","month","parseInt","year","fullYear","now","Date","currentMonth","getMonth","currentYear","getFullYear","isSubmitDisabled","fieldNames","some","submit","endpoint","token","expiry","expiryDate","response","method","body","pan","cardNumber","expiry_month","Number","expiry_year","cvv","cvc","address","postal_code","zipCode","console","log","success","data"],"sourceRoot":"../../../src","sources":["core/Collector.ts"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,mBAAgB;AAC1C,SAASC,cAAc,EAAEC,YAAY,QAAQ,mBAAgB;AAK7D,OAAO,MAAMC,WAAW,CAAC;EAGvBC,IAAI,GAA2B,CAAC,CAAC;EACjCC,MAAM,GAA2B,CAAC,CAAC;EACnCC,WAAW,GAA8E,CAAC,C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0 @@
|
|
|
1
|
-
import { fetchData } from "../utils/fetch";
|
|
2
|
-
import { formatCardYear, formatString } from "../utils/utils";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type FieldState = { value: string; error?: string };
|
|
6
|
-
|
|
7
|
-
export class BivoCollect {
|
|
8
|
-
vaultId: string;
|
|
9
|
-
environment: "sandbox" | "live";
|
|
10
|
-
form: Record<string, string> = {};
|
|
11
|
-
errors: Record<string, string> = {};
|
|
12
|
-
fieldConfig: Record<string, { required?: boolean; regex?: RegExp; errorMsg?: string }> = {};
|
|
13
|
-
|
|
14
|
-
constructor(vaultId: string, environment: "sandbox" | "live") {
|
|
15
|
-
this.vaultId = vaultId;
|
|
16
|
-
this.environment = environment;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setField(fieldName: string, value: string, onStateChange?: (state: FieldState) => void, required: boolean = false, regex?: RegExp, errorMsg?: string) {
|
|
20
|
-
this.form[fieldName] = value;
|
|
21
|
-
this.fieldConfig[fieldName] = { required, regex, errorMsg };
|
|
22
|
-
const error = this.validateField(fieldName, value, required, regex, errorMsg);
|
|
23
|
-
this.errors[fieldName] = error || "";
|
|
24
|
-
onStateChange?.({ value, error });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
validateField(fieldName: string, value: string, required?: boolean, regex?: RegExp, errorMsg?: string) {
|
|
30
|
-
const trimmedValue = value?.trim();
|
|
31
|
-
|
|
32
|
-
// Required check
|
|
33
|
-
if (!trimmedValue && required) return "Required";
|
|
34
|
-
|
|
35
|
-
// If custom regex is provided → use it first
|
|
36
|
-
if (regex && trimmedValue) {
|
|
37
|
-
if (!regex.test(trimmedValue)) {
|
|
38
|
-
return errorMsg || "Invalid value";
|
|
39
|
-
}
|
|
40
|
-
return "";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Default validations
|
|
44
|
-
switch (fieldName) {
|
|
45
|
-
case "card": {
|
|
46
|
-
const digits = trimmedValue.replace(/\D/g, "");
|
|
47
|
-
if (digits.length < 12) return "Invalid card number";
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
case "cvv": {
|
|
52
|
-
if (!/^\d{3,4}$/.test(trimmedValue)) {
|
|
53
|
-
return "Invalid CVV";
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
case "exp": {
|
|
59
|
-
// Format check MM/YY
|
|
60
|
-
if (!/^\d{2}\/\d{2}$/.test(trimmedValue)) {
|
|
61
|
-
return "Invalid expiry";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const [monthStr, yearStr] = trimmedValue.split("/");
|
|
65
|
-
if (!monthStr || !yearStr) {
|
|
66
|
-
return "Invalid expiry";
|
|
67
|
-
}
|
|
68
|
-
const month = parseInt(monthStr, 10);
|
|
69
|
-
const year = parseInt(yearStr, 10);
|
|
70
|
-
|
|
71
|
-
if (month < 1 || month > 12) {
|
|
72
|
-
return "Invalid month";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Convert YY → YYYY (assume 2000-2099)
|
|
76
|
-
const fullYear = 2000 + year;
|
|
77
|
-
|
|
78
|
-
const now = new Date();
|
|
79
|
-
const currentMonth = now.getMonth() + 1;
|
|
80
|
-
const currentYear = now.getFullYear();
|
|
81
|
-
|
|
82
|
-
// Expiry check
|
|
83
|
-
if (
|
|
84
|
-
fullYear < currentYear ||
|
|
85
|
-
(fullYear === currentYear && month < currentMonth)
|
|
86
|
-
) {
|
|
87
|
-
return "Card expired";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return "";
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
isSubmitDisabled(fieldNames: string[]) {
|
|
98
|
-
return fieldNames.some((fieldName) => {
|
|
99
|
-
const value = this.form[fieldName]?.trim() ?? "";
|
|
100
|
-
const error = this.errors[fieldName];
|
|
101
|
-
return !value || !!error;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async submit(endpoint: string, token: string) {
|
|
106
|
-
// console.log("Submitting form:", this.form, this.errors);
|
|
107
|
-
const expiry = this.form.expiryDate?.split("/") || [];
|
|
108
|
-
|
|
109
|
-
// Replace fetchData with your API call
|
|
110
|
-
const response = await fetchData(endpoint, {
|
|
111
|
-
method: "POST",
|
|
112
|
-
body: {
|
|
113
|
-
token,
|
|
114
|
-
pan:formatString(this.form.cardNumber || ""),
|
|
115
|
-
expiry_month: Number(expiry[0] || 0) || null,
|
|
116
|
-
expiry_year: formatCardYear(expiry[1] || "") || null,
|
|
117
|
-
cvv: this.form.cvc ? formatString(this.form.cvc) : null,
|
|
118
|
-
address: {
|
|
119
|
-
postal_code: this.form.zipCode ? formatString(this.form.zipCode) : null,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
console.log("🚀 ~ BivoCollect ~ submit ~ response:", response,endpoint,token)
|
|
124
|
-
if (response.error) {
|
|
125
|
-
return{ success: false, error: response.error };
|
|
126
|
-
} else {
|
|
127
|
-
return{ success: true, data: response.data };
|
|
128
|
-
}
|
|
129
|
-
// return response.json();
|
|
130
|
-
}
|
|
131
|
-
}
|