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.

PaymentSheet Crashing on Android in v.0.19.0

See original GitHub issue

Describe the bug In v0.19.0, on Android (13 and 10), presentPaymentSheet call crashes the app without any errors. After installing Sentry I see a IllegalStateException: ViewTreeLifecycleOwner not found

On iOS everything works perfectly.

To Reproduce I’m just following this Stripe Developers video about Accept a payment:

export default function TestPaymentScreen(props) {
	const [ready, setReady] = useState(false);
  const {initPaymentSheet, presentPaymentSheet, loading} = usePaymentSheet();

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

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

    const {error} = await initPaymentSheet({
      customerId: customer,
      customerEphemeralKeySecret: ephemeralKey,
      paymentIntentClientSecret: paymentIntent,
      merchantDisplayName: 'MyApp',
      allowsDelayedPaymentMethods: true,
      returnURL: 'stripe-example://stripe-redirect',
    });
    if (error) {
      Alert.alert(`Error codes: ${error.code}`, error.message);
    } else {
      setReady(true);
    }
  };

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

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

  async function buy() {
    const {error} = await presentPaymentSheet();

    if (error) {
      Alert.alert(`Error code: ${error.code}`, error.message);
    } else {
      Alert.alert('Success', 'The payment was confirmed successfully');
      setReady(false);
    }
  }

   /* ... */
}

When openPaymentSheet() is called pressing the button, the android app crashes without any error in the Metro server console. The Sentry dashboard shows:

IllegalStateException
ViewTreeLifecycleOwner not found from androidx.coordinatorlayout.widget.CoordinatorLayout{5876b97 V.E...... ......I. 0,0-0,0 #7f0800cf app:id/coordinator}

Expected behavior Payment sheet opening

Smartphone

  • Device: Pixel 4
  • OS: Android
  • Version 13

I attach the following files: android:app:build.gradle.txt android:build.gradle.txt package.json.txt

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:18

github_iconTop GitHub Comments

1reaction
charliecruzan-stripecommented, Dec 6, 2022

Awesome! Glad to hear it, hopefully that addresses it for the remainder of folks experiencing random payment sheet crashes in this issue. Thanks for posting here!

1reaction
charliecruzan-stripecommented, Dec 6, 2022

@Ace090 why do you have implementation(project(':stripe_stripe-react-native')) { exclude module: 'appcompat' } in your app/build.gradle?

If you can try to reproduce this in a blank project, that would be helpful. Otherwise, my I think this is specific to your project and could have to do with that

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 >
stripe_ios | Flutter Package - Pub.dev
Added Link support in Payment Sheet. ... Several fixes by the Stripe sdk v.0.19.0. ... Fix #416 ocassional crash on Android on the...
Read more >
Stripe React Native SDK - npm
The Stripe React Native SDK allows you to build delightful payment experiences in your native Android and iOS apps using React Native.
Read more >
stripe-react-native - bytemeta
PaymentSheet Crashing on Android in v. · Error in createPaymentMethod: Card details not complete (Android) · requiredShippingAddressFields postal address returns ...
Read more >
Stripe-payments - Bloglovin'
PaymentSheet Crashing on Android in v.0.19.0 · active questions tagged android - Stack Overflow. ·. 3d · In stripe-react-native v0.19.0, on Android (13...
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