In-App Purchase on Google Play (Android) using CocoonJS

  • 50 favourites

Index

Stats

2,222 visits, 6,282 views

Translations

This tutorial hasn't been translated.

Tools

Getting your product ready in Construct 2

First off we need to add the CocoonJS object if you have not already added it to your project.

Set the properties to the following: (The physics settings has nothing to do with IAP)

The setting of Managed vs. unmanaged means that ludeis cloud thing will take care of some of it for you.

Warning if you set it to unmanaged the Purchase completed event will not be triggered.

The purchase is a 3 step process:

You Fetch action

Then Buy action

Then Purchase completed event

If you try to buy without doing a fetch the purchase will fail. I was stuck on this for a while :-/

I did the fetch on start of layout, but you could do it in another event if you like, as long as you do it before you buy. (the fetch can take some time, so there is also a Fetch completed which you could check for before you buy)

You can fetch multiple products at the same time, just seperate the products in the fetch with a , (comma)

This show the events needed to make a purchase:

First we check if we are in cocoonjs(e.g. not in a browser etc.)

Then we check if the store is available

Then we purchase

Everytime Construct 2 asks for a product ID it is important that you write the exact product that you created in Google Play (same case etc.) otherwise it will not find the product.

Then you just need to upload your APK to Google Play, wait for it to be ready, and your purchase should work.

You can use the webstorage(look in the manual and the tutorial for reference on how to use) to persist the purchase.

As I wrote in the top I have not been able to get Restore purchases to work. From what I can read on the Ludei wiki it should, when done restoring, trigger the Purchase completed event. But from what I have tried, it is not triggered. I will update if I get wiser :-)

An finally, please help me out if I wrote something stupid and need to correct it.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!