Kongregate Integration

Integrate Kongregate purchases for web-browser games


In this guide, you will learn how to set up Kongregate purchases with Gamedonia. It is a pretty straightforward process, let's see how it's done.

Kongregate purchases are only available for the Gamedonia Actionscript web SDK.

Gamedonia calls will only work under a valid Gamedonia session. This means there needs to be a user logged in with Gamedonia. The main exceptions are, for obvious reasons, creating and logging users in.

Kongregate setup

First of all, to be able to purchase items in Kongregate, you need to create items to purchase. You can do it visiting the site of your game at Kongregate and adding /items to the URL like this:


There you can manage your items for purchase. Let's create a new one by clicking on New Item.


Set up the next fields:

  • Identifier - This will be referenced fom your code.
  • Name - The public name of the item.
  • Description - A short description of the product.
  • Price - The price of the product.

Now set up any optional fields you may need and click on Create.

Then you will see your created product with its price and attributes. Copy the product identifier, because you will need it later.


Before you're done at the Kongregate site, we first need to obtain your Kongregate API key. You can do that at the URL of your Kongregate game adding /api in the end. The URL would be like this:


There you can see the some keys for your game. Copy the one called API key. You will need it later.


Dashboard setup

Go to the Gamedonia Dashboard and open the Social Networks > Settings tab. Here you will just need to set up a single field called Game API Key with the API key of your game you got from the Kongregate website. Then click on the Update button just below the Kongregate Settings and your API Key will be stored in Gamedonia.



Now on to the actual process of purchasing an item in Kongregate using the Gamedonia Actionscript web SDK.

Initialize and request

First you need to initialize Gamedonia with the right Kongregate options. Let's see how it's done:

import com.gamedonia.sdk.GDOptions;
import com.gamedonia.sdk.Gamedonia;
import com.gamedonia.sdk.GamedoniaInAppPurchases;
import com.gamedonia.sdk.GamedoniaStoreEvent;
import com.gamedonia.sdk.GamedoniaUsers;
import com.gamedonia.sdk.social.GamedoniaKongregate;

protected function init():void {
	// Create an options object with Kongregate API key
	// This way GamedoniaSDK will initialize the Kongregate API
	var options:GDOptions = new GDOptions();
	options.inAppPurchases = true;
	options.stage = stage;
	options.kong_api_key = "your_kongregate_API_key";
	// Allow the API access to this SWF
	Gamedonia.initializeWithOptions("your_gamedonia_api_key", "your_gamedonia_game_secret", "http://webapi.gamedonia.com", "v1", options, handleInit);
	// Add event listeners for all 3 purchase events
	GamedoniaInAppPurchases.instance.addEventListener(GamedoniaStoreEvent.PRODUCTS_REQUESTED, onProductsRequested);
	GamedoniaInAppPurchases.instance.addEventListener(GamedoniaStoreEvent.PRODUCT_PURCHASED_OK, onProductPurchasedOk);
	GamedoniaInAppPurchases.instance.addEventListener(GamedoniaStoreEvent.PRODUCT_PURCHASED_KO, onProductPurchasedKo);

protected function handleInit(response:Object):void {
	GamedoniaUsers.authenticate(Gamedonia.CredentialsType_KONGREGATE, null, handleLogin);

protected function handleLogin(success:Boolean):void {
	var productsList:Array = new Array( "product_id" );
	GamedoniaInAppPurchases.instance.requestProducts( productsList );

As you can see, what we first did is initialize Gamedonia adding some Kongregate configuration using the options parameter. It's important that you set your Kongregate API key that you obtained before at the Kongregate website.

Once the initialization is done, you need to login your user using Kongregate credentials. You can do this using the authenticate method. Then you will want to request the products you want to have available from your Kongregate item list. The id of each product has to be exactly the same as the one you set up on the Kongregate website.

Event callbacks

Next thing to do is to process the event listener callbacks. You can handle each event ( PRODUCTS_REQUESTED, PRODUCT_PURCHASED_OK, PRODUCT_PURCHASED_KO) as you prefer. The code would look like this:

private function onProductsRequested(event:GamedoniaStoreEvent):void {
	// Your products_requested processing

private function onProductPurchasedOk(event:GamedoniaStoreEvent):void {
	// Your purchase success processing

private function onProductPurchasedKo(event:GamedoniaStoreEvent):void {
	// Your purchase fail processing

Buy a product

To actually buy a product in Kongregate you just need a single line of code:


It's important that you set exactly the same product id in your code as in the Kongregate web. When buyProduct is called from Kongregate, a pop-up should appear with the details of the transaction. The user can confirm the purchase by clicking on the Checkout button, or he may close and cancel the transaction.

Then the transaction event of success or failure will trigger and you will be able to manage each one adequately.