Initialization Android In App Billing using cordov

2019-06-07 18:01发布

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条回答
孤傲高冷的网名
2楼-- · 2019-06-07 18:33

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!

查看更多
登录 后发表回答