integrate stripe
This commit is contained in:
parent
a8a6039d8d
commit
3ec859e32b
10
main.go
10
main.go
|
|
@ -54,6 +54,7 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
var datetimestring = t.Format("20060102150405")
|
||||
var scales = getMyDevs(userName)
|
||||
var last_metrics []OneMetric
|
||||
var checkout_session_id string
|
||||
|
||||
if (r.URL.Path == "/scales.html") || (r.URL.Path == "/abos.html") {
|
||||
// wir holen noch die letzten Metriken
|
||||
|
|
@ -63,16 +64,25 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
if (r.URL.Path == "/abos.html") {
|
||||
// wir generieren die Stripe Session ID
|
||||
checkout_session_id = GetStripeSessionID()
|
||||
logit("Stripe Session ID: " + checkout_session_id)
|
||||
|
||||
}
|
||||
|
||||
data := struct {
|
||||
UserName string
|
||||
DateTimeString string
|
||||
Scales []string
|
||||
LastMetrics []OneMetric
|
||||
CheckoutSessionID string
|
||||
} {
|
||||
userName,
|
||||
datetimestring,
|
||||
scales,
|
||||
last_metrics,
|
||||
checkout_session_id,
|
||||
}
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, "layout", &data); err != nil {
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
{{range .LastMetrics}}
|
||||
<div class="columns is-vcentered is-marginless">
|
||||
<div class="column is-full has-background-primary">
|
||||
<span id="alias_{{.Deveui}}" class="is-size-5">{{.Alias}}</span>
|
||||
<div class="select is-pulled-right is-vcentered">
|
||||
<span id="alias_{{.Deveui}}" class="is-size-7-mobile is-size-4-tablet">{{.Alias}} (bis 01.01.2099)</span>
|
||||
<div class="select is-pulled-right is-vcentered is-size-7-mobile">
|
||||
<select class="has-background-light">
|
||||
<option>keine Verlängerung</option>
|
||||
<option>1 Jahr verlängern</option>
|
||||
<option>2 Jahre verlängern</option>
|
||||
<option>3 Jahre verlängern</option>
|
||||
<option>keine</option>
|
||||
<option>1 Jahr</option>
|
||||
<option>2 Jahre</option>
|
||||
<option>3 Jahre</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -23,8 +23,27 @@
|
|||
<div class="column is-full"></div>
|
||||
</div>
|
||||
{{end}}
|
||||
<div>
|
||||
<button id="pay-button" class="button is-success">Pay</button>
|
||||
</div>
|
||||
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
|
||||
<script>
|
||||
|
||||
var stripe = Stripe('pk_test_YkSGqH3Tk9WKK9HrlY63GhAg');
|
||||
|
||||
$("#pay-button").click(function() {
|
||||
stripe.redirectToCheckout({
|
||||
sessionId: '{{.CheckoutSessionID}}'
|
||||
}).then(function (result) {
|
||||
// If `redirectToCheckout` fails due to a browser or network
|
||||
// error, display the localized error message to your customer
|
||||
// using `result.error.message`.
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{{ else }}
|
||||
<h4>Bitte zuerst <a href="login.html">einloggen</a></h4>
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
{{define "body_content"}}
|
||||
<p class="title is-4">Zahlung abgebrochen!</p>
|
||||
<p>Zahlung wurde abgebrochen</p>
|
||||
{{end}}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
{{define "body_content"}}
|
||||
<p class="title is-4">Danke schoen!</p>
|
||||
<p>Danke fuer die Zahlung!</p>
|
||||
{{end}}
|
||||
|
|
@ -103,11 +103,11 @@ Device ID: <span id="deveui"></span>
|
|||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<p id="paid_until_{{.Deveui}}" class="has-text-centered" style="align-items: center;"><a class="button is-warning is-small" href="/abos.html">
|
||||
<span class="icon">
|
||||
<i class="fa fa-shopping-cart"></i>
|
||||
<p id="paid_until_{{.Deveui}}" class="has-text-centered"><a class="button is-warning is-small" href="/abos.html">
|
||||
<span class="has-text-centered is-size-6">aktiv bis 01.01.1999 </span>
|
||||
<span class="icon is-medium">
|
||||
<i class="fa fa-2x fa-cart-plus"></i>
|
||||
</span>
|
||||
<span>Abo verlängern (aktiv bis 01.01.1999)</span>
|
||||
</a></p>
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/stripe/stripe-go"
|
||||
"github.com/stripe/stripe-go/checkout/session"
|
||||
)
|
||||
|
||||
func GetStripeSessionID() string {
|
||||
stripe.Key = "sk_test_GJbXPD0IAFNvvGpNEpaeDfhl"
|
||||
|
||||
params := &stripe.CheckoutSessionParams{
|
||||
PaymentMethodTypes: stripe.StringSlice([]string{
|
||||
"card",
|
||||
}),
|
||||
LineItems: []*stripe.CheckoutSessionLineItemParams{
|
||||
&stripe.CheckoutSessionLineItemParams{
|
||||
Name: stripe.String("Abo"),
|
||||
Description: stripe.String("Abo mini-beieli.ch"),
|
||||
Amount: stripe.Int64(500),
|
||||
Currency: stripe.String(string(stripe.CurrencyCHF)),
|
||||
Quantity: stripe.Int64(1),
|
||||
},
|
||||
},
|
||||
SuccessURL: stripe.String("https://mini-beieli.ch/payment_received.html"),
|
||||
CancelURL: stripe.String("https://mini-beieli.ch/payment_cancelled.html"),
|
||||
}
|
||||
|
||||
session, err := session.New(params)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return session.ID
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue