forked from checkout/checkout-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
59 lines (47 loc) · 1.44 KB
/
client.go
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
59
package ideal
import (
"context"
"github.com/PaddleHQ/checkout-sdk-go/client"
"github.com/PaddleHQ/checkout-sdk-go/common"
"github.com/PaddleHQ/checkout-sdk-go/configuration"
)
type Client struct {
configuration *configuration.Configuration
apiClient client.HttpClient
}
func NewClient(configuration *configuration.Configuration, apiClient client.HttpClient) *Client {
return &Client{
configuration: configuration,
apiClient: apiClient,
}
}
func (c *Client) GetInfo() (*IdealInfo, error) {
return c.GetInfoWithContext(context.Background())
}
func (c *Client) GetInfoWithContext(ctx context.Context) (*IdealInfo, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}
var response IdealInfo
err = c.apiClient.GetWithContext(ctx, common.BuildPath(idealExternalPath), auth, &response)
if err != nil {
return nil, err
}
return &response, nil
}
func (c *Client) GetIssuers() (*IssuerResponse, error) {
return c.GetIssuersWithContext(context.Background())
}
func (c *Client) GetIssuersWithContext(ctx context.Context) (*IssuerResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
if err != nil {
return nil, err
}
var response IssuerResponse
err = c.apiClient.GetWithContext(ctx, common.BuildPath(idealExternalPath, issuersPath), auth, &response)
if err != nil {
return nil, err
}
return &response, nil
}