使用cordova插件初始化Android In App Billing

sta*_*bit 2 android phonegap-plugins angularjs cordova ionic

在我的离子 Cordova 应用程序中,我使用应用内购买插件:https : //github.com/j3k0/cordova-plugin-purchase

这是我用来初始化存储的方法:

storekit.init({
            debug: true, // Enable IAP messages on the console
            ready: service.IAP.onReady,
            purchase: service.IAP.onPurchase,
            restore: service.IAP.onRestore,
            error: service.IAP.onError
        });
Run Code Online (Sandbox Code Playgroud)

此初始化在 iOS 上运行良好,所有产品也可以正常加载,但 Android 设备在购买时无法加载。

我猜,对于 android 有不同的初始化方法。

我在应用程序中添加了插件:

cordova plugin add cc.fovea.cordova.purchase  --variable BILLING_KEY="<BILLING_KEY>"
Run Code Online (Sandbox Code Playgroud)

请帮忙。

pau*_*aul 5

首先,当我使用它时,npm 版本在 android 上有点问题。尝试删除它并从 Git 中添加它。

cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git --variable BILLING_KEY="MIIB...AQAB"
Run Code Online (Sandbox Code Playgroud)

其次,看起来您可能正在使用一些较旧的语法。这个插件的 doco 并没有很好的版本控制。网络上有不同版本的 doco。我认为是最新版本。

这是我的初始化代码。看看它是否也适合你。

            products = ["my.test.product"];
            for (var i = 0; i < products.length; i++) {
                if (window.store) {
                    store.register({
                        id:    products[i],
                        alias: 'alias '+i,
                        type:   store.NON_CONSUMABLE
                    });

                }
            }

            // When everything goes as expected, it's time to celebrate!
            if (window.store) store.ready(function() {
                console.log("\\o/ STORE READY \\o/");
            });

            // After we've done our setup, we tell the store to do
            // it's first refresh. Nothing will happen if we do not call store.refresh()
            if (window.store) store.refresh();
Run Code Online (Sandbox Code Playgroud)

您还可以将 store 对象发送到 console.log 以便在 chrome 调试器中仔细查看它。

哦,如果您有多个应用程序,请通过删除和阅读插件确保您使用正确的 BILLING_KEY。

祝你好运!