@blocklet/payment-react 1.17.12 → 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
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
+
import Toast from "@arcblock/ux/lib/Toast";
|
|
4
|
+
import Header from "@blocklet/ui-react/lib/Header";
|
|
5
|
+
import { ArrowBackOutlined, ArrowForwardOutlined, HelpOutlineOutlined } from "@mui/icons-material";
|
|
6
|
+
import { Box, Button, Divider, Stack, Typography } from "@mui/material";
|
|
7
|
+
import { styled } from "@mui/system";
|
|
8
|
+
import { fromTokenToUnit } from "@ocap/util";
|
|
9
|
+
import { useMount, useRequest, useSetState } from "ahooks";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { FormProvider, useForm, useWatch } from "react-hook-form";
|
|
12
|
+
import { joinURL } from "ufo";
|
|
13
|
+
import { usePaymentContext } from "../contexts/payment.js";
|
|
14
|
+
import api from "../libs/api.js";
|
|
15
|
+
import {
|
|
16
|
+
findCurrency,
|
|
17
|
+
formatError,
|
|
18
|
+
getPrefix,
|
|
19
|
+
getQueryParams,
|
|
20
|
+
getStatementDescriptor,
|
|
21
|
+
isMobileSafari,
|
|
22
|
+
isValidCountry
|
|
23
|
+
} from "../libs/util.js";
|
|
24
|
+
import PaymentError from "./error.js";
|
|
25
|
+
import PaymentForm from "./form/index.js";
|
|
26
|
+
import PaymentSuccess from "./success.js";
|
|
27
|
+
import { useMobile } from "../hooks/mobile.js";
|
|
28
|
+
import ProductDonation from "./product-donation.js";
|
|
29
|
+
import ConfirmDialog from "../components/confirm.js";
|
|
30
|
+
import PaymentBeneficiaries from "../components/payment-beneficiaries.js";
|
|
31
|
+
import DonationSkeleton from "./skeleton/donation.js";
|
|
32
|
+
const getBenefits = async (id, url) => {
|
|
33
|
+
const { data } = await api.get(`/api/payment-links/${id}/benefits?${url ? `url=${url}` : ""}`);
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
PaymentInner.defaultProps = {
|
|
37
|
+
completed: false,
|
|
38
|
+
showCheckoutSummary: true,
|
|
39
|
+
formRender: {}
|
|
40
|
+
};
|
|
41
|
+
function PaymentInner({
|
|
42
|
+
checkoutSession,
|
|
43
|
+
paymentMethods,
|
|
44
|
+
paymentLink,
|
|
45
|
+
paymentIntent,
|
|
46
|
+
customer,
|
|
47
|
+
completed,
|
|
48
|
+
mode,
|
|
49
|
+
onPaid,
|
|
50
|
+
onError,
|
|
51
|
+
onChange,
|
|
52
|
+
action,
|
|
53
|
+
formRender,
|
|
54
|
+
benefits
|
|
55
|
+
}) {
|
|
56
|
+
const { t } = useLocaleContext();
|
|
57
|
+
const { settings, session } = usePaymentContext();
|
|
58
|
+
const [state, setState] = useSetState({
|
|
59
|
+
checkoutSession,
|
|
60
|
+
submitting: false,
|
|
61
|
+
paying: false,
|
|
62
|
+
paid: false,
|
|
63
|
+
paymentIntent,
|
|
64
|
+
stripeContext: void 0,
|
|
65
|
+
customer,
|
|
66
|
+
customerLimited: false,
|
|
67
|
+
stripePaying: false
|
|
68
|
+
});
|
|
69
|
+
const query = getQueryParams(window.location.href);
|
|
70
|
+
const defaultCurrencyId = query.currencyId || state.checkoutSession.currency_id || state.checkoutSession.line_items[0]?.price.currency_id;
|
|
71
|
+
const defaultMethodId = paymentMethods.find((m) => m.payment_currencies.some((c) => c.id === defaultCurrencyId))?.id;
|
|
72
|
+
const items = state.checkoutSession.line_items;
|
|
73
|
+
const donationSettings = paymentLink?.donation_settings;
|
|
74
|
+
const [benefitsState, setBenefitsState] = useSetState({
|
|
75
|
+
open: false,
|
|
76
|
+
amount: "0"
|
|
77
|
+
});
|
|
78
|
+
const methods = useForm({
|
|
79
|
+
defaultValues: {
|
|
80
|
+
customer_name: customer?.name || session?.user?.fullName || "",
|
|
81
|
+
customer_email: customer?.email || session?.user?.email || "",
|
|
82
|
+
customer_phone: customer?.phone || session?.user?.phone || "",
|
|
83
|
+
payment_method: defaultMethodId,
|
|
84
|
+
payment_currency: defaultCurrencyId,
|
|
85
|
+
billing_address: Object.assign(
|
|
86
|
+
{
|
|
87
|
+
country: "",
|
|
88
|
+
state: "",
|
|
89
|
+
city: "",
|
|
90
|
+
line1: "",
|
|
91
|
+
line2: "",
|
|
92
|
+
postal_code: ""
|
|
93
|
+
},
|
|
94
|
+
customer?.address || {},
|
|
95
|
+
{ country: isValidCountry(customer?.address?.country || "") ? customer?.address?.country : "us" }
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (!isMobileSafari()) {
|
|
101
|
+
return () => {
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
let scrollTop = 0;
|
|
105
|
+
const focusinHandler = () => {
|
|
106
|
+
scrollTop = window.scrollY;
|
|
107
|
+
};
|
|
108
|
+
const focusoutHandler = () => {
|
|
109
|
+
window.scrollTo(0, scrollTop);
|
|
110
|
+
};
|
|
111
|
+
document.body.addEventListener("focusin", focusinHandler);
|
|
112
|
+
document.body.addEventListener("focusout", focusoutHandler);
|
|
113
|
+
return () => {
|
|
114
|
+
document.body.removeEventListener("focusin", focusinHandler);
|
|
115
|
+
document.body.removeEventListener("focusout", focusoutHandler);
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!methods || query.currencyId) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (state.checkoutSession.currency_id !== defaultCurrencyId) {
|
|
123
|
+
methods.setValue("payment_currency", state.checkoutSession.currency_id);
|
|
124
|
+
}
|
|
125
|
+
}, [state.checkoutSession, defaultCurrencyId, query.currencyId]);
|
|
126
|
+
const currencyId = useWatch({ control: methods.control, name: "payment_currency", defaultValue: defaultCurrencyId });
|
|
127
|
+
const currency = findCurrency(paymentMethods, currencyId) || settings.baseCurrency;
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (onChange) {
|
|
130
|
+
onChange(methods.getValues());
|
|
131
|
+
}
|
|
132
|
+
}, [currencyId]);
|
|
133
|
+
const onChangeAmount = async ({ priceId, amount }) => {
|
|
134
|
+
const amountStr = fromTokenToUnit(amount, currency.decimal).toString();
|
|
135
|
+
setBenefitsState({ amount: amountStr });
|
|
136
|
+
try {
|
|
137
|
+
const { data } = await api.put(`/api/checkout-sessions/${state.checkoutSession.id}/amount`, {
|
|
138
|
+
priceId,
|
|
139
|
+
amount: amountStr
|
|
140
|
+
});
|
|
141
|
+
setState({ checkoutSession: data });
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.error(err);
|
|
144
|
+
Toast.error(formatError(err));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const handlePaid = (result) => {
|
|
148
|
+
setState({ checkoutSession: result.checkoutSession });
|
|
149
|
+
onPaid(result);
|
|
150
|
+
};
|
|
151
|
+
const renderBenefits = () => {
|
|
152
|
+
if (!benefits) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
if (benefits.length === 1) {
|
|
156
|
+
return t("payment.checkout.donation.benefits.one", {
|
|
157
|
+
name: benefits[0].name
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return t("payment.checkout.donation.benefits.multiple", {
|
|
161
|
+
count: benefits.length
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8 } }, children: [
|
|
165
|
+
completed ? /* @__PURE__ */ jsxs(Stack, { children: [
|
|
166
|
+
/* @__PURE__ */ jsx(
|
|
167
|
+
PaymentSuccess,
|
|
168
|
+
{
|
|
169
|
+
mode,
|
|
170
|
+
payee: getStatementDescriptor(state.checkoutSession.line_items),
|
|
171
|
+
action: state.checkoutSession.mode,
|
|
172
|
+
invoiceId: state.checkoutSession.invoice_id,
|
|
173
|
+
subscriptionId: state.checkoutSession.subscription_id,
|
|
174
|
+
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t("payment.checkout.completed.donate")
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ jsx(
|
|
178
|
+
Divider,
|
|
179
|
+
{
|
|
180
|
+
sx: {
|
|
181
|
+
mt: {
|
|
182
|
+
xs: "16px",
|
|
183
|
+
md: "-24px"
|
|
184
|
+
},
|
|
185
|
+
mb: {
|
|
186
|
+
xs: "16px",
|
|
187
|
+
md: "16px"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-end", alignItems: "center", flexWrap: "wrap", gap: 1, children: /* @__PURE__ */ jsx(
|
|
193
|
+
Button,
|
|
194
|
+
{
|
|
195
|
+
variant: "outlined",
|
|
196
|
+
size: "large",
|
|
197
|
+
onClick: formRender?.onCancel,
|
|
198
|
+
sx: { width: "fit-content", minWidth: 120 },
|
|
199
|
+
children: t("common.close")
|
|
200
|
+
}
|
|
201
|
+
) })
|
|
202
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
203
|
+
benefitsState.open && /* @__PURE__ */ jsx(PaymentBeneficiaries, { data: benefits, currency, totalAmount: benefitsState.amount }),
|
|
204
|
+
/* @__PURE__ */ jsxs(Stack, { sx: { display: benefitsState.open ? "none" : "block" }, children: [
|
|
205
|
+
/* @__PURE__ */ jsx(
|
|
206
|
+
Typography,
|
|
207
|
+
{
|
|
208
|
+
title: t("payment.checkout.orderSummary"),
|
|
209
|
+
sx: {
|
|
210
|
+
color: "text.primary",
|
|
211
|
+
fontSize: "18px",
|
|
212
|
+
fontWeight: "500",
|
|
213
|
+
lineHeight: "24px",
|
|
214
|
+
mb: 2
|
|
215
|
+
},
|
|
216
|
+
children: t("payment.checkout.donation.tipAmount")
|
|
217
|
+
}
|
|
218
|
+
),
|
|
219
|
+
items.map((x) => /* @__PURE__ */ jsx(
|
|
220
|
+
ProductDonation,
|
|
221
|
+
{
|
|
222
|
+
item: x,
|
|
223
|
+
settings: donationSettings,
|
|
224
|
+
onChange: onChangeAmount,
|
|
225
|
+
currency
|
|
226
|
+
},
|
|
227
|
+
`${x.price_id}-${currency.id}`
|
|
228
|
+
))
|
|
229
|
+
] }),
|
|
230
|
+
/* @__PURE__ */ jsx(
|
|
231
|
+
Divider,
|
|
232
|
+
{
|
|
233
|
+
sx: {
|
|
234
|
+
mt: {
|
|
235
|
+
xs: "32px",
|
|
236
|
+
md: "0"
|
|
237
|
+
},
|
|
238
|
+
mb: {
|
|
239
|
+
xs: "16px",
|
|
240
|
+
md: "-8px"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
),
|
|
245
|
+
/* @__PURE__ */ jsxs(Stack, { direction: "row", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 1, children: [
|
|
246
|
+
benefits && benefits.length > 0 && (benefitsState.open ? /* @__PURE__ */ jsxs(
|
|
247
|
+
Typography,
|
|
248
|
+
{
|
|
249
|
+
onClick: () => setBenefitsState({ open: false }),
|
|
250
|
+
sx: {
|
|
251
|
+
cursor: "pointer",
|
|
252
|
+
color: "text.secondary",
|
|
253
|
+
"&:hover": {
|
|
254
|
+
color: "text.primary"
|
|
255
|
+
},
|
|
256
|
+
display: "flex",
|
|
257
|
+
alignItems: "center"
|
|
258
|
+
},
|
|
259
|
+
children: [
|
|
260
|
+
/* @__PURE__ */ jsx(ArrowBackOutlined, { className: "benefits-arrow", sx: { fontSize: "18px", mr: 0.5 } }),
|
|
261
|
+
t("common.back")
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
) : /* @__PURE__ */ jsxs(
|
|
265
|
+
Box,
|
|
266
|
+
{
|
|
267
|
+
display: "flex",
|
|
268
|
+
gap: 0.5,
|
|
269
|
+
alignItems: "center",
|
|
270
|
+
onClick: () => setBenefitsState({ open: true }),
|
|
271
|
+
sx: {
|
|
272
|
+
color: "text.secondary",
|
|
273
|
+
cursor: "pointer",
|
|
274
|
+
"& .benefits-arrow": {
|
|
275
|
+
opacity: 0,
|
|
276
|
+
transform: "translateX(-4px)",
|
|
277
|
+
transition: "all 0.2s"
|
|
278
|
+
},
|
|
279
|
+
"&:hover": {
|
|
280
|
+
color: "text.primary",
|
|
281
|
+
"& .benefits-arrow": {
|
|
282
|
+
opacity: 1,
|
|
283
|
+
transform: "translateX(0)"
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
children: [
|
|
288
|
+
/* @__PURE__ */ jsx(HelpOutlineOutlined, { sx: { fontSize: "18px" } }),
|
|
289
|
+
/* @__PURE__ */ jsx(Typography, { children: renderBenefits() }),
|
|
290
|
+
/* @__PURE__ */ jsx(ArrowForwardOutlined, { className: "benefits-arrow", sx: { fontSize: "18px" } })
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
)),
|
|
294
|
+
benefitsState.open ? null : /* @__PURE__ */ jsxs(
|
|
295
|
+
Box,
|
|
296
|
+
{
|
|
297
|
+
display: "flex",
|
|
298
|
+
gap: 2,
|
|
299
|
+
sx: {
|
|
300
|
+
flex: {
|
|
301
|
+
xs: 1,
|
|
302
|
+
md: "auto"
|
|
303
|
+
},
|
|
304
|
+
justifyContent: "flex-end"
|
|
305
|
+
},
|
|
306
|
+
children: [
|
|
307
|
+
formRender?.cancel,
|
|
308
|
+
/* @__PURE__ */ jsx(
|
|
309
|
+
PaymentForm,
|
|
310
|
+
{
|
|
311
|
+
currencyId,
|
|
312
|
+
checkoutSession: state.checkoutSession,
|
|
313
|
+
paymentMethods,
|
|
314
|
+
paymentIntent,
|
|
315
|
+
paymentLink,
|
|
316
|
+
customer,
|
|
317
|
+
onPaid: handlePaid,
|
|
318
|
+
onError,
|
|
319
|
+
mode,
|
|
320
|
+
action,
|
|
321
|
+
onlyShowBtn: true
|
|
322
|
+
}
|
|
323
|
+
)
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
] })
|
|
328
|
+
] }),
|
|
329
|
+
state.customerLimited && /* @__PURE__ */ jsx(
|
|
330
|
+
ConfirmDialog,
|
|
331
|
+
{
|
|
332
|
+
onConfirm: () => window.open(
|
|
333
|
+
joinURL(getPrefix(), `/customer/invoice/past-due?referer=${encodeURIComponent(window.location.href)}`),
|
|
334
|
+
"_self"
|
|
335
|
+
),
|
|
336
|
+
onCancel: () => setState({ customerLimited: false }),
|
|
337
|
+
confirm: t("payment.customer.pastDue.alert.confirm"),
|
|
338
|
+
title: t("payment.customer.pastDue.alert.title"),
|
|
339
|
+
message: t("payment.customer.pastDue.alert.description"),
|
|
340
|
+
color: "primary"
|
|
341
|
+
}
|
|
342
|
+
)
|
|
343
|
+
] }) });
|
|
344
|
+
}
|
|
345
|
+
DonationForm.defaultProps = {
|
|
346
|
+
completed: false,
|
|
347
|
+
error: null,
|
|
348
|
+
showCheckoutSummary: true,
|
|
349
|
+
formRender: {}
|
|
350
|
+
};
|
|
351
|
+
export default function DonationForm({
|
|
352
|
+
checkoutSession,
|
|
353
|
+
paymentMethods,
|
|
354
|
+
paymentIntent,
|
|
355
|
+
paymentLink,
|
|
356
|
+
customer,
|
|
357
|
+
completed,
|
|
358
|
+
error,
|
|
359
|
+
mode,
|
|
360
|
+
onPaid,
|
|
361
|
+
onError,
|
|
362
|
+
onChange,
|
|
363
|
+
goBack,
|
|
364
|
+
action,
|
|
365
|
+
showCheckoutSummary = true,
|
|
366
|
+
formRender,
|
|
367
|
+
id
|
|
368
|
+
}) {
|
|
369
|
+
const { t } = useLocaleContext();
|
|
370
|
+
const { refresh, livemode, setLivemode } = usePaymentContext();
|
|
371
|
+
const { isMobile } = useMobile();
|
|
372
|
+
const [delay, setDelay] = useState(false);
|
|
373
|
+
const isMobileSafariEnv = isMobileSafari();
|
|
374
|
+
const paymentLinkId = id.startsWith("plink_") ? id : void 0;
|
|
375
|
+
const { data: benefits, loading: benefitLoading } = useRequest(
|
|
376
|
+
() => {
|
|
377
|
+
if (paymentLinkId) {
|
|
378
|
+
return getBenefits(paymentLinkId);
|
|
379
|
+
}
|
|
380
|
+
return Promise.resolve([]);
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
refreshDeps: [paymentLinkId || paymentLink?.id],
|
|
384
|
+
ready: !!paymentLinkId || !!paymentLink?.id
|
|
385
|
+
}
|
|
386
|
+
);
|
|
387
|
+
useMount(() => {
|
|
388
|
+
setTimeout(() => {
|
|
389
|
+
setDelay(true);
|
|
390
|
+
}, 500);
|
|
391
|
+
});
|
|
392
|
+
useEffect(() => {
|
|
393
|
+
if (checkoutSession) {
|
|
394
|
+
if (livemode !== checkoutSession.livemode) {
|
|
395
|
+
setLivemode(checkoutSession.livemode);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}, [checkoutSession, livemode, setLivemode, refresh]);
|
|
399
|
+
const renderContent = () => {
|
|
400
|
+
const footer = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
401
|
+
/* @__PURE__ */ jsx(Divider, { sx: { mt: { xs: "16px", md: "-24px" }, mb: { xs: "16px", md: "-16px" } } }),
|
|
402
|
+
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-end", alignItems: "center", flexWrap: "wrap", gap: 1, children: /* @__PURE__ */ jsx(Button, { variant: "outlined", size: "large", onClick: formRender?.onCancel, children: t("common.cancel") }) })
|
|
403
|
+
] });
|
|
404
|
+
if (error) {
|
|
405
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
406
|
+
/* @__PURE__ */ jsx(PaymentError, { mode, title: "Oops", description: formatError(error), button: null }),
|
|
407
|
+
footer
|
|
408
|
+
] });
|
|
409
|
+
}
|
|
410
|
+
if (!checkoutSession || !delay || !paymentLink || benefitLoading) {
|
|
411
|
+
return /* @__PURE__ */ jsx(DonationSkeleton, {});
|
|
412
|
+
}
|
|
413
|
+
if (checkoutSession?.expires_at <= Math.round(Date.now() / 1e3)) {
|
|
414
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
415
|
+
/* @__PURE__ */ jsx(
|
|
416
|
+
PaymentError,
|
|
417
|
+
{
|
|
418
|
+
mode,
|
|
419
|
+
title: t("payment.checkout.expired.title"),
|
|
420
|
+
description: t("payment.checkout.expired.description"),
|
|
421
|
+
button: null
|
|
422
|
+
}
|
|
423
|
+
),
|
|
424
|
+
footer
|
|
425
|
+
] });
|
|
426
|
+
}
|
|
427
|
+
if (!checkoutSession.line_items.length) {
|
|
428
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
429
|
+
/* @__PURE__ */ jsx(
|
|
430
|
+
PaymentError,
|
|
431
|
+
{
|
|
432
|
+
mode,
|
|
433
|
+
title: t("payment.checkout.emptyItems.title"),
|
|
434
|
+
description: t("payment.checkout.emptyItems.description"),
|
|
435
|
+
button: null
|
|
436
|
+
}
|
|
437
|
+
),
|
|
438
|
+
footer
|
|
439
|
+
] });
|
|
440
|
+
}
|
|
441
|
+
return /* @__PURE__ */ jsx(
|
|
442
|
+
PaymentInner,
|
|
443
|
+
{
|
|
444
|
+
formRender,
|
|
445
|
+
checkoutSession,
|
|
446
|
+
paymentMethods,
|
|
447
|
+
paymentLink,
|
|
448
|
+
paymentIntent,
|
|
449
|
+
completed: completed || checkoutSession.status === "complete",
|
|
450
|
+
customer,
|
|
451
|
+
onPaid,
|
|
452
|
+
onError,
|
|
453
|
+
onChange,
|
|
454
|
+
goBack,
|
|
455
|
+
mode,
|
|
456
|
+
action,
|
|
457
|
+
showCheckoutSummary,
|
|
458
|
+
benefits
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
};
|
|
462
|
+
return /* @__PURE__ */ jsxs(
|
|
463
|
+
Stack,
|
|
464
|
+
{
|
|
465
|
+
display: "flex",
|
|
466
|
+
flexDirection: "column",
|
|
467
|
+
sx: {
|
|
468
|
+
height: mode === "standalone" ? "100vh" : "auto",
|
|
469
|
+
overflow: isMobileSafariEnv ? "visible" : "hidden"
|
|
470
|
+
},
|
|
471
|
+
children: [
|
|
472
|
+
mode === "standalone" ? /* @__PURE__ */ jsx(
|
|
473
|
+
Header,
|
|
474
|
+
{
|
|
475
|
+
meta: void 0,
|
|
476
|
+
addons: void 0,
|
|
477
|
+
sessionManagerProps: void 0,
|
|
478
|
+
homeLink: void 0,
|
|
479
|
+
theme: void 0,
|
|
480
|
+
hideNavMenu: void 0,
|
|
481
|
+
maxWidth: false,
|
|
482
|
+
sx: { borderBottom: "1px solid var(--stroke-border-base, #EFF1F5)" }
|
|
483
|
+
}
|
|
484
|
+
) : null,
|
|
485
|
+
/* @__PURE__ */ jsxs(
|
|
486
|
+
Root,
|
|
487
|
+
{
|
|
488
|
+
mode,
|
|
489
|
+
sx: {
|
|
490
|
+
flex: 1,
|
|
491
|
+
overflow: {
|
|
492
|
+
xs: isMobileSafariEnv ? "visible" : "auto",
|
|
493
|
+
md: "hidden"
|
|
494
|
+
},
|
|
495
|
+
...isMobile && mode === "standalone" ? {
|
|
496
|
+
".cko-payment-submit-btn": {
|
|
497
|
+
position: "fixed",
|
|
498
|
+
bottom: 20,
|
|
499
|
+
left: 0,
|
|
500
|
+
right: 0,
|
|
501
|
+
zIndex: 999,
|
|
502
|
+
background: "#fff",
|
|
503
|
+
padding: "10px",
|
|
504
|
+
textAlign: "center",
|
|
505
|
+
button: {
|
|
506
|
+
color: "#fff",
|
|
507
|
+
maxWidth: 542
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
} : {}
|
|
511
|
+
},
|
|
512
|
+
children: [
|
|
513
|
+
goBack && /* @__PURE__ */ jsx(
|
|
514
|
+
ArrowBackOutlined,
|
|
515
|
+
{
|
|
516
|
+
sx: { mr: 0.5, color: "text.secondary", alignSelf: "flex-start", margin: "16px 0", cursor: "pointer" },
|
|
517
|
+
onClick: goBack,
|
|
518
|
+
fontSize: "medium"
|
|
519
|
+
}
|
|
520
|
+
),
|
|
521
|
+
/* @__PURE__ */ jsx(Stack, { className: "cko-container", sx: { gap: { sm: mode === "standalone" ? 0 : mode === "inline" ? 4 : 8 } }, children: renderContent() })
|
|
522
|
+
]
|
|
523
|
+
}
|
|
524
|
+
)
|
|
525
|
+
]
|
|
526
|
+
}
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
export const Root = styled(Box)`
|
|
530
|
+
box-sizing: border-box;
|
|
531
|
+
display: flex;
|
|
532
|
+
flex-direction: column;
|
|
533
|
+
align-items: center;
|
|
534
|
+
overflow: hidden;
|
|
535
|
+
position: relative;
|
|
536
|
+
|
|
537
|
+
.cko-container {
|
|
538
|
+
overflow: hidden;
|
|
539
|
+
width: 100%;
|
|
540
|
+
display: flex;
|
|
541
|
+
flex-direction: column;
|
|
542
|
+
justify-content: center;
|
|
543
|
+
position: relative;
|
|
544
|
+
flex: 1;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
.cko-overview {
|
|
548
|
+
position: relative;
|
|
549
|
+
flex-direction: column;
|
|
550
|
+
display: ${(props) => props.mode.endsWith("-minimal") ? "none" : "flex"};
|
|
551
|
+
background: var(--backgrounds-bg-base);
|
|
552
|
+
min-height: 'auto';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
.cko-footer {
|
|
556
|
+
display: ${(props) => props.mode.endsWith("-minimal") ? "none" : "block"};
|
|
557
|
+
text-align: center;
|
|
558
|
+
margin-top: 20px;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
.cko-payment-form {
|
|
562
|
+
.MuiFormLabel-root {
|
|
563
|
+
color: var(--foregrounds-fg-base, #010714);
|
|
564
|
+
font-weight: 500;
|
|
565
|
+
margin-top: 12px;
|
|
566
|
+
margin-bottom: 4px;
|
|
567
|
+
}
|
|
568
|
+
.MuiBox-root {
|
|
569
|
+
margin: 0;
|
|
570
|
+
}
|
|
571
|
+
.MuiFormHelperText-root {
|
|
572
|
+
margin-left: 14px;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
@media (max-width: ${({ theme }) => theme.breakpoints.values.md}px) {
|
|
577
|
+
padding-top: 0;
|
|
578
|
+
overflow: auto;
|
|
579
|
+
|
|
580
|
+
.cko-container {
|
|
581
|
+
flex-direction: column;
|
|
582
|
+
justify-content: flex-start;
|
|
583
|
+
gap: 0;
|
|
584
|
+
overflow: visible;
|
|
585
|
+
min-width: 200px;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
.cko-overview {
|
|
589
|
+
width: 100%;
|
|
590
|
+
min-height: auto;
|
|
591
|
+
flex: none;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
.cko-footer {
|
|
595
|
+
position: relative;
|
|
596
|
+
margin-bottom: 4px;
|
|
597
|
+
margin-top: 0;
|
|
598
|
+
bottom: 0;
|
|
599
|
+
left: 0;
|
|
600
|
+
transform: translateX(0);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
`;
|
package/es/payment/error.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ type ModeType = LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal
|
|
|
3
3
|
type Props = {
|
|
4
4
|
title: string;
|
|
5
5
|
description: string;
|
|
6
|
-
button?: string;
|
|
6
|
+
button?: string | React.ReactNode;
|
|
7
7
|
mode?: ModeType;
|
|
8
8
|
};
|
|
9
9
|
declare function PaymentError({ title, description, button, mode }: Props): import("react").JSX.Element;
|
package/es/payment/error.js
CHANGED
|
@@ -13,7 +13,17 @@ export default function PaymentError({ title, description, button, mode }) {
|
|
|
13
13
|
return /* @__PURE__ */ jsx(Stack, { sx: heightStyle, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs(Stack, { sx: { width: "280px" }, direction: "column", alignItems: "center", justifyContent: "center", children: [
|
|
14
14
|
/* @__PURE__ */ jsx(Typography, { variant: "h5", sx: { mb: 2 }, children: title }),
|
|
15
15
|
/* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { mb: 2, textAlign: "center" }, children: description }),
|
|
16
|
-
|
|
16
|
+
typeof button === "string" ? /* @__PURE__ */ jsx(
|
|
17
|
+
Button,
|
|
18
|
+
{
|
|
19
|
+
variant: "text",
|
|
20
|
+
size: "small",
|
|
21
|
+
sx: { color: "text.link" },
|
|
22
|
+
component: Link,
|
|
23
|
+
href: window.blocklet?.appUrl,
|
|
24
|
+
children: button
|
|
25
|
+
}
|
|
26
|
+
) : button
|
|
17
27
|
] }) });
|
|
18
28
|
}
|
|
19
29
|
PaymentError.defaultProps = {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import 'react-international-phone/style.css';
|
|
2
2
|
import type { CheckoutCallbacks, CheckoutContext } from '../../types';
|
|
3
|
-
|
|
4
|
-
declare
|
|
3
|
+
export declare const waitForCheckoutComplete: (sessionId: string) => Promise<CheckoutContext>;
|
|
4
|
+
export declare const hasDidWallet: (user: any) => any;
|
|
5
|
+
type PageData = CheckoutContext & CheckoutCallbacks & {
|
|
6
|
+
onlyShowBtn?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, currencyId, onlyShowBtn, }: PageData): import("react").JSX.Element;
|
|
5
9
|
declare namespace PaymentForm {
|
|
6
|
-
var defaultProps: {
|
|
10
|
+
var defaultProps: {
|
|
11
|
+
onlyShowBtn: boolean;
|
|
12
|
+
};
|
|
7
13
|
}
|
|
8
14
|
export default PaymentForm;
|