@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.
Files changed (47) hide show
  1. package/dist/cjs/hooks/useCreditCard.d.ts +3 -3
  2. package/dist/cjs/hooks/useCreditCard.js +10 -15
  3. package/dist/cjs/hooks/useDonationForm.d.ts +13 -14
  4. package/dist/cjs/hooks/useDonationForm.js +17 -17
  5. package/dist/cjs/hooks/useGiftCardForm.d.ts +1 -1
  6. package/dist/cjs/hooks/useGiftCardsForm.d.ts +12 -22
  7. package/dist/cjs/hooks/useGiftCardsForm.js +17 -15
  8. package/dist/cjs/utils/cards.d.ts +2 -2
  9. package/dist/cjs/utils/cards.js +2 -2
  10. package/dist/cjs/utils/cart.d.ts +32 -24
  11. package/dist/cjs/utils/cart.js +30 -87
  12. package/dist/cjs/utils/checkout.d.ts +38 -19
  13. package/dist/cjs/utils/checkout.js +13 -2
  14. package/dist/cjs/utils/datetimes.d.ts +10 -109
  15. package/dist/cjs/utils/datetimes.js +15 -149
  16. package/dist/cjs/utils/index.d.ts +0 -1
  17. package/dist/cjs/utils/index.js +1 -1
  18. package/dist/cjs/utils/maps.d.ts +10 -10
  19. package/dist/cjs/utils/maps.js +4 -5
  20. package/dist/cjs/utils/orders.d.ts +1 -20
  21. package/dist/cjs/utils/orders.js +83 -72
  22. package/dist/cjs/utils/revenueCenters.d.ts +2 -2
  23. package/dist/cjs/utils/revenueCenters.js +1 -1
  24. package/dist/esm/hooks/useCreditCard.d.ts +3 -3
  25. package/dist/esm/hooks/useCreditCard.js +10 -15
  26. package/dist/esm/hooks/useDonationForm.d.ts +13 -14
  27. package/dist/esm/hooks/useDonationForm.js +17 -17
  28. package/dist/esm/hooks/useGiftCardForm.d.ts +1 -1
  29. package/dist/esm/hooks/useGiftCardsForm.d.ts +12 -22
  30. package/dist/esm/hooks/useGiftCardsForm.js +17 -15
  31. package/dist/esm/utils/cards.d.ts +2 -2
  32. package/dist/esm/utils/cards.js +2 -2
  33. package/dist/esm/utils/cart.d.ts +32 -24
  34. package/dist/esm/utils/cart.js +29 -85
  35. package/dist/esm/utils/checkout.d.ts +38 -19
  36. package/dist/esm/utils/checkout.js +11 -1
  37. package/dist/esm/utils/datetimes.d.ts +10 -109
  38. package/dist/esm/utils/datetimes.js +14 -142
  39. package/dist/esm/utils/index.d.ts +0 -1
  40. package/dist/esm/utils/index.js +1 -1
  41. package/dist/esm/utils/maps.d.ts +10 -10
  42. package/dist/esm/utils/maps.js +4 -5
  43. package/dist/esm/utils/orders.d.ts +1 -20
  44. package/dist/esm/utils/orders.js +82 -68
  45. package/dist/esm/utils/revenueCenters.d.ts +2 -2
  46. package/dist/esm/utils/revenueCenters.js +1 -1
  47. package/package.json +1 -1
@@ -1,12 +1,9 @@
1
- import { Dispatch } from 'react';
2
- import { CardType, CreditCard, CreditCardData, CreditCards, Profile, PurchaseDonationRequest, RequestStatus } from '@open-tender/types';
3
- interface CreditCardOption {
4
- label: string;
5
- value: unknown;
6
- name?: string;
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: CreditCard;
23
- creditCardOptions: CreditCardOption[];
19
+ creditCard: CreditCardSaved | null;
20
+ creditCardOptions: {
21
+ name: string;
22
+ value: unknown;
23
+ }[];
24
24
  handleCreditCard: (value: string) => void;
25
- handleSubmit: (evt?: any) => void;
25
+ handleSubmit: () => void;
26
26
  handleReset: () => void;
27
- setErrors: Dispatch<any>;
27
+ setErrors: import("react").Dispatch<any>;
28
28
  };
