@@ -3,27 +3,20 @@ import {loadStripe} from '@stripe/stripe-js';
3
3
import {
4
4
PaymentElement ,
5
5
useStripe ,
6
- CustomCheckoutProvider ,
7
- useCustomCheckout ,
6
+ CheckoutProvider ,
7
+ useCheckout ,
8
8
AddressElement ,
9
9
} from '../../src' ;
10
10
11
11
import '../styles/common.css' ;
12
12
13
- const CustomerDetails = ( ) => {
14
- const {
15
- phoneNumber,
16
- updatePhoneNumber,
17
- email,
18
- updateEmail,
19
- } = useCustomCheckout ( ) ;
20
-
13
+ const CustomerDetails = ( { phoneNumber, setPhoneNumber, email, setEmail} ) => {
21
14
const handlePhoneNumberChange = ( event ) => {
22
- updatePhoneNumber ( event . target . value ) ;
15
+ setPhoneNumber ( event . target . value ) ;
23
16
} ;
24
17
25
18
const handleEmailChange = ( event ) => {
26
- updateEmail ( event . target . value ) ;
19
+ setEmail ( event . target . value ) ;
27
20
} ;
28
21
29
22
return (
@@ -52,48 +45,53 @@ const CustomerDetails = () => {
52
45
} ;
53
46
54
47
const CheckoutForm = ( ) => {
55
- const customCheckout = useCustomCheckout ( ) ;
48
+ const checkout = useCheckout ( ) ;
56
49
const [ status , setStatus ] = React . useState ( ) ;
57
50
const [ loading , setLoading ] = React . useState ( false ) ;
58
51
const stripe = useStripe ( ) ;
52
+ const [ phoneNumber , setPhoneNumber ] = React . useState ( '' ) ;
53
+ const [ email , setEmail ] = React . useState ( '' ) ;
59
54
60
55
React . useEffect ( ( ) => {
61
- const { confirmationRequirements} = customCheckout || { } ;
56
+ const { confirmationRequirements} = checkout || { } ;
62
57
setStatus (
63
58
confirmationRequirements && confirmationRequirements . length > 0
64
59
? `Missing: ${ confirmationRequirements . join ( ', ' ) } `
65
60
: ''
66
61
) ;
67
- } , [ customCheckout , setStatus ] ) ;
62
+ } , [ checkout , setStatus ] ) ;
68
63
69
64
const handleSubmit = async ( event ) => {
70
65
event . preventDefault ( ) ;
71
66
72
- if ( ! stripe || ! customCheckout ) {
73
- return ;
74
- }
75
-
76
- const { canConfirm, confirm} = customCheckout ;
77
- if ( ! canConfirm ) {
67
+ if ( ! stripe || ! checkout ) {
78
68
return ;
79
69
}
80
70
81
71
try {
82
72
setLoading ( true ) ;
83
- await confirm ( { return_url : window . location . href } ) ;
73
+ await checkout . confirm ( {
74
+ email,
75
+ phoneNumber,
76
+ returnUrl : window . location . href ,
77
+ } ) ;
84
78
setLoading ( false ) ;
85
79
} catch ( err ) {
86
80
console . error ( err ) ;
87
81
setStatus ( err . message ) ;
88
82
}
89
83
} ;
90
84
91
- const buttonDisabled =
92
- ! stripe || ! customCheckout || ! customCheckout . canConfirm || loading ;
85
+ const buttonDisabled = ! stripe || ! checkout || loading ;
93
86
94
87
return (
95
88
< form onSubmit = { handleSubmit } >
96
- < CustomerDetails />
89
+ < CustomerDetails
90
+ email = { email }
91
+ setEmail = { setEmail }
92
+ phoneNumber = { phoneNumber }
93
+ setPhoneNumber = { setPhoneNumber }
94
+ />
97
95
< h3 > Payment Details</ h3 >
98
96
< PaymentElement />
99
97
< h3 > Billing Details</ h3 >
@@ -125,7 +123,7 @@ const App = () => {
125
123
e . preventDefault ( ) ;
126
124
setStripePromise (
127
125
loadStripe ( pk , {
128
- betas : [ 'custom_checkout_beta_1 ' ] ,
126
+ betas : [ 'custom_checkout_beta_5 ' ] ,
129
127
} )
130
128
) ;
131
129
} ;
@@ -171,12 +169,12 @@ const App = () => {
171
169
</ label >
172
170
</ form >
173
171
{ stripePromise && clientSecret && (
174
- < CustomCheckoutProvider
172
+ < CheckoutProvider
175
173
stripe = { stripePromise }
176
174
options = { { clientSecret, elementsOptions : { appearance : { theme} } } }
177
175
>
178
176
< CheckoutForm />
179
- </ CustomCheckoutProvider >
177
+ </ CheckoutProvider >
180
178
) }
181
179
</ >
182
180
) ;
0 commit comments