Skip to content

Instantly share code, notes, and snippets.

@j3k0

j3k0/index.html

Last active Sep 4, 2019
Embed
What would you like to do?
Tutorial Cordova In-App Purchase Consumable
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>Hello World</title>
</head>
<body>
<div class="app">
<p id="gold-coins">Gold:</p>
<div id="consumable1-purchase">Please wait...</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
document.addEventListener('deviceready', initStore);
document.addEventListener('deviceready', refreshGoldCoinsUI);
function initStore() {
if (!window.store) {
console.log('Store not available');
return;
}
store.verbosity = store.INFO;
store.register({
id: 'cc.fovea.purchase.consumable1',
alias: 'my_consumable1',
type: store.CONSUMABLE
});
store.error(function(error) {
console.log('ERROR ' + error.code + ': ' + error.message);
});
store.when('my_consumable1').updated(refreshProductUI);
store.when('my_consumable1').approved(function(p) {
p.verify();
});
store.when('my_consumable1').verified(finishPurchase);
store.refresh();
}
function refreshGoldCoinsUI() {
document.getElementById('gold-coins').innerHTML =
'Gold: <strong>' + (window.localStorage.goldCoins | 0) + '</strong>';
}
function refreshProductUI(product) {
const info = product.loaded
? `<h1>${product.title}</h1>` +
`<p>${product.description}</p>` +
`<p>${product.price}</p>`
: '<p>Retrieving info...</p>';
const button = product.canPurchase
? '<button onclick="purchaseConsumable1()">Buy Now!</button>'
: '';
const el = document.getElementById('consumable1-purchase');
el.innerHTML = info + button;
}
function purchaseConsumable1() {
store.order('my_consumable1');
}
function finishPurchase(p) {
window.localStorage.goldCoins = (window.localStorage.goldCoins | 0) + 10;
p.finish();
refreshGoldCoinsUI();
}
@martinkirby

This comment has been minimized.

Copy link

@martinkirby martinkirby commented Sep 4, 2019

I arrived at this page from a link that promises the **non-**consumable ios full version... could someone change this page to the non-consumable full code?... thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.