#pavlos_unexpected
1 messages ¡ Page 1 of 1 (latest)
đ 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.
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.
- pavlos_error, 19 hours ago, 68 messages
Hi, let me help you with this.
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.
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
Due to the nature of our product, we require this flow to be synchronous that way
Could you tell a bit more about this?
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
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?
Normally, if you're redirected after you confirm the payment, the redirect URL contains the PaymentIntent client_secret. You can use it to get the PI on the frontend: https://docs.stripe.com/js/payment_intents/retrieve_payment_intent
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
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?
Are you using deferred confirmation flow? You can also use this flow to confirm the PaymentIntent on the backend: https://docs.stripe.com/payments/finalize-payments-on-the-server?platform=android
I really can't say, it might depend on multiple factors, and then change the from one day to another.
I see, thank you.
We'll try updating to a more asynchronous flow using webhooks.
Happy to help.