-
Notifications
You must be signed in to change notification settings - Fork 1
Connecting to The Service
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:
- Read the Google Play Billing Overview to familiarize yourself with important concepts and terms.
- Configure your in-app products using the Google Play Console:
- To configure a one-time product, see Create a managed product.
- To configure a rewarded product, see Create a rewarded product.
- To configure a subscription, see Create a subscription.
- Enable Plugin Vending Service
Make sure that Vending service is enabled under the Android Native services list. See the screenshot below:
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.
Reliable and high-quality Unity Development service. Let's Talk!
Website | AssetStore | LinkedIn | Youtube | Scripting Reference
- Build Info
- Dark Mode
- Package Info
- Runtime Permissions
- Run External App
- Immersive Mode
- PackageManager
- Popups & Preloaders
- Rate Us Dialog
- Activity
- Intent
- Settings Page
- Media Player
- Date Picker Dialog
- Time Picker Dialog
- Locale
- Wheel Picker Dialog
- Developer Console Setup
- Connecting to The Service
- Purchase Flow
- Transactions Validation
- Subscriptions
- Licensing
- Getting Started
- Games Sing-in
- Server-side API Access
- Leaderboards
- Achievements
- Saved Games
- Image Manager
- Settings Intent