-
Notifications
You must be signed in to change notification settings - Fork 152
/
refund.go
49 lines (37 loc) · 1.05 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
package notify
import (
"github.com/ArtisanCloud/PowerLibs/v2/http/response"
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/models"
"github.com/ArtisanCloud/PowerWeChat/v2/src/payment/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/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{}) (*response.HttpResponse, 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()
}