#pavlos_unexpected

1 messages ¡ Page 1 of 1 (latest)

analog yokeBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1220335465241247798

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

warped pawnBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

vast jetty
#

Hi, let me help you with this.

vagrant horizon
#

I noticed that in What actually happened? section I added what I expected to happen. Just to confirm, in (4), if we haven't added a delay between (3) and (4), then the Stripe API may give us a pending payment intent status. When we do add a delay before calling (4), then the Stripe API returns us a succeeded status.

vast jetty
#

I would not recommend calling the API directly to get the PaymentIntent status. The standard approach is to use webhooks instead: https://docs.stripe.com/webhooks

vagrant horizon
#

Due to the nature of our product, we require this flow to be synchronous that way

vast jetty
#

Could you tell a bit more about this?

vagrant horizon
#

I'm sure the better way would be to add some kind of polling there, but I just wanted to make sure that this could be the case, that there are consistency issues if we call the API too quickly

#

before we go into possible alternative approaches

vast jetty
#

It's totally probable that the API might return outdated results if called to quickly, that's why Stripe provides webhooks.

#

Are you using Payment Element? At what point are you sending a request to the backend?

vagrant horizon
#

Let me check our client-side code and let you know

#

Be right back!

vast jetty
#

But backend business logic must always use webhooks - in case the customer closes the browser/app before your request to the backend is made. This way the purchase will be lost. Webhooks also employ various retry techniques to make sure you app gets the notification no matter what.

#

Sorry, you mentioned you use mobile SDK, my bad

vagrant horizon
#

This is our Android code:

private lateinit var paymentLauncher: PaymentLauncher

private fun onPaymentResult(paymentResult: PaymentResult) {
        when (paymentResult) {
            PaymentResult.Canceled -> {
                hideLoading()
            }

            PaymentResult.Completed -> {
                viewModel.handleOnPaymentResult()
            }

            is PaymentResult.Failed -> {
                hideLoading()
            }
        }
    }

fun handleOnPaymentResult() {
        // We already have a loader indicator visible

        getCredentialsCall { _, accessToken, idToken ->
            if (accessToken == null || idToken == null) {
                _eventShowOrHideLoadingDialog.value = false

                return@getCredentialsCall
            }

            viewModelScope.launch {
                // We added a 3000ms delay here
                
                val completeStripeDeferred = async {
                    repository.completeStripeForSubscription(
                        accessToken = accessToken,
                        idToken = idToken,
                        paymentIntentID = latestPaymentIntentID
                    )
                }

                val completeStripeResult = completeStripeDeferred.await()

                handleOnCompleteStripeForSubscriptionResult(
                    result = completeStripeResult
                )
            }
        }
    }
#

I see, webhooks would be the way to go, yes.

#

Until then, do you think 3 seconds delay is a safe amount of time?

vast jetty
vast jetty
vagrant horizon
#

I see, thank you.

#

We'll try updating to a more asynchronous flow using webhooks.

vast jetty
#

Happy to help.