@blocklet/payment-react 1.13.113
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/LICENSE +13 -0
- package/README.md +29 -0
- package/babel.config.es.js +8 -0
- package/build.config.ts +29 -0
- package/es/api.d.ts +2 -0
- package/es/api.js +18 -0
- package/es/checkout/index.d.ts +15 -0
- package/es/checkout/index.js +61 -0
- package/es/components/input.d.ts +23 -0
- package/es/components/input.js +44 -0
- package/es/components/livemode.d.ts +2 -0
- package/es/components/livemode.js +24 -0
- package/es/components/pricing-table.d.ts +18 -0
- package/es/components/pricing-table.js +175 -0
- package/es/components/status.d.ts +3 -0
- package/es/components/status.js +20 -0
- package/es/components/switch.d.ts +6 -0
- package/es/components/switch.js +42 -0
- package/es/contexts/payment.d.ts +29 -0
- package/es/contexts/payment.js +45 -0
- package/es/dayjs.d.ts +2 -0
- package/es/dayjs.js +14 -0
- package/es/index.d.ts +16 -0
- package/es/index.js +29 -0
- package/es/locales/en.d.ts +2 -0
- package/es/locales/en.js +213 -0
- package/es/locales/index.d.ts +10 -0
- package/es/locales/index.js +20 -0
- package/es/locales/zh.d.ts +2 -0
- package/es/locales/zh.js +213 -0
- package/es/payment/amount.d.ts +12 -0
- package/es/payment/amount.js +22 -0
- package/es/payment/error.d.ts +13 -0
- package/es/payment/error.js +12 -0
- package/es/payment/footer.d.ts +4 -0
- package/es/payment/footer.js +9 -0
- package/es/payment/form/addon.d.ts +2 -0
- package/es/payment/form/addon.js +14 -0
- package/es/payment/form/address.d.ts +7 -0
- package/es/payment/form/address.js +119 -0
- package/es/payment/form/index.d.ts +9 -0
- package/es/payment/form/index.js +337 -0
- package/es/payment/form/phone.d.ts +4 -0
- package/es/payment/form/phone.js +97 -0
- package/es/payment/form/stripe.d.ts +13 -0
- package/es/payment/form/stripe.js +158 -0
- package/es/payment/header.d.ts +7 -0
- package/es/payment/header.js +29 -0
- package/es/payment/index.d.ts +28 -0
- package/es/payment/index.js +327 -0
- package/es/payment/product-card.d.ts +21 -0
- package/es/payment/product-card.js +34 -0
- package/es/payment/product-item.d.ts +19 -0
- package/es/payment/product-item.js +107 -0
- package/es/payment/product-skeleton.d.ts +4 -0
- package/es/payment/product-skeleton.js +34 -0
- package/es/payment/skeleton/overview.d.ts +2 -0
- package/es/payment/skeleton/overview.js +13 -0
- package/es/payment/skeleton/payment.d.ts +2 -0
- package/es/payment/skeleton/payment.js +19 -0
- package/es/payment/success.d.ts +8 -0
- package/es/payment/success.js +164 -0
- package/es/payment/summary.d.ts +12 -0
- package/es/payment/summary.js +178 -0
- package/es/theme.d.ts +1 -0
- package/es/theme.js +17 -0
- package/es/types/index.d.ts +19 -0
- package/es/types/index.js +0 -0
- package/es/types/shims.d.ts +18 -0
- package/es/util.d.ts +52 -0
- package/es/util.js +390 -0
- package/lib/api.d.ts +2 -0
- package/lib/api.js +26 -0
- package/lib/checkout/index.d.ts +15 -0
- package/lib/checkout/index.js +83 -0
- package/lib/components/input.d.ts +23 -0
- package/lib/components/input.js +72 -0
- package/lib/components/livemode.d.ts +2 -0
- package/lib/components/livemode.js +29 -0
- package/lib/components/pricing-table.d.ts +18 -0
- package/lib/components/pricing-table.js +232 -0
- package/lib/components/status.d.ts +3 -0
- package/lib/components/status.js +23 -0
- package/lib/components/switch.d.ts +6 -0
- package/lib/components/switch.js +51 -0
- package/lib/contexts/payment.d.ts +29 -0
- package/lib/contexts/payment.js +73 -0
- package/lib/dayjs.d.ts +2 -0
- package/lib/dayjs.js +21 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +143 -0
- package/lib/locales/en.d.ts +2 -0
- package/lib/locales/en.js +220 -0
- package/lib/locales/index.d.ts +10 -0
- package/lib/locales/index.js +33 -0
- package/lib/locales/zh.d.ts +2 -0
- package/lib/locales/zh.js +220 -0
- package/lib/payment/amount.d.ts +12 -0
- package/lib/payment/amount.js +28 -0
- package/lib/payment/error.d.ts +13 -0
- package/lib/payment/error.js +52 -0
- package/lib/payment/footer.d.ts +4 -0
- package/lib/payment/footer.js +25 -0
- package/lib/payment/form/addon.d.ts +2 -0
- package/lib/payment/form/addon.js +37 -0
- package/lib/payment/form/address.d.ts +7 -0
- package/lib/payment/form/address.js +152 -0
- package/lib/payment/form/index.d.ts +9 -0
- package/lib/payment/form/index.js +464 -0
- package/lib/payment/form/phone.d.ts +4 -0
- package/lib/payment/form/phone.js +133 -0
- package/lib/payment/form/stripe.d.ts +13 -0
- package/lib/payment/form/stripe.js +213 -0
- package/lib/payment/header.d.ts +7 -0
- package/lib/payment/header.js +58 -0
- package/lib/payment/index.d.ts +28 -0
- package/lib/payment/index.js +382 -0
- package/lib/payment/product-card.d.ts +21 -0
- package/lib/payment/product-card.js +81 -0
- package/lib/payment/product-item.d.ts +19 -0
- package/lib/payment/product-item.js +160 -0
- package/lib/payment/product-skeleton.d.ts +4 -0
- package/lib/payment/product-skeleton.js +71 -0
- package/lib/payment/skeleton/overview.d.ts +2 -0
- package/lib/payment/skeleton/overview.js +48 -0
- package/lib/payment/skeleton/payment.d.ts +2 -0
- package/lib/payment/skeleton/payment.js +54 -0
- package/lib/payment/success.d.ts +8 -0
- package/lib/payment/success.js +215 -0
- package/lib/payment/summary.d.ts +12 -0
- package/lib/payment/summary.js +225 -0
- package/lib/theme.d.ts +1 -0
- package/lib/theme.js +19 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/index.js +1 -0
- package/lib/types/shims.d.ts +18 -0
- package/lib/util.d.ts +52 -0
- package/lib/util.js +487 -0
- package/package.json +104 -0
- package/src/api.ts +24 -0
- package/src/checkout/index.tsx +74 -0
- package/src/components/input.tsx +58 -0
- package/src/components/livemode.tsx +23 -0
- package/src/components/pricing-table.tsx +207 -0
- package/src/components/status.tsx +19 -0
- package/src/components/switch.tsx +48 -0
- package/src/contexts/payment.tsx +74 -0
- package/src/dayjs.ts +17 -0
- package/src/index.ts +32 -0
- package/src/locales/en.tsx +218 -0
- package/src/locales/index.tsx +30 -0
- package/src/locales/zh.tsx +214 -0
- package/src/payment/amount.tsx +24 -0
- package/src/payment/error.tsx +29 -0
- package/src/payment/footer.tsx +12 -0
- package/src/payment/form/addon.tsx +24 -0
- package/src/payment/form/address.tsx +119 -0
- package/src/payment/form/index.tsx +401 -0
- package/src/payment/form/phone.tsx +103 -0
- package/src/payment/form/stripe.tsx +195 -0
- package/src/payment/header.tsx +40 -0
- package/src/payment/index.tsx +367 -0
- package/src/payment/product-card.tsx +55 -0
- package/src/payment/product-item.tsx +121 -0
- package/src/payment/product-skeleton.tsx +39 -0
- package/src/payment/skeleton/overview.tsx +21 -0
- package/src/payment/skeleton/payment.tsx +35 -0
- package/src/payment/success.tsx +186 -0
- package/src/payment/summary.tsx +198 -0
- package/src/theme.ts +18 -0
- package/src/types/index.ts +29 -0
- package/src/types/shims.d.ts +18 -0
- package/src/util.ts +543 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = PricingTable;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
9
|
+
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
10
|
+
var _iconsMaterial = require("@mui/icons-material");
|
|
11
|
+
var _lab = require("@mui/lab");
|
|
12
|
+
var _material = require("@mui/material");
|
|
13
|
+
var _ahooks = require("ahooks");
|
|
14
|
+
var _react = require("react");
|
|
15
|
+
var _amount = _interopRequireDefault(require("../payment/amount"));
|
|
16
|
+
var _util = require("../util");
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
const groupItemsByRecurring = items => {
|
|
19
|
+
const grouped = {};
|
|
20
|
+
const recurring = {};
|
|
21
|
+
items.forEach(x => {
|
|
22
|
+
const key = [x.price.recurring?.interval, x.price.recurring?.interval_count].join("-");
|
|
23
|
+
recurring[key] = x.price.recurring;
|
|
24
|
+
if (!grouped[key]) {
|
|
25
|
+
grouped[key] = [];
|
|
26
|
+
}
|
|
27
|
+
grouped[key].push(x);
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
recurring,
|
|
31
|
+
grouped
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
PricingTable.defaultProps = {
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
mode: "checkout",
|
|
37
|
+
interval: ""
|
|
38
|
+
};
|
|
39
|
+
function PricingTable({
|
|
40
|
+
table,
|
|
41
|
+
alignItems,
|
|
42
|
+
interval,
|
|
43
|
+
mode,
|
|
44
|
+
onSelect
|
|
45
|
+
}) {
|
|
46
|
+
const {
|
|
47
|
+
t,
|
|
48
|
+
locale
|
|
49
|
+
} = (0, _context.useLocaleContext)();
|
|
50
|
+
const [state, setState] = (0, _ahooks.useSetState)({
|
|
51
|
+
interval,
|
|
52
|
+
loading: ""
|
|
53
|
+
});
|
|
54
|
+
const {
|
|
55
|
+
recurring,
|
|
56
|
+
grouped
|
|
57
|
+
} = groupItemsByRecurring(table.items);
|
|
58
|
+
(0, _react.useEffect)(() => {
|
|
59
|
+
if (table) {
|
|
60
|
+
if (!state.interval || !grouped[state.interval]) {
|
|
61
|
+
const keys = Object.keys(recurring);
|
|
62
|
+
if (keys[0]) {
|
|
63
|
+
setState({
|
|
64
|
+
interval: keys[0]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [table]);
|
|
70
|
+
const handleSelect = async priceId => {
|
|
71
|
+
try {
|
|
72
|
+
setState({
|
|
73
|
+
loading: priceId
|
|
74
|
+
});
|
|
75
|
+
await onSelect(priceId);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error(err);
|
|
78
|
+
_Toast.default.error((0, _util.formatError)(err));
|
|
79
|
+
} finally {
|
|
80
|
+
setState({
|
|
81
|
+
loading: ""
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
86
|
+
direction: "column",
|
|
87
|
+
alignItems: alignItems === "center" ? "center" : "flex-start",
|
|
88
|
+
sx: {
|
|
89
|
+
pt: {
|
|
90
|
+
xs: 4,
|
|
91
|
+
sm: 2
|
|
92
|
+
},
|
|
93
|
+
gap: {
|
|
94
|
+
xs: 3,
|
|
95
|
+
sm: mode === "select" ? 3 : 5
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
children: [Object.keys(recurring).length > 1 && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ToggleButtonGroup, {
|
|
99
|
+
color: "primary",
|
|
100
|
+
value: state.interval,
|
|
101
|
+
onChange: (_, value) => {
|
|
102
|
+
if (value !== null) {
|
|
103
|
+
setState({
|
|
104
|
+
interval: value
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
exclusive: true,
|
|
109
|
+
children: Object.keys(recurring).map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ToggleButton, {
|
|
110
|
+
value: x,
|
|
111
|
+
sx: {
|
|
112
|
+
textTransform: "capitalize"
|
|
113
|
+
},
|
|
114
|
+
children: (0, _util.formatRecurring)(recurring[x], true, "", locale)
|
|
115
|
+
}, x))
|
|
116
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
117
|
+
flexWrap: "wrap",
|
|
118
|
+
direction: "row",
|
|
119
|
+
gap: {
|
|
120
|
+
xs: 3,
|
|
121
|
+
sm: 5,
|
|
122
|
+
md: mode === "checkout" ? 10 : 5
|
|
123
|
+
},
|
|
124
|
+
justifyContent: alignItems === "center" ? "center" : "flex-start",
|
|
125
|
+
children: grouped[state.interval]?.map(x => {
|
|
126
|
+
let action = x.subscription_data?.trial_period_days ? t("payment.checkout.try") : t("payment.checkout.subscription");
|
|
127
|
+
if (mode === "select") {
|
|
128
|
+
action = x.is_selected ? t("payment.checkout.selected") : t("payment.checkout.select");
|
|
129
|
+
}
|
|
130
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
|
|
131
|
+
in: true,
|
|
132
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
133
|
+
padding: 4,
|
|
134
|
+
spacing: 2,
|
|
135
|
+
direction: "column",
|
|
136
|
+
alignItems: "center",
|
|
137
|
+
sx: {
|
|
138
|
+
width: 320,
|
|
139
|
+
cursor: "pointer",
|
|
140
|
+
borderWidth: "1px",
|
|
141
|
+
borderStyle: "solid",
|
|
142
|
+
borderColor: mode === "select" && x.is_selected ? "primary.main" : "#eee",
|
|
143
|
+
borderRadius: 1,
|
|
144
|
+
transition: "border-color 0.3s ease 0s, box-shadow 0.3s ease 0s",
|
|
145
|
+
boxShadow: "0 4px 8px rgba(0, 0, 0, 20%)",
|
|
146
|
+
"&:hover": {
|
|
147
|
+
borderColor: mode === "select" && x.is_selected ? "primary.main" : "#ddd",
|
|
148
|
+
boxShadow: "0 8px 16px rgba(0, 0, 0, 20%)"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
152
|
+
textAlign: "center",
|
|
153
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
154
|
+
direction: "row",
|
|
155
|
+
alignItems: "center",
|
|
156
|
+
spacing: 1,
|
|
157
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
158
|
+
variant: "h5",
|
|
159
|
+
color: "text.primary",
|
|
160
|
+
fontWeight: 600,
|
|
161
|
+
children: x.product.name
|
|
162
|
+
}), x.is_highlight && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Chip, {
|
|
163
|
+
label: x.highlight_text,
|
|
164
|
+
color: "default",
|
|
165
|
+
size: "small"
|
|
166
|
+
})]
|
|
167
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
168
|
+
color: "text.secondary",
|
|
169
|
+
children: x.product.description
|
|
170
|
+
})]
|
|
171
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
172
|
+
direction: "row",
|
|
173
|
+
alignItems: "center",
|
|
174
|
+
spacing: 1,
|
|
175
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_amount.default, {
|
|
176
|
+
amount: (0, _util.formatPriceAmount)(x.price, table.currency, x.product.unit_label)
|
|
177
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
178
|
+
direction: "column",
|
|
179
|
+
alignItems: "flex-start",
|
|
180
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
181
|
+
component: "span",
|
|
182
|
+
color: "text.secondary",
|
|
183
|
+
fontSize: "0.8rem",
|
|
184
|
+
children: t("payment.checkout.per")
|
|
185
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
186
|
+
component: "span",
|
|
187
|
+
color: "text.secondary",
|
|
188
|
+
fontSize: "0.8rem",
|
|
189
|
+
children: (0, _util.formatRecurring)(x.price.recurring, false, "", locale)
|
|
190
|
+
})]
|
|
191
|
+
})]
|
|
192
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
|
|
193
|
+
fullWidth: true,
|
|
194
|
+
size: "large",
|
|
195
|
+
loadingPosition: "end",
|
|
196
|
+
variant: x.is_highlight || x.is_selected ? "contained" : "outlined",
|
|
197
|
+
color: x.is_highlight || x.is_selected ? "primary" : "info",
|
|
198
|
+
sx: {
|
|
199
|
+
fontSize: "1.2rem"
|
|
200
|
+
},
|
|
201
|
+
loading: state.loading === x.price_id,
|
|
202
|
+
disabled: x.is_disabled,
|
|
203
|
+
onClick: () => handleSelect(x.price_id),
|
|
204
|
+
children: action
|
|
205
|
+
}), x.product.features.length > 0 && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
206
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
207
|
+
children: t("payment.checkout.include")
|
|
208
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.List, {
|
|
209
|
+
dense: true,
|
|
210
|
+
children: x.product.features.map(f => /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.ListItem, {
|
|
211
|
+
disableGutters: true,
|
|
212
|
+
disablePadding: true,
|
|
213
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ListItemIcon, {
|
|
214
|
+
sx: {
|
|
215
|
+
minWidth: 25
|
|
216
|
+
},
|
|
217
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_iconsMaterial.CheckOutlined, {
|
|
218
|
+
color: "success",
|
|
219
|
+
fontSize: "small"
|
|
220
|
+
})
|
|
221
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.ListItemText, {
|
|
222
|
+
primary: f.name
|
|
223
|
+
})]
|
|
224
|
+
}, f.name))
|
|
225
|
+
})]
|
|
226
|
+
})]
|
|
227
|
+
})
|
|
228
|
+
}, x.price_id);
|
|
229
|
+
})
|
|
230
|
+
})]
|
|
231
|
+
});
|
|
232
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = Status;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _material = require("@mui/material");
|
|
9
|
+
function Status(props) {
|
|
10
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Chip, {
|
|
11
|
+
size: "small",
|
|
12
|
+
variant: "outlined",
|
|
13
|
+
...props,
|
|
14
|
+
sx: {
|
|
15
|
+
...(props.sx || {}),
|
|
16
|
+
borderRadius: "4px",
|
|
17
|
+
height: 20,
|
|
18
|
+
lineHeight: 1,
|
|
19
|
+
textTransform: "capitalize",
|
|
20
|
+
marginRight: "10px"
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LiteralUnion } from 'type-fest';
|
|
2
|
+
type SwitchProps = {
|
|
3
|
+
variant?: LiteralUnion<'success' | 'error' | 'warning' | 'info' | 'primary' | 'secondary', string>;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: import("@emotion/styled").StyledComponent<import("@mui/material").SwitchProps & import("@mui/system").MUIStyledCommonProps<import("@mui/system").Theme> & SwitchProps, {}, {}>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _material = require("@mui/material");
|
|
8
|
+
var _system = require("@mui/system");
|
|
9
|
+
module.exports = (0, _system.styled)(_material.Switch)(({
|
|
10
|
+
variant = "success",
|
|
11
|
+
theme
|
|
12
|
+
}) => ({
|
|
13
|
+
width: 28,
|
|
14
|
+
height: 16,
|
|
15
|
+
padding: 0,
|
|
16
|
+
display: "inline-flex",
|
|
17
|
+
"&:active": {
|
|
18
|
+
"& .MuiSwitch-thumb": {
|
|
19
|
+
width: 15
|
|
20
|
+
},
|
|
21
|
+
"& .MuiSwitch-switchBase.Mui-checked": {
|
|
22
|
+
transform: "translateX(9px)"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"& .MuiSwitch-switchBase": {
|
|
26
|
+
padding: 2,
|
|
27
|
+
"&.Mui-checked": {
|
|
28
|
+
transform: "translateX(12px)",
|
|
29
|
+
color: "#fff",
|
|
30
|
+
"& + .MuiSwitch-track": {
|
|
31
|
+
opacity: 1,
|
|
32
|
+
backgroundColor: theme.palette[variant].light
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"& .MuiSwitch-thumb": {
|
|
37
|
+
boxShadow: "0 2px 4px 0 rgb(0 35 11 / 20%)",
|
|
38
|
+
width: 12,
|
|
39
|
+
height: 12,
|
|
40
|
+
borderRadius: 6,
|
|
41
|
+
transition: theme.transitions.create(["width"], {
|
|
42
|
+
duration: 200
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
"& .MuiSwitch-track": {
|
|
46
|
+
borderRadius: 16 / 2,
|
|
47
|
+
opacity: 1,
|
|
48
|
+
backgroundColor: theme.palette.mode === "dark" ? "rgba(255,255,255,.35)" : "rgba(0,0,0,.25)",
|
|
49
|
+
boxSizing: "border-box"
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { TPaymentCurrency, TPaymentMethodExpanded } from '@blocklet/payment-types';
|
|
3
|
+
import type { Axios } from 'axios';
|
|
4
|
+
export interface Settings {
|
|
5
|
+
paymentMethods: TPaymentMethodExpanded[];
|
|
6
|
+
baseCurrency: TPaymentCurrency;
|
|
7
|
+
}
|
|
8
|
+
export type PaymentContextType = {
|
|
9
|
+
livemode: boolean;
|
|
10
|
+
session: any;
|
|
11
|
+
connect: any;
|
|
12
|
+
prefix: string;
|
|
13
|
+
settings: Settings;
|
|
14
|
+
refresh: () => void;
|
|
15
|
+
setLivemode: (livemode: boolean) => void;
|
|
16
|
+
api: Axios;
|
|
17
|
+
};
|
|
18
|
+
declare const PaymentContext: import("react").Context<PaymentContextType>;
|
|
19
|
+
declare const Consumer: import("react").Consumer<PaymentContextType>;
|
|
20
|
+
declare function PaymentProvider({ children, session, connect }: {
|
|
21
|
+
children: any;
|
|
22
|
+
session: any;
|
|
23
|
+
connect: any;
|
|
24
|
+
}): JSX.Element;
|
|
25
|
+
declare namespace PaymentProvider {
|
|
26
|
+
var defaultProps: {};
|
|
27
|
+
}
|
|
28
|
+
declare function usePaymentContext(): PaymentContextType;
|
|
29
|
+
export { PaymentContext, PaymentProvider, Consumer as SettingsConsumer, usePaymentContext };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PaymentContext = void 0;
|
|
7
|
+
exports.PaymentProvider = PaymentProvider;
|
|
8
|
+
exports.SettingsConsumer = void 0;
|
|
9
|
+
exports.usePaymentContext = usePaymentContext;
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
var _material = require("@mui/material");
|
|
12
|
+
var _ahooks = require("ahooks");
|
|
13
|
+
var _react = require("react");
|
|
14
|
+
var _api = _interopRequireDefault(require("../api"));
|
|
15
|
+
var _util = require("../util");
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
const prefix = (0, _util.getPrefix)();
|
|
18
|
+
const PaymentContext = exports.PaymentContext = (0, _react.createContext)({
|
|
19
|
+
api: _api.default
|
|
20
|
+
});
|
|
21
|
+
const {
|
|
22
|
+
Provider,
|
|
23
|
+
Consumer
|
|
24
|
+
} = PaymentContext;
|
|
25
|
+
exports.SettingsConsumer = Consumer;
|
|
26
|
+
const getSettings = async () => {
|
|
27
|
+
const {
|
|
28
|
+
data
|
|
29
|
+
} = await _api.default.get("/api/settings");
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
32
|
+
function PaymentProvider({
|
|
33
|
+
children,
|
|
34
|
+
session,
|
|
35
|
+
connect
|
|
36
|
+
}) {
|
|
37
|
+
const {
|
|
38
|
+
data,
|
|
39
|
+
error,
|
|
40
|
+
run,
|
|
41
|
+
loading
|
|
42
|
+
} = (0, _ahooks.useRequest)(getSettings);
|
|
43
|
+
const [livemode, setLivemode] = (0, _ahooks.useLocalStorageState)("livemode", {
|
|
44
|
+
defaultValue: true
|
|
45
|
+
});
|
|
46
|
+
if (error) {
|
|
47
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Alert, {
|
|
48
|
+
severity: "error",
|
|
49
|
+
children: error.message
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (loading) {
|
|
53
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CircularProgress, {});
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Provider, {
|
|
56
|
+
value: {
|
|
57
|
+
session,
|
|
58
|
+
connect,
|
|
59
|
+
prefix,
|
|
60
|
+
livemode: !!livemode,
|
|
61
|
+
settings: data,
|
|
62
|
+
refresh: run,
|
|
63
|
+
setLivemode,
|
|
64
|
+
api: _api.default
|
|
65
|
+
},
|
|
66
|
+
children
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function usePaymentContext() {
|
|
70
|
+
const context = (0, _react.useContext)(PaymentContext);
|
|
71
|
+
return context;
|
|
72
|
+
}
|
|
73
|
+
PaymentProvider.defaultProps = {};
|
package/lib/dayjs.d.ts
ADDED
package/lib/dayjs.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
8
|
+
var _duration = _interopRequireDefault(require("dayjs/plugin/duration"));
|
|
9
|
+
var _localizedFormat = _interopRequireDefault(require("dayjs/plugin/localizedFormat"));
|
|
10
|
+
var _relativeTime = _interopRequireDefault(require("dayjs/plugin/relativeTime"));
|
|
11
|
+
var _timezone = _interopRequireDefault(require("dayjs/plugin/timezone"));
|
|
12
|
+
var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
Promise.resolve().then(() => require("dayjs/locale/en"));
|
|
15
|
+
Promise.resolve().then(() => require("dayjs/locale/zh"));
|
|
16
|
+
_dayjs.default.extend(_relativeTime.default);
|
|
17
|
+
_dayjs.default.extend(_localizedFormat.default);
|
|
18
|
+
_dayjs.default.extend(_duration.default);
|
|
19
|
+
_dayjs.default.extend(_utc.default);
|
|
20
|
+
_dayjs.default.extend(_timezone.default);
|
|
21
|
+
module.exports = _dayjs.default;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import api from './api';
|
|
2
|
+
import Checkout from './checkout';
|
|
3
|
+
import FormInput from './components/input';
|
|
4
|
+
import Livemode from './components/livemode';
|
|
5
|
+
import PricingTable from './components/pricing-table';
|
|
6
|
+
import Status from './components/status';
|
|
7
|
+
import Switch from './components/switch';
|
|
8
|
+
import dayjs from './dayjs';
|
|
9
|
+
import Amount from './payment/amount';
|
|
10
|
+
import PhoneInput from './payment/form/phone';
|
|
11
|
+
import Payment from './payment/index';
|
|
12
|
+
import ProductSkeleton from './payment/product-skeleton';
|
|
13
|
+
export * from './util';
|
|
14
|
+
export * from './contexts/payment';
|
|
15
|
+
export { translations, createTranslator } from './locales';
|
|
16
|
+
export { api, dayjs, FormInput, PhoneInput, Status, Livemode, Switch, Checkout, Payment, PricingTable, ProductSkeleton, Amount, };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
api: true,
|
|
8
|
+
Checkout: true,
|
|
9
|
+
FormInput: true,
|
|
10
|
+
Livemode: true,
|
|
11
|
+
PricingTable: true,
|
|
12
|
+
Status: true,
|
|
13
|
+
Switch: true,
|
|
14
|
+
dayjs: true,
|
|
15
|
+
Amount: true,
|
|
16
|
+
PhoneInput: true,
|
|
17
|
+
Payment: true,
|
|
18
|
+
ProductSkeleton: true,
|
|
19
|
+
translations: true,
|
|
20
|
+
createTranslator: true
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "Amount", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _amount.default;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "Checkout", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _checkout.default;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "FormInput", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _input.default;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "Livemode", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return _livemode.default;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "Payment", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _index.default;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "PhoneInput", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _phone.default;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(exports, "PricingTable", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _pricingTable.default;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "ProductSkeleton", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _productSkeleton.default;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(exports, "Status", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return _status.default;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "Switch", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _switch.default;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(exports, "api", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () {
|
|
85
|
+
return _api.default;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "createTranslator", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () {
|
|
91
|
+
return _locales.createTranslator;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "dayjs", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function () {
|
|
97
|
+
return _dayjs.default;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "translations", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () {
|
|
103
|
+
return _locales.translations;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
var _api = _interopRequireDefault(require("./api"));
|
|
107
|
+
var _checkout = _interopRequireDefault(require("./checkout"));
|
|
108
|
+
var _input = _interopRequireDefault(require("./components/input"));
|
|
109
|
+
var _livemode = _interopRequireDefault(require("./components/livemode"));
|
|
110
|
+
var _pricingTable = _interopRequireDefault(require("./components/pricing-table"));
|
|
111
|
+
var _status = _interopRequireDefault(require("./components/status"));
|
|
112
|
+
var _switch = _interopRequireDefault(require("./components/switch"));
|
|
113
|
+
var _dayjs = _interopRequireDefault(require("./dayjs"));
|
|
114
|
+
var _amount = _interopRequireDefault(require("./payment/amount"));
|
|
115
|
+
var _phone = _interopRequireDefault(require("./payment/form/phone"));
|
|
116
|
+
var _index = _interopRequireDefault(require("./payment/index"));
|
|
117
|
+
var _productSkeleton = _interopRequireDefault(require("./payment/product-skeleton"));
|
|
118
|
+
var _util = require("./util");
|
|
119
|
+
Object.keys(_util).forEach(function (key) {
|
|
120
|
+
if (key === "default" || key === "__esModule") return;
|
|
121
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
122
|
+
if (key in exports && exports[key] === _util[key]) return;
|
|
123
|
+
Object.defineProperty(exports, key, {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function () {
|
|
126
|
+
return _util[key];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
var _payment = require("./contexts/payment");
|
|
131
|
+
Object.keys(_payment).forEach(function (key) {
|
|
132
|
+
if (key === "default" || key === "__esModule") return;
|
|
133
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
134
|
+
if (key in exports && exports[key] === _payment[key]) return;
|
|
135
|
+
Object.defineProperty(exports, key, {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function () {
|
|
138
|
+
return _payment[key];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
var _locales = require("./locales");
|
|
143
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|