@12-apps/payments-frontend 3.31.1 → 3.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@12-apps/payments-frontend",
3
- "version": "3.31.1",
3
+ "version": "3.32.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Browser half of the vendor-agnostic payments platform: plug-and-play MUI components for the per-provider settings page (credential form from each provider's schema, masked hints, verify/enable) and the checkout page (PIX QR + polling, card tokenization, hosted-checkout redirect), plus the headless hooks and fetch clients they build on. Talks only to the host's payments HTTP surface — never to a provider directly. Microfrontend-ready: no app coupling, host injects theme and auth.",
@@ -233,6 +233,9 @@ function StatusStep({
233
233
  // FAILED only, where it picks the sentence and decides whether a retry
234
234
  // could work at all.
235
235
  decline={c.decline}
236
+ // A Pix the store confirms by hand ends without proof either way
237
+ // (FUT-3232), so its refusal and lapse get their own sentences.
238
+ manual={c.order?.pix?.confirmation === "MANUAL"}
236
239
  />
237
240
  );
238
241
  }
@@ -289,6 +289,7 @@ export function PaymentStep({
289
289
  onChange={onMethodChange}
290
290
  cardUnavailable={choice.cardUnavailable}
291
291
  offered={choice.offered}
292
+ pixByStore={config?.chain?.find((link) => link.methods.includes("PIX"))?.confirmation === "MANUAL"}
292
293
  />
293
294
  )}
294
295
 
@@ -34,6 +34,16 @@ export const EN_US_PAYMENT_STATUS_COPY: PaymentStatusCopy = {
34
34
  heading: "The code expired",
35
35
  support: "Nothing was charged. Generate a new code to carry on.",
36
36
  },
