@blocklet/payment-react 1.13.210 → 1.13.212
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 +20 -0
- package/es/checkout/donate.js +199 -0
- package/es/checkout/form.d.ts +2 -1
- package/es/checkout/form.js +13 -2
- package/es/components/blockchain/tx.d.ts +2 -0
- package/es/components/blockchain/tx.js +16 -5
- package/es/components/safe-guard.d.ts +3 -0
- package/es/components/safe-guard.js +4 -0
- package/es/index.d.ts +3 -1
- package/es/index.js +5 -1
- package/es/locales/en.js +8 -0
- package/es/locales/zh.js +8 -0
- package/es/payment/error.d.ts +3 -1
- package/es/payment/error.js +4 -3
- package/es/payment/form/currency.js +10 -12
- package/es/payment/form/index.d.ts +1 -1
- package/es/payment/form/index.js +15 -3
- package/es/payment/index.d.ts +3 -3
- package/es/payment/index.js +38 -13
- package/es/payment/product-donation.d.ts +7 -0
- package/es/payment/product-donation.js +99 -0
- package/es/payment/skeleton/overview.js +2 -2
- package/es/payment/skeleton/payment.js +2 -5
- package/es/payment/success.d.ts +2 -1
- package/es/payment/success.js +21 -12
- package/es/payment/summary.d.ts +8 -2
- package/es/payment/summary.js +46 -29
- package/es/types/index.d.ts +2 -0
- package/es/util.d.ts +2 -0
- package/es/util.js +47 -3
- package/lib/checkout/donate.d.ts +20 -0
- package/lib/checkout/donate.js +284 -0
- package/lib/checkout/form.d.ts +2 -1
- package/lib/checkout/form.js +5 -2
- package/lib/components/blockchain/tx.d.ts +2 -0
- package/lib/components/blockchain/tx.js +3 -1
- package/lib/components/safe-guard.d.ts +3 -0
- package/lib/components/safe-guard.js +12 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +16 -0
- package/lib/locales/en.js +8 -0
- package/lib/locales/zh.js +8 -0
- package/lib/payment/error.d.ts +3 -1
- package/lib/payment/error.js +5 -3
- package/lib/payment/form/currency.js +10 -12
- package/lib/payment/form/index.d.ts +1 -1
- package/lib/payment/form/index.js +16 -4
- package/lib/payment/index.d.ts +3 -3
- package/lib/payment/index.js +56 -24
- package/lib/payment/product-donation.d.ts +7 -0
- package/lib/payment/product-donation.js +169 -0
- package/lib/payment/skeleton/overview.js +2 -2
- package/lib/payment/skeleton/payment.js +4 -8
- package/lib/payment/success.d.ts +2 -1
- package/lib/payment/success.js +3 -2
- package/lib/payment/summary.d.ts +8 -2
- package/lib/payment/summary.js +30 -7
- package/lib/types/index.d.ts +2 -0
- package/lib/util.d.ts +2 -0
- package/lib/util.js +44 -4
- package/package.json +6 -6
- package/src/checkout/donate.tsx +256 -0
- package/src/checkout/form.tsx +13 -4
- package/src/components/blockchain/tx.tsx +8 -1
- package/src/components/safe-guard.tsx +5 -0
- package/src/index.ts +4 -0
- package/src/locales/en.tsx +8 -0
- package/src/locales/zh.tsx +8 -0
- package/src/payment/error.tsx +4 -2
- package/src/payment/form/currency.tsx +11 -13
- package/src/payment/form/index.tsx +14 -4
- package/src/payment/index.tsx +40 -14
- package/src/payment/product-donation.tsx +118 -0
- package/src/payment/skeleton/overview.tsx +2 -2
- package/src/payment/skeleton/payment.tsx +1 -4
- package/src/payment/success.tsx +7 -2
- package/src/payment/summary.tsx +47 -28
- package/src/types/index.ts +2 -0
- package/src/util.ts +54 -3
package/es/payment/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import Center from "@arcblock/ux/lib/Center";
|
|
3
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
4
3
|
import Toast from "@arcblock/ux/lib/Toast";
|
|
5
4
|
import { ArrowBackOutlined } from "@mui/icons-material";
|
|
6
5
|
import { Box, Fade, Stack } from "@mui/material";
|
|
7
6
|
import { styled } from "@mui/system";
|
|
7
|
+
import { fromTokenToUnit } from "@ocap/util";
|
|
8
8
|
import { useSetState } from "ahooks";
|
|
9
9
|
import { useEffect, useState } from "react";
|
|
10
10
|
import { FormProvider, useForm, useWatch } from "react-hook-form";
|
|
@@ -35,7 +35,8 @@ export default function Payment({
|
|
|
35
35
|
onPaid,
|
|
36
36
|
onError,
|
|
37
37
|
onChange,
|
|
38
|
-
goBack
|
|
38
|
+
goBack,
|
|
39
|
+
action
|
|
39
40
|
}) {
|
|
40
41
|
const { t } = useLocaleContext();
|
|
41
42
|
const { refresh, livemode, setLivemode } = usePaymentContext();
|
|
@@ -56,28 +57,30 @@ export default function Payment({
|
|
|
56
57
|
}
|
|
57
58
|
}, [checkoutSession, livemode, setLivemode, refresh]);
|
|
58
59
|
if (error) {
|
|
59
|
-
return /* @__PURE__ */ jsx(PaymentError, { title: "Oops", description: formatError(error) });
|
|
60
|
+
return /* @__PURE__ */ jsx(PaymentError, { mode, title: "Oops", description: formatError(error) });
|
|
60
61
|
}
|
|
61
62
|
if (!checkoutSession || !delay) {
|
|
62
63
|
return /* @__PURE__ */ jsx(Root, { mode, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : 8 } }, children: [
|
|
63
64
|
/* @__PURE__ */ jsx(Stack, { className: "cko-overview", children: /* @__PURE__ */ jsx(OverviewSkeleton, {}) }),
|
|
64
65
|
/* @__PURE__ */ jsx(Stack, { className: "cko-payment", children: /* @__PURE__ */ jsx(PaymentSkeleton, {}) }),
|
|
65
|
-
/* @__PURE__ */ jsx(CheckoutFooter, { className: "cko-footer" })
|
|
66
|
+
mode === "standalone" && /* @__PURE__ */ jsx(CheckoutFooter, { className: "cko-footer" })
|
|
66
67
|
] }) });
|
|
67
68
|
}
|
|
68
69
|
if (checkoutSession.expires_at <= Math.round(Date.now() / 1e3)) {
|
|
69
|
-
return /* @__PURE__ */ jsx(
|
|
70
|
+
return /* @__PURE__ */ jsx(
|
|
70
71
|
PaymentError,
|
|
71
72
|
{
|
|
73
|
+
mode,
|
|
72
74
|
title: t("payment.checkout.expired.title"),
|
|
73
75
|
description: t("payment.checkout.expired.description")
|
|
74
76
|
}
|
|
75
|
-
)
|
|
77
|
+
);
|
|
76
78
|
}
|
|
77
79
|
if (checkoutSession.status === "complete") {
|
|
78
80
|
return /* @__PURE__ */ jsx(
|
|
79
81
|
PaymentError,
|
|
80
82
|
{
|
|
83
|
+
mode,
|
|
81
84
|
title: t("payment.checkout.complete.title"),
|
|
82
85
|
description: t("payment.checkout.complete.description")
|
|
83
86
|
}
|
|
@@ -96,7 +99,8 @@ export default function Payment({
|
|
|
96
99
|
onError,
|
|
97
100
|
onChange,
|
|
98
101
|
goBack,
|
|
99
|
-
mode
|
|
102
|
+
mode,
|
|
103
|
+
action
|
|
100
104
|
}
|
|
101
105
|
);
|
|
102
106
|
}
|
|
@@ -114,7 +118,8 @@ export function PaymentInner({
|
|
|
114
118
|
onPaid,
|
|
115
119
|
onError,
|
|
116
120
|
onChange,
|
|
117
|
-
goBack
|
|
121
|
+
goBack,
|
|
122
|
+
action
|
|
118
123
|
}) {
|
|
119
124
|
const { t } = useLocaleContext();
|
|
120
125
|
const { settings, session } = usePaymentContext();
|
|
@@ -186,6 +191,18 @@ export function PaymentInner({
|
|
|
186
191
|
Toast.error(formatError(err));
|
|
187
192
|
}
|
|
188
193
|
};
|
|
194
|
+
const onChangeAmount = async ({ priceId, amount }) => {
|
|
195
|
+
try {
|
|
196
|
+
const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
|
|
197
|
+
priceId,
|
|
198
|
+
amount: fromTokenToUnit(amount, currency.decimal).toString()
|
|
199
|
+
});
|
|
200
|
+
setState({ checkoutSession: data });
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error(err);
|
|
203
|
+
Toast.error(formatError(err));
|
|
204
|
+
}
|
|
205
|
+
};
|
|
189
206
|
const handlePaid = (result) => {
|
|
190
207
|
setState({ checkoutSession: result.checkoutSession });
|
|
191
208
|
onPaid(result);
|
|
@@ -199,7 +216,7 @@ export function PaymentInner({
|
|
|
199
216
|
fontSize: "medium"
|
|
200
217
|
}
|
|
201
218
|
),
|
|
202
|
-
/* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : 8 } }, children: [
|
|
219
|
+
/* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8 } }, children: [
|
|
203
220
|
/* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-overview", direction: "column", children: [
|
|
204
221
|
mode === "standalone" ? /* @__PURE__ */ jsx(PaymentHeader, { checkoutSession: state.checkoutSession }) : null,
|
|
205
222
|
/* @__PURE__ */ jsx(
|
|
@@ -214,20 +231,26 @@ export function PaymentInner({
|
|
|
214
231
|
onDownsell,
|
|
215
232
|
onApplyCrossSell,
|
|
216
233
|
onCancelCrossSell,
|
|
234
|
+
onChangeAmount,
|
|
217
235
|
checkoutSessionId: state.checkoutSession.id,
|
|
218
|
-
crossSellBehavior: state.checkoutSession.cross_sell_behavior
|
|
236
|
+
crossSellBehavior: state.checkoutSession.cross_sell_behavior,
|
|
237
|
+
donationSettings: paymentLink?.donation_settings,
|
|
238
|
+
action
|
|
219
239
|
}
|
|
220
240
|
)
|
|
221
241
|
] }) }),
|
|
222
|
-
/* @__PURE__ */ jsxs(Stack, { className: "cko-payment", direction: "column", spacing: 4, children: [
|
|
242
|
+
/* @__PURE__ */ jsxs(Stack, { className: "cko-payment", direction: "column", spacing: { xs: 2, sm: 4 }, children: [
|
|
223
243
|
completed && /* @__PURE__ */ jsx(
|
|
224
244
|
PaymentSuccess,
|
|
225
245
|
{
|
|
246
|
+
mode,
|
|
226
247
|
payee: getStatementDescriptor(state.checkoutSession.line_items),
|
|
227
248
|
action: state.checkoutSession.mode,
|
|
228
249
|
invoiceId: state.checkoutSession.invoice_id,
|
|
229
250
|
subscriptionId: state.checkoutSession.subscription_id,
|
|
230
|
-
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(
|
|
251
|
+
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(
|
|
252
|
+
`payment.checkout.completed.${paymentLink?.donation_settings ? "donate" : state.checkoutSession.mode}`
|
|
253
|
+
)
|
|
231
254
|
}
|
|
232
255
|
),
|
|
233
256
|
!completed && /* @__PURE__ */ jsx(
|
|
@@ -236,10 +259,12 @@ export function PaymentInner({
|
|
|
236
259
|
checkoutSession: state.checkoutSession,
|
|
237
260
|
paymentMethods,
|
|
238
261
|
paymentIntent,
|
|
262
|
+
paymentLink,
|
|
239
263
|
customer,
|
|
240
264
|
onPaid: handlePaid,
|
|
241
265
|
onError,
|
|
242
|
-
mode
|
|
266
|
+
mode,
|
|
267
|
+
action
|
|
243
268
|
}
|
|
244
269
|
)
|
|
245
270
|
] }),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { DonationSettings, TLineItemExpanded } from '@blocklet/payment-types';
|
|
3
|
+
export default function ProductDonation({ item, settings, onChange, }: {
|
|
4
|
+
item: TLineItemExpanded;
|
|
5
|
+
settings: DonationSettings;
|
|
6
|
+
onChange: Function;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
+
import { Box, Card, CardActionArea, FormControlLabel, Stack, TextField, Typography } from "@mui/material";
|
|
4
|
+
import { useSetState } from "ahooks";
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
import Switch from "../components/switch-button.js";
|
|
7
|
+
export default function ProductDonation({
|
|
8
|
+
item,
|
|
9
|
+
settings,
|
|
10
|
+
onChange
|
|
11
|
+
}) {
|
|
12
|
+
const { t } = useLocaleContext();
|
|
13
|
+
const preset = settings.amount.preset || settings.amount.presets?.[0] || "0";
|
|
14
|
+
const [state, setState] = useSetState({
|
|
15
|
+
selected: preset,
|
|
16
|
+
input: "",
|
|
17
|
+
custom: settings.amount.presets?.length === 0,
|
|
18
|
+
error: ""
|
|
19
|
+
});
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (settings.amount.preset) {
|
|
22
|
+
setState({ selected: settings.amount.preset, custom: false });
|
|
23
|
+
} else if (settings.amount.presets && settings.amount.presets.length > 0) {
|
|
24
|
+
setState({ selected: settings.amount.presets[0], custom: false });
|
|
25
|
+
}
|
|
26
|
+
}, [settings.amount.preset, settings.amount.presets, setState]);
|
|
27
|
+
const handleSelect = (amount) => {
|
|
28
|
+
setState({ selected: amount, custom: false, error: "" });
|
|
29
|
+
onChange({ priceId: item.price_id, amount });
|
|
30
|
+
};
|
|
31
|
+
const handleInput = (event) => {
|
|
32
|
+
const { value } = event.target;
|
|
33
|
+
const min = parseFloat(settings.amount.minimum || "0");
|
|
34
|
+
const max = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
|
|
35
|
+
if (value < min || value > max) {
|
|
36
|
+
setState({ input: value, error: t("payment.checkout.donation.between", { min, max }) });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
setState({ error: "", input: value });
|
|
40
|
+
onChange({ priceId: item.price_id, amount: value });
|
|
41
|
+
};
|
|
42
|
+
const handleToggle = (event) => {
|
|
43
|
+
if (event.target.checked) {
|
|
44
|
+
setState({ custom: true, input: state.selected, error: "" });
|
|
45
|
+
} else {
|
|
46
|
+
setState({ custom: false, input: "", error: "" });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 1.5, children: [
|
|
50
|
+
settings.amount.custom && preset !== "0" && /* @__PURE__ */ jsx(
|
|
51
|
+
FormControlLabel,
|
|
52
|
+
{
|
|
53
|
+
control: /* @__PURE__ */ jsx(Switch, { checked: state.custom, sx: { marginRight: 0.4 }, onChange: handleToggle }),
|
|
54
|
+
label: state.custom ? t("payment.checkout.donation.select") : t("payment.checkout.donation.custom"),
|
|
55
|
+
sx: { marginRight: 2, marginLeft: 0.5, color: "text.secondary" }
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
!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(
|
|
59
|
+
Card,
|
|
60
|
+
{
|
|
61
|
+
variant: "outlined",
|
|
62
|
+
sx: {
|
|
63
|
+
minWidth: 120,
|
|
64
|
+
textAlign: "center",
|
|
65
|
+
...state.selected === amount && !state.custom ? { borderColor: "primary.main" } : {}
|
|
66
|
+
},
|
|
67
|
+
children: /* @__PURE__ */ jsx(CardActionArea, { onClick: () => handleSelect(amount), children: /* @__PURE__ */ jsxs(Stack, { direction: "row", sx: { py: 1 }, spacing: 0.5, alignItems: "flex-end", justifyContent: "center", children: [
|
|
68
|
+
/* @__PURE__ */ jsx(
|
|
69
|
+
Typography,
|
|
70
|
+
{
|
|
71
|
+
component: "strong",
|
|
72
|
+
lineHeight: 1,
|
|
73
|
+
variant: "h5",
|
|
74
|
+
sx: { fontVariantNumeric: "tabular-nums", fontWeight: 400 },
|
|
75
|
+
children: amount
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ jsx(Typography, { component: "small", lineHeight: 1, fontSize: 12, children: "ABT" }),
|
|
79
|
+
" "
|
|
80
|
+
] }) })
|
|
81
|
+
},
|
|
82
|
+
amount
|
|
83
|
+
)) }),
|
|
84
|
+
state.custom && /* @__PURE__ */ jsx(
|
|
85
|
+
TextField,
|
|
86
|
+
{
|
|
87
|
+
label: preset !== "0" ? null : t("payment.checkout.donation.custom"),
|
|
88
|
+
type: "number",
|
|
89
|
+
value: state.input,
|
|
90
|
+
onChange: handleInput,
|
|
91
|
+
inputProps: { min: settings.amount.minimum, max: settings.amount.maximum },
|
|
92
|
+
margin: "none",
|
|
93
|
+
fullWidth: true,
|
|
94
|
+
error: !!state.error,
|
|
95
|
+
helperText: state.error
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
] });
|
|
99
|
+
}
|
|
@@ -6,8 +6,8 @@ export default function OverviewSkeleton() {
|
|
|
6
6
|
/* @__PURE__ */ jsx(Skeleton, { variant: "circular", width: 32, height: 32 }),
|
|
7
7
|
/* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "2rem", width: "40%" } })
|
|
8
8
|
] }),
|
|
9
|
-
/* @__PURE__ */ jsx(Typography, { mt:
|
|
9
|
+
/* @__PURE__ */ jsx(Typography, { mt: 2, component: "div", variant: "h4", children: /* @__PURE__ */ jsx(Skeleton, {}) }),
|
|
10
10
|
/* @__PURE__ */ jsx(Typography, { component: "div", variant: "h2", children: /* @__PURE__ */ jsx(Skeleton, {}) }),
|
|
11
|
-
/* @__PURE__ */ jsx(Skeleton, { sx: { mt:
|
|
11
|
+
/* @__PURE__ */ jsx(Skeleton, { sx: { mt: 2 }, variant: "rounded", width: 200, height: 200 })
|
|
12
12
|
] }) });
|
|
13
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Fade, Skeleton, Stack, Typography } from "@mui/material";
|
|
3
3
|
export default function PaymentSkeleton() {
|
|
4
|
-
return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", spacing:
|
|
4
|
+
return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { direction: "column", spacing: 2, children: [
|
|
5
5
|
/* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { fontSize: "2rem", width: "40%" } }),
|
|
6
6
|
/* @__PURE__ */ jsxs(Box, { children: [
|
|
7
7
|
/* @__PURE__ */ jsx(Typography, { component: "div", variant: "h4", children: /* @__PURE__ */ jsx(Skeleton, {}) }),
|
|
@@ -11,9 +11,6 @@ export default function PaymentSkeleton() {
|
|
|
11
11
|
/* @__PURE__ */ jsx(Typography, { component: "div", variant: "h4", children: /* @__PURE__ */ jsx(Skeleton, {}) }),
|
|
12
12
|
/* @__PURE__ */ jsx(Typography, { component: "div", variant: "h1", children: /* @__PURE__ */ jsx(Skeleton, {}) })
|
|
13
13
|
] }),
|
|
14
|
-
/* @__PURE__ */
|
|
15
|
-
/* @__PURE__ */ jsx(Typography, { component: "div", variant: "h4", children: /* @__PURE__ */ jsx(Skeleton, {}) }),
|
|
16
|
-
/* @__PURE__ */ jsx(Typography, { component: "div", variant: "h1", children: /* @__PURE__ */ jsx(Skeleton, {}) })
|
|
17
|
-
] })
|
|
14
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { component: "div", variant: "h4", children: /* @__PURE__ */ jsx(Skeleton, {}) }) })
|
|
18
15
|
] }) });
|
|
19
16
|
}
|
package/es/payment/success.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
type Props = {
|
|
3
|
+
mode: string;
|
|
3
4
|
message: string;
|
|
4
5
|
action: string;
|
|
5
6
|
payee: string;
|
|
6
7
|
invoiceId?: string;
|
|
7
8
|
subscriptionId?: string;
|
|
8
9
|
};
|
|
9
|
-
declare function PaymentSuccess({ message, action, payee, invoiceId, subscriptionId }: Props): import("react").JSX.Element;
|
|
10
|
+
declare function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId }: Props): import("react").JSX.Element;
|
|
10
11
|
declare namespace PaymentSuccess {
|
|
11
12
|
var defaultProps: {
|
|
12
13
|
invoiceId: string;
|
package/es/payment/success.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Grow, Link, Stack, Typography } from "@mui/material";
|
|
|
4
4
|
import { styled } from "@mui/system";
|
|
5
5
|
import { joinURL } from "ufo";
|
|
6
6
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
7
|
-
export default function PaymentSuccess({ message, action, payee, invoiceId, subscriptionId }) {
|
|
7
|
+
export default function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId }) {
|
|
8
8
|
const { t } = useLocaleContext();
|
|
9
9
|
const { prefix } = usePaymentContext();
|
|
10
10
|
let next = null;
|
|
@@ -13,17 +13,26 @@ export default function PaymentSuccess({ message, action, payee, invoiceId, subs
|
|
|
13
13
|
} else if (invoiceId) {
|
|
14
14
|
next = /* @__PURE__ */ jsx(Typography, { textAlign: "center", sx: { mt: 2 }, children: /* @__PURE__ */ jsx(Link, { href: joinURL(prefix, `/customer/invoice/${invoiceId}`), children: t("payment.checkout.next.invoice", { payee }) }) });
|
|
15
15
|
}
|
|
16
|
-
return /* @__PURE__ */ jsx(Grow, { in: true, children: /* @__PURE__ */ jsxs(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
return /* @__PURE__ */ jsx(Grow, { in: true, children: /* @__PURE__ */ jsxs(
|
|
17
|
+
Stack,
|
|
18
|
+
{
|
|
19
|
+
direction: "column",
|
|
20
|
+
alignItems: "center",
|
|
21
|
+
justifyContent: mode === "standalone" ? "center" : "flex-start",
|
|
22
|
+
sx: { height: mode === "standalone" ? 360 : 300 },
|
|
23
|
+
children: [
|
|
24
|
+
/* @__PURE__ */ jsx(Div, { children: /* @__PURE__ */ jsxs("div", { className: "check-icon", children: [
|
|
25
|
+
/* @__PURE__ */ jsx("span", { className: "icon-line line-tip" }),
|
|
26
|
+
/* @__PURE__ */ jsx("span", { className: "icon-line line-long" }),
|
|
27
|
+
/* @__PURE__ */ jsx("div", { className: "icon-circle" }),
|
|
28
|
+
/* @__PURE__ */ jsx("div", { className: "icon-fix" })
|
|
29
|
+
] }) }),
|
|
30
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h5", color: "text.primary", mb: 3, children: message }),
|
|
31
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body1", color: "text.secondary", textAlign: "center", children: t("payment.checkout.completed.tip", { payee }) }),
|
|
32
|
+
next
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
) });
|
|
27
36
|
}
|
|
28
37
|
PaymentSuccess.defaultProps = {
|
|
29
38
|
invoiceId: "",
|
package/es/payment/summary.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
2
|
+
import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
3
|
type Props = {
|
|
4
4
|
items: TLineItemExpanded[];
|
|
5
5
|
currency: TPaymentCurrency;
|
|
@@ -8,21 +8,27 @@ type Props = {
|
|
|
8
8
|
showStaking?: boolean;
|
|
9
9
|
onUpsell?: Function;
|
|
10
10
|
onDownsell?: Function;
|
|
11
|
+
onChangeAmount?: Function;
|
|
11
12
|
onApplyCrossSell?: Function;
|
|
12
13
|
onCancelCrossSell?: Function;
|
|
13
14
|
checkoutSessionId?: string;
|
|
14
15
|
crossSellBehavior?: string;
|
|
16
|
+
donationSettings?: DonationSettings;
|
|
17
|
+
action?: string;
|
|
15
18
|
};
|
|
16
|
-
declare function PaymentSummary({ items, currency, trialInDays, billingThreshold, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, checkoutSessionId, crossSellBehavior, showStaking, ...rest }: Props): import("react").JSX.Element;
|
|
19
|
+
declare function PaymentSummary({ items, currency, trialInDays, billingThreshold, onUpsell, onDownsell, onApplyCrossSell, onCancelCrossSell, onChangeAmount, checkoutSessionId, crossSellBehavior, showStaking, donationSettings, action, ...rest }: Props): import("react").JSX.Element;
|
|
17
20
|
declare namespace PaymentSummary {
|
|
18
21
|
var defaultProps: {
|
|
19
22
|
onUpsell: any;
|
|
20
23
|
onDownsell: any;
|
|
21
24
|
onApplyCrossSell: any;
|
|
22
25
|
onCancelCrossSell: any;
|
|
26
|
+
onChangeAmount: any;
|
|
23
27
|
checkoutSessionId: string;
|
|
24
28
|
crossSellBehavior: string;
|
|
25
29
|
showStaking: boolean;
|
|
30
|
+
donationSettings: null;
|
|
31
|
+
action: string;
|
|
26
32
|
};
|
|
27
33
|
}
|
|
28
34
|
export default PaymentSummary;
|
package/es/payment/summary.js
CHANGED
|
@@ -11,6 +11,7 @@ import api from "../api.js";
|
|
|
11
11
|
import Status from "../components/status.js";
|
|
12
12
|
import { formatAmount, formatCheckoutHeadlines, getPriceUintAmountByCurrency } from "../util.js";
|
|
13
13
|
import PaymentAmount from "./amount.js";
|
|
14
|
+
import ProductDonation from "./product-donation.js";
|
|
14
15
|
import ProductItem from "./product-item.js";
|
|
15
16
|
const shake = keyframes`
|
|
16
17
|
0% {
|
|
@@ -69,9 +70,12 @@ PaymentSummary.defaultProps = {
|
|
|
69
70
|
onDownsell: noop,
|
|
70
71
|
onApplyCrossSell: noop,
|
|
71
72
|
onCancelCrossSell: noop,
|
|
73
|
+
onChangeAmount: noop,
|
|
72
74
|
checkoutSessionId: "",
|
|
73
75
|
crossSellBehavior: "",
|
|
74
|
-
showStaking: false
|
|
76
|
+
showStaking: false,
|
|
77
|
+
donationSettings: null,
|
|
78
|
+
action: ""
|
|
75
79
|
};
|
|
76
80
|
export default function PaymentSummary({
|
|
77
81
|
items,
|
|
@@ -82,9 +86,12 @@ export default function PaymentSummary({
|
|
|
82
86
|
onDownsell,
|
|
83
87
|
onApplyCrossSell,
|
|
84
88
|
onCancelCrossSell,
|
|
89
|
+
onChangeAmount,
|
|
85
90
|
checkoutSessionId,
|
|
86
91
|
crossSellBehavior,
|
|
87
92
|
showStaking,
|
|
93
|
+
donationSettings,
|
|
94
|
+
action,
|
|
88
95
|
...rest
|
|
89
96
|
}) {
|
|
90
97
|
const { t, locale } = useLocaleContext();
|
|
@@ -135,35 +142,45 @@ export default function PaymentSummary({
|
|
|
135
142
|
}
|
|
136
143
|
};
|
|
137
144
|
return /* @__PURE__ */ jsx(Fade, { in: true, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-product", direction: "column", ...rest, children: [
|
|
138
|
-
/* @__PURE__ */ jsxs(Stack, { className: "cko-product-summary", direction: "column", alignItems: "flex-start", sx: { mb:
|
|
139
|
-
/* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 500, fontSize: "1.15rem", color: "text.secondary" }, children: headlines.action }),
|
|
145
|
+
/* @__PURE__ */ jsxs(Stack, { className: "cko-product-summary", direction: "column", alignItems: "flex-start", sx: { mb: { xs: 0, sm: 3 } }, children: [
|
|
146
|
+
/* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 500, fontSize: "1.15rem", color: "text.secondary" }, children: action || headlines.action }),
|
|
140
147
|
/* @__PURE__ */ jsx(PaymentAmount, { amount: headlines.amount }),
|
|
141
148
|
headlines.then && /* @__PURE__ */ jsx(Typography, { sx: { fontSize: "0.9rem", color: "text.secondary" }, children: headlines.then })
|
|
142
149
|
] }),
|
|
143
|
-
/* @__PURE__ */ jsx(Stack, { spacing: 2, children: items.map(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
150
|
+
/* @__PURE__ */ jsx(Stack, { spacing: { xs: 1, sm: 2 }, children: items.map(
|
|
151
|
+
(x) => x.price.custom_unit_amount && onChangeAmount && donationSettings ? /* @__PURE__ */ jsx(
|
|
152
|
+
ProductDonation,
|
|
153
|
+
{
|
|
154
|
+
item: x,
|
|
155
|
+
settings: donationSettings,
|
|
156
|
+
onChange: onChangeAmount
|
|
157
|
+
},
|
|
158
|
+
`${x.price_id}-${currency.id}`
|
|
159
|
+
) : /* @__PURE__ */ jsx(
|
|
160
|
+
ProductItem,
|
|
161
|
+
{
|
|
162
|
+
item: x,
|
|
163
|
+
items,
|
|
164
|
+
trialInDays,
|
|
165
|
+
currency,
|
|
166
|
+
onUpsell: handleUpsell,
|
|
167
|
+
onDownsell: handleDownsell,
|
|
168
|
+
children: x.cross_sell && /* @__PURE__ */ jsx(
|
|
169
|
+
LoadingButton,
|
|
170
|
+
{
|
|
171
|
+
size: "small",
|
|
172
|
+
loadingPosition: "end",
|
|
173
|
+
color: "error",
|
|
174
|
+
variant: "text",
|
|
175
|
+
loading: state.loading,
|
|
176
|
+
onClick: handleCancelCrossSell,
|
|
177
|
+
children: t("payment.checkout.cross_sell.remove")
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
},
|
|
181
|
+
`${x.price_id}-${currency.id}`
|
|
182
|
+
)
|
|
183
|
+
) }),
|
|
167
184
|
data && items.some((x) => x.price_id === data.id) === false && /* @__PURE__ */ jsx(Grow, { in: true, children: /* @__PURE__ */ jsxs(
|
|
168
185
|
Stack,
|
|
169
186
|
{
|
|
@@ -175,7 +192,7 @@ export default function PaymentSummary({
|
|
|
175
192
|
borderRadius: 1,
|
|
176
193
|
padding: 1,
|
|
177
194
|
animation: state.shake ? `${shake} 0.2s 5 ease-in-out` : "none",
|
|
178
|
-
mt:
|
|
195
|
+
mt: { xs: 1, sm: 2 }
|
|
179
196
|
},
|
|
180
197
|
children: [
|
|
181
198
|
/* @__PURE__ */ jsx(
|
|
@@ -218,7 +235,7 @@ export default function PaymentSummary({
|
|
|
218
235
|
border: "1px solid #eee",
|
|
219
236
|
borderRadius: 1,
|
|
220
237
|
padding: 1,
|
|
221
|
-
mt:
|
|
238
|
+
mt: { xs: 1, sm: 2 }
|
|
222
239
|
},
|
|
223
240
|
children: [
|
|
224
241
|
/* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [
|
package/es/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type CheckoutContext = {
|
|
|
7
7
|
paymentIntent?: TPaymentIntent;
|
|
8
8
|
customer?: TCustomer;
|
|
9
9
|
mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
|
|
10
|
+
action?: string;
|
|
10
11
|
};
|
|
11
12
|
export type CheckoutFormData = {
|
|
12
13
|
customer_name: string;
|
|
@@ -26,6 +27,7 @@ export type CheckoutFormData = {
|
|
|
26
27
|
export type CheckoutProps = Partial<CheckoutCallbacks> & {
|
|
27
28
|
id: string;
|
|
28
29
|
extraParams?: Record<string, any>;
|
|
30
|
+
action?: string;
|
|
29
31
|
mode?: LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal', string>;
|
|
30
32
|
};
|
|
31
33
|
export type CheckoutCallbacks = {
|
package/es/util.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { PaymentDetails, PriceCurrency, PriceRecurring, TLineItemExpanded, TPaymentCurrency, TPaymentMethod, TPaymentMethodExpanded, TPrice, TSubscriptionExpanded, TSubscriptionItemExpanded } from '@blocklet/payment-types';
|
|
3
3
|
export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
4
|
+
export declare const isPaymentKitMounted: () => any;
|
|
4
5
|
export declare const getPrefix: () => any;
|
|
5
6
|
export declare function formatToDate(date: Date | string | number, locale?: string): any;
|
|
6
7
|
export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
|
|
@@ -25,6 +26,7 @@ export declare function formatLineItemPricing(item: TLineItemExpanded, currency:
|
|
|
25
26
|
export declare function getSubscriptionStatusColor(status: string): "success" | "primary" | "warning" | "error" | "default";
|
|
26
27
|
export declare function getPaymentIntentStatusColor(status: string): "success" | "warning" | "default";
|
|
27
28
|
export declare function getRefundStatusColor(status: string): "success" | "warning" | "default";
|
|
29
|
+
export declare function getPayoutStatusColor(status: string): "success" | "warning" | "default";
|
|
28
30
|
export declare function getInvoiceStatusColor(status: string): "success" | "warning" | "default" | "secondary";
|
|
29
31
|
export declare function getWebhookStatusColor(status: string): "success" | "default";
|
|
30
32
|
export declare function getCheckoutAmount(items: TLineItemExpanded[], currency: TPaymentCurrency, trialing?: boolean, upsell?: boolean): {
|
package/es/util.js
CHANGED
|
@@ -6,6 +6,9 @@ import { joinURL } from "ufo";
|
|
|
6
6
|
import dayjs from "./dayjs.js";
|
|
7
7
|
import { t } from "./locales/index.js";
|
|
8
8
|
export const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
9
|
+
export const isPaymentKitMounted = () => {
|
|
10
|
+
return (window.blocklet?.componentMountPoints || []).some((x) => x.did === PAYMENT_KIT_DID);
|
|
11
|
+
};
|
|
9
12
|
export const getPrefix = () => {
|
|
10
13
|
const componentId = (window?.blocklet?.componentId || "").split("/").pop();
|
|
11
14
|
if (componentId === PAYMENT_KIT_DID) {
|
|
@@ -78,6 +81,9 @@ export function formatNumber(n, precision = 6, trim = true) {
|
|
|
78
81
|
return trim ? trimEnd(num.format(options), "0.") : num.format(options);
|
|
79
82
|
}
|
|
80
83
|
export const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
|
|
84
|
+
if (price.custom_unit_amount) {
|
|
85
|
+
return `Custom (${currency.symbol})`;
|
|
86
|
+
}
|
|
81
87
|
const unit = getPriceUintAmountByCurrency(price, currency);
|
|
82
88
|
const amount = bn ? fromUnitToToken(new BN(unit).mul(new BN(quantity)), currency.decimal).toString() : +unit * quantity;
|
|
83
89
|
if (price?.type === "recurring" && price.recurring) {
|
|
@@ -143,9 +149,15 @@ export function getPriceUintAmountByCurrency(price, currency) {
|
|
|
143
149
|
const options = getPriceCurrencyOptions(price);
|
|
144
150
|
const option = options.find((x) => x.currency_id === currency.id);
|
|
145
151
|
if (option) {
|
|
152
|
+
if (option.custom_unit_amount) {
|
|
153
|
+
return option.custom_unit_amount.preset || option.custom_unit_amount.presets[0];
|
|
154
|
+
}
|
|
146
155
|
return option.unit_amount;
|
|
147
156
|
}
|
|
148
157
|
if (price.currency_id === currency.id) {
|
|
158
|
+
if (price.custom_unit_amount) {
|
|
159
|
+
return price.custom_unit_amount.preset || price.custom_unit_amount.presets[0];
|
|
160
|
+
}
|
|
149
161
|
return price.unit_amount;
|
|
150
162
|
}
|
|
151
163
|
console.warn(`Currency ${currency.id} not configured for price`, price);
|
|
@@ -155,7 +167,14 @@ export function getPriceCurrencyOptions(price) {
|
|
|
155
167
|
if (Array.isArray(price.currency_options)) {
|
|
156
168
|
return price.currency_options;
|
|
157
169
|
}
|
|
158
|
-
return [
|
|
170
|
+
return [
|
|
171
|
+
{
|
|
172
|
+
currency_id: price.currency_id,
|
|
173
|
+
unit_amount: price.unit_amount,
|
|
174
|
+
custom_unit_amount: price.custom_unit_amount || null,
|
|
175
|
+
tiers: null
|
|
176
|
+
}
|
|
177
|
+
];
|
|
159
178
|
}
|
|
160
179
|
export function formatLineItemPricing(item, currency, trial, locale = "en") {
|
|
161
180
|
const price = item.upsell_price || item.price;
|
|
@@ -242,6 +261,19 @@ export function getRefundStatusColor(status) {
|
|
|
242
261
|
return "default";
|
|
243
262
|
}
|
|
244
263
|
}
|
|
264
|
+
export function getPayoutStatusColor(status) {
|
|
265
|
+
switch (status) {
|
|
266
|
+
case "paid":
|
|
267
|
+
return "success";
|
|
268
|
+
case "failed":
|
|
269
|
+
return "warning";
|
|
270
|
+
case "canceled":
|
|
271
|
+
case "pending":
|
|
272
|
+
case "in_transit":
|
|
273
|
+
default:
|
|
274
|
+
return "default";
|
|
275
|
+
}
|
|
276
|
+
}
|
|
245
277
|
export function getInvoiceStatusColor(status) {
|
|
246
278
|
switch (status) {
|
|
247
279
|
case "paid":
|
|
@@ -266,14 +298,26 @@ export function getWebhookStatusColor(status) {
|
|
|
266
298
|
}
|
|
267
299
|
}
|
|
268
300
|
export function getCheckoutAmount(items, currency, trialing = false, upsell = true) {
|
|
301
|
+
if (items.find((x) => (x.upsell_price || x.price).custom_unit_amount) && items.length > 1) {
|
|
302
|
+
throw new Error("Multiple items with custom unit amount are not supported");
|
|
303
|
+
}
|
|
269
304
|
let renew = new BN(0);
|
|
270
305
|
const total = items.filter((x) => {
|
|
271
306
|
const price = upsell ? x.upsell_price || x.price : x.price;
|
|
272
307
|
return price != null;
|
|
273
308
|
}).reduce((acc, x) => {
|
|
309
|
+
if (x.custom_amount) {
|
|
310
|
+
return acc.add(new BN(x.custom_amount));
|
|
311
|
+
}
|
|
274
312
|
const price = upsell ? x.upsell_price || x.price : x.price;
|
|
313
|
+
const unitPrice = getPriceUintAmountByCurrency(price, currency);
|
|
314
|
+
if (price.custom_unit_amount) {
|
|
315
|
+
if (unitPrice) {
|
|
316
|
+
return acc.add(new BN(unitPrice).mul(new BN(x.quantity)));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
275
319
|
if (price?.type === "recurring") {
|
|
276
|
-
renew = renew.add(new BN(
|
|
320
|
+
renew = renew.add(new BN(unitPrice).mul(new BN(x.quantity)));
|
|
277
321
|
if (trialing) {
|
|
278
322
|
return acc;
|
|
279
323
|
}
|
|
@@ -281,7 +325,7 @@ export function getCheckoutAmount(items, currency, trialing = false, upsell = tr
|
|
|
281
325
|
return acc;
|
|
282
326
|
}
|
|
283
327
|
}
|
|
284
|
-
return acc.add(new BN(
|
|
328
|
+
return acc.add(new BN(unitPrice).mul(new BN(x.quantity)));
|
|
285
329
|
}, new BN(0)).toString();
|
|
286
330
|
return { subtotal: total, total, renew: renew.toString(), discount: "0", shipping: "0", tax: "0" };
|
|
287
331
|
}
|