Test Setup Failed
Push — main ( 273289...2d1dd5 )
by Acho
02:18
created

mtnmomo.WithAPIKey   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
package mtnmomo
2
3
import (
4
	"net/http"
5
	"strings"
6
)
7
8
// Option is options for constructing a client
9
type Option interface {
10
	apply(config *clientConfig)
11
}
12
13
type clientOptionFunc func(config *clientConfig)
14
15
func (fn clientOptionFunc) apply(config *clientConfig) {
16
	fn(config)
17
}
18
19
// WithHTTPClient sets the underlying HTTP client used for API requests.
20
// By default, http.DefaultClient is used.
21
func WithHTTPClient(httpClient *http.Client) Option {
22
	return clientOptionFunc(func(config *clientConfig) {
23
		if httpClient != nil {
24
			config.httpClient = httpClient
25
		}
26
	})
27
}
28
29
// WithBaseURL set's the base url for the flutterwave API
30
func WithBaseURL(baseURL string) Option {
31
	return clientOptionFunc(func(config *clientConfig) {
32
		if baseURL != "" {
33
			config.baseURL = strings.TrimRight(baseURL, "/")
34
		}
35
	})
36
}
37
38
// WithSubscriptionKey sets the delay in milliseconds before a response is gotten.
39
func WithSubscriptionKey(subscriptionKey string) Option {
40
	return clientOptionFunc(func(config *clientConfig) {
41
		config.subscriptionKey = subscriptionKey
42
	})
43
}
44
45
// WithTargetEnvironment sets the identifier of the EWP system where the transaction shall be processed.
46
func WithTargetEnvironment(targetEnvironment string) Option {
47
	return clientOptionFunc(func(config *clientConfig) {
48
		config.targetEnvironment = targetEnvironment
49
	})
50
}
51
52
// WithAPIUser sets the API user.
53
func WithAPIUser(apiUser string) Option {
54
	return clientOptionFunc(func(config *clientConfig) {
55
		config.apiUser = apiUser
56
	})
57
}
58
59
// WithAPIKey sets the API key.
60
func WithAPIKey(apiKey string) Option {
61
	return clientOptionFunc(func(config *clientConfig) {
62
		config.apiKey = apiKey
63
	})
64
}
65