@brissoto/pay-react-native 0.0.0-stage → 1.5.0
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/LICENSE +21 -0
- package/README.md +181 -2
- package/assets/brand/paypal-wordmark.png +0 -0
- package/assets/fonts/Figtree-Bold.ttf +0 -0
- package/assets/fonts/Figtree-ExtraBold.ttf +0 -0
- package/assets/fonts/Figtree-Medium.ttf +0 -0
- package/assets/fonts/Figtree-Regular.ttf +0 -0
- package/assets/fonts/Figtree-SemiBold.ttf +0 -0
- package/assets/fonts/OFL.txt +93 -0
- package/assets/logos/airtel.png +0 -0
- package/assets/logos/app-store.png +0 -0
- package/assets/logos/apple-pay.png +0 -0
- package/assets/logos/at.png +0 -0
- package/assets/logos/bancontact.png +0 -0
- package/assets/logos/card.png +0 -0
- package/assets/logos/cb.png +0 -0
- package/assets/logos/celtiis.png +0 -0
- package/assets/logos/eps.png +0 -0
- package/assets/logos/feexpay.png +0 -0
- package/assets/logos/google-pay.png +0 -0
- package/assets/logos/google-play.png +0 -0
- package/assets/logos/iapkit.png +0 -0
- package/assets/logos/ideal.png +0 -0
- package/assets/logos/mastercard.png +0 -0
- package/assets/logos/mixx.png +0 -0
- package/assets/logos/moov.png +0 -0
- package/assets/logos/mtn.png +0 -0
- package/assets/logos/mybank.png +0 -0
- package/assets/logos/nexus.png +0 -0
- package/assets/logos/orange.png +0 -0
- package/assets/logos/pawapay.png +0 -0
- package/assets/logos/paypal.png +0 -0
- package/assets/logos/telecel.png +0 -0
- package/assets/logos/tnm.png +0 -0
- package/assets/logos/visa.png +0 -0
- package/assets/logos/vodacom.png +0 -0
- package/assets/logos/wave.png +0 -0
- package/dist/checkout-core/hooks/use-checkout-controller.d.ts +9 -0
- package/dist/checkout-core/hooks/use-checkout-controller.js +563 -0
- package/dist/checkout-core/hooks/use-checkout-payment.d.ts +9 -0
- package/dist/checkout-core/hooks/use-checkout-payment.js +136 -0
- package/dist/checkout-core/hooks/use-checkout-timers.d.ts +15 -0
- package/dist/checkout-core/hooks/use-checkout-timers.js +44 -0
- package/dist/checkout-core/hooks/use-phone-number.d.ts +7 -0
- package/dist/checkout-core/hooks/use-phone-number.js +82 -0
- package/dist/checkout-core/messages/en.d.ts +302 -0
- package/dist/checkout-core/messages/en.js +301 -0
- package/dist/checkout-core/messages/fr.d.ts +4 -0
- package/dist/checkout-core/messages/fr.js +302 -0
- package/dist/checkout-core/models/checkout.card.utils.d.ts +7 -0
- package/dist/checkout-core/models/checkout.card.utils.js +25 -0
- package/dist/checkout-core/models/checkout.constants.d.ts +101 -0
- package/dist/checkout-core/models/checkout.constants.js +339 -0
- package/dist/checkout-core/models/checkout.country.utils.d.ts +17 -0
- package/dist/checkout-core/models/checkout.country.utils.js +45 -0
- package/dist/checkout-core/models/checkout.enum.d.ts +233 -0
- package/dist/checkout-core/models/checkout.enum.js +259 -0
- package/dist/checkout-core/models/checkout.fetch.utils.d.ts +6 -0
- package/dist/checkout-core/models/checkout.fetch.utils.js +22 -0
- package/dist/checkout-core/models/checkout.interface.d.ts +698 -0
- package/dist/checkout-core/models/checkout.interface.js +1 -0
- package/dist/checkout-core/models/checkout.money.utils.d.ts +7 -0
- package/dist/checkout-core/models/checkout.money.utils.js +21 -0
- package/dist/checkout-core/models/checkout.phone.utils.d.ts +33 -0
- package/dist/checkout-core/models/checkout.phone.utils.js +159 -0
- package/dist/checkout-core/models/checkout.view.utils.d.ts +77 -0
- package/dist/checkout-core/models/checkout.view.utils.js +331 -0
- package/dist/checkout-core/models/domain.enum.d.ts +106 -0
- package/dist/checkout-core/models/domain.enum.js +113 -0
- package/dist/components/BrissotoPayProvider.d.ts +8 -0
- package/dist/components/BrissotoPayProvider.js +39 -0
- package/dist/components/PaymentSheetModal.d.ts +9 -0
- package/dist/components/PaymentSheetModal.js +106 -0
- package/dist/components/SheetBone.d.ts +3 -0
- package/dist/components/SheetBone.js +12 -0
- package/dist/components/SheetButton.d.ts +7 -0
- package/dist/components/SheetButton.js +47 -0
- package/dist/components/SheetCardFields.d.ts +10 -0
- package/dist/components/SheetCardFields.js +86 -0
- package/dist/components/SheetChosenMethod.d.ts +3 -0
- package/dist/components/SheetChosenMethod.js +60 -0
- package/dist/components/SheetCodeField.d.ts +8 -0
- package/dist/components/SheetCodeField.js +98 -0
- package/dist/components/SheetContent.d.ts +3 -0
- package/dist/components/SheetContent.js +133 -0
- package/dist/components/SheetDial.d.ts +7 -0
- package/dist/components/SheetDial.js +36 -0
- package/dist/components/SheetFailed.d.ts +3 -0
- package/dist/components/SheetFailed.js +44 -0
- package/dist/components/SheetForm.d.ts +8 -0
- package/dist/components/SheetForm.js +141 -0
- package/dist/components/SheetGrabber.d.ts +2 -0
- package/dist/components/SheetGrabber.js +17 -0
- package/dist/components/SheetHeader.d.ts +7 -0
- package/dist/components/SheetHeader.js +83 -0
- package/dist/components/SheetIcon.d.ts +3 -0
- package/dist/components/SheetIcon.js +78 -0
- package/dist/components/SheetLayout.d.ts +11 -0
- package/dist/components/SheetLayout.js +63 -0
- package/dist/components/SheetLogo.d.ts +3 -0
- package/dist/components/SheetLogo.js +20 -0
- package/dist/components/SheetMessage.d.ts +3 -0
- package/dist/components/SheetMessage.js +15 -0
- package/dist/components/SheetMethodCard.d.ts +3 -0
- package/dist/components/SheetMethodCard.js +71 -0
- package/dist/components/SheetNameField.d.ts +7 -0
- package/dist/components/SheetNameField.js +48 -0
- package/dist/components/SheetPaypalButton.d.ts +3 -0
- package/dist/components/SheetPaypalButton.js +23 -0
- package/dist/components/SheetPhoneField.d.ts +3 -0
- package/dist/components/SheetPhoneField.js +59 -0
- package/dist/components/SheetPillSelect.d.ts +7 -0
- package/dist/components/SheetPillSelect.js +134 -0
- package/dist/components/SheetRow.d.ts +3 -0
- package/dist/components/SheetRow.js +28 -0
- package/dist/components/SheetSimulator.d.ts +6 -0
- package/dist/components/SheetSimulator.js +40 -0
- package/dist/components/SheetSkeleton.d.ts +5 -0
- package/dist/components/SheetSkeleton.js +23 -0
- package/dist/components/SheetStep.d.ts +6 -0
- package/dist/components/SheetStep.js +21 -0
- package/dist/components/SheetStoreTab.d.ts +7 -0
- package/dist/components/SheetStoreTab.js +27 -0
- package/dist/components/SheetSuccess.d.ts +3 -0
- package/dist/components/SheetSuccess.js +51 -0
- package/dist/components/SheetSummary.d.ts +3 -0
- package/dist/components/SheetSummary.js +32 -0
- package/dist/components/SheetTerminal.d.ts +6 -0
- package/dist/components/SheetTerminal.js +31 -0
- package/dist/components/SheetText.d.ts +5 -0
- package/dist/components/SheetText.js +27 -0
- package/dist/components/SheetToast.d.ts +7 -0
- package/dist/components/SheetToast.js +71 -0
- package/dist/components/SheetWaiting.d.ts +7 -0
- package/dist/components/SheetWaiting.js +88 -0
- package/dist/hooks/use-native-platform.d.ts +10 -0
- package/dist/hooks/use-native-platform.js +71 -0
- package/dist/hooks/use-payment-sheet.d.ts +4 -0
- package/dist/hooks/use-payment-sheet.js +10 -0
- package/dist/hooks/use-shake.d.ts +3 -0
- package/dist/hooks/use-shake.js +18 -0
- package/dist/hooks/use-sheet-motion.d.ts +7 -0
- package/dist/hooks/use-sheet-motion.js +62 -0
- package/dist/hooks/use-sheet-resize.d.ts +6 -0
- package/dist/hooks/use-sheet-resize.js +15 -0
- package/dist/hooks/use-sheet-room.d.ts +4 -0
- package/dist/hooks/use-sheet-room.js +8 -0
- package/dist/hooks/use-sheet-theme.d.ts +4 -0
- package/dist/hooks/use-sheet-theme.js +12 -0
- package/dist/hooks/use-step-slide.d.ts +16 -0
- package/dist/hooks/use-step-slide.js +50 -0
- package/dist/hooks/use-store-recovery.d.ts +9 -0
- package/dist/hooks/use-store-recovery.js +50 -0
- package/dist/hooks/use-store-tab.d.ts +11 -0
- package/dist/hooks/use-store-tab.js +112 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/models/sheet.constants.d.ts +125 -0
- package/dist/models/sheet.constants.js +204 -0
- package/dist/models/sheet.enum.d.ts +46 -0
- package/dist/models/sheet.enum.js +53 -0
- package/dist/models/sheet.interface.d.ts +426 -0
- package/dist/models/sheet.interface.js +1 -0
- package/dist/models/sheet.utils.d.ts +68 -0
- package/dist/models/sheet.utils.js +214 -0
- package/dist/services/checkout.service.d.ts +15 -0
- package/dist/services/checkout.service.js +96 -0
- package/dist/services/provider-window.service.d.ts +13 -0
- package/dist/services/provider-window.service.js +53 -0
- package/dist/services/store.service.d.ts +36 -0
- package/dist/services/store.service.js +107 -0
- package/package.json +73 -4
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { useTranslations } from 'use-intl';
|
|
4
|
+
import { FLOW_TRAITS, SIMULATOR_NO_ANSWER_SUFFIX, } from "../checkout-core/models/checkout.constants.js";
|
|
5
|
+
import { simulatorOutcomesOf } from "../checkout-core/models/checkout.view.utils.js";
|
|
6
|
+
import { PRESSED_OPACITY } from "../models/sheet.constants.js";
|
|
7
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
8
|
+
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
9
|
+
import { SheetText } from "./SheetText.js";
|
|
10
|
+
/**
|
|
11
|
+
* On a test payment the Simulator took, the tester plays the payer's phone,
|
|
12
|
+
* or makes the provider misbehave. Never on a live payment.
|
|
13
|
+
*/
|
|
14
|
+
export function SheetSimulator({ core }) {
|
|
15
|
+
const t = useTranslations('checkout');
|
|
16
|
+
const { colors } = useSheetTheme();
|
|
17
|
+
const traits = FLOW_TRAITS[core.view.attempt.flow];
|
|
18
|
+
const outcomes = simulatorOutcomesOf(core.view.attempt);
|
|
19
|
+
return (_jsxs(View, { accessibilityLabel: t('simulator.title'), style: [
|
|
20
|
+
styles.panel,
|
|
21
|
+
{ backgroundColor: colors.warnSoft, borderColor: colors.warnLine },
|
|
22
|
+
], children: [_jsx(SheetText, { weight: FigtreeEnum.EXTRA_BOLD, size: 12, color: colors.warnInk2, style: styles.title, children: t('simulator.title') }), _jsxs(SheetText, { paragraph: true, size: 13, color: colors.warnInk2, style: styles.body, children: [t('simulator.body'), traits.prompt &&
|
|
23
|
+
` ${t('simulator.no_answer', { suffix: SIMULATOR_NO_ANSWER_SUFFIX })}`] }), _jsx(View, { style: styles.outcomes, children: outcomes.map((outcome) => (_jsx(TouchableOpacity, { onPress: () => core.actions.simulate(outcome), activeOpacity: PRESSED_OPACITY, accessibilityRole: "button", style: [
|
|
24
|
+
styles.outcome,
|
|
25
|
+
{ backgroundColor: colors.surface, borderColor: colors.warnLine },
|
|
26
|
+
], children: _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, size: 13, children: t(`simulator.${outcome}`) }) }, outcome))) })] }));
|
|
27
|
+
}
|
|
28
|
+
const styles = StyleSheet.create({
|
|
29
|
+
panel: { borderWidth: 1, borderRadius: 12, padding: 14, marginTop: 18 },
|
|
30
|
+
title: { letterSpacing: 0.7, textTransform: 'uppercase' },
|
|
31
|
+
body: { marginTop: 4, marginBottom: 12 },
|
|
32
|
+
outcomes: { flexDirection: 'row', flexWrap: 'wrap', gap: 8 },
|
|
33
|
+
outcome: {
|
|
34
|
+
minHeight: 36,
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
borderWidth: 1,
|
|
37
|
+
borderRadius: 8,
|
|
38
|
+
paddingHorizontal: 12,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useTranslations } from 'use-intl';
|
|
4
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
5
|
+
import { SheetBone } from "./SheetBone.js";
|
|
6
|
+
/**
|
|
7
|
+
* The summary while the payment loads, bone for bone: its label and the
|
|
8
|
+
* amount.
|
|
9
|
+
*/
|
|
10
|
+
export function SheetSkeleton() {
|
|
11
|
+
const t = useTranslations('checkout');
|
|
12
|
+
const { colors } = useSheetTheme();
|
|
13
|
+
return (_jsxs(View, { accessibilityRole: "progressbar", accessibilityLabel: t('loading'), style: [styles.summary, { borderColor: colors.line }], children: [_jsx(SheetBone, { width: 96, height: 13 }), _jsx(View, { style: styles.amount, children: _jsx(SheetBone, { width: 168, height: 34 }) })] }));
|
|
14
|
+
}
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
summary: {
|
|
17
|
+
paddingHorizontal: 18,
|
|
18
|
+
paddingVertical: 16,
|
|
19
|
+
borderBottomWidth: 1,
|
|
20
|
+
gap: 8,
|
|
21
|
+
},
|
|
22
|
+
amount: { paddingVertical: 2 },
|
|
23
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SheetStepProps } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* The step of the form shown, sliding in once the payer moves; on to the
|
|
4
|
+
* number, the keyboard comes up at once.
|
|
5
|
+
*/
|
|
6
|
+
export declare function SheetStep({ core, phoneRef, children }: SheetStepProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { Animated } from 'react-native';
|
|
4
|
+
import { CheckoutStepEnum, CheckoutTabEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
5
|
+
import { useStepSlide } from "../hooks/use-step-slide.js";
|
|
6
|
+
/**
|
|
7
|
+
* The step of the form shown, sliding in once the payer moves; on to the
|
|
8
|
+
* number, the keyboard comes up at once.
|
|
9
|
+
*/
|
|
10
|
+
export function SheetStep({ core, phoneRef, children }) {
|
|
11
|
+
const { step } = core.derived;
|
|
12
|
+
const slide = useStepSlide(step);
|
|
13
|
+
const typing = slide.moved &&
|
|
14
|
+
step === CheckoutStepEnum.DETAILS &&
|
|
15
|
+
core.ui.tab === CheckoutTabEnum.MOBILE_MONEY;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (typing)
|
|
18
|
+
phoneRef.current?.focus();
|
|
19
|
+
}, [typing, phoneRef]);
|
|
20
|
+
return (_jsx(Animated.View, { style: slide.style, children: children }, step));
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SheetStoreTabProps } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* The store tab: this phone's store, alone and picked, at the price it
|
|
4
|
+
* charges, who sends the receipt, and the refund consent line, which the
|
|
5
|
+
* gateway learns was shown. Its button is the sheet's own.
|
|
6
|
+
*/
|
|
7
|
+
export declare function SheetStoreTab({ store }: SheetStoreTabProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { StyleSheet, View } from 'react-native';
|
|
4
|
+
import { useTranslations } from 'use-intl';
|
|
5
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
6
|
+
import { STORE_TABS } from "../models/sheet.constants.js";
|
|
7
|
+
import { SheetMethodCard } from "./SheetMethodCard.js";
|
|
8
|
+
import { SheetText } from "./SheetText.js";
|
|
9
|
+
/**
|
|
10
|
+
* The store tab: this phone's store, alone and picked, at the price it
|
|
11
|
+
* charges, who sends the receipt, and the refund consent line, which the
|
|
12
|
+
* gateway learns was shown. Its button is the sheet's own.
|
|
13
|
+
*/
|
|
14
|
+
export function SheetStoreTab({ store }) {
|
|
15
|
+
const t = useTranslations('checkout');
|
|
16
|
+
const { colors } = useSheetTheme();
|
|
17
|
+
const { name, logo } = STORE_TABS[store.store];
|
|
18
|
+
const price = store.offer.displayPrice;
|
|
19
|
+
const { onConsentShown } = store;
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
onConsentShown();
|
|
22
|
+
}, [onConsentShown]);
|
|
23
|
+
return (_jsxs(View, { style: styles.tab, children: [_jsx(SheetMethodCard, { logo: logo, name: name, sub: price, muted: false, checked: true, alone: true }), _jsx(SheetText, { paragraph: true, size: 13, color: colors.muted, children: t('sheet.store_body', { price, store: name }) }), _jsx(SheetText, { paragraph: true, size: 12, color: colors.muted, children: t('sheet.store_refund_consent', { store: name }) })] }));
|
|
24
|
+
}
|
|
25
|
+
const styles = StyleSheet.create({
|
|
26
|
+
tab: { gap: 12, marginTop: 12 },
|
|
27
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SheetClosingProps } from '../models/sheet.interface.js';
|
|
2
|
+
/** Paid: the check, the amount and the receipt; Done closes, as the countdown on it does by itself. */
|
|
3
|
+
export declare function SheetSuccess({ core, onClose }: SheetClosingProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useFormatter, useTranslations } from 'use-intl';
|
|
4
|
+
import { CURRENCY_LABEL } from "../checkout-core/models/checkout.constants.js";
|
|
5
|
+
import { cardLabel } from "../checkout-core/models/checkout.card.utils.js";
|
|
6
|
+
import { formatAmount } from "../checkout-core/models/checkout.money.utils.js";
|
|
7
|
+
import { maskE164 } from "../checkout-core/models/checkout.phone.utils.js";
|
|
8
|
+
import { logoOf } from "../checkout-core/models/checkout.view.utils.js";
|
|
9
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
10
|
+
import { FigtreeEnum, SheetIconEnum } from "../models/sheet.enum.js";
|
|
11
|
+
import { SheetButton } from "./SheetButton.js";
|
|
12
|
+
import { SheetIcon } from "./SheetIcon.js";
|
|
13
|
+
import { SheetLayout } from "./SheetLayout.js";
|
|
14
|
+
import { SheetLogo } from "./SheetLogo.js";
|
|
15
|
+
import { SheetRow } from "./SheetRow.js";
|
|
16
|
+
import { SheetText } from "./SheetText.js";
|
|
17
|
+
/** Paid: the check, the amount and the receipt; Done closes, as the countdown on it does by itself. */
|
|
18
|
+
export function SheetSuccess({ core, onClose }) {
|
|
19
|
+
const t = useTranslations('checkout');
|
|
20
|
+
const format = useFormatter();
|
|
21
|
+
const { colors } = useSheetTheme();
|
|
22
|
+
const { view, returnLeft } = core;
|
|
23
|
+
// Only a status check pays a payment: there is always an attempt.
|
|
24
|
+
const attempt = view.attempt;
|
|
25
|
+
return (_jsx(SheetLayout, { foot: _jsx(SheetButton
|
|
26
|
+
// Nothing stops the countdown in the sheet: it always runs here.
|
|
27
|
+
, {
|
|
28
|
+
// Nothing stops the countdown in the sheet: it always runs here.
|
|
29
|
+
label: t('sheet.done_in', { seconds: returnLeft }), onPress: onClose }), children: _jsxs(View, { style: styles.success, children: [_jsx(View, { style: styles.icon, children: _jsx(SheetIcon, { kind: SheetIconEnum.CHECK, color: colors.surface, background: colors.successInk, size: 64 }) }), _jsx(SheetText, { weight: FigtreeEnum.EXTRA_BOLD, size: 22, accessibilityRole: "header", style: [styles.center, styles.title], children: t('success_title') }), _jsxs(View, { style: styles.amountRow, children: [_jsx(SheetText, { weight: FigtreeEnum.EXTRA_BOLD, size: 34, style: styles.amount, children: formatAmount(view.amount, view.currency) }), _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, size: 16, color: colors.ink2, children: CURRENCY_LABEL[view.currency] })] }), _jsx(SheetText, { paragraph: true, color: colors.muted, style: styles.center, children: t('paid_to', { app: view.app.name }) }), _jsxs(View, { style: [styles.rows, { borderColor: colors.line }], children: [_jsxs(SheetRow, { label: t('method'), children: [_jsx(SheetLogo, { logo: logoOf(attempt) }), _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, children: attempt.methodName })] }), attempt.phone && (_jsx(SheetRow, { label: t('number'), children: maskE164(attempt.phone) })), attempt.card && (_jsx(SheetRow, { label: t('card'), children: cardLabel(attempt.card) })), _jsx(SheetRow, { label: t('date'), children: format.dateTime(view.paidAt, {
|
|
30
|
+
day: 'numeric',
|
|
31
|
+
month: 'short',
|
|
32
|
+
year: 'numeric',
|
|
33
|
+
hour: '2-digit',
|
|
34
|
+
minute: '2-digit',
|
|
35
|
+
}) }), _jsx(SheetRow, { label: t('reference'), children: attempt.reference })] })] }) }));
|
|
36
|
+
}
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
|
+
success: { paddingHorizontal: 18, paddingTop: 30 },
|
|
39
|
+
icon: { alignItems: 'center' },
|
|
40
|
+
center: { textAlign: 'center' },
|
|
41
|
+
title: { marginTop: 18, letterSpacing: -0.4 },
|
|
42
|
+
amountRow: {
|
|
43
|
+
flexDirection: 'row',
|
|
44
|
+
alignItems: 'baseline',
|
|
45
|
+
justifyContent: 'center',
|
|
46
|
+
gap: 6,
|
|
47
|
+
marginTop: 6,
|
|
48
|
+
},
|
|
49
|
+
amount: { letterSpacing: -0.85, fontVariant: ['tabular-nums'] },
|
|
50
|
+
rows: { borderTopWidth: 1, marginTop: 22 },
|
|
51
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SheetSummaryProps } from '../models/sheet.interface.js';
|
|
2
|
+
/** The amount to pay, in PayPal's currency while it is picked. The order and its lines stay on the web checkout. */
|
|
3
|
+
export declare function SheetSummary({ total }: SheetSummaryProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useTranslations } from 'use-intl';
|
|
4
|
+
import { CURRENCY_LABEL } from "../checkout-core/models/checkout.constants.js";
|
|
5
|
+
import { formatAmount } from "../checkout-core/models/checkout.money.utils.js";
|
|
6
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
7
|
+
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
8
|
+
import { SheetText } from "./SheetText.js";
|
|
9
|
+
/** The amount to pay, in PayPal's currency while it is picked. The order and its lines stay on the web checkout. */
|
|
10
|
+
export function SheetSummary({ total }) {
|
|
11
|
+
const t = useTranslations('checkout');
|
|
12
|
+
const { colors } = useSheetTheme();
|
|
13
|
+
const { amount, currency } = total;
|
|
14
|
+
return (_jsxs(View, { style: [styles.summary, { borderColor: colors.line }], children: [_jsx(SheetText, { size: 13, color: colors.muted, children: t('total_label') }), _jsxs(View, { style: styles.amountRow, children: [_jsx(SheetText, { weight: FigtreeEnum.EXTRA_BOLD, size: 34, style: styles.amount, children: formatAmount(amount, currency) }), _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, size: 16, color: colors.ink2, children: CURRENCY_LABEL[currency] })] })] }));
|
|
15
|
+
}
|
|
16
|
+
const styles = StyleSheet.create({
|
|
17
|
+
summary: {
|
|
18
|
+
paddingHorizontal: 18,
|
|
19
|
+
paddingVertical: 16,
|
|
20
|
+
borderBottomWidth: 1,
|
|
21
|
+
},
|
|
22
|
+
amountRow: {
|
|
23
|
+
flexDirection: 'row',
|
|
24
|
+
alignItems: 'baseline',
|
|
25
|
+
gap: 6,
|
|
26
|
+
marginTop: 2,
|
|
27
|
+
},
|
|
28
|
+
amount: {
|
|
29
|
+
letterSpacing: -0.85,
|
|
30
|
+
fontVariant: ['tabular-nums'],
|
|
31
|
+
},
|
|
32
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SheetTerminalProps } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* A payment that cannot be paid any more, said plainly, and the way back to
|
|
4
|
+
* the app. One no method could ever take has a single Close.
|
|
5
|
+
*/
|
|
6
|
+
export declare function SheetTerminal({ core, kind, onClose }: SheetTerminalProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslations } from 'use-intl';
|
|
3
|
+
import { TerminalKindEnum } from "../checkout-core/models/checkout.enum.js";
|
|
4
|
+
import { SheetIconEnum } from "../models/sheet.enum.js";
|
|
5
|
+
import { SheetButton } from "./SheetButton.js";
|
|
6
|
+
import { SheetLayout } from "./SheetLayout.js";
|
|
7
|
+
import { SheetMessage } from "./SheetMessage.js";
|
|
8
|
+
const COPY_KEY = {
|
|
9
|
+
[TerminalKindEnum.EXPIRED]: 'expired',
|
|
10
|
+
[TerminalKindEnum.CANCELLED]: 'cancelled',
|
|
11
|
+
[TerminalKindEnum.LOCKED]: 'locked_screen',
|
|
12
|
+
[TerminalKindEnum.NO_METHOD]: 'no_method',
|
|
13
|
+
[TerminalKindEnum.UNAVAILABLE]: 'unavailable_screen',
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A payment that cannot be paid any more, said plainly, and the way back to
|
|
17
|
+
* the app. One no method could ever take has a single Close.
|
|
18
|
+
*/
|
|
19
|
+
export function SheetTerminal({ core, kind, onClose }) {
|
|
20
|
+
const t = useTranslations('checkout');
|
|
21
|
+
const app = core.view.app.name;
|
|
22
|
+
const key = COPY_KEY[kind];
|
|
23
|
+
const locked = kind === TerminalKindEnum.LOCKED;
|
|
24
|
+
const unavailable = kind === TerminalKindEnum.UNAVAILABLE;
|
|
25
|
+
let icon = SheetIconEnum.CLOCK;
|
|
26
|
+
if (locked)
|
|
27
|
+
icon = SheetIconEnum.LOCK;
|
|
28
|
+
else if (unavailable)
|
|
29
|
+
icon = SheetIconEnum.BAN;
|
|
30
|
+
return (_jsx(SheetLayout, { foot: _jsx(SheetButton, { label: unavailable ? t('close') : t('return_to', { app }), onPress: onClose }), children: _jsx(SheetMessage, { title: t(`${key}.title`), body: t(`${key}.body`, { app }), icon: icon, danger: locked }) }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SheetInputProps, SheetTextProps } from '../models/sheet.interface.js';
|
|
2
|
+
/** Every text of the sheet: Figtree, in the sheet's ink unless told otherwise; a paragraph's lines spaced as on the web. */
|
|
3
|
+
export declare function SheetText({ weight, size, color, paragraph, style, ...props }: SheetTextProps): import("react").JSX.Element;
|
|
4
|
+
/** Every field of the sheet: Figtree at 16, so iOS never zooms, in the sheet's ink. */
|
|
5
|
+
export declare function SheetInput({ style, ...props }: SheetInputProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Text, TextInput } from 'react-native';
|
|
3
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
4
|
+
import { PARAGRAPH_LINE_HEIGHT } from "../models/sheet.constants.js";
|
|
5
|
+
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
6
|
+
/** Every text of the sheet: Figtree, in the sheet's ink unless told otherwise; a paragraph's lines spaced as on the web. */
|
|
7
|
+
export function SheetText({ weight = FigtreeEnum.REGULAR, size = 14, color, paragraph = false, style, ...props }) {
|
|
8
|
+
const { colors } = useSheetTheme();
|
|
9
|
+
return (_jsx(Text, { ...props, style: [
|
|
10
|
+
{ fontFamily: weight, fontSize: size, color: color ?? colors.ink },
|
|
11
|
+
paragraph && { lineHeight: Math.round(size * PARAGRAPH_LINE_HEIGHT) },
|
|
12
|
+
style,
|
|
13
|
+
] }));
|
|
14
|
+
}
|
|
15
|
+
/** Every field of the sheet: Figtree at 16, so iOS never zooms, in the sheet's ink. */
|
|
16
|
+
export function SheetInput({ style, ...props }) {
|
|
17
|
+
const { colors } = useSheetTheme();
|
|
18
|
+
return (_jsx(TextInput, { placeholderTextColor: colors.faint, selectionColor: colors.ink, ...props, style: [
|
|
19
|
+
{
|
|
20
|
+
fontFamily: FigtreeEnum.MEDIUM,
|
|
21
|
+
fontSize: 16,
|
|
22
|
+
color: colors.ink,
|
|
23
|
+
fontVariant: ['tabular-nums'],
|
|
24
|
+
},
|
|
25
|
+
style,
|
|
26
|
+
] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SheetToastProps } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* One short message at a time, in a small card at the top of the sheet:
|
|
4
|
+
* the method's logo, else the tone's disc (a check when done, "!" for a
|
|
5
|
+
* problem, "i" to know). As on the web checkout.
|
|
6
|
+
*/
|
|
7
|
+
export declare function SheetToast({ toast }: SheetToastProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { CheckoutToastToneEnum } from "../checkout-core/models/checkout.enum.js";
|
|
4
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
5
|
+
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
6
|
+
import { SheetLogo } from "./SheetLogo.js";
|
|
7
|
+
import { SheetText } from "./SheetText.js";
|
|
8
|
+
/**
|
|
9
|
+
* One short message at a time, in a small card at the top of the sheet:
|
|
10
|
+
* the method's logo, else the tone's disc (a check when done, "!" for a
|
|
11
|
+
* problem, "i" to know). As on the web checkout.
|
|
12
|
+
*/
|
|
13
|
+
export function SheetToast({ toast }) {
|
|
14
|
+
const { colors, dark } = useSheetTheme();
|
|
15
|
+
if (!toast)
|
|
16
|
+
return null;
|
|
17
|
+
const disc = {
|
|
18
|
+
[CheckoutToastToneEnum.SUCCESS]: colors.successInk,
|
|
19
|
+
[CheckoutToastToneEnum.WARNING]: colors.warnInk,
|
|
20
|
+
[CheckoutToastToneEnum.INFO]: colors.muted,
|
|
21
|
+
}[toast.tone];
|
|
22
|
+
return (_jsx(View, { pointerEvents: "none", style: styles.place, children: _jsxs(View, { testID: "sheet-toast", accessibilityLiveRegion: "polite", accessibilityRole: "alert", style: [
|
|
23
|
+
styles.toast,
|
|
24
|
+
{
|
|
25
|
+
backgroundColor: dark ? colors.fill3 : colors.surface,
|
|
26
|
+
borderColor: colors.line3,
|
|
27
|
+
},
|
|
28
|
+
], children: [toast.logo ? (_jsx(SheetLogo, { logo: toast.logo })) : (_jsx(View, { testID: `toast-${toast.tone}`, style: [styles.disc, { backgroundColor: disc }], children: toast.tone === CheckoutToastToneEnum.SUCCESS ? (_jsx(View, { style: styles.check })) : (_jsx(SheetText, { weight: FigtreeEnum.BOLD, size: 12, color: "white", style: styles.glyph, children: toast.tone === CheckoutToastToneEnum.WARNING ? '!' : 'i' })) })), _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, size: 13.5, style: styles.text, children: toast.message })] }) }));
|
|
29
|
+
}
|
|
30
|
+
const styles = StyleSheet.create({
|
|
31
|
+
place: {
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
top: 24,
|
|
34
|
+
left: 18,
|
|
35
|
+
right: 18,
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
},
|
|
38
|
+
toast: {
|
|
39
|
+
flexDirection: 'row',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
gap: 10,
|
|
42
|
+
borderWidth: 1,
|
|
43
|
+
borderRadius: 12,
|
|
44
|
+
paddingVertical: 10,
|
|
45
|
+
paddingLeft: 12,
|
|
46
|
+
paddingRight: 16,
|
|
47
|
+
shadowColor: 'black',
|
|
48
|
+
shadowOpacity: 0.18,
|
|
49
|
+
shadowRadius: 16,
|
|
50
|
+
shadowOffset: { width: 0, height: 8 },
|
|
51
|
+
elevation: 6,
|
|
52
|
+
},
|
|
53
|
+
disc: {
|
|
54
|
+
width: 20,
|
|
55
|
+
height: 20,
|
|
56
|
+
borderRadius: 10,
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
justifyContent: 'center',
|
|
59
|
+
},
|
|
60
|
+
check: {
|
|
61
|
+
width: 5,
|
|
62
|
+
height: 9,
|
|
63
|
+
marginTop: -2,
|
|
64
|
+
borderColor: 'white',
|
|
65
|
+
borderRightWidth: 2,
|
|
66
|
+
borderBottomWidth: 2,
|
|
67
|
+
transform: [{ rotate: '45deg' }],
|
|
68
|
+
},
|
|
69
|
+
glyph: { lineHeight: 14, textAlign: 'center' },
|
|
70
|
+
text: { flexShrink: 1 },
|
|
71
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SheetScreenProps } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Waiting for the payer to approve on their phone: what to do, the method
|
|
4
|
+
* and the clock, Send again once 30 seconds have passed, the network's USSD steps
|
|
5
|
+
* once no new request is left, and another method. It moves on by itself.
|
|
6
|
+
*/
|
|
7
|
+
export declare function SheetWaiting({ core }: SheetScreenProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Pressable, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { useTranslations } from 'use-intl';
|
|
5
|
+
import { FLOW_TRAITS, URGENT_SECONDS, WAIT_SECONDS, } from "../checkout-core/models/checkout.constants.js";
|
|
6
|
+
import { CheckoutButtonVariantEnum, PayRouteEnum, } from "../checkout-core/models/checkout.enum.js";
|
|
7
|
+
import { formatClock, formatMoney, } from "../checkout-core/models/checkout.money.utils.js";
|
|
8
|
+
import { maskE164 } from "../checkout-core/models/checkout.phone.utils.js";
|
|
9
|
+
import { canSendAgain, sendAgainLeftOf, } from "../checkout-core/models/checkout.view.utils.js";
|
|
10
|
+
import { useSheetTheme } from "../hooks/use-sheet-theme.js";
|
|
11
|
+
import { FigtreeEnum } from "../models/sheet.enum.js";
|
|
12
|
+
import { SheetButton } from "./SheetButton.js";
|
|
13
|
+
import { SheetDial } from "./SheetDial.js";
|
|
14
|
+
import { SheetLayout } from "./SheetLayout.js";
|
|
15
|
+
import { SheetRow } from "./SheetRow.js";
|
|
16
|
+
import { SheetSimulator } from "./SheetSimulator.js";
|
|
17
|
+
import { SheetText } from "./SheetText.js";
|
|
18
|
+
const NO_BREAK_SPACE = '\u00a0';
|
|
19
|
+
/**
|
|
20
|
+
* Waiting for the payer to approve on their phone: what to do, the method
|
|
21
|
+
* and the clock, Send again once 30 seconds have passed, the network's USSD steps
|
|
22
|
+
* once no new request is left, and another method. It moves on by itself.
|
|
23
|
+
*/
|
|
24
|
+
export function SheetWaiting({ core }) {
|
|
25
|
+
const t = useTranslations('checkout');
|
|
26
|
+
const { colors, brand } = useSheetTheme();
|
|
27
|
+
const { view, waitLeft, actions } = core;
|
|
28
|
+
const attempt = view.attempt;
|
|
29
|
+
// A payment code or a card needs nothing more from the payer: no prompt to send again.
|
|
30
|
+
// A store's sheet and PayPal's window have no clock: they take their own time.
|
|
31
|
+
const { prompt, clock, providerWindow, route } = FLOW_TRAITS[attempt.flow];
|
|
32
|
+
const store = route === PayRouteEnum.STORE;
|
|
33
|
+
const values = { method: attempt.methodName };
|
|
34
|
+
/** The second of the wait the prompt was last sent at. */
|
|
35
|
+
const [sentAt, setSentAt] = useState(0);
|
|
36
|
+
const sendAgainIn = sendAgainLeftOf(attempt, waitLeft, sentAt);
|
|
37
|
+
// The number never breaks across lines.
|
|
38
|
+
const phone = attempt.phone
|
|
39
|
+
? maskE164(attempt.phone).replace(/ /g, NO_BREAK_SPACE)
|
|
40
|
+
: '';
|
|
41
|
+
return (_jsx(SheetLayout, { foot: _jsxs(_Fragment, { children: [prompt && canSendAgain(attempt) && (_jsx(SheetButton, { variant: CheckoutButtonVariantEnum.SECONDARY, label: sendAgainIn > 0
|
|
42
|
+
? t('send_again_in', { clock: formatClock(sendAgainIn) })
|
|
43
|
+
: t('send_again'), disabled: sendAgainIn > 0, onPress: () => {
|
|
44
|
+
setSentAt(WAIT_SECONDS - waitLeft);
|
|
45
|
+
actions.sendAgain();
|
|
46
|
+
} })), _jsx(Pressable, { onPress: actions.useAnother, accessibilityRole: "button", style: styles.link, children: _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, style: styles.center, children: t('use_another') }) })] }), children: _jsxs(View, { style: styles.waiting, children: [_jsxs(View, { style: styles.pulse, children: [_jsx(View, { style: [styles.halo, styles.outer, { backgroundColor: brand }] }), _jsx(View, { style: [styles.halo, styles.inner, { backgroundColor: brand }] }), _jsx(View, { testID: "icon-phone", style: [styles.phone, { borderColor: brand }], children: _jsx(View, { style: [styles.speaker, { backgroundColor: brand }] }) })] }), _jsx(SheetText, { weight: FigtreeEnum.EXTRA_BOLD, size: 21, accessibilityRole: "header", style: [styles.center, styles.title], children: prompt
|
|
47
|
+
? t('sheet.approve_title')
|
|
48
|
+
: attempt.pendingAtStore
|
|
49
|
+
? t('sheet.store_pending_title')
|
|
50
|
+
: t('checking_title') }), _jsx(SheetText, { paragraph: true, size: 14, color: colors.muted, style: styles.center, children: store
|
|
51
|
+
? t(attempt.pendingAtStore
|
|
52
|
+
? 'sheet.store_pending_body'
|
|
53
|
+
: 'sheet.store_checking', values)
|
|
54
|
+
: attempt.phone
|
|
55
|
+
? prompt
|
|
56
|
+
? t(attempt.manual ? 'sheet.manual_body' : 'sheet.approve_body', { ...values, phone })
|
|
57
|
+
: `${t('checking_with', values)} ${phone}`
|
|
58
|
+
: providerWindow
|
|
59
|
+
? t(`${attempt.payerApproved ? 'checking_window_approved' : 'checking_window'}.${attempt.flow}`)
|
|
60
|
+
: t('checking_card', values) }), clock && (_jsxs(View, { style: [styles.rows, { borderColor: colors.line }], children: [_jsx(SheetRow, { label: attempt.methodName, children: formatMoney(attempt.price.amount, attempt.price.currency) }), _jsx(SheetRow, { label: t('sheet.expires_in'), urgent: waitLeft <= URGENT_SECONDS, children: formatClock(waitLeft) })] })), attempt.simulated && _jsx(SheetSimulator, { core: core }), _jsx(SheetDial, { core: core })] }) }));
|
|
61
|
+
}
|
|
62
|
+
const styles = StyleSheet.create({
|
|
63
|
+
waiting: { paddingHorizontal: 18, paddingTop: 30 },
|
|
64
|
+
pulse: {
|
|
65
|
+
alignSelf: 'center',
|
|
66
|
+
width: 128,
|
|
67
|
+
height: 128,
|
|
68
|
+
alignItems: 'center',
|
|
69
|
+
justifyContent: 'center',
|
|
70
|
+
},
|
|
71
|
+
halo: { position: 'absolute' },
|
|
72
|
+
outer: { width: 128, height: 128, borderRadius: 64, opacity: 0.06 },
|
|
73
|
+
inner: { width: 96, height: 96, borderRadius: 48, opacity: 0.12 },
|
|
74
|
+
phone: {
|
|
75
|
+
width: 24,
|
|
76
|
+
height: 38,
|
|
77
|
+
borderWidth: 2.5,
|
|
78
|
+
borderRadius: 6,
|
|
79
|
+
alignItems: 'center',
|
|
80
|
+
justifyContent: 'flex-end',
|
|
81
|
+
paddingBottom: 4,
|
|
82
|
+
},
|
|
83
|
+
speaker: { width: 6, height: 2.5, borderRadius: 1.25 },
|
|
84
|
+
title: { marginTop: 22, marginBottom: 8, letterSpacing: -0.4 },
|
|
85
|
+
center: { textAlign: 'center' },
|
|
86
|
+
rows: { borderTopWidth: 1, marginTop: 22 },
|
|
87
|
+
link: { minHeight: 40, justifyContent: 'center' },
|
|
88
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { TextInputInstance } from 'react-native';
|
|
3
|
+
import type { NativePlatform } from '../models/sheet.interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* What only the phone does for the checkout core. Leaving for the app is
|
|
6
|
+
* closing the sheet: `presentPayment` resolves, nothing opens the return URL.
|
|
7
|
+
* The card fields page talks through its WebView (`cardFields`). One stable
|
|
8
|
+
* object for the sheet's life.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useNativePlatform(onLeave: () => void, phoneField: RefObject<TextInputInstance | null>): NativePlatform;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { AppState, Share } from 'react-native';
|
|
3
|
+
import { ProviderWindowEndEnum } from "../checkout-core/models/checkout.enum.js";
|
|
4
|
+
import { cardFieldsSubmit } from "../models/sheet.utils.js";
|
|
5
|
+
import { readPhoneStore } from "../services/store.service.js";
|
|
6
|
+
import { closeProviderWindow, openProviderWindow, } from "../services/provider-window.service.js";
|
|
7
|
+
/** Opens the in-app browser on a provider's window once its start gave the link; ends when the browser shuts. */
|
|
8
|
+
async function untilBrowserShut(started) {
|
|
9
|
+
const result = await started;
|
|
10
|
+
if (result?.approvalUrl)
|
|
11
|
+
await openProviderWindow(result.approvalUrl);
|
|
12
|
+
return ProviderWindowEndEnum.CLOSED;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What only the phone does for the checkout core. Leaving for the app is
|
|
16
|
+
* closing the sheet: `presentPayment` resolves, nothing opens the return URL.
|
|
17
|
+
* The card fields page talks through its WebView (`cardFields`). One stable
|
|
18
|
+
* object for the sheet's life.
|
|
19
|
+
*/
|
|
20
|
+
export function useNativePlatform(onLeave, phoneField) {
|
|
21
|
+
const leave = useRef(onLeave);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
leave.current = onLeave;
|
|
24
|
+
}, [onLeave]);
|
|
25
|
+
const cardPage = useRef(null);
|
|
26
|
+
const [cardListeners] = useState(() => new Set());
|
|
27
|
+
const [platform] = useState(() => ({
|
|
28
|
+
onReturn: (listener) => {
|
|
29
|
+
const subscription = AppState.addEventListener('change', (state) => {
|
|
30
|
+
if (state === 'active')
|
|
31
|
+
listener();
|
|
32
|
+
});
|
|
33
|
+
return () => subscription.remove();
|
|
34
|
+
},
|
|
35
|
+
// Inactive (a notification pulled down) is not leaving.
|
|
36
|
+
onLeave: (listener) => {
|
|
37
|
+
const subscription = AppState.addEventListener('change', (state) => {
|
|
38
|
+
if (state === 'background')
|
|
39
|
+
listener();
|
|
40
|
+
});
|
|
41
|
+
return () => subscription.remove();
|
|
42
|
+
},
|
|
43
|
+
isAway: () => AppState.currentState === 'background',
|
|
44
|
+
// No clipboard in React Native itself: the share sheet offers Copy.
|
|
45
|
+
copyText: (text) => {
|
|
46
|
+
void Share.share({ message: text }).catch(() => undefined);
|
|
47
|
+
},
|
|
48
|
+
openUrl: () => leave.current(),
|
|
49
|
+
onCardMessage: (listener) => {
|
|
50
|
+
cardListeners.add(listener);
|
|
51
|
+
return () => void cardListeners.delete(listener);
|
|
52
|
+
},
|
|
53
|
+
// Pay is pressed on the form, where a picked card always shows its page.
|
|
54
|
+
submitCard: () => cardPage.current.injectJavaScript(cardFieldsSubmit()),
|
|
55
|
+
// A wrong number on Pay: the keyboard comes up on it.
|
|
56
|
+
onPhoneRejected: () => phoneField.current?.focus(),
|
|
57
|
+
phoneStore: () => readPhoneStore(),
|
|
58
|
+
// Nothing blocks a browser here: it opens once the link is known.
|
|
59
|
+
// The return page tells the gateway: the browser only closes.
|
|
60
|
+
openPaypal: (started) => untilBrowserShut(started),
|
|
61
|
+
// The bank's page the same way (ADR 0014); a browser shut before the
|
|
62
|
+
// return page loads, the core says closed.
|
|
63
|
+
openBankRedirect: (started) => untilBrowserShut(started),
|
|
64
|
+
closeProviderWindow: () => closeProviderWindow(),
|
|
65
|
+
}));
|
|
66
|
+
const [cardFields] = useState(() => ({
|
|
67
|
+
page: cardPage,
|
|
68
|
+
receive: (message) => cardListeners.forEach((listener) => listener(message)),
|
|
69
|
+
}));
|
|
70
|
+
return { platform, cardFields };
|
|
71
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PaymentSheet } from '../models/sheet.interface.js';
|
|
2
|
+
export declare const PaymentSheetContext: import("react").Context<PaymentSheet | null>;
|
|
3
|
+
/** `presentPayment`, from the `BrissotoPayProvider` around the app. */
|
|
4
|
+
export declare function usePaymentSheet(): PaymentSheet;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, use } from 'react';
|
|
2
|
+
export const PaymentSheetContext = createContext(null);
|
|
3
|
+
/** `presentPayment`, from the `BrissotoPayProvider` around the app. */
|
|
4
|
+
export function usePaymentSheet() {
|
|
5
|
+
const sheet = use(PaymentSheetContext);
|
|
6
|
+
if (!sheet) {
|
|
7
|
+
throw new Error('usePaymentSheet needs a BrissotoPayProvider around the app.');
|
|
8
|
+
}
|
|
9
|
+
return sheet;
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Animated, Easing } from 'react-native';
|
|
3
|
+
import { SHAKE_MS, SHAKE_OFFSETS } from "../models/sheet.constants.js";
|
|
4
|
+
/** A side-to-side shake each time `count` grows past 0: the offset to put in a `translateX`. */
|
|
5
|
+
export function useShake(count) {
|
|
6
|
+
const [offset] = useState(() => new Animated.Value(0));
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (count === 0)
|
|
9
|
+
return;
|
|
10
|
+
Animated.sequence(SHAKE_OFFSETS.map((toValue) => Animated.timing(offset, {
|
|
11
|
+
toValue,
|
|
12
|
+
duration: SHAKE_MS / SHAKE_OFFSETS.length,
|
|
13
|
+
easing: Easing.out(Easing.quad),
|
|
14
|
+
useNativeDriver: true,
|
|
15
|
+
}))).start();
|
|
16
|
+
}, [count, offset]);
|
|
17
|
+
return offset;
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SheetMotion } from '../models/sheet.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* The bottom sheet's moves, in plain React Native: it slides up from below
|
|
4
|
+
* the screen, follows a finger dragging its top down, springs back or
|
|
5
|
+
* `onSwipe`s when let go, and slides away once `open` turns false.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useSheetMotion(open: boolean, onSwipe: () => void): SheetMotion;
|