29
- export {};
@@ -1,13 +1,13 @@
1
1
  import { useMemo, useEffect, useRef, useState } from 'react';
2
2
  import { 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) => {
4
4
  const submitRef = useRef(null);
5
5
  const inputRef = useRef(null);
6
6
  const recaptchaRef = useRef(null);
7
7
  const [amount, setAmount] = useState('');
8
8
  const [email, setEmail] = useState('');
9
9
  const [isNewCard, setIsNewCard] = useState(true);
10
- const [creditCard, setCreditCard] = useState({});
10
+ const [creditCard, setCreditCard] = useState(null);
11
11
  const [creditCardOptions, setCreditCardOptions] = useState([]);
12
12
  const [errors, setErrors] = useState({});
13
13
  const [submitting, setSubmitting] = useState(false);
@@ -29,30 +29,30 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
29
29
  recaptchaRef.current.reset();
30
30
  setErrors(error);
31
31
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
32
- windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
32
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
33
33
  }
34
34
  else if (success) {
35
- windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
35
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
36
36
  }
37
37
  }
38
- }, [windowref, loading, error, setAlert, success]);
38
+ }, [windowRef, loading, error, setAlert, success]);
39
39
  useEffect(() => {
40
40
  if ((creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) && loading !== 'pending') {
41
41
  const options = creditCards.map(i => ({
42
- label: `${i.card_type_name} ending in ${i.last4}`,
42
+ name: `${i.card_type_name} ending in ${i.last4}`,
43
43
  value: i.customer_card_id
44
44
  }));
45
45
  setCreditCardOptions(options);
46
46
  const defaultCard = creditCards.length
47
47
  ? { customer_card_id: creditCards[0].customer_card_id }
48
- : {};
48
+ : null;
49
49
  setCreditCard(defaultCard);
50
50
  setIsNewCard(false);
51
51
  }
52
52
  }, [creditCards, loading]);
53
53
  useEffect(() => {
54
- setEmail((customer === null || customer === void 0 ? void 0 : customer.email) ? customer.email : '');
55
- }, [customer]);
54
+ setEmail((customer === null || customer === void 0 ? void 0 : customer.email) || '');
55
+ }, [customer === null || customer === void 0 ? void 0 : customer.email]);
56
56
  const handleAmount = (value) => {
57
57
  const cleanValue = makeNumeric(value);
58
58
  setAmount(cleanValue);
@@ -75,7 +75,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
75
75
  if (!token) {
76
76
  setSubmitting(false);
77
77
  setErrors({ form: 'Please complete the recaptcha before submitting' });
78
- windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
78
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
79
79
  }
80
80
  else {
81
81
  setSubmitting(true);
@@ -91,7 +91,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
91
91
  catch (err) {
92
92
  setSubmitting(false);
93
93
  setErrors({ form: 'Please complete the recaptcha before submitting' });
94
- windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
94
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
95
95
  }
96
96
  }
97
97
  else {
@@ -105,13 +105,12 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
105
105
  });
106
106
  }
107
107
  };
