@brissoto/pay-react-native 0.0.0-stage → 1.4.5
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 +180 -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 +297 -0
- package/dist/checkout-core/messages/en.js +296 -0
- package/dist/checkout-core/messages/fr.d.ts +4 -0
- package/dist/checkout-core/messages/fr.js +297 -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 +230 -0
- package/dist/checkout-core/models/checkout.enum.js +256 -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 +696 -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 +328 -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 +132 -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 +139 -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 +3 -0
- package/dist/components/SheetTerminal.js +21 -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 +423 -0
- package/dist/models/sheet.interface.js +1 -0
- package/dist/models/sheet.utils.d.ts +68 -0
- package/dist/models/sheet.utils.js +211 -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,136 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { PayRefusalEnum } from "../models/checkout.enum.js";
|
|
3
|
+
/**
|
|
4
|
+
* One payment for a checkout (ADR 0006): read once over plain calls, read
|
|
5
|
+
* again after each call that changes it, and followed live only between
|
|
6
|
+
* `follow(true)` and `follow(false)`, which the controller says while the
|
|
7
|
+
* payer is on the waiting screen. Once `paymentId` is cleared (a sheet
|
|
8
|
+
* closing) the last answer stays.
|
|
9
|
+
*/
|
|
10
|
+
export function useCheckoutPayment(connection, paymentId, report) {
|
|
11
|
+
const [held, setHeld] = useState({
|
|
12
|
+
view: undefined,
|
|
13
|
+
failed: false,
|
|
14
|
+
});
|
|
15
|
+
const [following, setFollowing] = useState(false);
|
|
16
|
+
/** Opened again after a failure: once, then the calls read over HTTP. */
|
|
17
|
+
const [reopened, setReopened] = useState(0);
|
|
18
|
+
const failures = useRef(0);
|
|
19
|
+
/** Followed live: the connection brings each change, nothing is read again. */
|
|
20
|
+
const followingNow = useRef(false);
|
|
21
|
+
/** The view shown: open reads again while it waits for its price. */
|
|
22
|
+
const shownView = useRef(undefined);
|
|
23
|
+
/** The payment held, and the newest answer shown: an older one never replaces it. */
|
|
24
|
+
const holding = useRef(paymentId);
|
|
25
|
+
const counter = useRef(0);
|
|
26
|
+
const shown = useRef(0);
|
|
27
|
+
const show = useCallback((ticket, next) => {
|
|
28
|
+
if (ticket < shown.current)
|
|
29
|
+
return;
|
|
30
|
+
shown.current = ticket;
|
|
31
|
+
setHeld(next);
|
|
32
|
+
}, []);
|
|
33
|
+
const read = useCallback((id) => {
|
|
34
|
+
const ticket = ++counter.current;
|
|
35
|
+
return connection.load(id).then((view) => {
|
|
36
|
+
if (holding.current === id)
|
|
37
|
+
show(ticket, () => ({ view, failed: false }));
|
|
38
|
+
},
|
|
39
|
+
// A failed read keeps what was shown.
|
|
40
|
+
(error) => {
|
|
41
|
+
report?.(error, 'read');
|
|
42
|
+
if (holding.current === id)
|
|
43
|
+
show(ticket, (previous) => ({ ...previous, failed: true }));
|
|
44
|
+
});
|
|
45
|
+
}, [connection, show, report]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
holding.current = paymentId;
|
|
48
|
+
if (paymentId)
|
|
49
|
+
void read(paymentId);
|
|
50
|
+
}, [paymentId, read]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
followingNow.current = following;
|
|
53
|
+
}, [following]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
shownView.current = held.view;
|
|
56
|
+
}, [held.view]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!following || !paymentId)
|
|
59
|
+
return undefined;
|
|
60
|
+
return connection.follow(paymentId, (view) => {
|
|
61
|
+
failures.current = 0;
|
|
62
|
+
show(++counter.current, () => ({ view, failed: false }));
|
|
63
|
+
},
|
|
64
|
+
// A broken connection is read over HTTP and opened once more; broken
|
|
65
|
+
// again, it stays closed and the calls read over HTTP.
|
|
66
|
+
() => {
|
|
67
|
+
setHeld((previous) => ({ ...previous, failed: true }));
|
|
68
|
+
failures.current += 1;
|
|
69
|
+
if (failures.current > 1) {
|
|
70
|
+
setFollowing(false);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
void read(paymentId);
|
|
74
|
+
setReopened((count) => count + 1);
|
|
75
|
+
});
|
|
76
|
+
}, [following, reopened, paymentId, connection, show, read]);
|
|
77
|
+
const mutations = useMemo(() => {
|
|
78
|
+
const { open, ...changing } = connection.mutations;
|
|
79
|
+
/**
|
|
80
|
+
* The call, then the payment read again, then the call's answer. Not
|
|
81
|
+
* read while followed live, nor after a refusal: nothing changed. A
|
|
82
|
+
* refusal as closed is the exception: the payment itself changed
|
|
83
|
+
* (expired, cancelled or paid late), so the page must see it.
|
|
84
|
+
*/
|
|
85
|
+
const reading = (call) => async (args) => {
|
|
86
|
+
const result = await call(args);
|
|
87
|
+
const answer = result;
|
|
88
|
+
const refused = answer?.ok === false;
|
|
89
|
+
const closed = refused && answer.reason === PayRefusalEnum.CLOSED;
|
|
90
|
+
if (!followingNow.current && (!refused || closed))
|
|
91
|
+
await read(args.paymentId);
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
// A product payment is priced by open: read it then, not before. Read
|
|
96
|
+
// even when open threw: a Pay press may have priced it meanwhile.
|
|
97
|
+
open: async (args) => {
|
|
98
|
+
try {
|
|
99
|
+
return await open(args);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
if (shownView.current?.priced === false)
|
|
103
|
+
await read(args.paymentId);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
pay: reading(changing.pay),
|
|
107
|
+
payWithCode: reading(changing.payWithCode),
|
|
108
|
+
checkNow: reading(changing.checkNow),
|
|
109
|
+
cancel: reading(changing.cancel),
|
|
110
|
+
resend: reading(changing.resend),
|
|
111
|
+
simulate: reading(changing.simulate),
|
|
112
|
+
startPaypal: reading(changing.startPaypal),
|
|
113
|
+
startBankRedirect: reading(changing.startBankRedirect),
|
|
114
|
+
// By reference: the checkout reads the payment once it answers.
|
|
115
|
+
paypalClosed: changing.paypalClosed,
|
|
116
|
+
paypalReturned: changing.paypalReturned,
|
|
117
|
+
...(changing.store
|
|
118
|
+
? {
|
|
119
|
+
store: {
|
|
120
|
+
payWithStore: reading(changing.store.payWithStore),
|
|
121
|
+
sendStorePurchase: reading(changing.store.sendStorePurchase),
|
|
122
|
+
storeSheet: reading(changing.store.storeSheet),
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
: {}),
|
|
126
|
+
};
|
|
127
|
+
}, [connection, read]);
|
|
128
|
+
const refresh = useCallback(() => {
|
|
129
|
+
if (paymentId)
|
|
130
|
+
void read(paymentId);
|
|
131
|
+
}, [paymentId, read]);
|
|
132
|
+
// Open gave up on a payment still unpriced: the page says it could not load.
|
|
133
|
+
const fail = useCallback(() => setHeld((previous) => ({ ...previous, failed: true })), []);
|
|
134
|
+
const calls = useMemo(() => ({ mutations, follow: setFollowing, refresh, fail }), [mutations, refresh, fail]);
|
|
135
|
+
return { ...held, calls };
|
|
136
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CheckoutToastToneEnum } from '../models/checkout.enum.js';
|
|
2
|
+
import type { ProviderLogoEnum } from '../models/domain.enum.js';
|
|
3
|
+
import type { CheckoutToast } from '../models/checkout.interface.js';
|
|
4
|
+
/** The time now, moving once a second while `running`: the waiting screen's clock. */
|
|
5
|
+
export declare function useNow(running: boolean): number;
|
|
6
|
+
/**
|
|
7
|
+
* The success screen's countdown back to the app: from 5 while `running`,
|
|
8
|
+
* calling `onDone` at 0. Nothing stops it: the payer always goes back.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useReturnCountdown(running: boolean, onDone: () => void): number;
|
|
11
|
+
/** One short message at a time at the top of the page, with its tone and the method it is about. */
|
|
12
|
+
export declare function useToast(): {
|
|
13
|
+
toast: CheckoutToast | null;
|
|
14
|
+
show: (message: string, tone: CheckoutToastToneEnum, logo?: ProviderLogoEnum | null) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { RETURN_SECONDS, TICK_MS, TOAST_MS, } from "../models/checkout.constants.js";
|
|
3
|
+
/** The time now, moving once a second while `running`: the waiting screen's clock. */
|
|
4
|
+
export function useNow(running) {
|
|
5
|
+
const [now, setNow] = useState(() => Date.now());
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!running)
|
|
8
|
+
return undefined;
|
|
9
|
+
setNow(Date.now());
|
|
10
|
+
const tick = setInterval(() => setNow(Date.now()), TICK_MS);
|
|
11
|
+
return () => clearInterval(tick);
|
|
12
|
+
}, [running]);
|
|
13
|
+
return now;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The success screen's countdown back to the app: from 5 while `running`,
|
|
17
|
+
* calling `onDone` at 0. Nothing stops it: the payer always goes back.
|
|
18
|
+
*/
|
|
19
|
+
export function useReturnCountdown(running, onDone) {
|
|
20
|
+
const [left, setLeft] = useState(RETURN_SECONDS);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!running)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (left === 0) {
|
|
25
|
+
onDone();
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const tick = setTimeout(() => setLeft(left - 1), TICK_MS);
|
|
29
|
+
return () => clearTimeout(tick);
|
|
30
|
+
}, [running, left, onDone]);
|
|
31
|
+
return left;
|
|
32
|
+
}
|
|
33
|
+
/** One short message at a time at the top of the page, with its tone and the method it is about. */
|
|
34
|
+
export function useToast() {
|
|
35
|
+
const [toast, setToast] = useState(null);
|
|
36
|
+
const timer = useRef(undefined);
|
|
37
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
38
|
+
const show = useCallback((message, tone, logo = null) => {
|
|
39
|
+
clearTimeout(timer.current);
|
|
40
|
+
setToast({ message, tone, logo });
|
|
41
|
+
timer.current = setTimeout(() => setToast(null), TOAST_MS);
|
|
42
|
+
}, []);
|
|
43
|
+
return { toast, show };
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PhoneNumber, PhoneNumberOptions } from '../models/checkout.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Mobile Money number, checked by the country's own rules
|
|
4
|
+
* (libphonenumber-js) and grouped as the payer types. A space deleted takes
|
|
5
|
+
* the digit before it. The field itself is the platform's.
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePhoneNumber({ country, countries, onCountryChange, }: PhoneNumberOptions): PhoneNumber;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { DIAL_CODES } from "../models/checkout.constants.js";
|
|
3
|
+
import { caretAfterDigits, formatInternational, formatNational, getPhoneStatus, placeholderOf, readTypedNumber, toE164, } from "../models/checkout.phone.utils.js";
|
|
4
|
+
const digitsOf = (text) => text.replace(/\D/g, '');
|
|
5
|
+
/**
|
|
6
|
+
* The Mobile Money number, checked by the country's own rules
|
|
7
|
+
* (libphonenumber-js) and grouped as the payer types. A space deleted takes
|
|
8
|
+
* the digit before it. The field itself is the platform's.
|
|
9
|
+
*/
|
|
10
|
+
export function usePhoneNumber({ country, countries, onCountryChange, }) {
|
|
11
|
+
const [number, setNumber] = useState({
|
|
12
|
+
country,
|
|
13
|
+
digits: '',
|
|
14
|
+
pending: null,
|
|
15
|
+
});
|
|
16
|
+
const [touched, setTouched] = useState(false);
|
|
17
|
+
const [focused, setFocused] = useState(false);
|
|
18
|
+
const [submitTried, setSubmitTried] = useState(false);
|
|
19
|
+
// The page moved to another country: the number belonged to the previous one.
|
|
20
|
+
const ours = number.country === country;
|
|
21
|
+
const digits = ours ? number.digits : '';
|
|
22
|
+
const pending = ours ? number.pending : null;
|
|
23
|
+
const value = pending === null
|
|
24
|
+
? formatNational(digits, country)
|
|
25
|
+
: formatInternational(pending);
|
|
26
|
+
const type = (typed, caret) => {
|
|
27
|
+
let raw = typed;
|
|
28
|
+
let before = digitsOf(typed.slice(0, caret)).length;
|
|
29
|
+
const international = /^\s*(\+|00)/.test(typed);
|
|
30
|
+
if (!international &&
|
|
31
|
+
typed.length < value.length &&
|
|
32
|
+
digitsOf(typed) === digitsOf(value) &&
|
|
33
|
+
before > 0) {
|
|
34
|
+
// Backspace on a space: the payer meant the digit before it.
|
|
35
|
+
const all = digitsOf(typed);
|
|
36
|
+
raw = all.slice(0, before - 1) + all.slice(before);
|
|
37
|
+
before -= 1;
|
|
38
|
+
}
|
|
39
|
+
const next = readTypedNumber(raw, country, countries);
|
|
40
|
+
setNumber(next);
|
|
41
|
+
setSubmitTried(false);
|
|
42
|
+
if (next.country !== country)
|
|
43
|
+
onCountryChange(next.country);
|
|
44
|
+
return international
|
|
45
|
+
? null
|
|
46
|
+
: caretAfterDigits(formatNational(next.digits, next.country), before);
|
|
47
|
+
};
|
|
48
|
+
const status = getPhoneStatus({
|
|
49
|
+
country,
|
|
50
|
+
digits,
|
|
51
|
+
foreign: pending !== null,
|
|
52
|
+
touched,
|
|
53
|
+
focused,
|
|
54
|
+
submitTried,
|
|
55
|
+
});
|
|
56
|
+
const reject = useCallback(() => {
|
|
57
|
+
setTouched(true);
|
|
58
|
+
setSubmitTried(true);
|
|
59
|
+
}, []);
|
|
60
|
+
const fill = useCallback((e164) => {
|
|
61
|
+
const next = readTypedNumber(e164, country, [country]);
|
|
62
|
+
if (next.country === country && next.pending === null)
|
|
63
|
+
setNumber(next);
|
|
64
|
+
}, [country]);
|
|
65
|
+
return {
|
|
66
|
+
value,
|
|
67
|
+
type,
|
|
68
|
+
e164: pending === null ? toE164(digits, country) : '',
|
|
69
|
+
dial: DIAL_CODES[country],
|
|
70
|
+
placeholder: placeholderOf(country),
|
|
71
|
+
status,
|
|
72
|
+
focused,
|
|
73
|
+
onFocus: () => setFocused(true),
|
|
74
|
+
onBlur: () => {
|
|
75
|
+
setFocused(false);
|
|
76
|
+
if (value.length > 0)
|
|
77
|
+
setTouched(true);
|
|
78
|
+
},
|
|
79
|
+
reject,
|
|
80
|
+
fill,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
total_label: string;
|
|
3
|
+
total: string;
|
|
4
|
+
details: string;
|
|
5
|
+
hide_details: string;
|
|
6
|
+
pay_with: string;
|
|
7
|
+
pay_with_method: string;
|
|
8
|
+
unavailable: string;
|
|
9
|
+
soon: string;
|
|
10
|
+
charged_in: string;
|
|
11
|
+
phone_label: string;
|
|
12
|
+
helper: string;
|
|
13
|
+
phone_errors: {
|
|
14
|
+
start: string;
|
|
15
|
+
short: string;
|
|
16
|
+
invalid: string;
|
|
17
|
+
empty: string;
|
|
18
|
+
country: string;
|
|
19
|
+
operator: string;
|
|
20
|
+
};
|
|
21
|
+
otp_label: string;
|
|
22
|
+
otp_placeholder: string;
|
|
23
|
+
otp_help: string;
|
|
24
|
+
card_fields: {
|
|
25
|
+
title: string;
|
|
26
|
+
number: string;
|
|
27
|
+
number_placeholder: string;
|
|
28
|
+
expiry: string;
|
|
29
|
+
expiry_placeholder: string;
|
|
30
|
+
cvc: string;
|
|
31
|
+
cvc_placeholder: string;
|
|
32
|
+
incomplete: string;
|
|
33
|
+
brand_refused: string;
|
|
34
|
+
unavailable: string;
|
|
35
|
+
};
|
|
36
|
+
mismatch: string;
|
|
37
|
+
switch_to: string;
|
|
38
|
+
pay_short: string;
|
|
39
|
+
pay_plain: string;
|
|
40
|
+
sending: string;
|
|
41
|
+
tab_wallet: string;
|
|
42
|
+
tab_card: string;
|
|
43
|
+
countries: {
|
|
44
|
+
cm: string;
|
|
45
|
+
ci: string;
|
|
46
|
+
sn: string;
|
|
47
|
+
bj: string;
|
|
48
|
+
tg: string;
|
|
49
|
+
bf: string;
|
|
50
|
+
cd: string;
|
|
51
|
+
cg: string;
|
|
52
|
+
ga: string;
|
|
53
|
+
gh: string;
|
|
54
|
+
mw: string;
|
|
55
|
+
rw: string;
|
|
56
|
+
sl: string;
|
|
57
|
+
ug: string;
|
|
58
|
+
zm: string;
|
|
59
|
+
be: string;
|
|
60
|
+
nl: string;
|
|
61
|
+
at: string;
|
|
62
|
+
it: string;
|
|
63
|
+
intl: string;
|
|
64
|
+
};
|
|
65
|
+
country: string;
|
|
66
|
+
continue: string;
|
|
67
|
+
back: string;
|
|
68
|
+
change: string;
|
|
69
|
+
method_missing: string;
|
|
70
|
+
secured_by: string;
|
|
71
|
+
help: string;
|
|
72
|
+
terms: string;
|
|
73
|
+
privacy: string;
|
|
74
|
+
test_sub: string;
|
|
75
|
+
test_badge: string;
|
|
76
|
+
loading: string;
|
|
77
|
+
confirm_title: string;
|
|
78
|
+
sent_to: string;
|
|
79
|
+
manual_to: string;
|
|
80
|
+
remaining: string;
|
|
81
|
+
steps: {
|
|
82
|
+
first: string;
|
|
83
|
+
last: string;
|
|
84
|
+
};
|
|
85
|
+
no_prompt: string;
|
|
86
|
+
send_again_hint: string;
|
|
87
|
+
dial_pending: string;
|
|
88
|
+
send_again: string;
|
|
89
|
+
send_again_in: string;
|
|
90
|
+
cancel: string;
|
|
91
|
+
checking_title: string;
|
|
92
|
+
checking_with: string;
|
|
93
|
+
checking_card: string;
|
|
94
|
+
/** By the flow of a PayPal window (`FLOW_TRAITS.providerWindow`). */
|
|
95
|
+
checking_window: {
|
|
96
|
+
paypal: string;
|
|
97
|
+
bank_redirect: string;
|
|
98
|
+
};
|
|
99
|
+
checking_window_approved: {
|
|
100
|
+
paypal: string;
|
|
101
|
+
bank_redirect: string;
|
|
102
|
+
};
|
|
103
|
+
bank: {
|
|
104
|
+
name_label: string;
|
|
105
|
+
name_placeholder: string;
|
|
106
|
+
name_missing: string;
|
|
107
|
+
other_countries: string;
|
|
108
|
+
window_title: string;
|
|
109
|
+
lost_title: string;
|
|
110
|
+
lost_hint: string;
|
|
111
|
+
not_finished: string;
|
|
112
|
+
};
|
|
113
|
+
paypal: {
|
|
114
|
+
window_approved: string;
|
|
115
|
+
window_cancelled: string;
|
|
116
|
+
window_back: string;
|
|
117
|
+
};
|
|
118
|
+
simulator: {
|
|
119
|
+
title: string;
|
|
120
|
+
body: string;
|
|
121
|
+
no_answer: string;
|
|
122
|
+
approved: string;
|
|
123
|
+
declined: string;
|
|
124
|
+
insufficient_funds: string;
|
|
125
|
+
no_account: string;
|
|
126
|
+
wrong_pin: string;
|
|
127
|
+
wrong_code: string;
|
|
128
|
+
provider_error: string;
|
|
129
|
+
wrong_amount: string;
|
|
130
|
+
approved_late: string;
|
|
131
|
+
reversed: string;
|
|
132
|
+
approved_all: string;
|
|
133
|
+
};
|
|
134
|
+
failure: {
|
|
135
|
+
declined: {
|
|
136
|
+
title: string;
|
|
137
|
+
body: string;
|
|
138
|
+
next: string;
|
|
139
|
+
};
|
|
140
|
+
insufficient_funds: {
|
|
141
|
+
title: string;
|
|
142
|
+
body: string;
|
|
143
|
+
next: string;
|
|
144
|
+
};
|
|
145
|
+
no_account: {
|
|
146
|
+
title: string;
|
|
147
|
+
body: string;
|
|
148
|
+
next: string;
|
|
149
|
+
};
|
|
150
|
+
wrong_pin: {
|
|
151
|
+
title: string;
|
|
152
|
+
body: string;
|
|
153
|
+
next: string;
|
|
154
|
+
};
|
|
155
|
+
wrong_code: {
|
|
156
|
+
title: string;
|
|
157
|
+
body: string;
|
|
158
|
+
next: string;
|
|
159
|
+
};
|
|
160
|
+
wrong_card_details: {
|
|
161
|
+
title: string;
|
|
162
|
+
body: string;
|
|
163
|
+
next: string;
|
|
164
|
+
};
|
|
165
|
+
provider_error: {
|
|
166
|
+
title: string;
|
|
167
|
+
body: string;
|
|
168
|
+
next: string;
|
|
169
|
+
};
|
|
170
|
+
timeout: {
|
|
171
|
+
title: string;
|
|
172
|
+
body: string;
|
|
173
|
+
next: string;
|
|
174
|
+
};
|
|
175
|
+
mismatch: {
|
|
176
|
+
title: string;
|
|
177
|
+
body: string;
|
|
178
|
+
next: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
retry: string;
|
|
182
|
+
retry_code: string;
|
|
183
|
+
use_another: string;
|
|
184
|
+
try_with: string;
|
|
185
|
+
tries_left: string;
|
|
186
|
+
tries_value: string;
|
|
187
|
+
not_charged: string;
|
|
188
|
+
success_title: string;
|
|
189
|
+
paid_to: string;
|
|
190
|
+
amount: string;
|
|
191
|
+
method: string;
|
|
192
|
+
number: string;
|
|
193
|
+
card: string;
|
|
194
|
+
date: string;
|
|
195
|
+
reference: string;
|
|
196
|
+
copy: string;
|
|
197
|
+
copied: string;
|
|
198
|
+
return_to: string;
|
|
199
|
+
return_in: string;
|
|
200
|
+
expired: {
|
|
201
|
+
title: string;
|
|
202
|
+
body: string;
|
|
203
|
+
};
|
|
204
|
+
cancelled: {
|
|
205
|
+
title: string;
|
|
206
|
+
body: string;
|
|
207
|
+
};
|
|
208
|
+
locked_screen: {
|
|
209
|
+
title: string;
|
|
210
|
+
body: string;
|
|
211
|
+
};
|
|
212
|
+
invalid: {
|
|
213
|
+
title: string;
|
|
214
|
+
body: string;
|
|
215
|
+
};
|
|
216
|
+
no_method: {
|
|
217
|
+
title: string;
|
|
218
|
+
body: string;
|
|
219
|
+
};
|
|
220
|
+
contact_support: string;
|
|
221
|
+
get_help: string;
|
|
222
|
+
returning: string;
|
|
223
|
+
not_redirected: string;
|
|
224
|
+
contact_title: string;
|
|
225
|
+
reference_title: string;
|
|
226
|
+
reference_hint: string;
|
|
227
|
+
close: string;
|
|
228
|
+
sheet: {
|
|
229
|
+
approve_title: string;
|
|
230
|
+
approve_body: string;
|
|
231
|
+
expires_in: string;
|
|
232
|
+
manual_body: string;
|
|
233
|
+
done_in: string;
|
|
234
|
+
close_title: string;
|
|
235
|
+
close_body: string;
|
|
236
|
+
keep_waiting: string;
|
|
237
|
+
dial: string;
|
|
238
|
+
store_pay: string;
|
|
239
|
+
store_body: string;
|
|
240
|
+
store_refund_consent: string;
|
|
241
|
+
store_checking: string;
|
|
242
|
+
store_pending_title: string;
|
|
243
|
+
store_pending_body: string;
|
|
244
|
+
};
|
|
245
|
+
faqs: {
|
|
246
|
+
not_received: {
|
|
247
|
+
q: string;
|
|
248
|
+
a: string;
|
|
249
|
+
};
|
|
250
|
+
debited: {
|
|
251
|
+
q: string;
|
|
252
|
+
a: string;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
channels: {
|
|
256
|
+
whatsapp: string;
|
|
257
|
+
email: string;
|
|
258
|
+
};
|
|
259
|
+
not_found: {
|
|
260
|
+
title: string;
|
|
261
|
+
body: string;
|
|
262
|
+
};
|
|
263
|
+
error: {
|
|
264
|
+
title: string;
|
|
265
|
+
body: string;
|
|
266
|
+
retry: string;
|
|
267
|
+
};
|
|
268
|
+
refusals: {
|
|
269
|
+
closed: string;
|
|
270
|
+
method: string;
|
|
271
|
+
phone: string;
|
|
272
|
+
code: string;
|
|
273
|
+
busy: string;
|
|
274
|
+
name: string;
|
|
275
|
+
};
|
|
276
|
+
toast: {
|
|
277
|
+
copied: string;
|
|
278
|
+
switched: string;
|
|
279
|
+
unavailable: string;
|
|
280
|
+
soon: string;
|
|
281
|
+
no_answer: string;
|
|
282
|
+
failed: string;
|
|
283
|
+
sent_again: string;
|
|
284
|
+
send_again_wait: string;
|
|
285
|
+
preview: string;
|
|
286
|
+
dial: string;
|
|
287
|
+
method_unavailable: string;
|
|
288
|
+
};
|
|
289
|
+
dark_mode: string;
|
|
290
|
+
light_mode: string;
|
|
291
|
+
language_label: string;
|
|
292
|
+
meta: {
|
|
293
|
+
title: string;
|
|
294
|
+
description: string;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
export default _default;
|