payment / IAP stuff is just not clear to me

So did anybody get this to work yet?  

I find this part of the SDK to be extremely un-user-friendly and lacking some good documentation. Especially now that the announcement has gone out to submit games, I was hoping to see a more finalized SDK and documentation on how to get it working.

How do I turn the KEY.DER file into a byte array? (I'm on a Mac btw, but I'm sure many Windows developers have the same question)   .. and why don't you do this server side and just let us download a source-code/text file with the contents?

Even better would be to just include the KEY.DER file in the APK and have code that reads the file.

Is there a better documentation coming for this? am I the only one running into issues getting this up and running?

Comments

  • nicknick Posts: 186Member, Administrator, Team OUYA
    edited March 2013
    There's an example of loading it from a file in the game sample in the newest ODK. (Samples/game-sample/src/tv/ouya/sample/game/OptionsActivity.java)

    Excerpt:
    try {
        InputStream inputStream = getResources().openRawResource(R.raw.key);
        applicationKey = new byte[inputStream.available()];
        inputStream.read(applicationKey);
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Post edited by nick on
  • KonajuGamesKonajuGames Posts: 560Member
    I used Hexplorer on Windows to load the key file and export as source code.  Quite a few hex editors will be able to export as source code.

    There is also quite comprehensive IAP documentation and the sample code in the ODK.
  • stolkstolk Posts: 119Member
    I use:
    $ od -t x1 key.der

    I managed to create the public key with keyFactory.generatePublic(keySpec);
    But I have not been able to use it to decrypt.

    I get a receipt back from the server, with a key and iv field, and when running the decrypt with:
    receipts = helper.decryptReceiptResponse(response, publicKey);
    ...I get an empty list.

    Did I do something wrong, or are old receipts that were created a few weeks ago not usable for decryption?

      Bram

  • KonajuGamesKonajuGames Posts: 560Member
    The store has been reset.  See the OUYA blog.
  • KonajuGamesKonajuGames Posts: 560Member
    @stolk: Why did you create a public key?  The app key is given to you when you start an app submission.
  • stolkstolk Posts: 119Member
    @stolk: Why did you create a public key?  The app key is given to you when you start an app submission.
    You need to create it from the spec.
    See the docs.

    // Create a PublicKey object from the key data downloaded from the developer portal.
            try {
                X509EncodedKeySpec keySpec = new X509EncodedKeySpec(APPLICATION_KEY);
                KeyFactory keyFactory = KeyFactory.getInstance("RSA");
                mPublicKey = keyFactory.generatePublic(keySpec);
            } catch (Exception e) {
                Log.e(LOG_TAG, "Unable to create encryption key", e);
            }

  • stolkstolk Posts: 119Member
    stolk said:

    Did I do something wrong, or are old receipts that were created a few weeks ago not usable for decryption?
    It was the latter... once I purchased the product again, receipt responses are fine now.
    They can be decrypted.

    So a heads up: if your IAP was purchased before the store-reset, its receipt is bogus.
    You have to buy it again on the new store.

      Bram

  • KonajuGamesKonajuGames Posts: 560Member
    I'll have to work out what the C# equivalent of that public key generation code is.  Since that code will always spit out the same thing, surely the OUYA dev portal could have supplied the public key in a ready to use state.
  • greeniekingreeniekin Posts: 92Member
    Having it available as raw numbers as well would make it easier. Though concept is simple enough to come up with you own solution. Just need a byte editor or hex editor.  Then you can just copy the numbers in order into something like this
    byte[] appKey = { 
        10, 20, 30, etc.//replace this line with the byte codes separated with commas
    };

  • orangepascalorangepascal Posts: 29Member
    nick said:
    There's an example of loading it from a file in the game sample in the newest ODK. (Samples/game-sample/src/tv/ouya/sample/game/OptionsActivity.java)

    Excerpt:
    try {
        InputStream inputStream = getResources().openRawResource(R.raw.key);
        applicationKey = new byte[inputStream.available()];
        inputStream.read(applicationKey);
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Thanks Nick, that did fixed the major issue I had.
    After some more tinkering I now have it all working ;)

    So payments will be live on March 28?  still feels a lot of test-phase and changes are happening, and I want to make sure it actually works correctly if I submit the game now and not have to do a rush job updating it before the 28th.
  • orangepascalorangepascal Posts: 29Member
    oh and is there a way to clear my own (developer) receipts?  for testing purposes.. 
  • EvgizEvgiz Posts: 184Member
    If you go to the products page there is a reset button to erase purchases of your own products.

    I made the OUYA exclusive games Cube and Creature and Hellworm!
    evgiz.net




  • orangepascalorangepascal Posts: 29Member
    thanks.. not sure why I didn't see that link before :D
  • arcticdogarcticdog Posts: 235Member
    edited March 2013
    I'll have to work out what the C# equivalent of that public key generation code is.  Since that code will always spit out the same thing, surely the OUYA dev portal could have supplied the public key in a ready to use state.
    I seem to remember reading somewhere that the Bouncy Castle framework had X509 certificate encryption stuff built into it.  If you don't mind introducing that dependency, and if it compiles for Xamarin.Android that might be a real quick way to accomplish that.

    Update:
    I was right about BC.. but the selected answer here offers a similar solution without the dependency: 

    Post edited by arcticdog on
  • KonajuGamesKonajuGames Posts: 560Member
    Thanks for the info @arcticdog.  That will be very helpful.
  • tgraupmanntgraupmann Posts: 2,869Administrator, Team OUYA
    edited June 2013
    Thanks @Nick!

    Integrated this into the Unity plugin.


    Post edited by tgraupmann on
    ~Tim Graupmann
    OUYA Inc | Android Developer
    Skype: tgraupmann_prey

    http://github.com/ouya/docs
    http://github.com/ouya/ouya-sdk-examples

    Check out the latest docs for your game engine: [setup] [adobe air] [android] [clickteam fusion] [construct 2] [corona] [libGDX] [game maker] [html5] [marmalade] [monogame] [unity] [unreal]

    Use caution when setting [persistent wireless mode].
Sign In or Register to comment.