-
Notifications
You must be signed in to change notification settings - Fork 12
/
notification_test.go
139 lines (121 loc) · 3.81 KB
/
notification_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package adyen
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"strings"
"testing"
"time"
)
// TestNotificationRequest - test adyen notification JSON conversion
func TestNotificationRequest(t *testing.T) {
t.Parallel()
responseJSON := `
{
"live":"false",
"notificationItems":[
{
"NotificationRequestItem":{
"additionalData":{
"cardSummary":"7777",
"eci":"N\/A",
"shopperIP":"127.0.0.1",
"totalFraudScore":"10",
"expiryDate":"12\/2012",
"xid":"AAE=",
"billingAddress.street":"Nieuwezijds Voorburgwal",
"cavvAlgorithm":"N\/A",
"cardBin":"976543",
"extraCostsValue":"101",
"billingAddress.city":"Amsterdam",
"threeDAuthenticated":"false",
"alias":"H934380689410347",
"paymentMethodVariant":"visa",
"billingAddress.country":"NL",
"fraudCheck-6-ShopperIpUsage":"10",
"deviceType":"Other",
" NAME1 ":"VALUE1",
"authCode":"1234",
"cardHolderName":"J. De Tester",
"threeDOffered":"false",
"billingAddress.houseNumberOrName":"21 - 5",
"threeDOfferedResponse":"N\/A",
"NAME2":" VALUE2 ",
"billingAddress.postalCode":"1012RC",
"browserCode":"Other",
"cavv":"AAE=",
"issuerCountry":"unknown",
"threeDAuthenticatedResponse":"N\/A",
"aliasType":"Default",
"extraCostsCurrency":"EUR",
"captureDelayHours":"120"
},
"amount":{
"currency":"EUR",
"value":10100
},
"eventCode":"AUTHORISATION",
"eventDate":"2017-12-27T14:53:06+01:00",
"merchantAccountCode":"TestCOM148",
"merchantReference":"8313842560770001",
"operations":["CANCEL","CAPTURE","REFUND"],
"paymentMethod":"visa",
"pspReference":"test_AUTHORISATION_1",
"reason":"1234:7777:12\/2012",
"success":"true"
}
}
]
}
`
body := strings.NewReader(responseJSON)
resp := &http.Response{
Status: "OK 200",
StatusCode: 200,
ContentLength: int64(body.Len()),
Body: ioutil.NopCloser(body),
}
buf := new(bytes.Buffer)
if _, err := buf.ReadFrom(resp.Body); err != nil {
t.Error(err)
}
var notification NotificationRequest
if err := json.Unmarshal(buf.Bytes(), ¬ification); err != nil {
t.Error(err)
}
if notification.Live {
t.Errorf("Expected notification environment should not be live, %t given", notification.Live)
}
if len(notification.NotificationItems) != 1 {
t.Errorf("Expected to have only one notification element in a list, %d given", len(notification.NotificationItems))
}
item := notification.NotificationItems[0].NotificationRequestItem
if item.EventCode != "AUTHORISATION" {
t.Errorf("Expected to have AUTHORISATION event code, %s given", item.EventCode)
}
if item.EventDate.Format(time.RFC3339) != "2017-12-27T14:53:06+01:00" {
t.Errorf("Expected to have 2017-12-27T14:53:06+01:00 event date, %s given", item.EventDate.Format(time.RFC3339))
}
if item.MerchantAccountCode != "TestCOM148" {
t.Errorf("Expected to have TestCOM148 merchant account code, %s given", item.MerchantAccountCode)
}
if item.MerchantReference != "8313842560770001" {
t.Errorf("Expected to have 8313842560770001 merchant reference, %s given", item.MerchantReference)
}
if strings.Join(item.Operations, ",") != "CANCEL,CAPTURE,REFUND" {
t.Errorf("Expected to have CANCEL,CAPTURE,REFUND operations available, %s given", strings.Join(item.Operations, ","))
}
if item.PaymentMethod != "visa" {
t.Errorf("Expected to have visa payment, %s given", item.PaymentMethod)
}
if item.PspReference != "test_AUTHORISATION_1" {
t.Errorf("Expected to have test_AUTHORISATION_1 as pspRegerence, %s given", item.PspReference)
}
if item.Reason != "1234:7777:12/2012" {
t.Errorf("Expected to have 1234:7777:12/2012 reason, %s given", item.Reason)
}
if !item.Success {
t.Errorf("Expected to have successful notification, %t given", item.Success)
}
}