From d07d02b2bccab8c021ea70cc03ad01d25c213d2a Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 7 Mar 2018 11:10:47 -0800 Subject: [PATCH] Take certID from backend instead of query params; Better loading; Uninstall app before updating --- .../qml/hifi/commerce/checkout/Checkout.qml | 22 ++++++++++++++----- .../hifi/commerce/purchases/PurchasedItem.qml | 2 +- scripts/system/html/js/marketplacesInject.js | 10 ++++----- scripts/system/marketplaces/marketplaces.js | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml index 9ffcbefdb5..6a53080899 100644 --- a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml +++ b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml @@ -52,6 +52,7 @@ Rectangle { property string referrer; property bool isInstalled; property bool isUpdating; + property string baseAppURL; // Style color: hifi.colors.white; Connections { @@ -106,9 +107,9 @@ Rectangle { if (result.status !== 'success') { console.log("Failed to get balance", result.data.message); } else { - root.balanceReceived = true; root.balanceAfterPurchase = result.data.balance - root.itemPrice; root.refreshBuyUI(); + root.balanceReceived = true; } } @@ -116,7 +117,6 @@ Rectangle { if (result.status !== 'success') { console.log("Failed to get Already Owned status", result.data.message); } else { - root.ownershipStatusReceived = true; if (result.data.marketplace_item_id === root.itemId) { root.alreadyOwned = result.data.already_owned; } else { @@ -124,6 +124,7 @@ Rectangle { root.alreadyOwned = false; } root.refreshBuyUI(); + root.ownershipStatusReceived = true; } } @@ -137,13 +138,20 @@ Rectangle { if (result.status !== 'success') { console.log("Failed to get Available Updates", result.data.message); } else { - root.availableUpdatesReceived = true; for (var i = 0; i < result.data.updates.length; i++) { - if (result.data.updates[i].item_id === root.itemId) { + // If the ItemID of the item we're looking at matches EITHER the ID of a "base" item + // OR the ID of an "upgrade" item, we're updating. + if (root.itemId === result.data.updates[i].item_id || + root.itemId === result.data.updates[i].updated_item_id) { root.isUpdating = true; + root.certificateId = result.data.updates[i].certificate_id; + if (root.itemType === "app") { + root.baseAppURL = result.data.updates[i].base_download_url; + } break; } } + root.availableUpdatesReceived = true; } } @@ -587,6 +595,11 @@ Rectangle { (viewInMyPurchasesButton.visible ? "Buy It Again" : "Confirm Purchase") : "--") : "Get Item")); onClicked: { if (root.isUpdating) { + // If we're updating an app, the existing app needs to be uninstalled. + // This call will fail/return `false` if the app isn't installed, but that's OK. + if (root.itemType === "app") { + Commerce.uninstallApp(root.baseAppURL); + } Commerce.updateItem(root.certificateId); } else if (root.isCertified) { if (!root.shouldBuyWithControlledFailure) { @@ -1047,7 +1060,6 @@ Rectangle { 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 51a31ed70a..df36bfd753 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, certificateId: root.certificateId}); + sendToPurchases({method: 'updateItemClicked', itemId: root.itemId, itemEdition: root.itemEdition, upgradeUrl: root.upgradeUrl}); } } } diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index c97700bc69..903d15223c 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -255,7 +255,7 @@ })); } - function updateButtonClicked(id, name, author, href, referrer, certId) { + function updateButtonClicked(id, name, author, href, referrer) { EventBridge.emitWebEvent(JSON.stringify({ type: "UPDATE", isUpdating: true, @@ -264,8 +264,7 @@ itemPrice: 0, itemHref: href, referrer: referrer, - itemAuthor: author, - certificateId: certId + itemAuthor: author })); } @@ -436,13 +435,12 @@ purchaseButton.on('click', function () { var urlParams = new URLSearchParams(window.location.search); - if (window.location.href.indexOf('certificateId=' != -1)) { + if (window.location.href.indexOf('edition=' != -1)) { // "Upgrading" case updateButtonClicked(window.location.pathname.split("/")[3], $('#top-center').find('h1').text(), $('#creator').find('.value').text(), href, - "itemPage", - urlParams.get('certificateId')); + "itemPage"); } else if ('available' === availability) { buyButtonClicked(window.location.pathname.split("/")[3], $('#top-center').find('h1').text(), diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index e54a986aac..6e010943c7 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -564,7 +564,7 @@ var selectionDisplay = null; // for gridTool.js to ignore tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL); break; case 'updateItemClicked': - tablet.gotoWebScreen(message.upgradeUrl + "?edition=" + message.itemEdition + "&certificateId=" + message.certificateId.replace(/\+/g, "%2B"), + tablet.gotoWebScreen(message.upgradeUrl + "?edition=" + message.itemEdition, MARKETPLACES_INJECT_SCRIPT_URL); break; case 'passphrasePopup_cancelClicked':