-
Notifications
You must be signed in to change notification settings - Fork 156
/
client.go
56 lines (43 loc) · 1.56 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
package reverse
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
payment "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/reverse/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
}
// Reverse order.
// https://pay.weixin.qq.com/wiki/doc/api/micropa
func (comp *Client) Reverse(ctx context.Context, number string, reverseType string) (*response.ResponseReserve, error) {
result := &response.ResponseReserve{}
config := (*comp.App).GetConfig()
params := &object.HashMap{
"appid": config.GetString("app_id", ""),
reverseType: number,
}
endpoint := comp.Wrap("secapi/pay/reverse")
_, err := comp.Request(ctx, endpoint, nil, http.MethodPost, params, false, nil, result)
return result, err
}
// Reverse order by out trade number.
// https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_11&index=3
func (comp *Client) ByOutTradeNumber(ctx context.Context, outTradeNumber string) (*response.ResponseReserve, error) {
return comp.Reverse(ctx, outTradeNumber, "out_trade_no")
}
// Reverse order by transaction_id.
// https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_11&index=3
func (comp *Client) ByTransactionId(ctx context.Context, transactionID string) (*response.ResponseReserve, error) {
return comp.Reverse(ctx, transactionID, "transaction_id")
}