forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment.go
68 lines (57 loc) · 1.62 KB
/
payment.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
65
66
67
68
package school
import (
"encoding/json"
"github.com/chenghonour/wechat-sdk/urls"
"github.com/chenghonour/wechat-sdk/wx"
)
type PaymentInfo struct {
StudentUserID string `json:"student_userid"`
TradeState int `json:"trade_state"`
TradeNO string `json:"trade_no"`
PayerParentUserID string `json:"payer_parent_userid"`
}
type ParamsPaymentGet struct {
PaymentID string `json:"payment_id"`
}
type ResultPaymentGet struct {
ProjectName string `json:"project_name"`
Amount int `json:"amount"`
PaymentResult []*PaymentInfo `json:"payment_result"`
}
// GetPaymentResult 获取学生付款结果
func GetPaymentResult(paymentID string, result *ResultPaymentGet) wx.Action {
params := &ParamsPaymentGet{
PaymentID: paymentID,
}
return wx.NewPostAction(urls.CorpSchoolGetPaymentResult,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsTradeGet struct {
PaymentID string `json:"payment_id"`
TradeNO string `json:"trade_no"`
}
type ResultTradeGet struct {
TransactionID string `json:"transaction_id"`
PayTime int64 `json:"pay_time"`
}
// GetTrade 获取订单详情
func GetTrade(paymentID, tradeNO string, result *ResultTradeGet) wx.Action {
params := &ParamsTradeGet{
PaymentID: paymentID,
TradeNO: tradeNO,
}
return wx.NewPostAction(urls.CorpSchoolGetTrade,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}