@blocklet/payment-react 1.13.123 → 1.13.125

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 (47) hide show
  1. package/es/api.js +0 -1
  2. package/es/components/confirm.d.ts +14 -0
  3. package/es/components/confirm.js +31 -0
  4. package/es/components/pricing-table.js +77 -67
  5. package/es/contexts/payment.d.ts +4 -2
  6. package/es/index.d.ts +4 -1
  7. package/es/index.js +7 -1
  8. package/es/locales/en.js +5 -1
  9. package/es/locales/zh.js +4 -0
  10. package/es/payment/form/index.js +2 -2
  11. package/es/payment/index.js +3 -3
  12. package/es/portal/invoice/list.d.ts +6 -0
  13. package/es/portal/invoice/list.js +84 -0
  14. package/es/portal/payment/list.d.ts +6 -0
  15. package/es/portal/payment/list.js +84 -0
  16. package/es/util.d.ts +4 -0
  17. package/es/util.js +56 -0
  18. package/lib/api.js +0 -1
  19. package/lib/components/confirm.d.ts +14 -0
  20. package/lib/components/confirm.js +49 -0
  21. package/lib/components/pricing-table.js +143 -135
  22. package/lib/contexts/payment.d.ts +4 -2
  23. package/lib/index.d.ts +4 -1
  24. package/lib/index.js +24 -0
  25. package/lib/locales/en.js +5 -1
  26. package/lib/locales/zh.js +4 -0
  27. package/lib/payment/form/index.js +2 -2
  28. package/lib/payment/index.js +3 -3
  29. package/lib/portal/invoice/list.d.ts +6 -0
  30. package/lib/portal/invoice/list.js +150 -0
  31. package/lib/portal/payment/list.d.ts +6 -0
  32. package/lib/portal/payment/list.js +149 -0
  33. package/lib/util.d.ts +4 -0
  34. package/lib/util.js +62 -1
  35. package/package.json +3 -3
  36. package/src/api.ts +1 -1
  37. package/src/components/confirm.tsx +39 -0
  38. package/src/components/pricing-table.tsx +125 -113
  39. package/src/contexts/payment.tsx +2 -2
  40. package/src/index.ts +6 -0
  41. package/src/locales/en.tsx +5 -1
  42. package/src/locales/zh.tsx +4 -0
  43. package/src/payment/form/index.tsx +5 -3
  44. package/src/payment/index.tsx +3 -3
  45. package/src/portal/invoice/list.tsx +122 -0
  46. package/src/portal/payment/list.tsx +120 -0
  47. package/src/util.ts +60 -0
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = CustomerInvoiceList;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _context = require("@arcblock/ux/lib/Locale/context");
9
+ var _material = require("@mui/material");
10
+ var _util = require("@ocap/util");
11
+ var _ahooks = require("ahooks");
12
+ var _api = _interopRequireDefault(require("../../api"));
13
+ var _status = _interopRequireDefault(require("../../components/status"));
14
+ var _util2 = require("../../util");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ const groupByDate = items => {
17
+ const grouped = {};
18
+ items.forEach(item => {
19
+ const date = new Date(item.created_at).toLocaleDateString();
20
+ if (!grouped[date]) {
21
+ grouped[date] = [];
22
+ }
23
+ grouped[date]?.push(item);
24
+ });
25
+ return grouped;
26
+ };
27
+ const fetchData = (params = {}) => {
28
+ const search = new URLSearchParams();
29
+ Object.keys(params).forEach(key => {
30
+ search.set(key, String(params[key]));
31
+ });
32
+ return _api.default.get(`/api/invoices?${search.toString()}`).then(res => res.data);
33
+ };
34
+ const pageSize = 10;
35
+ function CustomerInvoiceList({
36
+ customer_id
37
+ }) {
38
+ const {
39
+ t
40
+ } = (0, _context.useLocaleContext)();
41
+ const {
42
+ data,
43
+ loadMore,
44
+ loadingMore,
45
+ loading
46
+ } = (0, _ahooks.useInfiniteScroll)(d => {
47
+ const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
48
+ return fetchData({
49
+ page,
50
+ pageSize,
51
+ status: "open,paid,uncollectible",
52
+ customer_id
53
+ });
54
+ }, {
55
+ reloadDeps: [customer_id]
56
+ });
57
+ if (loading || !data) {
58
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {});
59
+ }
60
+ if (data && data.list.length === 0) {
61
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
62
+ color: "text.secondary",
63
+ children: t("payment.customer.invoice.empty")
64
+ });
65
+ }
66
+ const hasMore = data && data.list.length < data.count;
67
+ const grouped = groupByDate(data.list);
68
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
69
+ direction: "column",
70
+ gap: 1,
71
+ sx: {
72
+ mt: 1
73
+ },
74
+ children: [Object.entries(grouped).map(([date, invoices]) => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
75
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
76
+ sx: {
77
+ fontWeight: "bold",
78
+ color: "text.secondary",
79
+ mt: 2,
80
+ mb: 1
81
+ },
82
+ children: date
83
+ }), invoices.map(invoice => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
84
+ direction: {
85
+ xs: "column",
86
+ sm: "row"
87
+ },
88
+ sx: {
89
+ my: 1
90
+ },
91
+ gap: {
92
+ xs: 0.5,
93
+ sm: 1.5,
94
+ md: 3
95
+ },
96
+ flexWrap: "nowrap",
97
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
98
+ flex: 3,
99
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)("a", {
100
+ href: `/customer/invoice/${invoice.id}`,
101
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
102
+ component: "span",
103
+ children: invoice.number
104
+ })
105
+ })
106
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
107
+ flex: 3,
108
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
109
+ children: (0, _util2.formatToDate)(invoice.created_at)
110
+ })
111
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
112
+ flex: 2,
113
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
114
+ textAlign: "right",
115
+ children: [(0, _util.fromUnitToToken)(invoice.total, invoice.paymentCurrency.decimal), "\xA0", invoice.paymentCurrency.symbol]
116
+ })
117
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
118
+ flex: 2,
119
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
120
+ label: invoice.status,
121
+ color: (0, _util2.getInvoiceStatusColor)(invoice.status)
122
+ })
123
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
124
+ flex: 4,
125
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
126
+ children: invoice.description || invoice.id
127
+ })
128
+ })]
129
+ }, invoice.id))]
130
+ }, date)), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
131
+ children: [hasMore && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
132
+ variant: "text",
133
+ type: "button",
134
+ color: "inherit",
135
+ onClick: loadMore,
136
+ disabled: loadingMore,
137
+ children: loadingMore ? t("common.loadingMore", {
138
+ resource: t("payment.customer.invoices")
139
+ }) : t("common.loadMore", {
140
+ resource: t("payament.customer.invoices")
141
+ })
142
+ }), !hasMore && data.count > pageSize && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
143
+ color: "text.secondary",
144
+ children: t("common.noMore", {
145
+ resource: t("payment.customer.invoices")
146
+ })
147
+ })]
148
+ })]
149
+ });
150
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ customer_id: string;
4
+ };
5
+ export default function CustomerPaymentList({ customer_id }: Props): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = CustomerPaymentList;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _context = require("@arcblock/ux/lib/Locale/context");
9
+ var _material = require("@mui/material");
10
+ var _util = require("@ocap/util");
11
+ var _ahooks = require("ahooks");
12
+ var _api = _interopRequireDefault(require("../../api"));
13
+ var _status = _interopRequireDefault(require("../../components/status"));
14
+ var _util2 = require("../../util");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ const groupByDate = items => {
17
+ const grouped = {};
18
+ items.forEach(item => {
19
+ const date = new Date(item.created_at).toLocaleDateString();
20
+ if (!grouped[date]) {
21
+ grouped[date] = [];
22
+ }
23
+ grouped[date]?.push(item);
24
+ });
25
+ return grouped;
26
+ };
27
+ const fetchData = (params = {}) => {
28
+ const search = new URLSearchParams();
29
+ Object.keys(params).forEach(key => {
30
+ search.set(key, String(params[key]));
31
+ });
32
+ return _api.default.get(`/api/payment-intents?${search.toString()}`).then(res => res.data);
33
+ };
34
+ const pageSize = 10;
35
+ function CustomerPaymentList({
36
+ customer_id
37
+ }) {
38
+ const {
39
+ t
40
+ } = (0, _context.useLocaleContext)();
41
+ const {
42
+ data,
43
+ loadMore,
44
+ loadingMore,
45
+ loading
46
+ } = (0, _ahooks.useInfiniteScroll)(d => {
47
+ const page = d ? Math.ceil(d.list.length / pageSize) + 1 : 1;
48
+ return fetchData({
49
+ page,
50
+ pageSize,
51
+ customer_id
52
+ });
53
+ }, {
54
+ reloadDeps: [customer_id]
55
+ });
56
+ if (loading || !data) {
57
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {});
58
+ }
59
+ if (data && data.list.length === 0) {
60
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
61
+ color: "text.secondary",
62
+ children: t("payment.customer.payment.empty")
63
+ });
64
+ }
65
+ const hasMore = data && data.list.length < data.count;
66
+ const grouped = groupByDate(data.list);
67
+ return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
68
+ direction: "column",
69
+ gap: 1,
70
+ sx: {
71
+ mt: 1
72
+ },
73
+ children: [Object.entries(grouped).map(([date, payments]) => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
74
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
75
+ sx: {
76
+ fontWeight: "bold",
77
+ color: "text.secondary",
78
+ mt: 2,
79
+ mb: 1
80
+ },
81
+ children: date
82
+ }), payments.map(item => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
83
+ direction: {
84
+ xs: "column",
85
+ sm: "row"
86
+ },
87
+ sx: {
88
+ my: 1
89
+ },
90
+ gap: {
91
+ xs: 0.5,
92
+ sm: 1.5,
93
+ md: 3
94
+ },
95
+ flexWrap: "nowrap",
96
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
97
+ flex: 3,
98
+ sx: {
99
+ minWidth: "220px"
100
+ },
101
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
102
+ component: "span",
103
+ children: item.id
104
+ })
105
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
106
+ flex: 3,
107
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
108
+ children: (0, _util2.formatToDate)(item.created_at)
109
+ })
110
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
111
+ flex: 2,
112
+ children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
113
+ textAlign: "right",
114
+ children: [(0, _util.fromUnitToToken)(item.amount, item.paymentCurrency.decimal), "\xA0", item.paymentCurrency.symbol]
115
+ })
116
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
117
+ flex: 3,
118
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_status.default, {
119
+ label: item.status,
120
+ color: (0, _util2.getPaymentIntentStatusColor)(item.status)
121
+ })
122
+ }), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
123
+ flex: 4,
124
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
125
+ children: item.description || item.id
126
+ })
127
+ })]
128
+ }, item.id))]
129
+ }, date)), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
130
+ children: [hasMore && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Button, {
131
+ variant: "text",
132
+ type: "button",
133
+ color: "inherit",
134
+ onClick: loadMore,
135
+ disabled: loadingMore,
136
+ children: loadingMore ? t("common.loadingMore", {
137
+ resource: t("payment.customer.payments")
138
+ }) : t("common.loadMore", {
139
+ resource: t("payment.customer.payments")
140
+ })
141
+ }), !hasMore && data.count > pageSize && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
142
+ color: "text.secondary",
143
+ children: t("common.noMore", {
144
+ resource: t("payment.customer.payments")
145
+ })
146
+ })]
147
+ })]
148
+ });
149
+ }
package/lib/util.d.ts CHANGED
@@ -20,6 +20,10 @@ export declare function formatLineItemPricing(item: TLineItemExpanded, currency:
20
20
  secondary?: string;
21
21
  quantity: string;
22
22
  };
