question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`presentPaymentSheet` crashes the app in android

See original GitHub issue

Describe the bug The app crashes after calling presentPaymentSheet.

To Reproduce I followed the example in the integration guide here. My checkout page:

import React, { useState, useEffect } from "react";
import { useStripe } from '@stripe/stripe-react-native';
import useAPIError from '../../common/hooks/useAPIError';
import stripeSheet from '../../common/api/stripe';
import { Button, VStack, Text } from 'native-base';

export default function CheckoutScreen() {
  const { initPaymentSheet, presentPaymentSheet } = useStripe();
  const [loading, setLoading] = useState(false);
  const [apiIntent, setApiIntent] = useState('');
  const [apiCustomer, setApiCustomer] = useState('');
  const [apiEphemeralKey, setApiEphemeralKey] = useState('');
  // const [clientSecret, setClientSecret] = useState();
  const { addError } = useAPIError();

  const fetchPaymentSheetParams = async () => {
      try{
        const response = await stripeSheet(addError);
        const { paymentIntent, ephemeralKey, customer }  = response.result;
        console.log(paymentIntent);
        console.log(ephemeralKey);
        console.log(customer);
        setApiIntent(paymentIntent);
        setApiEphemeralKey(ephemeralKey);
        setApiCustomer(customer);
        return {
          paymentIntent,
          ephemeralKey,
          customer,
        };

      }catch(e){
          // TODO: handle error
          return {
            paymentIntent: null,
            ephemeralKey: null,
            customer: null,
          }
      }
  };

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

    const { error } = await initPaymentSheet({
      customerId: customer,
      customerEphemeralKeySecret: ephemeralKey,
      paymentIntentClientSecret: paymentIntent,

    });
    if (!error) {
      setLoading(true);
    }else{
    }
  };

  const openPaymentSheet = async () => {
    const { error } = await presentPaymentSheet(); // app crashes here
    if (error) {
      addError(`Error code: ${error.code}`, error.message);
    } else {
      addError('Success', 'Your order is confirmed!');
    }
  };

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

  return (
    <VStack>

      <Button colorScheme="primary" onPress={initializePaymentSheet}>Retry</Button>
      <Text>Disabled is {(!loading) + ''}</Text>
      <Text>intent is {apiIntent}</Text>
      <Text>customer is {apiCustomer}</Text>
      <Text>ephemeralKey is {apiEphemeralKey}</Text>
      <Button
        colorScheme="primary"
        disabled={!loading}
        onPress={openPaymentSheet}
      >Checkout</Button>

    </VStack>
  );
}

Screenshots

Screenshot_20211004-105834

Smartphone (please complete the following information):

  • Device: Android Huawei GR3 2017
  • OS: Android 8.0

Additional context Developing app with expo and using nativebase for UI (I tried pure react native UI but the issue is still there).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
obayitcommented, Oct 4, 2021

Thanks, I solved the issue by downgrading the package to 0.1.4 with:

yarn upgrade @stripe/stripe-react-native@0.1.4

Then adding these missing args to initPaymentSheet:

      customFlow: false,
      merchantDisplayName: 'Example Inc.',
      style: 'alwaysDark',
1reaction
arekkubaczkowskicommented, Oct 4, 2021

Expo does support the older version of this library (0.1.4), this means that there are differences in initializing the PaymentSheet. Please follow our example which points to this specific version: https://github.com/stripe/stripe-react-native/blob/v0.1.4/example/src/screens/PaymentsUICompleteScreen.tsx

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - PaymentSheet Crashing on Android in v.0.19.0
In stripe-react-native v0.19.0, on Android (13 and 10), presentPaymentSheet call crashes the app without any errors.
Read more >
Detect and diagnose crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Accept a payment | Stripe Documentation
Securely accept payments online.
Read more >
App Center Crashes for React Native - Microsoft Learn
App Center Crashes will automatically generate a crash log every time your app crashes. The log is first written to the device's storage...
Read more >
Stripe payment integration React Native. calling ...
Coding example for the question Stripe payment integration React Native. calling presentPaymentSheet function leads to app crash-React Native.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found