@brissoto/pay-react-native 1.6.4 → 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.
@@ -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((method) => method.state === MethodStateEnum.AVAILABLE);
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,18 @@ 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 shown = onCard ? [...cards, ...otherBanks] : wallets;
161
- const picked = shown.find((method) => method.id === ui.method);
162
- // Nothing picked yet: the open tab's price (EUR on cards, XAF on Cameroon's wallets).
163
- const tabPrice = (shown.find((method) => method.state === MethodStateEnum.AVAILABLE) ??
164
- shown.at(0))?.price;
165
- const selected = picked?.state === MethodStateEnum.AVAILABLE ? picked : null;
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;
166
180
  const missing = selected
167
181
  ? missingBeforePay(selected, payInputOf(ui, phone))
168
182
  : [];
169
183
  const detected = phone.valid
170
- ? (wallets.find((method) => method.state === MethodStateEnum.AVAILABLE &&
171
- brandOf(method) === phone.operator) ?? null)
184
+ ? (wallets.find((method) => isAvailable(method) && brandOf(method) === phone.operator) ?? null)
172
185
  : null;
173
186
  const failed = view.methods.find((method) => method.id === view.attempt?.method);
174
187
  const suggestion = view.methods.find((method) => method.kind === MethodKindEnum.MOBILE_MONEY &&
175
- method.state === MethodStateEnum.AVAILABLE &&
188
+ isAvailable(method) &&
176
189
  method.country === failed?.country &&
177
190
  method.id !== failed.id) ?? null;
178
191
  const screen = screenOf(view, ui);
@@ -194,7 +207,7 @@ export function deriveCheckout(view, ui, phone) {
194
207
  canPay: !!selected && missing.length === 0 && !ui.submitting && !ui.cardPaying,
195
208
  detected,
196
209
  total: selected?.price ??
197
- (choosing ? tabPrice : view.attempt?.price) ?? {
210
+ (choosing ? tabPriceOf(ui.tab, tabMethods) : view.attempt?.price) ?? {
198
211
  amount: view.amount,
199
212
  currency: view.currency,
200
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(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
+ 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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brissoto/pay-react-native",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "Brissoto Pay for Expo and React Native apps: the payment sheet.",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,