@blocklet/payment-react 1.18.13 → 1.18.15
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/libs/util.d.ts +4 -0
- package/es/libs/util.js +20 -0
- package/es/payment/form/index.js +5 -0
- package/es/payment/form/stripe/form.js +41 -11
- package/es/payment/form/stripe/index.d.ts +1 -0
- package/es/payment/form/stripe/index.js +2 -1
- package/es/theme/index.js +5 -0
- package/lib/libs/util.d.ts +4 -0
- package/lib/libs/util.js +25 -0
- package/lib/payment/form/index.js +5 -0
- package/lib/payment/form/stripe/form.js +16 -3
- package/lib/payment/form/stripe/index.d.ts +1 -0
- package/lib/payment/form/stripe/index.js +2 -1
- package/lib/theme/index.js +5 -0
- package/package.json +8 -8
- package/src/libs/util.ts +25 -0
- package/src/payment/form/index.tsx +5 -0
- package/src/payment/form/stripe/form.tsx +26 -3
- package/src/payment/form/stripe/index.tsx +2 -0
- package/src/theme/index.tsx +5 -0
package/es/libs/util.d.ts
CHANGED
|
@@ -114,3 +114,7 @@ export declare function getInvoiceDescriptionAndReason(invoice: TInvoiceExpanded
|
|
|
114
114
|
export declare function getPaymentKitComponent(): any;
|
|
115
115
|
export declare function openDonationSettings(openInNewTab?: boolean): void;
|
|
116
116
|
export declare function getUserProfileLink(userDid: string, locale?: string): string;
|
|
117
|
+
export declare function parseMarkedText(text: string): Array<{
|
|
118
|
+
type: 'text' | 'marked';
|
|
119
|
+
content: string;
|
|
120
|
+
}>;
|
package/es/libs/util.js
CHANGED
|
@@ -933,3 +933,23 @@ export function getUserProfileLink(userDid, locale = "en") {
|
|
|
933
933
|
})
|
|
934
934
|
);
|
|
935
935
|
}
|
|
936
|
+
export function parseMarkedText(text) {
|
|
937
|
+
if (!text)
|
|
938
|
+
return [];
|
|
939
|
+
const parts = text.split(/(#([^#]*)#)/);
|
|
940
|
+
const result = [];
|
|
941
|
+
for (let i = 0; i < parts.length; i++) {
|
|
942
|
+
const part = parts[i];
|
|
943
|
+
if (!part)
|
|
944
|
+
continue;
|
|
945
|
+
if (i % 3 === 0) {
|
|
946
|
+
result.push({ type: "text", content: part });
|
|
947
|
+
} else if (i % 3 === 1 && part.startsWith("#") && part.endsWith("#")) {
|
|
948
|
+
const content = part.slice(1, -1);
|
|
949
|
+
if (content.length >= 0) {
|
|
950
|
+
result.push({ type: "marked", content });
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return result.filter((p) => p.content !== "");
|
|
955
|
+
}
|
package/es/payment/form/index.js
CHANGED
|
@@ -137,6 +137,11 @@ export default function PaymentForm({
|
|
|
137
137
|
setValue("customer_phone", session.user.phone);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
if (!session?.user) {
|
|
141
|
+
setValue("customer_name", "");
|
|
142
|
+
setValue("customer_email", "");
|
|
143
|
+
setValue("customer_phone", "");
|
|
144
|
+
}
|
|
140
145
|
}, [session?.user, getValues, setValue]);
|
|
141
146
|
useEffect(() => {
|
|
142
147
|
setValue("payment_method", currencies[paymentCurrencyIndex]?.method?.id);
|
|
@@ -8,7 +8,7 @@ import { useSetState } from "ahooks";
|
|
|
8
8
|
import { useEffect, useCallback } from "react";
|
|
9
9
|
import { useMobile } from "../../../hooks/mobile.js";
|
|
10
10
|
import LoadingButton from "../../../components/loading-button.js";
|
|
11
|
-
const { Elements, PaymentElement, useElements, useStripe, loadStripe } = globalThis.__STRIPE_COMPONENTS__;
|
|
11
|
+
const { Elements, PaymentElement, useElements, useStripe, loadStripe, LinkAuthenticationElement } = globalThis.__STRIPE_COMPONENTS__;
|
|
12
12
|
function StripeCheckoutForm({
|
|
13
13
|
clientSecret,
|
|
14
14
|
intentType,
|
|
@@ -90,10 +90,30 @@ function StripeCheckoutForm({
|
|
|
90
90
|
// eslint-disable-line
|
|
91
91
|
);
|
|
92
92
|
return /* @__PURE__ */ jsxs(Content, { onSubmit: handleSubmit, children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
LinkAuthenticationElement,
|
|
95
|
+
{
|
|
96
|
+
options: {
|
|
97
|
+
defaultEmail: customer.email
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
),
|
|
93
101
|
/* @__PURE__ */ jsx(
|
|
94
102
|
PaymentElement,
|
|
95
103
|
{
|
|
96
|
-
options: {
|
|
104
|
+
options: {
|
|
105
|
+
layout: "auto",
|
|
106
|
+
fields: { billingDetails: "never" },
|
|
107
|
+
readOnly: state.confirming,
|
|
108
|
+
defaultValues: {
|
|
109
|
+
billingDetails: {
|
|
110
|
+
name: customer.name,
|
|
111
|
+
phone: customer.phone,
|
|
112
|
+
email: customer.email,
|
|
113
|
+
address: customer.address
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
97
117
|
onReady: () => setState({ loaded: true })
|
|
98
118
|
}
|
|
99
119
|
),
|
|
@@ -170,17 +190,27 @@ export default function StripeCheckout({
|
|
|
170
190
|
minWidth: isMobile ? "100%" : "500px"
|
|
171
191
|
}
|
|
172
192
|
},
|
|
173
|
-
children: /* @__PURE__ */ jsx(
|
|
174
|
-
|
|
193
|
+
children: /* @__PURE__ */ jsx(
|
|
194
|
+
Elements,
|
|
175
195
|
{
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
196
|
+
options: {
|
|
197
|
+
clientSecret,
|
|
198
|
+
locale: locale === "zh" ? "zh-CN" : "en"
|
|
199
|
+
},
|
|
200
|
+
stripe: stripePromise,
|
|
201
|
+
children: /* @__PURE__ */ jsx(
|
|
202
|
+
StripeCheckoutForm,
|
|
203
|
+
{
|
|
204
|
+
clientSecret,
|
|
205
|
+
intentType,
|
|
206
|
+
mode,
|
|
207
|
+
customer,
|
|
208
|
+
onConfirm,
|
|
209
|
+
returnUrl
|
|
210
|
+
}
|
|
211
|
+
)
|
|
182
212
|
}
|
|
183
|
-
)
|
|
213
|
+
)
|
|
184
214
|
}
|
|
185
215
|
);
|
|
186
216
|
}
|
|
@@ -6,7 +6,8 @@ export default createLazyComponent(async () => {
|
|
|
6
6
|
PaymentElement: stripeReact.PaymentElement,
|
|
7
7
|
useElements: stripeReact.useElements,
|
|
8
8
|
useStripe: stripeReact.useStripe,
|
|
9
|
-
loadStripe: stripe.loadStripe
|
|
9
|
+
loadStripe: stripe.loadStripe,
|
|
10
|
+
LinkAuthenticationElement: stripeReact.LinkAuthenticationElement
|
|
10
11
|
};
|
|
11
12
|
const { default: Component } = await import("./form.js");
|
|
12
13
|
return Component;
|
package/es/theme/index.js
CHANGED
|
@@ -139,6 +139,11 @@ export function PaymentThemeProvider({
|
|
|
139
139
|
fontWeight: "500",
|
|
140
140
|
lineHeight: "24px"
|
|
141
141
|
},
|
|
142
|
+
".base-dialog": {
|
|
143
|
+
".MuiPaper-root>.MuiDialogContent-root": {
|
|
144
|
+
paddingTop: "0"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
142
147
|
a: {
|
|
143
148
|
textDecoration: "none !important"
|
|
144
149
|
}
|
package/lib/libs/util.d.ts
CHANGED
|
@@ -114,3 +114,7 @@ export declare function getInvoiceDescriptionAndReason(invoice: TInvoiceExpanded
|
|
|
114
114
|
export declare function getPaymentKitComponent(): any;
|
|
115
115
|
export declare function openDonationSettings(openInNewTab?: boolean): void;
|
|
116
116
|
export declare function getUserProfileLink(userDid: string, locale?: string): string;
|
|
117
|
+
export declare function parseMarkedText(text: string): Array<{
|
|
118
|
+
type: 'text' | 'marked';
|
|
119
|
+
content: string;
|
|
120
|
+
}>;
|
package/lib/libs/util.js
CHANGED
|
@@ -55,6 +55,7 @@ exports.isValidCountry = isValidCountry;
|
|
|
55
55
|
exports.lazyLoad = lazyLoad;
|
|
56
56
|
exports.mergeExtraParams = void 0;
|
|
57
57
|
exports.openDonationSettings = openDonationSettings;
|
|
58
|
+
exports.parseMarkedText = parseMarkedText;
|
|
58
59
|
exports.sleep = sleep;
|
|
59
60
|
exports.stopEvent = stopEvent;
|
|
60
61
|
exports.truncateText = truncateText;
|
|
@@ -1116,4 +1117,28 @@ function getUserProfileLink(userDid, locale = "en") {
|
|
|
1116
1117
|
locale,
|
|
1117
1118
|
did: userDid
|
|
1118
1119
|
}));
|
|
1120
|
+
}
|
|
1121
|
+
function parseMarkedText(text) {
|
|
1122
|
+
if (!text) return [];
|
|
1123
|
+
const parts = text.split(/(#([^#]*)#)/);
|
|
1124
|
+
const result = [];
|
|
1125
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1126
|
+
const part = parts[i];
|
|
1127
|
+
if (!part) continue;
|
|
1128
|
+
if (i % 3 === 0) {
|
|
1129
|
+
result.push({
|
|
1130
|
+
type: "text",
|
|
1131
|
+
content: part
|
|
1132
|
+
});
|
|
1133
|
+
} else if (i % 3 === 1 && part.startsWith("#") && part.endsWith("#")) {
|
|
1134
|
+
const content = part.slice(1, -1);
|
|
1135
|
+
if (content.length >= 0) {
|
|
1136
|
+
result.push({
|
|
1137
|
+
type: "marked",
|
|
1138
|
+
content
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return result.filter(p => p.content !== "");
|
|
1119
1144
|
}
|
|
@@ -156,6 +156,11 @@ function PaymentForm({
|
|
|
156
156
|
setValue("customer_phone", session.user.phone);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
if (!session?.user) {
|
|
160
|
+
setValue("customer_name", "");
|
|
161
|
+
setValue("customer_email", "");
|
|
162
|
+
setValue("customer_phone", "");
|
|
163
|
+
}
|
|
159
164
|
}, [session?.user, getValues, setValue]);
|
|
160
165
|
(0, _react.useEffect)(() => {
|
|
161
166
|
setValue("payment_method", currencies[paymentCurrencyIndex]?.method?.id);
|
|
@@ -20,7 +20,8 @@ const {
|
|
|
20
20
|
PaymentElement,
|
|
21
21
|
useElements,
|
|
22
22
|
useStripe,
|
|
23
|
-
loadStripe
|
|
23
|
+
loadStripe,
|
|
24
|
+
LinkAuthenticationElement
|
|
24
25
|
} = globalThis.__STRIPE_COMPONENTS__;
|
|
25
26
|
function StripeCheckoutForm({
|
|
26
27
|
clientSecret,
|
|
@@ -123,13 +124,25 @@ function StripeCheckoutForm({
|
|
|
123
124
|
|
|
124
125
|
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(Content, {
|
|
125
126
|
onSubmit: handleSubmit,
|
|
126
|
-
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(
|
|
127
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(LinkAuthenticationElement, {
|
|
128
|
+
options: {
|
|
129
|
+
defaultEmail: customer.email
|
|
130
|
+
}
|
|
131
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(PaymentElement, {
|
|
127
132
|
options: {
|
|
128
133
|
layout: "auto",
|
|
129
134
|
fields: {
|
|
130
135
|
billingDetails: "never"
|
|
131
136
|
},
|
|
132
|
-
readOnly: state.confirming
|
|
137
|
+
readOnly: state.confirming,
|
|
138
|
+
defaultValues: {
|
|
139
|
+
billingDetails: {
|
|
140
|
+
name: customer.name,
|
|
141
|
+
phone: customer.phone,
|
|
142
|
+
email: customer.email,
|
|
143
|
+
address: customer.address
|
|
144
|
+
}
|
|
145
|
+
}
|
|
133
146
|
},
|
|
134
147
|
onReady: () => setState({
|
|
135
148
|
loaded: true
|
|
@@ -12,7 +12,8 @@ module.exports = (0, _lazyLoader.createLazyComponent)(async () => {
|
|
|
12
12
|
PaymentElement: stripeReact.PaymentElement,
|
|
13
13
|
useElements: stripeReact.useElements,
|
|
14
14
|
useStripe: stripeReact.useStripe,
|
|
15
|
-
loadStripe: stripe.loadStripe
|
|
15
|
+
loadStripe: stripe.loadStripe,
|
|
16
|
+
LinkAuthenticationElement: stripeReact.LinkAuthenticationElement
|
|
16
17
|
};
|
|
17
18
|
const {
|
|
18
19
|
default: Component
|
package/lib/theme/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.15",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -53,15 +53,15 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@arcblock/did-connect": "^2.
|
|
57
|
-
"@arcblock/ux": "^2.
|
|
58
|
-
"@arcblock/ws": "^1.19.
|
|
59
|
-
"@blocklet/ui-react": "^2.
|
|
56
|
+
"@arcblock/did-connect": "^2.12.12",
|
|
57
|
+
"@arcblock/ux": "^2.12.12",
|
|
58
|
+
"@arcblock/ws": "^1.19.15",
|
|
59
|
+
"@blocklet/ui-react": "^2.12.12",
|
|
60
60
|
"@mui/icons-material": "^5.16.6",
|
|
61
61
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
62
62
|
"@mui/material": "^5.16.6",
|
|
63
63
|
"@mui/system": "^5.16.6",
|
|
64
|
-
"@ocap/util": "^1.19.
|
|
64
|
+
"@ocap/util": "^1.19.15",
|
|
65
65
|
"@stripe/react-stripe-js": "^2.7.3",
|
|
66
66
|
"@stripe/stripe-js": "^2.4.0",
|
|
67
67
|
"@vitejs/plugin-legacy": "^5.4.1",
|
|
@@ -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.15",
|
|
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": "fd58f00bb5d9c625439c03577d9b5f33676823e2"
|
|
127
127
|
}
|
package/src/libs/util.ts
CHANGED
|
@@ -1194,3 +1194,28 @@ export function getUserProfileLink(userDid: string, locale = 'en') {
|
|
|
1194
1194
|
})
|
|
1195
1195
|
);
|
|
1196
1196
|
}
|
|
1197
|
+
|
|
1198
|
+
export function parseMarkedText(text: string): Array<{
|
|
1199
|
+
type: 'text' | 'marked';
|
|
1200
|
+
content: string;
|
|
1201
|
+
}> {
|
|
1202
|
+
if (!text) return [];
|
|
1203
|
+
const parts = text.split(/(#([^#]*)#)/);
|
|
1204
|
+
const result: { type: 'text' | 'marked'; content: string }[] = [];
|
|
1205
|
+
|
|
1206
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1207
|
+
const part = parts[i];
|
|
1208
|
+
// eslint-disable-next-line no-continue
|
|
1209
|
+
if (!part) continue;
|
|
1210
|
+
if (i % 3 === 0) {
|
|
1211
|
+
result.push({ type: 'text', content: part });
|
|
1212
|
+
} else if (i % 3 === 1 && part.startsWith('#') && part.endsWith('#')) {
|
|
1213
|
+
const content = part.slice(1, -1);
|
|
1214
|
+
if (content.length >= 0) {
|
|
1215
|
+
result.push({ type: 'marked', content });
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
return result.filter((p) => p.content !== '');
|
|
1221
|
+
}
|
|
@@ -192,6 +192,11 @@ export default function PaymentForm({
|
|
|
192
192
|
setValue('customer_phone', session.user.phone);
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
+
if (!session?.user) {
|
|
196
|
+
setValue('customer_name', '');
|
|
197
|
+
setValue('customer_email', '');
|
|
198
|
+
setValue('customer_phone', '');
|
|
199
|
+
}
|
|
195
200
|
}, [session?.user, getValues, setValue]);
|
|
196
201
|
|
|
197
202
|
useEffect(() => {
|
|
@@ -9,7 +9,8 @@ import { useEffect, useCallback } from 'react';
|
|
|
9
9
|
import { useMobile } from '../../../hooks/mobile';
|
|
10
10
|
import LoadingButton from '../../../components/loading-button';
|
|
11
11
|
|
|
12
|
-
const { Elements, PaymentElement, useElements, useStripe, loadStripe } = (globalThis as any)
|
|
12
|
+
const { Elements, PaymentElement, useElements, useStripe, loadStripe, LinkAuthenticationElement } = (globalThis as any)
|
|
13
|
+
.__STRIPE_COMPONENTS__;
|
|
13
14
|
|
|
14
15
|
export type StripeCheckoutFormProps = {
|
|
15
16
|
clientSecret: string;
|
|
@@ -113,8 +114,25 @@ function StripeCheckoutForm({
|
|
|
113
114
|
|
|
114
115
|
return (
|
|
115
116
|
<Content onSubmit={handleSubmit}>
|
|
117
|
+
<LinkAuthenticationElement
|
|
118
|
+
options={{
|
|
119
|
+
defaultEmail: customer.email,
|
|
120
|
+
}}
|
|
121
|
+
/>
|
|
116
122
|
<PaymentElement
|
|
117
|
-
options={{
|
|
123
|
+
options={{
|
|
124
|
+
layout: 'auto',
|
|
125
|
+
fields: { billingDetails: 'never' },
|
|
126
|
+
readOnly: state.confirming,
|
|
127
|
+
defaultValues: {
|
|
128
|
+
billingDetails: {
|
|
129
|
+
name: customer.name,
|
|
130
|
+
phone: customer.phone,
|
|
131
|
+
email: customer.email,
|
|
132
|
+
address: customer.address,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
}}
|
|
118
136
|
onReady={() => setState({ loaded: true })}
|
|
119
137
|
/>
|
|
120
138
|
{(!stripe || !elements || !state.loaded) && (
|
|
@@ -208,7 +226,12 @@ export default function StripeCheckout({
|
|
|
208
226
|
minWidth: isMobile ? '100%' : '500px',
|
|
209
227
|
},
|
|
210
228
|
}}>
|
|
211
|
-
<Elements
|
|
229
|
+
<Elements
|
|
230
|
+
options={{
|
|
231
|
+
clientSecret,
|
|
232
|
+
locale: locale === 'zh' ? 'zh-CN' : 'en',
|
|
233
|
+
}}
|
|
234
|
+
stripe={stripePromise}>
|
|
212
235
|
<StripeCheckoutForm
|
|
213
236
|
clientSecret={clientSecret}
|
|
214
237
|
intentType={intentType}
|
|
@@ -6,6 +6,7 @@ declare global {
|
|
|
6
6
|
__STRIPE_COMPONENTS__?: {
|
|
7
7
|
Elements: any;
|
|
8
8
|
PaymentElement: any;
|
|
9
|
+
LinkAuthenticationElement: any;
|
|
9
10
|
useElements: () => any;
|
|
10
11
|
useStripe: () => any;
|
|
11
12
|
loadStripe: (key: string) => Promise<any>;
|
|
@@ -22,6 +23,7 @@ export default createLazyComponent<React.ComponentType<StripeCheckoutProps>, Str
|
|
|
22
23
|
useElements: stripeReact.useElements,
|
|
23
24
|
useStripe: stripeReact.useStripe,
|
|
24
25
|
loadStripe: stripe.loadStripe,
|
|
26
|
+
LinkAuthenticationElement: stripeReact.LinkAuthenticationElement,
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
const { default: Component } = await import('./form');
|
package/src/theme/index.tsx
CHANGED
|
@@ -150,6 +150,11 @@ export function PaymentThemeProvider({
|
|
|
150
150
|
fontWeight: '500',
|
|
151
151
|
lineHeight: '24px',
|
|
152
152
|
},
|
|
153
|
+
'.base-dialog': {
|
|
154
|
+
'.MuiPaper-root>.MuiDialogContent-root': {
|
|
155
|
+
paddingTop: '0',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
153
158
|
a: {
|
|
154
159
|
textDecoration: 'none !important',
|
|
155
160
|
},
|