Start the purchase flow for predefined items
purchaseItems(items, callback)

Requesting Item Purchase

You may bring up the "purchase items" dialog box by using the purchaseItems method on the mtx property on the Kongregate API object. It takes either an array of item identifiers or an array of identifier/metadata objects, as well as a callback function which should be called with the result of the purchase:

Name

Type

Description

items

Array

Array of item identifier strings, or an array of objects each with an identifier and data field.

callback

Function

A callback function for when the purchase dialog is closed.

The callback function is passed an object with the following fields:

Name

Type

Description

success

Boolean

A flag indicating whether or not the purchase was successful.

Example: Purchasing a single item with identifier "sword":

kongregate.mtx.purchaseItems(["sword"], onPurchaseResult);

function onPurchaseResult(result:Object):void {
  trace("Purchase success:" + result.success);
}
kongregate.mtx.purchaseItems(["sword"], onPurchaseResult);

function onPurchaseResult(result) {
  console.log("Purchase success:" + result.success);
}
Application.ExternalEval(@"
  kongregate.mtx.purchaseItems(['sword'], function(result) {
    var unityObject = kongregateUnitySupport.getUnityObject();
    var success = String(result.success);
    unityObject.SendMessage('MyGameObject', 'OnPurchaseResult', success);
  });
");

Metadata

You can attach a metadata string to the item instance if needed which can be retrieved from the server later. It is important to note that the client can change this data using a browser plugin fairly easily, so it is a good idea to obfuscate this string, as well as verify its validity as it relates to your game.

Example: Purchasing an item with metadata attached:

var items:Array = [{identifier:"sword", data:"+1str"}];
kongregate.mtx.purchaseItems(items, onPurchaseResult);

function onPurchaseResult(result:Object):void {
  trace("Purchase success:" + result.success);
}
var items = [{identifier:"sword", data:"+1str"}];
kongregate.mtx.purchaseItems(items, onPurchaseResult);

function onPurchaseResult(result) {
  console.log("Purchase success:" + result.success);
}