@kiosinc/commons-rn 0.1.61 → 0.1.63
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/lib/commonjs/api/customer.js +75 -0
- package/lib/commonjs/api/customer.js.map +1 -0
- package/lib/commonjs/auth/hooks/useAuthentication.js +6 -0
- package/lib/commonjs/auth/hooks/useAuthentication.js.map +1 -1
- package/lib/commonjs/auth/hooks/useTermsOfService.js +8 -10
- package/lib/commonjs/auth/hooks/useTermsOfService.js.map +1 -1
- package/lib/commonjs/auth/providers/authentication/AuthenticationProvider.js +2 -1
- package/lib/commonjs/auth/providers/authentication/AuthenticationProvider.js.map +1 -1
- package/lib/commonjs/auth/providers/authentication/reducer/authentication.reducer.js +19 -1
- package/lib/commonjs/auth/providers/authentication/reducer/authentication.reducer.js.map +1 -1
- package/lib/commonjs/hooks/useCheckCustomer.js +57 -0
- package/lib/commonjs/hooks/useCheckCustomer.js.map +1 -0
- package/lib/commonjs/hooks/useCustomer.js +251 -0
- package/lib/commonjs/hooks/useCustomer.js.map +1 -0
- package/lib/commonjs/index.js +32 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/screens/SavedCards/CardRow.js +79 -0
- package/lib/commonjs/screens/SavedCards/CardRow.js.map +1 -0
- package/lib/commonjs/screens/SavedCards/SavedCards.js +180 -0
- package/lib/commonjs/screens/SavedCards/SavedCards.js.map +1 -0
- package/lib/commonjs/selectBusiness/queryKeys.js +6 -1
- package/lib/commonjs/selectBusiness/queryKeys.js.map +1 -1
- package/lib/commonjs/types/customer.d.js +7 -0
- package/lib/commonjs/types/customer.d.js.map +1 -0
- package/lib/commonjs/utils/checkout.js +11 -0
- package/lib/commonjs/utils/checkout.js.map +1 -0
- package/lib/commonjs/utils/currency.js +17 -0
- package/lib/commonjs/utils/currency.js.map +1 -0
- package/lib/commonjs/utils/square.js +39 -0
- package/lib/commonjs/utils/square.js.map +1 -0
- package/lib/module/api/customer.js +59 -0
- package/lib/module/api/customer.js.map +1 -0
- package/lib/module/auth/hooks/useAuthentication.js +6 -0
- package/lib/module/auth/hooks/useAuthentication.js.map +1 -1
- package/lib/module/auth/hooks/useTermsOfService.js +8 -10
- package/lib/module/auth/hooks/useTermsOfService.js.map +1 -1
- package/lib/module/auth/providers/authentication/AuthenticationProvider.js +2 -1
- package/lib/module/auth/providers/authentication/AuthenticationProvider.js.map +1 -1
- package/lib/module/auth/providers/authentication/reducer/authentication.reducer.js +19 -1
- package/lib/module/auth/providers/authentication/reducer/authentication.reducer.js.map +1 -1
- package/lib/module/hooks/useCheckCustomer.js +50 -0
- package/lib/module/hooks/useCheckCustomer.js.map +1 -0
- package/lib/module/hooks/useCustomer.js +243 -0
- package/lib/module/hooks/useCustomer.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/screens/SavedCards/CardRow.js +71 -0
- package/lib/module/screens/SavedCards/CardRow.js.map +1 -0
- package/lib/module/screens/SavedCards/SavedCards.js +170 -0
- package/lib/module/screens/SavedCards/SavedCards.js.map +1 -0
- package/lib/module/selectBusiness/queryKeys.js +6 -1
- package/lib/module/selectBusiness/queryKeys.js.map +1 -1
- package/lib/module/types/customer.d.js +5 -0
- package/lib/module/types/customer.d.js.map +1 -0
- package/lib/module/utils/checkout.js +4 -0
- package/lib/module/utils/checkout.js.map +1 -0
- package/lib/module/utils/currency.js +10 -0
- package/lib/module/utils/currency.js.map +1 -0
- package/lib/module/utils/square.js +36 -0
- package/lib/module/utils/square.js.map +1 -0
- package/lib/typescript/src/api/customer.d.ts +23 -0
- package/lib/typescript/src/api/customer.d.ts.map +1 -0
- package/lib/typescript/src/auth/hooks/useAuthentication.d.ts.map +1 -1
- package/lib/typescript/src/auth/hooks/useTermsOfService.d.ts.map +1 -1
- package/lib/typescript/src/auth/providers/authentication/AuthenticationProvider.d.ts.map +1 -1
- package/lib/typescript/src/auth/providers/authentication/reducer/authentication.reducer.d.ts.map +1 -1
- package/lib/typescript/src/auth/providers/authentication/types/authentication.types.d.ts +1 -0
- package/lib/typescript/src/auth/providers/authentication/types/authentication.types.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCheckCustomer.d.ts +4 -0
- package/lib/typescript/src/hooks/useCheckCustomer.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useCustomer.d.ts +58 -0
- package/lib/typescript/src/hooks/useCustomer.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/SavedCards/CardRow.d.ts +11 -0
- package/lib/typescript/src/screens/SavedCards/CardRow.d.ts.map +1 -0
- package/lib/typescript/src/screens/SavedCards/SavedCards.d.ts +7 -0
- package/lib/typescript/src/screens/SavedCards/SavedCards.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/queryKeys.d.ts +5 -0
- package/lib/typescript/src/selectBusiness/queryKeys.d.ts.map +1 -1
- package/lib/typescript/src/utils/checkout.d.ts +3 -0
- package/lib/typescript/src/utils/checkout.d.ts.map +1 -0
- package/lib/typescript/src/utils/currency.d.ts +5 -0
- package/lib/typescript/src/utils/currency.d.ts.map +1 -0
- package/lib/typescript/src/utils/square.d.ts +6 -0
- package/lib/typescript/src/utils/square.d.ts.map +1 -0
- package/package.json +3 -1
- package/src/api/customer.ts +112 -0
- package/src/auth/hooks/useAuthentication.ts +4 -0
- package/src/auth/hooks/useTermsOfService.ts +8 -11
- package/src/auth/providers/authentication/AuthenticationProvider.tsx +1 -0
- package/src/auth/providers/authentication/reducer/authentication.reducer.ts +20 -0
- package/src/auth/providers/authentication/types/authentication.types.ts +1 -0
- package/src/hooks/useCheckCustomer.ts +42 -0
- package/src/hooks/useCustomer.ts +331 -0
- package/src/index.tsx +6 -0
- package/src/screens/SavedCards/CardRow.tsx +94 -0
- package/src/screens/SavedCards/SavedCards.tsx +197 -0
- package/src/selectBusiness/queryKeys.ts +5 -0
- package/src/types/customer.d.ts +70 -0
- package/src/utils/checkout.ts +5 -0
- package/src/utils/currency.ts +10 -0
- package/src/utils/square.ts +50 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Alert,
|
|
4
|
+
Button,
|
|
5
|
+
LineLoader,
|
|
6
|
+
RefreshControl,
|
|
7
|
+
Text,
|
|
8
|
+
View,
|
|
9
|
+
} from '../../components';
|
|
10
|
+
import { ActivityIndicator, useTheme } from 'react-native-paper';
|
|
11
|
+
import uuid from 'react-native-uuid';
|
|
12
|
+
import { useTranslation } from 'react-i18next';
|
|
13
|
+
import { FlatList } from 'react-native';
|
|
14
|
+
import { onStartCardEntry } from '../../utils/square';
|
|
15
|
+
import { useCustomerQueries } from '../../hooks/useCustomer';
|
|
16
|
+
import { useCheckCustomer } from '../../hooks/useCheckCustomer';
|
|
17
|
+
import { CardRow } from './CardRow';
|
|
18
|
+
import { CustomerCardPayment } from '../../types/customer';
|
|
19
|
+
|
|
20
|
+
export const SavedCards = ({
|
|
21
|
+
onCheckout,
|
|
22
|
+
total,
|
|
23
|
+
}: {
|
|
24
|
+
onCheckout?: (selectedCard: CustomerCardPayment) => void;
|
|
25
|
+
total?: string;
|
|
26
|
+
}) => {
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
const theme = useTheme();
|
|
29
|
+
const { customer } = useCheckCustomer();
|
|
30
|
+
const {
|
|
31
|
+
useSaveCustomerCard,
|
|
32
|
+
useFetchSavedCards,
|
|
33
|
+
useDisableCard,
|
|
34
|
+
useUpdateCustomer,
|
|
35
|
+
} = useCustomerQueries();
|
|
36
|
+
const { saveCard, saveCardLoading } = useSaveCustomerCard();
|
|
37
|
+
const { disableCard, disableCardLoading } = useDisableCard();
|
|
38
|
+
const [selectedPaymentId, onSelectPaymentId] = useState('');
|
|
39
|
+
const { updateCustomer, updateCustomerLoading } = useUpdateCustomer();
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (customer?.paymentId) {
|
|
43
|
+
onSelectPaymentId(customer.paymentId);
|
|
44
|
+
}
|
|
45
|
+
}, [customer?.paymentId, onSelectPaymentId]);
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
data: cards = [],
|
|
49
|
+
isFetching,
|
|
50
|
+
isLoading,
|
|
51
|
+
refetch,
|
|
52
|
+
} = useFetchSavedCards();
|
|
53
|
+
|
|
54
|
+
const onAddPress = () => {
|
|
55
|
+
onStartCardEntry(
|
|
56
|
+
(cardDetails) => {
|
|
57
|
+
saveCard({
|
|
58
|
+
sourceId: cardDetails.nonce,
|
|
59
|
+
idempotentKey: uuid.v4() as string,
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
() => {}
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const label =
|
|
67
|
+
cards.length > 0 ? t('checkout.payAndPlaceOrder') : t('checkout.payByCard');
|
|
68
|
+
|
|
69
|
+
if (isLoading) {
|
|
70
|
+
return <ActivityIndicator />;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const onUseCard = () => {
|
|
74
|
+
if (cards.length === 0) {
|
|
75
|
+
// If no cards then initiate add card flow.
|
|
76
|
+
onStartCardEntry(
|
|
77
|
+
(cardDetails) => {
|
|
78
|
+
saveCard({
|
|
79
|
+
sourceId: cardDetails.nonce,
|
|
80
|
+
idempotentKey: uuid.v4() as string,
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
() => {}
|
|
84
|
+
);
|
|
85
|
+
} else if (!customer.paymentId) {
|
|
86
|
+
Alert.show({ title: 'Select a card' });
|
|
87
|
+
} else {
|
|
88
|
+
// Make payment
|
|
89
|
+
const selectedCard = cards.find(
|
|
90
|
+
(card: any) => card.linkedObjectId === customer.paymentId
|
|
91
|
+
);
|
|
92
|
+
if (selectedCard) {
|
|
93
|
+
onCheckout?.(selectedCard);
|
|
94
|
+
} else {
|
|
95
|
+
Alert.show({ title: 'Select a card' });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<View flex={1}>
|
|
102
|
+
<View px="16" bg="background" flex={1}>
|
|
103
|
+
<LineLoader
|
|
104
|
+
isLoading={isFetching || disableCardLoading || updateCustomerLoading}
|
|
105
|
+
/>
|
|
106
|
+
<FlatList
|
|
107
|
+
extraData={{ selectedPaymentId, disableCardLoading }}
|
|
108
|
+
refreshControl={
|
|
109
|
+
<RefreshControl refreshing={false} onRefresh={refetch} />
|
|
110
|
+
}
|
|
111
|
+
data={cards}
|
|
112
|
+
showsVerticalScrollIndicator={false}
|
|
113
|
+
renderItem={({ item: card, index }) => (
|
|
114
|
+
<CardRow
|
|
115
|
+
isDisabled={disableCardLoading}
|
|
116
|
+
isSelected={selectedPaymentId === card.linkedObjectId}
|
|
117
|
+
isSelectable={!!onCheckout}
|
|
118
|
+
key={index}
|
|
119
|
+
card={card}
|
|
120
|
+
onDelete={(id: string) => {
|
|
121
|
+
disableCard(id);
|
|
122
|
+
}}
|
|
123
|
+
onSelect={(linkedObjectId: string) => {
|
|
124
|
+
onSelectPaymentId(linkedObjectId);
|
|
125
|
+
updateCustomer({
|
|
126
|
+
paymentId: linkedObjectId,
|
|
127
|
+
addressId: customer.addressId,
|
|
128
|
+
squareCustomerId: customer.squareCustomerId,
|
|
129
|
+
});
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
ListHeaderComponent={
|
|
134
|
+
<>
|
|
135
|
+
{cards.length > 0 ? (
|
|
136
|
+
<Text mb="8" variant="titleMedium">
|
|
137
|
+
{t('checkout.paymentMethods')}
|
|
138
|
+
</Text>
|
|
139
|
+
) : (
|
|
140
|
+
<Text variant="bodyLarge" color="outline">
|
|
141
|
+
{t('checkout.noSavedCards')}
|
|
142
|
+
</Text>
|
|
143
|
+
)}
|
|
144
|
+
</>
|
|
145
|
+
}
|
|
146
|
+
ListFooterComponent={
|
|
147
|
+
<View alignItems="flex-start">
|
|
148
|
+
<Button
|
|
149
|
+
pt={'16'}
|
|
150
|
+
loading={saveCardLoading}
|
|
151
|
+
onPress={onAddPress}
|
|
152
|
+
icon="plus"
|
|
153
|
+
mode="text"
|
|
154
|
+
>
|
|
155
|
+
{t('checkout.addCard')}
|
|
156
|
+
</Button>
|
|
157
|
+
</View>
|
|
158
|
+
}
|
|
159
|
+
/>
|
|
160
|
+
</View>
|
|
161
|
+
{!!onCheckout && (
|
|
162
|
+
<View
|
|
163
|
+
bg="secondaryContainer"
|
|
164
|
+
height={84}
|
|
165
|
+
padding="16"
|
|
166
|
+
justifyContent="space-between"
|
|
167
|
+
flexDirection="row"
|
|
168
|
+
width="100%"
|
|
169
|
+
>
|
|
170
|
+
<View>
|
|
171
|
+
<Text variant="bodyLarge" color="onSurface">
|
|
172
|
+
{t('order.total')}
|
|
173
|
+
</Text>
|
|
174
|
+
<Text variant="titleLarge" color="onSurface">
|
|
175
|
+
{total}
|
|
176
|
+
</Text>
|
|
177
|
+
</View>
|
|
178
|
+
<Button
|
|
179
|
+
mode="contained"
|
|
180
|
+
height={40}
|
|
181
|
+
width={'auto'}
|
|
182
|
+
alignSelf="center"
|
|
183
|
+
bg="primary"
|
|
184
|
+
labelStyle={[
|
|
185
|
+
{
|
|
186
|
+
color: theme.colors.background,
|
|
187
|
+
},
|
|
188
|
+
]}
|
|
189
|
+
onPress={onUseCard}
|
|
190
|
+
>
|
|
191
|
+
{label}
|
|
192
|
+
</Button>
|
|
193
|
+
</View>
|
|
194
|
+
)}
|
|
195
|
+
</View>
|
|
196
|
+
);
|
|
197
|
+
};
|
|
@@ -2,6 +2,11 @@ export const queryKeys = {
|
|
|
2
2
|
BUSINESSES: 'BUSINESSES',
|
|
3
3
|
TERMS_AND_CONDITIONS: 'TERMS_AND_CONDITIONS',
|
|
4
4
|
TERMS_AND_CONDITIONS_URL: 'TERMS_AND_CONDITIONS_URL',
|
|
5
|
+
CARDS: 'CARDS',
|
|
6
|
+
CUSTOMER: 'CUSTOMER',
|
|
7
|
+
PROGRAM: 'PROGRAM',
|
|
8
|
+
LOYALTY: 'LOYALTY',
|
|
9
|
+
REWARDS: 'REWARDS',
|
|
5
10
|
};
|
|
6
11
|
|
|
7
12
|
export const DEFAULT_STALE_TIME = 60 * (60 * 1000); // 60 mins
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface SaveCardRequest {
|
|
2
|
+
sourceId: string;
|
|
3
|
+
verificationToken?: string;
|
|
4
|
+
idempotentKey: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ConnectSquareCustomerRequest {
|
|
8
|
+
uid: string;
|
|
9
|
+
businessId: string;
|
|
10
|
+
idempotentKey: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Address {
|
|
14
|
+
addressLine1: string;
|
|
15
|
+
addressLine2: string;
|
|
16
|
+
// city: string;
|
|
17
|
+
// state: string;
|
|
18
|
+
// zip: string;
|
|
19
|
+
// country: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CreateCustomerProfileProps {
|
|
23
|
+
address: Address | null;
|
|
24
|
+
}
|
|
25
|
+
export interface CustomerProfileProps {
|
|
26
|
+
addressId: string | null;
|
|
27
|
+
paymentId: string | null;
|
|
28
|
+
squareCustomerId: string | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface UpdateSquareLoyaltyCustomerRequest {
|
|
32
|
+
uid: string;
|
|
33
|
+
businessId: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface DocumentProps {
|
|
37
|
+
created: string;
|
|
38
|
+
updated: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
enum PaymentType {
|
|
42
|
+
card = 'card',
|
|
43
|
+
}
|
|
44
|
+
export interface CardDetailsProps {
|
|
45
|
+
bin: string;
|
|
46
|
+
cardBrand: string;
|
|
47
|
+
cardType: string;
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
expMonth: number;
|
|
50
|
+
expYear: number;
|
|
51
|
+
fingerprint: string;
|
|
52
|
+
last4: string;
|
|
53
|
+
merchantId: string;
|
|
54
|
+
prepaidType: string;
|
|
55
|
+
version: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface CustomerPaymentProps {
|
|
59
|
+
type: PaymentType;
|
|
60
|
+
linkedObjectId: string;
|
|
61
|
+
provider: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface CustomerCardPayment
|
|
65
|
+
extends CustomerPaymentProps,
|
|
66
|
+
DocumentProps {
|
|
67
|
+
uid: string;
|
|
68
|
+
cardDetails: CardDetailsProps;
|
|
69
|
+
id: string;
|
|
70
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CardDetails,
|
|
3
|
+
SQIPCardEntry,
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
} from 'react-native-square-in-app-payments';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Callback when successfully get the card nonce details for processig
|
|
9
|
+
* card entry is still open and waiting for processing card nonce details
|
|
10
|
+
* @param {*} cardDetails
|
|
11
|
+
* @param onCompleteCallback
|
|
12
|
+
*/
|
|
13
|
+
async function onCardNonceRequestSuccess(
|
|
14
|
+
cardDetails: CardDetails,
|
|
15
|
+
onCompleteCallback: (cardDetails: CardDetails) => void
|
|
16
|
+
) {
|
|
17
|
+
try {
|
|
18
|
+
// take payment with the card details
|
|
19
|
+
// await chargeCard(cardDetails);
|
|
20
|
+
|
|
21
|
+
// payment finished successfully
|
|
22
|
+
// you must call this method to close card entry
|
|
23
|
+
await SQIPCardEntry.completeCardEntry(() =>
|
|
24
|
+
onCompleteCallback(cardDetails)
|
|
25
|
+
);
|
|
26
|
+
} catch (ex) {
|
|
27
|
+
// payment failed to complete due to error
|
|
28
|
+
// notify card entry to show processing error
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
await SQIPCardEntry.showCardNonceProcessingError(ex.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An event listener to start card entry flow
|
|
36
|
+
*/
|
|
37
|
+
export async function onStartCardEntry(
|
|
38
|
+
onSuccessCallback: (cardDetails: CardDetails) => void,
|
|
39
|
+
onCancelCallback: () => void
|
|
40
|
+
) {
|
|
41
|
+
const cardEntryConfig = {
|
|
42
|
+
collectPostalCode: false,
|
|
43
|
+
};
|
|
44
|
+
await SQIPCardEntry.startCardEntryFlow(
|
|
45
|
+
cardEntryConfig,
|
|
46
|
+
(cardDetails: CardDetails) =>
|
|
47
|
+
onCardNonceRequestSuccess(cardDetails, onSuccessCallback),
|
|
48
|
+
onCancelCallback
|
|
49
|
+
);
|
|
50
|
+
}
|