payment-kit 1.13.294 → 1.13.296

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.
@@ -28,7 +28,7 @@ export default {
28
28
  const { checkoutSessionId, connectedDid } = extraParams;
29
29
  const { paymentIntent, paymentCurrency, paymentMethod } = await ensurePaymentIntent(
30
30
  checkoutSessionId,
31
- userDid || connectedDid
31
+ connectedDid || userDid
32
32
  );
33
33
  if (!paymentIntent) {
34
34
  throw new Error('Payment intent not found');
@@ -88,7 +88,7 @@ export default {
88
88
  const { checkoutSessionId, connectedDid } = extraParams;
89
89
  const { checkoutSession, customer, paymentIntent, paymentMethod } = await ensurePaymentIntent(
90
90
  checkoutSessionId,
91
- userDid || connectedDid
91
+ connectedDid || userDid
92
92
  );
93
93
  if (!paymentIntent) {
94
94
  throw new Error('Payment intent not found');
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.13.294
17
+ version: 1.13.296
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.13.294",
3
+ "version": "1.13.296",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -52,7 +52,7 @@
52
52
  "@arcblock/validator": "^1.18.124",
53
53
  "@blocklet/js-sdk": "1.16.28",
54
54
  "@blocklet/logger": "1.16.28",
55
- "@blocklet/payment-react": "1.13.294",
55
+ "@blocklet/payment-react": "1.13.296",
56
56
  "@blocklet/sdk": "1.16.28",
57
57
  "@blocklet/ui-react": "^2.10.3",
58
58
  "@blocklet/uploader": "^0.1.18",
@@ -118,7 +118,7 @@
118
118
  "devDependencies": {
119
119
  "@abtnode/types": "1.16.28",
120
120
  "@arcblock/eslint-config-ts": "^0.3.2",
121
- "@blocklet/payment-types": "1.13.294",
121
+ "@blocklet/payment-types": "1.13.296",
122
122
  "@types/cookie-parser": "^1.4.7",
123
123
  "@types/cors": "^2.8.17",
124
124
  "@types/debug": "^4.1.12",
@@ -158,5 +158,5 @@
158
158
  "parser": "typescript"
159
159
  }
160
160
  },
161
- "gitHead": "94e507a512252badd0ee5b537cba5a1d52cc061b"
161
+ "gitHead": "e0f0556ce4ed8833464248e00250c09dbde2c5a9"
162
162
  }
@@ -112,7 +112,9 @@ export default function PriceForm({ prefix, simple }: PriceFormProps) {
112
112
  <FormLabel>{t('admin.price.model')}</FormLabel>
113
113
  <Select {...field} fullWidth size="small">
114
114
  <MenuItem value="standard">{t('admin.price.models.standard')}</MenuItem>
115
- <MenuItem value="package">{t('admin.price.models.package')}</MenuItem>
115
+ <MenuItem value="package" disabled>
116
+ {t('admin.price.models.package')}
117
+ </MenuItem>
116
118
  <MenuItem value="graduated" disabled>
117
119
  {t('admin.price.models.graduated')}
118
120
  </MenuItem>
@@ -1,7 +1,8 @@
1
+ import { useState } from 'react';
1
2
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
3
  import { usePaymentContext } from '@blocklet/payment-react';
3
4
  import type { TProductExpanded } from '@blocklet/payment-types';
4
- import { MenuItem, Select, Stack, Typography } from '@mui/material';
5
+ import { FormControl, MenuItem, Select, Stack, Typography } from '@mui/material';
5
6
 
6
7
  import { useProductsContext } from '../../contexts/products';
7
8
  import { formatProductPrice } from '../../libs/util';
@@ -10,42 +11,47 @@ import InfoCard from '../info-card';
10
11
  type Props = {
11
12
  data: TProductExpanded;
12
13
  onSelect: Function;
14
+ valid: boolean;
13
15
  };
14
16
 
15
- export default function CrossSellSelect({ data, onSelect }: Props) {
17
+ export default function CrossSellSelect({ data, onSelect, valid }: Props) {
16
18
  const { t, locale } = useLocaleContext();
17
19
  const { products } = useProductsContext();
18
20
  const { settings } = usePaymentContext();
21
+ const [value, setValue] = useState('empty');
19
22
 
20
23
  const onSelectPrice = (e: any) => {
21
24
  if (e.target.value && e.target.value !== 'empty') {
25
+ setValue(e.target.value);
22
26
  onSelect(e.target.value);
23
27
  }
24
28
  };
25
29
 
26
30
  return (
27
- <Select
28
- value="empty"
29
- sx={{ width: 300 }}
30
- size="small"
31
- onChange={onSelectPrice}
32
- MenuProps={{ style: { maxHeight: 480 } }}>
33
- <MenuItem value="empty">
34
- <Stack direction="row" alignItems="center">
35
- <Typography>{t('admin.product.find')}</Typography>
36
- </Stack>
37
- </MenuItem>
38
- {products
39
- .filter((x) => x.id !== data.id)
40
- .map((x) => (
41
- <MenuItem key={x.id} value={x.id}>
42
- <InfoCard
43
- name={x.name}
44
- description={formatProductPrice(x as any, settings.baseCurrency, locale)}
45
- logo={x.images[0]}
46
- />
47
- </MenuItem>
48
- ))}
49
- </Select>
31
+ <FormControl error={!valid}>
32
+ <Select
33
+ value={value}
34
+ sx={{ minWidth: 300 }}
35
+ size="small"
36
+ onChange={onSelectPrice}
37
+ MenuProps={{ style: { maxHeight: 480 } }}>
38
+ <MenuItem value="empty">
39
+ <Stack direction="row" alignItems="center">
40
+ <Typography>{t('admin.product.find')}</Typography>
41
+ </Stack>
42
+ </MenuItem>
43
+ {products
44
+ .filter((x) => x.id !== data.id)
45
+ .map((x: TProductExpanded) => (
46
+ <MenuItem key={x.id} value={x.id}>
47
+ <InfoCard
48
+ name={x.name}
49
+ description={formatProductPrice(x as any, settings.baseCurrency, locale)}
50
+ logo={x.images[0]}
51
+ />
52
+ </MenuItem>
53
+ ))}
54
+ </Select>
55
+ </FormControl>
50
56
  );
51
57
  }
@@ -3,21 +3,23 @@ import Toast from '@arcblock/ux/lib/Toast';
3
3
  import { api, formatError, usePaymentContext } from '@blocklet/payment-react';
4
4
  import type { TProductExpanded } from '@blocklet/payment-types';
5
5
  import { DeleteOutlineOutlined } from '@mui/icons-material';
6
- import { CircularProgress, Grid, IconButton, Stack } from '@mui/material';
6
+ import { CircularProgress, Grid, IconButton, Stack, Typography } from '@mui/material';
7
7
  import { useSetState } from 'ahooks';
8
-
9
- import { ProductsProvider } from '../../contexts/products';
10
- import { formatProductPrice } from '../../libs/util';
8
+ import { useState } from 'react';
9
+ import { ProductsProvider, useProductsContext } from '../../contexts/products';
10
+ import { formatProductPrice, isProductCurrenciesMatched } from '../../libs/util';
11
11
  import InfoCard from '../info-card';
12
12
  import InfoRow from '../info-row';
13
13
  import CrossSellSelect from './cross-sell-select';
14
14
 
15
15
  export function CrossSellForm({ data, onChange }: { data: TProductExpanded; onChange: Function }) {
16
- const { locale } = useLocaleContext();
16
+ const { locale, t } = useLocaleContext();
17
17
  const { settings } = usePaymentContext();
18
18
  const [state, setState] = useSetState({
19
19
  loading: false,
20
20
  });
21
+ const { products } = useProductsContext();
22
+ const [crossSellErr, setCrossSellErr] = useState(false);
21
23
 
22
24
  const onRemoveUpsell = async () => {
23
25
  try {
@@ -34,6 +36,14 @@ export function CrossSellForm({ data, onChange }: { data: TProductExpanded; onCh
34
36
 
35
37
  const onSelectUpsell = async (id: string) => {
36
38
  try {
39
+ const upsellProduct = products.find((x) => x.id === id);
40
+ if (!upsellProduct) {
41
+ throw new Error('no product found');
42
+ }
43
+ if (!isProductCurrenciesMatched(upsellProduct, data)) {
44
+ setCrossSellErr(true);
45
+ return;
46
+ }
37
47
  setState({ loading: true });
38
48
  await api.put(`/api/products/${data.id}`, { cross_sell: { cross_sells_to_id: id } }).then((res) => res.data);
39
49
  setState({ loading: false });
@@ -65,7 +75,12 @@ export function CrossSellForm({ data, onChange }: { data: TProductExpanded; onCh
65
75
  );
66
76
  }
67
77
 
68
- return <CrossSellSelect data={data} onSelect={onSelectUpsell} />;
78
+ return (
79
+ <>
80
+ <CrossSellSelect data={data} onSelect={onSelectUpsell} valid={!crossSellErr} />
81
+ {crossSellErr && <Typography color="error">{t('admin.product.currencyNotAligned')}</Typography>}
82
+ </>
83
+ );
69
84
  }
70
85
 
71
86
  export default function ProductCrossSell({ data, onChange }: { data: TProductExpanded; onChange: Function }) {
package/src/libs/util.ts CHANGED
@@ -76,6 +76,25 @@ export function getWebhookStatusColor(status: string) {
76
76
  }
77
77
  }
78
78
 
79
+ export function getDefaultPriceCurrencyIdsFromProduct(product: TProductExpanded): string[] {
80
+ return (
81
+ product.prices.find((price) => price.id === product.default_price_id)?.currency_options.map((x) => x.currency_id) ||
82
+ []
83
+ );
84
+ }
85
+
86
+ // Checks if the currencies of the products in the list match up to a certain index
87
+ export function isProductCurrenciesMatched(productA: TProductExpanded, productB: TProductExpanded): boolean {
88
+ const currenciesA = getDefaultPriceCurrencyIdsFromProduct(productA);
89
+
90
+ const currenciesB = getDefaultPriceCurrencyIdsFromProduct(productB);
91
+
92
+ return (
93
+ currenciesA.every((currencyId) => currenciesB.includes(currencyId)) &&
94
+ currenciesB.every((currencyId) => currenciesA.includes(currencyId))
95
+ );
96
+ }
97
+
79
98
  export function isPriceCurrencyAligned(list: LineItem[], products: TProductExpanded[], index: number) {
80
99
  const prices = list.map((x) => {
81
100
  const product = getProductByPriceId(products, x.price_id);
@@ -64,6 +64,7 @@ export default flat({
64
64
  archivedTip:
65
65
  'This product can’t be added to new invoices, subscriptions, payment links, or pricing tables. Any existing subscriptions with this product remain active until canceled and any existing payment links or pricing tables are deactivated.',
66
66
  locked: 'This product is locked because at least one of its prices is used by a subscription or a payment.',
67
+ currencyNotAligned: 'all prices must have the same currency settings',
67
68
  image: {
68
69
  label: 'Image',
69
70
  add: 'Add image',
@@ -63,6 +63,7 @@ export default flat({
63
63
  archivedTip:
64
64
  '此产品无法添加到新的账单、订阅、支付链接或定价表。具有此产品的任何现有订阅将保持活动状态,直到取消,任何现有的支付链接或定价表将被停用。',
65
65
  locked: '此产品已锁定,因为至少有一个价格用于订阅或支付。',
66
+ currencyNotAligned: '所有价格必须具有相同的货币设置',
66
67
  image: {
67
68
  label: '图片',
68
69
  add: '添加图片',