@12-apps/payments-frontend 3.23.0 → 3.23.1
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.23.
|
|
3
|
+
"version": "3.23.1",
|
|
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.",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useCallback, type Dispatch, type SetStateAction } from "react";
|
|
2
|
+
|
|
3
|
+
import type { Step } from "./checkout-actions";
|
|
4
|
+
import type { CheckoutDecline } from "./decline";
|
|
5
|
+
import type { BuyerInfo, OrderStatus, PaymentMethod } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The two actions the payment step raises on its own: paying once an e-mail
|
|
9
|
+
* has been typed, and reporting the result the provider's screen reached.
|
|
10
|
+
*
|
|
11
|
+
* Extracted from `useCheckoutController` for the same reason `useRetryAction`
|
|
12
|
+
* and `useGoToPayment` were: the controller is the one function that has to
|
|
13
|
+
* hold every piece of checkout state at once, and each action it also spells
|
|
14
|
+
* out inline is a line it cannot spend on the state. FUT-1170 and FUT-1240
|
|
15
|
+
* together pushed it past the size gate; these two callbacks are the part that
|
|
16
|
+
* reads the same wherever it lives.
|
|
17
|
+
*/
|
|
18
|
+
export function useResolutionActions(input: {
|
|
19
|
+
buyer: BuyerInfo;
|
|
20
|
+
method: PaymentMethod | null;
|
|
21
|
+
startPayment: (method: PaymentMethod, buyer: BuyerInfo) => Promise<void>;
|
|
22
|
+
setBuyerState: Dispatch<SetStateAction<BuyerInfo>>;
|
|
23
|
+
setDecline: Dispatch<SetStateAction<CheckoutDecline | null>>;
|
|
24
|
+
setFinalStatus: Dispatch<SetStateAction<OrderStatus | null>>;
|
|
25
|
+
setStep: Dispatch<SetStateAction<Step>>;
|
|
26
|
+
}): {
|
|
27
|
+
payWithEmail: (email: string) => void;
|
|
28
|
+
handleResolved: (status: OrderStatus, refusal?: CheckoutDecline | null) => void;
|
|
29
|
+
} {
|
|
30
|
+
const { buyer, method, startPayment, setBuyerState, setDecline, setFinalStatus, setStep } = input;
|
|
31
|
+
const payWithEmail = useCallback((email: string) => {
|
|
32
|
+
if (!method) return;
|
|
33
|
+
const next = { ...buyer, email };
|
|
34
|
+
setBuyerState(next);
|
|
35
|
+
void startPayment(method, next);
|
|
36
|
+
}, [buyer, method, setBuyerState, startPayment]);
|
|
37
|
+
const handleResolved = useCallback((status: OrderStatus, refusal?: CheckoutDecline | null) => {
|
|
38
|
+
setDecline(refusal ?? null);
|
|
39
|
+
setFinalStatus(status);
|
|
40
|
+
setStep("status");
|
|
41
|
+
}, [setDecline, setFinalStatus, setStep]);
|
|
42
|
+
return { payWithEmail, handleResolved };
|
|
43
|
+
}
|
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
OrderStatus,
|
|
29
29
|
PaymentMethod,
|
|
30
30
|
} from "./types";
|
|
31
|
+
import { useResolutionActions } from "./resolution-actions";
|
|
31
32
|
import { useHostedResume } from "./use-hosted-resume";
|
|
32
33
|
|
|
33
34
|
const STEP_ORDER: Step[] = ["dados", "payment", "status"];
|
|
@@ -140,17 +141,9 @@ export function useCheckoutController(
|
|
|
140
141
|
buyer, saveProfile, createOrder, navigate, tenantSlug, basket, failure,
|
|
141
142
|
setCreating, setDecline, setOrder, setFinalStatus,
|
|
142
143
|
});
|
|
143
|
-
const payWithEmail =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
setBuyerState(next);
|
|
147
|
-
void startPayment(method, next);
|
|
148
|
-
}, [buyer, method, startPayment]);
|
|
149
|
-
const handleResolved = useCallback((s: OrderStatus, refusal?: CheckoutDecline | null) => {
|
|
150
|
-
setDecline(refusal ?? null);
|
|
151
|
-
setFinalStatus(s);
|
|
152
|
-
setStep("status");
|
|
153
|
-
}, []);
|
|
144
|
+
const { payWithEmail, handleResolved } = useResolutionActions({
|
|
145
|
+
buyer, method, startPayment, setBuyerState, setDecline, setFinalStatus, setStep,
|
|
146
|
+
});
|
|
154
147
|
const retry = useRetryAction({
|
|
155
148
|
decline, order, clearError, setOrder, setDecline, setFinalStatus, setStep, setFreshInstrument,
|
|
156
149
|
});
|