File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
components/public-api-server/pkg Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,15 @@ package server
6
6
7
7
import (
8
8
"fmt"
9
- "github.com/gitpod-io/gitpod/public-api/config"
10
9
"net/url"
11
10
11
+ "github.com/gitpod-io/gitpod/public-api/config"
12
+ "github.com/gorilla/handlers"
13
+
12
14
"github.com/gitpod-io/gitpod/common-go/baseserver"
13
15
"github.com/gitpod-io/gitpod/public-api-server/pkg/apiv1"
14
16
"github.com/gitpod-io/gitpod/public-api-server/pkg/proxy"
17
+ "github.com/gitpod-io/gitpod/public-api-server/pkg/webhooks"
15
18
v1 "github.com/gitpod-io/gitpod/public-api/v1"
16
19
"github.com/prometheus/client_golang/prometheus"
17
20
"github.com/sirupsen/logrus"
@@ -36,6 +39,10 @@ func Start(logger *logrus.Entry, cfg *config.Configuration) error {
36
39
return fmt .Errorf ("failed to initialize public api server: %w" , err )
37
40
}
38
41
42
+ srv .HTTPMux ().Handle ("/stripe/invoices/webhook" ,
43
+ handlers .ContentTypeHandler (webhooks .NewStripeWebhookHandler (), "application/json" ),
44
+ )
45
+
39
46
if registerErr := register (srv , gitpodAPI , registry ); registerErr != nil {
40
47
return fmt .Errorf ("failed to register services: %w" , registerErr )
41
48
}
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
+ // Licensed under the GNU Affero General Public License (AGPL).
3
+ // See License-AGPL.txt in the project root for license information.
4
+
5
+ package webhooks
6
+
7
+ import (
8
+ "encoding/json"
9
+ "fmt"
10
+ "net/http"
11
+
12
+ "github.com/gitpod-io/gitpod/common-go/log"
13
+ "github.com/stripe/stripe-go/v72"
14
+ )
15
+
16
+ type webhookHandler struct {}
17
+
18
+ func NewStripeWebhookHandler () * webhookHandler {
19
+ return & webhookHandler {}
20
+ }
21
+
22
+ func (h * webhookHandler ) ServeHTTP (w http.ResponseWriter , req * http.Request ) {
23
+ const maxBodyBytes = int64 (65536 )
24
+
25
+ req .Body = http .MaxBytesReader (w , req .Body , maxBodyBytes )
26
+
27
+ event := stripe.Event {}
28
+ err := json .NewDecoder (req .Body ).Decode (& event )
29
+ if err != nil {
30
+ log .WithError (err ).Error ("Stripe webhook error while parsing event payload" )
31
+ w .WriteHeader (http .StatusBadRequest )
32
+ return
33
+ }
34
+
35
+ // TODO: verify webhook signature.
36
+ // Conditional on there being a secret configured.
37
+
38
+ fmt .Fprintf (w , "event type: %s" , event .Type )
39
+ }
You can’t perform that action at this time.
0 commit comments