-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
58 lines (45 loc) · 1.38 KB
/
client.go
File metadata and controls
58 lines (45 loc) · 1.38 KB
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
package revolut
import (
"net/url"
revolut_business "github.com/jerethom/revolut-api-go/business"
"github.com/jerethom/revolut-api-go/constants"
revolut_merchant "github.com/jerethom/revolut-api-go/merchant/1.0"
"github.com/jerethom/revolut-api-go/shared"
)
type Client struct {
privateKey string
apiVersion constants.RevolutApiVersion
url *url.URL
isSandbox bool
Merchant *revolut_merchant.Merchant
Business *revolut_business.Business
}
type ClientOption func(client *Client)
func WithApiVersion(version constants.RevolutApiVersion) ClientOption {
return func(client *Client) {
client.apiVersion = version
}
}
func WithIsSandbox(sandbox bool) ClientOption {
return func(client *Client) {
client.isSandbox = sandbox
}
}
func NewClient(privateKey string, options ...ClientOption) *Client {
client := &Client{privateKey: privateKey}
for _, option := range options {
option(client)
}
if client.apiVersion == "" {
client.apiVersion = constants.RevolutApiVersionLatest
}
if client.isSandbox {
client.url, _ = url.Parse(constants.DefaultMerchantSandboxApiUrl)
} else {
client.url, _ = url.Parse(constants.DefaultMerchantApiUrl)
}
clientRequest := shared.NewClientRequest(client.privateKey, client.apiVersion, client.url)
client.Merchant = revolut_merchant.NewMerchant(clientRequest)
client.Business = revolut_business.NewBusiness(clientRequest)
return client
}