• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by crazyKnight · Jun 15, 2011 at 09:32 AM · androidin-app-purchase

in app purchase android

hey ,

i am trying to implement in app purchase in my android game,the game currently has 20 levels what i am trying to do is, when the user downloads the game from the market(the game would be free)the first 10 levels will be unlocked(from the starting) but to play the next 10 levels the user has to pay some amount of money(in app purchase).

i dont want a 10 level add on package sort of thing,when the game is first time downloaded from the market it will have all the 20 levels in it but 10 levels will be locked(by a simple loop condition).

my idea of implementing this was,

i would create a gui button for the purchase and trigger a event with playerprefs(by suppose setting a int value to 1)and then in eclipse(i used the following link to convert the game into an eclipse supportable format http://unity3d.com/support/documentation/Manual/Android-Integrating%20Unity%20With%20Eclipse.html ) i heard we can get the playerprefs event called in eclipse and then in eclipse i can do the entire coding related the purchase(i am not concerned about the coding in eclipse regarding purchase as i have done that many times for my non unity apps) but what concerning me is that how will i return a confirmation to unity that the purchase is complete and i can unlock the levels in the game.

i dont know what i am thinking is feasible or not...any suggestion on how this could be implemented or how i could a return a confirmation back to unity about the completion of the purchase.

i would also appreciate any new idea for implementing this..

Thanks in advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

7 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Voxel-Busters · Aug 09, 2015 at 10:33 PM

This can be setup with some little effort. Create a gameobject and add a class with a method. On purchase successful in Android, Call

UnityPlayer.UnitySendMessage(UnityDefines.NATIVE_BINDING_EVENT_LISTENER, methodName, message);

Where UnityDefines.NATIVE_BINDING_EVENT_LISTENER is the name of gameObject. Message needs to be a string and you need to convert your purchase info to a string format so that you can parse back in unity.

You can try Cross Platform Native Plugins for a smoother and quick solution. It provides necessary callbacks with very easy setup and lots more features. alt text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Furry McTank · Nov 19, 2014 at 08:22 PM

I put a game called Barfly onto Google Play and used the OpenAIB plugin to put a couple of in app purchases in it. http://www.youtube.com/watch?v=69alYbOYIZs

Don't know about the other stores but it works well with Google Play (it's a free plugin too).

There's examples with the plugin which aren't too hard to follow but here's a couple of things to watch out for:

1) You need to have uploaded your .apk to GooglePlay before you can test an iap as you need your GoogleKey for the app. If you just upload your game as an alpha or beta you don't have to worry about publishing an unfinished game. Before you do this make sure you have the following permission in your Android manifest.

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

This will allow you to create in app purchases in your GooglePlay developer console. For your game you want to make a managed iap - this means users can only download it once.

2) Then it's just a case of making sure your PublicKey is correct and that the name of your purchase is correct in your scripts.

3) Another thing to watch out for is that certain calls will only work on an Android device, not in the Unity editor! A big one here is OnQueryInventorySucceeded(). I thought this was broken as it didn't show up in my log, but when I ran my game on my phone and used the ./adb logcat to see the phone specific debug messages it worked fine. This returns all the user's purchases, so for your case put this code into OnQueryInventorySucceeded()

bool hasBought;

hasBought = inventory.HasPurchase (SKU);

if(hasbought) [CODE TO UNLOCK LEVELS 10-20]

where SKU is defined earlier as the string you call your iap in the googleplay console, something like:

public const string SKU = "add_extra_levels";

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by One Platform Foundation · Feb 06, 2014 at 09:50 PM

No need to compile OpenIAB from sources anymore.

OpenIAB also can be found in Asset Store or download from Releases on GitHub

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liju · May 08, 2014 at 09:28 AM 0
Share

How to use OpenIAB unity plugin ? any tutorial available ?

avatar image
0

Answer by Extrawurst · Nov 17, 2013 at 11:49 AM

No need to buy any plugin for this anymore. There is OpenIAB open source and free. Just go and grab it on github:

OpenIAB unity plugin

Currently it supports all sorts of android stores, but iOS is about to be released soon!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liju · May 08, 2014 at 09:27 AM 0
Share

how to use OpenIAB unity plugin

avatar image
6

Answer by maxgreen · Sep 23, 2012 at 06:57 PM

You might want to check out the free Soomla Store plugin on the Asset Store.

It's also an open source project on Github, and they have a sample app there as well, with properly documented code.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to add .properties files to apk root programmatically? 2 Answers

How can one upload on the Android Market if one's game exceeds the market size limit (50MB or less) ? 0 Answers

Making an in-app virtual good purchasable only by some users 1 Answer

What do I pass into Application.OpenURL to open up the Android market from an app? 2 Answers

Difficulty with Android IMarketBillingService 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges