@blocklet/payment-react 1.18.5 → 1.18.7
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/README.md +394 -341
- package/es/checkout/donate.d.ts +28 -4
- package/es/checkout/donate.js +5 -6
- package/es/components/loading-button.d.ts +10 -0
- package/es/components/loading-button.js +75 -0
- package/es/components/pricing-table.js +2 -3
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/payment/form/index.js +14 -12
- package/es/payment/form/stripe/form.js +19 -4
- package/es/payment/index.js +0 -1
- package/es/payment/summary.js +1 -1
- package/es/theme/index.js +2 -1
- package/lib/checkout/donate.d.ts +28 -4
- package/lib/checkout/donate.js +4 -7
- package/lib/components/loading-button.d.ts +10 -0
- package/lib/components/loading-button.js +86 -0
- package/lib/components/pricing-table.js +3 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -0
- package/lib/payment/form/index.js +14 -14
- package/lib/payment/form/stripe/form.js +24 -5
- package/lib/payment/index.js +0 -1
- package/lib/payment/summary.js +3 -3
- package/lib/theme/index.js +2 -1
- package/package.json +6 -6
- package/src/checkout/donate.tsx +33 -16
- package/src/components/loading-button.tsx +100 -0
- package/src/components/pricing-table.tsx +3 -3
- package/src/index.ts +2 -0
- package/src/payment/form/index.tsx +65 -60
- package/src/payment/form/stripe/form.tsx +20 -5
- package/src/payment/index.tsx +0 -1
- package/src/payment/summary.tsx +1 -1
- package/src/theme/index.tsx +1 -0
|
@@ -41,6 +41,7 @@ import PhoneInput from './phone';
|
|
|
41
41
|
import StripeCheckout from './stripe';
|
|
42
42
|
import { useMobile } from '../../hooks/mobile';
|
|
43
43
|
import { validatePhoneNumber } from '../../libs/phone-validator';
|
|
44
|
+
import LoadingButton from '../../components/loading-button';
|
|
44
45
|
|
|
45
46
|
export const waitForCheckoutComplete = async (sessionId: string) => {
|
|
46
47
|
let result: CheckoutContext;
|
|
@@ -212,7 +213,7 @@ export default function PaymentForm({
|
|
|
212
213
|
// }, [domSize, theme]);
|
|
213
214
|
|
|
214
215
|
const afterUserLoggedIn = useMemoizedFn(() => {
|
|
215
|
-
if (hasDidWallet(session.user)) {
|
|
216
|
+
if (hasDidWallet(session.user) || skipBindWallet) {
|
|
216
217
|
handleSubmit(onFormSubmit, onFormError)();
|
|
217
218
|
} else {
|
|
218
219
|
session.bindWallet(() => {
|
|
@@ -239,6 +240,9 @@ export default function PaymentForm({
|
|
|
239
240
|
|
|
240
241
|
const method = paymentMethods.find((x) => x.id === paymentMethod) as TPaymentMethodExpanded;
|
|
241
242
|
|
|
243
|
+
const showForm = session?.user;
|
|
244
|
+
const skipBindWallet = method.type === 'stripe';
|
|
245
|
+
|
|
242
246
|
const handleConnected = async () => {
|
|
243
247
|
try {
|
|
244
248
|
const result = await waitForCheckoutComplete(checkoutSession.id);
|
|
@@ -316,7 +320,7 @@ export default function PaymentForm({
|
|
|
316
320
|
action: checkoutSession.mode,
|
|
317
321
|
prefix: joinURL(getPrefix(), '/api/did'),
|
|
318
322
|
saveConnect: false,
|
|
319
|
-
extraParams: { checkoutSessionId: checkoutSession.id },
|
|
323
|
+
extraParams: { checkoutSessionId: checkoutSession.id, sessionUserDid: session?.user?.did },
|
|
320
324
|
onSuccess: async () => {
|
|
321
325
|
connect.close();
|
|
322
326
|
await handleConnected();
|
|
@@ -372,6 +376,10 @@ export default function PaymentForm({
|
|
|
372
376
|
errorRef.current.scrollIntoView({ behavior: 'smooth' });
|
|
373
377
|
}
|
|
374
378
|
if (session?.user) {
|
|
379
|
+
if (skipBindWallet) {
|
|
380
|
+
handleSubmit(onFormSubmit, onFormError)();
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
375
383
|
if (hasDidWallet(session.user)) {
|
|
376
384
|
handleSubmit(onFormSubmit, onFormError)();
|
|
377
385
|
} else {
|
|
@@ -492,56 +500,58 @@ export default function PaymentForm({
|
|
|
492
500
|
)}
|
|
493
501
|
</Stack>
|
|
494
502
|
</Fade>
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
503
|
+
{showForm && (
|
|
504
|
+
<Stack
|
|
505
|
+
direction="column"
|
|
506
|
+
className="cko-payment-form"
|
|
507
|
+
id="cko-payment-form"
|
|
508
|
+
spacing={0}
|
|
509
|
+
ref={!isEmpty(errors) ? (errorRef as any) : undefined}
|
|
510
|
+
sx={{ flex: 1, overflow: 'auto', py: 1 }}>
|
|
511
|
+
<FormLabel className="base-label">{t('payment.checkout.customer.name')}</FormLabel>
|
|
512
|
+
<FormInput
|
|
513
|
+
name="customer_name"
|
|
514
|
+
variant="outlined"
|
|
515
|
+
errorPosition="right"
|
|
516
|
+
rules={{
|
|
517
|
+
required: t('payment.checkout.required'),
|
|
518
|
+
}}
|
|
519
|
+
/>
|
|
520
|
+
<FormLabel className="base-label">{t('payment.checkout.customer.email')}</FormLabel>
|
|
521
|
+
<FormInput
|
|
522
|
+
name="customer_email"
|
|
523
|
+
variant="outlined"
|
|
524
|
+
errorPosition="right"
|
|
525
|
+
rules={{
|
|
526
|
+
required: t('payment.checkout.required'),
|
|
527
|
+
validate: (x) => (isEmail(x) ? true : t('payment.checkout.invalid')),
|
|
528
|
+
}}
|
|
529
|
+
/>
|
|
530
|
+
{checkoutSession.phone_number_collection?.enabled && (
|
|
531
|
+
<>
|
|
532
|
+
<FormLabel className="base-label">{t('payment.checkout.customer.phone')}</FormLabel>
|
|
533
|
+
<PhoneInput
|
|
534
|
+
name="customer_phone"
|
|
535
|
+
variant="outlined"
|
|
536
|
+
errorPosition="right"
|
|
537
|
+
placeholder="Phone number"
|
|
538
|
+
rules={{
|
|
539
|
+
required: t('payment.checkout.required'),
|
|
540
|
+
validate: async (x: string) => {
|
|
541
|
+
const isValid = await validatePhoneNumber(x);
|
|
542
|
+
return isValid ? true : t('payment.checkout.invalid');
|
|
543
|
+
},
|
|
544
|
+
}}
|
|
545
|
+
/>
|
|
546
|
+
</>
|
|
547
|
+
)}
|
|
548
|
+
<AddressForm
|
|
549
|
+
mode={checkoutSession.billing_address_collection as string}
|
|
550
|
+
stripe={method?.type === 'stripe'}
|
|
551
|
+
sx={{ marginTop: '0 !important' }}
|
|
552
|
+
/>
|
|
553
|
+
</Stack>
|
|
554
|
+
)}
|
|
545
555
|
</Stack>
|
|
546
556
|
</Fade>
|
|
547
557
|
<Divider sx={{ mt: 2.5, mb: 2.5 }} />
|
|
@@ -549,24 +559,19 @@ export default function PaymentForm({
|
|
|
549
559
|
<Fade in>
|
|
550
560
|
<Stack className="cko-payment-submit">
|
|
551
561
|
<Box className="cko-payment-submit-btn">
|
|
552
|
-
<
|
|
562
|
+
<LoadingButton
|
|
553
563
|
variant="contained"
|
|
554
564
|
color="primary"
|
|
555
565
|
size="large"
|
|
556
566
|
className="cko-submit-button"
|
|
557
567
|
onClick={() => {
|
|
558
|
-
if (state.submitting || state.paying) {
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
568
|
onAction();
|
|
562
569
|
}}
|
|
563
570
|
fullWidth
|
|
571
|
+
loading={state.submitting || state.paying}
|
|
564
572
|
disabled={state.stripePaying || !quantityInventoryStatus || !payable}>
|
|
565
|
-
{(state.submitting || state.paying) && (
|
|
566
|
-
<CircularProgress size={16} sx={{ mr: 0.5, color: 'var(--foregrounds-fg-on-color, #fff)' }} />
|
|
567
|
-
)}
|
|
568
573
|
{state.submitting || state.paying ? t('payment.checkout.processing') : buttonText}
|
|
569
|
-
</
|
|
574
|
+
</LoadingButton>
|
|
570
575
|
</Box>
|
|
571
576
|
|
|
572
577
|
{['subscription', 'setup'].includes(checkoutSession.mode) && (
|
|
@@ -2,11 +2,12 @@ import Center from '@arcblock/ux/lib/Center';
|
|
|
2
2
|
import Dialog from '@arcblock/ux/lib/Dialog';
|
|
3
3
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
4
|
import type { TCustomer } from '@blocklet/payment-types';
|
|
5
|
-
import { LoadingButton } from '@mui/lab';
|
|
6
5
|
import { CircularProgress, Typography } from '@mui/material';
|
|
7
6
|
import { styled } from '@mui/system';
|
|
8
7
|
import { useSetState } from 'ahooks';
|
|
9
8
|
import { useEffect, useCallback } from 'react';
|
|
9
|
+
import { useMobile } from '../../../hooks/mobile';
|
|
10
|
+
import LoadingButton from '../../../components/loading-button';
|
|
10
11
|
|
|
11
12
|
const { Elements, PaymentElement, useElements, useStripe, loadStripe } = (globalThis as any).__STRIPE_COMPONENTS__;
|
|
12
13
|
|
|
@@ -128,7 +129,6 @@ function StripeCheckoutForm({
|
|
|
128
129
|
type="submit"
|
|
129
130
|
disabled={state.confirming || !state.loaded}
|
|
130
131
|
loading={state.confirming}
|
|
131
|
-
loadingPosition="end"
|
|
132
132
|
variant="contained"
|
|
133
133
|
color="primary"
|
|
134
134
|
size="large">
|
|
@@ -171,7 +171,8 @@ export default function StripeCheckout({
|
|
|
171
171
|
returnUrl = '',
|
|
172
172
|
}: StripeCheckoutProps) {
|
|
173
173
|
const stripePromise = loadStripe(publicKey);
|
|
174
|
-
const {
|
|
174
|
+
const { isMobile } = useMobile();
|
|
175
|
+
const { t, locale } = useLocaleContext();
|
|
175
176
|
const [state, setState] = useSetState({
|
|
176
177
|
open: true,
|
|
177
178
|
closable: true,
|
|
@@ -192,8 +193,22 @@ export default function StripeCheckout({
|
|
|
192
193
|
showCloseButton={state.closable}
|
|
193
194
|
open={state.open}
|
|
194
195
|
onClose={handleClose}
|
|
195
|
-
disableEscapeKeyDown
|
|
196
|
-
|
|
196
|
+
disableEscapeKeyDown
|
|
197
|
+
sx={{
|
|
198
|
+
'.StripeElement': {
|
|
199
|
+
minWidth: isMobile ? '100%' : '500px',
|
|
200
|
+
py: 1,
|
|
201
|
+
},
|
|
202
|
+
form: {
|
|
203
|
+
justifyContent: 'flex-start',
|
|
204
|
+
},
|
|
205
|
+
}}
|
|
206
|
+
PaperProps={{
|
|
207
|
+
style: {
|
|
208
|
+
minWidth: isMobile ? '100%' : '500px',
|
|
209
|
+
},
|
|
210
|
+
}}>
|
|
211
|
+
<Elements options={{ clientSecret, locale: locale === 'zh' ? 'zh-CN' : 'en' }} stripe={stripePromise}>
|
|
197
212
|
<StripeCheckoutForm
|
|
198
213
|
clientSecret={clientSecret}
|
|
199
214
|
intentType={intentType}
|
package/src/payment/index.tsx
CHANGED
package/src/payment/summary.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
2
|
import type { DonationSettings, TLineItemExpanded, TPaymentCurrency } from '@blocklet/payment-types';
|
|
3
3
|
import { HelpOutline } from '@mui/icons-material';
|
|
4
|
-
import { LoadingButton } from '@mui/lab';
|
|
5
4
|
import { Box, Divider, Fade, Grow, Stack, Tooltip, Typography, Collapse, IconButton } from '@mui/material';
|
|
6
5
|
import type { IconButtonProps } from '@mui/material';
|
|
7
6
|
import { BN, fromTokenToUnit, fromUnitToToken } from '@ocap/util';
|
|
@@ -19,6 +18,7 @@ import ProductItem from './product-item';
|
|
|
19
18
|
import Livemode from '../components/livemode';
|
|
20
19
|
import { usePaymentContext } from '../contexts/payment';
|
|
21
20
|
import { useMobile } from '../hooks/mobile';
|
|
21
|
+
import LoadingButton from '../components/loading-button';
|
|
22
22
|
|
|
23
23
|
// const shake = keyframes`
|
|
24
24
|
// 0% {
|