diff --git a/accounts/client_test.go b/accounts/client_test.go index 2a58e16..13c27a6 100644 --- a/accounts/client_test.go +++ b/accounts/client_test.go @@ -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 }) }, @@ -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, @@ -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 }) }, @@ -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, @@ -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 }) }, @@ -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, @@ -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 }) }, @@ -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, @@ -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, @@ -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) { @@ -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 }) }, @@ -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, @@ -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, @@ -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) { @@ -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 }) }, @@ -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, @@ -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, @@ -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) { @@ -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 }) }, @@ -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, @@ -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, @@ -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) { @@ -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 }) }, @@ -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, @@ -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, @@ -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 }) }, @@ -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, @@ -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 }) }, @@ -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, diff --git a/apm/ideal/client.go b/apm/ideal/client.go index b9d94cf..b36eeba 100644 --- a/apm/ideal/client.go +++ b/apm/ideal/client.go @@ -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" @@ -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 } @@ -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 } diff --git a/apm/ideal/client_test.go b/apm/ideal/client_test.go index 6e13712..e76507a 100644 --- a/apm/ideal/client_test.go +++ b/apm/ideal/client_test.go @@ -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 }) }, diff --git a/apm/klarna/client.go b/apm/klarna/client.go index addca8f..c2885aa 100644 --- a/apm/klarna/client.go +++ b/apm/klarna/client.go @@ -1,6 +1,7 @@ package klarna import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -20,13 +21,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) CreateCreditSession(request CreditSessionRequest) (*CreditSessionResponse, error) { + return c.CreateCreditSessionWithContext(context.Background(), request) +} + +func (c *Client) CreateCreditSessionWithContext(ctx context.Context, request CreditSessionRequest) (*CreditSessionResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.PublicKey) if err != nil { return nil, err } var response CreditSessionResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(c.getBaseUrl(), creditSessionPath), auth, request, @@ -41,13 +47,18 @@ func (c *Client) CreateCreditSession(request CreditSessionRequest) (*CreditSessi } func (c *Client) GetCreditSession(sessionId string) (*CreditSession, error) { + return c.GetCreditSessionWithContext(context.Background(), sessionId) +} + +func (c *Client) GetCreditSessionWithContext(ctx context.Context, sessionId string) (*CreditSession, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.PublicKey) if err != nil { return nil, err } var response CreditSession - err = c.apiClient.Get( + err = c.apiClient.GetWithContext( + ctx, common.BuildPath(c.getBaseUrl(), creditSessionPath, sessionId), auth, &response, @@ -60,13 +71,18 @@ func (c *Client) GetCreditSession(sessionId string) (*CreditSession, error) { } func (c *Client) CapturePayment(paymentId string, request OrderCaptureRequest) (*CaptureResponse, error) { + return c.CapturePaymentWithContext(context.Background(), paymentId, request) +} + +func (c *Client) CapturePaymentWithContext(ctx context.Context, paymentId string, request OrderCaptureRequest) (*CaptureResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response CaptureResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(c.getBaseUrl(), ordersPath, paymentId, capturesPath), auth, request, @@ -81,13 +97,18 @@ func (c *Client) CapturePayment(paymentId string, request OrderCaptureRequest) ( } func (c *Client) VoidPayment(paymentId string, request payments.VoidRequest) (*payments.VoidResponse, error) { + return c.VoidPaymentWithContext(context.Background(), paymentId, request) +} + +func (c *Client) VoidPaymentWithContext(ctx context.Context, paymentId string, request payments.VoidRequest) (*payments.VoidResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response payments.VoidResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(c.getBaseUrl(), ordersPath, paymentId, voidsPath), auth, request, diff --git a/apm/klarna/client_test.go b/apm/klarna/client_test.go index dff4622..06e6ddd 100644 --- a/apm/klarna/client_test.go +++ b/apm/klarna/client_test.go @@ -45,10 +45,10 @@ func TestCreateSession(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).(*CreditSessionResponse) + respMapping := args.Get(4).(*CreditSessionResponse) *respMapping = session }) }, @@ -68,7 +68,7 @@ func TestCreateSession(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, @@ -150,10 +150,10 @@ func TestGetCreditSession(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).(*CreditSession) + respMapping := args.Get(3).(*CreditSession) *respMapping = session }) }, @@ -175,7 +175,7 @@ func TestGetCreditSession(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, @@ -239,10 +239,10 @@ func TestCapturePayment(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).(*CaptureResponse) + respMapping := args.Get(4).(*CaptureResponse) *respMapping = captureResponse }) }, @@ -263,7 +263,7 @@ func TestCapturePayment(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, @@ -330,10 +330,10 @@ func TestVoidPayment(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).(*payments.VoidResponse) + respMapping := args.Get(4).(*payments.VoidResponse) *respMapping = voidResponse }) }, @@ -354,7 +354,7 @@ func TestVoidPayment(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, diff --git a/apm/sepa/client.go b/apm/sepa/client.go index 75568f9..22c48c1 100644 --- a/apm/sepa/client.go +++ b/apm/sepa/client.go @@ -1,6 +1,7 @@ package sepa import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) GetMandate(mandateId string) (*MandateResponse, error) { + return c.GetMandateWithContext(context.Background(), mandateId) +} + +func (c *Client) GetMandateWithContext(ctx context.Context, mandateId string) (*MandateResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response MandateResponse - err = c.apiClient.Get(common.BuildPath(sepaMandatesPath, mandateId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(sepaMandatesPath, mandateId), auth, &response) if err != nil { return nil, err } @@ -34,13 +39,18 @@ func (c *Client) GetMandate(mandateId string) (*MandateResponse, error) { } func (c *Client) CancelMandate(mandateId string) (*SepaResource, error) { + return c.CancelMandateWithContext(context.Background(), mandateId) +} + +func (c *Client) CancelMandateWithContext(ctx context.Context, mandateId string) (*SepaResource, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response SepaResource - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(sepaMandatesPath, mandateId, cancelPath), auth, nil, @@ -55,13 +65,17 @@ func (c *Client) CancelMandate(mandateId string) (*SepaResource, error) { } func (c *Client) GetMandateViaPpro(mandateId string) (*MandateResponse, error) { + return c.GetMandateViaPproWithContext(context.Background(), mandateId) +} + +func (c *Client) GetMandateViaPproWithContext(ctx context.Context, mandateId string) (*MandateResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response MandateResponse - err = c.apiClient.Get(common.BuildPath(apmsPath, pproPath, sepaMandatesPath, mandateId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(apmsPath, pproPath, sepaMandatesPath, mandateId), auth, &response) if err != nil { return nil, err } @@ -70,13 +84,18 @@ func (c *Client) GetMandateViaPpro(mandateId string) (*MandateResponse, error) { } func (c *Client) CancelMandateViaPpro(mandateId string) (*SepaResource, error) { + return c.CancelMandateViaPproWithContext(context.Background(), mandateId) +} + +func (c *Client) CancelMandateViaPproWithContext(ctx context.Context, mandateId string) (*SepaResource, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response SepaResource - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(apmsPath, pproPath, sepaMandatesPath, mandateId, cancelPath), auth, nil, diff --git a/apm/sepa/client_test.go b/apm/sepa/client_test.go index e95f701..44cd828 100644 --- a/apm/sepa/client_test.go +++ b/apm/sepa/client_test.go @@ -40,10 +40,10 @@ func TestGetMandate(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).(*MandateResponse) + respMapping := args.Get(3).(*MandateResponse) *respMapping = mandate }) }, @@ -63,7 +63,7 @@ func TestGetMandate(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, @@ -126,10 +126,10 @@ func TestCancelMandate(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).(*SepaResource) + respMapping := args.Get(4).(*SepaResource) *respMapping = cancelResponse }) }, diff --git a/balances/client_test.go b/balances/client_test.go index 291717b..bf61bf4 100644 --- a/balances/client_test.go +++ b/balances/client_test.go @@ -49,10 +49,10 @@ func TestRetrieveEntityBalances(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).(*QueryResponse) + respMapping := args.Get(3).(*QueryResponse) *respMapping = response }) }, diff --git a/client/client.go b/client/client.go index d5ef491..171f1b0 100644 --- a/client/client.go +++ b/client/client.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "context" "io" "io/ioutil" "net/http" @@ -13,11 +14,17 @@ import ( type HttpClient interface { Get(path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error + GetWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error Post(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error + PostWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error Put(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error + PutWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error Patch(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}) error + PatchWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}) error Delete(path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error + DeleteWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error Upload(path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}) error + UploadWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}) error } type ApiClient struct { @@ -40,30 +47,55 @@ func NewApiClient(configuration *configuration.Configuration, baseUri string) *A } func (a *ApiClient) Get(path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { - return a.invoke(http.MethodGet, path, authorization, nil, responseMapping, nil) + return a.GetWithContext(context.Background(), path, authorization, responseMapping) +} + +func (a *ApiClient) GetWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { + return a.invoke(ctx, http.MethodGet, path, authorization, nil, responseMapping, nil) } func (a *ApiClient) Post(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { - return a.invoke(http.MethodPost, path, authorization, request, responseMapping, idempotencyKey) + return a.PostWithContext(context.Background(), path, authorization, request, responseMapping, idempotencyKey) +} + +func (a *ApiClient) PostWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { + return a.invoke(ctx, http.MethodPost, path, authorization, request, responseMapping, idempotencyKey) } func (a *ApiClient) Put(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { - return a.invoke(http.MethodPut, path, authorization, request, responseMapping, idempotencyKey) + return a.PutWithContext(context.Background(), path, authorization, request, responseMapping, idempotencyKey) +} + +func (a *ApiClient) PutWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { + return a.invoke(ctx, http.MethodPut, path, authorization, request, responseMapping, idempotencyKey) } func (a *ApiClient) Patch(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}) error { - return a.invoke(http.MethodPatch, path, authorization, request, responseMapping, nil) + return a.PatchWithContext(context.Background(), path, authorization, request, responseMapping) +} + +func (a *ApiClient) PatchWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}) error { + return a.invoke(ctx, http.MethodPatch, path, authorization, request, responseMapping, nil) } func (a *ApiClient) Delete(path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { - return a.invoke(http.MethodDelete, path, authorization, nil, responseMapping, nil) + return a.DeleteWithContext(context.Background(), path, authorization, responseMapping) +} + +func (a *ApiClient) DeleteWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { + return a.invoke(ctx, http.MethodDelete, path, authorization, nil, responseMapping, nil) } func (a *ApiClient) Upload(path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}) error { - return a.submit(path, authorization, request, responseMapping) + return a.UploadWithContext(context.Background(), path, authorization, request, responseMapping) +} + +func (a *ApiClient) UploadWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}) error { + return a.submit(ctx, path, authorization, request, responseMapping) } func (a *ApiClient) invoke( + ctx context.Context, method string, path string, authorization *configuration.SdkAuthorization, @@ -76,7 +108,7 @@ func (a *ApiClient) invoke( return err } - req, err := a.buildRequest(method, path, authorization, "application/json", body, idempotencyKey) + req, err := a.buildRequest(ctx, method, path, authorization, "application/json", body, idempotencyKey) if err != nil { return err } @@ -91,12 +123,14 @@ func (a *ApiClient) invoke( } func (a *ApiClient) submit( + ctx context.Context, path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}, ) error { req, err := a.buildRequest( + ctx, http.MethodPost, path, authorization, @@ -118,6 +152,7 @@ func (a *ApiClient) submit( } func (a *ApiClient) buildRequest( + ctx context.Context, method string, path string, authorization *configuration.SdkAuthorization, @@ -125,7 +160,7 @@ func (a *ApiClient) buildRequest( body *bytes.Buffer, idempotencyKey *string, ) (*http.Request, error) { - req, err := http.NewRequest(method, a.BaseUri+path, body) + req, err := http.NewRequestWithContext(ctx, method, a.BaseUri+path, body) if err != nil { return nil, err } diff --git a/customers/client.go b/customers/client.go index 69d9936..b7e071a 100644 --- a/customers/client.go +++ b/customers/client.go @@ -1,6 +1,7 @@ package customers import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) Create(request CustomerRequest) (*common.IdResponse, error) { + return c.CreateWithContext(context.Background(), request) +} + +func (c *Client) CreateWithContext(ctx context.Context, request CustomerRequest) (*common.IdResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.IdResponse - err = c.apiClient.Post(common.BuildPath(Path), auth, request, &response, nil) + err = c.apiClient.PostWithContext(ctx, common.BuildPath(Path), auth, request, &response, nil) if err != nil { return nil, err } @@ -34,13 +39,17 @@ func (c *Client) Create(request CustomerRequest) (*common.IdResponse, error) { } func (c *Client) Get(customerId string) (*GetCustomerResponse, error) { + return c.GetWithContext(context.Background(), customerId) +} + +func (c *Client) GetWithContext(ctx context.Context, customerId string) (*GetCustomerResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response GetCustomerResponse - err = c.apiClient.Get(common.BuildPath(Path, customerId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(Path, customerId), auth, &response) if err != nil { return nil, err } @@ -49,13 +58,17 @@ func (c *Client) Get(customerId string) (*GetCustomerResponse, error) { } func (c *Client) Update(customerId string, request CustomerRequest) (*common.MetadataResponse, error) { + return c.UpdateWithContext(context.Background(), customerId, request) +} + +func (c *Client) UpdateWithContext(ctx context.Context, customerId string, request CustomerRequest) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Patch(common.BuildPath(Path, customerId), auth, request, &response) + err = c.apiClient.PatchWithContext(ctx, common.BuildPath(Path, customerId), auth, request, &response) if err != nil { return nil, err } @@ -64,13 +77,17 @@ func (c *Client) Update(customerId string, request CustomerRequest) (*common.Met } func (c *Client) Delete(customerId string) (*common.MetadataResponse, error) { + return c.DeleteWithContext(context.Background(), customerId) +} + +func (c *Client) DeleteWithContext(ctx context.Context, customerId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Delete(common.BuildPath(Path, customerId), auth, &response) + err = c.apiClient.DeleteWithContext(ctx, common.BuildPath(Path, customerId), auth, &response) if err != nil { return nil, err } diff --git a/customers/client_test.go b/customers/client_test.go index ca9d558..5d86833 100644 --- a/customers/client_test.go +++ b/customers/client_test.go @@ -50,10 +50,10 @@ func TestCreate(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 }) }, @@ -71,7 +71,7 @@ func TestCreate(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) { @@ -89,7 +89,7 @@ func TestCreate(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, @@ -155,10 +155,10 @@ func TestGet(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).(*GetCustomerResponse) + respMapping := args.Get(3).(*GetCustomerResponse) *respMapping = customer }) }, @@ -179,7 +179,7 @@ func TestGet(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 *GetCustomerResponse, err error) { @@ -197,7 +197,7 @@ func TestGet(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, @@ -257,10 +257,10 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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.MetadataResponse) + respMapping := args.Get(4).(*common.MetadataResponse) *respMapping = response }) }, @@ -283,7 +283,7 @@ func TestUpdate(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *common.MetadataResponse, err error) { @@ -302,7 +302,7 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, @@ -325,7 +325,7 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusUnprocessableEntity, @@ -385,10 +385,10 @@ func TestDelete(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Run(func(args mock.Arguments) { - respMapping := args.Get(2).(*common.MetadataResponse) + respMapping := args.Get(3).(*common.MetadataResponse) *respMapping = response }) }, @@ -406,7 +406,7 @@ func TestDelete(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *common.MetadataResponse, err error) { @@ -424,7 +424,7 @@ func TestDelete(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, diff --git a/disputes/client.go b/disputes/client.go index 47385dd..964d958 100644 --- a/disputes/client.go +++ b/disputes/client.go @@ -1,6 +1,7 @@ package disputes import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,6 +20,10 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) Query(queryFilter QueryFilter) (*QueryResponse, error) { + return c.QueryWithContext(context.Background(), queryFilter) +} + +func (c *Client) QueryWithContext(ctx context.Context, queryFilter QueryFilter) (*QueryResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err @@ -30,7 +35,7 @@ func (c *Client) Query(queryFilter QueryFilter) (*QueryResponse, error) { } var response QueryResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -39,13 +44,17 @@ func (c *Client) Query(queryFilter QueryFilter) (*QueryResponse, error) { } func (c *Client) GetDisputeDetails(disputeId string) (*DisputeResponse, error) { + return c.GetDisputeDetailsWithContext(context.Background(), disputeId) +} + +func (c *Client) GetDisputeDetailsWithContext(ctx context.Context, disputeId string) (*DisputeResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response DisputeResponse - err = c.apiClient.Get(common.BuildPath(disputes, disputeId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(disputes, disputeId), auth, &response) if err != nil { return nil, err } @@ -54,13 +63,18 @@ func (c *Client) GetDisputeDetails(disputeId string) (*DisputeResponse, error) { } func (c *Client) Accept(disputeId string) (*common.MetadataResponse, error) { + return c.AcceptWithContext(context.Background(), disputeId) +} + +func (c *Client) AcceptWithContext(ctx context.Context, disputeId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(disputes, disputeId, accept), auth, nil, @@ -75,13 +89,18 @@ func (c *Client) Accept(disputeId string) (*common.MetadataResponse, error) { } func (c *Client) PutEvidence(disputeId string, evidenceRequest Evidence) (*common.MetadataResponse, error) { + return c.PutEvidenceWithContext(context.Background(), disputeId, evidenceRequest) +} + +func (c *Client) PutEvidenceWithContext(ctx context.Context, disputeId string, evidenceRequest Evidence) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Put( + err = c.apiClient.PutWithContext( + ctx, common.BuildPath(disputes, disputeId, evidence), auth, evidenceRequest, @@ -96,13 +115,17 @@ func (c *Client) PutEvidence(disputeId string, evidenceRequest Evidence) (*commo } func (c *Client) GetEvidence(disputeId string) (*EvidenceResponse, error) { + return c.GetEvidenceWithContext(context.Background(), disputeId) +} + +func (c *Client) GetEvidenceWithContext(ctx context.Context, disputeId string) (*EvidenceResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response EvidenceResponse - err = c.apiClient.Get(common.BuildPath(disputes, disputeId, evidence), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(disputes, disputeId, evidence), auth, &response) if err != nil { return nil, err } @@ -111,13 +134,18 @@ func (c *Client) GetEvidence(disputeId string) (*EvidenceResponse, error) { } func (c *Client) SubmitEvidence(disputeId string) (*common.MetadataResponse, error) { + return c.SubmitEvidenceWithContext(context.Background(), disputeId) +} + +func (c *Client) SubmitEvidenceWithContext(ctx context.Context, disputeId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(disputes, disputeId, evidence), auth, nil, @@ -147,6 +175,10 @@ func (c *Client) GetCompiledSubmittedEvidence(disputeId string) (*DisputeCompile } func (c *Client) UploadFile(file common.File) (*common.IdResponse, error) { + return c.UploadFileWithContext(context.Background(), file) +} + +func (c *Client) UploadFileWithContext(ctx context.Context, file common.File) (*common.IdResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err @@ -158,7 +190,7 @@ func (c *Client) UploadFile(file common.File) (*common.IdResponse, error) { } var response common.IdResponse - err = c.apiClient.Upload(common.BuildPath(files), auth, req, &response) + err = c.apiClient.UploadWithContext(ctx, common.BuildPath(files), auth, req, &response) if err != nil { return nil, err } @@ -167,13 +199,17 @@ func (c *Client) UploadFile(file common.File) (*common.IdResponse, error) { } func (c *Client) GetFileDetails(fileId string) (*common.FileResponse, error) { + return c.GetFileDetailsWithContext(context.Background(), fileId) +} + +func (c *Client) GetFileDetailsWithContext(ctx context.Context, fileId string) (*common.FileResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response common.FileResponse - err = c.apiClient.Get(common.BuildPath(files, fileId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(files, fileId), auth, &response) if err != nil { return nil, err } @@ -182,13 +218,17 @@ func (c *Client) GetFileDetails(fileId string) (*common.FileResponse, error) { } func (c *Client) GetDisputeSchemeFiles(disputeId string) (*SchemeFilesResponse, error) { + return c.GetDisputeSchemeFilesWithContext(context.Background(), disputeId) +} + +func (c *Client) GetDisputeSchemeFilesWithContext(ctx context.Context, disputeId string) (*SchemeFilesResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response SchemeFilesResponse - err = c.apiClient.Get(common.BuildPath(disputes, disputeId, schemeFiles), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(disputes, disputeId, schemeFiles), auth, &response) if err != nil { return nil, err } diff --git a/disputes/client_test.go b/disputes/client_test.go index 4c9fc5c..5fffbcf 100644 --- a/disputes/client_test.go +++ b/disputes/client_test.go @@ -75,10 +75,10 @@ func TestQuery(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).(*QueryResponse) + respMapping := args.Get(3).(*QueryResponse) *respMapping = queryResponse }) }, @@ -120,7 +120,7 @@ func TestQuery(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, @@ -187,10 +187,10 @@ func TestGetDisputeDetails(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).(*DisputeResponse) + respMapping := args.Get(3).(*DisputeResponse) *respMapping = disputeResponse }) }, @@ -212,7 +212,7 @@ func TestGetDisputeDetails(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 *DisputeResponse, err error) { @@ -230,7 +230,7 @@ func TestGetDisputeDetails(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, @@ -284,10 +284,10 @@ func TestAccept(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 = response }) }, @@ -304,7 +304,7 @@ func TestAccept(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) { @@ -322,7 +322,7 @@ func TestAccept(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.StatusNotFound, @@ -377,10 +377,10 @@ func TestPutEvidence(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.MetadataResponse) + respMapping := args.Get(4).(*common.MetadataResponse) *respMapping = response }) }, @@ -399,7 +399,7 @@ func TestPutEvidence(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, 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) }, checker: func(response *common.MetadataResponse, err error) { @@ -418,7 +418,7 @@ func TestPutEvidence(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, @@ -474,10 +474,10 @@ func TestGetEvidence(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).(*EvidenceResponse) + respMapping := args.Get(3).(*EvidenceResponse) *respMapping = evidenceResponse }) }, @@ -495,7 +495,7 @@ func TestGetEvidence(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 *EvidenceResponse, err error) { @@ -513,7 +513,7 @@ func TestGetEvidence(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, @@ -567,10 +567,10 @@ func TestSubmitEvidence(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 = response }) }, @@ -587,7 +587,7 @@ func TestSubmitEvidence(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) { @@ -605,7 +605,7 @@ func TestSubmitEvidence(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.StatusNotFound, @@ -770,10 +770,10 @@ func TestGetDisputeSchemeFiles(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).(*SchemeFilesResponse) + respMapping := args.Get(3).(*SchemeFilesResponse) *respMapping = schemeFilesResponse }) }, @@ -792,7 +792,7 @@ func TestGetDisputeSchemeFiles(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 *SchemeFilesResponse, err error) { @@ -810,7 +810,7 @@ func TestGetDisputeSchemeFiles(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, diff --git a/events/abc/client.go b/events/abc/client.go index 5353468..0832d81 100644 --- a/events/abc/client.go +++ b/events/abc/client.go @@ -1,6 +1,7 @@ package abc import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) RetrieveAllEventTypes() (*EventTypesResponse, error) { + return c.RetrieveAllEventTypesWithContext(context.Background()) +} + +func (c *Client) RetrieveAllEventTypesWithContext(ctx context.Context) (*EventTypesResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response EventTypesResponse - err = c.apiClient.Get(common.BuildPath(eventTypes), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(eventTypes), auth, &response) if err != nil { return nil, err } @@ -35,6 +40,13 @@ func (c *Client) RetrieveAllEventTypes() (*EventTypesResponse, error) { func (c *Client) RetrieveAllEventTypesQuery( query QueryRetrieveAllEventType, +) (*EventTypesResponse, error) { + return c.RetrieveAllEventTypesQueryWithContext(context.Background(), query) +} + +func (c *Client) RetrieveAllEventTypesQueryWithContext( + ctx context.Context, + query QueryRetrieveAllEventType, ) (*EventTypesResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { @@ -48,7 +60,7 @@ func (c *Client) RetrieveAllEventTypesQuery( } var response EventTypesResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -57,13 +69,17 @@ func (c *Client) RetrieveAllEventTypesQuery( } func (c *Client) RetrieveEvents() (*EventsPageResponse, error) { + return c.RetrieveEventsWithContext(context.Background()) +} + +func (c *Client) RetrieveEventsWithContext(ctx context.Context) (*EventsPageResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response EventsPageResponse - err = c.apiClient.Get(common.BuildPath(events), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(events), auth, &response) if err != nil { return nil, err } @@ -72,6 +88,10 @@ func (c *Client) RetrieveEvents() (*EventsPageResponse, error) { } func (c *Client) RetrieveEventsQuery(query QueryRetrieveEvents) (*EventsPageResponse, error) { + return c.RetrieveEventsQueryWithContext(context.Background(), query) +} + +func (c *Client) RetrieveEventsQueryWithContext(ctx context.Context, query QueryRetrieveEvents) (*EventsPageResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err @@ -84,7 +104,7 @@ func (c *Client) RetrieveEventsQuery(query QueryRetrieveEvents) (*EventsPageResp } var response EventsPageResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -93,13 +113,17 @@ func (c *Client) RetrieveEventsQuery(query QueryRetrieveEvents) (*EventsPageResp } func (c *Client) RetrieveEvent(eventId string) (*EventResponse, error) { + return c.RetrieveEventWithContext(context.Background(), eventId) +} + +func (c *Client) RetrieveEventWithContext(ctx context.Context, eventId string) (*EventResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response EventResponse - err = c.apiClient.Get(common.BuildPath(events, eventId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(events, eventId), auth, &response) if err != nil { return nil, err } @@ -110,6 +134,14 @@ func (c *Client) RetrieveEvent(eventId string) (*EventResponse, error) { func (c *Client) RetrieveEventNotification( eventId string, notificationId string, +) (*EventNotificationResponse, error) { + return c.RetrieveEventNotificationWithContext(context.Background(), eventId, notificationId) +} + +func (c *Client) RetrieveEventNotificationWithContext( + ctx context.Context, + eventId string, + notificationId string, ) (*EventNotificationResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { @@ -117,7 +149,7 @@ func (c *Client) RetrieveEventNotification( } var response EventNotificationResponse - err = c.apiClient.Get(common.BuildPath(events, eventId, notifications, notificationId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(events, eventId, notifications, notificationId), auth, &response) if err != nil { return nil, err } @@ -126,13 +158,18 @@ func (c *Client) RetrieveEventNotification( } func (c *Client) RetryWebhook(eventId string, webhookId string) (*common.MetadataResponse, error) { + return c.RetryWebhookWithContext(context.Background(), eventId, webhookId) +} + +func (c *Client) RetryWebhookWithContext(ctx context.Context, eventId string, webhookId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(events, eventId, webhooks, webhookId), auth, nil, @@ -147,13 +184,17 @@ func (c *Client) RetryWebhook(eventId string, webhookId string) (*common.Metadat } func (c *Client) RetryAllWebhooks(eventId string) (*common.MetadataResponse, error) { + return c.RetryAllWebhooksWithContext(context.Background(), eventId) +} + +func (c *Client) RetryAllWebhooksWithContext(ctx context.Context, eventId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Post(common.BuildPath(events, eventId, webhooks, retry), + err = c.apiClient.PostWithContext(ctx, common.BuildPath(events, eventId, webhooks, retry), auth, nil, &response, diff --git a/events/abc/client_test.go b/events/abc/client_test.go index de15a07..46dd86f 100644 --- a/events/abc/client_test.go +++ b/events/abc/client_test.go @@ -56,10 +56,10 @@ func TestRetrieveAllEventTypes(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).(*EventTypesResponse) + respMapping := args.Get(3).(*EventTypesResponse) *respMapping = EventTypesResponse{ HttpResponse: mocks.HttpMetadataStatusOk, EventTypes: eventTypes1Dot0, @@ -81,10 +81,10 @@ func TestRetrieveAllEventTypes(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).(*EventTypesResponse) + respMapping := args.Get(3).(*EventTypesResponse) *respMapping = response }) }, @@ -103,7 +103,7 @@ func TestRetrieveAllEventTypes(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 *EventTypesResponse, err error) { @@ -168,10 +168,10 @@ func TestRetrieveEvents(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).(*EventsPageResponse) + respMapping := args.Get(3).(*EventsPageResponse) *respMapping = response }) }, @@ -195,10 +195,10 @@ func TestRetrieveEvents(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).(*EventsPageResponse) + respMapping := args.Get(3).(*EventsPageResponse) *respMapping = EventsPageResponse{ HttpResponse: mocks.HttpMetadataStatusNoContent, } @@ -217,7 +217,7 @@ func TestRetrieveEvents(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 *EventsPageResponse, err error) { @@ -236,7 +236,7 @@ func TestRetrieveEvents(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, @@ -303,10 +303,10 @@ func TestRetrieveEvent(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).(*EventResponse) + respMapping := args.Get(3).(*EventResponse) *respMapping = response }) }, @@ -327,7 +327,7 @@ func TestRetrieveEvent(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 *EventResponse, err error) { @@ -346,7 +346,7 @@ func TestRetrieveEvent(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, @@ -408,10 +408,10 @@ func TestRetrieveEventNotification(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).(*EventNotificationResponse) + respMapping := args.Get(3).(*EventNotificationResponse) *respMapping = response }) }, @@ -431,7 +431,7 @@ func TestRetrieveEventNotification(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 *EventNotificationResponse, err error) { @@ -451,7 +451,7 @@ func TestRetrieveEventNotification(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, @@ -511,10 +511,10 @@ func TestRetryWebhook(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 }) }, @@ -531,7 +531,7 @@ func TestRetryWebhook(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiPost: 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 *common.MetadataResponse, err error) { @@ -550,7 +550,7 @@ func TestRetryWebhook(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.StatusNotFound, @@ -572,7 +572,7 @@ func TestRetryWebhook(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.StatusNotFound, @@ -629,10 +629,10 @@ func TestRetryAllWebhooks(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 }) }, @@ -649,7 +649,7 @@ func TestRetryAllWebhooks(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiPost: 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 *common.MetadataResponse, err error) { @@ -668,7 +668,7 @@ func TestRetryAllWebhooks(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.StatusNotFound, diff --git a/financial/client_test.go b/financial/client_test.go index eb03c50..c04e970 100644 --- a/financial/client_test.go +++ b/financial/client_test.go @@ -58,10 +58,10 @@ func TestGetFinancialActions(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).(*QueryResponse) + respMapping := args.Get(3).(*QueryResponse) *respMapping = queryResponse }) }, @@ -85,7 +85,7 @@ func TestGetFinancialActions(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 *QueryResponse, err error) { @@ -105,7 +105,7 @@ func TestGetFinancialActions(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, diff --git a/forex/client_test.go b/forex/client_test.go index 04fe5c7..71d8f88 100644 --- a/forex/client_test.go +++ b/forex/client_test.go @@ -51,10 +51,10 @@ func TestRequestQuote(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).(*QuoteResponse) + respMapping := args.Get(4).(*QuoteResponse) *respMapping = quote }) }, @@ -75,7 +75,7 @@ func TestRequestQuote(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, @@ -156,10 +156,10 @@ func TestGetRates(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).(*RatesResponse) + respMapping := args.Get(3).(*RatesResponse) *respMapping = ratesResponse }) }, @@ -181,7 +181,7 @@ func TestGetRates(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 *RatesResponse, err error) { @@ -203,7 +203,7 @@ func TestGetRates(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, diff --git a/instruments/abc/client.go b/instruments/abc/client.go index b54d1a4..f370ebb 100644 --- a/instruments/abc/client.go +++ b/instruments/abc/client.go @@ -1,6 +1,7 @@ package abc import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -20,13 +21,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) Create(request CreateInstrumentRequest) (*CreateInstrumentResponse, error) { + return c.CreateWithContext(context.Background(), request) +} + +func (c *Client) CreateWithContext(ctx context.Context, request CreateInstrumentRequest) (*CreateInstrumentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response CreateInstrumentResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(instruments.Path), auth, request, @@ -41,13 +47,17 @@ func (c *Client) Create(request CreateInstrumentRequest) (*CreateInstrumentRespo } func (c *Client) Get(instrumentId string) (*GetInstrumentResponse, error) { + return c.GetWithContext(context.Background(), instrumentId) +} + +func (c *Client) GetWithContext(ctx context.Context, instrumentId string) (*GetInstrumentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response GetInstrumentResponse - err = c.apiClient.Get(common.BuildPath(instruments.Path, instrumentId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(instruments.Path, instrumentId), auth, &response) if err != nil { return nil, err } @@ -56,13 +66,18 @@ func (c *Client) Get(instrumentId string) (*GetInstrumentResponse, error) { } func (c *Client) Update(instrumentId string, request UpdateInstrumentRequest) (*UpdateInstrumentResponse, error) { + return c.UpdateWithContext(context.Background(), instrumentId, request) +} + +func (c *Client) UpdateWithContext(ctx context.Context, instrumentId string, request UpdateInstrumentRequest) (*UpdateInstrumentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response UpdateInstrumentResponse - err = c.apiClient.Patch( + err = c.apiClient.PatchWithContext( + ctx, common.BuildPath(instruments.Path, instrumentId), auth, request, @@ -76,13 +91,17 @@ func (c *Client) Update(instrumentId string, request UpdateInstrumentRequest) (* } func (c *Client) Delete(instrumentId string) (*common.MetadataResponse, error) { + return c.DeleteWithContext(context.Background(), instrumentId) +} + +func (c *Client) DeleteWithContext(ctx context.Context, instrumentId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Delete(common.BuildPath(instruments.Path, instrumentId), auth, &response) + err = c.apiClient.DeleteWithContext(ctx, common.BuildPath(instruments.Path, instrumentId), auth, &response) if err != nil { return nil, err } diff --git a/instruments/abc/client_test.go b/instruments/abc/client_test.go index 40b08ef..afc4165 100644 --- a/instruments/abc/client_test.go +++ b/instruments/abc/client_test.go @@ -58,10 +58,10 @@ func TestCreate(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).(*CreateInstrumentResponse) + respMapping := args.Get(4).(*CreateInstrumentResponse) *respMapping = instrumentResponse }) }, @@ -80,7 +80,7 @@ func TestCreate(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 *CreateInstrumentResponse, err error) { @@ -98,7 +98,7 @@ func TestCreate(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, @@ -166,10 +166,10 @@ func TestGet(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).(*GetInstrumentResponse) + respMapping := args.Get(3).(*GetInstrumentResponse) *respMapping = instrument }) }, @@ -189,7 +189,7 @@ func TestGet(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 *GetInstrumentResponse, err error) { @@ -207,7 +207,7 @@ func TestGet(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, @@ -270,10 +270,10 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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).(*UpdateInstrumentResponse) + respMapping := args.Get(4).(*UpdateInstrumentResponse) *respMapping = updateResponse }) }, @@ -293,7 +293,7 @@ func TestUpdate(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *UpdateInstrumentResponse, err error) { @@ -312,7 +312,7 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, @@ -335,7 +335,7 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusUnprocessableEntity, @@ -395,10 +395,10 @@ func TestDelete(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Run(func(args mock.Arguments) { - respMapping := args.Get(2).(*common.MetadataResponse) + respMapping := args.Get(3).(*common.MetadataResponse) *respMapping = response }) }, @@ -415,7 +415,7 @@ func TestDelete(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *common.MetadataResponse, err error) { @@ -433,7 +433,7 @@ func TestDelete(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, diff --git a/instruments/nas/client_test.go b/instruments/nas/client_test.go index a515526..adc6178 100644 --- a/instruments/nas/client_test.go +++ b/instruments/nas/client_test.go @@ -101,10 +101,10 @@ func TestCreate(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).(*CreateInstrumentResponse) + respMapping := args.Get(4).(*CreateInstrumentResponse) *respMapping = createTokenResponse }) }, @@ -124,10 +124,10 @@ func TestCreate(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).(*CreateInstrumentResponse) + respMapping := args.Get(4).(*CreateInstrumentResponse) *respMapping = createBankAccountResponse }) }, @@ -169,7 +169,7 @@ func TestCreate(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 *CreateInstrumentResponse, err error) { @@ -187,7 +187,7 @@ func TestCreate(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, @@ -294,10 +294,10 @@ func TestGet(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).(*GetInstrumentResponse) + respMapping := args.Get(3).(*GetInstrumentResponse) *respMapping = response }) }, @@ -317,7 +317,7 @@ func TestGet(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 *GetInstrumentResponse, err error) { @@ -335,7 +335,7 @@ func TestGet(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, @@ -430,10 +430,10 @@ func TestClientGetBankAccountFieldFormatting(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).(*GetBankAccountFieldFormattingResponse) + respMapping := args.Get(3).(*GetBankAccountFieldFormattingResponse) *respMapping = response }) }, @@ -465,7 +465,7 @@ func TestClientGetBankAccountFieldFormatting(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 *GetBankAccountFieldFormattingResponse, err error) { @@ -485,7 +485,7 @@ func TestClientGetBankAccountFieldFormatting(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, @@ -549,10 +549,10 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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).(*UpdateInstrumentResponse) + respMapping := args.Get(4).(*UpdateInstrumentResponse) *respMapping = response }) }, @@ -572,7 +572,7 @@ func TestUpdate(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *UpdateInstrumentResponse, err error) { @@ -591,7 +591,7 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, @@ -613,7 +613,7 @@ func TestUpdate(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: func(m *mock.Mock) mock.Call { - return *m.On("Patch", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + return *m.On("PatchWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusUnprocessableEntity, @@ -673,10 +673,10 @@ func TestDelete(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Run(func(args mock.Arguments) { - respMapping := args.Get(2).(*common.MetadataResponse) + respMapping := args.Get(3).(*common.MetadataResponse) *respMapping = response }) }, @@ -693,7 +693,7 @@ func TestDelete(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *common.MetadataResponse, err error) { @@ -711,7 +711,7 @@ func TestDelete(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, diff --git a/issuing/client_issuing_test.go b/issuing/client_issuing_test.go index ab99ff8..e085529 100644 --- a/issuing/client_issuing_test.go +++ b/issuing/client_issuing_test.go @@ -91,10 +91,10 @@ func TestCreateCardholder(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).(*cardholders.CardholderResponse) + respMapping := args.Get(4).(*cardholders.CardholderResponse) *respMapping = response }) }, @@ -119,7 +119,7 @@ func TestCreateCardholder(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.StatusUnauthorized, @@ -142,7 +142,7 @@ func TestCreateCardholder(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, @@ -170,7 +170,7 @@ func TestCreateCardholder(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.StatusInternalServerError, @@ -242,10 +242,10 @@ func TestGetCardholder(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).(*cardholders.CardholderDetailsResponse) + respMapping := args.Get(3).(*cardholders.CardholderDetailsResponse) *respMapping = response }) }, @@ -280,7 +280,7 @@ func TestGetCardholder(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, @@ -339,10 +339,10 @@ func TestGetCardholderCards(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).(*cardholders.CardholderCardsResponse) + respMapping := args.Get(3).(*cardholders.CardholderCardsResponse) *respMapping = response }) }, @@ -359,7 +359,7 @@ func TestGetCardholderCards(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, @@ -412,10 +412,10 @@ func TestCreateCard(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).(*cards.CardResponse) + respMapping := args.Get(4).(*cards.CardResponse) *respMapping = response }) }, @@ -461,10 +461,10 @@ func TestGetCardDetails(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPost: 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).(*cards.CardDetailsResponse) + respMapping := args.Get(3).(*cards.CardDetailsResponse) *respMapping = response }) }, @@ -513,10 +513,10 @@ func TestEnrollThreeDS(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).(*cards.ThreeDSEnrollmentResponse) + respMapping := args.Get(4).(*cards.ThreeDSEnrollmentResponse) *respMapping = response }) }, @@ -565,10 +565,10 @@ func TestUpdateThreeDS(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPost: 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).(*cards.ThreeDSUpdateResponse) + respMapping := args.Get(4).(*cards.ThreeDSUpdateResponse) *respMapping = response }) }, @@ -614,10 +614,10 @@ func TestGetCardThreeDSDetails(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPost: 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).(*cards.ThreeDSEnrollmentDetailsResponse) + respMapping := args.Get(3).(*cards.ThreeDSEnrollmentDetailsResponse) *respMapping = response }) }, @@ -663,10 +663,10 @@ func TestActivateCard(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 = response }) }, @@ -714,10 +714,10 @@ func TestGetCardCredentials(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPost: 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).(*cards.CardCredentialsResponse) + respMapping := args.Get(3).(*cards.CardCredentialsResponse) *respMapping = response }) }, @@ -766,10 +766,10 @@ func TestRevokeCard(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 = response }) }, @@ -815,10 +815,10 @@ func TestSuspendCard(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 = response }) }, @@ -865,10 +865,10 @@ func TestCreateControl(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).(*controls.CardControlResponse) + respMapping := args.Get(4).(*controls.CardControlResponse) *respMapping = response }) }, @@ -915,10 +915,10 @@ func TestGetCardControls(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).(*controls.CardControlsQueryResponse) + respMapping := args.Get(3).(*controls.CardControlsQueryResponse) *respMapping = response }) }, @@ -964,10 +964,10 @@ func TestGetCardControlDetails(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).(*controls.CardControlResponse) + respMapping := args.Get(3).(*controls.CardControlResponse) *respMapping = response }) }, @@ -1016,10 +1016,10 @@ func TestUpdateCardControl(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiUpdate: 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).(*controls.CardControlResponse) + respMapping := args.Get(4).(*controls.CardControlResponse) *respMapping = response }) }, @@ -1065,10 +1065,10 @@ func TestRemoveCardControl(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Run(func(args mock.Arguments) { - respMapping := args.Get(2).(*common.IdResponse) + respMapping := args.Get(3).(*common.IdResponse) *respMapping = response }) }, @@ -1115,10 +1115,10 @@ func TestSimulateAuthorization(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).(*issuingTesting.CardAuthorizationResponse) + respMapping := args.Get(4).(*issuingTesting.CardAuthorizationResponse) *respMapping = response }) }, @@ -1169,10 +1169,10 @@ func TestSimulateIncrement(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).(*issuingTesting.CardSimulationResponse) + respMapping := args.Get(4).(*issuingTesting.CardSimulationResponse) *respMapping = issuingResponse }) }, @@ -1190,7 +1190,7 @@ func TestSimulateIncrement(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 *issuingTesting.CardSimulationResponse, err error) { @@ -1209,7 +1209,7 @@ func TestSimulateIncrement(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.StatusNotFound, @@ -1264,10 +1264,10 @@ func TestSimulateClearing(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 = issuingResponse }) }, @@ -1284,7 +1284,7 @@ func TestSimulateClearing(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) { @@ -1303,7 +1303,7 @@ func TestSimulateClearing(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.StatusNotFound, @@ -1359,10 +1359,10 @@ func TestSimulateReversal(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).(*issuingTesting.CardSimulationResponse) + respMapping := args.Get(4).(*issuingTesting.CardSimulationResponse) *respMapping = issuingResponse }) }, @@ -1380,7 +1380,7 @@ func TestSimulateReversal(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 *issuingTesting.CardSimulationResponse, err error) { @@ -1399,7 +1399,7 @@ func TestSimulateReversal(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.StatusNotFound, diff --git a/metadata/client_test.go b/metadata/client_test.go index a204fa9..9db0159 100644 --- a/metadata/client_test.go +++ b/metadata/client_test.go @@ -57,10 +57,10 @@ func TestRequestQuote(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).(*CardMetadataResponse) + respMapping := args.Get(4).(*CardMetadataResponse) *respMapping = response }) }, @@ -81,7 +81,7 @@ func TestRequestQuote(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, diff --git a/mocks/client_mock.go b/mocks/client_mock.go index dfd2556..deec2cf 100644 --- a/mocks/client_mock.go +++ b/mocks/client_mock.go @@ -1,6 +1,7 @@ package mocks import ( + "context" "github.com/stretchr/testify/mock" "github.com/checkout/checkout-sdk-go/common" @@ -12,7 +13,11 @@ type ( ) func (m *ApiClientMock) Get(path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { - args := m.Called(path, authorization, responseMapping) + return m.GetWithContext(context.Background(), path, authorization, responseMapping) +} + +func (m *ApiClientMock) GetWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { + args := m.Called(ctx, path, authorization, responseMapping) if args.Get(0) != nil { return args.Get(0).(error) @@ -22,7 +27,11 @@ func (m *ApiClientMock) Get(path string, authorization *configuration.SdkAuthori } func (m *ApiClientMock) Post(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { - args := m.Called(path, authorization, request, responseMapping, idempotencyKey) + return m.PostWithContext(context.Background(), path, authorization, request, responseMapping, idempotencyKey) +} + +func (m *ApiClientMock) PostWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { + args := m.Called(ctx, path, authorization, request, responseMapping, idempotencyKey) if args.Get(0) != nil { return args.Get(0).(error) @@ -32,7 +41,11 @@ func (m *ApiClientMock) Post(path string, authorization *configuration.SdkAuthor } func (m *ApiClientMock) Put(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { - args := m.Called(path, authorization, request, responseMapping, idempotencyKey) + return m.PutWithContext(context.Background(), path, authorization, request, responseMapping, idempotencyKey) +} + +func (m *ApiClientMock) PutWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}, idempotencyKey *string) error { + args := m.Called(ctx, path, authorization, request, responseMapping, idempotencyKey) if args.Get(0) != nil { return args.Get(0).(error) @@ -42,7 +55,11 @@ func (m *ApiClientMock) Put(path string, authorization *configuration.SdkAuthori } func (m *ApiClientMock) Patch(path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}) error { - args := m.Called(path, authorization, request, responseMapping) + return m.PatchWithContext(context.Background(), path, authorization, request, responseMapping) +} + +func (m *ApiClientMock) PatchWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request interface{}, responseMapping interface{}) error { + args := m.Called(ctx, path, authorization, request, responseMapping) if args.Get(0) != nil { return args.Get(0).(error) @@ -52,7 +69,11 @@ func (m *ApiClientMock) Patch(path string, authorization *configuration.SdkAutho } func (m *ApiClientMock) Delete(path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { - args := m.Called(path, authorization, responseMapping) + return m.DeleteWithContext(context.Background(), path, authorization, responseMapping) +} + +func (m *ApiClientMock) DeleteWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, responseMapping interface{}) error { + args := m.Called(ctx, path, authorization, responseMapping) if args.Get(0) != nil { return args.Get(0).(error) @@ -62,7 +83,11 @@ func (m *ApiClientMock) Delete(path string, authorization *configuration.SdkAuth } func (m *ApiClientMock) Upload(path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}) error { - args := m.Called(path, authorization, request, responseMapping) + return m.UploadWithContext(context.Background(), path, authorization, request, responseMapping) +} + +func (m *ApiClientMock) UploadWithContext(ctx context.Context, path string, authorization *configuration.SdkAuthorization, request *common.FileUploadRequest, responseMapping interface{}) error { + args := m.Called(ctx, path, authorization, request, responseMapping) if args.Get(0) != nil { return args.Get(0).(error) diff --git a/payments/abc/client.go b/payments/abc/client.go index 25defb9..5bd9c5d 100644 --- a/payments/abc/client.go +++ b/payments/abc/client.go @@ -1,6 +1,7 @@ package abc import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -20,13 +21,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) RequestPayment(request PaymentRequest, idempotencyKey *string) (*PaymentResponse, error) { + return c.RequestPaymentWithContext(context.Background(), request, idempotencyKey) +} + +func (c *Client) RequestPaymentWithContext(ctx context.Context, request PaymentRequest, idempotencyKey *string) (*PaymentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response PaymentResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments), auth, request, @@ -41,6 +47,10 @@ func (c *Client) RequestPayment(request PaymentRequest, idempotencyKey *string) } func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentListResponse, error) { + return c.RequestPaymentListWithContext(context.Background(), request) +} + +func (c *Client) RequestPaymentListWithContext(ctx context.Context, request payments.QueryRequest) (*GetPaymentListResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err @@ -52,7 +62,7 @@ func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentL } var response GetPaymentListResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -61,13 +71,18 @@ func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentL } func (c *Client) RequestPayout(request PayoutRequest, idempotencyKey *string) (*PaymentResponse, error) { + return c.RequestPayoutWithContext(context.Background(), request, idempotencyKey) +} + +func (c *Client) RequestPayoutWithContext(ctx context.Context, request PayoutRequest, idempotencyKey *string) (*PaymentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response PaymentResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments), auth, request, @@ -82,13 +97,17 @@ func (c *Client) RequestPayout(request PayoutRequest, idempotencyKey *string) (* } func (c *Client) GetPaymentDetails(paymentId string) (*GetPaymentResponse, error) { + return c.GetPaymentDetailsWithContext(context.Background(), paymentId) +} + +func (c *Client) GetPaymentDetailsWithContext(ctx context.Context, paymentId string) (*GetPaymentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response GetPaymentResponse - err = c.apiClient.Get(common.BuildPath(payments.PathPayments, paymentId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(payments.PathPayments, paymentId), auth, &response) if err != nil { return nil, err } @@ -97,13 +116,18 @@ func (c *Client) GetPaymentDetails(paymentId string) (*GetPaymentResponse, error } func (c *Client) GetPaymentActions(paymentId string) (*GetPaymentActionsResponse, error) { + return c.GetPaymentActionsWithContext(context.Background(), paymentId) +} + +func (c *Client) GetPaymentActionsWithContext(ctx context.Context, paymentId string) (*GetPaymentActionsResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response GetPaymentActionsResponse - err = c.apiClient.Get( + err = c.apiClient.GetWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "actions"), auth, &response, @@ -119,6 +143,15 @@ func (c *Client) CapturePayment( paymentId string, captureRequest CaptureRequest, idempotencyKey *string, +) (*payments.CaptureResponse, error) { + return c.CapturePaymentWithContext(context.Background(), paymentId, captureRequest, idempotencyKey) +} + +func (c *Client) CapturePaymentWithContext( + ctx context.Context, + paymentId string, + captureRequest CaptureRequest, + idempotencyKey *string, ) (*payments.CaptureResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { @@ -126,7 +159,8 @@ func (c *Client) CapturePayment( } var response payments.CaptureResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "captures"), auth, captureRequest, @@ -168,6 +202,15 @@ func (c *Client) RefundPayment( paymentId string, refundRequest *payments.RefundRequest, idempotencyKey *string, +) (*payments.RefundResponse, error) { + return c.RefundPaymentWithContext(context.Background(), paymentId, refundRequest, idempotencyKey) +} + +func (c *Client) RefundPaymentWithContext( + ctx context.Context, + paymentId string, + refundRequest *payments.RefundRequest, + idempotencyKey *string, ) (*payments.RefundResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { @@ -175,7 +218,8 @@ func (c *Client) RefundPayment( } var response payments.RefundResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "refunds"), auth, refundRequest, @@ -193,6 +237,15 @@ func (c *Client) VoidPayment( paymentId string, voidRequest *payments.VoidRequest, idempotencyKey *string, +) (*payments.VoidResponse, error) { + return c.VoidPaymentWithContext(context.Background(), paymentId, voidRequest, idempotencyKey) +} + +func (c *Client) VoidPaymentWithContext( + ctx context.Context, + paymentId string, + voidRequest *payments.VoidRequest, + idempotencyKey *string, ) (*payments.VoidResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { @@ -200,7 +253,8 @@ func (c *Client) VoidPayment( } var response payments.VoidResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "voids"), auth, voidRequest, diff --git a/payments/abc/client_test.go b/payments/abc/client_test.go index c02b7e8..6033821 100644 --- a/payments/abc/client_test.go +++ b/payments/abc/client_test.go @@ -70,10 +70,10 @@ func TestRequestPayment(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).(*PaymentResponse) + respMapping := args.Get(4).(*PaymentResponse) *respMapping = paymentResponse }) }, @@ -94,7 +94,7 @@ func TestRequestPayment(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 *PaymentResponse, err error) { @@ -112,7 +112,7 @@ func TestRequestPayment(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, @@ -197,10 +197,10 @@ func TestRequestPaymentList(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).(*GetPaymentListResponse) + respMapping := args.Get(3).(*GetPaymentListResponse) *respMapping = paymentListResponse }) }, @@ -225,7 +225,7 @@ func TestRequestPaymentList(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 *GetPaymentListResponse, err error) { @@ -243,7 +243,7 @@ func TestRequestPaymentList(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, @@ -315,10 +315,10 @@ func TestRequestPayout(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).(*PaymentResponse) + respMapping := args.Get(4).(*PaymentResponse) *respMapping = paymentResponse }) }, @@ -338,7 +338,7 @@ func TestRequestPayout(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 *PaymentResponse, err error) { @@ -356,7 +356,7 @@ func TestRequestPayout(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, @@ -423,10 +423,10 @@ func TestGetPaymentDetails(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).(*GetPaymentResponse) + respMapping := args.Get(3).(*GetPaymentResponse) *respMapping = paymentResponse }) }, @@ -448,7 +448,7 @@ func TestGetPaymentDetails(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 *GetPaymentResponse, err error) { @@ -466,7 +466,7 @@ func TestGetPaymentDetails(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, @@ -535,10 +535,10 @@ func TestGetPaymentActions(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).(*GetPaymentActionsResponse) + respMapping := args.Get(3).(*GetPaymentActionsResponse) *respMapping = paymentActionsResponse }) }, @@ -557,7 +557,7 @@ func TestGetPaymentActions(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 *GetPaymentActionsResponse, err error) { @@ -576,7 +576,7 @@ func TestGetPaymentActions(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, @@ -642,10 +642,10 @@ func TestCapturePayment(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).(*payments.CaptureResponse) + respMapping := args.Get(4).(*payments.CaptureResponse) *respMapping = captureResponse }) }, @@ -664,7 +664,7 @@ func TestCapturePayment(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 *payments.CaptureResponse, err error) { @@ -683,7 +683,7 @@ func TestCapturePayment(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.StatusForbidden}) }, @@ -703,7 +703,7 @@ func TestCapturePayment(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.StatusNotFound, @@ -726,7 +726,7 @@ func TestCapturePayment(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, @@ -798,10 +798,10 @@ func TestRefundPayment(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).(*payments.RefundResponse) + respMapping := args.Get(4).(*payments.RefundResponse) *respMapping = refundResponse }) }, @@ -820,7 +820,7 @@ func TestRefundPayment(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 *payments.RefundResponse, err error) { @@ -838,7 +838,7 @@ func TestRefundPayment(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.StatusForbidden}) }, @@ -857,7 +857,7 @@ func TestRefundPayment(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.StatusNotFound, @@ -879,7 +879,7 @@ func TestRefundPayment(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, @@ -950,10 +950,10 @@ func TestVoidPayment(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).(*payments.VoidResponse) + respMapping := args.Get(4).(*payments.VoidResponse) *respMapping = voidResponse }) }, @@ -972,7 +972,7 @@ func TestVoidPayment(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 *payments.VoidResponse, err error) { @@ -990,7 +990,7 @@ func TestVoidPayment(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.StatusForbidden}) }, @@ -1009,7 +1009,7 @@ func TestVoidPayment(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.StatusNotFound, @@ -1031,7 +1031,7 @@ func TestVoidPayment(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, diff --git a/payments/hosted/client.go b/payments/hosted/client.go index 3852c2f..0bf4925 100644 --- a/payments/hosted/client.go +++ b/payments/hosted/client.go @@ -1,6 +1,7 @@ package hosted import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) CreateHostedPaymentsPageSession(request HostedPaymentRequest) (*HostedPaymentResponse, error) { + return c.CreateHostedPaymentsPageSessionWithContext(context.Background(), request) +} + +func (c *Client) CreateHostedPaymentsPageSessionWithContext(ctx context.Context, request HostedPaymentRequest) (*HostedPaymentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response HostedPaymentResponse - err = c.apiClient.Post(common.BuildPath(HostedPaymentsPath), auth, request, &response, nil) + err = c.apiClient.PostWithContext(ctx, common.BuildPath(HostedPaymentsPath), auth, request, &response, nil) if err != nil { return nil, err } @@ -34,13 +39,17 @@ func (c *Client) CreateHostedPaymentsPageSession(request HostedPaymentRequest) ( } func (c *Client) GetHostedPaymentsPageDetails(hostedPaymentId string) (*HostedPaymentDetails, error) { + return c.GetHostedPaymentsPageDetailsWithContext(context.Background(), hostedPaymentId) +} + +func (c *Client) GetHostedPaymentsPageDetailsWithContext(ctx context.Context, hostedPaymentId string) (*HostedPaymentDetails, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response HostedPaymentDetails - err = c.apiClient.Get(common.BuildPath(HostedPaymentsPath, hostedPaymentId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(HostedPaymentsPath, hostedPaymentId), auth, &response) if err != nil { return nil, err } diff --git a/payments/hosted/client_test.go b/payments/hosted/client_test.go index 5f3c76a..22c1e6f 100644 --- a/payments/hosted/client_test.go +++ b/payments/hosted/client_test.go @@ -44,11 +44,11 @@ func TestCreateHostedPaymentsPageSession(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).(*HostedPaymentResponse) - *respMapping = hostedPaymentResponse + respMapping := args.Get(4).(*HostedPaymentResponse) + *respMapping = hostedPayementResponse }) }, checker: func(response *HostedPaymentResponse, err error) { @@ -82,7 +82,7 @@ func TestCreateHostedPaymentsPageSession(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, @@ -145,10 +145,10 @@ func TestGetHostedPaymentsPageDetails(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).(*HostedPaymentDetails) + respMapping := args.Get(3).(*HostedPaymentDetails) *respMapping = hostedPaymentDetails }) }, @@ -189,7 +189,7 @@ func TestGetHostedPaymentsPageDetails(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, diff --git a/payments/links/client.go b/payments/links/client.go index 0a55b16..4fe8a33 100644 --- a/payments/links/client.go +++ b/payments/links/client.go @@ -1,6 +1,7 @@ package links import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,17 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) CreatePaymentLink(request PaymentLinkRequest) (*PaymentLinkResponse, error) { + return c.CreatePaymentLinkWithContext(context.Background(), request) +} + +func (c *Client) CreatePaymentLinkWithContext(ctx context.Context, request PaymentLinkRequest) (*PaymentLinkResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response PaymentLinkResponse - err = c.apiClient.Post(common.BuildPath(PaymentLinksPath), auth, request, &response, nil) + err = c.apiClient.PostWithContext(ctx, common.BuildPath(PaymentLinksPath), auth, request, &response, nil) if err != nil { return nil, err } @@ -34,13 +39,17 @@ func (c *Client) CreatePaymentLink(request PaymentLinkRequest) (*PaymentLinkResp } func (c *Client) GetPaymentLink(paymentLinkId string) (*PaymentLinkDetails, error) { + return c.GetPaymentLinkWithContext(context.Background(), paymentLinkId) +} + +func (c *Client) GetPaymentLinkWithContext(ctx context.Context, paymentLinkId string) (*PaymentLinkDetails, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response PaymentLinkDetails - err = c.apiClient.Get(common.BuildPath(PaymentLinksPath, paymentLinkId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(PaymentLinksPath, paymentLinkId), auth, &response) if err != nil { return nil, err } diff --git a/payments/links/client_test.go b/payments/links/client_test.go index ba76ccd..62406c8 100644 --- a/payments/links/client_test.go +++ b/payments/links/client_test.go @@ -44,10 +44,10 @@ func TestCreatePaymentLink(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).(*PaymentLinkResponse) + respMapping := args.Get(4).(*PaymentLinkResponse) *respMapping = payementLinkResponse }) }, @@ -64,7 +64,7 @@ func TestCreatePaymentLink(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 *PaymentLinkResponse, err error) { @@ -82,7 +82,7 @@ func TestCreatePaymentLink(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, @@ -145,10 +145,10 @@ func TestGetPaymentLink(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).(*PaymentLinkDetails) + respMapping := args.Get(3).(*PaymentLinkDetails) *respMapping = paymentLinkDetails }) }, @@ -171,7 +171,7 @@ func TestGetPaymentLink(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 *PaymentLinkDetails, err error) { @@ -189,7 +189,7 @@ func TestGetPaymentLink(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, diff --git a/payments/nas/client.go b/payments/nas/client.go index 3b78887..80cdc6e 100644 --- a/payments/nas/client.go +++ b/payments/nas/client.go @@ -1,6 +1,8 @@ package nas import ( + "context" + "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -20,13 +22,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) RequestPayment(request PaymentRequest, idempotencyKey *string) (*PaymentResponse, error) { + return c.RequestPaymentWithContext(context.Background(), request, idempotencyKey) +} + +func (c *Client) RequestPaymentWithContext(ctx context.Context, request PaymentRequest, idempotencyKey *string) (*PaymentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response PaymentResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments), auth, request, @@ -41,6 +48,10 @@ func (c *Client) RequestPayment(request PaymentRequest, idempotencyKey *string) } func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentListResponse, error) { + return c.RequestPaymentListWithContext(context.Background(), request) +} + +func (c *Client) RequestPaymentListWithContext(ctx context.Context, request payments.QueryRequest) (*GetPaymentListResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err @@ -52,7 +63,7 @@ func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentL } var response GetPaymentListResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -61,13 +72,18 @@ func (c *Client) RequestPaymentList(request payments.QueryRequest) (*GetPaymentL } func (c *Client) RequestPayout(request PayoutRequest, idempotencyKey *string) (*PayoutResponse, error) { + return c.RequestPayoutWithContext(context.Background(), request, idempotencyKey) +} + +func (c *Client) RequestPayoutWithContext(ctx context.Context, request PayoutRequest, idempotencyKey *string) (*PayoutResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response PayoutResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments), auth, request, @@ -82,13 +98,17 @@ func (c *Client) RequestPayout(request PayoutRequest, idempotencyKey *string) (* } func (c *Client) GetPaymentDetails(paymentId string) (*GetPaymentResponse, error) { + return c.GetPaymentDetailsWithContext(context.Background(), paymentId) +} + +func (c *Client) GetPaymentDetailsWithContext(ctx context.Context, paymentId string) (*GetPaymentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response GetPaymentResponse - err = c.apiClient.Get(common.BuildPath(payments.PathPayments, paymentId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(payments.PathPayments, paymentId), auth, &response) if err != nil { return nil, err } @@ -97,13 +117,18 @@ func (c *Client) GetPaymentDetails(paymentId string) (*GetPaymentResponse, error } func (c *Client) GetPaymentActions(paymentId string) (*GetPaymentActionsResponse, error) { + return c.GetPaymentActionsWithContext(context.Background(), paymentId) +} + +func (c *Client) GetPaymentActionsWithContext(ctx context.Context, paymentId string) (*GetPaymentActionsResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { return nil, err } var response GetPaymentActionsResponse - err = c.apiClient.Get( + err = c.apiClient.GetWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "actions"), auth, &response, @@ -144,6 +169,15 @@ func (c *Client) CapturePayment( paymentId string, captureRequest CaptureRequest, idempotencyKey *string, +) (*payments.CaptureResponse, error) { + return c.CapturePaymentWithContext(context.Background(), paymentId, captureRequest, idempotencyKey) +} + +func (c *Client) CapturePaymentWithContext( + ctx context.Context, + paymentId string, + captureRequest CaptureRequest, + idempotencyKey *string, ) (*payments.CaptureResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { @@ -151,7 +185,8 @@ func (c *Client) CapturePayment( } var response payments.CaptureResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "captures"), auth, captureRequest, @@ -193,6 +228,15 @@ func (c *Client) RefundPayment( paymentId string, refundRequest *payments.RefundRequest, idempotencyKey *string, +) (*payments.RefundResponse, error) { + return c.RefundPaymentWithContext(context.Background(), paymentId, refundRequest, idempotencyKey) +} + +func (c *Client) RefundPaymentWithContext( + ctx context.Context, + paymentId string, + refundRequest *payments.RefundRequest, + idempotencyKey *string, ) (*payments.RefundResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { @@ -200,7 +244,8 @@ func (c *Client) RefundPayment( } var response payments.RefundResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "refunds"), auth, refundRequest, @@ -218,6 +263,15 @@ func (c *Client) VoidPayment( paymentId string, voidRequest *payments.VoidRequest, idempotencyKey *string, +) (*payments.VoidResponse, error) { + return c.VoidPaymentWithContext(context.Background(), paymentId, voidRequest, idempotencyKey) +} + +func (c *Client) VoidPaymentWithContext( + ctx context.Context, + paymentId string, + voidRequest *payments.VoidRequest, + idempotencyKey *string, ) (*payments.VoidResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth) if err != nil { @@ -225,7 +279,8 @@ func (c *Client) VoidPayment( } var response payments.VoidResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(payments.PathPayments, paymentId, "voids"), auth, voidRequest, diff --git a/payments/nas/client_test.go b/payments/nas/client_test.go index 82e275a..4095e00 100644 --- a/payments/nas/client_test.go +++ b/payments/nas/client_test.go @@ -71,10 +71,10 @@ func TestRequestPayment(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).(*PaymentResponse) + respMapping := args.Get(4).(*PaymentResponse) *respMapping = paymentResponse }) }, @@ -113,7 +113,7 @@ func TestRequestPayment(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, @@ -198,10 +198,10 @@ func TestRequestPaymentList(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).(*GetPaymentListResponse) + respMapping := args.Get(3).(*GetPaymentListResponse) *respMapping = paymentListResponse }) }, @@ -227,7 +227,7 @@ func TestRequestPaymentList(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 *GetPaymentListResponse, err error) { @@ -245,7 +245,7 @@ func TestRequestPaymentList(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, @@ -310,10 +310,10 @@ func TestRequestPayout(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).(*PayoutResponse) + respMapping := args.Get(4).(*PayoutResponse) *respMapping = payoutResponse }) }, @@ -331,7 +331,7 @@ func TestRequestPayout(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 *PayoutResponse, err error) { @@ -349,7 +349,7 @@ func TestRequestPayout(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, @@ -416,10 +416,10 @@ func TestGetPaymentDetails(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).(*GetPaymentResponse) + respMapping := args.Get(3).(*GetPaymentResponse) *respMapping = paymentResponse }) }, @@ -441,7 +441,7 @@ func TestGetPaymentDetails(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 *GetPaymentResponse, err error) { @@ -459,7 +459,7 @@ func TestGetPaymentDetails(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, @@ -528,10 +528,10 @@ func TestGetPaymentActions(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).(*GetPaymentActionsResponse) + respMapping := args.Get(3).(*GetPaymentActionsResponse) *respMapping = paymentActionsResponse }) }, @@ -550,7 +550,7 @@ func TestGetPaymentActions(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 *GetPaymentActionsResponse, err error) { @@ -569,7 +569,7 @@ func TestGetPaymentActions(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, @@ -834,10 +834,10 @@ func TestCapturePayment(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).(*payments.CaptureResponse) + respMapping := args.Get(4).(*payments.CaptureResponse) *respMapping = captureResponse }) }, @@ -856,7 +856,7 @@ func TestCapturePayment(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 *payments.CaptureResponse, err error) { @@ -875,7 +875,7 @@ func TestCapturePayment(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.StatusForbidden}) }, @@ -895,7 +895,7 @@ func TestCapturePayment(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.StatusNotFound, @@ -918,7 +918,7 @@ func TestCapturePayment(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, @@ -990,10 +990,10 @@ func TestRefundPayment(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).(*payments.RefundResponse) + respMapping := args.Get(4).(*payments.RefundResponse) *respMapping = refundResponse }) }, @@ -1012,7 +1012,7 @@ func TestRefundPayment(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 *payments.RefundResponse, err error) { @@ -1030,7 +1030,7 @@ func TestRefundPayment(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.StatusForbidden}) }, @@ -1049,7 +1049,7 @@ func TestRefundPayment(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.StatusNotFound, @@ -1071,7 +1071,7 @@ func TestRefundPayment(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, @@ -1142,10 +1142,10 @@ func TestVoidPayment(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).(*payments.VoidResponse) + respMapping := args.Get(4).(*payments.VoidResponse) *respMapping = voidResponse }) }, @@ -1164,7 +1164,7 @@ func TestVoidPayment(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 *payments.VoidResponse, err error) { @@ -1182,7 +1182,7 @@ func TestVoidPayment(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.StatusForbidden}) }, @@ -1201,7 +1201,7 @@ func TestVoidPayment(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.StatusNotFound, @@ -1223,7 +1223,7 @@ func TestVoidPayment(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, diff --git a/reconciliation/client.go b/reconciliation/client.go index 60d7360..d420eaa 100644 --- a/reconciliation/client.go +++ b/reconciliation/client.go @@ -1,6 +1,7 @@ package reconciliation import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,6 +20,10 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) QueryPaymentsReport(query PaymentReportsQuery) (*PaymentReportsResponse, error) { + return c.QueryPaymentsReportWithContext(context.Background(), query) +} + +func (c *Client) QueryPaymentsReportWithContext(ctx context.Context, query PaymentReportsQuery) (*PaymentReportsResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err @@ -30,7 +35,7 @@ func (c *Client) QueryPaymentsReport(query PaymentReportsQuery) (*PaymentReports } var response PaymentReportsResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -39,13 +44,17 @@ func (c *Client) QueryPaymentsReport(query PaymentReportsQuery) (*PaymentReports } func (c *Client) GetSinglePaymentReport(paymentId string) (*PaymentReportsResponse, error) { + return c.GetSinglePaymentReportWithContext(context.Background(), paymentId) +} + +func (c *Client) GetSinglePaymentReportWithContext(ctx context.Context, paymentId string) (*PaymentReportsResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response PaymentReportsResponse - err = c.apiClient.Get(common.BuildPath(reporting, payments, paymentId), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(reporting, payments, paymentId), auth, &response) if err != nil { return nil, err } @@ -54,6 +63,10 @@ func (c *Client) GetSinglePaymentReport(paymentId string) (*PaymentReportsRespon } func (c *Client) QueryStatementsReport(query common.DateRangeQuery) (*StatementReportsResponse, error) { + return c.QueryStatementsReportWithContext(context.Background(), query) +} + +func (c *Client) QueryStatementsReportWithContext(ctx context.Context, query common.DateRangeQuery) (*StatementReportsResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err @@ -65,7 +78,7 @@ func (c *Client) QueryStatementsReport(query common.DateRangeQuery) (*StatementR } var response StatementReportsResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -74,6 +87,10 @@ func (c *Client) QueryStatementsReport(query common.DateRangeQuery) (*StatementR } func (c *Client) RetrieveCVSPaymentsReport(query common.DateRangeQuery) (*common.ContentResponse, error) { + return c.RetrieveCVSPaymentsReportWithContext(context.Background(), query) +} + +func (c *Client) RetrieveCVSPaymentsReportWithContext(ctx context.Context, query common.DateRangeQuery) (*common.ContentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err @@ -85,7 +102,7 @@ func (c *Client) RetrieveCVSPaymentsReport(query common.DateRangeQuery) (*common } var response common.ContentResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } @@ -94,13 +111,17 @@ func (c *Client) RetrieveCVSPaymentsReport(query common.DateRangeQuery) (*common } func (c *Client) RetrieveCVSSingleStatementReport(statementId string) (*common.ContentResponse, error) { + return c.RetrieveCVSSingleStatementReportWithContext(context.Background(), statementId) +} + +func (c *Client) RetrieveCVSSingleStatementReportWithContext(ctx context.Context, statementId string) (*common.ContentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response common.ContentResponse - err = c.apiClient.Get(common.BuildPath(reporting, statements, statementId, payments, download), auth, &response) + err = c.apiClient.GetWithContext(ctx, common.BuildPath(reporting, statements, statementId, payments, download), auth, &response) if err != nil { return nil, err } @@ -109,6 +130,10 @@ func (c *Client) RetrieveCVSSingleStatementReport(statementId string) (*common.C } func (c *Client) RetrieveCVSStatementsReport(query common.DateRangeQuery) (*common.ContentResponse, error) { + return c.RetrieveCVSStatementsReportWithContext(context.Background(), query) +} + +func (c *Client) RetrieveCVSStatementsReportWithContext(ctx context.Context, query common.DateRangeQuery) (*common.ContentResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err @@ -120,7 +145,7 @@ func (c *Client) RetrieveCVSStatementsReport(query common.DateRangeQuery) (*comm } var response common.ContentResponse - err = c.apiClient.Get(url, auth, &response) + err = c.apiClient.GetWithContext(ctx, url, auth, &response) if err != nil { return nil, err } diff --git a/reconciliation/client_test.go b/reconciliation/client_test.go index dcfd241..4c58c49 100644 --- a/reconciliation/client_test.go +++ b/reconciliation/client_test.go @@ -54,10 +54,10 @@ func TestQueryPaymentsReport(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).(*PaymentReportsResponse) + respMapping := args.Get(3).(*PaymentReportsResponse) *respMapping = reportResponse }) }, @@ -75,7 +75,7 @@ func TestQueryPaymentsReport(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 *PaymentReportsResponse, err error) { @@ -136,10 +136,10 @@ func TestGetSinglePaymentReport(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).(*PaymentReportsResponse) + respMapping := args.Get(3).(*PaymentReportsResponse) *respMapping = reportResponse }) }, @@ -157,7 +157,7 @@ func TestGetSinglePaymentReport(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 *PaymentReportsResponse, err error) { @@ -175,7 +175,7 @@ func TestGetSinglePaymentReport(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, @@ -252,10 +252,10 @@ func TestQueryStatementsReport(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).(*StatementReportsResponse) + respMapping := args.Get(3).(*StatementReportsResponse) *respMapping = reportResponse }) }, @@ -273,7 +273,7 @@ func TestQueryStatementsReport(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 *StatementReportsResponse, err error) { @@ -331,10 +331,10 @@ func TestRetrieveCVSPaymentsReport(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).(*common.ContentResponse) + respMapping := args.Get(3).(*common.ContentResponse) *respMapping = contentResponse }) }, @@ -352,7 +352,7 @@ func TestRetrieveCVSPaymentsReport(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 *common.ContentResponse, err error) { @@ -404,10 +404,10 @@ func TestRetrieveCVSSingleStatementReport(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).(*common.ContentResponse) + respMapping := args.Get(3).(*common.ContentResponse) *respMapping = contentResponse }) }, @@ -425,7 +425,7 @@ func TestRetrieveCVSSingleStatementReport(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 *common.ContentResponse, err error) { @@ -443,7 +443,7 @@ func TestRetrieveCVSSingleStatementReport(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, @@ -506,10 +506,10 @@ func TestRetrieveCVSStatementsReport(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).(*common.ContentResponse) + respMapping := args.Get(3).(*common.ContentResponse) *respMapping = contentResponse }) }, @@ -527,7 +527,7 @@ func TestRetrieveCVSStatementsReport(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 *common.ContentResponse, err error) { diff --git a/sessions/client_test.go b/sessions/client_test.go index b2a7657..a22cb9f 100644 --- a/sessions/client_test.go +++ b/sessions/client_test.go @@ -50,10 +50,10 @@ func TestRequestSession(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).(*SessionDetails) + respMapping := args.Get(4).(*SessionDetails) *respMapping = sessionDetails }) }, @@ -71,7 +71,7 @@ func TestRequestSession(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 *SessionResponse, err error) { @@ -89,7 +89,7 @@ func TestRequestSession(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, @@ -157,10 +157,10 @@ func TestGetSessionDetails(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).(*GetSessionResponse) + respMapping := args.Get(3).(*GetSessionResponse) *respMapping = sessionResponse }) }, @@ -179,7 +179,7 @@ func TestGetSessionDetails(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 *GetSessionResponse, err error) { @@ -197,7 +197,7 @@ func TestGetSessionDetails(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, @@ -261,10 +261,10 @@ func TestUpdateSession(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).(*GetSessionResponse) + respMapping := args.Get(4).(*GetSessionResponse) *respMapping = sessionResponse }) }, @@ -282,7 +282,7 @@ func TestUpdateSession(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, 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) }, checker: func(response *GetSessionResponse, err error) { @@ -300,7 +300,7 @@ func TestUpdateSession(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, @@ -353,10 +353,10 @@ func TestCompleteSession(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 = response }) }, @@ -373,7 +373,7 @@ func TestCompleteSession(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) { @@ -391,7 +391,7 @@ func TestCompleteSession(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.StatusNotFound, @@ -450,10 +450,10 @@ func TestUpdate3dsMethodCompletion(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).(*Update3dsMethodCompletionResponse) + respMapping := args.Get(4).(*Update3dsMethodCompletionResponse) *respMapping = sessionResponse }) }, @@ -471,7 +471,7 @@ func TestUpdate3dsMethodCompletion(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, 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) }, checker: func(response *Update3dsMethodCompletionResponse, err error) { @@ -489,7 +489,7 @@ func TestUpdate3dsMethodCompletion(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, diff --git a/sources/client.go b/sources/client.go index 65896b7..bf19ba7 100644 --- a/sources/client.go +++ b/sources/client.go @@ -1,6 +1,7 @@ package sources import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) CreateSepaSource(request *sepaSourceRequest) (*CreateSepaSourceResponse, error) { + return c.CreateSepaSourceWithContext(context.Background(), request) +} + +func (c *Client) CreateSepaSourceWithContext(ctx context.Context, request *sepaSourceRequest) (*CreateSepaSourceResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response CreateSepaSourceResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(path), auth, request, diff --git a/sources/client_test.go b/sources/client_test.go index e928d14..aaff06e 100644 --- a/sources/client_test.go +++ b/sources/client_test.go @@ -53,10 +53,10 @@ func TestCreateSepaSource(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).(*CreateSepaSourceResponse) + respMapping := args.Get(4).(*CreateSepaSourceResponse) *respMapping = sepaResponse }) }, @@ -74,7 +74,7 @@ func TestCreateSepaSource(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 *CreateSepaSourceResponse, err error) { @@ -92,7 +92,7 @@ func TestCreateSepaSource(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, diff --git a/tokens/client.go b/tokens/client.go index 68ec13c..6878cc9 100644 --- a/tokens/client.go +++ b/tokens/client.go @@ -1,6 +1,7 @@ package tokens import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) RequestCardToken(request CardTokenRequest) (*CardTokenResponse, error) { + return c.RequestCardTokenWithContext(context.Background(), request) +} + +func (c *Client) RequestCardTokenWithContext(ctx context.Context, request CardTokenRequest) (*CardTokenResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.PublicKey) if err != nil { return nil, err } var response CardTokenResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(tokensPath), auth, request, @@ -40,13 +46,18 @@ func (c *Client) RequestCardToken(request CardTokenRequest) (*CardTokenResponse, } func (c *Client) RequestWalletToken(request WalletTokenRequest) (*CardTokenResponse, error) { + return c.RequestWalletTokenWithContext(context.Background(), request) +} + +func (c *Client) RequestWalletTokenWithContext(ctx context.Context, request WalletTokenRequest) (*CardTokenResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.PublicKey) if err != nil { return nil, err } var response CardTokenResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(tokensPath), auth, request, diff --git a/tokens/client_test.go b/tokens/client_test.go index 7c0d8c4..e062d8b 100644 --- a/tokens/client_test.go +++ b/tokens/client_test.go @@ -58,10 +58,10 @@ func TestRequestCardToken(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).(*CardTokenResponse) + respMapping := args.Get(4).(*CardTokenResponse) *respMapping = cardTokenResponse }) }, @@ -83,7 +83,7 @@ func TestRequestCardToken(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 *CardTokenResponse, err error) { @@ -101,7 +101,7 @@ func TestRequestCardToken(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, diff --git a/transfers/client_test.go b/transfers/client_test.go index 5e0aca0..319f8cf 100644 --- a/transfers/client_test.go +++ b/transfers/client_test.go @@ -43,10 +43,10 @@ func TestInitiateTransferOfFounds(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).(*TransferResponse) + respMapping := args.Get(4).(*TransferResponse) *respMapping = transfer }) }, @@ -65,7 +65,7 @@ func TestInitiateTransferOfFounds(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 *TransferResponse, err error) { @@ -83,7 +83,7 @@ func TestInitiateTransferOfFounds(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, @@ -158,10 +158,10 @@ func TestRetrieveTransfer(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).(*TransferDetails) + respMapping := args.Get(3).(*TransferDetails) *respMapping = transferDetails }) }, @@ -184,7 +184,7 @@ func TestRetrieveTransfer(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 *TransferDetails, err error) { @@ -202,7 +202,7 @@ func TestRetrieveTransfer(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, diff --git a/webhooks/abc/client.go b/webhooks/abc/client.go index a8887b6..77e1ec8 100644 --- a/webhooks/abc/client.go +++ b/webhooks/abc/client.go @@ -1,6 +1,7 @@ package abc import ( + "context" "github.com/checkout/checkout-sdk-go/client" "github.com/checkout/checkout-sdk-go/common" "github.com/checkout/checkout-sdk-go/configuration" @@ -19,13 +20,18 @@ func NewClient(configuration *configuration.Configuration, apiClient client.Http } func (c *Client) RetrieveWebhooks() (*WebhooksResponse, error) { + return c.RetrieveWebhooksWithContext(context.Background()) +} + +func (c *Client) RetrieveWebhooksWithContext(ctx context.Context) (*WebhooksResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response WebhooksResponse - err = c.apiClient.Get( + err = c.apiClient.GetWithContext( + ctx, common.BuildPath(webhooks), auth, &response, @@ -38,13 +44,18 @@ func (c *Client) RetrieveWebhooks() (*WebhooksResponse, error) { } func (c *Client) RegisterWebhook(request WebhookRequest) (*WebhookResponse, error) { + return c.RegisterWebhookWithContext(context.Background(), request) +} + +func (c *Client) RegisterWebhookWithContext(ctx context.Context, request WebhookRequest) (*WebhookResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response WebhookResponse - err = c.apiClient.Post( + err = c.apiClient.PostWithContext( + ctx, common.BuildPath(webhooks), auth, request, @@ -59,13 +70,18 @@ func (c *Client) RegisterWebhook(request WebhookRequest) (*WebhookResponse, erro } func (c *Client) RetrieveWebhook(webhookId string) (*WebhookResponse, error) { + return c.RetrieveWebhookWithContext(context.Background(), webhookId) +} + +func (c *Client) RetrieveWebhookWithContext(ctx context.Context, webhookId string) (*WebhookResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response WebhookResponse - err = c.apiClient.Get( + err = c.apiClient.GetWithContext( + ctx, common.BuildPath(webhooks, webhookId), auth, &response, @@ -78,13 +94,18 @@ func (c *Client) RetrieveWebhook(webhookId string) (*WebhookResponse, error) { } func (c *Client) UpdateWebhook(webhookId string, request WebhookRequest) (*WebhookResponse, error) { + return c.UpdateWebhookWithContext(context.Background(), webhookId, request) +} + +func (c *Client) UpdateWebhookWithContext(ctx context.Context, webhookId string, request WebhookRequest) (*WebhookResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response WebhookResponse - err = c.apiClient.Put( + err = c.apiClient.PutWithContext( + ctx, common.BuildPath(webhooks, webhookId), auth, request, @@ -99,13 +120,18 @@ func (c *Client) UpdateWebhook(webhookId string, request WebhookRequest) (*Webho } func (c *Client) PartiallyUpdateWebhook(webhookId string, request WebhookRequest) (*WebhookResponse, error) { + return c.PartiallyUpdateWebhookWithContext(context.Background(), webhookId, request) +} + +func (c *Client) PartiallyUpdateWebhookWithContext(ctx context.Context, webhookId string, request WebhookRequest) (*WebhookResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response WebhookResponse - err = c.apiClient.Patch( + err = c.apiClient.PatchWithContext( + ctx, common.BuildPath(webhooks, webhookId), auth, request, @@ -119,13 +145,18 @@ func (c *Client) PartiallyUpdateWebhook(webhookId string, request WebhookRequest } func (c *Client) RemoveWebhook(webhookId string) (*common.MetadataResponse, error) { + return c.RemoveWebhookWithContext(context.Background(), webhookId) +} + +func (c *Client) RemoveWebhookWithContext(ctx context.Context, webhookId string) (*common.MetadataResponse, error) { auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKey) if err != nil { return nil, err } var response common.MetadataResponse - err = c.apiClient.Delete( + err = c.apiClient.DeleteWithContext( + ctx, common.BuildPath(webhooks, webhookId), auth, &response, diff --git a/webhooks/abc/client_test.go b/webhooks/abc/client_test.go index ce48021..d2c5f5e 100644 --- a/webhooks/abc/client_test.go +++ b/webhooks/abc/client_test.go @@ -57,10 +57,10 @@ func TestClientRetrieveWebhooks(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).(*WebhooksResponse) + respMapping := args.Get(3).(*WebhooksResponse) *respMapping = response }) }, @@ -77,10 +77,10 @@ func TestClientRetrieveWebhooks(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).(*WebhooksResponse) + respMapping := args.Get(3).(*WebhooksResponse) *respMapping = WebhooksResponse{ HttpResponse: mocks.HttpMetadataStatusNoContent, } @@ -99,7 +99,7 @@ func TestClientRetrieveWebhooks(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.StatusUnauthorized, @@ -198,11 +198,11 @@ func TestClientRegisterWebhook(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).(*WebhookResponse) + respMapping := args.Get(4).(*WebhookResponse) *respMapping = response }) }, @@ -219,8 +219,8 @@ func TestClientRegisterWebhook(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 *WebhookResponse, err error) { @@ -238,8 +238,8 @@ func TestClientRegisterWebhook(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, @@ -322,10 +322,10 @@ func TestClientRetrieveWebhook(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).(*WebhookResponse) + respMapping := args.Get(3).(*WebhookResponse) *respMapping = response }) }, @@ -343,7 +343,7 @@ func TestClientRetrieveWebhook(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.StatusUnauthorized, @@ -366,7 +366,7 @@ func TestClientRetrieveWebhook(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, @@ -466,10 +466,10 @@ func TestClientUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiUpdate: 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).(*WebhookResponse) + respMapping := args.Get(4).(*WebhookResponse) *respMapping = response }) }, @@ -487,7 +487,7 @@ func TestClientUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiUpdate: 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.StatusUnauthorized, @@ -510,7 +510,7 @@ func TestClientUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiUpdate: 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, @@ -532,7 +532,7 @@ func TestClientUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiUpdate: 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.StatusConflict, @@ -554,7 +554,7 @@ func TestClientUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiUpdate: 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.StatusUnprocessableEntity, @@ -660,10 +660,10 @@ func TestClientPartiallyUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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).(*WebhookResponse) + respMapping := args.Get(4).(*WebhookResponse) *respMapping = response }) }, @@ -681,7 +681,7 @@ func TestClientPartiallyUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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.StatusUnauthorized, @@ -704,7 +704,7 @@ func TestClientPartiallyUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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, @@ -726,7 +726,7 @@ func TestClientPartiallyUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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.StatusConflict, @@ -748,7 +748,7 @@ func TestClientPartiallyUpdateWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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.StatusUnprocessableEntity, @@ -809,10 +809,10 @@ func TestClientRemoveWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Run(func(args mock.Arguments) { - respMapping := args.Get(2).(*common.MetadataResponse) + respMapping := args.Get(3).(*common.MetadataResponse) *respMapping = response }) }, @@ -830,7 +830,7 @@ func TestClientRemoveWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusUnauthorized, @@ -853,7 +853,7 @@ func TestClientRemoveWebhook(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, diff --git a/workflows/client_test.go b/workflows/client_test.go index 94806e6..3ae4a92 100644 --- a/workflows/client_test.go +++ b/workflows/client_test.go @@ -45,10 +45,10 @@ func TestCreateWorkflow(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 = response }) }, @@ -65,7 +65,7 @@ func TestCreateWorkflow(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) { @@ -83,7 +83,7 @@ func TestCreateWorkflow(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, @@ -150,10 +150,10 @@ func TestGetWorkflows(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).(*GetWorkflowsResponse) + respMapping := args.Get(3).(*GetWorkflowsResponse) *respMapping = workflowsResponse }) }, @@ -171,7 +171,7 @@ func TestGetWorkflows(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 *GetWorkflowsResponse, err error) { @@ -229,10 +229,10 @@ func TestGetWorkflow(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).(*GetWorkflowResponse) + respMapping := args.Get(3).(*GetWorkflowResponse) *respMapping = workflowResponse }) }, @@ -252,7 +252,7 @@ func TestGetWorkflow(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 *GetWorkflowResponse, err error) { @@ -270,7 +270,7 @@ func TestGetWorkflow(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, @@ -333,10 +333,10 @@ func TestUpdateWorkflow(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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).(*UpdateWorkflowResponse) + respMapping := args.Get(4).(*UpdateWorkflowResponse) *respMapping = updateResponse }) }, @@ -356,7 +356,7 @@ func TestUpdateWorkflow(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiPatch: 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) }, checker: func(response *UpdateWorkflowResponse, err error) { @@ -374,7 +374,7 @@ func TestUpdateWorkflow(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiPatch: 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, @@ -427,10 +427,10 @@ func TestRemoveWorkflow(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Run(func(args mock.Arguments) { - respMapping := args.Get(2).(*common.MetadataResponse) + respMapping := args.Get(3).(*common.MetadataResponse) *respMapping = response }) }, @@ -447,7 +447,7 @@ func TestRemoveWorkflow(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) }, checker: func(response *common.MetadataResponse, err error) { @@ -465,7 +465,7 @@ func TestRemoveWorkflow(t *testing.T) { Return(&configuration.SdkAuthorization{}, nil) }, apiDelete: func(m *mock.Mock) mock.Call { - return *m.On("Delete", mock.Anything, mock.Anything, mock.Anything). + return *m.On("DeleteWithContext", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return( errors.CheckoutAPIError{ StatusCode: http.StatusNotFound, @@ -522,10 +522,10 @@ func TestUpdateWorkflowAction(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.MetadataResponse) + respMapping := args.Get(4).(*common.MetadataResponse) *respMapping = response }) }, @@ -544,7 +544,7 @@ func TestUpdateWorkflowAction(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, 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) }, checker: func(response *common.MetadataResponse, err error) { @@ -563,7 +563,7 @@ func TestUpdateWorkflowAction(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, @@ -586,7 +586,7 @@ func TestUpdateWorkflowAction(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, @@ -643,10 +643,10 @@ func TestUpdateWorkflowCondition(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.MetadataResponse) + respMapping := args.Get(4).(*common.MetadataResponse) *respMapping = response }) }, @@ -665,7 +665,7 @@ func TestUpdateWorkflowCondition(t *testing.T) { Return(nil, errors.CheckoutAuthorizationError("Invalid authorization type")) }, 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) }, checker: func(response *common.MetadataResponse, err error) { @@ -684,7 +684,7 @@ func TestUpdateWorkflowCondition(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, @@ -707,7 +707,7 @@ func TestUpdateWorkflowCondition(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, @@ -884,10 +884,10 @@ func TestGetEventTypes(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).(*events.EventTypesResponse) + respMapping := args.Get(3).(*events.EventTypesResponse) *respMapping = eventTypes }) }, @@ -905,7 +905,7 @@ func TestGetEventTypes(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 *events.EventTypesResponse, err error) { @@ -961,10 +961,10 @@ func TestGetEvent(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).(*events.EventResponse) + respMapping := args.Get(3).(*events.EventResponse) *respMapping = eventResponse }) }, @@ -986,7 +986,7 @@ func TestGetEvent(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 *events.EventResponse, err error) { @@ -1004,7 +1004,7 @@ func TestGetEvent(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, @@ -1067,10 +1067,10 @@ func TestGetSubjectEvents(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).(*events.SubjectEventsResponse) + respMapping := args.Get(3).(*events.SubjectEventsResponse) *respMapping = subjectEventsResponse }) }, @@ -1088,7 +1088,7 @@ func TestGetSubjectEvents(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 *events.SubjectEventsResponse, err error) { @@ -1106,7 +1106,7 @@ func TestGetSubjectEvents(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, @@ -1160,10 +1160,10 @@ func TestReflowByEvent(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 = response }) }, @@ -1180,7 +1180,7 @@ func TestReflowByEvent(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) { @@ -1198,7 +1198,7 @@ func TestReflowByEvent(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.StatusNotFound, @@ -1251,10 +1251,10 @@ func TestReflowBySubject(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 = response }) }, @@ -1271,7 +1271,7 @@ func TestReflowBySubject(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) { @@ -1289,7 +1289,7 @@ func TestReflowBySubject(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.StatusNotFound, @@ -1344,10 +1344,10 @@ func TestReflowByEventAndWorkflow(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 = response }) }, @@ -1364,7 +1364,7 @@ func TestReflowByEventAndWorkflow(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) { @@ -1383,7 +1383,7 @@ func TestReflowByEventAndWorkflow(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.StatusNotFound, @@ -1406,7 +1406,7 @@ func TestReflowByEventAndWorkflow(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.StatusNotFound, @@ -1461,10 +1461,10 @@ func TestReflowBySubjectAndWorkflow(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 = response }) }, @@ -1481,7 +1481,7 @@ func TestReflowBySubjectAndWorkflow(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) { @@ -1500,7 +1500,7 @@ func TestReflowBySubjectAndWorkflow(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.StatusNotFound, @@ -1523,7 +1523,7 @@ func TestReflowBySubjectAndWorkflow(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.StatusNotFound, @@ -1579,10 +1579,10 @@ func TestReflow(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 = response }) }, @@ -1603,10 +1603,10 @@ func TestReflow(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 = response }) }, @@ -1623,7 +1623,7 @@ func TestReflow(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) { @@ -1641,7 +1641,7 @@ func TestReflow(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, @@ -1710,10 +1710,10 @@ func TestGetActionInvocations(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).(*actions.ActionInvocationsResponse) + respMapping := args.Get(3).(*actions.ActionInvocationsResponse) *respMapping = actionInvocationsResponse }) }, @@ -1736,7 +1736,7 @@ func TestGetActionInvocations(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 *actions.ActionInvocationsResponse, err error) { @@ -1755,7 +1755,7 @@ func TestGetActionInvocations(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, @@ -1779,7 +1779,7 @@ func TestGetActionInvocations(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,