@open-tender/utils 0.4.91 → 0.4.93

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.
@@ -45,7 +45,7 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false, includeAddr
45
45
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
46
46
  };
47
47
  const handleBlur = (name) => {
48
- const { errors: validationErrors } = (0, index_1.validateCreditCard)(data, cardType);
48
+ const { errors: validationErrors } = (0, index_1.validateCreditCard)(data, cardType, requireCardholderName);
49
49
  if (validationErrors) {
50
50
  const error = validationErrors[name];
51
51
  setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
3
+ export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  recaptchaRef: import("react").MutableRefObject<any>;
6
6
  data: CreditCardData | null;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCreditCardForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const __1 = require("../");
6
- const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
6
+ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id, kountSessionId, requireCardholderName = false) => {
7
7
  const submitRef = (0, react_1.useRef)(null);
8
8
  const recaptchaRef = (0, react_1.useRef)(null);
9
9
  const [submitting, setSubmitting] = (0, react_1.useState)(false);
@@ -24,13 +24,15 @@ const useCreditCardForm = (loading, error, data, cardType, addCard, callback, re
24
24
  setErrors({});
25
25
  if (!data || !cardType)
26
26
  return;
27
- const { card, errors: cardErrors } = (0, __1.validateCreditCard)(data, cardType);
27
+ const { card, errors: cardErrors } = (0, __1.validateCreditCard)(data, cardType, requireCardholderName);
28
28
  if (cardErrors) {
29
29
  setErrors(cardErrors);
30
30
  setSubmitting(false);
31
31
  }
32
32
  else {
33
33
  const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
34
+ if (kountSessionId)
35
+ cardRc.kount_device_session_id = kountSessionId;
34
36
  if (recaptchaKey) {
35
37
  try {
36
38
  const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, Donat
3
3
  export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
4
4
  type: string;
5
5
  args?: unknown;
6
- }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean) => {
7
7
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
8
8
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
9
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDonationsForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
- const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
6
+ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
7
7
  const submitRef = (0, react_1.useRef)(null);
8
8
  const inputRef = (0, react_1.useRef)(null);
9
9
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -72,6 +72,14 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
72
72
  type: 'working',
73
73
  args: { text: 'Submitting your contribution...' }
74
74
  };
75
+ const formData = {
76
+ amount: amount,
77
+ email: email,
78
+ credit_card,
79
+ token: ''
80
+ };
81
+ if (kountSessionId)
82
+ formData.kount_device_session_id = kountSessionId;
75
83
  if (recaptchaKey) {
76
84
  try {
77
85
  const token = recaptchaRef.current.getValue();
@@ -83,12 +91,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
83
91
  else {
84
92
  setSubmitting(true);
85
93
  setAlert(alert);
86
- purchase({
87
- amount: amount,
88
- email: email,
89
- credit_card,
90
- token: token
91
- });
94
+ purchase(Object.assign(Object.assign({}, formData), { token }));
92
95
  }
93
96
  }
94
97
  catch (err) {
@@ -100,12 +103,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
100
103
  else {
101
104
  setSubmitting(true);
102
105
  setAlert(alert);
103
- purchase({
104
- amount: amount,
105
- email: email,
106
- credit_card,
107
- token: ''
108
- });
106
+ purchase(formData);
109
107
  }
110
108
  };
111
109
  const handleSubmit = (evt) => {
@@ -119,7 +117,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
119
117
  else {
120
118
  if (isNewCard) {
121
119
  if (cardData && cardType) {
122
- const { card, errors: errs } = (0, utils_1.validateCreditCard)(cardData, cardType);
120
+ const { card, errors: errs } = (0, utils_1.validateCreditCard)(cardData, cardType, requireCardholderName);
123
121
  if (errs) {
124
122
  setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
125
123
  setSubmitting(false);
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftC
3
3
  export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
4
4
  type: string;
5
5
  args?: unknown;
6
- }) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean) => {
7
7
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
8
8
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
9
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useGiftCardsForm = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../utils");
6
- const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url) => {
6
+ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
7
7
  const submitRef = (0, react_1.useRef)(null);
8
8
  const inputRef = (0, react_1.useRef)(null);
9
9
  const recaptchaRef = (0, react_1.useRef)(null);
@@ -94,6 +94,14 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
94
94
  type: 'working',
95
95
  args: { text: 'Submitting your purchase...' }
96
96
  };
97
+ const formData = {
98
+ credit_card,
99
+ name: name !== null && name !== void 0 ? name : '',
100
+ email: email !== null && email !== void 0 ? email : '',
101
+ url: url !== null && url !== void 0 ? url : ''
102
+ };
103
+ if (kountSessionId)
104
+ formData.kount_device_session_id = kountSessionId;
97
105
  if (recaptchaKey) {
98
106
  try {
99
107
  const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
@@ -107,14 +115,8 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
107
115
  setSubmitting(true);
108
116
  setAlert(alert);
109
117
  const gift_cards = makeGiftCards(cards);
110
- purchase({
111
- token,
112
- credit_card,
113
- name: name !== null && name !== void 0 ? name : '',
114
- email: email !== null && email !== void 0 ? email : '',
115
- url: url !== null && url !== void 0 ? url : '',
116
- gift_cards
117
- });
118
+ purchase(Object.assign(Object.assign({}, formData), { token,
119
+ gift_cards }));
118
120
  }
119
121
  }
120
122
  catch (err) {
@@ -126,13 +128,7 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
126
128
  setSubmitting(true);
127
129
  setAlert(alert);
128
130
  const gift_cards = makeGiftCards(cards);
129
- purchase({
130
- credit_card,
131
- name: name !== null && name !== void 0 ? name : '',
132
- email: email !== null && email !== void 0 ? email : '',
133
- url: url !== null && url !== void 0 ? url : '',
134
- gift_cards
135
- });
131
+ purchase(Object.assign(Object.assign({}, formData), { gift_cards }));
136
132
  }
137
133
  };
138
134
  const handleSubmit = (evt) => {
@@ -146,7 +142,7 @@ const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, in
146
142
  else {
147
143
  if (isNewCard) {
148
144
  if (cardData && cardType) {
149
- const { card, errors } = (0, utils_1.validateCreditCard)(cardData, cardType);
145
+ const { card, errors } = (0, utils_1.validateCreditCard)(cardData, cardType, requireCardholderName);
150
146
  if (errors) {
151
147
  setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
152
148
  setSubmitting(false);
@@ -17,4 +17,4 @@ export declare const makeNumeric: (str: string) => string;
17
17
  export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
18
18
  export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
19
19
  export declare const formatCard: (card: CreditCardData | null) => [CreditCardData | null, CardType | null];
20
- export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) => CreditCardValidate;
20
+ export declare const validateCreditCard: (card: CreditCardData, cardType: CardType, requireCardholderName?: boolean) => CreditCardValidate;
@@ -110,9 +110,9 @@ const formatCard = (card) => {
110
110
  return [creditCard, creditCardType];
111
111
  };
112
112
  exports.formatCard = formatCard;
113
- const validateCreditCard = (card, cardType) => {
113
+ const validateCreditCard = (card, cardType, requireCardholderName = false) => {
114
114
  const errors = {};
115
- let { acct, exp, cvv, zip } = card;
115
+ let { acct, exp, cvv, zip, cardholder_name } = card;
116
116
  const acctLength = cardType === 'AMEX' ? 15 : 16;
117
117
  acct = acct ? acct.replace(/\s/g, '') : '';
118
118
  if (acct.length !== acctLength) {
@@ -148,10 +148,14 @@ const validateCreditCard = (card, cardType) => {
148
148
  else if (!(0, helpers_1.isNum)(zip)) {
149
149
  errors.zip = 'Zip code must be only numbers';
150
150
  }
151
+ cardholder_name = cardholder_name === null || cardholder_name === void 0 ? void 0 : cardholder_name.trim();
152
+ if (requireCardholderName && !cardholder_name) {
153
+ errors.cardholder_name = 'Cardholder name is required';
154
+ }
151
155
  if (!(0, helpers_1.isEmpty)(errors)) {
152
156
  return { card, cardType, errors };
153
157
  }
154
- card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip });
158
+ card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip, cardholder_name });
155
159
  return { card, cardType, errors: null };
156
160
  };
157
161
  exports.validateCreditCard = validateCreditCard;
@@ -42,7 +42,7 @@ export const useCreditCard = (initState, cardErrors = {}, disabled = false, incl
42
42
  setData(Object.assign(Object.assign({}, data), { [name]: value }));
43
43
  };
44
44
  const handleBlur = (name) => {
45
- const { errors: validationErrors } = validateCreditCard(data, cardType);
45
+ const { errors: validationErrors } = validateCreditCard(data, cardType, requireCardholderName);
46
46
  if (validationErrors) {
47
47
  const error = validationErrors[name];
48
48
  setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CardType, CreditCardData, CreditCardErrors, RequestError, RequestStatus } from '@open-tender/types';
3
- export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null) => {
3
+ export declare const useCreditCardForm: (loading: RequestStatus, error: RequestError, data: CreditCardData | null, cardType: CardType | null, addCard: (data: CreditCardData, callback: () => void) => void, callback: () => void, recaptchaKey: string | null, revenue_center_id: number | null, kountSessionId?: string | null, requireCardholderName?: boolean) => {
4
4
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
5
5
  recaptchaRef: import("react").MutableRefObject<any>;
6
6
  data: CreditCardData | null;
@@ -1,6 +1,6 @@
1
1
  import { useState, useEffect, useRef } from 'react';
2
2
  import { makeFormErrors, validateCreditCard } from '../';
3
- export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id) => {
3
+ export const useCreditCardForm = (loading, error, data, cardType, addCard, callback, recaptchaKey, revenue_center_id, kountSessionId, requireCardholderName = false) => {
4
4
  const submitRef = useRef(null);
5
5
  const recaptchaRef = useRef(null);
6
6
  const [submitting, setSubmitting] = useState(false);
@@ -21,13 +21,15 @@ export const useCreditCardForm = (loading, error, data, cardType, addCard, callb
21
21
  setErrors({});
22
22
  if (!data || !cardType)
23
23
  return;
24
- const { card, errors: cardErrors } = validateCreditCard(data, cardType);
24
+ const { card, errors: cardErrors } = validateCreditCard(data, cardType, requireCardholderName);
25
25
  if (cardErrors) {
26
26
  setErrors(cardErrors);
27
27
  setSubmitting(false);
28
28
  }
29
29
  else {
30
30
  const cardRc = revenue_center_id ? Object.assign(Object.assign({}, card), { revenue_center_id }) : card;
31
+ if (kountSessionId)
32
+ cardRc.kount_device_session_id = kountSessionId;
31
33
  if (recaptchaKey) {
32
34
  try {
33
35
  const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, Donat
3
3
  export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
4
4
  type: string;
5
5
  args?: unknown;
6
- }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window, kountSessionId?: string | null, requireCardholderName?: boolean) => {
7
7
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
8
8
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
9
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -1,6 +1,6 @@
1
1
  import { useMemo, useEffect, useRef, useState } from 'react';
2
2
  import { makeFormErrors, makeNumeric, validateCreditCard } from '../utils';
3
- export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
3
+ export const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef, kountSessionId, requireCardholderName = false) => {
4
4
  const submitRef = useRef(null);
5
5
  const inputRef = useRef(null);
6
6
  const recaptchaRef = useRef(null);
@@ -69,6 +69,14 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
69
69
  type: 'working',
70
70
  args: { text: 'Submitting your contribution...' }
71
71
  };
72
+ const formData = {
73
+ amount: amount,
74
+ email: email,
75
+ credit_card,
76
+ token: ''
77
+ };
78
+ if (kountSessionId)
79
+ formData.kount_device_session_id = kountSessionId;
72
80
  if (recaptchaKey) {
73
81
  try {
74
82
  const token = recaptchaRef.current.getValue();
@@ -80,12 +88,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
80
88
  else {
81
89
  setSubmitting(true);
82
90
  setAlert(alert);
83
- purchase({
84
- amount: amount,
85
- email: email,
86
- credit_card,
87
- token: token
88
- });
91
+ purchase(Object.assign(Object.assign({}, formData), { token }));
89
92
  }
90
93
  }
91
94
  catch (err) {
@@ -97,12 +100,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
97
100
  else {
98
101
  setSubmitting(true);
99
102
  setAlert(alert);
100
- purchase({
101
- amount: amount,
102
- email: email,
103
- credit_card,
104
- token: ''
105
- });
103
+ purchase(formData);
106
104
  }
107
105
  };
108
106
  const handleSubmit = (evt) => {
@@ -116,7 +114,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
116
114
  else {
117
115
  if (isNewCard) {
118
116
  if (cardData && cardType) {
119
- const { card, errors: errs } = validateCreditCard(cardData, cardType);
117
+ const { card, errors: errs } = validateCreditCard(cardData, cardType, requireCardholderName);
120
118
  if (errs) {
121
119
  setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
122
120
  setSubmitting(false);
@@ -3,7 +3,7 @@ import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftC
3
3
  export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
4
4
  type: string;
5
5
  args?: unknown;
6
- }) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string) => {
6
+ }) => void, loading: RequestStatus, error: RequestError, success: boolean, initState: GiftCardPurchaseData, customer?: Customer | null, creditCards?: CreditCards, recaptchaKey?: string | null, cardData?: CreditCardData, cardType?: CardType, url?: string, kountSessionId?: string | null, requireCardholderName?: boolean) => {
7
7
  inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
8
8
  submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
9
9
  recaptchaRef: import("react").MutableRefObject<any>;
@@ -1,6 +1,6 @@
1
1
  import { useMemo, useRef, useState, useEffect } from 'react';
2
2
  import { makeFormErrors, validateCreditCard } from '../utils';
3
- export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url) => {
3
+ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, url, kountSessionId, requireCardholderName = false) => {
4
4
  const submitRef = useRef(null);
5
5
  const inputRef = useRef(null);
6
6
  const recaptchaRef = useRef(null);
@@ -91,6 +91,14 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
91
91
  type: 'working',
92
92
  args: { text: 'Submitting your purchase...' }
93
93
  };
94
+ const formData = {
95
+ credit_card,
96
+ name: name !== null && name !== void 0 ? name : '',
97
+ email: email !== null && email !== void 0 ? email : '',
98
+ url: url !== null && url !== void 0 ? url : ''
99
+ };
100
+ if (kountSessionId)
101
+ formData.kount_device_session_id = kountSessionId;
94
102
  if (recaptchaKey) {
95
103
  try {
96
104
  const token = (_a = recaptchaRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
@@ -104,14 +112,8 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
104
112
  setSubmitting(true);
105
113
  setAlert(alert);
106
114
  const gift_cards = makeGiftCards(cards);
107
- purchase({
108
- token,
109
- credit_card,
110
- name: name !== null && name !== void 0 ? name : '',
111
- email: email !== null && email !== void 0 ? email : '',
112
- url: url !== null && url !== void 0 ? url : '',
113
- gift_cards
114
- });
115
+ purchase(Object.assign(Object.assign({}, formData), { token,
116
+ gift_cards }));
115
117
  }
116
118
  }
117
119
  catch (err) {
@@ -123,13 +125,7 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
123
125
  setSubmitting(true);
124
126
  setAlert(alert);
125
127
  const gift_cards = makeGiftCards(cards);
126
- purchase({
127
- credit_card,
128
- name: name !== null && name !== void 0 ? name : '',
129
- email: email !== null && email !== void 0 ? email : '',
130
- url: url !== null && url !== void 0 ? url : '',
131
- gift_cards
132
- });
128
+ purchase(Object.assign(Object.assign({}, formData), { gift_cards }));
133
129
  }
134
130
  };
135
131
  const handleSubmit = (evt) => {
@@ -143,7 +139,7 @@ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, succ
143
139
  else {
144
140
  if (isNewCard) {
145
141
  if (cardData && cardType) {
146
- const { card, errors } = validateCreditCard(cardData, cardType);
142
+ const { card, errors } = validateCreditCard(cardData, cardType, requireCardholderName);
147
143
  if (errors) {
148
144
  setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
149
145
  setSubmitting(false);
@@ -17,4 +17,4 @@ export declare const makeNumeric: (str: string) => string;
17
17
  export declare const makeAcctNumber: (str: string, cardType: CardType) => string;
18
18
  export declare const formatCardField: (field: keyof CreditCardData, value: string) => string;
19
19
  export declare const formatCard: (card: CreditCardData | null) => [CreditCardData | null, CardType | null];
20
- export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) => CreditCardValidate;
20
+ export declare const validateCreditCard: (card: CreditCardData, cardType: CardType, requireCardholderName?: boolean) => CreditCardValidate;
@@ -102,9 +102,9 @@ export const formatCard = (card) => {
102
102
  creditCard.cardholder_name = card.cardholder_name;
103
103
  return [creditCard, creditCardType];
104
104
  };
105
- export const validateCreditCard = (card, cardType) => {
105
+ export const validateCreditCard = (card, cardType, requireCardholderName = false) => {
106
106
  const errors = {};
107
- let { acct, exp, cvv, zip } = card;
107
+ let { acct, exp, cvv, zip, cardholder_name } = card;
108
108
  const acctLength = cardType === 'AMEX' ? 15 : 16;
109
109
  acct = acct ? acct.replace(/\s/g, '') : '';
110
110
  if (acct.length !== acctLength) {
@@ -140,9 +140,13 @@ export const validateCreditCard = (card, cardType) => {
140
140
  else if (!isNum(zip)) {
141
141
  errors.zip = 'Zip code must be only numbers';
142
142
  }
143
+ cardholder_name = cardholder_name === null || cardholder_name === void 0 ? void 0 : cardholder_name.trim();
144
+ if (requireCardholderName && !cardholder_name) {
145
+ errors.cardholder_name = 'Cardholder name is required';
146
+ }
143
147
  if (!isEmpty(errors)) {
144
148
  return { card, cardType, errors };
145
149
  }
146
- card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip });
150
+ card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip, cardholder_name });
147
151
  return { card, cardType, errors: null };
148
152
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/utils",
3
- "version": "0.4.91",
3
+ "version": "0.4.93",
4
4
  "description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -36,7 +36,7 @@
36
36
  "private": false,
37
37
  "devDependencies": {
38
38
  "@emotion/react": "^11.10.4",
39
- "@open-tender/types": "^0.4.128",
39
+ "@open-tender/types": "^0.4.130",
40
40
  "@reduxjs/toolkit": "^1.8.5",
41
41
  "@types/google.maps": "^3.53.5",
42
42
  "@types/jest": "^29.5.11",
@@ -58,7 +58,7 @@
58
58
  "typescript": "^4.8.2"
59
59
  },
60
60
  "peerDependencies": {
61
- "@open-tender/types": "^0.4.128",
61
+ "@open-tender/types": "^0.4.130",
62
62
  "@reduxjs/toolkit": "^1.8.5",
63
63
  "react": "^18.2.0"
64
64
  },