payment-kit 1.16.3 → 1.16.5

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 (36) hide show
  1. package/api/src/libs/api.ts +5 -0
  2. package/api/src/libs/session.ts +7 -1
  3. package/api/src/libs/util.ts +20 -0
  4. package/api/src/routes/connect/collect-batch.ts +65 -24
  5. package/api/src/routes/prices.ts +10 -7
  6. package/api/src/routes/pricing-table.ts +14 -2
  7. package/api/src/routes/subscriptions.ts +60 -1
  8. package/api/src/store/models/price.ts +1 -0
  9. package/blocklet.yml +1 -1
  10. package/package.json +17 -17
  11. package/src/components/filter-toolbar.tsx +41 -17
  12. package/src/components/layout/admin.tsx +2 -1
  13. package/src/components/payment-link/after-pay.tsx +1 -1
  14. package/src/components/payment-link/before-pay.tsx +6 -0
  15. package/src/components/payment-link/item.tsx +5 -2
  16. package/src/components/payment-link/product-select.tsx +4 -3
  17. package/src/components/price/currency-select.tsx +59 -6
  18. package/src/components/price/form.tsx +71 -14
  19. package/src/components/price/upsell-select.tsx +1 -1
  20. package/src/components/price/upsell.tsx +4 -2
  21. package/src/components/pricing-table/payment-settings.tsx +10 -7
  22. package/src/components/pricing-table/price-item.tsx +3 -2
  23. package/src/components/pricing-table/product-settings.tsx +2 -0
  24. package/src/components/product/cross-sell-select.tsx +7 -4
  25. package/src/components/product/cross-sell.tsx +5 -2
  26. package/src/components/section/header.tsx +3 -2
  27. package/src/components/subscription/list.tsx +4 -0
  28. package/src/pages/admin/products/links/create.tsx +1 -0
  29. package/src/pages/admin/products/links/detail.tsx +10 -4
  30. package/src/pages/admin/products/links/index.tsx +3 -2
  31. package/src/pages/admin/products/prices/list.tsx +19 -4
  32. package/src/pages/admin/products/pricing-tables/create.tsx +13 -4
  33. package/src/pages/admin/products/pricing-tables/detail.tsx +4 -2
  34. package/src/pages/admin/products/products/create.tsx +5 -2
  35. package/src/pages/admin/products/products/detail.tsx +26 -4
  36. package/src/pages/admin/products/products/index.tsx +4 -2
