AppStore Class
In-App Purchases are encapsulated in objects of the AppStore class. This class supports only Apple iTunes Store. Google's Android Market will be added soon in separate class.
Item Index
Methods
- this constructor
- call
- clone
- debugShow
- eval
- exists
- finish
- isAvailable static
- propertyAt
- purchase
- remove
- requestProducts
- toString
- valueOf
Methods
this
()
Constructs new instance of AppStore object.
call
thisObj[p]
Invokes the function in context of this set to thisObj.
Parameters:
-
thisObjObject -
[p]Object optional
Returns:
clone
() Object
Makes copy of the object and returns it.
Returns:
debugShow
out=console[p]
Reports class name and list of property name/values of the object. Intended to use for debugging purposes.
Parameters:
-
out=consoleStreamStream for output, the default is console.
-
[p]Object optional
Returns:
eval
what[namespace]
Evaluates (interprets) what with context of this equal to the object. If namespace object is given then it is used as global namespace for evaluated code.
Parameters:
Example:
var obj = new Object();
obj.number = 3;
obj.eval("number = number*number", obj);
obj.number; // 9
exists
tag[deep=false]
Checks property by its tag for existence.
Parameters:
-
tagSymbolSymbol of the property.
-
[deep=false]Boolean optionalIf deep == true then does deep lookup - in function itself and its chain of classes.
Returns:
finish
transaction
To confirm finish of purchase process to have to call this method otherwise AppStore will think the transaction was interrupted and will attempt to resume it on the next application launch.
Parameters:
-
transactionAppStoreTransactionThe transaction object created during callbacks.
isAvailable
() Boolean static
This static method returns true if purchases are allowed, false otherwise. iOS device can be disabled to make payments (to prevent children from accidentally purchasing things without parents' permission).
Returns:
Example:
if (AppStore.isAvailable()) {
console << "Apple iTunes Store is supported";
} else {
console << "Apple iTunes Store is not supported, or it is disabled!";
}
propertyAt
tag
Does lookup in the object for member/property by its tag. This is a direct equivalent of obj.tag construction. Be patient when using propertyAt in "property undefined handler". It can leads to "Stack overflow" exception, because propertyAt can call "property undefined handler". See also exists functions.
Parameters:
-
tagSymbol
purchase
identifier
This method send purchase request to the store of the given product identifier.
Parameters:
-
identifierString
Example:
var appStore = new AppStore();
appStore.purchase("com.company.productA.feature1");
remove
tag
Removes property of the function by its tag (a.k.a. name).
Parameters:
-
tagSymbolSymbol of the property.
Returns:
requestProducts
identifiers
Requests list of available items for sale. See AppStore/onProductsRetrieved
Parameters:
-
identifiersArrayList of Strings of product identifiers you want to retrieve information.
Example:
var appStore = new AppStore();
appStore.onProductsRetrieved = function (valid, invalid) {
for (var val in valid) {
console << val.productIdentifier << "\n";
console << val.title << "\n";
console << val.description << "\n";
console << val.price << "\n";
console << val.priceLocale << "\n";
console << "\n";
}
for (var inv in invalid)
console << "invalid product identifier: " << inv << "";
}
appStore.requestProducts(["com.company.productA.feature1", "com.company.productA.feature2"]);
toString
()
Returns string "[object Object]".
valueOf
() Object
Returns object itself.
Returns:
Properties
className
String
Name of the class if object was created as instance of user defined class.
Example:
class Clazz
{
}
var instance = new Clazz();
var obj = { };
// obj has "undefined" className
assert obj.className == undefined;
// instance has "Clazz" className
assert instance.className == "Clazz";
Events
onProductsRetrieved
Called when the App Store responds to the product request requestProducts
Event Payload:
-
validArrayList of valid products
-
invalidArrayArray of strings of invalid product identfiers.
Example:
var appStore = new AppStore();
appStore.onProductsRetrieved = function (valid, invalid) {
for (var val in valid) {
console << val.productIdentifier << "\n";
console << val.title << "\n";
console << val.description << "\n";
console << val.price << "\n";
console << val.priceLocale << "\n";
console << "\n";
}
for (var inv in invalid)
console << "invalid product identifier: " << inv << "";
}
appStore.requestProducts(["com.company.productA.feature1", "com.company.productA.feature2"]);
onTransactionCompleted
Called when the purchase has been successfully processed.
Event Payload:
-
transactionAppStoreTransaction
Example:
var appStore = new AppStore();
appStore.onTransactionCompleted = function(transaction) {
appStore.finish(transaction);
}
appStore.purchase("com.company.productA.feature1");
onTransactionFailed
Called when the purchase has been failed.
Event Payload:
-
transactionAppStoreTransaction -
errorCodeInteger -
errorMessageString
Example:
var appStore = new AppStore();
appStore.onTransactionFailed = function(transaction, errorCode, errorMessage) {
appStore.finish(transaction);
console << "Error #" << errorCode << "\n";
console << "\t" << errorMessage << "\n";
}
appStore.purchase("com.company.productA.feature1");
onTransactionRestored
Called when the purchase has been restored.
Event Payload:
-
transactionAppStoreTransaction
Example:
var appStore = new AppStore();
appStore.onTransactionRestored = function(transaction) {
console << "Transaction of product identifier " << transaction.productIdentifier << " has been restored.\n";
}
appStore.purchase("com.company.productA.feature1");
