JavaScript Authorize.net back button issue

Authorize.net doesn't like it when customers use the back button to make corrections after submitting a failed transaction.

You can prevent this by leveraging sessionStorage to track errors and reloading the page if the back button is pressed.

This example is specific to WooCommerce, but can be altered to suit any cart.
if (typeof Storage !== 'undefined') {
	if (location.href.indexOf('/store/checkout/pay/') !== -1 && location.href.indexOf('wc_error') !== -1) {

		window.sessionStorage.setItem('wooError', '1');
		
	}
	else if (location.href.indexOf('/store/checkout/pay/') !== -1 && location.href.indexOf('wc_error') === -1 && window.sessionStorage.getItem('wooError')) {
		
		// prevent back button to go back and correct credit card after error,  try to take them back to initial checkout page
		window.sessionStorage.removeItem('wooError');
		location.reload(true);
		
	}
}
Posted by
Snippet Viewed 1486 times.

Share your JavaScript code snippets:

  • Get some recognition & a link back to your site.
  • Create your own code library.
  • Help your fellow developers, as they have helped you.

 

Submit | Browse

Most Recent javascript snippets

Most Viewed