tkh*_*khm 8 javascript android cordova
请告诉我使用Cordova插件实现应用内购买的方法.
我正在使用Cordova开发Android应用程序.有一些应用内购买插件,但我决定使用Cordova Purchase Plugin.
我为PhoneGap/Cordova iOS和Android的应用内购买的 README.md做了一些设置.因此,我可以使用针对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();
};
Run Code Online (Sandbox Code Playgroud)
它没有显示插件不可用时显示的"Store not available",显示'registerProducts'和'refresh'.(*当然,我将'myProductA'添加到Google Play开发者控制台上的应用内商品中.)
但是我注意到没有调用下面的函数.
store.when("product").updated(function (p)
Run Code Online (Sandbox Code Playgroud)
而且我无法理解参数应该填写什么,所以我在下面注释掉了.(*我确实删除了评论,但它仍无效.)
store.validator = "https://api.fovea.cc:1982/check-purchase";
Run Code Online (Sandbox Code Playgroud)
我猜那些事情会让事情出错.我不确定堆叠在我身上是什么,所以我的问题不清楚.我想要一些线索来解决它......或者我不应该使用Cordova插件实现应用内购买?
请把你的手给我.
(我的英语不流利,所以我很抱歉有任何困惑.)
您可以尝试使用此插件:https://github.com/AlexDisler/cordova-plugin-inapppurchase
以下是加载产品和进行购买的示例:
inAppPurchase
.buy('com.yourapp.consumable_prod1')
.then(function (data) {
// ...then mark it as consumed:
return inAppPurchase.consume(data.productType, data.receipt, data.signature);
})
.then(function () {
console.log('product was successfully consumed!');
})
.catch(function (err) {
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
它支持Android和iOS.
| 归档时间: |
|
| 查看次数: |
14039 次 |
| 最近记录: |