{"_id":"56af6e8460a37a0d00ed87ac","project":"56abbf55f25f160d00e17f4e","version":{"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","__v":12,"createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"category":{"_id":"56af6d6ecc4cbd0d00ce2c88","pages":["56af6e8460a37a0d00ed87ac","56af71e58be2ea0d00b48887","56af73a08be2ea0d00b48890"],"version":"56abbf55f25f160d00e17f51","__v":3,"project":"56abbf55f25f160d00e17f4e","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-01T14:36:30.275Z","from_sync":false,"order":2,"slug":"concepts","title":"Kongregate APIs & Concepts"},"__v":17,"user":"56abbec30b9e0b0d00616274","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-01T14:41:08.265Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Approval required\",\n  \"body\": \"If you are selling in-app purchases you will need to submit your game to apps:::at:::kongregate.com for QA testing and approval prior to publishing the game. You will be able to test the API before this, it only prevents launching without approval.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Edge case: already live games\",\n  \"body\": \"If your game is already live and you now want to add in-app purchases you will need to contact us **before** you are able to test out the API functionality.\"\n}\n[/block]\n## Kreds (Virtual Goods) API\n\nThe Kreds API allows users to purchase virtual items in your game using Kongregate's \"kreds\" currency. The API includes both client and server-side components. The client API initiates purchases and can also check the user's inventory, which is useful for single-player game unlocks like map packs and advanced features. For games that have consumable items and currency sales, the server-side API enables the game to \"use\" (decrement the count of) an item in the player's Kongregate inventory.\n\nThere are also two different ways to manage your inventory of purchasable items. The first is to create items manually on our web interface. This is most useful for single-player client-side games, as well as multiplayer games that have only a few items (usually in the form of packages of premium currency) that don't change price often. The other option is to use the [dynamic item creation/pricing API](doc:api-dynamic-purchasing), which uses a secure sever-side call to let Kongregate know what the item is and how much it should cost. This is useful for games with large inventories of items that are priced directly in Kreds, or games that may which to change the price of items programmatically and regularly. It also may be easier for games currently using Facebook's Payments API to use this setup.\n\n### Quick Function Reference\n\n**Client Functions:**\n\n*   [purchaseItems](doc:client-api-mtx-purchaseitems) - Requests an item for purchase\n*   [purchaseItemsRemote](doc:client-api-mtx-purchaseitemsremote) - Starts the dynamic purchase flow.\n*   [requestItemList](doc:client-api-mtx-requestitemlist) - Request item definitions.\n*   [requestUserItemList](doc:client-api-mtx-requestuseritemlist) - Requests list of a user's inventory of items\n*   [showKredPurchaseDialog](doc:client-api-mtx-showkredpurchasedialog) - Opens the Kred Purchase lightbox\n\n**REST Functions:**\n\n*   [Items - List](doc:server-api-item-list) - Requests a list of all available items\n*   [Items - User](doc:server-api-user-items)  - Request a user's inventory\n*   [Items - Consume](doc:server-api-use-item) - Consumes a user's limited-use item\n\n## Setting Up Items\n\nThere are two ways to set up virtual goods items in the Kongregate backend:\n\n### Dynamic Item Setup\n\nDynamic item management requires secure, signed server-to-server communications. You can read details about the [Dynamic Purchasing API](doc:api-dynamic-purchasing)  to get that set up and running. This method is often easier for developers porting from Facebook, or if you will be making regular changes to pricing and items.\n\n### Manual Item Setup\n\nIf you will be selling only a few packs of virtual currency at consistent prices, or the game is client-only, the manual item method (described on the rest of this page) is often quicker and easier to set up. The item management tools are accessible by adding `/items` to the end of your game URL, for example:\n\n`http://www.kongregate.com/games/YourName/YourGame/items`\n\nOn the `/items` page you will be able to add and modify the items that you will be selling in your game. \"Items\" is a generic term used on our end and can really apply to map packs, premium currency bundles, in-game upgrades, etc. Items have the following attributes:\n\n*   **Identifier** - This is an internal identifier that your game will reference the item with.\n*   **Name** - The name of the item, which will be displayed to the player when making a purchase.\n*   **Description** - A description for the item that will also be displayed to the player.\n*   **Initial Uses** - The number of times an item can be used. Perpetual unlocks should have their initial uses field left blank (unlimited). One time use items, like premium currency, should be set to 1\\. If you have multi-use items, they will track remaining uses and decrement each time the item is consumed.\n*   **Price** - The price of the item in Kreds.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"The **Image** attribute for these items is largely deprecated and very optional. It's probably not worth setting them up at this point.\",\n  \"title\": \"Note\"\n}\n[/block]\nOnce the [Client API](doc:client-api-introduction) is loaded, you can access the microtransaction functions from the `mtx` object on the API, for example `kongregate.mtx.purchaseItems`, etc.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"If using the JavaScript API via Unity, make sure to read the [Unity API](doc:unity-api#section-callbacks-asynchronous-methods) documentation about how to handle callbacks to ensure you can receive the results of your purchase and inventory operations.\"\n}\n[/block]\n## Item Purchase Flow\n\nWhen a player wants to purchase an item in your game, it should go through these steps to complete it.\n\n### Requesting a Purchase\n\nTo begin a transaction, call the [purchaseItems](doc:client-api-mtx-purchaseitems)  or [purchaseItemsRemote](doc:client-api-mtx-purchaseitemsremote)  method on the `mtx` object to bring up the \"purchase items\" dialog box. The dialog box will handle the transaction, including helping the user buy more Kreds if needed. While the dialog box will return a success/fail to the game, these results should always be verified with a separate (server-side if possible) API call.\n\nAfter a purchase completes, you will get a client-side callback. There is also a server-side callback if you have set up your [callback URL](doc:server-side-http) whenever the inventory is invalidated (i.e. has been changed by adding a new purchased item).\n\nPrices for items should be listed in Kreds, not dollars, to avoid confusion and ambiguity (since Kreds get slightly cheaper when purchased in bulk). If you would like to put an icon of Kreds in the game, please feel free to use either of these images and scale them as needed or as reference.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Single Kred\",\n    \"h-1\": \"Stack of Kreds\",\n    \"0-0\": \"![Single Kred](https://cdn3.kongcdn.com/assets/files/0001/4666/kred_single.png)\",\n    \"0-1\": \"![Stack of Kreds](https://cdn3.kongcdn.com/assets/files/0001/4665/kred_stack.png)\"\n  },\n  \"cols\": 2,\n  \"rows\": 1\n}\n[/block]\n### Requesting User Item Instances\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"This is not needed when utilizing the Dynamic Purchase API\"\n}\n[/block]\nThe inventory of any user can be requested by using the [requestUserItemList](doc:client-api-mtx-requestuseritemlist)  method on the client side, or the [user_items](doc:server-api-user-items) method on the server side. Checking the existence of an item in the user's inventory can be used client-side to track game unlocks. On the server side, this method should always be used to confirm that a purchase was fully successful prior to giving credit for the purchase to the user.\n\nAdditionally, the server should check for item instances in a player's inventory whenever a game session starts. If they are present, they should be credited and consumed (with the `use_item` call described below) at that time. The reason for this is two-fold. First, it helps reduce customer support issues that may occur due to connectivity issues or bugs during a purchase since a player can refresh the game page and get the item properly credited. Additionally, if the game qualifies for promotional efforts from us one such promotion is giving away items to players on Kongregate for achieving goals, and that can only be done if we can put an item in a player's inventory outside of the normal purchase flow.\n\n### Using/Consuming an Item\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"This is not needed when utilizing the Dynamic Purchase API\"\n}\n[/block]\nIf you have a consumable item, or anything that is intended to only be credited once, you will need to \"use\" the item to make sure the status of the item is tracked on our servers. You can use an item with the [use_item](doc:server-api-use-item) server-side call. Using an item decrements its \"remaining uses\" count on the Kongregate servers. If it is decremented to 0 it will be removed. Items that have a starting number of uses set to 0 (unlimited) cannot be used in this manner.\n\n### Testing purchases\n\nThe game's developer account (that is, the one you used to create/upload the game) can make free test purchases in that game. All purchases will cost 0 Kreds, but will go through the full process and be functional for testing. If you need additional test accounts, let us know the Kongregate usernames and we can give them access and some kreds to test with.\n\n### Requesting a List of Available Items\n\nIf you are programmatically generating purchase lists within your game it may be useful to get a list of items available for purchase from Kongregate. The [items](doc:server-api-item-list)  call or [requestItemList](doc:client-api-mtx-requestitemlist)  client method will allow you to get this list, as well as tags associated with the items so you can filter out the irrelevant ones.\n\n### Displaying a \"Free Kreds\" Dialog\n\nSome games have \"earn\" or \"free\" buttons to help players without access to a credit card make purchases in the game. You can bring up the purchase dialog and focus it on either mobile payments or offers to help your players find a payment method that may work better for them. You can do this using the [showKredPurchaseDialog](doc:client-api-mtx-showkredpurchasedialog)  method. The only argument is the default purchase method you would like to display, which can be either \"offers\" to show the free/offer Kred options, or \"mobile\" to show the SMS options. Any other value will simply show the default purchase dialog.\n\n### Handling Guest Users\n\nSince guest users on Kongregate are not allowed to purchase items, you must decide how you want to handle them in your game. In general, whenever a guest user wants to purchase an item, it is a good idea to display a message letting them know they must sign in or register before they can purchase, and then display the sign-in lightbox. Further documentation on this process can be found in [Handling Guests](doc:concepts-handling-guests).","excerpt":"","slug":"concepts-virtual-goods","type":"basic","title":"Kreds & Virtual Goods"}

Kreds & Virtual Goods


[block:callout] { "type": "warning", "title": "Approval required", "body": "If you are selling in-app purchases you will need to submit your game to apps@kongregate.com for QA testing and approval prior to publishing the game. You will be able to test the API before this, it only prevents launching without approval." } [/block] [block:callout] { "type": "danger", "title": "Edge case: already live games", "body": "If your game is already live and you now want to add in-app purchases you will need to contact us **before** you are able to test out the API functionality." } [/block] ## Kreds (Virtual Goods) API The Kreds API allows users to purchase virtual items in your game using Kongregate's "kreds" currency. The API includes both client and server-side components. The client API initiates purchases and can also check the user's inventory, which is useful for single-player game unlocks like map packs and advanced features. For games that have consumable items and currency sales, the server-side API enables the game to "use" (decrement the count of) an item in the player's Kongregate inventory. There are also two different ways to manage your inventory of purchasable items. The first is to create items manually on our web interface. This is most useful for single-player client-side games, as well as multiplayer games that have only a few items (usually in the form of packages of premium currency) that don't change price often. The other option is to use the [dynamic item creation/pricing API](doc:api-dynamic-purchasing), which uses a secure sever-side call to let Kongregate know what the item is and how much it should cost. This is useful for games with large inventories of items that are priced directly in Kreds, or games that may which to change the price of items programmatically and regularly. It also may be easier for games currently using Facebook's Payments API to use this setup. ### Quick Function Reference **Client Functions:** * [purchaseItems](doc:client-api-mtx-purchaseitems) - Requests an item for purchase * [purchaseItemsRemote](doc:client-api-mtx-purchaseitemsremote) - Starts the dynamic purchase flow. * [requestItemList](doc:client-api-mtx-requestitemlist) - Request item definitions. * [requestUserItemList](doc:client-api-mtx-requestuseritemlist) - Requests list of a user's inventory of items * [showKredPurchaseDialog](doc:client-api-mtx-showkredpurchasedialog) - Opens the Kred Purchase lightbox **REST Functions:** * [Items - List](doc:server-api-item-list) - Requests a list of all available items * [Items - User](doc:server-api-user-items) - Request a user's inventory * [Items - Consume](doc:server-api-use-item) - Consumes a user's limited-use item ## Setting Up Items There are two ways to set up virtual goods items in the Kongregate backend: ### Dynamic Item Setup Dynamic item management requires secure, signed server-to-server communications. You can read details about the [Dynamic Purchasing API](doc:api-dynamic-purchasing) to get that set up and running. This method is often easier for developers porting from Facebook, or if you will be making regular changes to pricing and items. ### Manual Item Setup If you will be selling only a few packs of virtual currency at consistent prices, or the game is client-only, the manual item method (described on the rest of this page) is often quicker and easier to set up. The item management tools are accessible by adding `/items` to the end of your game URL, for example: `http://www.kongregate.com/games/YourName/YourGame/items` On the `/items` page you will be able to add and modify the items that you will be selling in your game. "Items" is a generic term used on our end and can really apply to map packs, premium currency bundles, in-game upgrades, etc. Items have the following attributes: * **Identifier** - This is an internal identifier that your game will reference the item with. * **Name** - The name of the item, which will be displayed to the player when making a purchase. * **Description** - A description for the item that will also be displayed to the player. * **Initial Uses** - The number of times an item can be used. Perpetual unlocks should have their initial uses field left blank (unlimited). One time use items, like premium currency, should be set to 1\. If you have multi-use items, they will track remaining uses and decrement each time the item is consumed. * **Price** - The price of the item in Kreds. [block:callout] { "type": "info", "body": "The **Image** attribute for these items is largely deprecated and very optional. It's probably not worth setting them up at this point.", "title": "Note" } [/block] Once the [Client API](doc:client-api-introduction) is loaded, you can access the microtransaction functions from the `mtx` object on the API, for example `kongregate.mtx.purchaseItems`, etc. [block:callout] { "type": "info", "title": "Note", "body": "If using the JavaScript API via Unity, make sure to read the [Unity API](doc:unity-api#section-callbacks-asynchronous-methods) documentation about how to handle callbacks to ensure you can receive the results of your purchase and inventory operations." } [/block] ## Item Purchase Flow When a player wants to purchase an item in your game, it should go through these steps to complete it. ### Requesting a Purchase To begin a transaction, call the [purchaseItems](doc:client-api-mtx-purchaseitems) or [purchaseItemsRemote](doc:client-api-mtx-purchaseitemsremote) method on the `mtx` object to bring up the "purchase items" dialog box. The dialog box will handle the transaction, including helping the user buy more Kreds if needed. While the dialog box will return a success/fail to the game, these results should always be verified with a separate (server-side if possible) API call. After a purchase completes, you will get a client-side callback. There is also a server-side callback if you have set up your [callback URL](doc:server-side-http) whenever the inventory is invalidated (i.e. has been changed by adding a new purchased item). Prices for items should be listed in Kreds, not dollars, to avoid confusion and ambiguity (since Kreds get slightly cheaper when purchased in bulk). If you would like to put an icon of Kreds in the game, please feel free to use either of these images and scale them as needed or as reference. [block:parameters] { "data": { "h-0": "Single Kred", "h-1": "Stack of Kreds", "0-0": "![Single Kred](https://cdn3.kongcdn.com/assets/files/0001/4666/kred_single.png)", "0-1": "![Stack of Kreds](https://cdn3.kongcdn.com/assets/files/0001/4665/kred_stack.png)" }, "cols": 2, "rows": 1 } [/block] ### Requesting User Item Instances [block:callout] { "type": "info", "title": "Note", "body": "This is not needed when utilizing the Dynamic Purchase API" } [/block] The inventory of any user can be requested by using the [requestUserItemList](doc:client-api-mtx-requestuseritemlist) method on the client side, or the [user_items](doc:server-api-user-items) method on the server side. Checking the existence of an item in the user's inventory can be used client-side to track game unlocks. On the server side, this method should always be used to confirm that a purchase was fully successful prior to giving credit for the purchase to the user. Additionally, the server should check for item instances in a player's inventory whenever a game session starts. If they are present, they should be credited and consumed (with the `use_item` call described below) at that time. The reason for this is two-fold. First, it helps reduce customer support issues that may occur due to connectivity issues or bugs during a purchase since a player can refresh the game page and get the item properly credited. Additionally, if the game qualifies for promotional efforts from us one such promotion is giving away items to players on Kongregate for achieving goals, and that can only be done if we can put an item in a player's inventory outside of the normal purchase flow. ### Using/Consuming an Item [block:callout] { "type": "info", "title": "Note", "body": "This is not needed when utilizing the Dynamic Purchase API" } [/block] If you have a consumable item, or anything that is intended to only be credited once, you will need to "use" the item to make sure the status of the item is tracked on our servers. You can use an item with the [use_item](doc:server-api-use-item) server-side call. Using an item decrements its "remaining uses" count on the Kongregate servers. If it is decremented to 0 it will be removed. Items that have a starting number of uses set to 0 (unlimited) cannot be used in this manner. ### Testing purchases The game's developer account (that is, the one you used to create/upload the game) can make free test purchases in that game. All purchases will cost 0 Kreds, but will go through the full process and be functional for testing. If you need additional test accounts, let us know the Kongregate usernames and we can give them access and some kreds to test with. ### Requesting a List of Available Items If you are programmatically generating purchase lists within your game it may be useful to get a list of items available for purchase from Kongregate. The [items](doc:server-api-item-list) call or [requestItemList](doc:client-api-mtx-requestitemlist) client method will allow you to get this list, as well as tags associated with the items so you can filter out the irrelevant ones. ### Displaying a "Free Kreds" Dialog Some games have "earn" or "free" buttons to help players without access to a credit card make purchases in the game. You can bring up the purchase dialog and focus it on either mobile payments or offers to help your players find a payment method that may work better for them. You can do this using the [showKredPurchaseDialog](doc:client-api-mtx-showkredpurchasedialog) method. The only argument is the default purchase method you would like to display, which can be either "offers" to show the free/offer Kred options, or "mobile" to show the SMS options. Any other value will simply show the default purchase dialog. ### Handling Guest Users Since guest users on Kongregate are not allowed to purchase items, you must decide how you want to handle them in your game. In general, whenever a guest user wants to purchase an item, it is a good idea to display a message letting them know they must sign in or register before they can purchase, and then display the sign-in lightbox. Further documentation on this process can be found in [Handling Guests](doc:concepts-handling-guests).