This commit is contained in:
jiangyong27 2024-10-27 14:36:57 +08:00
parent fcf2ba32fc
commit 174050c281
1 changed files with 75 additions and 0 deletions

View File

@ -54,6 +54,33 @@ func (p *Pay) CreateOrder(order *CreateOrderReq) (map[string]interface{}, error)
return rsp.Data, nil return rsp.Data, nil
} }
func (p *Pay) CreatePartnerOrder(order *CreateOrderReq) (map[string]interface{}, error) {
if order.PayType == "" {
errors.New("payType is nil")
}
if order.PayPrice <= 0 {
return nil, errors.New("payPrice is nil")
}
reqBody, _ := json.Marshal(order)
result, err := util.HttpPostJson(p.address+"/api/pay/partner/order", map[string]string{
"x-token": p.token,
}, reqBody)
if err != nil {
return nil, err
}
var rsp CommonResponse
if err := json.Unmarshal([]byte(result), &rsp); err != nil {
return nil, err
}
if rsp.Code != 0 {
return nil, fmt.Errorf("%d:%s", rsp.Code, rsp.Message)
}
return rsp.Data, nil
}
func (p *Pay) UpdateOrder(data map[string]interface{}) error { func (p *Pay) UpdateOrder(data map[string]interface{}) error {
reqBody, _ := json.Marshal(data) reqBody, _ := json.Marshal(data)
@ -99,6 +126,30 @@ func (p *Pay) GetOrder(outTradeNo string) (map[string]interface{}, error) {
return rsp.Data, nil return rsp.Data, nil
} }
func (p *Pay) GetPartnerOrder(outTradeNo string) (map[string]interface{}, error) {
if outTradeNo == "" {
errors.New("outTradeNo is nil")
}
reqUrl := fmt.Sprintf("%s/api/pay/partner/order?outTradeNo=%s", p.address, outTradeNo)
result, err := util.HttpGet(reqUrl, map[string]string{
"x-token": p.token,
})
if err != nil {
return nil, err
}
var rsp CommonResponse
if err := json.Unmarshal([]byte(result), &rsp); err != nil {
return nil, err
}
if rsp.Code != 0 {
return nil, fmt.Errorf("%d:%s", rsp.Code, rsp.Message)
}
return rsp.Data, nil
}
func (p *Pay) RefundOrder(outTradeNo, reason string) error { func (p *Pay) RefundOrder(outTradeNo, reason string) error {
if outTradeNo == "" { if outTradeNo == "" {
errors.New("outTradeNo is nil") errors.New("outTradeNo is nil")
@ -122,3 +173,27 @@ func (p *Pay) RefundOrder(outTradeNo, reason string) error {
return nil return nil
} }
func (p *Pay) RefundPartnerOrder(outTradeNo, reason string) error {
if outTradeNo == "" {
errors.New("outTradeNo is nil")
}
reqUrl := fmt.Sprintf("%s/api/pay/partner/order?outTradeNo=%s&reason=%s", p.address, outTradeNo, reason)
result, err := util.HttpDelete(reqUrl, map[string]string{
"x-token": p.token,
})
if err != nil {
return err
}
var rsp CommonResponse
if err := json.Unmarshal([]byte(result), &rsp); err != nil {
return err
}
if rsp.Code != 0 {
return fmt.Errorf("%d:%s", rsp.Code, rsp.Message)
}
return nil
}