@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,735 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = SuccessView;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _react = require("react");
9
+ var _material = require("@mui/material");
10
+ var _Check = _interopRequireDefault(require("@mui/icons-material/Check"));
11
+ var _CheckCircle = _interopRequireDefault(require("@mui/icons-material/CheckCircle"));
12
+ var _VerifiedUser = _interopRequireDefault(require("@mui/icons-material/VerifiedUser"));
13
+ var _ErrorOutline = _interopRequireDefault(require("@mui/icons-material/ErrorOutline"));
14
+ var _OpenInNew = _interopRequireDefault(require("@mui/icons-material/OpenInNew"));
15
+ var _ArrowBack = _interopRequireDefault(require("@mui/icons-material/ArrowBack"));
16
+ var _ufo = require("ufo");
17
+ var _context = require("@arcblock/ux/lib/Locale/context");
18
+ var _paymentReactHeadless = require("@blocklet/payment-react-headless");
19
+ var _util = require("../../libs/util");
20
+ var _format = require("../utils/format");
21
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
+ const scaleIn = (0, _material.keyframes)`
23
+ from { transform: scale(0); opacity: 0; }
24
+ 60% { transform: scale(1.15); }
25
+ to { transform: scale(1); opacity: 1; }
26
+ `;
27
+ const fadeUp = (0, _material.keyframes)`
28
+ from { opacity: 0; transform: translateY(16px); }
29
+ to { opacity: 1; transform: translateY(0); }
30
+ `;
31
+ function useConfetti(containerRef, enabled) {
32
+ const firedRef = (0, _react.useRef)(false);
33
+ (0, _react.useEffect)(() => {
34
+ if (!enabled || firedRef.current || !containerRef.current) return void 0;
35
+ firedRef.current = true;
36
+ const container = containerRef.current;
37
+ const canvas = document.createElement("canvas");
38
+ canvas.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:10;";
39
+ canvas.width = container.offsetWidth;
40
+ canvas.height = container.offsetHeight;
41
+ container.appendChild(canvas);
42
+ const ctx = canvas.getContext("2d");
43
+ if (!ctx) return void 0;
44
+ const colors = ["#3b82f6", "#60a5fa", "#34d399", "#fbbf24", "#f472b6", "#a78bfa", "#f97316"];
45
+ const pieces = [];
46
+ for (let i = 0; i < 80; i++) {
47
+ pieces.push({
48
+ x: canvas.width / 2 + (Math.random() - 0.5) * 60,
49
+ y: canvas.height * 0.35,
50
+ vx: (Math.random() - 0.5) * 12,
51
+ vy: -Math.random() * 14 - 4,
52
+ w: Math.random() * 8 + 4,
53
+ h: Math.random() * 6 + 2,
54
+ color: colors[Math.floor(Math.random() * colors.length)],
55
+ rot: Math.random() * Math.PI * 2,
56
+ rv: (Math.random() - 0.5) * 0.3,
57
+ opacity: 1
58
+ });
59
+ }
60
+ let frame;
61
+ const gravity = 0.25;
62
+ const friction = 0.99;
63
+ const animate = () => {
64
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
65
+ let alive = false;
66
+ for (const p of pieces) {
67
+ p.vy += gravity;
68
+ p.vx *= friction;
69
+ p.x += p.vx;
70
+ p.y += p.vy;
71
+ p.rot += p.rv;
72
+ if (p.y > canvas.height * 0.6) {
73
+ p.opacity -= 0.02;
74
+ }
75
+ if (p.opacity > 0) {
76
+ alive = true;
77
+ ctx.save();
78
+ ctx.globalAlpha = p.opacity;
79
+ ctx.translate(p.x, p.y);
80
+ ctx.rotate(p.rot);
81
+ ctx.fillStyle = p.color;
82
+ ctx.fillRect(-p.w / 2, -p.h / 2, p.w, p.h);
83
+ ctx.restore();
84
+ }
85
+ }
86
+ if (alive) {
87
+ frame = requestAnimationFrame(animate);
88
+ } else {
89
+ canvas.remove();
90
+ }
91
+ };
92
+ const timer = setTimeout(() => {
93
+ frame = requestAnimationFrame(animate);
94
+ }, 400);
95
+ return () => {
96
+ clearTimeout(timer);
97
+ cancelAnimationFrame(frame);
98
+ canvas.remove();
99
+ };
100
+ }, [enabled, containerRef]);
101
+ }
102
+ function getCustomMessage(session) {
103
+ return session?.payment_link?.after_completion?.hosted_confirmation?.custom_message;
104
+ }
105
+ function getPayee(session) {
106
+ const items = session?.line_items || [];
107
+ for (const item of items) {
108
+ if (item?.price?.product?.statement_descriptor) {
109
+ return item.price.product.statement_descriptor;
110
+ }
111
+ }
112
+ return session?.app_name || session?.payment_link?.app_name || "";
113
+ }
114
+ function getVendorLabel(vendor, isFailed, t) {
115
+ const name = vendor.name || vendor.title;
116
+ const isCompleted = vendor.status === "delivered";
117
+ if (vendor.vendorType === "didnames") {
118
+ if (isFailed) return t("payment.checkout.vendor.didnames.failed", {
119
+ name
120
+ });
121
+ if (isCompleted) return t("payment.checkout.vendor.didnames.completed", {
122
+ name
123
+ });
124
+ return t("payment.checkout.vendor.didnames.processing", {
125
+ name
126
+ });
127
+ }
128
+ if (isFailed) return t("payment.checkout.vendor.launcher.failed", {
129
+ name
130
+ });
131
+ if (isCompleted) return t("payment.checkout.vendor.launcher.completed", {
132
+ name
133
+ });
134
+ return t("payment.checkout.vendor.launcher.processing", {
135
+ name
136
+ });
137
+ }
138
+ function HeroSuccessIcon() {
139
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
140
+ sx: {
141
+ position: "relative",
142
+ mb: 1,
143
+ animation: `${scaleIn} 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both`
144
+ },
145
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
146
+ sx: {
147
+ position: "absolute",
148
+ inset: -24,
149
+ background: theme => theme.palette.mode === "dark" ? "radial-gradient(circle, rgba(59,130,246,0.12) 0%, transparent 70%)" : "radial-gradient(circle, rgba(59,130,246,0.08) 0%, transparent 70%)",
150
+ borderRadius: "50%",
151
+ pointerEvents: "none"
152
+ }
153
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
154
+ sx: {
155
+ position: "relative",
156
+ width: {
157
+ xs: 100,
158
+ md: 120
159
+ },
160
+ height: {
161
+ xs: 100,
162
+ md: 120
163
+ },
164
+ borderRadius: {
165
+ xs: "28px",
166
+ md: "32px"
167
+ },
168
+ background: theme => theme.palette.mode === "dark" ? "linear-gradient(135deg, rgba(59,130,246,0.15) 0%, rgba(255,255,255,0.04) 100%)" : "linear-gradient(135deg, #eff6ff 0%, #ffffff 100%)",
169
+ border: "1px solid",
170
+ borderColor: theme => theme.palette.mode === "dark" ? "rgba(59,130,246,0.2)" : "rgba(59,130,246,0.12)",
171
+ boxShadow: theme => theme.palette.mode === "dark" ? "0 10px 30px -5px rgba(0,0,0,0.3)" : "0 10px 30px -5px rgba(59,130,246,0.1)",
172
+ display: "flex",
173
+ alignItems: "center",
174
+ justifyContent: "center"
175
+ },
176
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
177
+ sx: {
178
+ position: "absolute",
179
+ inset: 0,
180
+ borderRadius: "inherit",
181
+ background: theme => theme.palette.mode === "dark" ? "linear-gradient(to top-right, rgba(59,130,246,0.1), transparent)" : "linear-gradient(to top-right, rgba(59,130,246,0.06), transparent)",
182
+ pointerEvents: "none"
183
+ }
184
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_VerifiedUser.default, {
185
+ sx: {
186
+ fontSize: {
187
+ xs: 52,
188
+ md: 64
189
+ },
190
+ color: "primary.main",
191
+ filter: theme => theme.palette.mode === "dark" ? "drop-shadow(0 0 12px rgba(59,130,246,0.4))" : "drop-shadow(0 0 12px rgba(59,130,246,0.2))"
192
+ }
193
+ })]
194
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
195
+ sx: {
196
+ position: "absolute",
197
+ bottom: {
198
+ xs: -6,
199
+ md: -8
200
+ },
201
+ right: {
202
+ xs: -6,
203
+ md: -8
204
+ },
205
+ width: {
206
+ xs: 32,
207
+ md: 38
208
+ },
209
+ height: {
210
+ xs: 32,
211
+ md: 38
212
+ },
213
+ borderRadius: {
214
+ xs: "12px",
215
+ md: "14px"
216
+ },
217
+ bgcolor: "background.paper",
218
+ boxShadow: "0 4px 12px rgba(0,0,0,0.1)",
219
+ border: "1px solid",
220
+ borderColor: theme => theme.palette.mode === "dark" ? "rgba(255,255,255,0.1)" : "rgba(59,130,246,0.08)",
221
+ display: "flex",
222
+ alignItems: "center",
223
+ justifyContent: "center"
224
+ },
225
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_CheckCircle.default, {
226
+ sx: {
227
+ fontSize: {
228
+ xs: 20,
229
+ md: 24
230
+ },
231
+ color: "success.main"
232
+ }
233
+ })
234
+ })]
235
+ });
236
+ }
237
+ function PaymentReceipt({
238
+ session,
239
+ t
240
+ }) {
241
+ const {
242
+ currencies
243
+ } = (0, _paymentReactHeadless.usePaymentMethodContext)();
244
+ const amountTotal = session?.amount_total;
245
+ const currencyId = session?.currency_id;
246
+ const subData = session?.subscription_data;
247
+ if (Number(subData?.trial_period_days || 0) > 0) return null;
248
+ if (!amountTotal || amountTotal === "0") return null;
249
+ const currency = currencies.find(c => c.id === currencyId) || null;
250
+ if (!currency) return null;
251
+ const formatted = (0, _format.formatTokenAmount)(amountTotal, currency);
252
+ if (!formatted || formatted === "0") return null;
253
+ const amountStr = `${formatted} ${currency.symbol || ""}`.trim();
254
+ const fullText = t("payment.checkout.completed.summary.paid", {
255
+ amount: amountStr
256
+ });
257
+ const idx = fullText.indexOf(amountStr);
258
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
259
+ sx: {
260
+ fontSize: {
261
+ xs: 15,
262
+ md: 16
263
+ },
264
+ color: "text.secondary",
265
+ fontWeight: 500,
266
+ lineHeight: 1.6,
267
+ textAlign: "center",
268
+ maxWidth: 440,
269
+ animation: `${fadeUp} 0.5s ease 0.3s both`
270
+ },
271
+ children: idx >= 0 ? /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
272
+ children: [fullText.slice(0, idx), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
273
+ component: "span",
274
+ sx: {
275
+ fontWeight: 700,
276
+ color: "text.primary"
277
+ },
278
+ children: amountStr
279
+ }), fullText.slice(idx + amountStr.length)]
280
+ }) : fullText
281
+ });
282
+ }
283
+ function VendorProgressItemV2({
284
+ vendor,
285
+ t
286
+ }) {
287
+ const [displayProgress, setDisplayProgress] = (0, _react.useState)(0);
288
+ const animationRef = (0, _react.useRef)();
289
+ const startAnimation = (0, _react.useCallback)(() => {
290
+ const realProgress = vendor.progress || 0;
291
+ let startTime;
292
+ let startProgress;
293
+ const animate = currentTime => {
294
+ if (!startTime) {
295
+ startTime = currentTime;
296
+ startProgress = displayProgress;
297
+ }
298
+ const elapsed = currentTime - startTime;
299
+ let newProgress;
300
+ if (realProgress === 100) {
301
+ newProgress = 100;
302
+ } else if (realProgress === 0) {
303
+ newProgress = Math.min(startProgress + elapsed / 1e3, 99);
304
+ } else if (realProgress > startProgress) {
305
+ const progress = Math.min(elapsed / 1e3, 1);
306
+ newProgress = startProgress + (realProgress - startProgress) * progress;
307
+ } else {
308
+ newProgress = Math.min(startProgress + elapsed / 1e3, 99);
309
+ }
310
+ newProgress = Math.round(newProgress);
311
+ setDisplayProgress(pre => Math.min(pre > newProgress ? pre : newProgress, 100));
312
+ if (realProgress === 100) return;
313
+ if (newProgress < 99 && realProgress < 100) {
314
+ animationRef.current = requestAnimationFrame(animate);
315
+ }
316
+ };
317
+ if (animationRef.current) cancelAnimationFrame(animationRef.current);
318
+ animationRef.current = requestAnimationFrame(animate);
319
+ }, [vendor.progress, displayProgress]);
320
+ (0, _react.useEffect)(() => {
321
+ startAnimation();
322
+ return () => {
323
+ if (animationRef.current) cancelAnimationFrame(animationRef.current);
324
+ };
325
+ }, [startAnimation]);
326
+ const isCompleted = displayProgress >= 100;
327
+ const isFailed = vendor.status === "failed";
328
+ const nameText = getVendorLabel(vendor, isFailed, t);
329
+ if (!vendor.name && !vendor.title) {
330
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
331
+ sx: {
332
+ mb: 1.5
333
+ },
334
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
335
+ direction: "row",
336
+ justifyContent: "space-between",
337
+ alignItems: "center",
338
+ sx: {
339
+ mb: 0.75
340
+ },
341
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
342
+ variant: "rounded",
343
+ height: 14,
344
+ width: 150
345
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
346
+ variant: "rounded",
347
+ height: 14,
348
+ width: 50
349
+ })]
350
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
351
+ variant: "rounded",
352
+ height: 6,
353
+ width: "100%"
354
+ })]
355
+ });
356
+ }
357
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
358
+ sx: {
359
+ mb: 1.5
360
+ },
361
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
362
+ direction: "row",
363
+ justifyContent: "space-between",
364
+ alignItems: "center",
365
+ sx: {
366
+ mb: 0.75
367
+ },
368
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
369
+ sx: {
370
+ fontSize: 13,
371
+ fontWeight: 600,
372
+ color: isFailed ? "error.main" : "text.secondary",
373
+ display: "flex",
374
+ alignItems: "center"
375
+ },
376
+ children: [nameText, isCompleted && !isFailed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_Check.default, {
377
+ sx: {
378
+ color: "success.main",
379
+ ml: 0.5,
380
+ fontSize: 16
381
+ }
382
+ })]
383
+ }), !isCompleted && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
384
+ sx: {
385
+ fontSize: 12,
386
+ fontWeight: 600,
387
+ color: isFailed ? "error.main" : "text.secondary"
388
+ },
389
+ children: t("payment.checkout.vendor.progress", {
390
+ progress: isFailed ? 0 : displayProgress
391
+ })
392
+ })]
393
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.LinearProgress, {
394
+ variant: "determinate",
395
+ value: isFailed ? 100 : displayProgress || 0,
396
+ sx: {
397
+ height: 6,
398
+ borderRadius: 3,
399
+ bgcolor: theme => theme.palette.mode === "dark" ? "rgba(255,255,255,0.08)" : "grey.200",
400
+ "& .MuiLinearProgress-bar": {
401
+ borderRadius: 3,
402
+ // eslint-disable-next-line no-nested-ternary
403
+ bgcolor: isFailed ? "error.main" : isCompleted ? "success.main" : "primary.main",
404
+ transition: "background-color 0.3s linear"
405
+ }
406
+ }
407
+ })]
408
+ });
409
+ }
410
+ function VendorProgressPanel({
411
+ vendorStatus,
412
+ pageInfo = void 0,
413
+ locale,
414
+ t
415
+ }) {
416
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
417
+ sx: {
418
+ width: "100%",
419
+ maxWidth: 420,
420
+ p: 2.5,
421
+ borderRadius: 3,
422
+ bgcolor: theme => theme.palette.mode === "dark" ? "rgba(255,255,255,0.04)" : "grey.50",
423
+ border: "1px solid",
424
+ borderColor: "divider",
425
+ animation: `${fadeUp} 0.5s ease 0.3s both`
426
+ },
427
+ children: [vendorStatus.vendors.map((vendor, idx) => /* @__PURE__ */(0, _jsxRuntime.jsx)(VendorProgressItemV2, {
428
+ vendor,
429
+ t
430
+ }, vendor.title || `vendor-${idx}`)), vendorStatus.hasFailed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
431
+ sx: {
432
+ fontSize: 13,
433
+ fontWeight: 600,
434
+ color: "warning.main",
435
+ mt: 1
436
+ },
437
+ children: t("payment.checkout.vendor.failedMsg")
438
+ }), vendorStatus.isAllCompleted && pageInfo?.success_message?.[locale] && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
439
+ sx: {
440
+ fontSize: 14,
441
+ fontWeight: 600,
442
+ color: "text.primary",
443
+ mt: 1
444
+ },
445
+ children: pageInfo.success_message[locale]
446
+ })]
447
+ });
448
+ }
449
+ function SubscriptionLinks({
450
+ mode,
451
+ subscriptions,
452
+ subscriptionId = void 0,
453
+ payee,
454
+ prefix,
455
+ t
456
+ }) {
457
+ if (!["subscription", "setup"].includes(mode)) return null;
458
+ if (subscriptions.length > 1) {
459
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
460
+ sx: {
461
+ width: "100%",
462
+ maxWidth: 420,
463
+ borderRadius: 3,
464
+ bgcolor: theme => theme.palette.mode === "dark" ? "rgba(255,255,255,0.04)" : "grey.50",
465
+ border: "1px solid",
466
+ borderColor: "divider",
467
+ overflow: "hidden",
468
+ animation: `${fadeUp} 0.5s ease 0.35s both`
469
+ },
470
+ children: subscriptions.map((sub, idx) => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
471
+ children: [idx > 0 && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
472
+ direction: "row",
473
+ alignItems: "center",
474
+ justifyContent: "space-between",
475
+ sx: {
476
+ px: 2.5,
477
+ py: 1.5
478
+ },
479
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
480
+ sx: {
481
+ fontSize: 13,
482
+ fontWeight: 500,
483
+ color: "text.secondary",
484
+ flex: 1,
485
+ minWidth: 0
486
+ },
487
+ noWrap: true,
488
+ children: sub.description || sub.id
489
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
490
+ sx: {
491
+ flex: 1,
492
+ borderBottom: "1px dashed",
493
+ borderColor: "grey.300",
494
+ mx: 2,
495
+ minWidth: 20
496
+ }
497
+ }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Link, {
498
+ href: (0, _ufo.joinURL)(prefix, `/customer/subscription/${sub.id}`),
499
+ underline: "none",
500
+ sx: {
501
+ display: "flex",
502
+ alignItems: "center",
503
+ gap: 0.5,
504
+ fontSize: 13,
505
+ fontWeight: 600,
506
+ color: "primary.main",
507
+ flexShrink: 0
508
+ },
509
+ children: [t("payment.checkout.next.view"), /* @__PURE__ */(0, _jsxRuntime.jsx)(_OpenInNew.default, {
510
+ sx: {
511
+ fontSize: 14
512
+ }
513
+ })]
514
+ })]
515
+ })]
516
+ }, sub.id))
517
+ });
518
+ }
519
+ if (subscriptionId) {
520
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
521
+ variant: "contained",
522
+ href: (0, _ufo.joinURL)(prefix, `/customer/subscription/${subscriptionId}`),
523
+ endIcon: /* @__PURE__ */(0, _jsxRuntime.jsx)(_OpenInNew.default, {
524
+ sx: {
525
+ fontSize: 16
526
+ }
527
+ }),
528
+ sx: {
529
+ width: "100%",
530
+ maxWidth: 320,
531
+ height: 52,
532
+ borderRadius: "16px",
533
+ textTransform: "none",
534
+ fontWeight: 700,
535
+ fontSize: {
536
+ xs: 16,
537
+ md: 17
538
+ },
539
+ letterSpacing: "0.02em",
540
+ boxShadow: "0 8px 24px -4px rgba(59,130,246,0.25)",
541
+ "&:hover": {
542
+ boxShadow: "0 12px 28px -4px rgba(59,130,246,0.35)"
543
+ },
544
+ animation: `${fadeUp} 0.5s ease 0.35s both`
545
+ },
546
+ children: t("payment.checkout.next.subscription", {
547
+ payee
548
+ })
549
+ });
550
+ }
551
+ return null;
552
+ }
553
+ function InvoiceLink({
554
+ mode,
555
+ invoiceId = void 0,
556
+ prefix,
557
+ t
558
+ }) {
559
+ if (mode !== "payment" || !invoiceId) return null;
560
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
561
+ variant: "contained",
562
+ href: (0, _ufo.joinURL)(prefix, `/customer/invoice/${invoiceId}`),
563
+ endIcon: /* @__PURE__ */(0, _jsxRuntime.jsx)(_OpenInNew.default, {
564
+ sx: {
565
+ fontSize: 16
566
+ }
567
+ }),
568
+ sx: {
569
+ width: "100%",
570
+ maxWidth: 320,
571
+ height: 52,
572
+ borderRadius: "16px",
573
+ textTransform: "none",
574
+ fontWeight: 700,
575
+ fontSize: {
576
+ xs: 16,
577
+ md: 17
578
+ },
579
+ letterSpacing: "0.02em",
580
+ boxShadow: "0 8px 24px -4px rgba(59,130,246,0.25)",
581
+ "&:hover": {
582
+ boxShadow: "0 12px 28px -4px rgba(59,130,246,0.35)"
583
+ },
584
+ animation: `${fadeUp} 0.5s ease 0.35s both`
585
+ },
586
+ children: t("payment.checkout.next.invoice")
587
+ });
588
+ }
589
+ function SuccessView({
590
+ submit,
591
+ session
592
+ }) {
593
+ const {
594
+ t,
595
+ locale
596
+ } = (0, _context.useLocaleContext)();
597
+ const {
598
+ vendorStatus
599
+ } = submit;
600
+ const payee = getPayee(session);
601
+ const prefix = (0, _util.getPrefix)();
602
+ const mode = session?.mode || "payment";
603
+ const resultSession = submit.result?.checkoutSession;
604
+ const subscriptions = session?.subscriptions || [];
605
+ const subscriptionId = session?.subscription_id || resultSession?.subscription_id;
606
+ const invoiceId = session?.invoice_id || submit.result?.checkoutSession?.invoice_id || submit.result?.checkoutSession?.payment_intent?.invoice_id;
607
+ const pageInfo = session?.metadata?.page_info;
608
+ const customMessage = getCustomMessage(session);
609
+ const submitType = session?.submit_type;
610
+ const messageKey = submitType === "donate" ? "payment.checkout.completed.donate" : `payment.checkout.completed.${mode}`;
611
+ const headline = customMessage || t(messageKey);
612
+ const isVendorProcessing = vendorStatus && !vendorStatus.isAllCompleted && !vendorStatus.hasFailed;
613
+ const containerRef = (0, _react.useRef)(null);
614
+ const showConfetti = !vendorStatus?.hasFailed;
615
+ useConfetti(containerRef, showConfetti);
616
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
617
+ ref: containerRef,
618
+ sx: {
619
+ position: "relative",
620
+ display: "flex",
621
+ flexDirection: "column",
622
+ justifyContent: "center",
623
+ alignItems: "center",
624
+ flex: 1,
625
+ minHeight: 400,
626
+ p: {
627
+ xs: 3,
628
+ md: 4
629
+ },
630
+ textAlign: "center",
631
+ overflow: "hidden"
632
+ },
633
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
634
+ spacing: 3,
635
+ alignItems: "center",
636
+ sx: {
637
+ width: "100%",
638
+ maxWidth: 440
639
+ },
640
+ children: [vendorStatus?.hasFailed ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_ErrorOutline.default, {
641
+ sx: {
642
+ fontSize: 64,
643
+ color: "warning.main",
644
+ animation: `${scaleIn} 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both`
645
+ }
646
+ }) : /* @__PURE__ */(0, _jsxRuntime.jsx)(HeroSuccessIcon, {}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
647
+ spacing: 1,
648
+ alignItems: "center",
649
+ sx: {
650
+ animation: `${fadeUp} 0.5s ease 0.2s both`
651
+ },
652
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
653
+ sx: {
654
+ fontSize: {
655
+ xs: 28,
656
+ md: 36
657
+ },
658
+ fontWeight: 800,
659
+ color: "text.primary",
660
+ lineHeight: 1.2,
661
+ letterSpacing: "-0.02em"
662
+ },
663
+ children: headline
664
+ }), payee && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
665
+ sx: {
666
+ fontSize: {
667
+ xs: 14,
668
+ md: 16
669
+ },
670
+ color: "text.secondary",
671
+ fontWeight: 500,
672
+ lineHeight: 1.6,
673
+ maxWidth: 360
674
+ },
675
+ children: t("payment.checkout.completed.tip", {
676
+ payee
677
+ })
678
+ })]
679
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(PaymentReceipt, {
680
+ session: resultSession || session,
681
+ t
682
+ }), vendorStatus && /* @__PURE__ */(0, _jsxRuntime.jsx)(VendorProgressPanel, {
683
+ vendorStatus,
684
+ pageInfo,
685
+ locale,
686
+ t
687
+ }), vendorStatus?.hasFailed && vendorStatus.error && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
688
+ severity: "warning",
689
+ sx: {
690
+ maxWidth: 420,
691
+ borderRadius: 3,
692
+ width: "100%"
693
+ },
694
+ children: vendorStatus.error
695
+ }), !isVendorProcessing && /* @__PURE__ */(0, _jsxRuntime.jsx)(SubscriptionLinks, {
696
+ mode,
697
+ subscriptions,
698
+ subscriptionId,
699
+ payee,
700
+ prefix,
701
+ t
702
+ }), !isVendorProcessing && /* @__PURE__ */(0, _jsxRuntime.jsx)(InvoiceLink, {
703
+ mode,
704
+ invoiceId,
705
+ prefix,
706
+ t
707
+ }), !isVendorProcessing && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
708
+ variant: "text",
709
+ startIcon: /* @__PURE__ */(0, _jsxRuntime.jsx)(_ArrowBack.default, {
710
+ sx: {
711
+ fontSize: 16
712
+ }
713
+ }),
714
+ onClick: () => {
715
+ if (window.history.length > 1) {
716
+ window.history.back();
717
+ } else {
718
+ window.location.href = "/";
719
+ }
720
+ },
721
+ sx: {
722
+ textTransform: "none",
723
+ fontWeight: 600,
724
+ fontSize: 14,
725
+ color: "text.secondary",
726
+ "&:hover": {
727
+ bgcolor: "action.hover"
728
+ },
729
+ animation: `${fadeUp} 0.5s ease 0.45s both`
730
+ },
731
+ children: t("common.back")
732
+ })]
733
+ })
734
+ });
735
+ }