@blocklet/payment-react 1.18.15 → 1.18.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/locales/zh.js CHANGED
@@ -237,12 +237,13 @@ export default flat({
237
237
  pastDue: {
238
238
  button: "\u7EED\u8D39",
239
239
  invoices: "\u6B20\u8D39\u5E10\u5355",
240
- warning: "\u8BF7\u5C3D\u5FEB\u652F\u4ED8\u6B20\u8D39\u8D26\u5355\uFF0C\u5426\u5219\u4F60\u5C06\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528\u670D\u52A1\u6216\u8D2D\u4E70\u65B0\u670D\u52A1\uFF0C\u8BF7\u9010\u4E2A\u6253\u5F00\u8D26\u5355\u8BE6\u60C5\u5E76\u5B8C\u6210\u652F\u4ED8",
240
+ warning: "\u8BF7\u5C3D\u5FEB\u652F\u4ED8\u6B20\u8D39\u8D26\u5355\uFF0C\u5426\u5219\u4F60\u5C06\u65E0\u6CD5\u7EE7\u7EED\u4F7F\u7528\u670D\u52A1\u6216\u8D2D\u4E70\u65B0\u670D\u52A1\u3002",
241
241
  alert: {
242
242
  title: "\u4F60\u6709\u6B20\u8D39\u8D26\u5355",
243
243
  description: "\u770B\u8D77\u6765\u4F60\u6709\u6B20\u8D39\u7684\u8D26\u5355\uFF0C\u5728\u4F60\u652F\u4ED8\u6240\u6709\u6B20\u8D39\u8D26\u5355\u4E4B\u524D\uFF0C\u65B0\u7684\u8D2D\u4E70\u6216\u8005\u8BA2\u9605\u5C06\u88AB\u7981\u6B62\uFF0C\u8BF7\u4E0D\u8981\u8C03\u76AE\u3002",
244
244
  confirm: "\u53BB\u652F\u4ED8"
245
- }
245
+ },
246
+ view: "\u67E5\u770B\u6B20\u8D39\u660E\u7EC6"
246
247
  },
247
248
  recover: {
248
249
  button: "\u6062\u590D\u8BA2\u9605",
@@ -291,7 +292,8 @@ export default flat({
291
292
  empty: "\u6CA1\u6709\u4EFB\u4F55\u8D26\u5355",
292
293
  next: "\u8FD8\u6CA1\u6709\u8D26\u5355\uFF0C\u4E0B\u6B21\u8D26\u5355\u5C06\u5728 {date} \u751F\u6210",
293
294
  invoiceNumber: "\u8D26\u5355\u7F16\u53F7",
294
- emptyList: "\u6CA1\u6709\u8D26\u5355"
295
+ emptyList: "\u6CA1\u6709\u8D26\u5355",
296
+ noPaymentRequired: "\u65E0\u9700\u652F\u4ED8"
295
297
  },
296
298
  payment: {
297
299
  empty: "\u6CA1\u6709\u652F\u4ED8\u8BB0\u5F55",
@@ -312,6 +314,11 @@ export default flat({
312
314
  changePayment: "\u5207\u6362\u652F\u4ED8\u65B9\u5F0F",
313
315
  trialLeft: "\u5269\u4F59\u8BD5\u7528\u65F6\u957F",
314
316
  owner: "\u8BA2\u9605\u62E5\u6709\u8005"
317
+ },
318
+ overdue: {
319
+ title: "\u60A8\u6709 {count} \u5F20\u6B20\u8D39\u8D26\u5355\uFF0C\u6D89\u53CA {subscriptionCount} \u4E2A\u8BA2\u9605\uFF0C\u603B\u91D1\u989D {total} {symbol}\u3002\u8BF7\u7ACB\u5373\u652F\u4ED8\uFF0C\u4EE5\u514D\u5F71\u54CD\u60A8\u7684\u4F7F\u7528\u3002",
320
+ simpleTitle: "\u60A8\u6709 {count} \u5F20\u6B20\u8D39\u8D26\u5355\uFF0C\u8BF7\u7ACB\u5373\u652F\u4ED8\uFF0C\u4EE5\u514D\u5F71\u54CD\u60A8\u7684\u4F7F\u7528\u3002",
321
+ empty: "\u606D\u559C\uFF01\u60A8\u5F53\u524D\u6CA1\u6709\u6B20\u8D39\u8D26\u5355\u3002"
315
322
  }
316
323
  },
317
324
  invoice: {
@@ -351,7 +358,9 @@ export default flat({
351
358
  viewNow: "\u7ACB\u5373\u67E5\u770B",
352
359
  description: "\u5982\u679C\u60A8\u6709\u4EFB\u4F55\u7591\u95EE\uFF0C\u53EF\u4EE5\u9009\u62E9 ",
353
360
  list: "\u6B20\u8D39\u8D26\u5355\uFF1A",
354
- empty: "\u60A8\u7684\u3010{name}\u3011\u8BA2\u9605\u5F53\u524D\u6CA1\u6709\u6B20\u8D39\u8D26\u5355"
361
+ empty: "\u60A8\u7684\u3010{name}\u3011\u8BA2\u9605\u5F53\u524D\u6CA1\u6709\u6B20\u8D39\u8D26\u5355",
362
+ retry: "\u91CD\u65B0\u652F\u4ED8",
363
+ paid: "\u5DF2\u652F\u4ED8"
355
364
  }
356
365
  }
357
366
  },
@@ -11,74 +11,72 @@ export default function AddressForm({ mode, stripe, sx = {} }) {
11
11
  const { t } = useLocaleContext();
12
12
  const { control } = useFormContext();
13
13
  if (mode === "required") {
14
- return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-payment-address cko-payment-form", sx, children: [
15
- /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t(`payment.checkout.billing.${mode}`) }),
16
- /* @__PURE__ */ jsxs(Stack, { direction: "column", className: "cko-payment-form", spacing: 0, children: [
17
- /* @__PURE__ */ jsx(Stack, { direction: "row", spacing: 0, children: /* @__PURE__ */ jsx(
18
- FormInput,
19
- {
20
- name: "billing_address.postal_code",
21
- rules: { required: t("payment.checkout.required") },
22
- errorPosition: "right",
23
- variant: "outlined",
24
- placeholder: t("payment.checkout.billing.postal_code"),
25
- InputProps: {
26
- startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", style: { marginRight: "2px", marginLeft: "-8px" }, children: /* @__PURE__ */ jsx(
27
- Controller,
28
- {
29
- name: "billing_address.country",
30
- control,
31
- render: ({ field }) => /* @__PURE__ */ jsx(
32
- CountrySelect,
33
- {
34
- ...field,
35
- sx: {
36
- "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
37
- borderColor: "transparent"
38
- }
14
+ return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsx(Stack, { className: "cko-payment-address cko-payment-form", sx, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", className: "cko-payment-form", spacing: 0, children: [
15
+ /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.line1") }),
16
+ /* @__PURE__ */ jsx(
17
+ FormInput,
18
+ {
19
+ name: "billing_address.line1",
20
+ rules: { required: t("payment.checkout.required") },
21
+ errorPosition: "right",
22
+ variant: "outlined",
23
+ placeholder: t("payment.checkout.billing.line1")
24
+ }
25
+ ),
26
+ /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.city") }),
27
+ /* @__PURE__ */ jsx(
28
+ FormInput,
29
+ {
30
+ name: "billing_address.city",
31
+ rules: { required: t("payment.checkout.required") },
32
+ errorPosition: "right",
33
+ variant: "outlined",
34
+ placeholder: t("payment.checkout.billing.city")
35
+ }
36
+ ),
37
+ /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.state") }),
38
+ /* @__PURE__ */ jsx(
39
+ FormInput,
40
+ {
41
+ name: "billing_address.state",
42
+ rules: { required: t("payment.checkout.required") },
43
+ errorPosition: "right",
44
+ variant: "outlined",
45
+ placeholder: t("payment.checkout.billing.state")
46
+ }
47
+ ),
48
+ /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.postal_code") }),
49
+ /* @__PURE__ */ jsx(
50
+ FormInput,
51
+ {
52
+ name: "billing_address.postal_code",
53
+ rules: { required: t("payment.checkout.required") },
54
+ errorPosition: "right",
55
+ variant: "outlined",
56
+ placeholder: t("payment.checkout.billing.postal_code"),
57
+ InputProps: {
58
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", style: { marginRight: "2px", marginLeft: "-8px" }, children: /* @__PURE__ */ jsx(
59
+ Controller,
60
+ {
61
+ name: "billing_address.country",
62
+ control,
63
+ render: ({ field }) => /* @__PURE__ */ jsx(
64
+ CountrySelect,
65
+ {
66
+ ...field,
67
+ sx: {
68
+ "&.Mui-focused .MuiOutlinedInput-notchedOutline": {
69
+ borderColor: "transparent"
39
70
  }
40
71
  }
41
- )
42
- }
43
- ) })
44
- }
45
- }
46
- ) }),
47
- /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.state") }),
48
- /* @__PURE__ */ jsx(
49
- FormInput,
50
- {
51
- name: "billing_address.state",
52
- rules: { required: t("payment.checkout.required") },
53
- errorPosition: "right",
54
- variant: "outlined",
55
- placeholder: t("payment.checkout.billing.state")
56
- }
57
- ),
58
- /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.line1") }),
59
- /* @__PURE__ */ jsx(
60
- FormInput,
61
- {
62
- name: "billing_address.line1",
63
- rules: { required: t("payment.checkout.required") },
64
- errorPosition: "right",
65
- variant: "outlined",
66
- placeholder: t("payment.checkout.billing.line1")
67
- }
68
- ),
69
- /* @__PURE__ */ jsx(FormLabel, { className: "base-label", children: t("payment.checkout.billing.city") }),
70
- /* @__PURE__ */ jsx(
71
- FormInput,
72
- {
73
- name: "billing_address.city",
74
- rules: { required: t("payment.checkout.required") },
75
- errorPosition: "right",
76
- variant: "outlined",
77
- placeholder: t("payment.checkout.billing.city")
72
+ }
73
+ )
74
+ }
75
+ ) })
78
76
  }
79
- )
80
- ] })
81
- ] }) });
77
+ }
78
+ )
79
+ ] }) }) });
82
80
  }
