-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgowebadmin.go
185 lines (161 loc) · 4.09 KB
/
gowebadmin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package gowebadmin
import (
"github.com/gin-gonic/gin"
"github.com/stripe/stripe-go/v72"
"html/template"
)
// Router für Login
// Router für das bezahlen
/*
router.Any("/create-portal-session", payment.Wrap(payment.CreatePortalSession))
router.Any("/create-customer-portal-session", payment.CheckoutWrap(payment.CreatePortalSession))
router.Any("/webhook", payment.Wrap(payment.HandleWebhook2))
router.GET("/checkout", payment.Checkout)
router.GET("/success", payment.Success)
router.GET("/success.html", payment.Success)
router.GET("/cancel", payment.Cancel)
*/
/*
router.GET("/login", login.LoginHandler(auth))
router.GET("/callback", login.CallbackHandler(auth))
router.GET("/logout", login.LogoutHandler)
*/
type Customer struct {
StripeAccount string
Title string
AuthO string
EMail string
SubscribedProducts []*stripe.Subscription
PaymentValid bool
MailVerified bool
AboDetails string
}
type DBSubscription struct {
Id string
Products []Product
}
type Product struct {
Name string
}
type Domains struct {
Domain string
MaxSites int64
UsedSites int64
Sites []string
LinkedSubscription string
Address string
Active bool
}
type WebAdmin struct {
Domain string
Collection string
Database Database
Stripe StripeConfig
Auth0 Auth0
MailTitle string
VerifyPath string
}
type Auth0 struct {
Domain string
DomainAPI string
ClientId string
ClientSecret string
Callback string
AfterLogin string
AfterLogout string
Authenticator *Authenticator
ClientIdAPI string
ClientSecretAPI string
}
type StripeConfig struct {
CheckoutTitle string
CheckoutTemplate *template.Template
PricingTabelId string
PublishabelKey string
StripeKey string
EndpointSecret string
WebhookSecret string
LookupKey string
CustomEndpoints CustomEndpoints
Pages Pages
CustomHead string
CustomBody string
CustomCss string
AllowedPlanNames []string
}
type Pages struct {
Checkout Page
Success Page
Cancel Page
}
type Page struct {
Path string
File string
}
type Database struct {
ConnectionString string
Database string
}
type CustomEndpoints struct {
SuccessUrl string
CancelUrl string
ReturnUrl string
}
func (web *WebAdmin) GetRouters(router *gin.Engine) {
router.Any("/create-portal-session", web.CustomerWrap(web.CreatePortalSession))
router.Any("/create-customer-portal-session", web.CustomerWrap(web.CreatePortalSession))
router.Any("/webhook", Wrap(web.HandleWebhook))
router.GET("/login", web.LoginHandler(web.Auth0.Authenticator))
router.GET("/callback", web.CallbackHandler(web.Auth0.Authenticator))
router.GET("/logout", web.LogoutHandler)
router.GET("/checkout", web.Checkout)
router.GET("/abo", web.Checkout)
router.GET("/verify", web.VerifyEmailBlock)
router.Any("/create-checkout-session", Wrap(web.CreateCheckoutSessionBasic))
}
func Gowebadmin(domain string, db Database, stripe StripeConfig, auth Auth0, coll string, id string, verify string) *WebAdmin {
// Init Webpages
SetStripeKey(stripe.StripeKey)
if stripe.CustomEndpoints.SuccessUrl == "" {
stripe.CustomEndpoints.SuccessUrl = "/success"
}
if stripe.CustomEndpoints.CancelUrl == "" {
stripe.CustomEndpoints.CancelUrl = "/cancel"
}
if stripe.CustomEndpoints.ReturnUrl == "" {
stripe.CustomEndpoints.ReturnUrl = "/config"
}
if stripe.Pages.Checkout.File == "" {
stripe.Pages.Checkout.File = "checkout.html"
}
if stripe.Pages.Checkout.Path == "" {
stripe.Pages.Checkout.Path = "/checkout"
}
if stripe.Pages.Success.File == "" {
stripe.Pages.Success.File = "success.html"
}
if stripe.Pages.Success.Path == "" {
stripe.Pages.Success.Path = "/success"
}
if stripe.Pages.Cancel.File == "" {
stripe.Pages.Cancel.File = "cancel.html"
}
if stripe.Pages.Cancel.Path == "" {
stripe.Pages.Cancel.Path = "/cancel"
}
web := &WebAdmin{
domain,
coll,
db,
stripe,
auth,
id,
verify,
}
web.InitStripeCheckout()
return web
}
func (web *WebAdmin) AddCustomer() {
}
func (web *WebAdmin) Validate() {
}