@blocklet/payment-react 1.18.29 → 1.18.31
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 +51 -23
- package/es/components/country-select.js +1 -0
- package/es/components/over-due-invoice-payment.js +44 -5
- package/es/history/invoice/list.js +3 -1
- package/es/libs/util.d.ts +2 -0
- package/es/libs/util.js +25 -2
- package/es/locales/en.js +2 -1
- package/es/locales/zh.js +2 -1
- package/es/payment/form/currency.d.ts +1 -1
- package/es/payment/form/currency.js +3 -3
- package/es/payment/form/index.d.ts +1 -1
- package/es/payment/form/index.js +22 -36
- package/es/payment/form/stripe/form.js +4 -2
- package/es/payment/index.js +10 -1
- package/es/payment/product-donation.js +4 -3
- package/es/payment/success.d.ts +3 -1
- package/es/payment/success.js +78 -6
- package/lib/checkout/donate.js +19 -11
- package/lib/components/country-select.js +1 -0
- package/lib/components/over-due-invoice-payment.js +42 -3
- package/lib/history/invoice/list.js +1 -0
- package/lib/libs/util.d.ts +2 -0
- package/lib/libs/util.js +27 -2
- package/lib/locales/en.js +2 -1
- package/lib/locales/zh.js +2 -1
- package/lib/payment/form/currency.d.ts +1 -1
- package/lib/payment/form/currency.js +3 -3
- package/lib/payment/form/index.d.ts +1 -1
- package/lib/payment/form/index.js +21 -35
- package/lib/payment/form/stripe/form.js +4 -2
- package/lib/payment/index.js +10 -1
- package/lib/payment/product-donation.js +4 -3
- package/lib/payment/success.d.ts +3 -1
- package/lib/payment/success.js +68 -15
- package/package.json +8 -8
- package/src/checkout/donate.tsx +23 -5
- package/src/components/country-select.tsx +1 -0
- package/src/components/over-due-invoice-payment.tsx +47 -4
- package/src/history/invoice/list.tsx +2 -0
- package/src/libs/util.ts +28 -2
- package/src/locales/en.tsx +1 -0
- package/src/locales/zh.tsx +1 -0
- package/src/payment/form/currency.tsx +4 -4
- package/src/payment/form/index.tsx +23 -47
- package/src/payment/form/stripe/form.tsx +4 -2
- package/src/payment/index.tsx +12 -1
- package/src/payment/product-donation.tsx +4 -3
- package/src/payment/success.tsx +73 -11
- package/src/payment/summary.tsx +1 -0
package/es/payment/success.js
CHANGED
|
@@ -1,15 +1,86 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
-
import { Grow, Link, Stack, Typography } from "@mui/material";
|
|
3
|
+
import { Grow, Link, Stack, Typography, Box, Paper } from "@mui/material";
|
|
4
4
|
import { styled } from "@mui/system";
|
|
5
5
|
import { joinURL } from "ufo";
|
|
6
|
+
import { Button } from "@arcblock/ux";
|
|
6
7
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
7
|
-
export default function PaymentSuccess({
|
|
8
|
+
export default function PaymentSuccess({
|
|
9
|
+
mode,
|
|
10
|
+
message,
|
|
11
|
+
action,
|
|
12
|
+
payee,
|
|
13
|
+
invoiceId,
|
|
14
|
+
subscriptionId,
|
|
15
|
+
subscriptions
|
|
16
|
+
}) {
|
|
8
17
|
const { t } = useLocaleContext();
|
|
9
18
|
const { prefix } = usePaymentContext();
|
|
10
19
|
let next = null;
|
|
11
|
-
if (["subscription", "setup"].includes(action)
|
|
12
|
-
|
|
20
|
+
if (["subscription", "setup"].includes(action)) {
|
|
21
|
+
if (subscriptions && subscriptions.length > 1) {
|
|
22
|
+
next = /* @__PURE__ */ jsx(
|
|
23
|
+
Paper,
|
|
24
|
+
{
|
|
25
|
+
elevation: 0,
|
|
26
|
+
sx: {
|
|
27
|
+
p: 3,
|
|
28
|
+
backgroundColor: "grey.50",
|
|
29
|
+
borderRadius: 2,
|
|
30
|
+
width: "100%",
|
|
31
|
+
mt: 2,
|
|
32
|
+
display: "flex",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
gap: 2
|
|
35
|
+
},
|
|
36
|
+
children: subscriptions.map((subscription) => /* @__PURE__ */ jsxs(
|
|
37
|
+
Box,
|
|
38
|
+
{
|
|
39
|
+
sx: {
|
|
40
|
+
display: "flex",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
justifyContent: "space-between"
|
|
43
|
+
},
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsx(
|
|
46
|
+
Typography,
|
|
47
|
+
{
|
|
48
|
+
variant: "body2",
|
|
49
|
+
sx: {
|
|
50
|
+
color: "text.secondary",
|
|
51
|
+
fontWeight: 500
|
|
52
|
+
},
|
|
53
|
+
children: subscription.description
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
/* @__PURE__ */ jsx(
|
|
57
|
+
Box,
|
|
58
|
+
{
|
|
59
|
+
sx: {
|
|
60
|
+
flex: 1,
|
|
61
|
+
borderBottom: "1px dashed",
|
|
62
|
+
borderColor: "grey.300",
|
|
63
|
+
mx: 2
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ jsx(Button, { variant: "text", color: "primary", size: "small", children: /* @__PURE__ */ jsx(
|
|
68
|
+
Link,
|
|
69
|
+
{
|
|
70
|
+
href: joinURL(prefix, `/customer/subscription/${subscription.id}`),
|
|
71
|
+
sx: { color: "text.secondary" },
|
|
72
|
+
children: t("payment.checkout.next.view")
|
|
73
|
+
}
|
|
74
|
+
) })
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
subscription.id
|
|
78
|
+
))
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
} else if (subscriptionId) {
|
|
82
|
+
next = /* @__PURE__ */ jsx(Button, { variant: "outlined", color: "primary", sx: { mt: 2 }, children: /* @__PURE__ */ jsx(Link, { href: joinURL(prefix, `/customer/subscription/${subscriptionId}`), children: t("payment.checkout.next.subscription", { payee }) }) });
|
|
83
|
+
}
|
|
13
84
|
} else if (invoiceId) {
|
|
14
85
|
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
86
|
}
|
|
@@ -19,7 +90,7 @@ export default function PaymentSuccess({ mode, message, action, payee, invoiceId
|
|
|
19
90
|
direction: "column",
|
|
20
91
|
alignItems: "center",
|
|
21
92
|
justifyContent: mode === "standalone" ? "center" : "flex-start",
|
|
22
|
-
sx: { height: mode === "standalone" ?
|
|
93
|
+
sx: { height: mode === "standalone" ? "fit-content" : 300 },
|
|
23
94
|
children: [
|
|
24
95
|
/* @__PURE__ */ jsx(Div, { children: /* @__PURE__ */ jsxs("div", { className: "check-icon", children: [
|
|
25
96
|
/* @__PURE__ */ jsx("span", { className: "icon-line line-tip" }),
|
|
@@ -36,7 +107,8 @@ export default function PaymentSuccess({ mode, message, action, payee, invoiceId
|
|
|
36
107
|
}
|
|
37
108
|
PaymentSuccess.defaultProps = {
|
|
38
109
|
invoiceId: "",
|
|
39
|
-
subscriptionId: ""
|
|
110
|
+
subscriptionId: "",
|
|
111
|
+
subscriptions: []
|
|
40
112
|
};
|
|
41
113
|
const Div = styled("div")`
|
|
42
114
|
width: 80px;
|
package/lib/checkout/donate.js
CHANGED
|
@@ -314,15 +314,19 @@ function SupporterSimple({
|
|
|
314
314
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.AvatarGroup, {
|
|
315
315
|
total: customersNum,
|
|
316
316
|
max: 10,
|
|
317
|
+
spacing: 4,
|
|
318
|
+
sx: {
|
|
319
|
+
"& .MuiAvatar-root": {
|
|
320
|
+
width: 24,
|
|
321
|
+
height: 24,
|
|
322
|
+
fontSize: "0.6rem"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
317
325
|
children: customers.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
318
326
|
title: x.customer?.name,
|
|
319
327
|
alt: x.customer?.metadata?.anonymous ? "" : x.customer?.name,
|
|
320
328
|
src: (0, _util.getCustomerAvatar)(x.customer?.did, x?.updated_at ? new Date(x.updated_at).toISOString() : "", 48),
|
|
321
|
-
variant: "circular"
|
|
322
|
-
sx: {
|
|
323
|
-
width: 24,
|
|
324
|
-
height: 24
|
|
325
|
-
}
|
|
329
|
+
variant: "circular"
|
|
326
330
|
}, x.id))
|
|
327
331
|
})]
|
|
328
332
|
});
|
|
@@ -665,14 +669,18 @@ function CheckoutDonateInner({
|
|
|
665
669
|
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.AvatarGroup, {
|
|
666
670
|
total: customers?.length,
|
|
667
671
|
max: 5,
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
variant: "circular",
|
|
672
|
-
sx: {
|
|
672
|
+
spacing: 4,
|
|
673
|
+
sx: {
|
|
674
|
+
"& .MuiAvatar-root": {
|
|
673
675
|
width: 18,
|
|
674
|
-
height: 18
|
|
676
|
+
height: 18,
|
|
677
|
+
fontSize: "0.6rem"
|
|
675
678
|
}
|
|
679
|
+
},
|
|
680
|
+
children: customers.map(x => /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Avatar, {
|
|
681
|
+
title: x.customer?.name,
|
|
682
|
+
src: (0, _util.getCustomerAvatar)(x.customer?.did, x?.updated_at ? new Date(x.updated_at).toISOString() : "", 24),
|
|
683
|
+
variant: "circular"
|
|
676
684
|
}, x.id))
|
|
677
685
|
}), customers?.length > 0 && t("payment.checkout.donation.gaveTips", {
|
|
678
686
|
count: customers?.length
|
|
@@ -11,6 +11,7 @@ var _context = require("@arcblock/ux/lib/Locale/context");
|
|
|
11
11
|
var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
|
|
12
12
|
var _ufo = require("ufo");
|
|
13
13
|
var _ahooks = require("ahooks");
|
|
14
|
+
var _pWaitFor = _interopRequireDefault(require("p-wait-for"));
|
|
14
15
|
var _ux = require("@arcblock/ux");
|
|
15
16
|
var _iconsMaterial = require("@mui/icons-material");
|
|
16
17
|
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
@@ -62,6 +63,7 @@ function OverdueInvoicePayment({
|
|
|
62
63
|
const sourceType = subscriptionId ? "subscription" : "customer";
|
|
63
64
|
const effectiveCustomerId = customerId || session?.user?.did;
|
|
64
65
|
const sourceId = subscriptionId || effectiveCustomerId;
|
|
66
|
+
const customerIdRef = (0, _react.useRef)(effectiveCustomerId);
|
|
65
67
|
const {
|
|
66
68
|
data = {
|
|
67
69
|
summary: {},
|
|
@@ -75,7 +77,12 @@ function OverdueInvoicePayment({
|
|
|
75
77
|
customerId: effectiveCustomerId,
|
|
76
78
|
authToken
|
|
77
79
|
}), {
|
|
78
|
-
ready: !!subscriptionId || !!effectiveCustomerId
|
|
80
|
+
ready: !!subscriptionId || !!effectiveCustomerId,
|
|
81
|
+
onSuccess: res => {
|
|
82
|
+
if (res.customer?.id && res.customer?.id !== customerIdRef.current) {
|
|
83
|
+
customerIdRef.current = res.customer?.id;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
79
86
|
});
|
|
80
87
|
const detailUrl = (0, _react.useMemo)(() => {
|
|
81
88
|
if (subscriptionId) {
|
|
@@ -108,15 +115,45 @@ function OverdueInvoicePayment({
|
|
|
108
115
|
trailing: true,
|
|
109
116
|
maxWait: 5e3
|
|
110
117
|
});
|
|
118
|
+
const isCrossOriginRequest = (0, _util.isCrossOrigin)();
|
|
111
119
|
const subscription = (0, _subscription.useSubscription)("events");
|
|
120
|
+
const waitForInvoiceAllPaid = async () => {
|
|
121
|
+
let isPaid = false;
|
|
122
|
+
await (0, _pWaitFor.default)(async () => {
|
|
123
|
+
const res = await refresh();
|
|
124
|
+
isPaid = res.invoices?.length === 0;
|
|
125
|
+
return isPaid;
|
|
126
|
+
}, {
|
|
127
|
+
interval: 2e3,
|
|
128
|
+
timeout: 3 * 60 * 1e3
|
|
129
|
+
});
|
|
130
|
+
return isPaid;
|
|
131
|
+
};
|
|
132
|
+
const handleConnected = async () => {
|
|
133
|
+
if (isCrossOriginRequest) {
|
|
134
|
+
try {
|
|
135
|
+
const paid = await waitForInvoiceAllPaid();
|
|
136
|
+
if (successToast) {
|
|
137
|
+
_Toast.default.close();
|
|
138
|
+
_Toast.default.success(t("payment.customer.invoice.paySuccess"));
|
|
139
|
+
}
|
|
140
|
+
if (paid) {
|
|
141
|
+
setDialogOpen(false);
|
|
142
|
+
onPaid(sourceId, selectCurrencyId, sourceType);
|
|
143
|
+
}
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.error("Check payment status failed:", err);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
112
149
|
(0, _react.useEffect)(() => {
|
|
113
|
-
if (subscription) {
|
|
150
|
+
if (subscription && !isCrossOriginRequest) {
|
|
114
151
|
subscription.on("invoice.paid", ({
|
|
115
152
|
response
|
|
116
153
|
}) => {
|
|
117
154
|
const relevantId = subscriptionId || response.customer_id;
|
|
118
155
|
const uniqueKey = `${relevantId}-${response.currency_id}`;
|
|
119
|
-
if (subscriptionId && response.subscription_id === subscriptionId || effectiveCustomerId &&
|
|
156
|
+
if (subscriptionId && response.subscription_id === subscriptionId || effectiveCustomerId && effectiveCustomerId === response.customer_id || customerIdRef.current && customerIdRef.current === response.customer_id) {
|
|
120
157
|
if (!processedCurrencies[uniqueKey]) {
|
|
121
158
|
setProcessedCurrencies(prev => ({
|
|
122
159
|
...prev,
|
|
@@ -160,9 +197,11 @@ function OverdueInvoicePayment({
|
|
|
160
197
|
saveConnect: false,
|
|
161
198
|
action: "collect-batch",
|
|
162
199
|
prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
|
|
200
|
+
useSocket: !isCrossOriginRequest,
|
|
163
201
|
extraParams,
|
|
164
202
|
onSuccess: () => {
|
|
165
203
|
connect.close();
|
|
204
|
+
handleConnected();
|
|
166
205
|
setPayLoading(false);
|
|
167
206
|
setPaymentStatus(prev => ({
|
|
168
207
|
...prev,
|
package/lib/libs/util.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ActionProps, PricingRenderProps } from '../types';
|
|
|
3
3
|
export declare const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
4
4
|
export declare const isPaymentKitMounted: () => any;
|
|
5
5
|
export declare const getPrefix: () => string;
|
|
6
|
+
export declare function isCrossOrigin(): boolean;
|
|
6
7
|
export declare function formatToDate(date: Date | string | number, locale?: string, format?: string): any;
|
|
7
8
|
export declare function formatToDatetime(date: Date | string | number, locale?: string): any;
|
|
8
9
|
export declare function formatTime(date: Date | string | number, format?: string, locale?: string): any;
|
|
@@ -49,6 +50,7 @@ export declare function formatPriceDisplay({ amount, then, actualAmount, showThe
|
|
|
49
50
|
actualAmount: string;
|
|
50
51
|
showThen?: boolean;
|
|
51
52
|
}, recurring: string, hasMetered: boolean, locale?: string): string;
|
|
53
|
+
export declare function hasMultipleRecurringIntervals(items: TLineItemExpanded[]): boolean;
|
|
52
54
|
export declare function getFreeTrialTime({ trialInDays, trialEnd }: {
|
|
53
55
|
trialInDays: number;
|
|
54
56
|
trialEnd: number;
|
package/lib/libs/util.js
CHANGED
|
@@ -49,6 +49,8 @@ exports.getUserProfileLink = getUserProfileLink;
|
|
|
49
49
|
exports.getWebhookStatusColor = getWebhookStatusColor;
|
|
50
50
|
exports.getWordBreakStyle = getWordBreakStyle;
|
|
51
51
|
exports.hasDelegateTxHash = hasDelegateTxHash;
|
|
52
|
+
exports.hasMultipleRecurringIntervals = hasMultipleRecurringIntervals;
|
|
53
|
+
exports.isCrossOrigin = isCrossOrigin;
|
|
52
54
|
exports.isMobileSafari = isMobileSafari;
|
|
53
55
|
exports.isPaymentKitMounted = void 0;
|
|
54
56
|
exports.isValidCountry = isValidCountry;
|
|
@@ -100,6 +102,16 @@ const getPrefix = () => {
|
|
|
100
102
|
return (0, _ufo.joinURL)(baseUrl, prefix);
|
|
101
103
|
};
|
|
102
104
|
exports.getPrefix = getPrefix;
|
|
105
|
+
function isCrossOrigin() {
|
|
106
|
+
try {
|
|
107
|
+
const prefix = getPrefix();
|
|
108
|
+
const prefixOrigin = new URL(prefix).origin;
|
|
109
|
+
const currentOrigin = window.location.origin;
|
|
110
|
+
return prefixOrigin !== currentOrigin;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
103
115
|
function formatToDate(date, locale = "en", format = "YYYY-MM-DD HH:mm:ss") {
|
|
104
116
|
if (!date) {
|
|
105
117
|
return "-";
|
|
@@ -538,6 +550,18 @@ function formatPriceDisplay({
|
|
|
538
550
|
}
|
|
539
551
|
return [amount, then].filter(Boolean).join(" ");
|
|
540
552
|
}
|
|
553
|
+
function hasMultipleRecurringIntervals(items) {
|
|
554
|
+
const intervals = /* @__PURE__ */new Set();
|
|
555
|
+
for (const item of items) {
|
|
556
|
+
if (item.price?.recurring?.interval && item.price?.type === "recurring") {
|
|
557
|
+
intervals.add(`${item.price.recurring.interval}-${item.price.recurring.interval_count}`);
|
|
558
|
+
if (intervals.size > 1) {
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
541
565
|
function getFreeTrialTime({
|
|
542
566
|
trialInDays,
|
|
543
567
|
trialEnd
|
|
@@ -623,6 +647,7 @@ function formatCheckoutHeadlines(items, currency, {
|
|
|
623
647
|
const item = items.find(x => x.price.type === "recurring");
|
|
624
648
|
const recurring = formatRecurring((item?.upsell_price || item?.price)?.recurring, false, "per", locale);
|
|
625
649
|
const hasMetered = items.some(x => x.price.type === "recurring" && x.price.recurring?.usage_type === "metered");
|
|
650
|
+
const differentRecurring = hasMultipleRecurringIntervals(items);
|
|
626
651
|
if (items.every(x => x.price.type === "recurring")) {
|
|
627
652
|
const subscription2 = [hasMetered ? (0, _locales.t)("payment.checkout.least", locale) : "", (0, _util.fromUnitToToken)(items.reduce((acc, x) => {
|
|
628
653
|
if (x.price.recurring?.usage_type === "metered") {
|
|
@@ -693,7 +718,7 @@ function formatCheckoutHeadlines(items, currency, {
|
|
|
693
718
|
then: hasMetered ? (0, _locales.t)("payment.checkout.meteredThen", locale, {
|
|
694
719
|
recurring
|
|
695
720
|
}) : recurring,
|
|
696
|
-
showThen: hasMetered,
|
|
721
|
+
showThen: hasMetered && !differentRecurring,
|
|
697
722
|
actualAmount
|
|
698
723
|
};
|
|
699
724
|
return {
|
|
@@ -713,7 +738,7 @@ function formatCheckoutHeadlines(items, currency, {
|
|
|
713
738
|
}),
|
|
714
739
|
amount,
|
|
715
740
|
then: formatMeteredThen(`${subscription} ${currency.symbol}`, recurring, hasMetered && Number(subscription) === 0, locale),
|
|
716
|
-
showThen:
|
|
741
|
+
showThen: !differentRecurring,
|
|
717
742
|
actualAmount
|
|
718
743
|
};
|
|
719
744
|
return {
|
package/lib/locales/en.js
CHANGED
|
@@ -122,7 +122,8 @@ module.exports = (0, _flat.default)({
|
|
|
122
122
|
login: "Login to load and save contact information",
|
|
123
123
|
next: {
|
|
124
124
|
subscription: "View subscription",
|
|
125
|
-
invoice: "View invoice"
|
|
125
|
+
invoice: "View invoice",
|
|
126
|
+
view: "View"
|
|
126
127
|
},
|
|
127
128
|
paymentRequired: "Payment Required",
|
|
128
129
|
staking: {
|
package/lib/locales/zh.js
CHANGED
|
@@ -122,7 +122,8 @@ module.exports = (0, _flat.default)({
|
|
|
122
122
|
login: "\u767B\u5F55\u4EE5\u52A0\u8F7D\u5E76\u4FDD\u5B58\u8054\u7CFB\u4FE1\u606F",
|
|
123
123
|
next: {
|
|
124
124
|
subscription: "\u67E5\u770B\u8BA2\u9605",
|
|
125
|
-
invoice: "\u67E5\u770B\u8D26\u5355"
|
|
125
|
+
invoice: "\u67E5\u770B\u8D26\u5355",
|
|
126
|
+
view: "\u67E5\u770B"
|
|
126
127
|
},
|
|
127
128
|
paymentRequired: "\u652F\u4ED8\u91D1\u989D",
|
|
128
129
|
staking: {
|
|
@@ -20,11 +20,11 @@ function CurrencySelector({
|
|
|
20
20
|
gap: 12,
|
|
21
21
|
gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))"
|
|
22
22
|
},
|
|
23
|
-
children: currencies.map(
|
|
24
|
-
const selected =
|
|
23
|
+
children: currencies.map(x => {
|
|
24
|
+
const selected = x.id === value;
|
|
25
25
|
return /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Card, {
|
|
26
26
|
variant: "outlined",
|
|
27
|
-
onClick: () => onChange(
|
|
27
|
+
onClick: () => onChange(x.id, x.method?.id),
|
|
28
28
|
className: selected ? "cko-payment-card" : "cko-payment-card-unselect",
|
|
29
29
|
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
30
30
|
direction: "row",
|
|
@@ -6,7 +6,7 @@ type PageData = CheckoutContext & CheckoutCallbacks & {
|
|
|
6
6
|
onlyShowBtn?: boolean;
|
|
7
7
|
isDonation?: boolean;
|
|
8
8
|
};
|
|
9
|
-
declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action,
|
|
9
|
+
declare function PaymentForm({ checkoutSession, paymentMethods, paymentIntent, paymentLink, customer, onPaid, onError, action, onlyShowBtn, isDonation, }: PageData): import("react").JSX.Element;
|
|
10
10
|
declare namespace PaymentForm {
|
|
11
11
|
var defaultProps: {
|
|
12
12
|
onlyShowBtn: boolean;
|
|
@@ -103,7 +103,6 @@ function PaymentForm({
|
|
|
103
103
|
onError,
|
|
104
104
|
// mode,
|
|
105
105
|
action,
|
|
106
|
-
currencyId,
|
|
107
106
|
onlyShowBtn,
|
|
108
107
|
isDonation = false
|
|
109
108
|
}) {
|
|
@@ -150,19 +149,6 @@ function PaymentForm({
|
|
|
150
149
|
stripePaying: false
|
|
151
150
|
});
|
|
152
151
|
const currencies = (0, _util.flattenPaymentMethods)(paymentMethods);
|
|
153
|
-
const [paymentCurrencyIndex, setPaymentCurrencyIndex] = (0, _react.useState)(() => {
|
|
154
|
-
const query = (0, _util.getQueryParams)(window.location.href);
|
|
155
|
-
const queryCurrencyId = query.currencyId || currencyId;
|
|
156
|
-
const index = currencies.findIndex(x => x.id === queryCurrencyId);
|
|
157
|
-
return index >= 0 ? index : 0;
|
|
158
|
-
});
|
|
159
|
-
const handleCurrencyChange = index => {
|
|
160
|
-
setPaymentCurrencyIndex(index);
|
|
161
|
-
const selectedCurrencyId = currencies[index]?.id;
|
|
162
|
-
if (selectedCurrencyId) {
|
|
163
|
-
(0, _currency2.saveCurrencyPreference)(selectedCurrencyId, session?.user?.did);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
152
|
const onCheckoutComplete = (0, _ahooks.useMemoizedFn)(async ({
|
|
167
153
|
response
|
|
168
154
|
}) => {
|
|
@@ -170,17 +156,9 @@ function PaymentForm({
|
|
|
170
156
|
await handleConnected();
|
|
171
157
|
}
|
|
172
158
|
});
|
|
173
|
-
const onInvoicePaid = (0, _ahooks.useMemoizedFn)(async ({
|
|
174
|
-
response
|
|
175
|
-
}) => {
|
|
176
|
-
if (response.customer_id === customer?.id && state.customerLimited) {
|
|
177
|
-
await onAction();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
159
|
(0, _react.useEffect)(() => {
|
|
181
160
|
if (subscription) {
|
|
182
161
|
subscription.on("checkout.session.completed", onCheckoutComplete);
|
|
183
|
-
subscription.on("invoice.paid", onInvoicePaid);
|
|
184
162
|
}
|
|
185
163
|
}, [subscription]);
|
|
186
164
|
const mergeUserInfo = (customerInfo, userInfo) => {
|
|
@@ -247,10 +225,6 @@ function PaymentForm({
|
|
|
247
225
|
};
|
|
248
226
|
initUserInfo();
|
|
249
227
|
}, [session?.user, checkoutSession.phone_number_collection?.enabled]);
|
|
250
|
-
(0, _react.useEffect)(() => {
|
|
251
|
-
setValue("payment_method", currencies[paymentCurrencyIndex]?.method?.id);
|
|
252
|
-
setValue("payment_currency", currencies[paymentCurrencyIndex]?.id);
|
|
253
|
-
}, [paymentCurrencyIndex, currencies, setValue]);
|
|
254
228
|
const paymentMethod = (0, _reactHookForm.useWatch)({
|
|
255
229
|
control,
|
|
256
230
|
name: "payment_method"
|
|
@@ -355,6 +329,7 @@ function PaymentForm({
|
|
|
355
329
|
action: checkoutSession.mode,
|
|
356
330
|
prefix: (0, _ufo.joinURL)((0, _util.getPrefix)(), "/api/did"),
|
|
357
331
|
saveConnect: false,
|
|
332
|
+
useSocket: (0, _util.isCrossOrigin)() === false,
|
|
358
333
|
extraParams: {
|
|
359
334
|
checkoutSessionId: checkoutSession.id,
|
|
360
335
|
sessionUserDid: session?.user?.did
|
|
@@ -377,6 +352,11 @@ function PaymentForm({
|
|
|
377
352
|
paying: false
|
|
378
353
|
});
|
|
379
354
|
onError(err);
|
|
355
|
+
},
|
|
356
|
+
messages: {
|
|
357
|
+
title: "DID Connect",
|
|
358
|
+
scan: "Use following methods to complete this payment",
|
|
359
|
+
confirm: "Confirm"
|
|
380
360
|
}
|
|
381
361
|
});
|
|
382
362
|
}
|
|
@@ -436,13 +416,13 @@ function PaymentForm({
|
|
|
436
416
|
}
|
|
437
417
|
if (hasDidWallet(session.user)) {
|
|
438
418
|
handleSubmit(onFormSubmit, onFormError)();
|
|
439
|
-
|
|
440
|
-
session.bindWallet(() => {
|
|
441
|
-
setTimeout(() => {
|
|
442
|
-
handleSubmit(onFormSubmit, onFormError)();
|
|
443
|
-
}, 2e3);
|
|
444
|
-
});
|
|
419
|
+
return;
|
|
445
420
|
}
|
|
421
|
+
session.bindWallet(() => {
|
|
422
|
+
setTimeout(() => {
|
|
423
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
424
|
+
}, 2e3);
|
|
425
|
+
});
|
|
446
426
|
} else {
|
|
447
427
|
if (isDonationMode) {
|
|
448
428
|
handleSubmit(onFormSubmit, onFormError)();
|
|
@@ -569,10 +549,16 @@ function PaymentForm({
|
|
|
569
549
|
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactHookForm.Controller, {
|
|
570
550
|
name: "payment_currency",
|
|
571
551
|
control,
|
|
572
|
-
render: (
|
|
573
|
-
|
|
552
|
+
render: ({
|
|
553
|
+
field
|
|
554
|
+
}) => /* @__PURE__ */(0, _jsxRuntime.jsx)(_currency.default, {
|
|
555
|
+
value: field.value,
|
|
574
556
|
currencies,
|
|
575
|
-
onChange:
|
|
557
|
+
onChange: (id, methodId) => {
|
|
558
|
+
field.onChange(id);
|
|
559
|
+
setValue("payment_method", methodId);
|
|
560
|
+
(0, _currency2.saveCurrencyPreference)(id, session?.user?.did);
|
|
561
|
+
}
|
|
576
562
|
})
|
|
577
563
|
})
|
|
578
564
|
}), state.stripePaying && state.stripeContext && /* @__PURE__ */(0, _jsxRuntime.jsx)(_stripe.default, {
|
|
@@ -189,9 +189,11 @@ function StripeCheckoutForm({
|
|
|
189
189
|
|
|
190
190
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Content, {
|
|
191
191
|
onSubmit: handleSubmit,
|
|
192
|
-
children: [(!state.paymentMethod ||
|
|
192
|
+
children: [(!state.paymentMethod || ["link", "card"].includes(state.paymentMethod)) && /* @__PURE__ */(0, _jsxRuntime.jsx)(LinkAuthenticationElement, {
|
|
193
193
|
options: {
|
|
194
|
-
|
|
194
|
+
defaultValues: {
|
|
195
|
+
email: customer.email
|
|
196
|
+
}
|
|
195
197
|
}
|
|
196
198
|
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(PaymentElementContainer, {
|
|
197
199
|
className: !state.isTransitioning ? "visible" : "",
|
package/lib/payment/index.js
CHANGED
|
@@ -116,6 +116,14 @@ function PaymentInner({
|
|
|
116
116
|
})
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
|
+
(0, _react.useEffect)(() => {
|
|
120
|
+
if (defaultCurrencyId) {
|
|
121
|
+
methods.setValue("payment_currency", defaultCurrencyId);
|
|
122
|
+
}
|
|
123
|
+
if (defaultMethodId) {
|
|
124
|
+
methods.setValue("payment_method", defaultMethodId);
|
|
125
|
+
}
|
|
126
|
+
}, [defaultCurrencyId, defaultMethodId]);
|
|
119
127
|
(0, _react.useEffect)(() => {
|
|
120
128
|
if (!(0, _util2.isMobileSafari)()) {
|
|
121
129
|
return () => {};
|
|
@@ -258,7 +266,7 @@ function PaymentInner({
|
|
|
258
266
|
billingThreshold: Math.max(state.checkoutSession.subscription_data?.billing_threshold_amount || 0,
|
|
259
267
|
// @ts-ignore
|
|
260
268
|
state.checkoutSession.subscription_data?.min_stake_amount || 0),
|
|
261
|
-
showStaking: method.type === "arcblock",
|
|
269
|
+
showStaking: method.type === "arcblock" && !state.checkoutSession.subscription_data?.no_stake,
|
|
262
270
|
currency,
|
|
263
271
|
onUpsell,
|
|
264
272
|
onDownsell,
|
|
@@ -289,6 +297,7 @@ function PaymentInner({
|
|
|
289
297
|
action: state.checkoutSession.mode,
|
|
290
298
|
invoiceId: state.checkoutSession.invoice_id,
|
|
291
299
|
subscriptionId: state.checkoutSession.subscription_id,
|
|
300
|
+
subscriptions: state.checkoutSession.subscriptions,
|
|
292
301
|
message: paymentLink?.after_completion?.hosted_confirmation?.custom_message || t(`payment.checkout.completed.${state.checkoutSession.submit_type === "donate" ? "donate" : state.checkoutSession.mode}`)
|
|
293
302
|
}), !completed && /* @__PURE__ */(0, _jsxRuntime.jsx)(_form.default, {
|
|
294
303
|
currencyId,
|
|
@@ -105,9 +105,10 @@ function ProductDonation({
|
|
|
105
105
|
if (hasPresets) {
|
|
106
106
|
sortedPresets = [...presets].map(p => parseFloat(p)).sort((a, b) => a - b);
|
|
107
107
|
}
|
|
108
|
-
const minPreset = hasPresets ? sortedPresets[
|
|
109
|
-
|
|
110
|
-
const
|
|
108
|
+
const minPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] : 1;
|
|
109
|
+
let maxPreset = hasPresets ? sortedPresets[sortedPresets.length - 1] * 5 : 100;
|
|
110
|
+
const systemMax = settings.amount.maximum ? parseFloat(settings.amount.maximum) : Infinity;
|
|
111
|
+
maxPreset = Math.min(maxPreset, systemMax);
|
|
111
112
|
const detectPrecision = () => {
|
|
112
113
|
let maxPrecision = 2;
|
|
113
114
|
if (!hasPresets) return 0;
|
package/lib/payment/success.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ type Props = {
|
|
|
5
5
|
payee: string;
|
|
6
6
|
invoiceId?: string;
|
|
7
7
|
subscriptionId?: string;
|
|
8
|
+
subscriptions?: any[];
|
|
8
9
|
};
|
|
9
|
-
declare function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId }: Props): import("react").JSX.Element;
|
|
10
|
+
declare function PaymentSuccess({ mode, message, action, payee, invoiceId, subscriptionId, subscriptions, }: Props): import("react").JSX.Element;
|
|
10
11
|
declare namespace PaymentSuccess {
|
|
11
12
|
var defaultProps: {
|
|
12
13
|
invoiceId: string;
|
|
13
14
|
subscriptionId: string;
|
|
15
|
+
subscriptions: never[];
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
export default PaymentSuccess;
|