Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@SynSzakala
Copy link
Contributor

@SynSzakala SynSzakala commented Aug 24, 2022

This PR adds management of BillingClient connection to Android implementation of InAppPurchase. This should fix issues caused by lost connections.

New and previously existing connection management is extracted to a new component, BillingClientManager.
This component is exported in billing_client_wrappers.dart, so that it can also be used when interacting with BillingClient directly.

Fixes flutter/flutter#110663

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@SynSzakala SynSzakala changed the title Draft: Fix in app purchase android billing client reconnect [in_app_purchase_android] Implement BillingClient connection management and introduce BillingClientManager Aug 31, 2022
@SynSzakala SynSzakala marked this pull request as ready for review August 31, 2022 15:17
@SynSzakala SynSzakala requested a review from GaryQian as a code owner August 31, 2022 15:17
@stuartmorgan-g stuartmorgan-g self-requested a review September 1, 2022 20:05
@dgjamaster
Copy link

I look forward to this PR being merged.
Thanks!!

@stuartmorgan-g
Copy link
Contributor

@GaryQian Ping on this review.

@@ -0,0 +1,147 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should document in BillingClient the drawbacks of using the BillingClient class directly and point them to the newly recommended way of handling operations using this new BillingClientManager class.

return await block(client);
}

/// Ends connection to the [BillingClient].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document when/under what conditions dispose should be called.

const String kInvalidBillingResultErrorMessage =
'Invalid billing result map from method channel.';

/// Abstraction of result of [BillingClient] operation that includes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class in the correct file? I expected this to live in the billing_client_manager.dart file.

return purchaseDetails;
}

final InAppPurchaseAndroidPlatformAddition addition =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unnecessary refactors


/// [BillingClient] instance managed by this [BillingClientManager].
///
/// This field should not be accessed outside of test code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is redundant as @VisibleForTesting will enforce preventing its usage outside of tests.

…econnect

# Conflicts:
#	packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
#	packages/in_app_purchase/in_app_purchase_android/pubspec.yaml
@SynSzakala SynSzakala requested review from GaryQian and removed request for stuartmorgan-g October 4, 2022 09:34
test('connects on initialization', () {
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(1));
});
test('waits for connection before executing the operations', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between tests

expect(runCalled, equals(true));
expect(runRawCalled, equals(true));
});
test('re-connects when client sends onBillingServiceDisconnected', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between tests

);
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(2));
});
test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between tests

expect(result.responseCode, equals(BillingResponse.ok));
},
);
test('does not re-connect when disposed', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between tests

);
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(2));
});
test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between tests

//await iapAndroidPlatform.isAvailable();
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(1));
});
test('re-connects when client sends onBillingServiceDisconnected', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between tests

import 'package:json_annotation/json_annotation.dart';

import 'billing_client_wrapper.dart';
import '../../billing_client_wrappers.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer directly importing billing_client_manager.dart over the export file which contains extraneous imports.

@GaryQian
Copy link
Contributor

GaryQian commented Oct 6, 2022

@SynSzakala Overall looks good, just a few small nits. Let me know when you address them!

@SynSzakala SynSzakala requested a review from GaryQian October 15, 2022 15:38
@SynSzakala SynSzakala force-pushed the fix_in_app_purchase_android_billing_client_reconnect branch from c9d6bfe to 51bb55a Compare October 15, 2022 15:43
@GaryQian
Copy link
Contributor

@SynSzakala It looks like there are some CLA signing issues where your secondary email needs to accept the CLA, or you can amend the commit that used your alternate email address and force-push.

Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for your contribution. Once you address the CLA issue, we can move forwards.

@SynSzakala SynSzakala force-pushed the fix_in_app_purchase_android_billing_client_reconnect branch from 51bb55a to 213ec8a Compare November 2, 2022 16:17
@SynSzakala
Copy link
Contributor Author

@GaryQian Everything should be ready for merge now.

@stuartmorgan-g stuartmorgan-g self-requested a review November 4, 2022 14:55
@olof-dev
Copy link

Thanks for this PR! The issue with lost connections leading to refunded purchases is hitting us pretty hard in production, so this is much appreciated.

@SynSzakala
Copy link
Contributor Author

SynSzakala commented Nov 23, 2022

@stuartmorgan @GaryQian Is there anything preventing us from merging this?

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SynSzakala Could you address all of the open comments from @GaryQian's review, and fix the analysis issues that are causing repo_checks to fail?

Once that's done I can approve this for landing.


Future<List<PurchaseDetails>> _getPurchaseDetailsFromResult(
PurchasesResultWrapper resultWrapper) async {
PurchasesResultWrapper resultWrapper,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you added commas everywhere? Changing formatting of lines that you aren't otherwise changing makes the diff (and git blame) more confusing.

@GaryQian
Copy link
Contributor

GaryQian commented Jan 5, 2023

@SynSzakala When you get a chance to fix the failing analyzer checks, we can move forwards with this. Thanks!

@olof-dev
Copy link

@SynSzakala It looks like the analyzer complaints are just warnings to do with 4 unneeded awaits. I was gonna send you a PR that deletes them, but I realized that there might then be CLA-type stuff to deal with. In any case, thanks again for this PR - it's substantial!

@SynSzakala
Copy link
Contributor Author

@GaryQian @stuartmorgan Cleared all comments (including unnecessary refactors), fixed analyzer issues. Looking forward to merge this!

…ndroid_billing_client_reconnect

# Conflicts:
#	packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md
@SynSzakala SynSzakala force-pushed the fix_in_app_purchase_android_billing_client_reconnect branch from aa02afc to 6bc41e0 Compare February 3, 2023 11:42
Copy link
Contributor

@GaryQian GaryQian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@SynSzakala
Copy link
Contributor Author

@stuartmorgan @GaryQian Are there any additional steps needed to merge this? I don't have the access to add "autosubmit" label as suggested in Tree Hygiene

@stuartmorgan-g
Copy link
Contributor

Are there any additional steps needed to merge this?

This needs a second review, per https://github.com/flutter/flutter/wiki/Tree-hygiene#getting-a-code-review

@bparrishMines Could you do the second review here, as the ecosystem-side codeowner for this plugin?

@stuartmorgan-g
Copy link
Contributor

We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages.

Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord.

Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[in_app_purchase][android] BillingClient connection is not restored after it's lost

5 participants