108
- const handleSubmit = (evt) => {
108
+ const handleSubmit = () => {
109
109
  var _a, _b, _c;
110
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
111
110
  if (!amount || !email) {
112
111
  setErrors({ form: 'Both amount and email are required' });
113
112
  ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus) && inputRef.current.focus();
114
- windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
113
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
115
114
  }
116
115
  else {
117
116
  if (isNewCard) {
@@ -120,7 +119,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
120
119
  if (errs) {
121
120
  setErrors(Object.assign(Object.assign({}, errs), { form: 'There are one or more credit card errors below' }));
122
121
  setSubmitting(false);
123
- windowref === null || windowref === void 0 ? void 0 : windowref.scrollTo(0, 0);
122
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
124
123
  }
125
124
  else {
126
125
  purchaseWithCaptcha(card);
@@ -128,7 +127,8 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
128
127
  }
129
128
  }
130
129
  else {
131
- purchaseWithCaptcha(creditCard);
130
+ if (creditCard)
131
+ purchaseWithCaptcha(creditCard);
132
132
  }
133
133
  ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
134
134
  }
@@ -140,7 +140,7 @@ export const useDonationsForm = (purchase, reset, setAlert, loading, error, succ
140
140
  setEmail(null);
141
141
  if (!customer)
142
142
  setIsNewCard(true);
143
- setCreditCard({});
143
+ setCreditCard(null);
144
144
  setCreditCardOptions([]);
145
145
  reset();
146
146
  };
@@ -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 | undefined;
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, CreditCard, CreditCardData, CreditCards, Customer, PurchaseGiftCardData, RequestStatus } from '@open-tender/types';
3
- interface CreditCardOption {
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?: any;
18
- }) => void, customer: Partial<Customer> | undefined, creditCards: CreditCards | undefined, recaptchaKey: string | null | undefined, initState: PurchaseGiftCardData, cardData: CreditCardData, cardType: CardType, windowRef?: Window) => {
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: CreditCardOption[];
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: (evt?: any) => void;
20
+ handleSubmit: () => void;
30
21
  handleReset: () => void;
31
22
  name: string | null;
32
23
  email: string | null;
33
- cards: PurchaseGiftCardData[];
24
+ cards: GiftCardPurchaseData[];
34
25
  isNewCard: boolean;
35
26
  newCardErrors: {};
36
- creditCard: CreditCard & Partial<CreditCardData>;
37
- setCreditCard: import("react").Dispatch<import("react").SetStateAction<CreditCard & Partial<CreditCardData>>>;
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 {};
@@ -1,6 +1,6 @@
1
1
  import { useMemo, useRef, useState, useEffect } from 'react';
2
2
  import { validateCreditCard } from '../utils';
3
- export const useGiftCardsForm = (purchase, reset, loading, error, success, setAlert, customer = {}, creditCards = [], recaptchaKey = null, initState, cardData, cardType, windowRef) => {
3
+ export const useGiftCardsForm = (purchase, reset, setAlert, loading, error, success, initState, customer, creditCards, recaptchaKey, cardData, cardType, windowRef) => {
4
4
  var _a, _b;
5
5
  const submitRef = useRef(null);
6
6
  const inputRef = useRef(null);
@@ -9,7 +9,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
9
9
  const [email, setEmail] = useState(null);
10
10
  const [cards, setCards] = useState([initState]);
11
11
  const [isNewCard, setIsNewCard] = useState(true);
12
- const [creditCard, setCreditCard] = useState({});
12
+ const [creditCard, setCreditCard] = useState(null);
13
13
  const [creditCardOptions, setCreditCardOptions] = useState([]);
14
14
  const [errors, setErrors] = useState({});
15
15
  const [submitting, setSubmitting] = useState(false);
@@ -35,7 +35,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
35
35
  }
36
36
  }, [windowRef, loading, error, setAlert, success]);
