Skip to content

Commit 9a99e16

Browse files
committed
Add shopify webhook routes
1 parent da418c4 commit 9a99e16

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

auth/service/service/service.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/tidepool-org/platform/mailer"
99
"github.com/tidepool-org/platform/oura/customerio"
1010
"github.com/tidepool-org/platform/oura/jotform"
11+
"github.com/tidepool-org/platform/oura/shopify"
1112

1213
userClient "github.com/tidepool-org/platform/user/client"
1314

@@ -40,6 +41,8 @@ import (
4041
"github.com/tidepool-org/platform/errors"
4142
"github.com/tidepool-org/platform/events"
4243
jotformAPI "github.com/tidepool-org/platform/oura/jotform/api"
44+
shopifyAPI "github.com/tidepool-org/platform/oura/shopify/api"
45+
shopifyClient "github.com/tidepool-org/platform/oura/shopify/client"
4346

4447
"github.com/tidepool-org/platform/log"
4548
oauthProvider "github.com/tidepool-org/platform/oauth/provider"
@@ -305,7 +308,17 @@ func (s *Service) initializeRouter() error {
305308
return errors.Wrap(err, "unable to create user client")
306309
}
307310

308-
webhookProcessor, err := jotform.NewWebhookProcessor(jotformConfig, s.Logger(), s.consentService, customerIOClient, usrClient)
311+
shopifyConfig := shopify.ClientConfig{}
312+
if err := envconfig.Process("", &shopifyConfig); err != nil {
313+
return errors.Wrap(err, "unable to load shopify config")
314+
}
315+
316+
shopifyClnt, err := shopifyClient.New(context.Background(), shopifyConfig)
317+
if err != nil {
318+
return errors.Wrap(err, "unable to create shopify client")
319+
}
320+
321+
webhookProcessor, err := jotform.NewWebhookProcessor(jotformConfig, s.Logger(), s.consentService, customerIOClient, usrClient, shopifyClnt)
309322
if err != nil {
310323
return errors.Wrap(err, "unable to create jotform webhook processor")
311324
}
@@ -315,9 +328,19 @@ func (s *Service) initializeRouter() error {
315328
return errors.Wrap(err, "unable to create jotform router")
316329
}
317330

331+
fulfillmentEventCreatedProcessor, err := shopify.NewFulfillmentCreatedEventProcessor(s.Logger(), customerIOClient, shopifyClnt)
332+
if err != nil {
333+
return errors.Wrap(err, "unable to create fulfillment created event processor")
334+
}
335+
336+
shopifyRouter, err := shopifyAPI.NewRouter(fulfillmentEventCreatedProcessor)
337+
if err != nil {
338+
return errors.Wrap(err, "unable to create shopify router")
339+
}
340+
318341
s.Logger().Debug("Initializing routers")
319342

320-
if err = s.API().InitializeRouters(apiRouter, v1Router, consentV1Router, jotformRouter); err != nil {
343+
if err = s.API().InitializeRouters(apiRouter, v1Router, consentV1Router, jotformRouter, shopifyRouter); err != nil {
321344
return errors.Wrap(err, "unable to initialize routers")
322345
}
323346

oura/shopify/api/router.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ type Router struct {
1313
fulfillmentCreatedEventProcessor *shopify.FulfillmentCreatedEventProcessor
1414
}
1515

16-
func NewRouter() (*Router, error) {
17-
return &Router{}, nil
16+
func NewRouter(fulfillmentCreatedEventProcessor *shopify.FulfillmentCreatedEventProcessor) (*Router, error) {
17+
return &Router{
18+
fulfillmentCreatedEventProcessor: fulfillmentCreatedEventProcessor,
19+
}, nil
1820
}
1921

2022
func (r *Router) Routes() []*rest.Route {

oura/shopify/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package shopify
33
import "context"
44

55
type ClientConfig struct {
6-
StoreID string `envconfig:"TIDEPOOL_SHOPIFY_STORE_ID" required:"true"`
7-
ClientID string `envconfig:"TIDEPOOL_SHOPIFY_CLIENT_ID" required:"true"`
8-
ClientSecret string `envconfig:"TIDEPOOL_SHOPIFY_CLIENT_SECRET" required:"true"`
6+
StoreID string `envconfig:"TIDEPOOL_SHOPIFY_STORE_ID"`
7+
ClientID string `envconfig:"TIDEPOOL_SHOPIFY_CLIENT_ID"`
8+
ClientSecret string `envconfig:"TIDEPOOL_SHOPIFY_CLIENT_SECRET"`
99
}
1010

1111
//go:generate mockgen -source=client.go -destination=./test/client.go -package=test Client

oura/shopify/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type defaultClient struct {
1515
gql graphql.Client
1616
}
1717

18-
func NewClient(ctx context.Context, cfg shopify.ClientConfig) (shopify.Client, error) {
18+
func New(ctx context.Context, cfg shopify.ClientConfig) (shopify.Client, error) {
1919
oauthConfig := clientcredentials.Config{
2020
ClientID: cfg.ClientID,
2121
ClientSecret: cfg.ClientSecret,

0 commit comments

Comments
 (0)