@blocklet/payment-react 1.18.0 → 1.18.2

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 (54) hide show
  1. package/es/checkout/donate.js +55 -10
  2. package/es/checkout/form.d.ts +2 -1
  3. package/es/checkout/form.js +32 -45
  4. package/es/components/payment-beneficiaries.d.ts +24 -0
  5. package/es/components/payment-beneficiaries.js +70 -0
  6. package/es/index.d.ts +2 -1
  7. package/es/index.js +3 -1
  8. package/es/locales/en.js +13 -1
  9. package/es/locales/zh.js +13 -1
  10. package/es/payment/donation-form.d.ts +24 -0
  11. package/es/payment/donation-form.js +604 -0
  12. package/es/payment/error.d.ts +1 -1
  13. package/es/payment/error.js +11 -1
  14. package/es/payment/form/index.d.ts +9 -3
  15. package/es/payment/form/index.js +60 -12
  16. package/es/payment/product-donation.js +101 -56
  17. package/es/payment/skeleton/donation.d.ts +1 -0
  18. package/es/payment/skeleton/donation.js +30 -0
  19. package/es/theme/index.js +13 -0
  20. package/es/types/index.d.ts +2 -0
  21. package/lib/checkout/donate.js +85 -10
  22. package/lib/checkout/form.d.ts +2 -1
  23. package/lib/checkout/form.js +39 -49
  24. package/lib/components/payment-beneficiaries.d.ts +24 -0
  25. package/lib/components/payment-beneficiaries.js +113 -0
  26. package/lib/index.d.ts +2 -1
  27. package/lib/index.js +8 -0
  28. package/lib/locales/en.js +13 -1
  29. package/lib/locales/zh.js +13 -1
  30. package/lib/payment/donation-form.d.ts +24 -0
  31. package/lib/payment/donation-form.js +645 -0
  32. package/lib/payment/error.d.ts +1 -1
  33. package/lib/payment/error.js +2 -2
  34. package/lib/payment/form/index.d.ts +9 -3
  35. package/lib/payment/form/index.js +60 -8
  36. package/lib/payment/product-donation.js +143 -72
  37. package/lib/payment/skeleton/donation.d.ts +1 -0
  38. package/lib/payment/skeleton/donation.js +66 -0
  39. package/lib/theme/index.js +13 -0
  40. package/lib/types/index.d.ts +2 -0
  41. package/package.json +3 -3
  42. package/src/checkout/donate.tsx +64 -11
  43. package/src/checkout/form.tsx +17 -31
  44. package/src/components/payment-beneficiaries.tsx +97 -0
  45. package/src/index.ts +2 -0
  46. package/src/locales/en.tsx +12 -0
  47. package/src/locales/zh.tsx +12 -0
  48. package/src/payment/donation-form.tsx +647 -0
  49. package/src/payment/error.tsx +13 -4
  50. package/src/payment/form/index.tsx +66 -11
  51. package/src/payment/product-donation.tsx +94 -39
  52. package/src/payment/skeleton/donation.tsx +35 -0
  53. package/src/theme/index.tsx +13 -0
  54. package/src/types/index.ts +2 -0
@@ -2,8 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import "react-international-phone/style.css";
3
3
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
4
4
  import Toast from "@arcblock/ux/lib/Toast";
5
- import { LoadingButton } from "@mui/lab";
6
- import { Box, Divider, Fade, FormLabel, Stack, Typography } from "@mui/material";
5
+ import { Box, Button, CircularProgress, Divider, Fade, FormLabel, Stack, Typography } from "@mui/material";
7
6
  import { useMemoizedFn, useSetState } from "ahooks";
8
7
  import pWaitFor from "p-wait-for";
9
8
  import { useEffect, useMemo, useRef, useState } from "react";
@@ -31,7 +30,7 @@ import PhoneInput from "./phone.js";
31
30
  import StripeCheckout from "./stripe/index.js";
32
31
  import { useMobile } from "../../hooks/mobile.js";
33
32
  import { validatePhoneNumber } from "../../libs/phone-validator.js";
