forked from zhutik/adyen-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment_gateway_test.go
142 lines (115 loc) · 3.8 KB
/
payment_gateway_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
140
141
142
package adyen
import (
"os"
"strings"
"testing"
"time"
)
// TestAuthoriseFailed
func TestAuthoriseFailed(t *testing.T) {
t.Parallel()
instance := getTestInstance()
authRequest := &Authorise{
Card: &Card{
Number: "4111111111111111",
ExpireMonth: "08",
ExpireYear: "2018",
Cvc: "737",
HolderName: "John Smith",
},
Amount: &Amount{
Value: 1000,
Currency: "EUR",
},
Reference: "",
MerchantAccount: os.Getenv("ADYEN_ACCOUNT"),
}
_, err := instance.Payment().Authorise(authRequest)
if err == nil {
t.Error("Request should fail, due to missing reference error")
}
if !strings.Contains(err.Error(), "Reference Missing") {
t.Errorf("Response should contain missing reference error, response - %s", err.Error())
}
}
// TestAuthorise
//
// In order to have test running correctly, account should be configured to have full API permissions
// Otherwise, Adyen API will return "not allowed" error. Please check https://github.com/Adyen/adyen-php-api-library/issues/20
func TestAuthorise(t *testing.T) {
t.Parallel()
instance := getTestInstance()
authRequest := &Authorise{
Card: &Card{
Number: "4111111111111111",
ExpireMonth: "08",
ExpireYear: "2018",
Cvc: "737",
HolderName: "John Smith",
},
Amount: &Amount{
Value: 1000,
Currency: "EUR",
},
Reference: "DE-TEST-1" + randomString(10),
MerchantAccount: os.Getenv("ADYEN_ACCOUNT"),
}
response, err := instance.Payment().Authorise(authRequest)
knownError, ok := err.(APIError)
if ok {
t.Errorf("Response should be succesfull. Known API Error: Code - %s, Message - %s, Type - %s", knownError.ErrorCode, knownError.Message, knownError.ErrorType)
}
if err != nil {
t.Errorf("Response should be succesfull, error - %s", err.Error())
}
if response.PspReference == "" {
t.Errorf("Response should contain PSP Reference. Response - %s", response)
}
if response.ResultCode != "Authorised" {
t.Errorf("Response resultCode should be Authorised, Response - %s", response)
}
}
// TestDirectoryLookUpMissingData - DirectoryLookUp Request failing due to missing data
func TestDirectoryLookUpMissingData(t *testing.T) {
t.Parallel()
instance := getTestInstance()
timeIn := time.Now().Local().Add(time.Minute * time.Duration(60))
directoryRequest := &DirectoryLookupRequest{
CurrencyCode: "EUR",
PaymentAmount: 1000,
MerchantReference: "DE-TEST-1" + randomString(10),
SessionsValidity: timeIn.Format(time.RFC3339),
CountryCode: "NL",
}
_, err := instance.Payment().DirectoryLookup(directoryRequest)
if err == nil {
t.Error("Request should fail due to missing request data")
}
if err.Error() != "merchantID, skinCode and HMAC hash need to be specified" {
t.Errorf("Error should indicate that request is missing configuration data, error - %s", err)
}
}
// TestDirectoryLookUp - test directory lookup v2 integration
//
// In order to have test running correctly, Adyen Skin need to be configured and passed through environment variable
func TestDirectoryLookUp(t *testing.T) {
t.Parallel()
instance := getTestInstanceWithHPP()
timeIn := time.Now().Local().Add(time.Minute * time.Duration(60))
directoryRequest := &DirectoryLookupRequest{
CurrencyCode: "EUR",
MerchantAccount: os.Getenv("ADYEN_ACCOUNT"),
PaymentAmount: 1000,
SkinCode: os.Getenv("ADYEN_SKINCODE"),
MerchantReference: "DE-TEST-1" + randomString(10),
SessionsValidity: timeIn.Format(time.RFC3339),
CountryCode: "NL",
}
response, err := instance.Payment().DirectoryLookup(directoryRequest)
if err != nil {
t.Errorf("DirectoryLookup response should be successful, error - %s", err)
}
if len(response.PaymentMethods) == 0 {
t.Errorf("DirectoryLookup response should contain at least one payment method available, response - %s", response)
}
}