Simple IAP System  5.0
Public Member Functions | Static Public Member Functions | Public Attributes | Events | List of all members
DBManager

Stores IAP related data such as all purchases, selected items and ingame currency. Makes use of the JSON format and simple encryption. You should only modify below values once (if necessary at all), thus they aren't public. More...

Inheritance diagram for DBManager:

Public Member Functions

void Init ()
 Initialization called by IAPManager in Awake(). More...
 

Static Public Member Functions

static DBManager GetInstance ()
 Returns a static reference to this script. More...
 
static int GetPurchase (string productID)
 Returns the purchase amount of a product. More...
 
static bool IsPurchased (string productID)
 Convenience method for checking whether a product is purchased or not. More...
 
static void SetPurchase (string productID, int amount=1)
 Sets a product id to purchased state. By default, the purchase amount is 1. Usually you would not want to call this directly except when granting products for free. More...
 
static int AddPurchase (string productID, int amount)
 This will increase the purchase amount by product id and return the new value. Negative values are clamped to 1. More...
 
static void ConsumePurchase (string productID, int amount=0)
 Consumes a product. If amount is not passed in, it is removed from purchased state completely. This should be used with caution. Also used for virtual product costs, expired subscriptions or fake purchases. More...
 
static JSONNode GetPlayerData (string keyID)
 Returns a player data node for a specific id. More...
 
static bool IsPlayerData (string keyID)
 Convenience method for checking whether player data exists or not. More...
 
static void SetPlayerData (string keyID, JSONData data)
 Used for storing your own player-related data on the device. JSONData supports all primitive data types. More...
 
static int AddPlayerData (string keyID, int amount)
 This will increment the player-related data value defined by id and return the new value. Can only work for integer compatible data. Negative values are clamped to 1. More...
 
static void ConsumePlayerData (string keyID, int amount=0)
 Consumes or removes a player data node for a specific id and saves the modified data on the device. Can only work for integer compatible data. If amount is not passed in, it is removed from player data completely. More...
 
static int GetCurrency (string currencyID)
 Returns the amount of funds for a specific currency. More...
 
static void SetCurrency (string currencyID, int amount)
 Overwrites and/or sets the total amount of funds for a specific currency. More...
 
static int AddCurrency (string currencyID, int amount)
 Increases the amount of funds for a specific currency and return the new value. More...
 
static int ConsumeCurrency (string currencyID, int amount)
 Convenience method for decreasing amount of funds for a specific currency and return the new value. More...
 
static bool IsRequirementMet (IAPRequirement req)
 Returns whether a requirement has been met. More...
 
static string GetReceipt (string productID)
 Reads receipt data for a specific product id. Optionally supports decryption. More...
 
static void SaveReceipt (string productID, string data)
 Saves receipt data along with the product id on the device. Optionally supports encryption. More...
 
static bool CanPurchaseVirtual (IAPProduct product)
 This method checks user's currency and product inventory for a virtual purchase. Returns true if the user owns all resources necessary to afford the new product. More...
 
static void PurchaseVirtual (IAPProduct product)
 
static List< string > GetAllPurchased (bool withUpgrades=false)
 Returns list that holds all purchased product ids. By default, for upgradeable products this only returns the current active one. More...
 
static Dictionary< string, int > GetCurrencies ()
 Returns a dictionary of all currencies (name and currently owned amount). More...
 
static Dictionary< string, List< string > > GetAllSelected ()
 Returns a dictionary that holds all group names with selected product ids. More...
 
static List< string > GetSelectedGroup (string groupName)
 Returns all selected products within a specific group. More...
 
static bool SetSelected (string productID, bool single)
 Sets a product id to selected state. If single is true, other ids in the same group get deselected. single = false allows for multi selection. Returns a boolean that indicates whether it was a new selection. More...
 
static bool IsSelected (string id)
 Returns whether a product has been selected. More...
 
