// Unity IAP framework will call this method after Initialize method regardless. public void RetrieveProducts(ReadOnlyCollection <ProductDefinition> products) { _billingClientStateListener = new BillingClientStateListener(); // Retry connection when Play Billing Service is disconnected. _billingClientStateListener.OnBillingServiceDisconnected += () => { _billingUtil.LogWarningFormat("Service disconnected, retrying connection..."); EndConnection(); InstantiateBillingClientAndMakeConnection(); }; _billingClientStateListener.OnBillingSetupFinished += (billingResult) => { MarkBillingClientStartConnectionCallComplete(billingResult); if (_billingClientReady) { _inventory.UpdateCatalog(products); // Kick off tasks to retrieve products information on the main thread. _billingUtil.RunOnMainThread(() => RetrieveProductsInternal(products)); } else { _billingUtil.LogWarningFormat("Google Play Store: play billing service unavailable!"); _billingUtil.RunOnMainThread(() => _callback.OnSetupFailed(InitializationFailureReason.PurchasingUnavailable)); } }; InstantiateBillingClientAndMakeConnection(); }
public void Initialize(IStoreCallback callback) { _callback = callback; _billingClientStateListener = new BillingClientStateListener(); // Retry connection when Play Billing Service is disconnected. _billingClientStateListener.OnBillingServiceDisconnected += () => { _billingUtil.LogWarningFormat("Service disconnected, retrying connection..."); EndConnection(); InstantiateBillingClientAndMakeConnection(); }; // Mark Billing Client startConnection method call as completed. _billingClientStateListener.OnBillingSetupFinished += MarkBillingClientStartConnectionCallComplete; InstantiateBillingClientAndMakeConnection(); // Block this method until startConnection call finishes. This is because the follow-up call will depend on // this connection. _billingClientStartConnectionCallStatus.WaitOne(Constants.BillingClientAsyncTimeout); }