Repository: flutter
Issue: [in_app_purchase] Failed and cancelled subscription purchases have empty product id on Android
Labels: platform-android,p: in_app_purchase,package,P2,team-android,triaged-android

## Steps to Reproduce

1. Run app with subscriptions on Android
2. Start purchase flow
3. Cancel flow - alternatively, complete purchase with "Test card, always declines"
4. Print out `PurchaseDetails.productID` from `InAppPurchase.instance.purchaseStream`

**Expected results:** Product id from failed purchase

**Actual results:** Empty string

<details>

```

Note: I adapted the code sample from #56222

<summary>Code sample</summary>

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:in_app_purchase/in_app_purchase.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text('Store'),
      ),
      body: Store(),
    ),
  );
}

class Store extends StatefulWidget {
  const Store({Key key}) : super(key: key);

  @override
  _StoreState createState() => _StoreState();
}

class _StoreState extends State<Store> {
  var _loading = true;
  var _products = <ProductDetails>[];
  var _purchases = <String, PurchaseDetails>{};
  StreamSubscription<List<PurchaseDetails>> _subscription;
  
  InAppPurchaseConnection get _iap => InAppPurchaseConnection.instance;

  @override
  void initState() {
    InAppPurchaseConnection.enablePendingPurchases();
    _subscription = _iap.purchaseUpdatedStream.listen(_processPurchases);
    _initialize();
    super.initState();
  }

  @override
  void dispose() {
    _subscription.cancel();
    super.dispose();
  }

  void _processPurchases(List<PurchaseDetails> purchases) {
    for (final purchase in purchases) {
      print('ID: ${purchase.productID}');     // This should never be empty or null
      print('STATUS: ${purchase.status}');
      
      setState(() {
        _purchases[purchase.productID] = purchase;
      });

      if (purchase.pendingCompletePurchase) _iap.completePurchase(purchase);
    }
  }

  Future<void> _initialize() async {
    final purchasesResponse = await _iap.queryPastPurchases();
    final productsResponse = await _iap.queryProductDetails(await _fetchIds());

    _processPurchases(purchasesResponse.pastPurchases);
    _products.addAll(productsResponse.productDetails);

    setState(() {
      _loading = false;
    });
  }

  Future<Set<String>> _fetchIds() async {
    return {/* ... */};
  }

  bool _isAvailable(ProductDetails product) =>
    !_purchases.containsKey(product.id)
      || _purchases[product.id].status == PurchaseStatus.error;

  @override
  Widget build(BuildContext context) => _loading ? Center(
    child: CircularProgressIndicator(),
  ) : Column(
    children: <Widget>[
      for (final product in _products) Card(
        child: Column(
          children: <Widget>[
            ListTile(
              title: Text(product.title),
              subtitle: Text(product.price),
            ),
            ButtonBar(
              children: <Widget>[
                FlatButton(
                  child: const Text('Buy'),
                  onPressed: _isAvailable(product) ? () {
                    _iap.buyConsumable(
                      purchaseParam: PurchaseParam(
                        productDetails: product,
                      ),
                      autoConsume: false
                    );
                  } : null,
                )
              ],
            )
          ],
        ),
      )
    ],
  );
}

```

</details>

<details>
<summary> flutter doctor </summary>


```
[✓] Flutter (Channel stable, 2.8.1, on Fedora Linux 35 (Workstation Edition)
    5.15.13-200.fc35.x86_64, locale en_US.UTF-8)
    • Flutter version 2.8.1 at /home/cachapa/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (5 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /home/cachapa/Android/Sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment 18.9 (build 11.0.13+8)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 13.0.0 (Fedora 13.0.0-3.fc35)
    • cmake version 3.22.1
    • ninja version 1.10.2
    • pkg-config version 1.8.0

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup
      for detailed instructions).

[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message
      below is not helpful, please let us know about this issue at
      https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
    • #0      _Utf8Decoder.convertSingle
      (dart:convert-patch/convert_patch.dart:1789:7)
      #1      Utf8Decoder.convert (dart:convert/utf.dart:318:42)
      #2      InputStream.readString
      (package:archive/src/util/input_stream.dart:207:30)
      #3      new ZipDirectory.read
      (package:archive/src/zip/zip_directory.dart:40:30)
      #4      ZipDecoder.decodeBuffer
      (package:archive/src/zip_decoder.dart:19:30)
      #5      ZipDecoder.decodeBytes
      (package:archive/src/zip_decoder.dart:14:12)
      #6      IntelliJPlugins._findPluginXml
      (package:flutter_tools/src/intellij/intellij.dart:130:44)
      #7      IntelliJPlugins._readPackageVersion
      (package:flutter_tools/src/intellij/intellij.dart:141:40)
      #8      IntelliJPlugins.validatePackage
      (package:flutter_tools/src/intellij/intellij.dart:63:35)
      #9      IntelliJValidator.validate
      (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
      #10     asyncGuard.<anonymous closure>
      (package:flutter_tools/src/base/async_guard.dart:111:32)
      #11     asyncGuard.<anonymous closure>
      (package:flutter_tools/src/base/async_guard.dart:109:18)
      #12     _rootRun (dart:async/zone.dart:1428:13)
      #13     _CustomZone.run (dart:async/zone.dart:1328:19)
      #14     _runZoned (dart:async/zone.dart:1863:10)
      #15     runZonedGuarded (dart:async/zone.dart:1851:12)
      #16     runZoned (dart:async/zone.dart:1782:12)
      #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
      #18     Doctor.startValidatorTasks
      (package:flutter_tools/src/doctor.dart:197:9)
      #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:301:47)
      #20     DoctorCommand.runCommand
      (package:flutter_tools/src/commands/doctor.dart:53:47)
      #21     FlutterCommand.verifyThenRunCommand
      (package:flutter_tools/src/runner/flutter_command.dart:1290:12)
      <asynchronous suspension>
      #22     FlutterCommand.run.<anonymous closure>
      (package:flutter_tools/src/runner/flutter_command.dart:1140:27)
      <asynchronous suspension>
      #23     AppContext.run.<anonymous closure>
      (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
      <asynchronous suspension>
      #25     FlutterCommandRunner.runCommand.<anonymous closure>
      (package:flutter_tools/src/runner/flutter_command_runner.dart:288:9)
      <asynchronous suspension>
      #26     AppContext.run.<anonymous closure>
      (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #27     FlutterCommandRunner.runCommand
      (package:flutter_tools/src/runner/flutter_command_runner.dart:236:5)
      <asynchronous suspension>
      #28     run.<anonymous closure>.<anonymous closure>
      (package:flutter_tools/runner.dart:62:9)
      <asynchronous suspension>
      #29     AppContext.run.<anonymous closure>
      (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #30     main (package:flutter_tools/executable.dart:94:3)
      <asynchronous suspension>


[✓] VS Code (version 1.63.0)
    • VS Code at /usr/share/code
    • Flutter extension version 3.29.0

[✓] Connected device (3 available)
    • MI PAD 4 (mobile) • 6392b510 • android-arm64  • Android 11 (API 30)
    • Linux (desktop)   • linux    • linux-x64      • Fedora Linux 35
      (Workstation Edition) 5.15.13-200.fc35.x86_64
    • Chrome (web)      • chrome   • web-javascript • Google Chrome 97.0.4692.71

! Doctor found issues in 2 categories.

```

</details>