/* TerranQuest - Augmented Reality fantasy game Copyright 2016 Netsyms Technologies Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ function buycoins(productId) { if (getPlatform() == DEVICE_ANDROID) { inAppPurchase .buy(productId) .then(function (data) { console.log(JSON.stringify(data)); $.getJSON(mkApiUrl('processiap', 'gs'), { os: 'android', data: data.receipt, signature: data.signature, id: productId, lang: USER_LANGUAGE }, function (result) { if (result.status == 'OK') { return inAppPurchase.consume(data.type, data.receipt, data.signature); } else { showErrorMessage("Error: " + result.message); } }).fail(function () { showErrorMessage("Error: Lost connection to TerranQuest servers. If your purchase does not appear within a few hours, contact support@netsyms.com."); }); }) .then(function () { playSound("coin"); showSuccessMessage("Thanks for your purchase!"); refreshcoins(); }) .catch(function (err) { playSound("error"); console.log("Error: " + err.message); showErrorMessage("Error: " + err.message); }); } else if (getPlatform() == DEVICE_IOS) { inAppPurchase .buy(productId) .then(function (data) { console.log(JSON.stringify(data)); $.getJSON(mkApiUrl('processiap', 'gs'), { os: 'ios', data: data.receipt, signature: data.signature, id: productId, lang: USER_LANGUAGE }, function (result) { if (result.status == 'OK') { return inAppPurchase.consume(data.type, data.receipt, data.signature); } else { showErrorMessage("Error: " + result.message); } }).fail(function () { showErrorMessage("Error: Lost connection to TerranQuest servers. If your purchase does not appear within a few hours, contact support@netsyms.com."); }); }) .then(function () { playSound("coin"); showSuccessMessage("Thanks for your purchase!"); refreshcoins(); }) .catch(function (err) { playSound("error"); console.log("Error: " + err.message); showErrorMessage("Error: " + err.message); }); } else { showErrorMessage("Store not available on your device. Please go to terranquest.net to purchase coins."); } } function buyitem(id, cost) { $('#shopitem-' + id).prop('onclick', null).off('click'); $.getJSON(mkApiUrl('buyitem', 'gs'), { merchid: id, cost: cost, lang: USER_LANGUAGE }, function (data) { if (data.status == 'OK') { playSound("coin"); showSuccessMessage(data.message); } else { playSound("error"); showErrorMessage(data.message); } loadstorefront(); }); } function getmerchhtmlfromjson(item) { var itemhtml = "
" + item.desc + "
" + "" + "Buy Item (" + item.cost + " coins)" + "" + "" + prod.description + "
" + "" + "Buy Coins (" + prod.price + ")" + "" + "