33import android .app .Activity ;
44import android .os .Handler ;
55import android .os .Looper ;
6+ import androidx .annotation .NonNull ;
67import com .android .billingclient .api .*;
78import com .android .billingclient .api .BillingClient .ProductType ;
89import 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