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.
Files changed (46) hide show
  1. package/build/components/OPCardForm.d.ts +29 -25
  2. package/build/components/OPCardForm.d.ts.map +1 -1
  3. package/build/components/OPCardForm.js +23 -23
  4. package/build/components/OPCardForm.js.map +1 -1
  5. package/build/components/OPCardNumberInput.d.ts +6 -6
  6. package/build/components/OPCardNumberInput.d.ts.map +1 -1
  7. package/build/components/OPCardNumberInput.js +7 -7
  8. package/build/components/OPCardNumberInput.js.map +1 -1
  9. package/build/components/OPCvv2Input.d.ts +5 -5
  10. package/build/components/OPCvv2Input.d.ts.map +1 -1
  11. package/build/components/OPCvv2Input.js +5 -5
  12. package/build/components/OPCvv2Input.js.map +1 -1
  13. package/build/components/OPExpInput.d.ts +7 -7
  14. package/build/components/OPExpInput.d.ts.map +1 -1
  15. package/build/components/OPExpInput.js +12 -7
  16. package/build/components/OPExpInput.js.map +1 -1
  17. package/build/components/OPExpMonthInput.d.ts +6 -6
  18. package/build/components/OPExpMonthInput.d.ts.map +1 -1
  19. package/build/components/OPExpMonthInput.js +6 -6
  20. package/build/components/OPExpMonthInput.js.map +1 -1
  21. package/build/components/OPExpYearInput.d.ts +6 -6
  22. package/build/components/OPExpYearInput.d.ts.map +1 -1
  23. package/build/components/OPExpYearInput.js +6 -6
  24. package/build/components/OPExpYearInput.js.map +1 -1
  25. package/build/components/OPHolderNameInput.d.ts +4 -4
  26. package/build/components/OPHolderNameInput.d.ts.map +1 -1
  27. package/build/components/OPHolderNameInput.js +4 -4
  28. package/build/components/OPHolderNameInput.js.map +1 -1
  29. package/build/components/forms/FormField.d.ts +3 -3
  30. package/build/components/forms/FormField.d.ts.map +1 -1
  31. package/build/components/forms/FormField.js +18 -3
  32. package/build/components/forms/FormField.js.map +1 -1
  33. package/build/context/FormContext.d.ts +2 -1
  34. package/build/context/FormContext.d.ts.map +1 -1
  35. package/build/context/FormContext.js +38 -1
  36. package/build/context/FormContext.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/components/OPCardForm.tsx +41 -36
  39. package/src/components/OPCardNumberInput.tsx +12 -11
  40. package/src/components/OPCvv2Input.tsx +10 -9
  41. package/src/components/OPExpInput.tsx +19 -13
  42. package/src/components/OPExpMonthInput.tsx +8 -7
  43. package/src/components/OPExpYearInput.tsx +7 -7
  44. package/src/components/OPHolderNameInput.tsx +8 -7
  45. package/src/components/forms/FormField.tsx +26 -5
  46. package/src/context/FormContext.tsx +50 -0
