Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close programatically a payment sheet #724

Closed
Liodene opened this issue Nov 16, 2021 · 17 comments · Fixed by #1287
Closed

Close programatically a payment sheet #724

Liodene opened this issue Nov 16, 2021 · 17 comments · Fixed by #1287
Labels
enhancement New feature or request

Comments

@Liodene
Copy link

Liodene commented Nov 16, 2021

Is your feature request related to a problem? Please describe.
We have a short term expiration on our cart for business reasons, so we just stop the purchase funnel when it expires.
The problem is that if the payment sheet is open and the cart expires, we have no way to close the payment sheet programatically.

Describe the solution you'd like
I'd like to have a function available to close any open payment sheet. We could get it either from the useStripe hook or in response or the presentPaymentSheet.

Describe alternatives you've considered
We tried to use a custom flow to be able to:

  1. Present the payment sheet and wait for the promise to return
  2. Once the promise return, check the expiration status
  3. If it's not expired, confirm with confirmPaymentSheet

The flow is less practical and a bit confusing for the user since the text displayed is about adding a card and not paying.
Moreover there are some issues inherent with the custom flow (#723) that prevents from using it at the moment.

Additional context
This feature request might relate to #447 but it's way more generic and doesn't concern only Apple Pay.

@YifanYes
Copy link

Is your feature request related to a problem? Please describe.
In our app, when you open the stripe payment screen, we register a transaction in our database. This transaccion after 10 minutes will be canceled for lack of activity. The problem is, the user can still pay in the stripe screen even after 10 minutes because the window has not been closed, creating a discrepancy where the user indeed have paid, but our database has recorder a canceled transaction. This problem is reported to us, as "I have paid, I have been charged, but there is no receipt and I have no orders".

Describe the solution you'd like
I'd like to have a way to close any open payment process after 10 minutes. A timeout. Right now I don't see any way of doing this, even after asking this question on the dev-help channel in the Stripe Developer Discord

Describe alternatives you've considered
I'm investigating a way of using webhooks from the Stripe API to solve this issue.

@shqear93
Copy link

shqear93 commented Jan 13, 2022

does anybody found a workaround?

@foloinfo
Copy link

foloinfo commented Feb 9, 2022

I have the same problem.

We block the reservation slot for few minues and cancel the payment intent from server when we could not confirm the payment has complete within the time.
It can prevent the payments without reservation but the user still can try to pay the amount, which is blocked by stripe server and receive the error.
We want to customize the the behaviour to show the error message in our app, not in the payment sheet in order to correctly navigate user for the next action.
Also the payment intent is already invalidated so there is no point keeping the payment sheet open anymore.

I would like to have closePaymentSheet function.

@ramonOrdering
Copy link

Hello @charliecruzan-stripe any news about this issue?

@Liodene were you able to solve it?

@shreypdev
Copy link

+1 on the issue

@ElSeniorMikael
Copy link

@charliecruzan-stripe since you closed my issue, could you at least give me some update on this request from 2021. That would be really nice to have some.

@charliecruzan-stripe
Copy link
Collaborator

I was taking a look into it today 🙂 to clarify, is there any use case anyone is looking for that does not include calling this function inside of a timeout?

What I'm wondering is if there's any situation that would not look something like:

setTimeout(async () => {
      // code to dismiss payment sheet
    }, <some amount of time>);

await presentPaymentSheet()

@ElSeniorMikael
Copy link

@charliecruzan-stripe , i will explains as much as i can my situation. I'm not quite sure i understand what you mean so i will give you my situation and hopefully it can help you.

We have limited products in our store and when we put it in our cart we have a reservation that is trigger. The customer have to purchase his products before the timer expire (15 minutes).

The way the pluggin work on our end, it send the qty of the product on hold in our wordpress backend and it clear it after 15 minutes.

That said, in our app when we put the item inside the cart, i start a timer of 900 seconds (15 minutes) with an interval that will make it drop to 0. Whenever that timer drop to zero there is a redux state that switch (isTimerExpired = true) so there is an useEffect that trigger a function, the product that the client hold get clear inside the app and in our backend and it is not assign to the customer anymore. So if someone else reserve it, the client end up by completing the payment and get 0 product to his order.

So if a customer open the stripe payment sheet and wait for his 15 minutes to pass for any reason (e.g: getting his CC, talking to someone or whatever the case). We need a way to close the payment sheet so the user cannot complete the payments without any products assign to his orders.

In my case, it would be trigger by a changing state, if that is possible.

@charliecruzan-stripe
Copy link
Collaborator

Thanks @ElSeniorMikael , so it sounds like your use case is also included in what I said above with setTimeout. I'm just wondering if there are any use cases by folks commenting here that are outside of that

@ElSeniorMikael
Copy link

@charliecruzan-stripe, one thing to keep in mind, i've realised this morning that Android get into background mode whenever stripe open. That said, it would mean that function coming from the app wouldn't trigger if stripe is open on the paymentSheets. In this case, if we can't trigger a function to close the Android. A timeout delay on the paymentSheets would be better in my opinion.

@charliecruzan-stripe
Copy link
Collaborator

charliecruzan-stripe commented Feb 6, 2023

Yep, that's what I was thinking as well so just trying to determine everyone's use cases here and see if that's a solution that works for all. Since we've buried it and i want to make sure people see it, I'm going to re-paste my question from earlier:

is there any use case anyone is looking for that does not include calling this function inside of a timeout?

What I'm wondering is if there's any situation that would not look something like:

setTimeout(async () => {
      // code to dismiss payment sheet
    }, <some amount of time>);

await presentPaymentSheet()

@ElSeniorMikael
Copy link

@charliecruzan-stripe Hello, i was wondering if you could provide us a time frame of when it could be available, that would be great :)

@charliecruzan-stripe
Copy link
Collaborator

@ElSeniorMikael released in v0.24.0

@ff-adrian-obando
Copy link

@ElSeniorMikael released in v0.24.0

Hello @charliecruzan-stripe, I just found this thread and first I wanted to thank you for the feature! is it possible to add UI to display the timeout? I think it will be good to have the option to give feedback to the user and let them know how much time is remaining before closing the payment sheet.

@charliecruzan-stripe
Copy link
Collaborator

@ff-adrian-obando I don't think that's something we'll be able to add to the payment sheet, sorry!

@mariamelsamni
Copy link

Hello @charliecruzan-stripe,

I had the same problem of mentioned above in this thread (the user has a certain duration to complete the payment before the reservation is rolled back), everything worked fine after I used the added timeout option to programmatically close the payment sheet, except for the case when I try to use the declined payment test cards, the payment sheet doesn't close after the specified period.

@ankit-ashutec
Copy link

@charliecruzan-stripe Can we have the same timeout option in the createPlatformPayPaymentMethod method as well? In my use case, users can pay using Google Pay or apple pay, and I want to close the payment intent if the user stays on the payment sheet for more than 5 or possibly 10 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.