@brissoto/pay-react-native 1.7.0 → 1.8.1
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/README.md +3 -1
- package/dist/components/BrissotoPayProvider.js +3 -1
- package/dist/components/PaymentSheetModal.d.ts +1 -1
- package/dist/components/PaymentSheetModal.js +2 -2
- package/dist/components/SheetButton.d.ts +2 -1
- package/dist/components/SheetButton.js +8 -3
- package/dist/components/SheetContent.d.ts +1 -1
- package/dist/components/SheetContent.js +7 -3
- package/dist/components/SheetPaypalButton.js +5 -2
- package/dist/hooks/use-native-platform.js +7 -2
- package/dist/hooks/use-outcome-haptic.d.ts +9 -0
- package/dist/hooks/use-outcome-haptic.js +45 -0
- package/dist/hooks/use-shake.d.ts +4 -1
- package/dist/hooks/use-shake.js +13 -3
- package/dist/models/sheet.constants.d.ts +16 -3
- package/dist/models/sheet.constants.js +43 -2
- package/dist/models/sheet.enum.d.ts +42 -0
- package/dist/models/sheet.enum.js +47 -0
- package/dist/models/sheet.interface.d.ts +34 -1
- package/dist/models/sheet.utils.d.ts +9 -2
- package/dist/models/sheet.utils.js +22 -3
- package/dist/services/haptics.service.d.ts +12 -0
- package/dist/services/haptics.service.js +39 -0
- package/dist/services/provider-window.service.d.ts +4 -1
- package/dist/services/provider-window.service.js +10 -2
- package/dist/services/store.service.d.ts +4 -1
- package/dist/services/store.service.js +10 -2
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Take payments in your Expo app through Brissoto Pay: a payment sheet slides up, the payer pays in it and never leaves the app. Pure JavaScript: it runs in Expo Go and any Expo app, with no native code and no rebuild.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npx expo install @brissoto/pay-react-native convex expo-font react-native-webview
|
|
6
|
+
npx expo install @brissoto/pay-react-native convex expo-font expo-haptics react-native-webview
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## 1. Create the payment on your server
|
|
@@ -43,6 +43,8 @@ npx expo install expo-iap
|
|
|
43
43
|
npx expo install expo-web-browser
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
**Haptics** play with [expo-haptics](https://docs.expo.dev/versions/latest/sdk/haptics/), in the install above: on Pay and the main buttons, and on each outcome (paid, failed, waiting for approval, a missing field). An app that left it out plays none: add it with `npx expo install expo-haptics`.
|
|
47
|
+
|
|
46
48
|
## 2. Wrap the app in the provider
|
|
47
49
|
|
|
48
50
|
```tsx
|
|
@@ -19,6 +19,8 @@ export function BrissotoPayProvider({ url = DEFAULT_URL, appearance, children, }
|
|
|
19
19
|
/** Sheets opened, so each gets a fresh one. */
|
|
20
20
|
const [count, setCount] = useState(0);
|
|
21
21
|
const busy = useRef(false);
|
|
22
|
+
/** Outcomes the payer felt, so no sheet of this app plays one twice. */
|
|
23
|
+
const [felt] = useState(() => new Set());
|
|
22
24
|
const presentPayment = useCallback(({ paymentId }) => {
|
|
23
25
|
if (busy.current) {
|
|
24
26
|
return Promise.reject(new Error('A payment sheet is already open.'));
|
|
@@ -35,5 +37,5 @@ export function BrissotoPayProvider({ url = DEFAULT_URL, appearance, children, }
|
|
|
35
37
|
setRequest({ ...closing, open: false });
|
|
36
38
|
closing.resolve(result);
|
|
37
39
|
};
|
|
38
|
-
return (_jsxs(PaymentSheetContext, { value: sheet, children: [children, request && (_jsx(PaymentSheetModal, { connection: connection, appearance: appearance, request: request, onClose: (result) => close(request, result) }, count))] }));
|
|
40
|
+
return (_jsxs(PaymentSheetContext, { value: sheet, children: [children, request && (_jsx(PaymentSheetModal, { connection: connection, appearance: appearance, request: request, felt: felt, onClose: (result) => close(request, result) }, count))] }));
|
|
39
41
|
}
|
|
@@ -6,4 +6,4 @@ import type { PaymentSheetModalProps } from '../models/sheet.interface.js';
|
|
|
6
6
|
* while a prompt waits on the phone asks first, and resolves `pending`.
|
|
7
7
|
* Android's back on the details goes back to the methods instead.
|
|
8
8
|
*/
|
|
9
|
-
export declare function PaymentSheetModal({ connection, appearance, request, onClose, }: PaymentSheetModalProps): import("react").JSX.Element;
|
|
9
|
+
export declare function PaymentSheetModal({ connection, appearance, request, onClose, felt, }: PaymentSheetModalProps): import("react").JSX.Element;
|
|
@@ -18,7 +18,7 @@ import { SheetContent } from "./SheetContent.js";
|
|
|
18
18
|
* while a prompt waits on the phone asks first, and resolves `pending`.
|
|
19
19
|
* Android's back on the details goes back to the methods instead.
|
|
20
20
|
*/
|
|
21
|
-
export function PaymentSheetModal({ connection, appearance, request, onClose, }) {
|
|
21
|
+
export function PaymentSheetModal({ connection, appearance, request, onClose, felt, }) {
|
|
22
22
|
const payment = useCheckoutPayment(connection, request.open ? request.paymentId : null);
|
|
23
23
|
const { view } = payment;
|
|
24
24
|
const scheme = useColorScheme();
|
|
@@ -92,7 +92,7 @@ export function PaymentSheetModal({ connection, appearance, request, onClose, })
|
|
|
92
92
|
], children: _jsx(View, { style: [styles.stage, { paddingTop: motion.topGap }], children: _jsxs(KeyboardAvoidingView, { behavior: "padding", style: styles.sheet, children: [_jsx(View, { testID: "payment-sheet-floor", style: [
|
|
93
93
|
styles.floor,
|
|
94
94
|
{ backgroundColor: theme.colors.surface },
|
|
95
|
-
] }), _jsx(IntlProvider, { locale: lang, messages: MESSAGES[lang], timeZone: TIME_ZONE, children: _jsx(SheetThemeContext, { value: theme, children: _jsx(SheetContent, { payment: payment, fontsReady: fontsLoaded || fontsError !== null, deviceLocale: deviceLocale, ipCountry: ipCountry, onClose: close, dragHandlers: motion.dragHandlers, backRef: backRef }) }) })] }) }) })] }) }));
|
|
95
|
+
] }), _jsx(IntlProvider, { locale: lang, messages: MESSAGES[lang], timeZone: TIME_ZONE, children: _jsx(SheetThemeContext, { value: theme, children: _jsx(SheetContent, { payment: payment, felt: felt, fontsReady: fontsLoaded || fontsError !== null, deviceLocale: deviceLocale, ipCountry: ipCountry, onClose: close, dragHandlers: motion.dragHandlers, backRef: backRef }) }) })] }) }) })] }) }));
|
|
96
96
|
}
|
|
97
97
|
const styles = StyleSheet.create({
|
|
98
98
|
screen: { flex: 1 },
|
|
@@ -4,5 +4,6 @@ import type { SheetButtonProps } from '../models/sheet.interface.js';
|
|
|
4
4
|
* outlined for the rest, plain (a text button, no box) for a quiet second
|
|
5
5
|
* choice, a link in the app colour for a quiet action in a line of its own.
|
|
6
6
|
* In the sheet's foot, the app's appearance sets their height, corner and label.
|
|
7
|
+
* A main action taps lightly as the finger lands, or plays its own haptic.
|
|
7
8
|
*/
|
|
8
|
-
export declare function SheetButton({ label, onPress, variant, busy, disabled, inactive, }: SheetButtonProps): import("react").JSX.Element;
|
|
9
|
+
export declare function SheetButton({ label, onPress, variant, busy, disabled, inactive, haptic: ownHaptic, }: SheetButtonProps): import("react").JSX.Element;
|
|
@@ -3,15 +3,17 @@ import { ActivityIndicator, StyleSheet, TouchableOpacity } from 'react-native';
|
|
|
3
3
|
import { CheckoutButtonVariantEnum } from "../checkout-core/models/checkout.enum.js";
|
|
4
4
|
import { useSheetButtonLook } from "../hooks/use-sheet-foot.js";
|
|
5
5
|
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
6
|
-
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
6
|
+
import { FigtreeEnum, SheetHapticEnum } from "../models/sheet.enum.js";
|
|
7
|
+
import { playHaptic } from "../services/haptics.service.js";
|
|
7
8
|
import { SheetText } from "./SheetText.js";
|
|
8
9
|
/**
|
|
9
10
|
* The sheet's buttons: filled in the app colour for the main action,
|
|
10
11
|
* outlined for the rest, plain (a text button, no box) for a quiet second
|
|
11
12
|
* choice, a link in the app colour for a quiet action in a line of its own.
|
|
12
13
|
* In the sheet's foot, the app's appearance sets their height, corner and label.
|
|
14
|
+
* A main action taps lightly as the finger lands, or plays its own haptic.
|
|
13
15
|
*/
|
|
14
|
-
export function SheetButton({ label, onPress, variant = CheckoutButtonVariantEnum.PRIMARY, busy = false, disabled = false, inactive = false, }) {
|
|
16
|
+
export function SheetButton({ label, onPress, variant = CheckoutButtonVariantEnum.PRIMARY, busy = false, disabled = false, inactive = false, haptic: ownHaptic, }) {
|
|
15
17
|
const { colors, brand } = useSheetTheme();
|
|
16
18
|
const primary = variant === CheckoutButtonVariantEnum.PRIMARY;
|
|
17
19
|
const link = variant === CheckoutButtonVariantEnum.LINK;
|
|
@@ -19,7 +21,10 @@ export function SheetButton({ label, onPress, variant = CheckoutButtonVariantEnu
|
|
|
19
21
|
const look = useSheetButtonLook(variant);
|
|
20
22
|
const ink = look.labelColor ?? (primary ? 'white' : link ? brand : colors.ink);
|
|
21
23
|
const off = disabled || busy;
|
|
22
|
-
|
|
24
|
+
const haptic = ownHaptic ?? (primary ? SheetHapticEnum.TAP : undefined);
|
|
25
|
+
return (_jsxs(TouchableOpacity, { onPress: onPress,
|
|
26
|
+
// Felt as the finger lands, as a native button; an inactive one says no instead.
|
|
27
|
+
onPressIn: haptic && !inactive ? () => playHaptic(haptic) : undefined, disabled: off, activeOpacity: 0.8, accessibilityRole: "button", accessibilityState: { disabled: off, busy },
|
|
23
28
|
// A text button is short: its tap reaches a little past it.
|
|
24
29
|
hitSlop: link ? 6 : plain ? 8 : undefined, style: [
|
|
25
30
|
link
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SheetContentProps } from '../models/sheet.interface.js';
|
|
2
2
|
/** The sheet's screens, driven by the shared checkout controller. */
|
|
3
|
-
export declare function SheetContent({ payment, fontsReady, deviceLocale, ipCountry, onClose, dragHandlers, backRef, }: SheetContentProps): import("react").JSX.Element;
|
|
3
|
+
export declare function SheetContent({ payment, felt, fontsReady, deviceLocale, ipCountry, onClose, dragHandlers, backRef, }: SheetContentProps): import("react").JSX.Element;
|
|
@@ -7,10 +7,13 @@ import { CURRENCY_LABEL, FLOW_TRAITS, } from "../checkout-core/models/checkout.c
|
|
|
7
7
|
import { CheckoutScreenEnum, CheckoutStepEnum, CheckoutTabEnum, TerminalKindEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
8
8
|
import { formatAmount } from "../checkout-core/models/checkout.money.utils.js";
|
|
9
9
|
import { useNativePlatform } from "../hooks/use-native-platform.js";
|
|
10
|
+
import { useOutcomeHaptic } from "../hooks/use-outcome-haptic.js";
|
|
10
11
|
import { useSheetResize } from "../hooks/use-sheet-resize.js";
|
|
11
12
|
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
12
13
|
import { useStoreTab } from "../hooks/use-store-tab.js";
|
|
13
14
|
import { SHEET_TOP_RADIUS } from "../models/sheet.constants.js";
|
|
15
|
+
import { outcomeHapticOf } from "../models/sheet.utils.js";
|
|
16
|
+
import { SheetHapticEnum } from "../models/sheet.enum.js";
|
|
14
17
|
import { SheetButton } from "./SheetButton.js";
|
|
15
18
|
import { SheetFailed } from "./SheetFailed.js";
|
|
16
19
|
import { SheetForm } from "./SheetForm.js";
|
|
@@ -31,7 +34,7 @@ const TERMINAL_KIND = {
|
|
|
31
34
|
[CheckoutScreenEnum.LOCKED]: TerminalKindEnum.LOCKED,
|
|
32
35
|
};
|
|
33
36
|
/** The sheet's screens, driven by the shared checkout controller. */
|
|
34
|
-
export function SheetContent({ payment, fontsReady, deviceLocale, ipCountry, onClose, dragHandlers, backRef, }) {
|
|
37
|
+
export function SheetContent({ payment, felt, fontsReady, deviceLocale, ipCountry, onClose, dragHandlers, backRef, }) {
|
|
35
38
|
const t = useTranslations('checkout');
|
|
36
39
|
const { colors } = useSheetTheme();
|
|
37
40
|
const clues = useMemo(() => ({ ipCountry: ipCountry ?? null, languages: [deviceLocale] }), [ipCountry, deviceLocale]);
|
|
@@ -65,6 +68,7 @@ export function SheetContent({ payment, fontsReady, deviceLocale, ipCountry, onC
|
|
|
65
68
|
(screen === CheckoutScreenEnum.FORM ||
|
|
66
69
|
screen === CheckoutScreenEnum.SUBMITTING);
|
|
67
70
|
const canGoBack = onForm && details && !busy;
|
|
71
|
+
useOutcomeHaptic(outcomeHapticOf(loading, failed, screen, view), felt);
|
|
68
72
|
const back = actions.backToMethods;
|
|
69
73
|
// Android's back on the details goes back a step, not out of the sheet.
|
|
70
74
|
useEffect(() => {
|
|
@@ -114,13 +118,13 @@ export function SheetContent({ payment, fontsReady, deviceLocale, ipCountry, onC
|
|
|
114
118
|
else {
|
|
115
119
|
body = (_jsx(SheetLayout, { foot: onStore ? (_jsx(SheetButton, { label: busy
|
|
116
120
|
? t('sending')
|
|
117
|
-
: t('sheet.store_pay', { price: store.offer.displayPrice }), busy: busy, onPress: store.buy })) : derived.selected &&
|
|
121
|
+
: t('sheet.store_pay', { price: store.offer.displayPrice }), busy: busy, haptic: SheetHapticEnum.PRESS, onPress: store.buy })) : derived.selected &&
|
|
118
122
|
FLOW_TRAITS[derived.selected.flow].ownButton ? (_jsx(SheetPaypalButton, { busy: busy, onPress: actions.pay })) : details ? (_jsx(SheetButton, { label: busy
|
|
119
123
|
? t('sending')
|
|
120
124
|
: t('pay_plain', {
|
|
121
125
|
amount: formatAmount(derived.total.amount, derived.total.currency),
|
|
122
126
|
currency: CURRENCY_LABEL[derived.total.currency],
|
|
123
|
-
}), busy: busy, inactive: !derived.canPay, onPress: actions.pay })) : (_jsx(SheetButton, { label: t('continue'), inactive: !derived.selected, onPress: actions.continueToDetails })), children: _jsxs(SheetStep, { core: core, phoneRef: phoneRef, children: [(!details || paysOwnWay) && (_jsx(SheetSummary, { total: derived.total, storePrice: onStore ? store.offer.displayPrice : undefined })), _jsx(SheetForm, { core: core, phoneRef: phoneRef, cardFields: cardFields, store: store })] }) }));
|
|
127
|
+
}), busy: busy, inactive: !derived.canPay, haptic: SheetHapticEnum.PRESS, onPress: actions.pay })) : (_jsx(SheetButton, { label: t('continue'), inactive: !derived.selected, onPress: actions.continueToDetails })), children: _jsxs(SheetStep, { core: core, phoneRef: phoneRef, children: [(!details || paysOwnWay) && (_jsx(SheetSummary, { total: derived.total, storePrice: onStore ? store.offer.displayPrice : undefined })), _jsx(SheetForm, { core: core, phoneRef: phoneRef, cardFields: cardFields, store: store })] }) }));
|
|
124
128
|
}
|
|
125
129
|
return (_jsxs(View, { testID: "payment-sheet", accessibilityViewIsModal: true, onAccessibilityEscape: onClose, style: [styles.sheet, { backgroundColor: colors.surface }], children: [_jsx(SheetHeader, { view: view, loading: loading, onClose: onClose, onBack: canGoBack ? back : undefined, dragHandlers: dragHandlers }), body, _jsx(SheetToast, { toast: core.toast })] }));
|
|
126
130
|
}
|
|
@@ -4,7 +4,8 @@ import { useTranslations } from 'use-intl';
|
|
|
4
4
|
import { PAYPAL_BUTTON_COLORS } from "../checkout-core/models/checkout.constants.js";
|
|
5
5
|
import { CheckoutButtonVariantEnum } from "../checkout-core/models/checkout.enum.js";
|
|
6
6
|
import { useSheetButtonLook } from "../hooks/use-sheet-foot.js";
|
|
7
|
-
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
7
|
+
import { FigtreeEnum, SheetHapticEnum } from "../models/sheet.enum.js";
|
|
8
|
+
import { playHaptic } from "../services/haptics.service.js";
|
|
8
9
|
import { PAYPAL_WORDMARK, PAYPAL_WORDMARK_SIZE, } from "../models/sheet.constants.js";
|
|
9
10
|
import { SheetText } from "./SheetText.js";
|
|
10
11
|
/**
|
|
@@ -15,7 +16,9 @@ import { SheetText } from "./SheetText.js";
|
|
|
15
16
|
export function SheetPaypalButton({ busy, onPress }) {
|
|
16
17
|
const t = useTranslations('checkout');
|
|
17
18
|
const look = useSheetButtonLook(CheckoutButtonVariantEnum.PRIMARY);
|
|
18
|
-
return (_jsx(TouchableOpacity, { onPress: onPress,
|
|
19
|
+
return (_jsx(TouchableOpacity, { onPress: onPress,
|
|
20
|
+
// Money is committed here: a firm press, as Pay.
|
|
21
|
+
onPressIn: () => playHaptic(SheetHapticEnum.PRESS), disabled: busy, activeOpacity: 0.8, accessibilityRole: "button", accessibilityLabel: t('pay_with_method', { method: 'PayPal' }), accessibilityState: { disabled: busy, busy }, style: [
|
|
19
22
|
styles.button,
|
|
20
23
|
{
|
|
21
24
|
minHeight: look.height,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { AppState, Share } from 'react-native';
|
|
3
3
|
import { ProviderWindowEndEnum } from "../checkout-core/models/checkout.enum.js";
|
|
4
|
+
import { SheetHapticEnum } from "../models/sheet.enum.js";
|
|
4
5
|
import { cardFieldsSubmit } from "../models/sheet.utils.js";
|
|
6
|
+
import { playHaptic } from "../services/haptics.service.js";
|
|
5
7
|
import { readPhoneStore } from "../services/store.service.js";
|
|
6
8
|
import { closeProviderWindow, openProviderWindow, } from "../services/provider-window.service.js";
|
|
7
9
|
/** Opens the in-app browser on a provider's window once its start gave the link; ends when the browser shuts. */
|
|
@@ -52,8 +54,11 @@ export function useNativePlatform(onLeave, phoneField) {
|
|
|
52
54
|
},
|
|
53
55
|
// Pay is pressed on the form, where a picked card always shows its page.
|
|
54
56
|
submitCard: () => cardPage.current.injectJavaScript(cardFieldsSubmit()),
|
|
55
|
-
// A wrong number on Pay: the keyboard comes up on it.
|
|
56
|
-
onPhoneRejected: () =>
|
|
57
|
+
// A wrong number on Pay: felt as an error, the keyboard comes up on it.
|
|
58
|
+
onPhoneRejected: () => {
|
|
59
|
+
playHaptic(SheetHapticEnum.ERROR);
|
|
60
|
+
phoneField.current?.focus();
|
|
61
|
+
},
|
|
57
62
|
phoneStore: () => readPhoneStore(),
|
|
58
63
|
// Nothing blocks a browser here: it opens once the link is known.
|
|
59
64
|
// The return page tells the gateway: the browser only closes.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SheetOutcome } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Plays the haptic of the outcome the sheet shows (`undefined` while it
|
|
4
|
+
* loads) each time it turns to a new one, and an outcome the app already
|
|
5
|
+
* felt (`felt`, by its key) never again: a payment paid while its sheet was
|
|
6
|
+
* closed is felt as it opens, once. A phone not in front waits for the
|
|
7
|
+
* payer to be back: a payment paid while away is felt on return.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useOutcomeHaptic(outcome: SheetOutcome | null | undefined, felt: Set<string>): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { AppState } from 'react-native';
|
|
3
|
+
import { AppStateEnum } from "../models/sheet.enum.js";
|
|
4
|
+
import { playHaptic } from "../services/haptics.service.js";
|
|
5
|
+
/**
|
|
6
|
+
* Plays the haptic of the outcome the sheet shows (`undefined` while it
|
|
7
|
+
* loads) each time it turns to a new one, and an outcome the app already
|
|
8
|
+
* felt (`felt`, by its key) never again: a payment paid while its sheet was
|
|
9
|
+
* closed is felt as it opens, once. A phone not in front waits for the
|
|
10
|
+
* payer to be back: a payment paid while away is felt on return.
|
|
11
|
+
*/
|
|
12
|
+
export function useOutcomeHaptic(outcome, felt) {
|
|
13
|
+
const loading = outcome === undefined;
|
|
14
|
+
const haptic = outcome?.haptic ?? null;
|
|
15
|
+
const key = outcome?.key ?? null;
|
|
16
|
+
/** The outcome this sheet showed last, by its key, else its haptic. */
|
|
17
|
+
const id = haptic && (key ?? haptic);
|
|
18
|
+
const lastShown = useRef(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (loading || id === lastShown.current)
|
|
21
|
+
return undefined;
|
|
22
|
+
lastShown.current = id;
|
|
23
|
+
if (!haptic || (key && felt.has(key)))
|
|
24
|
+
return undefined;
|
|
25
|
+
const play = () => {
|
|
26
|
+
if (key)
|
|
27
|
+
felt.add(key);
|
|
28
|
+
playHaptic(haptic);
|
|
29
|
+
};
|
|
30
|
+
// Inactive too: a notification pulled down, a call, the store's own sheet.
|
|
31
|
+
const away = AppState.currentState === AppStateEnum.BACKGROUND ||
|
|
32
|
+
AppState.currentState === AppStateEnum.INACTIVE;
|
|
33
|
+
if (!away) {
|
|
34
|
+
play();
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const subscription = AppState.addEventListener('change', (state) => {
|
|
38
|
+
if (state !== AppStateEnum.ACTIVE)
|
|
39
|
+
return;
|
|
40
|
+
subscription.remove();
|
|
41
|
+
play();
|
|
42
|
+
});
|
|
43
|
+
return () => subscription.remove();
|
|
44
|
+
}, [loading, id, haptic, key, felt]);
|
|
45
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Animated } from 'react-native';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* A side-to-side shake each time `count` grows, felt as an error as it
|
|
4
|
+
* starts: the offset to put in a `translateX`.
|
|
5
|
+
*/
|
|
3
6
|
export declare function useShake(count: number): Animated.Value;
|
package/dist/hooks/use-shake.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Animated, Easing } from 'react-native';
|
|
3
3
|
import { SHAKE_MS, SHAKE_OFFSETS } from "../models/sheet.constants.js";
|
|
4
|
-
|
|
4
|
+
import { SheetHapticEnum } from "../models/sheet.enum.js";
|
|
5
|
+
import { playHaptic } from "../services/haptics.service.js";
|
|
6
|
+
/**
|
|
7
|
+
* A side-to-side shake each time `count` grows, felt as an error as it
|
|
8
|
+
* starts: the offset to put in a `translateX`.
|
|
9
|
+
*/
|
|
5
10
|
export function useShake(count) {
|
|
6
11
|
const [offset] = useState(() => new Animated.Value(0));
|
|
12
|
+
/** The count last seen: a field shown again on an old count stays still, one back at 0 shakes again. */
|
|
13
|
+
const seen = useRef(count);
|
|
7
14
|
useEffect(() => {
|
|
8
|
-
|
|
15
|
+
const grew = count > seen.current;
|
|
16
|
+
seen.current = count;
|
|
17
|
+
if (!grew)
|
|
9
18
|
return;
|
|
19
|
+
playHaptic(SheetHapticEnum.ERROR);
|
|
10
20
|
Animated.sequence(SHAKE_OFFSETS.map((toValue) => Animated.timing(offset, {
|
|
11
21
|
toValue,
|
|
12
22
|
duration: SHAKE_MS / SHAKE_OFFSETS.length,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { LayoutAnimationConfig } from 'react-native';
|
|
2
|
-
import type { StoreTabSpec } from './sheet.interface.js';
|
|
2
|
+
import type { ImpactFeel, NotificationFeel, StoreTabSpec } from './sheet.interface.js';
|
|
3
3
|
import en from '../checkout-core/messages/en.js';
|
|
4
|
-
import { CheckoutThemeEnum, PhoneStoreEnum } from '../checkout-core/models/checkout.enum.js';
|
|
4
|
+
import { CheckoutScreenEnum, CheckoutThemeEnum, PhoneStoreEnum } from '../checkout-core/models/checkout.enum.js';
|
|
5
5
|
import { LangEnum, ProviderLogoEnum } from '../checkout-core/models/domain.enum.js';
|
|
6
|
-
import { FigtreeEnum } from './sheet.enum.js';
|
|
6
|
+
import { FigtreeEnum, SheetHapticEnum } from './sheet.enum.js';
|
|
7
7
|
/** The production backend: Live and Test payments alike. */
|
|
8
8
|
export declare const DEFAULT_URL = "https://api-pay.brissoto.com";
|
|
9
9
|
/** Each store as its tab shows it: its own name (a brand, in every language) and tile. */
|
|
@@ -139,3 +139,16 @@ export declare const PAYPAL_WORDMARK_SIZE: {
|
|
|
139
139
|
height: number;
|
|
140
140
|
width: number;
|
|
141
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* How each haptic feels. iOS: Apple's notification feedback for an outcome
|
|
144
|
+
* or a refused Pay, a light impact for a button, a medium one where money is
|
|
145
|
+
* committed. Android: its own constants, which follow the touch feedback
|
|
146
|
+
* setting; the iOS call stands in where the phone is older than Confirm and
|
|
147
|
+
* Reject.
|
|
148
|
+
*/
|
|
149
|
+
export declare const HAPTIC_FEELS: Record<SheetHapticEnum, NotificationFeel | ImpactFeel>;
|
|
150
|
+
/**
|
|
151
|
+
* The haptic of each outcome screen: paid, or a failure the payer did not
|
|
152
|
+
* choose. A cancelled payment, chosen, plays none.
|
|
153
|
+
*/
|
|
154
|
+
export declare const OUTCOME_HAPTICS: Partial<Record<CheckoutScreenEnum, SheetHapticEnum>>;
|
|
@@ -34,10 +34,10 @@ import logoVisa from '../../assets/logos/visa.png';
|
|
|
34
34
|
import logoWave from '../../assets/logos/wave.png';
|
|
35
35
|
import { LayoutAnimation } from 'react-native';
|
|
36
36
|
import en from "../checkout-core/messages/en.js";
|
|
37
|
-
import { CheckoutThemeEnum, PhoneStoreEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
37
|
+
import { CheckoutScreenEnum, CheckoutThemeEnum, PhoneStoreEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
38
38
|
import fr from "../checkout-core/messages/fr.js";
|
|
39
39
|
import { LangEnum, ProviderLogoEnum, } from "../checkout-core/models/domain.enum.js";
|
|
40
|
-
import { FigtreeEnum } from "./sheet.enum.js";
|
|
40
|
+
import { AndroidHapticEnum, FigtreeEnum, HapticImpactEnum, HapticNotificationEnum, SheetHapticEnum, } from "./sheet.enum.js";
|
|
41
41
|
/** The production backend: Live and Test payments alike. */
|
|
42
42
|
export const DEFAULT_URL = 'https://api-pay.brissoto.com';
|
|
43
43
|
/** Each store as its tab shows it: its own name (a brand, in every language) and tile. */
|
|
@@ -221,3 +221,44 @@ export const SHEET_BADGE_RADIUS = 12;
|
|
|
221
221
|
export const PAYPAL_WORDMARK = paypalWordmark;
|
|
222
222
|
/** The wordmark's height on the button, and its width for that height. */
|
|
223
223
|
export const PAYPAL_WORDMARK_SIZE = { height: 20, width: 71 };
|
|
224
|
+
/**
|
|
225
|
+
* How each haptic feels. iOS: Apple's notification feedback for an outcome
|
|
226
|
+
* or a refused Pay, a light impact for a button, a medium one where money is
|
|
227
|
+
* committed. Android: its own constants, which follow the touch feedback
|
|
228
|
+
* setting; the iOS call stands in where the phone is older than Confirm and
|
|
229
|
+
* Reject.
|
|
230
|
+
*/
|
|
231
|
+
export const HAPTIC_FEELS = {
|
|
232
|
+
[SheetHapticEnum.SUCCESS]: {
|
|
233
|
+
notification: HapticNotificationEnum.SUCCESS,
|
|
234
|
+
android: AndroidHapticEnum.CONFIRM,
|
|
235
|
+
},
|
|
236
|
+
[SheetHapticEnum.WARNING]: {
|
|
237
|
+
notification: HapticNotificationEnum.WARNING,
|
|
238
|
+
android: AndroidHapticEnum.LONG_PRESS,
|
|
239
|
+
},
|
|
240
|
+
[SheetHapticEnum.ERROR]: {
|
|
241
|
+
notification: HapticNotificationEnum.ERROR,
|
|
242
|
+
android: AndroidHapticEnum.REJECT,
|
|
243
|
+
},
|
|
244
|
+
[SheetHapticEnum.TAP]: {
|
|
245
|
+
impact: HapticImpactEnum.LIGHT,
|
|
246
|
+
android: AndroidHapticEnum.KEYBOARD_TAP,
|
|
247
|
+
},
|
|
248
|
+
[SheetHapticEnum.PRESS]: {
|
|
249
|
+
impact: HapticImpactEnum.MEDIUM,
|
|
250
|
+
android: AndroidHapticEnum.VIRTUAL_KEY,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* The haptic of each outcome screen: paid, or a failure the payer did not
|
|
255
|
+
* choose. A cancelled payment, chosen, plays none.
|
|
256
|
+
*/
|
|
257
|
+
export const OUTCOME_HAPTICS = {
|
|
258
|
+
[CheckoutScreenEnum.SUCCESS]: SheetHapticEnum.SUCCESS,
|
|
259
|
+
[CheckoutScreenEnum.REDIRECT]: SheetHapticEnum.SUCCESS,
|
|
260
|
+
[CheckoutScreenEnum.FAILED]: SheetHapticEnum.ERROR,
|
|
261
|
+
[CheckoutScreenEnum.EXPIRED]: SheetHapticEnum.ERROR,
|
|
262
|
+
[CheckoutScreenEnum.LOCKED]: SheetHapticEnum.ERROR,
|
|
263
|
+
[CheckoutScreenEnum.INVALID]: SheetHapticEnum.ERROR,
|
|
264
|
+
};
|
|
@@ -44,3 +44,45 @@ export declare enum WebBrowserResultEnum {
|
|
|
44
44
|
CANCEL = "cancel",
|
|
45
45
|
DISMISS = "dismiss"
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* What the payer feels: an outcome (paid, a failure, a wait), a refused
|
|
49
|
+
* Pay, or a button pressed (a light tap, a firmer one where money is
|
|
50
|
+
* committed).
|
|
51
|
+
*/
|
|
52
|
+
export declare enum SheetHapticEnum {
|
|
53
|
+
SUCCESS = "success",
|
|
54
|
+
WARNING = "warning",
|
|
55
|
+
ERROR = "error",
|
|
56
|
+
TAP = "tap",
|
|
57
|
+
PRESS = "press"
|
|
58
|
+
}
|
|
59
|
+
/** iOS's notification feedback. Values are expo-haptics' `NotificationFeedbackType`. */
|
|
60
|
+
export declare enum HapticNotificationEnum {
|
|
61
|
+
SUCCESS = "success",
|
|
62
|
+
WARNING = "warning",
|
|
63
|
+
ERROR = "error"
|
|
64
|
+
}
|
|
65
|
+
/** iOS's impact feedback. Values are expo-haptics' `ImpactFeedbackStyle`. */
|
|
66
|
+
export declare enum HapticImpactEnum {
|
|
67
|
+
LIGHT = "light",
|
|
68
|
+
MEDIUM = "medium"
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Android's own haptic constants, which follow the phone's touch feedback
|
|
72
|
+
* setting. Confirm and Reject need Android 11. Values are expo-haptics'
|
|
73
|
+
* `AndroidHaptics`.
|
|
74
|
+
*/
|
|
75
|
+
export declare enum AndroidHapticEnum {
|
|
76
|
+
CONFIRM = "confirm",
|
|
77
|
+
REJECT = "reject",
|
|
78
|
+
LONG_PRESS = "long-press",
|
|
79
|
+
KEYBOARD_TAP = "keyboard-tap",
|
|
80
|
+
VIRTUAL_KEY = "virtual-key"
|
|
81
|
+
}
|
|
82
|
+
/** Where the app stands, as React Native says it. Values are its `AppStateStatus`. */
|
|
83
|
+
export declare enum AppStateEnum {
|
|
84
|
+
ACTIVE = "active",
|
|
85
|
+
BACKGROUND = "background",
|
|
86
|
+
/** iOS: still on screen, not in front (a notification pulled down, a call). */
|
|
87
|
+
INACTIVE = "inactive"
|
|
88
|
+
}
|
|
@@ -51,3 +51,50 @@ export var WebBrowserResultEnum;
|
|
|
51
51
|
WebBrowserResultEnum["CANCEL"] = "cancel";
|
|
52
52
|
WebBrowserResultEnum["DISMISS"] = "dismiss";
|
|
53
53
|
})(WebBrowserResultEnum || (WebBrowserResultEnum = {}));
|
|
54
|
+
/**
|
|
55
|
+
* What the payer feels: an outcome (paid, a failure, a wait), a refused
|
|
56
|
+
* Pay, or a button pressed (a light tap, a firmer one where money is
|
|
57
|
+
* committed).
|
|
58
|
+
*/
|
|
59
|
+
export var SheetHapticEnum;
|
|
60
|
+
(function (SheetHapticEnum) {
|
|
61
|
+
SheetHapticEnum["SUCCESS"] = "success";
|
|
62
|
+
SheetHapticEnum["WARNING"] = "warning";
|
|
63
|
+
SheetHapticEnum["ERROR"] = "error";
|
|
64
|
+
SheetHapticEnum["TAP"] = "tap";
|
|
65
|
+
SheetHapticEnum["PRESS"] = "press";
|
|
66
|
+
})(SheetHapticEnum || (SheetHapticEnum = {}));
|
|
67
|
+
/** iOS's notification feedback. Values are expo-haptics' `NotificationFeedbackType`. */
|
|
68
|
+
export var HapticNotificationEnum;
|
|
69
|
+
(function (HapticNotificationEnum) {
|
|
70
|
+
HapticNotificationEnum["SUCCESS"] = "success";
|
|
71
|
+
HapticNotificationEnum["WARNING"] = "warning";
|
|
72
|
+
HapticNotificationEnum["ERROR"] = "error";
|
|
73
|
+
})(HapticNotificationEnum || (HapticNotificationEnum = {}));
|
|
74
|
+
/** iOS's impact feedback. Values are expo-haptics' `ImpactFeedbackStyle`. */
|
|
75
|
+
export var HapticImpactEnum;
|
|
76
|
+
(function (HapticImpactEnum) {
|
|
77
|
+
HapticImpactEnum["LIGHT"] = "light";
|
|
78
|
+
HapticImpactEnum["MEDIUM"] = "medium";
|
|
79
|
+
})(HapticImpactEnum || (HapticImpactEnum = {}));
|
|
80
|
+
/**
|
|
81
|
+
* Android's own haptic constants, which follow the phone's touch feedback
|
|
82
|
+
* setting. Confirm and Reject need Android 11. Values are expo-haptics'
|
|
83
|
+
* `AndroidHaptics`.
|
|
84
|
+
*/
|
|
85
|
+
export var AndroidHapticEnum;
|
|
86
|
+
(function (AndroidHapticEnum) {
|
|
87
|
+
AndroidHapticEnum["CONFIRM"] = "confirm";
|
|
88
|
+
AndroidHapticEnum["REJECT"] = "reject";
|
|
89
|
+
AndroidHapticEnum["LONG_PRESS"] = "long-press";
|
|
90
|
+
AndroidHapticEnum["KEYBOARD_TAP"] = "keyboard-tap";
|
|
91
|
+
AndroidHapticEnum["VIRTUAL_KEY"] = "virtual-key";
|
|
92
|
+
})(AndroidHapticEnum || (AndroidHapticEnum = {}));
|
|
93
|
+
/** Where the app stands, as React Native says it. Values are its `AppStateStatus`. */
|
|
94
|
+
export var AppStateEnum;
|
|
95
|
+
(function (AppStateEnum) {
|
|
96
|
+
AppStateEnum["ACTIVE"] = "active";
|
|
97
|
+
AppStateEnum["BACKGROUND"] = "background";
|
|
98
|
+
/** iOS: still on screen, not in front (a notification pulled down, a call). */
|
|
99
|
+
AppStateEnum["INACTIVE"] = "inactive";
|
|
100
|
+
})(AppStateEnum || (AppStateEnum = {}));
|
|
@@ -4,7 +4,7 @@ import type { WebView } from 'react-native-webview';
|
|
|
4
4
|
import type { CheckoutButtonVariantEnum, PhoneStoreEnum, TerminalKindEnum } from '../checkout-core/models/checkout.enum.js';
|
|
5
5
|
import type { LangEnum, ProviderLogoEnum } from '../checkout-core/models/domain.enum.js';
|
|
6
6
|
import type { CardFieldsMessage, CheckoutColors, CheckoutCore, CheckoutToast, CheckoutConnection, CheckoutPayment, CheckoutPlatform, CheckoutView, Price } from '../checkout-core/models/checkout.interface.js';
|
|
7
|
-
import type { FigtreeEnum, SheetIconEnum, StoreProductTypeEnum, WebBrowserResultEnum } from './sheet.enum.js';
|
|
7
|
+
import type { AndroidHapticEnum, FigtreeEnum, HapticImpactEnum, HapticNotificationEnum, SheetHapticEnum, SheetIconEnum, StoreProductTypeEnum, WebBrowserResultEnum } from './sheet.enum.js';
|
|
8
8
|
/**
|
|
9
9
|
* How the sheet ended. `closed`: the payer closed it with the payment still
|
|
10
10
|
* open. A hint only: ship on `payment.paid` from the webhook or `getPayment`.
|
|
@@ -80,9 +80,13 @@ export interface PaymentSheetModalProps {
|
|
|
80
80
|
appearance?: BrissotoPayAppearance;
|
|
81
81
|
request: SheetRequest;
|
|
82
82
|
onClose: (result: PaymentSheetResult) => void;
|
|
83
|
+
/** The outcomes this app's sheets made the payer feel, by `SheetOutcome.key`. */
|
|
84
|
+
felt: Set<string>;
|
|
83
85
|
}
|
|
84
86
|
export interface SheetContentProps {
|
|
85
87
|
payment: CheckoutPayment;
|
|
88
|
+
/** The outcomes this app's sheets made the payer feel, by `SheetOutcome.key`. */
|
|
89
|
+
felt: Set<string>;
|
|
86
90
|
/** Fonts still loading: the sheet shows its skeleton. */
|
|
87
91
|
fontsReady: boolean;
|
|
88
92
|
deviceLocale: string;
|
|
@@ -225,6 +229,8 @@ export interface SheetButtonProps {
|
|
|
225
229
|
disabled?: boolean;
|
|
226
230
|
/** Looks off but still answers: Pay says what is missing. */
|
|
227
231
|
inactive?: boolean;
|
|
232
|
+
/** Felt as the finger lands (a light tap for a main action), unless inactive: the refusal is felt instead. */
|
|
233
|
+
haptic?: SheetHapticEnum;
|
|
228
234
|
}
|
|
229
235
|
/** A brand tile: the provider's logo, square, at one of `LOGO_SIZE`. */
|
|
230
236
|
export interface SheetLogoProps {
|
|
@@ -468,3 +474,30 @@ export interface StoreSheetAttempt {
|
|
|
468
474
|
export interface SheetStoreTabProps {
|
|
469
475
|
store: StoreTab;
|
|
470
476
|
}
|
|
477
|
+
/** A feel on Android: its own constant, or the iOS call where the phone has none. */
|
|
478
|
+
export interface AndroidFeel {
|
|
479
|
+
android: AndroidHapticEnum;
|
|
480
|
+
}
|
|
481
|
+
/** An outcome or a refusal: iOS's notification feedback. */
|
|
482
|
+
export interface NotificationFeel extends AndroidFeel {
|
|
483
|
+
notification: HapticNotificationEnum;
|
|
484
|
+
}
|
|
485
|
+
/** A button: iOS's impact feedback. */
|
|
486
|
+
export interface ImpactFeel extends AndroidFeel {
|
|
487
|
+
impact: HapticImpactEnum;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* The outcome a sheet shows and its haptic. `key` names the payment and
|
|
491
|
+
* attempt it is for, so an app feels it once however many sheets show it;
|
|
492
|
+
* null when there is none to name (a payment that could not load).
|
|
493
|
+
*/
|
|
494
|
+
export interface SheetOutcome {
|
|
495
|
+
haptic: SheetHapticEnum;
|
|
496
|
+
key: string | null;
|
|
497
|
+
}
|
|
498
|
+
/** The part of expo-haptics the sheet calls, an optional dependency. */
|
|
499
|
+
export interface ExpoHaptics {
|
|
500
|
+
notificationAsync: (type: HapticNotificationEnum) => Promise<void>;
|
|
501
|
+
impactAsync: (style: HapticImpactEnum) => Promise<void>;
|
|
502
|
+
performAndroidHapticsAsync: (type: AndroidHapticEnum) => Promise<void>;
|
|
503
|
+
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { CheckoutButtonVariantEnum, CheckoutThemeEnum, StoreSheetOutcomeEnum } from '../checkout-core/models/checkout.enum.js';
|
|
1
|
+
import { CheckoutButtonVariantEnum, CheckoutScreenEnum, CheckoutThemeEnum, StoreSheetOutcomeEnum } from '../checkout-core/models/checkout.enum.js';
|
|
2
2
|
import { LangEnum } from '../checkout-core/models/domain.enum.js';
|
|
3
3
|
import type { CountryEnum } from '../checkout-core/models/domain.enum.js';
|
|
4
4
|
import type { CardFieldsMessage, CheckoutView } from '../checkout-core/models/checkout.interface.js';
|
|
5
|
-
import type { BrissotoPayAppearance, CardFieldsAddress, PaymentSheetResult, SheetButtonLook, StorePurchase, StoreSheetAttempt, UnreportedPurchase } from './sheet.interface.js';
|
|
5
|
+
import type { BrissotoPayAppearance, CardFieldsAddress, PaymentSheetResult, SheetButtonLook, SheetOutcome, StorePurchase, StoreSheetAttempt, UnreportedPurchase } from './sheet.interface.js';
|
|
6
|
+
/**
|
|
7
|
+
* The outcome a sheet shows, for its haptic: `undefined` while it loads,
|
|
8
|
+
* null on a screen with none. A payment that could not load, or is not
|
|
9
|
+
* there, is an error with nothing to name it by; a store purchase waiting
|
|
10
|
+
* for someone's approval (Ask to Buy), a warning.
|
|
11
|
+
*/
|
|
12
|
+
export declare function outcomeHapticOf(loading: boolean, failed: boolean, screen: CheckoutScreenEnum, view: CheckoutView | null | undefined): SheetOutcome | null | undefined;
|
|
6
13
|
/** The payment's language, else the device's when the sheet speaks it, else English. */
|
|
7
14
|
export declare function sheetLanguage(payment: LangEnum | null, deviceLocale: string): LangEnum;
|
|
8
15
|
/** The payment's theme, else the device's scheme. */
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
import { CardFieldsMessageEnum, CheckoutButtonVariantEnum, CheckoutPaymentStatusEnum, CheckoutThemeEnum, PayRefusalEnum, StoreSheetOutcomeEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
1
|
+
import { CardFieldsMessageEnum, CheckoutButtonVariantEnum, CheckoutPaymentStatusEnum, CheckoutScreenEnum, CheckoutThemeEnum, PayRefusalEnum, StoreSheetOutcomeEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
2
2
|
import { AttemptStatusEnum, LangEnum, } from "../checkout-core/models/domain.enum.js";
|
|
3
|
-
import { BANK_PAGE_VIEWPORT, BUTTON_MAX_FONT_SIZE, BUTTON_MIN_FONT_SIZE, BUTTON_MIN_HEIGHT, PAGE_VIEWPORT, PILL_ROW_HEIGHT, SHEET_BUTTON_LOOK, SHEET_DIM_OPACITY, SHEET_FLICK_SPEED, SHEET_SWIPE_DISTANCE, STORE_TOKEN_PATTERN, } from "./sheet.constants.js";
|
|
4
|
-
import { StoreErrorCodeEnum, StorePurchaseStateEnum } from "./sheet.enum.js";
|
|
3
|
+
import { BANK_PAGE_VIEWPORT, BUTTON_MAX_FONT_SIZE, BUTTON_MIN_FONT_SIZE, BUTTON_MIN_HEIGHT, OUTCOME_HAPTICS, PAGE_VIEWPORT, PILL_ROW_HEIGHT, SHEET_BUTTON_LOOK, SHEET_DIM_OPACITY, SHEET_FLICK_SPEED, SHEET_SWIPE_DISTANCE, STORE_TOKEN_PATTERN, } from "./sheet.constants.js";
|
|
4
|
+
import { SheetHapticEnum, StoreErrorCodeEnum, StorePurchaseStateEnum, } from "./sheet.enum.js";
|
|
5
|
+
/**
|
|
6
|
+
* The outcome a sheet shows, for its haptic: `undefined` while it loads,
|
|
7
|
+
* null on a screen with none. A payment that could not load, or is not
|
|
8
|
+
* there, is an error with nothing to name it by; a store purchase waiting
|
|
9
|
+
* for someone's approval (Ask to Buy), a warning.
|
|
10
|
+
*/
|
|
11
|
+
export function outcomeHapticOf(loading, failed, screen, view) {
|
|
12
|
+
if (loading)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (failed || !view)
|
|
15
|
+
return { haptic: SheetHapticEnum.ERROR, key: null };
|
|
16
|
+
const { attempt } = view;
|
|
17
|
+
const haptic = screen === CheckoutScreenEnum.WAITING && attempt?.pendingAtStore
|
|
18
|
+
? SheetHapticEnum.WARNING
|
|
19
|
+
: OUTCOME_HAPTICS[screen];
|
|
20
|
+
if (!haptic)
|
|
21
|
+
return null;
|
|
22
|
+
return { haptic, key: `${view.id}:${attempt?.reference ?? ''}:${haptic}` };
|
|
23
|
+
}
|
|
5
24
|
/** The payment's language, else the device's when the sheet speaks it, else English. */
|
|
6
25
|
export function sheetLanguage(payment, deviceLocale) {
|
|
7
26
|
if (payment)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SheetHapticEnum } from '../models/sheet.enum.js';
|
|
2
|
+
import type { ExpoHaptics } from '../models/sheet.interface.js';
|
|
3
|
+
/**
|
|
4
|
+
* expo-haptics, an optional dependency: null when the app has none. The
|
|
5
|
+
* require sits right in its `try`: Metro then bundles an app without it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function installedExpoHaptics(): ExpoHaptics | null;
|
|
8
|
+
/**
|
|
9
|
+
* Plays one haptic and forgets it. Without expo-haptics, off a phone, or
|
|
10
|
+
* when the phone's engine fails, nothing is felt and the payment goes on.
|
|
11
|
+
*/
|
|
12
|
+
export declare function playHaptic(haptic: SheetHapticEnum, load?: () => ExpoHaptics | null): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { HAPTIC_FEELS } from "../models/sheet.constants.js";
|
|
3
|
+
/**
|
|
4
|
+
* expo-haptics, an optional dependency: null when the app has none. The
|
|
5
|
+
* require sits right in its `try`: Metro then bundles an app without it.
|
|
6
|
+
*/
|
|
7
|
+
export function installedExpoHaptics() {
|
|
8
|
+
try {
|
|
9
|
+
return require('expo-haptics');
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** A notification or an impact: iOS's own call, and Android's stand-in through the vibrator. */
|
|
16
|
+
const notificationOrImpact = (haptics, feel) => 'notification' in feel
|
|
17
|
+
? haptics.notificationAsync(feel.notification)
|
|
18
|
+
: haptics.impactAsync(feel.impact);
|
|
19
|
+
/**
|
|
20
|
+
* Plays one haptic and forgets it. Without expo-haptics, off a phone, or
|
|
21
|
+
* when the phone's engine fails, nothing is felt and the payment goes on.
|
|
22
|
+
*/
|
|
23
|
+
export function playHaptic(haptic, load = installedExpoHaptics) {
|
|
24
|
+
if (Platform.OS !== 'ios' && Platform.OS !== 'android')
|
|
25
|
+
return;
|
|
26
|
+
const haptics = load();
|
|
27
|
+
if (!haptics)
|
|
28
|
+
return;
|
|
29
|
+
const feel = HAPTIC_FEELS[haptic];
|
|
30
|
+
// In a promise: an expo-haptics too old for a call throws, and is caught.
|
|
31
|
+
const started = Promise.resolve();
|
|
32
|
+
const played = Platform.OS === 'ios'
|
|
33
|
+
? started.then(() => notificationOrImpact(haptics, feel))
|
|
34
|
+
: started
|
|
35
|
+
.then(() => haptics.performAndroidHapticsAsync(feel.android))
|
|
36
|
+
// Older than the constant, phone or expo-haptics: the vibrator stands in.
|
|
37
|
+
.catch(() => notificationOrImpact(haptics, feel));
|
|
38
|
+
played.catch(() => undefined);
|
|
39
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ExpoWebBrowser } from '../models/sheet.interface.js';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* expo-web-browser, an optional dependency: throws when the app has none.
|
|
4
|
+
* The require sits right in its `try`: Metro then bundles an app without it.
|
|
5
|
+
*/
|
|
3
6
|
export declare function installedWebBrowser(): ExpoWebBrowser;
|
|
4
7
|
/**
|
|
5
8
|
* Opens a provider window on `url`, PayPal's or a bank redirect's bank (ADR 0014): an in-app browser (expo-web-browser), else
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { AppState, Linking } from 'react-native';
|
|
2
2
|
import { WebBrowserResultEnum } from "../models/sheet.enum.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* expo-web-browser, an optional dependency: throws when the app has none.
|
|
5
|
+
* The require sits right in its `try`: Metro then bundles an app without it.
|
|
6
|
+
*/
|
|
4
7
|
export function installedWebBrowser() {
|
|
5
|
-
|
|
8
|
+
try {
|
|
9
|
+
return require('expo-web-browser');
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new Error('expo-web-browser is not installed');
|
|
13
|
+
}
|
|
6
14
|
}
|
|
7
15
|
/**
|
|
8
16
|
* Opens a provider window on `url`, PayPal's or a bank redirect's bank (ADR 0014): an in-app browser (expo-web-browser), else
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { PhoneStoreEnum } from '../checkout-core/models/checkout.enum.js';
|
|
2
2
|
import type { PhoneStore } from '../checkout-core/models/checkout.interface.js';
|
|
3
3
|
import type { ExpoIap, StoreOffer, StorePurchase, StorePurchaseError, StoreSheetAttempt } from '../models/sheet.interface.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* expo-iap, an optional dependency: throws when the app has none. The
|
|
6
|
+
* require sits right in its `try`: Metro then bundles an app without it.
|
|
7
|
+
*/
|
|
5
8
|
export declare function installedExpoIap(): ExpoIap;
|
|
6
9
|
/** This phone's store: the App Store on an iPhone, Google Play on Android, none elsewhere. */
|
|
7
10
|
export declare const phoneStoreOf: () => PhoneStoreEnum | null;
|
|
@@ -3,9 +3,17 @@ import { PhoneStoreEnum } from "../checkout-core/models/checkout.enum.js";
|
|
|
3
3
|
import { STORE_COUNTRY_TIMEOUT_MS } from "../models/sheet.constants.js";
|
|
4
4
|
import { StoreProductStatusEnum, StoreProductTypeEnum, } from "../models/sheet.enum.js";
|
|
5
5
|
import { answerWithin } from "../models/sheet.utils.js";
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* expo-iap, an optional dependency: throws when the app has none. The
|
|
8
|
+
* require sits right in its `try`: Metro then bundles an app without it.
|
|
9
|
+
*/
|
|
7
10
|
export function installedExpoIap() {
|
|
8
|
-
|
|
11
|
+
try {
|
|
12
|
+
return require('expo-iap');
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new Error('expo-iap is not installed');
|
|
16
|
+
}
|
|
9
17
|
}
|
|
10
18
|
const STORE_OF_PLATFORM = {
|
|
11
19
|
ios: PhoneStoreEnum.APP_STORE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brissoto/pay-react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Brissoto Pay for Expo and React Native apps: the payment sheet.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -34,13 +34,17 @@
|
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"convex": "^1.48.0",
|
|
36
36
|
"expo-font": "*",
|
|
37
|
+
"expo-haptics": "*",
|
|
37
38
|
"expo-iap": ">=4.7.0",
|
|
39
|
+
"expo-web-browser": "*",
|
|
38
40
|
"react": "*",
|
|
39
41
|
"react-native": "*",
|
|
40
|
-
"react-native-webview": "*"
|
|
41
|
-
"expo-web-browser": "*"
|
|
42
|
+
"react-native-webview": "*"
|
|
42
43
|
},
|
|
43
44
|
"peerDependenciesMeta": {
|
|
45
|
+
"expo-haptics": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
44
48
|
"expo-iap": {
|
|
45
49
|
"optional": true
|
|
46
50
|
},
|
|
@@ -61,6 +65,7 @@
|
|
|
61
65
|
"expo": "~58.0.22",
|
|
62
66
|
"expo-dev-client": "~58.0.18",
|
|
63
67
|
"expo-font": "~58.0.11",
|
|
68
|
+
"expo-haptics": "~58.0.0",
|
|
64
69
|
"expo-iap": "^6.4.3",
|
|
65
70
|
"expo-status-bar": "~58.0.4",
|
|
66
71
|
"expo-web-browser": "~58.0.7",
|