diff --git a/class-rcp-payment-gateway-stripe-elements.php b/class-rcp-payment-gateway-stripe-elements.php index 7c34fff..65cc2ab 100644 --- a/class-rcp-payment-gateway-stripe-elements.php +++ b/class-rcp-payment-gateway-stripe-elements.php @@ -90,18 +90,26 @@ public function fields() { function stripeTokenHandler( token ) { var form, hiddenInput; - // Insert the token ID into the form so it gets submitted to the server - form = document.getElementById( form_id ); - hiddenInput = document.createElement( 'input' ); - - // Assign attributes to hidden field - hiddenInput.setAttribute( 'type', 'hidden' ); - hiddenInput.setAttribute( 'name', 'stripeToken' ); - hiddenInput.setAttribute( 'value', token.id ); - hiddenInput.setAttribute( 'id', 'stripeToken' ); - - form.appendChild( hiddenInput ); - form.submit(); + // Use token if already present, work around for better Chrome support during redirects + if ( document.getElementById( 'stripeToken' ) ) { + hiddenInput = document.getElementById( 'stripeToken' ); + + // If token isn't present in DOM, create new one and submit form + } else { + hiddenInput = document.createElement( 'input' ); + + // Append the token form field into the form with applicable attributes + form = document.getElementById( form_id ); + + // Assign attributes to hidden field + hiddenInput.setAttribute( 'type', 'hidden' ); + hiddenInput.setAttribute( 'name', 'stripeToken' ); + hiddenInput.setAttribute( 'value', token.id ); + hiddenInput.setAttribute( 'id', 'stripeToken' ); + + form.appendChild( hiddenInput ); + form.submit(); + } } // Attempts the creation of a Stripe Token