It's working!

This commit is contained in:
Zach Fox 2018-03-05 14:48:50 -08:00
parent 4046c873bd
commit 35b23cc954
8 changed files with 24 additions and 31 deletions

View file

@ -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:

View file

@ -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});
}
}
}

View file

@ -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");

View file

@ -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,

View file

@ -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<Ledger>();
auto wallet = DependencyManager::get<Wallet>();
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);
}

View file

@ -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;

View file

@ -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 <span class="hifi-glyph hifi-glyph-hfc" style="filter:invert(1);background-size:20px;' +
@ -445,12 +434,15 @@
}
purchaseButton.on('click', function () {
if (window.location.href.indexOf('edition=' != -1)) {
var urlParams = new URLSearchParams(window.location.search);
if (window.location.href.indexOf('certificateId=' != -1)) {
updateButtonClicked(window.location.pathname.split("/")[3],
$('#top-center').find('h1').text(),
$('#creator').find('.value').text(),
href,
"itemPage");
"itemPage",
urlParams.get('certificateId'));
} else if ('available' === availability) {
buyButtonClicked(window.location.pathname.split("/")[3],
$('#top-center').find('h1').text(),

View file

@ -561,7 +561,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,
tablet.gotoWebScreen(message.upgradeUrl + "?edition=" + message.itemEdition + "&certificateId=" + message.certificateId.replace(/\+/g, "%2B"),
MARKETPLACES_INJECT_SCRIPT_URL);
break;
case 'passphrasePopup_cancelClicked':