2020-03-13 23:01:39 -04:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2024-06-17 18:21:01 -04:00
|
|
|
import { settings, elements, apiPost, parseParams, setupHeader } from "/global.js";
|
2020-03-13 23:01:39 -04:00
|
|
|
|
|
|
|
(function()
|
|
|
|
{
|
|
|
|
// Element names specific to this page
|
|
|
|
elements.ccNew = "cc-new";
|
2021-03-30 17:02:12 -04:00
|
|
|
elements.cvv = "cvv";
|
2024-06-17 18:21:01 -04:00
|
|
|
elements.default = "default";
|
2020-03-13 23:01:39 -04:00
|
|
|
elements.expiryMonth = "expiry-month";
|
|
|
|
elements.expiryYear = "expiry-year";
|
|
|
|
elements.updateButton = "update-button";
|
|
|
|
|
|
|
|
// Data received from API calls
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
// Static references to UI elements
|
|
|
|
var ui = {};
|
|
|
|
ui.ccNew = {};
|
2021-03-30 17:02:12 -04:00
|
|
|
ui.cvv = {};
|
2024-06-17 18:21:01 -04:00
|
|
|
ui.default = {};
|
2020-03-13 23:01:39 -04:00
|
|
|
ui.expiryMonth = {};
|
|
|
|
ui.expiryYear = {};
|
|
|
|
ui.updateButton = {};
|
|
|
|
|
|
|
|
// Click handler for update button
|
|
|
|
var handleUpdate = function(event)
|
|
|
|
{
|
|
|
|
if (event.currentTarget.disabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var req = {
|
2024-06-17 18:21:01 -04:00
|
|
|
"data": {
|
|
|
|
"card_number": ui.ccNew.value.replaceAll("-", "").replaceAll(" ", ""),
|
|
|
|
"cvv": ui.cvv.value,
|
|
|
|
"expiry_month": parseInt(ui.expiryMonth.value),
|
|
|
|
"expiry_year": parseInt(ui.expiryYear.value)
|
|
|
|
},
|
|
|
|
"is_default": ui.default.checked,
|
|
|
|
"type": "credit_card"
|
2020-03-13 23:01:39 -04:00
|
|
|
};
|
|
|
|
|
2024-06-17 18:21:01 -04:00
|
|
|
apiPost("/account/payment-methods", req, function(response)
|
2020-03-13 23:01:39 -04:00
|
|
|
{
|
|
|
|
location.href = "/account";
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Initial setup
|
|
|
|
var setup = function()
|
|
|
|
{
|
|
|
|
// Parse URL parameters
|
|
|
|
data.params = parseParams();
|
|
|
|
|
|
|
|
setupHeader();
|
|
|
|
|
|
|
|
// Get element references
|
|
|
|
ui.ccNew = document.getElementById(elements.ccNew);
|
2021-03-30 17:02:12 -04:00
|
|
|
ui.cvv = document.getElementById(elements.cvv);
|
2024-06-17 18:21:01 -04:00
|
|
|
ui.default = document.getElementById(elements.default);
|
2020-03-13 23:01:39 -04:00
|
|
|
ui.expiryMonth = document.getElementById(elements.expiryMonth);
|
|
|
|
ui.expiryYear = document.getElementById(elements.expiryYear);
|
|
|
|
ui.updateButton = document.getElementById(elements.updateButton);
|
|
|
|
|
|
|
|
// Populate expiry selectors
|
|
|
|
var now = new Date();
|
|
|
|
ui.expiryMonth.value = now.getMonth() + 1;
|
|
|
|
for (var i = 0; i < 25; i++) {
|
|
|
|
var year = document.createElement("option");
|
|
|
|
year.value = now.getFullYear() + i;
|
|
|
|
year.innerHTML = now.getFullYear() + i;
|
|
|
|
ui.expiryYear.appendChild(year);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register event handlers
|
|
|
|
ui.updateButton.addEventListener("click", handleUpdate);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Attach onload handler
|
|
|
|
window.addEventListener("load", setup);
|
|
|
|
})();
|