Smooth out bugs in IAP, check for incomplete purchases at startup
This commit is contained in:
parent
a3bfeb18d1
commit
0cee4fc2f8
@ -74,8 +74,8 @@ function buycoins(productId) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
loadstorefront();
|
showShopMessage("Thanks for your purchase!", false);
|
||||||
showShopMessage("Thanks for your purchase!", true);
|
refreshcoins();
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
console.log("Error: " + err.message);
|
console.log("Error: " + err.message);
|
||||||
@ -157,9 +157,6 @@ function setcoinhtmlfromiap(coinsjson) {
|
|||||||
+ "</div>";
|
+ "</div>";
|
||||||
});
|
});
|
||||||
$('#coin-list').html(coinsHtml);
|
$('#coin-list').html(coinsHtml);
|
||||||
/*
|
|
||||||
[{ productId: 'com.yourapp.prod1', 'title': '...', description: '...', price: '...' }, ...]
|
|
||||||
*/
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
console.log(err.message);
|
console.log(err.message);
|
||||||
@ -188,3 +185,11 @@ function loadstorefront() {
|
|||||||
loadinventory(); // Make sure purchases stay in sync
|
loadinventory(); // Make sure purchases stay in sync
|
||||||
// Put it last in case it fails, so it doesn't crash stuff badly
|
// Put it last in case it fails, so it doesn't crash stuff badly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshcoins() {
|
||||||
|
$.getJSON(mkApiUrl('shopitems'), function (data) {
|
||||||
|
if (data.status == 'OK') {
|
||||||
|
$('#coinbalance').text(data.balance);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -134,3 +134,32 @@
|
|||||||
openIntro();
|
openIntro();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<script>
|
||||||
|
/*
|
||||||
|
* Try to restore any broken coin purchases
|
||||||
|
*/
|
||||||
|
inAppPurchase
|
||||||
|
.restorePurchases()
|
||||||
|
.then(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
data.forEach(function (prod) {
|
||||||
|
if (prod.state == 2 || prod.state == 1) { // Refunded (2) or cancelled (1), let's consume it
|
||||||
|
inAppPurchase.consume(prod.type, prod.receipt, prod.signature);
|
||||||
|
} else { // Product is active
|
||||||
|
$.getJSON(mkApiUrl('processiap', 'gs'), {
|
||||||
|
os: 'android',
|
||||||
|
data: prod.receipt,
|
||||||
|
signature: prod.signature,
|
||||||
|
id: prod.productId
|
||||||
|
}, function (result) {
|
||||||
|
if (result.status == 'OK') {
|
||||||
|
inAppPurchase.consume(prod.type, prod.receipt, prod.signature);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
</script>
|
Reference in New Issue
Block a user