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

Please tell me the way to implement a purchase through the application using the Cordova plugin.

I am developing an Android application using Cordova. There are some plugins for connecting to applications, but I decided to use the Purchase Cordova plugin.

I made some settings on the README.md In-App Purchase for PhoneGap / Cordova iOS and Android . As a result, I could call the plugin by demonstrating the purchase plugin for Cordoba with my little modification. (See the following, this is part of the 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 (ie 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 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", which is displayed when the plugin is unavailable, "registerProducts" and "refresh" are displayed. (* Of course, I added "myProductA" to application apps in the Google Play Developer Console.)

But I noticed that the function below is not called.

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

And also I could not understand what this parameter should fill in, so I commented on this below. (* I deleted the comment, but it still does not work.)

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

I think these things are doing something wrong. I'm not sure what is on my stack, so my question is incomprehensible. I want some hints to resolve it ... or should I not implement the purchase through the application using the Cordova plugin?

Please give me your hand.

(I do not speak English, so I'm sorry for any confusion.)

+7
javascript android cordova
source share
2 answers

You can try this plugin as an alternative: https://github.com/AlexDisler/cordova-plugin-inapppurchase

Here is an example of downloading products and making a purchase:

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

It supports both Android and iOS.

+5
source share

Step to integrate billing in the application in the Phone-gap application.

1 β†’ clone this project on your computer using this link Invoicing library in the application

2 β†’ using CMD, go to your root directory of your phonegap application

3 β†’ then run this command plugin cordova add / path / to / your / cloned project --variable BILLING_KEY = "QWINMERR .......... RIGR"

Notes: for BILLING_KEY, open the developer console, then open the application and go to the Service & API for more information. Please refer to the attached screenshots. BILLING_KEY

+1
source share

All Articles