Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement in-app-purchase using Cordova plugin?

Tags:

People also ask

Is Cordova discontinued?

Effective immediately, App Center will no longer offer the option to create Apache Cordova apps through the portal, CLI or API. Starting April 1, 2022, the App Center service will no longer accept calls from the Cordova SDK.


Please tell me the way to implement in-app-purchase using Cordova plugin.

I'm developing Android application using Cordova. There are some in-app-purchase plugins but I decide to use Cordova Purchase Plugin.

I did some setups along README.md of In-App Purchase for PhoneGap / Cordova iOS and Android. As a result, I could call the Plugin using Demo of the Purchase Plugin for Cordova with my little modification. (See the following, it is a portion of code.)

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

It did not show 'Store not available' that is shown when plugin is not available, show 'registerProducts', and 'refresh.' (*Of course I added 'myProductA' to in-app Products on Google Play Developer Console.)

But I noticed that the below function is not called.

store.when("product").updated(function (p)

And also I couldn't understand what the parameter should fill in it, so I commented out the below. (*I did remove the comment out, but it still not working.)

store.validator = "https://api.fovea.cc:1982/check-purchase";

I guess those things make something wrong. I'm not sure what is stack on me, so my question is not clearly. I want some clues to solve it... or I shouldn't implement in-app-purchase using Cordova plugin?

Please give me your hand.

(I'm not fluent in English, so I'm sorry for any confusion.)