Moscrif API Docs for: 2012q3
Show:

AppStore Class

Extends Object
Library: store

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.

Methods

this

()

Inherited from Object

Constructs new instance of AppStore object.

call

(
  • thisObj
  • [p]
)
Object

Inherited from Object

Invokes the function in context of this set to thisObj.

Parameters:

  • thisObj Object
  • [p] Object optional

Returns:

Object:

clone

() Object

Inherited from Object

Makes copy of the object and returns it.

Returns:

Object: Copy of the object

debugShow

(
  • out=console
  • [p]
)
Array

Inherited from Object

Reports class name and list of property name/values of the object. Intended to use for debugging purposes.

Parameters:

  • out=console Stream

    Stream for output, the default is console.

  • [p] Object optional

Returns:

Array: list of members.

eval

(
  • what
  • [namespace]
)

Inherited from Object

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:

  • what String | Stream

    Code to evaluate.

  • [namespace] Object optional

    Object used as global namespace for evaluated code

Example:

var obj = new Object();
obj.number = 3;
obj.eval("number = number*number", obj);
obj.number; // 9

exists

(
  • tag
  • [deep=false]
)
Boolean

Inherited from Object

Checks property by its tag for existence.

Parameters:

  • tag Symbol

    Symbol of the property.

  • [deep=false] Boolean optional

    If 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:

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:

Boolean: true if purchases are allowed, false otherwise.

Example:

if (AppStore.isAvailable()) {
    console << "Apple iTunes Store is supported";
} else {
    console << "Apple iTunes Store is not supported, or it is disabled!";
}

propertyAt

(
  • tag
)

Inherited from Object

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:

  • tag Symbol

purchase

(
  • identifier
)

This method send purchase request to the store of the given product identifier.

Parameters:

Example:

var appStore = new AppStore();
appStore.purchase("com.company.productA.feature1");

remove

(
  • tag
)
Boolean

Inherited from Object

Removes property of the function by its tag (a.k.a. name).

Parameters:

  • tag Symbol

    Symbol of the property.

Returns:

requestProducts

(
  • identifiers
)

Requests list of available items for sale. See AppStore/onProductsRetrieved

Parameters:

  • identifiers Array

    List 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

()

Inherited from Object

Returns string "[object Object]".

valueOf

() Object

Inherited from Object

Returns object itself.

Returns:

Object:

Properties

className

String

Inherited from Object:

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";

length

Integer

Inherited from Object:

Total number of members this instance contains.

Events

onProductsRetrieved

Called when the App Store responds to the product request requestProducts

Event Payload:

  • valid Array

    List of valid products

  • invalid Array

    Array 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:

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:

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:

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");