83
81
  if (stripe) {
84
82
  return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-payment-address cko-payment-form", sx, children: [
@@ -4,19 +4,27 @@ type DialogProps = {
4
4
  onClose?: () => void;
5
5
  title?: string;
6
6
  };
7
+ type DetailLinkOptions = {
8
+ enabled?: boolean;
9
+ onClick?: (e: React.MouseEvent) => void;
10
+ title?: string;
11
+ };
7
12
  type Props = {
8
- subscriptionId: string;
13
+ subscriptionId?: string;
14
+ customerId?: string;
9
15
  mode?: 'default' | 'custom';
10
- onPaid?: (subscriptionId: string, currencyId: string) => void;
16
+ onPaid?: (id: string, currencyId: string, type: 'subscription' | 'customer') => void;
11
17
  dialogProps?: DialogProps;
12
- inSubscriptionDetail?: boolean;
18
+ detailLinkOptions?: DetailLinkOptions;
19
+ successToast?: boolean;
13
20
  children?: (handlePay: (item: SummaryItem) => void, data: {
14
- subscription: Subscription;
21
+ subscription?: Subscription;
15
22
  summary: {
16
23
  [key: string]: SummaryItem;
17
24
  };
18
25
  invoices: Invoice[];
19
- subscriptionUrl: string;
26
+ subscriptionCount?: number;
27
+ detailUrl: string;
20
28
  }) => React.ReactNode;
21
29
  };
22
30
  type SummaryItem = {
@@ -24,7 +32,7 @@ type SummaryItem = {
24
32
  currency: PaymentCurrency;
25
33
  method: PaymentMethod;
26
34
  };
27
- declare function OverdueInvoicePayment({ subscriptionId, mode, dialogProps, children, onPaid, inSubscriptionDetail, }: Props): import("react").JSX.Element | null;
35
+ declare function OverdueInvoicePayment({ subscriptionId, customerId, mode, dialogProps, children, onPaid, detailLinkOptions, successToast, }: Props): import("react").JSX.Element | null;
28
36
  declare namespace OverdueInvoicePayment {
29
37
  var defaultProps: {
30
38
  mode: string;
@@ -33,7 +41,12 @@ declare namespace OverdueInvoicePayment {
33
41
  open: boolean;
34
42
  };
35
43
  children: null;
36
- inSubscriptionDetail: boolean;
44
+ detailLinkOptions: {
45
+ enabled: boolean;
46
+ };
47
+ subscriptionId: undefined;
48
+ customerId: undefined;
49
+ successToast: boolean;
37
50
  };
38
51
  }
39
52
  export default OverdueInvoicePayment;
@@ -12,22 +12,38 @@ var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
12
12
  var _ufo = require("ufo");
13
13
  var _ahooks = require("ahooks");
14
14
  var _ux = require("@arcblock/ux");
15
+ var _iconsMaterial = require("@mui/icons-material");
16
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
15
17
  var _payment = require("../contexts/payment");
16
18
  var _util = require("../libs/util");
17
19
  var _subscription = require("../hooks/subscription");
18
20
  var _api = _interopRequireDefault(require("../libs/api"));
21
+ var _loadingButton = _interopRequireDefault(require("./loading-button"));
19
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
- const fetchOverdueInvoices = async subscriptionId => {
21
- const res = await _api.default.get(`/api/subscriptions/${subscriptionId}/overdue/invoices`);
23
+ const fetchOverdueInvoices = async params => {
24
+ if (!params.subscriptionId && !params.customerId) {
25
+ throw new Error("Either subscriptionId or customerId must be provided");
26
+ }
27
+ let url;
28
+ if (params.subscriptionId) {
29
+ url = `/api/subscriptions/${params.subscriptionId}/overdue/invoices`;
30
+ } else {
31
+ url = `/api/customers/${params.customerId}/overdue/invoices`;
32
+ }
33
+ const res = await _api.default.get(url);
22
34
  return res.data;
23
35
  };
24
36
  function OverdueInvoicePayment({
25
37
  subscriptionId,
38
+ customerId,
26
39
  mode = "default",
27
40
  dialogProps = {},
28
41
  children,
29
42
  onPaid = () => {},
30
- inSubscriptionDetail = false
43
+ detailLinkOptions = {
44
+ enabled: true
45
+ },
46
+ successToast = true
31
47
  }) {
32
48
  const {
33
49
  t
@@ -39,47 +55,74 @@ function OverdueInvoicePayment({
39
55
  const [payLoading, setPayLoading] = (0, _react.useState)(false);
40
56
  const [dialogOpen, setDialogOpen] = (0, _react.useState)(dialogProps.open || false);
41
57
  const [processedCurrencies, setProcessedCurrencies] = (0, _react.useState)({});
58
+ const [paymentStatus, setPaymentStatus] = (0, _react.useState)({});
59
+ const sourceType = subscriptionId ? "subscription" : "customer";
60
+ const sourceId = subscriptionId || customerId;
42
61
  const {
43
62
  data = {
44
- subscription: {},
45
63
  summary: {},
46
64
  invoices: []
47
65
  },
48
66
  error,
49
67
  loading,
50
68
  runAsync: refresh
51
- } = (0, _ahooks.useRequest)(() => fetchOverdueInvoices(subscriptionId));
52
- const subscriptionUrl = (0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/subscription/${subscriptionId}`);
69
+ } = (0, _ahooks.useRequest)(() => fetchOverdueInvoices({
70
+ subscriptionId,
71
+ customerId
72
+ }), {
73
+ ready: !!subscriptionId || !!customerId
74
+ });
75
+ const detailUrl = (0, _react.useMemo)(() => {
76
+ if (subscriptionId) {
77
+ return (0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/subscription/${subscriptionId}`);
78
+ }
79
+ if (customerId) {
80
+ return (0, _ufo.joinURL)((0, _util.getPrefix)(), "/customer/invoice/past-due");
81
+ }
82
+ return "";
83
+ }, [subscriptionId, customerId]);
53
84
  const summaryList = (0, _react.useMemo)(() => {
54
85
  if (!data?.summary) {
55
86
  return [];
56
87
  }
57
88
  return Object.values(data.summary);
58
89
  }, [data?.summary]);
90
+ const debouncedHandleInvoicePaid = (0, _debounce.default)(async currencyId => {
91
+ if (successToast) {
92
+ _Toast.default.close();
93
+ _Toast.default.success(t("payment.customer.invoice.paySuccess"));
94
+ }
95
+ setPayLoading(false);
96
+ const res = await refresh();
97
+ if (res.invoices?.length === 0) {
98
+ setDialogOpen(false);
99
+ onPaid(sourceId, currencyId, sourceType);
100
+ }
101
+ }, 1e3, {
102
+ leading: false,
103
+ trailing: true,
104
+ maxWait: 5e3
105
+ });
59
106
  const subscription = (0, _subscription.useSubscription)("events");
60
107
  (0, _react.useEffect)(() => {
61
108
  if (subscription) {
62
109
  subscription.on("invoice.paid", ({
63
110
  response
64
111
  }) => {
65
- const uniqueKey = `${response.subscription_id}-${response.currency_id}`;
66
- if (response.subscription_id === subscriptionId && !processedCurrencies[uniqueKey]) {
67
- _Toast.default.success(t("payment.customer.invoice.paySuccess"));
68
- setPayLoading(false);
69
- setProcessedCurrencies({
70
- ...processedCurrencies,
71
- [uniqueKey]: 1
72
- });
73
- refresh().then(res => {
74
- if (res.invoices?.length === 0) {
75
- setDialogOpen(false);
76
- onPaid(subscriptionId, response.currency_id);
77
- }
78
- });
112
+ const relevantId = subscriptionId || response.customer_id;
113
+ const uniqueKey = `${relevantId}-${response.currency_id}`;
114
+ if (subscriptionId && response.subscription_id === subscriptionId || customerId && response.customer_id === customerId) {
115
+ if (!processedCurrencies[uniqueKey]) {
116
+ setProcessedCurrencies(prev => ({
117
+ ...prev,
118
+ [uniqueKey]: 1
119
+ }));
120
+ debouncedHandleInvoicePaid(response.currency_id);
121
+ }
79
122
  }
80
123
  });
81
124
  }
82
- }, [subscription]);
125
+ }, [subscription, subscriptionId, customerId]);
83
126
  const handlePay = item => {
84
127
  const {
85
128
  currency,
@@ -94,18 +137,32 @@ function OverdueInvoicePayment({
94
137
  }
95
138
  setSelectCurrencyId(currency.id);
96
139
  setPayLoading(true);
140
+ setPaymentStatus(prev => ({
141
+ ...prev,
142
+ [currency.id]: "idle"
143
+ }));
97
144
  if (["arcblock", "ethereum", "base"].includes(method.type)) {
145
+ const extraParams = {
146
+ currencyId: currency.id
147
+ };
148
+ if (subscriptionId) {
149
+ extraParams.subscriptionId = subscriptionId;
150
+ } else if (customerId) {
151
+ extraParams.customerId = customerId;
152
+ }
98
153
  connect.open({
99
154
  containerEl: void 0,
100
155
  saveConnect: false,
101
156
  action: "collect-batch",
102
157
  prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
103
- extraParams: {
104
- currencyId: currency.id,
105
- subscriptionId
106
- },
158
+ extraParams,
107
159
  onSuccess: () => {
108
160
  connect.close();
161
+ setPayLoading(false);
162
+ setPaymentStatus(prev => ({
163
+ ...prev,
164
+ [currency.id]: "success"
165
+ }));
109
166
  },
110
167
  onClose: () => {
111
168
  connect.close();
@@ -113,6 +170,10 @@ function OverdueInvoicePayment({
113
170
  },
114
171
  onError: err => {
115
172
  _Toast.default.error((0, _util.formatError)(err));
173
+ setPaymentStatus(prev => ({
174
+ ...prev,
175
+ [currency.id]: "error"
176
+ }));
116
177
  setPayLoading(false);
117
178
  }
118
179
  });
@@ -123,7 +184,10 @@ function OverdueInvoicePayment({
123
184
  dialogProps.onClose?.();
124
185
  };
125
186
  const handleViewDetailClick = e => {
126
- if (inSubscriptionDetail) {
187
+ if (detailLinkOptions.onClick) {
188
+ e.preventDefault();
189
+ detailLinkOptions.onClick(e);
190
+ } else if (!detailLinkOptions.enabled) {
127
191
  e.preventDefault();
128
192
  handleClose();
129
193
  }
@@ -131,39 +195,112 @@ function OverdueInvoicePayment({
131
195
  if (loading) {
132
196
  return null;
133
197
  }
134
- const renderPayButton = (item, props) => {
135
- const isPayLoading = payLoading && item.currency.id === selectCurrencyId;
198
+ const getDetailLinkText = () => {
199
+ if (detailLinkOptions.title) {
200
+ return detailLinkOptions.title;
201
+ }
202
+ if (subscriptionId) {
203
+ return t("payment.subscription.overdue.view");
204
+ }
205
+ return t("payment.customer.pastDue.view");
206
+ };
207
+ const renderPayButton = (item, primaryButton = true, props = {
208
+ variant: "contained"
209
+ }) => {
210
+ const {
211
+ currency
212
+ } = item;
213
+ const inProcess = payLoading && selectCurrencyId === currency.id;
214
+ const status = paymentStatus[currency.id] || "idle";
215
+ if (status === "success") {
216
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
217
+ variant: props?.variant || "contained",
218
+ size: "small",
219
+ ...(primaryButton ? {} : {
220
+ color: "success",
221
+ startIcon: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.CheckCircle, {})
222
+ }),
223
+ children: t("payment.subscription.overdue.paid")
224
+ });
225
+ }
226
+ if (status === "error") {
227
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
228
+ variant: "contained",
229
+ size: "small",
230
+ onClick: () => handlePay(item),
231
+ ...props,
232
+ children: t("payment.subscription.overdue.retry")
233
+ });
234
+ }
136
235
  if (item.method.type === "stripe") {
137
236
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
138
237
  variant: "contained",
139
238
  color: "primary",
140
- onClick: () => window.open(subscriptionUrl, "_blank"),
239
+ onClick: () => window.open(detailUrl, "_blank"),
141
240
  ...props,
142
241
  children: t("payment.subscription.overdue.viewNow")
143
242
  });
144
243
  }
145
- return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Button, {
244
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_loadingButton.default, {
146
245
  variant: "contained",
147
- color: "primary",
246
+ size: "small",
247
+ disabled: inProcess,
248
+ loading: inProcess,
148
249
  onClick: () => handlePay(item),
149
250
  ...props,
150
- disabled: isPayLoading,
151
- children: [isPayLoading && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {
152
- size: 14,
153
- sx: {
154
- mr: 1,
155
- color: "text.lighter"
156
- }
157
- }), t("payment.subscription.overdue.payNow")]
251
+ children: t("payment.subscription.overdue.payNow")
158
252
  });
159
253
  };
254
+ const getOverdueTitle = () => {
255
+ if (subscriptionId && data.subscription) {
256
+ if (summaryList.length === 1) {
257
+ return t("payment.subscription.overdue.title", {
258
+ name: data.subscription?.description,
259
+ count: data.invoices?.length,
260
+ total: (0, _util.formatAmount)(summaryList[0]?.amount, summaryList[0]?.currency?.decimal),
261
+ symbol: summaryList[0]?.currency?.symbol
262
+ });
263
+ }
264
+ return t("payment.subscription.overdue.simpleTitle", {
265
+ name: data.subscription?.description,
266
+ count: data.invoices?.length
267
+ });
268
+ }
269
+ if (customerId) {
270
+ if (summaryList.length === 1) {
271
+ return t("payment.customer.overdue.title", {
272
+ subscriptionCount: data.subscriptionCount || 0,
273
+ count: data.invoices?.length,
274
+ total: (0, _util.formatAmount)(summaryList[0]?.amount, summaryList[0]?.currency?.decimal),
275
+ symbol: summaryList[0]?.currency?.symbol
276
+ });
277
+ }
278
+ return t("payment.customer.overdue.simpleTitle", {
279
+ subscriptionCount: data.subscriptionCount || 0,
280
+ count: data.invoices?.length
281
+ });
282
+ }
283
+ return "";
284
+ };
285
+ const getEmptyStateMessage = () => {
286
+ if (subscriptionId && data.subscription) {
287
+ return t("payment.subscription.overdue.empty", {
288
+ name: data.subscription?.description
289
+ });
290
+ }
291
+ if (customerId) {
292
+ return t("payment.customer.overdue.empty");
293
+ }
294
+ return "";
295
+ };
160
296
  if (mode === "custom" && children && typeof children === "function") {
161
297
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
162
298
  children: children(handlePay, {
163
299
  subscription: data?.subscription,
164
- subscriptionUrl,
165
300
  summary: data?.summary,
166
- invoices: data?.invoices
301
+ invoices: data?.invoices,
302
+ subscriptionCount: data?.subscriptionCount,
303
+ detailUrl
167
304
  })
168
305
  });
169
306
  }
@@ -190,10 +327,7 @@ function OverdueInvoicePayment({
190
327
  children: [summaryList.length === 0 && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
191
328
  children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
192
329
  severity: "success",
193
- children: t("payment.subscription.overdue.empty", {
194
- // @ts-ignore
195
- name: data?.subscription?.description
196
- })
330
+ children: getEmptyStateMessage()
197
331
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
198
332
  direction: "row",
199
333
  justifyContent: "flex-end",
@@ -212,21 +346,17 @@ function OverdueInvoicePayment({
212
346
  children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
213
347
  color: "text.secondary",
214
348
  variant: "body1",
215
- children: [t("payment.subscription.overdue.title", {
216
- // @ts-ignore
217
- name: data?.subscription?.description,
218
- count: data?.invoices?.length,
219
- total: (0, _util.formatAmount)(summaryList[0]?.amount, summaryList[0]?.currency?.decimal),
220
- symbol: summaryList[0]?.currency?.symbol
221
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)("br", {}), t("payment.subscription.overdue.description"), /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
222
- href: subscriptionUrl,
223
- target: "_blank",
224
- onClick: handleViewDetailClick,
225
- rel: "noreferrer",
226
- style: {
227
- color: "var(--foregrounds-fg-interactive, 0086FF)"
228
- },
229
- children: t("payment.subscription.overdue.view")
349
+ children: [getOverdueTitle(), detailLinkOptions.enabled && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
350
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)("br", {}), t("payment.subscription.overdue.description"), /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
351
+ href: detailUrl,
352
+ target: "_blank",
353
+ onClick: handleViewDetailClick,
354
+ rel: "noreferrer",
355
+ style: {
356
+ color: "var(--foregrounds-fg-interactive, 0086FF)"
357
+ },
358
+ children: getDetailLinkText()
359
+ })]
230
360
  })]
231
361
  }), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
232
362
  direction: "row",
@@ -244,19 +374,17 @@ function OverdueInvoicePayment({
244
374
  children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
245
375
  color: "text.secondary",
246
376
  variant: "body1",
247
- children: [t("payment.subscription.overdue.simpleTitle", {
248
- // @ts-ignore
249
- name: data?.subscription?.description,
250
- count: data?.invoices?.length
251
- }), /* @__PURE__ */(0, _jsxRuntime.jsx)("br", {}), t("payment.subscription.overdue.description"), /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
252
- href: subscriptionUrl,
253
- target: "_blank",
254
- rel: "noreferrer",
255
- onClick: handleViewDetailClick,
256
- style: {
257
- color: "var(--foregrounds-fg-interactive, 0086FF)"
258
- },
259
- children: t("payment.subscription.overdue.view")
377
+ children: [getOverdueTitle(), detailLinkOptions.enabled && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
378
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)("br", {}), t("payment.subscription.overdue.description"), /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
379
+ href: detailUrl,
380
+ target: "_blank",
381
+ rel: "noreferrer",
382
+ onClick: handleViewDetailClick,
383
+ style: {
384
+ color: "var(--foregrounds-fg-interactive, 0086FF)"
385
+ },
386
+ children: getDetailLinkText()
387
+ })]
260
388
  })]
261
389
  }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
262
390
  color: "text.secondary",
@@ -281,7 +409,7 @@ function OverdueInvoicePayment({
281
409
  total: (0, _util.formatAmount)(item?.amount, item?.currency?.decimal),
282
410
  currency: item?.currency?.symbol
283
411
  })
284
- }), renderPayButton(item, {
412
+ }), renderPayButton(item, false, {
285
413
  variant: "text",
286
414
  sx: {
287
415
  color: "text.link"
@@ -300,6 +428,11 @@ OverdueInvoicePayment.defaultProps = {
300
428
  open: true
301
429
  },
302
430
  children: null,
303
- inSubscriptionDetail: false
431
+ detailLinkOptions: {
432
+ enabled: true
433
+ },
434
+ subscriptionId: void 0,
435
+ customerId: void 0,
436
+ successToast: true
304
437
  };
305
438
  module.exports = OverdueInvoicePayment;