34
- const waitForCheckoutComplete = async (sessionId) => {
33
+ export const waitForCheckoutComplete = async (sessionId) => {
35
34
  let result;
36
35
  await pWaitFor(
37
36
  async () => {
@@ -49,11 +48,13 @@ const waitForCheckoutComplete = async (sessionId) => {
49
48
  );
50
49
  return result;
51
50
  };
52
- const hasDidWallet = (user) => {
51
+ export const hasDidWallet = (user) => {
53
52
  const connected = user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
54
53
  return connected.some((x) => x.provider === "wallet");
55
54
  };
56
- PaymentForm.defaultProps = {};
55
+ PaymentForm.defaultProps = {
56
+ onlyShowBtn: false
57
+ };
57
58
  export default function PaymentForm({
58
59
  checkoutSession,
59
60
  paymentMethods,
@@ -64,7 +65,8 @@ export default function PaymentForm({
64
65
  onError,
65
66
  // mode,
66
67
  action,
67
- currencyId
68
+ currencyId,
69
+ onlyShowBtn
68
70
  }) {
69
71
  const { t } = useLocaleContext();
70
72
  const { isMobile } = useMobile();
@@ -316,6 +318,45 @@ export default function PaymentForm({
316
318
  const onStripeCancel = () => {
317
319
  setState({ stripePaying: false });
318
320
  };
321
+ if (onlyShowBtn) {
322
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
323
+ /* @__PURE__ */ jsx(Box, { className: "cko-payment-submit-btn", children: /* @__PURE__ */ jsxs(
324
+ Button,
325
+ {
326
+ variant: "contained",
327
+ color: "primary",
328
+ size: "large",
329
+ className: "cko-submit-button",
330
+ onClick: () => {
331
+ if (state.submitting || state.paying) {
332
+ return;
333
+ }
334
+ onAction();
335
+ },
336
+ fullWidth: true,
337
+ disabled: state.stripePaying || !quantityInventoryStatus || !payable,
338
+ children: [
339
+ (state.submitting || state.paying) && /* @__PURE__ */ jsx(CircularProgress, { size: 16, sx: { mr: 0.5, color: "var(--foregrounds-fg-on-color, #fff)" } }),
340
+ state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
341
+ ]
342
+ }
343
+ ) }),
344
+ state.customerLimited && /* @__PURE__ */ jsx(
345
+ ConfirmDialog,
346
+ {
347
+ onConfirm: () => window.open(
348
+ joinURL(getPrefix(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`),
349
+ "_self"
350
+ ),
351
+ onCancel: () => setState({ customerLimited: false }),
352
+ confirm: t("payment.customer.pastDue.alert.confirm"),
353
+ title: t("payment.customer.pastDue.alert.title"),
354
+ message: t("payment.customer.pastDue.alert.description"),
355
+ color: "primary"
356
+ }
357
+ )
358
+ ] });
359
+ }
319
360
  return /* @__PURE__ */ jsxs(Fragment, { children: [
320
361
  /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-payment-contact", children: [
321
362
  /* @__PURE__ */ jsx(
@@ -433,18 +474,25 @@ export default function PaymentForm({
433
474
  ] }) }),
434
475
  /* @__PURE__ */ jsx(Divider, { sx: { mt: 2.5, mb: 2.5 } }),
435
476
  /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-payment-submit", children: [
436
- /* @__PURE__ */ jsx(Box, { className: "cko-payment-submit-btn", children: /* @__PURE__ */ jsx(
437
- LoadingButton,
477
+ /* @__PURE__ */ jsx(Box, { className: "cko-payment-submit-btn", children: /* @__PURE__ */ jsxs(
478
+ Button,
438
479
  {
439
480
  variant: "contained",
440
481
  color: "primary",
441
482
  size: "large",
442
483
  className: "cko-submit-button",
443
- onClick: onAction,
484
+ onClick: () => {
485
+ if (state.submitting || state.paying) {
486
+ return;
487
+ }
488
+ onAction();
489
+ },
444
490
  fullWidth: true,
445
- disabled: state.submitting || state.paying || state.stripePaying || !quantityInventoryStatus || !payable,
446
- loading: state.submitting || state.paying,
447
- children: state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
491
+ disabled: state.stripePaying || !quantityInventoryStatus || !payable,
492
+ children: [
493
+ (state.submitting || state.paying) && /* @__PURE__ */ jsx(CircularProgress, { size: 16, sx: { mr: 0.5, color: "var(--foregrounds-fg-on-color, #fff)" } }),
494
+ state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
495
+ ]
448
496
  }
449
497
  ) }),
450
498
  ["subscription", "setup"].includes(checkoutSession.mode) && /* @__PURE__ */ jsx(Typography, { sx: { mt: 2.5, color: "text.lighter", fontSize: "0.9rem", lineHeight: "1.1rem" }, children: t("payment.checkout.confirm", { payee }) })
@@ -1,9 +1,8 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
- import { Box, Card, CardActionArea, FormControlLabel, Stack, TextField, Typography } from "@mui/material";
3
+ import { Avatar, Box, Card, CardActionArea, Grid, Stack, TextField, Typography } from "@mui/material";
4
4
  import { useSetState } from "ahooks";
5
- import { useEffect } from "react";
6
- import Switch from "../components/switch-button.js";
5
+ import { useEffect, useRef } from "react";
7
6
  import { formatAmountPrecisionLimit } from "../libs/util.js";
8
7
  import { usePaymentContext } from "../contexts/payment.js";
9
8
  import { usePreventWheel } from "../hooks/scroll.js";
@@ -16,13 +15,17 @@ export default function ProductDonation({
16
15
  const { t, locale } = useLocaleContext();
17
16
  const { setPayable } = usePaymentContext();
18
17
  usePreventWheel();
19
- const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
18
+ const presets = settings?.amount?.presets || [];
19
+ const preset = settings?.amount?.preset || presets?.[0] || "0";
20
+ const supportPreset = presets.length > 0;
21
+ const supportCustom = !!settings?.amount?.custom;
20
22
  const [state, setState] = useSetState({
21
23
  selected: preset,
22
24
  input: "",
23
- custom: settings.amount.presets?.length === 0,
25
+ custom: !supportPreset,
24
26
  error: ""
25
27
  });
28
+ const customInputRef = useRef(null);
26
29
  useEffect(() => {
27
30
  if (settings.amount.preset) {
28
31
  setState({ selected: settings.amount.preset, custom: false });
@@ -32,7 +35,15 @@ export default function ProductDonation({
32
35
  onChange({ priceId: item.price_id, amount: settings.amount.presets[0] });
33
36
  }
34
37
  }, [settings.amount.preset, settings.amount.presets]);
38
+ useEffect(() => {
39
+ if (state.custom) {
40
+ setTimeout(() => {
41
+ customInputRef.current?.focus();
42
+ }, 0);
43
+ }
44
+ }, [state.custom]);
35
45
  const handleSelect = (amount) => {
46
+ setPayable(true);
36
47
  setState({ selected: amount, custom: false, error: "" });
37
48
  onChange({ priceId: item.price_id, amount });
38
49
  };
@@ -55,71 +66,105 @@ export default function ProductDonation({
55
66
  setState({ error: "", input: value });
56
67
  onChange({ priceId: item.price_id, amount: value });
57
68
  };
58
- const handleToggle = (event) => {
59
- if (event.target.checked) {
60
- setState({ custom: true, input: state.selected, error: "" });
61
- } else {
62
- setPayable(true);
63
- handleSelect(preset);
69
+ const handleCustomSelect = () => {
70
+ setState({ custom: true, error: "" });
71
+ if (!state.input) {
72
+ setPayable(false);
64
73
  }
65
74
  };
66
75
  return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 1.5, children: [
67
- settings.amount.custom && preset !== "0" && /* @__PURE__ */ jsx(
68
- FormControlLabel,
69
- {
70
- control: /* @__PURE__ */ jsx(Switch, { checked: state.custom, sx: { marginRight: 0.4 }, onChange: handleToggle }),
71
- label: state.custom ? t("payment.checkout.donation.select") : t("payment.checkout.donation.custom"),
72
- sx: { marginRight: 2, marginLeft: 0.5, color: "text.lighter" }
73
- }
74
- ),
75
- !state.custom && /* @__PURE__ */ jsx(Box, { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 1.5, children: settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map((amount) => /* @__PURE__ */ jsx(
76
- Card,
77
- {
78
- variant: "outlined",
79
- sx: {
80
- minWidth: 115,
81
- textAlign: "center",
82
- ...state.selected === amount && !state.custom ? { borderColor: "primary.main" } : {}
76
+ supportPreset && /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, children: [
77
+ settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map((amount) => /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, sm: 3, children: /* @__PURE__ */ jsx(
78
+ Card,
79
+ {
80
+ variant: "outlined",
81
+ sx: {
82
+ minWidth: 115,
83
+ textAlign: "center",
84
+ transition: "all 0.3s",
85
+ cursor: "pointer",
86
+ "&:hover": {
87
+ transform: "translateY(-4px)",
88
+ boxShadow: 3
89
+ },
90
+ height: "42px",
91
+ ...state.selected === amount && !state.custom ? { borderColor: "primary.main", borderWidth: 1 } : {}
92
+ },
93
+ children: /* @__PURE__ */ jsx(CardActionArea, { onClick: () => handleSelect(amount), children: /* @__PURE__ */ jsxs(
94
+ Stack,
95
+ {
96
+ direction: "row",
97
+ sx: { py: 1.5, px: 1.5 },
98
+ spacing: 0.5,
99
+ alignItems: "center",
100
+ justifyContent: "center",
101
+ children: [
102
+ /* @__PURE__ */ jsx(Avatar, { src: currency?.logo, sx: { width: 16, height: 16, mr: 0.5 }, alt: currency?.symbol }),
103
+ /* @__PURE__ */ jsx(
104
+ Typography,
105
+ {
106
+ component: "strong",
107
+ lineHeight: 1,
108
+ variant: "h3",
109
+ sx: { fontVariantNumeric: "tabular-nums", fontWeight: 400 },
110
+ children: amount
111
+ }
112
+ ),
113
+ /* @__PURE__ */ jsx(Typography, { lineHeight: 1, fontSize: 14, color: "text.secondary", children: currency?.symbol })
114
+ ]
115
+ }
116
+ ) })
83
117
  },
84
- children: /* @__PURE__ */ jsx(CardActionArea, { onClick: () => handleSelect(amount), children: /* @__PURE__ */ jsxs(
85
- Stack,
86
- {
87
- direction: "row",
88
- sx: { py: 1, px: 0.5 },
89
- spacing: 0.5,
90
- alignItems: "flex-end",
91
- justifyContent: "center",
92
- children: [
93
- /* @__PURE__ */ jsx(
94
- Typography,
95
- {
96
- component: "strong",
97
- lineHeight: 1,
98
- variant: "h3",
99
- sx: { fontVariantNumeric: "tabular-nums", fontWeight: 400 },
100
- children: amount
101
- }
102
- ),
103
- /* @__PURE__ */ jsx(Typography, { component: "small", lineHeight: 1, fontSize: 12, children: "ABT" }),
104
- " "
105
- ]
106
- }
107
- ) })
108
- },
109
- amount
110
- )) }),
118
+ amount
119
+ ) }, amount)),
120
+ supportCustom && /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, sm: 3, children: /* @__PURE__ */ jsx(
121
+ Card,
122
+ {
123
+ variant: "outlined",
124
+ sx: {
125
+ textAlign: "center",
126
+ transition: "all 0.3s",
127
+ cursor: "pointer",
128
+ "&:hover": {
129
+ transform: "translateY(-4px)",
130
+ boxShadow: 3
131
+ },
132
+ height: "42px",
133
+ ...state.custom ? { borderColor: "primary.main", borderWidth: 1 } : {}
134
+ },
135
+ children: /* @__PURE__ */ jsx(CardActionArea, { onClick: () => handleCustomSelect(), children: /* @__PURE__ */ jsx(
136
+ Stack,
137
+ {
138
+ direction: "row",
139
+ sx: { py: 1.5, px: 1.5 },
140
+ spacing: 0.5,
141
+ alignItems: "center",
142
+ justifyContent: "center",
143
+ children: /* @__PURE__ */ jsx(Typography, { variant: "h3", lineHeight: 1, sx: { fontWeight: 400 }, children: t("common.custom") })
144
+ }
145
+ ) })
146
+ },
147
+ "custom"
148
+ ) }, "custom")
149
+ ] }),
111
150
  state.custom && /* @__PURE__ */ jsx(
112
151
  TextField,
113
152
  {
114
- label: preset !== "0" ? null : t("payment.checkout.donation.custom"),
115
153
  type: "number",
116
154
  value: state.input,
117
155
  onChange: handleInput,
118
- inputProps: { min: settings.amount.minimum, max: settings.amount.maximum },
119
156
  margin: "none",
120
157
  fullWidth: true,
121
158
  error: !!state.error,
122
159
  helperText: state.error,
160
+ inputRef: customInputRef,
161
+ InputProps: {
162
+ endAdornment: /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 0.5, alignItems: "center", sx: { ml: 1 }, children: [
163
+ /* @__PURE__ */ jsx(Avatar, { src: currency?.logo, sx: { width: 16, height: 16 }, alt: currency?.symbol }),
164
+ /* @__PURE__ */ jsx(Typography, { children: currency?.symbol })
165
+ ] }),
166
+ autoComplete: "off"
167
+ },
123
168
  sx: {
124
169
  mt: preset !== "0" ? 0 : 1
125
170
  }
@@ -0,0 +1 @@
1
+ export default function DonationSkeleton(): import("react").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Box, Divider, Fade, Skeleton, Stack } from "@mui/material";
3
+ export default function DonationSkeleton() {
4
+ return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", children: [
5
+ /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "2rem", width: "40%" } }),
6
+ /* @__PURE__ */ jsx(Skeleton, { sx: { mt: 2 }, variant: "rounded", height: 80 }),
7
+ /* @__PURE__ */ jsx(
8
+ Divider,
9
+ {
10
+ sx: {
11
+ mt: {
12
+ xs: "16px",
13
+ md: "16px"
14
+ },
15
+ mb: {
16
+ xs: "16px",
17
+ md: "16px"
18
+ }
19
+ }
20
+ }
21
+ ),
22
+ /* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", spacing: 2, children: [
23
+ /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "1.5rem", width: "40%" } }),
24
+ /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", gap: 2, children: [
25
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Skeleton, { height: 60, width: 80 }) }),
26
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Skeleton, { height: 60, width: 120 }) })
27
+ ] })
28
+ ] })
29
+ ] }) });
30
+ }
package/es/theme/index.js CHANGED
@@ -37,6 +37,9 @@ export function PaymentThemeProvider({
37
37
  fontSize: "14px",
38
38
  minHeight: "1.65em",
39
39
  lineHeight: "1.65em"
40
+ },
41
+ "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
42
+ borderWidth: "1px"
40
43
  }
41
44
  }
42
45
  }
@@ -111,6 +114,9 @@ export function PaymentThemeProvider({
111
114
  },
112
115
  MuiPopover: {
113
116
  styleOverrides: {
117
+ root: {
118
+ zIndex: 1200
119
+ },
114
120
  paper: ({ theme }) => ({
115
121
  border: `1px solid ${theme.palette.divider}`,
116
122
  boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)"
@@ -228,6 +234,13 @@ export function PaymentThemeProvider({
228
234
  }
229
235
  }
230
236
  }
237
+ },
238
+ MuiDialog: {
239
+ styleOverrides: {
240
+ root: {
241
+ zIndex: 1200
242
+ }
243
+ }
231
244
  }
232
245
  }
233
246
  };
@@ -36,6 +36,8 @@ export type CheckoutProps = Partial<CheckoutCallbacks> & {
36
36
  action?: string;
37
37
  mode?: LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal', string>;
38
38
  theme?: 'default' | 'inherit' | PaymentThemeOptions;
39
+ formType?: 'donation' | 'payment';
40
+ formRender?: Record<string, any>;
39
41
  };
40
42
  export type CheckoutCallbacks = {
41
43
  onPaid: (res: CheckoutContext) => void;
@@ -18,6 +18,8 @@ var _util = require("../libs/util");
18
18
  var _form = _interopRequireDefault(require("./form"));
19
19
  var _theme = require("../theme");
20
20
  var _payment = require("../contexts/payment");
21
+ var _livemode = _interopRequireDefault(require("../components/livemode"));
22
+ var _mobile = require("../hooks/mobile");
21
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
24
  const donationCache = {};
23
25
  const createOrUpdateDonation = (settings, livemode = true) => {
@@ -308,8 +310,18 @@ function CheckoutDonateInner({
308
310
  donation,
309
311
  supporters
310
312
  } = useDonation(settings, livemode, mode);
313
+ const customers = (0, _unionBy.default)(supporters?.data?.supporters || [], "customer_did");
314
+ const {
315
+ t
316
+ } = (0, _context.useLocaleContext)();
311
317
  const [anchorEl, setAnchorEl] = (0, _react.useState)(null);
312
318
  const [popoverOpen, setPopoverOpen] = (0, _react.useState)(false);
319
+ const {
320
+ isMobile
321
+ } = (0, _mobile.useMobile)();
322
+ const {
323
+ connect
324
+ } = (0, _payment.usePaymentContext)();
313
325
  const handlePaid = (...args) => {
314
326
  if (onPaid) {
315
327
  onPaid(...args);
@@ -467,21 +479,64 @@ function CheckoutDonateInner({
467
479
  return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
468
480
  children: [renderInnerView(), donation.data && /* @__PURE__ */(0, _jsxRuntime.jsx)(_Dialog.default, {
469
481
  open: state.open,
470
- title: settings.title,
482
+ title: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
483
+ display: "flex",
484
+ alignItems: "center",
485
+ gap: 0.5,
486
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
487
+ variant: "h3",
488
+ sx: {
489
+ maxWidth: 320,
490
+ textOverflow: "ellipsis",
491
+ overflow: "hidden"
492
+ },
493
+ children: settings.title
494
+ }), !donation.data.livemode && /* @__PURE__ */(0, _jsxRuntime.jsx)(_livemode.default, {
495
+ sx: {
496
+ width: "fit-content"
497
+ }
498
+ })]
499
+ }),
471
500
  maxWidth: "md",
472
- showCloseButton: true,
501
+ toolbar: isMobile ? null : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
502
+ display: "flex",
503
+ alignItems: "center",
504
+ gap: 1,
505
+ sx: {
506
+ color: "text.secondary"
507
+ },
508
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.AvatarGroup, {
509
+ total: customers?.length,
510
+ max: 5,
511
+ children: customers.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
512
+ title: x.customer?.name,
513
+ src: (0, _util.getCustomerAvatar)(x.customer?.did, x?.updated_at ? new Date(x.updated_at).toISOString() : "", 18),
514
+ variant: "circular",
515
+ sx: {
516
+ width: 18,
517
+ height: 18
518
+ }
519
+ }, x.id))
520
+ }), customers?.length > 0 && t("payment.checkout.donation.gaveTips", {
521
+ count: customers?.length
522
+ })]
523
+ }),
524
+ showCloseButton: false,
473
525
  disableEscapeKeyDown: true,
474
526
  sx: {
475
527
  ".MuiDialogContent-root": {
476
- padding: {
477
- xs: 0,
478
- md: "0 16px 0"
479
- },
528
+ padding: "16px 24px",
480
529
  borderTop: "1px solid var(--stroke-border-base, #EFF1F5)",
481
- width: {
482
- xs: "100%",
483
- md: 900
484
- }
530
+ width: "100%"
531
+ },
532
+ ".ux-dialog_header": {
533
+ gap: 5
534
+ }
535
+ },
536
+ PaperProps: {
537
+ style: {
538
+ minHeight: "auto",
539
+ width: 680
485
540
  }
486
541
  },
487
542
  onClose: (e, reason) => setState({
@@ -499,8 +554,28 @@ function CheckoutDonateInner({
499
554
  action: settings.appearance?.button?.text,
500
555
  mode: "inline",
501
556
  theme,
557
+ formType: "donation",
502
558
  extraParams: {
503
559
  livemode
560
+ },
561
+ formRender: {
562
+ cancel: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
563
+ variant: "outlined",
564
+ size: "large",
565
+ onClick: () => {
566
+ connect.close();
567
+ setState({
568
+ open: false
569
+ });
570
+ },
571
+ children: t("common.cancel")
572
+ }),
573
+ onCancel: () => {
574
+ connect.close();
575
+ setState({
576
+ open: false
577
+ });
578
+ }
504
579
  }
505
580
  })
506
581
  })
@@ -1,5 +1,5 @@
1
1
  import type { CheckoutProps } from '../types';
2
- declare function CheckoutForm({ id, mode, onPaid, onError, onChange, goBack, extraParams, action, theme, ...restProps }: CheckoutProps): import("react").JSX.Element;
2
+ declare function CheckoutForm({ id, mode, onPaid, onError, onChange, goBack, extraParams, action, theme, formType, ...restProps }: CheckoutProps): import("react").JSX.Element;
3
3
  declare namespace CheckoutForm {
4
4
  var defaultProps: {
5
5
  onPaid: any;
@@ -10,6 +10,7 @@ declare namespace CheckoutForm {
10
10
  mode: string;
11
11
  action: string;
12
12
  extraParams: {};
13
+ formType: string;
13
14
  };
14
15
  }
15
16
  export default CheckoutForm;
@@ -13,6 +13,7 @@ var _api = _interopRequireDefault(require("../libs/api"));
13
13
  var _util = require("../libs/util");
14
14
  var _payment = _interopRequireDefault(require("../payment"));
15
15
  var _theme = require("../theme");
16
+ var _donationForm = _interopRequireDefault(require("../payment/donation-form"));
16
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18
  const promises = {};
18
19
  const startFromPaymentLink = (id, params) => {
@@ -41,6 +42,7 @@ function CheckoutForm({
41
42
  extraParams,
42
43
  action,
43
44
  theme = "default",
45
+ formType = "payment",
44
46
  ...restProps
45
47
  }) {
46
48
  if (!id.startsWith("plink_") && !id.startsWith("cs_")) {
@@ -73,62 +75,49 @@ function CheckoutForm({
73
75
  });
74
76
  onError?.(err);
75
77
  };
78
+ const Checkout = formType === "donation" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_donationForm.default, {
79
+ checkoutSession: data?.checkoutSession,
80
+ paymentMethods: data?.paymentMethods,
81
+ paymentIntent: data?.paymentIntent,
82
+ paymentLink: data?.paymentLink,
83
+ customer: data?.customer,
84
+ completed: state.completed,
85
+ error: apiError,
86
+ onPaid: handlePaid,
87
+ onError: handleError,
88
+ onChange,
89
+ goBack,
90
+ mode,
91
+ action,
92
+ id,
93
+ ...restProps
94
+ }) : /* @__PURE__ */(0, _jsxRuntime.jsx)(_payment.default, {
95
+ checkoutSession: data?.checkoutSession,
96
+ paymentMethods: data?.paymentMethods,
97
+ paymentIntent: data?.paymentIntent,
98
+ paymentLink: data?.paymentLink,
99
+ customer: data?.customer,
100
+ completed: state.completed,
101
+ error: apiError,
102
+ onPaid: handlePaid,
103
+ onError: handleError,
104
+ onChange,
105
+ goBack,
106
+ mode,
107
+ action,
108
+ ...restProps
109
+ });
76
110
  if (theme === "inherit") {
77
- return /* @__PURE__ */(0, _jsxRuntime.jsx)(_payment.default, {
78
- checkoutSession: data?.checkoutSession,
79
- paymentMethods: data?.paymentMethods,
80
- paymentIntent: data?.paymentIntent,
81
- paymentLink: data?.paymentLink,
82
- customer: data?.customer,
83
- completed: state.completed,
84
- error: apiError,
85
- onPaid: handlePaid,
86
- onError: handleError,
87
- onChange,
88
- goBack,
89
- mode,
90
- action,
91
- ...restProps
92
- });
111
+ return Checkout;
93
112
  }
94
113
  if (theme && typeof theme === "object") {
95
114
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_theme.PaymentThemeProvider, {
96
115
  theme,
97
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_payment.default, {
98
- checkoutSession: data?.checkoutSession,
99
- paymentMethods: data?.paymentMethods,
100
- paymentIntent: data?.paymentIntent,
101
- paymentLink: data?.paymentLink,
102
- customer: data?.customer,
103
- completed: state.completed,
104
- error: apiError,
105
- onPaid: handlePaid,
106
- onError: handleError,
107
- onChange,
108
- goBack,
109
- mode,
110
- action,
111
- ...restProps
112
- })
116
+ children: Checkout
113
117
  });
114
118
  }
115
119
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_theme.PaymentThemeProvider, {
116
- children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_payment.default, {
117
- checkoutSession: data?.checkoutSession,
118
- paymentMethods: data?.paymentMethods,
119
- paymentIntent: data?.paymentIntent,
120
- paymentLink: data?.paymentLink,
121
- customer: data?.customer,
122
- completed: state.completed,
123
- error: apiError,
124
- onPaid: handlePaid,
125
- onError: handleError,
126
- onChange,
127
- goBack,
128
- mode,
129
- action,
130
- ...restProps
131
- })
120
+ children: Checkout
132
121
  });
133
122
  }
134
123
  CheckoutForm.defaultProps = {
@@ -136,5 +125,6 @@ CheckoutForm.defaultProps = {
136
125
  onError: console.error,
137
126
  mode: "inline",
138
127
  action: "",
139
- extraParams: {}
128
+ extraParams: {},
129
+ formType: "payment"
140
130
  };