Skip to content

Commit e0cc3da

Browse files
Add context for all API interactions (#86)
* Add Context to HTTP layer * Add Context to Customers client * Add Context to Disputes client * Add Context to Events client * Add Context to Hosted client * Add Context to Instruments client * Add Context to Links client * Add Context to Payments client * Add Context to Reconciliation client * Add Context to Sources client * Add Context to Tokens client * Add Context to Webhook client * Add Context to iDEAL client * Add Context to Klarna client * Add Context to SEPA client * Update tests * Add Context to NAS Payments --------- Co-authored-by: Armando Rodríguez <[email protected]>
1 parent e1958a1 commit e0cc3da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+996
-570
lines changed

accounts/client_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func TestCreateEntity(t *testing.T) {
5656
Return(&configuration.SdkAuthorization{}, nil)
5757
},
5858
apiPost: func(m *mock.Mock) mock.Call {
59-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
59+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
6060
Return(nil).
6161
Run(func(args mock.Arguments) {
62-
respMapping := args.Get(3).(*OnboardEntityResponse)
62+
respMapping := args.Get(4).(*OnboardEntityResponse)
6363
*respMapping = onboardEntity
6464
})
6565
},
@@ -81,7 +81,7 @@ func TestCreateEntity(t *testing.T) {
8181
Return(&configuration.SdkAuthorization{}, nil)
8282
},
8383
apiPost: func(m *mock.Mock) mock.Call {
84-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
84+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
8585
Return(
8686
errors.CheckoutAPIError{
8787
StatusCode: http.StatusUnprocessableEntity,
@@ -387,10 +387,10 @@ func TestGetEntity(t *testing.T) {
387387
Return(&configuration.SdkAuthorization{}, nil)
388388
},
389389
apiGet: func(m *mock.Mock) mock.Call {
390-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
390+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
391391
Return(nil).
392392
Run(func(args mock.Arguments) {
393-
respMapping := args.Get(2).(*OnboardEntityDetails)
393+
respMapping := args.Get(3).(*OnboardEntityDetails)
394394
*respMapping = entityDetails
395395
})
396396
},
@@ -416,7 +416,7 @@ func TestGetEntity(t *testing.T) {
416416
Return(&configuration.SdkAuthorization{}, nil)
417417
},
418418
apiGet: func(m *mock.Mock) mock.Call {
419-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
419+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
420420
Return(
421421
errors.CheckoutAPIError{
422422
StatusCode: http.StatusNotFound,
@@ -513,10 +513,10 @@ func TestUpdateEntity(t *testing.T) {
513513
Return(&configuration.SdkAuthorization{}, nil)
514514
},
515515
apiPut: func(m *mock.Mock) mock.Call {
516-
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
516+
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
517517
Return(nil).
518518
Run(func(args mock.Arguments) {
519-
respMapping := args.Get(3).(*OnboardEntityResponse)
519+
respMapping := args.Get(4).(*OnboardEntityResponse)
520520
*respMapping = onboardEntity
521521
})
522522
},
@@ -554,7 +554,7 @@ func TestUpdateEntity(t *testing.T) {
554554
Return(&configuration.SdkAuthorization{}, nil)
555555
},
556556
apiPut: func(m *mock.Mock) mock.Call {
557-
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
557+
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
558558
Return(
559559
errors.CheckoutAPIError{
560560
StatusCode: http.StatusNotFound,
@@ -647,10 +647,10 @@ func TestCreatePaymentInstruments(t *testing.T) {
647647
Return(&configuration.SdkAuthorization{}, nil)
648648
},
649649
apiPost: func(m *mock.Mock) mock.Call {
650-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
650+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
651651
Return(nil).
652652
Run(func(args mock.Arguments) {
653-
respMapping := args.Get(3).(*common.MetadataResponse)
653+
respMapping := args.Get(4).(*common.MetadataResponse)
654654
*respMapping = metadataResponse
655655
})
656656
},
@@ -668,7 +668,7 @@ func TestCreatePaymentInstruments(t *testing.T) {
668668
Return(&configuration.SdkAuthorization{}, nil)
669669
},
670670
apiPost: func(m *mock.Mock) mock.Call {
671-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
671+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
672672
Return(
673673
errors.CheckoutAPIError{
674674
StatusCode: http.StatusBadRequest,
@@ -690,7 +690,7 @@ func TestCreatePaymentInstruments(t *testing.T) {
690690
Return(&configuration.SdkAuthorization{}, nil)
691691
},
692692
apiPost: func(m *mock.Mock) mock.Call {
693-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
693+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
694694
Return(
695695
errors.CheckoutAPIError{
696696
StatusCode: http.StatusUnprocessableEntity,
@@ -717,7 +717,7 @@ func TestCreatePaymentInstruments(t *testing.T) {
717717
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
718718
},
719719
apiPost: func(m *mock.Mock) mock.Call {
720-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
720+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
721721
Return(nil)
722722
},
723723
checker: func(response *common.MetadataResponse, err error) {
@@ -795,10 +795,10 @@ func TestCreatePaymentInstrument(t *testing.T) {
795795
Return(&configuration.SdkAuthorization{}, nil)
796796
},
797797
apiPost: func(m *mock.Mock) mock.Call {
798-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
798+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
799799
Return(nil).
800800
Run(func(args mock.Arguments) {
801-
respMapping := args.Get(3).(*common.IdResponse)
801+
respMapping := args.Get(4).(*common.IdResponse)
802802
*respMapping = idResponse
803803
})
804804
},
@@ -817,7 +817,7 @@ func TestCreatePaymentInstrument(t *testing.T) {
817817
Return(&configuration.SdkAuthorization{}, nil)
818818
},
819819
apiPost: func(m *mock.Mock) mock.Call {
820-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
820+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
821821
Return(
822822
errors.CheckoutAPIError{
823823
StatusCode: http.StatusBadRequest,
@@ -839,7 +839,7 @@ func TestCreatePaymentInstrument(t *testing.T) {
839839
Return(&configuration.SdkAuthorization{}, nil)
840840
},
841841
apiPost: func(m *mock.Mock) mock.Call {
842-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
842+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
843843
Return(
844844
errors.CheckoutAPIError{
845845
StatusCode: http.StatusUnprocessableEntity,
@@ -866,7 +866,7 @@ func TestCreatePaymentInstrument(t *testing.T) {
866866
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
867867
},
868868
apiPost: func(m *mock.Mock) mock.Call {
869-
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
869+
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
870870
Return(nil)
871871
},
872872
checker: func(response *common.IdResponse, err error) {
@@ -946,10 +946,10 @@ func TestQueryPaymentInstruments(t *testing.T) {
946946
Return(&configuration.SdkAuthorization{}, nil)
947947
},
948948
apiGet: func(m *mock.Mock) mock.Call {
949-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
949+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
950950
Return(nil).
951951
Run(func(args mock.Arguments) {
952-
respMapping := args.Get(2).(*PaymentInstrumentQueryResponse)
952+
respMapping := args.Get(3).(*PaymentInstrumentQueryResponse)
953953
*respMapping = paymentInstrumentQueryResponse
954954
})
955955
},
@@ -967,7 +967,7 @@ func TestQueryPaymentInstruments(t *testing.T) {
967967
Return(&configuration.SdkAuthorization{}, nil)
968968
},
969969
apiGet: func(m *mock.Mock) mock.Call {
970-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
970+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
971971
Return(
972972
errors.CheckoutAPIError{
973973
StatusCode: http.StatusBadRequest,
@@ -989,7 +989,7 @@ func TestQueryPaymentInstruments(t *testing.T) {
989989
Return(&configuration.SdkAuthorization{}, nil)
990990
},
991991
apiGet: func(m *mock.Mock) mock.Call {
992-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
992+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
993993
Return(
994994
errors.CheckoutAPIError{
995995
StatusCode: http.StatusUnprocessableEntity,
@@ -1016,7 +1016,7 @@ func TestQueryPaymentInstruments(t *testing.T) {
10161016
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
10171017
},
10181018
apiGet: func(m *mock.Mock) mock.Call {
1019-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1019+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
10201020
Return(nil)
10211021
},
10221022
checker: func(response *PaymentInstrumentQueryResponse, err error) {
@@ -1088,10 +1088,10 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
10881088
Return(&configuration.SdkAuthorization{}, nil)
10891089
},
10901090
apiGet: func(m *mock.Mock) mock.Call {
1091-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1091+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
10921092
Return(nil).
10931093
Run(func(args mock.Arguments) {
1094-
respMapping := args.Get(2).(*PaymentInstrumentDetailsResponse)
1094+
respMapping := args.Get(3).(*PaymentInstrumentDetailsResponse)
10951095
*respMapping = paymentInstrumentDetailsResponse
10961096
})
10971097
},
@@ -1117,7 +1117,7 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
11171117
Return(&configuration.SdkAuthorization{}, nil)
11181118
},
11191119
apiGet: func(m *mock.Mock) mock.Call {
1120-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1120+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
11211121
Return(
11221122
errors.CheckoutAPIError{
11231123
StatusCode: http.StatusBadRequest,
@@ -1139,7 +1139,7 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
11391139
Return(&configuration.SdkAuthorization{}, nil)
11401140
},
11411141
apiGet: func(m *mock.Mock) mock.Call {
1142-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1142+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
11431143
Return(
11441144
errors.CheckoutAPIError{
11451145
StatusCode: http.StatusUnprocessableEntity,
@@ -1166,7 +1166,7 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
11661166
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
11671167
},
11681168
apiGet: func(m *mock.Mock) mock.Call {
1169-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1169+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
11701170
Return(nil)
11711171
},
11721172
checker: func(response *PaymentInstrumentDetailsResponse, err error) {
@@ -1231,10 +1231,10 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) {
12311231
Return(&configuration.SdkAuthorization{}, nil)
12321232
},
12331233
apiPut: func(m *mock.Mock) mock.Call {
1234-
return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1234+
return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
12351235
Return(nil).
12361236
Run(func(args mock.Arguments) {
1237-
respMapping := args.Get(3).(*common.IdResponse)
1237+
respMapping := args.Get(4).(*common.IdResponse)
12381238
*respMapping = idResponse
12391239
})
12401240
},
@@ -1259,7 +1259,7 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) {
12591259
Return(&configuration.SdkAuthorization{}, nil)
12601260
},
12611261
apiPut: func(m *mock.Mock) mock.Call {
1262-
return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1262+
return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
12631263
Return(
12641264
errors.CheckoutAPIError{
12651265
StatusCode: http.StatusNotFound,
@@ -1286,7 +1286,7 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) {
12861286
Return(&configuration.SdkAuthorization{}, nil)
12871287
},
12881288
apiPut: func(m *mock.Mock) mock.Call {
1289-
return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1289+
return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
12901290
Return(
12911291
errors.CheckoutAPIError{
12921292
StatusCode: http.StatusNotFound,
@@ -1355,10 +1355,10 @@ func TestGetPayoutSchedule(t *testing.T) {
13551355
Return(&configuration.SdkAuthorization{}, nil)
13561356
},
13571357
apiGet: func(m *mock.Mock) mock.Call {
1358-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1358+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
13591359
Return(nil).
13601360
Run(func(args mock.Arguments) {
1361-
respMapping := args.Get(2).(*PayoutSchedule)
1361+
respMapping := args.Get(3).(*PayoutSchedule)
13621362
*respMapping = schedule
13631363
})
13641364
},
@@ -1380,7 +1380,7 @@ func TestGetPayoutSchedule(t *testing.T) {
13801380
Return(&configuration.SdkAuthorization{}, nil)
13811381
},
13821382
apiGet: func(m *mock.Mock) mock.Call {
1383-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
1383+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
13841384
Return(
13851385
errors.CheckoutAPIError{
13861386
StatusCode: http.StatusNotFound,
@@ -1450,10 +1450,10 @@ func TestUpdatePayoutSchedule(t *testing.T) {
14501450
Return(&configuration.SdkAuthorization{}, nil)
14511451
},
14521452
apiPut: func(m *mock.Mock) mock.Call {
1453-
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1453+
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
14541454
Return(nil).
14551455
Run(func(args mock.Arguments) {
1456-
respMapping := args.Get(3).(*common.IdResponse)
1456+
respMapping := args.Get(4).(*common.IdResponse)
14571457
*respMapping = idResponse
14581458
})
14591459
},
@@ -1475,7 +1475,7 @@ func TestUpdatePayoutSchedule(t *testing.T) {
14751475
Return(&configuration.SdkAuthorization{}, nil)
14761476
},
14771477
apiPut: func(m *mock.Mock) mock.Call {
1478-
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
1478+
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
14791479
Return(
14801480
errors.CheckoutAPIError{
14811481
StatusCode: http.StatusNotFound,

apm/ideal/client.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ideal
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,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http
1920
}
2021

2122
func (c *Client) GetInfo() (*IdealInfo, error) {
23+
return c.GetInfoWithContext(context.Background())
24+
}
25+
26+
func (c *Client) GetInfoWithContext(ctx context.Context) (*IdealInfo, error) {
2227
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
2328
if err != nil {
2429
return nil, err
2530
}
2631

2732
var response IdealInfo
28-
err = c.apiClient.Get(common.BuildPath(idealExternalPath), auth, &response)
33+
err = c.apiClient.GetWithContext(ctx, common.BuildPath(idealExternalPath), auth, &response)
2934
if err != nil {
3035
return nil, err
3136
}
@@ -34,13 +39,17 @@ func (c *Client) GetInfo() (*IdealInfo, error) {
3439
}
3540

3641
func (c *Client) GetIssuers() (*IssuerResponse, error) {
42+
return c.GetIssuersWithContext(context.Background())
43+
}
44+
45+
func (c *Client) GetIssuersWithContext(ctx context.Context) (*IssuerResponse, error) {
3746
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey)
3847
if err != nil {
3948
return nil, err
4049
}
4150

4251
var response IssuerResponse
43-
err = c.apiClient.Get(common.BuildPath(idealExternalPath, issuersPath), auth, &response)
52+
err = c.apiClient.GetWithContext(ctx, common.BuildPath(idealExternalPath, issuersPath), auth, &response)
4453
if err != nil {
4554
return nil, err
4655
}

apm/ideal/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ func TestGetInfo(t *testing.T) {
4242
Return(&configuration.SdkAuthorization{}, nil)
4343
},
4444
apiGet: func(m *mock.Mock) mock.Call {
45-
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
45+
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
4646
Return(nil).
4747
Run(func(args mock.Arguments) {
48-
respMapping := args.Get(2).(*IdealInfo)
48+
respMapping := args.Get(3).(*IdealInfo)
4949
*respMapping = response
5050
})
5151
},

0 commit comments

Comments
 (0)