@blocklet/payment-react 1.25.10 → 1.26.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.
Files changed (160) hide show
  1. package/es/checkout-v2/checkout-v2.d.ts +2 -0
  2. package/es/checkout-v2/checkout-v2.js +121 -0
  3. package/es/checkout-v2/components/dialogs/checkout-dialogs.d.ts +1 -0
  4. package/es/checkout-v2/components/dialogs/checkout-dialogs.js +106 -0
  5. package/es/checkout-v2/components/left/billing-toggle.d.ts +6 -0
  6. package/es/checkout-v2/components/left/billing-toggle.js +118 -0
  7. package/es/checkout-v2/components/left/cross-sell-card.d.ts +10 -0
  8. package/es/checkout-v2/components/left/cross-sell-card.js +167 -0
  9. package/es/checkout-v2/components/left/product-item-card.d.ts +26 -0
  10. package/es/checkout-v2/components/left/product-item-card.js +571 -0
  11. package/es/checkout-v2/components/left/promotion-input.d.ts +19 -0
  12. package/es/checkout-v2/components/left/promotion-input.js +178 -0
  13. package/es/checkout-v2/components/left/staking-breakdown.d.ts +9 -0
  14. package/es/checkout-v2/components/left/staking-breakdown.js +48 -0
  15. package/es/checkout-v2/components/left/trial-info.d.ts +13 -0
  16. package/es/checkout-v2/components/left/trial-info.js +48 -0
  17. package/es/checkout-v2/components/right/currency-grid.d.ts +8 -0
  18. package/es/checkout-v2/components/right/currency-grid.js +48 -0
  19. package/es/checkout-v2/components/right/customer-info-card.d.ts +17 -0
  20. package/es/checkout-v2/components/right/customer-info-card.js +156 -0
  21. package/es/checkout-v2/components/right/status-feedback.d.ts +7 -0
  22. package/es/checkout-v2/components/right/status-feedback.js +17 -0
  23. package/es/checkout-v2/components/right/submit-button.d.ts +10 -0
  24. package/es/checkout-v2/components/right/submit-button.js +29 -0
  25. package/es/checkout-v2/components/right/subscription-disclaimer.d.ts +11 -0
  26. package/es/checkout-v2/components/right/subscription-disclaimer.js +8 -0
  27. package/es/checkout-v2/components/shared/exchange-rate-footer.d.ts +23 -0
  28. package/es/checkout-v2/components/shared/exchange-rate-footer.js +182 -0
  29. package/es/checkout-v2/components/shared/scenario-badge.d.ts +6 -0
  30. package/es/checkout-v2/components/shared/scenario-badge.js +47 -0
  31. package/es/checkout-v2/components/shared/total-display.d.ts +7 -0
  32. package/es/checkout-v2/components/shared/total-display.js +84 -0
  33. package/es/checkout-v2/index.d.ts +2 -0
  34. package/es/checkout-v2/index.js +1 -0
  35. package/es/checkout-v2/layouts/checkout-layout.d.ts +7 -0
  36. package/es/checkout-v2/layouts/checkout-layout.js +226 -0
  37. package/es/checkout-v2/panels/left/composite-panel.d.ts +1 -0
  38. package/es/checkout-v2/panels/left/composite-panel.js +423 -0
  39. package/es/checkout-v2/panels/left/credit-topup-panel.d.ts +1 -0
  40. package/es/checkout-v2/panels/left/credit-topup-panel.js +615 -0
  41. package/es/checkout-v2/panels/left/scenario-router.d.ts +1 -0
  42. package/es/checkout-v2/panels/left/scenario-router.js +19 -0
  43. package/es/checkout-v2/panels/right/payment-panel.d.ts +1 -0
  44. package/es/checkout-v2/panels/right/payment-panel.js +644 -0
  45. package/es/checkout-v2/types.d.ts +15 -0
  46. package/es/checkout-v2/types.js +0 -0
  47. package/es/checkout-v2/utils/format.d.ts +59 -0
  48. package/es/checkout-v2/utils/format.js +125 -0
  49. package/es/checkout-v2/utils/scenario-detector.d.ts +3 -0
  50. package/es/checkout-v2/utils/scenario-detector.js +17 -0
  51. package/es/checkout-v2/views/error-view.d.ts +7 -0
  52. package/es/checkout-v2/views/error-view.js +269 -0
  53. package/es/checkout-v2/views/loading-view.d.ts +5 -0
  54. package/es/checkout-v2/views/loading-view.js +158 -0
  55. package/es/checkout-v2/views/success-view.d.ts +29 -0
  56. package/es/checkout-v2/views/success-view.js +614 -0
  57. package/es/components/phone-field.d.ts +14 -0
  58. package/es/components/phone-field.js +96 -0
  59. package/es/index.d.ts +3 -1
  60. package/es/index.js +3 -1
  61. package/es/locales/en.js +45 -6
  62. package/es/locales/zh.js +45 -6
  63. package/es/payment/form/index.js +10 -1
  64. package/lib/checkout-v2/checkout-v2.d.ts +2 -0
  65. package/lib/checkout-v2/checkout-v2.js +151 -0
  66. package/lib/checkout-v2/components/dialogs/checkout-dialogs.d.ts +1 -0
  67. package/lib/checkout-v2/components/dialogs/checkout-dialogs.js +131 -0
  68. package/lib/checkout-v2/components/left/billing-toggle.d.ts +6 -0
  69. package/lib/checkout-v2/components/left/billing-toggle.js +126 -0
  70. package/lib/checkout-v2/components/left/cross-sell-card.d.ts +10 -0
  71. package/lib/checkout-v2/components/left/cross-sell-card.js +257 -0
  72. package/lib/checkout-v2/components/left/product-item-card.d.ts +26 -0
  73. package/lib/checkout-v2/components/left/product-item-card.js +738 -0
  74. package/lib/checkout-v2/components/left/promotion-input.d.ts +19 -0
  75. package/lib/checkout-v2/components/left/promotion-input.js +220 -0
  76. package/lib/checkout-v2/components/left/staking-breakdown.d.ts +9 -0
  77. package/lib/checkout-v2/components/left/staking-breakdown.js +96 -0
  78. package/lib/checkout-v2/components/left/trial-info.d.ts +13 -0
  79. package/lib/checkout-v2/components/left/trial-info.js +82 -0
  80. package/lib/checkout-v2/components/right/currency-grid.d.ts +8 -0
  81. package/lib/checkout-v2/components/right/currency-grid.js +96 -0
  82. package/lib/checkout-v2/components/right/customer-info-card.d.ts +17 -0
  83. package/lib/checkout-v2/components/right/customer-info-card.js +246 -0
  84. package/lib/checkout-v2/components/right/status-feedback.d.ts +7 -0
  85. package/lib/checkout-v2/components/right/status-feedback.js +30 -0
  86. package/lib/checkout-v2/components/right/submit-button.d.ts +10 -0
  87. package/lib/checkout-v2/components/right/submit-button.js +35 -0
  88. package/lib/checkout-v2/components/right/subscription-disclaimer.d.ts +11 -0
  89. package/lib/checkout-v2/components/right/subscription-disclaimer.js +33 -0
  90. package/lib/checkout-v2/components/shared/exchange-rate-footer.d.ts +23 -0
  91. package/lib/checkout-v2/components/shared/exchange-rate-footer.js +282 -0
  92. package/lib/checkout-v2/components/shared/scenario-badge.d.ts +6 -0
  93. package/lib/checkout-v2/components/shared/scenario-badge.js +57 -0
  94. package/lib/checkout-v2/components/shared/total-display.d.ts +7 -0
  95. package/lib/checkout-v2/components/shared/total-display.js +154 -0
  96. package/lib/checkout-v2/index.d.ts +2 -0
  97. package/lib/checkout-v2/index.js +13 -0
  98. package/lib/checkout-v2/layouts/checkout-layout.d.ts +7 -0
  99. package/lib/checkout-v2/layouts/checkout-layout.js +308 -0
  100. package/lib/checkout-v2/panels/left/composite-panel.d.ts +1 -0
  101. package/lib/checkout-v2/panels/left/composite-panel.js +515 -0
  102. package/lib/checkout-v2/panels/left/credit-topup-panel.d.ts +1 -0
  103. package/lib/checkout-v2/panels/left/credit-topup-panel.js +799 -0
  104. package/lib/checkout-v2/panels/left/scenario-router.d.ts +1 -0
  105. package/lib/checkout-v2/panels/left/scenario-router.js +29 -0
  106. package/lib/checkout-v2/panels/right/payment-panel.d.ts +1 -0
  107. package/lib/checkout-v2/panels/right/payment-panel.js +906 -0
  108. package/lib/checkout-v2/types.d.ts +15 -0
  109. package/lib/checkout-v2/types.js +1 -0
  110. package/lib/checkout-v2/utils/format.d.ts +59 -0
  111. package/lib/checkout-v2/utils/format.js +158 -0
  112. package/lib/checkout-v2/utils/scenario-detector.d.ts +3 -0
  113. package/lib/checkout-v2/utils/scenario-detector.js +23 -0
  114. package/lib/checkout-v2/views/error-view.d.ts +7 -0
  115. package/lib/checkout-v2/views/error-view.js +321 -0
  116. package/lib/checkout-v2/views/loading-view.d.ts +5 -0
  117. package/lib/checkout-v2/views/loading-view.js +168 -0
  118. package/lib/checkout-v2/views/success-view.d.ts +29 -0
  119. package/lib/checkout-v2/views/success-view.js +735 -0
  120. package/lib/components/phone-field.d.ts +14 -0
  121. package/lib/components/phone-field.js +130 -0
  122. package/lib/index.d.ts +3 -1
  123. package/lib/index.js +8 -0
  124. package/lib/locales/en.js +45 -6
  125. package/lib/locales/zh.js +45 -6
  126. package/lib/payment/form/index.js +10 -1
  127. package/package.json +4 -3
  128. package/src/checkout-v2/checkout-v2.tsx +155 -0
  129. package/src/checkout-v2/components/dialogs/checkout-dialogs.tsx +134 -0
  130. package/src/checkout-v2/components/left/billing-toggle.tsx +122 -0
  131. package/src/checkout-v2/components/left/cross-sell-card.tsx +170 -0
  132. package/src/checkout-v2/components/left/product-item-card.tsx +634 -0
  133. package/src/checkout-v2/components/left/promotion-input.tsx +207 -0
  134. package/src/checkout-v2/components/left/staking-breakdown.tsx +57 -0
  135. package/src/checkout-v2/components/left/trial-info.tsx +63 -0
  136. package/src/checkout-v2/components/right/currency-grid.tsx +59 -0
  137. package/src/checkout-v2/components/right/customer-info-card.tsx +214 -0
  138. package/src/checkout-v2/components/right/status-feedback.tsx +35 -0
  139. package/src/checkout-v2/components/right/submit-button.tsx +37 -0
  140. package/src/checkout-v2/components/right/subscription-disclaimer.tsx +27 -0
  141. package/src/checkout-v2/components/shared/exchange-rate-footer.tsx +221 -0
  142. package/src/checkout-v2/components/shared/scenario-badge.tsx +51 -0
  143. package/src/checkout-v2/components/shared/total-display.tsx +112 -0
  144. package/src/checkout-v2/index.ts +2 -0
  145. package/src/checkout-v2/layouts/checkout-layout.tsx +232 -0
  146. package/src/checkout-v2/panels/left/composite-panel.tsx +465 -0
  147. package/src/checkout-v2/panels/left/credit-topup-panel.tsx +681 -0
  148. package/src/checkout-v2/panels/left/scenario-router.tsx +22 -0
  149. package/src/checkout-v2/panels/right/payment-panel.tsx +703 -0
  150. package/src/checkout-v2/types.ts +18 -0
  151. package/src/checkout-v2/utils/format.ts +204 -0
  152. package/src/checkout-v2/utils/scenario-detector.ts +30 -0
  153. package/src/checkout-v2/views/error-view.tsx +293 -0
  154. package/src/checkout-v2/views/loading-view.tsx +162 -0
  155. package/src/checkout-v2/views/success-view.tsx +770 -0
  156. package/src/components/phone-field.tsx +119 -0
  157. package/src/index.ts +3 -0
  158. package/src/locales/en.tsx +45 -4
  159. package/src/locales/zh.tsx +43 -4
  160. package/src/payment/form/index.tsx +16 -1
