-
Notifications
You must be signed in to change notification settings - Fork 12
/
environment.go
72 lines (61 loc) · 2.22 KB
/
environment.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
package adyen
import (
"errors"
"fmt"
)
// Environment allows clients to be configured for Testing
// and Production environments.
type Environment struct {
apiURL string
clientURL string
hppURL string
checkoutURL string
}
var (
errProdEnvValidation = errors.New("production requires random and company name fields as per https://docs.adyen.com/developers/api-reference/live-endpoints")
)
// Testing - instance of testing environment
var Testing = Environment{
apiURL: "https://pal-test.adyen.com/pal/servlet",
clientURL: "https://test.adyen.com/hpp/cse/js/",
hppURL: "https://test.adyen.com/hpp/",
checkoutURL: "https://checkout-test.adyen.com/services/PaymentSetupAndVerification",
}
// Production - instance of production environment
var Production = Environment{
apiURL: "https://%s-%s-pal-live.adyenpayments.com/pal/servlet",
clientURL: "https://live.adyen.com/hpp/cse/js/",
hppURL: "https://live.adyen.com/hpp/",
checkoutURL: "https://%s-%s-checkout-live.adyenpayments.com/services/PaymentSetupAndVerification",
}
// TestEnvironment returns test environment configuration.
func TestEnvironment() (e Environment) {
return Testing
}
// ProductionEnvironment returns production environment configuration.
func ProductionEnvironment(random, companyName string) (e Environment, err error) {
if random == "" || companyName == "" {
err = errProdEnvValidation
return
}
e = Production
e.apiURL = fmt.Sprintf(e.apiURL, random, companyName)
e.checkoutURL = fmt.Sprintf(e.checkoutURL, random, companyName)
return e, nil
}
// BaseURL returns api base url
func (e Environment) BaseURL(service string, version string) string {
return e.apiURL + "/" + service + "/" + version
}
// ClientURL returns Adyen Client URL to load external scripts
func (e Environment) ClientURL(clientID string) string {
return e.clientURL + clientID + ".shtml"
}
// HppURL returns Adyen HPP url to execute Hosted Payment Paged API requests
func (e Environment) HppURL(request string) string {
return e.hppURL + request + ".shtml"
}
// CheckoutURL returns the full URL to a Checkout API endpoint.
func (e Environment) CheckoutURL(service string, version string) string {
return e.checkoutURL + "/" + version + "/" + service
}