smobilpay.WithAccessSecret   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
nop 1
1
package smobilpay
2
3
import (
4
	"net/http"
5
	"strings"
6
	"time"
7
)
8
9
// Option is options for constructing a client
10
type Option interface {
11
	apply(config *clientConfig)
12
}
13
14
type clientOptionFunc func(config *clientConfig)
15
16
func (fn clientOptionFunc) apply(config *clientConfig) {
17
	fn(config)
18
}
19
20
// WithHTTPClient sets the underlying HTTP client used for API requests.
21
// By default, http.DefaultClient is used.
22
func WithHTTPClient(httpClient *http.Client) Option {
23
	return clientOptionFunc(func(config *clientConfig) {
24
		if httpClient != nil {
25
			config.httpClient = httpClient
26
		}
27
	})
28
}
29
30
// WithBaseURL set's the base url for the smobilpay API
31
func WithBaseURL(baseURL string) Option {
32
	return clientOptionFunc(func(config *clientConfig) {
33
		if baseURL != "" {
34
			config.baseURL = strings.TrimRight(baseURL, "/")
35
		}
36
	})
37
}
38
39
// WithAccessToken sets the access token for the smobilpay api
40
func WithAccessToken(accessToken string) Option {
41
	return clientOptionFunc(func(config *clientConfig) {
42
		config.accessToken = accessToken
43
	})
44
}
45
46
// WithAccessSecret sets the access secret for the smobilpay api
47
func WithAccessSecret(accessSecret string) Option {
48
	return clientOptionFunc(func(config *clientConfig) {
49
		config.accessSecret = accessSecret
50
	})
51
}
52
53
// WithCollectSyncVerifyInterval sets the interval for calling the `/verifytx` endpoint to check the status of pending transactions
54
func WithCollectSyncVerifyInterval(interval time.Duration) Option {
55
	return clientOptionFunc(func(config *clientConfig) {
56
		config.collectSyncVerifyInterval = interval
57
	})
58
}
59
60
// WithCollectSyncVerifyRetryCount sets the number of retries for calling the `/verifytx` endpoint to check the status of pending transactions
61
func WithCollectSyncVerifyRetryCount(retryCount uint) Option {
62
	return clientOptionFunc(func(config *clientConfig) {
63
		config.collectSyncVerifyRetryCount = retryCount
64
	})
65
}
66