Skip to content

Commit

Permalink
v0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir committed Jul 25, 2018
1 parent 4cf99a4 commit faf48b9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.2.3
* Fix on Android to queue up early requests prior billing client setup

## 0.2.2
* Fix on iOS to return price in cents ($1.99 = 199)

Expand Down
13 changes: 6 additions & 7 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ Version format is `v{major}.{minor}.{patch}`. e.g. `v0.1.1`.

1. Do `flutter analyze`. Ensure no issues found!
2. Update `pubsec.yaml` with new version.
3. Update `README.md` with new version.
4. Update `CHANGELOG.md` with new version and add details describing what's new and/or changed.
5. Do `git commit -am "{version}"`.
6. Do `git tag {version}`.
7. Do `flutter packages pub publish --dry-run`. Check to ensure there are no warnings!
8. Do `flutter packages pub publish` to publish new version.
9. Push changes `git push && git push --tags`
3. Update `CHANGELOG.md` with new version and add details describing what's new and/or changed.
4. Do `git commit -am "{version}"`.
5. Do `git tag {version}`.
6. Do `flutter packages pub publish --dry-run`. Check to ensure there are no warnings!
7. Do `flutter packages pub publish` to publish new version.
8. Push changes `git push && git push --tags`
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.SkuDetailsResponseListener;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -31,10 +33,15 @@
public final class BillingPlugin implements MethodCallHandler {
private final String TAG = BillingPlugin.class.getSimpleName();

private enum BillingServiceStatus {
IDLE, STARTING, READY
}

private final Activity activity;
private final BillingClient billingClient;
private final Map<String, Result> pendingPurchaseRequests;
private boolean billingServiceConnected;
private final Deque<Request> pendingRequests;
private BillingServiceStatus billingServiceStatus;

public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_billing");
Expand All @@ -45,6 +52,8 @@ private BillingPlugin(Activity activity) {
this.activity = activity;

pendingPurchaseRequests = new HashMap<>();
pendingRequests = new ArrayDeque<>();
billingServiceStatus = BillingServiceStatus.IDLE;

billingClient = BillingClient.newBuilder(activity)
.setListener(new BillingListener())
Expand All @@ -63,7 +72,7 @@ public void onActivityDestroyed(Activity activity) {
}
});

startServiceConnection(new Request() {
executeServiceRequest(new Request() {
@Override
public void execute() {
Log.d(TAG, "Billing service is ready.");
Expand Down Expand Up @@ -193,40 +202,45 @@ private void stopServiceConnection() {
Log.d(TAG, "Stopping billing service.");

billingClient.endConnection();

billingServiceConnected = false;
billingServiceStatus = BillingServiceStatus.IDLE;
}
}

private void startServiceConnection(final Request request) {
private void startServiceConnection() {
if (billingServiceStatus != BillingServiceStatus.IDLE) return;
billingServiceStatus = BillingServiceStatus.STARTING;
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
Log.d(TAG, "Billing service was setup with code " + billingResponseCode);

if (billingResponseCode == BillingResponse.OK) {
billingServiceConnected = true;
billingServiceStatus = billingResponseCode == BillingResponse.OK ? BillingServiceStatus.READY : BillingServiceStatus.IDLE;
Request request;

request.execute();
} else {
request.failed();
while ((request = pendingRequests.poll()) != null) {
if (billingServiceStatus == BillingServiceStatus.READY) {
request.execute();
} else {
request.failed();
}
}
}

@Override
public void onBillingServiceDisconnected() {
Log.d(TAG, "Billing service was disconnected!");

billingServiceConnected = false;
billingServiceStatus = BillingServiceStatus.IDLE;
}
});
}

private void executeServiceRequest(Request request) {
if (billingServiceConnected) {
if (billingServiceStatus == BillingServiceStatus.READY) {
request.execute();
} else {
startServiceConnection(request);
pendingRequests.add(request);
startServiceConnection();
}
}

Expand All @@ -252,6 +266,7 @@ public void onPurchasesUpdated(int resultCode, List<Purchase> purchases) {

interface Request {
void execute();

void failed();
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_billing
description: A flutter plugin to communicate with billing on iOS and Android.
version: 0.2.2
version: 0.2.3
author: Volodymyr Lykhonis <[email protected]>
homepage: https://github.com/VolodymyrLykhonis/flutter_billing

Expand Down

0 comments on commit faf48b9

Please sign in to comment.