This repository was archived by the owner on Mar 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhook.go
More file actions
91 lines (78 loc) · 2.01 KB
/
hook.go
File metadata and controls
91 lines (78 loc) · 2.01 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package themap
import (
"net/url"
"strconv"
)
// type NotifyType uint8
//
// const (
// AddCard NotifyType = iota
// Block
// Charged
// Void
// )
// Notify holds notification payload
type Notify struct {
MerchantContract string
OriginalOrderId string
MerchantOrderId string
Amount int
AuthCode string
RRN string
Success bool
CardNumber string
BankName string
ErrCode string
State string
Type string
CardUID string
CustomParams string
FeePercent float32
TerminalID int
Signature string
}
// NewNotify returns Notify data from bytes
func NewNotify(payload, signkey string) (*Notify, error) {
var err error
p, err := url.ParseQuery(payload)
if err != nil {
return nil, err
}
notify := &Notify{MerchantContract: p.Get("MerchantContract"), OriginalOrderId: p.Get("OriginalOrderId"), MerchantOrderId: p.Get("MerchantOrderId"),
AuthCode: p.Get("AuthCode"), RRN: p.Get("RRN"), CardNumber: p.Get("CardNumber"), BankName: p.Get("BankName"), ErrCode: p.Get("ErrCode"),
State: p.Get("State"), Type: p.Get("Notification"), CardUID: p.Get("CardUId"), CustomParams: p.Get("CustomParams"), Signature: p.Get("Signature")}
if p.Get("Amount") != "" {
notify.Amount, err = strconv.Atoi(p.Get("Amount"))
if err != nil {
notify.Amount = 0
}
}
if p.Get("Success") != "" {
notify.Success, err = strconv.ParseBool(p.Get("Success"))
if err != nil {
notify.Success = false
}
}
if p.Get("FeePercent") != "" {
fee, err := strconv.ParseFloat(p.Get("FeePercent"), 32)
if err != nil {
notify.FeePercent = 0
} else {
notify.FeePercent = float32(fee)
}
}
if p.Get("TerminalID") != "" {
notify.TerminalID, err = strconv.Atoi(p.Get("TerminalID"))
if err != nil {
notify.TerminalID = 0
}
}
// Check signature
if notify.Signature != "" {
sig := NewSignature(signkey, notify.Signature)
if !sig.Verify(payload) {
err = ErrBadSignature
}
}
return notify, err
}