stripe-react-native: initPaymentSheet error

Describe the bug When using initPaymentSheet it always returns an error:

{code: "Failed", localizedMessage: "There was an unexpected error -- try again in a few seconds", message: "There was an unexpected error -- try again in a few seconds", declineCode: null, type: null, …}

Also getting the same error on presentPaymentSheet (if I use confirmPayment: false the Payment Sheet doesn’t open at all, if I don’t use it then it opens and closes automatically with the same error).

Using iOS, I haven’t tested this on Android.

My code:

Server

exports.paymentSheet = functions.https.onRequest(
  async (req, res) => {
  const customer = await stripe.customers.create();
  const ephemeralKey = await stripe.ephemeralKeys.create(
    {customer: customer.id},
    {apiVersion: '2020-08-27'}
  );
  const paymentIntent = await stripe.paymentIntents.create({
    amount: 1099,
    currency: 'usd',
    customer: customer.id,
  });
  res.json({
    paymentIntent: paymentIntent.client_secret,
    ephemeralKey: ephemeralKey.secret,
    customer: customer.id
  });
});

Client

  const fetchPaymentSheetParams = async () => {
    const response = await fetch(`${API_URL}/paymentSheet`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
    });
    const {paymentIntent, ephemeralKey, customer} = await response.json();

    return {
      paymentIntent,
      ephemeralKey,
      customer,
    };
  };

  const initializePaymentSheet = async () => {
    const {paymentIntent, ephemeralKey, customer} =
      await fetchPaymentSheetParams();

    const {error, paymentOption} = await initPaymentSheet({
      customerId: customer,
      customerEphemeralKeySecret: ephemeralKey,
      paymentIntentClientSecret: paymentIntent,
      customFlow: true,
      merchantDisplayName: 'Example Inc.',
      style: 'alwaysDark',
    });

    setLoading(false);
    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    }
    // updateButtons(paymentOption);
  };


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

Btw, this is a duplicate of #461 sorry couldn’t reopen the issue.

Versions

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18

Most upvoted comments

Hello,

I have the same issue using @stripe/stripe-react-native": “0.2.2”…

When I call the presentPaymentSheet, the modal disappears with this error message Error code: Failed There was an unexpected error -- try again in a few seconds

See the following video:

https://user-images.githubusercontent.com/8127893/137519765-7a90bae9-4e02-4844-9453-200736df04a7.mov

Any ideas?

Thanks!