-
Notifications
You must be signed in to change notification settings - Fork 13
/
checkout.go
42 lines (33 loc) · 1.16 KB
/
checkout.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
package registry
import (
"errors"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/app"
"github.com/coretrix/hitrix/service/component/checkout"
"github.com/coretrix/hitrix/service/component/config"
"github.com/sarulabs/di"
"github.com/xorcare/pointer"
)
func ServiceDefinitionCheckout() *service.Definition {
return &service.Definition{
Name: service.CheckoutService,
Global: true,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
secretKey, ok := configService.String("checkout.secret_key")
if ok {
return nil, errors.New("missing checkout.secret_key key")
}
webhookSecrets, ok := configService.StringMap("checkout.webhook_keys")
if ok {
return nil, errors.New("missing checkout.webhook_keys key")
}
var publicKey *string
if publicKeyVal, ok := configService.String("checkout.public_key"); ok && publicKeyVal != "" {
publicKey = pointer.String(publicKeyVal)
}
appService := ctn.Get(service.AppService).(*app.App)
return checkout.NewCheckout(secretKey, publicKey, appService.Mode, webhookSecrets), nil
},
}
}