@blocklet/payment-react 1.22.15 → 1.22.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.
@@ -2,6 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useRef, useState } from "react";
3
3
  import { Button, Typography, Stack, Alert, useTheme } from "@mui/material";
4
4
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
5
+ import useArcblockBrowser from "@arcblock/react-hooks/lib/useBrowser";
5
6
  import Toast from "@arcblock/ux/lib/Toast";
6
7
  import { joinURL } from "ufo";
7
8
  import { useRequest } from "ahooks";
@@ -44,6 +45,8 @@ function OverdueInvoicePayment({
44
45
  authToken = void 0
45
46
  }) {
46
47
  const { t, locale } = useLocaleContext();
48
+ const browser = useArcblockBrowser();
49
+ const inArcSphere = browser?.arcSphere;
47
50
  const theme = useTheme();
48
51
  const { connect, session } = usePaymentContext();
49
52
  const [selectCurrencyId, setSelectCurrencyId] = useState("");
@@ -134,12 +137,17 @@ function OverdueInvoicePayment({
134
137
  });
135
138
  const isCrossOriginRequest = isCrossOrigin();
136
139
  const subscription = useSubscription("events");
137
- const waitForInvoiceAllPaid = async () => {
140
+ const waitForInvoicePaidByCurrency = async (currencyId) => {
138
141
  let isPaid = false;
139
142
  await pWaitFor(
140
143
  async () => {
141
- const res = await refresh();
142
- isPaid = res.invoices?.length === 0;
144
+ const checkData = await fetchOverdueInvoices({
145
+ subscriptionId,
146
+ customerId: effectiveCustomerId,
147
+ authToken
148
+ });
149
+ const hasRemainingInvoices = checkData.invoices?.some((inv) => inv.currency_id === currencyId);
150
+ isPaid = !hasRemainingInvoices;
143
151
  return isPaid;
144
152
  },
145
153
  { interval: 2e3, timeout: 3 * 60 * 1e3 }
@@ -147,19 +155,26 @@ function OverdueInvoicePayment({
147
155
  return isPaid;
148
156
  };
149
157
  const handleConnected = async (currencyId, isStripe = false) => {
150
- if (isCrossOriginRequest) {
158
+ if (isCrossOriginRequest || inArcSphere) {
151
159
  try {
152
- const paid = await waitForInvoiceAllPaid();
153
- if (successToast) {
154
- Toast.close();
155
- Toast.success(t("payment.customer.invoice.paySuccess"));
156
- }
160
+ const paid = await waitForInvoicePaidByCurrency(currencyId);
157
161
  if (paid) {
158
- setDialogOpen(false);
159
- onPaid(sourceId, currencyId, sourceType);
162
+ setPaymentStatus((prev) => ({ ...prev, [currencyId]: "success" }));
163
+ const finalRes = await refresh();
164
+ if (successToast) {
165
+ Toast.close();
166
+ Toast.success(t("payment.customer.invoice.paySuccess"));
167
+ }
168
+ if (finalRes.invoices?.length === 0) {
169
+ setDialogOpen(false);
170
+ onPaid(sourceId, currencyId, sourceType);
171
+ }
160
172
  }
161
173
  } catch (err) {
162
174
  console.error("Check payment status failed:", err);
175
+ setPaymentStatus((prev) => ({ ...prev, [currencyId]: "error" }));
176
+ } finally {
177
+ setPayLoading(false);
163
178
  }
164
179
  } else if (isStripe) {
165
180
  setStripePaymentInProgress((prev) => ({ ...prev, [currencyId]: true }));
@@ -167,7 +182,7 @@ function OverdueInvoicePayment({
167
182
  }
168
183
  };
169
184
  useEffect(() => {
170
- if (!subscription || isCrossOriginRequest) {
185
+ if (!subscription || isCrossOriginRequest || inArcSphere) {
171
186
  return void 0;
172
187
  }
173
188
  const handleInvoicePaid = ({ response }) => {
package/es/libs/util.js CHANGED
@@ -675,7 +675,7 @@ export const getSubscriptionTimeSummary = (subscription, locale = "en") => {
675
675
  if (subscription.cancel_at) {
676
676
  const endTime = subscription.cancel_at * 1e3;
677
677
  const { time: time2, isToday: isToday2 } = getLineTimeInfo(endTime, locale);
678
- return { action: "willEnd", time: time2, isToday: isToday2 };
678
+ return { action: endTime > Date.now() ? "willEnd" : "ended", time: time2, isToday: isToday2 };
679
679
  }
680
680
  if (subscription.cancel_at_period_end) {
681
681
  const endTime = subscription.current_period_end * 1e3;
@@ -688,7 +688,7 @@ export const getSubscriptionTimeSummary = (subscription, locale = "en") => {
688
688
  if (subscription.status === "past_due") {
689
689
  const endTime = (subscription.cancel_at || subscription.current_period_end) * 1e3;
690
690
  const { time, isToday } = getLineTimeInfo(endTime, locale);
691
- return { action: "ended", time, isToday };
691
+ return { action: endTime > Date.now() ? "willEnd" : "ended", time, isToday };
692
692
  }
693
693
  if (subscription.status === "canceled") {
694
694
  const { time, isToday } = getLineTimeInfo(subscription.canceled_at * 1e3, locale);
@@ -8,6 +8,7 @@ var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _react = require("react");
9
9
  var _material = require("@mui/material");
10
10
  var _context = require("@arcblock/ux/lib/Locale/context");
11
+ var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
11
12
  var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
12
13
  var _ufo = require("ufo");
13
14
  var _ahooks = require("ahooks");
@@ -55,6 +56,8 @@ function OverdueInvoicePayment({
55
56
  t,
56
57
  locale
57
58
  } = (0, _context.useLocaleContext)();
59
+ const browser = (0, _useBrowser.default)();
60
+ const inArcSphere = browser?.arcSphere;
58
61
  const theme = (0, _material.useTheme)();
59
62
  const {
60
63
  connect,
@@ -155,11 +158,16 @@ function OverdueInvoicePayment({
155
158
  });
156
159
  const isCrossOriginRequest = (0, _util.isCrossOrigin)();
157
160
  const subscription = (0, _subscription.useSubscription)("events");
158
- const waitForInvoiceAllPaid = async () => {
161
+ const waitForInvoicePaidByCurrency = async currencyId => {
159
162
  let isPaid = false;
160
163
  await (0, _pWaitFor.default)(async () => {
161
- const res = await refresh();
162
- isPaid = res.invoices?.length === 0;
164
+ const checkData = await fetchOverdueInvoices({
165
+ subscriptionId,
166
+ customerId: effectiveCustomerId,
167
+ authToken
168
+ });
169
+ const hasRemainingInvoices = checkData.invoices?.some(inv => inv.currency_id === currencyId);
170
+ isPaid = !hasRemainingInvoices;
163
171
  return isPaid;
164
172
  }, {
165
173
  interval: 2e3,
@@ -168,19 +176,32 @@ function OverdueInvoicePayment({
168
176
  return isPaid;
169
177
  };
170
178
  const handleConnected = async (currencyId, isStripe = false) => {
171
- if (isCrossOriginRequest) {
179
+ if (isCrossOriginRequest || inArcSphere) {
172
180
  try {
173
- const paid = await waitForInvoiceAllPaid();
174
- if (successToast) {
175
- _Toast.default.close();
176
- _Toast.default.success(t("payment.customer.invoice.paySuccess"));
177
- }
181
+ const paid = await waitForInvoicePaidByCurrency(currencyId);
178
182
  if (paid) {
179
- setDialogOpen(false);
180
- onPaid(sourceId, currencyId, sourceType);
183
+ setPaymentStatus(prev => ({
184
+ ...prev,
185
+ [currencyId]: "success"
186
+ }));
187
+ const finalRes = await refresh();
188
+ if (successToast) {
189
+ _Toast.default.close();
190
+ _Toast.default.success(t("payment.customer.invoice.paySuccess"));
191
+ }
192
+ if (finalRes.invoices?.length === 0) {
193
+ setDialogOpen(false);
194
+ onPaid(sourceId, currencyId, sourceType);
195
+ }
181
196
  }
182
197
  } catch (err) {
183
198
  console.error("Check payment status failed:", err);
199
+ setPaymentStatus(prev => ({
200
+ ...prev,
201
+ [currencyId]: "error"
202
+ }));
203
+ } finally {
204
+ setPayLoading(false);
184
205
  }
185
206
  } else if (isStripe) {
186
207
  setStripePaymentInProgress(prev => ({
@@ -194,7 +215,7 @@ function OverdueInvoicePayment({
194
215
  }
195
216
  };
196
217
  (0, _react.useEffect)(() => {
197
- if (!subscription || isCrossOriginRequest) {
218
+ if (!subscription || isCrossOriginRequest || inArcSphere) {
198
219
  return void 0;
199
220
  }
200
221
  const handleInvoicePaid = ({
package/lib/libs/util.js CHANGED
@@ -834,7 +834,7 @@ const getSubscriptionTimeSummary = (subscription, locale = "en") => {
834
834
  isToday: isToday2
835
835
  } = getLineTimeInfo(endTime, locale);
836
836
  return {
837
- action: "willEnd",
837
+ action: endTime > Date.now() ? "willEnd" : "ended",
838
838
  time: time2,
839
839
  isToday: isToday2
840
840
  };
@@ -868,7 +868,7 @@ const getSubscriptionTimeSummary = (subscription, locale = "en") => {
868
868
  isToday
869
869
  } = getLineTimeInfo(endTime, locale);
870
870
  return {
871
- action: "ended",
871
+ action: endTime > Date.now() ? "willEnd" : "ended",
872
872
  time,
873
873
  isToday
874
874
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.22.15",
3
+ "version": "1.22.16",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -54,18 +54,18 @@
54
54
  }
55
55
  },
56
56
  "dependencies": {
57
- "@arcblock/bridge": "^3.2.6",
58
- "@arcblock/did-connect-react": "^3.2.6",
59
- "@arcblock/react-hooks": "^3.2.6",
60
- "@arcblock/ux": "^3.2.6",
61
- "@arcblock/ws": "^1.27.6",
62
- "@blocklet/theme": "^3.2.6",
63
- "@blocklet/ui-react": "^3.2.6",
57
+ "@arcblock/bridge": "^3.2.7",
58
+ "@arcblock/did-connect-react": "^3.2.7",
59
+ "@arcblock/react-hooks": "^3.2.7",
60
+ "@arcblock/ux": "^3.2.7",
61
+ "@arcblock/ws": "^1.27.11",
62
+ "@blocklet/theme": "^3.2.7",
63
+ "@blocklet/ui-react": "^3.2.7",
64
64
  "@mui/icons-material": "^7.1.2",
65
65
  "@mui/lab": "7.0.0-beta.14",
66
66
  "@mui/material": "^7.1.2",
67
67
  "@mui/system": "^7.1.1",
68
- "@ocap/util": "^1.27.6",
68
+ "@ocap/util": "^1.27.11",
69
69
  "@stripe/react-stripe-js": "^2.9.0",
70
70
  "@stripe/stripe-js": "^2.4.0",
71
71
  "@vitejs/plugin-legacy": "^7.0.0",
@@ -96,7 +96,7 @@
96
96
  "@babel/core": "^7.27.4",
97
97
  "@babel/preset-env": "^7.27.2",
98
98
  "@babel/preset-react": "^7.27.1",
99
- "@blocklet/payment-types": "1.22.15",
99
+ "@blocklet/payment-types": "1.22.16",
100
100
  "@storybook/addon-essentials": "^7.6.20",
101
101
  "@storybook/addon-interactions": "^7.6.20",
102
102
  "@storybook/addon-links": "^7.6.20",
@@ -127,5 +127,5 @@
127
127
  "vite-plugin-babel": "^1.3.1",
128
128
  "vite-plugin-node-polyfills": "^0.23.0"
129
129
  },
130
- "gitHead": "4d8543567eb8958c55a8cf06d9031f3f64c57e27"
130
+ "gitHead": "68ff7bcdc9f185a8d885d9af189d2e2c1cc5fbf6"
131
131
  }
@@ -2,6 +2,7 @@
2
2
  import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Button, Typography, Stack, Alert, SxProps, useTheme } from '@mui/material';
4
4
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
+ import useArcblockBrowser from '@arcblock/react-hooks/lib/useBrowser';
5
6
  import Toast from '@arcblock/ux/lib/Toast';
6
7
  import { joinURL } from 'ufo';
7
8
  import type {
@@ -107,6 +108,8 @@ function OverdueInvoicePayment({
107
108
  authToken = undefined,
108
109
  }: Props) {
109
110
  const { t, locale } = useLocaleContext();
111
+ const browser = useArcblockBrowser();
112
+ const inArcSphere = browser?.arcSphere;
110
113
  const theme = useTheme();
111
114
  const { connect, session } = usePaymentContext();
112
115
  const [selectCurrencyId, setSelectCurrencyId] = useState('');
@@ -212,12 +215,17 @@ function OverdueInvoicePayment({
212
215
  const isCrossOriginRequest = isCrossOrigin();
213
216
 
214
217
  const subscription = useSubscription('events');
215
- const waitForInvoiceAllPaid = async () => {
218
+ const waitForInvoicePaidByCurrency = async (currencyId: string) => {
216
219
  let isPaid = false;
217
220
  await pWaitFor(
218
221
  async () => {
219
- const res = await refresh();
220
- isPaid = res.invoices?.length === 0;
222
+ const checkData = await fetchOverdueInvoices({
223
+ subscriptionId,
224
+ customerId: effectiveCustomerId,
225
+ authToken,
226
+ });
227
+ const hasRemainingInvoices = checkData.invoices?.some((inv: Invoice) => inv.currency_id === currencyId);
228
+ isPaid = !hasRemainingInvoices;
221
229
  return isPaid;
222
230
  },
223
231
  { interval: 2000, timeout: 3 * 60 * 1000 }
@@ -226,19 +234,26 @@ function OverdueInvoicePayment({
226
234
  };
227
235
 
228
236
  const handleConnected = async (currencyId: string, isStripe = false) => {
229
- if (isCrossOriginRequest) {
237
+ if (isCrossOriginRequest || inArcSphere) {
230
238
  try {
231
- const paid = await waitForInvoiceAllPaid();
232
- if (successToast) {
233
- Toast.close();
234
- Toast.success(t('payment.customer.invoice.paySuccess'));
235
- }
239
+ const paid = await waitForInvoicePaidByCurrency(currencyId);
236
240
  if (paid) {
237
- setDialogOpen(false);
238
- onPaid(sourceId as string, currencyId, sourceType as 'subscription' | 'customer');
241
+ setPaymentStatus((prev) => ({ ...prev, [currencyId]: 'success' }));
242
+ const finalRes = await refresh();
243
+ if (successToast) {
244
+ Toast.close();
245
+ Toast.success(t('payment.customer.invoice.paySuccess'));
246
+ }
247
+ if (finalRes.invoices?.length === 0) {
248
+ setDialogOpen(false);
249
+ onPaid(sourceId as string, currencyId, sourceType as 'subscription' | 'customer');
250
+ }
239
251
  }
240
252
  } catch (err) {
241
253
  console.error('Check payment status failed:', err);
254
+ setPaymentStatus((prev) => ({ ...prev, [currencyId]: 'error' }));
255
+ } finally {
256
+ setPayLoading(false);
242
257
  }
243
258
  } else if (isStripe) {
244
259
  setStripePaymentInProgress((prev) => ({ ...prev, [currencyId]: true }));
@@ -247,7 +262,7 @@ function OverdueInvoicePayment({
247
262
  };
248
263
 
249
264
  useEffect(() => {
250
- if (!subscription || isCrossOriginRequest) {
265
+ if (!subscription || isCrossOriginRequest || inArcSphere) {
251
266
  return undefined;
252
267
  }
253
268
 
package/src/libs/util.ts CHANGED
@@ -898,7 +898,7 @@ export const getSubscriptionTimeSummary = (subscription: TSubscriptionExpanded,
898
898
  if (subscription.cancel_at) {
899
899
  const endTime = subscription.cancel_at * 1000;
900
900
  const { time, isToday } = getLineTimeInfo(endTime, locale);
901
- return { action: 'willEnd', time, isToday };
901
+ return { action: endTime > Date.now() ? 'willEnd' : 'ended', time, isToday };
902
902
  }
903
903
  if (subscription.cancel_at_period_end) {
904
904
  const endTime = subscription.current_period_end * 1000;
@@ -911,7 +911,7 @@ export const getSubscriptionTimeSummary = (subscription: TSubscriptionExpanded,
911
911
  if (subscription.status === 'past_due') {
912
912
  const endTime = (subscription.cancel_at || subscription.current_period_end) * 1000;
913
913
  const { time, isToday } = getLineTimeInfo(endTime, locale);
914
- return { action: 'ended', time, isToday };
914
+ return { action: endTime > Date.now() ? 'willEnd' : 'ended', time, isToday };
915
915
  }
916
916
  if (subscription.status === 'canceled') {
917
917
  const { time, isToday } = getLineTimeInfo(subscription.canceled_at * 1000, locale);