37
+ manual: {
38
+ failed: {
39
+ heading: "The store did not find your Pix",
40
+ support: "If you have already paid, talk to the store before paying again.",
41
+ },
42
+ expired: {
43
+ heading: "The store did not confirm the payment in time",
44
+ support: "If you have already paid, talk to the store before paying again.",
45
+ },
46
+ },
37
47
  awaitingTimedOut: {
38
48
  heading: "We have not had the confirmation yet",
39
49
  support:
@@ -22,9 +22,11 @@ interface MethodOption {
22
22
  * host's Portuguese. The order and the icons are still ours — that is layout,
23
23
  * not language.
24
24
  */
25
- function methodOptions(copy: MethodPickerCopy): MethodOption[] {
25
+ function methodOptions(copy: MethodPickerCopy, pixByStore: boolean): MethodOption[] {
26
+ // A Pix the store confirms by hand is not "aprovação imediata" (FUT-3232).
27
+ const pixDescription = (pixByStore ? copy.pixManualDescription : undefined) ?? copy.pixDescription;
26
28
  return [
27
- { value: "PIX", label: copy.pixLabel, description: copy.pixDescription, icon: <PixIcon /> },
29
+ { value: "PIX", label: copy.pixLabel, description: pixDescription, icon: <PixIcon /> },
28
30
  {
29
31
  value: "CARD",
30
32
  label: copy.cardLabel,
@@ -125,8 +127,9 @@ function MethodTile({
125
127
  function visibleOptions(
126
128
  copy: MethodPickerCopy,
127
129
  offered: PaymentMethod[] | null,
130
+ pixByStore: boolean,
128
131
  ): MethodOption[] {
129
- return methodOptions(copy).filter(
132
+ return methodOptions(copy, pixByStore).filter(
130
133
  (option) => offered === null || offered.includes(option.value),
131
134
  );
132
135
  }
@@ -136,6 +139,7 @@ export function MethodPicker({
136
139
  onChange,
137
140
  cardUnavailable = false,
138
141
  offered = null,
142
+ pixByStore = false,
139
143
  }: {
140
144
  /** The chosen method, or `null` before the buyer has picked one. */
141
145
  value: PaymentMethod | null;
@@ -144,10 +148,12 @@ export function MethodPicker({
144
148
  cardUnavailable?: boolean;
145
149
  /** Methods the store's chain can charge, or `null` while unknown (fail open). */
146
150
  offered?: PaymentMethod[] | null;
151
+ /** True ⇒ the chain's first PIX provider is one the STORE confirms by hand. */
152
+ pixByStore?: boolean;
147
153
  }): JSX.Element {
148
154
  const { Text } = useCheckoutComponents();
149
155
  const copy = useCheckoutCopy().screens.method;
150
- const options = visibleOptions(copy, offered);
156
+ const options = visibleOptions(copy, offered, pixByStore);
151
157
  return (
152
158
  <Box>
153
159
  <Text variant="body" size="sm" weight="bold" as="p" style={{ marginBottom: 8 }}>
@@ -0,0 +1,81 @@
1
+ import type { JSX } from "react";
2
+
3
+ import type { CheckoutDecline } from "./decline";
4
+ import type { OrderStatus } from "./types";
5
+ import { useCheckoutComponents } from "./ui";
6
+ import type { PaymentStatusCopy } from "./view-copy";
7
+
8
+ /**
9
+ * The confirmation screen's "pay again" action — retry or regenerate — split
10
+ * out of `./payment-status-parts.tsx` when the Pix the store confirms
11
+ * (FUT-3232) gave it a second look and took that file past its size gate.
12
+ */
13
+
14
+ /**
15
+ * Whether "Tentar novamente" may be offered for a refusal (FUT-1145).
16
+ *
17
+ * `retriable === false` is the provider's OWN verdict that another attempt with
18
+ * this instrument cannot succeed — attempts exhausted (10001), a cancelled
19
+ * recurring mandate (20118), a malformed request. Offering a retry there is
20
+ * offering a button that mints another failed order and shows the same screen
21
+ * again; on a card the issuer is already counting, it is worse than useless.
22
+ *
23
+ * SILENCE MEANS YES. An undefined verdict is a provider that offered no
24
+ * guidance, not a refusal to retry, and withholding the button on silence
25
+ * would strand a buyer whose card is fine.
26
+ */
27
+ function retryable(decline: CheckoutDecline | null): boolean {
28
+ return decline?.retriable !== false;
29
+ }
30
+
31
+ /**
32
+ * How "Tentar novamente" / "Gerar novo código" look. Under a Pix the store
33
+ * confirms they step back to outline: the sentence above them asks a buyer who
34
+ * may already have paid to talk to the store first, and a filled button would
35
+ * say the opposite.
36
+ */
37
+ function againLook(byStore: boolean): { variant: "solid" | "outline"; color: "primary" | "neutral" } {
38
+ return byStore ? { variant: "outline", color: "neutral" } : { variant: "solid", color: "primary" };
39
+ }
40
+
41
+ /** "Tentar novamente" on a retryable FAILED, "Gerar novo código" on EXPIRED, else nothing. */
42
+ export function PayAgain({
43
+ copy,
44
+ status,
45
+ decline,
46
+ onRetry,
47
+ onRegenerate,
48
+ byStore,
49
+ }: {
50
+ copy: PaymentStatusCopy;
51
+ status: OrderStatus;
52
+ decline: CheckoutDecline | null;
53
+ onRetry?: () => void;
54
+ onRegenerate?: () => void;
55
+ byStore: boolean;
56
+ }): JSX.Element | null {
57
+ const { Button } = useCheckoutComponents();
58
+ const again = againLook(byStore);
59
+ if (status === "FAILED" && onRetry && retryable(decline)) {
60
+ return (
61
+ <Button variant={again.variant} color={again.color} size="lg" onClick={onRetry} dataTestId="payment-retry">
62
+ {copy.retryAction}
63
+ </Button>
64
+ );
65
+ }
66
+ if (status === "EXPIRED" && onRegenerate) {
67
+ return (
68
+ <Button
69
+ variant={again.variant}
70
+ color={again.color}
71
+ size="lg"
72
+ onClick={onRegenerate}
73
+ dataTestId="payment-regenerate"
74
+ >
75
+ {copy.regenerateAction}
76
+ </Button>
77
+ );
78
+ }
79
+ return null;
80
+ }
81
+
@@ -4,6 +4,7 @@ import type { JSX, ReactNode } from "react";
4
4
  import { CheckCircleOutlineIcon, ErrorOutlineIcon, ScheduleIcon } from "./icons";
5
5
  import type { CheckoutDecline } from "./decline";
6
6
  import type { OrderStatus } from "./types";
7
+ import { PayAgain } from "./payment-status-again";
7
8
  import { useCheckoutComponents } from "./ui";
8
9
  import type { PaymentStatusCopy, StatusOutcomeCopy } from "./view-copy";
9
10
 
@@ -120,6 +121,23 @@ function failedOutcome(copy: PaymentStatusCopy, decline: CheckoutDecline | null)
120
121
  return (reason ? copy.declined?.[reason] : undefined) ?? copy.failed;
121
122
  }
122
123
 
124
+ /**
125
+ * A SETTLED outcome's sentences. A Pix only the store confirms swaps FAILED and
126
+ * EXPIRED for its own pair when the host wrote one (`copy.manual`): neither the
127
+ * store's "não recebi" nor its lapsed window proves no money moved.
128
+ */
129
+ function settledOutcome(
130
+ copy: PaymentStatusCopy,
131
+ status: OrderStatus,
132
+ decline: CheckoutDecline | null,
133
+ manual: boolean,
134
+ ): StatusOutcomeCopy {
135
+ const byStore = manual ? copy.manual : undefined;
136
+ if (status === "FAILED") return byStore?.failed ?? failedOutcome(copy, decline);
137
+ if (status === "EXPIRED") return byStore?.expired ?? copy.expired;
138
+ return copy[OUTCOME_COPY_KEY[status]];
139
+ }
140
+
123
141
  /**
124
142
  * The headline block: icon, outcome, and one supporting line.
125
143
  *
@@ -135,23 +153,22 @@ export function OutcomeHero({
135
153
  wait,
136
154
  decline,
137
155
  hero,
156
+ manual = false,
138
157
  }: {
139
158
  copy: PaymentStatusCopy;
140
159
  status: OrderStatus;
141
160
  wait: WaitState;
142
161
  decline: CheckoutDecline | null;
143
162
  hero?: ReactNode;
163
+ /** The payment was a Pix only the store confirms — see {@link settledOutcome}. */
164
+ manual?: boolean;
144
165
  }): JSX.Element {
145
166
  const { Text } = useCheckoutComponents();
146
167
  const face = status === "AWAITING_PAYMENT" ? awaitingFace(copy, wait) : null;
147
168
  const visual = face
148
169
  ? { icon: OUTCOME_VISUAL.AWAITING_PAYMENT.icon, tone: face.tone }
149
170
  : OUTCOME_VISUAL[status];
150
- const outcome = face
151
- ? face.outcome
152
- : status === "FAILED"
153
- ? failedOutcome(copy, decline)
154
- : copy[OUTCOME_COPY_KEY[status]];
171
+ const outcome = face ? face.outcome : settledOutcome(copy, status, decline, manual);
155
172
  return (
156
173
  <Box
157
174
  // `payment-paid` is load-bearing for the storefront journeys — it is how
@@ -233,23 +250,6 @@ export function PaidFacts({
233
250
  );
234
251
  }
235
252
 
236
- /**
237
- * Whether "Tentar novamente" may be offered for a refusal (FUT-1145).
238
- *
239
- * `retriable === false` is the provider's OWN verdict that another attempt with
240
- * this instrument cannot succeed — attempts exhausted (10001), a cancelled
241
- * recurring mandate (20118), a malformed request. Offering a retry there is
242
- * offering a button that mints another failed order and shows the same screen
243
- * again; on a card the issuer is already counting, it is worse than useless.
244
- *
245
- * SILENCE MEANS YES. An undefined verdict is a provider that offered no
246
- * guidance, not a refusal to retry, and withholding the button on silence
247
- * would strand a buyer whose card is fine.
248
- */
249
- function retryable(decline: CheckoutDecline | null): boolean {
250
- return decline?.retriable !== false;
251
- }
252
-
253
253
  /**
254
254
  * How much of the eye the way out asks for on a PAID confirmation.
255
255
  *
@@ -293,6 +293,7 @@ export function StatusActions({
293
293
  onNotPaid,
294
294
  onBackToMenu,
295
295
  backActionEmphasis = "primary",
296
+ manual,
296
297
  }: {
297
298
  copy: PaymentStatusCopy;
298
299
  status: OrderStatus;
@@ -310,6 +311,8 @@ export function StatusActions({
310
311
  onBackToMenu: () => void;
311
312
  /** Whether back-to-menu leads a PAID screen. See {@link BackActionEmphasis}. */
312
313
  backActionEmphasis?: BackActionEmphasis;
314
+ /** The payment was a Pix only the store confirms — see `PayAgain`. */
315
+ manual?: boolean;
313
316
  }): JSX.Element {
314
317
  const { Button } = useCheckoutComponents();
315
318
  const back = backLook(status, backActionEmphasis);
@@ -337,16 +340,14 @@ export function StatusActions({
337
340
  {copy.notPaidAction}
338
341
  </Button>
339
342
  ) : null}
340
- {status === "FAILED" && onRetry && retryable(decline) ? (
341
- <Button variant="solid" color="primary" size="lg" onClick={onRetry} dataTestId="payment-retry">
342
- {copy.retryAction}
343
- </Button>
344
- ) : null}
345
- {status === "EXPIRED" && onRegenerate ? (
346
- <Button variant="solid" color="primary" size="lg" onClick={onRegenerate} dataTestId="payment-regenerate">
347
- {copy.regenerateAction}
348
- </Button>
349
- ) : null}
343
+ <PayAgain
344
+ copy={copy}
345
+ status={status}
346
+ decline={decline}
347
+ onRetry={onRetry}
348
+ onRegenerate={onRegenerate}
349
+ byStore={manual === true}
350
+ />
350
351
  <Button
351
352
  // Full width and last, so the thumb lands on the same place in every
352
353
  // outcome instead of hunting a button that moves with the state.
@@ -117,6 +117,12 @@ interface PaymentStatusProps {
117
117
  * sentence, and it decides whether a retry is offered at all.
118
118
  */
119
119
  decline?: CheckoutDecline | null;
120
+ /**
121
+ * The payment was a Pix only the STORE confirms (FUT-3232): a FAILED or
122
+ * EXPIRED screen then says the store did not find it, never that nothing
123
+ * was charged.
124
+ */
125
+ manual?: boolean;
120
126
  }
121
127
 
122
128
  /**
@@ -198,6 +204,7 @@ export function PaymentStatus(props: PaymentStatusProps): JSX.Element {
198
204
  wait={view.wait}
199
205
  decline={view.decline}
200
206
  hero={props.paidHero}
207
+ manual={props.manual === true}
201
208
  />
202
209
 
203
210
  {view.paid ? (
@@ -220,6 +227,7 @@ export function PaymentStatus(props: PaymentStatusProps): JSX.Element {
220
227
  onNotPaid={view.notPaid}
221
228
  onBackToMenu={onBackToMenu}
222
229
  backActionEmphasis={props.backActionEmphasis}
230
+ manual={props.manual === true}
223
231
  />
224
232
 
225
233
  {view.paid ? props.paidFooter : null}
@@ -28,6 +28,16 @@ export const PT_BR_PAYMENT_STATUS_COPY: PaymentStatusCopy = {
28
28
  heading: "O código expirou",
29
29
  support: "Nenhum valor foi cobrado. Gere um novo código para continuar.",
30
30
  },
31
+ manual: {
32
+ failed: {
33
+ heading: "A loja não identificou o seu Pix",
34
+ support: "Se você já pagou, fale com a loja antes de pagar de novo.",
35
+ },
36
+ expired: {
37
+ heading: "A loja não confirmou o pagamento a tempo",
38
+ support: "Se você já pagou, fale com a loja antes de pagar de novo.",
39
+ },
40
+ },
31
41
  awaitingTimedOut: {
32
42
  heading: "Ainda não recebemos a confirmação",
33
43
  support:
@@ -32,6 +32,12 @@ export interface MethodPickerCopy {
32
32
  cardLabel: string;
33
33
  /** What each method is like to use — shown under its name. */
34
34
  pixDescription: string;
35
+ /**
36
+ * PIX's line when the store confirms it by hand (the chain's first PIX
37
+ * provider declares `confirmation: 'MANUAL'`). Optional; absent falls back
38
+ * to `pixDescription`, so a host enabling such a provider should set it.
39
+ */
40
+ pixManualDescription?: string;
35
41
  cardDescription: string;
36
42
  /** This store's providers cannot take that method. */
37
43
  unavailableHere: string;
@@ -22,6 +22,7 @@ export const EN_US_CHECKOUT_SCREENS_COPY: CheckoutScreensCopy = {
22
22
  pixLabel: 'PIX',
23
23
  cardLabel: 'Card',
24
24
  pixDescription: 'Approved instantly',
25
+ pixManualDescription: 'Confirmed by the store',
25
26
  cardDescription: 'Credit, paid in full',
26
27
  unavailableHere: 'Unavailable in this store',
27
28
  },
@@ -15,6 +15,7 @@ export const PT_BR_CHECKOUT_SCREENS_COPY: CheckoutScreensCopy = {
15
15
  pixLabel: 'PIX',
16
16
  cardLabel: 'Cartão',
17
17
  pixDescription: 'Aprovação imediata',
18
+ pixManualDescription: 'Confirmado pela loja',
18
19
  cardDescription: 'Crédito à vista',
19
20
  unavailableHere: 'Indisponível nesta loja',
20
21
  },
@@ -275,15 +275,15 @@ export interface CheckoutChainLink {
275
275
  provider: string;
276
276
  /**
277
277
  * The provider's own name as a BUYER should read it ("InfinitePay"), which
278
- * `GET /api/checkout/config` publishes per entry.
279
- *
280
- * Optional, and the DEGRADE DIRECTION IS "SAY NOTHING": an older host serves
281
- * no name, and a hand-off screen then describes where the buyer is going
282
- * without naming it, rather than printing the internal `provider` id — a
283
- * buyer shown "infinitepay" learns less than one shown nothing, and learns
284
- * it in a vocabulary that is ours rather than theirs.
278
+ * `GET /api/checkout/config` publishes per entry. Optional, and the DEGRADE
279
+ * DIRECTION IS "SAY NOTHING": an older host serves no name, and a hand-off
280
+ * screen then describes where the buyer is going without naming it, rather
281
+ * than printing the internal `provider` id — a buyer shown "infinitepay"
282
+ * learns less than one shown nothing, in a vocabulary ours rather than theirs.
285
283
  */
286
284
  displayName?: string | null;
285
+ /** `MANUAL`: only the store confirms this entry's charges (`pixmanual`); absent is automatic. */
286
+ confirmation?: "AUTOMATIC" | "MANUAL";
287
287
  tokenization: "NONE" | "PUBLIC_KEY" | "SDK" | "REDIRECT";
288
288
  publicKey: string | null;
289
289
  mockTokenization: boolean;
@@ -93,6 +93,14 @@ export interface PaymentStatusCopy {
93
93
  */
94
94
  declined: Partial<Record<CheckoutDeclineReason, StatusOutcomeCopy>>;
95
95
  awaitingTimedOut: StatusOutcomeCopy;
96
+ /**
97
+ * FAILED and EXPIRED for a Pix only the STORE confirms (FUT-3232). The store
98
+ * answering "não recebi", or letting its window lapse, says nothing about
99
+ * whether the buyer paid — a static key takes money whatever the store
100
+ * later says — so "nothing was charged" would be a guess, and "pay again" an
101
+ * invitation to pay twice. Absent, those two keep their ordinary sentences.
102
+ */
103
+ manual?: { failed: StatusOutcomeCopy; expired: StatusOutcomeCopy };
96
104
  /**
97
105
  * The wait cannot reach the payment right now (FUT-1144) — and is STILL
98
106
  * ASKING, which is the whole difference between this outcome and the one