@blocklet/payment-react 1.18.28 → 1.18.29

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.
@@ -40,14 +40,15 @@ function OverdueInvoicePayment({
40
40
  authToken
41
41
  }) {
42
42
  const { t } = useLocaleContext();
43
- const { connect } = usePaymentContext();
43
+ const { connect, session } = usePaymentContext();
44
44
  const [selectCurrencyId, setSelectCurrencyId] = useState("");
45
45
  const [payLoading, setPayLoading] = useState(false);
46
46
  const [dialogOpen, setDialogOpen] = useState(dialogProps.open || false);
47
47
  const [processedCurrencies, setProcessedCurrencies] = useState({});
48
48
  const [paymentStatus, setPaymentStatus] = useState({});
49
49
  const sourceType = subscriptionId ? "subscription" : "customer";
50
- const sourceId = subscriptionId || customerId;
50
+ const effectiveCustomerId = customerId || session?.user?.did;
51
+ const sourceId = subscriptionId || effectiveCustomerId;
51
52
  const {
52
53
  data = {
53
54
  summary: {},
@@ -56,18 +57,18 @@ function OverdueInvoicePayment({
56
57
  error,
57
58
  loading,
58
59
  runAsync: refresh
59
- } = useRequest(() => fetchOverdueInvoices({ subscriptionId, customerId, authToken }), {
60
- ready: !!subscriptionId || !!customerId
60
+ } = useRequest(() => fetchOverdueInvoices({ subscriptionId, customerId: effectiveCustomerId, authToken }), {
61
+ ready: !!subscriptionId || !!effectiveCustomerId
61
62
  });
62
63
  const detailUrl = useMemo(() => {
63
64
  if (subscriptionId) {
64
65
  return joinURL(getPrefix(), `/customer/subscription/${subscriptionId}`);
65
66
  }
66
- if (customerId) {
67
+ if (effectiveCustomerId) {
67
68
  return joinURL(getPrefix(), "/customer/invoice/past-due");
68
69
  }
69
70
  return "";
70
- }, [subscriptionId, customerId]);
71
+ }, [subscriptionId, effectiveCustomerId]);
71
72
  const summaryList = useMemo(() => {
72
73
  if (!data?.summary) {
73
74
  return [];
@@ -100,7 +101,7 @@ function OverdueInvoicePayment({
100
101
  subscription.on("invoice.paid", ({ response }) => {
101
102
  const relevantId = subscriptionId || response.customer_id;
102
103
  const uniqueKey = `${relevantId}-${response.currency_id}`;
103
- if (subscriptionId && response.subscription_id === subscriptionId || customerId && response.customer_id === customerId) {
104
+ if (subscriptionId && response.subscription_id === subscriptionId || effectiveCustomerId && [data.customer?.id, effectiveCustomerId].includes(response.customer_id)) {
104
105
  if (!processedCurrencies[uniqueKey]) {
105
106
  setProcessedCurrencies((prev) => ({ ...prev, [uniqueKey]: 1 }));
106
107
  debouncedHandleInvoicePaid(response.currency_id);
@@ -108,7 +109,7 @@ function OverdueInvoicePayment({
108
109
  }
109
110
  });
110
111
  }
111
- }, [subscription, subscriptionId, customerId]);
112
+ }, [subscription, subscriptionId, effectiveCustomerId]);
112
113
  const handlePay = (item) => {
113
114
  const { currency, method } = item;
114
115
  if (method.type === "stripe") {
@@ -128,8 +129,8 @@ function OverdueInvoicePayment({
128
129
  const extraParams = { currencyId: currency.id };
129
130
  if (subscriptionId) {
130
131
  extraParams.subscriptionId = subscriptionId;
131
- } else if (customerId) {
132
- extraParams.customerId = customerId;
132
+ } else if (effectiveCustomerId) {
133
+ extraParams.customerId = effectiveCustomerId;
133
134
  }
134
135
  connect.open({
135
136
  containerEl: void 0,
@@ -246,7 +247,7 @@ function OverdueInvoicePayment({
246
247
  count: data.invoices?.length
247
248
  });
248
249
  }
249
- if (customerId) {
250
+ if (effectiveCustomerId) {
250
251
  let title = "";
251
252
  if (summaryList.length === 1) {
252
253
  title = t("payment.customer.overdue.title", {
@@ -275,10 +276,7 @@ function OverdueInvoicePayment({
275
276
  name: data.subscription?.description
276
277
  });
277
278
  }
278
- if (customerId) {
279
- return t("payment.customer.overdue.empty");
280
- }
281
- return "";
279
+ return t("payment.customer.overdue.empty");
282
280
  };
283
281
  if (mode === "custom" && children && typeof children === "function") {
284
282
  return /* @__PURE__ */ jsx(Stack, { children: children(handlePay, {
@@ -602,7 +602,7 @@ export default function PaymentForm({
602
602
  state.customerLimited && /* @__PURE__ */ jsx(
603
603
  OverdueInvoicePayment,
604
604
  {
605
- customerId: customer?.id || session?.user?.didssion?.user?.did,
605
+ customerId: customer?.id || session?.user?.did,
606
606
  onPaid: () => {
607
607
  setState({ customerLimited: false });
608
608
  onAction();
@@ -51,7 +51,8 @@ function OverdueInvoicePayment({
51
51
  t
52
52
  } = (0, _context.useLocaleContext)();
53
53
  const {
54
- connect
54
+ connect,
55
+ session
55
56
  } = (0, _payment.usePaymentContext)();
56
57
  const [selectCurrencyId, setSelectCurrencyId] = (0, _react.useState)("");
57
58
  const [payLoading, setPayLoading] = (0, _react.useState)(false);
@@ -59,7 +60,8 @@ function OverdueInvoicePayment({
59
60
  const [processedCurrencies, setProcessedCurrencies] = (0, _react.useState)({});
60
61
  const [paymentStatus, setPaymentStatus] = (0, _react.useState)({});
61
62
  const sourceType = subscriptionId ? "subscription" : "customer";
62
- const sourceId = subscriptionId || customerId;
63
+ const effectiveCustomerId = customerId || session?.user?.did;
64
+ const sourceId = subscriptionId || effectiveCustomerId;
63
65
  const {
64
66
  data = {
65
67
  summary: {},
@@ -70,20 +72,20 @@ function OverdueInvoicePayment({
70
72
  runAsync: refresh
71
73
  } = (0, _ahooks.useRequest)(() => fetchOverdueInvoices({
72
74
  subscriptionId,
73
- customerId,
75
+ customerId: effectiveCustomerId,
74
76
  authToken
75
77
  }), {
76
- ready: !!subscriptionId || !!customerId
78
+ ready: !!subscriptionId || !!effectiveCustomerId
77
79
  });
78
80
  const detailUrl = (0, _react.useMemo)(() => {
79
81
  if (subscriptionId) {
80
82
  return (0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/subscription/${subscriptionId}`);
81
83
  }
82
- if (customerId) {
84
+ if (effectiveCustomerId) {
83
85
  return (0, _ufo.joinURL)((0, _util.getPrefix)(), "/customer/invoice/past-due");
84
86
  }
85
87
  return "";
86
- }, [subscriptionId, customerId]);
88
+ }, [subscriptionId, effectiveCustomerId]);
87
89
  const summaryList = (0, _react.useMemo)(() => {
88
90
  if (!data?.summary) {
89
91
  return [];
@@ -114,7 +116,7 @@ function OverdueInvoicePayment({
114
116
  }) => {
115
117
  const relevantId = subscriptionId || response.customer_id;
116
118
  const uniqueKey = `${relevantId}-${response.currency_id}`;
117
- if (subscriptionId && response.subscription_id === subscriptionId || customerId && response.customer_id === customerId) {
119
+ if (subscriptionId && response.subscription_id === subscriptionId || effectiveCustomerId && [data.customer?.id, effectiveCustomerId].includes(response.customer_id)) {
118
120
  if (!processedCurrencies[uniqueKey]) {
119
121
  setProcessedCurrencies(prev => ({
120
122
  ...prev,
@@ -125,7 +127,7 @@ function OverdueInvoicePayment({
125
127
  }
126
128
  });
127
129
  }
128
- }, [subscription, subscriptionId, customerId]);
130
+ }, [subscription, subscriptionId, effectiveCustomerId]);
129
131
  const handlePay = item => {
130
132
  const {
131
133
  currency,
@@ -150,8 +152,8 @@ function OverdueInvoicePayment({
150
152
  };
151
153
  if (subscriptionId) {
152
154
  extraParams.subscriptionId = subscriptionId;
153
- } else if (customerId) {
154
- extraParams.customerId = customerId;
155
+ } else if (effectiveCustomerId) {
156
+ extraParams.customerId = effectiveCustomerId;
155
157
  }
156
158
  connect.open({
157
159
  containerEl: void 0,
@@ -276,7 +278,7 @@ function OverdueInvoicePayment({
276
278
  count: data.invoices?.length
277
279
  });
278
280
  }
279
- if (customerId) {
281
+ if (effectiveCustomerId) {
280
282
  let title = "";
281
283
  if (summaryList.length === 1) {
282
284
  title = t("payment.customer.overdue.title", {
@@ -305,10 +307,7 @@ function OverdueInvoicePayment({
305
307
  name: data.subscription?.description
306
308
  });
307
309
  }
308
- if (customerId) {
309
- return t("payment.customer.overdue.empty");
310
- }
311
- return "";
310
+ return t("payment.customer.overdue.empty");
312
311
  };
313
312
  if (mode === "custom" && children && typeof children === "function") {
314
313
  return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
@@ -681,7 +681,7 @@ function PaymentForm({
681
681
  })]
682
682
  })
683
683
  }), state.customerLimited && /* @__PURE__ */(0, _jsxRuntime.jsx)(_overDueInvoicePayment.default, {
684
- customerId: customer?.id || session?.user?.didssion?.user?.did,
684
+ customerId: customer?.id || session?.user?.did,
685
685
  onPaid: () => {
686
686
  setState({
687
687
  customerLimited: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.18.28",
3
+ "version": "1.18.29",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -93,7 +93,7 @@
93
93
  "@babel/core": "^7.25.2",
94
94
  "@babel/preset-env": "^7.25.2",
95
95
  "@babel/preset-react": "^7.24.7",
96
- "@blocklet/payment-types": "1.18.28",
96
+ "@blocklet/payment-types": "1.18.29",
97
97
  "@storybook/addon-essentials": "^7.6.20",
98
98
  "@storybook/addon-interactions": "^7.6.20",
99
99
  "@storybook/addon-links": "^7.6.20",
@@ -124,5 +124,5 @@
124
124
  "vite-plugin-babel": "^1.2.0",
125
125
  "vite-plugin-node-polyfills": "^0.21.0"
126
126
  },
127
- "gitHead": "5e904113fcdc51ef6ef4d67b664ed14f733da384"
127
+ "gitHead": "bb8d03a1da62822cbc2ae57d7c5f2912aaebc0da"
128
128
  }
@@ -4,7 +4,14 @@ import { Button, Typography, Stack, Alert, SxProps } from '@mui/material';
4
4
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
5
  import Toast from '@arcblock/ux/lib/Toast';
6
6
  import { joinURL } from 'ufo';
7
- import type { Invoice, PaymentCurrency, PaymentMethod, Subscription, TInvoiceExpanded } from '@blocklet/payment-types';
7
+ import type {
8
+ Customer,
9
+ Invoice,
10
+ PaymentCurrency,
11
+ PaymentMethod,
12
+ Subscription,
13
+ TInvoiceExpanded,
14
+ } from '@blocklet/payment-types';
8
15
  import { useRequest } from 'ahooks';
9
16
  import { Dialog } from '@arcblock/ux';
10
17
  import { CheckCircle as CheckCircleIcon } from '@mui/icons-material';
@@ -60,6 +67,7 @@ type OverdueInvoicesResult = {
60
67
  summary: { [key: string]: SummaryItem };
61
68
  invoices: Invoice[];
62
69
  subscriptionCount?: number;
70
+ customer?: Customer;
63
71
  };
64
72
 
65
73
  const fetchOverdueInvoices = async (params: {
@@ -95,7 +103,7 @@ function OverdueInvoicePayment({
95
103
  authToken,
96
104
  }: Props) {
97
105
  const { t } = useLocaleContext();
98
- const { connect } = usePaymentContext();
106
+ const { connect, session } = usePaymentContext();
99
107
  const [selectCurrencyId, setSelectCurrencyId] = useState('');
100
108
  const [payLoading, setPayLoading] = useState(false);
101
109
  const [dialogOpen, setDialogOpen] = useState(dialogProps.open || false);
@@ -103,7 +111,8 @@ function OverdueInvoicePayment({
103
111
  const [paymentStatus, setPaymentStatus] = useState<{ [key: string]: 'success' | 'error' | 'idle' }>({});
104
112
 
105
113
  const sourceType = subscriptionId ? 'subscription' : 'customer';
106
- const sourceId = subscriptionId || customerId;
114
+ const effectiveCustomerId = customerId || session?.user?.did;
115
+ const sourceId = subscriptionId || effectiveCustomerId;
107
116
  const {
108
117
  data = {
109
118
  summary: {},
@@ -112,19 +121,19 @@ function OverdueInvoicePayment({
112
121
  error,
113
122
  loading,
114
123
  runAsync: refresh,
115
- } = useRequest(() => fetchOverdueInvoices({ subscriptionId, customerId, authToken }), {
116
- ready: !!subscriptionId || !!customerId,
124
+ } = useRequest(() => fetchOverdueInvoices({ subscriptionId, customerId: effectiveCustomerId, authToken }), {
125
+ ready: !!subscriptionId || !!effectiveCustomerId,
117
126
  });
118
127
 
119
128
  const detailUrl = useMemo(() => {
120
129
  if (subscriptionId) {
121
130
  return joinURL(getPrefix(), `/customer/subscription/${subscriptionId}`);
122
131
  }
123
- if (customerId) {
132
+ if (effectiveCustomerId) {
124
133
  return joinURL(getPrefix(), '/customer/invoice/past-due');
125
134
  }
126
135
  return '';
127
- }, [subscriptionId, customerId]);
136
+ }, [subscriptionId, effectiveCustomerId]);
128
137
 
129
138
  const summaryList = useMemo(() => {
130
139
  if (!data?.summary) {
@@ -163,7 +172,7 @@ function OverdueInvoicePayment({
163
172
 
164
173
  if (
165
174
  (subscriptionId && response.subscription_id === subscriptionId) ||
166
- (customerId && response.customer_id === customerId)
175
+ (effectiveCustomerId && [data.customer?.id, effectiveCustomerId].includes(response.customer_id))
167
176
  ) {
168
177
  if (!processedCurrencies[uniqueKey]) {
169
178
  setProcessedCurrencies((prev) => ({ ...prev, [uniqueKey]: 1 }));
@@ -173,7 +182,7 @@ function OverdueInvoicePayment({
173
182
  });
174
183
  }
175
184
  // eslint-disable-next-line react-hooks/exhaustive-deps
176
- }, [subscription, subscriptionId, customerId]);
185
+ }, [subscription, subscriptionId, effectiveCustomerId]);
177
186
 
178
187
  const handlePay = (item: SummaryItem) => {
179
188
  const { currency, method } = item;
@@ -196,8 +205,8 @@ function OverdueInvoicePayment({
196
205
 
197
206
  if (subscriptionId) {
198
207
  extraParams.subscriptionId = subscriptionId;
199
- } else if (customerId) {
200
- extraParams.customerId = customerId;
208
+ } else if (effectiveCustomerId) {
209
+ extraParams.customerId = effectiveCustomerId;
201
210
  }
202
211
 
203
212
  connect.open({
@@ -343,7 +352,7 @@ function OverdueInvoicePayment({
343
352
  count: data.invoices?.length,
344
353
  });
345
354
  }
346
- if (customerId) {
355
+ if (effectiveCustomerId) {
347
356
  let title = '';
348
357
  if (summaryList.length === 1) {
349
358
  title = t('payment.customer.overdue.title', {
@@ -374,11 +383,7 @@ function OverdueInvoicePayment({
374
383
  name: data.subscription?.description,
375
384
  });
376
385
  }
377
- if (customerId) {
378
- return t('payment.customer.overdue.empty');
379
- }
380
-
381
- return '';
386
+ return t('payment.customer.overdue.empty');
382
387
  };
383
388
 
384
389
  if (mode === 'custom' && children && typeof children === 'function') {
@@ -726,7 +726,7 @@ export default function PaymentForm({
726
726
  </Fade>
727
727
  {state.customerLimited && (
728
728
  <OverdueInvoicePayment
729
- customerId={customer?.id || session?.user?.didssion?.user?.did}
729
+ customerId={customer?.id || session?.user?.did}
730
730
  onPaid={() => {
731
731
  setState({ customerLimited: false });
732
732
  onAction();