1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
// Config contains information that helps during the setup of a new Mollie client. |
4
|
|
|
type Config struct { |
5
|
|
|
testing bool |
6
|
|
|
auth string |
7
|
|
|
reqIdempotency bool |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
// ToggleTesting enables/disables the test-mode in the current Config. |
11
|
|
|
func (c *Config) ToggleTesting() bool { |
12
|
1 |
|
c.testing = !c.testing |
13
|
|
|
|
14
|
1 |
|
return c.testing |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
// ToggleIdempotency enables/disables the request idempotency feature |
18
|
|
|
// in the current Config. |
19
|
|
|
func (c *Config) ToggleIdempotency() bool { |
20
|
1 |
|
c.reqIdempotency = !c.reqIdempotency |
21
|
|
|
|
22
|
1 |
|
return c.reqIdempotency |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
// SwitchAuthStrategy changes the environment variable used to fetch the |
26
|
|
|
// auth tokens. |
27
|
|
|
// |
28
|
|
|
// Known values are: [MOLLIE_API_TOKEN,MOLLIE_ORG_TOKEN], if you use a custom |
29
|
|
|
// environment variable pass it as argument. |
30
|
|
|
func (c *Config) SwitchAuthStrategy(auth string) string { |
31
|
1 |
|
c.auth = auth |
32
|
|
|
|
33
|
1 |
|
return c.auth |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/* Configuration init helpers. */ |
37
|
|
|
|
38
|
|
|
// NewConfig builds a Mollie configuration object, |
39
|
|
|
// it takes t to indicate if our client is meant to create requests for testing, |
40
|
|
|
// and auth to indicate the authentication method we want to use. |
41
|
|
|
func NewConfig(t bool, auth string) *Config { |
42
|
1 |
|
return createConfig(t, false, auth) |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// NewAPITestingConfig builds a configuration object with the following settings: |
46
|
|
|
// tests mode: enabled |
47
|
|
|
// api token source: MOLLIE_API_TOKEN |
48
|
|
|
// |
49
|
|
|
// it receives `reqIdem (boolean)` to enable the request idempotency feature. |
50
|
|
|
func NewAPITestingConfig(reqIdem bool) *Config { |
51
|
1 |
|
return createConfig(true, reqIdem, APITokenEnv) |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// NewAPIConfig builds a configuration object with the following settings: |
55
|
|
|
// tests mode: disabled |
56
|
|
|
// api token source: MOLLIE_API_TOKEN |
57
|
|
|
// |
58
|
|
|
// it receives `reqIdem (boolean)` to enable the request idempotency feature. |
59
|
|
|
func NewAPIConfig(reqIdem bool) *Config { |
60
|
1 |
|
return createConfig(false, reqIdem, APITokenEnv) |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// NewOrgTestingConfig builds a configuration object with the following settings: |
64
|
|
|
// tests mode: enabled |
65
|
|
|
// api token source: MOLLIE_ORG_TOKEN |
66
|
|
|
// |
67
|
|
|
// it receives `reqIdem (boolean)` to enable the request idempotency feature. |
68
|
|
|
func NewOrgTestingConfig(reqIdem bool) *Config { |
69
|
1 |
|
return createConfig(true, reqIdem, OrgTokenEnv) |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// NewOrgConfig builds a configuration object with the following settings: |
73
|
|
|
// tests mode: disabled |
74
|
|
|
// Org token source: MOLLIE_ORG_TOKEN |
75
|
|
|
// |
76
|
|
|
// it receives `reqIdem (boolean)` to enable the request idempotency feature. |
77
|
|
|
func NewOrgConfig(reqIdem bool) *Config { |
78
|
1 |
|
return createConfig(false, reqIdem, OrgTokenEnv) |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
func createConfig(test, reqIdem bool, auth string) *Config { |
82
|
1 |
|
return &Config{ |
83
|
|
|
testing: test, |
84
|
|
|
auth: auth, |
85
|
|
|
reqIdempotency: reqIdem, |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|