expo-openpay 0.1.21 → 0.1.23
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/build/components/OPCardForm.d.ts +29 -25
- package/build/components/OPCardForm.d.ts.map +1 -1
- package/build/components/OPCardForm.js +23 -23
- package/build/components/OPCardForm.js.map +1 -1
- package/build/components/OPCardNumberInput.d.ts +6 -6
- package/build/components/OPCardNumberInput.d.ts.map +1 -1
- package/build/components/OPCardNumberInput.js +7 -7
- package/build/components/OPCardNumberInput.js.map +1 -1
- package/build/components/OPCvv2Input.d.ts +5 -5
- package/build/components/OPCvv2Input.d.ts.map +1 -1
- package/build/components/OPCvv2Input.js +5 -5
- package/build/components/OPCvv2Input.js.map +1 -1
- package/build/components/OPExpInput.d.ts +7 -7
- package/build/components/OPExpInput.d.ts.map +1 -1
- package/build/components/OPExpInput.js +12 -7
- package/build/components/OPExpInput.js.map +1 -1
- package/build/components/OPExpMonthInput.d.ts +6 -6
- package/build/components/OPExpMonthInput.d.ts.map +1 -1
- package/build/components/OPExpMonthInput.js +6 -6
- package/build/components/OPExpMonthInput.js.map +1 -1
- package/build/components/OPExpYearInput.d.ts +6 -6
- package/build/components/OPExpYearInput.d.ts.map +1 -1
- package/build/components/OPExpYearInput.js +6 -6
- package/build/components/OPExpYearInput.js.map +1 -1
- package/build/components/OPHolderNameInput.d.ts +4 -4
- package/build/components/OPHolderNameInput.d.ts.map +1 -1
- package/build/components/OPHolderNameInput.js +4 -4
- package/build/components/OPHolderNameInput.js.map +1 -1
- package/build/components/forms/FormField.d.ts +3 -3
- package/build/components/forms/FormField.d.ts.map +1 -1
- package/build/components/forms/FormField.js +18 -3
- package/build/components/forms/FormField.js.map +1 -1
- package/build/context/FormContext.d.ts +2 -1
- package/build/context/FormContext.d.ts.map +1 -1
- package/build/context/FormContext.js +38 -1
- package/build/context/FormContext.js.map +1 -1
- package/package.json +1 -1
- package/src/components/OPCardForm.tsx +41 -36
- package/src/components/OPCardNumberInput.tsx +12 -11
- package/src/components/OPCvv2Input.tsx +10 -9
- package/src/components/OPExpInput.tsx +19 -13
- package/src/components/OPExpMonthInput.tsx +8 -7
- package/src/components/OPExpYearInput.tsx +7 -7
- package/src/components/OPHolderNameInput.tsx +8 -7
- package/src/components/forms/FormField.tsx +26 -5
- package/src/context/FormContext.tsx +50 -0
|
@@ -21,7 +21,6 @@ type StylingProps = {
|
|
|
21
21
|
type AppFormFieldProps = TextInputProps & {
|
|
22
22
|
customStyles?: StyleProp<ViewStyle>;
|
|
23
23
|
defaultStyling?: boolean;
|
|
24
|
-
errorMessages?: Record<string, string | undefined>;
|
|
25
24
|
icon?:
|
|
26
25
|
| { type: "material"; name: keyof typeof MaterialCommunityIcons.glyphMap }
|
|
27
26
|
| { type: "fa6"; name: keyof typeof FontAwesome6.glyphMap }
|
|
@@ -33,8 +32,9 @@ type AppFormFieldProps = TextInputProps & {
|
|
|
33
32
|
onValueChange?: (value: string) => void;
|
|
34
33
|
validate?: (
|
|
35
34
|
value: string,
|
|
36
|
-
|
|
35
|
+
validationMessages?: Record<string, string | undefined>,
|
|
37
36
|
) => string | undefined;
|
|
37
|
+
validationMessages?: Record<string, string | undefined>;
|
|
38
38
|
withAnimatedText: boolean;
|
|
39
39
|
withIcon: boolean;
|
|
40
40
|
withLabel?: boolean;
|
|
@@ -43,11 +43,11 @@ type AppFormFieldProps = TextInputProps & {
|
|
|
43
43
|
|
|
44
44
|
export default function AppFormField({
|
|
45
45
|
defaultStyling,
|
|
46
|
-
errorMessages = {},
|
|
47
46
|
name,
|
|
48
47
|
labelStyle = {},
|
|
49
48
|
placeholder,
|
|
50
49
|
validate,
|
|
50
|
+
validationMessages = {},
|
|
51
51
|
withLabel = false,
|
|
52
52
|
...otherProps
|
|
53
53
|
}: AppFormFieldProps) {
|
|
@@ -73,13 +73,34 @@ export default function AppFormField({
|
|
|
73
73
|
onBlur={() => {
|
|
74
74
|
setFieldTouched(name);
|
|
75
75
|
if (validate) {
|
|
76
|
-
const errorMessage = validate(values[name],
|
|
76
|
+
const errorMessage = validate(values[name], validationMessages);
|
|
77
77
|
setFieldError(name, errorMessage);
|
|
78
78
|
}
|
|
79
79
|
}}
|
|
80
80
|
onChangeText={(text) => {
|
|
81
81
|
if (name === "cardNumber") text = formatCreditCardNumber(text);
|
|
82
|
-
if (name === "exp")
|
|
82
|
+
if (name === "exp") {
|
|
83
|
+
text = formatExp(text);
|
|
84
|
+
|
|
85
|
+
const month = text.slice(0, 2);
|
|
86
|
+
const year = text.slice(3);
|
|
87
|
+
|
|
88
|
+
if (month.length === 2) {
|
|
89
|
+
setFieldValue("expMonth", month);
|
|
90
|
+
setFieldError("expMonth", undefined);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (year.length === 2) {
|
|
94
|
+
setFieldValue("expYear", year);
|
|
95
|
+
setFieldError("expYear", undefined);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (name === "expMonth" || name === "expYear") {
|
|
100
|
+
setFieldError("exp", undefined);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
setFieldError(name, undefined);
|
|
83
104
|
setFieldValue(name, text);
|
|
84
105
|
|
|
85
106
|
if (otherProps.onValueChange) {
|
|
@@ -33,24 +33,74 @@ export default function FormProvider({
|
|
|
33
33
|
children,
|
|
34
34
|
initialValues = {},
|
|
35
35
|
onSubmit,
|
|
36
|
+
validationMessages = {},
|
|
36
37
|
}: {
|
|
37
38
|
children: React.ReactNode;
|
|
38
39
|
initialValues?: FormValues;
|
|
39
40
|
onSubmit?: (token: string) => any;
|
|
40
41
|
onDeviceSessionId?: (id: string) => any;
|
|
42
|
+
validationMessages?: any;
|
|
41
43
|
}) {
|
|
42
44
|
const [values, setValues] = useState<FormValues>(initialValues);
|
|
43
45
|
const [errors, setErrors] = useState<FormErrors>({});
|
|
44
46
|
const [touched, setTouched] = useState<FormTouched>({});
|
|
45
47
|
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
|
|
46
48
|
|
|
49
|
+
const isEmpty = (val: any) =>
|
|
50
|
+
val === undefined ||
|
|
51
|
+
val === null ||
|
|
52
|
+
(typeof val === "string" && val.trim() === "");
|
|
53
|
+
|
|
47
54
|
const handleSubmit = async (): Promise<any> => {
|
|
48
55
|
try {
|
|
49
56
|
setIsSubmitting(true);
|
|
50
57
|
|
|
58
|
+
const newErrors: FormErrors = {};
|
|
59
|
+
|
|
60
|
+
// Required validations
|
|
61
|
+
if (isEmpty(values["cardholderName"]))
|
|
62
|
+
newErrors["cardholderName"] =
|
|
63
|
+
validationMessages?.cardholderInput?.required ||
|
|
64
|
+
"Cardholder name is required";
|
|
65
|
+
|
|
66
|
+
if (isEmpty(values["cardNumber"]))
|
|
67
|
+
newErrors["cardNumber"] =
|
|
68
|
+
validationMessages?.cardNumberInput?.required ||
|
|
69
|
+
"Card number is required";
|
|
70
|
+
|
|
71
|
+
if (isEmpty(values["cvc"]))
|
|
72
|
+
newErrors["cvc"] =
|
|
73
|
+
validationMessages?.cvv2Input?.required || "CVC is required";
|
|
74
|
+
|
|
51
75
|
if (values["exp"]) {
|
|
52
76
|
values["expMonth"] = values["exp"].slice(0, 2);
|
|
53
77
|
values["expYear"] = values["exp"].slice(3);
|
|
78
|
+
} else {
|
|
79
|
+
newErrors["exp"] =
|
|
80
|
+
validationMessages?.expInput?.required || "Expiration is required";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isEmpty(values["expMonth"]))
|
|
84
|
+
newErrors["expMonth"] =
|
|
85
|
+
validationMessages?.expMonthInput?.required ||
|
|
86
|
+
"Expiration month is required";
|
|
87
|
+
|
|
88
|
+
if (isEmpty(values["expYear"]))
|
|
89
|
+
newErrors["expYear"] =
|
|
90
|
+
validationMessages?.expYearInput?.required ||
|
|
91
|
+
"Expiration year is required";
|
|
92
|
+
|
|
93
|
+
if (Object.keys(newErrors).length > 0) {
|
|
94
|
+
setErrors(newErrors);
|
|
95
|
+
|
|
96
|
+
const touchedFields: FormTouched = {};
|
|
97
|
+
Object.keys(newErrors).forEach((key) => {
|
|
98
|
+
touchedFields[key] = true;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
setTouched((prev) => ({ ...prev, ...touchedFields }));
|
|
102
|
+
|
|
103
|
+
return;
|
|
54
104
|
}
|
|
55
105
|
|
|
56
106
|
const token = await tokenizeCard(
|