After we developing the game by Unity3d, we need to add purchase model to make money.
This project is designed to make it add In-App-Purchase easy. Currently support:
- App Store
- Google Billing
As a solution, UIAP include client and server. The server is based on Express of Node.js. The server code is used to verify purchase,you can run it in your host.
You can download this package(i can't visit that url,try this) and import to Unity3d .
Or you can clone this repo, copy IAP
folder to Client/Assets/
. you should also copy the file under the Plugins
to your Assets/Plugins
.
There's a demo project in IAP/Example
,which show how to use the interface.
You can copy all file in NodeServer
to your host, and type under code:
node bin/www
Doing that will run the express. Anyway, you may need to change the server ip which client connect, it should be configed in IAP.cs
.
After installing the plugin,we can use it by following code:
string list = "{\"items\":[\"item0\",\"item1\",\"item2\"]}";
IAP.getInstance().getItemList(list,listBack);
The first parameter is the skulist. Considering the number of the goods could increase, when we want to get the item info,we should offer the sku name.
It should follow the json format,such as:
{
"items":
[
"item0",
"item1",
"item2"
]
}
Second parameter is the callback,It should look like:
void listBack(string result)
{
//do something
}
Parameter of this function also follow json format.
IAP.getInstance().pay("item0",payBack);
The first parameter is sku of items. The second is callback which looks like:
void payBack(string result)
{
//do something
}
After adding the interface, we should config the export settings.
In order to add IAP into an App Store game,we should follow standard operation to export.
- Change the Bundle Identifier of your app.
- Keep your code sign of Xcode is correct.
- Add StoreKit.framework in Xcode Project.
- Connect your device and build the package.
In order to add Google Billing into your game,we should follow standard operation to export.
- open AndroidManifest.xml in Assets/Plugins/Android. Change your public key of google billing.
- you should also edit the defaultSku under the public key, which is used to update status when the app init.
- Change the Bundle Identifier of your app.
- Set your KeyStore.
- Export the package.
- Unity3d v4+
- IOS 6.0+
- Google Billing v3
Currently the info which is passed between native code and Unity3d is hard Code,if you want change it you should change the file inside.
I may work on those in the future.
UIAP is published under MIT License
Copyright (c) 2014 SongYang Fan (@fansongy)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.