forked from zhutik/adyen-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature_test.go
74 lines (58 loc) · 2 KB
/
signature_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
package adyen
import (
"net/http"
"os"
"testing"
"github.com/google/go-querystring/query"
)
func TestSignatureCalculateSignature(t *testing.T) {
t.Parallel()
instance := getTestInstanceWithHPP()
req := DirectoryLookupRequest{
CurrencyCode: "EUR",
MerchantAccount: os.Getenv("ADYEN_ACCOUNT"),
ShipBeforeDate: "2015-11-31T13:42:40+1:00",
PaymentAmount: 1000,
SkinCode: os.Getenv("ADYEN_SKINCODE"),
MerchantReference: "DE-100100GMWJGS",
SessionsValidity: "2015-11-29T13:42:40+1:00",
}
err := req.CalculateSignature(instance)
if err != nil {
t.Fatal(err)
}
v, _ := query.Values(req)
// there is no automated way to verify full URL, cause adyen webpage require authenication first
// to debug request signature, print URL params, login to https://ca-test.adyen.com and follow full link below
url := "https://ca-test.adyen.com/ca/ca/skin/checkhmac.shtml" + "?" + v.Encode()
if _, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
t.Fatal(err)
}
}
func TestSignatureCalculateSignatureForSkipHppRequest(t *testing.T) {
t.Parallel()
instance := getTestInstanceWithHPP()
req := SkipHppRequest{
MerchantReference: "DE-100100GMWJGS",
PaymentAmount: 1000,
CurrencyCode: instance.Currency,
ShipBeforeDate: "2015-11-31T13:42:40+1:00",
SkinCode: os.Getenv("ADYEN_SKINCODE"),
MerchantAccount: os.Getenv("ADYEN_ACCOUNT"),
ShopperLocale: "en_GB",
SessionsValidity: "2015-11-29T13:42:40+1:00",
CountryCode: "NL",
BrandCode: "ideal",
}
err := req.CalculateSignature(instance)
if err != nil {
t.Fatal(err)
}
v, _ := query.Values(req)
// there is no automated way to verify full URL, cause adyen webpage require authenication first
// to debug request signature, print URL params, login to https://ca-test.adyen.com and follow full link below
url := "https://ca-test.adyen.com/ca/ca/skin/checkhmac.shtml" + "?" + v.Encode()
if _, err = http.NewRequest(http.MethodGet, url, nil); err != nil {
t.Fatal(err)
}
}