@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.
Files changed (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -2
  3. package/assets/brand/paypal-wordmark.png +0 -0
  4. package/assets/fonts/Figtree-Bold.ttf +0 -0
  5. package/assets/fonts/Figtree-ExtraBold.ttf +0 -0
  6. package/assets/fonts/Figtree-Medium.ttf +0 -0
  7. package/assets/fonts/Figtree-Regular.ttf +0 -0
  8. package/assets/fonts/Figtree-SemiBold.ttf +0 -0
  9. package/assets/fonts/OFL.txt +93 -0
  10. package/assets/logos/airtel.png +0 -0
  11. package/assets/logos/app-store.png +0 -0
  12. package/assets/logos/apple-pay.png +0 -0
  13. package/assets/logos/at.png +0 -0
  14. package/assets/logos/bancontact.png +0 -0
  15. package/assets/logos/card.png +0 -0
  16. package/assets/logos/cb.png +0 -0
  17. package/assets/logos/celtiis.png +0 -0
  18. package/assets/logos/eps.png +0 -0
  19. package/assets/logos/feexpay.png +0 -0
  20. package/assets/logos/google-pay.png +0 -0
  21. package/assets/logos/google-play.png +0 -0
  22. package/assets/logos/iapkit.png +0 -0
  23. package/assets/logos/ideal.png +0 -0
  24. package/assets/logos/mastercard.png +0 -0
  25. package/assets/logos/mixx.png +0 -0
  26. package/assets/logos/moov.png +0 -0
  27. package/assets/logos/mtn.png +0 -0
  28. package/assets/logos/mybank.png +0 -0
  29. package/assets/logos/nexus.png +0 -0
  30. package/assets/logos/orange.png +0 -0
  31. package/assets/logos/pawapay.png +0 -0
  32. package/assets/logos/paypal.png +0 -0
  33. package/assets/logos/telecel.png +0 -0
  34. package/assets/logos/tnm.png +0 -0
  35. package/assets/logos/visa.png +0 -0
  36. package/assets/logos/vodacom.png +0 -0
  37. package/assets/logos/wave.png +0 -0
  38. package/dist/checkout-core/hooks/use-checkout-controller.d.ts +9 -0
  39. package/dist/checkout-core/hooks/use-checkout-controller.js +563 -0
  40. package/dist/checkout-core/hooks/use-checkout-payment.d.ts +9 -0
  41. package/dist/checkout-core/hooks/use-checkout-payment.js +136 -0
  42. package/dist/checkout-core/hooks/use-checkout-timers.d.ts +15 -0
  43. package/dist/checkout-core/hooks/use-checkout-timers.js +44 -0
  44. package/dist/checkout-core/hooks/use-phone-number.d.ts +7 -0
  45. package/dist/checkout-core/hooks/use-phone-number.js +82 -0
  46. package/dist/checkout-core/messages/en.d.ts +302 -0
  47. package/dist/checkout-core/messages/en.js +301 -0
  48. package/dist/checkout-core/messages/fr.d.ts +4 -0
  49. package/dist/checkout-core/messages/fr.js +302 -0
  50. package/dist/checkout-core/models/checkout.card.utils.d.ts +7 -0
  51. package/dist/checkout-core/models/checkout.card.utils.js +25 -0
  52. package/dist/checkout-core/models/checkout.constants.d.ts +101 -0
  53. package/dist/checkout-core/models/checkout.constants.js +339 -0
  54. package/dist/checkout-core/models/checkout.country.utils.d.ts +17 -0
  55. package/dist/checkout-core/models/checkout.country.utils.js +45 -0
  56. package/dist/checkout-core/models/checkout.enum.d.ts +233 -0
  57. package/dist/checkout-core/models/checkout.enum.js +259 -0
  58. package/dist/checkout-core/models/checkout.fetch.utils.d.ts +6 -0
  59. package/dist/checkout-core/models/checkout.fetch.utils.js +22 -0
  60. package/dist/checkout-core/models/checkout.interface.d.ts +698 -0
  61. package/dist/checkout-core/models/checkout.interface.js +1 -0
  62. package/dist/checkout-core/models/checkout.money.utils.d.ts +7 -0
  63. package/dist/checkout-core/models/checkout.money.utils.js +21 -0
  64. package/dist/checkout-core/models/checkout.phone.utils.d.ts +33 -0
  65. package/dist/checkout-core/models/checkout.phone.utils.js +159 -0
  66. package/dist/checkout-core/models/checkout.view.utils.d.ts +77 -0
  67. package/dist/checkout-core/models/checkout.view.utils.js +331 -0
  68. package/dist/checkout-core/models/domain.enum.d.ts +106 -0
  69. package/dist/checkout-core/models/domain.enum.js +113 -0
  70. package/dist/components/BrissotoPayProvider.d.ts +8 -0
  71. package/dist/components/BrissotoPayProvider.js +39 -0
  72. package/dist/components/PaymentSheetModal.d.ts +9 -0
  73. package/dist/components/PaymentSheetModal.js +106 -0
  74. package/dist/components/SheetBone.d.ts +3 -0
  75. package/dist/components/SheetBone.js +12 -0
  76. package/dist/components/SheetButton.d.ts +7 -0
  77. package/dist/components/SheetButton.js +47 -0
  78. package/dist/components/SheetCardFields.d.ts +10 -0
  79. package/dist/components/SheetCardFields.js +86 -0
  80. package/dist/components/SheetChosenMethod.d.ts +3 -0
  81. package/dist/components/SheetChosenMethod.js +60 -0
  82. package/dist/components/SheetCodeField.d.ts +8 -0
  83. package/dist/components/SheetCodeField.js +98 -0
  84. package/dist/components/SheetContent.d.ts +3 -0
  85. package/dist/components/SheetContent.js +133 -0
  86. package/dist/components/SheetDial.d.ts +7 -0
  87. package/dist/components/SheetDial.js +36 -0
  88. package/dist/components/SheetFailed.d.ts +3 -0
  89. package/dist/components/SheetFailed.js +44 -0
  90. package/dist/components/SheetForm.d.ts +8 -0
  91. package/dist/components/SheetForm.js +141 -0
  92. package/dist/components/SheetGrabber.d.ts +2 -0
  93. package/dist/components/SheetGrabber.js +17 -0
  94. package/dist/components/SheetHeader.d.ts +7 -0
  95. package/dist/components/SheetHeader.js +83 -0
  96. package/dist/components/SheetIcon.d.ts +3 -0
  97. package/dist/components/SheetIcon.js +78 -0
  98. package/dist/components/SheetLayout.d.ts +11 -0
  99. package/dist/components/SheetLayout.js +63 -0
  100. package/dist/components/SheetLogo.d.ts +3 -0
  101. package/dist/components/SheetLogo.js +20 -0
  102. package/dist/components/SheetMessage.d.ts +3 -0
  103. package/dist/components/SheetMessage.js +15 -0
  104. package/dist/components/SheetMethodCard.d.ts +3 -0
  105. package/dist/components/SheetMethodCard.js +71 -0
  106. package/dist/components/SheetNameField.d.ts +7 -0
  107. package/dist/components/SheetNameField.js +48 -0
  108. package/dist/components/SheetPaypalButton.d.ts +3 -0
  109. package/dist/components/SheetPaypalButton.js +23 -0
  110. package/dist/components/SheetPhoneField.d.ts +3 -0
  111. package/dist/components/SheetPhoneField.js +59 -0
  112. package/dist/components/SheetPillSelect.d.ts +7 -0
  113. package/dist/components/SheetPillSelect.js +134 -0
  114. package/dist/components/SheetRow.d.ts +3 -0
  115. package/dist/components/SheetRow.js +28 -0
  116. package/dist/components/SheetSimulator.d.ts +6 -0
  117. package/dist/components/SheetSimulator.js +40 -0
  118. package/dist/components/SheetSkeleton.d.ts +5 -0
  119. package/dist/components/SheetSkeleton.js +23 -0
  120. package/dist/components/SheetStep.d.ts +6 -0
  121. package/dist/components/SheetStep.js +21 -0
  122. package/dist/components/SheetStoreTab.d.ts +7 -0
  123. package/dist/components/SheetStoreTab.js +27 -0
  124. package/dist/components/SheetSuccess.d.ts +3 -0
  125. package/dist/components/SheetSuccess.js +51 -0
  126. package/dist/components/SheetSummary.d.ts +3 -0
  127. package/dist/components/SheetSummary.js +32 -0
  128. package/dist/components/SheetTerminal.d.ts +6 -0
  129. package/dist/components/SheetTerminal.js +31 -0
  130. package/dist/components/SheetText.d.ts +5 -0
  131. package/dist/components/SheetText.js +27 -0
  132. package/dist/components/SheetToast.d.ts +7 -0
  133. package/dist/components/SheetToast.js +71 -0
  134. package/dist/components/SheetWaiting.d.ts +7 -0
  135. package/dist/components/SheetWaiting.js +88 -0
  136. package/dist/hooks/use-native-platform.d.ts +10 -0
  137. package/dist/hooks/use-native-platform.js +71 -0
  138. package/dist/hooks/use-payment-sheet.d.ts +4 -0
  139. package/dist/hooks/use-payment-sheet.js +10 -0
  140. package/dist/hooks/use-shake.d.ts +3 -0
  141. package/dist/hooks/use-shake.js +18 -0
  142. package/dist/hooks/use-sheet-motion.d.ts +7 -0
  143. package/dist/hooks/use-sheet-motion.js +62 -0
  144. package/dist/hooks/use-sheet-resize.d.ts +6 -0
  145. package/dist/hooks/use-sheet-resize.js +15 -0
  146. package/dist/hooks/use-sheet-room.d.ts +4 -0
  147. package/dist/hooks/use-sheet-room.js +8 -0
  148. package/dist/hooks/use-sheet-theme.d.ts +4 -0
  149. package/dist/hooks/use-sheet-theme.js +12 -0
  150. package/dist/hooks/use-step-slide.d.ts +16 -0
  151. package/dist/hooks/use-step-slide.js +50 -0
  152. package/dist/hooks/use-store-recovery.d.ts +9 -0
  153. package/dist/hooks/use-store-recovery.js +50 -0
  154. package/dist/hooks/use-store-tab.d.ts +11 -0
  155. package/dist/hooks/use-store-tab.js +112 -0
  156. package/dist/index.d.ts +3 -0
  157. package/dist/index.js +2 -0
  158. package/dist/models/sheet.constants.d.ts +125 -0
  159. package/dist/models/sheet.constants.js +204 -0
  160. package/dist/models/sheet.enum.d.ts +46 -0
  161. package/dist/models/sheet.enum.js +53 -0
  162. package/dist/models/sheet.interface.d.ts +426 -0
  163. package/dist/models/sheet.interface.js +1 -0
  164. package/dist/models/sheet.utils.d.ts +68 -0
  165. package/dist/models/sheet.utils.js +214 -0
  166. package/dist/services/checkout.service.d.ts +15 -0
  167. package/dist/services/checkout.service.js +96 -0
  168. package/dist/services/provider-window.service.d.ts +13 -0
  169. package/dist/services/provider-window.service.js +53 -0
  170. package/dist/services/store.service.d.ts +36 -0
  171. package/dist/services/store.service.js +107 -0
  172. package/package.json +73 -4
@@ -0,0 +1,62 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Animated, Easing, PanResponder, useWindowDimensions, } from 'react-native';
3
+ import { SHEET_DIM_OPACITY, SHEET_SLIDE_MS, SHEET_TOP_GAP, } from "../models/sheet.constants.js";
4
+ import { sheetSwipeCloses } from "../models/sheet.utils.js";
5
+ /**
6
+ * The bottom sheet's moves, in plain React Native: it slides up from below
7
+ * the screen, follows a finger dragging its top down, springs back or
8
+ * `onSwipe`s when let go, and slides away once `open` turns false.
9
+ */
10
+ export function useSheetMotion(open, onSwipe) {
11
+ const { height } = useWindowDimensions();
12
+ const [slide] = useState(() => new Animated.Value(height));
13
+ const [drag] = useState(() => new Animated.Value(0));
14
+ const [shown, setShown] = useState(open);
15
+ const swiped = useRef(onSwipe);
16
+ useEffect(() => {
17
+ swiped.current = onSwipe;
18
+ }, [onSwipe]);
19
+ useEffect(() => {
20
+ Animated.timing(slide, {
21
+ toValue: open ? 0 : height,
22
+ duration: SHEET_SLIDE_MS,
23
+ easing: Easing.out(Easing.cubic),
24
+ useNativeDriver: true,
25
+ }).start(() => {
26
+ if (!open)
27
+ setShown(false);
28
+ });
29
+ }, [open, height, slide]);
30
+ const [dragHandlers] = useState(() => {
31
+ const settle = () => Animated.spring(drag, {
32
+ toValue: 0,
33
+ bounciness: 0,
34
+ useNativeDriver: true,
35
+ }).start();
36
+ return PanResponder.create({
37
+ // The top holds only close, which takes its own taps.
38
+ onStartShouldSetPanResponder: () => true,
39
+ onPanResponderMove: (_event, { dy }) => drag.setValue(Math.max(0, dy)),
40
+ onPanResponderRelease: (_event, { dy, vy }) => {
41
+ // Closing asks first while a prompt waits: the sheet comes back up.
42
+ if (sheetSwipeCloses(dy, vy))
43
+ swiped.current();
44
+ settle();
45
+ },
46
+ onPanResponderTerminate: settle,
47
+ }).panHandlers;
48
+ });
49
+ const [translateY] = useState(() => Animated.add(slide, drag));
50
+ const dim = useMemo(() => translateY.interpolate({
51
+ inputRange: [0, height],
52
+ outputRange: [SHEET_DIM_OPACITY, 0],
53
+ extrapolate: 'clamp',
54
+ }), [translateY, height]);
55
+ return {
56
+ shown,
57
+ translateY,
58
+ dim,
59
+ dragHandlers,
60
+ topGap: height * SHEET_TOP_GAP,
61
+ };
62
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Eases the sheet's height when what it shows changes `shape` (another
3
+ * screen, tab, method, the card fields' page): the next layout animates,
4
+ * on iOS and Android alike. The first one does not: the sheet slides up.
5
+ */
6
+ export declare function useSheetResize(shape: string): void;
@@ -0,0 +1,15 @@
1
+ import { useState } from 'react';
2
+ import { LayoutAnimation } from 'react-native';
3
+ import { SHEET_RESIZE } from "../models/sheet.constants.js";
4
+ /**
5
+ * Eases the sheet's height when what it shows changes `shape` (another
6
+ * screen, tab, method, the card fields' page): the next layout animates,
7
+ * on iOS and Android alike. The first one does not: the sheet slides up.
8
+ */
9
+ export function useSheetResize(shape) {
10
+ const [last, setLast] = useState(shape);
11
+ if (last !== shape) {
12
+ setLast(shape);
13
+ LayoutAnimation.configureNext(SHEET_RESIZE);
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ import type { SheetRoom } from '../models/sheet.interface.js';
2
+ export declare const SheetRoomContext: import("react").Context<SheetRoom>;
3
+ /** The room the open sheet has for what scrolls, inside its `SheetLayout`. */
4
+ export declare function useSheetRoom(): SheetRoom;
@@ -0,0 +1,8 @@
1
+ import { createContext, use } from 'react';
2
+ /** Outside a `SheetLayout`: everything shows, nothing is held. */
3
+ const NO_ROOM = { room: null, pinEnd: () => undefined };
4
+ export const SheetRoomContext = createContext(NO_ROOM);
5
+ /** The room the open sheet has for what scrolls, inside its `SheetLayout`. */
6
+ export function useSheetRoom() {
7
+ return use(SheetRoomContext);
8
+ }
@@ -0,0 +1,4 @@
1
+ import type { SheetTheme } from '../models/sheet.interface.js';
2
+ export declare const SheetThemeContext: import("react").Context<SheetTheme>;
3
+ /** The open sheet's colours. */
4
+ export declare function useSheetTheme(): SheetTheme;
@@ -0,0 +1,12 @@
1
+ import { createContext, use } from 'react';
2
+ import { CHECKOUT_COLORS } from "../checkout-core/models/checkout.constants.js";
3
+ import { CheckoutThemeEnum } from "../checkout-core/models/checkout.enum.js";
4
+ export const SheetThemeContext = createContext({
5
+ colors: CHECKOUT_COLORS[CheckoutThemeEnum.LIGHT],
6
+ brand: CHECKOUT_COLORS[CheckoutThemeEnum.LIGHT].ink,
7
+ dark: false,
8
+ });
9
+ /** The open sheet's colours. */
10
+ export function useSheetTheme() {
11
+ return use(SheetThemeContext);
12
+ }
@@ -0,0 +1,16 @@
1
+ import { Animated } from 'react-native';
2
+ import { CheckoutStepEnum } from '../checkout-core/models/checkout.enum.js';
3
+ /**
4
+ * Each step of the form slides in once the payer moves: the details from the
5
+ * right, the methods back from the left. Still when the phone asks for less
6
+ * motion. `moved` says whether the step changed since the sheet opened.
7
+ */
8
+ export declare function useStepSlide(step: CheckoutStepEnum): {
9
+ moved: boolean;
10
+ style: {
11
+ opacity: Animated.Value;
12
+ transform: {
13
+ translateX: Animated.Interpolation<number>;
14
+ }[];
15
+ };
16
+ };
@@ -0,0 +1,50 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { AccessibilityInfo, Animated, Easing } from 'react-native';
3
+ import { CheckoutStepEnum } from "../checkout-core/models/checkout.enum.js";
4
+ import { STEP_SLIDE_DISTANCE, STEP_SLIDE_MS, } from "../models/sheet.constants.js";
5
+ /**
6
+ * Each step of the form slides in once the payer moves: the details from the
7
+ * right, the methods back from the left. Still when the phone asks for less
8
+ * motion. `moved` says whether the step changed since the sheet opened.
9
+ */
10
+ export function useStepSlide(step) {
11
+ const [shown, setShown] = useState({ step, moved: false });
12
+ if (shown.step !== step)
13
+ setShown({ step, moved: true });
14
+ const [still, setStill] = useState(false);
15
+ useEffect(() => {
16
+ void AccessibilityInfo.isReduceMotionEnabled().then(setStill);
17
+ }, []);
18
+ // A value of its own for each step's view: it starts out of place.
19
+ const sliding = shown.moved && !still;
20
+ const progress = useMemo(() => new Animated.Value(sliding ? 0 : 1),
21
+ // `shown` changes with each step shown: a new value for its new view.
22
+ [shown, sliding]);
23
+ useEffect(() => {
24
+ if (!sliding)
25
+ return;
26
+ Animated.timing(progress, {
27
+ toValue: 1,
28
+ duration: STEP_SLIDE_MS,
29
+ easing: Easing.out(Easing.cubic),
30
+ useNativeDriver: true,
31
+ }).start();
32
+ }, [progress, sliding]);
33
+ const from = step === CheckoutStepEnum.DETAILS
34
+ ? STEP_SLIDE_DISTANCE
35
+ : -STEP_SLIDE_DISTANCE;
36
+ return {
37
+ moved: shown.moved,
38
+ style: {
39
+ opacity: progress,
40
+ transform: [
41
+ {
42
+ translateX: progress.interpolate({
43
+ inputRange: [0, 1],
44
+ outputRange: [from, 0],
45
+ }),
46
+ },
47
+ ],
48
+ },
49
+ };
50
+ }
@@ -0,0 +1,9 @@
1
+ import type { StoreRecovery } from '../models/sheet.interface.js';
2
+ /**
3
+ * On start, every store purchase the app never reported (killed in the
4
+ * store's sheet, the network lost) goes to the gateway again, each at once
5
+ * (ADR 0007). It pays its payment, and is finished on the phone only once
6
+ * the gateway reads its attempt paid, a duplicate included. One not paid
7
+ * within `STORE_RECOVERY_MS` stays unfinished, for the next start.
8
+ */
9
+ export declare function useStoreRecovery(recovery: StoreRecovery): void;
@@ -0,0 +1,50 @@
1
+ import { useEffect } from 'react';
2
+ import { STORE_RECOVERY_MS } from "../models/sheet.constants.js";
3
+ import { quietly, unreportedPurchaseOf } from "../models/sheet.utils.js";
4
+ import { finishStorePurchase, readUnfinishedPurchases, } from "../services/store.service.js";
5
+ /**
6
+ * On start, every store purchase the app never reported (killed in the
7
+ * store's sheet, the network lost) goes to the gateway again, each at once
8
+ * (ADR 0007). It pays its payment, and is finished on the phone only once
9
+ * the gateway reads its attempt paid, a duplicate included. One not paid
10
+ * within `STORE_RECOVERY_MS` stays unfinished, for the next start.
11
+ */
12
+ export function useStoreRecovery(recovery) {
13
+ useEffect(() => {
14
+ let closed = false;
15
+ const stops = [];
16
+ const recoverOne = async (purchase) => {
17
+ const unreported = unreportedPurchaseOf(purchase);
18
+ if (!unreported)
19
+ return;
20
+ const sent = await recovery.recover(unreported).catch(() => null);
21
+ if (!sent?.ok || closed)
22
+ return;
23
+ const following = { paid: false, unfollow: () => { } };
24
+ const stop = () => {
25
+ clearTimeout(timer);
26
+ following.unfollow();
27
+ };
28
+ const timer = setTimeout(stop, STORE_RECOVERY_MS);
29
+ const unfollow = recovery.follow(unreported.token, (answer) => {
30
+ if (!answer?.paid)
31
+ return;
32
+ following.paid = true;
33
+ stop();
34
+ quietly(finishStorePurchase(purchase));
35
+ });
36
+ following.unfollow = unfollow;
37
+ // Paid already: the answer came before the connection was handed back.
38
+ if (following.paid)
39
+ unfollow();
40
+ stops.push(stop);
41
+ };
42
+ void readUnfinishedPurchases().then((purchases) => {
43
+ purchases.forEach((purchase) => void recoverOne(purchase));
44
+ });
45
+ return () => {
46
+ closed = true;
47
+ stops.forEach((stop) => stop());
48
+ };
49
+ }, [recovery]);
50
+ }
@@ -0,0 +1,11 @@
1
+ import type { CheckoutCore, StoreMutations } from '../checkout-core/models/checkout.interface.js';
2
+ import type { StoreTab } from '../models/sheet.interface.js';
3
+ /**
4
+ * The payment sheet's store tab (ADR 0007): this phone's store only, once
5
+ * the gateway may sell the payment's product through it and the store
6
+ * itself lists it, at the store's own price. Its button opens an attempt,
7
+ * then the store's sheet with the attempt's token; the purchase goes to the
8
+ * gateway, which verifies it, and is finished on the phone only once the
9
+ * attempt shows paid. Null while there is no tab to show.
10
+ */
11
+ export declare function useStoreTab(core: CheckoutCore, calls: StoreMutations | undefined): StoreTab | null;
@@ -0,0 +1,112 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { StoreSheetOutcomeEnum } from "../checkout-core/models/checkout.enum.js";
3
+ import { AttemptStatusEnum } from "../checkout-core/models/domain.enum.js";
4
+ import { StorePurchaseStateEnum } from "../models/sheet.enum.js";
5
+ import { isAttemptPurchase, quietly, sheetOutcomeOf, } from "../models/sheet.utils.js";
6
+ import { finishStorePurchase, listenToStore, openStoreSheet, phoneStoreOf, readStoreOffer, } from "../services/store.service.js";
7
+ /**
8
+ * The payment sheet's store tab (ADR 0007): this phone's store only, once
9
+ * the gateway may sell the payment's product through it and the store
10
+ * itself lists it, at the store's own price. Its button opens an attempt,
11
+ * then the store's sheet with the attempt's token; the purchase goes to the
12
+ * gateway, which verifies it, and is finished on the phone only once the
13
+ * attempt shows paid. Null while there is no tab to show.
14
+ */
15
+ export function useStoreTab(core, calls) {
16
+ const { view, actions } = core;
17
+ const store = phoneStoreOf();
18
+ const productId = view?.stores.find((candidate) => candidate.store === store)?.productId ??
19
+ null;
20
+ const [offer, setOffer] = useState(null);
21
+ /** The attempt the store's sheet was last opened for. */
22
+ const opened = useRef(null);
23
+ /** Its purchase, sent to the gateway and not finished yet. */
24
+ const sent = useRef(null);
25
+ /** The tab showed the refund consent line (ADR 0008). */
26
+ const consented = useRef(false);
27
+ const onConsentShown = useCallback(() => {
28
+ consented.current = true;
29
+ }, []);
30
+ const paymentId = view?.id;
31
+ // An answer for an older product never shows: the offer names its own.
32
+ useEffect(() => {
33
+ if (productId)
34
+ void readStoreOffer(productId).then(setOffer);
35
+ }, [productId]);
36
+ // The store's sheet answers through listeners, for as long as the tab shows.
37
+ const selling = !!offer && !!calls && !!paymentId;
38
+ useEffect(() => {
39
+ if (!selling)
40
+ return undefined;
41
+ const tell = (outcome) => {
42
+ const attempt = opened.current;
43
+ quietly(calls.storeSheet({
44
+ paymentId,
45
+ reference: attempt.reference,
46
+ outcome,
47
+ }));
48
+ };
49
+ return listenToStore((purchase) => {
50
+ const attempt = opened.current;
51
+ if (!attempt || !isAttemptPurchase(purchase, attempt))
52
+ return;
53
+ if (purchase.purchaseState === StorePurchaseStateEnum.PENDING) {
54
+ tell(StoreSheetOutcomeEnum.PENDING);
55
+ return;
56
+ }
57
+ sent.current = purchase;
58
+ quietly(calls.sendStorePurchase({
59
+ paymentId,
60
+ reference: attempt.reference,
61
+ purchase: purchase.purchaseToken,
62
+ }));
63
+ }, (error) => {
64
+ if (opened.current)
65
+ tell(sheetOutcomeOf(error.code));
66
+ });
67
+ }, [selling, calls, paymentId]);
68
+ // Finished once the gateway says the attempt paid: never before.
69
+ const attempt = view?.attempt;
70
+ const paid = !!attempt &&
71
+ attempt.reference === opened.current?.reference &&
72
+ attempt.status === AttemptStatusEnum.SUCCEEDED;
73
+ useEffect(() => {
74
+ const purchase = sent.current;
75
+ if (!paid || !purchase)
76
+ return;
77
+ sent.current = null;
78
+ quietly(finishStorePurchase(purchase));
79
+ }, [paid]);
80
+ if (!store || !offer || offer.productId !== productId)
81
+ return null;
82
+ return {
83
+ store,
84
+ offer,
85
+ onConsentShown,
86
+ buy: () => {
87
+ void actions
88
+ .payWithStore(store, consented.current)
89
+ .then(async (result) => {
90
+ if (!result)
91
+ return;
92
+ const sheet = {
93
+ reference: result.reference,
94
+ token: result.token,
95
+ productId: result.productId,
96
+ };
97
+ opened.current = sheet;
98
+ sent.current = null;
99
+ try {
100
+ await openStoreSheet(sheet);
101
+ }
102
+ catch {
103
+ quietly(calls.storeSheet({
104
+ paymentId: paymentId,
105
+ reference: sheet.reference,
106
+ outcome: StoreSheetOutcomeEnum.ERROR,
107
+ }));
108
+ }
109
+ });
110
+ },
111
+ };
112
+ }
@@ -0,0 +1,3 @@
1
+ export { BrissotoPayProvider } from './components/BrissotoPayProvider.js';
2
+ export { usePaymentSheet } from './hooks/use-payment-sheet.js';
3
+ export type { BrissotoPayProviderProps, PaymentSheet, PaymentSheetError, PaymentSheetResult, PaymentSheetStatus, PresentPaymentOptions, } from './models/sheet.interface.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { BrissotoPayProvider } from "./components/BrissotoPayProvider.js";
2
+ export { usePaymentSheet } from "./hooks/use-payment-sheet.js";
@@ -0,0 +1,125 @@
1
+ import type { LayoutAnimationConfig } from 'react-native';
2
+ import type { StoreTabSpec } from './sheet.interface.js';
3
+ import en from '../checkout-core/messages/en.js';
4
+ import { PhoneStoreEnum } from '../checkout-core/models/checkout.enum.js';
5
+ import { LangEnum, ProviderLogoEnum } from '../checkout-core/models/domain.enum.js';
6
+ import { FigtreeEnum } from './sheet.enum.js';
7
+ /** The production backend: Live and Test payments alike. */
8
+ export declare const DEFAULT_URL = "https://api-pay.brissoto.com";
9
+ /** Each store as its tab shows it: its own name (a brand, in every language) and tile. */
10
+ export declare const STORE_TABS: Record<PhoneStoreEnum, StoreTabSpec>;
11
+ /** How long the sheet waits for the store's country before it opens without one. */
12
+ export declare const STORE_COUNTRY_TIMEOUT_MS = 3000;
13
+ /**
14
+ * Where the gateway answers the payer's country from Cloudflare's header:
15
+ * its HTTP action `/checkout/country`, which the gateway's own address
16
+ * serves under `/http`.
17
+ */
18
+ export declare const IP_COUNTRY_PATH = "/http/checkout/country";
19
+ /** How long the sheet waits for the payer's country before it opens without it. */
20
+ export declare const IP_COUNTRY_TIMEOUT_MS = 3000;
21
+ /** How long a start waits for the gateway to pay a recovered purchase; unpaid, it comes back next start. */
22
+ export declare const STORE_RECOVERY_MS = 60000;
23
+ /** The token the sheet has a store purchase carry: a UUID, as the gateway makes it. */
24
+ export declare const STORE_TOKEN_PATTERN: RegExp;
25
+ /** The public Convex functions the web checkout calls, by path. */
26
+ export declare const CHECKOUT_FUNCTIONS: {
27
+ get: string;
28
+ pay: string;
29
+ payWithCode: string;
30
+ checkNow: string;
31
+ open: string;
32
+ cancel: string;
33
+ resend: string;
34
+ simulate: string;
35
+ startPaypal: string;
36
+ paypalClosed: string;
37
+ paypalReturned: string;
38
+ startBankRedirect: string;
39
+ payWithStore: string;
40
+ sendStorePurchase: string;
41
+ storeSheet: string;
42
+ recoverStorePurchase: string;
43
+ storePurchase: string;
44
+ };
45
+ /** Figtree ships inside the package: `expo-font` loads it when a sheet opens. */
46
+ export declare const FIGTREE_FILES: Record<FigtreeEnum, number>;
47
+ /** The sheet's timezone for dates, as the web checkout's. */
48
+ export declare const TIME_ZONE = "Africa/Douala";
49
+ /** The payer copy the web checkout shows, by language. */
50
+ export declare const MESSAGES: Record<LangEnum, {
51
+ checkout: typeof en;
52
+ }>;
53
+ /** Brand tiles, the web's `public/logo/` PNGs bundled with the package. */
54
+ export declare const PROVIDER_LOGOS: Record<ProviderLogoEnum, number>;
55
+ /** At its tallest, the sheet leaves this share of the screen above it, clear of the status bar. */
56
+ export declare const SHEET_TOP_GAP = 0.1;
57
+ /** How dark the app gets behind the sheet. */
58
+ export declare const SHEET_DIM_OPACITY = 0.4;
59
+ /** How long the sheet takes to slide up or away, in ms. */
60
+ export declare const SHEET_SLIDE_MS = 280;
61
+ /** Points down that close the sheet when the finger lets go. */
62
+ export declare const SHEET_SWIPE_DISTANCE = 120;
63
+ /** A flick down this fast (points per ms) closes it, however short. */
64
+ export declare const SHEET_FLICK_SPEED = 0.8;
65
+ /** How the sheet's height eases from one screen to the next. */
66
+ export declare const SHEET_RESIZE: LayoutAnimationConfig;
67
+ /** Room under what scrolls in the sheet, below its last part. */
68
+ export declare const SHEET_BODY_BOTTOM = 16;
69
+ /** The card fields page's own viewport, as the web app's root sets it. */
70
+ export declare const PAGE_VIEWPORT = "width=device-width, initial-scale=1";
71
+ /** The card fields page's viewport while a bank's page shows in it: no zoom on its small field's focus (iOS). */
72
+ export declare const BANK_PAGE_VIEWPORT = "width=device-width, initial-scale=1, maximum-scale=1";
73
+ /** A paragraph's line height, as a share of its size: the web checkout's 1.5, a touch tighter for Figtree on phones. */
74
+ export declare const PARAGRAPH_LINE_HEIGHT = 1.45;
75
+ /** How long a step of the form takes to slide in, and from how far. */
76
+ export declare const STEP_SLIDE_MS = 260;
77
+ export declare const STEP_SLIDE_DISTANCE = 32;
78
+ /** A field the payer still has to fill, shaken once when Pay is pressed: its offsets, then back. */
79
+ export declare const SHAKE_MS = 300;
80
+ export declare const SHAKE_OFFSETS: number[];
81
+ /** The form's one row height and one corner, Pay's: the tabs, the method picked, the fields and the buttons line up. */
82
+ export declare const FIELD_HEIGHT = 50;
83
+ export declare const FIELD_RADIUS = 14;
84
+ /** The tabs' inset around the tab on: its corner follows the bar's. */
85
+ export declare const TABS_INSET = 3;
86
+ /** The web's h-9 pill: its height, and a corner of half of it. */
87
+ export declare const PILL_HEIGHT = 36;
88
+ /** A row of the pill's list, and the share of the screen the list takes at most: the payment sheet's top stays in sight. */
89
+ export declare const PILL_ROW_HEIGHT = 52;
90
+ export declare const PILL_LIST_MAX_SHARE = 0.5;
91
+ /** The current row's disc and the tick drawn in it, two strokes of a turned box. */
92
+ export declare const CHECK_DISC_SIZE = 22;
93
+ export declare const TICK_WIDTH = 5.5;
94
+ export declare const TICK_HEIGHT = 10;
95
+ /** The pill's chevron: a turned box of two strokes in a 12-point box, as the web's size-3 icon. */
96
+ export declare const CHEVRON_BOX = 12;
97
+ export declare const CHEVRON_SIZE = 6.5;
98
+ /** Every stroke drawn with borders: chevrons and ticks. */
99
+ export declare const STROKE_WIDTH = 2;
100
+ /** How see-through a row or a pill turns while pressed. */
101
+ export declare const PRESSED_OPACITY = 0.7;
102
+ /** The rounded top of the payment sheet and of the sheets over it. */
103
+ export declare const SHEET_TOP_RADIUS = 14;
104
+ /** Room under a sheet's last line, over the home indicator or the navigation bar. */
105
+ export declare const SHEET_FOOT_BOTTOM = 28;
106
+ /**
107
+ * Over and under the secured line, between the foot's separator and Pay.
108
+ * Figtree leaves 2pt more room over its letters than under them at this
109
+ * size, so the space over is 2 less: the letters sit in the middle.
110
+ */
111
+ export declare const SHEET_FOOT_TOP = 11;
112
+ export declare const SHEET_FOOT_GAP = 13;
113
+ /**
114
+ * The app's logo in the header and a screen's disc under it (failed, closed)
115
+ * share one size: one under the other, their centres line up.
116
+ */
117
+ export declare const SHEET_BADGE_SIZE = 44;
118
+ export declare const SHEET_BADGE_RADIUS = 12;
119
+ /** PayPal's wordmark on its gold button (3x, 24 points high in the file). */
120
+ export declare const PAYPAL_WORDMARK: number;
121
+ /** The wordmark's height on the button, and its width for that height. */
122
+ export declare const PAYPAL_WORDMARK_SIZE: {
123
+ height: number;
124
+ width: number;
125
+ };