Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

Google Play Billing Library release notes

Google Play Billing Library 1.2.2 Release (2019-03-07)

Bug fixes

  • Fixed a threading issue introduced in v1.2.1. Background calls no longer block the main thread.

Other changes

  • Although using the main thread is still recommended, you can now instantiate the Google Play Billing Library from a background thread.
  • Instantiation has been fully migrated to the background thread to reduce the chance of causing ANRs.

Play Billing Library 1.2.1 Release (2019-03-04)

Major changes

Other changes

  • Added public constructors for PurchasesResult and SkuDetailsResult to make testing easier.
  • SkuDetails objects can use a new method, getOriginalJson().
  • All AIDL service calls are now handled by background threads.

Bug fixes

  • Null callback listeners are no longer passed into public APIs.

Google Play Billing Library 1.2 Release (2018-10-18)

Summary of changes

  • The Google Play Billing Library is now licensed under the Android Software Development Kit License Agreement.
  • Added the launchPriceChangeConfirmationFlow API, which prompts users to review a pending change to a subscription price.
  • Added support for a new proration mode, DEFERRED, when upgrading or downgrading a user's subscription.
  • In the BillingFlowParams class, replaced setSku() with setSkuDetails().
  • Minor bug fixes and code optimizations.

Detailed changes

Price change confirmation

You can now change the price of a subscription in Google Play Console and prompt users to review and accept the new price when they enter your app.

To use this API, create a PriceChangeFlowParams object by using the skuDetails of the subscription product, and then call launchPriceChangeConfirmationFlow(). Implement the PriceChangeConfirmationListener to handle the result when the price change confirmation flow finishes, as shown in the following code snippet:

Kotlin

val priceChangeFlowParams = PriceChangeFlowParams.newBuilder()
    .setSkuDetails(skuDetailsOfThePriceChangedSubscription)
    .build()

billingClient.launchPriceChangeConfirmationFlow(activity,
        priceChangeFlowParams,
        object : PriceChangeConfirmationListener() {
            override fun onPriceChangeConfirmationResult(responseCode: Int) {
                // Handle the result.
            }
        })

Java

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

billingClient.launchPriceChangeConfirmationFlow(activity,
        priceChangeFlowParams,
        new PriceChangeConfirmationListener() {
            @Override
            public void onPriceChangeConfirmationResult(int responseCode) {
                // Handle the result.
            }
        });

The price change confirmation flow displays a dialog containing the new pricing information, asking users to accept the new price. This flow returns a response code of type BillingClient.BillingResponse.

New proration mode

When upgrading or downgrading a user's subscription, you can use a new proration mode, DEFERRED. This mode updates the user's subscription when it next renews. To learn more about how to set this proration mode, see Set proration mode.

New method for setting SKU details

In the BillingFlowParams class, the setSku() method has been deprecated. This change serves to optimize the Google Play Billing flow.

When constructing a new instance of BillingFlowParams in your in-app billing client, we recommend that you instead work with the JSON object directly using setSkuDetails(), as shown in the following code snippet:

In the BillingFlowParams Builder class, the setSku() method has been deprecated. Instead, use the setSkuDetails() method, as shown in the following code snippet. The object passed into setSkuDetails() object comes from the querySkuDetailsAsync() method.

Kotlin

private lateinit var mBillingClient: BillingClient
private val mSkuDetailsMap = HashMap<String, SkuDetails>()

private fun querySkuDetails() {
    val skuDetailsParamsBuilder = SkuDetailsParams.newBuilder()
    mBillingClient.querySkuDetailsAsync(skuDetailsParamsBuilder.build()
    ) { responseCode, skuDetailsList ->
        if (responseCode == 0) {
            for (skuDetails in skuDetailsList) {
                mSkuDetailsMap[skuDetails.sku] = skuDetails
            }
        }
    }
}

private fun startPurchase(skuId: String) {
    val billingFlowParams = BillingFlowParams.newBuilder()
    .setSkuDetails(mSkuDetailsMap[skuId])
    .build()
}

Java

private BillingClient mBillingClient;
private Map<String, SkuDetails> mSkuDetailsMap = new HashMap<>();

private void querySkuDetails() {
    SkuDetailsParams.Builder skuDetailsParamsBuilder
            = SkuDetailsParams.newBuilder();
    mBillingClient.querySkuDetailsAsync(skuDetailsParamsBuilder.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode,
                        List<SkuDetails> skuDetailsList) {
                    if (responseCode == 0) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            mSkuDetailsMap.put(skuDetails.getSku(), skuDetails);
                        }
                    }
                }
            });
}

private void startPurchase(String skuId) {
    BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
            .setSkuDetails(mSkuDetailsMap.get(skuId))
            .build();
}

