-
Notifications
You must be signed in to change notification settings - Fork 146
/
client.go
58 lines (44 loc) · 1.53 KB
/
client.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
package refund
import (
"context"
"fmt"
"github.com/ArtisanCloud/PowerLibs/v3/object"
payment "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/refund/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/refund/response"
"net/http"
)
type Client struct {
*payment.BaseClient
}
func NewClient(app *payment.ApplicationPaymentInterface) (*Client, error) {
baseClient, err := payment.NewBaseClient(app)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// Refund.
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
func (comp *Client) Refund(ctx context.Context, options *request.RequestRefund) (*response.ResponseRefund, error) {
result := &response.ResponseRefund{}
//body, err := object.StructToHashMapWithTag(options, "json")
body, err := object.StructToHashMap(options)
if err != nil {
return nil, err
}
endpoint := comp.Wrap("/v3/refund/domestic/refunds")
_, err = comp.PlainRequest(ctx, endpoint, nil, http.MethodPost, body, false, nil, result)
return result, err
}
// Query Refund.
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml
func (comp *Client) Query(ctx context.Context, refundOutNO string) (*response.ResponseRefund, error) {
result := &response.ResponseRefund{}
endpoint := fmt.Sprintf("/v3/refund/domestic/refunds/%s", refundOutNO)
endpoint = comp.Wrap(endpoint)
_, err := comp.Request(ctx, endpoint, nil, http.MethodGet, &object.HashMap{}, false, nil, result)
return result, err
}