Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question IAP receipt validation : Send it to the test environment instead.

Discussion in 'Unity IAP' started by matthieu_unity674, Feb 9, 2023.

  1. matthieu_unity674

    matthieu_unity674

    Joined:
    Jun 21, 2022
    Posts:
    4
    TLDR : How to get rid of the Send it to the test environment instead. error message when redeeming an IAP ?
    _______________________

    Hi,

    Since a few days, I'm triying to integrate IAP in my game.
    Basically, I just want to sell 3 packs of gems (consumable then).

    I don't really know what to begin with as I tried so many stuff for this few days but I'll start with the error I'm currently facing. Note that I'm going a cross platform integration but for now testing on iOS device.

    Here is my current code integration :

    Code (CSharp):
    1.  
    2. // Init IAP
    3. public void InitIAP () {
    4.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    5.         builder.AddProduct("50_gems", ProductType.Consumable);
    6.         builder.AddProduct("100_gems", ProductType.Consumable);
    7.  
    8.         UnityPurchasing.Initialize(this, builder);
    9.     }
    10.  
    Code (CSharp):
    1.  
    2. // Process purchase
    3. public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
    4. {
    5.     var wrapper = (Dictionary<string, object>)MiniJson.JsonDecode(e.purchasedProduct.receipt);
    6.     string payload = "";
    7.     if (wrapper != null) {
    8.         payload = (string)wrapper["Payload"];
    9.     } else {
    10.         Debug.Log("wrapper null");
    11.     }
    12.  
    13.     Redeem(payload);
    14.  
    15.     return PurchaseProcessingResult.Complete;
    16. }
    17.  
    Code (CSharp):
    1.  
    2. private async void Redeem(string payload) {
    3.         try {
    4.             #if UNITY_IPHONE
    5.                 RedeemAppleAppStorePurchaseArgs args = new("50_GEMS", payload, 49, "EUR");
    6.                 RedeemAppleAppStorePurchaseResult result = await EconomyService.Instance.Purchases.RedeemAppleAppStorePurchaseAsync(args);
    7.                 Debug.Log(result);
    8.             #endif
    9.             #if UNITY_ANDROID
    10.                 RedeemAppleAppStorePurchaseArgs args = new("50_GEMS", payload, 49, "EUR");
    11.                 RedeemAppleAppStorePurchaseResult result = await EconomyService.Instance.Purchases.RedeemGooglePlayPurchaseAsync(args);
    12.             #endif
    13.             ok.SetActive(true);
    14.             Debug.Log("Redeem succeed");
    15.             Debug.Log(result.Verification.Status);
    16.             Debug.Log(result.Rewards.Currency.Count);
    17.             Debug.Log(result.Verification.Store.Code);
    18.             Debug.Log(result.Verification.Store.Message);
    19.         } catch (EconomyAppleAppStorePurchaseFailedException err) {
    20.             ko.SetActive(true);
    21.             errorMessage.text = err.Data.Verification.Store.Message;
    22.             Debug.Log("Catch error in redeem");
    23.             Debug.Log(err.Data.Verification.Status);
    24.             Debug.Log(err.Data.Verification.Store.Code);
    25.             Debug.Log(err.Data.Verification.Store.Message);
    26.         }
    27.     }
    28.  
    With this current configuration, I'm always falling into the catch in the redeem function, err.Data.Verification.Store.Message giving me :

    This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.


    Given I'm not receiving the NoProductsAvailable error on initialize I assume that my Apple configuration is alright (see https://docs.unity3d.com/Packages/com.unity.purchasing@4.1/manual/AppleTesting.html).

    I'm receiving the same error when I'm building on my phone with xcode and when I release on TestFlight.
    However I noticed that on App Store Conenct TestFlight section, the last release that I opened to "External testers" is still Waiting for review.

    Capture d’écran 2023-02-09 à 14.10.44.png

    Is there by any chance a chance that IAP does not work if Apple did not review the application yet ? Even in test mode ?

    I'm linking images of my configuration in the App Store Connect IAP section and UGS Economy configuration. Capture d’écran 2023-02-09 à 14.16.57.png

    Capture d’écran 2023-02-09 à 14.15.25.png


    I try the app both on my usual AppleID account and Sandbox user.

    I red about the StoreKit tool in xcode and I tried to use it with the proper configuration but I'm getting the "No product available" error message.

    I think I'm quite exhaustive on the informations I provided. Sorry if this is not really comprehensible, I am quite lost if all of this integration.

    Thank you for your help !
     
  2. glenhunter

    glenhunter

    Unity Technologies

    Joined:
    Apr 2, 2019
    Posts:
    92
    Hi there! You will need to submit and get your application accepted with your first in-app purchases already integrated for IAP to work for subsequent IAP additions you should not have to upload a new build.
     
    Arnaud_Gorain likes this.
  3. matthieu_unity674

    matthieu_unity674

    Joined:
    Jun 21, 2022
    Posts:
    4
    Hi ! Thank you for your reply.
    I find this really strange to submit the app to production environnement without doing any tests on the integration of the IAP in the game's flow but I'm surely going to try this then.

    Thanks again !
     
  4. pixel_pps

    pixel_pps

    Joined:
    Sep 21, 2022
    Posts:
    3
    This looks like iOS documented feature. First you verify against production environment sending receipt to https://buy.itunes.apple.com/verifyReceipt. But if you try verify sandbox payment then response from this environment has specify error code that mean this payment is from sandbox and muss be verified on sandbox environment https://sandbox.itunes.apple.com/verifyReceipt. Thats all. Look apple in app documentation for more info
     
  5. MichaelHSP

    MichaelHSP

    Joined:
    Jul 22, 2023
    Posts:
    1
    I am trying to set up RedeemGooglePlayStorePurchaseArgs but I keep getting an error with the receipt on a internal test build from google play console, could you assist me please? Here is the code:
    Code (CSharp):
    1. var receipt = JsonUtility.FromJson<GooglePlayReceipt>(purchasedProduct.receipt);
    2.  
    3.         // Extract the necessary data from the receipt
    4.         string purchaseData = receipt.Payload; // or other appropriate field
    5.         string purchaseDataSignature = receipt.TransactionID; // or other appropriate field
    6.         int localCost = (int)(purchasedProduct.metadata.localizedPrice * 100);
    7.         string localCurrency = purchasedProduct.metadata.isoCurrencyCode;
    8.  
    9. try{
    10. RedeemGooglePlayStorePurchaseArgs args = new RedeemGooglePlayStorePurchaseArgs(purchaseID, purchaseData, purchaseDataSignature ,localCost, localCurrency)
    11. await EconomyService.Instance.Purchases.RedeemGooglePlayPurchaseAsync(args);
    12.             debugMsg += "Succesful redeemed Gooogle play purchase";
    13.             Debug.Log($"Successfully redeemed Google purchase");
    14.         }
    15.         catch (EconomyGooglePlayStorePurchaseFailedException e)
    16.         {
    17.             Debug.LogError(e);
    18.         }
    19. }