Пример #1
0
        /// <summary>
        /// Consume purchase corresponding to the purchase token.
        /// This will result in this item being removed from all
        /// subsequent responses to <see cref="GetPurchases(Action{SA_Result})"/> and allow repurchase of items of the same sku.
        /// </summary>
        /// <param name="purchase">purchase to consume</param>
        /// <param name="callback">Consume request callback</param>
        public static void Consume(AN_Purchase purchase, Action <SA_Result> callback)
        {
            var product = Inventory.GetProductById(purchase.ProductId);

            if (product != null)
            {
                if (!product.IsConsumable)
                {
                    Debug.LogWarning("You are trying to consume product with id: " + product.ProductId + " that was originally marked as non consumable product");
                }
            }
            else
            {
                Debug.LogWarning("product " + purchase.ProductId + " isn't the registered inventory product");
            }

            AN_VendingLib.API.Consume(purchase, (result) => {
                if (result.IsSucceeded)
                {
                    foreach (var invPurchase in Inventory.Purchases)
                    {
                        if (invPurchase.ProductId.Equals(purchase.ProductId))
                        {
                            Inventory.Purchases.Remove(invPurchase);
                            break;
                        }
                    }
                }
                callback.Invoke(result);
            });
        }
Пример #2
0
        /// <summary>
        /// Consume purchase corresponding to the purchase token.
        /// This will result in this item being removed from all
        /// subsequent responses to <see cref="GetPurchases(Action{SA_Result})"/> and allow repurchase of items of the same sku.
        /// </summary>
        /// <param name="purchase">purchase to consume</param>
        /// <param name="callback">Consume request callback</param>
        public static void Consume(AN_Purchase purchase, Action <SA_Result> callback)
        {
            m_Client.Consume(purchase.Token, result =>
            {
                if (result.IsSucceeded)
                {
                    foreach (var invPurchase in Inventory.Purchases)
                    {
                        if (invPurchase.ProductId.Equals(purchase.ProductId))
                        {
                            Inventory.Purchases.Remove(invPurchase);
                            break;
                        }
                    }
                }

                callback.Invoke((SA_Result)result);
            });
        }
Пример #3
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);
            });
        }
 public AN_BillingPurchaseResult(AN_Purchase purchase)
 {
     m_purchase = purchase;
 }