Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update client.go #6

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ import (
"fmt"
"net/http"
"sort"
"time"
)

// Client is the main entity which execute request against the Tinkoff Acquiring API endpoint
type Client struct {
terminalKey string
password string
baseURL string
terminalKey string
password string
baseURL string
postTimeoutSec int
}

// NewClient returns new Client instance
func NewClient(terminalKey, password string) *Client {
return &Client{
terminalKey: terminalKey,
password: password,
baseURL: "https://securepay.tinkoff.ru/v2",
terminalKey: terminalKey,
password: password,
baseURL: "https://securepay.tinkoff.ru/v2",
postTimeoutSec: 2,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для timeout'ов придуман context

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Согласен! Добавлю возможность передачи контекста (пока просто новые функции будут XXXWithContext().

}
}

// SetBaseURL allows to change default API endpoint
func (c *Client) SetBaseURL(baseURL string) {
c.baseURL = baseURL
}
func (c *Client) SetPostTimeout(seconds int) { c.postTimeoutSec = seconds }

func (c *Client) decodeResponse(response *http.Response, result interface{}) error {
return json.NewDecoder(response.Body).Decode(result)
Expand All @@ -43,7 +47,8 @@ func (c *Client) PostRequest(url string, request RequestInterface) (*http.Respon
if err != nil {
return nil, err
}
resp, err := http.Post(c.baseURL+url, "application/json", bytes.NewReader(data))
transport := &http.Client{Timeout: time.Duration(c.postTimeoutSec) * time.Second}
resp, err := transport.Post(c.baseURL+url, "application/json", bytes.NewReader(data))
return resp, err
}

Expand Down