Skip to content

Commit

Permalink
Google Play Billing Library: Update from v5.2.1 to v7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kus04e4ek committed Jun 13, 2024
1 parent a5a818f commit 9966100
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion GodotGooglePlayBilling.gdap
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ binary_type="local"
binary="GodotGooglePlayBilling.1.2.0.release.aar"

[dependencies]
remote=["com.android.billingclient:billing:5.2.1"]
remote=["com.android.billingclient:billing:7.0.0"]
2 changes: 1 addition & 1 deletion godot-google-play-billing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ android {

dependencies {
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'com.android.billingclient:billing:5.2.1'
implementation 'com.android.billingclient:billing:7.0.0'
compileOnly fileTree(dir: 'libs', include: ['godot-lib*.aar'])
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeParams;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.PriceChangeConfirmationListener;
import com.android.billingclient.api.PriceChangeFlowParams;
import com.android.billingclient.api.PendingPurchasesParams;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesResponseListener;
import com.android.billingclient.api.PurchasesUpdatedListener;
Expand All @@ -63,7 +62,7 @@
import java.util.List;
import java.util.Set;

public class GodotGooglePlayBilling extends GodotPlugin implements PurchasesUpdatedListener, BillingClientStateListener, PriceChangeConfirmationListener {
public class GodotGooglePlayBilling extends GodotPlugin implements PurchasesUpdatedListener, BillingClientStateListener {

private final BillingClient billingClient;
private final HashMap<String, SkuDetails> skuDetailsCache = new HashMap<>(); // sku → SkuDetails
Expand All @@ -74,9 +73,12 @@ public class GodotGooglePlayBilling extends GodotPlugin implements PurchasesUpda
public GodotGooglePlayBilling(Godot godot) {
super(godot);

PendingPurchasesParams pendingPurchasesParams =
PendingPurchasesParams.newBuilder().enableOneTimeProducts().build();

billingClient = BillingClient
.newBuilder(getActivity())
.enablePendingPurchases()
.enablePendingPurchases(pendingPurchasesParams)
.setListener(this)
.build();
calledStartConnection = false;
Expand Down Expand Up @@ -203,11 +205,6 @@ public Dictionary confirmPriceChange(String sku) {
}

SkuDetails skuDetails = skuDetailsCache.get(sku);

PriceChangeFlowParams priceChangeFlowParams =
PriceChangeFlowParams.newBuilder().setSkuDetails(skuDetails).build();

billingClient.launchPriceChangeConfirmationFlow(getActivity(), priceChangeFlowParams, this);

Dictionary returnValue = new Dictionary();
returnValue.put("status", 0); // OK = 0
Expand All @@ -216,14 +213,14 @@ public Dictionary confirmPriceChange(String sku) {
@UsedByGodot
public Dictionary purchase(String sku) {
return purchaseInternal("", sku,
BillingFlowParams.ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY);
BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.UNKNOWN_REPLACEMENT_MODE);
}
@UsedByGodot
public Dictionary updateSubscription(String oldToken, String sku, int prorationMode) {
return purchaseInternal(oldToken, sku, prorationMode);
public Dictionary updateSubscription(String oldToken, String sku, int replacementMode) {
return purchaseInternal(oldToken, sku, replacementMode);
}

private Dictionary purchaseInternal(String oldToken, String sku, int prorationMode) {
private Dictionary purchaseInternal(String oldToken, String sku, int replacementMode) {
if (!skuDetailsCache.containsKey(sku)) {
Dictionary returnValue = new Dictionary();
returnValue.put("status", 1); // FAILED = 1
Expand All @@ -241,11 +238,11 @@ private Dictionary purchaseInternal(String oldToken, String sku, int prorationMo
if (!obfuscatedProfileId.isEmpty()) {
purchaseParamsBuilder.setObfuscatedProfileId(obfuscatedProfileId);
}
if (!oldToken.isEmpty() && prorationMode != BillingFlowParams.ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY) {
if (!oldToken.isEmpty() && replacementMode != BillingFlowParams.SubscriptionUpdateParams.ReplacementMode.UNKNOWN_REPLACEMENT_MODE) {
BillingFlowParams.SubscriptionUpdateParams updateParams =
BillingFlowParams.SubscriptionUpdateParams.newBuilder()
.setOldSkuPurchaseToken(oldToken)
.setReplaceSkusProrationMode(prorationMode)
.setOldPurchaseToken(oldToken)
.setSubscriptionReplacementMode(replacementMode)
.build();
purchaseParamsBuilder.setSubscriptionUpdateParams(updateParams);
}
Expand Down Expand Up @@ -280,11 +277,6 @@ public void onPurchasesUpdated(final BillingResult billingResult, @Nullable fina
}
}

@Override
public void onPriceChangeConfirmationResult(BillingResult billingResult) {
emitSignal("price_change_acknowledged", billingResult.getResponseCode());
}

@Override
public void onMainResume() {
if (calledStartConnection) {
Expand Down

0 comments on commit 9966100

Please sign in to comment.