payment-kit 1.18.34 → 1.18.35

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.
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.18.34
17
+ version: 1.18.35
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.18.34",
3
+ "version": "1.18.35",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -54,7 +54,7 @@
54
54
  "@arcblock/validator": "^1.20.2",
55
55
  "@blocklet/js-sdk": "^1.16.42",
56
56
  "@blocklet/logger": "^1.16.42",
57
- "@blocklet/payment-react": "1.18.34",
57
+ "@blocklet/payment-react": "1.18.35",
58
58
  "@blocklet/sdk": "^1.16.42",
59
59
  "@blocklet/ui-react": "^2.13.12",
60
60
  "@blocklet/uploader": "^0.1.83",
@@ -122,7 +122,7 @@
122
122
  "devDependencies": {
123
123
  "@abtnode/types": "^1.16.42",
124
124
  "@arcblock/eslint-config-ts": "^0.3.3",
125
- "@blocklet/payment-types": "1.18.34",
125
+ "@blocklet/payment-types": "1.18.35",
126
126
  "@types/cookie-parser": "^1.4.7",
127
127
  "@types/cors": "^2.8.17",
128
128
  "@types/debug": "^4.1.12",
@@ -168,5 +168,5 @@
168
168
  "parser": "typescript"
169
169
  }
170
170
  },
171
- "gitHead": "0ddb7c08956891409919c8027b56b77eba1726d4"
171
+ "gitHead": "802a98b5ca81475f8cd7b9dcbb77fce7240b9788"
172
172
  }
package/scripts/sdk.js CHANGED
@@ -69,16 +69,72 @@ const checkoutModule = {
69
69
  subscription_data: {
70
70
  no_stake: true,
71
71
  },
72
+ });
73
+ console.log('createBatchSubscription', checkoutSession);
74
+ return checkoutSession;
75
+ },
76
+
77
+ // 批量订阅 + 免质押 + 自定义表单规则
78
+ async createBatchSubscriptionWithCustomField() {
79
+ const checkoutSession = await payment.checkout.sessions.create({
80
+ mode: 'subscription',
81
+ line_items: [
82
+ {
83
+ price_id: 'price_fQFIS12yi0JR3KePLmitjrhA',
84
+ quantity: 1,
85
+ subscription_data: {
86
+ metadata: { test: 'test price_fQFIS12yi0JR3KePLmitjrhA' },
87
+ },
88
+ },
89
+ {
90
+ price_id: 'price_PXyI9Duz99eqty1AqbaEc73u',
91
+ quantity: 1,
92
+ subscription_data: {
93
+ metadata: { test: 'test price_PXyI9Duz99eqty1AqbaEc73u' },
94
+ },
95
+ },
96
+ ],
97
+ enable_subscription_grouping: true,
98
+ subscription_data: {
99
+ no_stake: true,
100
+ },
101
+ phone_number_collection: {
102
+ enabled: true,
103
+ },
104
+ billing_address_collection: 'required',
72
105
  metadata: {
73
106
  page_info: {
74
107
  form_purpose_description: {
75
108
  en: 'Information collected helps us process your payment and deliver our services.',
76
109
  zh: '收集的信息帮助我们处理您的付款并提供服务。',
77
110
  },
111
+ field_validation: {
112
+ customer_name: {
113
+ pattern: '^[a-zA-Z\\s]{2,50}$',
114
+ pattern_message: {
115
+ en: 'Name should only contain 2-50 letters and spaces',
116
+ zh: '姓名应只包含2-50个字母和空格',
117
+ },
118
+ },
119
+ customer_email: {
120
+ pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
121
+ pattern_message: {
122
+ en: 'Please enter a valid email address',
123
+ zh: '请输入有效的电子邮件地址',
124
+ },
125
+ },
126
+ 'billing_address.line1': {
127
+ pattern: '^.{5,100}$',
128
+ pattern_message: {
129
+ en: 'Address should be 5-100 characters',
130
+ zh: '地址应为5-100个字符',
131
+ },
132
+ },
133
+ },
78
134
  },
79
135
  },
80
136
  });
81
- console.log('createBatchSubscription', checkoutSession);
137
+ console.log('createBatchSubscriptionWithCustomField', checkoutSession);
82
138
  return checkoutSession;
83
139
  },
