Kongregate Developers

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, as shown below:

purchaseItems(items:Array, callback:Function):void
  • items:Array - The array of item identifier strings or item/metadata objects.
  • callback:Function - The callback function

The callback will be called with a single Object argument which has one field:

  • success:Boolean - True if the user successfully purchased the items

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

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

function onPurchaseResult(result:Object){
  trace("Purchase success:" + result.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){
  trace("Purchase success:" + result.success);
}

Comments