static void SetDeselected (string productID)
 Sets a product id to deselected state. More...
 
static string Read ()
 Returns the local data in string format. More...
 
static void Save (string key="")
 Save modified data to the device. Optionally supports encryption. More...
 
static void Overwrite (string otherData)
 Overwrite the current storage with another JSON representation. E.g. after downloading data from a remote server. More...
 
static string GetJSON (string key)
 Returns the desired JSON data node as a string. In case of content, free products are excluded. More...
 
static void Clear (string data)
 Remove data defined by section key. E.g. content, selected or currency. Should be used for testing purposes only. More...
 
static void ClearAll ()
 Removes all PlayerPref data set in this project. Should be used for testing purposes only. More...
 
static string GetDeviceId ()
 

Public Attributes

const string prefsKey = "data"
 The name of the playerpref key on the device. More...
 
const string idPrefixKey = "SIS_"
 The prefix for storing receipt keys on the device. More...
 
bool memoryOnly = false
 Should purchase data only be saved in device memory rather than on disk? Warning: if you do not use some cloud save provider and login system (like PlayFab), your user's purchases will only exist throughout the current game session. More...
 
bool encrypt = false
 Whether the data saved on the device should be encrypted. More...
 
string obfuscKey
 56+8 bit key for encrypting the JSON string: 8 characters, do not use code characters (=.,? etc) and play-test that your key actually works! on Windows Phone this key must be exactly 16 characters (128 bit) long. SAVE THIS KEY SOMEWHERE ON YOUR END, SO IT DOES NOT GET LOST ON UPDATES More...
 
const string currencyKey = "Currency"
 
const string contentKey = "Content"
 
const string selectedKey = "Selected"
 
const string playerKey = "Player"
 

Events

static Action< string > dataUpdateEvent
 Fired when a data save/update on the device happens, delivering the updated key, when available. More...
 
static Action< string > itemSelectedEvent
 Fired when selecting a shop item, delivering its product ID. More...
 
static Action< string > itemDeselectedEvent
 Fired when deselecting a shop item, delivering its product ID. More...
 

Detailed Description

Stores IAP related data such as all purchases, selected items and ingame currency. Makes use of the JSON format and simple encryption. You should only modify below values once (if necessary at all), thus they aren't public.

Member Function Documentation

static int AddCurrency ( string  currencyID,
int  amount 
)
static

Increases the amount of funds for a specific currency and return the new value.

static int AddPlayerData ( string  keyID,
int  amount 
)
static

This will increment the player-related data value defined by id and return the new value. Can only work for integer compatible data. Negative values are clamped to 1.

static int AddPurchase ( string  productID,
int  amount 
)
static

This will increase the purchase amount by product id and return the new value. Negative values are clamped to 1.

static bool CanPurchaseVirtual ( IAPProduct  product)
static

This method checks user's currency and product inventory for a virtual purchase. Returns true if the user owns all resources necessary to afford the new product.

static void Clear ( string  data)
static

Remove data defined by section key. E.g. content, selected or currency. Should be used for testing purposes only.

static void ClearAll ( )
static

Removes all PlayerPref data set in this project. Should be used for testing purposes only.

static int ConsumeCurrency ( string  currencyID,
int  amount 
)
static

Convenience method for decreasing amount of funds for a specific currency and return the new value.

static void ConsumePlayerData ( string  keyID,
int  amount = 0 
)
static

Consumes or removes a player data node for a specific id and saves the modified data on the device. Can only work for integer compatible data. If amount is not passed in, it is removed from player data completely.

static void ConsumePurchase ( string  productID,
int  amount = 0 
)
static

Consumes a product. If amount is not passed in, it is removed from purchased state completely. This should be used with caution. Also used for virtual product costs, expired subscriptions or fake purchases.

static List<string> GetAllPurchased ( bool  withUpgrades = false)
static

