@brissoto/pay-react-native 1.4.5 → 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.
package/README.md CHANGED
@@ -139,15 +139,16 @@ Open the sheet with it: `presentPayment({ paymentId })`. Ship on the `payment.pa
139
139
 
140
140
  ## Results
141
141
 
142
- | `result.status` | When |
143
- | --------------- | ----------------------------------------------------------------------------------------- |
144
- | `paid` | The payment is paid. |
145
- | `pending` | The payer closed the sheet while a prompt waited on their phone: it may still go through. |
146
- | `closed` | The payer closed the sheet with the payment still open. |
147
- | `cancelled` | The payment was cancelled. |
148
- | `expired` | The payment expired. |
149
- | `locked` | Too many failed tries: the payment can no longer be paid. |
150
- | `refunded` | A store refunded the payment. |
142
+ | `result.status` | When |
143
+ | --------------- | ---------------------------------------------------------------------------------------------- |
144
+ | `paid` | The payment is paid. |
145
+ | `pending` | The payer closed the sheet while a prompt waited on their phone: it may still go through. |
146
+ | `closed` | The payer closed the sheet with the payment still open. |
147
+ | `cancelled` | The payment was cancelled. |
148
+ | `expired` | The payment expired. |
149
+ | `locked` | Too many failed tries: the payment can no longer be paid. |
150
+ | `refunded` | A store refunded the payment. |
151
+ | `unavailable` | No method could take the payment (`payment.unavailable`): the sheet said so. Nothing was paid. |
151
152
 
152
153
  When the sheet could not show the payment, `status` is `closed` and `result.error` says why: `not_found` (no payment has this id) or `network` (it could not load).
153
154
 
@@ -67,6 +67,7 @@ declare const _default: {
67
67
  back: string;
68
68
  change: string;
69
69
  method_missing: string;
70
+ tab_empty: string;
70
71
  secured_by: string;
71
72
  help: string;
72
73
  terms: string;
@@ -217,6 +218,10 @@ declare const _default: {
217
218
  title: string;
218
219
  body: string;
219
220
  };
221
+ unavailable_screen: {
222
+ title: string;
223
+ body: string;
224
+ };
220
225
  contact_support: string;
221
226
  get_help: string;
222
227
  returning: string;
@@ -67,6 +67,7 @@ export default {
67
67
  back: 'Back to payment methods',
68
68
  change: 'Change',
69
69
  method_missing: 'Choose a payment method',
70
+ tab_empty: 'No payment method available here for now.',
70
71
  secured_by: 'Payment secured by',
71
72
  help: 'Need help?',
72
73
  terms: 'Terms',
@@ -217,6 +218,10 @@ export default {
217
218
  title: 'No way to pay right now',
218
219
  body: '{app} offers no payment method at the moment. Try again later.',
219
220
  },
221
+ unavailable_screen: {
222
+ title: 'Payment unavailable',
223
+ body: 'No payment method is available in your country yet.',
224
+ },
220
225
  contact_support: 'Contact support',
221
226
  get_help: 'Get help',
222
227
  returning: 'Returning to {app}…',
@@ -68,6 +68,7 @@ const messages = {
68
68
  back: 'Retour aux moyens de paiement',
69
69
  change: 'Modifier',
70
70
  method_missing: 'Choisissez un moyen de paiement',
71
+ tab_empty: 'Aucun moyen de paiement disponible ici pour le moment.',
71
72
  secured_by: 'Paiement sécurisé par',
72
73
  help: "Besoin d'aide ?",
73
74
  terms: 'Conditions',
@@ -217,6 +218,10 @@ const messages = {
217
218
  title: 'Aucun moyen de paiement pour le moment',
218
219
  body: '{app} ne propose aucun moyen de paiement en ce moment. Réessayez plus tard.',
219
220
  },
221
+ unavailable_screen: {
222
+ title: 'Paiement indisponible',
223
+ body: "Aucun moyen de paiement n'est encore disponible dans votre pays.",
224
+ },
220
225
  contact_support: 'Contacter le support',
221
226
  get_help: "Obtenir de l'aide",
222
227
  returning: 'Retour à {app}…',
@@ -12,6 +12,8 @@ export declare enum CheckoutScreenEnum {
12
12
  INVALID = "invalid",
13
13
  /** Every method went off since the link was made: nothing to pay with. */
14
14
  NO_METHOD = "no_method",
15
+ /** No method could take it when it was made: it never will. */
16
+ UNAVAILABLE = "unavailable",
15
17
  REDIRECT = "redirect"
16
18
  }
17
19
  /** The form's two steps: pick a method, then what it needs (the number and its code, or the card). */
@@ -190,7 +192,8 @@ export declare enum TerminalKindEnum {
190
192
  CANCELLED = "cancelled",
191
193
  LOCKED = "locked",
192
194
  INVALID = "invalid",
193
- NO_METHOD = "no_method"
195
+ NO_METHOD = "no_method",
196
+ UNAVAILABLE = "unavailable"
194
197
  }
195
198
  export declare enum CheckoutButtonVariantEnum {
196
199
  PRIMARY = "primary",
@@ -13,6 +13,8 @@ export var CheckoutScreenEnum;
13
13
  CheckoutScreenEnum["INVALID"] = "invalid";
14
14
  /** Every method went off since the link was made: nothing to pay with. */
15
15
  CheckoutScreenEnum["NO_METHOD"] = "no_method";
16
+ /** No method could take it when it was made: it never will. */
17
+ CheckoutScreenEnum["UNAVAILABLE"] = "unavailable";
16
18
  CheckoutScreenEnum["REDIRECT"] = "redirect";
17
19
  })(CheckoutScreenEnum || (CheckoutScreenEnum = {}));
18
20
  /** The form's two steps: pick a method, then what it needs (the number and its code, or the card). */
@@ -213,6 +215,7 @@ export var TerminalKindEnum;
213
215
  TerminalKindEnum["LOCKED"] = "locked";
214
216
  TerminalKindEnum["INVALID"] = "invalid";
215
217
  TerminalKindEnum["NO_METHOD"] = "no_method";
218
+ TerminalKindEnum["UNAVAILABLE"] = "unavailable";
216
219
  })(TerminalKindEnum || (TerminalKindEnum = {}));
217
220
  export var CheckoutButtonVariantEnum;
218
221
  (function (CheckoutButtonVariantEnum) {
@@ -139,6 +139,8 @@ export interface CheckoutView {
139
139
  preferredTab: CheckoutTabEnum | null;
140
140
  app: CheckoutApp;
141
141
  methods: Array<CheckoutMethod>;
142
+ /** No method could take it when it was created: nothing can ever be paid on it. */
143
+ unavailable: boolean;
142
144
  /**
143
145
  * False for a store product's payment until the payment sheet first
144
146
  * opens it: its currency and amount are not set yet.
@@ -87,6 +87,8 @@ export function screenOf(view, ui) {
87
87
  const terminal = TERMINAL_SCREEN[view.status];
88
88
  if (terminal)
89
89
  return terminal;
90
+ if (view.unavailable)
91
+ return CheckoutScreenEnum.UNAVAILABLE;
90
92
  // A store product's price comes once the sheet said it opened.
91
93
  if (!view.priced)
92
94
  return CheckoutScreenEnum.LOADING;
@@ -282,6 +284,7 @@ export function previewView(app, methods) {
282
284
  theme: null,
283
285
  preferredMethod: null,
284
286
  preferredTab: null,
287
+ unavailable: false,
285
288
  priced: true,
286
289
  stores: [],
287
290
  attemptsLeft: 0,
@@ -30,6 +30,7 @@ const TERMINAL_KIND = {
30
30
  [CheckoutScreenEnum.CANCELLED]: TerminalKindEnum.CANCELLED,
31
31
  [CheckoutScreenEnum.LOCKED]: TerminalKindEnum.LOCKED,
32
32
  [CheckoutScreenEnum.NO_METHOD]: TerminalKindEnum.NO_METHOD,
33
+ [CheckoutScreenEnum.UNAVAILABLE]: TerminalKindEnum.UNAVAILABLE,
33
34
  };
34
35
  /** The sheet's screens, driven by the shared checkout controller. */
35
36
  export function SheetContent({ payment, fontsReady, deviceLocale, ipCountry, onClose, dragHandlers, backRef, }) {
@@ -28,7 +28,7 @@ function GridRows({ cards, missing, alone }) {
28
28
  return rows.map((row) => (_jsxs(View, { style: styles.gridRow, children: [row.map(({ id, ...card }) => (_jsx(SheetMethodCard, { ...card, missing: missing, alone: alone }, id))), row.length === 1 && !alone && _jsx(View, { style: styles.gridSpacer })] }, row[0].id)));
29
29
  }
30
30
  /**
31
- * The tab's methods, a lone one full width; then, on the Card tab of a
31
+ * The tab's methods, a lone one full width, or a line saying it has none; then, on the Card tab of a
32
32
  * guessed country, the other countries' bank redirects behind "Paying from
33
33
  * another country?". Red with a hint, and shaken, after Continue with none picked.
34
34
  */
@@ -36,7 +36,7 @@ function MethodGrid({ cards, others, missing }) {
36
36
  const t = useTranslations('checkout');
37
37
  const { colors } = useSheetTheme();
38
38
  const shake = useShake(missing);
39
- return (_jsxs(Animated.View, { testID: "method-grid", accessibilityRole: "radiogroup", style: [styles.grid, { transform: [{ translateX: shake }] }], children: [_jsx(GridRows, { cards: cards, missing: missing > 0, alone: cards.length === 1 }), others &&
39
+ return (_jsxs(Animated.View, { testID: "method-grid", accessibilityRole: "radiogroup", style: [styles.grid, { transform: [{ translateX: shake }] }], children: [cards.length === 0 && !others ? (_jsx(View, { style: styles.empty, children: _jsx(SheetText, { size: 13, color: colors.muted, style: styles.emptyText, children: t('tab_empty') }) })) : (_jsx(GridRows, { cards: cards, missing: missing > 0, alone: cards.length === 1 })), others &&
40
40
  (others.open ? (_jsxs(View, { style: styles.others, children: [_jsx(SheetText, { weight: FigtreeEnum.SEMI_BOLD, size: 13, color: colors.muted, children: t('bank.other_countries') }), _jsx(GridRows, { cards: others.cards, missing: missing > 0, alone: false })] })) : (_jsx(View, { style: styles.othersLink, children: _jsx(SheetButton, { variant: CheckoutButtonVariantEnum.LINK, label: t('bank.other_countries'), onPress: others.onOpen }) }))), missing > 0 && (_jsx(SheetText, { accessibilityRole: "alert", weight: FigtreeEnum.MEDIUM, size: 13, color: colors.danger, children: t('method_missing') }))] }));
41
41
  }
42
42
  /**
@@ -129,6 +129,8 @@ const styles = StyleSheet.create({
129
129
  elevation: 1,
130
130
  },
131
131
  grid: { gap: 8, marginTop: 12 },
132
+ empty: { paddingVertical: 16 },
133
+ emptyText: { textAlign: 'center' },
132
134
  gridRow: { flexDirection: 'row', gap: 8 },
133
135
  // A card's flex share leaves out its padding and border (13 a side): the
134
136
  // spacer takes the same, so a lone last card is as wide as the others.
@@ -1,3 +1,6 @@
1
1
  import type { SheetTerminalProps } from '../models/sheet.interface.js';
2
- /** A payment that cannot be paid any more, said plainly, and the way back to the app. */
2
+ /**
3
+ * A payment that cannot be paid any more, said plainly, and the way back to
4
+ * the app. One no method could ever take has a single Close.
5
+ */
3
6
  export declare function SheetTerminal({ core, kind, onClose }: SheetTerminalProps): import("react").JSX.Element;
@@ -10,12 +10,22 @@ const COPY_KEY = {
10
10
  [TerminalKindEnum.CANCELLED]: 'cancelled',
11
11
  [TerminalKindEnum.LOCKED]: 'locked_screen',
12
12
  [TerminalKindEnum.NO_METHOD]: 'no_method',
13
+ [TerminalKindEnum.UNAVAILABLE]: 'unavailable_screen',
13
14
  };
14
- /** A payment that cannot be paid any more, said plainly, and the way back to the app. */
15
+ /**
16
+ * A payment that cannot be paid any more, said plainly, and the way back to
17
+ * the app. One no method could ever take has a single Close.
18
+ */
15
19
  export function SheetTerminal({ core, kind, onClose }) {
16
20
  const t = useTranslations('checkout');
17
21
  const app = core.view.app.name;
18
22
  const key = COPY_KEY[kind];
19
23
  const locked = kind === TerminalKindEnum.LOCKED;
20
- return (_jsx(SheetLayout, { foot: _jsx(SheetButton, { label: t('return_to', { app }), onPress: onClose }), children: _jsx(SheetMessage, { title: t(`${key}.title`), body: t(`${key}.body`, { app }), icon: locked ? SheetIconEnum.LOCK : SheetIconEnum.CLOCK, danger: locked }) }));
24
+ const unavailable = kind === TerminalKindEnum.UNAVAILABLE;
25
+ let icon = SheetIconEnum.CLOCK;
26
+ if (locked)
27
+ icon = SheetIconEnum.LOCK;
28
+ else if (unavailable)
29
+ icon = SheetIconEnum.BAN;
30
+ return (_jsx(SheetLayout, { foot: _jsx(SheetButton, { label: unavailable ? t('close') : t('return_to', { app }), onPress: onClose }), children: _jsx(SheetMessage, { title: t(`${key}.title`), body: t(`${key}.body`, { app }), icon: icon, danger: locked }) }));
21
31
  }
@@ -7,9 +7,12 @@ import type { CardFieldsMessage, CheckoutColors, CheckoutCore, CheckoutToast, Ch
7
7
  import type { FigtreeEnum, SheetIconEnum, StoreProductTypeEnum, WebBrowserResultEnum } from './sheet.enum.js';
8
8
  /**
9
9
  * How the sheet ended. `closed`: the payer closed it with the payment still
10
- * open. A hint only: ship on `payment.paid` from the webhook or `getPayment`.
10
+ * open. `unavailable`: no method could take the payment, so the sheet said
11
+ * so and offered Close only (`payment.unavailable` on the server). A hint only: ship on `payment.paid` from the webhook or `getPayment`.
11
12
  */
12
- export type PaymentSheetStatus = 'paid' | 'pending' | 'cancelled' | 'expired' | 'locked' | 'refunded' | 'closed';
13
+ export type PaymentSheetStatus = 'paid' | 'pending' | 'cancelled' | 'expired' | 'locked' | 'refunded' | 'closed'
14
+ /** No payment method could take the payment: the sheet said so, nothing was paid. */
15
+ | 'unavailable';
13
16
  /** Why the sheet could not show the payment: no payment has this id, or it could not load. */
14
17
  export type PaymentSheetError = 'not_found' | 'network';
15
18
  export interface PaymentSheetResult {
@@ -27,6 +27,9 @@ export function sheetResult(view, failed) {
27
27
  if (view.status !== CheckoutPaymentStatusEnum.PENDING) {
28
28
  return { status: view.status };
29
29
  }
30
+ // No method could ever take it: the app may offer something else.
31
+ if (view.unavailable)
32
+ return { status: 'unavailable' };
30
33
  // A prompt still on the phone: approved later, the payment goes through.
31
34
  return {
32
35
  status: view.attempt?.status === AttemptStatusEnum.PENDING ? 'pending' : 'closed',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brissoto/pay-react-native",
3
- "version": "1.4.5",
3
+ "version": "1.5.0",
4
4
  "description": "Brissoto Pay for Expo and React Native apps: the payment sheet.",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,