Compare commits

...
36 Commits
Author SHA1 Message Date
jlehmann 534ff18a59 changed description document 2025-09-20 11:35:48 +02:00
jlehmann 89e6d009ef added pictures 2025-09-19 20:43:19 +02:00
jlehmann e6d8e6321a changed document 2025-09-19 20:09:51 +02:00
jlehmann 547da06a6f test with multicolumn images 2025-09-19 19:40:58 +02:00
jlehmann cc7d1eafee add missing image 2025-09-19 19:26:37 +02:00
jlehmann a3f961a7c4 change pictures 2025-09-19 19:23:37 +02:00
jlehmann 117ff4c6aa remove frontpage picture again 2025-09-19 18:21:35 +02:00
jlehmann 459e656f44 new frontpage picture 2025-09-19 16:35:40 +02:00
jlehmann 14e5536d5d new picture 2025-09-19 16:20:43 +02:00
jlehmann 4ea5374695 fix alignment with new Bulma Version 2025-08-09 20:09:47 +02:00
jlehmann 75507e26ea Update Bulma Version to 1.0.4 2025-08-09 19:13:44 +02:00
jlehmann 717fac9efd New Abo cost for calendar year, not month (in the perspective of the customer) 2025-08-09 17:12:37 +02:00
jlehmann a8f17eed19 cleanup, adjust offset because of new apexcharts version 2025-08-07 15:57:48 +02:00
jlehmann 92c1606f47 Update apexcharts version 2025-08-07 15:17:03 +02:00
jlehmann de40dc68ff small text update 2025-08-07 14:10:43 +02:00
jlehmann d2a12cc3bb address must be able to contain html 2025-08-07 14:00:55 +02:00
jlehmann e8fc18bc87 add vars to templates 2025-08-07 13:50:00 +02:00
jlehmann a87f5085e7 fix funtion 2025-08-07 13:43:57 +02:00
jlehmann b36ab9e572 fix funtion 2025-08-07 13:42:49 +02:00
jlehmann 2168404670 fix funtion 2025-08-07 13:37:58 +02:00
jlehmann 025441ef7d make some snippet content configurable - fix error 2025-08-07 13:33:41 +02:00
jlehmann 26957ff42b make some snippet content configurable 2025-08-07 13:31:43 +02:00
jlehmann 9d947c08ba make some snippet content configurable 2025-08-07 13:27:34 +02:00
jlehmann 49560c8cec change rental fee 2025-08-07 11:25:03 +02:00
jlehmann 5727e667fb New Text on main site, no selling but leasing 2025-08-07 11:16:15 +02:00
jlehmann 66fa08d48b change address 2025-05-13 19:40:36 +02:00
jlehmann 01c9e06d42 Stripe: new version of Library and creating customer 2023-02-03 17:20:12 +01:00
jlehmann 8b945eeaba timezone in docker image 2022-12-28 17:11:56 +01:00
jlehmann fb55a302f9 make it ready for containers... 2022-12-27 13:58:23 +01:00
jlehmann 8bf76a4a6c REDIS_CONNECTION_STRING as env 2022-12-27 13:39:09 +01:00
jlehmann 15a2827afe add Dockerfile 2022-12-27 09:21:27 +01:00
jlehmann a827a6e91b add some validation code 2022-10-02 16:19:12 +02:00
jlehmann d8eece9046 update user only if it exists 2022-10-02 16:07:31 +02:00
jlehmann 972f38fe6a use html mail for abocost because of table 2022-09-16 11:00:41 +02:00
jlehmann 44e6536c4f add payment years to expiration date, not now 2022-09-15 18:12:40 +02:00
jlehmann fb3e1dbe52 make expiration text more precise 2022-08-01 11:05:08 +02:00
31 changed files with 40820 additions and 38319 deletions
+2
View File
@@ -1,2 +1,4 @@
mini-beieli-web
nohup.out
mini-beieli-sass/node_modules
mini-beieli-sass/package-lock.json
+16
View File
@@ -0,0 +1,16 @@
FROM golang:alpine AS builder
WORKDIR /build
ADD go.mod .
COPY . .
RUN go build
FROM alpine
RUN apk add --no-cache tzdata
ENV TZ=Europe/Zurich
WORKDIR /build
RUN apk add --no-cache tzdata
COPY --from=builder /build/mini-beieli-web /build/mini-beieli-web
COPY snippets snippets
COPY templates templates
COPY static static
CMD ["./mini-beieli-web"]
EXPOSE 4000
+7
View File
@@ -51,6 +51,13 @@ $ TOKEN="XXXXXX influxdb access token with rw access rights XXXXXX"
$ influx delete --token "${TOKEN}" --org minibeieliorg --bucket minibeielibucket --start 2021-06-01T10:53:00Z --stop 2021-06-01T10:53:00Z --predicate '_measurement="measurement" AND deveui="0000D3A659832805"'
```
### Create and Push Docker Image
```
Example:
$ podman login --username drpuur git.nbit.ch
$ podman build --tag git.nbit.ch/drpuur/mini-beieli-web:2025080701 -f ./Dockerfile
$ podman push git.nbit.ch/drpuur/wo-bisch-web:2025080701
```
Autor: Joerg Lehmann, nbit Informatik GmbH
+1 -1
View File
@@ -30,7 +30,7 @@ func sendEmailAbo(username string, alias string, deveui string, days_left int, l
var ablauftext string
if days_left == 0 {
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") ist abgelaufen."
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft heute ab."
} else if days_left > 0 {
fmt.Printf("SEND EMAIL ABO (%s) - %s:%s\n", level, username, deveui)
ablauftext = "Das Abo von \"" + alias + "\" (DevEUI: " + deveui + ") laeuft in " + strconv.Itoa(days_left) + " Tagen ab."
+1 -2
View File
@@ -5,7 +5,6 @@ go 1.17
require (
github.com/gomodule/redigo v1.8.9
github.com/gorilla/securecookie v1.1.1
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/stripe/stripe-go v70.15.0+incompatible
github.com/stripe/stripe-go/v74 v74.7.0
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
)
+7 -4
View File
@@ -4,23 +4,26 @@ github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws
github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stripe/stripe-go v70.15.0+incompatible h1:hNML7M1zx8RgtepEMlxyu/FpVPrP7KZm1gPFQquJQvM=
github.com/stripe/stripe-go v70.15.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY=
github.com/stripe/stripe-go/v74 v74.7.0 h1:KHlyslQj9YOv62b1sycQ31LFj7KlqR+seHsSowAWrjc=
github.com/stripe/stripe-go/v74 v74.7.0/go.mod h1:5PoXNp30AJ3tGq57ZcFuaMylzNi8KpwlrYAFmO1fHZw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+4 -2
View File
@@ -56,7 +56,9 @@ func sendPaymentConfirmationEmail(username, charge_data string, amount int64) {
mail_message := "To: " + username + `
From: info@mini-beieli.ch
Subject: Zahlungsbestaetigung mini-beieli.ch
MIME-version: 1.0;
Content-Type: text/html; charset="UTF-8";
<pre>
Lieber Benutzer von mini-beieli.ch
Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
@@ -65,7 +67,7 @@ Sie haben soeben erfolgreich folgende Abo-Verlaengerungen bezahlt:
Mit freundlichen Grüssen
--
mini-beieli.ch`
mini-beieli.ch</pre>`
sendEmail(username, "mail@mini-beieli.ch", mail_message)
}
+35 -1
View File
@@ -9,6 +9,31 @@ import (
"time"
)
func getConfigFromEnv(item string) string {
value := os.Getenv("CONFIG_ENVVAR")
if value == "" {
value = "ADDRESS,INITIALCOST,YEARLYCOST"
}
configArr := strings.Split(value, ",")
// Check for expected length to prevent out-of-range panic
if len(configArr) < 3 {
logit("CONFIG_ENVVAR has less than 3 elements")
return "NOTFOUND"
}
switch strings.ToLower(item) {
case "address":
return configArr[0]
case "initialcost":
return configArr[1]
case "yearlycost":
return configArr[2]
default:
return "NOTFOUND"
}
}
func serveTemplate(w http.ResponseWriter, r *http.Request) {
logit("Called URL: " + r.URL.Path)
// wennn kein File angegeben ist: index.html
@@ -40,6 +65,9 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
t := time.Now()
var datetimestring = t.Format("20060102150405")
var address = template.HTML(getConfigFromEnv("address"))
var initialcost = getConfigFromEnv("initialcost")
var yearlycost = getConfigFromEnv("yearlycost")
var scales = getMyDevs(userName)
var last_metrics []OneMetric
@@ -63,12 +91,18 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
data := struct {
UserName string
DateTimeString string
Address template.HTML
InitialCost string
YearlyCost string
Scales []string
LastMetrics []OneMetric
QueryValues map[string][]string
}{
userName,
datetimestring,
address,
initialcost,
yearlycost,
scales,
last_metrics,
query_values,
@@ -102,6 +136,6 @@ func main() {
http.HandleFunc("/checknodes", checkNodesHandler)
logit("Starting Web Application...")
http.ListenAndServe("127.0.0.1:4000", nil)
http.ListenAndServe(":4000", nil)
logit("Terminating Web Application...")
}
File diff suppressed because it is too large Load Diff
+15 -8
View File
@@ -1,17 +1,24 @@
{
"name": "mini-beieli-sass",
"version": "1.0.1",
"version": "1.0.2",
"description": "SASS for mini-beieli-web",
"main": "enter sass/mini-beieli-web.scss",
"main": "css/mini-beieli-web.css",
"scripts": {
"css-build": "node-sass --omit-source-map-url sass/mini-beieli-web.scss css/mini-beieli-web.css",
"test": "echo \"Error: no test specified\" && exit 1"
"css-build": "sass --no-source-map --load-path=node_modules sass/mini-beieli-web.scss css/mini-beieli-web.css",
"css-build:min": "sass --no-source-map --load-path=node_modules --style=compressed sass/mini-beieli-web.scss css/mini-beieli-web.min.css",
"watch": "sass --watch sass/mini-beieli-web.scss css/mini-beieli-web.css",
"clean": "rm -rf css/*",
"test": "echo \"No tests yet\""
},
"author": "Joerg Lehmann",
"license": "ISC",
"devDependencies": {
"bulma": "^0.9.0",
"bulma-helpers": "^0.3.12",
"node-sass": "^4.14.1"
}
"bulma": "^1.0.4",
"sass": "^1.77.0"
},
"browserslist": [
"> 0.5%",
"last 2 versions",
"not dead"
]
}
+5 -6
View File
@@ -1,10 +1,9 @@
@charset "utf-8";
// Import a Google Font
@import url('https://fonts.googleapis.com/css?family=Rubik:400,700');
@use "bulma/sass/utilities/initial-variables" with (
$family-sans-serif: ("Rubik", sans-serif)
);
// Set nbit Style...
$family-sans-serif: "Rubik", sans-serif;
@use "bulma/bulma" as *;
@import "../node_modules/bulma/bulma.sass";
@import "../node_modules/bulma-helpers/bulma-helpers.sass";
@import url("https://fonts.googleapis.com/css?family=Rubik:400,700");
+14 -11
View File
@@ -25,7 +25,7 @@ func newPool() *redis.Pool {
// Dial is an application supplied function for creating and
// configuring a connection.
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", ":6379")
c, err := redis.Dial("tcp", getenv("REDIS_CONNECTION_STRING", ":6379"))
if err != nil {
panic(err.Error())
}
@@ -119,15 +119,14 @@ func checkUserAvailable(username string) bool {
conn := globalPool.Get()
defer conn.Close()
_, err := conn.Do("HGETALL", userPrefix+username)
if err == redis.ErrNil {
logit("User does not exist and is therefore available:" + username)
exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username))
if !exists {
logit("checkUserAvailable: User does not exist, so it is available: " + username)
return true
} else if err != nil {
logit("checkUserAvailable: Error to query Key Value Store")
} else {
logit("checkUserAvailable: User exist, so it is not available: " + username)
return false
}
return false
}
func getMyDevs(username string) []string {
@@ -316,11 +315,7 @@ func prolongActivation(deveui string, years int) (string, error) {
fmt.Println(t.Unix())
var t_new time.Time
if t.Before(time.Now()) {
t_new = time.Now().AddDate(years, 0, 0)
} else {
t_new = t.AddDate(years, 0, 0)
}
active_until_new := t_new.Format(layout)
// SET object
@@ -366,6 +361,14 @@ func updateUser(username, password string) {
conn := globalPool.Get()
defer conn.Close()
logit("updateUser: " + username)
// we exit if user does not exit
exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username))
if !exists {
logit("updateUser: User does not exist: " + username)
return
}
pwd := []byte(password)
hashedPassword, err := bcrypt.GenerateFromPassword(pwd, bcrypt.DefaultCost)
if err != nil {
+1 -6
View File
@@ -1,9 +1,4 @@
{{define "body_content"}}
<p class="title is-4">Kontakt</p>
<p>nbit Informatik GmbH<br />
Kirchweg 2<br />
3510 Konolfingen<br />
<br />
+41 31 792 00 40<br />
<a href='&#109;ai&#108;&#116;o&#58;i&#37;6Ef&#111;&#64;%6Ebi&#116;&#46;%63h'>&#105;nfo&#64;nbit&#46;ch</a>
<p>{{ .Address }}
{{end}}
+1 -1
View File
@@ -51,7 +51,7 @@
<!-- Content ... -->
</section>
<script src="https://cdn.jsdelivr.net/npm/apexcharts@3.27.3"></script>
<script src="https://cdn.jsdelivr.net/npm/apexcharts@5.3.2"></script>
<script src="static/js/chart.js"></script>
+25 -7
View File
@@ -1,10 +1,35 @@
{{define "body_content"}}
<div class="columns is-multiline">
<div class="column is-half">
<div class="box">
<div class="image">
<img src="/static/images/mini-beieli-eine-waage.jpeg" alt="Detail eine Waage">
</div>
<div class="mt-2">Ansicht auf eine Waage</div>
</div>
</div>
<div class="column is-half">
<div class="box">
<div class="image">
<img src="/static/images/mini-beieli-eine-waage-nur-boexli.jpeg" alt="Waage (Boexli)">
</div>
<hr />
<div class="mt-2">Ansicht auf die Box mit der Elektronik/Uebertragungseinheit</div>
</div>
</div>
</div>
<div class="box">
<div class="image">
<img src="/static/images/mini-beieli-web-screenshot.jpeg" alt="Messwerte&uuml;bersicht einer Waage">
</div>
<div class="mt-2">Messwerte&uuml;bersicht einer Waage</div>
</div>
<div class="box">
<div class="image">
<img src="/static/images/mini-beieli-gewichtsentwicklung-screenshot.jpeg" alt="Gewichtsentwicklung">
</div>
<div class="mt-2">Grafik der Gewichtsentwicklung (Zeitdauer kann gew&auml;hlt werden)</div>
</div>
<div class="box">
<div class="image">
<img src="/static/images/mini-beieli-bestueckte-leiterplatte.jpeg" alt="Bestueckte Leiterplatte">
@@ -17,11 +42,4 @@
</div>
<div class="mt-2">CAD Zeichnung Aluminium-Auflage (CNC gefr&auml;st, eloxiert)</div>
</div>
<div class="box">
<div class="image">
<img src="/static/images/mini-beieli-kabelkonfektionierung.jpeg" alt="Kabelkonfektionierung">
</div>
<hr />
<div class="mt-2">Kabelkonfektionierung in Werkstatt für Menschen mit Behinderung</div>
</div>
{{end}}
+3 -6
View File
@@ -5,15 +5,12 @@
<div>
<div class="message is-danger">
<div class="message-body">
Aktuell finden Feldversuche statt... Wer trotzdem schon eine m&ouml;chte, bitte melden!
Kann ab sofort gemietet werden. Abokosten pro Kalenderjahr: {{ .YearlyCost }}
<br /><br />
Hier gibt es einen <a href="static/files/mini-beieli-kurzbeschrieb.pdf" target="_blank">Kurzbeschrieb</a>
Hier gibt es einen <a href="static/files/mini-beieli-kurzbeschrieb.pdf" target="_blank">Kurzbeschrieb</a>, hier ein paar <a href="/images.html">Bilder</a>.
<br /><br />
Sonderpreis: CHF 500.-- (exkl. MwSt., so lange Vorrat, inkl. ein Jahr Abogeb&uuml;hr geschenkt, anschliessend CHF 5.-- pro Monat).
Einmalige Kosten pro Waage: {{ .InitialCost }} (so lange Vorrat, beinhaltet das Abo für das erste Kalenderjahr)
</div>
</div>
<div class="image">
<a href="/images.html"><img src="/static/images/mini-beieli-ready-to-sell.jpeg" alt="Waagen zum Verkauf"></a>
</div>
</div>
{{end}}
-8
View File
@@ -1,8 +0,0 @@
{{define "body_content"}}
<p class="title is-4">Bestellformular</p>
<div class="message is-danger">
<div class="message-body">
Aktuell noch in Entwicklung, kommen Sie sp&auml;ter noch einmal vorbei...
</div>
</div>
{{end}}
+19208 -17998
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB

After

Width:  |  Height:  |  Size: 350 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 331 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.
-16
View File
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -17,7 +17,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
minfunc = function(min) { if (min > 0) { return 0 } else { return min } }
maxfunc = function(max) { return max + 5 }
labels = {
offsetX: 35,
offsetX: 12,
offsetY: -5,
align: 'right'
};
@@ -28,7 +28,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
minfunc = function(min) { return 0 }
maxfunc = function(max) { return 100 }
labels = {
offsetX: 30,
offsetX: 12,
offsetY: -5,
align: 'right'
};
@@ -49,7 +49,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
]
};
labels = {
offsetX: 45,
offsetX: 12,
offsetY: -5,
align: 'right',
formatter: function(val, index) {
@@ -63,7 +63,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
minfunc = function(min) { return 0 }
maxfunc = function(max) { return 100 }
labels = {
offsetX: 30,
offsetX: 12,
offsetY: -5,
align: 'right'
};
@@ -75,7 +75,7 @@ function drawGraph(deveui, alias, property, start, stop, minmax, create_graph) {
minfunc = function(min) { return 900 }
maxfunc = function(max) { return 1060 }
labels = {
offsetX: 35,
offsetX: 12,
offsetY: -5,
align: 'right'
};
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+35 -2
View File
@@ -3,8 +3,9 @@ package main
import (
"encoding/json"
"fmt"
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/paymentintent"
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/customer"
"github.com/stripe/stripe-go/v74/paymentintent"
"io/ioutil"
"log"
"net/http"
@@ -21,6 +22,33 @@ func getStripePK() string {
return os.Getenv("STRIPE_PK")
}
func getCustomerid(name string) string {
// if customer does not already exist, create it...
var cid = ""
params := &stripe.CustomerSearchParams{}
params.Query = *stripe.String("name:'" + name + "'")
customers := customer.Search(params)
for customers.Next() {
fmt.Printf("%s\n", customers.Current().(*stripe.Customer).ID)
cid = customers.Current().(*stripe.Customer).ID
}
if cid == "" {
// create new customer
paramsc := &stripe.CustomerParams{
Name: stripe.String(name),
}
customer, err := customer.New(paramsc)
if err != nil {
log.Println("Error Creating Customer: " + name)
}
cid = customer.ID
}
return cid
}
func getstripepaymentintentHandler(response http.ResponseWriter, request *http.Request) {
name := getUserName(request)
if name != "" {
@@ -51,7 +79,12 @@ func getstripepaymentintentHandler(response http.ResponseWriter, request *http.R
stripe.Key = getStripeKey()
// if customer does not already exist, create it...
customerid := getCustomerid(name)
// define payment
params := &stripe.PaymentIntentParams{
Customer: stripe.String(customerid),
Amount: stripe.Int64(abo_amount),
Currency: stripe.String(string(stripe.CurrencyCHF)),
}