I have a problem with the plugin, impossible to show products :
`
IAP.JS
var IAP = {
list: [ 'produit_138' ],
products: {}
};
var localStorage = window.localStorage || {};
IAP.initialize = function () {
// Check availability of the store plugin
if (!window.store) {
alert('In-App Purchases not available');
return;
}
// Initialize
store.init({
debug: true,
noAutoFinish: true,
ready: IAP.onReady,
purchase: IAP.onPurchase,
finish: IAP.onFinish,
restore: IAP.onRestore,
error: IAP.onError,
restoreCompleted: IAP.onRestoreCompleted
});
};
IAP.onReady = function () {
// Once setup is done, load all product data.
store.load(IAP.list, function (products, invalidIds) {
alert('IAPs loading done:');
for (var j = 0; j < products.length; ++j) {
var p = products[j];
alert('Loaded IAP(' + j + '). title:' + p.title +
' description:' + p.description +
' price:' + p.price +
' id:' + p.id);
IAP.products[p.id] = p;
}
IAP.loaded = true;
for (var i = 0; i < invalidIds.length; ++i) {
alert('Error: could not load ' + invalidIds[i]);
}
IAP.render();
});
// Also check the receipts
// store.loadReceipts(function (receipts) {
// alert('appStoreReceipt: ' + receipts.appStoreReceipt);
// });
};
IAP.onPurchase = function (transactionId, productId) {
var n = (localStorage['store.' + productId]|0) + 1;
localStorage['store.' + productId] = n;
if (IAP.purchaseCallback) {
IAP.purchaseCallback(productId);
delete IAP.purchaseCallbackl;
}
store.finish(transactionId);
store.loadReceipts(function (receipts) {
alert('Receipt for appStore = ' + receipts.appStoreReceipt);
alert('Receipt for ' + productId + ' = ' + receipts.forProduct(productId));
});
};
IAP.onFinish = function (transactionId, productId) {
alert('Finished transaction for ' + productId + ' : ' + transactionId);
};
IAP.onError = function (errorCode, errorMessage) {
alert('Error: ' + errorMessage);
};
IAP.onRestore = function (transactionId, productId) {
alert("Restored: " + productId);
var n = (localStorage['store.' + productId]|0) + 1;
localStorage['store.' + productId] = n;
};
IAP.onRestoreCompleted = function () {
alert("Restore Completed");
};
IAP.buy = function (productId, callback) {
IAP.purchaseCallback = callback;
store.purchase(productId);
};
IAP.restore = function () {
store.restore();
};
IAP.fullVersion = function () {
return localStorage['store.produit_138'];
};`
ON MY INDEX.JS
`var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
IAP.initialize();
IAP.render = function () {
var el = document.getElementById('in-app-purchase-list');
if (IAP.loaded) {
var html = "<ul>";
alert(IAP.list);
alert(IAP.products);
var index = 0;
var buttonStyle = "display:inline-block; padding: 5px 20px; border: 1px solid black";
for (var id in IAP.products) {
var p = IAP.products[id];
html += "<li>" +
"<h3>" + p.title + "</h3>" +
"<p>" + p.description + "</p>" +
"<div style='" + buttonStyle + "' id='buy-" + index + "' productId='" + p.id + "' type='button'>" + p.price + "</div>" +
"</li>";
++index;
}
html += "</ul>";
html += "<div style='" + buttonStyle + "' id='restore'>RESTORE ALL</div>"
el.innerHTML = html;
while (index > 0) {
--index;
document.getElementById("buy-" + index).onclick = function (event) {
var pid = this.getAttribute("productId");
IAP.buy(pid);
};
}
document.getElementById("restore").onclick = function (event) {
IAP.restore();
};
}
else {
el.innerHTML = "In-App Purchases not available";
}
};
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
alert('Received Event: ' + id);
}
Hi,
I have a problem with the plugin, impossible to show products : ` IAP.JS var IAP = { list: [ 'produit_138' ], products: {} }; var localStorage = window.localStorage || {};
ON MY INDEX.JS
`var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicity call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready');
};` and in my index.html