Esempio n. 1
0
/*!
  Returns a product from the cache by \a productId or NULL if not found.
*/
Product *IAPurchase::productFromCacheByProductId(QString productId)
{
    for (int i = 0; i < m_productCache.count(); i++) {
        Product *p = (Product*)m_productCache[i];

        if (p->id() == productId) {
            return p;
        }
    }

    return 0;
}
Esempio n. 2
0
/*!
  Starts downloading the product related .sis file from the back-end (if the
  purchase was successful).
*/
void IAPurchase::purchaseCompleted(int requestId, QString status, QString purchaseTicket)
{
    Product *product = 0;

    if (QString::compare(status, "OK", Qt::CaseInsensitive) == 0) {
        // Find product request from our cache
        product = productFromCacheByRequestId(requestId);

        if (product) {
            // Purchase done
            emit productPurchaseDone(product->id());

            // Start downloading level plugins AND send purchase ticket to
            // the back-end server
            emit downloadingProduct(product->id());

            QString productIdForDownload = product->id();

            QString request =
                    "http://fn-iap-repo.cloudapp.net/api/quickhit/"
                    + productIdForDownload;
            request = request.trimmed();
            QUrl url(request,QUrl::StrictMode);
            m_downloadMgr->downloadSis(productIdForDownload, purchaseTicket, url);
        }
        else {
            // Error
            m_invalidProductPurchaseRequestId = m_buyProductRequestId;
            productPurchaseError();
        }
    }
    else  {
        // Error
        m_invalidProductPurchaseRequestId = m_buyProductRequestId;
        productPurchaseError();
    }
}