Skip to content

Instantly share code, notes, and snippets.

@gcoop
Created September 18, 2010 20:12
Show Gist options
  • Save gcoop/586002 to your computer and use it in GitHub Desktop.
Save gcoop/586002 to your computer and use it in GitHub Desktop.
/**
* ProductStore - Constructor.
*/
function ProductStore()
{
}
/**
* Checks to see whether the product store is open and in-app purchases can be made.
*
* @param function cb Callback function.
*
* @return bool
*/
ProductStore.prototype.isOpen = function(cb)
{
// PhoneGap.exec essentially executes our ProductStore classes isOpen method for us.
PhoneGap.exec("ProductStore.isOpen", cb);
}
/**
* Returns a JSON object with a list of product objects.
*
* @param function cb Callback function.
*
* @return object
*/
ProductStore.prototype.getProducts = function(cb)
{
PhoneGap.exec("ProductStore.getProducts", cb);
}
/**
* Starts a product purchase (async), return JSON object with product purchase status.
*
* @param string id ID for product to purchase.
* @param function cb Callback function.
*
* @return object
*/
ProductStore.buyProduct = function (id, cb)
{
PhoneGap.exec("ProductStore.buyProduct", id, cb);
}
ProductStore.attach = function()
{
if ( !window.plugins )
window.plugins = {};
if ( !window.plugins.ProductStorePlugin )
window.plugins.ProductStorePlugin = new ProductStore();
}
/**
* Add to PhoneGap constructor.
*
* PhoneGap.addConstructor ensures attach function is not run until PhoneGap is ready.
*/
PhoneGap.addConstructor(ProductStore.attach);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment