JackAppDev / flutter_iap

Flutter iap plugin
MIT License
100 stars 15 forks source link

Consuming product over mobile data network fails #40

Closed Lastmanstanding closed 5 years ago

Lastmanstanding commented 5 years ago

There is a consistent issue in our environment when running FlutterIap.buy over Mobile data network where it fails with error code 6 (BILLING_RESPONSE_RESULT_ERROR - Fatal error during the API action) when, seemingly, doing the auto-consume. The actual (first) purchase goes through fine, but subsequential purchases of same product thus fails with error code 7 (BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED). No exceptions are thrown. Running the same code over Wifi works fine, both consume/purchase.

We have not tried this with a different carrier, since the behaviour is still unexpected and thus need to be controlled in code. If it is just a carrier issue it would be good to have an exception thrown, and/or possibly the consume functionality exposed as part of package.

The tests are run on v1.2.3, android, with product android.test.purchased

A snippet code to produce this:

      List<String> productIds = ["android.test.purchased"];

      try {
        IAPResponse response = await FlutterIap.fetchProducts(productIds);
        productIds = response.products
            .map((IAPProduct product) => product.productIdentifier)
            .toList();

        IAPResponse purchased = await FlutterIap.fetchInventory();
        List<String> purchasedIds = purchased.purchases
            .map((IAPPurchase purchase) => purchase.productIdentifier)
            .toList();

        print("Already purchased: ${purchasedIds.join(',')}");

        iapResponse = await FlutterIap.buy(productIds[0]);
        print("New ${productIds[0]}: ${iapResponse.status}");

      } catch (e, s) {
        print('Tilted. Error: $e');
        print('Stack trace:\n $s');
      }

Have attached some of the output from 2 subsequentual purchases run over Wifi and then same over Mobile data. First over Wifi.txt Second over Wifi.txt First over Mobile data.txt Second over Mobile data.txt

Short summary of those:

First purchase using Wifi, gives:

...
E/Consuming(15080): android.test.purchased
I/flutter (15080): New android.test.purchased: loaded
D/BillingManager(15080): Destroying the manager.
D/InputEventReceiver(15080): channel 'cf3e46c <this.app.id>/com.android.billingclient.api.ProxyBillingActivity (client)' ~ Disposing input event receiver.
D/InputEventReceiver(15080): channel 'cf3e46c <this.app.id>/com.android.billingclient.api.ProxyBillingActivity (client)' ~NativeInputEventReceiver.
E/token   (15080): inapp:<this.app.id>:android.test.purchased
...

First purchase using Mobile data, gives:

...
E/Consuming(15080): android.test.purchased
I/flutter (15080): New android.test.purchased: loaded
D/BillingManager(15080): Destroying the manager.
D/InputEventReceiver(15080): channel '1cf6cd3 <this.app.id>/com.android.billingclient.api.ProxyBillingActivity (client)' ~ Disposing input event receiver.
D/InputEventReceiver(15080): channel '1cf6cd3 <this.app.id>/com.android.billingclient.api.ProxyBillingActivity (client)' ~NativeInputEventReceiver.
W/BillingClient(15080): Error consuming purchase with token. Response code: 6
W/BillingClient(15080): Error consuming purchase.
E/token   (15080): inapp:<this.app.id>:android.test.purchased
...

Second purchase using Mobile data, gives:

...
W/BillingClient(22044): Unable to buy item, Error response code: 7
W/BillingManager(22044): onPurchasesUpdated() got unknown resultCode: 7
...
Lastmanstanding commented 5 years ago

Auto-consume works now over mobile networks in our environment. We have upgraded to Flutter v0.8.2 but unclear if that had any impact. Could be whatever else. Anyway, there are some error handling requests attached in this issue, but I will still close this one.