plugin/dctw/v1/api/direct/direct.go

60 lines
1.3 KiB
Go

package direct
import (
"context"
"encoding/json"
"gitea.cdlsxd.cn/sdk/plugin/dctw/v1/api"
"gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core"
"io/ioutil"
"net/http"
)
type Direct api.Service
const (
orderPath = "/internal/v1/recharge/create"
queryPath = "/internal/v1/recharge/query"
)
func (c *Direct) Order(ctx context.Context, request *Order) (*OrderResp, error) {
result, err := c.Request(ctx, request, orderPath)
if err != nil {
return nil, err
}
var response *OrderResp
if err = json.Unmarshal(result, &response); err != nil {
return nil, err
}
return response, nil
}
func (c *Direct) Query(ctx context.Context, request *Query) (*QueryResp, error) {
result, err := c.Request(ctx, request, queryPath)
if err != nil {
return nil, err
}
var response *QueryResp
if err = json.Unmarshal(result, &response); err != nil {
return nil, err
}
return response, nil
}
func (c *Direct) Notify(_ context.Context, httpRequest *http.Request) (*Notify, error) {
body, err := ioutil.ReadAll(httpRequest.Body)
if err != nil {
return nil, err
}
if err = c.VerifyDctW(httpRequest.Header.Get(core.SignKeyName), body); err != nil {
return nil, err
}
var response *Notify
if err = json.Unmarshal(body, &response); err != nil {
return nil, err
}
return response, err
}