This commit is contained in:
matty 2024-04-02 15:43:20 -04:00
parent 18ead8b027
commit 5107f68d4c

View File

@ -12,7 +12,7 @@ async function showPage({ rootEl, peertubeHelpers }) {
const description = await peertubeHelpers.markdownRenderer.enhancedMarkdownToHTML(settings["sell-description"]); const description = await peertubeHelpers.markdownRenderer.enhancedMarkdownToHTML(settings["sell-description"]);
const plans = []; const plans = [];
for(let i = 1; i <= 5; i++) { for (let i = 1; i <= 5; i++) {
const name = settings["plan-" + i + "-name"]; const name = settings["plan-" + i + "-name"];
const key = settings["plan-" + i + "-key"]; const key = settings["plan-" + i + "-key"];
const storage = settings["plan-" + i + "-storage"]; const storage = settings["plan-" + i + "-storage"];
@ -33,23 +33,24 @@ async function showPage({ rootEl, peertubeHelpers }) {
headers: peertubeHelpers.getAuthHeader(), headers: peertubeHelpers.getAuthHeader(),
}); });
const data = await response.json(); const data = await response.json();
// If have error // If have error
if (!data || !data.status || (data.status && data.status !== "success")) { if (!data || !data.status || (data.status && data.status !== "success")) {
peertubeHelpers.notifier.error(data.message || "Unknown error"); peertubeHelpers.notifier.error(data.message || "Unknown error");
}else{ } else {
session_id = data?.data?.session_id; session_id = data?.data?.session_id;
sub_plan = data?.data?.sub_plan; sub_plan = data?.data?.sub_plan;
} }
rootEl.innerHTML = ` rootEl.innerHTML = `
<div class="ncd-content text-center"> <div class="ncd-content text-center">
<h4><i>To subscribe to a storage plan with cryptocurrency (BTC, ETC, XMR) or cancel/update your subscription tier, <a href="/about/contact">contact us</a>.</i></h4>
<h1>${await peertubeHelpers.translate("Choose your Storage Plan")}</h1> <h1>${await peertubeHelpers.translate("Choose your Storage Plan")}</h1>
<p>${description.length ? description : await peertubeHelpers.translate("You want tu spport us ? Or need more space ? Your in the right place!")}</p> <p>${description.length ? description : await peertubeHelpers.translate("You want tu spport us ? Or need more space ? Your in the right place!")}</p>
<div class="mt-5"> <div class="mt-5">
<div class="row"> <div class="row">
${(await Promise.all(plans.map(async (plan) => ${(await Promise.all(plans.map(async (plan) =>
`<div class="col-sm-12 col-md-6 col-lg-4" style="margin-bottom: 1rem;"> `<div class="col-sm-12 col-md-6 col-lg-4" style="margin-bottom: 1rem;">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<form method="POST" action="#" class="ncdSubscriptionForm"> <form method="POST" action="#" class="ncdSubscriptionForm">
@ -65,18 +66,14 @@ async function showPage({ rootEl, peertubeHelpers }) {
</div> </div>
`))).join("")} `))).join("")}
</div> </div>
<h4><i>NCTV also offers cryptocurrency subscriptions for media storage. Contact Matty on <a href="https://nicecrew.digital/@matty" target="_blank">NCD</a>, <a href="https://matrix.to/#/@matty:chat.nicecrew.digital" target="_blank">Matrix</a>, or via <a href="mailto:matty@nicecrew.digital">email</a>.</i></h4>
</div> </div>
<div class="mt-5"> <div class="mt-5">
<form method="POST" action="#" id="formManageSub"> <form method="POST" action="#" id="formManageSub">
<input type="hidden" id="session-id" name="session_id" value="${session_id}" /> <input type="hidden" id="session-id" name="session_id" value="${session_id}" />
<button id="checkout-and-portal-button" type="submit" class="btn btn-primary">${await translate("Manage my Subscription")}</button> <button id="checkout-and-portal-button" type="submit" class="btn btn-primary">${await translate("Manage my Subscription")}</button>
</form> </form>
</div>
</div>
${sub_plan ? ` ${sub_plan ? `
@ -100,7 +97,7 @@ function listenSubmitSubscription(peertubeHelpers) {
document.querySelectorAll(".ncdSubscriptionForm").forEach(el => { document.querySelectorAll(".ncdSubscriptionForm").forEach(el => {
el.addEventListener("submit", (e) => { el.addEventListener("submit", (e) => {
e.preventDefault(); e.preventDefault();
try { try {
const form = new URLSearchParams(new FormData(e.target)); const form = new URLSearchParams(new FormData(e.target));
fetch(baseUrl + "/create-checkout-session", { fetch(baseUrl + "/create-checkout-session", {
@ -108,17 +105,17 @@ function listenSubmitSubscription(peertubeHelpers) {
headers: peertubeHelpers.getAuthHeader(), headers: peertubeHelpers.getAuthHeader(),
body: form, body: form,
}).then((res) => res.json()).then((data) => { }).then((res) => res.json()).then((data) => {
if(!data || !data.status || data.status !== "success") { if (!data || !data.status || data.status !== "success") {
peertubeHelpers.notifier.error(data.message || "Unknown error"); peertubeHelpers.notifier.error(data.message || "Unknown error");
return; return;
} }
window.location.href = data.data.redirectUrl; window.location.href = data.data.redirectUrl;
}).catch(err => { }).catch(err => {
console.error(err); console.error(err);
peertubeHelpers.notifier.error(err); peertubeHelpers.notifier.error(err);
}) })
} catch (error) { } catch (error) {
peertubeHelpers.notifier.error(error); peertubeHelpers.notifier.error(error);
} }
@ -137,17 +134,17 @@ function listenSubmitSubscription(peertubeHelpers) {
headers: peertubeHelpers.getAuthHeader(), headers: peertubeHelpers.getAuthHeader(),
body: form, body: form,
}).then((res) => res.json()).then((data) => { }).then((res) => res.json()).then((data) => {
if(!data || !data.status || data.status !== "success") { if (!data || !data.status || data.status !== "success") {
peertubeHelpers.notifier.error(data.message || "Unknown error"); peertubeHelpers.notifier.error(data.message || "Unknown error");
return; return;
} }
window.location.href = data.data.redirectUrl; window.location.href = data.data.redirectUrl;
}).catch(err => { }).catch(err => {
console.error(err); console.error(err);
peertubeHelpers.notifier.error(err); peertubeHelpers.notifier.error(err);
}) })
} catch (error) { } catch (error) {
peertubeHelpers.notifier.error(error); peertubeHelpers.notifier.error(error);
} }