@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.
Files changed (136) hide show
  1. package/es/checkout/donate.d.ts +2 -1
  2. package/es/checkout/donate.js +9 -10
  3. package/es/checkout/form.d.ts +1 -1
  4. package/es/checkout/form.js +23 -1
  5. package/es/checkout/table.d.ts +1 -1
  6. package/es/checkout/table.js +8 -1
  7. package/es/components/blockchain/tx.js +2 -1
  8. package/es/components/country-select.d.ts +16 -0
  9. package/es/components/country-select.js +82 -0
  10. package/es/components/input.d.ts +21 -21
  11. package/es/components/input.js +43 -42
  12. package/es/components/livemode.js +1 -0
  13. package/es/components/pricing-table.js +0 -2
  14. package/es/components/status.js +2 -3
  15. package/es/components/table.d.ts +2 -0
  16. package/es/components/table.js +186 -0
  17. package/es/contexts/payment.d.ts +2 -0
  18. package/es/contexts/payment.js +5 -2
  19. package/es/history/invoice/list.d.ts +5 -1
  20. package/es/history/invoice/list.js +218 -48
  21. package/es/hooks/mobile.d.ts +4 -0
  22. package/es/hooks/mobile.js +10 -0
  23. package/es/index.d.ts +5 -1
  24. package/es/index.js +7 -1
  25. package/es/libs/util.d.ts +15 -2
  26. package/es/libs/util.js +92 -28
  27. package/es/locales/en.js +23 -7
  28. package/es/locales/index.d.ts +0 -1
  29. package/es/locales/index.js +10 -1
  30. package/es/locales/zh.js +22 -6
  31. package/es/payment/error.js +2 -2
  32. package/es/payment/footer.js +1 -1
  33. package/es/payment/form/address.d.ts +9 -2
  34. package/es/payment/form/address.js +69 -69
  35. package/es/payment/form/currency.js +39 -25
  36. package/es/payment/form/index.d.ts +1 -1
  37. package/es/payment/form/index.js +83 -81
  38. package/es/payment/form/phone.js +15 -51
  39. package/es/payment/index.d.ts +1 -10
  40. package/es/payment/index.js +274 -219
  41. package/es/payment/product-card.js +4 -4
  42. package/es/payment/product-donation.js +7 -2
  43. package/es/payment/product-item.d.ts +2 -2
  44. package/es/payment/product-item.js +120 -81
  45. package/es/payment/summary.js +188 -118
  46. package/es/theme/index.css +240 -0
  47. package/es/theme/index.d.ts +9 -0
  48. package/es/theme/index.js +243 -0
  49. package/es/theme/typography.d.ts +2 -0
  50. package/es/theme/typography.js +53 -0
  51. package/es/types/index.d.ts +11 -0
  52. package/lib/checkout/donate.d.ts +2 -1
  53. package/lib/checkout/donate.js +14 -2
  54. package/lib/checkout/form.d.ts +1 -1
  55. package/lib/checkout/form.js +22 -1
  56. package/lib/checkout/table.d.ts +1 -1
  57. package/lib/checkout/table.js +14 -1
  58. package/lib/components/blockchain/tx.js +4 -1
  59. package/lib/components/country-select.d.ts +16 -0
  60. package/lib/components/country-select.js +115 -0
  61. package/lib/components/input.d.ts +21 -21
  62. package/lib/components/input.js +21 -12
  63. package/lib/components/livemode.js +1 -0
  64. package/lib/components/pricing-table.js +0 -2
  65. package/lib/components/status.js +2 -3
  66. package/lib/components/table.d.ts +2 -0
  67. package/lib/components/table.js +220 -0
  68. package/lib/contexts/payment.d.ts +2 -0
  69. package/lib/contexts/payment.js +4 -1
  70. package/lib/history/invoice/list.d.ts +5 -1
  71. package/lib/history/invoice/list.js +293 -62
  72. package/lib/hooks/mobile.d.ts +4 -0
  73. package/lib/hooks/mobile.js +17 -0
  74. package/lib/index.d.ts +5 -1
  75. package/lib/index.js +36 -0
  76. package/lib/libs/util.d.ts +15 -2
  77. package/lib/libs/util.js +115 -37
  78. package/lib/locales/en.js +23 -7
  79. package/lib/locales/index.d.ts +0 -1
  80. package/lib/locales/index.js +14 -3
  81. package/lib/locales/zh.js +22 -6
  82. package/lib/payment/error.js +5 -1
  83. package/lib/payment/footer.js +1 -1
  84. package/lib/payment/form/address.d.ts +9 -2
  85. package/lib/payment/form/address.js +67 -59
  86. package/lib/payment/form/currency.js +31 -24
  87. package/lib/payment/form/index.d.ts +1 -1
  88. package/lib/payment/form/index.js +92 -93
  89. package/lib/payment/form/phone.js +11 -59
  90. package/lib/payment/index.d.ts +1 -10
  91. package/lib/payment/index.js +291 -219
  92. package/lib/payment/product-card.js +5 -4
  93. package/lib/payment/product-donation.js +9 -2
  94. package/lib/payment/product-item.d.ts +2 -2
  95. package/lib/payment/product-item.js +38 -19
  96. package/lib/payment/summary.js +219 -127
  97. package/lib/theme/index.css +240 -0
  98. package/lib/theme/index.d.ts +9 -0
  99. package/lib/theme/index.js +259 -0
  100. package/lib/theme/typography.d.ts +2 -0
  101. package/lib/theme/typography.js +59 -0
  102. package/lib/types/index.d.ts +11 -0
  103. package/package.json +14 -11
  104. package/src/checkout/donate.tsx +16 -10
  105. package/src/checkout/form.tsx +23 -0
  106. package/src/checkout/table.tsx +13 -1
  107. package/src/components/blockchain/tx.tsx +2 -1
  108. package/src/components/country-select.tsx +93 -0
  109. package/src/components/input.tsx +49 -46
  110. package/src/components/livemode.tsx +1 -0
  111. package/src/components/pricing-table.tsx +0 -2
  112. package/src/components/status.tsx +1 -2
  113. package/src/components/table.tsx +200 -0
  114. package/src/contexts/payment.tsx +6 -1
  115. package/src/history/invoice/list.tsx +258 -49
  116. package/src/hooks/mobile.ts +13 -0
  117. package/src/index.ts +7 -0
  118. package/src/libs/util.ts +120 -31
  119. package/src/locales/en.tsx +19 -4
  120. package/src/locales/index.tsx +10 -3
  121. package/src/locales/zh.tsx +18 -3
  122. package/src/payment/error.tsx +2 -2
  123. package/src/payment/footer.tsx +1 -1
  124. package/src/payment/form/address.tsx +56 -47
  125. package/src/payment/form/currency.tsx +29 -23
  126. package/src/payment/form/index.tsx +89 -76
  127. package/src/payment/form/phone.tsx +14 -51
  128. package/src/payment/index.tsx +294 -242
  129. package/src/payment/product-card.tsx +4 -4
  130. package/src/payment/product-donation.tsx +7 -3
  131. package/src/payment/product-item.tsx +49 -20
  132. package/src/payment/summary.tsx +191 -108
  133. package/src/theme/index.css +240 -0
  134. package/src/theme/index.tsx +250 -0
  135. package/src/theme/typography.ts +56 -0
  136. 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.secondary" }
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: 120,
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): import("react").JSX.Element;
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
- return /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-start", spacing: 1, sx: { width: "100%" }, children: [
34
- /* @__PURE__ */ jsxs(Stack, { direction: "column", alignItems: "flex-end", sx: { width: "100%" }, children: [
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: "flex-start",
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
- description: item.price.product?.description,
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: pricing.primary }),
62
- pricing.secondary && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.85rem", color: "text.secondary" }, children: pricing.secondary })
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
- children
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
- component: "label",
74
- htmlFor: "upsell-switch",
72
+ label: formatQuantityInventory(item.price, item.quantity, locale),
73
+ variant: "outlined",
75
74
  sx: {
76
- fontSize: 12,
77
- cursor: "pointer",
78
- color: "text.primary"
79
- },
80
- children: [
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
- /* @__PURE__ */ jsx(Typography, { component: "span", sx: { fontSize: 12 }, children: formatPrice(item.price.upsell.upsells_to, currency, item.price.product?.unit_label, 1, true, locale) })
81
+ ) : null,
82
+ children
107
83
  ] }),
108
- canUpsell && item.upsell_price_id && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", sx: { width: "100%" }, children: [
109
- /* @__PURE__ */ jsxs(
110
- Typography,
111
- {
112
- component: "label",
113
- htmlFor: "upsell-switch",
114
- sx: {
115
- fontSize: 12,
116
- cursor: "pointer",
117
- color: "text.secondary"
118
- },
119
- children: [
120
- /* @__PURE__ */ jsx(
121
- Switch,
122
- {
123
- id: "upsell-switch",
124
- sx: { mr: 1 },
125
- variant: "success",
126
- checked: true,
127
- onChange: () => onDownsell(item.upsell_price_id)
128
- }
129
- ),
130
- t("payment.checkout.upsell.revert", {
131
- recurring: t(`common.${formatRecurring(item.price.recurring)}`)
132
- })
133
- ]
134
- }
135
- ),
136
- /* @__PURE__ */ jsx(Typography, { component: "span", sx: { fontSize: 12 }, children: formatPrice(item.price, currency, item.price.product?.unit_label, 1, true, locale) })
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
  }