feat: add wechat pay
This commit is contained in:
48
backend/providers/pay/provider.go
Normal file
48
backend/providers/pay/provider.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"backend/providers/app"
|
||||
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||
"github.com/go-pay/gopay"
|
||||
"github.com/go-pay/gopay/wechat/v3"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
o := opt.New(opts...)
|
||||
var config Config
|
||||
if err := o.UnmarshalConfig(&config); err != nil {
|
||||
return err
|
||||
}
|
||||
return container.Container.Provide(func(app *app.Config) (*Client, error) {
|
||||
wechatPay, err := wechat.NewClientV3(
|
||||
config.WeChat.MechID,
|
||||
config.WeChat.SerialNo,
|
||||
config.WeChat.ApiV3Key,
|
||||
config.WeChat.PrivateKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := wechatPay.AutoVerifySign(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if app.IsDevMode() {
|
||||
wechatPay.DebugSwitch = gopay.DebugOn
|
||||
}
|
||||
|
||||
return &Client{
|
||||
conf: &config,
|
||||
WeChat: wechatPay,
|
||||
}, nil
|
||||
}, o.DiOptions()...)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
conf *Config
|
||||
|
||||
WeChat *wechat.ClientV3
|
||||
}
|
||||
Reference in New Issue
Block a user