23
+ export declare function getSubscriptionStatusColor(status: string): "success" | "primary" | "warning" | "error" | "default";
24
+ export declare function getPaymentIntentStatusColor(status: string): "success" | "warning" | "default";
25
+ export declare function getInvoiceStatusColor(status: string): "success" | "warning" | "default" | "secondary";
26
+ export declare function getWebhookStatusColor(status: string): "success" | "default";
23
27
  export declare function getCheckoutAmount(items: TLineItemExpanded[], currency: TPaymentCurrency, includeFreeTrial?: boolean, upsell?: boolean): {
24
28
  subtotal: any;
25
29
  total: any;
package/lib/util.js CHANGED
@@ -17,12 +17,17 @@ exports.formatToDate = formatToDate;
17
17
  exports.formatToDatetime = formatToDatetime;
18
18
  exports.formatUpsellSaving = formatUpsellSaving;
19
19
  exports.getCheckoutAmount = getCheckoutAmount;
20
+ exports.getInvoiceStatusColor = getInvoiceStatusColor;
21
+ exports.getPaymentIntentStatusColor = getPaymentIntentStatusColor;
20
22
  exports.getPrefix = void 0;
21
23
  exports.getPriceCurrencyOptions = getPriceCurrencyOptions;
22
24
  exports.getPriceUintAmountByCurrency = getPriceUintAmountByCurrency;
23
25
  exports.getRecurringPeriod = getRecurringPeriod;
24
26
  exports.getStatementDescriptor = getStatementDescriptor;
25
- exports.getSubscriptionTimeSummary = exports.getSubscriptionAction = void 0;
27
+ exports.getSubscriptionAction = void 0;
28
+ exports.getSubscriptionStatusColor = getSubscriptionStatusColor;
29
+ exports.getSubscriptionTimeSummary = void 0;
30
+ exports.getWebhookStatusColor = getWebhookStatusColor;
26
31
  exports.isValidCountry = isValidCountry;
27
32
  exports.mergeExtraParams = void 0;
28
33
  exports.sleep = sleep;
@@ -218,6 +223,62 @@ function formatLineItemPricing(item, currency, trial, locale = "en") {
218
223
  quantity
219
224
  };
220
225
  }
