Skip to content

Commit 3647be0

Browse files
Add context to missing clients and update tests
1 parent e0cc3da commit 3647be0

28 files changed

+868
-230
lines changed

accounts/client.go

Lines changed: 143 additions & 59 deletions
Large diffs are not rendered by default.

accounts/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ func TestGetSubEntityMembers(t *testing.T) {
165165
Return(&configuration.SdkAuthorization{}, nil)
166166
},
167167
apiGet: func(m *mock.Mock) mock.Call {
168-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
168+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
169169
Return(nil).
170170
Run(func(args mock.Arguments) {
171-
respMapping := args.Get(2).(*OnboardSubEntityDetailsResponse)
171+
respMapping := args.Get(3).(*OnboardSubEntityDetailsResponse)
172172
*respMapping = subEntityDetails
173173
})
174174
},

balances/client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package balances
22

33
import (
4+
"context"
45
"github.com/checkout/checkout-sdk-go/client"
56
"github.com/checkout/checkout-sdk-go/common"
67
"github.com/checkout/checkout-sdk-go/configuration"
@@ -19,6 +20,14 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http
1920
}
2021

2122
func (c *Client) RetrieveEntityBalances(entityId string, query QueryFilter) (*QueryResponse, error) {
23+
return c.RetrieveEntityBalancesWithContext(context.Background(), entityId, query)
24+
}
25+
26+
func (c *Client) RetrieveEntityBalancesWithContext(
27+
ctx context.Context,
28+
entityId string,
29+
query QueryFilter,
30+
) (*QueryResponse, error) {
2231
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
2332
if err != nil {
2433
return nil, err
@@ -30,7 +39,8 @@ func (c *Client) RetrieveEntityBalances(entityId string, query QueryFilter) (*Qu
3039
}
3140

3241
var response QueryResponse
33-
err = c.apiClient.Get(
42+
err = c.apiClient.GetWithContext(
43+
ctx,
3444
url,
3545
auth,
3646
&response,

disputes/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ func TestGetCompiledSubmittedEvidence(t *testing.T) {
672672
Return(&configuration.SdkAuthorization{}, nil)
673673
},
674674
apiGet: func(m *mock.Mock) mock.Call {
675-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
675+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
676676
Return(nil).
677677
Run(func(args mock.Arguments) {
678-
respMapping := args.Get(2).(*DisputeCompiledSubmittedEvidenceResponse)
678+
respMapping := args.Get(3).(*DisputeCompiledSubmittedEvidenceResponse)
679679
*respMapping = compiledSubmittedEvidenceResponse
680680
})
681681
},
@@ -713,7 +713,7 @@ func TestGetCompiledSubmittedEvidence(t *testing.T) {
713713
Return(&configuration.SdkAuthorization{}, nil)
714714
},
715715
apiGet: func(m *mock.Mock) mock.Call {
716-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
716+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
717717
Return(
718718
errors.CheckoutAPIError{
719719
StatusCode: http.StatusNotFound,

financial/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package financial
22

33
import (
4+
"context"
5+
46
"github.com/checkout/checkout-sdk-go/client"
57
"github.com/checkout/checkout-sdk-go/common"
68
"github.com/checkout/checkout-sdk-go/configuration"
@@ -19,6 +21,10 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http
1921
}
2022

2123
func (c *Client) GetFinancialActions(query QueryFilter) (*QueryResponse, error) {
24+
return c.GetFinancialActionsWithContext(context.Background(), query)
25+
}
26+
27+
func (c *Client) GetFinancialActionsWithContext(ctx context.Context, query QueryFilter) (*QueryResponse, error) {
2228
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
2329
if err != nil {
2430
return nil, err
@@ -30,7 +36,8 @@ func (c *Client) GetFinancialActions(query QueryFilter) (*QueryResponse, error)
3036
}
3137

3238
var response QueryResponse
33-
err = c.apiClient.Get(
39+
err = c.apiClient.GetWithContext(
40+
ctx,
3441
url,
3542
auth,
3643
&response,

forex/client.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package forex
22

33
import (
4+
"context"
5+
46
"github.com/checkout/checkout-sdk-go/client"
57
"github.com/checkout/checkout-sdk-go/common"
68
"github.com/checkout/checkout-sdk-go/configuration"
@@ -19,13 +21,24 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http
1921
}
2022

2123
func (c *Client) RequestQuote(request QuoteRequest) (*QuoteResponse, error) {
24+
return c.RequestQuoteWithContext(context.Background(), request)
25+
}
26+
27+
func (c *Client) RequestQuoteWithContext(ctx context.Context, request QuoteRequest) (*QuoteResponse, error) {
2228
auth, err := c.configuration.Credentials.GetAuthorization(configuration.OAuth)
2329
if err != nil {
2430
return nil, err
2531
}
2632

2733
var response QuoteResponse
28-
err = c.apiClient.Post(common.BuildPath(forex, quotes), auth, request, &response, nil)
34+
err = c.apiClient.PostWithContext(
35+
ctx,
36+
common.BuildPath(forex, quotes),
37+
auth,
38+
request,
39+
&response,
40+
nil,
41+
)
2942
if err != nil {
3043
return nil, err
3144
}
@@ -34,6 +47,10 @@ func (c *Client) RequestQuote(request QuoteRequest) (*QuoteResponse, error) {
3447
}
3548

3649
func (c *Client) GetRates(queryFilter RatesQuery) (*RatesResponse, error) {
50+
return c.GetRatesWithContext(context.Background(), queryFilter)
51+
}
52+
53+
func (c *Client) GetRatesWithContext(ctx context.Context, queryFilter RatesQuery) (*RatesResponse, error) {
3754
auth, err := c.configuration.Credentials.GetAuthorization(configuration.OAuth)
3855
if err != nil {
3956
return nil, err
@@ -45,7 +62,7 @@ func (c *Client) GetRates(queryFilter RatesQuery) (*RatesResponse, error) {
4562
}
4663

4764
var response RatesResponse
48-
err = c.apiClient.Get(url, auth, &response)
65+
err = c.apiClient.GetWithContext(ctx, url, auth, &response)
4966
if err != nil {
5067
return nil, err
5168
}

instruments/nas/client.go

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package nas
22

33
import (
4+
"context"
5+
46
"github.com/checkout/checkout-sdk-go/client"
57
"github.com/checkout/checkout-sdk-go/common"
68
"github.com/checkout/checkout-sdk-go/configuration"
@@ -20,19 +22,20 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http
2022
}
2123

2224
func (c *Client) Create(request CreateInstrumentRequest) (*CreateInstrumentResponse, error) {
25+
return c.CreateWithContext(context.Background(), request)
26+
}
27+
28+
func (c *Client) CreateWithContext(
29+
ctx context.Context,
30+
request CreateInstrumentRequest,
31+
) (*CreateInstrumentResponse, error) {
2332
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
2433
if err != nil {
2534
return nil, err
2635
}
2736

2837
var response CreateInstrumentResponse
29-
err = c.apiClient.Post(
30-
common.BuildPath(instruments.Path),
31-
auth,
32-
request,
33-
&response,
34-
nil,
35-
)
38+
err = c.apiClient.PostWithContext(ctx, common.BuildPath(instruments.Path), auth, request, &response, nil)
3639
if err != nil {
3740
return nil, err
3841
}
@@ -41,13 +44,17 @@ func (c *Client) Create(request CreateInstrumentRequest) (*CreateInstrumentRespo
4144
}
4245

4346
func (c *Client) Get(instrumentId string) (*GetInstrumentResponse, error) {
47+
return c.GetWithContext(context.Background(), instrumentId)
48+
}
49+
50+
func (c *Client) GetWithContext(ctx context.Context, instrumentId string) (*GetInstrumentResponse, error) {
4451
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
4552
if err != nil {
4653
return nil, err
4754
}
4855

4956
var response GetInstrumentResponse
50-
err = c.apiClient.Get(common.BuildPath(instruments.Path, instrumentId), auth, &response)
57+
err = c.apiClient.GetWithContext(ctx, common.BuildPath(instruments.Path, instrumentId), auth, &response)
5158
if err != nil {
5259
return nil, err
5360
}
@@ -59,23 +66,28 @@ func (c *Client) GetBankAccountFieldFormatting(
5966
country string,
6067
currency string,
6168
query QueryBankAccountFormatting,
69+
) (*GetBankAccountFieldFormattingResponse, error) {
70+
return c.GetBankAccountFieldFormattingWithContext(context.Background(), country, currency, query)
71+
}
72+
73+
func (c *Client) GetBankAccountFieldFormattingWithContext(
74+
ctx context.Context,
75+
country string,
76+
currency string,
77+
query QueryBankAccountFormatting,
6278
) (*GetBankAccountFieldFormattingResponse, error) {
6379
auth, err := c.configuration.Credentials.GetAuthorization(configuration.OAuth)
6480
if err != nil {
6581
return nil, err
6682
}
6783

68-
url, err := common.BuildQueryPath(
69-
common.BuildPath(instruments.ValidationPath,
70-
country,
71-
currency),
72-
query)
84+
url, err := common.BuildQueryPath(common.BuildPath(instruments.ValidationPath, country, currency), query)
7385
if err != nil {
7486
return nil, err
7587
}
7688

7789
var response GetBankAccountFieldFormattingResponse
78-
err = c.apiClient.Get(url, auth, &response)
90+
err = c.apiClient.GetWithContext(ctx, url, auth, &response)
7991
if err != nil {
8092
return nil, err
8193
}
@@ -84,18 +96,21 @@ func (c *Client) GetBankAccountFieldFormatting(
8496
}
8597

8698
func (c *Client) Update(instrumentId string, request UpdateInstrumentRequest) (*UpdateInstrumentResponse, error) {
99+
return c.UpdateWithContext(context.Background(), instrumentId, request)
100+
}
101+
102+
func (c *Client) UpdateWithContext(
103+
ctx context.Context,
104+
instrumentId string,
105+
request UpdateInstrumentRequest,
106+
) (*UpdateInstrumentResponse, error) {
87107
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
88108
if err != nil {
89109
return nil, err
90110
}
91111

92112
var response UpdateInstrumentResponse
93-
err = c.apiClient.Patch(
94-
common.BuildPath(instruments.Path, instrumentId),
95-
auth,
96-
request,
97-
&response,
98-
)
113+
err = c.apiClient.PatchWithContext(ctx, common.BuildPath(instruments.Path, instrumentId), auth, request, &response)
99114
if err != nil {
100115
return nil, err
101116
}
@@ -104,13 +119,17 @@ func (c *Client) Update(instrumentId string, request UpdateInstrumentRequest) (*
104119
}
105120

106121
func (c *Client) Delete(instrumentId string) (*common.MetadataResponse, error) {
122+
return c.DeleteWithContext(context.Background(), instrumentId)
123+
}
124+
125+
func (c *Client) DeleteWithContext(ctx context.Context, instrumentId string) (*common.MetadataResponse, error) {
107126
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
108127
if err != nil {
109128
return nil, err
110129
}
111130

112131
var response common.MetadataResponse
113-
err = c.apiClient.Delete(common.BuildPath(instruments.Path, instrumentId), auth, &response)
132+
err = c.apiClient.DeleteWithContext(ctx, common.BuildPath(instruments.Path, instrumentId), auth, &response)
114133
if err != nil {
115134
return nil, err
116135
}

instruments/nas/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ func TestCreate(t *testing.T) {
147147
Return(&configuration.SdkAuthorization{}, nil)
148148
},
149149
apiPost: func(m *mock.Mock) mock.Call {
150-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
150+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
151151
Return(nil).
152152
Run(func(args mock.Arguments) {
153-
respMapping := args.Get(3).(*CreateInstrumentResponse)
153+
respMapping := args.Get(4).(*CreateInstrumentResponse)
154154
*respMapping = createSepaResponse
155155
})
156156
},

0 commit comments

Comments
 (0)