Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity IAP InitiatePurchase with payload NullReferenceException

Discussion in 'Unity IAP' started by Femidko, Mar 7, 2018.

  1. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    57
    int purchaseId = 20;
    sController.InitiatePurchase(product, purchaseId.ToString());

    And all ok without payload.
    IAP 1.17.0
    Unity 5.6.5f1
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Would you be able to show your code differences with and without payload?
     
  3. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    57
    int purchaseId = 20;
    sController.InitiatePurchase(product, purchaseId.ToString());

    and

    sController.InitiatePurchase(product);
     
  4. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    57
    And always there is a DuplicateTransaction error on one specific product. This product is no different from the rest, valid, is tested and "availableToPurchase".
     
  5. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @Femidko

    I'm sorry to hear you are experiencing this issue. I'm going to recreate and look at possible fix or workarounds.

    Does this happen in the editor or on the device itself? Also, which platform are you experiencing this on (or is it everywhere)?
     
  6. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    57
    This is happen on the device itself. Android, on different mobiles.
     
  7. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi @Femidko ,
    I'm sorry that I can't reproduce it on my side. I'm using Unity 1.17.0 and Unity 2017.2.0f3.
    Could you please post the full log?

    Regarding the DuplicateTransaction error, have you consumed that specific product?
    If you haven't, that should be expected behavior. You can only buy a consumable product again after you consume it.
    You can call m_Controller.ConfirmPendingPurchase() to consume a product.

    This is my test log for buying a product again without consuming.
     
  8. qd19218960

    qd19218960

    Joined:
    Oct 15, 2015
    Posts:
    3
    if use payload on ios it happen, roll back to 1.16.0 will be fine.
     
  9. Femidko

    Femidko

    Joined:
    Aug 4, 2013
    Posts:
    57
    Unity 5.6.5f1 as I said.

    On Unity 2017.x play-games-plugin-for-unity authentication callback function does not called. I'm just shocked. Such serious organizations allow such errors in releases (solvable with the usual unit-test). Please forgive me for the offtopic.
     
  10. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
  11. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi @qd19218960 ,
    I also tried to reproduce it on iOS, but couldn't make it happen.
    Which version of Unity are you using?
    Can you reproduce it in a new project?
     
  12. qd19218960

    qd19218960

    Joined:
    Oct 15, 2015
    Posts:
    3
    Unity 5.6.5p3
    IAP 1.18.0
    Log :

    UnityIAP: JSONStore exception handling developerPayload: System.InvalidCastException: Cannot cast from source type to destination type.
    at UnityEngine.Purchasing.JSONStore.Purchase (UnityEngine.Purchasing.ProductDefinition product, System.String developerPayload) [0x00000] in <filename unknown>:0
    UnityEngine.Purchasing.PurchasingManager:InitiatePurchase(Product, String)
    RGame.SDK.PurchasingManager:OnPurchase(PurchasingIDVO, String) (at Assets/Scripts/sdk/Purchasing/Abroad/PurchasingManager.cs:345)
     
  13. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi @qd19218960 ,

    I'm using exactly same versions but still couldn't make it happen.
    Have you tried it in a new project?
    Could you please send me a test project which could reproduce this issue?
    If you don't want to send it here, you can open a support ticket.
    https://analytics.cloud.unity3d.com/support/
    Thank you.
     
  14. kevinatgame

    kevinatgame

    Joined:
    Aug 31, 2015
    Posts:
    8
    same issue occures here, just checked the change log of unity iap plugin:
    ## [1.19.0] - 2018-04-17
    ### Added
    - For GooglePlay store, `developerPayload` has been encoded to base64 string and formatted to a JSON string with two other information of the product. When extract `developerPayload` from the product receipt, firstly decode the json string and get the `developerPayload` field base64 string, secondly decode the base64 string to the original `developerPayload`.

    this is ridiculous!
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446