StoreView.qml Example File
qthangman/qml/qthangman/StoreView.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtPurchasing 1.0
Item {
PageHeader {
id: header
title: "Hangman Store"
}
Column {
anchors.top: header.bottom
anchors.bottom: restoreButton.top
anchors.margins: topLevel.globalMargin
anchors.right: parent.right
anchors.left: parent.left
spacing: topLevel.globalMargin
StoreItem {
product: product100Vowels
width: parent.width
}
StoreItem {
product: productUnlockVowels
width: parent.width
}
}
SimpleButton {
id: restoreButton
anchors.bottom: parent.bottom
anchors.margins: topLevel.globalMargin
anchors.horizontalCenter: parent.horizontalCenter
height: topLevel.buttonHeight
width: parent.width * .5
text: "Restore Purchases"
onClicked: {
iapStore.restorePurchases();
}
}
Product {
id: product100Vowels
store: iapStore
type: Product.Consumable
identifier: "org.qtproject.qthangman.100vowels"
onPurchaseSucceeded: {
console.log(identifier + " purchase successful");
applicationData.vowelsAvailable += 100;
transaction.finalize();
pageStack.pop();
}
onPurchaseFailed: {
console.log(identifier + " purchase failed");
console.log("reason: "
+ transaction.failureReason === Transaction.CanceledByUser ? "Canceled" : transaction.errorString);
transaction.finalize();
}
}
Product {
id: productUnlockVowels
type: Product.Unlockable
store: iapStore
identifier: "org.qtproject.qthangman.unlockvowels"
onPurchaseSucceeded: {
console.log(identifier + " purchase successful");
applicationData.vowelsUnlocked = true;
transaction.finalize();
pageStack.pop();
}
onPurchaseFailed: {
console.log(identifier + " purchase failed");
console.log("reason: "
+ transaction.failureReason === Transaction.CanceledByUser ? "Canceled" : transaction.errorString);
transaction.finalize();
}
onPurchaseRestored: {
console.log(identifier + "purchase restored");
applicationData.vowelsUnlocked = true;
console.log("timestamp: " + transaction.timestamp);
transaction.finalize();
pageStack.pop();
}
}
}