1

I'm trying to test out Google's PaymentRequest api on a local website running in my android emulator. However, when I do

var paymentRequest = window.PaymentRequest(//some object here//);

I get the following error

"Error: Failed to construct 'PaymentRequest': Must be in a secure context

Now, PaymentRequest DOES run on localhost and https, but running it from a port on an android emulator, where the uri is 10.2.2.01:8000/myUrlHere will fail becuase that's not localhost. Any ideas as to how to get around this?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
whatoncewaslost
  • 2,216
  • 2
  • 17
  • 25
  • what system are you running on? if its mac checkout this article http://brianflove.com/2014/12/02/enable-https-in-apache-on-mac-yosemite/ – kandroidj Jun 05 '17 at 15:57

2 Answers2

4

PaymentRequest must be used on secure context, which is one of:

  1. HTTPS.
  2. Localhost.
  3. Local file on disk.

http:// 10.2.2.01:8000 is not a secure context, so you can't use PaymentRequest there. Try one of the following:

  1. https: //10.2.2.01:8000. (The SSL certificate must be valid. This means the lock icon in the URL bar should be green. You can get one from https://letsencrypt.org/, for example.)
  2. https: //localhost:8000.
  3. file:///sdcard/index.html
  • 1
    Note that if using with Stripe, localhost isn't good enough - you need full green-checked https. (I've requested they disable this limitation and trust PaymentRequest's security decisions.) – Freewalker Mar 22 '18 at 15:09
2

If you own an Android device, there's a way to test your site by connecting the device via USB cable and serve from localhost. Try this:

https://developers.google.com/web/tools/chrome-devtools/remote-debugging/

If you don't, you may want to try this tool with the emulator:

https://ngrok.com/

ngrok allows you to serve from localhost proxying from ***.ngrok.com domain.

agektmr
  • 2,144
  • 15
  • 14