InAppPurchasing::InAppPurchasing(QObject *parent) : QObject(parent) { m_myStore = new QInAppStore(this); QObject::connect(m_myStore, &QInAppStore::productRegistered, this, &InAppPurchasing::markProductAvailable); QObject::connect(m_myStore, &QInAppStore::productUnknown, this, &InAppPurchasing::markProductAsNotAvailable); QObject::connect(m_myStore, &QInAppStore::transactionReady, this, &InAppPurchasing::handleTransaction); initializeProducts(); } void InAppPurchasing::initializeProducts() { m_pendingProducts.push_back(QStringLiteral("product_1")); m_pendingProducts.push_back(QStringLiteral("product_2")); m_pendingProducts.push_back(QStringLiteral("product_3")); m_pendingProducts.push_back(QStringLiteral("product_4")); m_pendingProducts.push_back(QStringLiteral("product_5")); for (const QString& product : qAsConst(m_pendingProducts)) { m_myStore->registerProduct(QInAppProduct::Unlockable, product); } } void InAppPurchasing::finalizeProductInitialization(const QString& productIdentifier) { qDebug() << "[!!!] finalizeProductInitialization" << productIdentifier; bool runRestore = false; m_pendingProductsLock.lock(); runRestore = m_pendingProducts.removeOne(productIdentifier) && m_pendingProducts.isEmpty(); m_pendingProductsLock.unlock(); if (runRestore) { m_myStore->restorePurchases(); } } void InAppPurchasing::markProductAvailable(QInAppProduct* product) { if (!product) return; qDebug() << "[!!] markProductAvailable"; finalizeProductInitialization(product->identifier()); } void InAppPurchasing::markProductAsNotAvailable(QInAppProduct::ProductType productType, const QString &identifier) { Q_UNUSED(productType); qDebug() << "[!!] markProductAsNotAvailable"; finalizeProductInitialization(identifier); } void InAppPurchasing::handleTransaction(QInAppTransaction* transaction) { if (!transaction) return; qDebug() << "[!!] handleTransaction"; if (transaction->status() == QInAppTransaction::PurchaseApproved || transaction->status() == QInAppTransaction::PurchaseRestored) { } transaction->finalize(); }