forked from lonng/nanoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
69 lines (54 loc) · 1.43 KB
/
test.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
package test
import (
"fmt"
"time"
"github.com/spf13/viper"
"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/yxsdk"
"github.com/lonnng/nanoserver/db/model"
log "github.com/sirupsen/logrus"
)
type TestPay struct {
enablePayTest bool
}
func (tp *TestPay) CreateOrderResponse(order *model.Order) (interface{}, error) {
if !tp.enablePayTest {
return nil, errutil.YXErrPayTestDisable
}
log.Infof("order_info: %+v", order)
return protocol.CreateOrderSnakeResponse{
Result: "success",
PayPlatform: types.Test,
}, nil
}
func (tp *TestPay) Notify(request interface{}) (*model.Trade, interface{}, error) {
order, ok := request.(*model.Order)
if !ok {
return nil, nil, errutil.YXErrWrongType
}
t := time.Now().Unix()
trade := &model.Trade{
OrderId: order.OrderId,
PayOrderId: order.OrderId,
PayPlatform: types.Test,
PayCreateAt: t,
PayAt: t,
ComsumerId: fmt.Sprintf("%d", order.Uid),
MerchantId: types.Test,
}
return trade, protocol.SuccessResponse, nil
}
func (tp *TestPay) Setup() error {
log.Info("pay_provider: test")
tp.enablePayTest = viper.GetBool("enable_pay_test")
log.Infof("enable_pay_test: %t", tp.enablePayTest)
if !tp.enablePayTest {
yxsdk.Remove(types.Test)
}
return nil
}
func init() {
yxsdk.Register(types.Test, &TestPay{})
}