Cordova In-app Purchase Plugin

This Cordova/PhoneGap plugin is used for In-App Purchase on iOS, Android and Windows apps.

In order to work demo apps, in-app billing setup is necessary in App Store Connect.
To check third party cordova plugins, you need to create a custom build debugger ( Android version or iOS version ).

Demo

Enable the Plugin in Monaca IDE

  1. From the IDE menu, go to Config → Manage Cordova Plugins .

  2. Click on Import Cordova Plugin button. Then, you can choose to import the plugin using a ZIP file or URL/Package Name.

Usage

The store API is mostly events based. As a user of this plugin, you will have to register listeners to changes happening to the products you register.

The core of the listening mechanism is the when() method. It allows you to be notified of changes to one or a set of products using a query mechanism:

store.when("product").updated(refreshScreen);
store.when("full version").owned(unlockApp);
store.when("subscription").approved(serverCheck);
store.when("downloadable content").downloaded(showContent);
etc.

The updated event is fired whenever one of the fields of a product is changed (its owned status for instance).

This event provides a generic way to track the statuses of your purchases, to unlock features when needed and to refresh your views accordingly.

API References

In this page, we only describe some main APIs used in our Demo. For a complete API references, please refer to here.

store.verbosity

The verbosity property defines how much you want store.js to write on the console. Available values are as follows:

  • store.QUIET or 0 to disable all logging (default)
  • store.ERROR or 1 to show only error messages
  • store.WARNING or 2 to show warnings and errors
  • store.INFO or 3 to also show information messages
  • store.DEBUG or 4 to enable internal debugging messages.
store.verbosity

Example

// Enable maximum logging level
store.verbosity = store.DEBUG;

store.register()

Add or register a product to the store before you can use them in your code.

store.register(product);

Parameter

Name Type Description
product JSON Object Production options

Example

store.register({
    id:    'consumable1', // id without package name!
    alias: 'Extra Life',
    type:   store.CONSUMABLE
});

store.refresh()

Load product data from the servers and restore whatever already have been purchased by the user.

store.refresh();

Example

// ...
// register products and events handlers here
// ...
//
// then and only then, call refresh.
store.refresh();

store.get(id/alias)

Retrieve a product by its id or alias.

store.get(id/alias)
Name Type Description
id String Product ID
alias String Product Name

Example

var product = store.get("consumable1");

store.when(query, event, callback)

Register a callback for a product-related event. For more details about this api, please refer to here

store.when(query, event, callback)

Return Value

  • Promise

Example

store.when("subscription1", "approved", function(product) { 
    console.log("Subscription approved!");
});

store.error(callback)

Register an error handler.

store.error(callback);

Example

store.error(function(e){
    console.log("ERROR " + e.code + ": " + e.message);
});

store.ready(callback)

Register the callback to be called when the store is ready to be used.

If the store is already ready, callback is executed immediately. store.ready() without arguments will return the ready status.

store.ready(callback)

Example

store.ready(function() {
    console.log("Store is ready");
});