Skip to content

Commit 882f9f7

Browse files
committed
Add billing page with checkout funktionality
1 parent a618264 commit 882f9f7

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

.prettierrc.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@
33
"tabWidth": 4,
44
"semi": true,
55
"singleQuote": false,
6-
"bracketSpacing": true
6+
"bracketSpacing": true,
7+
"overrides": [
8+
{
9+
"files": ["*.html"],
10+
"options": {
11+
"parser": "go-template"
12+
}
13+
},
14+
{
15+
"files": ["content/**/*.md", ".forestry/**/*.yml"],
16+
"options": {
17+
"tabWidth": 2
18+
}
19+
}
20+
]
721
}

assets/js/billing.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { stripePublicKey } from "@params";
2+
3+
(async () => {
4+
const params = new URLSearchParams(window.location.search);
5+
const stripe = new Stripe(stripePublicKey);
6+
window.stripe = stripe;
7+
const action = params.get("action");
8+
const sessionId = params.get("session_id");
9+
10+
switch (action) {
11+
case "checkout_success":
12+
alert("You have successfully completed your purchase! A receipt will be sent to you via email shortly.");
13+
window.location = "/";
14+
break;
15+
case "checkout":
16+
if (!sessionId) {
17+
window.location = "/";
18+
}
19+
try {
20+
const result = await stripe.redirectToCheckout({ sessionId });
21+
if (result.error) {
22+
throw result.error;
23+
}
24+
} catch (e) {
25+
console.error(e);
26+
alert("An unexpected error occured! Please contact us at [email protected]!");
27+
window.location = "/";
28+
}
29+
break;
30+
default:
31+
window.location = "/";
32+
}
33+
})();

config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ params:
1111
security_whitepaper_url: https://github.com/padloc/padloc/blob/master/security.md
1212
github_url: https://github.com/padloc/padloc
1313

14+
stripePublicKey: ""
15+
1416
downloads:
1517
- title: Padloc for Mac
1618
type: desktop

content/billing/billing.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
date: 2016-11-13T20:17:39+01:00
3+
title: Billing
4+
---

layouts/section/billing.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{ define "css" }}
2+
{{ template "basecss" . }}
3+
{{ end }}
4+
5+
{{ define "js" }}
6+
{{ $js := resources.Get "js/billing.js" | js.Build (dict "params" (dict "stripePublicKey" .Site.Params.stripePublicKey )) }}
7+
<script src="https://js.stripe.com/v3/"></script>
8+
<script src="{{ $js.RelPermalink }}"></script>
9+
{{ end }}
10+
11+
{{ define "main" }}
12+
<section style="padding: 10em; text-align: center;">Redirecting you to the checkout page...</section>
13+
{{ end }}

static/img/brand/logo.png

56.5 KB
Loading

0 commit comments

Comments
 (0)