Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity IAP - android.test.purchased not being consumed?

Discussion in 'Android' started by Maisey, Jan 27, 2016.

  1. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    242
    Hello,

    I'm trying out the Unity IAP solution for Android. I'm using the product id: "android.test.purchased" which is a special product id that can be used for testing to simulate an actual purchase. But the problem with this is, that, once it has been bought it can't be purchased again, which is troublesome when testing.

    Is there some way we can explicitly consume a product, is this a bug or how are you gonna handle this issue? According to this Stackoverflow: http://stackoverflow.com/questions/13896666/in-app-billing-test-android-test-purchased-already-owned they recommend that one consume the product, so that it can be used again.

    Thanks!
     
  2. nproject

    nproject

    Joined:
    Jan 16, 2015
    Posts:
    68
    Unity IAP automatically consumes consumable products on google play when your app confirms a purchase as processed.

    source: http://forum.unity3d.com/threads/restoring-a-purchase-on-android.374012/
     
  3. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    242
    Thank you, but I don't see how this helps me. :(

    Unless something is wrong with the purchase I will return "PurchaseProcessingResult.Complete". Therefore, according to what you said, it should be consumed. But it doesn't because it's not a "normal" consumable, rather, I think it's more like a non-consumable and Unity IAP must make it a special case when handling it (or let us manually consume any products).
     
  4. davinc131

    davinc131

    Joined:
    Jun 23, 2015
    Posts:
    19
    In version 3 api google for sales of products in applications, it supports only two types of products. Manageable products and signature products. Already Unity IAP has three products. Manageable, signature and consumables, and this has caused tremendous confusion in my head, because I see in posts around, it is necessary to consume the product after the purchase is completed. Some suggest the use of "m_Help.ConsumeAsync ()" method to do the job, but I have no IDEA how to implement it in a C # code. The version of my Unity is 5.3.3 and do not know if the new version of Unity supports this method. What needs to be exclarecido then, is how to simulate consumables in Unity IAP when Google Play supports only the signature products and manageable?
     
    M.A.N. likes this.
  5. gfaraj

    gfaraj

    Joined:
    Jul 11, 2016
    Posts:
    23
    Can someone respond to this? How do you "consume" a managed product when using Unity IAP for Google Play, so that the user can purchase it again?
     
  6. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    290
    "Unity IAP automatically consumes consumable products on google play when your app confirms a purchase as processed."

    We too are seeing a problem where it doesn't seem to be happening:

    The code looks kind of like this...


    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
    Product pp;
    pp = args.purchasedProduct;
    Debug.Log("IAP calledback from store to ProcessPurchase! --> " +pp.definition.id);
    Debug.Log("IAP being careful to use the store-specific for verification: " +pp.definition.storeSpecificId);

    PurchaseSUCCESSFUL( pp ); // our own routine to pay out the coins...
    return PurchaseProcessingResult.Complete;
    }

    It seems that "return PurchaseProcessingResult.Complete;" is not having any effect, at the end.

    It's like you can only buy a given consumable ONCE; on further attempts to buy that consumable it just returns immediately.

    Anyone else seeing this??
     
  7. emperor1412

    emperor1412

    Joined:
    Jan 30, 2012
    Posts:
    26
    Unity 5.4.3

    I face with the same problem now, the same code flow work ok on iOS but not ok on android.
    For me, in the method

    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgse)

    I won't return PurchaseProcessingResult.Completed immediately, because I need to do receipt validation with my server so it will return PurchaseProcessingResult.Pending;

    Then later when the validation succeed, I will call ConfirmPendingPurchase(e.purchasedProduct);
    This flow work completely ok on iOS but not Android.

    The first time I purchased the Managed/comsumable item it was ok, but then the second time I make purchase, I always received the receipt data of previous success purchase and thus my server always return "Receipt already used" because it tracked all the verified receipt data.

    At first I tested the game using test account (google email added to the list of test users) that was allowed to make purchase without real money charge, later I remove this email from the list, deleted the app and download it from CH play again, but the problem still existed.

    Here is the code I have, Unity guys please have a look, this bug still occur until now, December 9th 2016.

    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
    2.     {
    3.         Debug.Log ("Purchase OK: " + e.purchasedProduct.definition.id);
    4.         Debug.Log ("Receipt: " + e.purchasedProduct.receipt);
    5.  
    6.         string receipt = e.purchasedProduct.receipt;
    7.         Dictionary<string, object> wrapper = JSONDotNetHelper.DeserializeObject<Dictionary<string, object>>(receipt);
    8.         if (null == wrapper)
    9.         {
    10.             if (cbFail != null)
    11.             {
    12.                 cbFail("Invalid receipts data");            
    13.             }
    14.             return PurchaseProcessingResult.Complete;
    15.         }
    16.  
    17.         Debug.Log ("Step 1");
    18.  
    19.         foreach (KeyValuePair<string, object> item in wrapper) {
    20.             Debug.LogFormat("Key:{0}\t-\tValue:{1}", item.Key, item.Value);
    21.         }
    22.  
    23.         Debug.Log ("Step 2");
    24.  
    25.         //var store = (string)wrapper["Store"];
    26.         var payload = (string)wrapper["Payload"];
    27.  
    28. #if UNITY_ANDROID
    29.         Dictionary<string, object> details = JSONDotNetHelper.DeserializeObject<Dictionary<string, object>>(payload);
    30.  
    31.         foreach (KeyValuePair<string, object> item in details) {
    32.             Debug.LogFormat("Key:{0}\t-\tValue:{1}", item.Key, item.Value);
    33.         }
    34.  
    35.         Debug.Log ("Step 3");
    36.  
    37.         var json = (string)details["json"]; // This is the INAPP_PURCHASE_DATA information
    38.         var sig = (string)details["signature"]; // This is the INAPP_DATA_SIGNATURE information
    39.  
    40.         Debug.LogFormat("CurrencyCode: {0}", e.purchasedProduct.metadata.isoCurrencyCode);
    41.         Debug.LogFormat("PurchasePrice: {0}", Convert.ToUInt32(e.purchasedProduct.metadata.localizedPrice));
    42.         Debug.LogFormat("ReceiptJson: {0}", json);
    43.         Debug.LogFormat("Signature: {0}", sig);
    44.  
    45.         ValidateGooglePlayPurchaseRequest req = new ValidateGooglePlayPurchaseRequest
    46.         {
    47.             CurrencyCode = e.purchasedProduct.metadata.isoCurrencyCode,
    48.             PurchasePrice = Convert.ToUInt32(e.purchasedProduct.metadata.localizedPrice),
    49.             ReceiptJson = json,
    50.             Signature = sig
    51.         };
    52.  
    53.         PlayFabClientAPI.ValidateGooglePlayPurchase(req, result =>
    54.         {
    55.             _storeController.ConfirmPendingPurchase(e.purchasedProduct);
    56.             GrantPurchase(e.purchasedProduct.definition.id);
    57.             Debug.Log("Validate GooglePlay Success: " + result.ToString());
    58.            
    59.             if (cbSuccess != null)
    60.             {
    61.                 cbSuccess(currentItem);
    62.             }
    63.         }, error =>
    64.         {
    65.             _storeController.ConfirmPendingPurchase(e.purchasedProduct);
    66.             Debug.Log("Validate GooglePlay Fail: " + error.ErrorMessage);
    67.             if (cbFail != null)
    68.             {
    69.                 cbFail(error.ErrorMessage);
    70.             }
    71.         });
    72.  
    73.  
    74. #elif UNITY_IOS
    75.         Debug.LogFormat("CurrencyCode: {0}", e.purchasedProduct.metadata.isoCurrencyCode);
    76.         Debug.LogFormat("PurchasePrice: {0}", Convert.ToUInt32(e.purchasedProduct.metadata.localizedPrice));
    77.         Debug.LogFormat("ReceiptData: {0}", payload);
    78.    
    79.         ValidateIOSReceiptRequest req1 = new ValidateIOSReceiptRequest
    80.         {
    81.             CurrencyCode = e.purchasedProduct.metadata.isoCurrencyCode,
    82.             PurchasePrice = Convert.ToInt32(e.purchasedProduct.metadata.localizedPrice),
    83.             ReceiptData = payload
    84.         };
    85.    
    86.         PlayFabClientAPI.ValidateIOSReceipt(req1, result =>
    87.         {
    88.             _storeController.ConfirmPendingPurchase(e.purchasedProduct);
    89.             GrantPurchase(e.purchasedProduct.definition.id);
    90.             Debug.Log("Validate Apple Success: " + result.ToString());
    91.             if (cbSuccess != null)
    92.             {
    93.                 cbSuccess(currentItem);
    94.             }
    95.         }, error =>
    96.         {
    97.             _storeController.ConfirmPendingPurchase(e.purchasedProduct);
    98.             Debug.Log("Validate Apple Fail: " + error.ErrorMessage);
    99.             if (cbFail != null)
    100.             {
    101.                 cbFail(error.ErrorMessage);
    102.             }
    103.         });
    104. #endif
    105.  
    106.       return PurchaseProcessingResult.Pending;
    107. }
    108.  
     
    Last edited: Dec 22, 2016
  8. dtaralla

    dtaralla

    Joined:
    Jan 1, 2016
    Posts:
    14
    *Bump*
    I have the exact same problem than emperor1412 just above, with Unity 5.5.2p1. I step-debugged and saw that I indeed call ConfirmPendingPurchase on the right product. However, next time I want to buy the product, I see a log "Already recorded transaction <some-hash-of-the-receipt>" and I received a PurchaseFailed event with PurchaseFailureReason.DuplicateTransaction. It happens each time, until I restart the app -- from the moment I quit and relaunch my app, I can buy the same item again. It's like Unity IAP only consume products on application exit :(

    Could someone please help? Is this a known issue?

    EDIT: I caught the "DuplicateTransaction" error and ignored it. Unity IAP and google play then allow me to buy the same consumable item again and again, even if it still outputs the "Already recorded transaction" log... So this seems like a Unity bug, where unity would confirm the purchase on google's end, but would not confirm the purchase in its cache until the app reboot...
     
    Last edited: Mar 22, 2017
  9. Nicolas1212

    Nicolas1212

    Joined:
    Dec 18, 2014
    Posts:
    104
    Just to chime in that I'm seeing the same issue on 5.5.1p4 - a user made two purchases of different IAPs on Android. On attempting a third, it's refusing with a message:

    msg: Couldn't purchase UnityEngine.Purchasing.Product, reason: DuplicateTransaction​
     
  10. Maucoimbra

    Maucoimbra

    Joined:
    Jun 5, 2017
    Posts:
    1
    Hello,

    Someone found the solution to the problem, I also have the same.

    The worst thing is that if the player closes the application and re-enters the store even if he does not buy anything, he ends up receiving the value of the last purchase made.

    Thank you,

    Mauricio.
     
  11. emperor1412

    emperor1412

    Joined:
    Jan 30, 2012
    Posts:
    26
    @Aurore hi this bug still occur after almost 1 year reported, please check it
     
  12. Laguna_Seca

    Laguna_Seca

    Joined:
    Mar 13, 2014
    Posts:
    24
    I get this problem in version 2017 :eek:
     
  13. marius_87

    marius_87

    Joined:
    Jan 2, 2013
    Posts:
    7
    Same problem here (Unity 2017.2.0f3) :(
     
  14. Alkanov

    Alkanov

    Joined:
    May 15, 2017
    Posts:
    13
    same here 2017.3.0f3 IAP services 1.15.0
     
  15. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    838
    For those reporting "same here", can you elaborate on your issue? The common issue in this thread looks to be the Duplicate Transaction issue, can someone confirm? Also, probably better to post in the Unity IAP forum at https://forum.unity.com/forums/unity-iap.112/
     
  16. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    782
    There are multiple issues in this thread and many new versions of the Unity IAP plugin have been released since this thread started. I can't address every individual post, but I will focus on the general questions and the recent posts.

    Unity IAP does not support the Google Play test product ids (such as android.test.purchased) for this exact reason. We recommend creating your own product ids.

    Unity IAP treats Consumable and Non-consumable products differently, even if Google does not. Unity IAP automatically consumes the purchase when you return Complete in ProcessPurchase or use ConfirmPendingPurchase.

    It looks like you are calling ConfirmPendingPurchase from within ProcessPurchase. This is not recommended and will cause unexpected behavior. You should return Pending and then, outside of ProcessPurchase, you should call ConfirmPendingPurchase.

    This may be the result of a bug that has since been fixed. You can find a list of the versions with the fix here:
    https://forum.unity.com/threads/sol...trigger-onpurchasefailed.457673/#post-3024228

    @Laguna_Seca, @marius_87, @Alkanov

    Any issue with DuplicatePurchase error that you are experiencing is either a regression or a new bug, so we need as much information as you can provide. Specifically, if you can provide the information requested here, that would help us track down the underlying cause:
    https://forum.unity.com/threads/read-this-before-you-post.450618/

    (For future reference, there is now a dedicated support forum for Unity IAP questions. It is more closely monitored by our support team. Although this thread does predate that forum.)