【发布时间】:2015-01-15 16:08:55
【问题描述】:
请告诉我如何使用 Cordova 插件实现应用内购买。
我正在使用 Cordova 开发 Android 应用程序。 有一些应用内购买插件,但我决定使用 Cordova 购买插件。
我在In-App Purchase for PhoneGap / Cordova iOS and Android 的 README.md 中做了一些设置。 结果,我只需稍加修改就可以使用Demo of the Purchase Plugin for Cordova 调用插件。 (见下文,是部分代码。)
app.initStore = function() {
if (!window.store) {
log('Store not available');
return;
}
// 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: 'myProductA',
alias: 'myProductA',
type: store.CONSUMABLE
});
// When any product gets updated, refresh the HTML.
store.when("product").updated(function (p) {
console.info("app.renderIAP is called");
app.renderIAP(p);
});
// Log all errors
store.error(function(error) {
log('ERROR ' + error.code + ': ' + error.message);
});
// When purchase of an extra life is approved,
// deliver it... by displaying logs in the console.
store.when("myProductA").approved(function (order) {
log("You got a ProductA");
order.finish();
});
// When the store is ready (i.e. all products are loaded and in their "final"
// state), we hide the "loading" indicator.
//
// Note that the "ready" function will be called immediately if the store
// is already ready.
store.ready(function() {
var el = document.getElementById("loading-indicator");
console.info(el + "ready is called")
if (el)
el.style.display = 'none';
});
// When store is ready, activate the "refresh" button;
store.ready(function() {
var el = document.getElementById('refresh-button');
console.info(el + "ready is called and refresh-button show?");
if (el) {
el.style.display = 'block';
el.onclick = function(ev) {
store.refresh();
};
}
});
// Refresh the store.
//
// This will contact the server to check all registered products
// validity and ownership status.
//
// It's fine to do this only at application startup, as it could be
// pretty expensive.
log('refresh');
store.refresh();
};
它没有显示插件不可用时显示的“商店不可用”,显示“registerProducts”和“刷新”。 (*当然,我在 Google Play 开发者控制台上的应用内产品中添加了“myProductA”。)
但是我注意到下面的函数没有被调用。
store.when("product").updated(function (p)
而且我也看不懂参数应该填什么,所以我把下面的注释掉了。 (*我确实删除了评论,但它仍然无法正常工作。)
store.validator = "https://api.fovea.cc:1982/check-purchase";
我猜这些事情会出错。 我不确定我的堆栈是什么,所以我的问题不清楚。 我想要一些线索来解决它...或者我不应该使用 Cordova 插件实现应用内购买?
请把手给我。
(我的英语不流利,所以如有任何混淆,我很抱歉。)
【问题讨论】:
-
有一些关于验证器函数here的文档。目前,cordova 插件的作者似乎提供了一种免费的方式来验证购买的物品,但我仍然不清楚他的服务是否真的有效(根据他的网站,当前为私人测试版)以及该服务可以访问什么样的信息到。
-
@antogerva 感谢您的评论。我忽略了你提到的链接。它看起来很有帮助,谢谢。无论如何,最后我放弃了使用这个插件并在cordova框架上实现了“应用内购买”功能。对我来说太难了。哈哈
-
大家好,请帮帮我。这是我的问题,请stackoverflow.com/questions/38657305/…
标签: javascript android cordova