javascriptandroidpayment-request-apisecure-context

Use google's PaymentRequest on local site running in Android Emulator


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?


Solution

  • 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