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:

NameTypeDescription
itemsArrayArray of item identifier strings, or an array of objects each with an identifier and data field.
callbackFunctionA callback function for when the purchase dialog is closed.

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

NameTypeDescription
successBooleanA flag indicating whether or not the purchase was successful.

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

mergeInto(LibraryManager.library, {
  PurchaseItems: function (str) {
    var stringArray = [];
    stringArray.push(UTF8ToString(str));
    kongregate.mtx.purchaseItems(stringArray, function(result){{
          var status = result.success ? 'SUCCESS' : 'FAIL';
          // Fire the callback in the Unity code
          kongregateUnitySupport.getUnityObject().SendMessage('KongregateAPIBehaviour', 'OnPurchaseProductResult', status);
        }});
  }
});
[DllImport("__Internal")]
private static extern void PurchaseItems(string item);

PurchaseItems("sword");

 void OnPurchaseProductResult(string result)
 {
     Debug.Log("OnPurchaseProductResult: " + result);
 }

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 = [{identifier:"sword", data:"+1str"}];
kongregate.mtx.purchaseItems(items, onPurchaseResult);

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