-
Notifications
You must be signed in to change notification settings - Fork 149
/
refund.go
48 lines (36 loc) · 1017 Bytes
/
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
package notify
import (
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/models"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/notify/request"
"net/http"
)
type Refund struct {
*Handler
}
func NewRefundNotify(app kernel.ApplicationPaymentInterface, request *http.Request) *Refund {
paid := &Refund{
NewHandler(app, request),
}
return paid
}
func (comp *Refund) Handle(closure func(message *request.RequestNotify, refund *models.Refund, fail func(message string)) interface{}) (*http.Response, error) {
message, err := comp.GetMessage()
if err != nil {
return nil, err
}
reqInfo, err := comp.reqInfo()
if err != nil {
return nil, err
}
// struct the content
refund := &models.Refund{}
err = object.JsonDecode([]byte(reqInfo), refund)
if err != nil {
return nil, err
}
result := closure(message, refund, comp.Fail)
comp.Strict(result)
return comp.ToResponse()
}