Play Billing Library 1.1 Release (2018-05-07)

Summary of changes

  • Added support to specify a proration mode in BillingFlowParams when upgrading/downgrading an existing subscription.
  • The replaceSkusProration boolean flag in BillingFlowParams is no longer supported. Use replaceSkusProrationMode instead.
  • launchBillingFlow() now triggers a callback for failed responses.

Behavior changes

Developers can set replaceSkusProrationMode in BillingFlowParams class

A ProrationMode provides further details on the type of proration when upgrading or downgrading a user's subscription.

Kotlin

BillingFlowParams.newBuilder()
    .setSku(skuId)
    .setType(billingType)
    .setOldSku(oldSku)
    .setReplaceSkusProrationMode(replaceSkusProrationMode)
    .build()

Java

BillingFlowParams.newBuilder()
    .setSku(skuId)
    .setType(billingType)
    .setOldSku(oldSku)
    .setReplaceSkusProrationMode(replaceSkusProrationMode)
    .build();

Currently, Google Play supports following proration modes:

IMMEDIATE_WITH_TIME_PRORATION Replacement takes effect immediately, and the new expiration time will be prorated and credited or charged to the user. This is the current default behavior.
IMMEDIATE_AND_CHARGE_PRORATED_PRICE Replacement takes effect immediately, and the billing cycle remains the same. The price for the remaining period will be charged.

Note: This option is only available for subscription upgrade.

IMMEDIATE_WITHOUT_PRORATION Replacement takes effect immediately, and the new price will be charged on next recurrence time. The billing cycle stays the same.

replaceSkusProration is no longer supported in BillingFlowParams class

Developers used to be able to set a boolean flag to charge a prorated amount for a subscription upgrade request. Given that we are supporting ProrationMode, which contains more detailed proration instruction, this boolean flag is no longer supported.

launchBillingFlow() now triggers a callback for failed responses

The Billing Library will always trigger the PurhcasesUpdatedListener callback and return a BillingResponse asynchronously. The synchronous return value of BillingResponse is kept as well.

Bug fixes

  • Properly exits early in async methods when service is disconnected.
  • Builder param objects no longer mutates built objects.
  • Issue 68087141: launchBillingFlow() now trigger callback for failed responses.

Google Play Billing Library 1.0 Release (2017-09-19, Announcement)

Important changes

  • Embedded billing permission inside library’s manifest. It's not necessary to add the com.android.vending.BILLING permission inside Android manifest anymore.
  • New builder added to BillingClient.Builder class.
  • Introduced builder pattern for SkuDetailsParams class to be used on methods to query SKUs.
  • Several API methods were updated for consistency (the same return argument names and order).

Behavior changes

BillingClient.Builder class

BillingClient.Builder is now initialized via the newBuilder pattern:

billingClient = BillingClient.newBuilder(context).setListener(this).build();

launchBillingFlow method is now called using a BillingFlowParams class

To initiate the billing flow for a purchase or subscription, the launchBillingFlow() method receives a BillingFlowParams instance initialized with parameters specific to the request:

BillingFlowParams.newBuilder().setSku(skuId)
                              .setType(billingType)
                              .setOldSku(oldSku)
                              .build();

// Then, use the BillingFlowParams to start the purchase flow
int responseCode = billingClient.launchBillingFlow(builder.build());

New way to query available products

Arguments for queryPurchaseHistoryAsync() and querySkuDetailsAsync() methods were wrapped into a Builder pattern:

SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList)
      .setType(itemType);
billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {...})

The result is now returned via result code and a list of SkuDetails objects instead of previous wrapper class for your convenience and to be consistent across our API:

public void onSkuDetailsResponse(@BillingResponse int responseCode, List<SkuDetails> skuDetailsList)

Parameters order changed on onConsumeResponse() method

The order of arguments for onConsumeResponse from the ConsumeResponseListener interface has changed to be consistent across our API:

public void onConsumeResponse(@BillingResponse int responseCode, String outToken)

Unwrapped PurchaseResult object

PurchaseResult has been unwraped to be consistent across our API:

void onPurchaseHistoryResponse(@BillingResponse int responseCode, List<Purchase> purchasesList)

Bug fixes

Developer Preview 1 Release (2017-06-12, Announcement)

Developer preview launched, aimed to simplify the development process when it comes to billing, allowing developers to focus their efforts on implementing logic specific to the Android app, such as application architecture and navigation structure.

The library includes several convenient classes and features for you to use when integrating your Android apps with the Google Play Billing API. The library also provides an abstraction layer on top of the Android Interface Definition Language (AIDL) service, making it easier for developers to define the interface between the app and the Google Play Billing API.