PLUGIN: Android In App Purchases.

The new ShiVa Asset Store. A forum for product inquiries, reviews, comments and critique.

PLUGIN: Android In App Purchases.

Postby Fraser » 2016-05-28 22:39

Just submitted a plugin to the store to enable Android in app purchases.
It has consume ability, so you can repeatedly sell same products ( coin/gem packs etc. ).
Or you can just use it for managed products ( permanently unlock game levels, remove ads, etc. ).

Demo app on GooglePlay store:
https://play.google.com/store/apps/deta ... dgoogleiap

Get the plugin on the ShiVa store:
http://www.shiva3dstore.com/sdaiap

DOCS:
Code: Select all
#########################################################################################################
    _              _           _     _     ____                   _      ___    _    ____ 
   / \   _ __   __| |_ __ ___ (_) __| |   / ___| ___   ___   __ _| | ___|_ _|  / \  |  _ \
  / _ \ | '_ \ / _` | '__/ _ \| |/ _` |  | |  _ / _ \ / _ \ / _` | |/ _ \| |  / _ \ | |_) |
 / ___ \| | | | (_| | | | (_) | | (_| |  | |_| | (_) | (_) | (_| | |  __/| | / ___ \|  __/
/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_|___\____|\___/ \___/ \__, |_|\___|___/_/   \_\_|   
                                     |_____|                |___/                         

SHIVA IN APP PURCHASING PLUGIN FOR SHIVA VERSIONS >= 1.9.2                           
INSTRUCTIONS FOR USING THE PLUGIN:

[1] #####################################################################################################

Add this line to your AndroidManifest.xml permissions:

<uses-permission android:name="com.android.vending.BILLING" />

[2] #####################################################################################################
Import the plugin com.silicondroid.androidgoogleiap.ste into your game project.

[3] #####################################################################################################
Drag the plugin into the GameEditor/Plugins tab to reference it in your game.

[4] #####################################################################################################
In your games onInit initialise the plugin like this:

--------------------------------------------------------------------------------
function MyMainAI.onInit (  )
--------------------------------------------------------------------------------
   
    application.setCurrentUserScene ( "empty", "" )
    local hScene = application.getCurrentUserScene ( )
      
   --------------------------------------------------------------------------------
   --   GET YOUR APPLICATIONS BASE64 ENCODED KEY FROM YOUR GOOGLEPLAY DEVERLOPER ACCOUNT.
   --   IT IS RECOMMENDED TO HIDE THIS KEY SOMEHOW.
   --   FOR EXAMPLE SWAP CHARACTERS SOMEHOW AND THEN RECONSTRUCT BY SWAPPING AGAIN AT RUNTIME.
   --   IF YOU DO NOT HIDE IT THEN SOMEBODY CAN SIMPLY PARSE THE APK LOOKING FOR A VALID STRING LITERAL KEY.

    local sBase64 = "MIIBIjANBgkqh...9WUhBcQIDAQAB"
   Android_GoogleIAP.initialise ( sBase64, nil, "MyMainAI", "onGoogleIAP_Callback" )
   
   ----------------------------------------------------------------------------------------------------
   --   DO AN INITIAL INVENTORY READ OF ALL PRODUCTS.
   --   YOU CAN FIND THE PRODUCT IDS FROM THE GOOGLEPLAY DEVELOPER CONSOLE BY OPENING THE IN-APP PRODUCTS TAB FOR YOUR APPLICATION.
   --   THE PRODUCT IDS ARE LISTED UNDER THE COLUMN LABELED NAME/ID.

   local sProductIDs = ""
    sProductIDs = sProductIDs .. "iap_test_gems_10,"
    sProductIDs = sProductIDs .. "iap_test_gems_100,"
    sProductIDs = sProductIDs .. "iap_test_gems_250,"
    Android_GoogleIAP.productsInventory ( sProductIDs )
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------

[5] #####################################################################################################
The plugin contains these functions:

Android_GoogleIAP.initialise ( sBase64key, hObject, sAI, sHandler )
hObject = nil if you are using user level AI message handler(recommended).
hObject = object handle if you are using object level AI message handler.
       
Android_GoogleIAP.productsInventory ( sCommaDelimitedProductIDs )
Android_GoogleIAP.productPurchase ( sProductID )
Android_GoogleIAP.productIsPurchased ( sProductID )
Android_GoogleIAP.productConsume ( sProductID )

The plugin does not block, it runs asynchronously.

You implement a callback handler in ShiVa script to catch returned data like this:

--------------------------------------------------------------------------------
function MyAI.onGoogleIAP_Callback ( kMessageType, sData )
--------------------------------------------------------------------------------

--MESSAGE TYPES ARE:
--Android_GoogleIAP.K_pluginLogError"   
--Android_GoogleIAP.K_pluginLogInfo"     
--Android_GoogleIAP.K_initialise"       
--Android_GoogleIAP.K_productsInventory"
--Android_GoogleIAP.K_productPurchase"   
--Android_GoogleIAP.K_productIsPurchased"
--Android_GoogleIAP.K_productConsume"   

--sData makeup can be found in the API popup documentation within ShiVa editor.

--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------
       
[6] #####################################################################################################
NOTES:
   You need to upload at least one version of your APK to googleplay and create some in app products for it.
   You do not need to use that APK to test purchases, you can use a locally built and signed one for testing if you like.
   The initial APK upload is just so you can establish some products in GooglPlay11.
   
   You cant use your developer account to test purchases.
   Either use another phone or create another account and sign your phone out of your developer account.
   
   After uploading your APK to googleplay it can take several hours for the products to work correctly.
   After updating your APK on googleplay it can take several hours for the products to work correctly.
   After updating in app products on googleplay it can take several hours for the products to work correctly.
   
INSTRUCTIONS FOR USING THE PLUGIN END.
Last edited by Fraser on 2016-05-29 17:20, edited 1 time in total.
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1324
Joined: 2012-02-05 19:28
Location: Europe

Re: PLUGIN: Android In App Purchases.

Postby lcocea » 2016-05-29 16:08

Excellent! Is it compatible with both 1.9.2 and 2.0?
Any plans for a Google Play Games Services plugin? :)
lcocea
Platinum Boarder
Platinum Boarder
 
Posts: 576
Joined: 2012-06-07 03:12

Re: PLUGIN: Android In App Purchases.

Postby Fraser » 2016-05-29 17:19

I haven't tested it in 2.0B but I'm 99.9% sure it will be fine, If not then I will fix it so it is.

I built an APK using ShiVa2B6, it builds and works fine, you can query the inventory and check purchased items.

However you cant purchase... I decrypted the built APKs mainfest by running:

Code: Select all
aapt l -a MyGame.apk


And found that it is missing:
Code: Select all
<uses-permission android:name="com.android.vending.BILLING" />


The manifest was the default one as produced by ShiVa2 export.
So it's not possible to use a custom manifest in ShiVa beta for Android builds.
In UAT 1.4.0 you can add a custom manifest to "additional files" when you build, that's what we need in ShiVa2.
This is a minor fix/tweak for ShiVa though and will happen in time no doubt.
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1324
Joined: 2012-02-05 19:28
Location: Europe

Re: PLUGIN: Android In App Purchases.

Postby Fraser » 2016-05-30 00:20

RE Google Play Services; yes I have been thinking about it over the past year or so.

I thinks it's best if the plugin were built in Android Studio, so I will wait and see how ShiVa2 plugin dev structure is. I seem to remember @broozar saying ShiVa2 will integrate with Android studio?

There is also a googleplay C++ SDK available but that requires building with C++11, maybe that will also be possible with ShiVa2? If so then all the better.
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1324
Joined: 2012-02-05 19:28
Location: Europe

Re: PLUGIN: Android In App Purchases.

Postby broozar » 2016-06-02 18:55

Fraser wrote:I thinks it's best if the plugin were built in Android Studio, so I will wait and see how ShiVa2 plugin dev structure is. I seem to remember @broozar saying ShiVa2 will integrate with Android studio?

AS support is in 2.0 since beta 4: http://www.shiva-engine.com/merry-chris ... 4-is-here/

Fraser wrote:There is also a googleplay C++ SDK available but that requires building with C++11, maybe that will also be possible with ShiVa2? If so then all the better.

I am doing all my plugin work in c++11, it's definitely fine to use. auto and unique_ptr ftw! You can also use c++11 in 192 plugins, shiva pretty much does not care which standard the dll is written in.
User avatar
broozar
Administrator
Administrator
 
Posts: 4103
Joined: 2007-09-16 10:22
Location: Berlin - Germany

Re: PLUGIN: Android In App Purchases.

Postby Fraser » 2016-06-04 16:43

Oh great news on C++11 working!
User avatar
Fraser
Platinum Boarder
Platinum Boarder
 
Posts: 1324
Joined: 2012-02-05 19:28
Location: Europe

Re: PLUGIN: Android In App Purchases.

Postby dbladez » 2016-08-25 03:08

I just purchased this and was going to test it out however with both Shiva 1.9.2 Advanced and Shiva 2.0 Beta 6 I get this in the shiva log viewer when I try to import the plugin.

self signed certificate
::LoadLibrary failed with code: 126
Could not open native plugin file : E:/Shiva/ShivaProjects/AndroidIABTest/Plugins/com.silicondroid.androidgoogleiap/Contents/Windows/Android_GoogleIAP_Windows.dll

The file is there, not sure why it won't load.

Then the api does not pop up code.

Same error on both versions of shiva. Tried with current and new empty projects.

It also has 2 pop up errors saying palm and blackberry are missing which is odd. Do I need to change the plugin tool paths? Although I don't have palm or blackberry.

If I try to right click in the game module and reload plugins it just shows.

[o Message ] Found 0 statically linked native plugin
[+ Warning ] ::LoadLibrary failed with code: 126
[+ Warning ] Could not open native plugin file : E:/Shiva/ShivaProjects/AndroidIABTest/Plugins/com.silicondroid.androidgoogleiap/Contents/Windows/Android_GoogleIAP_Windows.dll

Any ideas?
dbladez
Platinum Boarder
Platinum Boarder
 
Posts: 693
Joined: 2010-11-03 22:10
Location: Ontario, Canada

Re: PLUGIN: Android In App Purchases.

Postby broozar » 2016-08-25 11:54

self signed certificate

signing on android is not (yet?) required on android, so don't worry.

::LoadLibrary failed with code: 126

general failure

Could not open native plugin file

... but the file is there. this could mean one of 3 things:

- a dll dependency from the plugin's SDK is not met (maybe you have to copy something to the project root directory? if so, should be in some sort of help file in the plugin)
- the dll is compiled with the wrong architecture target (f.i. 64bit vs 32bit), however this should not bee the issue here
- most likely explanation: dll cannot be opened because it has been compiled against c++ runtime (developer) libs that are not present on your system. ask the plugin maker which compiler toolchain he used (for instance vs140) and then install the corresponding MSVC++ REDIST (f.i. this one https://www.microsoft.com/en-us/downloa ... x?id=48145). most games do this these days, like when you first start a game on steam, it checks the system and installs missing redists for C++, DX etc.

It also has 2 pop up errors saying palm and blackberry are missing

Android IAPs only work on Android. make sure your export profile creates an STK for Android only, otherwise you will get messages on export about missing libs for other platforms.
User avatar
broozar
Administrator
Administrator
 
Posts: 4103
Joined: 2007-09-16 10:22
Location: Berlin - Germany

Re: PLUGIN: Android In App Purchases.

Postby dbladez » 2016-08-26 20:21

1. Thought that also and copied for the dll dependency I copied pretty much every file there was in all folders just encase still didn't help.
2. I Thought of that initially also and tried it on a 32 bit windows 7 I have on a laptop. Same error.
3. Could be that, I'll get that d/l and try it out. Otherwise do you gotta somehow un-install the msvc++ redist? Then only install up to the one used to make the plugin? First I"ll try updating though.
dbladez
Platinum Boarder
Platinum Boarder
 
Posts: 693
Joined: 2010-11-03 22:10
Location: Ontario, Canada

Re: PLUGIN: Android In App Purchases.

Postby dbladez » 2016-08-26 20:32

Edit: Installed all latest versions of all MVC++ Redistributable x64's and x86's.. 8, 9, 10, 11, 12 & 14.
Still same error.
Tested in on a windows 10 laptop also, same error.
dbladez
Platinum Boarder
Platinum Boarder
 
Posts: 693
Joined: 2010-11-03 22:10
Location: Ontario, Canada

Next

Return to Asset Store

Who is online

Users browsing this forum: No registered users and 1 guest