@blocklet/payment-react 1.14.23 → 1.14.25
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/es/checkout/donate.js +26 -3
- package/es/libs/util.d.ts +15 -2
- package/es/libs/util.js +44 -9
- package/es/locales/en.js +3 -2
- package/es/locales/zh.js +3 -2
- package/es/payment/form/currency.js +0 -10
- package/es/payment/index.js +1 -14
- package/es/payment/product-donation.js +24 -14
- package/es/payment/product-item.d.ts +3 -1
- package/es/payment/product-item.js +8 -4
- package/es/payment/summary.d.ts +3 -1
- package/es/payment/summary.js +7 -3
- package/lib/checkout/donate.js +19 -4
- package/lib/libs/util.d.ts +15 -2
- package/lib/libs/util.js +61 -9
- package/lib/locales/en.js +3 -2
- package/lib/locales/zh.js +3 -2
- package/lib/payment/form/currency.js +0 -10
- package/lib/payment/index.js +1 -14
- package/lib/payment/product-donation.js +3 -2
- package/lib/payment/product-item.d.ts +3 -1
- package/lib/payment/product-item.js +11 -4
- package/lib/payment/summary.d.ts +3 -1
- package/lib/payment/summary.js +10 -3
- package/package.json +3 -3
- package/src/checkout/donate.tsx +25 -2
- package/src/libs/util.ts +53 -10
- package/src/locales/en.tsx +3 -2
- package/src/locales/zh.tsx +3 -2
- package/src/payment/form/currency.tsx +0 -10
- package/src/payment/index.tsx +2 -14
- package/src/payment/product-donation.tsx +7 -2
- package/src/payment/product-item.tsx +8 -3
- package/src/payment/summary.tsx +7 -2
package/src/locales/zh.tsx
CHANGED
|
@@ -62,9 +62,10 @@ export default flat({
|
|
|
62
62
|
continue: '继续',
|
|
63
63
|
qty: '{count} 件',
|
|
64
64
|
each: '每件 {unit}',
|
|
65
|
-
trial: '免费试用 {count}
|
|
65
|
+
trial: '免费试用 {count} {interval}',
|
|
66
66
|
billed: '{rule}收费',
|
|
67
67
|
metered: '按用量',
|
|
68
|
+
minute: '分钟',
|
|
68
69
|
hour: '小时',
|
|
69
70
|
day: '天',
|
|
70
71
|
week: '周',
|
|
@@ -135,7 +136,7 @@ export default flat({
|
|
|
135
136
|
then: '然后 {subscription} {recurring}',
|
|
136
137
|
meteredThen: '然后{recurring}按用量计费',
|
|
137
138
|
metered: '{recurring}按用量计费',
|
|
138
|
-
free: '免费试用 {count}
|
|
139
|
+
free: '免费试用 {count} {interval}',
|
|
139
140
|
least: '至少',
|
|
140
141
|
completed: {
|
|
141
142
|
payment: '感谢您的购买',
|
|
@@ -63,16 +63,6 @@ const Root = styled<any>('section')`
|
|
|
63
63
|
background: var(--backgrounds-bg-field, #f9fafb);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// .cko-payment-card::before {
|
|
67
|
-
// content: '';
|
|
68
|
-
// position: absolute;
|
|
69
|
-
// right: 0;
|
|
70
|
-
// bottom: 0;
|
|
71
|
-
// border: 12px solid ${(props) => props.theme.palette.primary.main};
|
|
72
|
-
// border-top-color: transparent;
|
|
73
|
-
// border-left-color: transparent;
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
66
|
.cko-payment-card-unselect {
|
|
77
67
|
border: 1px solid #ddd;
|
|
78
68
|
padding: 4px 8px;
|
package/src/payment/index.tsx
CHANGED
|
@@ -155,6 +155,7 @@ function PaymentInner({
|
|
|
155
155
|
setState({ checkoutSession: result.checkoutSession });
|
|
156
156
|
onPaid(result);
|
|
157
157
|
};
|
|
158
|
+
|
|
158
159
|
return (
|
|
159
160
|
<FormProvider {...methods}>
|
|
160
161
|
<Stack className="cko-container" sx={{ gap: { sm: mode === 'standalone' ? 0 : mode === 'inline' ? 4 : 8 } }}>
|
|
@@ -164,6 +165,7 @@ function PaymentInner({
|
|
|
164
165
|
<PaymentSummary
|
|
165
166
|
items={state.checkoutSession.line_items}
|
|
166
167
|
trialInDays={state.checkoutSession.subscription_data?.trial_period_days || 0}
|
|
168
|
+
trialEnd={state.checkoutSession.subscription_data?.trial_end || 0}
|
|
167
169
|
billingThreshold={Math.max(
|
|
168
170
|
state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
169
171
|
// @ts-ignore
|
|
@@ -376,23 +378,18 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
376
378
|
box-sizing: border-box;
|
|
377
379
|
display: flex;
|
|
378
380
|
flex-direction: column;
|
|
379
|
-
// justify-content: center;
|
|
380
381
|
align-items: center;
|
|
381
382
|
overflow: hidden;
|
|
382
|
-
// min-height: ${(props) => (props.mode === 'standalone' ? '100vh' : 'auto')};
|
|
383
383
|
position: relative;
|
|
384
384
|
.cko-container {
|
|
385
385
|
overflow: hidden;
|
|
386
386
|
width: 100%;
|
|
387
|
-
// max-width: ${(props) => (props.mode.endsWith('-minimal') ? '400px' : '1000px')};
|
|
388
387
|
display: flex;
|
|
389
388
|
flex-direction: row;
|
|
390
389
|
justify-content: center;
|
|
391
|
-
// gap: 4px;
|
|
392
390
|
position: relative;
|
|
393
391
|
flex: 1;
|
|
394
392
|
padding: 1px;
|
|
395
|
-
// padding: ${(props) => (props.mode === 'standalone' ? '0 16px' : '0')};
|
|
396
393
|
}
|
|
397
394
|
|
|
398
395
|
.base-card {
|
|
@@ -405,14 +402,11 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
405
402
|
}
|
|
406
403
|
|
|
407
404
|
.cko-overview {
|
|
408
|
-
// width: ${(props) => (props.mode.endsWith('-minimal') ? '100%' : '400px')};
|
|
409
|
-
// min-height: ${(props) => (props.mode === 'standalone' ? '540px' : 'auto')};
|
|
410
405
|
position: relative;
|
|
411
406
|
flex-direction: column;
|
|
412
407
|
display: ${(props) => (props.mode.endsWith('-minimal') ? 'none' : 'flex')};
|
|
413
408
|
background: var(--backgrounds-bg-base);
|
|
414
409
|
min-height: 'auto';
|
|
415
|
-
// width: 502px;
|
|
416
410
|
}
|
|
417
411
|
.cko-header {
|
|
418
412
|
left: 0;
|
|
@@ -440,8 +434,6 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
440
434
|
|
|
441
435
|
.cko-payment {
|
|
442
436
|
width: 502px;
|
|
443
|
-
// width: ${(props) => (props.mode.endsWith('-minimal') ? '100%' : '400px')};
|
|
444
|
-
// box-shadow: -4px 0px 8px 0px rgba(2, 7, 19, 0.04);
|
|
445
437
|
padding-left: ${(props) => (props.mode === 'standalone' ? '40px' : '20px')};
|
|
446
438
|
position: relative;
|
|
447
439
|
&:before {
|
|
@@ -466,10 +458,6 @@ export const Root = styled(Box)<{ mode: LiteralUnion<'standalone' | 'inline' | '
|
|
|
466
458
|
}
|
|
467
459
|
|
|
468
460
|
.cko-payment-form {
|
|
469
|
-
// .MuiInputAdornment-positionStart {
|
|
470
|
-
// width: 50px;
|
|
471
|
-
// }
|
|
472
|
-
|
|
473
461
|
.MuiFormLabel-root {
|
|
474
462
|
color: var(--foregrounds-fg-base, #010714);
|
|
475
463
|
font-weight: 500;
|
|
@@ -99,11 +99,16 @@ export default function ProductDonation({
|
|
|
99
99
|
...(state.selected === amount && !state.custom ? { borderColor: 'primary.main' } : {}),
|
|
100
100
|
}}>
|
|
101
101
|
<CardActionArea onClick={() => handleSelect(amount)}>
|
|
102
|
-
<Stack
|
|
102
|
+
<Stack
|
|
103
|
+
direction="row"
|
|
104
|
+
sx={{ py: 1, px: 0.5 }}
|
|
105
|
+
spacing={0.5}
|
|
106
|
+
alignItems="flex-end"
|
|
107
|
+
justifyContent="center">
|
|
103
108
|
<Typography
|
|
104
109
|
component="strong"
|
|
105
110
|
lineHeight={1}
|
|
106
|
-
variant="
|
|
111
|
+
variant="h3"
|
|
107
112
|
sx={{ fontVariantNumeric: 'tabular-nums', fontWeight: 400 }}>
|
|
108
113
|
{amount}
|
|
109
114
|
</Typography>
|
|
@@ -13,11 +13,13 @@ import {
|
|
|
13
13
|
formatUpsellSaving,
|
|
14
14
|
} from '../libs/util';
|
|
15
15
|
import ProductCard from './product-card';
|
|
16
|
+
import dayjs from '../libs/dayjs';
|
|
16
17
|
|
|
17
18
|
type Props = {
|
|
18
19
|
item: TLineItemExpanded;
|
|
19
20
|
items: TLineItemExpanded[];
|
|
20
21
|
trialInDays: number;
|
|
22
|
+
trialEnd?: number;
|
|
21
23
|
currency: TPaymentCurrency;
|
|
22
24
|
onUpsell: Function;
|
|
23
25
|
onDownsell: Function;
|
|
@@ -28,12 +30,14 @@ type Props = {
|
|
|
28
30
|
ProductItem.defaultProps = {
|
|
29
31
|
mode: 'normal',
|
|
30
32
|
children: null,
|
|
33
|
+
trialEnd: 0,
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export default function ProductItem({
|
|
34
37
|
item,
|
|
35
38
|
items,
|
|
36
39
|
trialInDays,
|
|
40
|
+
trialEnd = 0,
|
|
37
41
|
currency,
|
|
38
42
|
mode,
|
|
39
43
|
children,
|
|
@@ -41,18 +45,19 @@ export default function ProductItem({
|
|
|
41
45
|
onDownsell,
|
|
42
46
|
}: Props) {
|
|
43
47
|
const { t, locale } = useLocaleContext();
|
|
44
|
-
const pricing = formatLineItemPricing(item, currency, trialInDays, locale);
|
|
48
|
+
const pricing = formatLineItemPricing(item, currency, { trialEnd, trialInDays }, locale);
|
|
45
49
|
const saving = formatUpsellSaving(items, currency);
|
|
46
50
|
const metered = item.price?.recurring?.usage_type === 'metered' ? t('common.metered') : '';
|
|
47
51
|
const canUpsell = mode === 'normal' && items.length === 1;
|
|
48
52
|
const primaryText = useMemo(() => {
|
|
49
53
|
const price = item.upsell_price || item.price || {};
|
|
50
54
|
const isRecurring = price?.type === 'recurring' && price?.recurring;
|
|
51
|
-
|
|
55
|
+
const trial = trialInDays > 0 || trialEnd > dayjs().unix();
|
|
56
|
+
if (isRecurring && !trial && price?.recurring?.usage_type !== 'metered') {
|
|
52
57
|
return `${pricing.primary} ${price.recurring ? formatRecurring(price.recurring, false, 'slash', locale) : ''}`;
|
|
53
58
|
}
|
|
54
59
|
return pricing.primary;
|
|
55
|
-
}, [trialInDays, pricing, item, locale]);
|
|
60
|
+
}, [trialInDays, trialEnd, pricing, item, locale]);
|
|
56
61
|
|
|
57
62
|
return (
|
|
58
63
|
<Stack direction="column" alignItems="flex-start" spacing={1} sx={{ width: '100%' }} className="product-item">
|
package/src/payment/summary.tsx
CHANGED
|
@@ -67,6 +67,7 @@ type Props = {
|
|
|
67
67
|
items: TLineItemExpanded[];
|
|
68
68
|
currency: TPaymentCurrency;
|
|
69
69
|
trialInDays: number;
|
|
70
|
+
trialEnd?: number;
|
|
70
71
|
billingThreshold: number;
|
|
71
72
|
showStaking?: boolean;
|
|
72
73
|
onUpsell?: Function;
|
|
@@ -131,6 +132,7 @@ PaymentSummary.defaultProps = {
|
|
|
131
132
|
showStaking: false,
|
|
132
133
|
donationSettings: null,
|
|
133
134
|
action: '',
|
|
135
|
+
trialEnd: 0,
|
|
134
136
|
};
|
|
135
137
|
|
|
136
138
|
export default function PaymentSummary({
|
|
@@ -148,6 +150,7 @@ export default function PaymentSummary({
|
|
|
148
150
|
showStaking,
|
|
149
151
|
donationSettings,
|
|
150
152
|
action,
|
|
153
|
+
trialEnd = 0,
|
|
151
154
|
...rest
|
|
152
155
|
}: Props) {
|
|
153
156
|
const { t, locale } = useLocaleContext();
|
|
@@ -157,7 +160,7 @@ export default function PaymentSummary({
|
|
|
157
160
|
const { data, runAsync } = useRequest(() =>
|
|
158
161
|
checkoutSessionId ? fetchCrossSell(checkoutSessionId) : Promise.resolve(null)
|
|
159
162
|
);
|
|
160
|
-
const headlines = formatCheckoutHeadlines(items, currency, trialInDays, locale);
|
|
163
|
+
const headlines = formatCheckoutHeadlines(items, currency, { trialEnd, trialInDays }, locale);
|
|
161
164
|
const staking = showStaking ? getStakingSetup(items, currency, billingThreshold) : '0';
|
|
162
165
|
const totalAmount = fromUnitToToken(
|
|
163
166
|
new BN(fromTokenToUnit(headlines.actualAmount, currency?.decimal)).add(new BN(staking)).toString(),
|
|
@@ -231,6 +234,7 @@ export default function PaymentSummary({
|
|
|
231
234
|
item={x}
|
|
232
235
|
items={items}
|
|
233
236
|
trialInDays={trialInDays}
|
|
237
|
+
trialEnd={trialEnd}
|
|
234
238
|
currency={currency}
|
|
235
239
|
onUpsell={handleUpsell}
|
|
236
240
|
onDownsell={handleDownsell}>
|
|
@@ -260,6 +264,7 @@ export default function PaymentSummary({
|
|
|
260
264
|
items={items}
|
|
261
265
|
trialInDays={trialInDays}
|
|
262
266
|
currency={currency}
|
|
267
|
+
trialEnd={trialEnd}
|
|
263
268
|
onUpsell={noop}
|
|
264
269
|
onDownsell={noop}>
|
|
265
270
|
<Stack direction="row" alignItems="center" justifyContent="space-between" sx={{ width: 1 }}>
|
|
@@ -303,7 +308,7 @@ export default function PaymentSummary({
|
|
|
303
308
|
</Typography>
|
|
304
309
|
{!settings.livemode && <Livemode />}
|
|
305
310
|
</Box>
|
|
306
|
-
{isMobile ? (
|
|
311
|
+
{isMobile && !donationSettings ? (
|
|
307
312
|
<>
|
|
308
313
|
<Stack
|
|
309
314
|
justifyContent="space-between"
|