Authorize.Net Unexpected token ! in JSON at position 0 hostedPaymentReturnOptions

When you configure the Authorize.Net Accept Hosted form, you might get the “Unexpected token ! in JSON at position 0” error b/c of malformed URL in the hostedPaymentReturnOptions parameter. To fix that I had to:

  1. Stop using “localhost” in the URLs. Apparently Authorize.Net doesn’t like that and throws an error.
  2. Escape ampersands with encodeURIComponent().
url.replace(/&/g, encodeURIComponent('&')

Leave a Comment