Simplify return values

This commit is contained in:
Alex Pliutau 2018-08-29 14:52:31 +07:00
parent af41710b9d
commit af8120920e
3 changed files with 20 additions and 42 deletions

View File

@ -9,4 +9,4 @@ go:
install:
- export PATH=$PATH:$HOME/gopath/bin
script:
- go test
- go test -v -race

View File

@ -17,14 +17,10 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
}
auth := &Authorization{}
if err = c.SendWithAuth(req, auth); err != nil {
err = c.SendWithAuth(req, auth)
return auth, err
}
return auth, nil
}
// CaptureAuthorization captures and process an existing authorization.
// To use this method, the original payment must have Intent set to "authorize"
// Endpoint: POST /v1/payments/authorization/ID/capture
@ -38,14 +34,10 @@ func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture b
}
capture := &Capture{}
if err = c.SendWithAuth(req, capture); err != nil {
err = c.SendWithAuth(req, capture)
return capture, err
}
return capture, nil
}
// VoidAuthorization voids a previously authorized payment
// Endpoint: POST /v1/payments/authorization/ID/void
func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
@ -56,14 +48,10 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
}
auth := &Authorization{}
if err = c.SendWithAuth(req, auth); err != nil {
err = c.SendWithAuth(req, auth)
return auth, err
}
return auth, nil
}
// ReauthorizeAuthorization reauthorize a Paypal account payment.
// PayPal recommends to reauthorize payment after ~3 days
// Endpoint: POST /v1/payments/authorization/ID/reauthorize
@ -75,10 +63,6 @@ func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorizat
}
auth := &Authorization{}
if err = c.SendWithAuth(req, auth); err != nil {
err = c.SendWithAuth(req, auth)
return auth, err
}
return auth, nil
}

View File

@ -52,26 +52,22 @@ func (c *Client) GetAccessToken() (*TokenResponse, error) {
}
// SetHTTPClient sets *http.Client to current client
func (c *Client) SetHTTPClient(client *http.Client) error {
func (c *Client) SetHTTPClient(client *http.Client) {
c.Client = client
return nil
}
// SetAccessToken sets saved token to current client
func (c *Client) SetAccessToken(token string) error {
func (c *Client) SetAccessToken(token string) {
c.Token = &TokenResponse{
Token: token,
}
c.tokenExpiresAt = time.Time{}
return nil
}
// SetLog will set/change the output destination.
// If log file is set paypalsdk will log all requests and responses to this Writer
func (c *Client) SetLog(log io.Writer) error {
func (c *Client) SetLog(log io.Writer) {
c.Log = log
return nil
}
// Send makes a request to the API, the response body will be
@ -112,20 +108,18 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
return errResp
}
if v != nil {
if w, ok := v.(io.Writer); ok {
io.Copy(w, resp.Body)
} else {
err = json.NewDecoder(resp.Body).Decode(v)
if err != nil {
return err
}
}
if v == nil {
return nil
}
if w, ok := v.(io.Writer); ok {
io.Copy(w, resp.Body)
return nil
}
return json.NewDecoder(resp.Body).Decode(v)
}
// SendWithAuth makes a request to the API and apply OAuth2 header automatically.
// If the access token soon to be expired or already expired, it will try to get a new one before
// making the main request