API Functions

Requesting Item Purchase

You may bring up the "purchase items" dialog box by using the purchaseItems method on the microtransaction services 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 "sword" and "shield" with no metadata, and then purchasing a "sword" with metadata equal to "+1str"

// Purchase item with no metadata:
kongregate.mtx.purchaseItems(["sword","shield"], onPurchaseResult );

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

// The purchase callback
function onPurchaseResult(result:Object){
  trace("Purchase success:" + result.success);
}

The second call shows how to attach a string of metadata to the item instance, which you can retrieve 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.

Comments