|
1
|
|
|
package afrikpay |
|
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 afrikpay 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
|
|
|
// WithAPIKey sets the AfrikPay API Key |
|
39
|
|
|
func WithAPIKey(apiKey string) Option { |
|
40
|
|
|
return clientOptionFunc(func(config *clientConfig) { |
|
41
|
|
|
config.apiKey = apiKey |
|
42
|
|
|
}) |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// WithWalletUsername sets the AfrikPay wallet username |
|
46
|
|
|
func WithWalletUsername(walletUsername string) Option { |
|
47
|
|
|
return clientOptionFunc(func(config *clientConfig) { |
|
48
|
|
|
config.walletUsername = walletUsername |
|
49
|
|
|
}) |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// WithWalletPassword sets the AfrikPay wallet password |
|
53
|
|
|
func WithWalletPassword(walletPassword string) Option { |
|
54
|
|
|
return clientOptionFunc(func(config *clientConfig) { |
|
55
|
|
|
config.walletPassword = walletPassword |
|
56
|
|
|
}) |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// WithWalletPin sets the AfrikPay wallet pin |
|
60
|
|
|
func WithWalletPin(walletPin string) Option { |
|
61
|
|
|
return clientOptionFunc(func(config *clientConfig) { |
|
62
|
|
|
config.walletPin = walletPin |
|
63
|
|
|
}) |
|
64
|
|
|
} |
|
65
|
|
|
|