stripe / stripe-react-native

React Native library for Stripe.
https://stripe.dev/stripe-react-native
MIT License
1.26k stars 263 forks source link

Expired API Key provided Error when executing presentPaymentSheet() #1661

Open fimbres opened 4 months ago

fimbres commented 4 months ago

Describe the bug When I open the payment sheet in my react native with expo app it opens with loading state, then it closes and an error appears saying: Expired API Key provided: ek_testYW*******r1xQ.

Fun fact 1: I don't know what does 'ek' at the start of the key even means, cause for example I think pk means public key or sk means secret key. And any of my current keys ends with 'r1xQ', so I don't know where that key came from.

Fun fact 2: It was working and suddenly after doing a couple changes in my implementation to change the appearance of the sheet. It began to crash.

To Reproduce Steps to reproduce the behavior:

  1. Build React Native App
  2. Implement the code here: https://docs.stripe.com/connect/direct-charges
  3. Open the sheet and maybe face the error.

Expected behavior be able to open the sheet again, and complete a payment.

Screenshots If applicable, add screenshots to help explain your problem.

Screenshot 2024-05-15 at 10 46 56 p m Screenshot 2024-05-15 at 10 47 23 p m

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

fimbres commented 4 months ago

Some Code:

const openPaymentSheet = async () => {
    const { error } = await presentPaymentSheet();

    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    } else {
      Alert.alert('Success', 'Your order is confirmed!');
    }
  };

  const initializePaymentSheet = async () => {
    setStatus('loading');

    const data = await createCheckout(userData?.stripeCustomerId!, userData?.stripeEphemeralKey!, totalPrice);

    const { error } = await initPaymentSheet({
      merchantDisplayName: "Paycon México",
      customerId: data?.customer,
      customerEphemeralKeySecret: data?.ephemeralKey,
      paymentIntentClientSecret: data?.paymentIntent!,
      allowsDelayedPaymentMethods: false,
      defaultBillingDetails: {
        name: userData?.name,
      },
      returnURL: 'paycon://home/checkout'
    });

    if (error) {
      setStatus('error');
    }
    else {
      setStatus('success');
    }
  };

  useEffect(() => {
    initializePaymentSheet();
  }, []);

<AppButton variant='primary' disabled={status === 'loading'} onPressIn={openPaymentSheet}>Realizar Compra</AppButton>