Open phoglenix opened 3 years ago
Ye I have to say its REALLY painful at the moment, I am struggling even to just get the getDigitalGoodsService
API to show up despite doing all the chrome://flags AND origin trial dance :(
Using https://github.com/PEConn/beer as an example, it should just work if you serve it locally right?
Just an idea: would it be helpful if you could get a dummy Digital Goods service object where all the methods returned no data?
Re: https://github.com/PEConn/beer - no, it needs to be in a TWA context (installed from the Play store) to work with the Play payment method. The CrOS and Android backends rely on the Android bits to complete method calls.
The getDigitalGoodsService method should exist on any https site if you have the "Experimental Web Platform Features" flag on or if the site has a valid OT token.
The getDigitalGoodsService method should exist on any https site if you have the "Experimental Web Platform Features" flag on or if the site has a valid OT token.
So this is true ONLY if you are running in a TWA context?
So just for my understanding this means to test Digital Goods one must do the following:
Is all the above correct?
Then if you want to make another change and test you have to deploy your site to beer.com and reload the CrOS app, theres no way to test it locally, it MUST be published?
The getDigitalGoodsService method should exist on any https site if you have the "Experimental Web Platform Features" flag on in your browser or if the site has a valid OT token.
No other context/setup is required for the method to exist.
However, to actually get a valid Play DG service object when calling getDigitalGoodsService, you need a TWA context. I'm not sure it has to be a public site or a valid PWA, but it does need to be a TWA in the Play store.
No other context/setup is required for the method to exist.
I have followed the instructions exactly listed here: https://developer.chrome.com/docs/android/trusted-web-activity/receive-payments-play-billing/#on-a-chrome-os-device.
I am on the Dev channel of CrOS, I have enabled the flags and STILL no API.
I can only conclude that you MUST have the browser running in a TWA context for the API to show..
Edit: I just tried opening the console on https://google.com
and typing window.getDigitalGoodsService
and BOOM it shows. I flip back to my locally hosted beer url and I get undefined
.. Perhaps it only works in a https
context?
Yes, https + "Experimental Web Platform Features" flag are the requirements for the method to exist. But it won't return a Play-backed DG service instance unless you're in a TWA context. This could certainly be better documented. Feel free to file an issue or send a PR to improve that help article you linked (see the "Improve Article" link at the bottom).
If you have ideas about how debugging could be more clear in the API itself, please let me know here.
I think it would be nice if you could do something with the DevTools such as the integration you get with service workers:
I will submit a request to update that article
I have been struggling this for months now. The window.getDigitalGoodsService always appears as undefined. The App is already published on Google playstore with inApp products. [ app.wplms.io ].
@MrVibe this API is still in Origin Trial. You can test locally by enabling Chrome flags as mentioned in the chrome dev article or you can sign up for the DGAPI v2 origin trial and add the token on your site.
Yes using digital goods api v2 , also verified the token here : https://googlechrome.github.io/OriginTrials/check-token.html yes, it is working now. Thanks for help.
Hi we got this enabled but getting error "unsupported context" running this small snippet :
`const PAYMENT_METHOD = "https://play.google.com/billing"; async function getDetails(sku) {
try { if (window.getDigitalGoodsService) {
service = await window.getDigitalGoodsService(PAYMENT_METHOD); ERROR APPEARING HERE
} else {
console.log("window doesn't have getDigitalGoodsService."); } } catch (error) { console.log('err',error); DEBUG MESSAGE GIVING : "DOMException: unsupported context" } } getDetails('50_credits'); `
HOW to detect what might be wrong here ?
app published to playstore in beta tester.
Note for this issue: perhaps we can provide more fine-grained exception messages here?
"Unsupported context" means that something is wrong with your app (TWA) context. Either you're not in Android/CrOS (unlikely), or your TWA package isn't installed for the current URL, or you aren't running as an app (in an app window).
Yes this : or you aren't running as an app (in an app window). was the case in our app, the url bar was appearing in the app and we have not cofigured the assetslinks.json file properly . The key point was to clear up the chrome browser cache after configuring the assetslinks.json file.
Hello, I am trying to get this to work but getDigitalGoodsService is undefined even from within a TWA installed from google store internal tests. It doesn't appear in origin trials anymore so I assume this is not necessary. But it just won't work. Was this API deleted? Any research I do leads to stuff from 2022 or older...
It is still expected to work. You need to be on an HTTPS page on Android or ChromeOS for getDigitalGoodsService to be available.
You may want to enable chrome://flags/#enable-debug-for-store-billing
to bypass a check:
This flag removes the restriction that the TWA has to be installed from the app-store
A common piece of origin trial feedback is that the API is difficult to test/debug. It requires a deployed instance of the app to really see if things work. Ideally we could make this easier somehow.