Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  174] [ 4]  / answers: 1 / hits: 16571  / 10 Years ago, thu, january 15, 2015, 12:00:00

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.)


More From » android

 Answers
68

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



Here's an example of loading 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.


[#68198] Tuesday, January 13, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayaw

Total Points: 749
Total Questions: 88
Total Answers: 86

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
tayaw questions
;