Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context for all API interactions #86

Merged
merged 20 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions accounts/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func TestCreateEntity(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(3).(*OnboardEntityResponse)
respMapping := args.Get(4).(*OnboardEntityResponse)
*respMapping = onboardEntity
})
},
Expand All @@ -81,7 +81,7 @@ func TestCreateEntity(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusUnprocessableEntity,
Expand Down Expand Up @@ -181,10 +181,10 @@ func TestGetEntity(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(2).(*OnboardEntityDetails)
respMapping := args.Get(3).(*OnboardEntityDetails)
*respMapping = entityDetails
})
},
Expand All @@ -210,7 +210,7 @@ func TestGetEntity(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusNotFound,
Expand Down Expand Up @@ -306,10 +306,10 @@ func TestUpdateEntity(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(3).(*OnboardEntityResponse)
respMapping := args.Get(4).(*OnboardEntityResponse)
*respMapping = onboardEntity
})
},
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestUpdateEntity(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusNotFound,
Expand Down Expand Up @@ -439,10 +439,10 @@ func TestCreatePaymentInstruments(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(3).(*common.MetadataResponse)
respMapping := args.Get(4).(*common.MetadataResponse)
*respMapping = metadataResponse
})
},
Expand All @@ -460,7 +460,7 @@ func TestCreatePaymentInstruments(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusBadRequest,
Expand All @@ -482,7 +482,7 @@ func TestCreatePaymentInstruments(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusUnprocessableEntity,
Expand All @@ -509,7 +509,7 @@ func TestCreatePaymentInstruments(t *testing.T) {
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)
},
checker: func(response *common.MetadataResponse, err error) {
Expand Down Expand Up @@ -586,10 +586,10 @@ func TestCreatePaymentInstrument(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(3).(*common.IdResponse)
respMapping := args.Get(4).(*common.IdResponse)
*respMapping = idResponse
})
},
Expand All @@ -608,7 +608,7 @@ func TestCreatePaymentInstrument(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusBadRequest,
Expand All @@ -630,7 +630,7 @@ func TestCreatePaymentInstrument(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusUnprocessableEntity,
Expand All @@ -657,7 +657,7 @@ func TestCreatePaymentInstrument(t *testing.T) {
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
},
apiPost: func(m *mock.Mock) mock.Call {
return *m.On("Post", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PostWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)
},
checker: func(response *common.IdResponse, err error) {
Expand Down Expand Up @@ -736,10 +736,10 @@ func TestQueryPaymentInstruments(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(2).(*PaymentInstrumentQueryResponse)
respMapping := args.Get(3).(*PaymentInstrumentQueryResponse)
*respMapping = paymentInstrumentQueryResponse
})
},
Expand All @@ -757,7 +757,7 @@ func TestQueryPaymentInstruments(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusBadRequest,
Expand All @@ -779,7 +779,7 @@ func TestQueryPaymentInstruments(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusUnprocessableEntity,
Expand All @@ -806,7 +806,7 @@ func TestQueryPaymentInstruments(t *testing.T) {
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)
},
checker: func(response *PaymentInstrumentQueryResponse, err error) {
Expand Down Expand Up @@ -877,10 +877,10 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(2).(*PaymentInstrumentDetailsResponse)
respMapping := args.Get(3).(*PaymentInstrumentDetailsResponse)
*respMapping = paymentInstrumentDetailsResponse
})
},
Expand All @@ -906,7 +906,7 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusBadRequest,
Expand All @@ -928,7 +928,7 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusUnprocessableEntity,
Expand All @@ -955,7 +955,7 @@ func TestRetrievePaymentInstrumentDetails(t *testing.T) {
Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type"))
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil)
},
checker: func(response *PaymentInstrumentDetailsResponse, err error) {
Expand Down Expand Up @@ -1019,10 +1019,10 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(3).(*common.IdResponse)
respMapping := args.Get(4).(*common.IdResponse)
*respMapping = idResponse
})
},
Expand All @@ -1047,7 +1047,7 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusNotFound,
Expand All @@ -1074,7 +1074,7 @@ func TestUpdatePaymentInstrumentDetails(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusNotFound,
Expand Down Expand Up @@ -1142,10 +1142,10 @@ func TestGetPayoutSchedule(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(2).(*PayoutSchedule)
respMapping := args.Get(3).(*PayoutSchedule)
*respMapping = schedule
})
},
Expand All @@ -1167,7 +1167,7 @@ func TestGetPayoutSchedule(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusNotFound,
Expand Down Expand Up @@ -1236,10 +1236,10 @@ func TestUpdatePayoutSchedule(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(3).(*common.IdResponse)
respMapping := args.Get(4).(*common.IdResponse)
*respMapping = idResponse
})
},
Expand All @@ -1261,7 +1261,7 @@ func TestUpdatePayoutSchedule(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiPut: func(m *mock.Mock) mock.Call {
return *m.On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
return *m.On("PutWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(
errors.CheckoutAPIError{
StatusCode: http.StatusNotFound,
Expand Down
13 changes: 11 additions & 2 deletions apm/ideal/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ideal

import (
"context"
"github.com/checkout/checkout-sdk-go/client"
"github.com/checkout/checkout-sdk-go/common"
"github.com/checkout/checkout-sdk-go/configuration"
Expand All @@ -19,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http
}

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.Get(common.BuildPath(idealExternalPath), auth, &response)
err = c.apiClient.GetWithContext(ctx, common.BuildPath(idealExternalPath), auth, &response)
if err != nil {
return nil, err
}
Expand All @@ -34,13 +39,17 @@ func (c *Client) GetInfo() (*IdealInfo, error) {
}

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.Get(common.BuildPath(idealExternalPath, issuersPath), auth, &response)
err = c.apiClient.GetWithContext(ctx, common.BuildPath(idealExternalPath, issuersPath), auth, &response)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions apm/ideal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func TestGetInfo(t *testing.T) {
Return(&configuration.SdkAuthorization{}, nil)
},
apiGet: func(m *mock.Mock) mock.Call {
return *m.On("Get", mock.Anything, mock.Anything, mock.Anything).
return *m.On("GetWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
Return(nil).
Run(func(args mock.Arguments) {
respMapping := args.Get(2).(*IdealInfo)
respMapping := args.Get(3).(*IdealInfo)
*respMapping = response
})
},
Expand Down
Loading
Loading