@kiosinc/commons-rn 0.1.95 → 0.1.97
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/assets/icons/apple_pay.svg +8 -0
- package/lib/commonjs/hooks/useCustomer.js +12 -3
- package/lib/commonjs/hooks/useCustomer.js.map +1 -1
- package/lib/commonjs/localization/translations/en.json +6 -1
- package/lib/commonjs/screens/SavedCards/CardRow.js +35 -21
- package/lib/commonjs/screens/SavedCards/CardRow.js.map +1 -1
- package/lib/commonjs/screens/SavedCards/SavedCards.js +61 -44
- package/lib/commonjs/screens/SavedCards/SavedCards.js.map +1 -1
- package/lib/commonjs/screens/SavedCards/useApplePay.js +85 -0
- package/lib/commonjs/screens/SavedCards/useApplePay.js.map +1 -0
- package/lib/module/assets/icons/apple_pay.svg +8 -0
- package/lib/module/hooks/useCustomer.js +12 -3
- package/lib/module/hooks/useCustomer.js.map +1 -1
- package/lib/module/localization/translations/en.json +6 -1
- package/lib/module/screens/SavedCards/CardRow.js +35 -21
- package/lib/module/screens/SavedCards/CardRow.js.map +1 -1
- package/lib/module/screens/SavedCards/SavedCards.js +62 -45
- package/lib/module/screens/SavedCards/SavedCards.js.map +1 -1
- package/lib/module/screens/SavedCards/useApplePay.js +77 -0
- package/lib/module/screens/SavedCards/useApplePay.js.map +1 -0
- package/lib/typescript/src/hooks/useCustomer.d.ts +1 -1
- package/lib/typescript/src/hooks/useCustomer.d.ts.map +1 -1
- package/lib/typescript/src/localization/index.d.ts +5 -0
- package/lib/typescript/src/localization/index.d.ts.map +1 -1
- package/lib/typescript/src/screens/SavedCards/CardRow.d.ts +5 -4
- package/lib/typescript/src/screens/SavedCards/CardRow.d.ts.map +1 -1
- package/lib/typescript/src/screens/SavedCards/SavedCards.d.ts +3 -2
- package/lib/typescript/src/screens/SavedCards/SavedCards.d.ts.map +1 -1
- package/lib/typescript/src/screens/SavedCards/useApplePay.d.ts +6 -0
- package/lib/typescript/src/screens/SavedCards/useApplePay.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/assets/icons/apple_pay.svg +8 -0
- package/src/hooks/useCustomer.ts +23 -3
- package/src/localization/translations/en.json +6 -1
- package/src/screens/SavedCards/CardRow.tsx +52 -31
- package/src/screens/SavedCards/SavedCards.tsx +71 -61
- package/src/screens/SavedCards/useApplePay.tsx +88 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SavedCards.d.ts","sourceRoot":"","sources":["../../../../../src/screens/SavedCards/SavedCards.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"SavedCards.d.ts","sourceRoot":"","sources":["../../../../../src/screens/SavedCards/SavedCards.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,eAAO,MAAM,UAAU;iCAKO,mBAAmB,GAAG,UAAU,KAAK,IAAI;;;iBAqLtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useApplePay.d.ts","sourceRoot":"","sources":["../../../../../src/screens/SavedCards/useApplePay.tsx"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW;;;;CAiFvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.14931 4H21.8507C21.9326 4 22.0148 4 22.0967 4.00048C22.1658 4.00097 22.2349 4.00174 22.3043 4.00362C22.4546 4.0077 22.6065 4.01659 22.7556 4.04332C22.9066 4.07053 23.0473 4.1149 23.1845 4.18475C23.3195 4.25335 23.4426 4.34308 23.5499 4.45014C23.6568 4.55721 23.7465 4.6805 23.8153 4.81553C23.8853 4.95274 23.9296 5.09343 23.9565 5.24469C23.9834 5.3935 23.9922 5.54542 23.9962 5.69591C23.9981 5.76499 23.999 5.83406 23.9994 5.90312C24 5.98521 24 6.06723 24 6.14946V17.2153C24 17.2975 24 17.3794 23.9994 17.4616C23.999 17.5307 23.9981 17.5998 23.9962 17.6688C23.9922 17.8192 23.9834 17.9711 23.9565 18.1199C23.9296 18.2712 23.8853 18.4118 23.8153 18.5491C23.7465 18.6841 23.6568 18.8076 23.5499 18.9145C23.4426 19.0217 23.3195 19.1114 23.1845 19.1798C23.0473 19.2499 22.9066 19.2943 22.7556 19.3214C22.6065 19.348 22.4546 19.3571 22.3043 19.3611C22.2349 19.3627 22.1658 19.3636 22.0967 19.3639C22.0148 19.3646 21.9326 19.3646 21.8507 19.3646H2.14931C2.06726 19.3646 1.98506 19.3646 1.90315 19.3639C1.83391 19.3636 1.76484 19.3627 1.69576 19.3611C1.54511 19.3571 1.39317 19.348 1.2444 19.3214C1.09326 19.2943 0.95261 19.2499 0.8154 19.1798C0.680509 19.1114 0.557016 19.0217 0.449995 18.9145C0.342928 18.8076 0.253204 18.6841 0.184621 18.5491C0.114747 18.4118 0.0703489 18.2712 0.043336 18.1199C0.0164551 17.9711 0.00750735 17.8192 0.00344744 17.6688C0.00159148 17.5998 0.000795452 17.5307 0.000344512 17.4616C-3.82314e-05 17.3958 -1.27661e-05 17.3303 1.27502e-05 17.2646C1.91332e-05 17.2482 2.55194e-05 17.2317 2.55194e-05 17.2153V6.14946C2.55194e-05 6.13301 1.91349e-05 6.11656 1.27527e-05 6.10013C-1.27644e-05 6.03441 -3.8244e-05 5.96878 0.000344512 5.90312C0.000795452 5.83406 0.00159148 5.76499 0.00344744 5.69591C0.00750735 5.54542 0.0164551 5.3935 0.043336 5.24469C0.0703489 5.09343 0.114747 4.95274 0.184621 4.81553C0.253204 4.6805 0.342928 4.55721 0.449995 4.45014C0.557016 4.34308 0.680509 4.25335 0.8154 4.18475C0.95261 4.1149 1.09326 4.07053 1.2444 4.04332C1.39317 4.01659 1.54511 4.0077 1.69576 4.00362C1.76484 4.00174 1.83391 4.00097 1.90315 4.00048C1.98506 4 2.06726 4 2.14931 4ZM22.0931 4.51255L21.8507 4.51208H2.14932L1.90614 4.51256C1.84101 4.51301 1.77539 4.51372 1.70976 4.51551C1.59463 4.51862 1.46021 4.52483 1.33496 4.54733C1.22625 4.56689 1.13495 4.59669 1.04779 4.64107C0.960548 4.68544 0.881367 4.74296 0.812204 4.81216C0.742763 4.88158 0.685257 4.96072 0.641222 5.04741C0.596563 5.13512 0.566853 5.22627 0.547482 5.33471C0.524703 5.46083 0.518497 5.59498 0.515395 5.70968C0.513625 5.77524 0.512885 5.84083 0.512451 5.90645L0.512146 6.09858L0.512161 6.14942V17.2152L0.512146 17.2661L0.512465 17.4586C0.512886 17.5238 0.513625 17.5894 0.515395 17.655C0.518497 17.7696 0.524703 17.9037 0.547295 18.0288C0.566839 18.1382 0.596563 18.2294 0.64099 18.3167C0.685373 18.404 0.742778 18.483 0.811854 18.552C0.881467 18.6217 0.96039 18.6791 1.04708 18.7231C1.13518 18.768 1.22631 18.7978 1.33502 18.8174C1.46173 18.84 1.60178 18.8462 1.7096 18.8492C1.7734 18.8506 1.83939 18.8515 1.90552 18.8518C1.98651 18.8524 2.06621 18.8524 2.14575 18.8524H2.14611H2.14932H21.8507C21.9313 18.8524 22.0122 18.8524 22.0928 18.8518C22.1604 18.8515 22.2264 18.8506 22.2927 18.8491C22.3981 18.8462 22.5381 18.84 22.6658 18.8172C22.7736 18.7978 22.8647 18.768 22.9517 18.7236C23.0392 18.6793 23.1182 18.6219 23.1878 18.5523C23.2569 18.4831 23.3145 18.4039 23.3589 18.3166C23.4035 18.2293 23.4331 18.1384 23.4523 18.0303C23.475 17.9049 23.4812 17.7703 23.4843 17.6549C23.4861 17.5896 23.4869 17.5244 23.4873 17.4592C23.4879 17.3784 23.4879 17.2994 23.4879 17.2201V17.2152V6.14942V6.14511C23.4879 6.06564 23.4879 5.98637 23.4873 5.90705C23.4869 5.84028 23.4861 5.77506 23.4843 5.70984C23.4812 5.5943 23.475 5.45959 23.4526 5.33574C23.4331 5.22609 23.4035 5.13524 23.3591 5.04831C23.3146 4.96086 23.2569 4.88149 23.1875 4.81194C23.1183 4.74285 23.039 4.68525 22.9526 4.64131C22.8649 4.59671 22.7737 4.56689 22.6648 4.54729C22.5396 4.52484 22.4053 4.51862 22.2904 4.51552C22.2244 4.51372 22.1587 4.51301 22.0931 4.51255Z" fill="currentColor"/>
|
|
3
|
+
<path d="M6.55187 9.1677C6.75737 8.91067 6.89682 8.56556 6.86004 8.21289C6.55922 8.22785 6.19213 8.41135 5.97961 8.66858C5.78878 8.88886 5.61989 9.24842 5.66392 9.58631C6.0016 9.6156 6.33897 9.41752 6.55187 9.1677Z" fill="currentColor"/>
|
|
4
|
+
<path d="M6.85617 9.65235C6.36577 9.62314 5.94882 9.93067 5.71463 9.93067C5.48031 9.93067 5.12169 9.66707 4.73382 9.67417C4.22897 9.68159 3.76053 9.96703 3.50435 10.421C2.97741 11.3292 3.36529 12.6764 3.8777 13.4161C4.12654 13.782 4.42644 14.185 4.8216 14.1705C5.19495 14.1558 5.3413 13.9287 5.79513 13.9287C6.24863 13.9287 6.38045 14.1705 6.77567 14.1632C7.18552 14.1558 7.44176 13.797 7.69059 13.4307C7.97606 13.0136 8.09292 12.6108 8.10027 12.5887C8.09292 12.5813 7.30996 12.281 7.30269 11.3803C7.2953 10.6262 7.91741 10.2675 7.94669 10.2452C7.59538 9.72565 7.04647 9.66707 6.85617 9.65235Z" fill="currentColor"/>
|
|
5
|
+
<path d="M11.1261 8.63086C12.192 8.63086 12.9342 9.36557 12.9342 10.4353C12.9342 11.5088 12.1767 12.2473 11.0994 12.2473H9.91928V14.124H9.06665V8.63086L11.1261 8.63086ZM9.91928 11.5316H10.8976C11.64 11.5316 12.0625 11.1319 12.0625 10.4391C12.0625 9.74629 11.64 9.35037 10.9014 9.35037H9.91928V11.5316Z" fill="currentColor"/>
|
|
6
|
+
<path d="M13.157 12.9857C13.157 12.2852 13.6937 11.8551 14.6455 11.8018L15.7418 11.7371V11.4288C15.7418 10.9834 15.441 10.7169 14.9386 10.7169C14.4627 10.7169 14.1657 10.9453 14.0935 11.3031H13.3169C13.3626 10.5798 13.9792 10.0469 14.969 10.0469C15.9397 10.0469 16.5602 10.5608 16.5602 11.364V14.1239H15.7722V13.4653H15.7532C15.521 13.9107 15.0147 14.1924 14.4894 14.1924C13.7052 14.1924 13.157 13.7051 13.157 12.9857ZM15.7418 12.6241V12.3081L14.7558 12.369C14.2647 12.4033 13.9869 12.6203 13.9869 12.9629C13.9869 13.3131 14.2762 13.5415 14.7177 13.5415C15.2925 13.5415 15.7418 13.1456 15.7418 12.6241Z" fill="currentColor"/>
|
|
7
|
+
<path d="M17.3041 15.5971V14.9309C17.3649 14.9461 17.5019 14.9461 17.5705 14.9461C17.9512 14.9461 18.1568 14.7862 18.2823 14.3751C18.2823 14.3675 18.3547 14.1315 18.3547 14.1277L16.9082 10.1191H17.7989L18.8116 13.3778H18.8267L19.8394 10.1191H20.7073L19.2073 14.3332C18.8649 15.304 18.469 15.6161 17.6391 15.6161C17.5705 15.6161 17.3649 15.6085 17.3041 15.5971Z" fill="currentColor"/>
|
|
8
|
+
</svg>
|
package/src/hooks/useCustomer.ts
CHANGED
|
@@ -189,7 +189,18 @@ export const useCustomerQueries = () => {
|
|
|
189
189
|
[queryKeys.LOYALTY, user?.uid, selectedBusinessId],
|
|
190
190
|
async () => {
|
|
191
191
|
if (isLoggedIn && selectedBusinessId) {
|
|
192
|
-
|
|
192
|
+
const response = await fetchSquareLoyalty(
|
|
193
|
+
user.uid,
|
|
194
|
+
selectedBusinessId
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (response?.data?.error) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
response.data.error.message || 'Unknown error occurred'
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return response;
|
|
193
204
|
} else {
|
|
194
205
|
return { data: null };
|
|
195
206
|
}
|
|
@@ -259,17 +270,26 @@ export const useCustomerQueries = () => {
|
|
|
259
270
|
const mutation = useMutation(
|
|
260
271
|
async () => {
|
|
261
272
|
if (isLoggedIn && selectedBusinessId) {
|
|
262
|
-
await connectSquareLoyalty(user?.uid, {
|
|
273
|
+
const response = await connectSquareLoyalty(user?.uid, {
|
|
263
274
|
businessId: selectedBusinessId,
|
|
264
275
|
idempotentKey: uuid.v4() as string,
|
|
265
276
|
uid: user?.uid,
|
|
266
277
|
});
|
|
278
|
+
|
|
279
|
+
if (response?.data?.error) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
response.data.error.message || 'Unknown error occurred'
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return response;
|
|
267
286
|
}
|
|
287
|
+
return null;
|
|
268
288
|
},
|
|
269
289
|
{
|
|
270
290
|
onError: (err: { code: string; message: string }) =>
|
|
271
291
|
Alert.show({
|
|
272
|
-
title: 'Code ' + err?.code,
|
|
292
|
+
title: err?.code ? 'Code ' + err?.code : '',
|
|
273
293
|
description: err?.message,
|
|
274
294
|
}),
|
|
275
295
|
onSuccess: () => {
|
|
@@ -66,6 +66,9 @@
|
|
|
66
66
|
"addCard": "Add card",
|
|
67
67
|
"noSavedCards": "You have no saved card yet.",
|
|
68
68
|
"paymentMethods": "Payment methods",
|
|
69
|
+
"selectPaymentMethod": "Select payment method to be used",
|
|
70
|
+
"selectValidPaymentMethod": "Select valid payment method to be used",
|
|
71
|
+
"noPaymentMethods": "You have no payment methods available",
|
|
69
72
|
"payment": "Payment",
|
|
70
73
|
"payAndPlaceOrder": "Pay & Place order",
|
|
71
74
|
"payByCard": "Pay by card",
|
|
@@ -84,6 +87,8 @@
|
|
|
84
87
|
},
|
|
85
88
|
"termsTitle": "Terms of Service Update",
|
|
86
89
|
"acceptTerms": "Accept Terms",
|
|
87
|
-
"version": "Version"
|
|
90
|
+
"version": "Version",
|
|
91
|
+
"error": "Error",
|
|
92
|
+
"cardSaveError": "Something went wrong saving the card"
|
|
88
93
|
}
|
|
89
94
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Alert, Card, IconButton, Text, View } from '../../components';
|
|
3
|
+
import ApplePayIcon from '../../assets/icons/apple_pay.svg';
|
|
3
4
|
import { RadioButton, useTheme } from 'react-native-paper';
|
|
4
5
|
import { useTranslation } from 'react-i18next';
|
|
5
6
|
import { getCardName } from '../../utils/checkout';
|
|
@@ -12,48 +13,55 @@ export const CardRow = ({
|
|
|
12
13
|
isSelectable,
|
|
13
14
|
isSelected,
|
|
14
15
|
isDisabled,
|
|
16
|
+
isApplePay = false,
|
|
15
17
|
}: {
|
|
16
|
-
card
|
|
17
|
-
onDelete
|
|
18
|
-
onSelect
|
|
18
|
+
card?: CustomerCardPayment;
|
|
19
|
+
onDelete?: (id: string) => void;
|
|
20
|
+
onSelect?: (linkedObjectId: string) => void;
|
|
19
21
|
isSelectable: boolean;
|
|
20
22
|
isSelected: boolean;
|
|
21
23
|
isDisabled: boolean;
|
|
24
|
+
isApplePay?: boolean;
|
|
22
25
|
}) => {
|
|
23
|
-
const name = getCardName(card);
|
|
24
26
|
const { t } = useTranslation();
|
|
25
27
|
const theme = useTheme();
|
|
26
28
|
|
|
27
29
|
const onDeleteCard = () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
if (card) {
|
|
31
|
+
Alert.show({
|
|
32
|
+
title: t('commons.confirmCardDelete'),
|
|
33
|
+
description: t('commons.cardDeleteDesc', {
|
|
34
|
+
card: card.cardDetails.last4,
|
|
35
|
+
}),
|
|
36
|
+
buttons: [
|
|
37
|
+
{
|
|
38
|
+
label: t('commons.delete'),
|
|
39
|
+
textColor: theme.colors.error,
|
|
40
|
+
onPress: () => onDelete?.(card.id),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: t('commons.cancel'),
|
|
44
|
+
textColor: theme.colors.onSurface,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
45
49
|
};
|
|
46
50
|
|
|
51
|
+
const cardName = isApplePay ? 'Apple Pay' : getCardName(card!);
|
|
52
|
+
|
|
47
53
|
return (
|
|
48
54
|
<Card
|
|
49
55
|
disabled={isDisabled}
|
|
50
56
|
mode="outlined"
|
|
51
57
|
borderRadius="4"
|
|
58
|
+
height={50}
|
|
59
|
+
justifyContent="center"
|
|
52
60
|
mb="8"
|
|
53
61
|
{...(isSelectable
|
|
54
62
|
? {
|
|
55
63
|
onPress: () => {
|
|
56
|
-
onSelect(card
|
|
64
|
+
onSelect?.(card?.linkedObjectId ?? '');
|
|
57
65
|
},
|
|
58
66
|
}
|
|
59
67
|
: {})}
|
|
@@ -66,10 +74,10 @@ export const CardRow = ({
|
|
|
66
74
|
>
|
|
67
75
|
{isSelectable && (
|
|
68
76
|
<RadioButton.Android
|
|
69
|
-
value={card
|
|
77
|
+
value={card?.linkedObjectId || 'apple-pay'}
|
|
70
78
|
status={isSelected ? 'checked' : 'unchecked'}
|
|
71
79
|
onPress={() => {
|
|
72
|
-
onSelect(card
|
|
80
|
+
onSelect?.(card?.linkedObjectId ?? '');
|
|
73
81
|
}}
|
|
74
82
|
/>
|
|
75
83
|
)}
|
|
@@ -80,13 +88,26 @@ export const CardRow = ({
|
|
|
80
88
|
alignItems="center"
|
|
81
89
|
justifyContent="space-between"
|
|
82
90
|
>
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
<View flexDirection="row" alignItems="center">
|
|
92
|
+
{isApplePay && (
|
|
93
|
+
<ApplePayIcon
|
|
94
|
+
height={24}
|
|
95
|
+
width={24}
|
|
96
|
+
color={theme.colors.onBackground}
|
|
97
|
+
/>
|
|
98
|
+
)}
|
|
99
|
+
<Text ps={isApplePay ? '8' : '0'} variant="bodyMedium">
|
|
100
|
+
{cardName}
|
|
101
|
+
</Text>
|
|
102
|
+
</View>
|
|
103
|
+
{!isApplePay && (
|
|
104
|
+
<IconButton
|
|
105
|
+
disabled={isDisabled}
|
|
106
|
+
icon="trash-can-outline"
|
|
107
|
+
bg="background"
|
|
108
|
+
onPress={onDeleteCard}
|
|
109
|
+
/>
|
|
110
|
+
)}
|
|
90
111
|
</View>
|
|
91
112
|
</View>
|
|
92
113
|
</Card>
|
|
@@ -10,19 +10,22 @@ import {
|
|
|
10
10
|
import { ActivityIndicator, useTheme } from 'react-native-paper';
|
|
11
11
|
import uuid from 'react-native-uuid';
|
|
12
12
|
import { useTranslation } from 'react-i18next';
|
|
13
|
-
import { FlatList } from 'react-native';
|
|
13
|
+
import { FlatList, Platform } from 'react-native';
|
|
14
14
|
import { onStartCardEntry } from '../../utils/square';
|
|
15
15
|
import { useCustomerQueries } from '../../hooks/useCustomer';
|
|
16
16
|
import { useCheckCustomer } from '../../hooks/useCheckCustomer';
|
|
17
17
|
import { CardRow } from './CardRow';
|
|
18
18
|
import { CustomerCardPayment } from '@kiosinc/commons-types';
|
|
19
|
+
import { useApplePay } from './useApplePay';
|
|
19
20
|
|
|
20
21
|
export const SavedCards = ({
|
|
21
22
|
onCheckout,
|
|
23
|
+
showApplePay,
|
|
22
24
|
total,
|
|
23
25
|
}: {
|
|
24
|
-
onCheckout?: (selectedCard: CustomerCardPayment) => void;
|
|
26
|
+
onCheckout?: (selectedCard: CustomerCardPayment | 'ApplePay') => void;
|
|
25
27
|
total?: string;
|
|
28
|
+
showApplePay?: boolean;
|
|
26
29
|
}) => {
|
|
27
30
|
const { t } = useTranslation();
|
|
28
31
|
const theme = useTheme();
|
|
@@ -35,14 +38,15 @@ export const SavedCards = ({
|
|
|
35
38
|
} = useCustomerQueries();
|
|
36
39
|
const { saveCard, saveCardLoading } = useSaveCustomerCard();
|
|
37
40
|
const { disableCard, disableCardLoading } = useDisableCard();
|
|
38
|
-
const [selectedPaymentId,
|
|
41
|
+
const [selectedPaymentId, setSelectedPaymentId] = useState('');
|
|
39
42
|
const { updateCustomer, updateCustomerLoading } = useUpdateCustomer();
|
|
43
|
+
const { hasApplePay } = useApplePay();
|
|
40
44
|
|
|
41
45
|
useEffect(() => {
|
|
42
46
|
if (customer?.paymentId) {
|
|
43
|
-
|
|
47
|
+
setSelectedPaymentId(customer.paymentId);
|
|
44
48
|
}
|
|
45
|
-
}, [customer?.paymentId
|
|
49
|
+
}, [customer?.paymentId]);
|
|
46
50
|
|
|
47
51
|
const {
|
|
48
52
|
data: cards = [],
|
|
@@ -51,7 +55,7 @@ export const SavedCards = ({
|
|
|
51
55
|
refetch,
|
|
52
56
|
} = useFetchSavedCards();
|
|
53
57
|
|
|
54
|
-
const
|
|
58
|
+
const handleAddCard = () => {
|
|
55
59
|
onStartCardEntry(
|
|
56
60
|
(cardDetails) => {
|
|
57
61
|
saveCard({
|
|
@@ -59,44 +63,50 @@ export const SavedCards = ({
|
|
|
59
63
|
idempotentKey: uuid.v4() as string,
|
|
60
64
|
});
|
|
61
65
|
},
|
|
62
|
-
() => {
|
|
66
|
+
() => {
|
|
67
|
+
Alert.show({
|
|
68
|
+
title: t('commons.error'),
|
|
69
|
+
description: t('commons.cardSaveError'),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
63
72
|
);
|
|
64
73
|
};
|
|
65
74
|
|
|
66
|
-
const
|
|
67
|
-
cards.length
|
|
75
|
+
const handleUseCard = () => {
|
|
76
|
+
if (!cards.length && !(hasApplePay && Platform.OS === 'ios')) {
|
|
77
|
+
Alert.show({ title: t('commons.noPaymentMethods') });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
68
80
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
if (!selectedPaymentId) {
|
|
82
|
+
Alert.show({ title: t('commons.selectPaymentMethod') });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
72
85
|
|
|
73
|
-
|
|
74
|
-
|
|
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' });
|
|
86
|
+
if (selectedPaymentId === 'ApplePay') {
|
|
87
|
+
onCheckout?.('ApplePay');
|
|
87
88
|
} else {
|
|
88
|
-
// Make payment
|
|
89
89
|
const selectedCard = cards.find(
|
|
90
|
-
(card: any) => card.linkedObjectId ===
|
|
90
|
+
(card: any) => card.linkedObjectId === selectedPaymentId
|
|
91
91
|
);
|
|
92
|
+
|
|
92
93
|
if (selectedCard) {
|
|
93
94
|
onCheckout?.(selectedCard);
|
|
94
95
|
} else {
|
|
95
|
-
Alert.show({ title: '
|
|
96
|
+
Alert.show({ title: t('commons.selectValidPaymentMethod') });
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
};
|
|
99
100
|
|
|
101
|
+
const paymentMethods =
|
|
102
|
+
hasApplePay && showApplePay && Platform.OS === 'ios'
|
|
103
|
+
? [{ linkedObjectId: 'ApplePay', isApplePay: true }, ...cards]
|
|
104
|
+
: cards;
|
|
105
|
+
|
|
106
|
+
if (isLoading) {
|
|
107
|
+
return <ActivityIndicator />;
|
|
108
|
+
}
|
|
109
|
+
|
|
100
110
|
return (
|
|
101
111
|
<View flex={1}>
|
|
102
112
|
<View px="16" bg="background" flex={1}>
|
|
@@ -106,49 +116,51 @@ export const SavedCards = ({
|
|
|
106
116
|
<FlatList
|
|
107
117
|
extraData={{ selectedPaymentId, disableCardLoading }}
|
|
108
118
|
refreshControl={
|
|
109
|
-
<RefreshControl refreshing={
|
|
119
|
+
<RefreshControl refreshing={isFetching} onRefresh={refetch} />
|
|
110
120
|
}
|
|
111
|
-
data={
|
|
121
|
+
data={paymentMethods}
|
|
112
122
|
showsVerticalScrollIndicator={false}
|
|
113
|
-
renderItem={({ item: card
|
|
123
|
+
renderItem={({ item: card }) => (
|
|
114
124
|
<CardRow
|
|
115
125
|
isDisabled={disableCardLoading}
|
|
116
126
|
isSelected={selectedPaymentId === card.linkedObjectId}
|
|
117
127
|
isSelectable={!!onCheckout}
|
|
118
|
-
|
|
128
|
+
isApplePay={card.isApplePay}
|
|
119
129
|
card={card}
|
|
120
130
|
onDelete={(id: string) => {
|
|
121
|
-
|
|
131
|
+
if (!card.isApplePay) {
|
|
132
|
+
disableCard(id);
|
|
133
|
+
}
|
|
122
134
|
}}
|
|
123
135
|
onSelect={(linkedObjectId: string) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
136
|
+
setSelectedPaymentId(linkedObjectId);
|
|
137
|
+
if (!card.isApplePay) {
|
|
138
|
+
updateCustomer({
|
|
139
|
+
paymentId: linkedObjectId,
|
|
140
|
+
addressId: customer.addressId,
|
|
141
|
+
squareCustomerId: customer.squareCustomerId,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
130
144
|
}}
|
|
131
145
|
/>
|
|
132
146
|
)}
|
|
133
147
|
ListHeaderComponent={
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
)}
|
|
144
|
-
</>
|
|
148
|
+
paymentMethods.length > 0 ? (
|
|
149
|
+
<Text mb="8" variant="titleMedium">
|
|
150
|
+
{t('commons.paymentMethods')}
|
|
151
|
+
</Text>
|
|
152
|
+
) : (
|
|
153
|
+
<Text variant="bodyLarge" color="outline">
|
|
154
|
+
{t('commons.noSavedCards')}
|
|
155
|
+
</Text>
|
|
156
|
+
)
|
|
145
157
|
}
|
|
146
158
|
ListFooterComponent={
|
|
147
159
|
<View alignItems="flex-start">
|
|
148
160
|
<Button
|
|
149
|
-
pt=
|
|
161
|
+
pt="16"
|
|
150
162
|
loading={saveCardLoading}
|
|
151
|
-
onPress={
|
|
163
|
+
onPress={handleAddCard}
|
|
152
164
|
icon="plus"
|
|
153
165
|
mode="text"
|
|
154
166
|
>
|
|
@@ -178,17 +190,15 @@ export const SavedCards = ({
|
|
|
178
190
|
<Button
|
|
179
191
|
mode="contained"
|
|
180
192
|
height={40}
|
|
181
|
-
width=
|
|
193
|
+
width="auto"
|
|
182
194
|
alignSelf="center"
|
|
183
195
|
bg="primary"
|
|
184
|
-
labelStyle={
|
|
185
|
-
|
|
186
|
-
color: theme.colors.background,
|
|
187
|
-
},
|
|
188
|
-
]}
|
|
189
|
-
onPress={onUseCard}
|
|
196
|
+
labelStyle={{ color: theme.colors.background }}
|
|
197
|
+
onPress={handleUseCard}
|
|
190
198
|
>
|
|
191
|
-
{
|
|
199
|
+
{cards.length > 0 || hasApplePay
|
|
200
|
+
? t('commons.payAndPlaceOrder')
|
|
201
|
+
: t('commons.payByCard')}
|
|
192
202
|
</Button>
|
|
193
203
|
</View>
|
|
194
204
|
)}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { SQIPApplePay } from 'react-native-square-in-app-payments';
|
|
5
|
+
import { Alert } from '@kiosinc/commons-rn';
|
|
6
|
+
|
|
7
|
+
export const useApplePay = () => {
|
|
8
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
9
|
+
const [hasApplePay, setHasApplePay] = useState(false);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const checkApplePay = async () => {
|
|
13
|
+
const digitalWalletEnabled = await SQIPApplePay.canUseApplePay();
|
|
14
|
+
setHasApplePay(digitalWalletEnabled);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
checkApplePay();
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
// Handle Apple Pay Nonce Request Success
|
|
21
|
+
const onApplePayNonceRequestSuccess = useCallback(async (cardDetails) => {
|
|
22
|
+
try {
|
|
23
|
+
// Perform operations with cardDetails
|
|
24
|
+
// await chargeCard(cardDetails);
|
|
25
|
+
|
|
26
|
+
Alert.show({ title: JSON.stringify(cardDetails) });
|
|
27
|
+
|
|
28
|
+
// Close the Apple Pay sheet with success
|
|
29
|
+
await SQIPApplePay.completeApplePayAuthorization(true);
|
|
30
|
+
} catch (ex: any) {
|
|
31
|
+
await SQIPApplePay.completeApplePayAuthorization(false, ex.message);
|
|
32
|
+
}
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
// Handle Apple Pay Nonce Request Failure
|
|
36
|
+
const onApplePayNonceRequestFailure = useCallback(async (errorInfo) => {
|
|
37
|
+
Alert.show({
|
|
38
|
+
title: errorInfo.message,
|
|
39
|
+
description: errorInfo.debugMessage,
|
|
40
|
+
});
|
|
41
|
+
await SQIPApplePay.completeApplePayAuthorization(false, errorInfo.message);
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
// Handle Apple Pay Entry Completion
|
|
45
|
+
const onApplePayEntryComplete = useCallback(() => {
|
|
46
|
+
setIsProcessing(false);
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
// Start Digital Wallet Flow
|
|
50
|
+
const startApplePay = useCallback(async () => {
|
|
51
|
+
if (Platform.OS === 'ios') {
|
|
52
|
+
if (hasApplePay) {
|
|
53
|
+
const applePayConfig = {
|
|
54
|
+
price: '0.1',
|
|
55
|
+
summaryLabel: 'Test Item',
|
|
56
|
+
countryCode: 'US',
|
|
57
|
+
currencyCode: 'USD',
|
|
58
|
+
paymentType: 2,
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
setIsProcessing(true);
|
|
62
|
+
await SQIPApplePay.requestApplePayNonce(
|
|
63
|
+
applePayConfig,
|
|
64
|
+
onApplePayNonceRequestSuccess,
|
|
65
|
+
onApplePayNonceRequestFailure,
|
|
66
|
+
onApplePayEntryComplete
|
|
67
|
+
);
|
|
68
|
+
} catch (ex) {
|
|
69
|
+
setIsProcessing(false);
|
|
70
|
+
// Handle InAppPaymentsException
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else if (Platform.OS === 'android') {
|
|
74
|
+
// Android-specific digital wallet logic
|
|
75
|
+
}
|
|
76
|
+
}, [
|
|
77
|
+
onApplePayNonceRequestSuccess,
|
|
78
|
+
onApplePayNonceRequestFailure,
|
|
79
|
+
onApplePayEntryComplete,
|
|
80
|
+
hasApplePay,
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
hasApplePay,
|
|
85
|
+
isProcessing,
|
|
86
|
+
startApplePay,
|
|
87
|
+
};
|
|
88
|
+
};
|