Skip to content

Connecting to The Service

levching edited this page Apr 15, 2020 · 3 revisions

This document explains how to add Google Play Billing into your app using the Google Play Library. Specifically, this document covers how to add Google Play Billing functionality that's common to all in-app product types: one-time products, rewarded products, and subscriptions. To learn how to add in-app product-specific functionality to your app, read the documents listed at the end of this page.

Before reading this page, do the following:

  1. Read the Google Play Billing Overview to familiarize yourself with important concepts and terms.
  2. Configure your in-app products using the Google Play Console:
  3. Enable Plugin Vending Service

Make sure that Vending service is enabled under the Android Native services list. See the screenshot below:

ConnectingtoTheService

NOTE: The goal of this plugin is to provide you full access to the Android InApps API. You should no be limited and have the same possibilities when Using Google Java billing library or Android Native plugin

There is no point of making a long article of how to use a plugin, you can ready Use the Google Play Billing Library the plugin API will be the same. Just in a bit C# ish manner.

For example if, inside Google Documentation, you see service connection sample like this:

private BillingClient billingClient;
...
billingClient = BillingClient.newBuilder(activity).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
    @Override
    public void onBillingSetupFinished(BillingResult billingResult) {
        if (billingResult.getResponseCode() == BillingResponse.OK) {
            // The BillingClient is ready. You can query purchases here.
        }
    }
    @Override
    public void onBillingServiceDisconnected() {
        // Try to restart the connection on the next request to
        // Google Play by calling the startConnection() method.
    }
});

The C# version would be:

using SA.Android.Vending.BillingClient;
...

public class BillingSample : AN_iBillingClientStateListener, AN_iPurchasesUpdatedListener
{

    private AN_BillingClient billingClient;

    public void Connect()
    {
        billingClient = AN_BillingClient.NewBuilder().SetListener(this).Build();
        billingClient.StartConnection(this);
    }

    public void OnBillingSetupFinished(SA_iResult billingResult)
    {
        if (billingResult.IsSucceeded) {
            // The BillingClient is ready. You can query purchases here.
        }
    }

    public void OnBillingServiceDisconnected()
    {
        // Try to restart the connection on the next request to
        // Google Play by calling the startConnection() method.
    }

    public void onPurchasesUpdated(SA_iResult billingResult, List<AN_Purchase> purchases)
    {
        //Handle Purchases
    }
}

Note: This is an experimental way of documentation article.

  • There is no point to make full documentation since it will be 1 to 1 google documentation copy
  • By exploring google native API docs you can gain a better understanding for the google provided API
  • If you missing some features, please let me know.
  • If you have troubles following google documentation and rewriting Java samples to C# plugin API, please let me know.
Clone this wiki locally