@blocklet/payment-react 1.18.0 → 1.18.1
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 +40 -10
- package/es/checkout/form.d.ts +2 -1
- package/es/checkout/form.js +32 -45
- package/es/components/payment-beneficiaries.d.ts +24 -0
- package/es/components/payment-beneficiaries.js +70 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/locales/en.js +13 -1
- package/es/locales/zh.js +13 -1
- package/es/payment/donation-form.d.ts +24 -0
- package/es/payment/donation-form.js +603 -0
- package/es/payment/error.d.ts +1 -1
- package/es/payment/error.js +11 -1
- package/es/payment/form/index.d.ts +9 -3
- package/es/payment/form/index.js +39 -4
- package/es/payment/product-donation.js +98 -57
- package/es/payment/skeleton/donation.d.ts +1 -0
- package/es/payment/skeleton/donation.js +30 -0
- package/es/theme/index.js +3 -0
- package/es/types/index.d.ts +2 -0
- package/lib/checkout/donate.js +76 -10
- package/lib/checkout/form.d.ts +2 -1
- package/lib/checkout/form.js +39 -49
- package/lib/components/payment-beneficiaries.d.ts +24 -0
- package/lib/components/payment-beneficiaries.js +113 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -0
- package/lib/locales/en.js +13 -1
- package/lib/locales/zh.js +13 -1
- package/lib/payment/donation-form.d.ts +24 -0
- package/lib/payment/donation-form.js +644 -0
- package/lib/payment/error.d.ts +1 -1
- package/lib/payment/error.js +2 -2
- package/lib/payment/form/index.d.ts +9 -3
- package/lib/payment/form/index.js +35 -2
- package/lib/payment/product-donation.js +140 -73
- package/lib/payment/skeleton/donation.d.ts +1 -0
- package/lib/payment/skeleton/donation.js +66 -0
- package/lib/theme/index.js +3 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +3 -3
- package/src/checkout/donate.tsx +54 -11
- package/src/checkout/form.tsx +17 -31
- package/src/components/payment-beneficiaries.tsx +97 -0
- package/src/index.ts +2 -0
- package/src/locales/en.tsx +12 -0
- package/src/locales/zh.tsx +12 -0
- package/src/payment/donation-form.tsx +646 -0
- package/src/payment/error.tsx +13 -4
- package/src/payment/form/index.tsx +46 -4
- package/src/payment/product-donation.tsx +91 -40
- package/src/payment/skeleton/donation.tsx +35 -0
- package/src/theme/index.tsx +3 -0
- package/src/types/index.ts +2 -0
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
module.exports = PaymentForm;
|
|
7
|
+
exports.waitForCheckoutComplete = exports.hasDidWallet = void 0;
|
|
7
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
9
|
require("react-international-phone/style.css");
|
|
9
10
|
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
@@ -51,11 +52,15 @@ const waitForCheckoutComplete = async sessionId => {
|
|
|
51
52
|
});
|
|
52
53
|
return result;
|
|
53
54
|
};
|
|
55
|
+
exports.waitForCheckoutComplete = waitForCheckoutComplete;
|
|
54
56
|
const hasDidWallet = user => {
|
|
55
57
|
const connected = user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
|
|
56
58
|
return connected.some(x => x.provider === "wallet");
|
|
57
59
|
};
|
|
58
|
-
|
|
60
|
+
exports.hasDidWallet = hasDidWallet;
|
|
61
|
+
PaymentForm.defaultProps = {
|
|
62
|
+
onlyShowBtn: false
|
|
63
|
+
};
|
|
59
64
|
function PaymentForm({
|
|
60
65
|
checkoutSession,
|
|
61
66
|
paymentMethods,
|
|
@@ -66,7 +71,8 @@ function PaymentForm({
|
|
|
66
71
|
onError,
|
|
67
72
|
// mode,
|
|
68
73
|
action,
|
|
69
|
-
currencyId
|
|
74
|
+
currencyId,
|
|
75
|
+
onlyShowBtn
|
|
70
76
|
}) {
|
|
71
77
|
const {
|
|
72
78
|
t
|
|
@@ -379,6 +385,33 @@ function PaymentForm({
|
|
|
379
385
|
stripePaying: false
|
|
380
386
|
});
|
|
381
387
|
};
|
|
388
|
+
if (onlyShowBtn) {
|
|
389
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
390
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
391
|
+
className: "cko-payment-submit-btn",
|
|
392
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_lab.LoadingButton, {
|
|
393
|
+
variant: "contained",
|
|
394
|
+
color: "primary",
|
|
395
|
+
size: "large",
|
|
396
|
+
className: "cko-submit-button",
|
|
397
|
+
onClick: onAction,
|
|
398
|
+
fullWidth: true,
|
|
399
|
+
disabled: state.submitting || state.paying || state.stripePaying || !quantityInventoryStatus || !payable,
|
|
400
|
+
loading: state.submitting || state.paying,
|
|
401
|
+
children: state.submitting || state.paying ? t("payment.checkout.processing") : buttonText
|
|
402
|
+
})
|
|
403
|
+
}), state.customerLimited && /* @__PURE__ */(0, _jsxRuntime.jsx)(_confirm.default, {
|
|
404
|
+
onConfirm: () => window.open((0, _ufo.joinURL)((0, _util.getPrefix)(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`), "_self"),
|
|
405
|
+
onCancel: () => setState({
|
|
406
|
+
customerLimited: false
|
|
407
|
+
}),
|
|
408
|
+
confirm: t("payment.customer.pastDue.alert.confirm"),
|
|
409
|
+
title: t("payment.customer.pastDue.alert.title"),
|
|
410
|
+
message: t("payment.customer.pastDue.alert.description"),
|
|
411
|
+
color: "primary"
|
|
412
|
+
})]
|
|
413
|
+
});
|
|
414
|
+
}
|
|
382
415
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
383
416
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
|
|
384
417
|
in: true,
|
|
@@ -9,11 +9,9 @@ var _context = require("@arcblock/ux/lib/Locale/context");
|
|
|
9
9
|
var _material = require("@mui/material");
|
|
10
10
|
var _ahooks = require("ahooks");
|
|
11
11
|
var _react = require("react");
|
|
12
|
-
var _switchButton = _interopRequireDefault(require("../components/switch-button"));
|
|
13
12
|
var _util = require("../libs/util");
|
|
14
13
|
var _payment = require("../contexts/payment");
|
|
15
14
|
var _scroll = require("../hooks/scroll");
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
15
|
function ProductDonation({
|
|
18
16
|
item,
|
|
19
17
|
settings,
|
|
@@ -28,13 +26,17 @@ function ProductDonation({
|
|
|
28
26
|
setPayable
|
|
29
27
|
} = (0, _payment.usePaymentContext)();
|
|
30
28
|
(0, _scroll.usePreventWheel)();
|
|
31
|
-
const
|
|
29
|
+
const presets = settings?.amount?.presets || [];
|
|
30
|
+
const preset = settings?.amount?.preset || presets?.[0] || "0";
|
|
31
|
+
const supportPreset = presets.length > 0;
|
|
32
|
+
const supportCustom = !!settings?.amount?.custom;
|
|
32
33
|
const [state, setState] = (0, _ahooks.useSetState)({
|
|
33
34
|
selected: preset,
|
|
34
35
|
input: "",
|
|
35
|
-
custom:
|
|
36
|
+
custom: !supportPreset,
|
|
36
37
|
error: ""
|
|
37
38
|
});
|
|
39
|
+
const customInputRef = (0, _react.useRef)(null);
|
|
38
40
|
(0, _react.useEffect)(() => {
|
|
39
41
|
if (settings.amount.preset) {
|
|
40
42
|
setState({
|
|
@@ -56,6 +58,13 @@ function ProductDonation({
|
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
}, [settings.amount.preset, settings.amount.presets]);
|
|
61
|
+
(0, _react.useEffect)(() => {
|
|
62
|
+
if (state.custom) {
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
customInputRef.current?.focus();
|
|
65
|
+
}, 0);
|
|
66
|
+
}
|
|
67
|
+
}, [state.custom]);
|
|
59
68
|
const handleSelect = amount => {
|
|
60
69
|
setState({
|
|
61
70
|
selected: amount,
|
|
@@ -103,93 +112,151 @@ function ProductDonation({
|
|
|
103
112
|
amount: value
|
|
104
113
|
});
|
|
105
114
|
};
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
error: ""
|
|
112
|
-
});
|
|
113
|
-
} else {
|
|
114
|
-
setPayable(true);
|
|
115
|
-
handleSelect(preset);
|
|
116
|
-
}
|
|
115
|
+
const handleCustomSelect = () => {
|
|
116
|
+
setState({
|
|
117
|
+
custom: true,
|
|
118
|
+
error: ""
|
|
119
|
+
});
|
|
117
120
|
};
|
|
118
121
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
119
122
|
display: "flex",
|
|
120
123
|
flexDirection: "column",
|
|
121
124
|
alignItems: "flex-start",
|
|
122
125
|
gap: 1.5,
|
|
123
|
-
children: [
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
alignItems: "center",
|
|
141
|
-
gap: 1.5,
|
|
142
|
-
children: settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map(amount => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
|
|
143
|
-
variant: "outlined",
|
|
144
|
-
sx: {
|
|
145
|
-
minWidth: 115,
|
|
146
|
-
textAlign: "center",
|
|
147
|
-
...(state.selected === amount && !state.custom ? {
|
|
148
|
-
borderColor: "primary.main"
|
|
149
|
-
} : {})
|
|
150
|
-
},
|
|
151
|
-
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
|
|
152
|
-
onClick: () => handleSelect(amount),
|
|
153
|
-
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
154
|
-
direction: "row",
|
|
155
|
-
sx: {
|
|
156
|
-
py: 1,
|
|
157
|
-
px: 0.5
|
|
126
|
+
children: [supportPreset && /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Grid, {
|
|
127
|
+
container: true,
|
|
128
|
+
spacing: 2,
|
|
129
|
+
children: [settings.amount.presets && settings.amount.presets.length > 0 && settings.amount.presets.map(amount => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grid, {
|
|
130
|
+
item: true,
|
|
131
|
+
xs: 6,
|
|
132
|
+
sm: 3,
|
|
133
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
|
|
134
|
+
variant: "outlined",
|
|
135
|
+
sx: {
|
|
136
|
+
minWidth: 115,
|
|
137
|
+
textAlign: "center",
|
|
138
|
+
transition: "all 0.3s",
|
|
139
|
+
cursor: "pointer",
|
|
140
|
+
"&:hover": {
|
|
141
|
+
transform: "translateY(-4px)",
|
|
142
|
+
boxShadow: 3
|
|
158
143
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
144
|
+
height: "42px",
|
|
145
|
+
...(state.selected === amount && !state.custom ? {
|
|
146
|
+
borderColor: "primary.main",
|
|
147
|
+
borderWidth: 1
|
|
148
|
+
} : {})
|
|
149
|
+
},
|
|
150
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
|
|
151
|
+
onClick: () => handleSelect(amount),
|
|
152
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
153
|
+
direction: "row",
|
|
166
154
|
sx: {
|
|
167
|
-
|
|
168
|
-
|
|
155
|
+
py: 1.5,
|
|
156
|
+
px: 1.5
|
|
169
157
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
158
|
+
spacing: 0.5,
|
|
159
|
+
alignItems: "center",
|
|
160
|
+
justifyContent: "center",
|
|
161
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
162
|
+
src: currency?.logo,
|
|
163
|
+
sx: {
|
|
164
|
+
width: 16,
|
|
165
|
+
height: 16,
|
|
166
|
+
mr: 0.5
|
|
167
|
+
},
|
|
168
|
+
alt: currency?.symbol
|
|
169
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
170
|
+
component: "strong",
|
|
171
|
+
lineHeight: 1,
|
|
172
|
+
variant: "h3",
|
|
173
|
+
sx: {
|
|
174
|
+
fontVariantNumeric: "tabular-nums",
|
|
175
|
+
fontWeight: 400
|
|
176
|
+
},
|
|
177
|
+
children: amount
|
|
178
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
179
|
+
lineHeight: 1,
|
|
180
|
+
fontSize: 14,
|
|
181
|
+
color: "text.secondary",
|
|
182
|
+
children: currency?.symbol
|
|
183
|
+
})]
|
|
184
|
+
})
|
|
177
185
|
})
|
|
178
|
-
})
|
|
179
|
-
}, amount))
|
|
186
|
+
}, amount)
|
|
187
|
+
}, amount)), supportCustom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Grid, {
|
|
188
|
+
item: true,
|
|
189
|
+
xs: 6,
|
|
190
|
+
sm: 3,
|
|
191
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
|
|
192
|
+
variant: "outlined",
|
|
193
|
+
sx: {
|
|
194
|
+
textAlign: "center",
|
|
195
|
+
transition: "all 0.3s",
|
|
196
|
+
cursor: "pointer",
|
|
197
|
+
"&:hover": {
|
|
198
|
+
transform: "translateY(-4px)",
|
|
199
|
+
boxShadow: 3
|
|
200
|
+
},
|
|
201
|
+
height: "42px",
|
|
202
|
+
...(state.custom ? {
|
|
203
|
+
borderColor: "primary.main",
|
|
204
|
+
borderWidth: 1
|
|
205
|
+
} : {})
|
|
206
|
+
},
|
|
207
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.CardActionArea, {
|
|
208
|
+
onClick: () => handleCustomSelect(),
|
|
209
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Stack, {
|
|
210
|
+
direction: "row",
|
|
211
|
+
sx: {
|
|
212
|
+
py: 1.5,
|
|
213
|
+
px: 1.5
|
|
214
|
+
},
|
|
215
|
+
spacing: 0.5,
|
|
216
|
+
alignItems: "center",
|
|
217
|
+
justifyContent: "center",
|
|
218
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
219
|
+
variant: "h3",
|
|
220
|
+
lineHeight: 1,
|
|
221
|
+
sx: {
|
|
222
|
+
fontWeight: 400
|
|
223
|
+
},
|
|
224
|
+
children: t("common.custom")
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
}, "custom")
|
|
229
|
+
}, "custom")]
|
|
180
230
|
}), state.custom && /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.TextField, {
|
|
181
|
-
label: preset !== "0" ? null : t("payment.checkout.donation.custom"),
|
|
182
231
|
type: "number",
|
|
183
232
|
value: state.input,
|
|
184
233
|
onChange: handleInput,
|
|
185
|
-
inputProps: {
|
|
186
|
-
min: settings.amount.minimum,
|
|
187
|
-
max: settings.amount.maximum
|
|
188
|
-
},
|
|
189
234
|
margin: "none",
|
|
190
235
|
fullWidth: true,
|
|
191
236
|
error: !!state.error,
|
|
192
237
|
helperText: state.error,
|
|
238
|
+
inputRef: customInputRef,
|
|
239
|
+
InputProps: {
|
|
240
|
+
endAdornment: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
241
|
+
direction: "row",
|
|
242
|
+
spacing: 0.5,
|
|
243
|
+
alignItems: "center",
|
|
244
|
+
sx: {
|
|
245
|
+
ml: 1
|
|
246
|
+
},
|
|
247
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
248
|
+
src: currency?.logo,
|
|
249
|
+
sx: {
|
|
250
|
+
width: 16,
|
|
251
|
+
height: 16
|
|
252
|
+
},
|
|
253
|
+
alt: currency?.symbol
|
|
254
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Typography, {
|
|
255
|
+
children: currency?.symbol
|
|
256
|
+
})]
|
|
257
|
+
}),
|
|
258
|
+
autoComplete: "off"
|
|
259
|
+
},
|
|
193
260
|
sx: {
|
|
194
261
|
mt: preset !== "0" ? 0 : 1
|
|
195
262
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function DonationSkeleton(): import("react").JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = DonationSkeleton;
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _material = require("@mui/material");
|
|
9
|
+
function DonationSkeleton() {
|
|
10
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Fade, {
|
|
11
|
+
in: true,
|
|
12
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
13
|
+
direction: "column",
|
|
14
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
|
|
15
|
+
variant: "text",
|
|
16
|
+
sx: {
|
|
17
|
+
fontSize: "2rem",
|
|
18
|
+
width: "40%"
|
|
19
|
+
}
|
|
20
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
|
|
21
|
+
sx: {
|
|
22
|
+
mt: 2
|
|
23
|
+
},
|
|
24
|
+
variant: "rounded",
|
|
25
|
+
height: 80
|
|
26
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Divider, {
|
|
27
|
+
sx: {
|
|
28
|
+
mt: {
|
|
29
|
+
xs: "16px",
|
|
30
|
+
md: "16px"
|
|
31
|
+
},
|
|
32
|
+
mb: {
|
|
33
|
+
xs: "16px",
|
|
34
|
+
md: "16px"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
38
|
+
direction: "row",
|
|
39
|
+
justifyContent: "space-between",
|
|
40
|
+
spacing: 2,
|
|
41
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
|
|
42
|
+
variant: "text",
|
|
43
|
+
sx: {
|
|
44
|
+
fontSize: "1.5rem",
|
|
45
|
+
width: "40%"
|
|
46
|
+
}
|
|
47
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Box, {
|
|
48
|
+
display: "flex",
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
gap: 2,
|
|
51
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
52
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
|
|
53
|
+
height: 60,
|
|
54
|
+
width: 80
|
|
55
|
+
})
|
|
56
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Box, {
|
|
57
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Skeleton, {
|
|
58
|
+
height: 60,
|
|
59
|
+
width: 120
|
|
60
|
+
})
|
|
61
|
+
})]
|
|
62
|
+
})]
|
|
63
|
+
})]
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
}
|
package/lib/theme/index.js
CHANGED
package/lib/types/index.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export type CheckoutProps = Partial<CheckoutCallbacks> & {
|
|
|
36
36
|
action?: string;
|
|
37
37
|
mode?: LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal', string>;
|
|
38
38
|
theme?: 'default' | 'inherit' | PaymentThemeOptions;
|
|
39
|
+
formType?: 'donation' | 'payment';
|
|
40
|
+
formRender?: Record<string, any>;
|
|
39
41
|
};
|
|
40
42
|
export type CheckoutCallbacks = {
|
|
41
43
|
onPaid: (res: CheckoutContext) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"@babel/core": "^7.25.2",
|
|
93
93
|
"@babel/preset-env": "^7.25.2",
|
|
94
94
|
"@babel/preset-react": "^7.24.7",
|
|
95
|
-
"@blocklet/payment-types": "1.18.
|
|
95
|
+
"@blocklet/payment-types": "1.18.1",
|
|
96
96
|
"@storybook/addon-essentials": "^7.6.20",
|
|
97
97
|
"@storybook/addon-interactions": "^7.6.20",
|
|
98
98
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"vite-plugin-babel": "^1.2.0",
|
|
124
124
|
"vite-plugin-node-polyfills": "^0.21.0"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "22060b542145f7c62282ee0d3ec132ff581e13ec"
|
|
127
127
|
}
|
package/src/checkout/donate.tsx
CHANGED
|
@@ -39,6 +39,8 @@ import type { CheckoutProps, PaymentThemeOptions } from '../types';
|
|
|
39
39
|
import CheckoutForm from './form';
|
|
40
40
|
import { PaymentThemeProvider } from '../theme';
|
|
41
41
|
import { usePaymentContext } from '../contexts/payment';
|
|
42
|
+
import Livemode from '../components/livemode';
|
|
43
|
+
import { useMobile } from '../hooks/mobile';
|
|
42
44
|
|
|
43
45
|
export type DonateHistory = {
|
|
44
46
|
supporters: TCheckoutSessionExpanded[];
|
|
@@ -329,9 +331,11 @@ function CheckoutDonateInner({
|
|
|
329
331
|
}: DonateProps) {
|
|
330
332
|
// eslint-disable-line
|
|
331
333
|
const { state, setState, donation, supporters } = useDonation(settings, livemode, mode);
|
|
332
|
-
|
|
334
|
+
const customers = uniqBy((supporters?.data as DonateHistory)?.supporters || [], 'customer_did');
|
|
335
|
+
const { t } = useLocaleContext();
|
|
333
336
|
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
|
|
334
337
|
const [popoverOpen, setPopoverOpen] = useState<boolean>(false);
|
|
338
|
+
const { isMobile } = useMobile();
|
|
335
339
|
|
|
336
340
|
const handlePaid = (...args: any[]) => {
|
|
337
341
|
if (onPaid) {
|
|
@@ -488,28 +492,58 @@ function CheckoutDonateInner({
|
|
|
488
492
|
}
|
|
489
493
|
return defaultRender;
|
|
490
494
|
};
|
|
495
|
+
|
|
491
496
|
return (
|
|
492
497
|
<>
|
|
493
498
|
{renderInnerView()}
|
|
494
499
|
{donation.data && (
|
|
495
500
|
<Dialog
|
|
496
501
|
open={state.open}
|
|
497
|
-
title={
|
|
502
|
+
title={
|
|
503
|
+
<Box display="flex" alignItems="center" gap={0.5}>
|
|
504
|
+
<Typography variant="h3" sx={{ maxWidth: 320, textOverflow: 'ellipsis', overflow: 'hidden' }}>
|
|
505
|
+
{settings.title}
|
|
506
|
+
</Typography>
|
|
507
|
+
{!donation.data.livemode && <Livemode sx={{ width: 'fit-content' }} />}
|
|
508
|
+
</Box>
|
|
509
|
+
}
|
|
498
510
|
maxWidth="md"
|
|
499
|
-
|
|
511
|
+
toolbar={
|
|
512
|
+
isMobile ? null : (
|
|
513
|
+
<Box display="flex" alignItems="center" gap={1} sx={{ color: 'text.secondary' }}>
|
|
514
|
+
<AvatarGroup total={customers?.length} max={5}>
|
|
515
|
+
{customers.map((x: any) => (
|
|
516
|
+
<Avatar
|
|
517
|
+
key={x.id}
|
|
518
|
+
title={x.customer?.name}
|
|
519
|
+
src={getCustomerAvatar(
|
|
520
|
+
x.customer?.did,
|
|
521
|
+
x?.updated_at ? new Date(x.updated_at).toISOString() : '',
|
|
522
|
+
18
|
|
523
|
+
)}
|
|
524
|
+
variant="circular"
|
|
525
|
+
sx={{ width: 18, height: 18 }}
|
|
526
|
+
/>
|
|
527
|
+
))}
|
|
528
|
+
</AvatarGroup>
|
|
529
|
+
{customers?.length > 0 && t('payment.checkout.donation.gaveTips', { count: customers?.length })}
|
|
530
|
+
</Box>
|
|
531
|
+
)
|
|
532
|
+
}
|
|
533
|
+
showCloseButton={false}
|
|
500
534
|
disableEscapeKeyDown
|
|
501
535
|
sx={{
|
|
502
536
|
'.MuiDialogContent-root': {
|
|
503
|
-
padding:
|
|
504
|
-
xs: 0,
|
|
505
|
-
md: '0 16px 0',
|
|
506
|
-
},
|
|
537
|
+
padding: '16px 24px',
|
|
507
538
|
borderTop: '1px solid var(--stroke-border-base, #EFF1F5)',
|
|
508
|
-
width:
|
|
509
|
-
xs: '100%',
|
|
510
|
-
md: 900,
|
|
511
|
-
},
|
|
539
|
+
width: '100%',
|
|
512
540
|
},
|
|
541
|
+
'.ux-dialog_header': {
|
|
542
|
+
gap: 5,
|
|
543
|
+
},
|
|
544
|
+
}}
|
|
545
|
+
PaperProps={{
|
|
546
|
+
style: { minHeight: 'auto', width: 680 },
|
|
513
547
|
}}
|
|
514
548
|
onClose={(e: any, reason: string) => setState({ open: reason === 'backdropClick' })}>
|
|
515
549
|
<Box sx={{ height: '100%', width: '100%' }}>
|
|
@@ -520,9 +554,18 @@ function CheckoutDonateInner({
|
|
|
520
554
|
action={settings.appearance?.button?.text}
|
|
521
555
|
mode="inline"
|
|
522
556
|
theme={theme}
|
|
557
|
+
formType="donation"
|
|
523
558
|
extraParams={{
|
|
524
559
|
livemode,
|
|
525
560
|
}}
|
|
561
|
+
formRender={{
|
|
562
|
+
cancel: (
|
|
563
|
+
<Button variant="outlined" size="large" onClick={() => setState({ open: false })}>
|
|
564
|
+
{t('common.cancel')}
|
|
565
|
+
</Button>
|
|
566
|
+
),
|
|
567
|
+
onCancel: () => setState({ open: false }),
|
|
568
|
+
}}
|
|
526
569
|
/>
|
|
527
570
|
</Box>
|
|
528
571
|
</Dialog>
|
package/src/checkout/form.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { getPrefix, mergeExtraParams } from '../libs/util';
|
|
|
9
9
|
import Payment from '../payment';
|
|
10
10
|
import type { CheckoutContext, CheckoutProps } from '../types';
|
|
11
11
|
import { PaymentThemeProvider } from '../theme';
|
|
12
|
+
import DonationForm from '../payment/donation-form';
|
|
12
13
|
|
|
13
14
|
const promises: { [key: string]: Promise<any> } = {};
|
|
14
15
|
const startFromPaymentLink = (id: string, params?: Record<string, any>): Promise<CheckoutContext> => {
|
|
@@ -41,6 +42,7 @@ export default function CheckoutForm({
|
|
|
41
42
|
extraParams,
|
|
42
43
|
action,
|
|
43
44
|
theme = 'default',
|
|
45
|
+
formType = 'payment',
|
|
44
46
|
...restProps
|
|
45
47
|
}: CheckoutProps) {
|
|
46
48
|
if (!id.startsWith('plink_') && !id.startsWith('cs_')) {
|
|
@@ -76,9 +78,9 @@ export default function CheckoutForm({
|
|
|
76
78
|
onError?.(err);
|
|
77
79
|
};
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<
|
|
81
|
+
const Checkout =
|
|
82
|
+
formType === 'donation' ? (
|
|
83
|
+
<DonationForm
|
|
82
84
|
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
83
85
|
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
84
86
|
paymentIntent={data?.paymentIntent}
|
|
@@ -92,34 +94,10 @@ export default function CheckoutForm({
|
|
|
92
94
|
goBack={goBack}
|
|
93
95
|
mode={mode as string}
|
|
94
96
|
action={action}
|
|
97
|
+
id={id}
|
|
95
98
|
{...restProps}
|
|
96
99
|
/>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
if (theme && typeof theme === 'object') {
|
|
100
|
-
return (
|
|
101
|
-
<PaymentThemeProvider theme={theme}>
|
|
102
|
-
<Payment
|
|
103
|
-
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
104
|
-
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
105
|
-
paymentIntent={data?.paymentIntent}
|
|
106
|
-
paymentLink={data?.paymentLink}
|
|
107
|
-
customer={data?.customer}
|
|
108
|
-
completed={state.completed}
|
|
109
|
-
error={apiError}
|
|
110
|
-
onPaid={handlePaid}
|
|
111
|
-
onError={handleError}
|
|
112
|
-
onChange={onChange}
|
|
113
|
-
goBack={goBack}
|
|
114
|
-
mode={mode as string}
|
|
115
|
-
action={action}
|
|
116
|
-
{...restProps}
|
|
117
|
-
/>
|
|
118
|
-
</PaymentThemeProvider>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
return (
|
|
122
|
-
<PaymentThemeProvider>
|
|
100
|
+
) : (
|
|
123
101
|
<Payment
|
|
124
102
|
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
125
103
|
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
@@ -136,8 +114,15 @@ export default function CheckoutForm({
|
|
|
136
114
|
action={action}
|
|
137
115
|
{...restProps}
|
|
138
116
|
/>
|
|
139
|
-
|
|
140
|
-
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (theme === 'inherit') {
|
|
120
|
+
return Checkout;
|
|
121
|
+
}
|
|
122
|
+
if (theme && typeof theme === 'object') {
|
|
123
|
+
return <PaymentThemeProvider theme={theme}>{Checkout}</PaymentThemeProvider>;
|
|
124
|
+
}
|
|
125
|
+
return <PaymentThemeProvider>{Checkout}</PaymentThemeProvider>;
|
|
141
126
|
}
|
|
142
127
|
|
|
143
128
|
CheckoutForm.defaultProps = {
|
|
@@ -146,4 +131,5 @@ CheckoutForm.defaultProps = {
|
|
|
146
131
|
mode: 'inline',
|
|
147
132
|
action: '',
|
|
148
133
|
extraParams: {},
|
|
134
|
+
formType: 'payment',
|
|
149
135
|
};
|