Skip to content

Commit eb2971c

Browse files
authored
Updating to google billing client 8.0.0 (#274)
* Updating android billing client version to 8.0.0 * Updating google billing class with new library. * Use java 8 instead of java 7. * Using new google billing client params.
1 parent f8508d6 commit eb2971c

3 files changed

Lines changed: 28 additions & 15 deletions

File tree

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ allprojects {
104104
tasks.withType(Sign) {
105105
onlyIf { isReleaseBuild() }
106106
}
107+
108+
tasks.withType(JavaCompile) {
109+
sourceCompatibility = JavaVersion.VERSION_1_8
110+
targetCompatibility = JavaVersion.VERSION_1_8
111+
}
107112
}
108113

109114
if (JavaVersion.current().isJava8Compatible()) {
@@ -112,4 +117,4 @@ if (JavaVersion.current().isJava8Compatible()) {
112117
options.addStringOption('Xdoclint:none', '-quiet')
113118
}
114119
}
115-
}
120+
}

gdx-pay-android-googlebilling/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ configurations {
3737

3838
dependencies {
3939
api project(':gdx-pay-client')
40-
api "com.android.billingclient:billing:6.0.1"
40+
api "com.android.billingclient:billing:8.0.0"
4141

4242
testImplementation libraries.junit
4343
}

gdx-pay-android-googlebilling/src/com/badlogic/gdx/pay/android/googlebilling/PurchaseManagerGoogleBilling.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.Activity;
44
import android.os.Handler;
55
import android.os.Looper;
6+
import androidx.annotation.NonNull;
67
import com.android.billingclient.api.*;
78
import com.android.billingclient.api.BillingClient.ProductType;
89
import com.badlogic.gdx.Gdx;
@@ -44,8 +45,15 @@ public class PurchaseManagerGoogleBilling implements PurchaseManager, PurchasesU
4445

4546
public PurchaseManagerGoogleBilling(Activity activity) {
4647
this.activity = activity;
47-
mBillingClient = BillingClient.newBuilder(activity).setListener(this)
48-
.enablePendingPurchases().build();
48+
PendingPurchasesParams params = PendingPurchasesParams.newBuilder()
49+
.enableOneTimeProducts()
50+
.enablePrepaidPlans()
51+
.build();
52+
53+
mBillingClient = BillingClient.newBuilder(activity)
54+
.setListener(this)
55+
.enablePendingPurchases(params)
56+
.build();
4957
}
5058

5159
@Override
@@ -155,7 +163,8 @@ private void fetchOfferDetails() {
155163
mBillingClient.queryProductDetailsAsync(
156164
params,
157165
new ProductDetailsResponseListener() {
158-
public void onProductDetailsResponse(@Nonnull BillingResult billingResult, @Nonnull List<ProductDetails> productDetailsList) {
166+
@Override
167+
public void onProductDetailsResponse(@NonNull BillingResult billingResult, @NonNull QueryProductDetailsResult productDetailsResult) {
159168
int responseCode = billingResult.getResponseCode();
160169
// it might happen that this was already disposed until the response comes back
161170
if (observer == null || Gdx.app == null)
@@ -166,12 +175,11 @@ public void onProductDetailsResponse(@Nonnull BillingResult billingResult, @Nonn
166175
if (!installationComplete) {
167176
observer.handleInstallError(new FetchItemInformationException(String.valueOf(responseCode)));
168177
}
169-
170178
} else {
171-
Gdx.app.debug(TAG,"Retrieved product count: " + productDetailsList.size());
179+
List<ProductDetails> productDetailsList = productDetailsResult.getProductDetailsList();
180+
Gdx.app.debug(TAG,"Retrieved product count: " + productDetailsList.size());
172181
for (ProductDetails productDetails : productDetailsList) {
173-
informationMap.put(productDetails.getProductId(), convertProductDetailsToInformation
174-
(productDetails));
182+
informationMap.put(productDetails.getProductId(), convertProductDetailsToInformation(productDetails));
175183
productDetailsMap.put(productDetails.getProductId(), productDetails);
176184
}
177185

@@ -231,7 +239,7 @@ private void convertSubscriptionProductToInformation(Information.Builder builder
231239
.priceCurrencyCode(paidForPricingPhase.getPriceCurrencyCode())
232240
.priceInCents((int) paidForPricingPhase.getPriceAmountMicros() / 10_000)
233241
.priceAsDouble(paidForPricingPhase.getPriceAmountMicros() / 1_000_000.0)
234-
;
242+
;
235243

236244
ProductDetails.PricingPhase freeTrialSubscriptionPhase = getFreeTrialSubscriptionPhase(details.getPricingPhases());
237245

@@ -248,9 +256,9 @@ private ProductDetails.SubscriptionOfferDetails getActiveSubscriptionOfferDetail
248256
@Nullable
249257
private ProductDetails.PricingPhase getPaidRecurringPricingPhase(ProductDetails.SubscriptionOfferDetails details) {
250258
for(ProductDetails.PricingPhase phase : details.getPricingPhases().getPricingPhaseList()) {
251-
if (isPaidForSubscriptionPhase(phase)) {
252-
return phase;
253-
}
259+
if (isPaidForSubscriptionPhase(phase)) {
260+
return phase;
261+
}
254262
}
255263
return null;
256264
}
@@ -374,7 +382,7 @@ protected BillingFlowParams.Builder getBillingFlowParams(ProductDetails productD
374382
Gdx.app.error(TAG, "subscriptionOfferDetails are empty for product: " + productDetails);
375383
offerToken = null;
376384
} else {
377-
offerToken = getActiveSubscriptionOfferDetails(subscriptionOfferDetails) // HOW TO SPECIFY AN ALTERNATE OFFER USING gdx-pay?
385+
offerToken = getActiveSubscriptionOfferDetails(subscriptionOfferDetails) // HOW TO SPECIFY AN ALTERNATE OFFER USING gdx-pay?
378386
.getOfferToken();
379387
}
380388

@@ -510,4 +518,4 @@ public void onAcknowledgePurchaseResponse(@Nonnull BillingResult billingResult)
510518
if (fromRestore)
511519
observer.handleRestore(transactions.toArray(new Transaction[0]));
512520
}
513-
}
521+
}

0 commit comments

Comments
 (0)