@@ -28,31 +28,35 @@ export const CapacitorStripeProvider :FC<CapacitorStripeProviderProps> = ({
2828 const [ isApplePayAvailable , setApplePayAvailableStatus ] = useState ( false )
2929 const [ isGooglePayAvailable , setGooglePayAvailableStatus ] = useState ( false )
3030 useEffect ( ( ) => {
31- const prom = Capacitor . isNativePlatform ( ) ? Promise . resolve ( ) : defineCustomElements ( )
32- prom . then ( ( ) => {
33- if ( ! initializeOptions . publishableKey ) return
34- Stripe . initialize ( initializeOptions )
35- . then ( ( ) => {
36- return Stripe . isApplePayAvailable ( ) . then ( ( ) => {
37- setApplePayAvailableStatus ( true )
38- } ) . catch ( ( ) => {
39- setApplePayAvailableStatus ( false )
40- } )
41- } )
42- . then ( ( ) => {
43- return Stripe . isGooglePayAvailable ( ) . then ( ( ) => {
44- setGooglePayAvailableStatus ( true )
45- } ) . catch ( ( ) => {
46- setGooglePayAvailableStatus ( false )
47- } )
48- } )
49- . then ( ( ) => {
50- setStripe ( Stripe )
51- } )
52- } ) ;
31+ if ( ! Capacitor . isNativePlatform ( ) ) {
32+ defineCustomElements ( ) ;
33+ }
34+ if ( ! initializeOptions . publishableKey ) {
35+ throw new Error ( 'publishableKey must be needed' ) ;
36+ }
37+ Stripe . initialize ( initializeOptions )
38+ . then ( ( ) => {
39+ return Stripe . isApplePayAvailable ( ) . then ( ( ) => {
40+ setApplePayAvailableStatus ( true )
41+ } ) . catch ( ( ) => {
42+ setApplePayAvailableStatus ( false )
43+ } )
44+ } )
45+ . then ( ( ) => {
46+ return Stripe . isGooglePayAvailable ( ) . then ( ( ) => {
47+ setGooglePayAvailableStatus ( true )
48+ } ) . catch ( ( ) => {
49+ setGooglePayAvailableStatus ( false )
50+ } )
51+ } )
52+ . then ( ( ) => {
53+ setStripe ( Stripe )
54+ } )
5355 } , [ initializeOptions , setApplePayAvailableStatus ] )
5456 if ( ! stripe ) {
55- if ( fallback ) return < > { fallback } </ >
57+ if ( fallback ) {
58+ return < > { fallback } </ >
59+ }
5660 return null ;
5761 }
5862 return (
0 commit comments