@@ -220,14 +220,16 @@ export default function PricingTableDetail(props: { id: string }) {
220
220
  sort: false,
221
221
  customBodyRenderLite: (_: any, index: number) => {
222
222
  const item = data.items[index] as any;
223
+ const itemCurrency = data?.currency || settings.baseCurrency;
223
224
  return (
224
- <Link to={`/admin/products/${item.product_id}`}>
225
+ <Link
226
+ to={`/admin/products/${item.product_id}?currency_id=${itemCurrency?.id}&price_id=${item.price.id}`}>
225
227
  <InfoCard
226
228
  name={item.product.name}
227
229
  description={formatProductPrice(
228
230
  // @ts-ignore
229
231
  { ...item.product, prices: [item.price] },
230
- settings.baseCurrency,
232
+ itemCurrency,
231
233
  locale
232
234
  )}
233
235
  logo={item.product.images[0]}
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
3
  import Toast from '@arcblock/ux/lib/Toast';
4
- import { api, formatError, formatPrice, usePaymentContext } from '@blocklet/payment-react';
4
+ import { api, findCurrency, formatError, formatPrice, usePaymentContext } from '@blocklet/payment-react';
5
5
  import { AddOutlined } from '@mui/icons-material';
6
6
  import { Box, Button, Divider, Typography } from '@mui/material';
7
7
  import { cloneDeep } from 'lodash';
@@ -83,9 +83,12 @@ export default function ProductsCreate() {
83
83
  if (expanded) {
84
84
  return t('admin.price.detail');
85
85
  }
86
+ const priceItem = getPrice(index);
87
+ const currency =
88
+ findCurrency(settings.paymentMethods, priceItem?.currency_id || '') || settings.baseCurrency;
86
89
 
87
90
  // @ts-ignore
88
- return formatPrice(getPrice(index), settings.baseCurrency, getValues().unit_label, 1, false, locale);
91
+ return formatPrice(priceItem as any, currency, getValues().unit_label, 1, false, locale);
89
92
  }}>
90
93
  <PriceForm prefix={`prices.${index}`} />
91
94
  </Collapse>
@@ -1,8 +1,8 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
2
  import Toast from '@arcblock/ux/lib/Toast';
3
- import { api, formatError, formatTime, useMobile, usePaymentContext } from '@blocklet/payment-react';
3
+ import { api, findCurrency, formatError, formatTime, useMobile, usePaymentContext } from '@blocklet/payment-react';
4
4
  import type { TPrice, TProduct, TProductExpanded } from '@blocklet/payment-types';
5
- import { ArrowBackOutlined } from '@mui/icons-material';
5
+ import { ArrowBackOutlined, InfoOutlined } from '@mui/icons-material';
6
6
  import {
7
7
  Alert,
8
8
  AlertTitle,
@@ -13,6 +13,7 @@ import {
13
13
  Divider,
14
14
  Grid,
15
15
  Stack,
16
+ Tooltip,
16
17
  Typography,
17
18
  } from '@mui/material';
18
19
  import { styled } from '@mui/system';
@@ -114,6 +115,9 @@ export default function ProductDetail(props: { id: string }) {
114
115
  setState((prev) => ({ editing: { ...prev.editing, metadata: true } }));
115
116
  };
116
117
 
118
+ const defaultCurrency =
119
+ findCurrency(settings.paymentMethods, data?.default_price?.currency_id) || settings.baseCurrency;
120
+
117
121
  return (
118
122
  <Root direction="column" spacing={2.5} sx={{ mb: 4 }}>
119
123
  <Box>
@@ -173,7 +177,7 @@ export default function ProductDetail(props: { id: string }) {
173
177
  {data.name}
174
178
  </Typography>
175
179
  <Typography variant="subtitle1" color="text.lighter">
176
- {formatProductPrice(data as any, settings.baseCurrency, locale)}
180
+ {formatProductPrice(data as any, defaultCurrency, locale)}
177
181
  </Typography>
178
182
  </Stack>
179
183
  </Stack>
@@ -372,7 +376,25 @@ export default function ProductDetail(props: { id: string }) {
372
376
  {isMobile && <Divider />}
373
377
  <Box className="payment-link-column-2" sx={{ gap: 2.5, display: 'flex', flexDirection: 'column' }}>
374
378
  <Box className="section">
375
- <SectionHeader title={t('admin.product.cross_sell.title')} />
379
+ <SectionHeader
380
+ title={
381
+ <Stack direction="row" alignItems="center" spacing={1}>
382
+ <Typography
383
+ variant="h3"
384
+ sx={{
385
+ fontSize: {
386
+ xs: '18px',
387
+ md: '1.25rem',
388
+ },
389
+ }}>
390
+ {t('admin.product.cross_sell.title')}
391
+ </Typography>
392
+ <Tooltip title={t('admin.product.currencyNotAligned')}>
393
+ <InfoOutlined sx={{ color: 'text.lighter' }} fontSize="small" />
394
+ </Tooltip>
395
+ </Stack>
396
+ }
397
+ />
376
398
  <Box className="section-body">
377
399
  <ProductCrossSell data={data} onChange={runAsync} />
378
400
  </Box>
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable react/no-unstable-nested-components */
2
2
  import { getDurableData } from '@arcblock/ux/lib/Datatable';
3
3
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
4
- import { Status, api, formatTime, usePaymentContext, Table } from '@blocklet/payment-react';
4
+ import { Status, api, formatTime, usePaymentContext, Table, findCurrency } from '@blocklet/payment-react';
5
5
  import type { TProductExpanded } from '@blocklet/payment-types';
6
6
  import { CircularProgress } from '@mui/material';
7
7
  import { useEffect, useState } from 'react';
@@ -75,11 +75,13 @@ export default function ProductsList() {
75
75
  filter: true,
76
76
  customBodyRenderLite: (_: string, index: number) => {
77
77
  const item = data.list[index] as TProductExpanded;
78
+ const currency =
79
+ findCurrency(settings.paymentMethods, item.prices[0]?.currency_id ?? '') || settings.baseCurrency;
78
80
  return (
79
81
  <Link to={`/admin/products/${item.id}`}>
80
82
  <InfoCard
81
83
  name={item.name}
82
- description={formatProductPrice(item as any, settings.baseCurrency, locale)}
84
+ description={formatProductPrice(item as any, currency!, locale)}
83
85
  logo={item.images[0]}
84
86
  />
85
87
  </Link>