Last updated
Last updated
Support us as a and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our ... become a sponsor today!
Steam Microtransactions (In-Game Purchases) are handled via the feature.
You cannot test Steam Inventory features with App ID 480 aka Spacewars.
To test Steam Inventory features including but not limited to microtransactions, crafting, player inventory, etc. you will need to register for your app ID and configure your own Steam Inventory Items. As a result of this limitation from Valve, the sample scenes for Inventory cannot be used with App 480 in any functional form.
A common request we see is for an example in-game store or other "MTX" (micro-transaction) example.
Valve's Spacewar doesn't have a usable Steam Inventory configuration and since your store would be highly dependent on what items you have and how they are configured. The sample scene we have provided (9 Item Store Tutorial) simply contains example scripts based on this article and is meant to be a teaching tool, not a functional example.
This article will describe the concepts of an item store and cover several common use cases providing abstract examples for each. Finally, in the end, we will compile a list of commonly asked questions and of course, if you have any questions please reach out to the community on our server.
Your in-game currency would simply be an inventory item. You would then set up "Exchange" recipes for all the items that can be "purchased" for that currency.
In short in-game currency is simply exchanging X items for Y items. See the article for more information on exchanging items.
So you have set up your inventory items, You are going to use full Client API so you can't simulate an end-to-end purchase. You're asking yourself ... How do I test my game logic to make sure it's handling inventory change correctly?
This is done when you want to send the user to the Steam Store page so they can "check out" spending real money on some item. Note you can call Start Purchase on a single item or you can set up a shopping cart building up a collection of items and call Start Purchase on all of them.
We have constructed a tool to help you manage a shopping cart in the game. This tool is capable of adding, removing and editing the quantities of items in it, it can report the estimated total of the cart and can manage and track the purchase operation through authorization reporting issues and or successes through simple Unity events.
On your Item Definition, you will see a Start Purchase option. A similar method is available on the Data Layer, Scriptable Object and of course in the Inventory API. You simply call this method indicating the number of items you wish to start a purchase with.
If the item has a properly formatted price or price category (it cannot have both) then the item will be added to the user's Steam Store cart ready for purchase. The Steam Overlay will open showing the user this cart.
When the user completes the transaction you will be notified in two ways.
You can also start purchase on a set of items, the following is the code from our Shopping Cart tool and how it handles this use case.
The first step in this process is the CanExchange check.
The Start Purchase function asks Steam to load a shopping cart with given items and present it to the user for payment processing. Only items that have a defined price can be purchased, only items available to this user can be purchased. Steam will process the payment from that point forward and you are not assured of getting a response. For example, a player may simply leave the cart open and never process the transaction, they may cancel the transaction, modify items in the cart, etc.
To use the feature you first need to know what item ID you want to "craft" i.e. exchange other items for.
Next, you need to know the instance ID and count of each item you will be exchanging. You typically get the Instance IDs from the Get All Items request but you can for example cascade crafting requests.
An example of a cascaded crafting request would be to craft Iron Ore into Iron Bars and then craft the Iron Bars into an Iron Sword. That is your exchanging 1 or more Ore items for Bars and 1 or more Bars for Sword.
The following image is an example of creating the "recipe" array needed by the Exchange Items node. In this example, we assumed we needed 15 of some item and if we had 2 stacks of 10 each with IDs of 123 and 124 respectively then the below "Make Array" node would be the correct recipe.
In the example, we are using all of stack 123 and 5 from stack 124.
If you are setting up an in-game store or some similar microtransaction system you will likely want to know what the price of the item is for this user.
Notice that the event tells you the currency code and currency symbol seen for the user and that prices are returned as a whole number e.g. int64
In the case of say USD you would want to convert the price to a float and divide by 100 so that 199 becomes 1.99
The above are the relevant nodes to yield a string formatted for the user's currency assuming a cent-based currency like USD, GBP, etc. The resulting string here would look like this `$1.99" assuming a base price of 199 and a currency symbol of $
Use the and click the "Grant" button beside any of the items, this will cause it to grant you an item which will raise the ... you can now observe your game logic and ensure it's performing as you expected.
You would add this script to your Store/Shop UI and use its members to add, remove and edit the items in the cart. Once you have populated the cart and are ready to "check out" you can call StartPurchase in the manager to kick off the process and track the results. To learn more about the use of .
Transaction Complete Event
Inventory Change Event
Assuming you want to track the completion of the order you should listen on the Micro Transaction Authorization Response. You can find this on the component or directly in the . In either case, this is an event that is raised when the Steam client informs your game of a completed e.g. authorization on a transaction. The event will indicate the app the transaction is for, the order ID of the transaction and rather or not the transaction was authorized.
It's fairly common to have users "purchase" items with an in-game currency. In reality, this is not a purchase it is an exchange. That is it is similar to crafting where some reagents are exchanged for some other item. Exchanges must be done one item at a time and the following code snippet shows how you would go about doing that for a given .
is a method on the that takes a given recipe as an input and has an output that collects the required items to complete the recipe.
Assuming this returns true then we can complete an exchange for this item on this recipe, so the next step is to request that using the output the method provided us. Unlike StartPurchase we will know in a single step whether or not this was a success and the items will already be updated.
If you want to fetch the price in the user's currency see: and . You can check if there is a price at all via .
The can be used to know when the player's inventory has changed. This will be raised by Steam for any change caused by the game but may not be raised in response to changes that start outside the game so it's important to not use this as an alternative to for keeping your view of the player's inventory up to date.
If a transaction is processed and authorized you will see a event be executed. That event will carry the Order ID which can be matched to the Order ID created with the Start Purchase request.
lets you pass in an array of to exchange for a given item. The callback works much like the discussed in the article.
Aka MTX, IAP, In App Purchase, cash shop, etc.