Initialization Android In App Billing using cordova plugin

二次信任 提交于 2019-12-08 08:15:59

问题


In My ionic Cordova Application, I am using In App Purchase Plugin: https://github.com/j3k0/cordova-plugin-purchase

Here is the method that I use to initialise store:

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

This Initialization works fine with iOS and all the products loading fine as well, But Android device does not load In Purchase.

I guess, For android there is a different initialization method.

I have added plugin in app:

cordova plugin add cc.fovea.cordova.purchase  --variable BILLING_KEY="<BILLING_KEY>"

Please help.


回答1:


Firstly, when I was using it, the npm version was a little buggy on android. Try removing it and adding it from Git.

cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git --variable BILLING_KEY="MIIB...AQAB"

Secondly, it looks like you are maybe using some older syntax. The doco for this plugin doesnt really have very good version control. There are different versions of doco all over the net. I think this is the latest version.

This is my initialisation code. See if it works for you too.

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

You can also send the store object to console.log to have a good look at it in chrome debugger.

Oh, and if you have more than one app, make sure you are using the correct BILLING_KEY by removing and readding the plugin.

Good Luck!



来源:https://stackoverflow.com/questions/31507222/initialization-android-in-app-billing-using-cordova-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!