Esempio n. 1
0
            public void onPurchasesUpdated(SA_iResult billingResult, List <BillingClient.AN_Purchase> purchases)
            {
                AN_BillingPurchaseResult result;

                if (billingResult.IsSucceeded)
                {
                    result = new AN_BillingPurchaseResult(new AN_Purchase(purchases[0]));
                }
                else
                {
                    result = new AN_BillingPurchaseResult(billingResult);
                }

                m_BillingPurchaseCallback.Invoke(result);
            }
Esempio n. 2
0
        /// <summary>
        /// This method begins a purchase request.
        /// </summary>
        /// <param name="product">product which you must specify in the application's product list on the Google Play Console.</param>
        /// <param name="developerPayload">
        /// A developer-specified string that contains supplemental information about an order.
        /// You can specify a value for this field when you make a Purchase request.
        /// </param>
        /// <param name="callback">Purchase request callback</param>
        public static void Purchase(AN_Product product, string developerPayload, Action <AN_BillingPurchaseResult> callback)
        {
            var request = new AN_VendingLib.AN_PurchaseRequest();

            request.m_product          = product;
            request.m_developerPayload = developerPayload;

            AN_VendingLib.API.Purchase(request, (result) => {
                if (result.IsSucceeded)
                {
                    Inventory.Purchases.Add(result.Purchase);
                }
                else
                {
                    //me might try to resolve some know response codes
                    switch (result.Error.Code)
                    {
                    case (int)AN_BillingRessponceCodes.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED:
                        AN_Purchase purchase = Inventory.GetPurchaseByProductId(product.ProductId);
                        if (purchase != null)
                        {
                            result = new AN_BillingPurchaseResult(purchase);
                            callback.Invoke(result);
                        }
                        else
                        {
                            GetPurchases((purchasesLoadResult) => {
                                purchase = Inventory.GetPurchaseByProductId(product.ProductId);
                                if (purchase != null)
                                {
                                    result = new AN_BillingPurchaseResult(purchase);
                                }
                                callback.Invoke(result);
                            });
                        }
                        return;
                    }
                }

                callback.Invoke(result);
            });
        }