@blocklet/payment-react 1.25.9 → 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 +10 -9
  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,615 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useMemo, useEffect, useRef, useCallback } from "react";
3
+ import { Box, IconButton, Typography, InputBase, Stack } from "@mui/material";
4
+ import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
5
+ import AccessTimeOutlinedIcon from "@mui/icons-material/AccessTimeOutlined";
6
+ import Inventory2OutlinedIcon from "@mui/icons-material/Inventory2Outlined";
7
+ import { useRequest } from "ahooks";
8
+ import { BN, fromTokenToUnit } from "@ocap/util";
9
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
10
+ import WarningAmberIcon from "@mui/icons-material/WarningAmber";
11
+ import {
12
+ useCheckoutStatus,
13
+ useLineItems,
14
+ useSessionContext,
15
+ useProduct,
16
+ useExchangeRate,
17
+ useSlippage,
18
+ usePaymentMethodContext,
19
+ useSubmitFeature
20
+ } from "@blocklet/payment-react-headless";
21
+ import { usePaymentContext } from "../../../contexts/payment.js";
22
+ import api from "../../../libs/api.js";
23
+ import { formatNumber, formatBNStr, formatCreditForCheckout, formatCreditAmount } from "../../../libs/util.js";
24
+ import { tSafe } from "../../utils/format.js";
25
+ import ScenarioBadge from "../../components/shared/scenario-badge.js";
26
+ import ExchangeRateFooter from "../../components/shared/exchange-rate-footer.js";
27
+ export default function CreditTopupPanel() {
28
+ const { t, locale } = useLocaleContext();
29
+ const { session, sessionData } = useSessionContext();
30
+ const { livemode } = useCheckoutStatus();
31
+ const { product } = useProduct();
32
+ const { currency, isStripe } = usePaymentMethodContext();
33
+ const lineItems = useLineItems();
34
+ const rate = useExchangeRate();
35
+ const slippage = useSlippage();
36
+ const { locked: configLocked } = useSubmitFeature();
37
+ const item = lineItems.items[0];
38
+ const activePrice = item ? item.upsell_price || item.price : null;
39
+ const creditConfig = activePrice?.metadata?.credit_config;
40
+ const creditAmount = creditConfig?.credit_amount ? Number(creditConfig.credit_amount) : 0;
41
+ const creditCurrencyId = creditConfig?.currency_id;
42
+ const { session: didSession, getCurrency } = usePaymentContext();
43
+ const creditCurrency = creditCurrencyId ? getCurrency(creditCurrencyId) : null;
44
+ const userDid = didSession?.user?.did || sessionData?.customer?.did;
45
+ const creditCurrencyDecimal = creditCurrency?.decimal;
46
+ const creditCurrencySymbol = creditCurrency?.symbol || "Credits";
47
+ const currencySymbol = "Credits";
48
+ const meterId = activePrice?.metadata?.meter_id;
49
+ const { data: meterData } = useRequest(
50
+ async () => {
51
+ if (!meterId) return null;
52
+ try {
53
+ const { data } = await api.get(`/api/meters/public/${meterId}`);
54
+ return data;
55
+ } catch {
56
+ return null;
57
+ }
58
+ },
59
+ { refreshDeps: [meterId] }
60
+ );
61
+ const creditName = meterData?.name || product?.name || "Credits";
62
+ const validDuration = creditConfig?.valid_duration_value;
63
+ const validDurationUnit = creditConfig?.valid_duration_unit || "days";
64
+ const scheduleConfig = creditConfig?.schedule;
65
+ const hasSchedule = scheduleConfig?.enabled && scheduleConfig?.delivery_mode && scheduleConfig.delivery_mode !== "invoice";
66
+ const hasExpiry = validDuration && validDuration > 0;
67
+ const step = Math.max(creditAmount, 1);
68
+ const adjustableQty = item?.adjustable_quantity;
69
+ const canAdjust = adjustableQty?.enabled !== false;
70
+ const minQuantity = Math.max(adjustableQty?.minimum || 1, 1);
71
+ const quantityAvailable = Math.min(
72
+ activePrice?.quantity_limit_per_checkout ?? Infinity,
73
+ activePrice?.quantity_available ?? Infinity
74
+ );
75
+ const maxQuantity = quantityAvailable ? Math.min(adjustableQty?.maximum || Infinity, quantityAvailable) : adjustableQty?.maximum || Infinity;
76
+ const { data: pendingAmount } = useRequest(
77
+ async () => {
78
+ if (!creditConfig || !userDid || !creditCurrencyId || creditCurrencyDecimal == null) return null;
79
+ try {
80
+ const { data } = await api.get("/api/meter-events/pending-amount", {
81
+ params: { customer_id: userDid, currency_id: creditCurrencyId }
82
+ });
83
+ return data?.[creditCurrencyId];
84
+ } catch {
85
+ return null;
86
+ }
87
+ },
88
+ { refreshDeps: [creditConfig, userDid, creditCurrencyId, creditCurrencyDecimal] }
89
+ );
90
+ const minQtyForPending = useMemo(() => {
91
+ if (!pendingAmount || !creditAmount || creditAmount <= 0) return null;
92
+ const pendingBN = new BN(pendingAmount || "0");
93
+ if (!pendingBN.gt(new BN(0))) return null;
94
+ const creditBN = fromTokenToUnit(creditAmount, creditCurrencyDecimal);
95
+ if (!creditBN || creditBN.isZero()) return null;
96
+ return Math.ceil(pendingBN.mul(new BN(100)).div(creditBN).toNumber() / 100);
97
+ }, [pendingAmount, creditAmount, creditCurrencyDecimal]);
98
+ const hasPendingAmount = pendingAmount && new BN(pendingAmount || "0").gt(new BN(0));
99
+ const pendingDisplayAmount = useMemo(() => {
100
+ if (!hasPendingAmount) return "";
101
+ return formatCreditForCheckout(formatBNStr(pendingAmount, creditCurrencyDecimal), creditCurrencySymbol, locale);
102
+ }, [hasPendingAmount, pendingAmount, creditCurrencyDecimal, creditCurrencySymbol, locale]);
103
+ const minCreditsForPending = minQtyForPending ? minQtyForPending * step : 0;
104
+ const minCreditsForPendingFormatted = minCreditsForPending ? formatCreditForCheckout(formatNumber(minCreditsForPending), creditCurrencySymbol, locale) : "";
105
+ const creditInfoText = useMemo(() => {
106
+ if (hasSchedule && scheduleConfig) {
107
+ const intervalUnit = scheduleConfig.interval_unit;
108
+ const intervalValue = scheduleConfig.interval_value;
109
+ let amountPerGrant;
110
+ if (scheduleConfig.amount_per_grant) {
111
+ amountPerGrant = Number(scheduleConfig.amount_per_grant);
112
+ } else {
113
+ amountPerGrant = creditAmount;
114
+ }
115
+ const formattedAmount = formatCreditAmount(formatNumber(amountPerGrant), currencySymbol);
116
+ const intervalDisplay = intervalValue === 1 ? t(`common.${intervalUnit}`) : `${intervalValue} ${t(`common.${intervalUnit}s`)}`;
117
+ return scheduleConfig.expire_with_next_grant ? t("payment.checkout.credit.schedule.withRefresh", { amount: formattedAmount, interval: intervalDisplay }) : t("payment.checkout.credit.schedule.periodic", { amount: formattedAmount, interval: intervalDisplay });
118
+ }
119
+ const productDesc = product?.description || "";
120
+ if (productDesc && productDesc.length > 10 && productDesc !== creditName) {
121
+ return productDesc;
122
+ }
123
+ return "";
124
+ }, [creditAmount, currencySymbol, hasSchedule, scheduleConfig, creditName, product, t]);
125
+ const validityText = useMemo(() => {
126
+ if (!hasExpiry) return "";
127
+ return t("payment.checkout.creditTopup.validFor", {
128
+ duration: validDuration,
129
+ unit: t(`common.${validDurationUnit}`)
130
+ });
131
+ }, [hasExpiry, validDuration, validDurationUnit, t]);
132
+ const hasSubtitle = !!creditInfoText;
133
+ const currentQty = item?.quantity || 1;
134
+ const [localQty, setLocalQty] = useState(currentQty);
135
+ const [desiredCredits, setDesiredCredits] = useState(currentQty * step);
136
+ const [isEditing, setIsEditing] = useState(false);
137
+ const [editValue, setEditValue] = useState("");
138
+ const inputRef = useRef(null);
139
+ useEffect(() => {
140
+ if (configLocked || session?.status === "complete") return;
141
+ if (item?.quantity && item.quantity !== localQty) {
142
+ setLocalQty(item.quantity);
143
+ setDesiredCredits(item.quantity * step);
144
+ }
145
+ }, [item?.quantity]);
146
+ const pendingEnforcedRef = useRef(false);
147
+ useEffect(() => {
148
+ if (configLocked || session?.status === "complete") return;
149
+ if (pendingEnforcedRef.current) return;
150
+ if (minQtyForPending && minQtyForPending > localQty) {
151
+ pendingEnforcedRef.current = true;
152
+ const newQty = Math.min(Math.max(minQtyForPending, minQuantity), maxQuantity);
153
+ setLocalQty(newQty);
154
+ setDesiredCredits(newQty * step);
155
+ if (item) lineItems.updateQuantity(item.price_id, newQty);
156
+ }
157
+ }, [minQtyForPending]);
158
+ const maxCredits = maxQuantity * step;
159
+ const minCredits = minQuantity * step;
160
+ const commitCredits = useCallback(
161
+ (credits) => {
162
+ if (credits <= 0) return;
163
+ const clamped = Math.max(minCredits, Math.min(maxCredits, credits));
164
+ const packs = Math.ceil(clamped / step);
165
+ const clampedPacks = Math.max(minQuantity, Math.min(maxQuantity, packs));
166
+ setLocalQty(clampedPacks);
167
+ setDesiredCredits(clamped);
168
+ if (item) lineItems.updateQuantity(item.price_id, clampedPacks);
169
+ },
170
+ [step, minQuantity, maxQuantity, minCredits, maxCredits, item, lineItems]
171
+ );
172
+ const handleStep = useCallback(
173
+ (delta) => {
174
+ const newCredits = desiredCredits + delta * step;
175
+ if (newCredits < step * minQuantity || Math.ceil(newCredits / step) > maxQuantity) return;
176
+ commitCredits(newCredits);
177
+ },
178
+ [desiredCredits, step, minQuantity, maxQuantity, commitCredits]
179
+ );
180
+ const actualPacks = Math.max(minQuantity, Math.min(maxQuantity, Math.ceil(desiredCredits / step)));
181
+ const actualCredits = actualPacks * step;
182
+ const actualCreditsFormatted = formatNumber(actualCredits, 6, true, true);
183
+ const desiredCreditsFormatted = formatNumber(desiredCredits, 6, true, true);
184
+ const showReceiveSection = canAdjust && step > 1;
185
+ const pendingMessage = useMemo(() => {
186
+ if (!hasPendingAmount) return "";
187
+ if (actualCredits >= minCreditsForPending) {
188
+ return t("payment.checkout.creditTopup.pendingEnough", {
189
+ pendingAmount: pendingDisplayAmount,
190
+ availableAmount: formatCreditForCheckout(
191
+ formatNumber(actualCredits - minCreditsForPending),
192
+ creditCurrencySymbol,
193
+ locale
194
+ )
195
+ });
196
+ }
197
+ return t("payment.checkout.creditTopup.pendingWarning", {
198
+ pendingAmount: pendingDisplayAmount,
199
+ minCredits: minCreditsForPendingFormatted
200
+ });
201
+ }, [
202
+ hasPendingAmount,
203
+ actualCredits,
204
+ minCreditsForPending,
205
+ pendingDisplayAmount,
206
+ creditCurrencySymbol,
207
+ locale,
208
+ minCreditsForPendingFormatted,
209
+ t
210
+ ]);
211
+ const startEditing = useCallback(() => {
212
+ if (!canAdjust) return;
213
+ setEditValue(String(desiredCredits));
214
+ setIsEditing(true);
215
+ setTimeout(() => inputRef.current?.select(), 0);
216
+ }, [canAdjust, desiredCredits]);
217
+ const commitEdit = useCallback(() => {
218
+ setIsEditing(false);
219
+ const parsed = parseInt(editValue.replace(/,/g, ""), 10);
220
+ if (!Number.isFinite(parsed) || parsed <= 0) return;
221
+ commitCredits(parsed);
222
+ }, [editValue, commitCredits]);
223
+ const handleEditKeyDown = useCallback(
224
+ (e) => {
225
+ if (e.key === "Enter") commitEdit();
226
+ else if (e.key === "Escape") setIsEditing(false);
227
+ },
228
+ [commitEdit]
229
+ );
230
+ const numberHeight = { xs: 48, md: 72 };
231
+ const numberFontSx = {
232
+ fontSize: numberHeight,
233
+ fontWeight: 800,
234
+ lineHeight: 1,
235
+ letterSpacing: "-0.03em"
236
+ };
237
+ const circleBtnSx = {
238
+ width: { xs: 40, md: 56 },
239
+ height: { xs: 40, md: 56 },
240
+ borderRadius: "50%",
241
+ bgcolor: "background.paper",
242
+ border: "1px solid",
243
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.12)" : "divider",
244
+ color: "text.secondary",
245
+ transition: "all 0.2s ease",
246
+ "&:hover": {
247
+ borderColor: "primary.main",
248
+ color: "primary.main",
249
+ bgcolor: "background.paper"
250
+ },
251
+ "&.Mui-disabled": {
252
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.06)",
253
+ color: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.12)"
254
+ }
255
+ };
256
+ return /* @__PURE__ */ jsxs(
257
+ Box,
258
+ {
259
+ sx: {
260
+ display: "flex",
261
+ flexDirection: "column",
262
+ height: "100%"
263
+ },
264
+ children: [
265
+ /* @__PURE__ */ jsxs(Box, { sx: { flex: 1, display: "flex", flexDirection: "column", justifyContent: "center" }, children: [
266
+ /* @__PURE__ */ jsx(ScenarioBadge, { livemode, label: tSafe(t, "payment.checkout.typeBadge.topup", "TOP-UP") }),
267
+ /* @__PURE__ */ jsx(
268
+ Typography,
269
+ {
270
+ sx: {
271
+ fontWeight: 800,
272
+ fontSize: { xs: 28, md: 48 },
273
+ lineHeight: 1.1,
274
+ letterSpacing: "-0.03em",
275
+ color: "text.primary",
276
+ mb: { xs: 0.5, md: 1 }
277
+ },
278
+ children: t("payment.checkout.creditTopup.title", { name: creditName })
279
+ }
280
+ ),
281
+ hasSubtitle && /* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "flex-start", gap: 1, mb: { xs: 1.5, md: 2.5 } }, children: /* @__PURE__ */ jsx(
282
+ Typography,
283
+ {
284
+ sx: { fontSize: { xs: 13, md: 15 }, fontWeight: 500, color: "text.secondary", lineHeight: 1.5 },
285
+ children: creditInfoText
286
+ }
287
+ ) }),
288
+ hasPendingAmount && /* @__PURE__ */ jsxs(
289
+ Stack,
290
+ {
291
+ direction: "row",
292
+ alignItems: "flex-start",
293
+ spacing: 1.5,
294
+ sx: {
295
+ mb: { xs: 1.5, md: 2.5 },
296
+ p: { xs: 1.5, md: 2 },
297
+ borderRadius: "12px",
298
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(255,152,0,0.12)" : "rgba(255,152,0,0.08)",
299
+ border: "1px solid",
300
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(255,152,0,0.25)" : "rgba(255,152,0,0.2)"
301
+ },
302
+ children: [
303
+ /* @__PURE__ */ jsx(WarningAmberIcon, { sx: { fontSize: 18, color: "warning.main", mt: 0.25, flexShrink: 0 } }),
304
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: { xs: 12, md: 13 }, fontWeight: 600, lineHeight: 1.5, color: "text.primary" }, children: pendingMessage })
305
+ ]
306
+ }
307
+ ),
308
+ canAdjust ? /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", maxWidth: 480 }, children: [
309
+ /* @__PURE__ */ jsx(
310
+ Typography,
311
+ {
312
+ sx: {
313
+ fontSize: { xs: 14, md: 17 },
314
+ fontWeight: 700,
315
+ color: "text.secondary",
316
+ mt: { xs: 3, md: 5 },
317
+ mb: { xs: 2, md: 3 }
318
+ },
319
+ children: t("payment.checkout.creditTopup.question", { symbol: currencySymbol })
320
+ }
321
+ ),
322
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: { xs: 1.5, md: 2 } }, children: [
323
+ /* @__PURE__ */ jsx(IconButton, { onClick: () => handleStep(-1), disabled: actualPacks <= minQuantity, sx: circleBtnSx, children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: { xs: 22, md: 28 }, fontWeight: 300, lineHeight: 1, mt: "-1px" }, children: "\u2212" }) }),
324
+ /* @__PURE__ */ jsxs(
325
+ Box,
326
+ {
327
+ sx: { flex: 1, minWidth: 0, textAlign: "center", cursor: canAdjust ? "text" : "default" },
328
+ onClick: startEditing,
329
+ children: [
330
+ /* @__PURE__ */ jsx(
331
+ Box,
332
+ {
333
+ sx: {
334
+ height: numberHeight,
335
+ display: "flex",
336
+ alignItems: "center",
337
+ justifyContent: "center"
338
+ },
339
+ children: isEditing ? /* @__PURE__ */ jsx(
340
+ InputBase,
341
+ {
342
+ inputRef,
343
+ value: editValue,
344
+ onChange: (e) => setEditValue(e.target.value.replace(/\D/g, "")),
345
+ onBlur: commitEdit,
346
+ onKeyDown: handleEditKeyDown,
347
+ autoFocus: true,
348
+ inputProps: { inputMode: "numeric", pattern: "[0-9]*" },
349
+ sx: {
350
+ width: "100%",
351
+ bgcolor: "transparent",
352
+ "&.Mui-focused": { bgcolor: "transparent" },
353
+ "& input": {
354
+ textAlign: "center",
355
+ ...numberFontSx,
356
+ p: 0,
357
+ fontFamily: "inherit",
358
+ bgcolor: "transparent",
359
+ "&:focus": { bgcolor: "transparent" }
360
+ }
361
+ }
362
+ }
363
+ ) : /* @__PURE__ */ jsx(Typography, { sx: { ...numberFontSx, color: "text.primary", userSelect: "none" }, children: desiredCreditsFormatted })
364
+ }
365
+ ),
366
+ /* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "center", gap: 0.75, mt: 1 }, children: /* @__PURE__ */ jsx(
367
+ Typography,
368
+ {
369
+ sx: {
370
+ fontSize: { xs: 12, md: 14 },
371
+ fontWeight: 700,
372
+ color: "text.secondary",
373
+ textTransform: "uppercase",
374
+ letterSpacing: "0.05em"
375
+ },
376
+ children: currencySymbol
377
+ }
378
+ ) })
379
+ ]
380
+ }
381
+ ),
382
+ /* @__PURE__ */ jsx(IconButton, { onClick: () => handleStep(1), disabled: actualPacks >= maxQuantity, sx: circleBtnSx, children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: { xs: 22, md: 28 }, fontWeight: 300, lineHeight: 1 }, children: "+" }) })
383
+ ] }),
384
+ step > 1 && /* @__PURE__ */ jsx(
385
+ Typography,
386
+ {
387
+ sx: {
388
+ fontSize: 11,
389
+ fontWeight: 600,
390
+ color: "grey.500",
391
+ textTransform: "uppercase",
392
+ letterSpacing: "0.08em",
393
+ textAlign: "center",
394
+ mt: { xs: 1.5, md: 2 }
395
+ },
396
+ children: t("payment.checkout.creditTopup.increment", {
397
+ step: formatNumber(step, 6, true, true),
398
+ symbol: currencySymbol
399
+ })
400
+ }
401
+ ),
402
+ showReceiveSection && /* @__PURE__ */ jsxs(
403
+ Box,
404
+ {
405
+ sx: {
406
+ display: "flex",
407
+ flexDirection: "column",
408
+ mt: { xs: 3, md: 4 },
409
+ borderRadius: "20px",
410
+ backdropFilter: "blur(12px)",
411
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.04)",
412
+ border: "1px solid",
413
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.18)" : "rgba(59,130,246,0.10)",
414
+ boxShadow: (theme) => theme.palette.mode === "dark" ? "0 8px 32px rgba(59,130,246,0.06)" : "0 8px 32px rgba(59,130,246,0.04)"
415
+ },
416
+ children: [
417
+ /* @__PURE__ */ jsxs(Box, { sx: { p: { xs: 2.5, md: 3.5 } }, children: [
418
+ /* @__PURE__ */ jsxs(
419
+ Typography,
420
+ {
421
+ sx: {
422
+ fontSize: { xs: 16, md: 20 },
423
+ fontWeight: 700,
424
+ color: "primary.main",
425
+ mb: 0.5
426
+ },
427
+ children: [
428
+ t("payment.checkout.creditTopup.willReceive"),
429
+ ": ",
430
+ /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontWeight: 800 }, children: formatCreditForCheckout(actualCreditsFormatted, currencySymbol, locale) })
431
+ ]
432
+ }
433
+ ),
434
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.75, mb: 0.5 }, children: [
435
+ /* @__PURE__ */ jsx(Inventory2OutlinedIcon, { sx: { fontSize: 16, color: "text.secondary" } }),
436
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: { xs: 12, md: 14 }, fontWeight: 600, color: "text.secondary" }, children: t("payment.checkout.creditTopup.packInfo", {
437
+ packs: actualPacks,
438
+ perPack: formatNumber(step, 6, true, true)
439
+ }) })
440
+ ] }),
441
+ /* @__PURE__ */ jsx(
442
+ Typography,
443
+ {
444
+ sx: {
445
+ fontSize: { xs: 12, md: 13 },
446
+ fontWeight: 500,
447
+ color: "grey.500"
448
+ },
449
+ children: t("payment.checkout.creditTopup.autoMatch")
450
+ }
451
+ )
452
+ ] }),
453
+ validityText && /* @__PURE__ */ jsxs(
454
+ Box,
455
+ {
456
+ sx: {
457
+ display: "flex",
458
+ alignItems: "center",
459
+ gap: 0.75,
460
+ px: { xs: 2.5, md: 3.5 },
461
+ py: { xs: 1.5, md: 2 },
462
+ borderTop: "1px solid",
463
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.15)" : "rgba(59,130,246,0.08)"
464
+ },
465
+ children: [
466
+ /* @__PURE__ */ jsx(AccessTimeOutlinedIcon, { sx: { fontSize: 14, color: "grey.500" } }),
467
+ /* @__PURE__ */ jsx(
468
+ Typography,
469
+ {
470
+ sx: {
471
+ fontSize: { xs: 12, md: 13 },
472
+ fontWeight: 500,
473
+ color: "grey.500"
474
+ },
475
+ children: validityText
476
+ }
477
+ )
478
+ ]
479
+ }
480
+ )
481
+ ]
482
+ }
483
+ ),
484
+ !showReceiveSection && validityText && /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.75, mt: { xs: 2.5, md: 3.5 } }, children: [
485
+ /* @__PURE__ */ jsx(InfoOutlinedIcon, { sx: { fontSize: 14, color: "grey.500" } }),
486
+ /* @__PURE__ */ jsx(
487
+ Typography,
488
+ {
489
+ sx: {
490
+ fontSize: { xs: 12, md: 13 },
491
+ fontWeight: 500,
492
+ color: "grey.500"
493
+ },
494
+ children: validityText
495
+ }
496
+ )
497
+ ] })
498
+ ] }) : (
499
+ // ── Non-adjustable: show fixed credit amount in a styled card ──
500
+ /* @__PURE__ */ jsxs(
501
+ Box,
502
+ {
503
+ sx: {
504
+ display: "flex",
505
+ flexDirection: "column",
506
+ mt: { xs: 2, md: 3 },
507
+ borderRadius: "20px",
508
+ backdropFilter: "blur(12px)",
509
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.04)",
510
+ border: "1px solid",
511
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.18)" : "rgba(59,130,246,0.10)",
512
+ boxShadow: (theme) => theme.palette.mode === "dark" ? "0 8px 32px rgba(59,130,246,0.06)" : "0 8px 32px rgba(59,130,246,0.04)"
513
+ },
514
+ children: [
515
+ /* @__PURE__ */ jsxs(Box, { sx: { p: { xs: 2.5, md: 3.5 } }, children: [
516
+ /* @__PURE__ */ jsx(
517
+ Typography,
518
+ {
519
+ sx: {
520
+ fontSize: { xs: 13, md: 14 },
521
+ fontWeight: 600,
522
+ color: "text.secondary",
523
+ mb: 1
524
+ },
525
+ children: t("payment.checkout.creditTopup.willReceive")
526
+ }
527
+ ),
528
+ /* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center", gap: 1.5 }, children: /* @__PURE__ */ jsx(
529
+ Typography,
530
+ {
531
+ sx: {
532
+ fontSize: { xs: 32, md: 48 },
533
+ fontWeight: 800,
534
+ lineHeight: 1,
535
+ letterSpacing: "-0.03em",
536
+ color: "primary.main"
537
+ },
538
+ children: formatCreditForCheckout(actualCreditsFormatted, currencySymbol, locale)
539
+ }
540
+ ) })
541
+ ] }),
542
+ validityText && /* @__PURE__ */ jsxs(
543
+ Box,
544
+ {
545
+ sx: {
546
+ display: "flex",
547
+ alignItems: "center",
548
+ gap: 0.75,
549
+ px: { xs: 2.5, md: 3.5 },
550
+ py: { xs: 1.5, md: 2 },
551
+ borderTop: "1px solid",
552
+ borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.15)" : "rgba(59,130,246,0.08)"
553
+ },
554
+ children: [
555
+ /* @__PURE__ */ jsx(AccessTimeOutlinedIcon, { sx: { fontSize: 14, color: "grey.500" } }),
556
+ /* @__PURE__ */ jsx(
557
+ Typography,
558
+ {
559
+ sx: {
560
+ fontSize: { xs: 12, md: 13 },
561
+ fontWeight: 500,
562
+ color: "grey.500"
563
+ },
564
+ children: validityText
565
+ }
566
+ )
567
+ ]
568
+ }
569
+ )
570
+ ]
571
+ }
572
+ )
573
+ )
574
+ ] }),
575
+ /* @__PURE__ */ jsxs(Box, { sx: { flexShrink: 0 }, children: [
576
+ rate.hasDynamicPricing && rate.status === "unavailable" && !isStripe && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.75, sx: { mb: 2 }, children: [
577
+ /* @__PURE__ */ jsx(Typography, { sx: { fontSize: 13, color: "text.secondary", fontWeight: 500 }, children: t("payment.dynamicPricing.unavailable.title") }),
578
+ /* @__PURE__ */ jsx(
579
+ Typography,
580
+ {
581
+ component: "span",
582
+ onClick: rate.refresh,
583
+ sx: {
584
+ fontSize: 13,
585
+ color: "primary.main",
586
+ fontWeight: 600,
587
+ cursor: "pointer",
588
+ "&:hover": { textDecoration: "underline" }
589
+ },
590
+ children: t("payment.dynamicPricing.unavailable.retry")
591
+ }
592
+ )
593
+ ] }),
594
+ /* @__PURE__ */ jsx(
595
+ ExchangeRateFooter,
596
+ {
597
+ hasDynamicPricing: rate.hasDynamicPricing,
598
+ rate: {
599
+ value: rate.value,
600
+ display: rate.display,
601
+ provider: rate.provider,
602
+ providerDisplay: rate.providerDisplay,
603
+ fetchedAt: rate.fetchedAt,
604
+ status: rate.status
605
+ },
606
+ slippage: { percent: slippage.percent, set: slippage.set },
607
+ currencySymbol: currency?.symbol || "",
608
+ isSubscription: ["subscription", "setup"].includes(session?.mode || "payment")
609
+ }
610
+ )
611
+ ] })
612
+ ]
613
+ }
614
+ );
615
+ }
@@ -0,0 +1 @@
1
+ export default function ScenarioRouter(): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useSessionContext } from "@blocklet/payment-react-headless";
3
+ import { detectScenario } from "../../utils/scenario-detector.js";
4
+ import CompositePanel from "./composite-panel.js";
5
+ import CreditTopupPanel from "./credit-topup-panel.js";
6
+ const SubscriptionPanel = CompositePanel;
7
+ export default function ScenarioRouter() {
8
+ const { session, items } = useSessionContext();
9
+ const scenario = detectScenario(session, items);
10
+ switch (scenario) {
11
+ case "subscription":
12
+ return /* @__PURE__ */ jsx(SubscriptionPanel, {});
13
+ case "credit-topup":
14
+ return /* @__PURE__ */ jsx(CreditTopupPanel, {});
15
+ case "composite":
16
+ default:
17
+ return /* @__PURE__ */ jsx(CompositePanel, {});
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export default function PaymentPanel(): import("react").JSX.Element;