|product_id||The product ID string for the purchase.|
|ds_map||The ds_map that will store the purchase information.|
With this function you can populate a previously created ds_map with a number of key/value pairs that describe the purchase details of the given product. The following data is returned within the map:
- "product" - The product ID string.
- "order" - The unique order ID, where available (not all stores support this).
- "token" - The purchase token string, where available (not all stores support this).
- "payload" - The payload returned by the target store, where available (not all purchases require this, and not all stores support this).
- "receipt" - The receipt string, where available (not all stores support this).
- "response" - A response value (as a real number), where available, based on the response values from Google Play (see here for details).
The map will also contain one further key, "status",
which can be use to check the current status of the purchase. This
key will have one of the following constants as it's value:
|iap_available||Product is available or the game is waiting for the result of a purchase.|
|iap_failed||The purchase attempt failed.|
|iap_purchased||The product was successfully purchased.|
|iap_canceled||The user cancelled the purchase.|
|iap_refunded||The purchase has been rescinded.|
The following notes are related to the "token" and "receipt" keys of the map returned in reference to the target store being used:
- For the Amazon Store the purchase "token" and "receipt" entries are treated as one and the same.
- For Google Play there is no "receipt" data and you are expected to verify purchases via the returned "payload" (should you be verifying via a payload it is recommended that you do not use hard coded values). gameMaker: Studio will still verify the data signature returned with a purchase by Google Play against the public key provided in the IAP tab of the Global Game Settings.
- For Google Play the "token" provided with a purchase is intended for use with consuming purchases.
- For iOS, MacOSX, Windows 8 (N and JS) and Windows Phone target stores there is "receipt" data available for purchases but the associated "token" is generated internally for developer purposes.
NOTE: The ds_map used is not created by the function, meaning that you must create it previously and remove it again from memory when not in use using the appropriate function.
var p_map = ds_map_create();
var p_index = ds_map_find_value(iap_data, "index");
if ds_map_find_value(p_map, "status") == iap_purchased
global.Gold += 100000;
The above code will create a ds_map and then populate it with the key/value pairs for the purchase with the product ID stored in the variable "p_index", which we get from the special iap_data ds_map which is created exclusively in the IAP Event. If the "status" key returns the constant iap_purchased, it will then set a global variable.