I am trying to use the stripe SDK with React Native and I am only working with Android. I am getting this error here.
Invariant Violation: requireNativeComponent: "CardField" was not found in the UIManager.
I am not too sure if it's an error with the publishable_key since I see examples where you pass the key in the StripeProvider directly or if you have to fetch it from localhost like I am doing below.
Or is it the version of "@stripe/stripe-react-native": "^0.4.0".
Any help would be appreciated!
Here is where I initialize stripe into my app and wrap in a provider.
import React, { useState, useEffect } from 'react';
import { Provider } from 'react-redux';
import store from './src/services/redux/store';
import { ThemeProvider } from 'react-native-elements';
import { theme } from './src/utils/theme';
import StackNavigator from './src/navigation/StackNavigator';
import { StripeProvider } from '@stripe/stripe-react-native';
export const API_URL = 'http://10.0.2.2:4242';
async function fetchPublishableKey() {
  try {
    const response = await fetch(`${API_URL}/config`);
    const { publishableKey } = await response.json();
    return publishableKey;
  } catch (e) {
    console.log('no stripe ', e);
  }
}
const App = () => {
  const [publishableKey, setPublishableKey] = useState('');
  useEffect(() => {
    async function init() {
      const publishableKey = await fetchPublishableKey();
      if (publishableKey) {
        console.log(
          ' **************************  publishablekey ************************** ',
          publishableKey
        );
        setPublishableKey(publishableKey);
      }
    }
    init();
  });
  return (
    <StripeProvider publishableKey={publishableKey}>
      <Provider store={store}>
        <ThemeProvider theme={theme}>
          <StackNavigator />
        </ThemeProvider>
      </Provider>
    </StripeProvider>
  );
};
export default App;
Here is where I am using the CardField component where the error is coming from.
import React, { useState } from 'react';
import { View, Text, TextInput } from 'react-native';
import { CardField, CardFieldInput, useStripe } from '@stripe/stripe-react-native';
const PaymentInfo = () => {
  const [card, setCard] = useState('');
  return (
    <View>
      <Text>PaymentInfo</Text>
      <TextInput placeholder="stripe" style={{ backgroundColor: 'white' }} />
      <CardField
        postalCodeEnabled={true}
        placeholder={{
          number: '4242 4242 4242 4242',
        }}
        cardStyle={{
          backgroundColor: '#FFFFFF',
          textColor: '#000000',
        }}
        style={{
          width: '100%',
          height: 50,
          marginVertical: 30,
        }}
        onCardChange={(cardDetails) => {
          setCard(cardDetails as any);
        }}
        onFocus={(focusedField) => {
          console.log('focusField', focusedField);
        }}
      />
    </View>
  );
};
export default PaymentInfo;
 
                        
I solved this error by upgrading my api level to 31. I was on 30 before and that is why it couldnt find the CardField.
build.gradle