Compare commits
32 Commits
e9041a05f6
...
main
Author | SHA1 | Date | |
---|---|---|---|
1d4b4a30d1 | |||
d0d6d8ebc3 | |||
640712769e | |||
d17b4fe2d5 | |||
57ee2fa2ef | |||
3199b487b1 | |||
0f551af936 | |||
63e22059cf | |||
6a168a4b83 | |||
5107f68d4c | |||
18ead8b027 | |||
5822ced6af | |||
d8396abd36 | |||
943c301d9a | |||
83b3ff39b0 | |||
0392a73033 | |||
e0148728d6 | |||
ddb9f00d89 | |||
89729cab43 | |||
78456b8868 | |||
dc4f0ee088 | |||
b4431f82d7 | |||
250db79c61 | |||
71d2f52578 | |||
f76e9794f9 | |||
8937dbd4b8 | |||
5deb4b752d | |||
c39c6fa7ba | |||
3a56584a98 | |||
f4fe0f8941 | |||
47dfbdea31 | |||
aa03c926a9 |
17
README.md
17
README.md
@ -12,7 +12,7 @@ This plugin allow you to sell storage space to your users using Stripe subscript
|
||||
Payments are automated with Stripe.
|
||||
|
||||
## Getting Started <a name = "getting_started"></a>
|
||||
This is the NCD fork of the [ncd-sell-storage](https://git.ncd-serv.fr/ncd/Peertube-plugins/src/branch/master/peertube-plugin-ncd-sell-storage) PeerTube plugin. This fork at inception allows you to add five packages rather than the original three. Everything else is pretty much left as-is, unless I decide to work on it more.
|
||||
This is the NCD fork of the [peertube-plugin-orion-sell-storage](https://git.orion-serv.fr/ncd/Peertube-plugins/src/branch/master/peertube-plugin-ncd-sell-storage) PeerTube plugin. This fork at inception allows you to add five packages rather than the original three. Everything else is pretty much left as-is, unless I decide to work on it more.
|
||||
Check [Prerequisites](#Prerequisites) to install this plugin
|
||||
|
||||
### Prerequisites
|
||||
@ -26,6 +26,13 @@ Check [Prerequisites](#Prerequisites) to install this plugin
|
||||
- Search for "ncd-sell-storage"
|
||||
- Click Install near the plugin name
|
||||
|
||||
## If installing locally
|
||||
- Clone Git repository
|
||||
- cd peertube-plugin-ncd-sell-storage
|
||||
- yarn
|
||||
- yarn build
|
||||
- Install via PeerTube CLI
|
||||
|
||||
### Configuration
|
||||
You need to configuration the plugin to work.
|
||||
Create an account on https://stripe.com to start.
|
||||
@ -34,11 +41,15 @@ Create an account on https://stripe.com to start.
|
||||
In your Stripe dashboard, you can test in "Test mode", and go live by unchecking "Test mode" in the top right.
|
||||
To go in live mode, you need to fill form in Stripe side. We recommand you to test in Test mode the integration before go in live.
|
||||
|
||||
# Note: If you perform a transaction in Test Mode, you'll need to manually clear the subscription status because the webhook will not send back the correct validation response, meaning the changes will take effect but nothing will be charged. Use a dedicated test account.
|
||||
|
||||
First, go to the Developer tab, and navigate to "API Keys". Grab your Secret API key, and insert it in your plugin settings.
|
||||
After that, always in the Developer tab, navigate to Webhook and create a webhook.
|
||||
|
||||
An example of webhook URL is available in your plugin settings.
|
||||
Its like https://your-instance.tld/plugins/ncd-sell-storage/1.0.0/router/webhook
|
||||
Its like https://your-instance.tld/plugins/ncd-sell-storage/1.1.2/router/webhook
|
||||
|
||||
# Note: If you update the plugin, you'll have to update the webhook link in Stripe. Don't forget this!
|
||||
|
||||
Keep in mind, you need to update the webhook URL on stripe-side for each new plugin version, because the version is in the URL.
|
||||
Now, configure your Currency and Page description in the plugin settings.
|
||||
@ -46,7 +57,7 @@ Now, configure your Currency and Page description in the plugin settings.
|
||||
Its time to add your Plans! In stripe, go to Product page, and add new product. Set a name, description and the price.
|
||||
After creation, go in this new Product and grab the "API ID" near the price field.
|
||||
|
||||
Now, you can continue configure your Plan (1, 2, 3) in the plugin settings.
|
||||
Now, you can continue configure your Plan (1, 2, 3, 4, 5) in the plugin settings.
|
||||
Repeat this process for each plans. Add new product, and grab the API ID corresponding to this price to insert it in your Product ID field, in the plugin settings.
|
||||
|
||||
## Usage <a name = "usage"></a>
|
||||
|
@ -7,55 +7,65 @@ async function register({
|
||||
peertubeHelpers,
|
||||
registerClientRoute,
|
||||
}) {
|
||||
|
||||
/**
|
||||
* Add link admin page
|
||||
*/
|
||||
|
||||
registerHook({
|
||||
target: "action:router.navigation-end",
|
||||
handler: async (params) => {
|
||||
if (params.path.startsWith("/my-account")) {
|
||||
if (document.getElementById("subscription-link")) return;
|
||||
|
||||
let href = "/p/my-subscription";
|
||||
|
||||
// Get menu container
|
||||
const menuContainer = document.getElementsByClassName("sub-menu")[0];
|
||||
|
||||
// Create link
|
||||
const content = `
|
||||
<a _ngcontent-dke-c79="" id="subscription-link" routerlinkactive="active" class="sub-menu-entry ng-star-inserted" href="${href}">
|
||||
${await peertubeHelpers.translate("Storage")}
|
||||
</a>
|
||||
`;
|
||||
|
||||
// Create node for it
|
||||
const nodeLink = document.createElement("div");
|
||||
nodeLink.innerHTML = content.trim();
|
||||
|
||||
// Insert to menu container
|
||||
menuContainer.appendChild(nodeLink.firstChild);
|
||||
target: "filter:left-menu.links.create.result",
|
||||
handler: (links) => {
|
||||
if (!Array.isArray(links)) {
|
||||
return links;
|
||||
}
|
||||
let myLibraryLinks;
|
||||
// Searching the 'in-my-library' entry.
|
||||
for (const link of links) {
|
||||
if (typeof link !== "object") {
|
||||
continue;
|
||||
}
|
||||
if (!("key" in link)) {
|
||||
continue;
|
||||
}
|
||||
if (link.key === "in-my-library" || link.key === "my-video-space") {
|
||||
myLibraryLinks = link;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!myLibraryLinks) {
|
||||
return links;
|
||||
}
|
||||
if (!Array.isArray(myLibraryLinks.links)) {
|
||||
return links;
|
||||
}
|
||||
|
||||
const label = "NCTV Storage";
|
||||
myLibraryLinks.links.unshift({
|
||||
label,
|
||||
shortLabel: label,
|
||||
path: "/p/ncd-my-subscription",
|
||||
icon: "film",
|
||||
});
|
||||
return links;
|
||||
},
|
||||
});
|
||||
|
||||
// Register routes
|
||||
registerClientRoute({
|
||||
route: "my-subscription",
|
||||
route: "ncd-my-subscription",
|
||||
onMount: ({ rootEl }) => {
|
||||
subPage.showPage({ rootEl, peertubeHelpers });
|
||||
},
|
||||
});
|
||||
|
||||
registerClientRoute({
|
||||
route: "subscription-success",
|
||||
route: "ncd-subscription-success",
|
||||
onMount: ({ rootEl }) => {
|
||||
successPage.showPage({ rootEl, peertubeHelpers });
|
||||
},
|
||||
});
|
||||
|
||||
registerClientRoute({
|
||||
route: "subscription-cancel",
|
||||
route: "ncd-subscription-cancel",
|
||||
onMount: ({ rootEl }) => {
|
||||
cancelPage.showPage({ rootEl, peertubeHelpers });
|
||||
},
|
||||
|
@ -44,17 +44,19 @@ async function showPage({ rootEl, peertubeHelpers }) {
|
||||
|
||||
rootEl.innerHTML = `
|
||||
<div class="ncd-content text-center">
|
||||
<h1>${await peertubeHelpers.translate("Choose your Subscription")}</h1>
|
||||
<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">
|
||||
<h1>${await peertubeHelpers.translate("Choose your Storage Plan")}</h1>
|
||||
<h5><i>To subscribe to a storage plan with cryptocurrency (BTC, ETH, XMR), <a href="/about/contact">contact us</a>.</i></h5>
|
||||
<h6><i>Note: Cryptocurrency prices are 25% higher to cover transaction fees.</i></h6>
|
||||
<!-- <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" style="max-width: 90%; margin: 0 auto;">
|
||||
<div class="row">
|
||||
${(await Promise.all(plans.map(async (plan) =>
|
||||
`<div class="col-sm-12 col-md-6 col-lg-4">
|
||||
`<div class="col-sm-12 col-md-6 col-lg-4" style="margin-bottom: 1rem;">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form method="POST" action="#" class="ncdSubscriptionForm">
|
||||
<h3 class="card-title">${plan.name}</h3>
|
||||
<h4>${plan.price}${currency} /${await peertubeHelpers.translate("month")}</h4>
|
||||
<h4>${currency}${plan.price} /${await peertubeHelpers.translate("month")}</h4>
|
||||
<p class="card-text">${plan.storage} ${await peertubeHelpers.translate("GB Storage")}</p>
|
||||
|
||||
<input type="hidden" name="lookup_key" value="${plan.key}">
|
||||
@ -65,8 +67,6 @@ async function showPage({ rootEl, peertubeHelpers }) {
|
||||
</div>
|
||||
`))).join("")}
|
||||
</div>
|
||||
|
||||
<p><i>${await translate("Secure payment with Stripe")}</i></p>
|
||||
</div>
|
||||
|
||||
${session_id ? `
|
||||
@ -75,12 +75,16 @@ async function showPage({ rootEl, peertubeHelpers }) {
|
||||
<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>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
` : ""}
|
||||
|
||||
|
||||
${sub_plan ? `
|
||||
<p><i><b>${await translate("Your current plan")}</b>: ${sub_plan.name}, ${sub_plan.price}${currency} /${await peertubeHelpers.translate("month")}, ${sub_plan.storage} ${await peertubeHelpers.translate("GB Storage")}</i></p>
|
||||
<p><i><b>${await translate("Your current plan")}</b>: ${sub_plan.name}, ${currency}${sub_plan.price} /${await peertubeHelpers.translate("month")}, ${sub_plan.storage} ${await peertubeHelpers.translate("GB Storage")}</i></p>
|
||||
|
||||
<div>
|
||||
<a href="https://billing.stripe.com/p/login/aEUg0YcdE3ff9j2cMM" target="_blank" style="font-size: 1.25rem; background-color: #0083f5; color: white; border-radius: 0.25rem; padding: 0.5rem 0.75rem; margin-top: 1.25rem;">Manage Subcription</a>
|
||||
<div>
|
||||
` : ""}
|
||||
|
||||
</div>
|
||||
@ -88,7 +92,7 @@ async function showPage({ rootEl, peertubeHelpers }) {
|
||||
|
||||
|
||||
const checkForListen = () => {
|
||||
document.querySelectorAll(".ncdSubscriptionForm").length === 3 ? listenSubmitSubscription(peertubeHelpers) : setTimeout(() => checkForListen(), 1000);
|
||||
document.querySelectorAll(".ncdSubscriptionForm").length === 5 ? listenSubmitSubscription(peertubeHelpers) : setTimeout(() => checkForListen(), 1000);
|
||||
};
|
||||
checkForListen();
|
||||
}
|
||||
|
@ -10,5 +10,5 @@
|
||||
"Subscription canceled.": "Souscription annulée.",
|
||||
"Secure payment with Stripe": "Paiement sécurisé via Stripe",
|
||||
"Your current plan": "Votre offre actuelle",
|
||||
"Storage": "Stockage"
|
||||
"NCTV Storage": "NCTV Stockage"
|
||||
}
|
||||
|
8
main.js
8
main.js
@ -121,8 +121,8 @@ async function register({
|
||||
}
|
||||
},
|
||||
mode: 'subscription',
|
||||
success_url: `${INSTANCE_URL}/p/subscription-success?session_id={CHECKOUT_SESSION_ID}`,
|
||||
cancel_url: `${INSTANCE_URL}/p/subscription-cancel`,
|
||||
success_url: `${INSTANCE_URL}/p/ncd-subscription-success?session_id={CHECKOUT_SESSION_ID}`,
|
||||
cancel_url: `${INSTANCE_URL}/p/ncd-subscription-cancel`,
|
||||
});
|
||||
|
||||
res.json({
|
||||
@ -151,13 +151,13 @@ async function register({
|
||||
const INSTANCE_URL = "https://" + req.get('host');
|
||||
|
||||
// For demonstration purposes, we're using the Checkout session to retrieve the customer ID.
|
||||
// Typically this is stored alongside the authenticated user in your database.
|
||||
// Typically this is stored alongside the authenticated user in your database. (psql) users -> userID ->
|
||||
const { session_id } = req.body;
|
||||
const checkoutSession = await stripe.checkout.sessions.retrieve(session_id);
|
||||
|
||||
// This is the url to which the customer will be redirected when they are done
|
||||
// managing their billing with the portal.
|
||||
const returnUrl = INSTANCE_URL + "/p/my-subscription";
|
||||
const returnUrl = INSTANCE_URL + "/p/ncd-my-subscription";
|
||||
|
||||
const portalSession = await stripe.billingPortal.sessions.create({
|
||||
customer: checkoutSession.customer,
|
||||
|
@ -1,11 +1,9 @@
|
||||
{
|
||||
"name": "@ncdmatty/peertube-plugin-ncd-sell-storage",
|
||||
"name": "peertube-plugin-ncd-sell-storage",
|
||||
"description": "NCD fork of the peertube-plugin-orion-sell-storage to sell storage to users using Stripe",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.2",
|
||||
"author": "matty",
|
||||
"bugs": {
|
||||
"url": "https://gitea.nicecrew.digital/matty/peertube-plugin-ncd-sell-storage"
|
||||
},
|
||||
"bugs": "https://gitea.nicecrew.digital/matty/peertube-plugin-ncd-sell-storage",
|
||||
"clientScripts": [
|
||||
{
|
||||
"script": "dist/common-client-plugin.js",
|
||||
|
Reference in New Issue
Block a user