getDigitalGoodsService("https://play.google.com/billing") always returning “DOMException: unsupported context” error
azabraao opened this issue · 2 comments
I have a working TWA on Play Store (website reference) that I’m trying to update for enabling it to handle google play digital goods payments. I’ve already implemented an in-app purchase using stripe. When I submitted a simple update to the app play store images it got rejected because they noticed the missing google in-app purchase that I didn’t know yet that was required. So I’m working now on implementing it.
What I’ve made:
- Updated my twa-manifest.json to include billing permissions. As the first step on this article by google:
...
"enableNotifications": true,
"features": {
"playBilling": {
"enabled": true
}
},
"alphaDependencies": {
"enabled": true
},
...
-
As I use Android Studio and not Bubblewrapp to build my app, I went to this other tutorial article And followed every step in it: (a) update build gradle, sync it. (b) Create DelegationService.java and reference it on AndroidManifest.xml (c) Added the service and the activity recommended by them, also to AndroidManifest.xml.
-
I made the app signed bundle release build and for quick testing, I’ve uploaded it to the play store internal testing
The problem:
I’ve used this generated testing link to download and install the new release on two devices: a Pixel 2 (Api 30) Emulator, and a Redmi Note 8 and as my target is to implement the play store digital goods api, I inspected the app from chrome://inspect/#devices and noticed that getDigitalGoodsService is enabled but fails when getting the Google Play Billing service:
if('getDigitalGoodsService' in window) {
const service = await getDigitalGoodsService("https://play.google.com/billing")
}
Which the getDigitalGoodsService fails with the error:
My hypothesis is that it isn’t working because the app is download from a testing link and not as a Play Store approved release.
Also, the URL bar is showing. But again my hypothesis to it is the same as above because I’ve made 0 changes to the digital asset links configuration that in the current production release is working fine on users' devices. But I wonder if this fact should give some explanation on why the getDigitalGoodsService fails.
Anyway, I hope I’m wrong on my hypothesis because it would mean that first I would need to release a version with the billing permissions which would be rejected because they will not see the implementation of google play billing, which is required to in-app purchases implementations. So as I don’t have an approved TWA release to debug and implement the billing, I would be stuck on the process. Unless of course, I’ve not yet noticed another way to solve it.
Any suggestions?
The URL bar showing is an indication that you are not in scope of the TWA (perhaps you haven't declared your origin correctly or signed using Digital Asset Links correctly?), which would be an unsupported context.
I'm not actually familiar with the TWA/Bubblewrap configuration. You may be better off filing bugs on the documentation sites that tell you how to set them up for DGAPI.
I was sure I had made the digital asset links configuration correctly, but you are right! I've made a better read on this doc and discovered that I didn't know that each release might have its own SHA 256 fingerprint and I could get it with the Asset Links Tool from Play Store.
Thank you so much @phoglenix 🎉
For those who might come here in the future. Remember to, using this Asset Links app verify the SHA 256 link, find and take your app configuration, and append it to your production assetlinks.json (on example.com/.well-known/assetlinks.json):
[
// ...your previous configuration
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
// your current testing asset links fingerprint took from the Asset Links app
}
}
]