Search Unity

Unity IAP Store Guides - Amazon, Apple, Google Play, Windows

Discussion in 'Unity IAP' started by nicholasr, Dec 8, 2015.

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

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Yes, obviously but that's the exact point I'm making. The ID is said to be store independent in your documentation but in reality it's not.

    Code (CSharp):
    1. builder.AddProduct("Money1", ProductType.NonConsumable, new IDs
    2.                 {
    3.                     {"gold1", GooglePlay.Name},
    4.                     {"GoldOne", WinRT.Name}
    5.                 });
    If it was store independent it shouldn't matter what I add as the first parameter string, it should only matter what I add in the specific cases for the Purchasing.IDs storeIDs

    If I'm required to add the same thing in the first string and the two later then how can I do something store independent?
     
  2. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Having investigated the Windows store ID issue I can confirm that declaring a store specific ID for 'WindowsPhone8.Name' would result in the wrong ID being used at runtime - this was a bug.

    Furthermore, having both 'WinRT.Name' and 'WindowsPhone8.Name' was confusing, given that Microsoft product IDs are universal across phone and desktop when making Universal builds.

    I have released version 1.2.2 of our store packages that deprecates WinRT.Name and WindowsPhone8.Name and introduces WindowsStore.Name as their replacement.

    You can update your project by going to the IAP cloud service window and selecting 'import' to reimport our store packages.

    @Nihil688 were you declaring a store specific ID using 'WinRT.Name' or 'WindowsPhone8.Name'? The former should have worked, the latter would not.
     
  3. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Right, I tested predominantly on Windows Universal 10 and the windows store made it backwards compatible with windows 8 which made it work.

    Mind you I did get a warning from Windows Store:
     
  4. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    I'm not sure why Microsoft would generate that warning, it seems to be an error on their part.
     
  5. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    Hi @nicholasr ,

    You suggest something like this:
    Code (CSharp):
    1. private void SendInfoToUnityAN()
    2.         {
    3.             Analytics.CustomEvent("RealMoneyPurchase", new Dictionary<string, object>
    4.         {
    5.              { "customSegment", _customSegmentParameter},
    6.              { "prodID", "coins"},
    7.              { "price", "25" }
    8.         });
    9. }
    *And the result will be => RealMoneyPurchase "coins" "25" ?

    Thanks in advance!
     
  6. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    @D0R1N Correct - once Analytics has time to collect and process the data (about six hours) the `RealMoneyPurchase` Custom Event will be available in the Data Explorer for your project at analytics.unity3d.com. You'll be able to see the values set into the keys `customSegment`, `prodID`, and `price`.
     
    RoyalCoder likes this.
  7. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Hi, I add init to my script:

    Code (CSharp):
    1. void InitializePurchasing() {
    2.     var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    3.  
    4.     builder.AddProduct(FULL_VERSION_ID, ProductType.NonConsumable);
    5.  
    6.     UnityPurchasing.Initialize(this, builder);
    7. }
    But when I run it in iOS device i get error: "NoProductAvailable".
    ID is true and registered in iTunesConnect. I tried and new IDS() method.
    I tried to on Dev mode, tried to change id but I have not more power... Help plz!
     
  8. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Have you been through the checklist here? Are you testing using an ituned connect test user account?
     
  9. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Advise

    What does it means:
    • Products must be cleared for sale in iTunes Connect
    • It may take many hours for newly created iTunes Connect products to be available for purchase

    I added the product to itunes connect:

    ER.png

    And done Init in controller which loading with store scene:

    IC.png

    But I taking the same error: "NoProductsAvailable".

    Help. Thanks!

    P.S. App is in TestFlight. And I log out from iTunes store. Sandbox user needed for purchase not for initialization.
     
  10. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    You are logged out of the App store before you launch your App?

    Can you DM me your product IDs if you are not happy to share them here?
     
  11. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Hi,

    Im having some difficulties with this plugin. already setup it as the guide say,have a beta published with an item, the unity editor say pass when i test it, my item and my id in google play and unity are the same. but the popup never show up...
    I tested it many times.

    any light?
     
  12. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Please take and attach a trace using adb, from when your application starts up and attach it to this thread.
     
  13. resetme

    resetme

    Joined:
    Jun 27, 2012
    Posts:
    204
    Sorry, it's working nicely, looks like my co worker updated a new version to google developer and it was in publishing again.

    Feel really ashamed to bother you.

    Just to other people, i see many tutorials about this and they upload the test apk in alpha open, the test apk also work in beta close.
     
    nicholasr likes this.
  14. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @resetme,

    No need to feel ashamed, that's what the forums are here for! Glad it's all working now!
     
    nicholasr likes this.
  15. Duobix

    Duobix

    Joined:
    Dec 6, 2014
    Posts:
    52
    Hi there, I'm trying to get IAP working on WP8.1.
    We got all the packages ID in app, we got the proper c# code, we got the proper packs on WP store set up.
    The thing is, that everytime we try to start the app on WP8.1, we get this:

    UnityIAPWin8:Exception loading listing information:Exception from HRESULT: 0x805A0194

    Could someone please decode this machine jibberish into some human-readable and fixable form? Thanks in advance.
     
  16. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Have you installed your Application from the store, not sideloaded from visual studio?
     
  17. Duobix

    Duobix

    Joined:
    Dec 6, 2014
    Posts:
    52
    We've pushed the app to store before, but the in-app purchases still don't show up, and we have no idea why.
     
  18. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    But have you installed the app from the store to do your testing?
     
  19. Duobix

    Duobix

    Joined:
    Dec 6, 2014
    Posts:
    52
    The above exception was provided from Visual Studio test.
    We've perfmormed testing on the app from the store also, with no results from shop also - should we look more into it?
     
  20. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    This error suggests that your App ID is not known. If you are sure your details are correct I suggest filing a support ticket with Microsoft.
     
  21. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Hey there !
    Any one here to help?
    I am getting an IAP not initialized error on both iOS and android. I have followed exactly the same code from the tutorial, Any fixes? :(
     
  22. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    I'm having a terrible issue in iOS. Every time the user restarts the app Unity's IAP loses the purchase receipt from non-consumable items the user got. So I'm having to force my users to "Restore Purchases" every time the app runs anew.

    The documentation for Product.receipt states: "Consumable receipts are not saved between app restarts.". Which obviously should mean that non-consumable receipts ARE saved between restarts. Only they are not. When testing in Sandbox mode I figure it was an issue there, but it's still happening on the actual App Store.

    I ask first that you implement this correctly. Receipts for non-consumables SHOULD be persisted between restarts, just like Unibill used to do and Prime31 does (and like your docs imply you would).

    Secondly, if that doesn't happen in the next patch, that you document a proper way to verify with the app's receipt. How that is not part of these guides is beyond me.
     
  23. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    Hey @Adnan2012 ! Sorry to hear about the initialization failure. Generally the application logs on iOS and Android will shed useful light on the issue, and similarly so will the value of the initialization result parameter (InitializationFailureReason) passed into `OnInitializeFailed`.

    Would you be game to share some text from those logs here, and also paste the failure parameter's value?

    @LotusBlack What devices / OS versions are you seeing purchase restoration failure on?

    The Apple Sandbox service supports purchase restoration.

    Unity IAP persists non-consumable purchases in a device-local transaction log.

    Is the game returning
    `PurchaseProcessingResult.Complete` from its `ProcessPurchase` implementation?
     
  24. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Hi Nicholasr Sir!
    Thanks allot for answering my query. Bad of me, I was actually wasn't doing alpha testings stuff properly. Working fine now super thanks.
    I was just curios to know about the consumable products in Unity IAP. How does unity handle it as Google Play Managed IAP?
    • If you are using the Version 3 API, you can also consume managed items within your application. You would typically implement consumption for items that can be purchased multiple times (such as in-game currency, fuel, or magic spells). Once purchased, a managed item cannot be purchased again until you consume the item, by sending a consumption request to Google Play.
      http://developer.android.com/google/play/billing/api.html
    How Unity is sending consumption request? If it's sending!
     
  25. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Unity IAP sends the consumption request when you return PurchaseProcessingResult.Complete from your ProcessPurchase method, or, if you return PurchaseProcessingResult.Pending, when you call IStoreController.ConfirmPendingPurchase at a later date.
     
  26. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @LotusBlack Sorry, the docs need clarification here.

    Apple provides a single receipt for the whole application. When a product is purchased, that receipt is associated with the product that was purchased, but that association does not persist between App restarts.

    To determine what a player is entitled to on Apple stores you should parse the App receipt, within which is a list of product Ids that the player has bought.

    We have been working on a library to help with validating and parsing Apple receipts, which should launch this week. I will update this thread when it does.
     
  27. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    @Banderous Glad to hear, I actually implemented the simplest workaround I could think as a contingency issue, if anyone else is wondering: I'm saving to PlayerPrefs a string with the App Store ID when a PurchaseProcessed event happens (it can happen from a RestoreTransactions too, so that's good).
     
  28. Ravshan

    Ravshan

    Joined:
    Apr 20, 2015
    Posts:
    3
    Hello,
    I just can't find any info about how to retrieve price from store using Unity IAP
    Is it possible?
    Thank you
     
  29. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    p.metadata.localizedPriceString

    Where p is a Product object from IStoreController.products.all

    [edit]Oh, you can also use p.metadata.localizedPrice, for a decimal value instead of a string.[/edit]
     
  30. Ravshan

    Ravshan

    Joined:
    Apr 20, 2015
    Posts:
    3
    oh, got it
    Thanks a lot)
     
  31. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @LotusBlack Version 1.3.0 of our store packages is now available, installable via the IAP cloud service window. It features a receipt validation and parsing library documented here which you can use to determine what a user is entitled to in an Apple or Google purchase receipt.
     
  32. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    @Banderous Excellent! I do have a question about how the receipt works though: I noticed that if I call IAppleExtensions.RefreshAppReceipt, I get a trigger for iTunes login, just as if I tried to RestoreTransactions. But shouldn't RestoreTransactions also refresh the receipt itself? So what's the diff between the two?

    And is the receipt cached somehow after each purchase the user makes by Unity?

    Correct me if I'm wrong, but the way I see it working is that I only call RefreshReceipt/RestoreTransactions on a fresh install? And then validate purchases each time the app runs, using the cached receipt?
     
  33. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Yes, I believe restore transactions and refresh transactions are very similar in how Apple implements them; the authentication is required to fetch the signed receipt from Apple's servers. The difference with restore transactions is that the transactions are then replayed.

    You can read the app receipt from local storage, as you suggest. That doesn't need any authentication.
     
  34. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    @Banderous Since I got your attention... :)

    Wouldn't it now be the natural evolution to have the Unity IAP lib just run these validators behind the scenes and to us users we'd just check each non-consumable product in our list with .hasReceipt to unlock the IAPs?

    That's how it's working for Android right now, so I assume it's in your to-do with Apple?
     
  35. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @LotusBlack @Fattie There is a risk in making Unity IAP 'authoritative' - we want to avoid providing a single target for cracking tools that will unlock IAPs in every Unity game.

    We are already running that risk by providing this reference receipt validation implementation, which is why we will be open sourcing it - so that others can modify it and increase the diversity of implementations.

    Consider Apple's receipt validation strategy which is simply to provide a specification for their receipt format and a high level overview of how to validate it - there is no reference implementation.

    I'm afraid I don't have a list of volume Unity IAP customers at present.
     
  36. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    Hey again @Banderous !

    Is it not how the lib is working for Android right now? Apparently on Android .hasReceipt is returning true, even after restarting the app and not restoring purchases. Or is there some behind-the-scenes difference that eludes me?

    Also, another concern about the lib in general:

    The way it is now, it does not initialize properly without internet connection, correct? But why? Don't we have the cached receipts and don't we feed in the products to the ConfigurationBuilder anyway?

    So it could probably succeed with a warning in the case where the player has no active internet connection and just say the prices can't be fetched (and purchases obviously fail), but otherwise work off of the cached receipts.
     
  37. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Hi @LotusBlack-- don't forget, Android sort of "automatically" restores purchases, as do other stores. it's only Apple where you have to explicitly restore purchases.

    indeed if you scroll down to `RestorePurchases()` in the excellent example code http://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game-beta

    it's basically only for Apple, it skips out otherwise. our kodes..

    Code (CSharp):
    1.     // note Apple (alone) currently requires explicit purchase restoration
    2.     public void RestorePurchases()
    3.         {
    4.         if (!IsInitialized())
    5.             {
    6.             Debug.Log("RestorePurchases fail, not initialized. Try later?");
    7.             return;
    8.             }
    9.  
    10.         if ( Application.platform != RuntimePlatform.IPhonePlayer && Application.platform != RuntimePlatform.OSXPlayer)
    11.             {
    12.             Debug.Log("RestorePurchases, it is NOT necessary to restore purchases on " + Application.platform);
    13.             return;
    14.             }
    15.  
    16.         Debug.Log("Since this is an Apple device, restoring purchases explicitly...");
    17.         var apple = iExtensionProvider.GetExtension<IAppleExtensions>();
    18.         apple.RestoreTransactions((result) =>
    19.             {
    20.             Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    21.             });
    22.         }
    BTW. I've never seen any reason not to simply: always call for restore whenever the app is actually launched. Users rarely launch apps, they just put them to the background. I think it's actually reassuring to users to see that it's explicitly picking up their unlocks and dragon clothes, when they do a full-open of the app.
     
    Last edited: Mar 8, 2016
  38. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @LotusBlack Google Play features its own cache, so will typically initialise even if you don't have Internet connectivity.

    On Apple stores you can read the app receipt from the device storage regardless of Internet connectivity.

    @Fattie Thanks! Unity IAP adds the relevant permissions and activity on Android (they're in the GooglePlay.aar), on Apple stores it links in the storekit framework using the plugin importer settings. I'm not aware of plist modifications on iOS, though they are on the Mac App store.

    Unity merges together the manifests of all the different android archives in your project. If other plugins have elements in their manifests they will be merged into the final app manifest.
     
  39. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    You don't need to explicitly tell Unity IAP what your product ID is on every platform:

    Unity IAP assumes this product is called "GREENEGGS" on every platform.

    If you add a different store specific ID for a specific platform, it will still be known as "GREENEGGS" on all the other platforms.

    Also from this snippet:

    Code (CSharp):
    1. private void PurchaseSUCCESSFULpidknown( string PID )
    2. {
    3.         if (consumables.Contains(PID)) { SuccessCONSUMable(PID); return; }
    4.         if (nonconsumables.Contains(PID)) { SuccessNONconsumable(PID); return; }
    5. }
    6.  
    You don't need to keep a list of what is consumable or non consumable, the type of the purchase is available on the purchase arguments:

    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2. {
    3.     Debug.Log(args.purchasedProduct.definition.type);
    4.     // ...
    5. }
     
  40. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    "You don't need to explicitly tell Unity IAP what your product ID is on every platform"

    Ahh! beautiful. So to be clear, say I do precisely this

    Code (CSharp):
    1. builder.AddProduct(
    2.    "localCode", // probably the same, i.e.: "JELLYBOMBS"
    3.    ProductType.Consumable, // or one of the other two
    4.    new IDs(){{ "JELLYBOMBS", AppleAppStore.Name }, });
    5.            // notice I happened to use AppStore, and only gave ONE store
    6.  
    - notice I happened to use only ONE of the stores
    - I assume it does not matter WHICH store I happened to use

    Result, `builder` now assumes JELLYBOMBS is available in ALL stores. (And indeed the code is "JELLYBOMBS" in all stores.)

    This is quite correct?

    Is there an issue with ... what if some items are not available in some stores? Does the system inherently believe "each item, should be in all stores"? (For the record, I would firmly agree that is how the system should work. I can't see any reason one would have something not available in one store or the other.)

    ----

    "You don't need to keep a list of what is consumable or non consumable, the type of the purchase is available on the purchase arguments:"

    Brilliant. I have to start reading these "A P I" things one day :O
     
  41. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Code (CSharp):
    1. builder.AddProduct("JELLYBOMBS", ProductType.Consumable);
    Then just create your product as 'JELLYBOMBS' in every store. If it has to be different for some reason on one or more stores, then you need to provide the overrides on those stores.
     
  42. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Ahh! For goodness sake - if only I'd looked at the doco

    Contents/Documentation/en/ScriptReference/Purchasing.ConfigurationBuilder.AddProduct.html

    With this call
    it does in fact make the local ID the same as the store ID.

    (Since Android is only lowercase, for anyone first making IAP in Apple, it's best to go with lowercase in Apple - then they are all the same.)

    So, so long as your Apple and Android ids are the same (and hence, all lowercase since PlayStore is only lowercase), you can just do this

    Code (CSharp):
    1. builder
    2.    .AddProduct("manyjellybombs", ProductType.Consumable)
    3.    .AddProduct("bigdragons", ProductType.NonConsumable)
    4.    .AddProduct("lasertoes", ProductType.NonConsumable);
    and that's the end of it. The local code is then the same as (both) app stores. Awesome.
     
  43. OnurYIL

    OnurYIL

    Joined:
    Nov 4, 2013
    Posts:
    140
    Hello everyone!

    I'm trying to implement IAPs to my Windows 10 game. Everything works fine at the editor, 0 errors, succesful purchases. But when I debug the project through Visual Studio on my local computer, I get a NullReferenceError.

    Now the Visual Studio debugger does not show where the error is, but I was sure I didn't have such error BEFORE I started to implement IAPs so I slowly disabled parts of the IAPDemo.cs code which came with the imported files through services.



    If I comment out the highlighted part, my game works fine. If I let it run, I get a NullReferenceException.

    Anyone knows whats up?

    Unity version 5.3.1f1.

    Thank you for the help!
     
  44. Nitin_CMLABS

    Nitin_CMLABS

    Joined:
    Jul 10, 2015
    Posts:
    15
    Hello, I am getting issue in Initializing the product id at Unity Window's IAP store while it's working fine in Unity_Editor but getting issue when i export it for Window 10 and run from visual studio 2015.

    Code for Initializing is :


    public void InitializePurchasing()
    {
    // If we have already connected to Purchasing ...
    if (IsInitialized())
    {
    // ... we are done here.
    return;
    }

    var module = StandardPurchasingModule.Instance();

    // Create a builder, first passing in a suite of Unity provided stores.
    var builder = ConfigurationBuilder.Instance(module);

    // Add a product to sell / restore by way of its identifier, associating the general identifier with its store-specific identifiers.
    builder.AddProduct(kProductIDConsumableGrassStack500, ProductType.Consumable, new IDs(){{ kProductIDConsumableGrassStack500, WindowsStore.Name }});// Continue adding the non-consumable product.
    builder.AddProduct(kProductIDConsumableGrassStack1500, ProductType.Consumable, new IDs(){{ kProductIDConsumableGrassStack1500, WindowsStore.Name }});// Continue adding the non-consumable product.
    builder.AddProduct(kProductIDConsumableGrassStack3000, ProductType.Consumable, new IDs(){{ kProductIDConsumableGrassStack3000, WindowsStore.Name }});// Continue adding the non-consumable product.
    builder.AddProduct(kProductIDConsumableGrassStack5000, ProductType.Consumable, new IDs(){{ kProductIDConsumableGrassStack5000, WindowsStore.Name }});// Continue adding the non-consumable product.
    builder.AddProduct(kProductIDConsumableGrassStack10000, ProductType.Consumable, new IDs(){{ kProductIDConsumableGrassStack10000, WindowsStore.Name }});// Continue adding the non-consumable product.
    builder.AddProduct(kProductIDNonConsumableRemoveAd, ProductType.NonConsumable, new IDs(){{ kProductIDNonConsumableRemoveAd, WindowsStore.Name }});// And finish adding the subscription product.
    UnityPurchasing.Initialize(this, builder);
    }


    Do i need to setup some setting in Unity or need to edit the code?
     
  45. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    Say @Banderous and guys,

    just to be clear, adding ANALYTICS to a project, does NOT add any libraries or packages (we can see in Project), is that right?

    I got confused: I stripped everything out of a project and was re-adding it. For IAP indeed it adds

    /Plugins/UnityPurchasing/

    folder. However to turn on only Analytics, it adds ... nothing? That's all correct? Cheers
     
  46. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
    Hey @Fattie,

    That is correct, when enabling Analytics from the Services window in the editor no libraries or packages are added to your project since Analytics is now integrated directly into the editor starting from version 5.2.
     
  47. kogen

    kogen

    Joined:
    Dec 2, 2015
    Posts:
    6
    Hey guys,

    so I'm also struggling with the same problem Lotus was describing two weeks earlier: The non-consumable product has been bought. The iTunes store knows I bought it, it's all fine unless I restart my application. Then the product is gone, I cannot rebuy it, since iTunes knows it already has been bought and the world is sad. :(

    So when I get it right, I would call this code for iOS after the Purchasor has been initialized?


    Code (CSharp):
    1. #if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_TVOS
    2. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    3. // Get a reference to IAppleConfiguration during IAP initialization.
    4. var appleConfig = builder.Configure<IAppleConfiguration>();
    5. var receiptData = System.Convert.FromBase64String(appleConfig.appReceipt);
    6. AppleReceipt receipt = new AppleValidator(AppleTangle.Data()).Validate(receiptData);
    7.  
    8. Debug.Log(receipt.bundleID);
    9. Debug.Log(receipt.receiptCreationDate);
    10. foreach (AppleInAppPurchaseReceipt productReceipt in receipt.inAppPurchaseReceipts) {
    11. if (productReceipt.productID == "myAppleID")
    12. {
    13. startMyFunctionForActivatingTheNonConsumable();
    14. }
    15.     Debug.Log(productReceipt.transactionIdentifier);
    16.     Debug.Log(productReceipt.productIdentifier);
    17. }
    Or am I getting something wrong here?
     
  48. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Yes, that ought to work assuming your product ID is correct. I suggest you debug log details of every product in the receipt to see what it contains and ensure you are checking for the right ID.
     
    nicholasr and erika_d like this.
  49. kogen

    kogen

    Joined:
    Dec 2, 2015
    Posts:
    6
    Okay I have to test that on iOS. I have another question concerning the receipt-validation on Google.
    I checked it pretty simple before like "if the purchaser is initialized and has the specific product ID, then switch on the non consumable product."
    Then I wrote your topic about validation and now I'm running into problems, since I don't know what exactly I should validate here. I took this code
    Code (CSharp):
    1.     public void testfunctionAfterInitialize()
    2.     {
    3.         // Unity IAP's validation logic is only included on these platforms.
    4.     #if UNITY_ANDROID
    5.         // Prepare the validator with the secrets we prepared in the Editor
    6.         // obfuscation window.
    7.         var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
    8.             null, Application.bundleIdentifier);
    9.  
    10.         try {
    11.             // that's the line I don't think I'm correct here can I do this with the validator that has a "null" value for the AppleTangle.Data()?
    12.             var result = validator.Validate(m_storeController.products.withID("myProductID").receipt);
    13.             if (result != null)
    14.             {
    15.                 this.startReCreationFunction();
    16.             }
    17.             }
    18.             // Unlock the appropriate content here.
    19.         } catch (IAPSecurityException) {
    20.             Debug.Log("Invalid receipt, not unlocking content");
    21.         }
    22.     #endif
    23.     }    
    but now this startRecreation() function is not called and the content is not accessible anymore.
    Can you tell me where I'm wrong?
     
  50. LotusBlack

    LotusBlack

    Joined:
    Apr 9, 2015
    Posts:
    35
    Isn't receipt validation automatic in Android though? Your product.hasReceipt methods should be returning true on Android even after reinitializing (reinstalling??) the app, from what I tested.
     
Thread Status:
Not open for further replies.