Search Unity

Android promo-code works every time player starts the game.

Discussion in 'Unity IAP' started by Leonid, Apr 1, 2021.

  1. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    90
    Hello!
    I'm getting very strange behaviour on IAP plugin 2.1.0 and 2019.4.6f1 with stock purchasing code.
    I have a product "product250Gold" which normally ads 250 gold after purchasing. I also have promo-codes created for this product. The product itself is initialized as Consumable:
    Code (CSharp):
    1. builder.AddProduct(product250Gold, ProductType.Consumable, new IDs() { { product250GoldApple, AppleAppStore.Name }, { product250GoldGoogle, GooglePlay.Name } });
    Here is the strange thing: If player redeems a promo code with this product he/she gets 250 gold every time the game is launched! Even after game is deleted and re-installed.
    Could you please help me to fix this issue?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Are you receiving a ProcessPurchase call IAP initialization for this product? Please show your code for ProcessPurchase. I personally have not tested promo codes.
     
  3. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    90
    Thanks for the quick response!
    Yes, I do receive ProcessPurchase call, it is the only way to add Gold, and gold amount is increasing every launch.
    Here is my code:
    Code (CSharp):
    1.         public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    2.         {
    3.             bool validPurchase = true; // Presume valid for platforms with no R.V.
    4. #if !UNITY_EDITOR
    5. #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
    6.             var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
    7.  
    8.             try
    9.             {
    10.                 var result = validator.Validate(e.purchasedProduct.receipt);
    11.  
    12.                 foreach (IPurchaseReceipt productReceipt in result)
    13.                 {
    14.                     GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
    15.                     if (null != google)
    16.                     {
    17.                         //Debug.Log(google.purchaseState);
    18.                         //Debug.Log(google.purchaseToken);
    19.                     }
    20.  
    21.                     AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt;
    22.                     if (null != apple)
    23.                     {
    24.                         //Debug.Log(apple.originalTransactionIdentifier);
    25.                     }
    26.                 }
    27.             }
    28.             catch (IAPSecurityException ex)
    29.             {
    30.                 validPurchase = false;
    31.                 return PurchaseProcessingResult.Complete;
    32.             }
    33. #endif
    34. #endif
    35.  
    36.             if (validPurchase)
    37.             {
    38.                 // Unlock the appropriate content here.
    39.                 if (String.Equals(e.purchasedProduct.definition.id, product250Gold, StringComparison.Ordinal))
    40.                 {
    41.                     //Some code to add 250 gold
    42.                 }
    43.             }
    44.  
    45.             return PurchaseProcessingResult.Complete;
    46.         }
     
  4. rokmckang

    rokmckang

    Joined:
    Apr 21, 2020
    Posts:
    6
    I have the same problem. You can selectively apply in-app products and redeem promotional codes. When the product is purchased at the store, "This product is already owned" appears, and when the app is initialized and restarted, the item entered as the promotion code in the public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e) function continues to appear at the same time as the IAP initialization. What should I do?
     
  5. Olegleg

    Olegleg

    Joined:
    Mar 30, 2021
    Posts:
    47
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  8. rokmckang

    rokmckang

    Joined:
    Apr 21, 2020
    Posts:
    6
    I received an in-app product reward with a promotional code, and when I checked the receipt, there is no orderID. In case it is not consumed because of this, it continues PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
    Is the function being called? Is it not related?
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Interesting. Do non-promo products work as expected? Are you returning Complete from ProcessPurchase?
     
  10. rokmckang

    rokmckang

    Joined:
    Apr 21, 2020
    Posts:
    6
    For in-app products that are not promotional products, there is no problem if you return Complete from ProcessPurchase.
    However, in the case of an in-app product registered as a promotional product, there is no OrderID in the receipt, and even if ProcessPurchase returns Complete, the problem is that the ProcessPurchase function is called and the corresponding promotional product continues to enter when the application is rerun.
     
  11. rokmckang

    rokmckang

    Joined:
    Apr 21, 2020
    Posts:
    6
    Please understand that I am not good at English.
    In summary
    1. Register one of the in-app products registered in the app as a promotional reward product.
    2. Enter the promotion code to receive the reward product from the app through the ProcessPurchase function and return Complete.
    3. There is no OrderID when checking receipt in ProcessPurchase function.
    4. Whenever the app is closed and run again, IAP is initialized and the promotional reward product is continuously displayed through the ProcessPurchase function.
    5. There is no problem when purchasing other products sold in the app that are not promotional reward products.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, so the answer is yes. We are checking.
     
  13. Olegleg

    Olegleg

    Joined:
    Mar 30, 2021
    Posts:
    47
    "No OrderID" is expected behaviour for promo codes:
    https://developer.android.com/google/play/billing/integrate
    "For one-time products, every purchase creates a new purchase token. Most purchases also generate a new Order ID. The exception to this is when the user is not charged any money, as described in Promo codes."
    https://developer.android.com/google/play/billing/security
    "Note: Do not use orderId to check for duplicate purchases or as a primary key in your database, as not all purchases are guaranteed to generate an orderId. In particular, purchases made with promo codes do not generate an orderId."
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Correct, we are continuing to test this feature.
     
  15. studiolumiere_unity

    studiolumiere_unity

    Joined:
    Apr 24, 2020
    Posts:
    21
    Hello I am using the 2019.4.16f1 LTS version and I am experiencing the same phenomenon. Need a quick fix.
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry a quick fix is not available. We are working on a tested solution however and should be available soon.
     
  17. studiolumiere_unity

    studiolumiere_unity

    Joined:
    Apr 24, 2020
    Posts:
    21
    Thank you
     
  18. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    90
    Hello!
    Could you please confirm if this bug is fixed in versions 3.1.0 and 2.2.8?
     
  19. rokmckang

    rokmckang

    Joined:
    Apr 21, 2020
    Posts:
    6
    On April 1st, the item received as a promotional code was updated to IAP version 2.2.8 and ran again, and the item is still coming in.
     
  20. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We have not addressed the issue yet, you'll see the mention in the release notes. It's still several weeks out.
     
    Leonid likes this.
  21. Leonid

    Leonid

    Joined:
    Aug 20, 2013
    Posts:
    90
    So 3.2.1 is released, no mention of the fix in the release notes unfortunately.
    I guess I'll have to stop using promo-codes for now.
     
  22. WilliamOD

    WilliamOD

    Unity Technologies

    Joined:
    May 31, 2021
    Posts:
    16
    Hi, I have looked into your problem and the issue should be fixed in the next release.

    In the meantime, a workaround would be to consume the products yourself with Google's ConsumeAsync API. Have a great day!
     
    Last edited: Jun 3, 2021
    Leonid likes this.
  23. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    @WilliamOD, is the fix coming to Iap Package 2.x (Unity 2018) as well?
     
  24. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No, moving forward any updates will be in the 3.x branch
     
  25. rokmckang

    rokmckang

    Joined:
    Apr 21, 2020
    Posts:
    6
    IAP update 2.3.0 does not work.
    The problem still occurs.
    May I know what is the current progress?
     
  26. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The update is ready, we are waiting on the Package Manager release process. Hopefully within the next couple of days.
     
  27. WilliamOD

    WilliamOD

    Unity Technologies

    Joined:
    May 31, 2021
    Posts:
    16
    The IAP 3.2.3 update contains the fix:)
     
    Leonid likes this.