GoogleChrome / android-browser-helper

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.
Apache License 2.0
694 stars 288 forks source link

DigitalGoodsApi clientAppUnavailable rejection on service #411

Open brainfoolong opened 1 year ago

brainfoolong commented 1 year ago

I trying to integrate DigitalGoodsApi. All works fine until the point when calling any service function from the getDigitalGoodsService callback.

window.getDigitalGoodsService('https://play.google.com/billing').then((service) => {
    return service.getDetails(['test']);
})

This will throw DomException: clientAppUnavailable

service is however a proper instance of the goods API. Function getDetails, listPurchases and other's are available, but try to call any of them will throw the error.

Most of the source code bellow is generated directly from https://www.pwabuilder.com/.

Tried on Android API 24 and API 30 within emulator. Chrome version 110 on both API versions (So this should not require any origin trials anymore) CompileSDK Target is 33 (tried with 30 and 31 as well)

The counterpart delegation service is simple

public class DelegationService extends  com.google.androidbrowserhelper.trusted.DelegationService {
    @Override
    public void onCreate() {
        super.onCreate();
        registerExtraCommandHandler(new DigitalGoodsRequestHandler(getApplicationContext()));
    }
}

Gradle deps

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.androidbrowserhelper:billing:1.0.0-alpha09'
    implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.4.0'
}

Android Manifest contains

        <service
            android:name="DelegationService"
            android:enabled="@bool/enableNotification"
            android:exported="@bool/enableNotification">            
                <meta-data
                    android:name="android.support.customtabs.trusted.SMALL_ICON"
                    android:resource="@drawable/ic_notification_icon" />        
            <intent-filter>
                <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </service>
monstermac77 commented 1 year ago

We're having this exact error too. We get it while logged into some Google accounts but not others. Did you find a fix @brainfoolong?

brainfoolong commented 1 year ago

@monstermac77 No. Never had a working version of that. Ended up not using this API.

monstermac77 commented 1 year ago

@monstermac77 No. Never had a working version of that. Ended up not using this API.

Got it. What API did you end up using? Since we’re in the Play Store I figured we had to use this API so Google got their 30% cut. Is there another option?

brainfoolong commented 1 year ago

I guess it's not a topic for this issue. But in short: I know no alternative. In-App Payments in PWA in PlayStore is still a no-no today.

monstermac77 commented 1 year ago

I guess it's not a topic for this issue. But in short: I know no alternative. In-App Payments in PWA in PlayStore is still a no-no today.

I assume you mean that it should work, but there's so little support that it's broken and Google doesn't care enough to fix it? It seems pretty austere to promote the use of PWAs, force us to use In-App billing, and then not support the API.

monstermac77 commented 1 year ago

@brainfoolong Just wanted to follow-up on this since you seem to be the only active person discussing these issues.

We also have since been getting a lot of TypeError: Failed to construct 'PaymentRequest': required member details is undefined. Curious if you ran into that at all or have an idea of what the issue might be. The error is on var request = new PaymentRequest(paymentMethods); where paymentMethods is defined as:

const paymentMethods = [{
     supportedMethods: ["https://play.google.com/billing"],
     data: {
         sku: sku,
     },
}];

This is the full traceback

TypeError: Failed to construct 'PaymentRequest': required member details is undefined.   purchase.js?new1:165 
    at makePurchase (purchase.js:163)
    at HTMLDivElement.<anonymous> (purchase.js:293)
    at HTMLDocument.dispatch (jquery.min.js:5)
    at HTMLDocument.y.handle (jquery.min.js:5)

And purchase.js is: https://www.coursicle.com/all/pwa/js/purchase.js

priveeengineering commented 2 months ago

You require these two objects even if they're not used

   const paymentMethods = [{
        supportedMethods: "https://play.google.com/billing",
        data: {
            sku: product.id,
        }
    }]

    // The "total" member of the paymentDetails is required by the Payment
    // Request API, but is not used when using Google Play Billing. We can
    // set it up with bogus details.
    const paymentDetails = {
        total: {
            label: `Total`,
            amount: {currency: `USD`, value: `0`}
        }
    }

    const request = new PaymentRequest(paymentMethods, paymentDetails)
brainfoolong commented 2 months ago

@monstermac77 and @priveeengineering Your posts are off-topic and are not related to my initial issue. Please keep this issue clean and create a new issue with your specific problem, if required.