2015-01-15 137 views
7

请告诉我使用Cordova插件实现应用程序内购买的方式。如何使用Cordova插件实现应用程序内购买?

我正在开发使用Cordova的Android应用程序。 有一些应用内购买插件,但我决定使用Cordova Purchase Plugin。

我沿着README.md In-App Purchase for PhoneGap/Cordova iOS and Android做了一些设置。 因此,我可以使用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插件实施应用内购买?

请给我你的手。

(我的英语不流利,所以我对任何混乱很抱歉。)

+1

有一些关于验证器函数的文档[这里](https://github.com/j3k0/cordova-plugin-purchase/blob/master/doc/api.md#validator)。目前,科尔多瓦插件的作者似乎提供了一种免费的方式来验证购买的商品,但我们仍不清楚他的服务是否真的有效(根据他的网站的私人测试版的资料)以及此服务访问哪种信息至。 – antogerva 2015-02-19 20:00:54

+0

@antogerva感谢您的评论。我忽略了你提到的链接。它看起来很有帮助,谢谢。无论如何,最后我放弃了使用这个插件,并且在cordova框架中实现了“在app购买”功能。这对我来说太难了.haha – tkhm 2015-02-20 07:22:53

+0

你好每一个人请帮助我。有我的问题请http://stackoverflow.com/questions/38657305/android-in-app-purchase-not-working – 2016-08-01 09:23:33

回答

5

你可以试试这个插件作为一种替代方案: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); 
    }); 

它同时支持Android和iOS。

+0

谢谢,亚历克斯!我阅读了链接和[你的博客](https://alexdisler.com/2016/02/29/in-app-purchases-ionic-cordova/)。它看起来非常棒,谢谢! – tkhm 2016-03-22 04:38:44

1

步骤的整合应用程式在电话间隙应用内结算。

1 >>使用CMD此链接In-App billing Library

2 >>在你的PC兼容机这个项目去你的PhoneGap应用程序的根目录

3 >>然后运行这个命令科尔多瓦插件添加/路径/到/你/复制项目--variable BILLING_KEY =“QWINMERR .......... RIGR”

注:为BILLING_KEY去开发者控制台,然后打开你的应用程序并进入服务&更多信息请参阅附件屏幕截图BILLING_KEY