capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
MIT License
185 stars 75 forks source link

Closing the Google Pay payment sheet with the cancel button does not emit event or throw #276

Closed ottojaa closed 8 months ago

ottojaa commented 1 year ago

Platform

Describe the bug If the user presses the close button in the Google Pay interface, GooglePayEventsEnum.Canceled is not emitted nor is any error thrown. In my experience only the events GooglePayEventsEnum.Loaded and GooglePayEventsEnum.Completed work.

This bug seems to be present in the demo as well.

It should at the very least throw an unknown error: right now it appears that the Promise is never resolved or rejected

I have not tested with Apple Pay as I have not set it up yet, but this problem could be relevant to it as well.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'https://capacitor-community-stripe.netlify.app/tabs/demo'
  2. Click on 'Google Pay - create'
  3. Click on 'Google Pay - present'
  4. From the appearing modal, close the window.
  5. No cancel event is emitted nor error is thrown.

Expected behavior I expect an event to be emitted when user deliberately closes the Google Pay interface, either via the close button or clicking outside of the modal.

If resolving the Promise with a specific event is not possible, at least throw an error so async logic can complete. Code such as

const { paymentResult } = await stripe.presentGooglePay();

 if (paymentResult !== GooglePayEventsEnum.Completed) {
        throw new Error(ERROR_GOOGLE_PAY);
 }

Works fine when user enters their payment information correctly and does not cancel, but if they do cancel, the code will be stuck indefinitely awaiting presentGooglePay to resolve.

Listening to events such as

 stripe.addListener(GooglePayEventsEnum.Canceled, () => {
            console.log('Canceled')
 });

Does not work either, only Loaded / Completed seem to be emitted.

Screenshots

Additional context "@stripe-elements/stripe-elements": "2.0.2" "@capacitor-community/stripe": "^4.2.0" "react": "^18.2.0"

I use the useCapacitorStripe hook which works fine otherwise.

rdlabo commented 8 months ago

move https://github.com/wpkyoto/stripe-pwa-elements/issues/41