From 35b23cc954e0ce05f7678caec67cadc1d39126ad Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 5 Mar 2018 14:48:50 -0800 Subject: [PATCH] It's working! --- .../qml/hifi/commerce/checkout/Checkout.qml | 8 ++++-- .../hifi/commerce/purchases/PurchasedItem.qml | 2 +- interface/src/commerce/Ledger.cpp | 8 +++--- interface/src/commerce/Ledger.h | 2 +- interface/src/commerce/QmlCommerce.cpp | 5 ++-- interface/src/commerce/QmlCommerce.h | 2 +- scripts/system/html/js/marketplacesInject.js | 26 +++++++------------ scripts/system/marketplaces/marketplaces.js | 2 +- 8 files changed, 24 insertions(+), 31 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml index 562ceb1cc1..9ffcbefdb5 100644 --- a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml +++ b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml @@ -35,6 +35,7 @@ Rectangle { property string itemId; property string itemHref; property string itemAuthor; + property string certificateId; property double balanceAfterPurchase; property bool alreadyOwned: false; property int itemPrice: -1; @@ -586,7 +587,7 @@ Rectangle { (viewInMyPurchasesButton.visible ? "Buy It Again" : "Confirm Purchase") : "--") : "Get Item")); onClicked: { if (root.isUpdating) { - Commerce.updateItem(root.itemId); + Commerce.updateItem(root.certificateId); } else if (root.isCertified) { if (!root.shouldBuyWithControlledFailure) { if (root.itemType === "contentSet" && !Entities.canReplaceContent()) { @@ -1037,13 +1038,16 @@ Rectangle { function fromScript(message) { switch (message.method) { case 'updateCheckoutQML': - root.isUpdating = message.params.isUpdating; + if (message.params.isUpdating) { + root.isUpdating = message.params.isUpdating; + } root.itemId = message.params.itemId; root.itemName = message.params.itemName.trim(); root.itemPrice = message.params.itemPrice; root.itemHref = message.params.itemHref; root.referrer = message.params.referrer; root.itemAuthor = message.params.itemAuthor; + root.certificateId = message.params.certificateId; refreshBuyUI(); break; default: diff --git a/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml b/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml index df36bfd753..51a31ed70a 100644 --- a/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml +++ b/interface/resources/qml/hifi/commerce/purchases/PurchasedItem.qml @@ -681,7 +681,7 @@ Item { verticalAlignment: Text.AlignVCenter; onLinkActivated: { - sendToPurchases({method: 'updateItemClicked', itemId: root.itemId, itemEdition: root.itemEdition, upgradeUrl: root.upgradeUrl}); + sendToPurchases({method: 'updateItemClicked', itemId: root.itemId, itemEdition: root.itemEdition, upgradeUrl: root.upgradeUrl, certificateId: root.certificateId}); } } } diff --git a/interface/src/commerce/Ledger.cpp b/interface/src/commerce/Ledger.cpp index c9b6bf3523..d0683b9872 100644 --- a/interface/src/commerce/Ledger.cpp +++ b/interface/src/commerce/Ledger.cpp @@ -374,12 +374,10 @@ void Ledger::getAvailableUpdates() { send(endpoint, "availableUpdatesSuccess", "availableUpdatesFailure", QNetworkAccessManager::PutOperation, AccountManagerAuth::Required, request); } -void Ledger::updateItem(const QString& hfc_key, const QString& asset_id, const QString& inventory_key) { +void Ledger::updateItem(const QString& hfc_key, const QString& certificate_id) { QJsonObject transaction; - transaction["hfc_key"] = hfc_key; - transaction["cost"] = 0; - transaction["asset_id"] = asset_id; - transaction["inventory_key"] = inventory_key; + transaction["public_key"] = hfc_key; + transaction["certificate_id"] = certificate_id; QJsonDocument transactionDoc{ transaction }; auto transactionString = transactionDoc.toJson(QJsonDocument::Compact); signedSend("transaction", transactionString, hfc_key, "update_item", "updateItemSuccess", "updateItemFailure"); diff --git a/interface/src/commerce/Ledger.h b/interface/src/commerce/Ledger.h index c68ed8493b..45506569fc 100644 --- a/interface/src/commerce/Ledger.h +++ b/interface/src/commerce/Ledger.h @@ -37,7 +37,7 @@ public: void transferHfcToUsername(const QString& hfc_key, const QString& username, const int& amount, const QString& optionalMessage); void alreadyOwned(const QString& marketplaceId); void getAvailableUpdates(); - void updateItem(const QString& hfc_key, const QString& asset_id, const QString& inventory_key); + void updateItem(const QString& hfc_key, const QString& certificate_id); enum CertificateStatus { CERTIFICATE_STATUS_UNKNOWN = 0, diff --git a/interface/src/commerce/QmlCommerce.cpp b/interface/src/commerce/QmlCommerce.cpp index 701f2403d4..41cad52842 100644 --- a/interface/src/commerce/QmlCommerce.cpp +++ b/interface/src/commerce/QmlCommerce.cpp @@ -351,7 +351,7 @@ void QmlCommerce::getAvailableUpdates() { ledger->getAvailableUpdates(); } -void QmlCommerce::updateItem(const QString& marketplaceId) { +void QmlCommerce::updateItem(const QString& certificateId) { auto ledger = DependencyManager::get(); auto wallet = DependencyManager::get(); QStringList keys = wallet->listPublicKeys(); @@ -360,6 +360,5 @@ void QmlCommerce::updateItem(const QString& marketplaceId) { return emit updateItemResult(result); } QString key = keys[0]; - // For now, we receive at the same key that pays for it. - ledger->updateItem(key, marketplaceId, key); + ledger->updateItem(key, certificateId); } diff --git a/interface/src/commerce/QmlCommerce.h b/interface/src/commerce/QmlCommerce.h index fdca17e557..1b2c08ee95 100644 --- a/interface/src/commerce/QmlCommerce.h +++ b/interface/src/commerce/QmlCommerce.h @@ -91,7 +91,7 @@ protected: Q_INVOKABLE bool openApp(const QString& appHref); Q_INVOKABLE void getAvailableUpdates(); - Q_INVOKABLE void updateItem(const QString& marketplaceId); + Q_INVOKABLE void updateItem(const QString& certificateId); private: QString _appsPath; diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index d033e6988d..c97700bc69 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -246,7 +246,6 @@ function buyButtonClicked(id, name, author, price, href, referrer) { EventBridge.emitWebEvent(JSON.stringify({ type: "CHECKOUT", - isUpdating: false, itemId: id, itemName: name, itemPrice: price ? parseInt(price, 10) : 0, @@ -256,7 +255,7 @@ })); } - function updateButtonClicked(id, name, author, href, referrer) { + function updateButtonClicked(id, name, author, href, referrer, certId) { EventBridge.emitWebEvent(JSON.stringify({ type: "UPDATE", isUpdating: true, @@ -265,21 +264,11 @@ itemPrice: 0, itemHref: href, referrer: referrer, - itemAuthor: author + itemAuthor: author, + certificateId: certId })); } - // From https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript - function getParameterByName(name, url) { - if (!url) url = window.location.href; - name = name.replace(/[\[\]]/g, "\\$&"); - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), - results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, " ")); - } - function injectBuyButtonOnMainPage() { var cost; @@ -437,7 +426,7 @@ var cost = $('.item-cost').text(); if (availability !== 'available') { purchaseButton.html('UNAVAILABLE (' + availability + ')'); - } else if (window.location.href.indexOf('edition=' != -1)) { + } else if (window.location.href.indexOf('certificateId=' != -1)) { purchaseButton.html('UPDATE FOR FREE'); } else if (parseInt(cost) > 0 && $('#side-info').find('#buyItemButton').size() === 0) { purchaseButton.html('PURCHASE