226
+ function getSubscriptionStatusColor(status) {
227
+ switch (status) {
228
+ case "active":
229
+ return "success";
230
+ case "trialing":
231
+ return "primary";
232
+ case "incomplete":
233
+ case "incomplete_expired":
234
+ case "paused":
235
+ return "warning";
236
+ case "past_due":
237
+ case "unpaid":
238
+ return "error";
239
+ case "canceled":
240
+ default:
241
+ return "default";
242
+ }
243
+ }
244
+ function getPaymentIntentStatusColor(status) {
245
+ switch (status) {
246
+ case "succeeded":
247
+ return "success";
248
+ case "requires_payment_method":
249
+ case "requires_confirmation":
250
+ case "requires_action":
251
+ case "requires_capture":
252
+ return "warning";
253
+ case "canceled":
254
+ case "processing":
255
+ default:
256
+ return "default";
257
+ }
258
+ }
259
+ function getInvoiceStatusColor(status) {
260
+ switch (status) {
261
+ case "paid":
262
+ return "success";
263
+ case "open":
264
+ return "secondary";
265
+ case "uncollectible":
266
+ return "warning";
267
+ case "draft":
268
+ case "void":
269
+ default:
270
+ return "default";
271
+ }
272
+ }
273
+ function getWebhookStatusColor(status) {
274
+ switch (status) {
275
+ case "enabled":
276
+ return "success";
277
+ case "disabled":
278
+ default:
279
+ return "default";
280
+ }
281
+ }
221
282
  function getCheckoutAmount(items, currency, includeFreeTrial = false, upsell = true) {
222
283
  let renew = new _util.BN(0);
223
284
  const total = items.reduce((acc, x) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.123",
3
+ "version": "1.13.125",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -89,7 +89,7 @@
89
89
  "@babel/core": "^7.19.3",
90
90
  "@babel/preset-env": "^7.19.3",
91
91
  "@babel/preset-react": "^7.18.6",
92
- "@blocklet/payment-types": "1.13.123",
92
+ "@blocklet/payment-types": "1.13.125",
93
93
  "@storybook/addon-essentials": "^7.6.10",
94
94
  "@storybook/addon-interactions": "^7.6.10",
95
95
  "@storybook/addon-links": "^7.6.10",
@@ -118,5 +118,5 @@
118
118
  "vite-plugin-babel": "^1.2.0",
119
119
  "vite-plugin-node-polyfills": "^0.19.0"
120
120
  },
121
- "gitHead": "ea37183dafcf5a89c0593886aa895b33eccf8529"
121
+ "gitHead": "6242d03d1b13c6e0d2875637db232dd8927207b6"
122
122
  }
