lmc/account/paymentreceipt/paymentreceipt.js

88 lines
2.6 KiB
JavaScript

/*
* This file is part of Linode Manager Classic.
*
* Linode Manager Classic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Linode Manager Classic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Linode Manager Classic. If not, see <https://www.gnu.org/licenses/>.
*/
import { settings, elements, apiGet, parseParams, setupHeader } from "/global.js";
(function()
{
// Element names specific to this page
elements.amount = "amount";
elements.date = "date";
elements.paymentID = "payment-id";
elements.subnav = "subnav-link";
elements.subnavActive = "subnav-link-active";
elements.total = "total";
// Data received from API calls
var data = {};
// Static references to UI elements
var ui = {};
ui.amount = {};
ui.date = {};
ui.paymentID = {};
ui.total = {};
// Callback for payment details API call
var displayPayment = function(response)
{
var paymentDate = new Date(response.date + "Z");
ui.date.innerHTML = paymentDate.toLocaleDateString();
ui.amount.innerHTML = "$" + response.usd.toFixed(2);
ui.total.innerHTML = "$" + response.usd.toFixed(2);
};
// Initial setup
var setup = function()
{
// Parse URL parameters
data.params = parseParams();
// We need a payment ID, so die if we don't have it
if (!data.params.pid) {
alert("No payment ID supplied!");
return;
}
setupHeader();
// Highlight the billing history subnav link
var subnavLinks = document.getElementsByClassName(elements.subnav);
for (var i = 0; i < subnavLinks.length; i++) {
if (subnavLinks[i].pathname == "/account/billing_history")
subnavLinks[i].className = elements.subnav + " " + elements.subnavActive;
else
subnavLinks[i].className = elements.subnav;
}
// Get element references
ui.amount = document.getElementById(elements.amount);
ui.date = document.getElementById(elements.date);
ui.paymentID = document.getElementById(elements.paymentID);
ui.total = document.getElementById(elements.total);
// Set payment ID
ui.paymentID.innerHTML = data.params.pid;
// Get data from API
apiGet("/account/payments/" + data.params.pid, displayPayment, null);
};
// Attach onload handler
window.addEventListener("load", setup);
})();