I added https://github.com/j3k0/cordova-plugin-purchase to my first phonegap app and tried code from this sample app: https://github.com/Fovea/cordova-plugin-purchase-demo I tried different ways, but while debugging my app always tells me "store is not defined" or goes into "if(!windows.store)". Why?
// Our application's global object
var app = {};
app.nonHostedContentUrl = "http://ge.tt/api/1/files/3JSfJhL2/0/blob?download";
//
// Constructor
// -----------
//
app.initialize = function() {
//log('initialize');
// Listen to the deviceready event.
// Make sure the score of 'this' isn't lost.
document.addEventListener('deviceready', this.bind(this.onDeviceReady), false);
};
//
// Methods
// -------
//
// deviceready event handler.
//
// will just initialize the Purchase plugin
app.onDeviceReady = function() {
//log('onDeviceReady');
this.initStore();
};
// initialize the purchase plugin if available
app.initStore = function() {
if (!window.store) {
alert('Store not available');
return;
}
app.platform = device.platform.toLowerCase();
//document.getElementsByTagName('body')[0].className = app.platform;
// Enable maximum logging level
store.verbosity = store.DEBUG;
// Enable remote receipt validation
store.validator = "https://api.fovea.cc:1982/check-purchase";
// Inform the store of your products
//log('registerProducts');
store.register({
id: 'consumable1', // id without package name!
alias: 'extra life',
type: store.CONSUMABLE
});
}
// make sure fn will be called with app as 'this'
app.bind = function(fn) {
return function() {
fn.call(app, arguments);
};
};
app.initialize();
my first try was:
function initializeStore() {
if (!window.store) {
alert('Window.Store not available');
return;
}
if (!store) {
alert('Store not available');
return;
}
// Let's set a pretty high verbosity level, so that we see a lot of stuff
// in the console (reassuring us that something is happening).
store.verbosity = store.INFO;
// We register a dummy product. It's ok, it shouldn't
// prevent the store "ready" event from firing.
store.register({
id: "myapp.inappid1",
alias: "100 points",
type: store.CONSUMABLE
});
store.ready(function() {
alert("\\o/ STORE READY \\o/");
});
store.refresh();
}
document.addEventListener('deviceready', initializeStore, false);
I also tried removing the plugin and add it from github, like told here: Initialization Android In App Billing using cordova plugin
Some suggestions?
If anyone else is searching for the answer: this plugin doesn't work in phonegap developer app! But it works when released.