Search Unity

Simple In-App Purchase System (SIS) - Shop solution

Discussion in 'Assets and Asset Store' started by Baroni, Aug 8, 2013.

?

Which billing plugin are you using in combination with Simple IAP System?

  1. Unity IAP

    66 vote(s)
    82.5%
  2. Voxel Busters

    5 vote(s)
    6.3%
  3. Stans Assets

    9 vote(s)
    11.3%
  4. Prime31

    0 vote(s)
    0.0%
  1. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Mmmh.. are you sure that case "continues" is actually being called? Did you eventually add some code above that switch-case, which prevents it from getting down there? Well, deleting and reimporting would certainly fix it, but you would lose your changes and could run into this issue again later. I'm always available for investigation of small repro projects, if you like to send it to me via email.

    Regarding PlayerPrefs: I wouldn't use them like that at all. I'd recommend using the DBManager for player data, because everything is stored in one place and can be encrypted. E.g. DBManager.IncrementPlayerData("continues", 1);

    I'm here to help, no worries :)
     
  2. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    Thank you :)

    No, the thing I just added PlayerPref "continues" to increase by one under "bullets" didnt change anything else, just to test if it would actually add 1, it didnt :
    Code (CSharp):
    1. case "bullets":
    2.                     //for virtual items, you could use DBManager's custom data option in order
    3.                     //to save amounts of virtual products. E.g. increasing bullets by 100:
    4.                     //int bullets = DBManager.GetPlayerData("bullets").AsInt;
    5.                     //DBManager.SetPlayerData("bullets", new SimpleJSON.JSONData(bullets + 100));
    6.                     PlayerPrefs.SetInt ("CONTINUES", PlayerPrefs.GetInt ("CONTINUES") + 1);
    7.                     ShowMessage("Bullets were added to your inventory!");
    8.                     break;
    Anyways, for now ill just try to remove it and re-import SIS, I'll let you know how that goes.

    Meanwhile is there docs or maybe you could explain to me briefly about DBManager.IncrementPlayerData and DBManager.SetPlayerData. Will it create "continues" in SimpleJSON automatically after first purchase or I have to declare it? And how can I pull it to display it in NGUI UILabel:
    mylabel.txt = (DBManager.GetPlayerData("continues")).ToString(); ?? not even close? :)
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Docs about what's available in the API is here: online documentation, and page 17 in the included documentation pdf has a sample on how to use them. Entries in the DBManager will be created automatically when they are first being used.

    Code (csharp):
    1. mylabel.txt = (DBManager.GetPlayerData("continues").AsInt).ToString();
     
  4. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    Thank you very much! I will read docs, re-import SIS and hopefully won't run into any more problems. If I will I know where to find you ;)

    Thanks again for everything.
     
    Baroni likes this.
  5. InfinityCoder88

    InfinityCoder88

    Joined:
    Oct 4, 2013
    Posts:
    241
    Hey 8bitCartridge ,
    Make sure that your IAPManager is active in the inspector ;) ...and you have only one IAPManager in one of your scene, ...I had this problem too, in my shop when buying some items... no messages was showing...then I checked step by step my components, when I paused my game I discovered the IAPManager deactivates when the shop scene starts, best solution is to insert IAPManager in your first scene (ex: MainMenu) ...will work perfectly ;)
     
    8bitCartridge and Baroni like this.
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    I've seen that some users have been trying to hack in localization for (offline) in-app purchases or virtual products in Simple IAP System, so here's a quick announcement that the upcoming version 2.4 will provide support for Smart Localization. Currently I'm improving the workflow for it, with the ultimate goal for localized IAPs to be as easy as drag&drop. I'll also upload a video tutorial for it later.

     
  7. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    @D0R1N

    Thanks for the tip mate! I will definitely keep that in mind, because I already re-imported SIS and everything works great! :)

    @Baroni

    Hey mister Baroni! Just wanted to let you know that I re-imported SIS and everything is up and running without any errors or any un-popping window problems :) thanks again!
    One quick question, I wasn't sure as per your tutorial about "sprite per item" part, how do I assign a specific sprite to a specific item? As far as I understood it has to have the same name, correct?

    Thank you in advance!
     
    InfinityCoder88 likes this.
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    In the NGUI version, yes: the sprite name should match with the product title. Also make sure that the icon on your IAPItem prefab already has the correct NGUI atlas assigned. In the uGUI version, just assign the desired sprite reference directly.
     
  9. mudparr

    mudparr

    Joined:
    Nov 20, 2012
    Posts:
    4
    So I've gotten everything working in the editor, have a play development account, created the items in the play dev console, but when I upload an apk and test is all of the pages of items are blank. The main menu is there, and I can navigate between the different item type pages, but none of the products show up. Just blank. Can you point me in the right direction?
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Hi mudparr, first you should check the device log (adb logcat -s Unity) for any suspicious messages. If you've correctly entered your Google Play developer key in the IAPManager and uploaded your app as alpha or beta (not draft), looking at the device log would be a good start.
     
  11. mudparr

    mudparr

    Joined:
    Nov 20, 2012
    Posts:
    4
    Thanks for the quick response. So I got that problem worked out (thanks to the device log), but now I have another problem and I can't seem to figure out what is going on. The test purchases seem to process correctly up until the end. I get the play prompt notifying me that it is just a test purchase. Transaction completes and it goes back to the game, but no currency (crystals in this case) are added. Not really sure if this works in the editor since I just get the message about not being on a mobile device. Nothing shows up in the device log now (at least not with the -s Unity flag set). Any further help in pointing me in the right direction would be appreciated.
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Real purchases won't work in the editor, but virtual purchases do work. Regarding crystals not being added: your IAPManager prefab is only present in the first scene of your game, right? And have you added another switch case to the IAPListener script where you add your crystals via DBManager.IncreaseFunds(...) (after specifying the crystals currency in the IAPSettings editor)?
     
  13. mudparr

    mudparr

    Joined:
    Nov 20, 2012
    Posts:
    4
    I only have one scene (just working on testing IAP for now) and the IAPListener script is modified. Looks about like so:

    switch (id)
    {
    //section for in app purchases
    case "crystals":
    //the user bought the item "crystals",
    //increase crystals by 1000 and show appropriate feedback
    DBManager.IncreaseFunds("crystals", 1000);
    ShowMessage("1000 crystals were added to your balance!");
    break;
    case "crystal_pack":
    etc. etc.

    crystals currency is set in IAPSettings

    In game content properly deducts crystals for purchase (though it was weird because I had to exit and enter again before I could select a purchased item).
     
  14. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    Thank you, Baroni!


    Edit: finally got a chance to leave a well deserved review, hope it helps people decide which asset to purchase :)
     
    Last edited: Oct 25, 2014
  15. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    You plugin is not working anymore with the newest UniBill plugin:
    that's what it states in the unibiller changelog and you actually still use that function...
    Removed Unibiller.GetAllPurchaseReceipts, replaced with a new 'receipt' property on PurchasableItem.

    And another question is if and when your plugin will work with ngui again..
     
  16. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    your code in iapmanager line 423 onwards should probably be:
    //save new receipt on the device, as Unibill does not track receipts
    string receipt = Unibiller.GetPurchasableItemById(id).receipt;
    if(receipt.Length > 0)
    DBManager.SaveReceipt(id, receipt);
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @mudparr
    Do you see the window where it tells "1000 crystals were added to your balance!"? I am thinking that the switch-case is not triggered, but I'm really clueless when it comes to why. If you would like me to investigate this for you, you can always send a small repro project to info [at] rebound-games.com.

    @8bitCartridge
    Thank you for the review! I am very flattered :)

    @gaiomed
    Thanks for your report, this has been fixed for the next update (your fix in the second post is correct). I am still distributing the NGUI-compatible version through our web store. If you would like to receive a download link for it, please send me an email with your Asset Store invoice no.
     
  18. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    @Baroni regarding NGUI compatiblity the question was in the direction if newer packages will be made compatible with ngui or the your plugin is uGUI in the future only, thx
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Ah, I see. The current plan is to keep the NGUI version for the next big updates. I can't tell what the future brings, or if everyone switches to uGUI, but we still have a considerable amount of customers using NGUI so it won't go away anytime soon.
     
  20. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    and when do you plan to release a current version with ngui support ? or is it already available as alpha?
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @gaiomed It has been here all along. If I may quote myself:

     
  22. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    ok I'll send you my invoice again, but a far more important questions is that I can't get the server side validation to work, pyments are always successful even if I rename the verify.php file so I shouldn't be found, any clue on this newest unit, unibill and your newest plugin...

    as a serurl I have http://www.mycompany.com
    Verification file name: verify.php

    and on my webserver no new file is created even though all rights are granted
    sort of clueless...
     
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    The server url should be http://www.mycompany.com/ (note the "/" at the end). Also make sure to follow the steps in the documentation for modifying verify.php. I can't help you on how to upload it to your webserver though, you will have to figure that out on your own.
     
  24. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    hi,

    yeah I debugged the trailing slash but still I am not able to get it done. For a log message you should change your code like this in line around 400 in inAppmanager.cs
    if (debug) Debug.Log("Verification URL error: " + www.error);

    I get a File Not Found Exception for http://www.polycular.com/verify.php
    but this works fine in the browser, is there something I could mess up with the virtual hosts in apache, but as it works perfectly in the browser I doubt that
     
  25. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    the exception is java.io.FileNotFound
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    I haven't come across this exception yet. When verifying receipts with Google, the php file will create an access token in the same directory. See line 92, where it calls requestAccessTokenAndroid($path);. The FileNotFound exception could possibly mean that it can't create the access token there. You should check if access_token.php is actually located in the same directory as verify.php on your server. If the file is not there, something went wrong in requestAccessTokenAndroid() (write access / Google client id / secret).

    The script returning "false" in the browser doesn't mean much, because it also throws false whenever a value hasn't been set.
     
  27. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    well, the exception means the verify.php can't be found as it is the exception of the unity app not the php script, the script is never called that's what this means, so there can't be a tokenfile created...
     
  28. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    if it just call the url without form the file is found and works and returns false as it hasn't got values... back to the start
     
  29. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    ok bit by bit hope that helps others not so php affine people like me too:
    you have to install the curl extension for your php (I am on debian wheezy and it was not installed)
    still the script give me the following errors:
    [27-Oct-2014 19:47:47 UTC] PHP Notice: Undefined index: type in /home/polycular
    /htdocs/verify.php on line 109
    [27-Oct-2014 19:47:47 UTC] PHP Notice: Undefined property: stdClass::$kind in /
    home/polycular/htdocs/verify.php on line 133
     
    Last edited: Oct 27, 2014
  30. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    so that's the response google gets me, I am pretty sure I did a lot of things rhymed together from your pdf and what google says in it's newer version... where they say the cloud stuff is deprecated and it should work with google play and the whole oauth2 stuff, really hope that will be easier on ;-(

    "error": {
    "errors": [
    {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
    }
    ],
    "code": 403,
    "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
    }
    }
     
  31. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    hmm guess need to do the play store S*** with oaut and key all over again, is your pdf still the way to go and succeed in that?
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Yes. The authentification stuff in the Google Play developer console brings you back to Google Cloud, so it doesn't matter where you are creating them. You can also do it in Google Play of course.
     
  33. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    hmmm I am really lost what is needed to get that thing to work.
    That's what I did:
    1) added google play to my app as service and created and linked a web app with some name other name to get the client_id and secret with that I followed the process and managed to get the tokens.
    The token refreshing seems to work as I always get new tokens and the access_token file is refreshed. Nevertheless I always get the error message back from above.
    when the php script calls https://www.googleapis.com/androidpublisher/v1.1/applications/$android_bid the error message is the reply. as a android_bid I entered in the script the identifier of the unity app in my case com.something.someapp

    What confuses me is the redirect_uri because it was set to oauth2callback but as nowhere is state to set it back to some really existing url I left it like it is.

    Do I need to enabel billing with the cloud platform?

    Always access not configured but what do I have to configure? I just miss something in this puzzle, wheter it is the naming of something or enabling tester (which I have) I am on alpha stage, I entered the emails in the play service as well...

    anyone went through this process and succeeded?

    do I need to put something in the manifest additionally to the normal permissions for getting inapp payment working?

    and what needs the starturl of the authorized webapp to be : http://www.company.com/verify.php ?
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @gaiomed
    It is impossible for me to figure out what you did/enabled/created in your Google Console... you need to follow the instructions mentioned here, these are the same as in the documentation pdf. My web application on https://console.developers.google.com > myProject > APIs & auth > Credentials looks like this:



    No.

    Hopefully your app is published as alpha, draft apps will not work.

    Unibill should do that for you. Receipt verification does not require additional permissions.

    starturl? Where did you get that from?
     
  35. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    Hi I guess I am getting there, it is a fundamental misunderstanding I had, you can link the play service to other apps as web apps and you get all the secrets and stuff and it generates the stuff in the api console but that is probably not how it should be as you just need to authorize the webapp and you don't need the googleplay service for that enabled in the android app and connect a web app to it, google has even made a video about 7 most mistakes with the GooglePlay service guess my fault was number 5, says a lot that they have to make a video like that...
    thx for the hints and hope if I do all over again it will work...
     
  36. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    Hi,

    it works thank you very much without the last hint I would have grey hair by now... Tricky thing is google has two dev consoles which you should choose the right one...
    only thing missing for a later version would be a dialog that the verification on the external server failed...
    best,
    robert
     
    Baroni likes this.
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    A dialog for the player? I don't think that the player should know that you are verifying his purchases, so I commented this out in the WaitForRequest method:
    Code (csharp):
    1. PurchaseFailed("The receipt for '" + id + "' could not be verified.");
    I'll include the error message in the Debug.Log though.
     
  38. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    62
    Hi, I was considering buying this to implement this into my game. what I wanted was to make a free version of my game buy not giving access to some features like the high score board scene and change game time scene. ( these are accessed by buttons on the main screen.) so, a one off purches would unlock these features. The only problem is I coded my game solely in java script/unity script and have had trouble with finding a package that intergrates with java script/unity script. I was wondering If this would be compatible with my project. Thank you.
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @shadow-river
    Hi, few days ago I have helped a customer in integrating SIS in a Unityscript project, so it is safe to say that these are compatible. Basically you just move the whole "SIS" folder into Plugins, except the "Editor" folder. You can then access all functionality from Unityscript after adding "import SIS;" at the top of your scripts.
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Version 2.4 is live:

    - added (offline) localization for in-app products and virtual products
    using Smart Localization: see (uGUI) documentation pdf chapter 9
    - Unibill: fixed error for missing GetAllPurchaseReceipts() API
    - StansAssets: fixed error caused by accessing billing instance in OnDestroy

    Localization sample scene included in the package:

     
  41. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    Again me, I now tried the server side validation for apple but the verify.php script returns:
    {"status":21002}

    which means 21002: The data in the receipt-data property was malformed

    when I log the data it looks quite ok to me:
    {"receipt-data":"TUlJVHhBWUp..........many bytes ...........=", "password":"some secret here"}

    it's on an iPad Air 1 iOS 8.0.2

    It doesn't work with the sandbox user and with normal users, the app is unpublished, it is not on testflight yet an older version without the server side validation is, but I guess that shouldn't be it...

    any ideas, any encoding issues (unicode, base64 whatever ?)

    best,robert
     
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    Hmm.. yeah that receipt looks fine to me too. What's your product type (non-consumable/non-renewing sub etc) and which billing plugin are you using? Unfortunately I don't have an iOS 8 device to test on right now...
     
  43. gaiomed

    gaiomed

    Joined:
    May 5, 2013
    Posts:
    44
    hi,

    i am on unibill, and in a stackoverflow I found that the receipt is already base64 encoded so no need to do that again...
    and there is another bug in your php script or the json package layout has change from the ios store...

    this part is somewhat not functioning:
    global $pid, $ios_bid;
    $response = json_decode($encodedResponse);
    $status = $response->{'status'};
    $server_pid = $response->{'receipt'}->{'product_id'};
    $server_bid = $response->{'receipt'}->{'bid'};

    if($status == 21007)
    {
    verifyReceiptIOS($receipt, true);
    }
    elseif (!isset($pid, $ios_bid) || $status != 0
    || $pid != $server_pid || $ios_bid != $server_bid)
    {
    echo 'false';
    }
    else
    {
    echo 'true';
    }


    the product_id is now in an array in_app which is part of the receipt, and it would be a good idea to call the sandbox just after the status response, as the rest of the packet won't be sent, my code looks now like this, but I still haven't figured out to access the array for the product_id info so I just ignore it currently....

    for me this works, change the cs code
    instead of
    byte[] recBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(data);
    string receipt = Convert.ToBase64String(recBytes);

    just
    string receipt = data;

    and the php script:
    global $pid, $ios_bid;
    $response = json_decode($encodedResponse);
    $status = $response->{'status'};

    if($status == 21007)
    {
    error_log("Sandbox");
    verifyReceiptIOS($receipt, true);
    }
    else
    {
    $server_bid = $response->{'receipt'}->{'bundle_id'};
    #no clue how to access the array

    if (!isset($pid, $ios_bid) || $status != 0 || $ios_bid != $server_bid)
    {
    error_log("not so muchn success");
    echo 'false';
    }
    else
    {
    error_log("verification success");
    echo 'true';
    }
    }
     
  44. mudparr

    mudparr

    Joined:
    Nov 20, 2012
    Posts:
    4
    Thanks again for the support. I think you have a great product here. So I got some of the other issues worked out and am just struggling with one last thing. I'm trying to figure out how to modify things so there is a prefab that can be assigned a group that allows single purchase, but no option to select or deselect, just bought once and I'm done (can't purchase again). Is there an easy way to do this that I'm missing or do I just need to dig more in the code?
     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @mudparr
    If I understand you correctly, then you should have a look at the sample scenes which come with Simple IAP System (at best in a new project with the original IAPManager). For real money purchases, the vertical scenes contain the "no ads" product. For virtual purchases, in the tab or menu scenes under items, there's the "bonus" level product. Both of these products can be bought only once, not selected or deselected, and indicate that they are already bought afterwards.

    Note: there is no code required to achieve this, just have a look at the prefab's IAPItem component.

    @gaiomed
    I'll investigate this further in the coming days. If I am experiencing issues with the current verification php script in combination with Unibill, I'll let you know.
     
  46. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    @Baroni

    Hey man, long time no speak ;)

    Everything works great, hopefully I'll be submitting to apple within a week :) got a small problem though (maybe it was already addressed, but couldn't find it here). When I deploy my app on iPhone, first time I start it my currency states that I have "0" when in reality it's 3,000. When I play it (change scenes) and go back it shows the correct amount, and that happens every time I close the app and start it fresh again. By the way I noticed same thing in the editor.

    Any advice ? Fix?

    Thank you !
     
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @8bitCartridge
    Hey there! How do you update your currency label? Is it located in the first scene?
     
  48. 8bitCartridge

    8bitCartridge

    Joined:
    Feb 26, 2014
    Posts:
    144
    Screen Shot 2014-11-09 at 11.17.26 PM.png @Baroni

    The way I have it set up is like this: first scene is the Main menu scene, thats where I have Shop Manager prefab. MyShop is on that scene as well, and it is accessible through a UIButton (opens shop, it tweens position so it is visible)



    Update my currency label? not sure :)


    Edited: Never mind, Baroni, I fixed it... not sure how it worked but I just put IAP Manager prefab in the first scene, didn't know I had to do it or not, because as long as I had ShopManager prefab IAP Manager prefab was inited by itself. Anyways now currency amount appears right away :) sorry for the pointless bother.
     
    Last edited: Nov 10, 2014
  49. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    If I want to use Android Native and IOS Native (from Stan's Assets) to handle the In-App purchasing, can I just set things up one time in SIS and release to both Android and iOS? Or do I have to change SIS settings when changing platforms? Thanks Baroni
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,272
    @8bitCartridge
    The IAPManager prefab always goes into the first scene :)

    @eridani
    This depends on your project settings, e.g. if you have the same bundle identifier for both platforms. Regarding in-app settings: even if you have different IAP product ids on Google Play and iTunes, you can use platform overrides in the IAP Settings editor, so you don't have to change anything when switching platforms. There are no Android or iOS specific steps involved.