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,