@brissoto/pay-react-native 1.6.3 → 1.6.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.
|
@@ -284,7 +284,7 @@ export interface CheckoutDerived {
|
|
|
284
284
|
mismatch: CheckoutMethod | null;
|
|
285
285
|
/** After a failure: another method of the same country the payer can use now. */
|
|
286
286
|
suggestion: CheckoutMethod | null;
|
|
287
|
-
/** What the payer pays: the picked method's price, else the last attempt's, else the payment's amount (ADR 0012). */
|
|
287
|
+
/** What the payer pays: the picked method's price, else the open tab's while choosing, else the last attempt's, else the payment's amount (ADR 0012). */
|
|
288
288
|
total: Price;
|
|
289
289
|
}
|
|
290
290
|
export interface CheckoutCoreActions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CheckoutScreenEnum, FlowAskEnum, SimulatorOutcomeEnum } from './checkout.enum.js';
|
|
1
|
+
import { CheckoutScreenEnum, CheckoutTabEnum, FlowAskEnum, SimulatorOutcomeEnum } from './checkout.enum.js';
|
|
2
2
|
import { CountryEnum } from './domain.enum.js';
|
|
3
3
|
import type { LangEnum, ProviderLogoEnum } from './domain.enum.js';
|
|
4
|
-
import type { CheckoutApp, CheckoutAttempt, CheckoutDerived, CheckoutMethod, CheckoutPreviewApp, CheckoutUi, CheckoutView, CountryClues, DialHelp, PayInput, PhoneStatus, SupportContact } from './checkout.interface.js';
|
|
4
|
+
import type { CheckoutApp, CheckoutAttempt, CheckoutDerived, CheckoutMethod, CheckoutPreviewApp, CheckoutUi, CheckoutView, CountryClues, DialHelp, PayInput, PhoneStatus, Price, SupportContact } from './checkout.interface.js';
|
|
5
5
|
/** Countries with Mobile Money methods, in the order their first method comes. */
|
|
6
6
|
export declare function countriesOf(methods: Array<CheckoutMethod>): Array<CountryEnum>;
|
|
7
7
|
/**
|
|
@@ -10,6 +10,8 @@ export declare function countriesOf(methods: Array<CheckoutMethod>): Array<Count
|
|
|
10
10
|
* the first the gateway serves, for a page that has nothing to offer.
|
|
11
11
|
*/
|
|
12
12
|
export declare function pickCountry(view: CheckoutView, clues: CountryClues, countries: Array<CountryEnum>): CountryEnum;
|
|
13
|
+
/** The method takes payments now: not down, closed or coming soon. */
|
|
14
|
+
export declare const isAvailable: (method: Pick<CheckoutMethod, "state">) => boolean;
|
|
13
15
|
/**
|
|
14
16
|
* How the page opens: on the details of the app's preferred method when it
|
|
15
17
|
* can be paid with, or of the only one that can; else on the methods, on its
|
|
@@ -33,6 +35,14 @@ export declare function missingBeforePay(method: Pick<CheckoutMethod, 'flow'>, i
|
|
|
33
35
|
export declare const payInputOf: (ui: CheckoutUi, phone: PhoneStatus) => PayInput;
|
|
34
36
|
/** The tile of a method or an attempt: the generic card for cards, whatever networks they take. */
|
|
35
37
|
export declare function logoOf(of: Pick<CheckoutMethod, 'flow' | 'logos'>): ProviderLogoEnum;
|
|
38
|
+
/**
|
|
39
|
+
* What the open tab costs while nothing is picked, so its amount never mixes
|
|
40
|
+
* groups (ADR 0012): the card's own price on the Card tab (a payer in Belgium
|
|
41
|
+
* sees euros), the wallets' on Mobile Money. A method that takes payments
|
|
42
|
+
* comes first; a tab whose methods are all down still says its currency. The
|
|
43
|
+
* store tab has its own price: none here.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tabPriceOf(tab: CheckoutTabEnum, methods: Array<CheckoutMethod>): Price | undefined;
|
|
36
46
|
/** Works out what the screens show from the payment, the page and the number typed. */
|
|
37
47
|
export declare function deriveCheckout(view: CheckoutView, ui: CheckoutUi, phone: PhoneStatus): CheckoutDerived;
|
|
38
48
|
/** Seconds left to approve an attempt started at `startedAt`. */
|
|
@@ -19,6 +19,8 @@ export function pickCountry(view, clues, countries) {
|
|
|
19
19
|
const served = countries.find((country) => country === payerCountry);
|
|
20
20
|
return served ?? countries.at(0) ?? Object.values(CountryEnum)[0];
|
|
21
21
|
}
|
|
22
|
+
/** The method takes payments now: not down, closed or coming soon. */
|
|
23
|
+
export const isAvailable = (method) => method.state === MethodStateEnum.AVAILABLE;
|
|
22
24
|
/**
|
|
23
25
|
* How the page opens: on the details of the app's preferred method when it
|
|
24
26
|
* can be paid with, or of the only one that can; else on the methods, on its
|
|
@@ -27,7 +29,7 @@ export function pickCountry(view, clues, countries) {
|
|
|
27
29
|
*/
|
|
28
30
|
export function initialUi(view, clues) {
|
|
29
31
|
const countries = countriesOf(view.methods);
|
|
30
|
-
const available = view.methods.filter(
|
|
32
|
+
const available = view.methods.filter(isAvailable);
|
|
31
33
|
const opening = available.find((method) => method.id === view.preferredMethod) ??
|
|
32
34
|
(available.length === 1 ? available[0] : undefined);
|
|
33
35
|
const payer = payerCountryOf(view, clues);
|
|
@@ -145,6 +147,21 @@ export const payInputOf = (ui, phone) => ({
|
|
|
145
147
|
export function logoOf(of) {
|
|
146
148
|
return FLOW_TRAITS[of.flow].genericTile ? CARD_LOGO : of.logos[0];
|
|
147
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* What the open tab costs while nothing is picked, so its amount never mixes
|
|
152
|
+
* groups (ADR 0012): the card's own price on the Card tab (a payer in Belgium
|
|
153
|
+
* sees euros), the wallets' on Mobile Money. A method that takes payments
|
|
154
|
+
* comes first; a tab whose methods are all down still says its currency. The
|
|
155
|
+
* store tab has its own price: none here.
|
|
156
|
+
*/
|
|
157
|
+
export function tabPriceOf(tab, methods) {
|
|
158
|
+
if (tab === CheckoutTabEnum.STORE)
|
|
159
|
+
return undefined;
|
|
160
|
+
const payable = methods.filter(isAvailable);
|
|
161
|
+
return (payable.find((method) => FLOW_TRAITS[method.flow].genericTile) ??
|
|
162
|
+
payable.at(0) ??
|
|
163
|
+
methods.at(0))?.price;
|
|
164
|
+
}
|
|
148
165
|
/** Works out what the screens show from the payment, the page and the number typed. */
|
|
149
166
|
export function deriveCheckout(view, ui, phone) {
|
|
150
167
|
const wallets = view.methods.filter((method) => method.kind === MethodKindEnum.MOBILE_MONEY &&
|
|
@@ -157,22 +174,22 @@ export function deriveCheckout(view, ui, phone) {
|
|
|
157
174
|
? []
|
|
158
175
|
: view.methods.filter((method) => FLOW_TRAITS[method.flow].countryScheme && !home(method));
|
|
159
176
|
const onCard = ui.tab === CheckoutTabEnum.CARD;
|
|
160
|
-
const
|
|
161
|
-
const
|
|
177
|
+
const tabMethods = onCard ? [...cards, ...otherBanks] : wallets;
|
|
178
|
+
const picked = tabMethods.find((method) => method.id === ui.method);
|
|
179
|
+
const selected = picked && isAvailable(picked) ? picked : null;
|
|
162
180
|
const missing = selected
|
|
163
181
|
? missingBeforePay(selected, payInputOf(ui, phone))
|
|
164
182
|
: [];
|
|
165
183
|
const detected = phone.valid
|
|
166
|
-
? (wallets.find((method) => method
|
|
167
|
-
brandOf(method) === phone.operator) ?? null)
|
|
184
|
+
? (wallets.find((method) => isAvailable(method) && brandOf(method) === phone.operator) ?? null)
|
|
168
185
|
: null;
|
|
169
186
|
const failed = view.methods.find((method) => method.id === view.attempt?.method);
|
|
170
187
|
const suggestion = view.methods.find((method) => method.kind === MethodKindEnum.MOBILE_MONEY &&
|
|
171
|
-
method
|
|
188
|
+
isAvailable(method) &&
|
|
172
189
|
method.country === failed?.country &&
|
|
173
190
|
method.id !== failed.id) ?? null;
|
|
174
191
|
const screen = screenOf(view, ui);
|
|
175
|
-
// On the methods, nothing picked: the
|
|
192
|
+
// On the methods, nothing picked: the open tab's price, never a past attempt's.
|
|
176
193
|
const choosing = screen === CheckoutScreenEnum.FORM ||
|
|
177
194
|
screen === CheckoutScreenEnum.SUBMITTING;
|
|
178
195
|
return {
|
|
@@ -190,7 +207,7 @@ export function deriveCheckout(view, ui, phone) {
|
|
|
190
207
|
canPay: !!selected && missing.length === 0 && !ui.submitting && !ui.cardPaying,
|
|
191
208
|
detected,
|
|
192
209
|
total: selected?.price ??
|
|
193
|
-
(choosing ?
|
|
210
|
+
(choosing ? tabPriceOf(ui.tab, tabMethods) : view.attempt?.price) ?? {
|
|
194
211
|
amount: view.amount,
|
|
195
212
|
currency: view.currency,
|
|
196
213
|
},
|
|
@@ -20,13 +20,14 @@ export function SheetSuccess({ core, onClose }) {
|
|
|
20
20
|
const format = useFormatter();
|
|
21
21
|
const { colors } = useSheetTheme();
|
|
22
22
|
const { view, returnLeft } = core;
|
|
23
|
-
// Only a status check pays a payment: there is always an attempt
|
|
23
|
+
// Only a status check pays a payment: there is always an attempt, and its
|
|
24
|
+
// price is what was charged (euros by card), not the payment's first price.
|
|
24
25
|
const attempt = view.attempt;
|
|
25
26
|
return (_jsx(SheetLayout, { foot: _jsx(SheetButton
|
|
26
27
|
// Nothing stops the countdown in the sheet: it always runs here.
|
|
27
28
|
, {
|
|
28
29
|
// 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(
|
|
30
|
+
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(attempt.price.amount, attempt.price.currency) }), _jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, size: 16, color: colors.ink2, children: CURRENCY_LABEL[attempt.price.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
31
|
day: 'numeric',
|
|
31
32
|
month: 'short',
|
|
32
33
|
year: 'numeric',
|