-
Notifications
You must be signed in to change notification settings - Fork 158
/
paid.go
48 lines (36 loc) · 1.01 KB
/
paid.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 Paid struct {
*Handler
}
func NewPaidNotify(app kernel.ApplicationPaymentInterface, request *http.Request) *Paid {
paid := &Paid{
NewHandler(app, request),
}
return paid
}
func (comp *Paid) Handle(closure func(message *request.RequestNotify, transaction *models.Transaction, 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
transaction := &models.Transaction{}
err = object.JsonDecode([]byte(reqInfo), transaction)
if err != nil {
return nil, err
}
result := closure(message, transaction, comp.Fail)
comp.Strict(result)
return comp.ToResponse()
}