84
140
 
@@ -469,7 +525,7 @@ const testModules = {
469
525
 
470
526
  async function runTest() {
471
527
  payment.environments.setTestMode(true);
472
- await testModules.checkout.createBatchSubscription();
528
+ await testModules.checkout.createBatchSubscriptionWithCustomField();
473
529
  }
474
530
 
475
531
  async function main() {
@@ -1,17 +1,13 @@
1
1
  import type { TCustomer } from '@blocklet/payment-types';
2
2
  import { Link } from 'react-router-dom';
3
-
3
+ import UserCard from '@arcblock/ux/lib/UserCard';
4
4
  import { getCustomerAvatar } from '@blocklet/payment-react';
5
- import DID from '@arcblock/ux/lib/DID';
6
- import { Box, Typography } from '@mui/material';
7
- import InfoCard from '../info-card';
8
5
 
9
6
  export default function CustomerLink({
10
7
  customer,
11
8
  linked,
12
9
  linkTo,
13
10
  size,
14
- tooltip,
15
11
  }: {
16
12
  customer: TCustomer;
17
13
  linked?: boolean;
@@ -22,61 +18,40 @@ export default function CustomerLink({
22
18
  if (!customer) {
23
19
  return null;
24
20
  }
21
+ const CustomerCard = (
22
+ // @ts-ignore
23
+ <UserCard
24
+ did={customer?.did}
25
+ showHoverCard
26
+ sx={{
27
+ border: 'none',
28
+ p: 0,
29
+ minWidth: 0,
30
+ }}
31
+ avatarProps={{
32
+ size: size === 'small' ? 24 : 40,
33
+ }}
34
+ showDid={size !== 'small'}
35
+ {...(customer.metadata.anonymous === true
36
+ ? {
37
+ user: {
38
+ fullName: customer.name || customer.email,
39
+ did: customer.did,
40
+ email: customer.email,
41
+ avatar: getCustomerAvatar(
42
+ customer?.did,
43
+ customer?.updated_at ? new Date(customer.updated_at).toISOString() : ''
44
+ ),
45
+ },
46
+ }
47
+ : {})}
48
+ />
49
+ );
25
50
  if (linked) {
26
- return (
27
- <Link to={linkTo || `/admin/customers/${customer.id}`}>
28
- <Box sx={{ '.info-card-wrapper': { cursor: 'pointer' }, '.info-card': { minWidth: 0 } }}>
29
- {/* @ts-ignore */}
30
- <InfoCard
31
- logo={getCustomerAvatar(
32
- customer?.did,
33
- customer?.updated_at ? new Date(customer.updated_at).toISOString() : '',
34
- size === 'small' ? 24 : 48
35
- )}
36
- name={
37
- <Typography
38
- sx={{ maxWidth: 208, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}
39
- className="customer-link-name">
40
- {customer.name || customer.email}
41
- </Typography>
42
- }
43
- {...(size === 'small'
44
- ? { tooltip: tooltip ? <DID did={customer?.did} /> : false, size: 24 }
45
- : {
46
- description: <DID did={customer?.did} compact responsive={false} sx={{ whiteSpace: 'nowrap' }} />,
47
- size: 48,
48
- })}
49
- />
50
- </Box>
51
- </Link>
52
- );
51
+ return <Link to={linkTo || `/admin/customers/${customer.id}`}>{CustomerCard}</Link>;
53
52
  }
54
53
 
55
- return (
56
- <Box sx={{ '.info-card': { minWidth: 0 } }}>
57
- {/* @ts-ignore */}
58
- <InfoCard
59
- logo={getCustomerAvatar(
60
- customer.did,
61
- customer.updated_at ? new Date(customer.updated_at).toISOString() : '',
62
- size === 'small' ? 24 : 48
63
- )}
64
- name={
65
- <Typography
66
- sx={{ maxWidth: 320, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}
67
- className="customer-link-name">
68
- {customer.name || customer.email}
69
- </Typography>
70
- }
71
- {...(size === 'small'
72
- ? { tooltip: tooltip ? <DID did={customer?.did} /> : false, size: 24 }
73
- : {
74
- description: <DID did={customer?.did} compact responsive={false} sx={{ whiteSpace: 'nowrap' }} />,
75
- size: 48,
76
- })}
77
- />
78
- </Box>
79
- );
54
+ return CustomerCard;
80
55
  }
81
56
 
82
57
  CustomerLink.defaultProps = {
@@ -282,7 +282,7 @@ export default function InvoiceList({
282
282
  options: {
283
283
  customBodyRenderLite: (_: string, index: number) => {
284
284
  const item = data.list[index] as TInvoiceExpanded;
285
- return <CustomerLink customer={item.customer} />;
285
+ return <CustomerLink customer={item.customer} size="small" />;
286
286
  },
287
287
  },
288
288
  });
@@ -15,6 +15,8 @@ import { useLocalStorageState } from 'ahooks';
15
15
  import { useEffect, useState } from 'react';
16
16
  import { Link } from 'react-router-dom';
17
17
 
18
+ import DID from '@arcblock/ux/lib/DID';
19
+ import ShortenLabel from '@arcblock/ux/lib/UserCard/Content/shorten-label';
18
20
  import { debounce, getAppInfo } from '../../libs/util';
19
21
  import CustomerLink from '../customer/link';
20
22
  import FilterToolbar from '../filter-toolbar';
@@ -202,8 +204,12 @@ export default function PayoutList({ customer_id, payment_intent_id, status, fea
202
204
  if (appInfo) {
203
205
  return (
204
206
  <InfoCard
205
- name={appInfo.name}
206
- description={`${item.destination.slice(0, 6)}...${item.destination.slice(-6)}`}
207
+ name={
208
+ <ShortenLabel sx={{ fontWeight: 500 }} maxLength={30}>
209
+ {appInfo.name}
210
+ </ShortenLabel>
211
+ }
212
+ description={<DID did={item.destination} compact responsive={false} sx={{ whiteSpace: 'nowrap' }} />}
207
213
  logo={appInfo.avatar}
208
214
  size={40}
209
215
  />
package/src/libs/util.ts CHANGED
@@ -3,14 +3,12 @@
3
3
  /* eslint-disable @typescript-eslint/indent */
4
4
  import { formatCheckoutHeadlines, formatPrice, getPrefix, getPriceCurrencyOptions } from '@blocklet/payment-react';
5
5
  import type {
6
- ChainType,
7
6
  LineItem,
8
7
  PriceRecurring,
9
8
  TInvoiceExpanded,
10
9
  TLineItemExpanded,
11
10
  TPaymentCurrency,
12
11
  TPaymentLinkExpanded,
13
- TPaymentMethod,
14
12
  TPaymentMethodExpanded,
15
13
  TPrice,
16
14
  TProductExpanded,
@@ -350,17 +348,6 @@ export function getAppInfo(address: string): { name: string; avatar: string; typ
350
348
  return null;
351
349
  }
352
350
 
353
- export function getTokenBalanceLink(method: TPaymentMethod, address: string) {
354
- const explorerHost = (method?.settings?.[method?.type as ChainType] as any)?.explorer_host || '';
355
- if (method.type === 'arcblock' && address) {
356
- return joinURL(explorerHost, 'accounts', address, 'tokens');
357
- }
358
- if (['ethereum', 'base'].includes(method.type) && address) {
359
- return joinURL(explorerHost, 'address', address);
360
- }
361
- return '';
362
- }
363
-
364
351
  export function isWillCanceled(subscription: TSubscriptionExpanded) {
365
352
  const now = Date.now() / 1000;
366
353
  if (
@@ -211,8 +211,8 @@ export default function CustomerDetail(props: { id: string }) {
211
211
  52
212
212
  )}
213
213
  alt={data.customer.name}
214
- variant="square"
215
- sx={{ width: 52, height: 52, borderRadius: 'var(--radius-s, 4px)' }}
214
+ variant="circular"
215
+ sx={{ width: 52, height: 52 }}
216
216
  />
217
217
  <Typography variant="h2" sx={{ fontWeight: 600 }}>
218
218
  {data.customer.name}
@@ -75,9 +75,8 @@ export default function CustomersList() {
75
75
  item?.updated_at ? new Date(item.updated_at).toISOString() : '',
76
76
  48
77
77
  )}
78
- variant="square"
78
+ variant="circular"
79
79
  alt={item?.name}
80
- sx={{ borderRadius: 'var(--radius-m, 8px)' }}
81
80
  />
82
81
  <Typography sx={{ wordBreak: 'break-all' }}>{item.name}</Typography>
83
82
  </Stack>
@@ -203,6 +203,7 @@ export default function PayoutDetail(props: { id: string }) {
203
203
  label={t('customer.payout.payer')}
204
204
  value={
205
205
  <InfoCard
206
+ variant="circular"
206
207
  logo={getCustomerAvatar(
207
208
  paymentIntent?.customer?.did,
208
209
  paymentIntent?.customer?.updated_at
@@ -242,7 +243,6 @@ export default function PayoutDetail(props: { id: string }) {
242
243
  />
243
244
  }
244
245
  size={40}
245
- variant="rounded"
246
246
  />
247
247
  }
248
248
  divider
@@ -27,6 +27,7 @@ import {
27
27
  formatBNStr,
28
28
  formatPrice,
29
29
  formatNumber,
30
+ getTokenBalanceLink,
30
31
  } from '@blocklet/payment-react';
31
32
  import type { TPaymentCurrency, TPaymentMethod } from '@blocklet/payment-types';
32
33
  import { joinURL } from 'ufo';
@@ -34,7 +35,7 @@ import { AccountBalanceWalletOutlined, ArrowBackOutlined, ArrowForwardOutlined }
34
35
  import Empty from '@arcblock/ux/lib/Empty';
35
36
  import { BN, fromUnitToToken } from '@ocap/util';
36
37
  import RechargeList from '../../../components/invoice/recharge';
37
- import { getTokenBalanceLink, goBackOrFallback } from '../../../libs/util';
38
+ import { goBackOrFallback } from '../../../libs/util';
38
39
  import { useSessionContext } from '../../../contexts/session';
39
40
  import { formatSmartDuration, TimeUnit } from '../../../libs/dayjs';
40
41
 
@@ -25,6 +25,7 @@ import {
25
25
  formatTime,
26
26
  api,
27
27
  formatBNStr,
28
+ getTokenBalanceLink,
28
29
  } from '@blocklet/payment-react';
29
30
  import { joinURL } from 'ufo';
30
31
  import type { TSubscriptionExpanded } from '@blocklet/payment-types';
@@ -35,7 +36,7 @@ import SubscriptionDescription from '../../../components/subscription/descriptio
35
36
  import InfoRow from '../../../components/info-row';
36
37
  import Currency from '../../../components/currency';
37
38
  import SubscriptionMetrics from '../../../components/subscription/metrics';
38
- import { getTokenBalanceLink, goBackOrFallback } from '../../../libs/util';
39
+ import { goBackOrFallback } from '../../../libs/util';
39
40
  import CustomerLink from '../../../components/customer/link';
40
41
  import { useSessionContext } from '../../../contexts/session';
41
42
  import { formatSmartDuration, TimeUnit } from '../../../libs/dayjs';
@@ -229,6 +229,7 @@ export default function SubscriptionEmbed() {
229
229
  </Stack>
230
230
  }
231
231
  size={24}
232
+ variant="circular"
232
233
  />
233
234
  ),
234
235
  });