From 174050c2810a11457a723caf0363e7f966f72d7b Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Sun, 27 Oct 2024 14:36:57 +0800 Subject: [PATCH] partner --- unify/pay.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/unify/pay.go b/unify/pay.go index 0ea34a7..bc909a4 100644 --- a/unify/pay.go +++ b/unify/pay.go @@ -54,6 +54,33 @@ func (p *Pay) CreateOrder(order *CreateOrderReq) (map[string]interface{}, error) 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 { reqBody, _ := json.Marshal(data) @@ -99,6 +126,30 @@ func (p *Pay) GetOrder(outTradeNo string) (map[string]interface{}, error) { 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 { if outTradeNo == "" { errors.New("outTradeNo is nil") @@ -122,3 +173,27 @@ func (p *Pay) RefundOrder(outTradeNo, reason string) error { 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 +}