I have a vue.js application, I'm integrating a 3rd party payment provider support. The way it works is the UI sends a payment request to the backend, the backend processes it, sends a request to the PSP, and gets back a redirect url. The frontend then needs to redirect to this url where the user authenticates with the PSP.
Since the communication with the PSP is handled asynchronously on the backend, and I don't have two-way communication from backend to frontend, my frontend essentially needs to continuously poll the backend, asking "Do we have a redirect url yet?" over and over again.
My first naive approach was to display a component (through v-if, when the "intitialize payment" request returns OK) and in the component I have this:
mounted() {
setInterval(this.pollForRedirect, 1000);
}
I did this so I could proceed with development, but it seems rather crude. Is there a best practice way to do this? Perhaps something native to vue?
Should I be periodically increasing the polling interval, so that I'm not spamming the server if the processing is taking longer than expected? How do I stop the polling when the user gives up and navigates away form the component?