package/src/api.ts CHANGED
@@ -9,8 +9,8 @@ const api = axios.create();
9
9
  api.interceptors.request.use(
10
10
  (config) => {
11
11
  const prefix = getPrefix();
12
+ // 'https://storage.staging.abtnet.io/app/payment-kit/.well-known/service'
12
13
  config.baseURL = prefix || '';
13
- config.timeout = 8000;
14
14
 
15
15
  const livemode = localStorage.getItem('livemode');
16
16
  const locale = getLocale(window.blocklet?.languages);
@@ -0,0 +1,39 @@
1
+ import { Confirm } from '@arcblock/ux/lib/Dialog';
2
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
+ import { Typography } from '@mui/material';
4
+ import type { EventHandler } from 'react';
5
+
6
+ export default function ConfirmDialog({
7
+ onConfirm,
8
+ onCancel,
9
+ title,
10
+ message,
11
+ loading,
12
+ }: {
13
+ onConfirm: EventHandler<any>;
14
+ onCancel: EventHandler<any>;
15
+ title: string | React.ReactNode;
16
+ message: string | React.ReactNode;
17
+ loading?: boolean;
18
+ }) {
19
+ const { t } = useLocaleContext();
20
+
21
+ return (
22
+ <Confirm
23
+ open
24
+ title={title}
25
+ onConfirm={onConfirm}
26
+ onCancel={onCancel}
27
+ confirmButton={{
28
+ text: t('common.confirm'),
29
+ props: { color: 'error', size: 'small', variant: 'contained', disabled: !!loading },
30
+ }}
31
+ cancelButton={{ text: t('common.cancel'), props: { color: 'inherit', size: 'small' } }}>
32
+ <Typography>{message}</Typography>
33
+ </Confirm>
34
+ );
35
+ }
36
+
37
+ ConfirmDialog.defaultProps = {
38
+ loading: false,
39
+ };