PlayerIO

The fastest way to build online games without breaking a sweat.

HTML5 (Javascript) Client Reference

javascript (html5) payVault class informationClass payVault

Language: Javascript (HTML5)

The PayVault service. Instances of this class represent a specific user's Vault, and contains methods and properties both for inspecting and manipulating the contents. All properties and methods that inspect the Vault requires that it is up-to-date first. This can be achieved explicitly by calling the refresh() method or implicitly by calling any method which modifies the Vault such as credit() or debit().

Example

Here is how to read the Coins balance:

Example

This is how to list all items in a vault:

Example

This is how you check if an item exists:

Example

Credit and Debit can be used like this:

Example

Buying items with Coins is really easy. This requires that you have created an item in the PayVaultItems table in BigDB with the key "speedboost", and a property "PriceCoins" containing the price.

Example

And here's how to consume an item:

Example

When it's time for a user to add more Coins, you can do it like this:

Example

And this is how to let the user buy an item directly. This requires that you have created an item in the PayVaultItems table in BigDB with the key "supercar", and a property "PriceUSD" containing the price.

Example

Finally, there are methods for retrieving the payment history of a user:

Properties

 
coins :Number

The number of coins in this user's Vault. You must call refresh() first to initialize this value.

items :Number

The list of items in this user's Vault. You must call refresh() first to initialize this value.

Methods

 
buy (items, storeItems, successCallback, errorCallback):

Buy items with Coins.

consume (items, successCallback, errorCallback):

Consume items in this Vault. This will cause them to be removed, but this action will not show up in the vault history.

count (string):

Returns the number of items of a given itemKey is in this Vault. This method can only be called on an up-to-date vault.

credit (coinAmount, reason, successCallback, errorCallback):

Give coins to this Vault

debit (coinAmount, reason, successCallback, errorCallback):

Take coins from this Vault

first (itemKey):number

Returns the first item of the given itemKey from this Vault. This method can only be called on an up-to-date vault.

getBuyCoinsInfo (provider, purchaseArguments, successCallback, errorCallback):

Gets information about how to make a coin purchase with the specified PayVault provider.

getBuyDirectInfo (provider, purchaseArguments, items, successCallback, errorCallback):

Gets information about how to make a direct item purchase with the specified PayVault provider.

give (items, successCallback, errorCallback):

Give the user items without taking any of his coins from the vault.

has (itemKey):boolean

This method checks if the Vault contains at least one item of the given itemKey. This method can only be called on an up-to-date vault.

readHistory (page, pageSize, successCallback, errorCallback):

Loads a page of entries from this Vaults history, in reverse chronological order, i.e. newest first.

refresh (successCallback, errorCallback):

Refreshes this Vault, making sure the Items and Coins are up-to-date.

payVault.coins

coins :Number

The number of coins in this user's Vault. You must call refresh() first to initialize this value.

payVault.items

items :Number

The list of items in this user's Vault. You must call refresh() first to initialize this value.

payVault.buy

buy (items, storeItems, successCallback, errorCallback):

Buy items with Coins.

Arguments

items:object[]
A list of items to buy. Each item must have a property called 'itemkey' with the item key. Any additional properties will be converted to item payload.
storeItems:boolean
Whether or not to store the items in the vault after purchase
successCallback:function()
Callback function that will be called when the item(s) have been bought and added to the vault. You don't need to call refresh after this call.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.consume

consume (items, successCallback, errorCallback):

Consume items in this Vault. This will cause them to be removed, but this action will not show up in the vault history.

Arguments

items:vaultItem[]
The VaultItems to use from the users vault - this should be instances of items in this Vault.
successCallback:function()
Callback function that will be called when the item(s) has been consumed. You don't need to call refresh after this call.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.count

count (string):

Returns the number of items of a given itemKey is in this Vault. This method can only be called on an up-to-date vault.

Arguments

string:
itemKey The itemKey of the items to count.

payVault.credit

credit (coinAmount, reason, successCallback, errorCallback):

Give coins to this Vault

Arguments

coinAmount:number
The amount of coins to give.
reason:string
Your reason for giving the coins to this user. This will show up in the vault history, and in the PayVault admin panel for this user.
successCallback:function()
Callback function that will be called when the credit has been completed. You don't need to call refresh after this call.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.debit

debit (coinAmount, reason, successCallback, errorCallback):

Take coins from this Vault

Arguments

coinAmount:number
The amount of coins to take.
reason:string
Your reason for taking the coins from this user. This will show up in the vault history, and in the PayVault admin panel for this user.
successCallback:function()
Callback function that will be called when the credit has been completed. You don't need to call refresh after this call.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.first

first (itemKey):number

Returns the first item of the given itemKey from this Vault. This method can only be called on an up-to-date vault.

Arguments

itemKey:string
The itemKey of the item to get.

payVault.getBuyCoinsInfo

getBuyCoinsInfo (provider, purchaseArguments, successCallback, errorCallback):

Gets information about how to make a coin purchase with the specified PayVault provider.

Arguments

provider:string
The name of the PayVault provider to use for the coin purchase.
purchaseArguments:object
Any additional information that will be given to the PayVault provider to configure this purchase.
successCallback:function(object)
Callback function that will be called with provider specifics about how to complete the purchase.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.getBuyDirectInfo

getBuyDirectInfo (provider, purchaseArguments, items, successCallback, errorCallback):

Gets information about how to make a direct item purchase with the specified PayVault provider.

Arguments

provider:string
The name of the PayVault provider to use for the item purchase.
purchaseArguments:object
Any additional information that will be given to the PayVault provider to configure this purchase.
items:object[]
A list of items to buy. Each item must have a property called 'itemkey' with the item key. Any additional properties will be converted to item payload.
successCallback:function(object)
Callback function that will be called with provider specifics about how to complete the purchase.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.give

give (items, successCallback, errorCallback):

Give the user items without taking any of his coins from the vault.

Arguments

items:object[]
A list of items to give. Each item must have a property called 'itemkey' with the item key. Any additional properties will be converted to item payload.
successCallback:function()
Callback function that will be called when the item(s) have been added to the vault. You don't need to call refresh after this call.
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.has

has (itemKey):boolean

This method checks if the Vault contains at least one item of the given itemKey. This method can only be called on an up-to-date vault.

Arguments

itemKey:string
The itemKey to check for.

payVault.readHistory

readHistory (page, pageSize, successCallback, errorCallback):

Loads a page of entries from this Vaults history, in reverse chronological order, i.e. newest first.

Arguments

page:number
The page of entries to load. The first page has number 0.
pageSize:number
The number of entries per page.
successCallback:function(payVaultHistoryEntries)
Callback function that will be called with the history entries found
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs

payVault.refresh

refresh (successCallback, errorCallback):

Refreshes this Vault, making sure the Items and Coins are up-to-date.

Arguments

successCallback:function()
Callback function that will be called when the refresh is complete
errorCallback:function(PlayerIOError)
Callback function that will be called if an error occurs