@@ -41,7 +41,31 @@ type CardFormProps = {
41
41
  merchantId: string;
42
42
  options?: {
43
43
  buttonTitle?: string;
44
- errorMessages?: {
44
+ expIsMMYY?: boolean;
45
+ groupedView?: boolean;
46
+ onSubmit?: (token: string) => any;
47
+ styling?: {
48
+ buttonStyle?: StyleProp<ViewStyle>;
49
+ buttonTextStyle?: StyleProp<TextStyle>;
50
+ colorScheme?: "light" | "dark";
51
+ darkTheme?: FormThemeColors;
52
+ formFieldStyle?: StyleProp<ViewStyle>;
53
+ defaultStyling?: boolean;
54
+ formKeyboardAvoidingViewStyle?: StyleProp<ViewStyle>;
55
+ formScrollViewStyle?: StyleProp<ViewStyle>;
56
+ labelStyle?: StyleProp<TextStyle>;
57
+ lightTheme?: FormThemeColors;
58
+ textInputStyle?: StyleProp<TextStyle>;
59
+ };
60
+ placeholders?: {
61
+ cardholderInput: string;
62
+ cardNumberInput: string;
63
+ cvv2Input: string;
64
+ expInput: string;
65
+ expMonthInput: string;
66
+ expYearInput: string;
67
+ };
68
+ validationMessages?: {
45
69
  cardholderInput?: {
46
70
  required: string;
47
71
  };
@@ -61,36 +85,16 @@ type CardFormProps = {
61
85
  required: string;
62
86
  };
63
87
  expMonthInput?: {
88
+ format: string;
89
+ invalid: string;
64
90
  required: string;
65
91
  };
66
92
  expYearInput?: {
93
+ expired: string;
94
+ format: string;
67
95
  required: string;
68
96
  };
69
97
  };
70
- expIsMMYY?: boolean;
71
- groupedView?: boolean;
72
- onSubmit?: (token: string) => any;
73
- styling?: {
74
- buttonStyle?: StyleProp<ViewStyle>;
75
- buttonTextStyle?: StyleProp<TextStyle>;
76
- colorScheme?: "light" | "dark";
77
- darkTheme?: FormThemeColors;
78
- formFieldStyle?: StyleProp<ViewStyle>;
79
- defaultStyling?: boolean;
80
- formKeyboardAvoidingViewStyle?: StyleProp<ViewStyle>;
81
- formScrollViewStyle?: StyleProp<ViewStyle>;
82
- labelStyle?: StyleProp<TextStyle>;
83
- lightTheme?: FormThemeColors;
84
- textInputStyle?: StyleProp<TextStyle>;
85
- };
86
- placeholders?: {
87
- cardholderInput: string;
88
- cardNumberInput: string;
89
- cvv2Input: string;
90
- expInput: string;
91
- expMonthInput: string;
92
- expYearInput: string;
93
- };
94
98
  withAnimatedTexts?: boolean;
95
99
  withIcons?: boolean;
96
100
  withLabels?: boolean;
@@ -107,7 +111,6 @@ export default function OPCardForm({
107
111
  }: CardFormProps) {
108
112
  const {
109
113
  buttonTitle,
110
- errorMessages,
111
114
  expIsMMYY = true,
112
115
  groupedView = true,
113
116
  onSubmit,
@@ -120,6 +123,7 @@ export default function OPCardForm({
120
123
  expMonthInput: "",
121
124
  expYearInput: "",
122
125
  },
126
+ validationMessages,
123
127
  withAnimatedTexts,
124
128
  withIcons,
125
129
  withLabels,
@@ -167,6 +171,7 @@ export default function OPCardForm({
167
171
  expYear: "",
168
172
  }}
169
173
  onSubmit={onSubmit}
174
+ validationMessages={validationMessages}
170
175
  >
171
176
  <KeyboardAvoidingView
172
177
  behavior="padding"
@@ -187,7 +192,6 @@ export default function OPCardForm({
187
192
  }
188
193
  >
189
194
  <OPHolderNameInput
190
- errorMessages={errorMessages?.cardholderInput}
191
195
  options={{
192
196
  formFieldStyle,
193
197
  defaultStyling,
@@ -196,13 +200,13 @@ export default function OPCardForm({
196
200
  textInputStyle,
197
201
  }}
198
202
  placeholder={placeholders.cardholderInput}
203
+ validationMessages={validationMessages?.cardholderInput}
199
204
  withAnimatedText={withAnimatedTexts}
200
205
  withIcon={withIcons}
201
206
  withLabel={withLabels}
202
207
  withPlaceholder={withPlaceholders}
203
208
  />
204
209
  <OPCardNumberInput
205
- errorMessages={errorMessages?.cardNumberInput}
206
210
  options={{
207
211
  formFieldStyle,
208
212
  defaultStyling,
@@ -211,6 +215,7 @@ export default function OPCardForm({
211
215
  textInputStyle,
212
216
  }}
213
217
  placeholder={placeholders.cardNumberInput}
218
+ validationMessages={validationMessages?.cardNumberInput}
214
219
  withAnimatedText={withAnimatedTexts}
215
220
  withIcon={withIcons}
216
221
  withLabel={withLabels}
@@ -220,7 +225,6 @@ export default function OPCardForm({
220
225
  <View style={{ flexDirection: "row", gap: 12 }}>
221
226
  {expIsMMYY ? (
222
227
  <OPExpInput
223
- errorMessages={errorMessages?.expInput}
224
228
  options={{
225
229
  formFieldStyle: { flex: 1 },
226
230
  defaultStyling,
@@ -229,6 +233,7 @@ export default function OPCardForm({
229
233
  textInputStyle,
230
234
  }}
231
235
  placeholder={placeholders.expInput}
236
+ validationMessages={validationMessages?.expInput}
232
237
  withAnimatedText={withAnimatedTexts}
233
238
  withIcon={withIcons}
234
239
  withLabel={withLabels}
@@ -237,7 +242,6 @@ export default function OPCardForm({
237
242
  ) : (
238
243
  <>
239
244
  <OPExpMonthInput
240
- errorMessages={errorMessages?.expMonthInput}
241
245
  options={{
242
246
  formFieldStyle: { flex: 1 },
243
247
  defaultStyling,
@@ -246,13 +250,13 @@ export default function OPCardForm({
246
250
  textInputStyle,
247
251
  }}
248
252
  placeholder={placeholders.expMonthInput}
253
+ validationMessages={validationMessages?.expMonthInput}
249
254
  withAnimatedText={withAnimatedTexts}
250
255
  withIcon={withIcons}
251
256
  withLabel={withLabels}
252
257
  withPlaceholder={withPlaceholders}
253
258
  />
254
259
  <OPExpYearInput
255
- errorMessages={errorMessages?.expYearInput}
256
260
  options={{
257
261
  formFieldStyle: { flex: 1 },
258
262
  defaultStyling,
@@ -261,6 +265,7 @@ export default function OPCardForm({
261
265
  textInputStyle,
262
266
  }}
263
267
  placeholder={placeholders.expYearInput}
268
+ validationMessages={validationMessages?.expYearInput}
264
269
  withAnimatedText={withAnimatedTexts}
265
270
  withIcon={withIcons}
266
271
  withLabel={withLabels}
@@ -269,7 +274,6 @@ export default function OPCardForm({
269
274
  </>
270
275
  )}
271
276
  <OPCvv2Input
272
- errorMessages={errorMessages?.cvv2Input}
273
277
  options={{
274
278
  formFieldStyle: { flex: 1 },
275
279
  defaultStyling,
@@ -278,6 +282,7 @@ export default function OPCardForm({
278
282
  textInputStyle,
279
283
  }}
280
284
  placeholder={placeholders.cvv2Input}
285
+ validationMessages={validationMessages?.cvv2Input}
281
286
  withAnimatedText={withAnimatedTexts}
282
287
  withIcon={withIcons}
283
288
  withLabel={withLabels}
@@ -288,7 +293,6 @@ export default function OPCardForm({
288
293
  <>
289
294
  {expIsMMYY ? (
290
295
  <OPExpInput
291
- errorMessages={errorMessages?.expInput}
292
296
  options={{
293
297
  formFieldStyle,
294
298
  defaultStyling,
@@ -297,6 +301,7 @@ export default function OPCardForm({
297
301
  textInputStyle,
298
302
  }}
299
303
  placeholder={placeholders.expInput}
304
+ validationMessages={validationMessages?.expInput}
300
305
  withAnimatedText={withAnimatedTexts}
301
306
  withIcon={withIcons}
302
307
  withLabel={withLabels}
@@ -305,7 +310,6 @@ export default function OPCardForm({
305
310
  ) : (
306
311
  <>
307
312
  <OPExpMonthInput
308
- errorMessages={errorMessages?.expMonthInput}
309
313
  options={{
310
314
  formFieldStyle,
311
315
  defaultStyling,
@@ -314,13 +318,13 @@ export default function OPCardForm({
314
318
  textInputStyle,
315
319
  }}
316
320
  placeholder={placeholders.expMonthInput}
321
+ validationMessages={validationMessages?.expMonthInput}
317
322
  withAnimatedText={withAnimatedTexts}
318
323
  withIcon={withIcons}
319
324
  withLabel={withLabels}
320
325
  withPlaceholder={withPlaceholders}
321
326
  />
322
327
  <OPExpYearInput
323
- errorMessages={errorMessages?.expYearInput}
324
328
  options={{
325
329
  formFieldStyle,
326
330
  defaultStyling,
@@ -329,6 +333,7 @@ export default function OPCardForm({
329
333
  textInputStyle,
330
334
  }}
331
335
  placeholder={placeholders.expYearInput}
336
+ validationMessages={validationMessages?.expYearInput}
332
337
  withAnimatedText={withAnimatedTexts}
333
338
  withIcon={withIcons}
334
339
  withLabel={withLabels}
@@ -338,7 +343,6 @@ export default function OPCardForm({
338
343
  )}
339
344
 
340
345
  <OPCvv2Input
341
- errorMessages={errorMessages?.cvv2Input}
342
346
  options={{
343
347
  formFieldStyle,
344
348
  defaultStyling,
@@ -347,6 +351,7 @@ export default function OPCardForm({
347
351
  textInputStyle,
348
352
  }}
349
353
  placeholder={placeholders.cvv2Input}
354
+ validationMessages={validationMessages?.cvv2Input}
350
355
  withAnimatedText={withAnimatedTexts}
351
356
  withIcon={withIcons}
352
357
  withLabel={withLabels}
@@ -17,11 +17,6 @@ type IconType =
17
17
  | { type: "png"; name: "amex" | "discover" | "mc" | "visa" };
18
18
 
19
19
  type CardInputOptions = {
20
- errorMessages?: {
21
- cardNumberLength?: string;
22
- invalid?: string;
23
- required?: string;
24
- };
25
20
  options?: {
26
21
  formFieldStyle?: StyleProp<ViewStyle>;
27
22
  defaultStyling?: boolean;
@@ -30,6 +25,11 @@ type CardInputOptions = {
30
25
  textInputStyle?: StyleProp<TextStyle>;
31
26
  };
32
27
  placeholder?: string;
28
+ validationMessages?: {
29
+ cardNumberLength?: string;
30
+ invalid?: string;
31
+ required?: string;
32
+ };
33
33
  withAnimatedText?: boolean;
34
34
  withIcon?: boolean;
35
35
  withLabel?: boolean;
@@ -65,14 +65,14 @@ function detectCardBrand(cardNumber: string): string | null {
65
65
  // Luhn algorithm validator
66
66
  function validateCardNumber(
67
67
  value: string,
68
- errorMessages?: Record<string, string | undefined>,
68
+ validationMessages?: Record<string, string | undefined>,
69
69
  ) {
70
- if (!value) return errorMessages?.required || "Card Number is required";
70
+ if (!value) return validationMessages?.required || "Card Number is required";
71
71
 
72
72
  const sanitized = value.replace(/\s+/g, "");
73
73
  if (sanitized.length < 13 || sanitized.length > 19) {
74
74
  return (
75
- errorMessages?.cardNumberLength || "Card Number must be 13-19 digits"
75
+ validationMessages?.cardNumberLength || "Card Number must be 13-19 digits"
76
76
  );
77
77
  }
78
78
 
@@ -87,15 +87,16 @@ function validateCardNumber(
87
87
  sum += digit;
88
88
  shouldDouble = !shouldDouble;
89
89
  }
90
- if (sum % 10 !== 0) return errorMessages?.invalid || "Invalid card number";
90
+ if (sum % 10 !== 0)
91
+ return validationMessages?.invalid || "Invalid card number";
91
92
 
92
93
  return undefined; // valid card
93
94
  }
94
95
 
95
96
  export default function OPCardNumberInput({
96
- errorMessages = { cardNumberLength: "", invalid: "", required: "" },
97
97
  options = {},
98
98
  placeholder = "",
99
+ validationMessages = { cardNumberLength: "", invalid: "", required: "" },
99
100
  withAnimatedText = true,
100
101
  withIcon = true,
101
102
  withLabel = false,
@@ -118,7 +119,6 @@ export default function OPCardNumberInput({
118
119
  autoComplete="cc-number"
119
120
  autoCorrect={false}
120
121
  defaultStyling={defaultStyling}
121
- errorMessages={errorMessages}
122
122
  icon={getCardBrandIcon(cardType)}
123
123
  keyboardType="number-pad"
124
124
  labelStyle={labelStyle}
@@ -130,6 +130,7 @@ export default function OPCardNumberInput({
130
130
  placeholder={placeholder || "Card Number"}
131
131
  styling={{ formFieldStyle, inputStyle, textInputStyle }}
132
132
  validate={validateCardNumber}
133
+ validationMessages={validationMessages}
133
134
  withAnimatedText={withAnimatedText}
134
135
  withIcon={withIcon}
135
136
  withLabel={withLabel}
@@ -3,10 +3,6 @@ import { StyleProp, ViewStyle, TextStyle } from "react-native";
3
3
  import { FormField } from "./forms";
4
4
 
5
5
  type CardInputOptions = {
6
- errorMessages?: {
7
- invalid?: string;
8
- required?: string;
9
- };
10
6
  options?: {
11
7
  formFieldStyle?: StyleProp<ViewStyle>;
12
8
  defaultStyling?: boolean;
@@ -15,6 +11,10 @@ type CardInputOptions = {
15
11
  textInputStyle?: StyleProp<TextStyle>;
16
12
  };
17
13
  placeholder?: string;
14
+ validationMessages?: {
15
+ invalid?: string;
16
+ required?: string;
17
+ };
18
18
  withAnimatedText?: boolean;
19
19
  withIcon?: boolean;
20
20
  withLabel?: boolean;
@@ -23,17 +23,18 @@ type CardInputOptions = {
23
23
 
24
24
  function validateCvv(
25
25
  value: string,
26
- errorMessages?: Record<string, string | undefined>,
26
+ validationMessages?: Record<string, string | undefined>,
27
27
  ) {
28
- if (!value) return errorMessages?.required || "CVV is required";
29
- if (!/^\d{3,4}$/.test(value)) return errorMessages?.invalid || "Invalid CVV";
28
+ if (!value) return validationMessages?.required || "CVV is required";
29
+ if (!/^\d{3,4}$/.test(value))
30
+ return validationMessages?.invalid || "Invalid CVV";
30
31
  return undefined;
31
32
  }
32
33
 
33
34
  export default function OPExpYearInput({
34
- errorMessages = { invalid: "", required: "" },
35
35
  options = {},
36
36
  placeholder = "",
37
+ validationMessages = { invalid: "", required: "" },
37
38
  withAnimatedText = true,
38
39
  withIcon = true,
39
40
  withLabel = false,
@@ -54,7 +55,6 @@ export default function OPExpYearInput({
54
55
  autoComplete="cc-csc"
55
56
  autoCorrect={false}
56
57
  defaultStyling={defaultStyling}
57
- errorMessages={errorMessages}
58
58
  icon={{ type: "material", name: "lock" }}
59
59
  keyboardType="number-pad"
60
60
  labelStyle={labelStyle}
@@ -63,6 +63,7 @@ export default function OPExpYearInput({
63
63
  placeholder={placeholder || "CVC"}
64
64
  styling={{ formFieldStyle, inputStyle, textInputStyle }}
65
65
  validate={validateCvv}
66
+ validationMessages={validationMessages}
66
67
  withAnimatedText={withAnimatedText}
67
68
  withIcon={withIcon}
68
69
  withLabel={withLabel}
@@ -3,12 +3,6 @@ import { StyleProp, ViewStyle, TextStyle } from "react-native";
3
3
  import { FormField } from "./forms";
4
4
 
5
5
  type CardInputOptions = {
6
- errorMessages?: {
7
- expired?: string;
8
- format?: string;
9
- invalidMonth?: string;
10
- required?: string;
11
- };
12
6
  options?: {
13
7
  formFieldStyle?: StyleProp<ViewStyle>;
14
8
  defaultStyling?: boolean;
@@ -17,6 +11,12 @@ type CardInputOptions = {
17
11
  textInputStyle?: StyleProp<TextStyle>;
18
12
  };
19
13
  placeholder?: string;
14
+ validationMessages?: {
15
+ expired?: string;
16
+ format?: string;
17
+ invalidMonth?: string;
18
+ required?: string;
19
+ };
20
20
  withAnimatedText?: boolean;
21
21
  withIcon?: boolean;
22
22
  withLabel?: boolean;
@@ -25,29 +25,35 @@ type CardInputOptions = {
25
25
 
26
26
  function validateExpiry(
27
27
  value: string,
28
- errorMessages?: Record<string, string | undefined>,
28
+ validationMessages?: Record<string, string | undefined>,
29
29
  ) {
30
- if (!value) return errorMessages?.required || "Expiry is required";
30
+ if (!value) return validationMessages?.required || "Expiry is required";
31
31
 
32
32
  const match = /^(\d{2})\/(\d{2})$/.exec(value);
33
- if (!match) return errorMessages?.format || "Use MM/YY format";
33
+ if (!match) return validationMessages?.format || "Use MM/YY format";
34
34
 
35
35
  const month = parseInt(match[1], 10);
36
36
  const year = 2000 + parseInt(match[2], 10);
37
37
 
38
- if (month < 1 || month > 12) return errorMessages?.invalid || "Invalid month";
38
+ if (month < 1 || month > 12)
39
+ return validationMessages?.invalidMonth || "Invalid month";
39
40
 
40
41
  const now = new Date();
41
42
  const expiry = new Date(year, month);
42
- if (expiry <= now) return errorMessages?.expired || "Card expired";
43
+ if (expiry <= now) return validationMessages?.expired || "Card expired";
43
44
 
44
45
  return undefined;
45
46
  }
46
47
 
47
48
  export default function OPExpYearInput({
48
- errorMessages = { expired: "", format: "", invalidMonth: "", required: "" },
49
49
  options = {},
50
50
  placeholder = "",
51
+ validationMessages = {
52
+ expired: "",
53
+ format: "",
54
+ invalidMonth: "",
55
+ required: "",
56
+ },
51
57
  withAnimatedText = true,
52
58
  withIcon = true,
53
59
  withLabel = false,
@@ -68,7 +74,6 @@ export default function OPExpYearInput({
68
74
  autoComplete="cc-exp"
69
75
  autoCorrect={false}
70
76
  defaultStyling={defaultStyling}
71
- errorMessages={errorMessages}
72
77
  icon={{ type: "material", name: "calendar-blank" }}
73
78
  keyboardType="number-pad"
74
79
  labelStyle={labelStyle}
@@ -77,6 +82,7 @@ export default function OPExpYearInput({
77
82
  placeholder={placeholder || "MM/YY"}
78
83
  styling={{ formFieldStyle, inputStyle, textInputStyle }}
79
84
  validate={validateExpiry}
85
+ validationMessages={validationMessages}
80
86
  withAnimatedText={withAnimatedText}
81
87
  withIcon={withIcon}
82
88
  withLabel={withLabel}
@@ -3,7 +3,6 @@ import { StyleProp, ViewStyle, TextStyle } from "react-native";
3
3
  import { FormField } from "./forms";
4
4
 
5
5
  type CardInputOptions = {
6
- errorMessages?: { format?: string; invalid?: string; required?: string };
7
6
  options?: {
8
7
  formFieldStyle?: StyleProp<ViewStyle>;
9
8
  defaultStyling?: boolean;
@@ -12,6 +11,7 @@ type CardInputOptions = {
12
11
  textInputStyle?: StyleProp<TextStyle>;
13
12
  };
14
13
  placeholder?: string;
14
+ validationMessages?: { format?: string; invalid?: string; required?: string };
15
15
  withAnimatedText?: boolean;
16
16
  withIcon?: boolean;
17
17
  withLabel?: boolean;
@@ -20,24 +20,25 @@ type CardInputOptions = {
20
20
 
21
21
  function validateExpiryMonth(
22
22
  value: string,
23
- errorMessages?: Record<string, string | undefined>,
23
+ validationMessages?: Record<string, string | undefined>,
24
24
  ) {
25
- if (!value) return errorMessages?.required || "Month is required";
25
+ if (!value) return validationMessages?.required || "Month is required";
26
26
 
27
27
  const match = /^(\d{2})$/.exec(value);
28
- if (!match) return errorMessages?.format || "Use MM format";
28
+ if (!match) return validationMessages?.format || "Use MM format";
29
29
 
30
30
  const month = parseInt(value, 10);
31
31
 
32
- if (month < 1 || month > 12) return errorMessages?.invalid || "Invalid month";
32
+ if (month < 1 || month > 12)
33
+ return validationMessages?.invalid || "Invalid month";
33
34
 
34
35
  return undefined;
35
36
  }
36
37
 
37
38
  export default function OPExpMonthInput({
38
- errorMessages = { format: "", invalid: "", required: "" },
39
39
  options = {},
40
40
  placeholder = "",
41
+ validationMessages = { format: "", invalid: "", required: "" },
41
42
  withAnimatedText = true,
42
43
  withIcon = true,
43
44
  withLabel = false,
@@ -58,7 +59,6 @@ export default function OPExpMonthInput({
58
59
  autoComplete="cc-exp-month"
59
60
  autoCorrect={false}
60
61
  defaultStyling={defaultStyling}
61
- errorMessages={errorMessages}
62
62
  icon={{ type: "material", name: "calendar-blank" }}
63
63
  keyboardType="number-pad"
64
64
  labelStyle={labelStyle}
@@ -67,6 +67,7 @@ export default function OPExpMonthInput({
67
67
  placeholder={placeholder || "MM"}
68
68
  styling={{ formFieldStyle, inputStyle, textInputStyle }}
69
69
  validate={validateExpiryMonth}
70
+ validationMessages={validationMessages}
70
71
  withAnimatedText={withAnimatedText}
71
72
  withIcon={withIcon}
72
73
  withLabel={withLabel}
@@ -3,7 +3,6 @@ import { StyleProp, ViewStyle, TextStyle } from "react-native";
3
3
  import { FormField } from "./forms";
4
4
 
5
5
  type CardInputOptions = {
6
- errorMessages?: { format?: string; expired?: string; required?: string };
7
6
  options?: {
8
7
  formFieldStyle?: StyleProp<ViewStyle>;
9
8
  defaultStyling?: boolean;
@@ -12,6 +11,7 @@ type CardInputOptions = {
12
11
  textInputStyle?: StyleProp<TextStyle>;
13
12
  };
14
13
  placeholder?: string;
14
+ validationMessages?: { expired?: string; format?: string; required?: string };
15
15
  withAnimatedText?: boolean;
16
16
  withIcon?: boolean;
17
17
  withLabel?: boolean;
@@ -20,25 +20,25 @@ type CardInputOptions = {
20
20
 
21
21
  function validateExpiryYear(
22
22
  value: string,
23
- errorMessages?: Record<string, string | undefined>,
23
+ validationMessages?: Record<string, string | undefined>,
24
24
  ) {
25
- if (!value) return errorMessages?.required || "Year is required";
25
+ if (!value) return validationMessages?.required || "Year is required";
26
26
 
27
27
  const match = /^(\d{2})$/.exec(value);
28
- if (!match) return errorMessages?.format || "Use YY format";
28
+ if (!match) return validationMessages?.format || "Use YY format";
29
29
 
30
30
  const year = 2000 + parseInt(value, 10);
31
31
  const currentYear = new Date().getFullYear();
32
32
 
33
- if (year <= currentYear) return errorMessages?.expired || "Card expired";
33
+ if (year <= currentYear) return validationMessages?.expired || "Card expired";
34
34
 
35
35
  return undefined;
36
36
  }
37
37
 
38
38
  export default function OPExpYearInput({
39
- errorMessages = { format: "", expired: "", required: "" },
40
39
  options = {},
41
40
  placeholder = "",
41
+ validationMessages = { expired: "", format: "", required: "" },
42
42
  withAnimatedText = true,
43
43
  withIcon = true,
44
44
  withLabel = false,
@@ -59,7 +59,6 @@ export default function OPExpYearInput({
59
59
  autoComplete="cc-exp-year"
60
60
  autoCorrect={false}
61
61
  defaultStyling={defaultStyling}
62
- errorMessages={errorMessages}
63
62
  icon={{ type: "material", name: "calendar-blank" }}
64
63
  keyboardType="number-pad"
65
64
  labelStyle={labelStyle}
@@ -68,6 +67,7 @@ export default function OPExpYearInput({
68
67
  placeholder={placeholder || "YY"}
69
68
  styling={{ formFieldStyle, inputStyle, textInputStyle }}
70
69
  validate={validateExpiryYear}
70
+ validationMessages={validationMessages}
71
71
  withAnimatedText={withAnimatedText}
72
72
  withIcon={withIcon}
73
73
  withLabel={withLabel}
@@ -3,9 +3,6 @@ import { StyleProp, ViewStyle, TextStyle } from "react-native";
3
3
  import { FormField } from "./forms";
4
4
 
5
5
  type CardInputOptions = {
6
- errorMessages?: {
7
- required: string;
8
- };
9
6
  options?: {
10
7
  formFieldStyle?: StyleProp<ViewStyle>;
11
8
  defaultStyling?: boolean;
@@ -14,6 +11,9 @@ type CardInputOptions = {
14
11
  textInputStyle?: StyleProp<TextStyle>;
15
12
  };
16
13
  placeholder?: string;
14
+ validationMessages?: {
15
+ required: string;
16
+ };
17
17
  withAnimatedText?: boolean;
18
18
  withIcon?: boolean;
19
19
  withLabel?: boolean;
@@ -22,17 +22,18 @@ type CardInputOptions = {
22
22
 
23
23
  function validateCardholderName(
24
24
  value: string,
25
- errorMessages?: Record<string, string | undefined>,
25
+ validationMessages?: Record<string, string | undefined>,
26
26
  ) {
27
- if (!value) return errorMessages?.required || "Cardholder name is required";
27
+ if (!value)
28
+ return validationMessages?.required || "Cardholder name is required";
28
29
 
29
30
  return undefined; // valid cardholder name
30
31
  }
31
32
 
32
33
  export default function OPHolderNameInput({
33
- errorMessages = { required: "" },
34
34
  options = {},
35
35
  placeholder = "",
36
+ validationMessages = { required: "" },
36
37
  withAnimatedText = true,
37
38
  withIcon = true,
38
39
  withLabel = false,
@@ -53,13 +54,13 @@ export default function OPHolderNameInput({
53
54
  autoComplete="cc-name"
54
55
  autoCorrect={false}
55
56
  defaultStyling={defaultStyling}
56
- errorMessages={errorMessages}
57
57
  icon={{ type: "material", name: "account" }}
58
58
  labelStyle={labelStyle}
59
59
  name="cardholderName"
60
60
  placeholder={placeholder || "Cardholder Name"}
61
61
  styling={{ formFieldStyle, inputStyle, textInputStyle }}
62
62
  validate={validateCardholderName}
63
+ validationMessages={validationMessages}
63
64
  withAnimatedText={withAnimatedText}
64
65
  withIcon={withIcon}
65
66
  withLabel={withLabel}