37
37
  useEffect(() => {
38
- if (creditCards.length) {
38
+ if (creditCards === null || creditCards === void 0 ? void 0 : creditCards.length) {
39
39
  const options = creditCards.map(i => ({
40
40
  name: `${i.card_type_name} ending in ${i.last4}`,
41
41
  value: i.customer_card_id
@@ -43,7 +43,7 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
43
43
  setCreditCardOptions(options);
44
44
  const defaultCard = creditCards.length
45
45
  ? { customer_card_id: creditCards[0].customer_card_id }
46
- : {};
46
+ : null;
47
47
  setCreditCard(defaultCard);
48
48
  setIsNewCard(false);
49
49
  }
@@ -140,9 +140,8 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
140
140
  });
141
141
  }
142
142
  };
143
- const handleSubmit = (evt) => {
143
+ const handleSubmit = () => {
144
144
  var _a, _b, _c;
145
- evt === null || evt === void 0 ? void 0 : evt.preventDefault();
146
145
  if (!name || !email) {
147
146
  setErrors({ form: 'Both name and email are required' });
148
147
  if (inputRef.current)
@@ -151,18 +150,21 @@ export const useGiftCardsForm = (purchase, reset, loading, error, success, setAl
151
150
  }
152
151
  else {
153
152
  if (isNewCard) {
154
- const { card, errors } = validateCreditCard(cardData, cardType);
155
- if (errors) {
156
- setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
157
- setSubmitting(false);
158
- windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
159
- }
160
- else {
161
- purchaseWithCaptcha(card);
153
+ if (cardData && cardType) {
154
+ const { card, errors } = validateCreditCard(cardData, cardType);
155
+ if (errors) {
156
+ setErrors(Object.assign(Object.assign({}, errors), { form: 'There are one or more credit card errors below' }));
157
+ setSubmitting(false);
158
+ windowRef === null || windowRef === void 0 ? void 0 : windowRef.scrollTo(0, 0);
159
+ }
160
+ else {
161
+ purchaseWithCaptcha(card);
162
+ }
162
163
  }
163
164
  }
164
165
  else {
165
- purchaseWithCaptcha(creditCard);
166
+ if (creditCard)
167
+ purchaseWithCaptcha(creditCard);
166
168
  }
167
169
  ((_b = submitRef.current) === null || _b === void 0 ? void 0 : _b.blur) && ((_c = submitRef.current) === null || _c === void 0 ? void 0 : _c.blur());
168
170
  }
@@ -1,4 +1,4 @@
1
- import { CardType, CreditCardData, ValidatedCreditCard } from '@open-tender/types';
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) => ValidatedCreditCard;
20
+ export declare const validateCreditCard: (card: CreditCardData, cardType: CardType) => CreditCardValidate;
@@ -137,8 +137,8 @@ export const validateCreditCard = (card, cardType) => {
137
137
  errors.zip = 'Zip code must be only numbers';
138
138
  }
139
139
  if (!isEmpty(errors)) {
140
- return { card, errors };
140
+ return { card, cardType, errors };
141
141
  }
142
142
  card = Object.assign(Object.assign({}, card), { acct, exp, cvv, zip });
143
- return { card, errors: null };
143
+ return { card, cardType, errors: null };
144
144
  };
@@ -1,4 +1,4 @@
1
- import { UnpreparedOrderData, Money, Order, Tender, CheckoutConfig, OrderCart, SoldOut, MenuCategories, Address, MenuItem, CartItem, OrderItem, Cart, Favorites, Orders, CartItemGroups, Customer, CartItemOption, CartOwner, SimpleCartItem, MenuItems, SimpleCart, SimpleCartGroups, OrderItemGroups, NutritionalInfoCalcs, OrderItemImages, DisplayItems, DisplayItem, GroupOrderGuests, GroupOrderGuest, CartLevels, NutritionalInfo } from '@open-tender/types';
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: Partial<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: Partial<Customer>;
60
- address: Partial<Address>;
61
- surcharges: {
62
- id?: number | undefined;
63
- }[] | undefined;
64
- discounts: {
65
- id: number;
66
- ext_id?: string | null | undefined;
67
- }[] | undefined;
68
- promoCodes: string[] | undefined;
69
- tenders: import("@open-tender/types").OrderTender[] | undefined;
70
- tip: number | `${number}.${number}`;
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: OrderItemImages) => any;
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: UnpreparedOrderData) => Partial<Order>;
182
- export declare const checkAmountRemaining: (total: Money, tenders: Array<Tender>) => number;
189
+ export declare const prepareOrder: (data: OrderData) => OrderCreate;
190
+ export declare const checkAmountRemaining: (total: Money, tenders: CheckoutTenders) => number;
@@ -1,3 +1,4 @@
1
+ import { isCreditTender, isHouseAccountTender, isOrderCustomer } from '@open-tender/types';
1
2
  import { convertStringToArray } from './helpers';
2
3
  // TODO: refactor for nested mods
3
4
  export const getItemOptions = (item) => {
@@ -139,6 +140,7 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
139
140
  return [];
140
141
  const groups = optionGroups.map(g => {
141
142
  const options = g.option_items.map(o => {
143
+ var _a;
142
144
  const isSoldOut = checkSoldOut(o.id, o.suspend_until, soldOut);
143
145
  const quantity = isSoldOut
144
146
  ? 0
@@ -146,7 +148,7 @@ const makeOrderItemGroups = (optionGroups, isEdit, soldOut = []) => {
146
148
  ? o.min_quantity || 1
147
149
  : 0;
148
150
  const cals = o.nutritional_info
149
- ? parseInt(o.nutritional_info.calories.toString())
151
+ ? parseInt((_a = o.nutritional_info.calories) === null || _a === void 0 ? void 0 : _a.toString())
150
152
  : null;
151
153
  const groups = makeOrderItemGroups(o.option_groups, isEdit, soldOut);
152
154
  const option = {
@@ -306,17 +308,14 @@ const rehydrateDetails = (details) => {
306
308
  };
307
309
  // TODO: maybe refactor
308
310
  const rehydrateCustomer = (customer) => {
309
- const newCustomer = {
310
- first_name: customer === null || customer === void 0 ? void 0 : customer.first_name,
311
- last_name: customer === null || customer === void 0 ? void 0 : customer.last_name,
312
- email: customer === null || customer === void 0 ? void 0 : customer.email,
313
- phone: customer === null || customer === void 0 ? void 0 : customer.phone,
314
- company: customer === null || customer === void 0 ? void 0 : customer.company
311
+ return {
312
+ customer_id: customer.customer_id,
313
+ first_name: customer.first_name,
314
+ last_name: customer.last_name,
315
+ email: customer.email,
316
+ phone: customer.phone,
317
+ company: customer.company || ''
315
318
  };
316
- if (customer === null || customer === void 0 ? void 0 : customer.customer_id) {
317
- newCustomer.customer_id = customer.customer_id;
318
- }
319
- return newCustomer;
320
319
  };
321
320
  // TODO: maybe refactor
322
321
  const rehydrateAddress = (address) => {
@@ -329,26 +328,21 @@ const rehydrateAddress = (address) => {
329
328
  phone: address.phone
330
329
  };
331
330
  };
332
- // TODO: maybe refactor
333
331
  const rehydrateSurcharges = (surcharges) => {
334
- return surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.surcharge_id }));
332
+ return (surcharges === null || surcharges === void 0 ? void 0 : surcharges.filter(i => i.is_optional).map(i => ({ id: i.id }))) || [];
335
333
  };
336
- // TODO: maybe refactor
337
334
  const rehydrateDiscounts = (discounts) => {
338
- return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.discount_id || i.id, ext_id: i.ext_id }));
335
+ return ((discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => !i.is_promo_code).map(i => ({ id: i.id, ext_id: i.ext_id }))) || []);
339
336
  };
340
- // TODO: maybe refactor
341
337
  const rehydratePromoCodes = (discounts) => {
342
- return discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name);
338
+ return (discounts === null || discounts === void 0 ? void 0 : discounts.filter(i => i.is_promo_code).map(i => i.name)) || [];
343
339
  };
344
- // TODO: maybe refactor
345
340
  const rehydrateTenders = (tenders) => {
346
- // const giftCards = tenders.filter((i) => i.tender_type === 'GIFT_CARD')
347
341
  const other = tenders === null || tenders === void 0 ? void 0 : tenders.map(i => {
348
- if (i.tender_type === 'CREDIT') {
342
+ if (isCreditTender(i)) {
349
343
  return Object.assign(Object.assign({}, i), i.credit_card);
350
344
  }
351
- else if (i.tender_type === 'HOUSE_ACCOUNT') {
345
+ else if (isHouseAccountTender(i)) {
352
346
  return Object.assign(Object.assign({}, i), i.house_account);
353
347
  }
354
348
  else {
@@ -357,18 +351,18 @@ const rehydrateTenders = (tenders) => {
357
351
  });
358
352
  return other;
359
353
  };
360
- // TODO: maybe refactor
361
354
  export const rehydrateCheckoutForm = (order) => {
362
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
363
355
  const form = {
364
- details: rehydrateDetails((_a = order.details) !== null && _a !== void 0 ? _a : null),
365
- customer: rehydrateCustomer((_b = order.customer) !== null && _b !== void 0 ? _b : null),
366
- address: rehydrateAddress((_c = order.address) !== null && _c !== void 0 ? _c : null),
367
- surcharges: rehydrateSurcharges((_d = order.surcharges) !== null && _d !== void 0 ? _d : null),
368
- discounts: rehydrateDiscounts((_e = order.discounts) !== null && _e !== void 0 ? _e : null),
369
- promoCodes: rehydratePromoCodes((_f = order.discounts) !== null && _f !== void 0 ? _f : null),
370
- tenders: rehydrateTenders((_g = order.tenders) !== null && _g !== void 0 ? _g : null),
371
- tip: (_j = (_h = order.totals) === null || _h === void 0 ? void 0 : _h.tip) !== null && _j !== void 0 ? _j : 0
356
+ details: rehydrateDetails(order.details),
357
+ customer: isOrderCustomer(order.customer)
358
+ ? rehydrateCustomer(order.customer)
359
+ : {},
360
+ address: rehydrateAddress(order.address),
361
+ surcharges: rehydrateSurcharges(order.surcharges),
362
+ discounts: rehydrateDiscounts(order.discounts),
363
+ promoCodes: rehydratePromoCodes(order.discounts),
364
+ tenders: rehydrateTenders(order.tenders),
365
+ tip: order.totals.tip
372
366
  };
373
367
  return form;
374
368
  };
@@ -571,54 +565,6 @@ export const makeSimpleCart = (cart) => {
571
565
  });
572
566
  return simpleCart;
573
567
  };
574
- // const makeSimpleGroups = (groups: CartItemGroups): SimpleCartGroups => {
575
- // return groups.map(g => {
576
- // const options = g.options
577
- // .filter(o => o.quantity !== 0)
578
- // .map(o => ({
579
- // id: o.id,
580
- // quantity: o.quantity,
581
- // groups: makeSimpleGroups(o.groups || [])
582
- // }))
583
- // return { id: g.id, options: options }
584
- // })
585
- // }
586
- // export const makeSimpleCart = (cart: Cart) => {
587
- // const simpleCart = cart.map(i => {
588
- // return {
589
- // id: i.id,
590
- // quantity: i.quantity,
591
- // groups: makeSimpleGroups(i.groups),
592
- // made_for: i.madeFor || '',
593
- // notes: i.notes || ''
594
- // }
595
- // })
596
- // return simpleCart
597
- // }
598
- const makeSimpleGroupsFromOrder = (groups) => {
599
- return groups.map(g => {
600
- const options = g.options
601
- .filter(o => o.quantity !== 0)
602
- .map(o => ({
603
- id: o.id,
604
- quantity: o.quantity,
605
- groups: makeSimpleGroupsFromOrder(o.groups || [])
606
- }));
607
- return { id: g.id, options: options };
608
- });
609
- };
610
- export const makeSimpleCartFromOrder = (cart) => {
611
- const simpleCart = cart.map(i => {
612
- return {
613
- id: i.id,
614
- quantity: i.quantity,
615
- groups: makeSimpleGroupsFromOrder(i.groups),
616
- made_for: i.made_for || '',
617
- notes: i.notes || ''
618
- };
619
- });
620
- return simpleCart;
621
- };
622
568
  /* cart validation */
623
569
  // TODO: refactor for nested modifiers
624
570
  // convert menu items to order items for validation but only include
@@ -771,13 +717,11 @@ export const getDefaultTip = (config) => {
771
717
  return config.gratuity.default ? config.gratuity.default.amount : null;
772
718
  };
773
719
  export const prepareOrder = (data) => {
774
- data = data || {};
775
- const requestedIso = !data.requestedAt ? 'asap' : data.requestedAt;
776
720
  const order = {
777
- revenue_center_id: data.revenueCenterId || null,
778
- service_type: data.serviceType || 'PICKUP',
779
- requested_at: requestedIso,
780
- cart: data.cart ? makeSimpleCart(data.cart) : []
721
+ revenue_center_id: data.revenueCenterId,
722
+ service_type: data.serviceType,
723
+ requested_at: data.requestedAt,
724
+ cart: makeSimpleCart(data.cart)
781
725
  };
782
726
  if (data.customer)
783
727
  order.customer = data.customer;