Initial Setup

AppGameKit provides several commands to deal with in app purchase. The typical logic for dealing with in app purchases is -

The initial set up can be handled with the following commands.

InAppPurchaseSetTitle ( "your app title" )
InAppPurchaseSetKeys ( "key1", "" )
InAppPurchaseAddProductID ( "productID1", 0 )
InAppPurchaseAddProductID ( "productID2", 0 )
InAppPurchaseAddProductID ( "productID3", 0 )
InAppPurchaseAddProductID ( "productID4", 0 )
InAppPurchaseSetup ( )

The command InAppPurchaseSetTitle takes a string parameter that defines the name of your application. This name may be displayed on any dialogs that get displayed when the user attempts to make an in app purchase.

If your app is to be released on the Google Play Store then you must call InAppPurchaseSetKeys passing in the public key for your application. This can be found within the Google Play Developer console application listing under the Services & APIs section titled "Your license key for this application". If your app does not target the Google Play Store then you do not need to call this command.

Each product you create comes with a unique identifier. This identifier needs to be supplied to the in app purchase set of commands using the InAppPurchaseAddProductID command. For each product you have created call InAppPurchaseAddProductID passing in the product ID and the type of product e.g. non-consumable (0) or consumable (1). When a product is added it will be given a number ID starting with 0. In our example "productID1" has an ID of 0, "productID2" an ID of 1, "productID3" an ID of 2 and "productID4" an ID of 3. These ID numbers are used in the purchase process.

The final step is to make a call to InAppPurchaseSetup. This will use the title, keys and product identifiers to finalise the process of setting up the in app purchase system. It is only after this command has been called that purchases can be made or previous purchases restored.