In App Purchase MonoGame iOS

This article uses Space Racer MT, a game developed by JMA Web Technologies, to demonstrate these features. To download the game, please click here.

This scenario covers an in-app purchase for buying more levels.

How It Works

The InAppPurchase manager sends a payment request to Apple, using the supplied ProductID. Upon success, the app stores the receipt and sets a is purchased property to true. The receipt ensures the customer purchases new products only. The is purchased property it set in the game to activate the purchase. In Space Racer MT, the is purchased property enables extra levels and difficulties.

The code uses the SKProductsRequest and SKProductsResponse objects to communicate to Apple. The SKProductsRequest contains the ProductID. Apple will return the price and title, based on that ID, for the proper country and language. The price needs to change for each country, using the SKProductExtender class, since the US dollar is a different amount.

It takes a few seconds to reach Apple and there is code for loading until Apple responds.

Installation

Here are the steps to integrate your game with iOS in app purchases:

First, uninstall your app from your device.

In iTunes Connect, add an in app purchase:

Manage In-App Purchases > Create New

Note the product ID because you pass this value to Apple.

In my case, I chose non-consumable because I only want the user to purchase the upgrade once. Consumable means that the upgrade can be purchased multiple times, such as slot machine tokens.

When you make the code, here are some notes:

First, you need to return the product’s localized price. $.99 is different in most countries.

Second, the in app purchase system has downtime. You need to write code for this scenario.