Game Foundation Tutorials
Using IAP Transactions
IAP Transactions can be an essential part of your product as they can help turn your game into a profitable business.
The mechanism is much the same as for the Virtual Transaction. The fundamental difference is that it turns real money into virtual goods. You'll use a similar editor to describe the transactions, and then use the same APIs to initiate them.
In order to use in-app purchases in your game, you'll need to set up an app and a product in your platform store (e.g. App Store, Google Play, etc.). Once that is set up, you can follow the below steps to get Unity's Purchasing SDK and Game Foundation to do most of your IAP work for you.
Getting set up
Follow instructions on how to enable and import the IAP SDK via the Services Window.
Tip: Game Foundation and IAP SDK can be installed in any order. However, you won't be able to enable the IAP option in the Game Foundation runtime settings until the IAP SDK is imported and compiled.
Select Runtime Settings from the Game Foundation menu.
Enable Unity Purchasing integration by checking the box.
Configure your products in the IAP Catalog window (instructions here).
The IAP Transaction Editor
To create a Virtual Transaction, you need to open the Transaction Window by selecting Window → Game Foundation → Transaction, and display the second tab, called IAP.
In order to see the specifics of the IAP Transaction editor form, please create a new one.
The creation form is similar to the one displayed for the Virtual Transaction, except that the Product Ids section takes the place of the Costs section.
Product IDs
Initiating an IAP Transaction calls the IAP SDK with the product id
defined in the platform stores (Google Store, Apple App Store).
The Product IDs section exposes the fields you can use to link the transaction to those products.
We currently support Google and Apple.
Any product IDs you enter also need to be entered into the IAP Catalog (which you configured in Step 4 above), or they won't be found at runtime.
Fill these fields with the IAP product you have configured in your store. It is not necessary to have both fields filled as long as you compile your app only for the platform you've configured properly.
Rewards
The Rewards section is exactly the same than the one used for Virtual Transactions. For this tutorial, let's be generous and reward the player with 'My First Currency' x 1000 currency and 'My First Item' x 5.
In your code
Similar to previous tutorials, you'll need to initialize Game Foundation. This time, in the callback when initialization is complete, configure the TransactionManager to use a purchasing adapter to handle IAP transactions. The built-in UnityPurchasingAdapter provides a decoupled interaction between Game Foundation and the Unity Purchasing SDK. You shouldn't have to do anything with the adapter directly other than create it and pass it in.
UnityPurchasingAdapter myPurchasingAdapter;
void Start()
{
myPurchasingAdapter = new UnityPurchasingAdapter();
GameFoundation.Initialize(
new MemoryDataLayer(), OnInitSucceeded);
}
void OnInitSucceeded()
{
TransactionManager
.InitializePurchasingAdapter(myPurchasingAdapter);
}
Advanced Tip: Uninitializing Game Foundation also uninitializes the TransactionManager. But you should not create more than one UnityPurchasingAdapter. You should keep a reference to the original UnityPurchasingAdapter you created, so you can give it back to the TransactionManager after reinitialization.
Processing the transaction
Processing an IAP Transaction is done in the same way as processing a Virtual Transaction, as seen in the previous tutorial.
IAP Transactions are asynchronous, meaning that from the time you click the button to the time the transaction is done being processed, it could take a while. It's recommended that your UI take this into consideration. As soon as the purchase button is tapped/clicked, you should disable it to prevent accidental multiple attempts at processing the transaction. Virtual Transactions can also be asynchronous if you are using a cloud backend data layer, so you would want to make the same consideration.
Conclusion
Making your game a successful business is now easier with a turn-key purchasing solution. Having a store, populated with virtual transactions and in-app purchasing transactions that you can easily reconfigure is a must for a good liveOps.
Because you need your retention to be great, and the user experience to be fine tuned, you may need to organize the products you want to sell, or maybe displaying only part of the offers based on conditions (like the player level).
Game Foundation has a solution for you: Stores, that are covered in the next tutorial.