Beispiel #1
0
        /// <summary>
        /// Initializes and Connects to Billing Client. Needs to be called in the Activity OnCreate
        /// </summary>
        public Task StartAsync()
        {
            Log.Debug(_billingTag, "Build BillingClient. connection...");

            // Setup the Task Source to wait for Connection
            if (_connected != null)
            {
                throw new InAppPurchaseException(PurchaseError.DeveloperError, "BillingClient has been already started");
            }

            _connected = new TaskCompletionSource <object>();

            _billingClient = BillingClient.NewBuilder(Application.Context)
                             .SetListener(this)
                             .EnablePendingPurchases()
                             .Build();

            // Attempt to connect to the service
            if (!_billingClient.IsReady)
            {
                Log.Debug(_billingTag, "Start Connection...");
                _billingClient.StartConnection(this);
            }
            else
            {
                // Already connected. Complete the _connected Task Source
                _connected.TrySetResult(null);
            }

            // Return awaitable Task which is signaled when the BillingClient calls OnBillingServiceDisconnected
            return(_connected.Task);
        }
Beispiel #2
0
        /// <summary>
        /// Start a connection on billingclient
        /// </summary>
        /// <returns></returns>
        public async Task <bool> ConnectAsync()
        {
            _tcsConnect = new TaskCompletionSource <bool>();

            BillingClient = BillingClient.NewBuilder(CurrentContext).EnablePendingPurchases().SetListener(this).Build();

            BillingClient.StartConnection(this);

            return(await _tcsConnect?.Task);
        }
Beispiel #3
0
 public void Start()
 {
     billingClient.StartConnection(this);
 }