forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refund.go
64 lines (58 loc) · 1.89 KB
/
refund.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
package wechat
import (
"encoding/json"
"fmt"
"net/http"
"github.com/cedarwu/gopay"
)
// 申请退款API
// Code = 0 is success
// 商户文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_9.shtml
func (c *ClientV3) V3Refund(bm gopay.BodyMap) (wxRsp *RefundRsp, err error) {
authorization, err := c.authorization(MethodPost, v3DomesticRefund, bm)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdPost(bm, v3DomesticRefund, authorization)
if err != nil {
return nil, err
}
wxRsp = &RefundRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(RefundOrderResponse)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}
// 查询单笔退款API
// Code = 0 is success
// 商户文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml
// 服务商文档:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_10.shtml
func (c *ClientV3) V3RefundQuery(outRefundNo string) (wxRsp *RefundQueryRsp, err error) {
uri := fmt.Sprintf(v3DomesticRefundQuery, outRefundNo)
authorization, err := c.authorization(MethodGet, uri, nil)
if err != nil {
return nil, err
}
res, si, bs, err := c.doProdGet(uri, authorization)
if err != nil {
return nil, err
}
wxRsp = &RefundQueryRsp{Code: Success, SignInfo: si}
wxRsp.Response = new(RefundQueryResponse)
if err = json.Unmarshal(bs, wxRsp.Response); err != nil {
return nil, fmt.Errorf("json.Unmarshal(%s):%w", string(bs), err)
}
if res.StatusCode != http.StatusOK {
wxRsp.Code = res.StatusCode
wxRsp.Error = string(bs)
return wxRsp, nil
}
return wxRsp, c.verifySyncSign(si)
}