@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/es/checkout/donate.js
CHANGED
|
@@ -211,7 +211,16 @@ function useDonation(settings, livemode = true, mode = "default") {
|
|
|
211
211
|
setState
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
|
-
function CheckoutDonateInner({
|
|
214
|
+
function CheckoutDonateInner({
|
|
215
|
+
settings,
|
|
216
|
+
livemode,
|
|
217
|
+
timeout,
|
|
218
|
+
onPaid,
|
|
219
|
+
onError,
|
|
220
|
+
mode,
|
|
221
|
+
inlineOptions = {},
|
|
222
|
+
theme
|
|
223
|
+
}) {
|
|
215
224
|
const { state, setState, donation, supporters } = useDonation(settings, livemode, mode);
|
|
216
225
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
217
226
|
const [popoverOpen, setPopoverOpen] = useState(false);
|
|
@@ -340,15 +349,29 @@ function CheckoutDonateInner({ settings, livemode, timeout, onPaid, onError, mod
|
|
|
340
349
|
maxWidth: "md",
|
|
341
350
|
showCloseButton: true,
|
|
342
351
|
disableEscapeKeyDown: true,
|
|
352
|
+
sx: {
|
|
353
|
+
".MuiDialogContent-root": {
|
|
354
|
+
padding: {
|
|
355
|
+
xs: 0,
|
|
356
|
+
md: "0 16px 0"
|
|
357
|
+
},
|
|
358
|
+
borderTop: "1px solid var(--stroke-border-base, #EFF1F5)",
|
|
359
|
+
width: {
|
|
360
|
+
xs: "100%",
|
|
361
|
+
md: 900
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
},
|
|
343
365
|
onClose: (e, reason) => setState({ open: reason === "backdropClick" }),
|
|
344
|
-
children: /* @__PURE__ */ jsx(Box, { sx: {
|
|
366
|
+
children: /* @__PURE__ */ jsx(Box, { sx: { height: "100%", width: "100%" }, children: /* @__PURE__ */ jsx(
|
|
345
367
|
CheckoutForm,
|
|
346
368
|
{
|
|
347
369
|
id: donation.data?.id,
|
|
348
370
|
onPaid: handlePaid,
|
|
349
371
|
onError,
|
|
350
372
|
action: settings.appearance?.button?.text,
|
|
351
|
-
mode: "inline"
|
|
373
|
+
mode: "inline",
|
|
374
|
+
theme
|
|
352
375
|
}
|
|
353
376
|
) })
|
|
354
377
|
}
|
package/es/libs/util.d.ts
CHANGED
|
@@ -19,7 +19,10 @@ export declare function getStatementDescriptor(items: any[]): any;
|
|
|
19
19
|
export declare function formatRecurring(recurring: PriceRecurring, translate?: boolean, separator?: string, locale?: string): string;
|
|
20
20
|
export declare function getPriceUintAmountByCurrency(price: TPrice, currency: TPaymentCurrency): string;
|
|
21
21
|
export declare function getPriceCurrencyOptions(price: TPrice): PriceCurrency[];
|
|
22
|
-
export declare function formatLineItemPricing(item: TLineItemExpanded, currency: TPaymentCurrency,
|
|
22
|
+
export declare function formatLineItemPricing(item: TLineItemExpanded, currency: TPaymentCurrency, { trialEnd, trialInDays }: {
|
|
23
|
+
trialEnd: number;
|
|
24
|
+
trialInDays: number;
|
|
25
|
+
}, locale?: string): {
|
|
23
26
|
primary: string;
|
|
24
27
|
secondary?: string;
|
|
25
28
|
quantity: string;
|
|
@@ -47,7 +50,17 @@ export declare function formatPriceDisplay({ amount, then, actualAmount, showThe
|
|
|
47
50
|
actualAmount: string;
|
|
48
51
|
showThen?: boolean;
|
|
49
52
|
}, recurring: string, hasMetered: boolean, locale?: string): string;
|
|
50
|
-
export declare function
|
|
53
|
+
export declare function getFreeTrialTime({ trialInDays, trialEnd }: {
|
|
54
|
+
trialInDays: number;
|
|
55
|
+
trialEnd: number;
|
|
56
|
+
}, locale?: string): {
|
|
57
|
+
count: number;
|
|
58
|
+
interval: string;
|
|
59
|
+
};
|
|
60
|
+
export declare function formatCheckoutHeadlines(items: TLineItemExpanded[], currency: TPaymentCurrency, { trialInDays, trialEnd }: {
|
|
61
|
+
trialInDays: number;
|
|
62
|
+
trialEnd: number;
|
|
63
|
+
}, locale?: string): {
|
|
51
64
|
action: string;
|
|
52
65
|
amount: string;
|
|
53
66
|
then?: string;
|
package/es/libs/util.js
CHANGED
|
@@ -202,7 +202,7 @@ export function getPriceCurrencyOptions(price) {
|
|
|
202
202
|
}
|
|
203
203
|
];
|
|
204
204
|
}
|
|
205
|
-
export function formatLineItemPricing(item, currency,
|
|
205
|
+
export function formatLineItemPricing(item, currency, { trialEnd, trialInDays }, locale = "en") {
|
|
206
206
|
const price = item.upsell_price || item.price;
|
|
207
207
|
let quantity = t("common.qty", locale, { count: item.quantity });
|
|
208
208
|
if (price.recurring?.usage_type === "metered" || +item.quantity === 1) {
|
|
@@ -211,6 +211,7 @@ export function formatLineItemPricing(item, currency, trial, locale = "en") {
|
|
|
211
211
|
const unitValue = new BN(getPriceUintAmountByCurrency(price, currency));
|
|
212
212
|
const total = `${fromUnitToToken(unitValue.mul(new BN(item.quantity)), currency.decimal)} ${currency.symbol}`;
|
|
213
213
|
const unit = `${fromUnitToToken(unitValue, currency.decimal)} ${currency.symbol}`;
|
|
214
|
+
const trialResult = getFreeTrialTime({ trialInDays, trialEnd }, locale);
|
|
214
215
|
const appendUnit = (v, alt) => {
|
|
215
216
|
if (price.product.unit_label) {
|
|
216
217
|
return `${v}/${price.product.unit_label}`;
|
|
@@ -221,9 +222,9 @@ export function formatLineItemPricing(item, currency, trial, locale = "en") {
|
|
|
221
222
|
return quantity ? t("common.each", locale, { unit }) : "";
|
|
222
223
|
};
|
|
223
224
|
if (price.type === "recurring" && price.recurring) {
|
|
224
|
-
if (
|
|
225
|
+
if (trialResult.count > 0) {
|
|
225
226
|
return {
|
|
226
|
-
primary: t("common.trial", locale, { count:
|
|
227
|
+
primary: t("common.trial", locale, { count: trialResult.count, interval: trialResult.interval }),
|
|
227
228
|
secondary: `${appendUnit(total, total)} ${formatRecurring(price.recurring, false, "slash", locale)}`,
|
|
228
229
|
quantity
|
|
229
230
|
};
|
|
@@ -415,11 +416,43 @@ export function formatPriceDisplay({ amount, then, actualAmount, showThen }, rec
|
|
|
415
416
|
}
|
|
416
417
|
return [amount, then].filter(Boolean).join(" ");
|
|
417
418
|
}
|
|
418
|
-
export function
|
|
419
|
+
export function getFreeTrialTime({ trialInDays, trialEnd }, locale = "en") {
|
|
420
|
+
const now = dayjs().unix();
|
|
421
|
+
if (trialEnd > 0 && trialEnd > now) {
|
|
422
|
+
if (trialEnd - now < 3600) {
|
|
423
|
+
return {
|
|
424
|
+
count: Math.ceil((trialEnd - now) / 60),
|
|
425
|
+
interval: t("common.minute", locale)
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (trialEnd - now < 86400) {
|
|
429
|
+
return {
|
|
430
|
+
count: Math.ceil((trialEnd - now) / 3600),
|
|
431
|
+
interval: t("common.hour", locale)
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
return {
|
|
435
|
+
count: Math.ceil((trialEnd - now) / 86400),
|
|
436
|
+
interval: t("common.day", locale)
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
if (trialInDays > 0) {
|
|
440
|
+
return {
|
|
441
|
+
count: trialInDays,
|
|
442
|
+
interval: t("common.day", locale)
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
return {
|
|
446
|
+
count: 0,
|
|
447
|
+
interval: t("common.day", locale)
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
export function formatCheckoutHeadlines(items, currency, { trialInDays, trialEnd }, locale = "en") {
|
|
419
451
|
const brand = getStatementDescriptor(items);
|
|
420
452
|
const { total } = getCheckoutAmount(items, currency, trialInDays > 0);
|
|
421
453
|
const actualAmount = fromUnitToToken(total, currency.decimal);
|
|
422
454
|
const amount = `${fromUnitToToken(total, currency.decimal)} ${currency.symbol}`;
|
|
455
|
+
const trialResult = getFreeTrialTime({ trialInDays, trialEnd }, locale);
|
|
423
456
|
if (items.length === 0) {
|
|
424
457
|
return {
|
|
425
458
|
action: t("payment.checkout.empty", locale),
|
|
@@ -453,17 +486,19 @@ export function formatCheckoutHeadlines(items, currency, trialInDays, locale = "
|
|
|
453
486
|
if (x.price.recurring?.usage_type === "metered") {
|
|
454
487
|
return acc;
|
|
455
488
|
}
|
|
456
|
-
return acc.add(
|
|
489
|
+
return acc.add(
|
|
490
|
+
new BN(getPriceUintAmountByCurrency(x.upsell_price || x.price, currency)).mul(new BN(x.quantity))
|
|
491
|
+
);
|
|
457
492
|
}, new BN(0)),
|
|
458
493
|
currency.decimal
|
|
459
494
|
),
|
|
460
495
|
currency.symbol
|
|
461
496
|
].filter(Boolean).join(" ");
|
|
462
497
|
if (items.length > 1) {
|
|
463
|
-
if (
|
|
498
|
+
if (trialResult.count > 0) {
|
|
464
499
|
const result4 = {
|
|
465
500
|
action: t("payment.checkout.try2", locale, { name, count: items.length - 1 }),
|
|
466
|
-
amount: t("payment.checkout.free", locale, { count:
|
|
501
|
+
amount: t("payment.checkout.free", locale, { count: trialResult.count, interval: trialResult.interval }),
|
|
467
502
|
then: formatMeteredThen(subscription2, recurring, hasMetered && Number(subscription2) === 0, locale),
|
|
468
503
|
showThen: true,
|
|
469
504
|
actualAmount: "0"
|
|
@@ -485,10 +520,10 @@ export function formatCheckoutHeadlines(items, currency, trialInDays, locale = "
|
|
|
485
520
|
priceDisplay: formatPriceDisplay(result3, recurring, hasMetered, locale)
|
|
486
521
|
};
|
|
487
522
|
}
|
|
488
|
-
if (
|
|
523
|
+
if (trialResult.count > 0) {
|
|
489
524
|
const result3 = {
|
|
490
525
|
action: t("payment.checkout.try1", locale, { name }),
|
|
491
|
-
amount: t("payment.checkout.free", locale, { count:
|
|
526
|
+
amount: t("payment.checkout.free", locale, { count: trialResult.count, interval: trialResult.interval }),
|
|
492
527
|
then: formatMeteredThen(subscription2, recurring, hasMetered && Number(subscription2) === 0, locale),
|
|
493
528
|
showThen: true,
|
|
494
529
|
actualAmount: "0"
|
package/es/locales/en.js
CHANGED
|
@@ -60,9 +60,10 @@ export default flat({
|
|
|
60
60
|
continue: "Continue",
|
|
61
61
|
qty: "Qty {count}",
|
|
62
62
|
each: "{unit} each",
|
|
63
|
-
trial: "Free for {count}
|
|
63
|
+
trial: "Free for {count} {interval}{count > 1 ? 's' : ''}",
|
|
64
64
|
billed: "billed {rule}",
|
|
65
65
|
metered: "based on usage",
|
|
66
|
+
minute: "minute",
|
|
66
67
|
hour: "hour",
|
|
67
68
|
day: "day",
|
|
68
69
|
week: "week",
|
|
@@ -133,7 +134,7 @@ export default flat({
|
|
|
133
134
|
then: "Then {subscription} {recurring}",
|
|
134
135
|
meteredThen: "Then {recurring} based on usage",
|
|
135
136
|
metered: "{recurring} based on usage",
|
|
136
|
-
free: "{count}
|
|
137
|
+
free: "{count} {interval}{count > 1 ? 's' : ''} free",
|
|
137
138
|
least: "continue with at least",
|
|
138
139
|
completed: {
|
|
139
140
|
payment: "Thanks for your purchase",
|
package/es/locales/zh.js
CHANGED
|
@@ -60,9 +60,10 @@ export default flat({
|
|
|
60
60
|
continue: "\u7EE7\u7EED",
|
|
61
61
|
qty: "{count} \u4EF6",
|
|
62
62
|
each: "\u6BCF\u4EF6 {unit}",
|
|
63
|
-
trial: "\u514D\u8D39\u8BD5\u7528 {count}
|
|
63
|
+
trial: "\u514D\u8D39\u8BD5\u7528 {count} {interval}",
|
|
64
64
|
billed: "{rule}\u6536\u8D39",
|
|
65
65
|
metered: "\u6309\u7528\u91CF",
|
|
66
|
+
minute: "\u5206\u949F",
|
|
66
67
|
hour: "\u5C0F\u65F6",
|
|
67
68
|
day: "\u5929",
|
|
68
69
|
week: "\u5468",
|
|
@@ -133,7 +134,7 @@ export default flat({
|
|
|
133
134
|
then: "\u7136\u540E {subscription} {recurring}",
|
|
134
135
|
meteredThen: "\u7136\u540E{recurring}\u6309\u7528\u91CF\u8BA1\u8D39",
|
|
135
136
|
metered: "{recurring}\u6309\u7528\u91CF\u8BA1\u8D39",
|
|
136
|
-
free: "\u514D\u8D39\u8BD5\u7528 {count}
|
|
137
|
+
free: "\u514D\u8D39\u8BD5\u7528 {count} {interval}",
|
|
137
138
|
least: "\u81F3\u5C11",
|
|
138
139
|
completed: {
|
|
139
140
|
payment: "\u611F\u8C22\u60A8\u7684\u8D2D\u4E70",
|
|
@@ -61,16 +61,6 @@ const Root = styled("section")`
|
|
|
61
61
|
background: var(--backgrounds-bg-field, #f9fafb);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// .cko-payment-card::before {
|
|
65
|
-
// content: '';
|
|
66
|
-
// position: absolute;
|
|
67
|
-
// right: 0;
|
|
68
|
-
// bottom: 0;
|
|
69
|
-
// border: 12px solid ${(props) => props.theme.palette.primary.main};
|
|
70
|
-
// border-top-color: transparent;
|
|
71
|
-
// border-left-color: transparent;
|
|
72
|
-
// }
|
|
73
|
-
|
|
74
64
|
.cko-payment-card-unselect {
|
|
75
65
|
border: 1px solid #ddd;
|
|
76
66
|
padding: 4px 8px;
|
package/es/payment/index.js
CHANGED
|
@@ -133,6 +133,7 @@ function PaymentInner({
|
|
|
133
133
|
{
|
|
134
134
|
items: state.checkoutSession.line_items,
|
|
135
135
|
trialInDays: state.checkoutSession.subscription_data?.trial_period_days || 0,
|
|
136
|
+
trialEnd: state.checkoutSession.subscription_data?.trial_end || 0,
|
|
136
137
|
billingThreshold: Math.max(
|
|
137
138
|
state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
138
139
|
// @ts-ignore
|
|
@@ -321,23 +322,18 @@ export const Root = styled(Box)`
|
|
|
321
322
|
box-sizing: border-box;
|
|
322
323
|
display: flex;
|
|
323
324
|
flex-direction: column;
|
|
324
|
-
// justify-content: center;
|
|
325
325
|
align-items: center;
|
|
326
326
|
overflow: hidden;
|
|
327
|
-
// min-height: ${(props) => props.mode === "standalone" ? "100vh" : "auto"};
|
|
328
327
|
position: relative;
|
|
329
328
|
.cko-container {
|
|
330
329
|
overflow: hidden;
|
|
331
330
|
width: 100%;
|
|
332
|
-
// max-width: ${(props) => props.mode.endsWith("-minimal") ? "400px" : "1000px"};
|
|
333
331
|
display: flex;
|
|
334
332
|
flex-direction: row;
|
|
335
333
|
justify-content: center;
|
|
336
|
-
// gap: 4px;
|
|
337
334
|
position: relative;
|
|
338
335
|
flex: 1;
|
|
339
336
|
padding: 1px;
|
|
340
|
-
// padding: ${(props) => props.mode === "standalone" ? "0 16px" : "0"};
|
|
341
337
|
}
|
|
342
338
|
|
|
343
339
|
.base-card {
|
|
@@ -350,14 +346,11 @@ export const Root = styled(Box)`
|
|
|
350
346
|
}
|
|
351
347
|
|
|
352
348
|
.cko-overview {
|
|
353
|
-
// width: ${(props) => props.mode.endsWith("-minimal") ? "100%" : "400px"};
|
|
354
|
-
// min-height: ${(props) => props.mode === "standalone" ? "540px" : "auto"};
|
|
355
349
|
position: relative;
|
|
356
350
|
flex-direction: column;
|
|
357
351
|
display: ${(props) => props.mode.endsWith("-minimal") ? "none" : "flex"};
|
|
358
352
|
background: var(--backgrounds-bg-base);
|
|
359
353
|
min-height: 'auto';
|
|
360
|
-
// width: 502px;
|
|
361
354
|
}
|
|
362
355
|
.cko-header {
|
|
363
356
|
left: 0;
|
|
@@ -385,8 +378,6 @@ export const Root = styled(Box)`
|
|
|
385
378
|
|
|
386
379
|
.cko-payment {
|
|
387
380
|
width: 502px;
|
|
388
|
-
// width: ${(props) => props.mode.endsWith("-minimal") ? "100%" : "400px"};
|
|
389
|
-
// box-shadow: -4px 0px 8px 0px rgba(2, 7, 19, 0.04);
|
|
390
381
|
padding-left: ${(props) => props.mode === "standalone" ? "40px" : "20px"};
|
|
391
382
|
position: relative;
|
|
392
383
|
&:before {
|
|
@@ -411,10 +402,6 @@ export const Root = styled(Box)`
|
|
|
411
402
|
}
|
|
412
403
|
|
|
413
404
|
.cko-payment-form {
|
|
414
|
-
// .MuiInputAdornment-positionStart {
|
|
415
|
-
// width: 50px;
|
|
416
|
-
// }
|
|
417
|
-
|
|
418
405
|
.MuiFormLabel-root {
|
|
419
406
|
color: var(--foregrounds-fg-base, #010714);
|
|
420
407
|
font-weight: 500;
|
|
@@ -79,20 +79,30 @@ export default function ProductDonation({
|
|
|
79
79
|
textAlign: "center",
|
|
80
80
|
...state.selected === amount && !state.custom ? { borderColor: "primary.main" } : {}
|
|
81
81
|
},
|
|
82
|
-
children: /* @__PURE__ */ jsx(CardActionArea, { onClick: () => handleSelect(amount), children: /* @__PURE__ */ jsxs(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
children: /* @__PURE__ */ jsx(CardActionArea, { onClick: () => handleSelect(amount), children: /* @__PURE__ */ jsxs(
|
|
83
|
+
Stack,
|
|
84
|
+
{
|
|
85
|
+
direction: "row",
|
|
86
|
+
sx: { py: 1, px: 0.5 },
|
|
87
|
+
spacing: 0.5,
|
|
88
|
+
alignItems: "flex-end",
|
|
89
|
+
justifyContent: "center",
|
|
90
|
+
children: [
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
Typography,
|
|
93
|
+
{
|
|
94
|
+
component: "strong",
|
|
95
|
+
lineHeight: 1,
|
|
96
|
+
variant: "h3",
|
|
97
|
+
sx: { fontVariantNumeric: "tabular-nums", fontWeight: 400 },
|
|
98
|
+
children: amount
|
|
99
|
+
}
|
|
100
|
+
),
|
|
101
|
+
/* @__PURE__ */ jsx(Typography, { component: "small", lineHeight: 1, fontSize: 12, children: "ABT" }),
|
|
102
|
+
" "
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
) })
|
|
96
106
|
},
|
|
97
107
|
amount
|
|
98
108
|
)) }),
|
|
@@ -4,17 +4,19 @@ type Props = {
|
|
|
4
4
|
item: TLineItemExpanded;
|
|
5
5
|
items: TLineItemExpanded[];
|
|
6
6
|
trialInDays: number;
|
|
7
|
+
trialEnd?: number;
|
|
7
8
|
currency: TPaymentCurrency;
|
|
8
9
|
onUpsell: Function;
|
|
9
10
|
onDownsell: Function;
|
|
10
11
|
mode?: 'normal' | 'cross-sell';
|
|
11
12
|
children?: React.ReactNode;
|
|
12
13
|
};
|
|
13
|
-
declare function ProductItem({ item, items, trialInDays, currency, mode, children, onUpsell, onDownsell, }: Props): JSX.Element;
|
|
14
|
+
declare function ProductItem({ item, items, trialInDays, trialEnd, currency, mode, children, onUpsell, onDownsell, }: Props): JSX.Element;
|
|
14
15
|
declare namespace ProductItem {
|
|
15
16
|
var defaultProps: {
|
|
16
17
|
mode: string;
|
|
17
18
|
children: null;
|
|
19
|
+
trialEnd: number;
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
export default ProductItem;
|
|
@@ -12,14 +12,17 @@ import {
|
|
|
12
12
|
formatUpsellSaving
|
|
13
13
|
} from "../libs/util.js";
|
|
14
14
|
import ProductCard from "./product-card.js";
|
|
15
|
+
import dayjs from "../libs/dayjs.js";
|
|
15
16
|
ProductItem.defaultProps = {
|
|
16
17
|
mode: "normal",
|
|
17
|
-
children: null
|
|
18
|
+
children: null,
|
|
19
|
+
trialEnd: 0
|
|
18
20
|
};
|
|
19
21
|
export default function ProductItem({
|
|
20
22
|
item,
|
|
21
23
|
items,
|
|
22
24
|
trialInDays,
|
|
25
|
+
trialEnd = 0,
|
|
23
26
|
currency,
|
|
24
27
|
mode,
|
|
25
28
|
children,
|
|
@@ -27,18 +30,19 @@ export default function ProductItem({
|
|
|
27
30
|
onDownsell
|
|
28
31
|
}) {
|
|
29
32
|
const { t, locale } = useLocaleContext();
|
|
30
|
-
const pricing = formatLineItemPricing(item, currency, trialInDays, locale);
|
|
33
|
+
const pricing = formatLineItemPricing(item, currency, { trialEnd, trialInDays }, locale);
|
|
31
34
|
const saving = formatUpsellSaving(items, currency);
|
|
32
35
|
const metered = item.price?.recurring?.usage_type === "metered" ? t("common.metered") : "";
|
|
33
36
|
const canUpsell = mode === "normal" && items.length === 1;
|
|
34
37
|
const primaryText = useMemo(() => {
|
|
35
38
|
const price = item.upsell_price || item.price || {};
|
|
36
39
|
const isRecurring = price?.type === "recurring" && price?.recurring;
|
|
37
|
-
|
|
40
|
+
const trial = trialInDays > 0 || trialEnd > dayjs().unix();
|
|
41
|
+
if (isRecurring && !trial && price?.recurring?.usage_type !== "metered") {
|
|
38
42
|
return `${pricing.primary} ${price.recurring ? formatRecurring(price.recurring, false, "slash", locale) : ""}`;
|
|
39
43
|
}
|
|
40
44
|
return pricing.primary;
|
|
41
|
-
}, [trialInDays, pricing, item, locale]);
|
|
45
|
+
}, [trialInDays, trialEnd, pricing, item, locale]);
|
|
42
46
|
return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", spacing: 1, sx: { width: "100%" }, className: "product-item", children: [
|
|
43
47
|
/* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", sx: { width: "100%" }, className: "product-item-content", children: [
|
|
44
48
|
/* @__PURE__ */ jsxs(
|
package/es/payment/summary.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type Props = {
|
|
|
4
4
|
items: TLineItemExpanded[];
|
|
5
5
|
currency: TPaymentCurrency;
|
|
6
6
|
trialInDays: number;
|
|
7
|
+
trialEnd?: number;
|
|
7
8
|
billingThreshold: number;
|
|
8
9
|
showStaking?: boolean;
|
|
9
10
|
onUpsell?: Function;
|
|
@@ -16,7 +17,7 @@ type Props = {
|
|
|
16
17
|
donationSettings?: DonationSettings;
|
|
17
18
|
action?: string;
|
|
18
19
|
};
|
|
19
|
-
declare function PaymentSummary({ items, currency, trialInDays, billingThreshold, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, onChangeAmount, checkoutSessionId, crossSellBehavior, showStaking, donationSettings, action, ...rest }: Props): import("react").JSX.Element;
|
|
20
|
+
declare function PaymentSummary({ items, currency, trialInDays, billingThreshold, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, onChangeAmount, checkoutSessionId, crossSellBehavior, showStaking, donationSettings, action, trialEnd, ...rest }: Props): import("react").JSX.Element;
|
|
20
21
|
declare namespace PaymentSummary {
|
|
21
22
|
var defaultProps: {
|
|
22
23
|
onUpsell: any;
|
|
@@ -29,6 +30,7 @@ declare namespace PaymentSummary {
|
|
|
29
30
|
showStaking: boolean;
|
|
30
31
|
donationSettings: null;
|
|
31
32
|
action: string;
|
|
33
|
+
trialEnd: number;
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
export default PaymentSummary;
|
package/es/payment/summary.js
CHANGED
|
@@ -83,7 +83,8 @@ PaymentSummary.defaultProps = {
|
|
|
83
83
|
crossSellBehavior: "",
|
|
84
84
|
showStaking: false,
|
|
85
85
|
donationSettings: null,
|
|
86
|
-
action: ""
|
|
86
|
+
action: "",
|
|
87
|
+
trialEnd: 0
|
|
87
88
|
};
|
|
88
89
|
export default function PaymentSummary({
|
|
89
90
|
items,
|
|
@@ -100,6 +101,7 @@ export default function PaymentSummary({
|
|
|
100
101
|
showStaking,
|
|
101
102
|
donationSettings,
|
|
102
103
|
action,
|
|
104
|
+
trialEnd = 0,
|
|
103
105
|
...rest
|
|
104
106
|
}) {
|
|
105
107
|
const { t, locale } = useLocaleContext();
|
|
@@ -109,7 +111,7 @@ export default function PaymentSummary({
|
|
|
109
111
|
const { data, runAsync } = useRequest(
|
|
110
112
|
() => checkoutSessionId ? fetchCrossSell(checkoutSessionId) : Promise.resolve(null)
|
|
111
113
|
);
|
|
112
|
-
const headlines = formatCheckoutHeadlines(items, currency, trialInDays, locale);
|
|
114
|
+
const headlines = formatCheckoutHeadlines(items, currency, { trialEnd, trialInDays }, locale);
|
|
113
115
|
const staking = showStaking ? getStakingSetup(items, currency, billingThreshold) : "0";
|
|
114
116
|
const totalAmount = fromUnitToToken(
|
|
115
117
|
new BN(fromTokenToUnit(headlines.actualAmount, currency?.decimal)).add(new BN(staking)).toString(),
|
|
@@ -180,6 +182,7 @@ export default function PaymentSummary({
|
|
|
180
182
|
item: x,
|
|
181
183
|
items,
|
|
182
184
|
trialInDays,
|
|
185
|
+
trialEnd,
|
|
183
186
|
currency,
|
|
184
187
|
onUpsell: handleUpsell,
|
|
185
188
|
onDownsell: handleDownsell,
|
|
@@ -209,6 +212,7 @@ export default function PaymentSummary({
|
|
|
209
212
|
items,
|
|
210
213
|
trialInDays,
|
|
211
214
|
currency,
|
|
215
|
+
trialEnd,
|
|
212
216
|
onUpsell: noop,
|
|
213
217
|
onDownsell: noop,
|
|
214
218
|
children: /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", sx: { width: 1 }, children: [
|
|
@@ -251,7 +255,7 @@ export default function PaymentSummary({
|
|
|
251
255
|
),
|
|
252
256
|
!settings.livemode && /* @__PURE__ */ jsx(Livemode, {})
|
|
253
257
|
] }),
|
|
254
|
-
isMobile ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
258
|
+
isMobile && !donationSettings ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
255
259
|
/* @__PURE__ */ jsxs(
|
|
256
260
|
Stack,
|
|
257
261
|
{
|
package/lib/checkout/donate.js
CHANGED
|
@@ -293,7 +293,8 @@ function CheckoutDonateInner({
|
|
|
293
293
|
onPaid,
|
|
294
294
|
onError,
|
|
295
295
|
mode,
|
|
296
|
-
inlineOptions = {}
|
|
296
|
+
inlineOptions = {},
|
|
297
|
+
theme
|
|
297
298
|
}) {
|
|
298
299
|
const {
|
|
299
300
|
state,
|
|
@@ -446,20 +447,34 @@ function CheckoutDonateInner({
|
|
|
446
447
|
maxWidth: "md",
|
|
447
448
|
showCloseButton: true,
|
|
448
449
|
disableEscapeKeyDown: true,
|
|
450
|
+
sx: {
|
|
451
|
+
".MuiDialogContent-root": {
|
|
452
|
+
padding: {
|
|
453
|
+
xs: 0,
|
|
454
|
+
md: "0 16px 0"
|
|
455
|
+
},
|
|
456
|
+
borderTop: "1px solid var(--stroke-border-base, #EFF1F5)",
|
|
457
|
+
width: {
|
|
458
|
+
xs: "100%",
|
|
459
|
+
md: 900
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
},
|
|
449
463
|
onClose: (e, reason) => setState({
|
|
450
464
|
open: reason === "backdropClick"
|
|
451
465
|
}),
|
|
452
466
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
453
467
|
sx: {
|
|
454
|
-
|
|
455
|
-
|
|
468
|
+
height: "100%",
|
|
469
|
+
width: "100%"
|
|
456
470
|
},
|
|
457
471
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
|
|
458
472
|
id: donation.data?.id,
|
|
459
473
|
onPaid: handlePaid,
|
|
460
474
|
onError,
|
|
461
475
|
action: settings.appearance?.button?.text,
|
|
462
|
-
mode: "inline"
|
|
476
|
+
mode: "inline",
|
|
477
|
+
theme
|
|
463
478
|
})
|
|
464
479
|
})
|
|
465
480
|
})]
|
package/lib/libs/util.d.ts
CHANGED
|
@@ -19,7 +19,10 @@ export declare function getStatementDescriptor(items: any[]): any;
|
|
|
19
19
|
export declare function formatRecurring(recurring: PriceRecurring, translate?: boolean, separator?: string, locale?: string): string;
|
|
20
20
|
export declare function getPriceUintAmountByCurrency(price: TPrice, currency: TPaymentCurrency): string;
|
|
21
21
|
export declare function getPriceCurrencyOptions(price: TPrice): PriceCurrency[];
|
|
22
|
-
export declare function formatLineItemPricing(item: TLineItemExpanded, currency: TPaymentCurrency,
|
|
22
|
+
export declare function formatLineItemPricing(item: TLineItemExpanded, currency: TPaymentCurrency, { trialEnd, trialInDays }: {
|
|
23
|
+
trialEnd: number;
|
|
24
|
+
trialInDays: number;
|
|
25
|
+
}, locale?: string): {
|
|
23
26
|
primary: string;
|
|
24
27
|
secondary?: string;
|
|
25
28
|
quantity: string;
|
|
@@ -47,7 +50,17 @@ export declare function formatPriceDisplay({ amount, then, actualAmount, showThe
|
|
|
47
50
|
actualAmount: string;
|
|
48
51
|
showThen?: boolean;
|
|
49
52
|
}, recurring: string, hasMetered: boolean, locale?: string): string;
|
|
50
|
-
export declare function
|
|
53
|
+
export declare function getFreeTrialTime({ trialInDays, trialEnd }: {
|
|
54
|
+
trialInDays: number;
|
|
55
|
+
trialEnd: number;
|
|
56
|
+
}, locale?: string): {
|
|
57
|
+
count: number;
|
|
58
|
+
interval: string;
|
|
59
|
+
};
|
|
60
|
+
export declare function formatCheckoutHeadlines(items: TLineItemExpanded[], currency: TPaymentCurrency, { trialInDays, trialEnd }: {
|
|
61
|
+
trialInDays: number;
|
|
62
|
+
trialEnd: number;
|
|
63
|
+
}, locale?: string): {
|
|
51
64
|
action: string;
|
|
52
65
|
amount: string;
|
|
53
66
|
then?: string;
|