Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API replacements to V5 migration #430

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.androidbrowserhelper.playbilling.digitalgoods;

import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClient.ProductType;
import com.android.billingclient.api.BillingClient.SkuType;
import com.android.billingclient.api.BillingResult;

Expand All @@ -26,8 +27,8 @@
/**
* Play Billing SKUs are split into purchases and subscriptions. This isn't a distinction that
* exists in the Digital Goods API, but since SKU ids are unique across both product types, we can
* just call methods that take a skuType twice, once with {@link SkuType#INAPP} and once with
* {@link SkuType#SUBS}. This class exists to combine the results of those calls.
* just call methods that take a ProductType twice, once with {@link ProductType#INAPP} and once with
* {@link ProductType#SUBS}. This class exists to combine the results of those calls.
*
* Although the Play Billing methods are asynchronous, their callbacks (which will call
* {@link #setInAppResult} and {@link #setSubsResult}) should both take place on the UI thread, so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.PriceChangeConfirmationListener;
import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.ProductDetailsResponseListener;
import com.android.billingclient.api.PurchaseHistoryResponseListener;
import com.android.billingclient.api.PurchasesResponseListener;
import com.android.billingclient.api.QueryProductDetailsParams.Product;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsResponseListener;
import com.google.androidbrowserhelper.playbilling.provider.BillingWrapper;
import com.google.androidbrowserhelper.playbilling.provider.MethodData;

Expand All @@ -34,7 +35,7 @@

/**
* A wrapper around {@link BillingWrapper} that ensures it is connected before calling
* {@link #querySkuDetails}, {@link #acknowledge} or {@link #consume}.
* {@link #queryProductDetails}, {@link #acknowledge} or {@link #consume}.
*/
public class ConnectedBillingWrapper implements BillingWrapper {
private final BillingWrapper mInner;
Expand Down Expand Up @@ -90,19 +91,19 @@ public void connect(BillingClientStateListener callback) {
}

@Override
public void querySkuDetails(@BillingClient.SkuType String skuType, List<String> skus,
SkuDetailsResponseListener callback) {
execute(() -> mInner.querySkuDetails(skuType, skus, callback));
public void queryProductDetails(@BillingClient.ProductType String productType, List<String> productsIds,
ProductDetailsResponseListener callback) {
execute(() -> mInner.queryProductDetails(productType, productsIds, callback));
}

@Override
public void queryPurchases(String skuType, PurchasesResponseListener callback) {
execute(() -> mInner.queryPurchases(skuType, callback));
public void queryPurchases(String productType, PurchasesResponseListener callback) {
execute(() -> mInner.queryPurchases(productType, callback));
}

@Override
public void queryPurchaseHistory(String skuType, PurchaseHistoryResponseListener callback) {
execute(() -> mInner.queryPurchaseHistory(skuType, callback));
public void queryPurchaseHistory(String productType, PurchaseHistoryResponseListener callback) {
execute(() -> mInner.queryPurchaseHistory(productType, callback));
}

@Override
Expand All @@ -116,15 +117,15 @@ public void consume(String token, ConsumeResponseListener callback) {
}

@Override
public boolean launchPaymentFlow(Activity activity, SkuDetails sku, MethodData data) {
public boolean launchPaymentFlow(Activity activity, ProductDetails productDetails, MethodData data) {
throw new IllegalStateException(
"EnsuredConnectionBillingWrapper doesn't handle launch Payment flow");
"EnsuredConnectionBillingWrapper doesn't handle launch Payment flow");
}

@Override
public void launchPriceChangeConfirmationFlow(Activity activity, SkuDetails sku,
PriceChangeConfirmationListener listener) {
public void launchPriceChangeConfirmationFlow(Activity activity, ProductDetails productDetails,
ProductDetailsResponseListener listener) {
throw new IllegalStateException("EnsuredConnectionBillingWrapper doesn't handle the " +
"price change confirmation flow");
"price change confirmation flow");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
import android.os.Parcelable;

import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClient.ProductType;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.ProductDetails;
import com.google.androidbrowserhelper.playbilling.provider.BillingWrapper;

import java.util.Arrays;
import java.util.List;

import androidx.annotation.Nullable;

import static com.google.androidbrowserhelper.playbilling.digitalgoods.DigitalGoodsConverter.toChromiumResponseCode;

/**
* A class for parsing Digital Goods API calls from the browser and converting them into a format
Expand All @@ -52,7 +52,7 @@ private GetDetailsCall(List<String> itemIds, DigitalGoodsCallback callback) {
/** Creates this class from a {@link Bundle}, returns {@code null} if the Bundle is invalid. **/
@Nullable
public static GetDetailsCall create(@Nullable Bundle args,
@Nullable DigitalGoodsCallback callback) {
@Nullable DigitalGoodsCallback callback) {
if (args == null || callback == null) return null;

String[] itemIds = args.getStringArray(PARAM_GET_DETAILS_ITEM_IDS);
Expand All @@ -62,22 +62,22 @@ public static GetDetailsCall create(@Nullable Bundle args,
}

/** Calls the callback provided in the constructor with serialized forms of the parameters. */
private void respond(BillingResult result, @Nullable List<SkuDetails> detailsList) {
private void respond(BillingResult result, @Nullable List<ProductDetails> detailsList) {
Logging.logGetDetailsResponse(result);

Parcelable[] parcelables = new Parcelable[0];
if (detailsList != null) {
parcelables = new Parcelable[detailsList.size()];

int index = 0;
for (SkuDetails details : detailsList) {
for (ProductDetails details : detailsList) {
parcelables[index++] = ItemDetails.create(details).toBundle();
}
}

Bundle args = new Bundle();
args.putInt(RESPONSE_GET_DETAILS_RESPONSE_CODE,
DigitalGoodsConverter.toChromiumResponseCode(result));
DigitalGoodsConverter.toChromiumResponseCode(result));
args.putParcelableArray(RESPONSE_GET_DETAILS_DETAILS_LIST, parcelables);
mCallback.run(RESPONSE_GET_DETAILS, args);
}
Expand All @@ -86,10 +86,10 @@ private void respond(BillingResult result, @Nullable List<SkuDetails> detailsLis
public void call(BillingWrapper billing) {
Logging.logGetDetailsCall(mItemIds);

BillingResultMerger<SkuDetails> merger = new BillingResultMerger<>(this::respond);
BillingResultMerger<ProductDetails> merger = new BillingResultMerger<>(this::respond);

billing.querySkuDetails(BillingClient.SkuType.INAPP, mItemIds, merger::setInAppResult);
billing.querySkuDetails(BillingClient.SkuType.SUBS, mItemIds, merger::setSubsResult);
billing.queryProductDetails(BillingClient.ProductType.INAPP, mItemIds, merger::setInAppResult);
billing.queryProductDetails(BillingClient.ProductType.SUBS, mItemIds, merger::setSubsResult);
}

/** Creates a Bundle that can be used with {@link #create}. For testing. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import android.os.Bundle;

import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.SkuDetails;

/**
Expand Down Expand Up @@ -57,10 +58,10 @@ public class ItemDetails {
public final int introductoryPriceCycles;

private ItemDetails(String id, String title, String description, String currency, String value,
String type, String iconUrl, String subscriptionPeriod,
String freeTrialPeriod, String introductoryPricePeriod,
String introductoryPriceCurrency, String introductoryPriceValue,
int introductoryPriceCycles) {
String type, String iconUrl, String subscriptionPeriod,
String freeTrialPeriod, String introductoryPricePeriod,
String introductoryPriceCurrency, String introductoryPriceValue,
int introductoryPriceCycles) {
this.id = id;
this.title = title;
this.description = description;
Expand All @@ -79,19 +80,19 @@ private ItemDetails(String id, String title, String description, String currency
/**
* Creates this class from a Play Billing {@link SkuDetails}.
*/
public static ItemDetails create(SkuDetails skuDetails) {
public static ItemDetails create(ProductDetails skuDetails) {
return new ItemDetails(
skuDetails.getSku(),
skuDetails.getTitle(),
skuDetails.getDescription(),
skuDetails.getPriceCurrencyCode(),
toPrice(skuDetails.getPriceAmountMicros()),
skuDetails.getType(), skuDetails.getIconUrl(), skuDetails.getSubscriptionPeriod(),
skuDetails.getFreeTrialPeriod(),
skuDetails.getIntroductoryPricePeriod(),
skuDetails.getPriceCurrencyCode(),
toPrice(skuDetails.getIntroductoryPriceAmountMicros()),
skuDetails.getIntroductoryPriceCycles());
skuDetails.getProductId(),
skuDetails.getTitle(),
skuDetails.getDescription(),
skuDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode(),
toPrice(skuDetails.getOneTimePurchaseOfferDetails().getPriceAmountMicros()),
skuDetails.getProductType(), skuDetails.getIconUrl(), skuDetails.getSubscriptionPeriod(),
skuDetails.getFreeTrialPeriod(),
skuDetails.getIntroductoryPricePeriod(),
skuDetails.getPriceCurrencyCode(),
toPrice(skuDetails.getIntroductoryPriceAmountMicros()),
skuDetails.getIntroductoryPriceCycles());
}

/**
Expand All @@ -114,8 +115,8 @@ public static ItemDetails create(Bundle bundle) {
int introductoryPriceCycles = bundle.getInt(KEY_INTRO_CYCLES);

return new ItemDetails(id, title, description, currency, value, type, iconUrl,
subscriptionPeriod, freeTrialPeriod, introductoryPricePeriod,
introductoryPriceCurrency, introductoryPriceValue, introductoryPriceCycles);
subscriptionPeriod, freeTrialPeriod, introductoryPricePeriod,
introductoryPriceCurrency, introductoryPriceValue, introductoryPriceCycles);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.PriceChangeConfirmationListener;
import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.ProductDetailsResponseListener;
import com.android.billingclient.api.PurchaseHistoryResponseListener;
import com.android.billingclient.api.PurchasesResponseListener;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsResponseListener;
import com.google.androidbrowserhelper.playbilling.digitalgoods.ConnectedBillingWrapper;
import com.android.billingclient.api.QueryProductDetailsParams.Product;

import java.util.List;

Expand All @@ -47,21 +46,21 @@ interface Listener {
void connect(BillingClientStateListener callback);

/**
* Get {@link SkuDetails} objects for the provided SKUs.
* Get {@link ProductDetails} objects for the provided products.
*/
void querySkuDetails(@BillingClient.SkuType String skuType, List<String> skus,
SkuDetailsResponseListener callback);
void queryProductDetails(@BillingClient.ProductType String productType, List<String> productsIds,
ProductDetailsResponseListener callback);

/**
* Returns details for currently owned items.
*/
void queryPurchases(@BillingClient.SkuType String skuType, PurchasesResponseListener callback);
void queryPurchases(@BillingClient.ProductType String productType, PurchasesResponseListener callback);

/**
* Returns details for all previously purchased items.
*/
void queryPurchaseHistory(@BillingClient.SkuType String skuType,
PurchaseHistoryResponseListener callback);
void queryPurchaseHistory(@BillingClient.ProductType String skuType,
PurchaseHistoryResponseListener callback);

/**
* Acknowledges that a purchase has occured.
Expand All @@ -77,12 +76,12 @@ void queryPurchaseHistory(@BillingClient.SkuType String skuType,
* Launches the Payment Flow. If it returns {@code true},
* {@link Listener#onPurchaseFlowComplete} should be called.
*/
boolean launchPaymentFlow(Activity activity, SkuDetails sku, MethodData methodData);
boolean launchPaymentFlow(Activity activity, ProductDetails productDetails, MethodData methodData);

/**
* Launches the price change confirmation flow.
*/
void launchPriceChangeConfirmationFlow(Activity activity, SkuDetails sku,
PriceChangeConfirmationListener listener);
void launchPriceChangeConfirmationFlow(Activity activity, ProductDetails productDetails,
ProductDetailsResponseListener listener);

}
Loading