@brissoto/pay-react-native 1.6.4 → 1.7.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/README.md CHANGED
@@ -202,7 +202,7 @@ Style the buttons at the foot of the sheet, per kind. Anything left out keeps th
202
202
  | ----------- | --------------------------------------------------------------------------------------------------------------- |
203
203
  | `primary` | Continue, Pay, Pay with the store, Try again, Done, Return to the app. PayPal takes its height and radius only. |
204
204
  | `secondary` | Send again (outlined). |
205
- | `plain` | Try with…, Use another method (no border). |
205
+ | `plain` | Try with…, Use another method: a text button, so `fontSize` and `labelColor` only. |
206
206
 
207
207
  | Field | Default | Allowed |
208
208
  | ------------ | ------------------------------------------------- | ------------------------------ |
@@ -192,7 +192,7 @@ export declare enum TerminalKindEnum {
192
192
  export declare enum CheckoutButtonVariantEnum {
193
193
  PRIMARY = "primary",
194
194
  SECONDARY = "secondary",
195
- /** The second choice under Pay or Try again: the secondary's look, no border. */
195
+ /** The second choice under Pay or Try again: a text button, no box, centred. */
196
196
  PLAIN = "plain",
197
197
  /** Gives something up: cancelling the payment. */
198
198
  DANGER = "danger",
@@ -215,7 +215,7 @@ export var CheckoutButtonVariantEnum;
215
215
  (function (CheckoutButtonVariantEnum) {
216
216
  CheckoutButtonVariantEnum["PRIMARY"] = "primary";
217
217
  CheckoutButtonVariantEnum["SECONDARY"] = "secondary";
218
- /** The second choice under Pay or Try again: the secondary's look, no border. */
218
+ /** The second choice under Pay or Try again: a text button, no box, centred. */
219
219
  CheckoutButtonVariantEnum["PLAIN"] = "plain";
220
220
  /** Gives something up: cancelling the payment. */
221
221
  CheckoutButtonVariantEnum["DANGER"] = "danger";
@@ -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
  },
@@ -1,8 +1,8 @@
1
1
  import type { SheetButtonProps } from '../models/sheet.interface.js';
2
2
  /**
3
3
  * The sheet's buttons: filled in the app colour for the main action,
4
- * outlined for the rest, plain (no border) for a quiet second choice, a link
5
- * in the app colour for a quiet action in a line of its own. In the sheet's
6
- * foot, the app's appearance sets their height, corner and label.
4
+ * outlined for the rest, plain (a text button, no box) for a quiet second
5
+ * choice, a link in the app colour for a quiet action in a line of its own.
6
+ * In the sheet's foot, the app's appearance sets their height, corner and label.
7
7
  */
8
8
  export declare function SheetButton({ label, onPress, variant, busy, disabled, inactive, }: SheetButtonProps): import("react").JSX.Element;
@@ -7,29 +7,32 @@ import { FigtreeEnum } from "../models/sheet.enum.js";
7
7
  import { SheetText } from "./SheetText.js";
8
8
  /**
9
9
  * The sheet's buttons: filled in the app colour for the main action,
10
- * outlined for the rest, plain (no border) for a quiet second choice, a link
11
- * in the app colour for a quiet action in a line of its own. In the sheet's
12
- * foot, the app's appearance sets their height, corner and label.
10
+ * outlined for the rest, plain (a text button, no box) for a quiet second
11
+ * choice, a link in the app colour for a quiet action in a line of its own.
12
+ * In the sheet's foot, the app's appearance sets their height, corner and label.
13
13
  */
14
14
  export function SheetButton({ label, onPress, variant = CheckoutButtonVariantEnum.PRIMARY, busy = false, disabled = false, inactive = false, }) {
15
15
  const { colors, brand } = useSheetTheme();
16
16
  const primary = variant === CheckoutButtonVariantEnum.PRIMARY;
17
17
  const link = variant === CheckoutButtonVariantEnum.LINK;
18
+ const plain = variant === CheckoutButtonVariantEnum.PLAIN;
18
19
  const look = useSheetButtonLook(variant);
19
20
  const ink = look.labelColor ?? (primary ? 'white' : link ? brand : colors.ink);
20
21
  const off = disabled || busy;
21
22
  return (_jsxs(TouchableOpacity, { onPress: onPress, disabled: off, activeOpacity: 0.8, accessibilityRole: "button", accessibilityState: { disabled: off, busy },
22
- // A link's text is short: its tap reaches a little past it.
23
- hitSlop: link ? 6 : undefined, style: [
23
+ // A text button is short: its tap reaches a little past it.
24
+ hitSlop: link ? 6 : plain ? 8 : undefined, style: [
24
25
  link
25
26
  ? styles.link
26
- : [
27
- styles.button,
28
- { minHeight: look.height, borderRadius: look.radius },
29
- ],
27
+ : plain
28
+ ? styles.plain
29
+ : [
30
+ styles.button,
31
+ { minHeight: look.height, borderRadius: look.radius },
32
+ ],
30
33
  primary
31
34
  ? { backgroundColor: brand }
32
- : variant !== CheckoutButtonVariantEnum.PLAIN &&
35
+ : !plain &&
33
36
  !link && {
34
37
  borderWidth: 1,
35
38
  borderColor: colors.line3,
@@ -45,6 +48,15 @@ const styles = StyleSheet.create({
45
48
  gap: 10,
46
49
  paddingHorizontal: 16,
47
50
  },
51
+ // Text only, centred under the action it backs up: no box, no full width.
52
+ plain: {
53
+ alignSelf: 'center',
54
+ flexDirection: 'row',
55
+ alignItems: 'center',
56
+ gap: 10,
57
+ paddingVertical: 6,
58
+ paddingHorizontal: 12,
59
+ },
48
60
  // The web's link: a line of its own, as tall as a tap needs.
49
61
  link: { alignSelf: 'flex-start', height: 32, justifyContent: 'center' },
50
62
  label: { textAlign: 'center', fontVariant: ['tabular-nums'] },
@@ -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/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { BrissotoPayProvider } from './components/BrissotoPayProvider.js';
2
2
  export { usePaymentSheet } from './hooks/use-payment-sheet.js';
3
- export type { BrissotoPayAppearance, BrissotoPayButtonAppearance, BrissotoPayButtonsAppearance, BrissotoPayProviderProps, BrissotoPayThemedColor, PaymentSheet, PaymentSheetError, PaymentSheetResult, PaymentSheetStatus, PresentPaymentOptions, } from './models/sheet.interface.js';
3
+ export type { BrissotoPayAppearance, BrissotoPayButtonAppearance, BrissotoPayTextButtonAppearance, BrissotoPayButtonsAppearance, BrissotoPayProviderProps, BrissotoPayThemedColor, PaymentSheet, PaymentSheetError, PaymentSheetResult, PaymentSheetStatus, PresentPaymentOptions, } from './models/sheet.interface.js';
@@ -43,19 +43,22 @@ export interface BrissotoPayButtonsAppearance {
43
43
  primary?: BrissotoPayButtonAppearance;
44
44
  /** Outlined: Send again. */
45
45
  secondary?: BrissotoPayButtonAppearance;
46
- /** No border, a quiet second choice: Try with…, Use another method. */
47
- plain?: BrissotoPayButtonAppearance;
46
+ /** A text button, no box: Try with…, Use another method. Its label only. */
47
+ plain?: BrissotoPayTextButtonAppearance;
48
48
  }
49
- export interface BrissotoPayButtonAppearance {
50
- /** In points, 44 at least (50 by default). */
51
- height?: number;
52
- /** In points, half the height at most: a pill (14 by default). */
53
- radius?: number;
49
+ /** A text button's label. */
50
+ export interface BrissotoPayTextButtonAppearance {
54
51
  /** The label's size in points, 12 to 22 (16 by default). */
55
52
  fontSize?: number;
56
53
  /** The label's colour: one for both themes, or one per theme. */
57
54
  labelColor?: string | BrissotoPayThemedColor;
58
55
  }
56
+ export interface BrissotoPayButtonAppearance extends BrissotoPayTextButtonAppearance {
57
+ /** In points, 44 at least (50 by default). */
58
+ height?: number;
59
+ /** In points, half the height at most: a pill (14 by default). */
60
+ radius?: number;
61
+ }
59
62
  export interface BrissotoPayThemedColor {
60
63
  light: string;
61
64
  dark: string;
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.7.0",
4
4
  "description": "Brissoto Pay for Expo and React Native apps: the payment sheet.",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,