Returns list that holds all purchased product ids. By default, for upgradeable products this only returns the current active one.

static Dictionary<string, List<string> > GetAllSelected ( )
static

Returns a dictionary that holds all group names with selected product ids.

static Dictionary<string, int> GetCurrencies ( )
static

Returns a dictionary of all currencies (name and currently owned amount).

static int GetCurrency ( string  currencyID)
static

Returns the amount of funds for a specific currency.

static string GetDeviceId ( )
static

static DBManager GetInstance ( )
static

Returns a static reference to this script.

static string GetJSON ( string  key)
static

Returns the desired JSON data node as a string. In case of content, free products are excluded.

static JSONNode GetPlayerData ( string  keyID)
static

Returns a player data node for a specific id.

static int GetPurchase ( string  productID)
static

Returns the purchase amount of a product.

static string GetReceipt ( string  productID)
static

Reads receipt data for a specific product id. Optionally supports decryption.

static List<string> GetSelectedGroup ( string  groupName)
static

Returns all selected products within a specific group.

void Init ( )

Initialization called by IAPManager in Awake().

static bool IsPlayerData ( string  keyID)
static

Convenience method for checking whether player data exists or not.

static bool IsPurchased ( string  productID)
static

Convenience method for checking whether a product is purchased or not.

static bool IsRequirementMet ( IAPRequirement  req)
static

Returns whether a requirement has been met.

static bool IsSelected ( string  id)
static

Returns whether a product has been selected.

static void Overwrite ( string  otherData)
static

Overwrite the current storage with another JSON representation. E.g. after downloading data from a remote server.

static void PurchaseVirtual ( IAPProduct  product)
static

static string Read ( )
static

Returns the local data in string format.

static void Save ( string  key = "")
static

Save modified data to the device. Optionally supports encryption.

static void SaveReceipt ( string  productID,
string  data 
)
static

Saves receipt data along with the product id on the device. Optionally supports encryption.

static void SetCurrency ( string  currencyID,
int  amount 
)
static

Overwrites and/or sets the total amount of funds for a specific currency.

static void SetDeselected ( string  productID)
static

Sets a product id to deselected state.

static void SetPlayerData ( string  keyID,
JSONData  data 
)
static

Used for storing your own player-related data on the device. JSONData supports all primitive data types.

static void SetPurchase ( string  productID,
int  amount = 1 
)
static

Sets a product id to purchased state. By default, the purchase amount is 1. Usually you would not want to call this directly except when granting products for free.

static bool SetSelected ( string  productID,
bool  single 
)
static

Sets a product id to selected state. If single is true, other ids in the same group get deselected. single = false allows for multi selection. Returns a boolean that indicates whether it was a new selection.

Member Data Documentation

const string contentKey = "Content"
const string currencyKey = "Currency"
bool encrypt = false

Whether the data saved on the device should be encrypted.

const string idPrefixKey = "SIS_"

The prefix for storing receipt keys on the device.

bool memoryOnly = false

Should purchase data only be saved in device memory rather than on disk? Warning: if you do not use some cloud save provider and login system (like PlayFab), your user's purchases will only exist throughout the current game session.

string obfuscKey

56+8 bit key for encrypting the JSON string: 8 characters, do not use code characters (=.,? etc) and play-test that your key actually works! on Windows Phone this key must be exactly 16 characters (128 bit) long. SAVE THIS KEY SOMEWHERE ON YOUR END, SO IT DOES NOT GET LOST ON UPDATES

const string playerKey = "Player"
const string prefsKey = "data"

The name of the playerpref key on the device.

const string selectedKey = "Selected"

Event Documentation

Action<string> dataUpdateEvent
static

Fired when a data save/update on the device happens, delivering the updated key, when available.

Action<string> itemDeselectedEvent
static

Fired when deselecting a shop item, delivering its product ID.

Action<string> itemSelectedEvent
static

Fired when selecting a shop item, delivering its product ID.