@blocklet/payment-react 1.14.20 → 1.14.22
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.d.ts +2 -1
- package/es/checkout/donate.js +9 -10
- package/es/checkout/form.d.ts +1 -1
- package/es/checkout/form.js +23 -1
- package/es/checkout/table.d.ts +1 -1
- package/es/checkout/table.js +8 -1
- package/es/components/blockchain/tx.js +2 -1
- package/es/components/country-select.d.ts +16 -0
- package/es/components/country-select.js +82 -0
- package/es/components/input.d.ts +21 -21
- package/es/components/input.js +43 -42
- package/es/components/livemode.js +1 -0
- package/es/components/pricing-table.js +0 -2
- package/es/components/status.js +2 -3
- package/es/components/table.d.ts +2 -0
- package/es/components/table.js +186 -0
- package/es/contexts/payment.d.ts +2 -0
- package/es/contexts/payment.js +5 -2
- package/es/history/invoice/list.d.ts +5 -1
- package/es/history/invoice/list.js +218 -48
- package/es/hooks/mobile.d.ts +4 -0
- package/es/hooks/mobile.js +10 -0
- package/es/index.d.ts +5 -1
- package/es/index.js +7 -1
- package/es/libs/util.d.ts +15 -2
- package/es/libs/util.js +92 -28
- package/es/locales/en.js +23 -7
- package/es/locales/index.d.ts +0 -1
- package/es/locales/index.js +10 -1
- package/es/locales/zh.js +22 -6
- package/es/payment/error.js +2 -2
- package/es/payment/footer.js +1 -1
- package/es/payment/form/address.d.ts +9 -2
- package/es/payment/form/address.js +69 -69
- package/es/payment/form/currency.js +39 -25
- package/es/payment/form/index.d.ts +1 -1
- package/es/payment/form/index.js +83 -81
- package/es/payment/form/phone.js +15 -51
- package/es/payment/index.d.ts +1 -10
- package/es/payment/index.js +274 -219
- package/es/payment/product-card.js +4 -4
- package/es/payment/product-donation.js +7 -2
- package/es/payment/product-item.d.ts +2 -2
- package/es/payment/product-item.js +120 -81
- package/es/payment/summary.js +188 -118
- package/es/theme/index.css +240 -0
- package/es/theme/index.d.ts +9 -0
- package/es/theme/index.js +243 -0
- package/es/theme/typography.d.ts +2 -0
- package/es/theme/typography.js +53 -0
- package/es/types/index.d.ts +11 -0
- package/lib/checkout/donate.d.ts +2 -1
- package/lib/checkout/donate.js +14 -2
- package/lib/checkout/form.d.ts +1 -1
- package/lib/checkout/form.js +22 -1
- package/lib/checkout/table.d.ts +1 -1
- package/lib/checkout/table.js +14 -1
- package/lib/components/blockchain/tx.js +4 -1
- package/lib/components/country-select.d.ts +16 -0
- package/lib/components/country-select.js +115 -0
- package/lib/components/input.d.ts +21 -21
- package/lib/components/input.js +21 -12
- package/lib/components/livemode.js +1 -0
- package/lib/components/pricing-table.js +0 -2
- package/lib/components/status.js +2 -3
- package/lib/components/table.d.ts +2 -0
- package/lib/components/table.js +220 -0
- package/lib/contexts/payment.d.ts +2 -0
- package/lib/contexts/payment.js +4 -1
- package/lib/history/invoice/list.d.ts +5 -1
- package/lib/history/invoice/list.js +293 -62
- package/lib/hooks/mobile.d.ts +4 -0
- package/lib/hooks/mobile.js +17 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +36 -0
- package/lib/libs/util.d.ts +15 -2
- package/lib/libs/util.js +115 -37
- package/lib/locales/en.js +23 -7
- package/lib/locales/index.d.ts +0 -1
- package/lib/locales/index.js +14 -3
- package/lib/locales/zh.js +22 -6
- package/lib/payment/error.js +5 -1
- package/lib/payment/footer.js +1 -1
- package/lib/payment/form/address.d.ts +9 -2
- package/lib/payment/form/address.js +67 -59
- package/lib/payment/form/currency.js +31 -24
- package/lib/payment/form/index.d.ts +1 -1
- package/lib/payment/form/index.js +92 -93
- package/lib/payment/form/phone.js +11 -59
- package/lib/payment/index.d.ts +1 -10
- package/lib/payment/index.js +291 -219
- package/lib/payment/product-card.js +5 -4
- package/lib/payment/product-donation.js +9 -2
- package/lib/payment/product-item.d.ts +2 -2
- package/lib/payment/product-item.js +38 -19
- package/lib/payment/summary.js +219 -127
- package/lib/theme/index.css +240 -0
- package/lib/theme/index.d.ts +9 -0
- package/lib/theme/index.js +259 -0
- package/lib/theme/typography.d.ts +2 -0
- package/lib/theme/typography.js +59 -0
- package/lib/types/index.d.ts +11 -0
- package/package.json +14 -11
- package/src/checkout/donate.tsx +16 -10
- package/src/checkout/form.tsx +23 -0
- package/src/checkout/table.tsx +13 -1
- package/src/components/blockchain/tx.tsx +2 -1
- package/src/components/country-select.tsx +93 -0
- package/src/components/input.tsx +49 -46
- package/src/components/livemode.tsx +1 -0
- package/src/components/pricing-table.tsx +0 -2
- package/src/components/status.tsx +1 -2
- package/src/components/table.tsx +200 -0
- package/src/contexts/payment.tsx +6 -1
- package/src/history/invoice/list.tsx +258 -49
- package/src/hooks/mobile.ts +13 -0
- package/src/index.ts +7 -0
- package/src/libs/util.ts +120 -31
- package/src/locales/en.tsx +19 -4
- package/src/locales/index.tsx +10 -3
- package/src/locales/zh.tsx +18 -3
- package/src/payment/error.tsx +2 -2
- package/src/payment/footer.tsx +1 -1
- package/src/payment/form/address.tsx +56 -47
- package/src/payment/form/currency.tsx +29 -23
- package/src/payment/form/index.tsx +89 -76
- package/src/payment/form/phone.tsx +14 -51
- package/src/payment/index.tsx +294 -242
- package/src/payment/product-card.tsx +4 -4
- package/src/payment/product-donation.tsx +7 -3
- package/src/payment/product-item.tsx +49 -20
- package/src/payment/summary.tsx +191 -108
- package/src/theme/index.css +240 -0
- package/src/theme/index.tsx +250 -0
- package/src/theme/typography.ts +56 -0
- package/src/types/index.ts +12 -0
|
@@ -5,6 +5,7 @@ import { useSetState } from "ahooks";
|
|
|
5
5
|
import { useEffect } from "react";
|
|
6
6
|
import Switch from "../components/switch-button.js";
|
|
7
7
|
import { formatAmountPrecisionLimit } from "../libs/util.js";
|
|
8
|
+
import { usePaymentContext } from "../contexts/payment.js";
|
|
8
9
|
export default function ProductDonation({
|
|
9
10
|
item,
|
|
10
11
|
settings,
|
|
@@ -12,6 +13,7 @@ export default function ProductDonation({
|
|
|
12
13
|
currency
|
|
13
14
|
}) {
|
|
14
15
|
const { t, locale } = useLocaleContext();
|
|
16
|
+
const { setPayable } = usePaymentContext();
|
|
15
17
|
const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
|
|
16
18
|
const [state, setState] = useSetState({
|
|
17
19
|
selected: preset,
|
|
@@ -39,12 +41,15 @@ export default function ProductDonation({
|
|
|
39
41
|
const precision = currency?.maximum_precision || 6;
|
|
40
42
|
if (formatAmountPrecisionLimit(value, locale)) {
|
|
41
43
|
setState({ input: value, error: formatAmountPrecisionLimit(value, locale, precision) });
|
|
44
|
+
setPayable(false);
|
|
42
45
|
return;
|
|
43
46
|
}
|
|
44
47
|
if (value < min || value > max) {
|
|
45
48
|
setState({ input: value, error: t("payment.checkout.donation.between", { min, max }) });
|
|
49
|
+
setPayable(false);
|
|
46
50
|
return;
|
|
47
51
|
}
|
|
52
|
+
setPayable(true);
|
|
48
53
|
setState({ error: "", input: value });
|
|
49
54
|
onChange({ priceId: item.price_id, amount: value });
|
|
50
55
|
};
|
|
@@ -61,7 +66,7 @@ export default function ProductDonation({
|
|
|
61
66
|
{
|
|
62
67
|
control: /* @__PURE__ */ jsx(Switch, { checked: state.custom, sx: { marginRight: 0.4 }, onChange: handleToggle }),
|
|
63
68
|
label: state.custom ? t("payment.checkout.donation.select") : t("payment.checkout.donation.custom"),
|
|
64
|
-
sx: { marginRight: 2, marginLeft: 0.5, color: "text.
|
|
69
|
+
sx: { marginRight: 2, marginLeft: 0.5, color: "text.lighter" }
|
|
65
70
|
}
|
|
66
71
|
),
|
|
67
72
|
!state.custom && /* @__PURE__ */ jsx(Box, { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 1.5, children: settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map((amount) => /* @__PURE__ */ jsx(
|
|
@@ -69,7 +74,7 @@ export default function ProductDonation({
|
|
|
69
74
|
{
|
|
70
75
|
variant: "outlined",
|
|
71
76
|
sx: {
|
|
72
|
-
minWidth:
|
|
77
|
+
minWidth: 115,
|
|
73
78
|
textAlign: "center",
|
|
74
79
|
...state.selected === amount && !state.custom ? { borderColor: "primary.main" } : {}
|
|
75
80
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
type Props = {
|
|
4
4
|
item: TLineItemExpanded;
|
|
5
5
|
items: TLineItemExpanded[];
|
|
@@ -10,7 +10,7 @@ type Props = {
|
|
|
10
10
|
mode?: 'normal' | 'cross-sell';
|
|
11
11
|
children?: React.ReactNode;
|
|
12
12
|
};
|
|
13
|
-
declare function ProductItem({ item, items, trialInDays, currency, mode, children, onUpsell, onDownsell, }: Props):
|
|
13
|
+
declare function ProductItem({ item, items, trialInDays, currency, mode, children, onUpsell, onDownsell, }: Props): JSX.Element;
|
|
14
14
|
declare namespace ProductItem {
|
|
15
15
|
var defaultProps: {
|
|
16
16
|
mode: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
3
|
import { Box, Stack, Typography } from "@mui/material";
|
|
4
|
+
import { useMemo } from "react";
|
|
4
5
|
import Status from "../components/status.js";
|
|
5
6
|
import Switch from "../components/switch-button.js";
|
|
6
7
|
import {
|
|
@@ -30,13 +31,22 @@ export default function ProductItem({
|
|
|
30
31
|
const saving = formatUpsellSaving(items, currency);
|
|
31
32
|
const metered = item.price?.recurring?.usage_type === "metered" ? t("common.metered") : "";
|
|
32
33
|
const canUpsell = mode === "normal" && items.length === 1;
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const primaryText = useMemo(() => {
|
|
35
|
+
const price = item.upsell_price || item.price || {};
|
|
36
|
+
const isRecurring = price?.type === "recurring" && price?.recurring;
|
|
37
|
+
if (isRecurring && trialInDays <= 0 && price?.recurring?.usage_type !== "metered") {
|
|
38
|
+
return `${pricing.primary} ${price.recurring ? formatRecurring(price.recurring, false, "slash", locale) : ""}`;
|
|
39
|
+
}
|
|
40
|
+
return pricing.primary;
|
|
41
|
+
}, [trialInDays, pricing, item, locale]);
|
|
42
|
+
return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", spacing: 1, sx: { width: "100%" }, className: "product-item", children: [
|
|
43
|
+
/* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", sx: { width: "100%" }, className: "product-item-content", children: [
|
|
35
44
|
/* @__PURE__ */ jsxs(
|
|
36
45
|
Stack,
|
|
37
46
|
{
|
|
38
47
|
direction: "row",
|
|
39
|
-
alignItems: "
|
|
48
|
+
alignItems: "center",
|
|
49
|
+
flexWrap: "wrap",
|
|
40
50
|
spacing: 0.5,
|
|
41
51
|
justifyContent: "space-between",
|
|
42
52
|
sx: { width: "100%" },
|
|
@@ -46,94 +56,123 @@ export default function ProductItem({
|
|
|
46
56
|
{
|
|
47
57
|
logo: item.price.product?.images[0],
|
|
48
58
|
name: item.price.product?.name,
|
|
49
|
-
|
|
50
|
-
extra: /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", children: [
|
|
51
|
-
item.price.type === "recurring" && item.price.recurring ? [pricing.quantity, t("common.billed", { rule: `${formatRecurring(item.upsell_price?.recurring || item.price.recurring, true, "per", locale)} ${metered}` })].filter(Boolean).join(", ") : pricing.quantity,
|
|
52
|
-
formatQuantityInventory(item.price, item.quantity, locale) ? /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: "0.85rem", color: "red" }, children: [
|
|
53
|
-
"\uFF08",
|
|
54
|
-
formatQuantityInventory(item.price, item.quantity, locale),
|
|
55
|
-
"\uFF09"
|
|
56
|
-
] }) : ""
|
|
57
|
-
] })
|
|
59
|
+
extra: /* @__PURE__ */ jsx(Box, { display: "flex", alignItems: "center", children: item.price.type === "recurring" && item.price.recurring ? [pricing.quantity, t("common.billed", { rule: `${formatRecurring(item.upsell_price?.recurring || item.price.recurring, true, "per", locale)} ${metered}` })].filter(Boolean).join(", ") : pricing.quantity })
|
|
58
60
|
}
|
|
59
61
|
),
|
|
60
62
|
/* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", flex: 1, children: [
|
|
61
|
-
/* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 500 }, gutterBottom: true, children:
|
|
62
|
-
pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.85rem", color: "text.
|
|
63
|
+
/* @__PURE__ */ jsx(Typography, { sx: { color: "text.primary", fontWeight: 500, whiteSpace: "nowrap" }, gutterBottom: true, children: primaryText }),
|
|
64
|
+
pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.85rem", color: "text.lighter" }, children: pricing.secondary })
|
|
63
65
|
] })
|
|
64
66
|
]
|
|
65
67
|
}
|
|
66
68
|
),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
canUpsell && !item.upsell_price_id && item.price.upsell?.upsells_to && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", sx: { width: "100%" }, children: [
|
|
70
|
-
/* @__PURE__ */ jsxs(
|
|
71
|
-
Typography,
|
|
69
|
+
formatQuantityInventory(item.price, item.quantity, locale) ? /* @__PURE__ */ jsx(
|
|
70
|
+
Status,
|
|
72
71
|
{
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
label: formatQuantityInventory(item.price, item.quantity, locale),
|
|
73
|
+
variant: "outlined",
|
|
75
74
|
sx: {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/* @__PURE__ */ jsx(
|
|
82
|
-
Switch,
|
|
83
|
-
{
|
|
84
|
-
id: "upsell-switch",
|
|
85
|
-
sx: { mr: 1 },
|
|
86
|
-
variant: "success",
|
|
87
|
-
checked: false,
|
|
88
|
-
onChange: () => onUpsell(item.price_id, item.price.upsell?.upsells_to_id)
|
|
89
|
-
}
|
|
90
|
-
),
|
|
91
|
-
t("payment.checkout.upsell.save", {
|
|
92
|
-
recurring: formatRecurring(item.price.upsell.upsells_to.recurring, true, "per", locale)
|
|
93
|
-
}),
|
|
94
|
-
/* @__PURE__ */ jsx(
|
|
95
|
-
Status,
|
|
96
|
-
{
|
|
97
|
-
label: t("payment.checkout.upsell.off", { saving }),
|
|
98
|
-
color: "primary",
|
|
99
|
-
variant: "outlined",
|
|
100
|
-
sx: { ml: 1 }
|
|
101
|
-
}
|
|
102
|
-
)
|
|
103
|
-
]
|
|
75
|
+
mt: 1,
|
|
76
|
+
borderColor: "var(--tags-tag-red-border, #FFC8D3)",
|
|
77
|
+
background: "var(--tags-tag-red-bg, #FFE2E6)",
|
|
78
|
+
color: "var(--tags-tag-red-text, #E40031)"
|
|
79
|
+
}
|
|
104
80
|
}
|
|
105
|
-
),
|
|
106
|
-
|
|
81
|
+
) : null,
|
|
82
|
+
children
|
|
107
83
|
] }),
|
|
108
|
-
canUpsell && item.upsell_price_id && /* @__PURE__ */ jsxs(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
84
|
+
canUpsell && !item.upsell_price_id && item.price.upsell?.upsells_to && /* @__PURE__ */ jsxs(
|
|
85
|
+
Stack,
|
|
86
|
+
{
|
|
87
|
+
direction: "row",
|
|
88
|
+
alignItems: "center",
|
|
89
|
+
justifyContent: "space-between",
|
|
90
|
+
sx: { width: "100%" },
|
|
91
|
+
className: "product-item-upsell",
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ jsxs(
|
|
94
|
+
Typography,
|
|
95
|
+
{
|
|
96
|
+
component: "label",
|
|
97
|
+
htmlFor: "upsell-switch",
|
|
98
|
+
sx: {
|
|
99
|
+
fontSize: 12,
|
|
100
|
+
cursor: "pointer",
|
|
101
|
+
color: "text.secondary"
|
|
102
|
+
},
|
|
103
|
+
children: [
|
|
104
|
+
/* @__PURE__ */ jsx(
|
|
105
|
+
Switch,
|
|
106
|
+
{
|
|
107
|
+
id: "upsell-switch",
|
|
108
|
+
sx: { mr: 1 },
|
|
109
|
+
variant: "success",
|
|
110
|
+
checked: false,
|
|
111
|
+
onChange: () => onUpsell(item.price_id, item.price.upsell?.upsells_to_id)
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
t("payment.checkout.upsell.save", {
|
|
115
|
+
recurring: formatRecurring(item.price.upsell.upsells_to.recurring, true, "per", locale)
|
|
116
|
+
}),
|
|
117
|
+
/* @__PURE__ */ jsx(
|
|
118
|
+
Status,
|
|
119
|
+
{
|
|
120
|
+
label: t("payment.checkout.upsell.off", { saving }),
|
|
121
|
+
variant: "outlined",
|
|
122
|
+
sx: {
|
|
123
|
+
ml: 1,
|
|
124
|
+
borderColor: " var(--tags-tag-orange-border, #FFE467)",
|
|
125
|
+
background: "var(--tags-tag-orange-bg, #FFF4BC)",
|
|
126
|
+
color: "var(--tags-tag-orange-text, #D24000)"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
/* @__PURE__ */ jsx(Typography, { component: "span", sx: { fontSize: 12 }, children: formatPrice(item.price.upsell.upsells_to, currency, item.price.product?.unit_label, 1, true, locale) })
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
),
|
|
137
|
+
canUpsell && item.upsell_price_id && /* @__PURE__ */ jsxs(
|
|
138
|
+
Stack,
|
|
139
|
+
{
|
|
140
|
+
direction: "row",
|
|
141
|
+
alignItems: "center",
|
|
142
|
+
justifyContent: "space-between",
|
|
143
|
+
sx: { width: "100%" },
|
|
144
|
+
className: "product-item-upsell",
|
|
145
|
+
children: [
|
|
146
|
+
/* @__PURE__ */ jsxs(
|
|
147
|
+
Typography,
|
|
148
|
+
{
|
|
149
|
+
component: "label",
|
|
150
|
+
htmlFor: "upsell-switch",
|
|
151
|
+
sx: {
|
|
152
|
+
fontSize: 12,
|
|
153
|
+
cursor: "pointer",
|
|
154
|
+
color: "text.secondary"
|
|
155
|
+
},
|
|
156
|
+
children: [
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
Switch,
|
|
159
|
+
{
|
|
160
|
+
id: "upsell-switch",
|
|
161
|
+
sx: { mr: 1 },
|
|
162
|
+
variant: "success",
|
|
163
|
+
checked: true,
|
|
164
|
+
onChange: () => onDownsell(item.upsell_price_id)
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
t("payment.checkout.upsell.revert", {
|
|
168
|
+
recurring: t(`common.${formatRecurring(item.price.recurring)}`)
|
|
169
|
+
})
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
/* @__PURE__ */ jsx(Typography, { component: "span", sx: { fontSize: 12 }, children: formatPrice(item.price, currency, item.price.product?.unit_label, 1, true, locale) })
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
)
|
|
138
177
|
] });
|
|
139
178
|
}
|