3 ms·
A long time ago while implementing the checkout page for an e-commerce site that's written as single-page application, we run into problem where, if the user go
by kenrick95 4y ago
A long time ago while implementing the checkout page for an e-commerce site that's written as single-page application, we run into problem where, if the user goes to a 3rd party site to authorize payment method, we need to restore the checkout state. One approach that did not work for us is to store the state in session storage, because we do not know exactly when we should unset this state. The solution we took was to base64-serialize the state, gzip this (so that it does not exceed the browser's URL limit), and save it to the URL as query parameter. We used the History API to replace the URL whenever the local state changes, we write it there at URL. That way, if user goes to 3rd party site, we can specify the current full URL as the callback URL after the payment method is authorized.
A side effect of this is that if user decided to abandon our site at checkout page, they are able to go back using browser navigation with state fully restored.