Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
COmpiling
  • Loading branch information
GaryQian committed Jul 7, 2022
commit 6823a7de0d6475fe2d6b20166155cf6b9e2914e4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package io.flutter.plugins.inapppurchase;

import static io.flutter.plugins.inapppurchase.Translator.fromPurchaseHistoryRecordList;
import static io.flutter.plugins.inapppurchase.Translator.fromPurchasesResult;
import static io.flutter.plugins.inapppurchase.Translator.fromPurchasesList;
import static io.flutter.plugins.inapppurchase.Translator.fromSkuDetailsList;

import android.app.Activity;
Expand All @@ -25,11 +25,14 @@
import com.android.billingclient.api.ConsumeParams;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.PriceChangeFlowParams;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchaseHistoryRecord;
import com.android.billingclient.api.PurchaseHistoryResponseListener;
import com.android.billingclient.api.PurchasesResponseListener;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsParams;
import com.android.billingclient.api.SkuDetailsResponseListener;
import com.android.billingclient.api.QueryPurchasesParams;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import java.util.HashMap;
Expand Down Expand Up @@ -153,7 +156,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
launchPriceChangeConfirmationFlow((String) call.argument("sku"), result);
break;
case InAppPurchasePlugin.MethodNames.GET_CONNECTION_STATE:
getConnectionState();
getConnectionState(result);
break;
default:
result.notImplemented();
Expand Down Expand Up @@ -256,7 +259,7 @@ private void launchBillingFlow(
BillingFlowParams.Builder paramsBuilder =
BillingFlowParams.newBuilder().setSkuDetails(skuDetails);
BillingFlowParams.SubscriptionUpdateParams.Builder subscriptionUpdateParamsBuilder =
BillingFlowParams.SubscriptionUpdateParams.Builder.newBuilder();
BillingFlowParams.SubscriptionUpdateParams.newBuilder();
if (accountId != null && !accountId.isEmpty()) {
paramsBuilder.setObfuscatedAccountId(accountId);
}
Expand Down Expand Up @@ -302,18 +305,22 @@ private void queryPurchasesAsync(String skuType, MethodChannel.Result result) {

// Like in our connect call, consider the billing client responding a "success" here regardless
// of status code.
billingClient.queryPurchaseHistoryAsync(
skuType,
QueryPurchasesParams.Builder paramsBuilder = QueryPurchasesParams.newBuilder();
paramsBuilder.setProductType(skuType);
billingClient.queryPurchasesAsync(
paramsBuilder.build(),
new PurchasesResponseListener() {
@Override
public void onQueryPurchasesResponse(
BillingResult billingResult, List<Purchase> purchasesList) {
final Map<String, Object> serialized = new HashMap<>();
serialized.put("billingResult", Translator.fromBillingResult(billingResult));
serialized.put(
"purchaseList", fromPurchaseList(purchasesList));
result.success(serialized);
}
@Override
public void onQueryPurchasesResponse(
BillingResult billingResult, List<Purchase> purchasesList) {
final Map<String, Object> serialized = new HashMap<>();
// The response code is no longer passed, as part of billing 4.1.0, so we pass OK here.
serialized.put("responseCode", BillingClient.BillingResponseCode.OK);
serialized.put("billingResult", Translator.fromBillingResult(billingResult));
serialized.put(
"purchaseList", fromPurchasesList(purchasesList));
result.success(serialized);
}
});
}

Expand All @@ -329,8 +336,6 @@ private void queryPurchaseHistoryAsync(String skuType, final MethodChannel.Resul
public void onPurchaseHistoryResponse(
BillingResult billingResult, List<PurchaseHistoryRecord> purchasesList) {
final Map<String, Object> serialized = new HashMap<>();
// The response code is no longer passed, as part of billing 4.1.0, so we pass OK here.
serialized.put("responseCode", BillingClient.BillingResponseCode.OK);
serialized.put("billingResult", Translator.fromBillingResult(billingResult));
serialized.put(
"purchaseHistoryRecordList", fromPurchaseHistoryRecordList(purchasesList));
Expand All @@ -339,7 +344,7 @@ public void onPurchaseHistoryResponse(
});
}

private void getConnectionState() {
private void getConnectionState(final MethodChannel.Result result) {
if (billingClientError(result)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.android.billingclient.api.AccountIdentifiers;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.Purchase.PurchasesResult;
import com.android.billingclient.api.PurchaseHistoryRecord;
import com.android.billingclient.api.SkuDetails;
import java.util.ArrayList;
Expand Down Expand Up @@ -63,7 +62,7 @@ static HashMap<String, Object> fromPurchase(Purchase purchase) {
info.put("purchaseToken", purchase.getPurchaseToken());
info.put("signature", purchase.getSignature());
if (!skus.isEmpty()) {
Copy link
Contributor

@cyanglaz cyanglaz Jul 6, 2022

Choose a reason for hiding this comment

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

Would it be easier to cleanup later if we put this logic to the dart side.
Then we don't have to cleanup the java code when we remove .sku.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes sense, I'll do that

info.put("sku", skus[0]);
info.put("sku", skus.get(0));
}
info.put("skus", skus);
info.put("isAutoRenewing", purchase.isAutoRenewing());
Expand All @@ -88,7 +87,7 @@ static HashMap<String, Object> fromPurchaseHistoryRecord(
info.put("purchaseToken", purchaseHistoryRecord.getPurchaseToken());
info.put("signature", purchaseHistoryRecord.getSignature());
if (!skus.isEmpty()) {
info.put("sku", skus[0]);
info.put("sku", skus.get(0));
}
info.put("skus", skus);
info.put("developerPayload", purchaseHistoryRecord.getDeveloperPayload());
Expand Down Expand Up @@ -122,14 +121,6 @@ static List<HashMap<String, Object>> fromPurchaseHistoryRecordList(
return serialized;
}

static HashMap<String, Object> fromPurchasesResult(PurchasesResult purchasesResult) {
HashMap<String, Object> info = new HashMap<>();
info.put("responseCode", purchasesResult.getResponseCode());
info.put("billingResult", fromBillingResult(purchasesResult.getBillingResult()));
info.put("purchasesList", fromPurchasesList(purchasesResult.getPurchasesList()));
return info;
}

static HashMap<String, Object> fromBillingResult(BillingResult billingResult) {
HashMap<String, Object> info = new HashMap<>();
info.put("responseCode", billingResult.getResponseCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ android {
defaultConfig {
applicationId project.APP_ID
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 30
versionCode project.VERSION_CODE
versionName project.VERSION_NAME
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -106,7 +106,7 @@ flutter {
}

dependencies {
implementation 'com.android.billingclient:billing:3.0.2'
implementation 'com.android.billingclient:billing:5.0.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.json:json:20180813'
Expand Down