0

我将https://github.com/j3k0/cordova-plugin-purchase添加到我的第一个 phonegap 应用程序中,并尝试了此示例应用程序中的代码:https ://github.com/Fovea/cordova-plugin-purchase-demo 我尝试了不同的方式,但是在调试我的应用程序时,总是告诉我“未定义商店”或进入“if(!windows.store)”。为什么?

// 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();

我的第一次尝试是:

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

我还尝试删除插件并从 github 添加它,就像这里所说的:Initialization Android In App Billing using cordova plugin

一些建议?

4

1 回答 1

2

如果其他人正在寻找答案:此插件在 phonegap 开发者应用程序中不起作用!但它在发布时有效。

于 2017-01-06T10:35:22.310 回答