@@ -0,0 +1,644 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
4
+ import CreditCardIcon from "@mui/icons-material/CreditCard";
5
+ import CurrencyBitcoinIcon from "@mui/icons-material/CurrencyBitcoin";
6
+ import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
7
+ import HelpOutlineIcon from "@mui/icons-material/HelpOutline";
8
+ import LocalOfferOutlinedIcon from "@mui/icons-material/LocalOfferOutlined";
9
+ import CloseIcon from "@mui/icons-material/Close";
10
+ import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
11
+ import {
12
+ Avatar,
13
+ Box,
14
+ Button,
15
+ CircularProgress,
16
+ Collapse,
17
+ Divider,
18
+ Drawer,
19
+ MenuItem,
20
+ Select,
21
+ Skeleton,
22
+ Stack,
23
+ ToggleButton,
24
+ ToggleButtonGroup,
25
+ Tooltip,
26
+ Typography
27
+ } from "@mui/material";
28
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
29
+ import {
30
+ useCheckoutStatus,
31
+ usePaymentMethodFeature,
32
+ useCustomerFormFeature,
33
+ useSubmitFeature,
34
+ usePricingFeature,
35
+ useSessionContext,
36
+ useLineItems,
37
+ usePromotion,
38
+ useExchangeRate
39
+ } from "@blocklet/payment-react-headless";
40
+ import { joinURL } from "ufo";
41
+ import { usePaymentContext } from "../../../contexts/payment.js";
42
+ import { useMobile } from "../../../hooks/mobile.js";
43
+ import { getPrefix } from "../../../libs/util.js";
44
+ import OverdueInvoicePayment from "../../../components/over-due-invoice-payment.js";
45
+ import { tSafe, whiteTooltipSx } from "../../utils/format.js";
46
+ import CustomerInfoCard from "../../components/right/customer-info-card.js";
47
+ import SubscriptionDisclaimer from "../../components/right/subscription-disclaimer.js";
48
+ import StatusFeedback from "../../components/right/status-feedback.js";
49
+ import PromotionInput from "../../components/left/promotion-input.js";
50
+ export default function PaymentPanel() {
51
+ const { t, locale } = useLocaleContext();
52
+ const { session, sessionData, subscription, refresh } = useSessionContext();
53
+ const { isDonation } = useCheckoutStatus();
54
+ const paymentMethod = usePaymentMethodFeature();
55
+ const form = useCustomerFormFeature();
56
+ const submit = useSubmitFeature();
57
+ const pricing = usePricingFeature();
58
+ const { session: didSession, connect, prefix: paymentKitPrefix } = usePaymentContext();
59
+ const { inventoryOk } = useLineItems();
60
+ const promotion = usePromotion();
61
+ const rate = useExchangeRate();
62
+ const { isMobile } = useMobile();
63
+ const isAmountLoading = paymentMethod.switching || rate.hasDynamicPricing && rate.status === "loading";
64
+ const { currency, types, isStripe, isCrypto } = paymentMethod;
65
+ const mode = session?.mode || "payment";
66
+ const discounts = session?.discounts || [];
67
+ const isLoggedIn = !!didSession?.user;
68
+ const actionLabel = isDonation ? t("payment.checkout.donate") : t(`payment.checkout.${mode}`);
69
+ const buttonLabel = isLoggedIn ? actionLabel : t("payment.checkout.connect", { action: actionLabel });
70
+ const [customerLimited, setCustomerLimited] = useState(false);
71
+ const [mobileDetailsOpen, setMobileDetailsOpen] = useState(false);
72
+ const [promoDrawerOpen, setPromoDrawerOpen] = useState(false);
73
+ useEffect(() => {
74
+ if (submit.status === "failed" && submit.context?.code === "CUSTOMER_LIMITED") {
75
+ setCustomerLimited(true);
76
+ }
77
+ }, [submit.status, submit.context]);
78
+ const canSubmit = submit.status === "idle" && session?.status === "open" && inventoryOk;
79
+ const isProcessing = ["submitting", "waiting_did"].includes(submit.status);
80
+ const handleAction = useCallback(() => {
81
+ if (!canSubmit) return;
82
+ submit.lock();
83
+ if (isLoggedIn || isDonation) {
84
+ submit.execute();
85
+ return;
86
+ }
87
+ didSession?.login?.(() => {
88
+ Promise.all([refresh(true), form.refetchCustomer()]).then(() => submit.execute()).catch((err) => {
89
+ console.error("Post-login refresh failed:", err);
90
+ });
91
+ });
92
+ }, [canSubmit, isLoggedIn, isDonation, didSession, refresh, form, submit]);
93
+ useEffect(() => {
94
+ if (didSession?.user && !submit.status.startsWith("submitting")) {
95
+ form.refetchCustomer();
96
+ }
97
+ }, [didSession?.user]);
98
+ const cryptoType = types.find((tp) => tp.type === "crypto");
99
+ const cryptoMethods = useMemo(
100
+ () => paymentMethod.available.filter((m) => m.type !== "stripe"),
101
+ [paymentMethod.available]
102
+ );
103
+ const networks = useMemo(() => {
104
+ if (!cryptoMethods.length) return [];
105
+ return cryptoMethods.map((m) => ({
106
+ id: m.id,
107
+ name: m.name,
108
+ logo: m.logo || "",
109
+ currencies: m.payment_currencies || []
110
+ }));
111
+ }, [cryptoMethods]);
112
+ const currentMethodId = paymentMethod.current?.id || "";
113
+ useEffect(() => {
114
+ const handleKeyDown = (e) => {
115
+ if (e.key === "Enter" && canSubmit && submit.status === "idle") {
116
+ const tag = e.target?.tagName?.toLowerCase();
117
+ if (tag === "textarea") return;
118
+ handleAction();
119
+ }
120
+ };
121
+ document.addEventListener("keydown", handleKeyDown);
122
+ return () => document.removeEventListener("keydown", handleKeyDown);
123
+ }, [canSubmit, submit.status, handleAction]);
124
+ const didConnectOpenedRef = useRef(false);
125
+ useEffect(() => {
126
+ if (submit.status !== "waiting_did") {
127
+ didConnectOpenedRef.current = false;
128
+ return;
129
+ }
130
+ const ctx = submit.context;
131
+ if (ctx?.type !== "did_connect" || !connect) return;
132
+ if (didConnectOpenedRef.current) return;
133
+ didConnectOpenedRef.current = true;
134
+ const didPrefix = `${paymentKitPrefix}/api/did`.replace(/([^:])\/\//g, "$1/");
135
+ connect.open({
136
+ locale,
137
+ action: ctx.action,
138
+ prefix: didPrefix,
139
+ saveConnect: false,
140
+ extraParams: ctx.extraParams,
141
+ onSuccess: () => {
142
+ connect.close();
143
+ },
144
+ onClose: () => {
145
+ connect.close();
146
+ submit.reset();
147
+ },
148
+ onError: (err) => {
149
+ console.error("DID Connect error:", err);
150
+ submit.reset();
151
+ },
152
+ messages: {
153
+ title: t("payment.checkout.connectModal.title", { action: buttonLabel }),
154
+ scan: t("payment.checkout.connectModal.scan"),
155
+ confirm: t("payment.checkout.connectModal.confirm")
156
+ }
157
+ });
158
+ }, [submit.status, submit.context, connect, locale, t, buttonLabel]);
159
+ const activeType = types.find((tp) => tp.active)?.type || "crypto";
160
+ const hasMultipleTypes = types.length > 1;
161
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", flex: 1, minHeight: 0 }, children: [
162
+ /* @__PURE__ */ jsxs(
163
+ Box,
164
+ {
165
+ sx: {
166
+ flex: 1,
167
+ display: "flex",
168
+ flexDirection: "column",
169
+ overflowY: "auto",
170
+ minHeight: 0,
171
+ "&::-webkit-scrollbar": { display: "none" },
172
+ scrollbarWidth: "none"
173
+ },
174
+ children: [
175
+ /* @__PURE__ */ jsx(
176
+ Typography,
177
+ {
178
+ sx: {
179
+ fontSize: 13,
180
+ fontWeight: 700,
181
+ letterSpacing: "0.02em",
182
+ color: "text.primary",
183
+ mb: 2.5
184
+ },
185
+ children: t("payment.checkout.paymentDetails")
186
+ }
187
+ ),
188
+ hasMultipleTypes && /* @__PURE__ */ jsx(
189
+ ToggleButtonGroup,
190
+ {
191
+ value: activeType,
192
+ exclusive: true,
193
+ onChange: (_, v) => v && paymentMethod.setType(v),
194
+ fullWidth: true,
195
+ size: "small",
196
+ sx: {
197
+ mb: 2.5,
198
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.06)" : "grey.100",
199
+ borderRadius: "10px",
200
+ p: 0.5,
201
+ "& .MuiToggleButton-root": {
202
+ textTransform: "none",
203
+ borderRadius: "8px !important",
204
+ py: 0.75,
205
+ border: "none",
206
+ fontSize: 14,
207
+ fontWeight: 500,
208
+ gap: 0.75,
209
+ color: "text.secondary"
210
+ },
211
+ "& .Mui-selected": {
212
+ bgcolor: "background.paper !important",
213
+ color: "text.primary",
214
+ fontWeight: 600,
215
+ boxShadow: (theme) => theme.palette.mode === "dark" ? "0 1px 3px rgba(0,0,0,0.3)" : "0 1px 3px rgba(0,0,0,0.08)",
216
+ "&:hover": { bgcolor: "background.paper !important" }
217
+ }
218
+ },
219
+ children: types.map((tp) => /* @__PURE__ */ jsxs(ToggleButton, { value: tp.type, children: [
220
+ tp.type === "stripe" ? /* @__PURE__ */ jsx(CreditCardIcon, { sx: { fontSize: 18 } }) : /* @__PURE__ */ jsx(CurrencyBitcoinIcon, { sx: { fontSize: 18 } }),
221
+ tp.label || (tp.type === "stripe" ? "Card" : "Crypto")
222
+ ] }, tp.type))
223
+ }
224
+ ),
225
+ isCrypto && networks.length > 0 && /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1.5, sx: { mb: 2.5 }, children: [
226
+ networks.length > 1 && /* @__PURE__ */ jsxs(Box, { sx: { flex: 1 }, children: [
227
+ /* @__PURE__ */ jsx(
228
+ Typography,
229
+ {
230
+ sx: {
231
+ fontSize: 12,
232
+ fontWeight: 600,
233
+ color: "text.secondary",
234
+ mb: 0.5,
235
+ letterSpacing: "0.02em"
236
+ },
237
+ children: t("common.network")
238
+ }
239
+ ),
240
+ /* @__PURE__ */ jsx(
241
+ Select,
242
+ {
243
+ value: currentMethodId,
244
+ onChange: (e) => {
245
+ const network = networks.find((n) => n.id === e.target.value);
246
+ if (network?.currencies?.[0]) {
247
+ paymentMethod.setCurrency(network.currencies[0].id);
248
+ }
249
+ },
250
+ fullWidth: true,
251
+ size: "small",
252
+ sx: {
253
+ borderRadius: "8px",
254
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.06)" : "grey.50",
255
+ "& .MuiOutlinedInput-notchedOutline": { borderColor: "transparent" },
256
+ "&:hover .MuiOutlinedInput-notchedOutline": { borderColor: "divider" },
257
+ "&.Mui-focused .MuiOutlinedInput-notchedOutline": { borderColor: "primary.main", borderWidth: 1 },
258
+ "& .MuiSelect-select": { display: "flex", alignItems: "center", gap: 1, py: 1 }
259
+ },
260
+ children: networks.map((net) => /* @__PURE__ */ jsxs(MenuItem, { value: net.id, sx: { gap: 1 }, children: [
261
+ net.logo && /* @__PURE__ */ jsx(Avatar, { src: net.logo, sx: { width: 20, height: 20 } }),
262
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14 }, children: net.name })
263
+ ] }, net.id))
264
+ }
265
+ )
266
+ ] }),
267
+ /* @__PURE__ */ jsxs(Box, { sx: { flex: 1 }, children: [
268
+ /* @__PURE__ */ jsx(
269
+ Typography,
270
+ {
271
+ sx: {
272
+ fontSize: 12,
273
+ fontWeight: 600,
274
+ color: "text.secondary",
275
+ mb: 0.5,
276
+ letterSpacing: "0.02em"
277
+ },
278
+ children: t("common.currency")
279
+ }
280
+ ),
281
+ /* @__PURE__ */ jsx(
282
+ Select,
283
+ {
284
+ value: currency?.id || "",
285
+ onChange: (e) => paymentMethod.setCurrency(e.target.value),
286
+ fullWidth: true,
287
+ size: "small",
288
+ sx: {
289
+ borderRadius: "8px",
290
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.06)" : "grey.50",
291
+ "& .MuiOutlinedInput-notchedOutline": { borderColor: "transparent" },
292
+ "&:hover .MuiOutlinedInput-notchedOutline": { borderColor: "divider" },
293
+ "&.Mui-focused .MuiOutlinedInput-notchedOutline": { borderColor: "primary.main", borderWidth: 1 },
294
+ "& .MuiSelect-select": { display: "flex", alignItems: "center", gap: 1, py: 1 }
295
+ },
296
+ children: (isCrypto && networks.length > 1 ? networks.find((n) => n.id === currentMethodId)?.currencies || [] : cryptoType?.currencies || []).map((cur) => /* @__PURE__ */ jsxs(MenuItem, { value: cur.id, sx: { gap: 1 }, children: [
297
+ cur.logo && /* @__PURE__ */ jsx(Avatar, { src: cur.logo, sx: { width: 20, height: 20 } }),
298
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14 }, children: cur.symbol }),
299
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 12, color: "text.secondary", ml: 0.5 }, children: cur.name })
300
+ ] }, cur.id))
301
+ }
302
+ )
303
+ ] })
304
+ ] }),
305
+ isStripe && currency && /* @__PURE__ */ jsxs(Box, { sx: { mb: 2.5 }, children: [
306
+ /* @__PURE__ */ jsx(
307
+ Typography,
308
+ {
309
+ sx: {
310
+ fontSize: 12,
311
+ fontWeight: 600,
312
+ color: "text.secondary",
313
+ mb: 0.5,
314
+ letterSpacing: "0.02em"
315
+ },
316
+ children: t("common.currency")
317
+ }
318
+ ),
319
+ /* @__PURE__ */ jsx(
320
+ Select,
321
+ {
322
+ value: currency.id || "usd",
323
+ readOnly: true,
324
+ fullWidth: true,
325
+ size: "small",
326
+ IconComponent: () => null,
327
+ sx: {
328
+ borderRadius: "8px",
329
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.06)" : "grey.50",
330
+ "& .MuiOutlinedInput-notchedOutline": { borderColor: "transparent !important" },
331
+ "& .MuiSelect-select": { display: "flex", alignItems: "center", gap: 1, py: 1 }
332
+ },
333
+ children: /* @__PURE__ */ jsxs(MenuItem, { value: currency.id || "usd", sx: { gap: 1 }, children: [
334
+ currency.logo && /* @__PURE__ */ jsx(Avatar, { src: currency.logo, sx: { width: 20, height: 20 } }),
335
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14, fontWeight: 600 }, children: currency.symbol }),
336
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 12, color: "text.secondary", ml: 0.5 }, children: currency.name })
337
+ ] })
338
+ }
339
+ )
340
+ ] }),
341
+ /* @__PURE__ */ jsx(CustomerInfoCard, { form, isLoggedIn })
342
+ ]
343
+ }
344
+ ),
345
+ /* @__PURE__ */ jsxs(Box, { className: "cko-v2-submit-btn", sx: { flexShrink: 0 }, children: [
346
+ isMobile && pricing.staking && /* @__PURE__ */ jsxs(Fragment, { children: [
347
+ /* @__PURE__ */ jsxs(
348
+ Box,
349
+ {
350
+ onClick: () => setMobileDetailsOpen(!mobileDetailsOpen),
351
+ sx: { display: "flex", alignItems: "center", justifyContent: "space-between", cursor: "pointer", mb: 1 },
352
+ children: [
353
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 13, fontWeight: 600, color: "text.secondary" }, children: t("payment.checkout.orderSummary") }),
354
+ /* @__PURE__ */ jsx(
355
+ ExpandMoreIcon,
356
+ {
357
+ sx: {
358
+ fontSize: 18,
359
+ color: "text.secondary",
360
+ transition: "0.2s",
361
+ transform: mobileDetailsOpen ? "rotate(180deg)" : "rotate(0deg)"
362
+ }
363
+ }
364
+ )
365
+ ]
366
+ }
367
+ ),
368
+ /* @__PURE__ */ jsxs(Collapse, { in: mobileDetailsOpen, children: [
369
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", sx: { mb: 1 }, children: [
370
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", children: [
371
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 13, color: "text.secondary" }, children: t("payment.checkout.staking.title") }),
372
+ /* @__PURE__ */ jsx(HelpOutlineIcon, { sx: { fontSize: 14, color: "text.disabled" } })
373
+ ] }),
374
+ isAmountLoading ? /* @__PURE__ */ jsx(Skeleton, { variant: "text", width: 60, height: 18 }) : /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: 13, fontWeight: 600 }, children: [
375
+ "+",
376
+ pricing.staking
377
+ ] })
378
+ ] }),
379
+ /* @__PURE__ */ jsx(Divider, { sx: { mb: 1 } })
380
+ ] })
381
+ ] }),
382
+ !isMobile && /* @__PURE__ */ jsxs(Fragment, { children: [
383
+ /* @__PURE__ */ jsx(Divider, { sx: { mb: 2 } }),
384
+ pricing.staking && /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", sx: { mb: 1 }, children: [
385
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", children: [
386
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 14, color: "text.secondary" }, children: t("payment.checkout.staking.title") }),
387
+ /* @__PURE__ */ jsx(
388
+ Tooltip,
389
+ {
390
+ title: t("payment.checkout.staking.tooltip"),
391
+ placement: "top",
392
+ arrow: true,
393
+ slotProps: { popper: { sx: whiteTooltipSx } },
394
+ children: /* @__PURE__ */ jsx(HelpOutlineIcon, { sx: { fontSize: 16, color: "text.disabled" } })
395
+ }
396
+ )
397
+ ] }),
398
+ isAmountLoading ? /* @__PURE__ */ jsx(Skeleton, { variant: "text", width: 80, height: 22 }) : /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: 14, fontWeight: 600 }, children: [
399
+ "+",
400
+ pricing.staking
401
+ ] })
402
+ ] }),
403
+ /* @__PURE__ */ jsx(
404
+ PromotionInput,
405
+ {
406
+ promotion: {
407
+ applied: promotion.applied,
408
+ code: promotion.code,
409
+ active: promotion.active,
410
+ inactiveReason: promotion.inactiveReason,
411
+ apply: promotion.apply,
412
+ remove: promotion.remove
413
+ },
414
+ discounts,
415
+ discountAmount: pricing.discount
416
+ }
417
+ )
418
+ ] }),
419
+ (() => {
420
+ const totalStr = pricing.total || "0";
421
+ const parts = totalStr.split(/\s+/);
422
+ const num = parts[0] || "0";
423
+ const sym = parts.slice(1).join(" ") || currency?.symbol || "";
424
+ const dotIdx = num.indexOf(".");
425
+ const intPart = dotIdx >= 0 ? num.slice(0, dotIdx) : num;
426
+ const decPart = dotIdx >= 0 ? num.slice(dotIdx) : "";
427
+ return /* @__PURE__ */ jsxs(Box, { sx: { mb: isMobile ? 1.5 : 2.5 }, children: [
428
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "flex-end", children: [
429
+ /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 700, fontSize: 14, color: "text.secondary", pb: 0.5 }, children: t("common.totalDue") }),
430
+ isAmountLoading ? /* @__PURE__ */ jsx(Skeleton, { variant: "text", width: 140, height: 44 }) : /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "right" }, children: [
431
+ /* @__PURE__ */ jsx(
432
+ Typography,
433
+ {
434
+ component: "span",
435
+ sx: {
436
+ fontSize: { xs: 28, md: 36 },
437
+ fontWeight: 800,
438
+ color: "text.primary",
439
+ lineHeight: 1,
440
+ transition: "opacity 0.3s ease"
441
+ },
442
+ children: intPart
443
+ }
444
+ ),
445
+ decPart && /* @__PURE__ */ jsx(
446
+ Typography,
447
+ {
448
+ component: "span",
449
+ sx: { fontSize: { xs: 16, md: 20 }, fontWeight: 700, color: "text.secondary", lineHeight: 1 },
450
+ children: decPart
451
+ }
452
+ ),
453
+ /* @__PURE__ */ jsx(
454
+ Typography,
455
+ {
456
+ component: "span",
457
+ sx: { fontSize: { xs: 14, md: 16 }, fontWeight: 600, color: "text.secondary", ml: 0.75 },
458
+ children: sym
459
+ }
460
+ )
461
+ ] })
462
+ ] }),
463
+ (pricing.usdEquivalent || isMobile && promotion.active) && !isAmountLoading && /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", sx: { mt: 0.25 }, children: [
464
+ (() => {
465
+ if (isMobile && !promotion.applied && promotion.active) {
466
+ return /* @__PURE__ */ jsxs(
467
+ Box,
468
+ {
469
+ onClick: () => setPromoDrawerOpen(true),
470
+ sx: { display: "flex", alignItems: "center", gap: 0.5, cursor: "pointer" },
471
+ children: [
472
+ /* @__PURE__ */ jsx(LocalOfferOutlinedIcon, { sx: { fontSize: 14, color: "primary.main" } }),
473
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 12, fontWeight: 600, color: "primary.main" }, children: tSafe(t, "payment.checkout.promotion.add", "Add promo code") })
474
+ ]
475
+ }
476
+ );
477
+ }
478
+ if (isMobile && promotion.applied) {
479
+ return /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [
480
+ /* @__PURE__ */ jsx(LocalOfferOutlinedIcon, { sx: { fontSize: 14, color: "success.main" } }),
481
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 12, fontWeight: 600, color: "success.main" }, children: promotion.code }),
482
+ pricing.discount && /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: [
483
+ "(-",
484
+ pricing.discount,
485
+ ")"
486
+ ] }),
487
+ /* @__PURE__ */ jsx(
488
+ CloseIcon,
489
+ {
490
+ onClick: promotion.remove,
491
+ sx: { fontSize: 14, color: "error.main", cursor: "pointer", ml: 0.25 }
492
+ }
493
+ )
494
+ ] });
495
+ }
496
+ return /* @__PURE__ */ jsx(Box, {});
497
+ })(),
498
+ pricing.usdEquivalent && /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: 13, color: "text.secondary" }, children: [
499
+ "\u2248 ",
500
+ pricing.usdEquivalent
501
+ ] })
502
+ ] })
503
+ ] });
504
+ })(),
505
+ /* @__PURE__ */ jsx(
506
+ Button,
507
+ {
508
+ variant: "contained",
509
+ size: "large",
510
+ fullWidth: true,
511
+ disabled: !canSubmit || submit.status === "waiting_stripe",
512
+ onClick: handleAction,
513
+ startIcon: isProcessing ? /* @__PURE__ */ jsx(CircularProgress, { size: 20, color: "inherit" }) : null,
514
+ endIcon: !isProcessing ? /* @__PURE__ */ jsx(ArrowForwardIcon, {}) : void 0,
515
+ sx: {
516
+ py: 1.5,
517
+ fontSize: "1.1rem",
518
+ fontWeight: 600,
519
+ textTransform: "none",
520
+ borderRadius: "12px"
521
+ },
522
+ children: isProcessing ? `${t("payment.checkout.processing")}...` : buttonLabel
523
+ }
524
+ ),
525
+ isMobile && /* @__PURE__ */ jsxs(
526
+ Stack,
527
+ {
528
+ direction: "row",
529
+ alignItems: "center",
530
+ justifyContent: "center",
531
+ spacing: 0.75,
532
+ sx: { mt: 1.5, opacity: 0.55 },
533
+ children: [
534
+ /* @__PURE__ */ jsx(LockOutlinedIcon, { sx: { fontSize: 13, color: "text.secondary" } }),
535
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: tSafe(t, "payment.checkout.ssl", "SSL Secure") }),
536
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.disabled" }, children: "\xB7" }),
537
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: tSafe(t, "common.terms", "Terms") }),
538
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.disabled" }, children: "|" }),
539
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: tSafe(t, "common.privacy", "Privacy") })
540
+ ]
541
+ }
542
+ )
543
+ ] }),
544
+ isMobile && /* @__PURE__ */ jsxs(
545
+ Drawer,
546
+ {
547
+ anchor: "bottom",
548
+ open: promoDrawerOpen,
549
+ onClose: () => setPromoDrawerOpen(false),
550
+ PaperProps: {
551
+ sx: {
552
+ borderRadius: "16px 16px 0 0",
553
+ p: 3,
554
+ pb: 4,
555
+ minHeight: "30vh"
556
+ }
557
+ },
558
+ children: [
559
+ /* @__PURE__ */ jsx(Box, { sx: { width: 40, height: 4, bgcolor: "divider", borderRadius: 2, mx: "auto", mb: 3 } }),
560
+ /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 700, fontSize: 16, mb: 2 }, children: tSafe(t, "payment.checkout.promotion.add", "Add promo code") }),
561
+ /* @__PURE__ */ jsx(
562
+ PromotionInput,
563
+ {
564
+ initialShowInput: true,
565
+ promotion: {
566
+ applied: promotion.applied,
567
+ code: promotion.code,
568
+ active: promotion.active,
569
+ inactiveReason: promotion.inactiveReason,
570
+ apply: async (...args) => {
571
+ const result = await promotion.apply(...args);
572
+ if (result.success) setPromoDrawerOpen(false);
573
+ return result;
574
+ },
575
+ remove: promotion.remove
576
+ },
577
+ discounts,
578
+ discountAmount: pricing.discount
579
+ }
580
+ )
581
+ ]
582
+ }
583
+ ),
584
+ /* @__PURE__ */ jsxs(Box, { sx: { flexShrink: 0 }, children: [
585
+ /* @__PURE__ */ jsx(
586
+ SubscriptionDisclaimer,
587
+ {
588
+ mode,
589
+ subscription,
590
+ staking: pricing.staking,
591
+ appName: session?.metadata?.app_name || "New Payment Kit"
592
+ }
593
+ ),
594
+ !isMobile && /* @__PURE__ */ jsxs(
595
+ Stack,
596
+ {
597
+ direction: "row",
598
+ alignItems: "center",
599
+ justifyContent: "center",
600
+ spacing: 0.75,
601
+ sx: { mt: 2.5, opacity: 0.55 },
602
+ children: [
603
+ /* @__PURE__ */ jsx(LockOutlinedIcon, { sx: { fontSize: 13, color: "text.secondary" } }),
604
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: tSafe(t, "payment.checkout.ssl", "SSL Secure") }),
605
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.disabled" }, children: "\xB7" }),
606
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: tSafe(t, "common.terms", "Terms") }),
607
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.disabled" }, children: "|" }),
608
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 11, color: "text.secondary" }, children: tSafe(t, "common.privacy", "Privacy") })
609
+ ]
610
+ }
611
+ )
612
+ ] }),
613
+ /* @__PURE__ */ jsx(StatusFeedback, { status: submit.status, context: submit.context, onReset: submit.reset }),
614
+ customerLimited && /* @__PURE__ */ jsx(
615
+ OverdueInvoicePayment,
616
+ {
617
+ customerId: sessionData?.customer?.id || session?.user?.did,
618
+ onPaid: () => {
619
+ setCustomerLimited(false);
620
+ submit.retry();
621
+ },
622
+ alertMessage: t("payment.customer.pastDue.alert.customMessage"),
623
+ detailLinkOptions: {
624
+ enabled: true,
625
+ onClick: () => {
626
+ setCustomerLimited(false);
627
+ window.open(
628
+ joinURL(getPrefix(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`),
629
+ "_self"
630
+ );
631
+ }
632
+ },
633
+ dialogProps: {
634
+ open: customerLimited,
635
+ onClose: () => {
636
+ setCustomerLimited(false);
637
+ submit.reset();
638
+ },
639
+ title: t("payment.customer.pastDue.alert.title")
640
+ }
641
+ }
642
+ )
643
+ ] });
644
+ }
@@ -0,0 +1,15 @@
1
+ import type { ThemeOptions, SxProps } from '@mui/material';
2
+ import type { LiteralUnion } from 'type-fest';
3
+ export type CheckoutScenario = 'credit-topup' | 'subscription' | 'composite';
4
+ export type PaymentThemeOptions = ThemeOptions & {
5
+ sx?: SxProps;
6
+ };
7
+ export interface CheckoutV2Props {
8
+ id: string;
9
+ onPaid?: (result: any) => void;
10
+ onError?: (err: Error) => void;
11
+ goBack?: () => void;
12
+ theme?: 'default' | 'inherit' | PaymentThemeOptions;
13
+ mode?: LiteralUnion<'standalone' | 'inline', string>;
14
+ extraParams?: Record<string, string>;
15
+ }
File without changes