@open-tender/utils 0.1.9 → 0.1.11
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/dist/cjs/hooks/useCreditCard.d.ts +3 -3
- package/dist/cjs/hooks/useCreditCard.js +10 -15
- package/dist/cjs/hooks/useDonationForm.d.ts +13 -14
- package/dist/cjs/hooks/useDonationForm.js +17 -17
- package/dist/cjs/hooks/useGiftCardForm.d.ts +1 -1
- package/dist/cjs/hooks/useGiftCardsForm.d.ts +12 -22
- package/dist/cjs/hooks/useGiftCardsForm.js +17 -15
- package/dist/cjs/utils/cards.d.ts +2 -2
- package/dist/cjs/utils/cards.js +2 -2
- package/dist/cjs/utils/cart.d.ts +32 -24
- package/dist/cjs/utils/cart.js +30 -87
- package/dist/cjs/utils/checkout.d.ts +38 -19
- package/dist/cjs/utils/checkout.js +13 -2
- package/dist/cjs/utils/datetimes.d.ts +10 -109
- package/dist/cjs/utils/datetimes.js +15 -149
- package/dist/cjs/utils/index.d.ts +0 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/maps.d.ts +10 -10
- package/dist/cjs/utils/maps.js +4 -5
- package/dist/cjs/utils/orders.d.ts +1 -20
- package/dist/cjs/utils/orders.js +83 -72
- package/dist/cjs/utils/revenueCenters.d.ts +2 -2
- package/dist/cjs/utils/revenueCenters.js +1 -1
- package/dist/esm/hooks/useCreditCard.d.ts +3 -3
- package/dist/esm/hooks/useCreditCard.js +10 -15
- package/dist/esm/hooks/useDonationForm.d.ts +13 -14
- package/dist/esm/hooks/useDonationForm.js +17 -17
- package/dist/esm/hooks/useGiftCardForm.d.ts +1 -1
- package/dist/esm/hooks/useGiftCardsForm.d.ts +12 -22
- package/dist/esm/hooks/useGiftCardsForm.js +17 -15
- package/dist/esm/utils/cards.d.ts +2 -2
- package/dist/esm/utils/cards.js +2 -2
- package/dist/esm/utils/cart.d.ts +32 -24
- package/dist/esm/utils/cart.js +29 -85
- package/dist/esm/utils/checkout.d.ts +38 -19
- package/dist/esm/utils/checkout.js +11 -1
- package/dist/esm/utils/datetimes.d.ts +10 -109
- package/dist/esm/utils/datetimes.js +14 -142
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/maps.d.ts +10 -10
- package/dist/esm/utils/maps.js +4 -5
- package/dist/esm/utils/orders.d.ts +1 -20
- package/dist/esm/utils/orders.js +82 -68
- package/dist/esm/utils/revenueCenters.d.ts +2 -2
- package/dist/esm/utils/revenueCenters.js +1 -1
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CreditCardData } from '@open-tender/types';
|
|
3
|
-
export declare const useCreditCard: (initState:
|
|
3
|
+
export declare const useCreditCard: (initState: CreditCardData, cardErrors?: {}, disabled?: boolean) => {
|
|
4
4
|
submitRef: import("react").MutableRefObject<null>;
|
|
5
5
|
data: CreditCardData;
|
|
6
6
|
cardType: "VISA" | "MC" | "DISC" | "AMEX" | "OTHER";
|
|
7
7
|
errors: {};
|
|
8
8
|
disabled: boolean;
|
|
9
9
|
setErrors: import("react").Dispatch<import("react").SetStateAction<{}>>;
|
|
10
|
-
handleChange: (
|
|
11
|
-
handleBlur: (
|
|
10
|
+
handleChange: (name: keyof CreditCardData, value: string) => void;
|
|
11
|
+
handleBlur: (name: keyof CreditCardData) => void;
|
|
12
12
|
isComplete: boolean;
|
|
13
13
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCreditCard = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const __1 = require("
|
|
5
|
+
const __1 = require("..");
|
|
6
6
|
const defaultState = {
|
|
7
7
|
acct: '',
|
|
8
8
|
exp: '',
|
|
@@ -18,29 +18,24 @@ const useCreditCard = (initState, cardErrors = {}, disabled = false) => {
|
|
|
18
18
|
const [errors, setErrors] = (0, react_1.useState)(cardErrors);
|
|
19
19
|
const { acct, exp, cvv, zip } = data;
|
|
20
20
|
const isComplete = acct && exp && cvv && zip && !(0, __1.isEmpty)(errors) ? true : false;
|
|
21
|
-
const handleChange = (
|
|
22
|
-
|
|
23
|
-
if (id === 'acct') {
|
|
21
|
+
const handleChange = (name, value) => {
|
|
22
|
+
if (name === 'acct') {
|
|
24
23
|
const currentType = (0, __1.getCardType)(value.replace(/\s/g, ''));
|
|
25
24
|
setCardType(currentType);
|
|
26
25
|
}
|
|
27
|
-
if (
|
|
28
|
-
value =
|
|
26
|
+
if (name !== 'is_default') {
|
|
27
|
+
value = (0, __1.formatCardField)(name, value);
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
value = (0, __1.formatCardField)(id, value);
|
|
32
|
-
}
|
|
33
|
-
setData(Object.assign(Object.assign({}, data), { [id]: value }));
|
|
29
|
+
setData(Object.assign(Object.assign({}, data), { [name]: value }));
|
|
34
30
|
};
|
|
35
|
-
const handleBlur = (
|
|
36
|
-
let { id } = evt.target;
|
|
31
|
+
const handleBlur = (name) => {
|
|
37
32
|
const { errors: validationErrors } = (0, __1.validateCreditCard)(data, cardType);
|
|
38
33
|
if (validationErrors) {
|
|
39
|
-
const error = validationErrors[
|
|
40
|
-
setErrors(Object.assign(Object.assign({}, errors), { [
|
|
34
|
+
const error = validationErrors[name];
|
|
35
|
+
setErrors(Object.assign(Object.assign({}, errors), { [name]: error }));
|
|
41
36
|
}
|
|
42
37
|
else {
|
|
43
|
-
setErrors(Object.assign(Object.assign({}, errors), { [
|
|
38
|
+
setErrors(Object.assign(Object.assign({}, errors), { [name]: null }));
|
|
44
39
|
}
|
|
45
40
|
};
|
|
46
41
|
return {
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { CardType,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare const useDonationsForm: (purchase: (data: PurchaseDonationRequest, callback?: () => void) => void, reset: () => void, setAlert: Dispatch<any>, loading: RequestStatus, error: any, success: boolean, customer?: Partial<Profile>, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowref?: Window) => {
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, DonationPurchase, RequestError, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useDonationsForm: (purchase: (data: DonationPurchase, callback?: () => void) => void, reset: () => void, setAlert: (data: {
|
|
4
|
+
type: string;
|
|
5
|
+
args?: unknown;
|
|
6
|
+
}) => void, loading: RequestStatus, error: RequestError, success: boolean, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
10
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
11
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
12
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
@@ -19,11 +16,13 @@ export declare const useDonationsForm: (purchase: (data: PurchaseDonationRequest
|
|
|
19
16
|
newCardErrors: {};
|
|
20
17
|
submitting: boolean;
|
|
21
18
|
isNewCard: boolean;
|
|
22
|
-
creditCard:
|
|
23
|
-
creditCardOptions:
|
|
19
|
+
creditCard: CreditCardSaved | null;
|
|
20
|
+
creditCardOptions: {
|
|
21
|
+
name: string;
|
|
22
|
+
value: unknown;
|
|
23
|
+
}[];
|
|
24
24
|
handleCreditCard: (value: string) => void;
|
|
25
|
-
handleSubmit: (
|
|
25
|
+
handleSubmit: () => void;
|
|
26
26
|
handleReset: () => void;
|
|
27
|
-
setErrors: Dispatch<any>;
|
|
27
|
+
setErrors: import("react").Dispatch<any>;
|
|
28
28
|
};
|
|
29
|
-
export {};
|
|
@@ -3,14 +3,14 @@ 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,
|
|
6
|
+
const useDonationsForm = (purchase, reset, setAlert, loading, error, success, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
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);
|
|
10
10
|
const [amount, setAmount] = (0, react_1.useState)('');
|
|
11
11
|
const [email, setEmail] = (0, react_1.useState)('');
|
|
12
12
|
const [isNewCard, setIsNewCard] = (0, react_1.useState)(true);
|
|
13
|
-
const [creditCard, setCreditCard] = (0, react_1.useState)(
|
|
13
|
+
const [creditCard, setCreditCard] = (0, react_1.useState)(null);
|
|
14
14
|
const [creditCardOptions, setCreditCardOptions] = (0, react_1.useState)([]);
|
|
15
15
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
16
16
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
@@ -32,30 +32,30 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
32
32
|
recaptchaRef.current.reset();
|
|
33
33
|
setErrors(error);
|
|
34
34
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
|
|
35
|
-
|
|
35
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
36
36
|
}
|
|
37
37
|
else if (success) {
|
|
38
|
-
|
|
38
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
}, [
|
|
41
|
+
}, [windowRef, loading, error, setAlert, success]);
|
|
42
42
|
(0, react_1.useEffect)(() => {
|
|
43
43
|
if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
|
|
44
44
|
const options = creditCards.map(i => ({
|
|
45
|
-
|
|
45
|
+
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
46
46
|
value: i.customer_card_id
|
|
47
47
|
}));
|
|
48
48
|
setCreditCardOptions(options);
|
|
49
49
|
const defaultCard = creditCards.length
|
|
50
50
|
? { customer_card_id: creditCards[0].customer_card_id }
|
|
51
|
-
:
|
|
51
|
+
: null;
|
|
52
52
|
setCreditCard(defaultCard);
|
|
53
53
|
setIsNewCard(false);
|
|
54
54
|
}
|
|
55
55
|
}, [creditCards, loading]);
|
|
56
56
|
(0, react_1.useEffect)(() => {
|
|
57
|
-
setEmail((customer === null || customer === void 0 ? void 0 : customer.email)
|
|
58
|
-
}, [customer]);
|
|
57
|
+
setEmail((customer === null || customer === void 0 ? void 0 : customer.email) || '');
|
|
58
|
+
}, [customer === null || customer === void 0 ? void 0 : customer.email]);
|
|
59
59
|
const handleAmount = (value) => {
|
|
60
60
|
const cleanValue = (0, utils_1.makeNumeric)(value);
|
|
61
61
|
setAmount(cleanValue);
|
|
@@ -78,7 +78,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
78
78
|
if (!token) {
|
|
79
79
|
setSubmitting(false);
|
|
80
80
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
81
|
-
|
|
81
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
84
|
setSubmitting(true);
|
|
@@ -94,7 +94,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
94
94
|
catch (err) {
|
|
95
95
|
setSubmitting(false);
|
|
96
96
|
setErrors({ form: 'Please complete the recaptcha before submitting' });
|
|
97
|
-
|
|
97
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
@@ -108,13 +108,12 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
110
|
};
|
|
111
|
-
const handleSubmit = (
|
|
111
|
+
const handleSubmit = () => {
|
|
112
112
|
var _a, _b, _c;
|
|
113
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
114
113
|
if (!amount || !email) {
|
|
115
114
|
setErrors({ form: 'Both amount and email are required' });
|
|
116
115
|
((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && inputRef.current.focus();
|
|
117
|
-
|
|
116
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
118
117
|
}
|
|
119
118
|
else {
|
|
120
119
|
if (isNewCard) {
|
|
@@ -123,7 +122,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
123
122
|
if (errs) {
|
|
124
123
|
setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
|
|
125
124
|
setSubmitting(false);
|
|
126
|
-
|
|
125
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
127
126
|
}
|
|
128
127
|
else {
|
|
129
128
|
purchaseWithCaptcha(card);
|
|
@@ -131,7 +130,8 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
else {
|
|
134
|
-
|
|
133
|
+
if (creditCard)
|
|
134
|
+
purchaseWithCaptcha(creditCard);
|
|
135
135
|
}
|
|
136
136
|
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
137
137
|
}
|
|
@@ -143,7 +143,7 @@ const useDonationsForm = (purchase, reset, setAlert, loading, error, success, cu
|
|
|
143
143
|
setEmail(null);
|
|
144
144
|
if (!customer)
|
|
145
145
|
setIsNewCard(true);
|
|
146
|
-
setCreditCard(
|
|
146
|
+
setCreditCard(null);
|
|
147
147
|
setCreditCardOptions([]);
|
|
148
148
|
reset();
|
|
149
149
|
};
|
|
@@ -5,7 +5,7 @@ export declare const useGiftCardForm: (giftCard: CustomerGiftCard, creditCards:
|
|
|
5
5
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
6
6
|
options: {
|
|
7
7
|
name: string;
|
|
8
|
-
value: number
|
|
8
|
+
value: number;
|
|
9
9
|
}[];
|
|
10
10
|
errors: {};
|
|
11
11
|
data: Partial<CustomerGiftCard>;
|
|
@@ -1,41 +1,31 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CardType,
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
value?: number;
|
|
6
|
-
}
|
|
7
|
-
interface PurchaseData {
|
|
8
|
-
credit_card: Partial<CreditCardData>;
|
|
9
|
-
email: string;
|
|
10
|
-
gift_cards: Array<Partial<PurchaseGiftCardData>>;
|
|
11
|
-
name: string;
|
|
12
|
-
url: string;
|
|
13
|
-
token?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare const useGiftCardsForm: (purchase: (data: PurchaseData) => void, reset: () => void, loading: RequestStatus, error: any, success: boolean, setAlert: (data: {
|
|
2
|
+
import { CardType, CreditCardData, CreditCardSaved, CreditCards, Customer, GiftCardPurchaseData, GiftCardsPurchase, RequestStatus } from '@open-tender/types';
|
|
3
|
+
export declare const useGiftCardsForm: (purchase: (data: GiftCardsPurchase) => void, reset: () => void, setAlert: (data: {
|
|
16
4
|
type: string;
|
|
17
|
-
args?:
|
|
18
|
-
}) => void,
|
|
5
|
+
args?: unknown;
|
|
6
|
+
}) => void, loading: RequestStatus, error: any, success: boolean, initState: GiftCardPurchaseData, customer?: Customer, creditCards?: CreditCards, recaptchaKey?: string, cardData?: CreditCardData, cardType?: CardType, windowRef?: Window) => {
|
|
19
7
|
inputRef: import("react").MutableRefObject<HTMLInputElement | null>;
|
|
20
8
|
submitRef: import("react").MutableRefObject<HTMLButtonElement | null>;
|
|
21
9
|
recaptchaRef: import("react").MutableRefObject<any>;
|
|
22
|
-
creditCardOptions:
|
|
10
|
+
creditCardOptions: {
|
|
11
|
+
name: string;
|
|
12
|
+
value: unknown;
|
|
13
|
+
}[];
|
|
23
14
|
handleName: (value: string) => void;
|
|
24
15
|
handleEmail: (value: string) => void;
|
|
25
16
|
handleChange: (name: string, value: string) => void;
|
|
26
17
|
handleQuantity: (index: number, quantity: number) => void;
|
|
27
18
|
handleAddAnother: () => void;
|
|
28
19
|
handleCreditCard: (value: number) => void;
|
|
29
|
-
handleSubmit: (
|
|
20
|
+
handleSubmit: () => void;
|
|
30
21
|
handleReset: () => void;
|
|
31
22
|
name: string | null;
|
|
32
23
|
email: string | null;
|
|
33
|
-
cards:
|
|
24
|
+
cards: GiftCardPurchaseData[];
|
|
34
25
|
isNewCard: boolean;
|
|
35
26
|
newCardErrors: {};
|
|
36
|
-
creditCard:
|
|
37
|
-
setCreditCard: import("react").Dispatch<import("react").SetStateAction<
|
|
27
|
+
creditCard: CreditCardSaved | null;
|
|
28
|
+
setCreditCard: import("react").Dispatch<import("react").SetStateAction<CreditCardSaved | null>>;
|
|
38
29
|
errors: {};
|
|
39
30
|
submitting: boolean;
|
|
40
31
|
};
|
|
41
|
-
export {};
|
|
@@ -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, loading, error, success,
|
|
6
|
+
const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
|
|
7
7
|
var _a, _b;
|
|
8
8
|
const submitRef = (0, react_1.useRef)(null);
|
|
9
9
|
const inputRef = (0, react_1.useRef)(null);
|
|
@@ -12,7 +12,7 @@ const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, cu
|
|
|
12
12
|
const [email, setEmail] = (0, react_1.useState)(null);
|
|
13
13
|
const [cards, setCards] = (0, react_1.useState)([initState]);
|
|
14
14
|
const [isNewCard, setIsNewCard] = (0, react_1.useState)(true);
|
|
15
|
-
const [creditCard, setCreditCard] = (0, react_1.useState)(
|
|
15
|
+
const [creditCard, setCreditCard] = (0, react_1.useState)(null);
|
|
16
16
|
const [creditCardOptions, setCreditCardOptions] = (0, react_1.useState)([]);
|
|
17
17
|
const [errors, setErrors] = (0, react_1.useState)({});
|
|
18
18
|
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
@@ -38,7 +38,7 @@ const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, cu
|
|
|
38
38
|
}
|
|
39
39
|
}, [windowRef, loading, error, setAlert, success]);
|
|
40
40
|
(0, react_1.useEffect)(() => {
|
|
41
|
-
if (creditCards.length) {
|
|
41
|
+
if (creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) {
|
|
42
42
|
const options = creditCards.map(i => ({
|
|
43
43
|
name: `${i.card_type_name} ending in ${i.last4}`,
|
|
44
44
|
value: i.customer_card_id
|
|
@@ -46,7 +46,7 @@ const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, cu
|
|
|
46
46
|
setCreditCardOptions(options);
|
|
47
47
|
const defaultCard = creditCards.length
|
|
48
48
|
? { customer_card_id: creditCards[0].customer_card_id }
|
|
49
|
-
:
|
|
49
|
+
: null;
|
|
50
50
|
setCreditCard(defaultCard);
|
|
51
51
|
setIsNewCard(false);
|
|
52
52
|
}
|
|
@@ -143,9 +143,8 @@ const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, cu
|
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
|
-
const handleSubmit = (
|
|
146
|
+
const handleSubmit = () => {
|
|
147
147
|
var _a, _b, _c;
|
|
148
|
-
evt === null || evt === void 0 ? void 0 : evt.preventDefault();
|
|
149
148
|
if (!name || !email) {
|
|
150
149
|
setErrors({ form: 'Both name and email are required' });
|
|
151
150
|
if (inputRef.current)
|
|
@@ -154,18 +153,21 @@ const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, cu
|
|
|
154
153
|
}
|
|
155
154
|
else {
|
|
156
155
|
if (isNewCard) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
if (cardData && cardType) {
|
|
157
|
+
const { card, errors } = (0, utils_1.validateCreditCard)(cardData, cardType);
|
|
158
|
+
if (errors) {
|
|
159
|
+
setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
|
|
160
|
+
setSubmitting(false);
|
|
161
|
+
windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
purchaseWithCaptcha(card);
|
|
165
|
+
}
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
else {
|
|
168
|
-
|
|
169
|
+
if (creditCard)
|
|
170
|
+
purchaseWithCaptcha(creditCard);
|
|
169
171
|
}
|
|
170
172
|
((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
|
|
171
173
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CardType, CreditCardData,
|
|
1
|
+
import { CardType, CreditCardData, CreditCardValidate } from '@open-tender/types';
|
|
2
2
|
export declare const cardNames: {
|
|
3
3
|
VISA: string;
|
|
4
4
|
MC: string;
|
|
@@ -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) => [CreditCardData | null, CardType | null];
|
|
20
|
-
export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) =>
|
|
20
|
+
export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) => CreditCardValidate;
|
package/dist/cjs/utils/cards.js
CHANGED
|
@@ -145,9 +145,9 @@ const validateCreditCard = (card, cardType) => {
|
|
|
145
145
|
errors.zip = 'Zip code must be only numbers';
|
|
146
146
|
}
|
|
147
147
|
if (!(0, helpers_1.isEmpty)(errors)) {
|
|
148
|
-
return { card, errors };
|
|
148
|
+
return { card, cardType, errors };
|
|
149
149
|
}
|
|
150
150
|
card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip });
|
|
151
|
-
return { card, errors: null };
|
|
151
|
+
return { card, cardType, errors: null };
|
|
152
152
|
};
|
|
153
153
|
exports.validateCreditCard = validateCreditCard;
|
package/dist/cjs/utils/cart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cart, CartItem, CartItemGroups, CartLevels, CartItemOption, CartOwner, CheckoutConfig, CheckoutFormAddress, CheckoutFormCustomer, CheckoutPromoCodes, CheckoutTenders, DisplayItem, DisplayItems, Favorites, GroupOrderGuest, GroupOrderGuests, MenuCategories, MenuItem, MenuItems, Money, NutritionalInfo, NutritionalInfoCalcs, Order, OrderCreate, OrderCreateDiscounts, OrderCreateSurcharges, OrderData, OrderItem, OrderItemGroups, Orders, SimpleCart, SimpleCartGroups, SimpleCartItem, SoldOut, Images } from '@open-tender/types';
|
|
2
2
|
export declare const getItemOptions: (item: Partial<CartItem>) => CartItemOption[];
|
|
3
3
|
export declare const makeModifierNames: (item: CartItem) => string;
|
|
4
4
|
export declare const hasGroupsBelowMin: (option: CartItemOption | null, groups: CartItemGroups) => boolean;
|
|
@@ -47,7 +47,7 @@ export declare const rehydrateCart: (menuItems: MenuItems, simpleCartItems: Simp
|
|
|
47
47
|
}[];
|
|
48
48
|
cartCounts: Record<string, number>;
|
|
49
49
|
};
|
|
50
|
-
export declare const rehydrateCheckoutForm: (order:
|
|
50
|
+
export declare const rehydrateCheckoutForm: (order: Order) => {
|
|
51
51
|
details: {
|
|
52
52
|
cart_id: number | null | undefined;
|
|
53
53
|
eating_utensils: boolean | undefined;
|
|
@@ -56,18 +56,33 @@ export declare const rehydrateCheckoutForm: (order: Partial<Order>) => {
|
|
|
56
56
|
serving_utensils: boolean | undefined;
|
|
57
57
|
tax_exempt_id: string | null | undefined;
|
|
58
58
|
};
|
|
59
|
-
customer:
|
|
60
|
-
address:
|
|
61
|
-
surcharges:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
customer: CheckoutFormCustomer;
|
|
60
|
+
address: CheckoutFormAddress;
|
|
61
|
+
surcharges: OrderCreateSurcharges;
|
|
62
|
+
discounts: OrderCreateDiscounts;
|
|
63
|
+
promoCodes: CheckoutPromoCodes;
|
|
64
|
+
tenders: (import("@open-tender/types").OrderTenderGiftCard | {
|
|
65
|
+
card_type: import("@open-tender/types").CardType;
|
|
66
|
+
card_type_name: import("@open-tender/types").CardTypeName;
|
|
67
|
+
customer_card_id: number;
|
|
68
|
+
has_profile?: boolean | undefined;
|
|
69
|
+
is_default?: boolean | undefined;
|
|
70
|
+
last4: string;
|
|
71
|
+
masked: string;
|
|
72
|
+
amount: `${number}.${number}`;
|
|
73
|
+
credit_card: import("@open-tender/types").CreditCard;
|
|
74
|
+
tender_type: import("@open-tender/types").TenderType;
|
|
75
|
+
} | {
|
|
76
|
+
house_account_id: number;
|
|
77
|
+
name: string;
|
|
78
|
+
amount: `${number}.${number}`;
|
|
79
|
+
house_account: {
|
|
80
|
+
house_account_id: number;
|
|
81
|
+
name: string;
|
|
82
|
+
};
|
|
83
|
+
tender_type: import("@open-tender/types").TenderType;
|
|
84
|
+
})[] | undefined;
|
|
85
|
+
tip: `${number}.${number}`;
|
|
71
86
|
};
|
|
72
87
|
export declare const makeGuestLookup: (cartGuests: GroupOrderGuests) => Record<string, GroupOrderGuest>;
|
|
73
88
|
export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner: CartOwner, cartGuests: GroupOrderGuests) => ({
|
|
@@ -113,7 +128,7 @@ export declare const combineCarts: (cart: Cart, guestCart: SimpleCart, cartOwner
|
|
|
113
128
|
cart_guest_id?: number | undefined;
|
|
114
129
|
customer_id?: number | undefined;
|
|
115
130
|
})[];
|
|
116
|
-
export declare const makeItemImageUrl: (images:
|
|
131
|
+
export declare const makeItemImageUrl: (images: Images) => any;
|
|
117
132
|
export declare const makeDisplayItemGroups: (optionGroups: OrderItemGroups) => {
|
|
118
133
|
options: DisplayItem[];
|
|
119
134
|
id: number;
|
|
@@ -163,13 +178,6 @@ export declare const makeSimpleCart: <C extends {
|
|
|
163
178
|
made_for: string;
|
|
164
179
|
notes: string;
|
|
165
180
|
}[];
|
|
166
|
-
export declare const makeSimpleCartFromOrder: (cart: OrderCart) => {
|
|
167
|
-
id: number;
|
|
168
|
-
quantity: number;
|
|
169
|
-
groups: SimpleCartGroups;
|
|
170
|
-
made_for: string;
|
|
171
|
-
notes: string;
|
|
172
|
-
}[];
|
|
173
181
|
export declare const validateCart: (cart: Cart, categories: MenuCategories, soldOut: SoldOut) => {
|
|
174
182
|
newCart: (CartItem | CartItemOption | null)[];
|
|
175
183
|
errors: {
|
|
@@ -178,5 +186,5 @@ export declare const validateCart: (cart: Cart, categories: MenuCategories, sold
|
|
|
178
186
|
} | null;
|
|
179
187
|
};
|
|
180
188
|
export declare const getDefaultTip: (config: CheckoutConfig) => string | null;
|
|
181
|
-
export declare const prepareOrder: (data:
|
|
182
|
-
export declare const checkAmountRemaining: (total: Money, tenders:
|
|
189
|
+
export declare const prepareOrder: (data: OrderData) => OrderCreate;
|
|
190
|
+
export declare const checkAmountRemaining: (total: Money, tenders: CheckoutTenders) => number;
|