forked from lonng/nanoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yxsdk.go
55 lines (44 loc) · 1.31 KB
/
yxsdk.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
package yxsdk
import (
"github.com/go-kit/kit/log"
"github.com/lonnng/nanoserver/internal/errutil"
"github.com/lonnng/nanoserver/internal/protocol"
"github.com/lonnng/nanoserver/internal/types"
"github.com/lonnng/nanoserver/cmd/mahjong/web/provider"
"github.com/lonnng/nanoserver/db/model"
)
type yxSDKProvider struct {
provider.Base
logger log.Logger
}
func (s *yxSDKProvider) CreateOrderResponse(order *model.Order) (interface{}, error) {
p := pm.provider(order.PayPlatform)
if p == nil {
s.logger.Log("err", errutil.YXErrInvalidPayPlatform.Error())
return nil, errutil.YXErrInvalidPayPlatform
}
return p.CreateOrderResponse(order)
}
func (s *yxSDKProvider) Notify(request interface{}) (*model.Trade, interface{}, error) {
r, ok := request.(*protocol.UnifyOrderCallbackRequest)
if !ok {
return nil, nil, errutil.YXErrWrongType
}
p := pm.provider(r.PayPlatform)
if p == nil {
s.logger.Log("err", errutil.YXErrInvalidPayPlatform.Error())
return nil, nil, errutil.YXErrInvalidPayPlatform
}
return p.Notify(r.RawRequest)
}
func (s *yxSDKProvider) Setup(logger log.Logger) error {
s.logger = log.NewContext(logger).With("provider", "yxsdk")
if err := pm.setup(logger); err != nil {
panic(err)
}
s.logger.Log("msg", "running")
return nil
}
func init() {
provider.Register(types.YX, &yxSDKProvider{})
}