Search Unity

[Solved] Second and more Purchase is free in Consumable items

Discussion in 'Unity IAP' started by StanislavMaksheev, Nov 11, 2016.

Thread Status:
Not open for further replies.
  1. StanislavMaksheev

    StanislavMaksheev

    Joined:
    Feb 6, 2015
    Posts:
    47
    Hi,
    First purchse going correct, but when I buy second and more times purchase is for free
    It is on ios and samsung stores.

    Into stores i use "Consumable" product.


    Code (CSharp):
    1. void Start()
    2.     {
    3.         Init();
    4.     }
    5.  
    6.     public void Init()
    7.     {
    8.         CurrentStoreInitState = StoreInitState.InitInProgress;
    9.  
    10.         var module = StandardPurchasingModule.Instance();
    11.         var builder = ConfigurationBuilder.Instance(module);
    12.         builder.Configure<IGooglePlayConfiguration>().SetPublicKey(GooglePublicKey);
    13.  
    14.         if (CheatEngineManager.IsCheatsEnabled)
    15.         {
    16.             builder.Configure<ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed); // TESTING: auto-approves all transactions by Samsung
    17.         }
    18.  
    19.         //регистрирую товары
    20.         builder.AddProduct(Goods.BuyCoins00.ToString(), ProductType.Consumable, new IDs
    21.         {
    22.             {Goods.BuyCoins00.ToString() + "IOS", AppleAppStore.Name},
    23.             {Goods.BuyCoins00.ToString().ToLower() + "googleplay", GooglePlay.Name},
    24.             {Goods.BuyCoins00.ToString().ToLower() + "samsung", SamsungApps.Name}
    25.         });
    26.  
    27.         UnityPurchasing.Initialize(this, builder);
    28.     }
    29.  
    30. public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    31.     {
    32.         this.controller = controller;
    33.         StoreInited(controller);
    34.         //this.extensions = extensions;
    35.         CurrentStoreInitState = StoreInitState.InitSuccess;
    36.     }
    37.  
    38.     public void OnInitializeFailed(InitializationFailureReason error)
    39.     {
    40.         CurrentStoreInitState = StoreInitState.InitFailed;
    41.         Debug.LogWarning("Не могу инициализировать магазин " + error);
    42.     }
    43.  
    44. public void BuyCoinTier(Goods coinTier)
    45.     {
    46.         if (IsCheats)
    47.         {
    48.             ActivateTier(coinTier);
    49.             Debug.LogError("Использован чит на покупку монет");
    50.  
    51.             //сохраняю покупку для панели читов
    52.             int value = 1 + ObscuredPrefs.GetInt("Cheat_" + coinTier);
    53.             ObscuredPrefs.SetInt("Cheat_" + coinTier, value);
    54.         }
    55.         else
    56.         {
    57.             Purchase(coinTier.ToString());
    58.         }
    59.     }
    60.  
    61. public void Purchase(string product)
    62.     {
    63.         if (_isPurchaseInProgress)
    64.         {
    65.             Debug.LogWarning("Совершается покупка");
    66.             return;
    67.         }
    68.  
    69.         if (controller != null)
    70.         {
    71.             //совершаю покупку
    72.             _isPurchaseInProgress = true;
    73.             controller.InitiatePurchase(product);
    74.         }
    75.         else
    76.         {
    77.             Debug.LogWarning("Покупки не инициализированы");
    78.             Init();
    79.         }
    80.  
    81. //вызывается когда покупка успешно выполнена
    82.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    83.     {
    84.         _isPurchaseInProgress = false;
    85.  
    86.         bool validPurchase = true; // Presume valid for platforms with no R.V.
    87.  
    88.         // Unity IAP's validation logic is only included on these platforms.
    89. #if (UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX)
    90.         // Prepare the validator with the secrets we prepared in the Editor
    91.         // obfuscation window.
    92.         var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    93.             AppleTangle.Data(), Application.bundleIdentifier);
    94.  
    95.         try
    96.         {
    97.             // On Google Play, result has a single product ID.
    98.             // On Apple stores, receipts contain multiple products.
    99.             validator.Validate(e.purchasedProduct.receipt);
    100.             // For informational purposes, we list the receipt(s)
    101.             Debug.Log("Receipt is valid");
    102.             //foreach (IPurchaseReceipt productReceipt in result)
    103.             //{
    104.             //    Debug.Log(productReceipt.productID);
    105.             //    Debug.Log(productReceipt.purchaseDate);
    106.             //    Debug.Log(productReceipt.transactionID);
    107.             //}
    108.         }
    109.         catch (IAPSecurityException)
    110.         {
    111.             Debug.LogWarning("Invalid receipt, быть может читер!");
    112.             validPurchase = false;
    113.             FailValidate();
    114.         }
    115. #endif
    116.  
    117.         if (validPurchase)
    118.         {
    119.             // Unlock the appropriate content here.
    120.             ProcessPurchaseComplete(e.purchasedProduct.definition.id, e.purchasedProduct.transactionID, e.purchasedProduct.receipt);
    121.         }
    122.        
    123.         Debug.Log("return purchase complete");
    124.         return PurchaseProcessingResult.Complete;
    125.     }
    126.  
    127.     public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
    128.     {
    129.         _isPurchaseInProgress = false;
    130.         Debug.LogWarning("Не могу купить " + i.receipt + ", потому что " + p);
    131.     }
    132.  
     

    Attached Files:

  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Hi @StanislavMaksheev,

    Would you be able to provide some more details about this issue?

    If you could provide a link to your app or a copy of your project, that would help us identify this issue.
    In addition, if you could, please provide a list of steps needed to reproduce this issue.

    If you would like to send the link in private, you can create a support ticket here:
    https://analytics.cloud.unity3d.com/support/
     
  3. StanislavMaksheev

    StanislavMaksheev

    Joined:
    Feb 6, 2015
    Posts:
    47
    I was update IAP sdk to latest version and it all now works.....
     
    ap-unity likes this.
Thread Status:
Not open for further replies.